Whamcloud - gitweb
LU-3963 libcfs: convert md[d/t]/mg[c/s] to linux atomic primitives
[fs/lustre-release.git] / lustre / mgs / mgs_nids.c
index df792fc..63c427f 100644 (file)
@@ -79,7 +79,7 @@ static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
  * shouldn't cross unit boundaries.
  */
 static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
-                           struct mgs_config_res *res, cfs_page_t **pages,
+                          struct mgs_config_res *res, struct page **pages,
                            int nrpages, int units_total, int unit_size)
 {
         struct mgs_nidtbl_target *tgt;
@@ -97,7 +97,7 @@ static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
 
         /* make sure unit_size is power 2 */
         LASSERT((unit_size & (unit_size - 1)) == 0);
-        LASSERT(nrpages << CFS_PAGE_SHIFT >= units_total * unit_size);
+       LASSERT(nrpages << PAGE_CACHE_SHIFT >= units_total * unit_size);
 
        mutex_lock(&tbl->mn_lock);
         LASSERT(nidtbl_is_sane(tbl));
@@ -154,25 +154,25 @@ static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
                         }
                         LASSERT((rc & (unit_size - 1)) == 0);
 
-                        if (units_in_page == 0) {
-                                /* allocate a new page */
-                                pages[index] = cfs_alloc_page(CFS_ALLOC_STD);
-                                if (pages[index] == NULL) {
-                                        rc = -ENOMEM;
-                                        break;
-                                }
+                       if (units_in_page == 0) {
+                               /* allocate a new page */
+                               pages[index] = alloc_page(GFP_IOFS);
+                               if (pages[index] == NULL) {
+                                       rc = -ENOMEM;
+                                       break;
+                               }
 
-                                /* destroy previous map */
-                                if (index > 0)
-                                        cfs_kunmap(pages[index - 1]);
+                               /* destroy previous map */
+                               if (index > 0)
+                                       kunmap(pages[index - 1]);
 
-                                /* reassign buffer */
-                                buf = cfs_kmap(pages[index]);
-                                ++index;
+                               /* reassign buffer */
+                               buf = kmap(pages[index]);
+                               ++index;
 
-                                units_in_page = CFS_PAGE_SIZE / unit_size;
-                                LASSERT(units_in_page > 0);
-                        }
+                               units_in_page = PAGE_CACHE_SIZE / unit_size;
+                               LASSERT(units_in_page > 0);
+                       }
 
                         /* allocate an unit */
                         LASSERT(((long)buf & (unit_size - 1)) == 0);
@@ -212,7 +212,7 @@ static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
                        bytes_in_unit, index, nrpages, units_total);
         }
         if (index > 0)
-                cfs_kunmap(pages[index - 1]);
+               kunmap(pages[index - 1]);
 out:
         LASSERT(version <= tbl->mn_version);
         res->mcr_size = tbl->mn_version;
@@ -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++;
@@ -440,77 +440,78 @@ static int mgs_ir_notify(void *arg)
 
         LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
         sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
-        cfs_daemonize(name);
 
        complete(&fsdb->fsdb_notify_comp);
 
         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,
                   struct fs_db *fsdb)
 {
-        int rc;
+       struct task_struct *task;
 
-        if (!ir_timeout)
-                ir_timeout = OBD_IR_MGS_TIMEOUT;
+       if (!ir_timeout)
+               ir_timeout = OBD_IR_MGS_TIMEOUT;
 
-        fsdb->fsdb_ir_state = IR_FULL;
-        if (cfs_time_before(cfs_time_current_sec(),
-                            mgs->mgs_start_time + ir_timeout))
-                fsdb->fsdb_ir_state = IR_STARTUP;
-        fsdb->fsdb_nonir_clients = 0;
-        CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
+       fsdb->fsdb_ir_state = IR_FULL;
+       if (cfs_time_before(cfs_time_current_sec(),
+                           mgs->mgs_start_time + ir_timeout))
+               fsdb->fsdb_ir_state = IR_STARTUP;
+       fsdb->fsdb_nonir_clients = 0;
+       CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
 
-        /* start notify thread */
+       /* start notify thread */
        fsdb->fsdb_mgs = mgs;
-        cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
-        cfs_waitq_init(&fsdb->fsdb_notify_waitq);
+       atomic_set(&fsdb->fsdb_notify_phase, 0);
+       init_waitqueue_head(&fsdb->fsdb_notify_waitq);
        init_completion(&fsdb->fsdb_notify_comp);
-        rc = cfs_create_thread(mgs_ir_notify, fsdb, CFS_DAEMON_FLAGS);
-        if (rc > 0)
+
+       task = kthread_run(mgs_ir_notify, fsdb,
+                              "mgs_%s_notify", fsdb->fsdb_name);
+       if (!IS_ERR(task))
                wait_for_completion(&fsdb->fsdb_notify_comp);
-        else
-                CERROR("Start notify thread error %d\n", rc);
+       else
+               CERROR("Start notify thread error %ld\n", PTR_ERR(task));
 
        mgs_nidtbl_init_fs(env, fsdb);
-        return 0;
+       return 0;
 }
 
 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
 {
        if (test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
-                return;
+               return;
 
-        mgs_fsc_cleanup_by_fsdb(fsdb);
+       mgs_fsc_cleanup_by_fsdb(fsdb);
 
-        mgs_nidtbl_fini_fs(fsdb);
+       mgs_nidtbl_fini_fs(fsdb);
 
-        LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
+       LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
 
-        fsdb->fsdb_notify_stop = 1;
-        cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
+       fsdb->fsdb_notify_stop = 1;
+       wake_up(&fsdb->fsdb_notify_waitq);
        wait_for_completion(&fsdb->fsdb_notify_comp);
 }
 
@@ -562,14 +563,14 @@ int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
         }
        mutex_unlock(&fsdb->fsdb_mutex);
 
-        LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
-        if (notify) {
-                CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
-                       fsdb->fsdb_name);
-                cfs_atomic_inc(&fsdb->fsdb_notify_phase);
-                cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
-        }
-        return 0;
+       LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
+       if (notify) {
+               CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
+                      fsdb->fsdb_name);
+               atomic_inc(&fsdb->fsdb_notify_phase);
+               wake_up(&fsdb->fsdb_notify_waitq);
+       }
+       return 0;
 }
 
 /* NID table can be cached by two entities: Clients and MDTs */
@@ -627,7 +628,7 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         int                bytes;
         int                page_count;
         int                nrpages;
-        cfs_page_t       **pages = NULL;
+       struct page       **pages = NULL;
         ENTRY;
 
         body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
@@ -646,7 +647,7 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
                RETURN(rc);
 
         bufsize = body->mcb_units << body->mcb_bits;
-        nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
+       nrpages = (bufsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
         if (nrpages > PTLRPC_MAX_BRW_PAGES)
                 RETURN(-EINVAL);
 
@@ -657,33 +658,29 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         if (pages == NULL)
                 RETURN(-ENOMEM);
 
-        rc = req_capsule_server_pack(&req->rq_pill);
-        if (rc)
-                GOTO(out, rc);
-
         res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
         if (res == NULL)
                 GOTO(out, rc = -EINVAL);
 
         res->mcr_offset = body->mcb_offset;
-        unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
+       unit_size = min_t(int, 1 << body->mcb_bits, PAGE_CACHE_SIZE);
        bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
                                pages, nrpages, bufsize / unit_size, unit_size);
-        if (bytes < 0)
-                GOTO(out, rc = bytes);
-
-        /* start bulk transfer */
-        page_count = (bytes + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
-        LASSERT(page_count <= nrpages);
-        desc = ptlrpc_prep_bulk_exp(req, page_count,
-                                    BULK_PUT_SOURCE, MGS_BULK_PORTAL);
-        if (desc == NULL)
-                GOTO(out, rc = -ENOMEM);
-
-        for (i = 0; i < page_count && bytes > 0; i++) {
+       if (bytes < 0)
+               GOTO(out, rc = bytes);
+
+       /* start bulk transfer */
+       page_count = (bytes + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       LASSERT(page_count <= nrpages);
+       desc = ptlrpc_prep_bulk_exp(req, page_count, 1,
+                                   BULK_PUT_SOURCE, MGS_BULK_PORTAL);
+       if (desc == NULL)
+               GOTO(out, rc = -ENOMEM);
+
+       for (i = 0; i < page_count && bytes > 0; i++) {
                ptlrpc_prep_bulk_page_pin(desc, pages[i], 0,
-                                         min_t(int, bytes, CFS_PAGE_SIZE));
-                bytes -= CFS_PAGE_SIZE;
+                                         min_t(int, bytes, PAGE_CACHE_SIZE));
+               bytes -= PAGE_CACHE_SIZE;
         }
 
         rc = target_bulk_io(req->rq_export, desc, &lwi);
@@ -693,7 +690,7 @@ out:
        for (i = 0; i < nrpages; i++) {
                if (pages[i] == NULL)
                        break;
-               cfs_free_page(pages[i]);
+               __free_page(pages[i]);
        }
        OBD_FREE(pages, sizeof(*pages) * nrpages);
        return rc;
@@ -759,7 +756,7 @@ int lprocfs_wr_ir_state(struct file *file, const char *buffer,
         char *ptr;
         int rc = 0;
 
-        if (count > CFS_PAGE_SIZE)
+       if (count > PAGE_CACHE_SIZE)
                 return -EINVAL;
 
         OBD_ALLOC(kbuf, count + 1);
@@ -877,14 +874,14 @@ int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
         if (new_fsc == NULL)
                 RETURN(-ENOMEM);
 
-        CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
-        CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
-        new_fsc->mfc_fsdb       = fsdb;
-        new_fsc->mfc_export     = class_export_get(exp);
-        new_fsc->mfc_ir_capable =
-                        !!(exp->exp_connect_flags & OBD_CONNECT_IMP_RECOV);
+       CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
+       CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
+       new_fsc->mfc_fsdb       = fsdb;
+       new_fsc->mfc_export     = class_export_get(exp);
+       new_fsc->mfc_ir_capable = !!(exp_connect_flags(exp) &
+                                    OBD_CONNECT_IMP_RECOV);
 
-        rc = -EEXIST;
+       rc = -EEXIST;
        mutex_lock(&fsdb->fsdb_mutex);
 
        /* tend to find it in export list because this list is shorter. */