}
/*
- * 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.
*/
}
/*
- * 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)
}
/*
- * 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)
{
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:
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;
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)
/*
- * 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
}
/*
- * 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,
}
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);
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) {
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);
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);
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));
}
/*
* 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.
*/
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);
}
ceph_put_snaprealm(realm);
- mutex_unlock(&mdsc->snap_mutex);
+ up_write(&mdsc->snap_rwsem);
return;
bad:
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;
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) {
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");
}