]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr / volumes: use negative error codes everywhere
authorVenky Shankar <vshankar@redhat.com>
Fri, 5 Jul 2019 09:50:42 +0000 (05:50 -0400)
committerRamana Raja <rraja@redhat.com>
Wed, 17 Jul 2019 10:07:37 +0000 (15:37 +0530)
cephfs python binding returns positive error code. mgr/volumes
incorrectly does error code checks assuming the error codes to
be negative.

this was not an issue till now since mgr/volumes mostly does a
`raise VolumeException()` for the most part followed by the exception
being displayed to the operator (one exception is catching cephfs
ObjectNotFound error, in which case -errno.ENOENT is returned
(and checked whereever required)).

Signed-off-by: Venky Shankar <vshankar@redhat.com>
(cherry picked from commit dd569e22e8d1b6287207fb2d1a4269d0bef20784)

src/pybind/mgr/volumes/fs/subvolume.py

index 6a647b8c44478be86ab649b61ce7e698ae2caf7e..1c47e947716e77a64d85931cae7ca2bdf5892952 100644 (file)
@@ -54,7 +54,7 @@ class SubVolume(object):
             except cephfs.ObjectNotFound:
                 self.fs.mkdir(subpath, mode)
             except cephfs.Error as e:
-                raise VolumeException(e.args[0], e.args[1])
+                raise VolumeException(-e.args[0], e.args[1])
 
     def _get_single_dir_entry(self, dir_path, exclude=[]):
         """
@@ -147,7 +147,7 @@ class SubVolume(object):
                 raise VolumeException(
                     -errno.ENOENT, "Subvolume '{0}' not found, cannot remove it".format(spec.subvolume_id))
         except cephfs.Error as e:
-            raise VolumeException(e.args[0], e.args[1])
+            raise VolumeException(-e.args[0], e.args[1])
 
     def purge_subvolume(self, spec, should_cancel):
         """
@@ -161,7 +161,7 @@ class SubVolume(object):
             except cephfs.ObjectNotFound:
                 return
             except cephfs.Error as e:
-                raise VolumeException(e.args[0], e.args[1])
+                raise VolumeException(-e.args[0], e.args[1])
             d = self.fs.readdir(dir_handle)
             while d and not should_cancel():
                 d_name = d.d_name.decode('utf-8')
@@ -192,7 +192,7 @@ class SubVolume(object):
         except cephfs.ObjectNotFound:
             return None
         except cephfs.Error as e:
-            raise VolumeException(e.args[0], e.args[1])
+            raise VolumeException(-e.args[0], e.args[1])
         return path
 
     ### group operations
@@ -212,7 +212,7 @@ class SubVolume(object):
             if not force:
                 raise VolumeException(-errno.ENOENT, "Subvolume group '{0}' not found".format(spec.group_id))
         except cephfs.Error as e:
-            raise VolumeException(e.args[0], e.args[1])
+            raise VolumeException(-e.args[0], e.args[1])
 
     def get_group_path(self, spec):
         path = spec.group_path
@@ -246,7 +246,7 @@ class SubVolume(object):
         except cephfs.ObjectNotFound:
             self.fs.mkdir(snappath, mode)
         except cephfs.Error as e:
-            raise VolumeException(e.args[0], e.args[1])
+            raise VolumeException(-e.args[0], e.args[1])
         else:
             log.warn("Snapshot '{0}' already exists".format(snappath))
 
@@ -261,7 +261,7 @@ class SubVolume(object):
             if not force:
                 raise VolumeException(-errno.ENOENT, "Snapshot '{0}' not found, cannot remove it".format(snappath))
         except cephfs.Error as e:
-            raise VolumeException(e.args[0], e.args[1])
+            raise VolumeException(-e.args[0], e.args[1])
 
     def create_subvolume_snapshot(self, spec, snapname, mode=0o755):
         snappath = spec.make_subvol_snap_path(self.rados.conf_get('client_snapdir'), snapname)