]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: clean up file flags to file mode translation
authorSage Weil <sage@newdream.net>
Tue, 19 Jul 2011 18:25:46 +0000 (11:25 -0700)
committerSage Weil <sage@newdream.net>
Tue, 19 Jul 2011 18:25:46 +0000 (11:25 -0700)
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 <sage@newdream.net>
src/include/ceph_fs.cc

index 933488b70c4e2b4ab74f9507c780520535222f01..162e30b16b0cc3fff5ef152f0c99496363ea01cb 100644 (file)
@@ -4,6 +4,8 @@
  *
  */
 
+#include <errno.h>
+
 /*
  * 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;