From 6779d91ea8ee8bb8f337213b0be2d31e4fd62619 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Thu, 8 Jul 2010 05:45:58 +0000 Subject: fix fuse volume creation from volfile Signed-off-by: Csaba Henk Signed-off-by: Anand V. Avati BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971 --- glusterfsd/src/glusterfsd.c | 80 ++++++++++++++++++++++----------------------- libglusterfs/src/graph.c | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 41 deletions(-) diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 8636e1f6c44..32a9bc8fc13 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -190,52 +190,60 @@ create_fuse_mount (glusterfs_ctx_t *ctx) xlator_t *master = NULL; cmd_args = &ctx->cmd_args; - - if (!cmd_args->mount_point) + master = ctx->master; + if (!master && !cmd_args->mount_point) return 0; - master = GF_CALLOC (1, sizeof (*master), - gfd_mt_xlator_t); - if (!master) - goto err; + if (!master) { + master = GF_CALLOC (1, sizeof (*master), + gfd_mt_xlator_t); + if (!master) + goto err; - master->name = gf_strdup ("fuse"); - if (!master->name) - goto err; + master->name = gf_strdup ("fuse"); + if (!master->name) + goto err; - if (xlator_set_type (master, ZR_XLATOR_FUSE) == -1) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "MOUNT-POINT %s initialization failed", - cmd_args->mount_point); - goto err; - } + if (xlator_set_type (master, ZR_XLATOR_FUSE) == -1) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "MOUNT-POINT %s initialization failed", + cmd_args->mount_point); + goto err; + } - master->ctx = ctx; - master->options = get_new_dict (); + master->options = get_new_dict (); - ret = dict_set_static_ptr (master->options, ZR_MOUNTPOINT_OPT, - cmd_args->mount_point); - if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set mount-point to options dictionary"); - goto err; + ctx->master = master; } + master->ctx = ctx; - if (cmd_args->fuse_attribute_timeout >= 0) + if (cmd_args->mount_point) + ret = dict_set_static_ptr (master->options, ZR_MOUNTPOINT_OPT, + cmd_args->mount_point); + + if (ret == 0 && cmd_args->fuse_attribute_timeout >= 0) ret = dict_set_double (master->options, ZR_ATTR_TIMEOUT_OPT, cmd_args->fuse_attribute_timeout); - if (cmd_args->fuse_entry_timeout >= 0) + + if (ret == 0 && cmd_args->fuse_entry_timeout >= 0) ret = dict_set_double (master->options, ZR_ENTRY_TIMEOUT_OPT, cmd_args->fuse_entry_timeout); - if (cmd_args->volfile_check) + if (ret == 0 && cmd_args->volfile_check) ret = dict_set_int32 (master->options, ZR_STRICT_VOLFILE_CHECK, cmd_args->volfile_check); - if (cmd_args->dump_fuse) + if (ret == 0 && cmd_args->dump_fuse) ret = dict_set_static_ptr (master->options, ZR_DUMP_FUSE, cmd_args->dump_fuse); + if (ret) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "failed to set mount-point to options " + "dictionary"); + goto err; + } + switch (cmd_args->fuse_direct_io_mode) { case GF_OPTION_DISABLE: /* disable */ ret = dict_set_static_ptr (master->options, ZR_DIRECT_IO_OPT, @@ -254,8 +262,6 @@ create_fuse_mount (glusterfs_ctx_t *ctx) if (ret) goto err; - ctx->master = master; - return 0; err: @@ -1180,14 +1186,10 @@ glusterfs_volumes_init (glusterfs_ctx_t *ctx) } ret = glusterfs_graph_prepare (graph, ctx); - - if (ret) { - glusterfs_graph_destroy (graph); - ret = -1; - goto out; - } - - ret = glusterfs_graph_activate (ctx, graph); + if (!ret) + ret = create_fuse_mount (ctx); + if (!ret) + ret = glusterfs_graph_activate (ctx, graph); if (ret) { glusterfs_graph_destroy (graph); @@ -1231,10 +1233,6 @@ main (int argc, char *argv[]) gf_proc_dump_init(); - ret = create_fuse_mount (ctx); - if (ret) - goto out; - ret = daemonize (ctx); if (ret) goto out; diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index 2609b7625df..af962107d44 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -193,6 +193,61 @@ err: } +int +glusterfs_set_master (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +{ + xlator_t *trav = NULL; + xlator_list_t *chp = NULL, **chpp = NULL; + + for (trav = graph->first; trav; trav = trav->next) { + if (strcmp (trav->type, "mount/fuse") != 0) + continue; + + if (ctx->master) { + gf_log ("graph", GF_LOG_ERROR, + "there can be at most one fuse volume"); + + return -1; + } + + if (!trav->children || trav->children->next) { + gf_log ("graph", GF_LOG_ERROR, + "fuse volume not configured with exactly one " + "child"); + return -1; + } + + if (xlator_has_parent (trav)) { + gf_log ("graph", GF_LOG_ERROR, + "fuse volume cannot have parents"); + + return -1; + } + + ctx->master = trav; + if (trav == graph->top) + graph->top = trav->children->xlator; + for (chpp = &trav->children->xlator->parents; + *chpp; + chpp = &(*chpp)->next) { + if ((*chpp)->xlator == trav) { + chp = *chpp; + *chpp = chp->next; + GF_FREE (chp); + if (!*chpp) + break; + } + } + if (trav == graph->first) + graph->first = trav->next; + if (trav->prev) + trav->prev->next = trav->next; + } + + return 0; +} + + int glusterfs_graph_readonly (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { @@ -383,6 +438,11 @@ glusterfs_graph_settop (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) for (trav = graph->first; trav; trav = trav->next) { if (strcmp (trav->name, volume_name) == 0) { + if (strcmp (trav->type, "mount/fuse") == 0) { + gf_log ("graph", GF_LOG_ERROR, + "fuse volume cannot be set as top"); + break; + } graph->top = trav; return 0; } @@ -428,6 +488,11 @@ glusterfs_graph_prepare (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) if (ret) return -1; + /* XXX: take fuse from volfile */ + ret = glusterfs_set_master (graph, ctx); + if (ret) + return -1; + /* XXX: RO VOLUME */ ret = glusterfs_graph_readonly (graph, ctx); if (ret) -- cgit