From cc4fa72926f9ac517365d91ae6144530dc67c001 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Wed, 16 Oct 2013 18:18:04 +0530 Subject: mgmt/glusterd: snapshot create command This is still a work in progress. As of now, these things are done: * Take the snapshot of the backend brick * Create the new volume for the snapshot * Create the brick and the client volfiles * Store the snapshot related info in /var/lib/glusterd * Create the snap object representing the snapshot TODO: Start the brick processes for the snapshot Change-Id: I26fbb0f8e5cf004d4c1dbca51819bab1cd1bac15 Signed-off-by: Raghavendra Bhat --- xlators/mgmt/glusterd/src/glusterd-volgen.c | 144 ++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 0de71a49a..fc326757d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -3172,6 +3172,38 @@ glusterd_generate_brick_volfile (glusterd_volinfo_t *volinfo, return ret; } +static int +glusterd_generate_snap_brick_volfile (glusterd_volinfo_t *volinfo, + glusterd_brickinfo_t *brickinfo, + glusterd_volinfo_t *snap_volinfo) +{ + volgen_graph_t graph = {0,}; + char filename[PATH_MAX] = {0,}; + int ret = -1; + char path[PATH_MAX] = {0,}; + char brick[PATH_MAX] = {0,}; + glusterd_conf_t *priv = NULL; + + priv = THIS->private; + GF_ASSERT (volinfo); + GF_ASSERT (brickinfo); + + GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, brick); + GLUSTERD_GET_SNAP_DIR (path, volinfo, snap_volinfo->volname, priv); + + snprintf (filename, PATH_MAX, "%s/%s.%s.%s.vol", + path, snap_volinfo->volname, + brickinfo->hostname, + brick); + + ret = build_server_graph (&graph, snap_volinfo, NULL, brickinfo); + if (!ret) + ret = volgen_write_volfile (&graph, filename); + + volgen_graph_free (&graph); + + return ret; +} static void @@ -3241,6 +3273,31 @@ out: return ret; } +int +generate_snap_brick_volfiles (glusterd_volinfo_t *volinfo, + glusterd_volinfo_t *snap_volinfo) +{ + glusterd_brickinfo_t *brickinfo = NULL; + int ret = -1; + + list_for_each_entry (brickinfo, &snap_volinfo->bricks, brick_list) { + gf_log ("", GF_LOG_DEBUG, + "Found a brick - %s:%s", brickinfo->hostname, + brickinfo->path); + + ret = glusterd_generate_snap_brick_volfile (volinfo, brickinfo, + snap_volinfo); + if (ret) + goto out; + } + + ret = 0; + +out: + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +} + static int generate_single_transport_client_volfile (glusterd_volinfo_t *volinfo, char *filepath, dict_t *dict) @@ -3322,6 +3379,93 @@ out: return ret; } +int +generate_snap_client_volfiles (glusterd_volinfo_t *actual_volinfo, + glusterd_volinfo_t *snap_volinfo, + glusterd_client_type_t client_type) +{ + char filepath[PATH_MAX] = {0,}; + int ret = -1; + char *types[] = {NULL, NULL, NULL}; + int i = 0; + dict_t *dict = NULL; + gf_transport_type type = GF_TRANSPORT_TCP; + char path[PATH_MAX] = {0, }; + xlator_t *this = NULL; + glusterd_conf_t *conf = NULL; + + this = THIS; + GF_ASSERT (this); + conf = this->private; + GF_ASSERT (conf); + + if (!actual_volinfo) { + gf_log (this->name, GF_LOG_ERROR, "actual volinfo is NULL." + "Unable to generate the client volfiles for snap"); + goto out; + } + + if (!snap_volinfo) { + gf_log (this->name, GF_LOG_ERROR, "snap volinfo is NULL. Unable" + "to generate the client volfiles for snap (volume: %s)", + actual_volinfo->volname); + goto out; + } + + enumerate_transport_reqs (actual_volinfo->transport_type, types); + dict = dict_new (); + if (!dict) + goto out; + for (i = 0; types[i]; i++) { + memset (filepath, 0, sizeof (filepath)); + ret = dict_set_str (dict, "client-transport-type", types[i]); + if (ret) + goto out; + type = transport_str_to_type (types[i]); + + ret = dict_set_uint32 (dict, "trusted-client", client_type); + if (ret) + goto out; + + GLUSTERD_GET_SNAP_DIR (path, actual_volinfo, + snap_volinfo->volname,conf); + if (client_type == GF_CLIENT_TRUSTED) { + if ((actual_volinfo->transport_type == + GF_TRANSPORT_BOTH_TCP_RDMA) && + type == GF_TRANSPORT_RDMA) { + snprintf (filepath, PATH_MAX, + "%s/trusted-%s.rdma-fuse.vol", + path, snap_volinfo->volname); + } else { + snprintf (filepath, PATH_MAX, + "%s/trusted-%s-fuse.vol", + path, snap_volinfo->volname); + } + } else { + if ((actual_volinfo->transport_type == + GF_TRANSPORT_BOTH_TCP_RDMA) && + (type == GF_TRANSPORT_RDMA)) { + snprintf (filepath, PATH_MAX, "%s/%s.rdma-fuse.vol", + path, snap_volinfo->volname); + } else { + snprintf (filepath, PATH_MAX, "%s/%s-fuse.vol", + path, snap_volinfo->volname); + } + } + + ret = generate_single_transport_client_volfile (snap_volinfo, + filepath, + dict); + if (ret) + goto out; + } + +out: + if (dict) + dict_unref (dict); + return ret; +} + int glusterd_create_rb_volfiles (glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo) -- cgit