From 2c25c99cb4572ffae97555a56b24a4c4097dcdec Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 10 May 2017 08:13:52 +0800 Subject: [PATCH 1/2] pybind: fix open flags calculation (O_WRONLY | O_RDWR) is invaild open flags Fixes: http://tracker.ceph.com/issues/19890 Signed-off-by: "Yan, Zheng" --- src/pybind/cephfs/cephfs.pyx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 94df1b21a99..e7b4ec1e97e 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -659,16 +659,26 @@ cdef class LibCephFS(object): if flags == '': cephfs_flags = os.O_RDONLY else: + access_flags = 0; for c in flags: if c == 'r': - cephfs_flags |= os.O_RDONLY + access_flags = 1; elif c == 'w': - cephfs_flags |= os.O_WRONLY | os.O_TRUNC | os.O_CREAT - elif c == '+': - cephfs_flags |= os.O_RDWR + access_flags = 2; + cephfs_flags |= os.O_TRUNC | os.O_CREAT + elif access_flags > 0 and c == '+': + access_flags = 3; else: raise OperationNotSupported( "open flags doesn't support %s" % c) + + if access_flags == 1: + cephfs_flags |= os.O_RDONLY; + elif access_flags == 2: + cephfs_flags |= os.O_WRONLY; + else: + cephfs_flags |= os.O_RDWR; + elif isinstance(flags, int): cephfs_flags = flags else: From e6493f64ba4592b8dca54ece4464efa6c7f331a7 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Fri, 12 May 2017 10:38:51 +0800 Subject: [PATCH 2/2] pybind: fix cephfs.OSError initialization Traceback (most recent call last): File "", line 1, in File "cephfs.pyx", line 672, in cephfs.LibCephFS.open (/home/zhyan/Ceph/ceph-2/build/src/pybind/cephfs/pyrex/cephfs.c:10160) File "cephfs.pyx", line 155, in cephfs.OSError.__init__ (/home/zhyan/Ceph/ceph-2/build/src/pybind/cephfs/pyrex/cephfs.c:1889) TypeError: __init__() takes exactly 3 positional arguments (2 given) Signed-off-by: "Yan, Zheng" --- src/pybind/cephfs/cephfs.pyx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index e7b4ec1e97e..806e0ab4c37 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -356,7 +356,8 @@ cdef class LibCephFS(object): self.state = "uninitialized" if rados_inst is not None: if auth_id is not None or conffile is not None or conf is not None: - raise InvalidValue("May not pass RADOS instance as well as other configuration") + raise make_ex(errno.EINVAL, + "May not pass RADOS instance as well as other configuration") self.create_with_rados(rados_inst) else: @@ -669,8 +670,8 @@ cdef class LibCephFS(object): elif access_flags > 0 and c == '+': access_flags = 3; else: - raise OperationNotSupported( - "open flags doesn't support %s" % c) + raise make_ex(errno.EOPNOTSUPP, + "open flags doesn't support %s" % c) if access_flags == 1: cephfs_flags |= os.O_RDONLY;