@@ -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,
};