]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: return error if we specified a wrong image name for rbd du 11854/head
authorDongsheng Yang <dongsheng.yang@easystack.cn>
Fri, 9 Sep 2016 08:53:25 +0000 (04:53 -0400)
committerLoic Dachary <ldachary@redhat.com>
Wed, 9 Nov 2016 12:23:11 +0000 (13:23 +0100)
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
(cherry picked from commit ce4c801cfc114f718ca51c32b657fec638ca9aaf)

src/tools/rbd/action/DiskUsage.cc

index 9ef2e7e93a4e41bc88c399494dcae6dc698988d2..3a38a052fb3d2eac107f8a6ddd5db9b639116c22 100644 (file)
@@ -110,12 +110,14 @@ static int do_disk_usage(librbd::RBD &rbd, librados::IoCtx &io_ctx,
   uint64_t used_size = 0;
   uint64_t total_prov = 0;
   uint64_t total_used = 0;
+  bool found = false;
   std::sort(names.begin(), names.end());
   for (std::vector<string>::const_iterator name = names.begin();
        name != names.end(); ++name) {
     if (imgname != NULL && *name != imgname) {
       continue;
     }
+    found = true;
 
     librbd::Image image;
     r = rbd.open_read_only(io_ctx, image, name->c_str(), NULL);
@@ -206,6 +208,10 @@ static int do_disk_usage(librbd::RBD &rbd, librados::IoCtx &io_ctx,
       ++count;
     }
   }
+  if (!found) {
+    std::cerr << "specified image " << imgname << " is not found." << std::endl;
+    return -ENOENT;
+  }
 
 out:
   if (f) {