diff options
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 74 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 32 |
2 files changed, 68 insertions, 38 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index f4e8ff8977e..e024544d34d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -1932,14 +1932,17 @@ out: int32_t glusterd_lvm_snapshot_remove (dict_t *rsp_dict, glusterd_volinfo_t *snap_vol) { - char *mnt_pt = NULL; - struct mntent *entry = NULL; - struct mntent save_entry = {0,}; - int32_t brick_count = -1; - int32_t ret = -1; - glusterd_brickinfo_t *brickinfo = NULL; - xlator_t *this = NULL; - char buff [PATH_MAX] = ""; + char *mnt_pt = NULL; + struct mntent *entry = NULL; + struct mntent save_entry = {0,}; + int32_t brick_count = -1; + int32_t ret = -1; + glusterd_brickinfo_t *brickinfo = NULL; + xlator_t *this = NULL; + char buff[PATH_MAX] = ""; + char brick_dir[PATH_MAX] = ""; + char *tmp = NULL; + gf_boolean_t is_brick_dir_present = _gf_false; this = THIS; GF_ASSERT (this); @@ -2021,10 +2024,65 @@ glusterd_lvm_snapshot_remove (dict_t *rsp_dict, glusterd_volinfo_t *snap_vol) goto out; } + ret = rmdir (mnt_pt); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to rmdir: %s, err: %s", + mnt_pt, strerror (errno)); + goto out; + } + + /* After removing the brick dir fetch the parent path + * i.e /var/run/gluster/snaps/<snap-vol-id>/ + */ + if (is_brick_dir_present == _gf_false) { + /* Peers not hosting bricks will have _gf_false */ + is_brick_dir_present = _gf_true; + + /* Need to fetch brick_dir to be removed from + * brickinfo->path, as in a restored volume, + * snap_vol won't have the non-hyphenated snap_vol_id + */ + tmp = strstr (mnt_pt, "brick"); + if (!tmp) { + gf_log (this->name, GF_LOG_ERROR, + "Invalid brick %s", brickinfo->path); + ret = -1; + goto out; + } + + strncpy (brick_dir, mnt_pt, (size_t) (tmp - mnt_pt)); + } + + GF_FREE (mnt_pt); + mnt_pt = NULL; + } + + if (is_brick_dir_present == _gf_true) { + ret = rmdir (brick_dir); + if (ret) { + if (errno == ENOTEMPTY) { + /* Will occur when multiple glusterds + * are running in the same node + */ + gf_log (this->name, GF_LOG_WARNING, + "Failed to rmdir: %s, err: %s. " + "More than one glusterd running " + "on this node.", + brick_dir, strerror (errno)); + ret = 0; + goto out; + } else + gf_log (this->name, GF_LOG_ERROR, + "Failed to rmdir: %s, err: %s", + brick_dir, strerror (errno)); + goto out; + } } ret = 0; out: + GF_FREE (mnt_pt); gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 790bf9644f6..7efa9fb6d17 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -3034,16 +3034,15 @@ out: } static int32_t -glusterd_store_recreate_brick_mounts (glusterd_volinfo_t *volinfo) +glusterd_recreate_vol_brick_mounts (xlator_t *this, + glusterd_volinfo_t *volinfo) { char *brick_mount_path = NULL; glusterd_brickinfo_t *brickinfo = NULL; int32_t ret = -1; int32_t brick_count = -1; struct stat st_buf = {0, }; - xlator_t *this = NULL; - this = THIS; GF_ASSERT (this); GF_ASSERT (volinfo); @@ -3896,33 +3895,6 @@ out: return ret; } -static int32_t -glusterd_recreate_vol_brick_mounts (xlator_t *this, - glusterd_volinfo_t *volinfo) -{ - int32_t ret = 0; - glusterd_conf_t *priv = NULL; - glusterd_brickinfo_t *brickinfo = NULL; - - GF_ASSERT (this); - priv = this->private; - GF_ASSERT (priv); - - list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - ret = glusterd_store_recreate_brick_mounts (volinfo); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "Failed to recreate brick mounts " - "for %s", volinfo->volname); - goto out; - } - } - -out: - gf_log (this->name, GF_LOG_TRACE, "Returning with %d", ret); - return ret; -} - /* Bricks for snap volumes are hosted at /var/run/gluster/snaps * When a volume is restored, it points to the bricks of the snap * volume it was restored from. Hence on a node restart these |