Whamcloud - gitweb
LU-10629 lod: Clear OST pool with setstripe
[fs/lustre-release.git] / lustre / osp / lproc_osp.c
index d315147..03a03db 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) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -75,21 +75,19 @@ osp_active_seq_write(struct file *file, const char __user *buffer,
 {
        struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
+       bool val;
        int rc;
-       __s64 val;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtobool_from_user(buffer, count, &val);
        if (rc)
                return rc;
-       if (val < 0 || val > 1)
-               return -ERANGE;
 
        LPROCFS_CLIMP_CHECK(dev);
        /* opposite senses */
        if (dev->u.cli.cl_import->imp_deactive == val)
                rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
        else
-               CDEBUG(D_CONFIG, "activate %lld: ignoring repeat request\n",
+               CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n",
                       val);
 
        LPROCFS_CLIMP_EXIT(dev);
@@ -105,7 +103,7 @@ LPROC_SEQ_FOPS(osp_active);
  * \retval             0 on success
  * \retval             negative number on error
  */
-static int osp_syn_in_flight_seq_show(struct seq_file *m, void *data)
+static int osp_sync_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device       *dev = m->private;
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
@@ -113,10 +111,10 @@ static int osp_syn_in_flight_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%u\n", atomic_read(&osp->opd_syn_rpc_in_flight));
+       seq_printf(m, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_flight));
        return 0;
 }
-LPROC_SEQ_FOPS_RO(osp_syn_in_flight);
+LPROC_SEQ_FOPS_RO(osp_sync_rpcs_in_flight);
 
 /**
  * Show number of RPCs in processing (including uncommitted by OST)
@@ -126,7 +124,7 @@ LPROC_SEQ_FOPS_RO(osp_syn_in_flight);
  * \retval             0 on success
  * \retval             negative number on error
  */
-static int osp_syn_in_prog_seq_show(struct seq_file *m, void *data)
+static int osp_sync_rpcs_in_progress_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device       *dev = m->private;
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
@@ -134,10 +132,10 @@ static int osp_syn_in_prog_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%u\n", atomic_read(&osp->opd_syn_rpc_in_progress));
+       seq_printf(m, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_progress));
        return 0;
 }
-LPROC_SEQ_FOPS_RO(osp_syn_in_prog);
+LPROC_SEQ_FOPS_RO(osp_sync_rpcs_in_progress);
 
 /**
  * Show number of changes to sync
@@ -147,7 +145,7 @@ LPROC_SEQ_FOPS_RO(osp_syn_in_prog);
  * \retval             0 on success
  * \retval             negative number on error
  */
-static int osp_syn_changes_seq_show(struct seq_file *m, void *data)
+static int osp_sync_changes_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device       *dev = m->private;
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
@@ -155,7 +153,7 @@ static int osp_syn_changes_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%u\n", atomic_read(&osp->opd_syn_changes));
+       seq_printf(m, "%u\n", atomic_read(&osp->opd_sync_changes));
        return 0;
 }
 
@@ -169,7 +167,7 @@ static int osp_syn_changes_seq_show(struct seq_file *m, void *data)
  * \retval             \a count on success
  * \retval             negative number on error
  */
-static ssize_t osp_syn_changes_seq_write(struct file *file,
+static ssize_t osp_sync_changes_seq_write(struct file *file,
                                         const char __user *buffer,
                                         size_t count, loff_t *off)
 {
@@ -188,7 +186,7 @@ static ssize_t osp_syn_changes_seq_write(struct file *file,
 
        return rc == 0 ? count : rc;
 }
-LPROC_SEQ_FOPS(osp_syn_changes);
+LPROC_SEQ_FOPS(osp_sync_changes);
 
 /**
  * Show maximum number of RPCs in flight allowed
@@ -206,7 +204,7 @@ static int osp_max_rpcs_in_flight_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_flight);
+       seq_printf(m, "%u\n", osp->opd_sync_max_rpcs_in_flight);
        return 0;
 }
 
@@ -227,20 +225,20 @@ osp_max_rpcs_in_flight_seq_write(struct file *file, const char __user *buffer,
        struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
+       unsigned int val;
        int rc;
-       __s64 val;
 
        if (osp == NULL)
                return -EINVAL;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtouint_from_user(buffer, count, 0, &val);
        if (rc)
                return rc;
 
-       if (val < 1 || val > INT_MAX)
+       if (val == 0)
                return -ERANGE;
 
-       osp->opd_syn_max_rpc_in_flight = val;
+       osp->opd_sync_max_rpcs_in_flight = val;
        return count;
 }
 LPROC_SEQ_FOPS(osp_max_rpcs_in_flight);
@@ -253,7 +251,7 @@ LPROC_SEQ_FOPS(osp_max_rpcs_in_flight);
  * \retval             0 on success
  * \retval             negative number on error
  */
-static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
+static int osp_max_rpcs_in_progress_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device       *dev = m->private;
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
@@ -261,7 +259,7 @@ static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%u\n", osp->opd_syn_max_rpc_in_progress);
+       seq_printf(m, "%u\n", osp->opd_sync_max_rpcs_in_progress);
        return 0;
 }
 
@@ -276,30 +274,30 @@ static int osp_max_rpcs_in_prog_seq_show(struct seq_file *m, void *data)
  * \retval             negative number on error
  */
 static ssize_t
-osp_max_rpcs_in_prog_seq_write(struct file *file, const char __user *buffer,
-                               size_t count, loff_t *off)
+osp_max_rpcs_in_progress_seq_write(struct file *file, const char __user *buffer,
+                                  size_t count, loff_t *off)
 {
        struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
+       unsigned int val;
        int rc;
-       __s64 val;
 
        if (osp == NULL)
                return -EINVAL;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtouint_from_user(buffer, count, 0, &val);
        if (rc)
                return rc;
 
-       if (val < 1 || val > INT_MAX)
+       if (val == 0)
                return -ERANGE;
 
-       osp->opd_syn_max_rpc_in_progress = val;
+       osp->opd_sync_max_rpcs_in_progress = val;
 
        return count;
 }
-LPROC_SEQ_FOPS(osp_max_rpcs_in_prog);
+LPROC_SEQ_FOPS(osp_max_rpcs_in_progress);
 
 /**
  * Show number of objects to precreate next time
@@ -338,13 +336,13 @@ osp_create_count_seq_write(struct file *file, const char __user *buffer,
        struct seq_file *m = file->private_data;
        struct obd_device *obd = m->private;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       unsigned int val;
        int rc, i;
-       __s64 val;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtouint_from_user(buffer, count, 0, &val);
        if (rc)
                return rc;
 
@@ -408,13 +406,13 @@ osp_max_create_count_seq_write(struct file *file, const char __user *buffer,
        struct seq_file *m = file->private_data;
        struct obd_device *obd = m->private;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       unsigned int val;
        int rc;
-       __s64 val;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtouint_from_user(buffer, count, 0, &val);
        if (rc)
                return rc;
 
@@ -444,11 +442,22 @@ static int osp_prealloc_next_id_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct lu_fid *fid;
+       __u64 id;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_used_fid) + 1);
+       fid = &osp->opd_pre_used_fid;
+       if (fid_is_idif(fid)) {
+               id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
+               id++;
+       } else {
+               id = unlikely(fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH) ?
+                       1 : fid_oid(fid) + 1;
+       }
+
+       seq_printf(m, "%llu\n", id);
        return 0;
 }
 LPROC_SEQ_FOPS_RO(osp_prealloc_next_id);
@@ -465,11 +474,17 @@ static int osp_prealloc_last_id_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct lu_fid *fid;
+       __u64 id;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return 0;
+       fid = &osp->opd_pre_last_created_fid;
+       id = fid_is_idif(fid) ?
+                        fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
+                        fid_oid(fid);
 
-       seq_printf(m, "%u\n", fid_oid(&osp->opd_pre_last_created_fid));
+       seq_printf(m, "%llu\n", id);
        return 0;
 }
 LPROC_SEQ_FOPS_RO(osp_prealloc_last_id);
@@ -486,11 +501,15 @@ static int osp_prealloc_next_seq_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct lu_fid *fid;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       seq_printf(m, "%#llx\n", fid_seq(&osp->opd_pre_used_fid));
+       fid = &osp->opd_pre_used_fid;
+       seq_printf(m, "%#llx\n", fid_is_idif(fid) ?
+                  fid_seq(fid) & (~0xffff) : fid_seq(fid));
+
        return 0;
 }
 LPROC_SEQ_FOPS_RO(osp_prealloc_next_seq);
@@ -507,12 +526,15 @@ static int osp_prealloc_last_seq_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct lu_fid *fid;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       seq_printf(m, "%#llx\n",
-                  fid_seq(&osp->opd_pre_last_created_fid));
+       fid = &osp->opd_pre_last_created_fid;
+       seq_printf(m, "%#llx\n", fid_is_idif(fid) ?
+                  fid_seq(fid) & (~0xffff) : fid_seq(fid));
+
        return 0;
 }
 LPROC_SEQ_FOPS_RO(osp_prealloc_last_seq);
@@ -554,7 +576,7 @@ static int osp_maxage_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%u\n", osp->opd_statfs_maxage);
+       seq_printf(m, "%lld\n", osp->opd_statfs_maxage);
        return 0;
 }
 
@@ -575,17 +597,17 @@ osp_maxage_seq_write(struct file *file, const char __user *buffer,
        struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
+       unsigned int val;
        int rc;
-       __s64 val;
 
        if (osp == NULL)
                return -EINVAL;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtouint_from_user(buffer, count, 0, &val);
        if (rc)
                return rc;
 
-       if (val < 1 || val > INT_MAX)
+       if (val == 0)
                return -ERANGE;
 
        osp->opd_statfs_maxage = val;
@@ -640,8 +662,8 @@ static int osp_destroys_in_flight_seq_show(struct seq_file *m, void *data)
                return -EINVAL;
 
        seq_printf(m, "%u\n",
-                  atomic_read(&osp->opd_syn_rpc_in_progress) +
-                  atomic_read(&osp->opd_syn_changes));
+                  atomic_read(&osp->opd_sync_rpcs_in_progress) +
+                  atomic_read(&osp->opd_sync_changes));
        return 0;
 }
 LPROC_SEQ_FOPS_RO(osp_destroys_in_flight);
@@ -662,7 +684,7 @@ static int osp_old_sync_processed_seq_show(struct seq_file *m, void *data)
        if (osp == NULL)
                return -EINVAL;
 
-       seq_printf(m, "%d\n", osp->opd_syn_prev_done);
+       seq_printf(m, "%d\n", osp->opd_sync_prev_done);
        return 0;
 }
 LPROC_SEQ_FOPS_RO(osp_old_sync_processed);
@@ -703,42 +725,24 @@ osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file,
 {
        struct seq_file   *m = file->private_data;
        struct obd_device *dev = m->private;
-       __s64 val;
+       unsigned int val;
        int rc;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
-       if (rc == 0) {
-               if (val < 0)
-                       return -ERANGE;
-
+       rc = kstrtouint_from_user(buffer, count, 0, &val);
+       if (!rc)
                rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
-       } else {
+       else
                count = rc;
-       }
 
        return count;
 }
 LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight);
 
-LPROC_SEQ_FOPS_WO_TYPE(osp, ping);
-LPROC_SEQ_FOPS_RO_TYPE(osp, uuid);
+LPROC_SEQ_FOPS_WR_ONLY(osp, ping);
 LPROC_SEQ_FOPS_RO_TYPE(osp, connect_flags);
 LPROC_SEQ_FOPS_RO_TYPE(osp, server_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osp, conn_uuid);
 
-/**
- * Show maximum pages per bulk RPC
- *
- * \param[in] m                seq_file handle
- * \param[in] data     unused for single entry
- * \retval             0 on success
- * \retval             negative number on error
- */
-static int osp_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
-{
-       return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
-}
-LPROC_SEQ_FOPS_RO(osp_max_pages_per_rpc);
 LPROC_SEQ_FOPS_RO_TYPE(osp, timeouts);
 
 LPROC_SEQ_FOPS_RW_TYPE(osp, import);
@@ -864,9 +868,27 @@ osp_reserved_mb_low_seq_write(struct file *file, const char __user *buffer,
 }
 LPROC_SEQ_FOPS(osp_reserved_mb_low);
 
+static ssize_t
+lprocfs_force_sync_seq_write(struct file *file, const char __user *buffer,
+                            size_t count, loff_t *off)
+{
+       struct seq_file   *m = file->private_data;
+       struct obd_device *dev = m->private;
+       struct dt_device  *dt = lu2dt_dev(dev->obd_lu_dev);
+       struct lu_env      env;
+       int                rc;
+
+       rc = lu_env_init(&env, LCT_LOCAL);
+       if (rc)
+               return rc;
+       rc = dt_sync(&env, dt);
+       lu_env_fini(&env);
+
+       return rc == 0 ? count : rc;
+}
+LPROC_SEQ_FOPS_WR_ONLY(osp, force_sync);
+
 static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &osp_uuid_fops                  },
        { .name =       "ping",
          .fops =       &osp_ping_fops,
          .proc_mode =  0222                            },
@@ -881,7 +903,7 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
        { .name =       "max_rpcs_in_flight",
          .fops =       &osp_max_rpcs_in_flight_fops    },
        { .name =       "max_rpcs_in_progress",
-         .fops =       &osp_max_rpcs_in_prog_fops      },
+         .fops =       &osp_max_rpcs_in_progress_fops  },
        { .name =       "create_count",
          .fops =       &osp_create_count_fops          },
        { .name =       "max_create_count",
@@ -907,17 +929,19 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
        { .name =       "prealloc_status",
          .fops =       &osp_pre_status_fops            },
        { .name =       "sync_changes",
-         .fops =       &osp_syn_changes_fops           },
+         .fops =       &osp_sync_changes_fops          },
        { .name =       "sync_in_flight",
-         .fops =       &osp_syn_in_flight_fops         },
+         .fops =       &osp_sync_rpcs_in_flight_fops   },
        { .name =       "sync_in_progress",
-         .fops =       &osp_syn_in_prog_fops           },
+         .fops =       &osp_sync_rpcs_in_progress_fops },
        { .name =       "old_sync_processed",
          .fops =       &osp_old_sync_processed_fops    },
        { .name =       "reserved_mb_high",
          .fops =       &osp_reserved_mb_high_fops      },
        { .name =       "reserved_mb_low",
          .fops =       &osp_reserved_mb_low_fops       },
+       { .name =       "force_sync",
+         .fops =       &osp_force_sync_fops    },
 
        /* for compatibility reasons */
        { .name =       "destroys_in_flight",
@@ -928,8 +952,6 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
 };
 
 static struct lprocfs_vars lprocfs_osp_md_vars[] = {
-       { .name =       "uuid",
-         .fops =       &osp_uuid_fops                  },
        { .name =       "ping",
          .fops =       &osp_ping_fops,
          .proc_mode =  0222                            },
@@ -944,7 +966,7 @@ static struct lprocfs_vars lprocfs_osp_md_vars[] = {
        { .name =       "max_rpcs_in_flight",
          .fops =       &osp_max_rpcs_in_flight_fops    },
        { .name =       "max_rpcs_in_progress",
-         .fops =       &osp_max_rpcs_in_prog_fops      },
+         .fops =       &osp_max_rpcs_in_progress_fops  },
        { .name =       "timeouts",
          .fops =       &osp_timeouts_fops              },
        { .name =       "import",
@@ -987,6 +1009,25 @@ static struct lprocfs_vars lprocfs_osp_osd_vars[] = {
        { NULL }
 };
 
+void osp_lprocfs_fini(struct osp_device *osp)
+{
+       struct obd_device *obd = osp->opd_obd;
+       struct kobject *osc;
+
+       osc = kset_find_obj(lustre_kset, "osc");
+       if (osc) {
+               sysfs_remove_link(osc, obd->obd_name);
+               kobject_put(osc);
+       }
+
+       if (!IS_ERR_OR_NULL(osp->opd_debugfs))
+               ldebugfs_remove(&osp->opd_debugfs);
+
+       ptlrpc_lprocfs_unregister_obd(obd);
+       if (osp->opd_symlink)
+               lprocfs_remove(&osp->opd_symlink);
+}
+
 /**
  * Initialize OSP lprocfs
  *
@@ -994,16 +1035,17 @@ static struct lprocfs_vars lprocfs_osp_osd_vars[] = {
  */
 void osp_lprocfs_init(struct osp_device *osp)
 {
-       struct obd_device       *obd = osp->opd_obd;
-       struct proc_dir_entry   *osc_proc_dir = NULL;
-       struct obd_type         *type;
-       int                      rc;
+       struct obd_device *obd = osp->opd_obd;
+       struct proc_dir_entry *osc_proc_dir = NULL;
+       struct obd_type *type;
+       struct kobject *osc;
+       int rc;
 
        if (osp->opd_connect_mdt)
                obd->obd_vars = lprocfs_osp_md_vars;
        else
                obd->obd_vars = lprocfs_osp_obd_vars;
-       if (lprocfs_obd_setup(obd) != 0)
+       if (lprocfs_obd_setup(obd, true) != 0)
                return;
 
        rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_osd_vars,
@@ -1022,6 +1064,23 @@ void osp_lprocfs_init(struct osp_device *osp)
 
        /* If the real OSC is present which is the case for setups
         * with both server and clients on the same node then use
+        * the OSC's proc root
+        */
+       osc = kset_find_obj(lustre_kset, "osc");
+       if (osc) {
+               rc = sysfs_create_link(osc, &obd->obd_kset.kobj,
+                                      obd->obd_name);
+               kobject_put(osc);
+       }
+
+       osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
+                                               "../osp/%s", obd->obd_name);
+       if (!osp->opd_debugfs)
+               CERROR("%s: failed to create OSC debugfs symlink\n",
+                      obd->obd_name);
+
+       /* If the real OSC is present which is the case for setups
+        * with both server and clients on the same node then use
         * the OSC's proc root */
        type = class_search_type(LUSTRE_OSC_NAME);
        if (type != NULL && type->typ_procroot != NULL)