From c66b61f9dcad217429e4876d27881d9fb2e7666f Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Tue, 31 Dec 2013 17:00:06 -0800 Subject: [PATCH] rbd: return 0 and an empty list when pool is entirely empty rbd_list will return -ENOENT when no rbd_directory object exists. Handle this in the cli tool and interpret it as success with an empty list. Add this to the release notes since it changes command line behavior. Fixes: #6693 Signed-off-by: Josh Durgin (cherry picked from commit ac547a5b7dc94282f079aef78e66348d99d9d5e9) Conflicts: PendingReleaseNotes src/rbd.cc --- PendingReleaseNotes | 48 ++++--------------- src/rbd.cc | 13 ++--- .../cli-integration/rbd/formatted-output.t | 9 ++++ 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/PendingReleaseNotes b/PendingReleaseNotes index b1c141492f60d..6f462c81f5070 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -1,40 +1,8 @@ -v0.67 -~~~~~ - -* The output of 'ceph status --format=json' or 'ceph -s --format=json' - has changed to return status information in a more structured and - usable format. - -* The 'ceph pg dump_stuck [threshold]' command used to require a - --threshold or -t prefix to the threshold argument, but now does - not. - -* Many more ceph commands now output formatted information; select - with '--format=', where can be 'json', 'json-pretty', - 'xml', or 'xml-pretty'. - -* ceph-rest-api, a wrapper around ceph_rest_api.py, can be used to start - up a test single-threaded HTTP server that provides access to cluster - information and administration in very similar ways to the ceph - commandline tool. ceph_rest_api.py can be used as a WSGI application - for deployment in a more-capable web server. See ceph-rest-api.8 - for more. - -* rgw copy object operation may return extra progress info during the - operation. At this point it will only happen when doing cross zone - copy operations. The S3 response will now return extra - field under the container. The Swift response will - now send the progress as a json array. - -* ceph-osd now requires a max fd limit of at least - filestore_wbthrottle_(xfs|btrfs)_inodes_hard_limit (5000 by default) - in order to accomodate the new write back throttle system. upstart - now sets the fd limit to 32k. sysvinit will set it to 32k by default - (still overrideable via max_open_files). - -* The 'ceph pg ...' commands (like 'ceph pg query') are - deprecated in favor of 'ceph tell ...'. This makes the - distinction between 'ceph pg ' and 'ceph pg - ' less awkward by making it clearer that the 'tell' - commands are talking to the OSD serving the placement group, not the - monitor. +v0.67.8 +======= + +- 'rbd ls' on a pool which never held rbd images now exits with code + 0. It outputs nothing in plain format, or an empty list in + non-plain format. This is consistent with the behavior for a pool + which used to hold images, but contains none. Scripts relying on + this behavior should be updated. diff --git a/src/rbd.cc b/src/rbd.cc index 6041ddeff1b70..15b85e100e00f 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -245,6 +245,8 @@ static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool lflag, { std::vector names; int r = rbd.list(io_ctx, names); + if (r == -ENOENT) + r = 0; if (r < 0) return r; @@ -2555,15 +2557,8 @@ if (!set_conf_param(v, p1, p2, p3)) { \ case OPT_LIST: r = do_list(rbd, io_ctx, lflag, formatter.get()); if (r < 0) { - switch (r) { - case -ENOENT: - cerr << "rbd: pool " << poolname << " doesn't contain rbd images" - << std::endl; - break; - default: - cerr << "rbd: list: " << cpp_strerror(-r) << std::endl; - } - return EXIT_FAILURE; + cerr << "rbd: list: " << cpp_strerror(-r) << std::endl; + return -r; } break; diff --git a/src/test/cli-integration/rbd/formatted-output.t b/src/test/cli-integration/rbd/formatted-output.t index bece14f11f161..99577c3a0e1ec 100644 --- a/src/test/cli-integration/rbd/formatted-output.t +++ b/src/test/cli-integration/rbd/formatted-output.t @@ -1,3 +1,12 @@ +ls on empty pool never containing images +======================================== + $ rados -p rbd rm rbd_directory || true + $ rbd ls + $ rbd ls --format json + [] (no-eol) + $ rbd ls --format xml + (no-eol) + create ======= $ rbd create -s 1024 foo -- 2.39.5