diff options
author | Avra Sengupta <asengupt@redhat.com> | 2014-04-23 04:26:24 +0000 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2014-05-06 00:24:39 -0700 |
commit | f846e54b8844decbc8bd73840e7d35b2dcaed2e0 (patch) | |
tree | e0f7be12df60b59c42651cd50bd683510e7cce24 /xlators/mgmt/glusterd/src/glusterd-snapshot.c | |
parent | a05c579f1c3695c4ddead0a5cfc2c92422bd4f8f (diff) |
glusterd: Fetch brick mount_dirs during brick create.
Fetch the mount directory path for a brick, during
volume create, add-brick, and replace-brick.
When a snap-create is missed, use this mount directory
information to create the brick path for the missed snap brick.
Change-Id: Iad3eec96a32cf340f26bdf3f28e2f529e4b77e31
BUG: 1061685
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: http://review.gluster.org/7550
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 115 |
1 files changed, 34 insertions, 81 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 54b61ee66cd..327155fee31 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -1042,7 +1042,6 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) { char *snap_brick_dir = NULL; char *snap_device = NULL; - char *tmpstr = NULL; char key[PATH_MAX] = ""; char snapbrckcnt[PATH_MAX] = ""; char snapbrckord[PATH_MAX] = ""; @@ -1081,7 +1080,6 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) /* Fetching data from source dict */ snprintf (key, sizeof(key) - 1, "vol%"PRId64".brickdir%"PRId64, i+1, j); - ret = dict_get_ptr (src, key, (void **)&snap_brick_dir); if (ret) { @@ -1090,20 +1088,9 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) continue; } - snprintf (key, sizeof(key) - 1, - "vol%"PRId64".brick_snapdevice%"PRId64, i+1, j); - - ret = dict_get_ptr (src, key, - (void **)&snap_device); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "Unable to fetch snap_device"); - goto out; - } - + /* Fetching brick order from source dict */ snprintf (snapbrckord, sizeof(snapbrckord) - 1, "vol%"PRId64".brick%"PRId64".order", i+1, j); - ret = dict_get_int64 (src, snapbrckord, &brick_order); if (ret) { gf_log (this->name, GF_LOG_ERROR, @@ -1111,39 +1098,36 @@ glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - /* Adding the data in the dst dict */ snprintf (key, sizeof(key) - 1, - "vol%"PRId64".brickdir%"PRId64, i+1, brick_order); - - tmpstr = gf_strdup (snap_brick_dir); - if (!tmpstr) { + "vol%"PRId64".brickdir%"PRId64, i+1, + brick_order); + ret = dict_set_dynstr_with_alloc (dst, key, + snap_brick_dir); + if (ret) { gf_log (this->name, GF_LOG_ERROR, - "Out Of Memory"); - ret = -1; + "Failed to set %s", key); goto out; } - ret = dict_set_dynstr (dst, key, tmpstr); + + snprintf (key, sizeof(key) - 1, + "vol%"PRId64".brick_snapdevice%"PRId64, + i+1, j); + ret = dict_get_ptr (src, key, + (void **)&snap_device); if (ret) { gf_log (this->name, GF_LOG_ERROR, - "Failed to set %s", key); - GF_FREE (tmpstr); + "Unable to fetch snap_device"); goto out; } snprintf (key, sizeof(key) - 1, "vol%"PRId64".brick_snapdevice%"PRId64, i+1, brick_order); - - tmpstr = gf_strdup (snap_device); - if (!tmpstr) { - ret = -1; - goto out; - } - ret = dict_set_dynstr (dst, key, tmpstr); + ret = dict_set_dynstr_with_alloc (dst, key, + snap_device); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to set %s", key); - GF_FREE (tmpstr); goto out; } } @@ -1205,12 +1189,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, char *volname = NULL; char *snapname = NULL; char *device = NULL; - char *tmpstr = NULL; - char *brick_dir = NULL; - char snap_brick_dir[PATH_MAX] = ""; - char *mnt_pt = NULL; char key[PATH_MAX] = ""; - char snap_mount[PATH_MAX] = ""; char snap_volname[64] = ""; char err_str[PATH_MAX] = ""; int ret = -1; @@ -1394,44 +1373,17 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, GF_FREE (device); goto out; } + device = NULL; - ret = glusterd_get_brick_root (brickinfo->path, - &mnt_pt); - if (ret) { - snprintf (err_str, sizeof (err_str), - "could not get the root of the brick path %s", - brickinfo->path); - loglevel = GF_LOG_WARNING; - goto out; - } - if (strncmp (brickinfo->path, mnt_pt, strlen(mnt_pt))) { - snprintf (err_str, sizeof (err_str), - "brick: %s brick mount: %s", - brickinfo->path, mnt_pt); - loglevel = GF_LOG_WARNING; - goto out; - } - - brick_dir = &brickinfo->path[strlen (mnt_pt)]; - brick_dir++; - - snprintf (snap_brick_dir, sizeof (snap_brick_dir), - "/%s", brick_dir); - - tmpstr = gf_strdup (snap_brick_dir); - if (!tmpstr) { - ret = -1; - goto out; - } snprintf (key, sizeof(key), "vol%"PRId64".brickdir%"PRId64, i, brick_count); - ret = dict_set_dynstr (rsp_dict, key, tmpstr); + ret = dict_set_dynstr_with_alloc (rsp_dict, key, + brickinfo->mount_dir); if (ret) { gf_log (this->name, GF_LOG_ERROR, - "Failed to set %s", snap_mount); + "Failed to set %s", key); goto out; } - tmpstr = NULL; snprintf (key, sizeof(key) - 1, "vol%"PRId64".brick%"PRId64".order", i, brick_count); @@ -1462,8 +1414,8 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, ret = 0; out: - if (ret) - GF_FREE (tmpstr); + if (device) + GF_FREE (device); if (ret && err_str[0] != '\0') { gf_log (this->name, loglevel, "%s", err_str); @@ -3536,23 +3488,16 @@ glusterd_add_bricks_to_snap_volume (dict_t *dict, dict_t *rsp_dict, * will help in mapping while recreating the missed snapshot */ gf_log (this->name, GF_LOG_WARNING, "Unable to fetch " - "snap mount path (%s). Using original brickinfo", key); + "snap mount path(%s). Adding to missed_snap_list", key); snap_brickinfo->snap_status = -1; - strcpy (snap_brick_path, original_brickinfo->path); + + *snap_brick_dir = original_brickinfo->mount_dir; /* In origiator node add snaps missed * from different nodes to the dict */ if (is_origin_glusterd (dict) == _gf_true) add_missed_snap = _gf_true; - } else { - /* Create brick-path in the format /var/run/gluster/snaps/ * - * <snap-uuid>/<original-brick#>/snap-brick-dir * - */ - snprintf (snap_brick_path, sizeof(snap_brick_path), - "%s/%s/brick%d%s", snap_mount_folder, - snap_vol->volname, brick_count+1, - *snap_brick_dir); } if ((snap_brickinfo->snap_status != -1) && @@ -3566,7 +3511,6 @@ glusterd_add_bricks_to_snap_volume (dict_t *dict, dict_t *rsp_dict, snap_vol->snapshot->snapname); snap_brickinfo->snap_status = -1; - strcpy (snap_brick_path, original_brickinfo->path); add_missed_snap = _gf_true; } @@ -3585,6 +3529,14 @@ glusterd_add_bricks_to_snap_volume (dict_t *dict, dict_t *rsp_dict, } } + /* Create brick-path in the format /var/run/gluster/snaps/ * + * <snap-uuid>/<original-brick#>/snap-brick-dir * + */ + snprintf (snap_brick_path, sizeof(snap_brick_path), + "%s/%s/brick%d%s", snap_mount_folder, + snap_vol->volname, brick_count+1, + *snap_brick_dir); + snprintf (key, sizeof(key), "vol%"PRId64".brick_snapdevice%d", volcount, brick_count); ret = dict_get_ptr (dict, key, (void **)&snap_device); @@ -3606,6 +3558,7 @@ glusterd_add_bricks_to_snap_volume (dict_t *dict, dict_t *rsp_dict, strcpy (snap_brickinfo->hostname, original_brickinfo->hostname); strcpy (snap_brickinfo->path, snap_brick_path); + strcpy (snap_brickinfo->mount_dir, original_brickinfo->mount_dir); uuid_copy (snap_brickinfo->uuid, original_brickinfo->uuid); /* AFR changelog names are based on brick_id and hence the snap * volume's bricks must retain the same ID */ |