summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-snapshot.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c154
1 files changed, 95 insertions, 59 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index e886f4b..4093cda 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -359,15 +359,16 @@ out:
int
glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
{
- char *volname = NULL;
- char *key = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- xlator_t *this = NULL;
- int ret = -1;
- int config_command = 0;
- char err_str[PATH_MAX] = {0,};
- glusterd_conf_t *conf = NULL;
- uint64_t value = 0;
+ char *volname = NULL;
+ char *key = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ xlator_t *this = NULL;
+ int ret = -1;
+ int config_command = 0;
+ char err_str[PATH_MAX] = {0,};
+ glusterd_conf_t *conf = NULL;
+ uint64_t value = 0;
+ gf_loglevel_t loglevel = GF_LOG_ERROR;
this = THIS;
@@ -381,8 +382,8 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
ret = dict_get_int32 (dict, "config-command", &config_command);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get config-command type");
+ snprintf (err_str, sizeof (err_str),
+ "failed to get config-command type");
goto out;
}
@@ -390,30 +391,25 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
if (!ret) {
ret = dict_get_uint64 (dict, key, &value);
if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
+ snprintf (err_str, sizeof (err_str), "Failed to get the"
" value for %s", key);
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
+
goto out;
}
}
ret = dict_get_str (dict, "volname", &volname);
if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
+ snprintf (err_str, sizeof (err_str), "Failed to get the"
" volume name");
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
goto out;
}
if (strncmp (volname, "all", strlen(volname))) {
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
- snprintf (err_str, PATH_MAX,"Volume %s does not exist.",
- volname);
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
+ snprintf (err_str, sizeof (err_str),
+ "Volume %s does not exist.", volname);
goto out;
}
}
@@ -437,6 +433,12 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
break;
}
out:
+
+ if (ret && err_str[0] != '\0') {
+ gf_log (this->name, loglevel, "%s", err_str);
+ *op_errstr = gf_strdup (err_str);
+ }
+
return ret;
}
@@ -586,6 +588,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
char snapbrckcnt[PATH_MAX] = "";
char snapbrckord[PATH_MAX] = "";
char snap_volname[64] = "";
+ char err_str[PATH_MAX] = "";
int ret = -1;
int64_t i = 0;
int64_t volume_count = 0;
@@ -596,13 +599,15 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
gf_boolean_t is_cg = _gf_false;
xlator_t *this = NULL;
uuid_t *snap_volid = NULL;
+ gf_loglevel_t loglevel = GF_LOG_ERROR;
this = THIS;
+ GF_ASSERT (op_errstr);
ret = dict_get_int64 (dict, "volcount", &volume_count);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to "
- "get the volume count");
+ snprintf (err_str, sizeof (err_str), "failed to "
+ "get the volume count");
goto out;
}
GF_ASSERT (volume_count);
@@ -611,15 +616,15 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
is_cg = _gf_true;
ret = dict_get_str (dict, "cg-name", &name);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get cg-name");
+ snprintf (err_str, sizeof (err_str),
+ "failed to get cg-name");
goto out;
}
} else {
ret = dict_get_str (dict, "snap-name", &name);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get snap-name");
+ snprintf (err_str, sizeof (err_str),
+ "failed to get snap-name");
goto out;
}
}
@@ -629,29 +634,46 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
snprintf (key, sizeof (key), "volname%ld", i+1);
ret = dict_get_str (dict, key, &volname);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get volume name");
+ snprintf (err_str, sizeof (err_str),
+ "failed to get volume name");
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get the volinfo for "
- "the volume %s", volname);
+ snprintf (err_str, sizeof (err_str),
+ "failed to get the volinfo for the volume "
+ "%s", volname);
goto out;
}
if (!glusterd_is_volume_started (volinfo)) {
- gf_log (this->name, GF_LOG_WARNING,
- "volume %s is not started",
- volinfo->volname);
ret = -1;
+ snprintf (err_str, sizeof (err_str),
+ "volume %s is not started",volinfo->volname);
+ loglevel = GF_LOG_WARNING;
goto out;
}
if (glusterd_is_defrag_on (volinfo)) {
ret = -1;
- gf_log (this->name, GF_LOG_WARNING,
- "rebalance process is running "
- "for the volume %s", volname);
+ snprintf (err_str, sizeof (err_str),
+ "rebalance process is running for the "
+ "volume %s", volname);
+ loglevel = GF_LOG_WARNING;
+ goto out;
+ }
+ if (volinfo->is_snap_volume == _gf_true) {
+ ret = -1;
+ snprintf (err_str, sizeof (err_str),
+ "Volume %s is a snap volume", volname);
+ loglevel = GF_LOG_WARNING;
+ goto out;
+ }
+ if (volinfo->snap_count >= volinfo->snap_max_hard_limit) {
+ ret = -1;
+ snprintf (err_str, sizeof (err_str),
+ "The number of existing snaps has reached the "
+ "maximum limit of %"PRIu64" ,for the volume %s",
+ volinfo->snap_max_hard_limit, volname);
+ loglevel = GF_LOG_WARNING;
goto out;
}
@@ -670,8 +692,10 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
if (is_cg) {
memset(snapname, '\0', sizeof (snapname));
- snprintf (tmp, sizeof (tmp), "%s_snap", volinfo->volname);
- snprintf (snapname, sizeof (snapname), "%s_%s", name, tmp);
+ snprintf (tmp, sizeof (tmp), "%s_snap",
+ volinfo->volname);
+ snprintf (snapname, sizeof (snapname), "%s_%s",
+ name, tmp);
strcpy(snap_volname, snapname);
}
@@ -692,9 +716,10 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
device = glusterd_get_brick_mount_details (brickinfo);
if (!device) {
- gf_log (this->name, GF_LOG_ERROR, "getting device name for "
- "the brick %s:%s failed", brickinfo->hostname,
- brickinfo->path);
+ snprintf (err_str, sizeof (err_str),
+ "getting device name for the brick "
+ "%s:%s failed", brickinfo->hostname,
+ brickinfo->path);
ret = -1;
goto out;
}
@@ -702,9 +727,11 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
device = glusterd_build_snap_device_path (device,
snap_volname);
if (!device) {
- gf_log (this->name, GF_LOG_WARNING, "cannot copy the "
- "snapshot device name (volname: %s, "
- "snapname: %s)", volinfo->volname, snapname);
+ snprintf (err_str, sizeof (err_str),
+ "cannot copy the snapshot device "
+ "name (volname: %s, snapname: %s)",
+ volinfo->volname, snapname);
+ loglevel = GF_LOG_WARNING;
ret = -1;
goto out;
}
@@ -721,14 +748,17 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
ret = glusterd_get_brick_root (brickinfo->path, &mnt_pt);
if (ret) {
- gf_log (this->name, GF_LOG_WARNING, "could not get the root of"
- "the brick path %s", brickinfo->path);
+ 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))) {
- gf_log (this->name, GF_LOG_WARNING, "brick: %s brick mount: %s",
- brickinfo->path, mnt_pt);
+ snprintf (err_str, sizeof (err_str),
+ "brick: %s brick mount: %s",
+ brickinfo->path, mnt_pt);
+ loglevel = GF_LOG_WARNING;
goto out;
}
@@ -736,8 +766,8 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
if (snap_brick_dir)
snap_brick_dir++;
- snprintf (snap_brick_path, sizeof (snap_brick_path), "%s/%s",
- snap_mount, snap_brick_dir);
+ snprintf (snap_brick_path, sizeof (snap_brick_path),
+ "%s/%s", snap_mount, snap_brick_dir);
ret = snprintf (snapmntname, sizeof(snapmntname) - 1,
"vol%ld.brick%ld", i+1, brick_count);
@@ -745,26 +775,27 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
tmpstr = gf_strdup (snap_brick_path);
if (!tmpstr) {
- gf_log ("", GF_LOG_ERROR, "Out Of Memory");
ret = -1;
goto out;
}
ret = dict_set_dynstr (rsp_dict, snapmntname, tmpstr);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Failed to set %s",
- snap_mount);
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set %s", snap_mount);
GF_FREE (tmpstr);
goto out;
}
tmpstr = NULL;
ret = snprintf (snapbrckord, sizeof(snapbrckord) - 1,
- "vol%ld.brick%ld.order", i+1, brick_count);
+ "vol%ld.brick%ld.order",
+ i+1, brick_count);
snapbrckord[ret] = '\0';
ret = dict_set_int64 (rsp_dict, snapbrckord, brick_order);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Failed to set brick order");
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set brick order");
goto out;
}
@@ -794,7 +825,12 @@ out:
if (ret)
GF_FREE (tmpstr);
- gf_log ("", GF_LOG_TRACE, "Returning %d", ret);
+ if (ret && err_str[0] != '\0') {
+ gf_log (this->name, loglevel, "%s", err_str);
+ *op_errstr = gf_strdup (err_str);
+ }
+
+ gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret);
return ret;
}