Skip to content

Commit f3d5db4

Browse files
Merge pull request ceph#65135 from rishabh-d-dave/libcephfs-platform-errno
libcephfs: convert ceph errno to host-based errno Reviewed-by: Patrick Donnelly <[email protected]>
2 parents b69aef5 + 2439bcb commit f3d5db4

File tree

5 files changed

+82
-55
lines changed

5 files changed

+82
-55
lines changed

qa/workunits/libcephfs/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -e
1+
#!/bin/sh -ex
22

33
ceph_test_libcephfs
44
ceph_test_libcephfs_access

src/include/platform_errno.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
3+
/*
4+
* Ceph - scalable distributed file system
5+
*
6+
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
7+
*
8+
* This is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License version 2.1, as published by the Free Software
11+
* Foundation. See file COPYING.
12+
*
13+
*/
14+
15+
/* XXX: This definitions are placed here so that it's easy to import them into
16+
* CephFS python bindings. Otherwise, entire src/include/types.h would needed to
17+
* be imported, which is unneccessary and also complicated.
18+
*/
19+
20+
#pragma once
21+
22+
#if defined(__sun) || defined(_AIX) || defined(__APPLE__) || \
23+
defined(__FreeBSD__) || defined(_WIN32)
24+
extern "C" {
25+
__s32 ceph_to_hostos_errno(__s32 e);
26+
__s32 hostos_to_ceph_errno(__s32 e);
27+
}
28+
#else
29+
#define ceph_to_hostos_errno(e) (e)
30+
#define hostos_to_ceph_errno(e) (e)
31+
#endif
32+
33+

src/include/types.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// this is needed for ceph_fs to compile in userland
1818
#include "int_types.h"
1919
#include "byteorder.h"
20+
#include "platform_errno.h"
2021

2122
#include "uuid.h"
2223

@@ -518,17 +519,6 @@ struct shard_id_t {
518519
WRITE_CLASS_ENCODER(shard_id_t)
519520
std::ostream &operator<<(std::ostream &lhs, const shard_id_t &rhs);
520521

521-
#if defined(__sun) || defined(_AIX) || defined(__APPLE__) || \
522-
defined(__FreeBSD__) || defined(_WIN32)
523-
extern "C" {
524-
__s32 ceph_to_hostos_errno(__s32 e);
525-
__s32 hostos_to_ceph_errno(__s32 e);
526-
}
527-
#else
528-
#define ceph_to_hostos_errno(e) (e)
529-
#define hostos_to_ceph_errno(e) (e)
530-
#endif
531-
532522
struct errorcode32_t {
533523
using code_t = __s32;
534524
code_t code;

src/pybind/cephfs/cephfs.pyx

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,47 +68,47 @@ CEPH_SETATTR_BTIME = 0x200
6868

6969
CEPH_NOSNAP = -2
7070

71-
# errno definitions
72-
cdef enum:
73-
EBLOCKLISTED = 108
74-
EPERM = 1
75-
ESTALE = 116
76-
ENOSPC = 28
77-
ETIMEDOUT = 110
78-
EIO = 5
79-
ENOTCONN = 107
80-
EEXIST = 17
81-
EINTR = 4
82-
EINVAL = 22
83-
EBADF = 9
84-
EROFS = 30
85-
EAGAIN = 11
86-
EACCES = 13
87-
ELOOP = 40
88-
EISDIR = 21
89-
ENOENT = 2
90-
ENOTDIR = 20
91-
ENAMETOOLONG = 36
92-
EBUSY = 16
93-
EDQUOT = 122
94-
EFBIG = 27
95-
ERANGE = 34
96-
ENXIO = 6
97-
ECANCELED = 125
98-
ENODATA = 61
99-
EOPNOTSUPP = 95
100-
EXDEV = 18
101-
ENOMEM = 12
102-
ENOTRECOVERABLE = 131
103-
ENOSYS = 38
104-
EWOULDBLOCK = EAGAIN
105-
ENOTEMPTY = 39
106-
EDEADLK = 35
107-
EDEADLOCK = EDEADLK
108-
EDOM = 33
109-
EMLINK = 31
110-
ETIME = 62
111-
EOLDSNAPC = 85
71+
# XXX: errno definitions, hard-coded numbers here are errnos defined by Linux
72+
# that are used for the Ceph on-the-wire status codes.
73+
EBLOCKLISTED = ceph_to_hostos_errno(108)
74+
EPERM = ceph_to_hostos_errno(1)
75+
ESTALE = ceph_to_hostos_errno(116)
76+
ENOSPC = ceph_to_hostos_errno(28)
77+
ETIMEDOUT = ceph_to_hostos_errno(110)
78+
EIO = ceph_to_hostos_errno(5)
79+
ENOTCONN = ceph_to_hostos_errno(107)
80+
EEXIST = ceph_to_hostos_errno(17)
81+
EINTR = ceph_to_hostos_errno(4)
82+
EINVAL = ceph_to_hostos_errno(22)
83+
EBADF = ceph_to_hostos_errno(9)
84+
EROFS = ceph_to_hostos_errno(30)
85+
EAGAIN = ceph_to_hostos_errno(11)
86+
EWOULDBLOCK = EAGAIN
87+
EACCES = ceph_to_hostos_errno(13)
88+
ELOOP = ceph_to_hostos_errno(40)
89+
EISDIR = ceph_to_hostos_errno(21)
90+
ENOENT = ceph_to_hostos_errno(2)
91+
ENOTDIR = ceph_to_hostos_errno(20)
92+
ENAMETOOLONG = ceph_to_hostos_errno(36)
93+
EBUSY = ceph_to_hostos_errno(16)
94+
EDQUOT = ceph_to_hostos_errno(122)
95+
EFBIG = ceph_to_hostos_errno(27)
96+
ERANGE = ceph_to_hostos_errno(34)
97+
ENXIO = ceph_to_hostos_errno(6)
98+
ECANCELED = ceph_to_hostos_errno(125)
99+
ENODATA = ceph_to_hostos_errno(61)
100+
EOPNOTSUPP = ceph_to_hostos_errno(95)
101+
EXDEV = ceph_to_hostos_errno(18)
102+
ENOMEM = ceph_to_hostos_errno(12)
103+
ENOTRECOVERABLE = ceph_to_hostos_errno(131)
104+
ENOSYS = ceph_to_hostos_errno(38)
105+
ENOTEMPTY = ceph_to_hostos_errno(39)
106+
EDEADLK = ceph_to_hostos_errno(35)
107+
EDEADLOCK = EDEADLK
108+
EDOM = ceph_to_hostos_errno(33)
109+
EMLINK = ceph_to_hostos_errno(31)
110+
ETIME = ceph_to_hostos_errno(62)
111+
EOLDSNAPC = ceph_to_hostos_errno(85)
112112

113113
cdef extern from "Python.h":
114114
# These are in cpython/string.pxd, but use "object" types instead of
@@ -529,7 +529,7 @@ cdef class LibCephFS(object):
529529
with nogil:
530530
ret = ceph_create_from_rados(&self.cluster, rados_inst.cluster)
531531
if ret != 0:
532-
raise Error("libcephfs_initialize failed with error code: %d" % ret)
532+
raise Error(f"libcephfs_initialize failed with error code: {ret}")
533533
self.state = "configuring"
534534

535535
NO_CONF_FILE = -1
@@ -558,7 +558,7 @@ cdef class LibCephFS(object):
558558
with nogil:
559559
ret = ceph_create(&self.cluster, <const char*>_auth_id)
560560
if ret != 0:
561-
raise Error("libcephfs_initialize failed with error code: %d" % ret)
561+
raise Error(f"libcephfs_initialize failed with error code: {ret}")
562562

563563
self.state = "configuring"
564564
if conffile in (self.NO_CONF_FILE, None):

src/pybind/cephfs/types.pxd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ ELSE:
5555
unsigned short int d_reclen
5656
unsigned char d_type
5757
char d_name[256]
58+
59+
cdef extern from "../../include/platform_errno.h":
60+
ctypedef signed int int32_t;
61+
int32_t ceph_to_hostos_errno(int32_t e)

0 commit comments

Comments
 (0)