]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-wnbd: consistently use negative error codes in rbd-wnbd 50656/head
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Thu, 23 Mar 2023 08:24:01 +0000 (08:24 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 24 Mar 2023 12:34:04 +0000 (12:34 +0000)
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 <lpetrut@cloudbasesolutions.com>
(cherry picked from commit 98a7aff741eb95bcc98df625d6558d726711a5fb)

src/tools/rbd_wnbd/rbd_wnbd.cc

index 0671844d10412b072fd5fbea23c581af970f0455..2e8f3ee0434bcc2bde0a203d6d033bedddb08b33 100644 (file)
@@ -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<const char*>& args,