Whamcloud - gitweb
LU-927 ptlrpc: common interfaces for ptlrpc_thread::t_flags
authorFan Yong <yong.fan@whamcloud.com>
Thu, 15 Dec 2011 01:50:20 +0000 (09:50 +0800)
committerOleg Drokin <green@whamcloud.com>
Wed, 4 Jan 2012 16:10:35 +0000 (11:10 -0500)
Build some common interfaces for ptlrpc_thread::t_flags processing:
thread_is_xxx and thread_yyy_flags. Operating ptlrpc_thread::t_flags
only can through these interfaces.

Signed-off-by: Fan Yong <yong.fan@whamcloud.com>
Change-Id: I285878ffeff8810ecbaf7a42b8d9381f392c0c9a
Reviewed-on: http://review.whamcloud.com/1690
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Niu Yawei <niu@whamcloud.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/include/lustre_net.h
lustre/ldlm/ldlm_pool.c
lustre/llite/llite_capa.c
lustre/llite/statahead.c
lustre/mdt/mdt_capa.c
lustre/ptlrpc/pinger.c
lustre/ptlrpc/sec_gc.c
lustre/ptlrpc/service.c

index 88edc1c..54bc06b 100644 (file)
@@ -984,6 +984,61 @@ struct ptlrpc_thread {
         struct lu_env *t_env;
 };
 
+static inline int thread_is_stopped(struct ptlrpc_thread *thread)
+{
+        return !!(thread->t_flags & SVC_STOPPED);
+}
+
+static inline int thread_is_stopping(struct ptlrpc_thread *thread)
+{
+        return !!(thread->t_flags & SVC_STOPPING);
+}
+
+static inline int thread_is_starting(struct ptlrpc_thread *thread)
+{
+        return !!(thread->t_flags & SVC_STARTING);
+}
+
+static inline int thread_is_running(struct ptlrpc_thread *thread)
+{
+        return !!(thread->t_flags & SVC_RUNNING);
+}
+
+static inline int thread_is_event(struct ptlrpc_thread *thread)
+{
+        return !!(thread->t_flags & SVC_EVENT);
+}
+
+static inline int thread_is_signal(struct ptlrpc_thread *thread)
+{
+        return !!(thread->t_flags & SVC_SIGNAL);
+}
+
+static inline void thread_clear_flags(struct ptlrpc_thread *thread, __u32 flags)
+{
+        thread->t_flags &= ~flags;
+}
+
+static inline void thread_set_flags(struct ptlrpc_thread *thread, __u32 flags)
+{
+        thread->t_flags = flags;
+}
+
+static inline void thread_add_flags(struct ptlrpc_thread *thread, __u32 flags)
+{
+        thread->t_flags |= flags;
+}
+
+static inline int thread_test_and_clear_flags(struct ptlrpc_thread *thread,
+                                              __u32 flags)
+{
+        if (thread->t_flags & flags) {
+                thread->t_flags &= ~flags;
+                return 1;
+        }
+        return 0;
+}
+
 /**
  * Request buffer descriptor structure.
  * This is a structure that contains one posted request buffer for service.
index 4f5b42d..9536dbd 100644 (file)
@@ -1300,7 +1300,7 @@ static int ldlm_pools_thread_main(void *arg)
         ENTRY;
 
         cfs_daemonize(t_name);
-        thread->t_flags = SVC_RUNNING;
+        thread_set_flags(thread, SVC_RUNNING);
         cfs_waitq_signal(&thread->t_ctl_waitq);
 
         CDEBUG(D_DLMTRACE, "%s: pool thread starting, process %d\n",
@@ -1321,19 +1321,18 @@ static int ldlm_pools_thread_main(void *arg)
                  */
                 lwi = LWI_TIMEOUT(cfs_time_seconds(LDLM_POOLS_THREAD_PERIOD),
                                   NULL, NULL);
-                l_wait_event(thread->t_ctl_waitq, (thread->t_flags &
-                                                   (SVC_STOPPING|SVC_EVENT)),
+                l_wait_event(thread->t_ctl_waitq,
+                             thread_is_stopping(thread) ||
+                             thread_is_event(thread),
                              &lwi);
 
-                if (thread->t_flags & SVC_STOPPING) {
-                        thread->t_flags &= ~SVC_STOPPING;
+                if (thread_test_and_clear_flags(thread, SVC_STOPPING))
                         break;
-                } else if (thread->t_flags & SVC_EVENT) {
-                        thread->t_flags &= ~SVC_EVENT;
-                }
+                else
+                        thread_test_and_clear_flags(thread, SVC_EVENT);
         }
 
-        thread->t_flags = SVC_STOPPED;
+        thread_set_flags(thread, SVC_STOPPED);
         cfs_waitq_signal(&thread->t_ctl_waitq);
 
         CDEBUG(D_DLMTRACE, "%s: pool thread exiting, process %d\n",
@@ -1372,7 +1371,7 @@ static int ldlm_pools_thread_start(void)
                 RETURN(rc);
         }
         l_wait_event(ldlm_pools_thread->t_ctl_waitq,
-                     (ldlm_pools_thread->t_flags & SVC_RUNNING), &lwi);
+                     thread_is_running(ldlm_pools_thread), &lwi);
         RETURN(0);
 }
 
@@ -1385,7 +1384,7 @@ static void ldlm_pools_thread_stop(void)
                 return;
         }
 
-        ldlm_pools_thread->t_flags = SVC_STOPPING;
+        thread_set_flags(ldlm_pools_thread, SVC_STOPPING);
         cfs_waitq_signal(&ldlm_pools_thread->t_ctl_waitq);
 
         /*
index 7fcd704..645e2cf 100644 (file)
@@ -30,6 +30,9 @@
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
@@ -119,11 +122,6 @@ static inline int have_expired_capa(void)
         return expired;
 }
 
-static inline int ll_capa_check_stop(void)
-{
-        return (ll_capa_thread.t_flags & SVC_STOPPING) ? 1: 0;
-}
-
 static void sort_add_capa(struct obd_capa *ocapa, cfs_list_t *head)
 {
         struct obd_capa *tmp;
@@ -180,15 +178,16 @@ static int capa_thread_main(void *unused)
 
         cfs_daemonize("ll_capa");
 
-        ll_capa_thread.t_flags = SVC_RUNNING;
+        thread_set_flags(&ll_capa_thread, SVC_RUNNING);
         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
 
         while (1) {
                 l_wait_event(ll_capa_thread.t_ctl_waitq,
-                             (ll_capa_check_stop() || have_expired_capa()),
+                             !thread_is_running(&ll_capa_thread) ||
+                             have_expired_capa(),
                              &lwi);
 
-                if (ll_capa_check_stop())
+                if (!thread_is_running(&ll_capa_thread))
                         break;
 
                 next = NULL;
@@ -285,7 +284,7 @@ static int capa_thread_main(void *unused)
                 cfs_spin_unlock(&capa_lock);
         }
 
-        ll_capa_thread.t_flags = SVC_STOPPED;
+        thread_set_flags(&ll_capa_thread, SVC_STOPPED);
         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
         RETURN(0);
 }
@@ -308,17 +307,17 @@ int ll_capa_thread_start(void)
                 RETURN(rc);
         }
         cfs_wait_event(ll_capa_thread.t_ctl_waitq,
-                       ll_capa_thread.t_flags & SVC_RUNNING);
+                       thread_is_running(&ll_capa_thread));
 
         RETURN(0);
 }
 
 void ll_capa_thread_stop(void)
 {
-        ll_capa_thread.t_flags = SVC_STOPPING;
+        thread_set_flags(&ll_capa_thread, SVC_STOPPING);
         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
         cfs_wait_event(ll_capa_thread.t_ctl_waitq,
-                       ll_capa_thread.t_flags & SVC_STOPPED);
+                       thread_is_stopped(&ll_capa_thread));
 }
 
 struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
index c3fa164..cb1883b 100644 (file)
@@ -150,21 +150,6 @@ static inline int sa_not_full(struct ll_statahead_info *sai)
         return (cfs_atomic_read(&sai->sai_cache_count) < sai->sai_max);
 }
 
-static inline int sa_is_running(struct ll_statahead_info *sai)
-{
-        return !!(sai->sai_thread.t_flags & SVC_RUNNING);
-}
-
-static inline int sa_is_stopping(struct ll_statahead_info *sai)
-{
-        return !!(sai->sai_thread.t_flags & SVC_STOPPING);
-}
-
-static inline int sa_is_stopped(struct ll_statahead_info *sai)
-{
-        return !!(sai->sai_thread.t_flags & SVC_STOPPED);
-}
-
 /**
  * (1) hit ratio less than 80%
  * or
@@ -491,7 +476,7 @@ static void ll_sai_put(struct ll_statahead_info *sai)
                 lli->lli_opendir_pid = 0;
                 cfs_spin_unlock(&lli->lli_sa_lock);
 
-                LASSERT(sa_is_stopped(sai));
+                LASSERT(thread_is_stopped(&sai->sai_thread));
 
                 if (sai->sai_sent > sai->sai_replied)
                         CDEBUG(D_READA,"statahead for dir "DFID" does not "
@@ -630,7 +615,7 @@ static int ll_statahead_interpret(struct ptlrpc_request *req,
                 GOTO(out, rc = -ESTALE);
         } else {
                 sai = ll_sai_get(lli->lli_sai);
-                if (unlikely(!sa_is_running(sai))) {
+                if (unlikely(!thread_is_running(&sai->sai_thread))) {
                         sai->sai_replied++;
                         cfs_spin_unlock(&lli->lli_sa_lock);
                         GOTO(out, rc = -EBADFD);
@@ -895,7 +880,7 @@ static int ll_statahead_thread(void *arg)
 
         atomic_inc(&sbi->ll_sa_total);
         cfs_spin_lock(&lli->lli_sa_lock);
-        thread->t_flags = SVC_RUNNING;
+        thread_set_flags(thread, SVC_RUNNING);
         cfs_spin_unlock(&lli->lli_sa_lock);
         cfs_waitq_signal(&thread->t_ctl_waitq);
         CDEBUG(D_READA, "start doing statahead for %s\n", parent->d_name.name);
@@ -970,13 +955,13 @@ keep_de:
                         l_wait_event(thread->t_ctl_waitq,
                                      sa_not_full(sai) ||
                                      !sa_received_empty(sai) ||
-                                     !sa_is_running(sai),
+                                     !thread_is_running(thread),
                                      &lwi);
 
                         while (!sa_received_empty(sai))
                                 do_statahead_interpret(sai, NULL);
 
-                        if (unlikely(!sa_is_running(sai))) {
+                        if (unlikely(!thread_is_running(thread))) {
                                 ll_release_page(page, 0);
                                 GOTO(out, rc);
                         }
@@ -999,7 +984,7 @@ keep_de:
                                 l_wait_event(thread->t_ctl_waitq,
                                              !sa_received_empty(sai) ||
                                              sai->sai_sent == sai->sai_replied||
-                                             !sa_is_running(sai),
+                                             !thread_is_running(thread),
                                              &lwi);
 
                                 while (!sa_received_empty(sai))
@@ -1007,7 +992,7 @@ keep_de:
 
                                 if ((sai->sai_sent == sai->sai_replied &&
                                      sa_received_empty(sai)) ||
-                                    !sa_is_running(sai))
+                                    !thread_is_running(thread))
                                         GOTO(out, rc = 0);
                         }
                 } else if (1) {
@@ -1035,7 +1020,7 @@ out:
         ll_dir_chain_fini(&chain);
         cfs_spin_lock(&lli->lli_sa_lock);
         if (!sa_received_empty(sai)) {
-                thread->t_flags = SVC_STOPPING;
+                thread_set_flags(thread, SVC_STOPPING);
                 cfs_spin_unlock(&lli->lli_sa_lock);
 
                 /* To release the resources held by received entries. */
@@ -1044,7 +1029,7 @@ out:
 
                 cfs_spin_lock(&lli->lli_sa_lock);
         }
-        thread->t_flags = SVC_STOPPED;
+        thread_set_flags(thread, SVC_STOPPED);
         cfs_spin_unlock(&lli->lli_sa_lock);
         cfs_waitq_signal(&sai->sai_waitq);
         cfs_waitq_signal(&thread->t_ctl_waitq);
@@ -1077,15 +1062,15 @@ void ll_stop_statahead(struct inode *dir, void *key)
                 struct l_wait_info lwi = { 0 };
                 struct ptlrpc_thread *thread = &lli->lli_sai->sai_thread;
 
-                if (!sa_is_stopped(lli->lli_sai)) {
-                        thread->t_flags = SVC_STOPPING;
+                if (!thread_is_stopped(thread)) {
+                        thread_set_flags(thread, SVC_STOPPING);
                         cfs_spin_unlock(&lli->lli_sa_lock);
                         cfs_waitq_signal(&thread->t_ctl_waitq);
 
                         CDEBUG(D_READA, "stopping statahead thread, pid %d\n",
                                cfs_curproc_pid());
                         l_wait_event(thread->t_ctl_waitq,
-                                     sa_is_stopped(lli->lli_sai),
+                                     thread_is_stopped(thread),
                                      &lwi);
                 } else {
                         cfs_spin_unlock(&lli->lli_sa_lock);
@@ -1238,8 +1223,9 @@ out:
 static void
 ll_sai_unplug(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
 {
-        struct ll_sb_info *sbi = ll_i2sbi(sai->sai_inode);
-        int                hit;
+        struct ptlrpc_thread *thread = &sai->sai_thread;
+        struct ll_sb_info    *sbi    = ll_i2sbi(sai->sai_inode);
+        int                  hit;
         ENTRY;
 
         if (entry != NULL && entry->se_stat == SA_ENTRY_SUCC)
@@ -1257,7 +1243,7 @@ ll_sai_unplug(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
 
                 sai->sai_miss++;
                 sai->sai_consecutive_miss++;
-                if (sa_low_hit(sai) && sa_is_running(sai)) {
+                if (sa_low_hit(sai) && thread_is_running(thread)) {
                         atomic_inc(&sbi->ll_sa_wrong);
                         CDEBUG(D_READA, "Statahead for dir "DFID" hit "
                                "ratio too low: hit/miss "LPU64"/"LPU64
@@ -1267,14 +1253,14 @@ ll_sai_unplug(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
                                sai->sai_miss, sai->sai_sent,
                                sai->sai_replied, cfs_curproc_pid());
                         cfs_spin_lock(&lli->lli_sa_lock);
-                        if (!sa_is_stopped(sai))
-                                sai->sai_thread.t_flags = SVC_STOPPING;
+                        if (!thread_is_stopped(thread))
+                                thread_set_flags(thread, SVC_STOPPING);
                         cfs_spin_unlock(&lli->lli_sa_lock);
                 }
         }
 
-        if (!sa_is_stopped(sai))
-                cfs_waitq_signal(&sai->sai_thread.t_ctl_waitq);
+        if (!thread_is_stopped(thread))
+                cfs_waitq_signal(&thread->t_ctl_waitq);
 
         EXIT;
 }
@@ -1295,6 +1281,7 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
         struct ll_statahead_info *sai   = lli->lli_sai;
         struct dentry            *parent;
         struct ll_sa_entry       *entry;
+        struct ptlrpc_thread     *thread;
         struct l_wait_info        lwi   = { 0 };
         int                       rc    = 0;
         ENTRY;
@@ -1302,7 +1289,8 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
         LASSERT(lli->lli_opendir_pid == cfs_curproc_pid());
 
         if (sai) {
-                if (unlikely(sa_is_stopped(sai) &&
+                thread = &sai->sai_thread;
+                if (unlikely(thread_is_stopped(thread) &&
                              cfs_list_empty(&sai->sai_entries_stated))) {
                         /* to release resource */
                         ll_stop_statahead(dir, lli->lli_opendir_key);
@@ -1353,7 +1341,7 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
                                                LWI_ON_SIGNAL_NOOP, NULL);
                         rc = l_wait_event(sai->sai_waitq,
                                           ll_sa_entry_stated(entry) ||
-                                          sa_is_stopped(sai),
+                                          thread_is_stopped(thread),
                                           &lwi);
                         if (rc < 0) {
                                 ll_sai_unplug(sai, entry);
@@ -1430,18 +1418,19 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
 
         lli->lli_sai = sai;
         rc = cfs_create_thread(ll_statahead_thread, parent, 0);
+        thread = &sai->sai_thread;
         if (rc < 0) {
                 CERROR("can't start ll_sa thread, rc: %d\n", rc);
                 dput(parent);
                 lli->lli_opendir_key = NULL;
-                sai->sai_thread.t_flags = SVC_STOPPED;
+                thread_set_flags(thread, SVC_STOPPED);
                 ll_sai_put(sai);
                 LASSERT(lli->lli_sai == NULL);
                 RETURN(-EAGAIN);
         }
 
-        l_wait_event(sai->sai_thread.t_ctl_waitq,
-                     sa_is_running(sai) || sa_is_stopped(sai),
+        l_wait_event(thread->t_ctl_waitq,
+                     thread_is_running(thread) || thread_is_stopped(thread),
                      &lwi);
 
         /*
index a40d839..578c3e8 100644 (file)
@@ -30,6 +30,9 @@
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
@@ -192,7 +195,7 @@ void mdt_ck_timer_callback(unsigned long castmeharder)
         struct ptlrpc_thread *thread = &mdt->mdt_ck_thread;
 
         ENTRY;
-        thread->t_flags |= SVC_EVENT;
+        thread_add_flags(thread, SVC_EVENT);
         cfs_waitq_signal(&thread->t_ctl_waitq);
         EXIT;
 }
@@ -215,7 +218,7 @@ static int mdt_ck_thread_main(void *args)
         cfs_daemonize_ctxt("mdt_ck");
         cfs_block_allsigs();
 
-        thread->t_flags = SVC_RUNNING;
+        thread_set_flags(thread, SVC_RUNNING);
         cfs_waitq_signal(&thread->t_ctl_waitq);
 
         rc = lu_env_init(&env, LCT_MD_THREAD|LCT_REMEMBER|LCT_NOREF);
@@ -233,12 +236,13 @@ static int mdt_ck_thread_main(void *args)
         mdsnum = mdt_md_site(mdt)->ms_node_id;
         while (1) {
                 l_wait_event(thread->t_ctl_waitq,
-                             thread->t_flags & (SVC_STOPPING | SVC_EVENT),
+                             thread_is_stopping(thread) ||
+                             thread_is_event(thread),
                              &lwi);
 
-                if (thread->t_flags & SVC_STOPPING)
+                if (thread_is_stopping(thread))
                         break;
-                thread->t_flags &= ~SVC_EVENT;
+                thread_clear_flags(thread, SVC_EVENT);
 
                 if (cfs_time_before(cfs_time_current(), mdt->mdt_ck_expiry))
                         break;
@@ -276,7 +280,7 @@ static int mdt_ck_thread_main(void *args)
         }
         lu_env_fini(&env);
 
-        thread->t_flags = SVC_STOPPED;
+        thread_set_flags(thread, SVC_STOPPED);
         cfs_waitq_signal(&thread->t_ctl_waitq);
         RETURN(0);
 }
@@ -293,7 +297,7 @@ int mdt_ck_thread_start(struct mdt_device *mdt)
                 return rc;
         }
 
-        l_wait_condition(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING);
+        l_wait_condition(thread->t_ctl_waitq, thread_is_running(thread));
         return 0;
 }
 
@@ -301,10 +305,10 @@ void mdt_ck_thread_stop(struct mdt_device *mdt)
 {
         struct ptlrpc_thread *thread = &mdt->mdt_ck_thread;
 
-        if (!(thread->t_flags & SVC_RUNNING))
+        if (!thread_is_running(thread))
                 return;
 
-        thread->t_flags = SVC_STOPPING;
+        thread_set_flags(thread, SVC_STOPPING);
         cfs_waitq_signal(&thread->t_ctl_waitq);
-        l_wait_condition(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
+        l_wait_condition(thread->t_ctl_waitq, thread_is_stopped(thread));
 }
index d91ac57..baabf7b 100644 (file)
@@ -272,7 +272,7 @@ static int ptlrpc_pinger_main(void *arg)
         cfs_daemonize(data->name);
 
         /* Record that the thread is running */
-        thread->t_flags = SVC_RUNNING;
+        thread_set_flags(thread, SVC_RUNNING);
         cfs_waitq_signal(&thread->t_ctl_waitq);
 
         /* And now, loop forever, pinging as needed. */
@@ -312,27 +312,29 @@ static int ptlrpc_pinger_main(void *arg)
                    next ping time to next_ping + .01 sec, which means
                    we will SKIP the next ping at next_ping, and the
                    ping will get sent 2 timeouts from now!  Beware. */
-                CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("CFS_TIME_T")\n",
-                                time_to_next_wake,
-                                cfs_time_add(this_ping, cfs_time_seconds(PING_INTERVAL)));
+                CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("
+                       CFS_TIME_T")\n", time_to_next_wake,
+                       cfs_time_add(this_ping,cfs_time_seconds(PING_INTERVAL)));
                 if (time_to_next_wake > 0) {
-                        lwi = LWI_TIMEOUT(max_t(cfs_duration_t, time_to_next_wake, cfs_time_seconds(1)),
-                                            NULL, NULL);
+                        lwi = LWI_TIMEOUT(max_t(cfs_duration_t,
+                                                time_to_next_wake,
+                                                cfs_time_seconds(1)),
+                                          NULL, NULL);
                         l_wait_event(thread->t_ctl_waitq,
-                                     thread->t_flags & (SVC_STOPPING|SVC_EVENT),
+                                     thread_is_stopping(thread) ||
+                                     thread_is_event(thread),
                                      &lwi);
-                        if (thread->t_flags & SVC_STOPPING) {
-                                thread->t_flags &= ~SVC_STOPPING;
+                        if (thread_test_and_clear_flags(thread, SVC_STOPPING)) {
                                 EXIT;
                                 break;
-                        } else if (thread->t_flags & SVC_EVENT) {
+                        } else {
                                 /* woken after adding import to reset timer */
-                                thread->t_flags &= ~SVC_EVENT;
+                                thread_test_and_clear_flags(thread, SVC_EVENT);
                         }
                 }
         }
 
-        thread->t_flags = SVC_STOPPED;
+        thread_set_flags(thread, SVC_STOPPED);
         cfs_waitq_signal(&thread->t_ctl_waitq);
 
         CDEBUG(D_NET, "pinger thread exiting, process %d\n", cfs_curproc_pid());
@@ -373,7 +375,7 @@ int ptlrpc_start_pinger(void)
                 RETURN(rc);
         }
         l_wait_event(pinger_thread->t_ctl_waitq,
-                     pinger_thread->t_flags & SVC_RUNNING, &lwi);
+                     thread_is_running(pinger_thread), &lwi);
 
         RETURN(0);
 }
@@ -394,12 +396,12 @@ int ptlrpc_stop_pinger(void)
 
         ptlrpc_pinger_remove_timeouts();
         cfs_mutex_down(&pinger_sem);
-        pinger_thread->t_flags = SVC_STOPPING;
+        thread_set_flags(pinger_thread, SVC_STOPPING);
         cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
         cfs_mutex_up(&pinger_sem);
 
         l_wait_event(pinger_thread->t_ctl_waitq,
-                     (pinger_thread->t_flags & SVC_STOPPED), &lwi);
+                     thread_is_stopped(pinger_thread), &lwi);
 
         OBD_FREE_PTR(pinger_thread);
         pinger_thread = NULL;
@@ -573,7 +575,7 @@ int ptlrpc_pinger_remove_timeouts(void)
 void ptlrpc_pinger_wake_up()
 {
 #ifdef ENABLE_PINGER
-        pinger_thread->t_flags |= SVC_EVENT;
+        thread_add_flags(pinger_thread, SVC_EVENT);
         cfs_waitq_signal(&pinger_thread->t_ctl_waitq);
 #endif
 }
index 47e40f7..f6cc912 100644 (file)
@@ -30,6 +30,9 @@
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
@@ -119,7 +122,7 @@ void sptlrpc_gc_add_ctx(struct ptlrpc_cli_ctx *ctx)
         cfs_list_add(&ctx->cc_gc_chain, &sec_gc_ctx_list);
         cfs_spin_unlock(&sec_gc_ctx_list_lock);
 
-        sec_gc_thread.t_flags |= SVC_SIGNAL;
+        thread_add_flags(&sec_gc_thread, SVC_SIGNAL);
         cfs_waitq_signal(&sec_gc_thread.t_ctl_waitq);
 }
 EXPORT_SYMBOL(sptlrpc_gc_add_ctx);
@@ -175,13 +178,13 @@ static int sec_gc_main(void *arg)
         cfs_daemonize_ctxt("sptlrpc_gc");
 
         /* Record that the thread is running */
-        thread->t_flags = SVC_RUNNING;
+        thread_set_flags(thread, SVC_RUNNING);
         cfs_waitq_signal(&thread->t_ctl_waitq);
 
         while (1) {
                 struct ptlrpc_sec *sec;
 
-                thread->t_flags &= ~SVC_SIGNAL;
+                thread_clear_flags(thread, SVC_SIGNAL);
                 sec_process_ctx_list();
 again:
                 /* go through sec list do gc.
@@ -209,16 +212,15 @@ again:
 
                 lwi = LWI_TIMEOUT(SEC_GC_INTERVAL * CFS_HZ, NULL, NULL);
                 l_wait_event(thread->t_ctl_waitq,
-                             thread->t_flags & (SVC_STOPPING | SVC_SIGNAL),
+                             thread_is_stopping(thread) ||
+                             thread_is_signal(thread),
                              &lwi);
 
-                if (thread->t_flags & SVC_STOPPING) {
-                        thread->t_flags &= ~SVC_STOPPING;
+                if (thread_test_and_clear_flags(thread, SVC_STOPPING))
                         break;
-                }
         }
 
-        thread->t_flags = SVC_STOPPED;
+        thread_set_flags(thread, SVC_STOPPED);
         cfs_waitq_signal(&thread->t_ctl_waitq);
         return 0;
 }
@@ -243,7 +245,7 @@ int sptlrpc_gc_init(void)
         }
 
         l_wait_event(sec_gc_thread.t_ctl_waitq,
-                     sec_gc_thread.t_flags & SVC_RUNNING, &lwi);
+                     thread_is_running(&sec_gc_thread), &lwi);
         return 0;
 }
 
@@ -251,11 +253,11 @@ void sptlrpc_gc_fini(void)
 {
         struct l_wait_info lwi = { 0 };
 
-        sec_gc_thread.t_flags = SVC_STOPPING;
+        thread_set_flags(&sec_gc_thread, SVC_STOPPING);
         cfs_waitq_signal(&sec_gc_thread.t_ctl_waitq);
 
         l_wait_event(sec_gc_thread.t_ctl_waitq,
-                     sec_gc_thread.t_flags & SVC_STOPPED, &lwi);
+                     thread_is_stopped(&sec_gc_thread), &lwi);
 }
 
 #else /* !__KERNEL__ */
index a36bc28..2fcffb5 100644 (file)
@@ -2017,8 +2017,8 @@ ptlrpc_threads_need_create(struct ptlrpc_service *svc)
 static inline int
 ptlrpc_thread_stopping(struct ptlrpc_thread *thread)
 {
-        return (thread->t_flags & SVC_STOPPING) != 0 ||
-                thread->t_svc->srv_is_stopping;
+        return thread_is_stopping(thread) ||
+               thread->t_svc->srv_is_stopping;
 }
 
 static inline int
@@ -2148,15 +2148,15 @@ static int ptlrpc_main(void *arg)
 
         cfs_spin_lock(&svc->srv_lock);
 
-        LASSERT((thread->t_flags & SVC_STARTING) != 0);
-        thread->t_flags &= ~SVC_STARTING;
+        LASSERT(thread_is_starting(thread));
+        thread_clear_flags(thread, SVC_STARTING);
         svc->srv_threads_starting--;
 
         /* SVC_STOPPING may already be set here if someone else is trying
          * to stop the service while this new thread has been dynamically
          * forked. We still set SVC_RUNNING to let our creator know that
          * we are now running, however we will exit as soon as possible */
-        thread->t_flags |= SVC_RUNNING;
+        thread_add_flags(thread, SVC_RUNNING);
         svc->srv_threads_running++;
         cfs_spin_unlock(&svc->srv_lock);
 
@@ -2233,19 +2233,15 @@ out:
                thread, thread->t_pid, thread->t_id, rc);
 
         cfs_spin_lock(&svc->srv_lock);
-        if ((thread->t_flags & SVC_STARTING) != 0) {
+        if (thread_test_and_clear_flags(thread, SVC_STARTING))
                 svc->srv_threads_starting--;
-                thread->t_flags &= ~SVC_STARTING;
-        }
 
-        if ((thread->t_flags & SVC_RUNNING) != 0) {
+        if (thread_test_and_clear_flags(thread, SVC_RUNNING))
                 /* must know immediately */
                 svc->srv_threads_running--;
-                thread->t_flags &= ~SVC_RUNNING;
-        }
 
         thread->t_id    = rc;
-        thread->t_flags |= SVC_STOPPED;
+        thread_add_flags(thread, SVC_STOPPED);
 
         cfs_waitq_signal(&thread->t_ctl_waitq);
         cfs_spin_unlock(&svc->srv_lock);
@@ -2405,12 +2401,12 @@ static void ptlrpc_stop_thread(struct ptlrpc_service *svc,
 
         cfs_spin_lock(&svc->srv_lock);
         /* let the thread know that we would like it to stop asap */
-        thread->t_flags |= SVC_STOPPING;
+        thread_add_flags(thread, SVC_STOPPING);
         cfs_spin_unlock(&svc->srv_lock);
 
         cfs_waitq_broadcast(&svc->srv_waitq);
         l_wait_event(thread->t_ctl_waitq,
-                     (thread->t_flags & SVC_STOPPED), &lwi);
+                     thread_is_stopped(thread), &lwi);
 
         cfs_spin_lock(&svc->srv_lock);
         cfs_list_del(&thread->t_link);
@@ -2502,7 +2498,7 @@ int ptlrpc_start_thread(struct ptlrpc_service *svc)
 
         svc->srv_threads_starting++;
         thread->t_id    = svc->srv_threads_next_id++;
-        thread->t_flags |= SVC_STARTING;
+        thread_add_flags(thread, SVC_STARTING);
         thread->t_svc   = svc;
 
         cfs_list_add(&thread->t_link, &svc->srv_threads);
@@ -2531,9 +2527,10 @@ int ptlrpc_start_thread(struct ptlrpc_service *svc)
                 RETURN(rc);
         }
         l_wait_event(thread->t_ctl_waitq,
-                     thread->t_flags & (SVC_RUNNING | SVC_STOPPED), &lwi);
+                     thread_is_running(thread) || thread_is_stopped(thread),
+                     &lwi);
 
-        rc = (thread->t_flags & SVC_STOPPED) ? thread->t_id : 0;
+        rc = thread_is_stopped(thread) ? thread->t_id : 0;
         RETURN(rc);
 }