]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kclient: snap_mutex -> snap_rwsem
authorSage Weil <sage@newdream.net>
Tue, 19 Aug 2008 17:05:54 +0000 (10:05 -0700)
committerSage Weil <sage@newdream.net>
Tue, 19 Aug 2008 20:36:18 +0000 (13:36 -0700)
src/kernel/inode.c
src/kernel/mds_client.c
src/kernel/mds_client.h
src/kernel/super.c

index 532bddcc1488bc1c113e4cf92b5ac0862fd40723..44ee8acdede9d9df36494c3d072f426e7c852176 100644 (file)
@@ -1136,7 +1136,7 @@ int ceph_get_cap_mds(struct inode *inode)
 }
 
 /*
- * caller should hold session snap_mutex, s_mutex.
+ * caller should hold session snap_rwsem, s_mutex.
  *
  * @fmode can be negative, in which case it is ignored.
  */
@@ -1259,7 +1259,7 @@ int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented)
 }
 
 /*
- * caller should hold i_lock, snap_mutex, and session s_mutex.
+ * caller should hold i_lock, snap_rwsem, and session s_mutex.
  * returns true if this is the last cap.  if so, caller should iput.
  */
 int __ceph_remove_cap(struct ceph_inode_cap *cap)
@@ -1290,7 +1290,7 @@ int __ceph_remove_cap(struct ceph_inode_cap *cap)
 }
 
 /*
- * caller should hold snap_mutex and session s_mutex.
+ * caller should hold snap_rwsem and session s_mutex.
  */
 void ceph_remove_cap(struct ceph_inode_cap *cap)
 {
@@ -1338,7 +1338,7 @@ void ceph_check_caps(struct ceph_inode_info *ci, int is_delayed, int flush_snap)
        struct list_head *p;
        int wanted, used;
        struct ceph_mds_session *session = 0;  /* if non-NULL, i hold s_mutex */
-       int took_snap_mutex = 0;             /* true if mdsc->snap_mutex held */
+       int took_snap_rwsem = 0;             /* true if mdsc->snap_rwsem held */
        int removed_last;
 
 retry:
@@ -1408,17 +1408,17 @@ ack:
                        mutex_unlock(&session->s_mutex);
                        session = 0;
                }
-               /* take snap_mutex before session mutex */
-               if (!flush_snap && !took_snap_mutex) {
-                       if (mutex_trylock(&mdsc->snap_mutex) == 0) {
+               /* take snap_rwsem before session mutex */
+               if (!flush_snap && !took_snap_rwsem) {
+                       if (down_write_trylock(&mdsc->snap_rwsem) == 0) {
                                dout(10, "inverting snap/in locks on %p\n",
                                     inode);
                                spin_unlock(&inode->i_lock);
-                               mutex_lock(&mdsc->snap_mutex);
-                               took_snap_mutex = 1;
+                               down_write(&mdsc->snap_rwsem);
+                               took_snap_rwsem = 1;
                                goto retry;
                        }
-                       took_snap_mutex = 1;
+                       took_snap_rwsem = 1;
                }
                if (!session) {
                        session = cap->session;
@@ -1447,8 +1447,8 @@ ack:
 out:
        if (session)
                mutex_unlock(&session->s_mutex);
-       if (took_snap_mutex)
-               mutex_unlock(&mdsc->snap_mutex);
+       if (took_snap_rwsem)
+               up_write(&mdsc->snap_rwsem);
 }
 
 void ceph_inode_set_size(struct inode *inode, loff_t size)
@@ -1485,7 +1485,7 @@ void ceph_put_fmode(struct ceph_inode_info *ci, int fmode)
 
 
 /*
- * caller holds s_mutex.  NOT snap_mutex.
+ * caller holds s_mutex.  NOT snap_rwsem.
  * return value:
  *  0 - ok
  *  1 - send the msg back to mds
@@ -1679,7 +1679,7 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)
 }
 
 /*
- * caller hold s_mutex, NOT snap_mutex.
+ * caller hold s_mutex, NOT snap_rwsem.
  */
 void ceph_handle_cap_trunc(struct inode *inode,
                           struct ceph_mds_caps *trunc,
index 08e12c3ff61f10da17466fd7bc7791cef8497a7e..6472263214d3a37134ea3c9fa8436acb08c13d2d 100644 (file)
@@ -1138,7 +1138,7 @@ void ceph_mdsc_handle_reply(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
        }
        BUG_ON(req->r_reply);
        if (req->r_expects_cap)
-               mutex_lock(&mdsc->snap_mutex);
+               down_write(&mdsc->snap_rwsem);
        mutex_unlock(&mdsc->mutex);
 
        mutex_lock(&req->r_session->s_mutex);
@@ -1190,7 +1190,7 @@ void ceph_mdsc_handle_reply(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
 
 done:
        if (req->r_expects_cap)
-               mutex_unlock(&mdsc->snap_mutex);
+               up_write(&mdsc->snap_rwsem);
        mutex_unlock(&req->r_session->s_mutex);
        mutex_lock(&mdsc->mutex);
        if (err) {
@@ -1538,7 +1538,7 @@ void ceph_mdsc_handle_caps(struct ceph_mds_client *mdsc,
        mutex_lock(&mdsc->mutex);
        session = __get_session(mdsc, mds);
        if (session)
-               mutex_lock(&mdsc->snap_mutex);
+               down_write(&mdsc->snap_rwsem);
        mutex_unlock(&mdsc->mutex);
        if (!session) {
                dout(10, "WTF, got cap but no session for mds%d\n", mds);
@@ -1560,7 +1560,7 @@ void ceph_mdsc_handle_caps(struct ceph_mds_client *mdsc,
 
        switch (op) {
        case CEPH_CAP_OP_GRANT:
-               mutex_unlock(&mdsc->snap_mutex);
+               up_write(&mdsc->snap_rwsem);
                if (ceph_handle_cap_grant(inode, h, session) == 1) {
                        dout(10, "sending reply back to mds%d\n", mds);
                        ceph_msg_get(msg);
@@ -1569,24 +1569,24 @@ void ceph_mdsc_handle_caps(struct ceph_mds_client *mdsc,
                break;
 
        case CEPH_CAP_OP_TRUNC:
-               mutex_unlock(&mdsc->snap_mutex);
+               up_write(&mdsc->snap_rwsem);
                ceph_handle_cap_trunc(inode, h, session);
                break;
 
        case CEPH_CAP_OP_EXPORT:
                ceph_handle_cap_export(inode, h, session);
-               mutex_unlock(&mdsc->snap_mutex);
+               up_write(&mdsc->snap_rwsem);
                break;
 
        case CEPH_CAP_OP_IMPORT:
                ceph_handle_cap_import(inode, h, session,
                                       msg->front.iov_base + sizeof(*h),
                                       le32_to_cpu(h->snap_trace_len));
-               mutex_unlock(&mdsc->snap_mutex);
+               up_write(&mdsc->snap_rwsem);
                break;
 
        default:
-               mutex_unlock(&mdsc->snap_mutex);
+               up_write(&mdsc->snap_rwsem);
                derr(10, "unknown cap op %d %s\n", op, ceph_cap_op_name(op));
        }
 
@@ -1615,7 +1615,7 @@ static void __cap_delay_cancel(struct ceph_mds_client *mdsc,
 
 /*
  * called with i_lock, then drops it.
- * caller should hold snap_mutex, s_mutex.
+ * caller should hold snap_rwsem, s_mutex.
  *
  * returns true if we removed the last cap on this inode.
  */
@@ -1788,7 +1788,7 @@ void ceph_mdsc_handle_snap(struct ceph_mds_client *mdsc,
        mutex_lock(&mdsc->mutex);
        session = __get_session(mdsc, mds);
        if (session)
-               mutex_lock(&mdsc->snap_mutex);
+               down_write(&mdsc->snap_rwsem);
        mutex_unlock(&mdsc->mutex);
        if (!session) {
                dout(10, "WTF, got snap but no session for mds%d\n", mds);
@@ -1894,7 +1894,7 @@ void ceph_mdsc_handle_snap(struct ceph_mds_client *mdsc,
        }
 
        ceph_put_snaprealm(realm);
-       mutex_unlock(&mdsc->snap_mutex);
+       up_write(&mdsc->snap_rwsem);
        return;
 
 bad:
@@ -2167,7 +2167,7 @@ static void delayed_work(struct work_struct *work)
 void ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
 {
        mutex_init(&mdsc->mutex);
-       mutex_init(&mdsc->snap_mutex);
+       init_rwsem(&mdsc->snap_rwsem);
        mdsc->client = client;
        mdsc->mdsmap = 0;            /* none yet */
        mdsc->sessions = 0;
@@ -2239,7 +2239,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
        spin_unlock(&mdsc->cap_delay_lock);
 
        mutex_lock(&mdsc->mutex);
-       mutex_lock(&mdsc->snap_mutex);
+       down_write(&mdsc->snap_rwsem);
 
        /* close sessions, caps */
        while (1) {
@@ -2265,7 +2265,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
 
        WARN_ON(!list_empty(&mdsc->cap_delay_list));
 
-       mutex_unlock(&mdsc->snap_mutex);
+       up_write(&mdsc->snap_rwsem);
        mutex_unlock(&mdsc->mutex);
        dout(10, "stopped\n");
 }
index 281d24053c8a66236253129de22746aebaf9a484..7d9df4f3831eb57038875e5c8e9d902ee15e246f 100644 (file)
@@ -129,7 +129,11 @@ struct ceph_mds_client {
        struct ceph_mds_session **sessions;    /* NULL if no session */
        int                     max_sessions;  /* len of s_mds_sessions */
 
-       struct mutex            snap_mutex;    /* all snaprealms */
+       /* 
+        * snap_rwsem will cover cap linkage into snaprealms, and realm
+        * snap contexts.  (later, we can do per-realm snap contexts locks..)
+        */
+       struct rw_semaphore     snap_rwsem;
        struct radix_tree_root  snaprealms;
 
        __u64                   last_tid;      /* most recent mds request */
index 4eb81fe49e2182ffccb901ed5275c46759281193..37ada5e192ab9a90aa455f79338fe26e8b21595a 100644 (file)
@@ -2,6 +2,7 @@
 #include <linux/parser.h>
 #include <linux/fs.h>
 #include <linux/mount.h>
+#include <linux/rwsem.h>
 #include <linux/seq_file.h>
 #include <linux/sched.h>
 #include <linux/string.h>