From c3f5ca89cccc599bbc5a6d1f7d1ec9b366495d56 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 4 Jul 2019 17:14:21 -0400 Subject: [PATCH] LU-4423 lustre: convert rsi_sem to a spinlock. This lock is never held over code that sleeps, and is only ever held for short periods of time. So a simple spinlock is best. Change-Id: I3280f52bf64ae2b896bd67436d8d8a42cab38ac2 Signed-off-by: NeilBrown Reviewed-on: https://review.whamcloud.com/35279 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/include/obd_class.h | 3 +-- lustre/llite/llite_lib.c | 6 +++--- lustre/llite/lproc_llite.c | 4 ++-- lustre/mdt/mdt_handler.c | 2 +- lustre/mdt/mdt_lib.c | 8 ++++---- lustre/mdt/mdt_lproc.c | 4 ++-- lustre/obdclass/lprocfs_status.c | 8 ++++---- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index dd83ca6..9be6bc0 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -1833,12 +1833,11 @@ void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs); void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs); /* root squash info */ -struct rw_semaphore; struct root_squash_info { uid_t rsi_uid; gid_t rsi_gid; struct list_head rsi_nosquash_nids; - struct rw_semaphore rsi_sem; + spinlock_t rsi_lock; }; int server_name2index(const char *svname, __u32 *idx, const char **endptr); diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 0ffbd6e..9e389d8 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -151,7 +151,7 @@ static struct ll_sb_info *ll_init_sbi(void) sbi->ll_squash.rsi_uid = 0; sbi->ll_squash.rsi_gid = 0; INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids); - init_rwsem(&sbi->ll_squash.rsi_sem); + spin_lock_init(&sbi->ll_squash.rsi_lock); /* Per-filesystem file heat */ sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT; @@ -2900,7 +2900,7 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi) struct lnet_process_id id; /* Update norootsquash flag */ - down_write(&squash->rsi_sem); + spin_lock(&squash->rsi_lock); if (list_empty(&squash->rsi_nosquash_nids)) sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH; else { @@ -2921,7 +2921,7 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi) else sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH; } - up_write(&squash->rsi_sem); + spin_unlock(&squash->rsi_lock); } /** diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 8728cc7..bf43681 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -1387,7 +1387,7 @@ static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v) struct root_squash_info *squash = &sbi->ll_squash; int len; - down_read(&squash->rsi_sem); + spin_lock(&squash->rsi_lock); if (!list_empty(&squash->rsi_nosquash_nids)) { len = cfs_print_nidlist(m->buf + m->count, m->size - m->count, &squash->rsi_nosquash_nids); @@ -1396,7 +1396,7 @@ static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v) } else { seq_puts(m, "NONE\n"); } - up_read(&squash->rsi_sem); + spin_unlock(&squash->rsi_lock); return 0; } diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index fdc360e..78a28d5 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -5174,7 +5174,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, m->mdt_squash.rsi_uid = 0; m->mdt_squash.rsi_gid = 0; INIT_LIST_HEAD(&m->mdt_squash.rsi_nosquash_nids); - init_rwsem(&m->mdt_squash.rsi_sem); + spin_lock_init(&m->mdt_squash.rsi_lock); spin_lock_init(&m->mdt_lock); m->mdt_enable_remote_dir = 1; m->mdt_enable_striped_dir = 1; diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index 020ff59..a970511 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -84,15 +84,15 @@ void mdt_exit_ucred(struct mdt_thread_info *info) } } -static int match_nosquash_list(struct rw_semaphore *sem, +static int match_nosquash_list(struct spinlock *rsi_lock, struct list_head *nidlist, lnet_nid_t peernid) { int rc; ENTRY; - down_read(sem); + spin_lock(rsi_lock); rc = cfs_match_nid(peernid, nidlist); - up_read(sem); + spin_unlock(rsi_lock); RETURN(rc); } @@ -107,7 +107,7 @@ static int mdt_root_squash(struct mdt_thread_info *info, lnet_nid_t peernid) if (!squash->rsi_uid || ucred->uc_fsuid) RETURN(0); - if (match_nosquash_list(&squash->rsi_sem, + if (match_nosquash_list(&squash->rsi_lock, &squash->rsi_nosquash_nids, peernid)) { CDEBUG(D_OTHER, "%s is in nosquash_nids list\n", diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index 9bc2522..6e502f2 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -567,7 +567,7 @@ static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data) struct root_squash_info *squash = &mdt->mdt_squash; int len = 0; - down_read(&squash->rsi_sem); + spin_lock(&squash->rsi_lock); if (!list_empty(&squash->rsi_nosquash_nids)) { len = cfs_print_nidlist(m->buf + m->count, m->size - m->count, &squash->rsi_nosquash_nids); @@ -575,7 +575,7 @@ static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data) seq_putc(m, '\n'); } else seq_puts(m, "NONE\n"); - up_read(&squash->rsi_sem); + spin_unlock(&squash->rsi_lock); return 0; } diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 63b28a8..2035fb7 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -2415,10 +2415,10 @@ int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count, if ((len == 4 && strncmp(kernbuf, "NONE", len) == 0) || (len == 5 && strncmp(kernbuf, "clear", len) == 0)) { /* empty string is special case */ - down_write(&squash->rsi_sem); + spin_lock(&squash->rsi_lock); if (!list_empty(&squash->rsi_nosquash_nids)) cfs_free_nidlist(&squash->rsi_nosquash_nids); - up_write(&squash->rsi_sem); + spin_unlock(&squash->rsi_lock); LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name); OBD_FREE(kernbuf, count + 1); RETURN(count); @@ -2434,11 +2434,11 @@ int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count, OBD_FREE(kernbuf, count + 1); kernbuf = NULL; - down_write(&squash->rsi_sem); + spin_lock(&squash->rsi_lock); if (!list_empty(&squash->rsi_nosquash_nids)) cfs_free_nidlist(&squash->rsi_nosquash_nids); list_splice(&tmp, &squash->rsi_nosquash_nids); - up_write(&squash->rsi_sem); + spin_unlock(&squash->rsi_lock); RETURN(count); -- 1.8.3.1