Whamcloud - gitweb
LU-9325 obd: replace lprocfs_str_to_s64
[fs/lustre-release.git] / lustre / mgs / mgs_nids.c
index b4ce943..7f73d86 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -48,7 +48,7 @@
 
 #include "mgs_internal.h"
 
-static unsigned int ir_timeout;
+static time64_t ir_timeout;
 
 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
 {
@@ -220,6 +220,9 @@ static int nidtbl_update_version(const struct lu_env *env,
        int               rc;
         ENTRY;
 
+       if (mgs->mgs_bottom->dd_rdonly)
+               RETURN(0);
+
        LASSERT(mutex_is_locked(&tbl->mn_lock));
 
        fsdb = local_file_find_or_create(env, mgs->mgs_los, mgs->mgs_nidtbl_dir,
@@ -247,7 +250,7 @@ static int nidtbl_update_version(const struct lu_env *env,
 out:
        dt_trans_stop(env, mgs->mgs_bottom, th);
 out_put:
-       lu_object_put(env, &fsdb->do_lu);
+       dt_object_put(env, fsdb);
        RETURN(rc);
 }
 
@@ -295,7 +298,7 @@ static int nidtbl_read_version(const struct lu_env *env,
                CERROR("%s: read version file %s error %d\n",
                       mgs->mgs_obd->obd_name, tbl->mn_fsdb->fsdb_name, rc);
        }
-       lu_object_put(env, &fsdb->do_lu);
+       dt_object_put(env, fsdb);
        RETURN(rc);
 }
 
@@ -395,37 +398,34 @@ 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 timespec64 ts;
+       ktime_t delta;
 
        atomic_set(&fsdb->fsdb_notify_phase, 0);
 
-        /* do statistic */
-        fsdb->fsdb_notify_count++;
-        delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
-        fsdb->fsdb_notify_total += delta;
-        if (delta > fsdb->fsdb_notify_max)
-                fsdb->fsdb_notify_max = delta;
+       /* do statistic */
+       fsdb->fsdb_notify_count++;
+       delta = ktime_sub(ktime_get(), fsdb->fsdb_notify_start);
+       fsdb->fsdb_notify_total = ktime_add(fsdb->fsdb_notify_total, delta);
+       if (ktime_after(delta, fsdb->fsdb_notify_max))
+               fsdb->fsdb_notify_max = delta;
 
-        cfs_duration_usec(delta, &tv);
-        CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
-               fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
+       ts = ktime_to_timespec64(fsdb->fsdb_notify_max);
+       CDEBUG(D_MGS, "Revoke recover lock of %s completed after %lld.%09lds\n",
+              fsdb->fsdb_name, (s64)ts.tv_sec, ts.tv_nsec);
 }
 
 static int mgs_ir_notify(void *arg)
 {
-        struct fs_db      *fsdb   = arg;
-        struct ldlm_res_id resid;
-
-        char name[sizeof(fsdb->fsdb_name) + 20];
+       struct fs_db *fsdb = arg;
+       struct ldlm_res_id resid;
+       char name[sizeof(fsdb->fsdb_name) + 16];
 
-        LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
-        sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
+       CLASSERT(sizeof(name) < 40); /* name is too large to be on stack */
 
+       snprintf(name, sizeof(name) - 1, "mgs_%s_notify", fsdb->fsdb_name);
        complete(&fsdb->fsdb_notify_comp);
-
-        set_user_nice(current, -2);
-
+       set_user_nice(current, -2);
        mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
        while (1) {
                struct l_wait_info   lwi = { 0 };
@@ -440,7 +440,7 @@ static int mgs_ir_notify(void *arg)
                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 = ktime_get();
                mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
        }
 
@@ -454,21 +454,14 @@ int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
        struct task_struct *task;
 
        if (!ir_timeout)
-               ir_timeout = OBD_IR_MGS_TIMEOUT;
+               ir_timeout = (time64_t)OBD_IR_MGS_TIMEOUT;
 
        fsdb->fsdb_ir_state = IR_FULL;
-       if (cfs_time_before(cfs_time_current_sec(),
-                           mgs->mgs_start_time + ir_timeout))
+       if (mgs->mgs_start_time + ir_timeout > ktime_get_real_seconds())
                fsdb->fsdb_ir_state = IR_STARTUP;
        fsdb->fsdb_nonir_clients = 0;
-       INIT_LIST_HEAD(&fsdb->fsdb_clients);
-
        /* start notify thread */
        fsdb->fsdb_mgs = mgs;
-       atomic_set(&fsdb->fsdb_notify_phase, 0);
-       init_waitqueue_head(&fsdb->fsdb_notify_waitq);
-       init_completion(&fsdb->fsdb_notify_comp);
-
        task = kthread_run(mgs_ir_notify, fsdb,
                               "mgs_%s_notify", fsdb->fsdb_name);
        if (!IS_ERR(task))
@@ -500,8 +493,8 @@ void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
 static inline void ir_state_graduate(struct fs_db *fsdb)
 {
         if (fsdb->fsdb_ir_state == IR_STARTUP) {
-               if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
-                                    cfs_time_current_sec())) {
+               if (ktime_get_real_seconds() >
+                   fsdb->fsdb_mgs->mgs_start_time + ir_timeout) {
                         fsdb->fsdb_ir_state = IR_FULL;
                         if (fsdb->fsdb_nonir_clients)
                                 fsdb->fsdb_ir_state = IR_PARTIAL;
@@ -525,7 +518,7 @@ int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
 
        rc = mgs_nidtbl_write(env, fsdb, mti);
         if (rc)
-                return rc;
+               GOTO(out, rc);
 
         /* check ir state */
        mutex_lock(&fsdb->fsdb_mutex);
@@ -551,7 +544,10 @@ int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
                atomic_inc(&fsdb->fsdb_notify_phase);
                wake_up(&fsdb->fsdb_notify_waitq);
        }
-       return 0;
+
+out:
+       mgs_put_fsdb(mgs, fsdb);
+       return rc;
 }
 
 /* NID table can be cached by two entities: Clients and MDTs */
@@ -595,7 +591,7 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
 {
        struct lu_env     *env = req->rq_svc_thread->t_env;
        struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
-        struct fs_db      *fsdb;
+       struct fs_db *fsdb = NULL;
         struct mgs_config_body  *body;
         struct mgs_config_res   *res;
         struct ptlrpc_bulk_desc *desc;
@@ -623,27 +619,27 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         if (rc)
                 RETURN(rc);
 
+       bufsize = body->mcb_units << body->mcb_bits;
+       nrpages = (bufsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       if (nrpages > PTLRPC_MAX_BRW_PAGES)
+               RETURN(-EINVAL);
+
        rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
-        if (rc)
+       if (rc)
                RETURN(rc);
 
-        bufsize = body->mcb_units << body->mcb_bits;
-       nrpages = (bufsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
-        if (nrpages > PTLRPC_MAX_BRW_PAGES)
-                RETURN(-EINVAL);
+       CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
+              body->mcb_name, bufsize);
 
-        CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
-               body->mcb_name, bufsize);
-
-        OBD_ALLOC(pages, sizeof(*pages) * nrpages);
-        if (pages == NULL)
-                RETURN(-ENOMEM);
+       OBD_ALLOC(pages, sizeof(*pages) * nrpages);
+       if (!pages)
+               GOTO(out, rc = -ENOMEM);
 
-        res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
-        if (res == NULL)
-                GOTO(out, rc = -EINVAL);
+       res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
+       if (!res)
+               GOTO(out, rc = -EINVAL);
 
-        res->mcr_offset = body->mcb_offset;
+       res->mcr_offset = body->mcb_offset;
        unit_size = min_t(int, 1 << body->mcb_bits, PAGE_SIZE);
        bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
                                pages, nrpages, bufsize / unit_size, unit_size);
@@ -658,7 +654,7 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
                                        PTLRPC_BULK_BUF_KIOV,
                                    MGS_BULK_PORTAL,
                                    &ptlrpc_bulk_kiov_pin_ops);
-       if (desc == NULL)
+       if (!desc)
                GOTO(out, rc = -ENOMEM);
 
        for (i = 0; i < page_count && bytes > 0; i++) {
@@ -666,18 +662,28 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
                                                 min_t(int, bytes,
                                                      PAGE_SIZE));
                bytes -= PAGE_SIZE;
-        }
+       }
 
-        rc = target_bulk_io(req->rq_export, desc, &lwi);
+       rc = target_bulk_io(req->rq_export, desc, &lwi);
        ptlrpc_free_bulk(desc);
 
+       GOTO(out, rc);
+
 out:
-       for (i = 0; i < nrpages; i++) {
-               if (pages[i] == NULL)
-                       break;
-               __free_page(pages[i]);
+       if (pages) {
+               for (i = 0; i < nrpages; i++) {
+                       if (!pages[i])
+                               break;
+
+                       __free_page(pages[i]);
+               }
+
+               OBD_FREE(pages, sizeof(*pages) * nrpages);
        }
-       OBD_FREE(pages, sizeof(*pages) * nrpages);
+
+       if (fsdb)
+               mgs_put_fsdb(mgs, fsdb);
+
        return rc;
 }
 
@@ -714,13 +720,13 @@ static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
 
 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
 {
-        if (*buf)
-                return -EINVAL;
+       if (*buf)
+               return -EINVAL;
 
-        fsdb->fsdb_notify_total = 0;
-        fsdb->fsdb_notify_max   = 0;
-        fsdb->fsdb_notify_count = 0;
-        return 0;
+       fsdb->fsdb_notify_total = ktime_set(0, 0);
+       fsdb->fsdb_notify_max = ktime_set(0, 0);
+       fsdb->fsdb_notify_count = 0;
+       return 0;
 }
 
 static struct lproc_ir_cmd {
@@ -793,11 +799,11 @@ int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
 
 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
 {
-        struct fs_db      *fsdb = data;
-        struct mgs_nidtbl *tbl  = &fsdb->fsdb_nidtbl;
-        const char        *ir_strings[] = IR_STRINGS;
-        struct timeval     tv_max;
-        struct timeval     tv;
+       struct fs_db *fsdb = data;
+       struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
+       const char *ir_strings[] = IR_STRINGS;
+       struct timespec64 ts_max;
+       struct timespec64 ts;
 
         /* mgs_live_seq_show() already holds fsdb_mutex. */
         ir_state_graduate(fsdb);
@@ -810,29 +816,30 @@ int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
                    ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
                    tbl->mn_version);
 
-        cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
-        cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
+       ts = ktime_to_timespec64(fsdb->fsdb_notify_total);
+       ts_max = ktime_to_timespec64(fsdb->fsdb_notify_max);
 
-        seq_printf(seq, "    notify_duration_total: %lu.%06lu\n"
-                        "    notify_duation_max: %lu.%06lu\n"
-                        "    notify_count: %u\n",
-                   tv.tv_sec, tv.tv_usec,
-                   tv_max.tv_sec, tv_max.tv_usec,
-                   fsdb->fsdb_notify_count);
+       seq_printf(seq, "    notify_duration_total: %lld.%09ld\n"
+                       "    notify_duation_max: %lld.%09ld\n"
+                       "    notify_count: %u\n",
+                  (s64)ts.tv_sec, ts.tv_nsec,
+                  (s64)ts_max.tv_sec, ts_max.tv_nsec,
+                  fsdb->fsdb_notify_count);
 
-        return 0;
+       return 0;
 }
 
 int lprocfs_ir_timeout_seq_show(struct seq_file *m, void *data)
 {
-       return lprocfs_uint_seq_show(m, &ir_timeout);
+       seq_printf(m, "%lld\n", ir_timeout);
+       return 0;
 }
 
 ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
                                     const char __user *buffer,
                                     size_t count, loff_t *off)
 {
-        return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
+       return kstrtoll_from_user(buffer, count, 0, &ir_timeout);
 }
 
 /* --------------- Handle non IR support clients --------------- */
@@ -840,9 +847,9 @@ ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
                   char *fsname)
 {
-        struct mgs_export_data *data = &exp->u.eu_mgs_data;
+       struct mgs_export_data *data = &exp->u.eu_mgs_data;
        struct mgs_device *mgs = exp2mgs_dev(exp);
-        struct fs_db      *fsdb;
+       struct fs_db *fsdb = NULL;
         struct mgs_fsc    *fsc     = NULL;
         struct mgs_fsc    *new_fsc = NULL;
         bool               found   = false;
@@ -855,8 +862,8 @@ int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
 
         /* allocate a new fsc in case we need it in spinlock. */
         OBD_ALLOC_PTR(new_fsc);
-        if (new_fsc == NULL)
-                RETURN(-ENOMEM);
+       if (!new_fsc)
+               GOTO(out, rc = -ENOMEM);
 
        INIT_LIST_HEAD(&new_fsc->mfc_export_list);
        INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
@@ -899,7 +906,10 @@ int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
                 class_export_put(new_fsc->mfc_export);
                 OBD_FREE_PTR(new_fsc);
         }
-        RETURN(rc);
+
+out:
+       mgs_put_fsdb(mgs, fsdb);
+       RETURN(rc);
 }
 
 void mgs_fsc_cleanup(struct obd_export *exp)