]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
consolidate and clean up FILE_CAPS
authorSage Weil <sage@newdream.net>
Thu, 17 Apr 2008 21:01:13 +0000 (14:01 -0700)
committerSage Weil <sage@newdream.net>
Thu, 17 Apr 2008 22:18:47 +0000 (15:18 -0700)
src/client/Client.cc
src/client/Client.h
src/include/ceph_fs.h
src/include/types.h
src/kernel/file.c
src/kernel/inode.c
src/kernel/super.c
src/kernel/super.h
src/mds/Locker.cc
src/mds/Server.cc
src/messages/MClientRequest.h

index 8cf6df0a6717becff5152fde88f2039f782274c7..62660e1da2f010450b2619c50a36f6984e63d4ba 100644 (file)
@@ -2753,7 +2753,7 @@ int Client::_open(const char *path, int flags, mode_t mode, Fh **fhp)
   req->head.args.open.flags = flags;
   req->head.args.open.mode = mode;
 
-  int cmode = file_flags_to_mode(flags);
+  int cmode = ceph_flags_to_mode(flags);
 
   // FIXME where does FUSE maintain user information
   req->set_caller_uid(getuid());
@@ -3047,7 +3047,7 @@ int Client::_read(Fh *f, off_t offset, off_t size, bufferlist *bl)
     movepos = true;
   }
 
-  bool lazy = f->mode == FILE_MODE_LAZY;
+  bool lazy = f->mode == CEPH_FILE_MODE_LAZY;
 
   // wait for RD cap and/or a valid file size
   while (1) {
@@ -3206,7 +3206,7 @@ int Client::_write(Fh *f, off_t offset, off_t size, const char *buf)
     unlock_fh_pos(f);
   }
 
-  bool lazy = f->mode == FILE_MODE_LAZY;
+  bool lazy = f->mode == CEPH_FILE_MODE_LAZY;
 
   dout(10) << "cur file size is " << in->inode.size << dendl;
 
@@ -3530,7 +3530,7 @@ int Client::lazyio_propogate(int fd, off_t offset, size_t count)
   Fh *f = fd_map[fd];
   Inode *in = f->inode;
 
-  if (f->mode & FILE_MODE_LAZY) {
+  if (f->mode & CEPH_FILE_MODE_LAZY) {
     // wait for lazy cap
     while ((in->file_caps() & CEPH_CAP_LAZYIO) == 0) {
       dout(7) << " don't have lazy cap, waiting" << dendl;
@@ -3566,7 +3566,7 @@ int Client::lazyio_synchronize(int fd, off_t offset, size_t count)
   Fh *f = fd_map[fd];
   Inode *in = f->inode;
   
-  if (f->mode & FILE_MODE_LAZY) {
+  if (f->mode & CEPH_FILE_MODE_LAZY) {
     // wait for lazy cap
     while ((in->file_caps() & CEPH_CAP_LAZYIO) == 0) {
       dout(7) << " don't have lazy cap, waiting" << dendl;
index 960d4ce5983a6faa06a3a5c2f1cab7ba48db9c59..0d08c0135ee1cebc2706a653e9becdaf788b4f79 100644 (file)
@@ -262,14 +262,14 @@ class Inode {
   }
 
   void add_open(int cmode) {
-    if (cmode & FILE_MODE_R) num_open_rd++;
-    if (cmode & FILE_MODE_W) num_open_wr++;
-    if (cmode & FILE_MODE_LAZY) num_open_lazy++;
+    if (cmode & CEPH_FILE_MODE_RD) num_open_rd++;
+    if (cmode & CEPH_FILE_MODE_WR) num_open_wr++;
+    if (cmode & CEPH_FILE_MODE_LAZY) num_open_lazy++;
   }
   void sub_open(int cmode) {
-    if (cmode & FILE_MODE_R) num_open_rd--;
-    if (cmode & FILE_MODE_W) num_open_wr--;
-    if (cmode & FILE_MODE_LAZY) num_open_lazy--;
+    if (cmode & CEPH_FILE_MODE_RD) num_open_rd--;
+    if (cmode & CEPH_FILE_MODE_WR) num_open_wr--;
+    if (cmode & CEPH_FILE_MODE_LAZY) num_open_lazy--;
   }
   
   int authority(const string& dname) {
index 57f9fa0b297f12691db10d4982cd9713f00ab033..20449d1a89959d62150ce42c1b6490c90959c614 100644 (file)
@@ -9,10 +9,12 @@
 #ifdef __KERNEL__
 # include <linux/in.h>
 # include <linux/types.h>
+# include <asm/fcntl.h>
 #else
 # include <netinet/in.h>
 # include "inttypes.h"
 # include "byteorder.h"
+# include <fcntl.h>
 #endif
 
 #define CEPH_MON_PORT 12345
@@ -494,6 +496,33 @@ struct ceph_mds_reply_dirfrag {
        __u32 dist[];
 } __attribute__ ((packed));
 
+/* file access modes */
+#define CEPH_FILE_MODE_PIN        0
+#define CEPH_FILE_MODE_RD         1
+#define CEPH_FILE_MODE_WR         2
+#define CEPH_FILE_MODE_RDWR       3  /* RD | WR */
+#define CEPH_FILE_MODE_LAZY       4
+#define CEPH_FILE_MODE_NUM        8  /* bc these are bit fields.. mostly */
+
+static inline int ceph_flags_to_mode(int flags)
+{
+       if ((flags & O_DIRECTORY) == O_DIRECTORY)
+               return CEPH_FILE_MODE_PIN;
+#ifdef O_LAZY
+       if (flags & O_LAZY) 
+               return CEPH_FILE_MODE_LAZY;
+#endif
+       if ((flags & O_APPEND) == O_APPEND) 
+               flags |= O_WRONLY;
+       
+       flags &= O_ACCMODE;
+       if ((flags & O_RDWR) == O_RDWR) 
+               return CEPH_FILE_MODE_RDWR;
+       if ((flags & O_WRONLY) == O_WRONLY) 
+               return CEPH_FILE_MODE_WR;
+       return CEPH_FILE_MODE_RD;
+}
+
 /* client file caps */
 #define CEPH_CAP_PIN       1  /* no specific capabilities beyond the pin */
 #define CEPH_CAP_RDCACHE   2  /* client can cache reads */
@@ -504,6 +533,27 @@ struct ceph_mds_reply_dirfrag {
 #define CEPH_CAP_LAZYIO   64  /* client can perform lazy io */
 #define CEPH_CAP_EXCL    128  /* exclusive/loner access */
 
+static inline int ceph_caps_for_mode(int mode)
+{
+       switch (mode) {
+       case CEPH_FILE_MODE_PIN: 
+               return CEPH_CAP_PIN;
+       case CEPH_FILE_MODE_RD: 
+               return CEPH_CAP_PIN | 
+                       CEPH_CAP_RD | CEPH_CAP_RDCACHE;
+       case CEPH_FILE_MODE_RDWR:
+               return CEPH_CAP_PIN | 
+                       CEPH_CAP_RD | CEPH_CAP_RDCACHE |
+                       CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
+                       CEPH_CAP_EXCL;
+       case CEPH_FILE_MODE_WR:
+               return CEPH_CAP_PIN | 
+                       CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
+                       CEPH_CAP_EXCL;
+       }
+       return 0;
+}
+
 enum {
        CEPH_CAP_OP_GRANT,   /* mds->client grant */
        CEPH_CAP_OP_ACK,     /* client->mds ack (if prior grant was a recall) */
index 0122a86102aabd588499ab3ad766e91e7f833faf..2a9192f40c36bbbcd2b2d282c1a48bcf9c5e2680 100644 (file)
@@ -151,28 +151,8 @@ namespace __gnu_cxx {
 }
 
 
-// these are bit masks
-#define FILE_MODE_R          1
-#define FILE_MODE_W          2
-#define FILE_MODE_RW         (1|2)
-#define FILE_MODE_LAZY       4
-#define FILE_MODE_PIN        8
-
-static inline int file_flags_to_mode(int flags) {
-  if (flags & O_DIRECTORY)
-    return FILE_MODE_PIN;
-  if (flags & O_LAZY) 
-    return FILE_MODE_LAZY;
-  if (flags & O_WRONLY) 
-    return FILE_MODE_W;
-  if (flags & O_RDWR) 
-    return FILE_MODE_RW;
-  if (flags & O_APPEND) 
-    return FILE_MODE_W;
-  return FILE_MODE_R;
-}
 static inline bool file_mode_is_readonly(int mode) {
-  return (mode & FILE_MODE_W) == 0;
+  return (mode & CEPH_FILE_MODE_WR) == 0;
 }
 
 
index f7c3de0150f8e7915bd1693558e3273e0bacdd76..884c832d531144f7420a70e5b6d9a5c3e6a85aa7 100644 (file)
@@ -36,7 +36,7 @@ prepare_open_request(struct super_block *sb, struct dentry *dentry,
        req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_OPEN, pathbase, path,
                                       0, 0);
        req->r_expects_cap = 1;
-       req->r_fmode = ceph_file_mode(flags);
+       req->r_fmode = ceph_flags_to_mode(flags);
        kfree(path);
        if (!IS_ERR(req)) {
                rhead = req->r_request->front.iov_base;
@@ -81,7 +81,7 @@ int ceph_open(struct inode *inode, struct file *file)
        if (S_ISDIR(inode->i_mode))
                flags = O_DIRECTORY;
        
-       fmode = ceph_file_mode(flags);
+       fmode = ceph_flags_to_mode(flags);
        wantcaps = ceph_caps_for_mode(fmode);
 
        dout(5, "open inode %p ino %llx file %p\n", inode,
index 911ffa3ce5c773829d59e3527a9ecbe5eeb2b722..62daebbe9ee8f525083d55750d56a58dc849d7ba 100644 (file)
@@ -691,11 +691,11 @@ void __ceph_remove_cap(struct ceph_inode_cap *cap)
        dout(10, "__ceph_remove_cap %p from %p\n", cap, &cap->ci->vfs_inode);
 
        /* remove from session list */
-       list_del(&cap->session_caps);
+       list_del_init(&cap->session_caps);
        session->s_nr_caps--;
 
        /* remove from inode list */
-       list_del(&cap->ci_caps);
+       list_del_init(&cap->ci_caps);
        cap->session = 0;
        cap->mds = -1;  /* mark unused */
                
index e16317496613cd696f5e0b13b9924fb0d648ccad..5e2fd01fb08512bb643e7db1bf228ca28eb84d35 100644 (file)
@@ -141,7 +141,7 @@ static struct inode *ceph_alloc_inode(struct super_block *sb)
        INIT_LIST_HEAD(&ci->i_caps);
        for (i = 0; i < STATIC_CAPS; i++)
                ci->i_static_caps[i].mds = -1;
-       for (i = 0; i < 4; i++)
+       for (i = 0; i < CEPH_FILE_MODE_NUM; i++)
                ci->i_nr_by_mode[i] = 0;
        init_waitqueue_head(&ci->i_cap_wq);
 
index 05ff42cacc91e63ce5c6e4c3ae8520a08dd9b67b..8de815f57db83ba923e17c22a52773043769f468 100644 (file)
@@ -136,12 +136,6 @@ struct ceph_inode_frag_map_item {
 
 #define STATIC_CAPS 2
 
-enum {
-       FILE_MODE_PIN,
-       FILE_MODE_RDONLY,
-       FILE_MODE_RDWR,
-       FILE_MODE_WRONLY
-};
 struct ceph_inode_info {
        u64 i_ceph_ino;
 
@@ -164,7 +158,7 @@ struct ceph_inode_info {
        wait_queue_head_t i_cap_wq;
        unsigned long i_hold_caps_until; /* jiffies */
 
-       int i_nr_by_mode[4];
+       int i_nr_by_mode[CEPH_FILE_MODE_NUM];
        loff_t i_max_size;      /* size authorized by mds */
        loff_t i_reported_size; /* (max_)size reported to or requested of mds */
        loff_t i_wanted_max_size;  /* offset we'd like to write too */
@@ -271,27 +265,6 @@ static inline int __ceph_caps_used(struct ceph_inode_info *ci)
        return used;
 }
 
-static inline int ceph_caps_for_mode(int mode)
-{
-       switch (mode) {
-       case FILE_MODE_PIN: 
-               return CEPH_CAP_PIN;
-       case FILE_MODE_RDONLY: 
-               return CEPH_CAP_PIN | 
-                       CEPH_CAP_RD | CEPH_CAP_RDCACHE;
-       case FILE_MODE_RDWR:
-               return CEPH_CAP_PIN | 
-                       CEPH_CAP_RD | CEPH_CAP_RDCACHE |
-                       CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
-                       CEPH_CAP_EXCL;
-       case FILE_MODE_WRONLY:
-               return CEPH_CAP_PIN | 
-                       CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
-                       CEPH_CAP_EXCL;
-       }
-       return 0;
-}
-
 static inline int __ceph_caps_file_wanted(struct ceph_inode_info *ci)
 {
        int want = 0;
@@ -310,19 +283,6 @@ static inline int __ceph_caps_wanted(struct ceph_inode_info *ci)
        return w;
 }
 
-static inline int ceph_file_mode(int flags)
-{
-       if ((flags & O_DIRECTORY) == O_DIRECTORY)
-               return FILE_MODE_PIN;
-       if ((flags & O_ACCMODE) == O_RDWR)
-               return FILE_MODE_RDWR;
-       if ((flags & O_ACCMODE) == O_WRONLY)
-               return FILE_MODE_WRONLY;
-       if ((flags & O_ACCMODE) == O_RDONLY)
-               return FILE_MODE_RDONLY;
-       return FILE_MODE_RDWR;  /* not -EINVAL under Linux, strangely */
-}
-
 static inline void __ceph_get_fmode(struct ceph_inode_info *ci, int mode) 
 {
        ci->i_nr_by_mode[mode]++;
index e54e1bada6d77ea1483d2798debf9025610fcd73..27c88fdc84dcf274b76f747c4823c23d102c421d 100644 (file)
@@ -494,10 +494,7 @@ Capability* Locker::issue_new_caps(CInode *in,
   // my needs
   assert(session->inst.name.is_client());
   int my_client = session->inst.name.num();
-  int my_want = 0;
-  if (mode & FILE_MODE_PIN) my_want |= CEPH_CAP_PIN;
-  if (mode & FILE_MODE_R) my_want |= CEPH_CAP_RDCACHE  | CEPH_CAP_RD;
-  if (mode & FILE_MODE_W) my_want |= CEPH_CAP_WRBUFFER | CEPH_CAP_WR | CEPH_CAP_EXCL;
+  int my_want = ceph_caps_for_mode(mode);
 
   // register a capability
   Capability *cap = in->get_client_cap(my_client);
index 1fff74489dbbc83adb85ef74e3decbcda3f38019..04e19c2694b46247bf67f77474990fd5ee97edf3 100644 (file)
@@ -3925,7 +3925,7 @@ void Server::handle_client_open(MDRequest *mdr)
   MClientRequest *req = mdr->client_request;
 
   int flags = req->head.args.open.flags;
-  int cmode = file_flags_to_mode(req->head.args.open.flags);
+  int cmode = ceph_flags_to_mode(req->head.args.open.flags);
 
   bool need_auth = !file_mode_is_readonly(cmode) || (flags & O_TRUNC);
 
@@ -3935,7 +3935,7 @@ void Server::handle_client_open(MDRequest *mdr)
   if (!cur) return;
 
   // can only open a dir with mode FILE_MODE_PIN, at least for now.
-  if (cur->inode.is_dir()) cmode = FILE_MODE_PIN;
+  if (cur->inode.is_dir()) cmode = CEPH_FILE_MODE_PIN;
 
   dout(10) << "open flags = " << flags
           << ", filemode = " << cmode
@@ -3981,8 +3981,8 @@ void Server::handle_client_open(MDRequest *mdr)
 void Server::_do_open(MDRequest *mdr, CInode *cur)
 {
   MClientRequest *req = mdr->client_request;
-  int cmode = file_flags_to_mode(req->head.args.open.flags);
-  if (cur->inode.is_dir()) cmode = FILE_MODE_PIN;
+  int cmode = ceph_flags_to_mode(req->head.args.open.flags);
+  if (cur->inode.is_dir()) cmode = CEPH_FILE_MODE_PIN;
 
   // register new cap
   Capability *cap = mds->locker->issue_new_caps(cur, cmode, mdr->session);
@@ -3998,8 +3998,8 @@ void Server::_do_open(MDRequest *mdr, CInode *cur)
   
   // hit pop
   mdr->now = g_clock.now();
-  if (cmode == FILE_MODE_RW ||
-      cmode == FILE_MODE_W
+  if (cmode == CEPH_FILE_MODE_RDWR ||
+      cmode == CEPH_FILE_MODE_WR
     mds->balancer->hit_inode(mdr->now, cur, META_POP_IWR);
   else
     mds->balancer->hit_inode(mdr->now, cur, META_POP_IRD, 
index 9ad89f82347207bd04dd09d35d8a014e43e1b69a..086b6301024d5b6d0ae7f32594d449d72400111a 100644 (file)
@@ -96,7 +96,7 @@ public:
   }
 
   bool open_file_mode_is_readonly() {
-    return file_mode_is_readonly(file_flags_to_mode(head.args.open.flags));
+    return file_mode_is_readonly(ceph_flags_to_mode(head.args.open.flags));
   }
   bool is_idempotent() {
     if (head.op == CEPH_MDS_OP_OPEN)