From 62e6f36a35c1c6b48afb4568e24b541921fb8dbc Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 19 Jul 2011 11:25:46 -0700 Subject: [PATCH] mds: clean up file flags to file mode translation There was some seriously wrong and ancient cruft in there. open(2) specifies that one of O_RDONLY, O_WRONLY, and O_RDWR must always be specified. Drop all the crazy. Linux VFS interprets O_WRONLY|O_RDWR as read+write, so we'll do the same. Signed-off-by: Sage Weil --- src/include/ceph_fs.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/include/ceph_fs.cc b/src/include/ceph_fs.cc index 933488b70c4e2..162e30b16b0cc 100644 --- a/src/include/ceph_fs.cc +++ b/src/include/ceph_fs.cc @@ -4,6 +4,8 @@ * */ +#include + /* * Some non-inline ceph helpers */ @@ -41,17 +43,19 @@ int ceph_flags_to_mode(int flags) if ((flags & O_DIRECTORY) == O_DIRECTORY) return CEPH_FILE_MODE_PIN; #endif - if ((flags & O_APPEND) && - (flags & O_ACCMODE) == 0) - flags |= O_WRONLY; - if ((flags & O_ACCMODE) == O_RDWR) - mode = CEPH_FILE_MODE_RDWR; - else if ((flags & O_ACCMODE) == O_WRONLY) + switch (flags & O_ACCMODE) { + case O_WRONLY: mode = CEPH_FILE_MODE_WR; - else + break; + case O_RDONLY: mode = CEPH_FILE_MODE_RD; - + break; + case O_RDWR: + case O_ACCMODE: /* this is what the VFS does */ + mode = CEPH_FILE_MODE_RDWR; + break; + } #ifdef O_LAZY if (flags & O_LAZY) mode |= CEPH_FILE_MODE_LAZY; -- 2.39.5