diff options
| author | Avra Sengupta <asengupt@redhat.com> | 2016-07-27 16:28:44 +0530 | 
|---|---|---|
| committer | Rajesh Joseph <rjoseph@redhat.com> | 2016-08-24 03:17:30 -0700 | 
| commit | 5d833c89aacc747d0bc654b4ab947c6bf59366d0 (patch) | |
| tree | d066b94f06c4865cc2d9483a49885c0f0d79b171 | |
| parent | 106a107ec5c8ecc48c3e048a9b8ad9ac809e278d (diff) | |
snapshot: Display number of snapshots in volume info
    Backport of http://review.gluster.org/#/c/15029/
Display number of snapshots in a volume in volume info
output. This number gets modified, with create, delete,
and restore operations.
> Reviewed-on: http://review.gluster.org/15029
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
(cherry picked from commit 1df4a89de17e44c8c1f9b4794a7b8c2741f2bc2e)
Change-Id: Ic9b7c2b6950980f8ce75ca362998c097ea7c863d
BUG: 1369328
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: http://review.gluster.org/15288
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
| -rw-r--r-- | cli/src/cli-rpc-ops.c | 7 | ||||
| -rw-r--r-- | cli/src/cli-xml-output.c | 12 | ||||
| -rwxr-xr-x | tests/basic/volume-snapshot.t | 20 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 5 | 
4 files changed, 44 insertions, 0 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 00919d2c7a7..b8a19243159 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -780,6 +780,7 @@ gf_cli_get_volume_cbk (struct rpc_req *req, struct iovec *iov,          int32_t                    disperse_count       = 0;          int32_t                    redundancy_count     = 0;          int32_t                    arbiter_count        = 0; +        int32_t                    snap_count           = 0;          int32_t                    vol_type             = 0;          int32_t                    transport            = 0;          char                      *volume_id_str        = NULL; @@ -967,6 +968,11 @@ xml_output:                  if (ret)                          goto out; +                snprintf (key, 256, "volume%d.snap_count", i); +                ret = dict_get_int32 (dict, key, &snap_count); +                if (ret) +                        goto out; +                  vol_type = type;                  // Distributed (stripe/replicate/stripe-replica) setups @@ -978,6 +984,7 @@ xml_output:                  cli_out ("Type: %s", cli_vol_type_str[vol_type]);                  cli_out ("Volume ID: %s", volume_id_str);                  cli_out ("Status: %s", cli_vol_status_str[status]); +                cli_out ("Snapshot Count: %d", snap_count);  #ifdef HAVE_BD_XLATOR                  k = 0; diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 443449287ba..dbc8aa7b848 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -2551,6 +2551,7 @@ cli_xml_output_vol_info (cli_local_t *local, dict_t *dict)          int                     stripe_count = 0;          int                     replica_count = 0;          int                     arbiter_count = 0; +        int                     snap_count    = 0;          int                     isArbiter = 0;          int                     disperse_count = 0;          int                     redundancy_count = 0; @@ -2631,6 +2632,17 @@ cli_xml_output_vol_info (cli_local_t *local, dict_t *dict)                  XML_RET_CHECK_AND_GOTO (ret, out);                  memset (key, 0, sizeof (key)); +                snprintf (key, sizeof (key), "volume%d.snap_count", i); +                ret = dict_get_int32 (dict, key, &snap_count); +                if (ret) +                        goto out; +                ret = xmlTextWriterWriteFormatElement (local->writer, +                                                     (xmlChar *)"snapshotCount", +                                                     "%d", snap_count); +                XML_RET_CHECK_AND_GOTO (ret, out); + + +                memset (key, 0, sizeof (key));                  snprintf (key, sizeof (key), "volume%d.brick_count", i);                  ret = dict_get_int32 (dict, key, &brick_count);                  if (ret) diff --git a/tests/basic/volume-snapshot.t b/tests/basic/volume-snapshot.t index 794ab4944b0..dd938b4064a 100755 --- a/tests/basic/volume-snapshot.t +++ b/tests/basic/volume-snapshot.t @@ -104,6 +104,11 @@ create_snapshots  EXPECT 'Started' snapshot_status ${V0}_snap;  EXPECT 'Started' snapshot_status ${V1}_snap; +EXPECT '1' volinfo_field $V0 'Snapshot Count'; +EXPECT '1' volinfo_field $V1 'Snapshot Count'; +EXPECT "1" get-cmd-field-xml "volume info $V0" "snapshotCount" +EXPECT "1" get-cmd-field-xml "volume info $V1" "snapshotCount" +  deactivate_snapshots  EXPECT 'Stopped' snapshot_status ${V0}_snap; @@ -132,10 +137,20 @@ create_snapshots_with_timestamp;  new_name1=`$CLI_1 snapshot list ${V0} | grep ${V0}_snap1`;  new_name2=`$CLI_1 snapshot list ${V1} | grep ${V1}_snap1`; +EXPECT '2' volinfo_field $V0 'Snapshot Count'; +EXPECT '2' volinfo_field $V1 'Snapshot Count'; +EXPECT "2" get-cmd-field-xml "volume info $V0" "snapshotCount" +EXPECT "2" get-cmd-field-xml "volume info $V1" "snapshotCount" +  EXPECT_NOT "{V0}_snap1" echo $new_name1;  EXPECT_NOT "{V1}_snap1" echo $new_name1;  delete_snapshots $new_name1 $new_name2; +EXPECT '1' volinfo_field $V0 'Snapshot Count'; +EXPECT '1' volinfo_field $V1 'Snapshot Count'; +EXPECT "1" get-cmd-field-xml "volume info $V0" "snapshotCount" +EXPECT "1" get-cmd-field-xml "volume info $V1" "snapshotCount" +  #Clean up  stop_force_volumes 2  EXPECT 'Stopped' volinfo_field $V0 'Status'; @@ -145,6 +160,11 @@ restore_snapshots  TEST ! snapshot_exists 1 ${V0}_snap  TEST ! snapshot_exists 1 ${V1}_snap +EXPECT '0' volinfo_field $V0 'Snapshot Count'; +EXPECT '0' volinfo_field $V1 'Snapshot Count'; +EXPECT "0" get-cmd-field-xml "volume info $V0" "snapshotCount" +EXPECT "0" get-cmd-field-xml "volume info $V1" "snapshotCount" +  delete_volumes 2  EXPECT_WITHIN $CONFIG_UPDATE_TIMEOUT "N" volume_exists $V0  EXPECT_WITHIN $CONFIG_UPDATE_TIMEOUT "N" volume_exists $V1 diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 91ae6237c54..bf62290d023 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -558,6 +558,11 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,          if (ret)                  goto out; +        snprintf (key, 256, "volume%d.snap_count", count); +        ret = dict_set_int32 (volumes, key, volinfo->snap_count); +        if (ret) +                goto out; +  #ifdef HAVE_BD_XLATOR          if (volinfo->caps) {                  caps = 0;  | 
