Commit daa5611c authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman

staging: lustre: fid: convert lcs_mutex to a spinlock

There is only one place where this lock is held
while the task might sleep - in
  ldebugfs_fid_space_seq_write()
while ldebugfs_fid_write_common() is called.

This call can easily be taken out of the locked region
by asking it to parse the user data into a local variable,
and then copying that variable into ->lcs_space while
holding the lock.

Note that ldebugfs_gid_write_common returns >0 on
success, so use that to gate updating ->lcs_space.

So make that change, and convert lcs_mutex to a spinlock
named lcs_lock.  spinlocks are slightly cheaper than mutexes
and using one makes is clear that the lock is only held for
a short time.
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ef8e5dbb
...@@ -198,24 +198,24 @@ static int seq_fid_alloc_prep(struct lu_client_seq *seq, ...@@ -198,24 +198,24 @@ static int seq_fid_alloc_prep(struct lu_client_seq *seq,
if (seq->lcs_update) { if (seq->lcs_update) {
add_wait_queue(&seq->lcs_waitq, link); add_wait_queue(&seq->lcs_waitq, link);
set_current_state(TASK_UNINTERRUPTIBLE); set_current_state(TASK_UNINTERRUPTIBLE);
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
schedule(); schedule();
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
remove_wait_queue(&seq->lcs_waitq, link); remove_wait_queue(&seq->lcs_waitq, link);
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
return -EAGAIN; return -EAGAIN;
} }
++seq->lcs_update; ++seq->lcs_update;
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
return 0; return 0;
} }
static void seq_fid_alloc_fini(struct lu_client_seq *seq) static void seq_fid_alloc_fini(struct lu_client_seq *seq)
{ {
LASSERT(seq->lcs_update == 1); LASSERT(seq->lcs_update == 1);
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
--seq->lcs_update; --seq->lcs_update;
wake_up(&seq->lcs_waitq); wake_up(&seq->lcs_waitq);
} }
...@@ -231,7 +231,7 @@ int seq_client_alloc_fid(const struct lu_env *env, ...@@ -231,7 +231,7 @@ int seq_client_alloc_fid(const struct lu_env *env,
LASSERT(fid); LASSERT(fid);
init_waitqueue_entry(&link, current); init_waitqueue_entry(&link, current);
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
if (OBD_FAIL_CHECK(OBD_FAIL_SEQ_EXHAUST)) if (OBD_FAIL_CHECK(OBD_FAIL_SEQ_EXHAUST))
seq->lcs_fid.f_oid = seq->lcs_width; seq->lcs_fid.f_oid = seq->lcs_width;
...@@ -256,7 +256,7 @@ int seq_client_alloc_fid(const struct lu_env *env, ...@@ -256,7 +256,7 @@ int seq_client_alloc_fid(const struct lu_env *env,
CERROR("%s: Can't allocate new sequence, rc %d\n", CERROR("%s: Can't allocate new sequence, rc %d\n",
seq->lcs_name, rc); seq->lcs_name, rc);
seq_fid_alloc_fini(seq); seq_fid_alloc_fini(seq);
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
return rc; return rc;
} }
...@@ -278,7 +278,7 @@ int seq_client_alloc_fid(const struct lu_env *env, ...@@ -278,7 +278,7 @@ int seq_client_alloc_fid(const struct lu_env *env,
} }
*fid = seq->lcs_fid; *fid = seq->lcs_fid;
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
CDEBUG(D_INFO, CDEBUG(D_INFO,
"%s: Allocated FID " DFID "\n", seq->lcs_name, PFID(fid)); "%s: Allocated FID " DFID "\n", seq->lcs_name, PFID(fid));
...@@ -296,16 +296,16 @@ void seq_client_flush(struct lu_client_seq *seq) ...@@ -296,16 +296,16 @@ void seq_client_flush(struct lu_client_seq *seq)
LASSERT(seq); LASSERT(seq);
init_waitqueue_entry(&link, current); init_waitqueue_entry(&link, current);
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
while (seq->lcs_update) { while (seq->lcs_update) {
add_wait_queue(&seq->lcs_waitq, &link); add_wait_queue(&seq->lcs_waitq, &link);
set_current_state(TASK_UNINTERRUPTIBLE); set_current_state(TASK_UNINTERRUPTIBLE);
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
schedule(); schedule();
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
remove_wait_queue(&seq->lcs_waitq, &link); remove_wait_queue(&seq->lcs_waitq, &link);
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
} }
...@@ -319,7 +319,7 @@ void seq_client_flush(struct lu_client_seq *seq) ...@@ -319,7 +319,7 @@ void seq_client_flush(struct lu_client_seq *seq)
seq->lcs_space.lsr_index = -1; seq->lcs_space.lsr_index = -1;
lu_seq_range_init(&seq->lcs_space); lu_seq_range_init(&seq->lcs_space);
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
} }
EXPORT_SYMBOL(seq_client_flush); EXPORT_SYMBOL(seq_client_flush);
...@@ -382,7 +382,7 @@ static int seq_client_init(struct lu_client_seq *seq, ...@@ -382,7 +382,7 @@ static int seq_client_init(struct lu_client_seq *seq,
seq->lcs_type = type; seq->lcs_type = type;
mutex_init(&seq->lcs_mutex); spin_lock_init(&seq->lcs_lock);
if (type == LUSTRE_SEQ_METADATA) if (type == LUSTRE_SEQ_METADATA)
seq->lcs_width = LUSTRE_METADATA_SEQ_MAX_WIDTH; seq->lcs_width = LUSTRE_METADATA_SEQ_MAX_WIDTH;
else else
......
...@@ -98,20 +98,23 @@ ldebugfs_fid_space_seq_write(struct file *file, ...@@ -98,20 +98,23 @@ ldebugfs_fid_space_seq_write(struct file *file,
size_t count, loff_t *off) size_t count, loff_t *off)
{ {
struct lu_client_seq *seq; struct lu_client_seq *seq;
struct lu_seq_range range;
int rc; int rc;
seq = ((struct seq_file *)file->private_data)->private; seq = ((struct seq_file *)file->private_data)->private;
mutex_lock(&seq->lcs_mutex); rc = ldebugfs_fid_write_common(buffer, count, &range);
rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space);
spin_lock(&seq->lcs_lock);
if (rc > 0)
seq->lcs_space = range;
spin_unlock(&seq->lcs_lock);
if (rc == 0) { if (rc == 0) {
CDEBUG(D_INFO, "%s: Space: " DRANGE "\n", CDEBUG(D_INFO, "%s: Space: " DRANGE "\n",
seq->lcs_name, PRANGE(&seq->lcs_space)); seq->lcs_name, PRANGE(&range));
} }
mutex_unlock(&seq->lcs_mutex);
return count; return count;
} }
...@@ -120,9 +123,9 @@ ldebugfs_fid_space_seq_show(struct seq_file *m, void *unused) ...@@ -120,9 +123,9 @@ ldebugfs_fid_space_seq_show(struct seq_file *m, void *unused)
{ {
struct lu_client_seq *seq = (struct lu_client_seq *)m->private; struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space)); seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
return 0; return 0;
} }
...@@ -142,7 +145,7 @@ ldebugfs_fid_width_seq_write(struct file *file, ...@@ -142,7 +145,7 @@ ldebugfs_fid_width_seq_write(struct file *file,
if (rc) if (rc)
return rc; return rc;
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
if (seq->lcs_type == LUSTRE_SEQ_DATA) if (seq->lcs_type == LUSTRE_SEQ_DATA)
max = LUSTRE_DATA_SEQ_MAX_WIDTH; max = LUSTRE_DATA_SEQ_MAX_WIDTH;
else else
...@@ -155,7 +158,7 @@ ldebugfs_fid_width_seq_write(struct file *file, ...@@ -155,7 +158,7 @@ ldebugfs_fid_width_seq_write(struct file *file,
seq->lcs_width); seq->lcs_width);
} }
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
return count; return count;
} }
...@@ -165,9 +168,9 @@ ldebugfs_fid_width_seq_show(struct seq_file *m, void *unused) ...@@ -165,9 +168,9 @@ ldebugfs_fid_width_seq_show(struct seq_file *m, void *unused)
{ {
struct lu_client_seq *seq = (struct lu_client_seq *)m->private; struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
seq_printf(m, "%llu\n", seq->lcs_width); seq_printf(m, "%llu\n", seq->lcs_width);
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
return 0; return 0;
} }
...@@ -177,9 +180,9 @@ ldebugfs_fid_fid_seq_show(struct seq_file *m, void *unused) ...@@ -177,9 +180,9 @@ ldebugfs_fid_fid_seq_show(struct seq_file *m, void *unused)
{ {
struct lu_client_seq *seq = (struct lu_client_seq *)m->private; struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
mutex_lock(&seq->lcs_mutex); spin_lock(&seq->lcs_lock);
seq_printf(m, DFID "\n", PFID(&seq->lcs_fid)); seq_printf(m, DFID "\n", PFID(&seq->lcs_fid));
mutex_unlock(&seq->lcs_mutex); spin_unlock(&seq->lcs_lock);
return 0; return 0;
} }
......
...@@ -324,7 +324,7 @@ enum lu_mgr_type { ...@@ -324,7 +324,7 @@ enum lu_mgr_type {
struct lu_client_seq { struct lu_client_seq {
/* Sequence-controller export. */ /* Sequence-controller export. */
struct obd_export *lcs_exp; struct obd_export *lcs_exp;
struct mutex lcs_mutex; spinlock_t lcs_lock;
/* /*
* Range of allowed for allocation sequences. When using lu_client_seq on * Range of allowed for allocation sequences. When using lu_client_seq on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment