summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c99
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c28
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h10
3 files changed, 111 insertions, 26 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 88abec616..eacda058b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -657,7 +657,7 @@ glusterd_new_snap_object()
glusterd_snap_cg_t*
glusterd_new_snap_cg_object(int64_t volume_count)
{
- glusterd_snap_cg_t *cg = NULL;
+ glusterd_snap_cg_t *cg = NULL;
glusterd_volinfo_t *volinfo = NULL;
if (volume_count < 0) {
@@ -1279,13 +1279,16 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
glusterd_volinfo_t *volinfo,
char *snapname, int8_t detail)
{
- int ret = -1;
- ssize_t index = -1;
- glusterd_snap_t *entry = NULL;
- glusterd_snap_t *tmp = NULL;
- xlator_t *this = NULL;
- char *value = NULL;
+ int ret = -1;
+ uint64_t index = 0;
+ glusterd_snap_t *entry = NULL;
+ glusterd_snap_t *tmp = NULL;
+ xlator_t *this = NULL;
+ char *value = NULL;
char key[256];
+ glusterd_conf_t *conf = NULL;
+ uint64_t snap_limit = 0;
+ char err_str[PATH_MAX];
this = THIS;
@@ -1295,6 +1298,9 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
GF_ASSERT (keyprefix);
GF_ASSERT (volinfo);
+ conf = this->private;
+ GF_ASSERT (conf);
+
value = gf_strdup (volinfo->volname);
if (NULL == value) {
goto out;
@@ -1319,7 +1325,36 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
ret = dict_set_int64 (dict, key, volinfo->snap_count);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to set total snap count");
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set total"
+ " snap count");
+ goto out;
+ }
+ ret = snprintf (key, sizeof (key), "%s.snap-available", keyprefix);
+ if (ret < 0) {
+ goto out;
+ }
+
+ if (conf->snap_max_limit < volinfo->snap_max_limit) {
+ snap_limit = conf->snap_max_limit;
+ gf_log(this->name, GF_LOG_DEBUG, "system snap_limit is "
+ "lesser than volume snap_limit, snap_limit value "
+ "is set to %ld",snap_limit);
+ }
+ else {
+ snap_limit = volinfo->snap_max_limit ;
+ gf_log(this->name, GF_LOG_DEBUG, "volume snap_limit is "
+ "lesser than system snap_limit, snap_limit value "
+ "is set to %ld",snap_limit);
+ }
+
+ if (snap_limit > volinfo->snap_count)
+ ret = dict_set_int64 (dict, key,
+ snap_limit - volinfo->snap_count);
+ else
+ ret = dict_set_int64 (dict, key, 0);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set available snaps");
goto out;
}
/* Ownership of value transferred to dict. Therefore we must initalize
@@ -1329,12 +1364,12 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
/* snapshot taken first should be displayed first */
list_for_each_entry_safe (entry, tmp, &volinfo->snaps,
snap_list) {
- ++index;
- ret = snprintf (key, sizeof (key), "%s.snap-%ld", keyprefix, index);
+ ret = snprintf (key, sizeof (key), "%s.snap-%ld", keyprefix,
+ index);
if (ret < 0) { /* Only negative value is error */
goto out;
}
-
+ ++index;
/* If snapname is NULL then get all the snaps
* for the given volume */
if (NULL == snapname) {
@@ -1376,14 +1411,13 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
* added to the dictionary. If snapshot name is passed
* as argument then we would send only one snap object.
* Therefore index should be reset to 0. */
- index = 0;
+ index = 1;
break; /* Found the snap */
}
/* If all the snap is written into the dictionary then write the
* snap count into the dictionary */
if (0 == ret) {
- ++index; /* To get count increment index by 1*/
ret = snprintf (key, sizeof (key), "%s.snap-count", keyprefix);
if (ret < 0) { /* Only negative value is error */
goto out;
@@ -1399,6 +1433,22 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
} else if (NULL != snapname) {
gf_log (this->name, GF_LOG_ERROR, "Snap (%s) not found",
snapname);
+ ret = snprintf (key, sizeof (key), "%s.err_str",
+ keyprefix);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = snprintf (err_str, sizeof (err_str), "Snapshot %s"
+ " not found", snapname);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = dict_set_str (dict, key, err_str);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to"
+ "set error string");
+ goto out;
+ }
}
out:
@@ -1600,7 +1650,6 @@ glusterd_snapshot_cg_get_snaplist_lk (dict_t *dict, glusterd_snap_cg_t *cg,
if (ret < 0) { /* Only negative value is error */
goto out;
}
-
ret = glusterd_snapshot_vol_get_snaplist (dict, key,
&(cg->volumes[i]), NULL, detail);
if (ret) {
@@ -1699,7 +1748,8 @@ out:
*/
static int
glusterd_snapshot_cg_get_snaplist (dict_t *dict, char *keyprefix,
- char *cgname, int8_t detail)
+ char *cgname, int8_t detail,
+ char *err_str, size_t len)
{
int ret = -1; /* Failure */
glusterd_conf_t *conf = NULL;
@@ -1721,8 +1771,9 @@ glusterd_snapshot_cg_get_snaplist (dict_t *dict, char *keyprefix,
cg = glusterd_find_snap_cg_by_name (conf, cgname);
if (NULL == cg) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s CG", cgname);
+ snprintf (err_str, len, "CG %s not found", cgname);
+ gf_log (this->name, GF_LOG_WARNING, "%s", err_str);
+ ret = -1;
goto out;
}
@@ -1868,7 +1919,7 @@ out:
*/
int
glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
- dict_t *dict)
+ dict_t *dict, char *err_str, size_t len)
{
int ret = -1;
int64_t volcount = 0;
@@ -1877,7 +1928,6 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
char *keyprefix = "snaplist";
char *cgname = NULL;
char *snapname = NULL;
- char *err_str = "Operation failed";
dict_t *voldict = NULL;
xlator_t *this = NULL;
char key[256] = {0,};
@@ -1928,8 +1978,8 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
goto out;
}
- ret = glusterd_snapshot_cg_get_snaplist (dict, key,
- cgname, detail);
+ ret = glusterd_snapshot_cg_get_snaplist (dict, key, cgname,
+ detail, err_str, len);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to get "
"snapshot list for %s CG", cgname);
@@ -2945,11 +2995,12 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
glusterd_volinfo_t *volinfo = NULL;
glusterd_snap_cg_t *cg = NULL;
glusterd_conf_t *priv = NULL;
- uuid_t cg_id;
+ uuid_t cg_id;
glusterd_snap_t *snap = NULL;
char err_str[PATH_MAX] = {0, };
this = THIS;
+ priv = this->private;
ret = dict_get_int64 (dict, "volcount", &volume_count);
if (ret) {
@@ -3041,7 +3092,6 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
"consistency group %s", name);
goto out;
}
-
uuid_copy (cg->cg_id, cg_id);
strncpy (cg->cg_name, name, sizeof (cg->cg_name));
ret = glusterd_add_snap_cg (priv, cg);
@@ -3362,7 +3412,8 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
break;
case GF_SNAP_OPTION_TYPE_LIST:
- ret = glusterd_handle_snapshot_list (req, cli_op, dict);
+ ret = glusterd_handle_snapshot_list (req, cli_op, dict,
+ err_str, sizeof (err_str));
if (ret) {
gf_log (this->name, GF_LOG_WARNING, "Snapshot list "
"failed");
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index f79cd2353..dd64867db 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1310,6 +1310,28 @@ _mk_rundir_p (glusterd_volinfo_t *volinfo)
return ret;
}
+static int
+_mk_snap_rundir_p (glusterd_volinfo_t *volinfo, glusterd_volinfo_t *snap_volinfo)
+{
+ char voldir[PATH_MAX] = {0,};
+ char rundir[PATH_MAX] = {0,};
+ glusterd_conf_t *priv = NULL;
+ xlator_t *this = NULL;
+ int ret = -1;
+
+ GF_ASSERT (volinfo);
+ GF_ASSERT (snap_volinfo);
+
+ this = THIS;
+ priv = this->private;
+ GLUSTERD_GET_SNAP_DIR (voldir, volinfo, snap_volinfo->volname, priv);
+ snprintf (rundir, sizeof (rundir)-1, "%s/run", voldir);
+ ret = mkdir_p (rundir, 0777, _gf_true);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR, "Failed to create rundir");
+ return ret;
+}
+
int32_t
glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo,
@@ -1482,10 +1504,12 @@ glusterd_snap_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
priv = this->private;
GF_ASSERT (priv);
- ret = _mk_rundir_p (volinfo);
+ ret = _mk_snap_rundir_p (volinfo, snap_volinfo);
if (ret)
goto out;
- GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo, priv);
+ GLUSTERD_GET_SNAP_BRICK_PIDFILE (pidfile, volinfo,
+ snap_volinfo->volname, brickinfo,
+ priv);
if (glusterd_is_service_running (pidfile, NULL))
goto connect;
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index bb998cccc..fb4f32a82 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -468,6 +468,16 @@ typedef ssize_t (*gd_serialize_t) (struct iovec outmsg, void *args);
volpath, brickinfo->hostname, exp_path); \
} while (0)
+#define GLUSTERD_GET_SNAP_BRICK_PIDFILE(pidfile,volinfo,snapname,brickinfo, \
+ priv) do { \
+ char exp_path[PATH_MAX] = {0,}; \
+ char volpath[PATH_MAX] = {0,}; \
+ GLUSTERD_GET_SNAP_DIR(volpath, volinfo, snapname, priv); \
+ GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, exp_path); \
+ snprintf (pidfile, PATH_MAX, "%s/run/%s-%s.pid", \
+ volpath, brickinfo->hostname, exp_path); \
+ } while (0)
+
#define GLUSTERD_GET_NFS_PIDFILE(pidfile,nfspath) { \
snprintf (pidfile, PATH_MAX, "%s/run/nfs.pid", \
nfspath); \