]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: return image id in info command output 20935/head
authorMykola Golub <mgolub@suse.com>
Thu, 15 Mar 2018 16:40:59 +0000 (18:40 +0200)
committerMykola Golub <mgolub@suse.com>
Sun, 18 Mar 2018 04:37:19 +0000 (06:37 +0200)
And as a side effect, previously when rbd info was called
with --image-id, the image id was shown instead of the image name,
so the user was not able to see the image name from info output.
Now it will show the image name.

Signed-off-by: Mykola Golub <mgolub@suse.com>
qa/workunits/rbd/cli_generic.sh
src/test/cli-integration/rbd/formatted-output.t
src/tools/rbd/action/Info.cc

index 3a4bdb39ebbd769476f85ba33d4de9e578e50b81..edda28ec114cbc206e3206a18b7a14cb020bbe05 100755 (executable)
@@ -419,7 +419,7 @@ test_trash() {
 
     rbd trash mv test2
     ID=`rbd trash ls | cut -d ' ' -f 1`
-    rbd info --image-id $ID | grep "rbd image '$ID'"
+    rbd info --image-id $ID | grep "rbd image 'test2'"
 
     rbd trash restore $ID
     rbd ls | grep test2
index eae9d4ea01fb8ac26f07412df660ca334327a0d8..2e73dcd7a6c2dbe10e45c21eeb55bd1e3a7f604d 100644 (file)
@@ -64,6 +64,7 @@ For now, use a more inclusive regex.
   {
       "block_name_prefix": "rb.0.*",  (glob)
       "format": 1, 
+      "id": "", 
       "name": "foo", 
       "object_size": 4194304, 
       "objects": 256, 
@@ -75,6 +76,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info foo --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>foo</name>
+    <id></id>
     <size>1073741824</size>
     <objects>256</objects>
     <order>22</order>
@@ -93,6 +95,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   {
       "block_name_prefix": "rb.0.*",  (glob)
       "format": 1, 
+      "id": "", 
       "name": "foo", 
       "object_size": 4194304, 
       "objects": 256, 
@@ -103,6 +106,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info foo@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>foo</name>
+    <id></id>
     <size>1073741824</size>
     <objects>256</objects>
     <order>22</order>
@@ -115,6 +119,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'bar':
   \tsize 1024 MB in 256 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff, deep-flatten (esc)
@@ -134,6 +139,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "bar", 
       "object_size": 4194304, 
       "objects": 256, 
@@ -144,6 +150,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info bar --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>bar</name>
+    <id>*</id> (glob)
     <size>1073741824</size>
     <objects>256</objects>
     <order>22</order>
@@ -165,6 +172,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'bar':
   \tsize 512 MB in 128 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff, deep-flatten (esc)
@@ -185,6 +193,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "bar", 
       "object_size": 4194304, 
       "objects": 128, 
@@ -196,6 +205,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info bar@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>bar</name>
+    <id>*</id> (glob)
     <size>536870912</size>
     <objects>128</objects>
     <order>22</order>
@@ -218,6 +228,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'bar':
   \tsize 1024 MB in 256 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff, deep-flatten (esc)
@@ -238,6 +249,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "bar", 
       "object_size": 4194304, 
       "objects": 256, 
@@ -249,6 +261,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info bar@snap2 --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>bar</name>
+    <id>*</id> (glob)
     <size>1073741824</size>
     <objects>256</objects>
     <order>22</order>
@@ -271,6 +284,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'baz':
   \tsize 2048 MB in 512 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering (esc)
@@ -286,6 +300,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "baz", 
       "object_size": 4194304, 
       "objects": 512, 
@@ -296,6 +311,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info baz --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>baz</name>
+    <id>*</id> (glob)
     <size>2147483648</size>
     <objects>512</objects>
     <order>22</order>
@@ -319,6 +335,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   {
       "block_name_prefix": "rb.0.*",  (glob)
       "format": 1, 
+      "id": "", 
       "name": "quux", 
       "object_size": 4194304, 
       "objects": 1, 
@@ -328,6 +345,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info quux --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>quux</name>
+    <id></id>
     <size>1048576</size>
     <objects>1</objects>
     <order>22</order>
@@ -339,6 +357,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'child':
   \tsize 512 MB in 128 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff (esc)
@@ -357,6 +376,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "child", 
       "object_size": 4194304, 
       "objects": 128, 
@@ -367,6 +387,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info rbd_other/child --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>child</name>
+    <id>*</id> (glob)
     <size>536870912</size>
     <objects>128</objects>
     <order>22</order>
@@ -387,6 +408,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'child':
   \tsize 512 MB in 128 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff (esc)
@@ -408,6 +430,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "child", 
       "object_size": 4194304, 
       "objects": 128, 
@@ -425,6 +448,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info rbd_other/child@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>child</name>
+    <id>*</id> (glob)
     <size>536870912</size>
     <objects>128</objects>
     <order>22</order>
@@ -452,6 +476,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'deep-flatten-child':
   \tsize 512 MB in 128 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff, deep-flatten (esc)
@@ -471,6 +496,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "deep-flatten-child", 
       "object_size": 4194304, 
       "objects": 128, 
@@ -481,6 +507,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info rbd_other/deep-flatten-child --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>deep-flatten-child</name>
+    <id>*</id> (glob)
     <size>536870912</size>
     <objects>128</objects>
     <order>22</order>
@@ -502,6 +529,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   rbd image 'deep-flatten-child':
   \tsize 512 MB in 128 objects (esc)
   \torder 22 (4096 kB objects) (esc)
+  \tid:* (glob)
   [^^]+ (re)
   \tformat: 2 (esc)
   \tfeatures: layering, exclusive-lock, object-map, fast-diff, deep-flatten (esc)
@@ -522,6 +550,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
       ], 
       "flags": [], 
       "format": 2, 
+      "id": "*",  (glob)
       "name": "deep-flatten-child", 
       "object_size": 4194304, 
       "objects": 128, 
@@ -533,6 +562,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
   $ rbd info rbd_other/deep-flatten-child@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
   <image>
     <name>deep-flatten-child</name>
+    <id>*</id> (glob)
     <size>536870912</size>
     <objects>128</objects>
     <order>22</order>
index 5a4f4c392aaf9551444c6b6e11fe1016b9820796..6927a303b0563f45dfe0505351857536858b41fc 100644 (file)
@@ -75,7 +75,6 @@ static void format_flags(Formatter *f, uint64_t flags)
 }
 
 static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image,
-                        const std::string &imgname, const std::string &imgid,
                         const std::string &snapname, Formatter *f)
 {
   librbd::image_info_t info;
@@ -85,6 +84,11 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image,
   librbd::mirror_image_info_t mirror_image;
   int r;
 
+  std::string imgname;
+  r = image.get_name(&imgname);
+  if (r < 0)
+    return r;
+
   r = image.stat(info, sizeof(info));
   if (r < 0)
     return r;
@@ -93,6 +97,13 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image,
   if (r < 0)
     return r;
 
+  std::string imgid;
+  if (!old_format) {
+    r = image.get_id(&imgid);
+    if (r < 0)
+      return r;
+  }
+
   std::string data_pool;
   if (!old_format) {
     int64_t data_pool_id = image.get_data_pool_id();
@@ -180,11 +191,8 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image,
 
   if (f) {
     f->open_object_section("image");
-    if (!imgname.empty()) {
-      f->dump_string("name", imgname);
-    } else {
-      f->dump_string("id", imgid);
-    }
+    f->dump_string("name", imgname);
+    f->dump_string("id", imgid);
     f->dump_unsigned("size", info.size);
     f->dump_unsigned("objects", info.num_objs);
     f->dump_int("order", info.order);
@@ -195,13 +203,16 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image,
     f->dump_string("block_name_prefix", prefix);
     f->dump_int("format", (old_format ? 1 : 2));
   } else {
-    std::cout << "rbd image '" << (imgname.empty() ? imgid : imgname) << "':\n"
+    std::cout << "rbd image '" << imgname << "':\n"
               << "\tsize " << prettybyte_t(info.size) << " in "
               << info.num_objs << " objects"
               << std::endl
               << "\torder " << info.order
               << " (" << prettybyte_t(info.obj_size) << " objects)"
               << std::endl;
+    if (!imgid.empty()) {
+      std::cout << "\tid: " << imgid << std::endl;
+    }
     if (!data_pool.empty()) {
       std::cout << "\tdata_pool: " << data_pool << std::endl;
     }
@@ -396,8 +407,7 @@ int execute(const po::variables_map &vm,
     return r;
   }
 
-  r = do_show_info(io_ctx, image, image_name, image_id, snap_name,
-                   formatter.get());
+  r = do_show_info(io_ctx, image, snap_name, formatter.get());
   if (r < 0) {
     std::cerr << "rbd: info: " << cpp_strerror(r) << std::endl;
     return r;