Skip to content

Commit 4fe51a1

Browse files
committed
mds: prepare infra to replace CEPHFS_EXXX codes to system codes
Signed-off-by: Igor Golikov <[email protected]> Fixes: https://tracker.ceph.com/issues/64611
1 parent b1b2716 commit 4fe51a1

File tree

4 files changed

+25
-108
lines changed

4 files changed

+25
-108
lines changed

src/common/win32/errno.cc

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ __u32 ceph_to_hostos_errno_unsigned(__u32 r)
4747
case 9: return EBADF;
4848
case 10: return ECHILD;
4949
// same as EWOULDBLOCK
50+
// need to be careful of treating EWOULDBLOCK same way as EAGAIN
51+
// in errno.h (in Windows) the EWOULDBLOCK is set to 140, while EAGAIN is 11
52+
// In the cephfs client tests we changed assertions that expected EWOULDBLOCK to EAGAIN,
53+
// since MDS returns EAGAIN for all cases. EWOULBLOCK originally was used with socket context,
54+
// so semantically it makes sense to use EAGAIN for operations that indicate some possible waiting/retry
5055
case 11: return EAGAIN;
5156
case 12: return ENOMEM;
5257
case 13: return EACCES;
@@ -597,57 +602,4 @@ std::string win32_lasterror_str()
597602
{
598603
DWORD err = ::GetLastError();
599604
return win32_strerror(err);
600-
}
601-
602-
static const ceph::unordered_map<int,NTSTATUS> cephfs_errno_to_ntstatus = {
603-
{CEPHFS_EBLOCKLISTED, STATUS_SYSTEM_SHUTDOWN},
604-
{CEPHFS_EPERM, STATUS_ACCESS_DENIED},
605-
{CEPHFS_ESTALE, STATUS_INVALID_HANDLE},
606-
{CEPHFS_ENOSPC, STATUS_DISK_FULL},
607-
{CEPHFS_ETIMEDOUT, STATUS_TIMEOUT},
608-
{CEPHFS_EIO, STATUS_DATA_ERROR},
609-
{CEPHFS_ENOTCONN, STATUS_CONNECTION_DISCONNECTED},
610-
{CEPHFS_EEXIST, STATUS_OBJECT_NAME_COLLISION},
611-
{CEPHFS_EINTR, STATUS_RETRY},
612-
{CEPHFS_EINVAL, STATUS_INVALID_PARAMETER},
613-
{CEPHFS_EBADF, STATUS_INVALID_HANDLE},
614-
{CEPHFS_EROFS, STATUS_MEDIA_WRITE_PROTECTED},
615-
{CEPHFS_EAGAIN, STATUS_RETRY},
616-
{CEPHFS_EACCES, STATUS_ACCESS_DENIED},
617-
{CEPHFS_ELOOP, STATUS_TOO_MANY_LINKS},
618-
{CEPHFS_EISDIR, STATUS_FILE_IS_A_DIRECTORY},
619-
{CEPHFS_ENOENT, STATUS_OBJECT_NAME_NOT_FOUND},
620-
{CEPHFS_ENOTDIR, STATUS_NOT_A_DIRECTORY},
621-
{CEPHFS_ENAMETOOLONG, STATUS_NAME_TOO_LONG},
622-
{CEPHFS_EBUSY, STATUS_DEVICE_BUSY},
623-
{CEPHFS_EDQUOT, STATUS_QUOTA_EXCEEDED},
624-
{CEPHFS_EFBIG, STATUS_FILE_TOO_LARGE},
625-
{CEPHFS_ERANGE, STATUS_INVALID_PARAMETER},
626-
{CEPHFS_ENXIO, STATUS_NOT_FOUND},
627-
{CEPHFS_ECANCELED, STATUS_REQUEST_CANCELED},
628-
{CEPHFS_ENODATA, STATUS_NOT_FOUND},
629-
{CEPHFS_EOPNOTSUPP, STATUS_NOT_SUPPORTED},
630-
{CEPHFS_EXDEV, STATUS_NOT_SAME_DEVICE},
631-
{CEPHFS_ENOMEM, STATUS_NO_MEMORY},
632-
{CEPHFS_ENOTRECOVERABLE, STATUS_INTERNAL_ERROR},
633-
{CEPHFS_ENOSYS, STATUS_NOT_IMPLEMENTED},
634-
{CEPHFS_ENOTEMPTY, STATUS_DIRECTORY_NOT_EMPTY},
635-
{CEPHFS_EDEADLK, STATUS_POSSIBLE_DEADLOCK},
636-
{CEPHFS_EDOM, STATUS_INVALID_PARAMETER},
637-
{CEPHFS_EMLINK, STATUS_TOO_MANY_LINKS},
638-
{CEPHFS_ETIME, STATUS_TIMEOUT},
639-
{CEPHFS_EOLDSNAPC, STATUS_DATA_ERROR}
640-
};
641-
642-
__u32 cephfs_errno_to_ntstatus_map(int cephfs_errno)
643-
{
644-
cephfs_errno = abs(cephfs_errno);
645-
646-
if (cephfs_errno == 0)
647-
return 0;
648-
649-
auto it = cephfs_errno_to_ntstatus.find(cephfs_errno);
650-
if (it != cephfs_errno_to_ntstatus.end())
651-
return it->second;
652-
return STATUS_INTERNAL_ERROR;
653-
}
605+
}

src/include/fs_types.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,6 @@
1313

1414
class JSONObj;
1515

16-
#define CEPHFS_EBLOCKLISTED 108
17-
#define CEPHFS_EPERM 1
18-
#define CEPHFS_ESTALE 116
19-
#define CEPHFS_ENOSPC 28
20-
#define CEPHFS_ETIMEDOUT 110
21-
#define CEPHFS_EIO 5
22-
#define CEPHFS_ENOTCONN 107
23-
#define CEPHFS_EEXIST 17
24-
#define CEPHFS_EINTR 4
25-
#define CEPHFS_EINVAL 22
26-
#define CEPHFS_EBADF 9
27-
#define CEPHFS_EROFS 30
28-
#define CEPHFS_EAGAIN 11
29-
#define CEPHFS_EACCES 13
30-
#define CEPHFS_ELOOP 40
31-
#define CEPHFS_EISDIR 21
32-
#define CEPHFS_ENOENT 2
33-
#define CEPHFS_ENOTDIR 20
34-
#define CEPHFS_ENAMETOOLONG 36
35-
#define CEPHFS_EBUSY 16
36-
#define CEPHFS_EDQUOT 122
37-
#define CEPHFS_EFBIG 27
38-
#define CEPHFS_ERANGE 34
39-
#define CEPHFS_ENXIO 6
40-
#define CEPHFS_ECANCELED 125
41-
#define CEPHFS_ENODATA 61
42-
#define CEPHFS_EOPNOTSUPP 95
43-
#define CEPHFS_EXDEV 18
44-
#define CEPHFS_ENOMEM 12
45-
#define CEPHFS_ENOTRECOVERABLE 131
46-
#define CEPHFS_ENOSYS 38
47-
#define CEPHFS_EWOULDBLOCK CEPHFS_EAGAIN
48-
#define CEPHFS_ENOTEMPTY 39
49-
#define CEPHFS_EDEADLK 35
50-
#define CEPHFS_EDEADLOCK CEPHFS_EDEADLK
51-
#define CEPHFS_EDOM 33
52-
#define CEPHFS_EMLINK 31
53-
#define CEPHFS_ETIME 62
54-
#define CEPHFS_EOLDSNAPC 85
55-
#define CEPHFS_EFAULT 14
56-
#define CEPHFS_EISCONN 106
57-
#define CEPHFS_EMULTIHOP 72
58-
#define CEPHFS_EINPROGRESS 115
59-
6016
// taken from linux kernel: include/uapi/linux/fcntl.h
6117
#define CEPHFS_AT_FDCWD -100 /* Special value used to indicate
6218
openat should use the current

src/include/types.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,30 +561,40 @@ __s32 hostos_to_ceph_errno(__s32 e);
561561
#endif
562562

563563
struct errorcode32_t {
564-
int32_t code;
564+
using code_t = __s32;
565+
code_t code;
565566

566567
errorcode32_t() : code(0) {}
567568
// cppcheck-suppress noExplicitConstructor
568-
explicit errorcode32_t(int32_t i) : code(i) {}
569+
explicit errorcode32_t(code_t i) : code(i) {}
569570

570-
operator int() const { return code; }
571-
int* operator&() { return &code; }
572-
errorcode32_t& operator=(int32_t i) {
571+
operator code_t() const { return code; }
572+
code_t* operator&() { return &code; }
573+
errorcode32_t& operator=(code_t i) {
573574
code = i;
574575
return *this;
575576
}
576577
bool operator==(const errorcode32_t&) const = default;
577578
auto operator<=>(const errorcode32_t&) const = default;
578579

580+
inline code_t get_host_to_wire() const {
581+
return hostos_to_ceph_errno(code);
582+
}
583+
584+
inline void set_wire_to_host(code_t host_code) {
585+
code = ceph_to_hostos_errno(host_code);
586+
}
587+
579588
void encode(ceph::buffer::list &bl) const {
580589
using ceph::encode;
581-
__s32 newcode = hostos_to_ceph_errno(code);
582-
encode(newcode, bl);
590+
auto new_code = get_host_to_wire();
591+
encode(new_code, bl);
583592
}
584593
void decode(ceph::buffer::list::const_iterator &bl) {
585594
using ceph::decode;
586-
decode(code, bl);
587-
code = ceph_to_hostos_errno(code);
595+
code_t newcode;
596+
decode(newcode, bl);
597+
set_wire_to_host(newcode);
588598
}
589599
void dump(ceph::Formatter *f) const {
590600
f->dump_int("code", code);

src/include/win32/win32_errno.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ extern "C" {
137137

138138
__s32 wsae_to_errno(__s32 r);
139139
__u32 errno_to_ntstatus(__s32 r);
140-
__u32 cephfs_errno_to_ntstatus_map(int cephfs_errno);
141140

142141
#ifdef __cplusplus
143142
}

0 commit comments

Comments
 (0)