From: Marcos Paulo de Souza <marcos@mpdesouza.com>
To: dsterba@suse.com, linux-btrfs@vger.kernel.org
Cc: Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: [RFC PATCH 5/8] btrfs: super: Introduce btrfs_dup_fc
Date: Wed, 12 Aug 2020 13:36:51 -0300 [thread overview]
Message-ID: <20200812163654.17080-6-marcos@mpdesouza.com> (raw)
In-Reply-To: <20200812163654.17080-1-marcos@mpdesouza.com>
From: Marcos Paulo de Souza <mpdesouza@suse.com>
This function will be used in a future patch when mounting root filesystem
before mounting a subvolume.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
fs/btrfs/super.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 88221d1d8bae..6b70fb73a1ea 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1091,6 +1091,56 @@ static int btrfs_fc_validate(struct fs_context *fc)
return 0;
}
+static int btrfs_dup_fc(struct fs_context *fc, struct fs_context *src_fc)
+{
+ int i;
+ struct btrfs_fs_context *ctx, *src = src_fc->fs_private;
+
+ ctx = kmemdup(src, sizeof(*ctx), GFP_KERNEL);
+ if (!ctx)
+ return -ENOMEM;
+
+ ctx->subvol_name = NULL;
+ ctx->devices = NULL;
+ ctx->root_mnt = NULL;
+
+ if (src->subvol_name) {
+ ctx->subvol_name = kstrdup(src->subvol_name, GFP_KERNEL);
+ if (!ctx->subvol_name)
+ goto nomem_ctx;
+ }
+
+ if (ctx->nr_devices) {
+ ctx->devices = kcalloc(ctx->nr_devices, sizeof(char *), GFP_KERNEL);
+ if (!ctx->devices)
+ goto nomem_sub;
+ for (i = 0; i < ctx->nr_devices; i++) {
+ ctx->devices[i] = kstrdup(src->devices[i], GFP_KERNEL);
+ if (!ctx->devices[i])
+ goto nomem_devs;
+ }
+ }
+
+ if (src_fc->source) {
+ fc->source = kstrdup(src_fc->source, GFP_KERNEL);
+ if (!fc->source)
+ goto nomem_devs;
+ }
+
+ fc->fs_private = ctx;
+ return 0;
+
+nomem_devs:
+ for (i = 0; i < ctx->nr_devices; i++)
+ kfree(ctx->devices[i]);
+ kfree(ctx->devices);
+nomem_sub:
+ kfree(ctx->subvol_name);
+nomem_ctx:
+ kfree(ctx);
+ return -ENOMEM;
+}
+
static int btrfs_fc_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
int opt;
@@ -2967,6 +3017,7 @@ static void btrfs_fc_free(struct fs_context *fc)
}
static const struct fs_context_operations btrfs_context_ops = {
+ .dup = btrfs_dup_fc,
.free = btrfs_fc_free,
.parse_param = btrfs_fc_parse_param,
};
--
2.28.0
next prev parent reply other threads:[~2020-08-12 17:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-12 16:36 [RFC PATCH 0/8] btrfs: convert to fscontext Marcos Paulo de Souza
2020-08-12 16:36 ` [RFC PATCH 1/8] btrfs: fs_context: Add initial fscontext parameters Marcos Paulo de Souza
2020-08-12 16:36 ` [RFC PATCH 2/8] btrfs: super: Introduce fs_context ops, init and free functions Marcos Paulo de Souza
2020-08-17 12:50 ` David Sterba
2020-08-12 16:36 ` [RFC PATCH 3/8] btrfs: super: Introduce btrfs_fc_parse_param and btrfs_apply_configuration Marcos Paulo de Souza
2020-08-17 13:09 ` David Sterba
2020-08-12 16:36 ` [RFC PATCH 4/8] btrfs: super: Introduce btrfs_fc_validate Marcos Paulo de Souza
2020-08-12 16:36 ` Marcos Paulo de Souza [this message]
2020-08-12 16:36 ` [RFC PATCH 6/8] btrfs: super: Introduce btrfs_mount_root_fc Marcos Paulo de Souza
2020-08-17 13:14 ` David Sterba
2020-08-12 16:36 ` [RFC PATCH 7/8] btrfs: Convert to fs_context Marcos Paulo de Souza
2020-08-17 13:26 ` David Sterba
2020-08-12 16:36 ` [RFC PATCH 8/8] btrfs: Remove leftover code from fscontext conversion Marcos Paulo de Souza
2020-08-17 12:44 ` [RFC PATCH 0/8] btrfs: convert to fscontext David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200812163654.17080-6-marcos@mpdesouza.com \
--to=marcos@mpdesouza.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=mpdesouza@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).