Whamcloud - gitweb
LU-4423 lustre: convert rsi_sem to a spinlock. 79/35279/4
authorNeilBrown <neilb@suse.com>
Thu, 4 Jul 2019 21:14:21 +0000 (17:14 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 20 Jul 2019 18:38:40 +0000 (18:38 +0000)
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 <neilb@suse.com>
Reviewed-on: https://review.whamcloud.com/35279
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/obd_class.h
lustre/llite/llite_lib.c
lustre/llite/lproc_llite.c
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_lib.c
lustre/mdt/mdt_lproc.c
lustre/obdclass/lprocfs_status.c

index dd83ca6..9be6bc0 100644 (file)
@@ -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);
index 0ffbd6e..9e389d8 100644 (file)
@@ -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);
 }
 
 /**
index 8728cc7..bf43681 100644 (file)
@@ -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;
 }
index fdc360e..78a28d5 100644 (file)
@@ -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;
index 020ff59..a970511 100644 (file)
@@ -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",
index 9bc2522..6e502f2 100644 (file)
@@ -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;
 }
index 63b28a8..2035fb7 100644 (file)
@@ -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);