diff options
author | Josh Durgin <josh.durgin@inktank.com> | 2012-12-10 22:34:05 -0800 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-12-13 17:43:23 -0800 |
commit | 8cf367cb79046b08cc593b14f77526eef2758ee6 (patch) | |
tree | 8d36b6ac673b9594c1de94b1cf3d22fbc7e665e8 | |
parent | c9894ff0e5782e43d5efa457d5bff5a9b2312274 (diff) | |
download | ceph-8cf367cb79046b08cc593b14f77526eef2758ee6.tar.gz |
rbd.py: check for new librbd methods before use
This way attempting to use format 2 images works when you upgrade the
python bindings before librbd, and attempting to use functions
that librbd does not have results in more understandable errors.
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r-- | src/pybind/rbd.py | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/pybind/rbd.py b/src/pybind/rbd.py index da5bc69f229..81ebb57f73e 100644 --- a/src/pybind/rbd.py +++ b/src/pybind/rbd.py @@ -155,22 +155,41 @@ class RBD(object): :param stripe_count: objects to stripe over before looping :type stripe_count: int :raises: :class:`ImageExists` + :raises: :class:`TypeError` + :raises: :class:`InvalidArgument` + :raises: :class:`FunctionNotSupported` """ if order is None: order = 0 if not isinstance(name, str): raise TypeError('name must be a string') if old_format: + if features != 0 or stripe_unit != 0 or stripe_count != 0: + raise InvalidArgument('format 1 images do not support feature' + ' masks or non-default striping') ret = self.librbd.rbd_create(ioctx.io, c_char_p(name), c_uint64(size), byref(c_int(order))) else: - ret = self.librbd.rbd_create3(ioctx.io, c_char_p(name), - c_uint64(size), - c_uint64(features), - byref(c_int(order)), - c_uint64(stripe_unit), - c_uint64(stripe_count)) + if not hasattr(self.librbd, 'rbd_create2'): + raise FunctionNotSupported('installed version of librbd does' + ' not support format 2 images') + has_create3 = hasattr(self.librbd, 'rbd_create3') + if (stripe_unit != 0 or stripe_count != 0) and not has_create3: + raise FunctionNotSupported('installed version of librbd does' + ' not support stripe unit or count') + if has_create3: + ret = self.librbd.rbd_create3(ioctx.io, c_char_p(name), + c_uint64(size), + c_uint64(features), + byref(c_int(order)), + c_uint64(stripe_unit), + c_uint64(stripe_count)) + else: + ret = self.librbd.rbd_create2(ioctx.io, c_char_p(name), + c_uint64(size), + c_uint64(features), + byref(c_int(order))) if ret < 0: raise make_ex(ret, 'error creating image') |