From 0bc0d9f97fa6f57cd3322acadfe8c9e70167ab39 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 23 Mar 2023 08:24:01 +0000 Subject: [PATCH] rbd-wnbd: consistently use negative error codes in rbd-wnbd The rbd-wnbd iterators return positive errors, which is why in certain cases we may end up with both positive and negative error codes. This change ensures that we'll consistently use negative error codes. Signed-off-by: Lucian Petrut (cherry picked from commit 98a7aff741eb95bcc98df625d6558d726711a5fb) --- src/tools/rbd_wnbd/rbd_wnbd.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tools/rbd_wnbd/rbd_wnbd.cc b/src/tools/rbd_wnbd/rbd_wnbd.cc index 0671844d104..2e8f3ee0434 100644 --- a/src/tools/rbd_wnbd/rbd_wnbd.cc +++ b/src/tools/rbd_wnbd/rbd_wnbd.cc @@ -129,10 +129,10 @@ WNBDActiveDiskIterator::WNBDActiveDiskIterator() // no error break; case ERROR_OPEN_FAILED: - error = ENOENT; + error = -ENOENT; break; default: - error = EINVAL; + error = -EINVAL; break; } } @@ -185,14 +185,14 @@ RegistryDiskIterator::RegistryDiskIterator() SERVICE_REG_KEY, false); if (!reg_key->hKey) { if (!reg_key->missingKey) - error = EINVAL; + error = -EINVAL; return; } if (RegQueryInfoKey(reg_key->hKey, NULL, NULL, NULL, &subkey_count, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) { derr << "Could not query registry key: " << SERVICE_REG_KEY << dendl; - error = EINVAL; + error = -EINVAL; return; } } @@ -215,12 +215,12 @@ bool RegistryDiskIterator::get(Config *cfg) return false; } else if (err) { derr << "Could not enumerate registry. Error: " << err << dendl; - error = EINVAL; + error = -EINVAL; return false; } if (load_mapping_config_from_registry(subkey_name, cfg)) { - error = EINVAL; + error = -EINVAL; return false; }; @@ -722,7 +722,7 @@ int disconnect_all_mappings( pool.join(); r = iterator.get_error(); - if (r == ENOENT) { + if (r == -ENOENT) { dout(0) << __func__ << ": wnbd adapter unavailable, " << "assuming that no wnbd mappings exist." << dendl; err = 0; @@ -1471,7 +1471,7 @@ static int do_list_mapped_devices(const std::string &format, bool pretty_format) int error = wnbd_disk_iterator.get_error(); if (error) { derr << "Could not get disk list: " << error << dendl; - return -error; + return error; } if (f) { @@ -1565,11 +1565,11 @@ static int do_stats(std::string search_devpath) } int error = wnbd_disk_iterator.get_error(); if (!error) { - error = ENOENT; + error = -ENOENT; } derr << "Could not find the specified disk." << dendl; - return -error; + return error; } static int parse_args(std::vector& args, -- 2.39.5