diff --git a/src/tools/rbd/action/DiskUsage.cc b/src/tools/rbd/action/DiskUsage.cc index 9ef2e7e93a4e41..02e8f715b23f62 100644 --- a/src/tools/rbd/action/DiskUsage.cc +++ b/src/tools/rbd/action/DiskUsage.cc @@ -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::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 of " << imgname << "is not found." << std::endl; + return -EINVAL; + } out: if (f) {