Whamcloud - gitweb
LU-3963 libcfs: convert md[d/t]/mg[c/s] to linux atomic primitives 74/7074/10
authorPeng Tao <tao.peng@emc.com>
Tue, 31 Dec 2013 15:22:23 +0000 (10:22 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 13 Jan 2014 19:19:10 +0000 (19:19 +0000)
This patch convers all cfs_atomic primitives in
mdd, mdt, mgc and mgs.

Signed-off-by: Liu Xuezhao <xuezhao.liu@emc.com>
Signed-off-by: Peng Tao <tao.peng@emc.com>
Signed-off-by: James Simmons <uja.ornl@gmail.com>
Change-Id: I052ca4da80b0cbd36df02a50f2ae0651eec28ea8
Reviewed-on: http://review.whamcloud.com/7074
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
lustre/mdd/mdd_device.c
lustre/mdt/mdt_handler.c
lustre/mgc/mgc_request.c
lustre/mgs/mgs_internal.h
lustre/mgs/mgs_nids.c

index 750281a..1d049ea 100644 (file)
@@ -1079,7 +1079,7 @@ static struct lu_device *mdd_device_free(const struct lu_env *env,
        struct mdd_device *m = lu2mdd_dev(lu);
        ENTRY;
 
-       LASSERT(cfs_atomic_read(&lu->ld_ref) == 0);
+       LASSERT(atomic_read(&lu->ld_ref) == 0);
        md_device_fini(&m->mdd_md_dev);
        OBD_FREE_PTR(m);
        RETURN(NULL);
index 2e7b16d..1b09982 100644 (file)
@@ -4238,7 +4238,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
         */
        mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
 
-       LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
+       LASSERT(atomic_read(&d->ld_ref) == 0);
 
        server_put_mount(mdt_obd_name(m));
 
index 9b2f6a9..b98d3de 100644 (file)
@@ -119,26 +119,26 @@ static DEFINE_SPINLOCK(config_list_lock);
 /* Take a reference to a config log */
 static int config_log_get(struct config_llog_data *cld)
 {
-        ENTRY;
-        cfs_atomic_inc(&cld->cld_refcount);
-        CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
-               cfs_atomic_read(&cld->cld_refcount));
-        RETURN(0);
+       ENTRY;
+       atomic_inc(&cld->cld_refcount);
+       CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
+               atomic_read(&cld->cld_refcount));
+       RETURN(0);
 }
 
 /* Drop a reference to a config log.  When no longer referenced,
    we can free the config log data */
 static void config_log_put(struct config_llog_data *cld)
 {
-        ENTRY;
+       ENTRY;
 
-        CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
-               cfs_atomic_read(&cld->cld_refcount));
-        LASSERT(cfs_atomic_read(&cld->cld_refcount) > 0);
+       CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
+               atomic_read(&cld->cld_refcount));
+       LASSERT(atomic_read(&cld->cld_refcount) > 0);
 
-        /* spinlock to make sure no item with 0 refcount in the list */
-        if (cfs_atomic_dec_and_lock(&cld->cld_refcount, &config_list_lock)) {
-                cfs_list_del(&cld->cld_list_chain);
+       /* spinlock to make sure no item with 0 refcount in the list */
+       if (atomic_dec_and_lock(&cld->cld_refcount, &config_list_lock)) {
+               cfs_list_del(&cld->cld_list_chain);
                spin_unlock(&config_list_lock);
 
                 CDEBUG(D_MGC, "dropping config log %s\n", cld->cld_logname);
@@ -178,16 +178,16 @@ struct config_llog_data *config_log_find(char *logname,
                 if (instance != cld->cld_cfg.cfg_instance)
                         continue;
 
-                /* instance may be NULL, should check name */
-                if (strcmp(logname, cld->cld_logname) == 0) {
-                        found = cld;
-                        break;
-                }
-        }
-        if (found) {
-                cfs_atomic_inc(&found->cld_refcount);
-                LASSERT(found->cld_stopping == 0 || cld_is_sptlrpc(found) == 0);
-        }
+               /* instance may be NULL, should check name */
+               if (strcmp(logname, cld->cld_logname) == 0) {
+                       found = cld;
+                       break;
+               }
+       }
+       if (found) {
+               atomic_inc(&found->cld_refcount);
+               LASSERT(found->cld_stopping == 0 || cld_is_sptlrpc(found) == 0);
+       }
        spin_unlock(&config_list_lock);
        RETURN(found);
 }
@@ -210,17 +210,17 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
         if (!cld)
                 RETURN(ERR_PTR(-ENOMEM));
 
-        strcpy(cld->cld_logname, logname);
-        if (cfg)
-                cld->cld_cfg = *cfg;
+       strcpy(cld->cld_logname, logname);
+       if (cfg)
+               cld->cld_cfg = *cfg;
        else
                cld->cld_cfg.cfg_callback = class_config_llog_handler;
        mutex_init(&cld->cld_lock);
-        cld->cld_cfg.cfg_last_idx = 0;
-        cld->cld_cfg.cfg_flags = 0;
-        cld->cld_cfg.cfg_sb = sb;
-        cld->cld_type = type;
-        cfs_atomic_set(&cld->cld_refcount, 1);
+       cld->cld_cfg.cfg_last_idx = 0;
+       cld->cld_cfg.cfg_flags = 0;
+       cld->cld_cfg.cfg_sb = sb;
+       cld->cld_type = type;
+       atomic_set(&cld->cld_refcount, 1);
 
         /* Keep the mgc around until we are done */
         cld->cld_mgcexp = class_export_get(obd->obd_self_export);
@@ -501,12 +501,13 @@ static DECLARE_COMPLETION(rq_exit);
 static void do_requeue(struct config_llog_data *cld)
 {
        int rc = 0;
-        ENTRY;
-        LASSERT(cfs_atomic_read(&cld->cld_refcount) > 0);
+       ENTRY;
 
-        /* Do not run mgc_process_log on a disconnected export or an
-           export which is being disconnected. Take the client
-           semaphore to make the check non-racy. */
+       LASSERT(atomic_read(&cld->cld_refcount) > 0);
+
+       /* Do not run mgc_process_log on a disconnected export or an
+        * export which is being disconnected. Take the client
+        * semaphore to make the check non-racy. */
        down_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
        if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count != 0) {
                CDEBUG(D_MGC, "updating log %s\n", cld->cld_logname);
@@ -576,13 +577,13 @@ static int mgc_requeue_thread(void *data)
 
                        spin_unlock(&config_list_lock);
 
-                        LASSERT(cfs_atomic_read(&cld->cld_refcount) > 0);
+                       LASSERT(atomic_read(&cld->cld_refcount) > 0);
 
-                        /* Whether we enqueued again or not in mgc_process_log,
-                         * we're done with the ref from the old enqueue */
-                        if (cld_prev)
-                                config_log_put(cld_prev);
-                        cld_prev = cld;
+                       /* Whether we enqueued again or not in mgc_process_log,
+                        * we're done with the ref from the old enqueue */
+                       if (cld_prev)
+                               config_log_put(cld_prev);
+                       cld_prev = cld;
 
                         cld->cld_lostlock = 0;
                        if (likely(!stopped))
@@ -621,12 +622,12 @@ static int mgc_requeue_thread(void *data)
    We are responsible for dropping the config log reference from here on out. */
 static void mgc_requeue_add(struct config_llog_data *cld)
 {
-        ENTRY;
+       ENTRY;
 
-        CDEBUG(D_INFO, "log %s: requeue (r=%d sp=%d st=%x)\n",
-               cld->cld_logname, cfs_atomic_read(&cld->cld_refcount),
-               cld->cld_stopping, rq_state);
-        LASSERT(cfs_atomic_read(&cld->cld_refcount) > 0);
+       CDEBUG(D_INFO, "log %s: requeue (r=%d sp=%d st=%x)\n",
+               cld->cld_logname, atomic_read(&cld->cld_refcount),
+               cld->cld_stopping, rq_state);
+       LASSERT(atomic_read(&cld->cld_refcount) > 0);
 
        mutex_lock(&cld->cld_lock);
        if (cld->cld_stopping || cld->cld_lostlock) {
@@ -838,19 +839,19 @@ static int mgc_llog_fini(const struct lu_env *env, struct obd_device *obd)
 }
 
 
-static cfs_atomic_t mgc_count = CFS_ATOMIC_INIT(0);
+static atomic_t mgc_count = ATOMIC_INIT(0);
 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
 {
-        int rc = 0;
-        ENTRY;
+       int rc = 0;
+       ENTRY;
 
-        switch (stage) {
-        case OBD_CLEANUP_EARLY:
-                break;
-        case OBD_CLEANUP_EXPORTS:
-                if (cfs_atomic_dec_and_test(&mgc_count)) {
-                        int running;
-                        /* stop requeue thread */
+       switch (stage) {
+       case OBD_CLEANUP_EARLY:
+               break;
+       case OBD_CLEANUP_EXPORTS:
+               if (atomic_dec_and_test(&mgc_count)) {
+                       int running;
+                       /* stop requeue thread */
                        spin_lock(&config_list_lock);
                        running = rq_state & RQ_RUNNING;
                        if (running)
@@ -859,15 +860,15 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
                        if (running) {
                                wake_up(&rq_waitq);
                                wait_for_completion(&rq_exit);
-                        }
-                }
-                obd_cleanup_client_import(obd);
+                       }
+               }
+               obd_cleanup_client_import(obd);
                rc = mgc_llog_fini(NULL, obd);
-                if (rc != 0)
-                        CERROR("failed to cleanup llogging subsystems\n");
-                break;
-        }
-        RETURN(rc);
+               if (rc != 0)
+                       CERROR("failed to cleanup llogging subsystems\n");
+               break;
+       }
+       RETURN(rc);
 }
 
 static int mgc_cleanup(struct obd_device *obd)
@@ -913,7 +914,7 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 #endif
        sptlrpc_lprocfs_cliobd_attach(obd);
 
-       if (cfs_atomic_inc_return(&mgc_count) == 1) {
+       if (atomic_inc_return(&mgc_count) == 1) {
                rq_state = 0;
                init_waitqueue_head(&rq_waitq);
 
@@ -963,29 +964,29 @@ static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                       PLDLMRES(lock->l_resource),
                       (char *)&lock->l_resource->lr_name.name[0]);
 
-                if (!cld) {
-                        CDEBUG(D_INFO, "missing data, won't requeue\n");
-                        break;
-                }
+               if (!cld) {
+                       CDEBUG(D_INFO, "missing data, won't requeue\n");
+                       break;
+               }
 
-                /* held at mgc_process_log(). */
-                LASSERT(cfs_atomic_read(&cld->cld_refcount) > 0);
-                /* Are we done with this log? */
-                if (cld->cld_stopping) {
-                        CDEBUG(D_MGC, "log %s: stopping, won't requeue\n",
-                               cld->cld_logname);
-                        config_log_put(cld);
-                        break;
-                }
-                /* Make sure not to re-enqueue when the mgc is stopping
-                   (we get called from client_disconnect_export) */
-                if (!lock->l_conn_export ||
-                    !lock->l_conn_export->exp_obd->u.cli.cl_conn_count) {
-                        CDEBUG(D_MGC, "log %.8s: disconnecting, won't requeue\n",
-                               cld->cld_logname);
-                        config_log_put(cld);
-                        break;
-                }
+               /* held at mgc_process_log(). */
+               LASSERT(atomic_read(&cld->cld_refcount) > 0);
+               /* Are we done with this log? */
+               if (cld->cld_stopping) {
+                       CDEBUG(D_MGC, "log %s: stopping, won't requeue\n",
+                               cld->cld_logname);
+                       config_log_put(cld);
+                       break;
+               }
+               /* Make sure not to re-enqueue when the mgc is stopping
+                  (we get called from client_disconnect_export) */
+               if (!lock->l_conn_export ||
+                   !lock->l_conn_export->exp_obd->u.cli.cl_conn_count) {
+                       CDEBUG(D_MGC, "log %.8s: disconnecting, won't requeue\n",
+                               cld->cld_logname);
+                       config_log_put(cld);
+                       break;
+               }
 
                 /* Re-enqueue now */
                 mgc_requeue_add(cld);
index 7f004e7..ca2846e 100644 (file)
@@ -149,7 +149,7 @@ struct fs_db {
        wait_queue_head_t    fsdb_notify_waitq;
        struct completion    fsdb_notify_comp;
        cfs_time_t           fsdb_notify_start;
-       cfs_atomic_t         fsdb_notify_phase;
+       atomic_t         fsdb_notify_phase;
        volatile unsigned int fsdb_notify_async:1,
                              fsdb_notify_stop:1;
         /* statistic data */
index 4d53969..63c427f 100644 (file)
@@ -414,10 +414,10 @@ static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
 void mgs_ir_notify_complete(struct fs_db *fsdb)
 {
-        struct timeval tv;
-        cfs_duration_t delta;
+       struct timeval tv;
+       cfs_duration_t delta;
 
-        cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
+       atomic_set(&fsdb->fsdb_notify_phase, 0);
 
         /* do statistic */
         fsdb->fsdb_notify_count++;
@@ -445,26 +445,26 @@ static int mgs_ir_notify(void *arg)
 
         set_user_nice(current, -2);
 
-        mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
-        while (1) {
-                struct l_wait_info   lwi = { 0 };
+       mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
+       while (1) {
+               struct l_wait_info   lwi = { 0 };
 
-                l_wait_event(fsdb->fsdb_notify_waitq,
-                             fsdb->fsdb_notify_stop ||
-                             cfs_atomic_read(&fsdb->fsdb_notify_phase),
-                             &lwi);
-                if (fsdb->fsdb_notify_stop)
-                        break;
+               l_wait_event(fsdb->fsdb_notify_waitq,
+                            fsdb->fsdb_notify_stop ||
+                            atomic_read(&fsdb->fsdb_notify_phase),
+                            &lwi);
+               if (fsdb->fsdb_notify_stop)
+                       break;
 
-                CDEBUG(D_MGS, "%s woken up, phase is %d\n",
-                       name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
+               CDEBUG(D_MGS, "%s woken up, phase is %d\n",
+                      name, atomic_read(&fsdb->fsdb_notify_phase));
 
-                fsdb->fsdb_notify_start = cfs_time_current();
+               fsdb->fsdb_notify_start = cfs_time_current();
                mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
-        }
+       }
 
        complete(&fsdb->fsdb_notify_comp);
-        return 0;
+       return 0;
 }
 
 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
@@ -484,7 +484,7 @@ int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
 
        /* start notify thread */
        fsdb->fsdb_mgs = mgs;
-       cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
+       atomic_set(&fsdb->fsdb_notify_phase, 0);
        init_waitqueue_head(&fsdb->fsdb_notify_waitq);
        init_completion(&fsdb->fsdb_notify_comp);
 
@@ -567,7 +567,7 @@ int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
        if (notify) {
                CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
                       fsdb->fsdb_name);
-               cfs_atomic_inc(&fsdb->fsdb_notify_phase);
+               atomic_inc(&fsdb->fsdb_notify_phase);
                wake_up(&fsdb->fsdb_notify_waitq);
        }
        return 0;