Whamcloud - gitweb
LU-14546 tests: set smbpasswd correctly
[fs/lustre-release.git] / lustre / osp / lproc_osp.c
index 59c90e2..19a3e98 100644 (file)
@@ -55,11 +55,11 @@ static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
                                            dd_kobj);
        struct lu_device *lu = dt2lu_dev(dt);
        struct obd_device *obd = lu->ld_obd;
+       struct obd_import *imp;
        int rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
-       rc = sprintf(buf, "%d\n", !obd->u.cli.cl_import->imp_deactive);
-       LPROCFS_CLIMP_EXIT(obd);
+       with_imp_locked(obd, imp, rc)
+               rc = sprintf(buf, "%d\n", !imp->imp_deactive);
        return rc;
 }
 
@@ -80,6 +80,7 @@ static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
                                            dd_kobj);
        struct lu_device *lu = dt2lu_dev(dt);
        struct obd_device *obd = lu->ld_obd;
+       struct obd_import *imp, *imp0;
        bool val;
        int rc;
 
@@ -87,16 +88,20 @@ static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
        if (rc)
                return rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
+       with_imp_locked(obd, imp0, rc)
+               imp = class_import_get(imp0);
+       if (rc)
+               return rc;
        /* opposite senses */
-       if (obd->u.cli.cl_import->imp_deactive == val)
-               rc = ptlrpc_set_import_active(obd->u.cli.cl_import, val);
+       if (imp->imp_deactive == val)
+               rc = ptlrpc_set_import_active(imp, val);
        else
                CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
                       (unsigned int)val);
 
-       LPROCFS_CLIMP_EXIT(obd);
-       return count;
+       class_import_put(imp);
+
+       return rc ?: count;
 }
 LUSTRE_RW_ATTR(active);
 
@@ -415,14 +420,17 @@ static ssize_t max_create_count_store(struct kobject *kobj,
        if (rc)
                return rc;
 
-       if (val < 0 || val > INT_MAX)
-               return -ERANGE;
-       if (val > OST_MAX_PRECREATE)
+       if (val && (val < OST_MIN_PRECREATE ||
+                   val > OST_MAX_PRECREATE))
                return -ERANGE;
 
        if (osp->opd_pre_create_count > val)
                osp->opd_pre_create_count = val;
 
+       /* Can be 0 after setting max_create_count to 0 */
+       if (osp->opd_pre_create_count == 0 && val != 0)
+               osp->opd_pre_create_count = OST_MIN_PRECREATE;
+
        osp->opd_pre_max_create_count = val;
 
        return count;
@@ -755,9 +763,7 @@ ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
        struct obd_device *obd = lu->ld_obd;
        int rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
        rc = ptlrpc_obd_ping(obd);
-       LPROCFS_CLIMP_EXIT(obd);
 
        return rc;
 }
@@ -770,17 +776,18 @@ ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
                                            dd_kobj);
        struct lu_device *lu = dt2lu_dev(dt);
        struct obd_device *obd = lu->ld_obd;
+       struct obd_import *imp;
        struct ptlrpc_connection *conn;
        ssize_t count;
 
-       LPROCFS_CLIMP_CHECK(obd);
-       conn = obd->u.cli.cl_import->imp_connection;
-       if (conn && obd->u.cli.cl_import)
-               count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
-       else
-               count = sprintf(buf, "%s\n", "<none>");
+       with_imp_locked(obd, imp, count) {
+               conn = imp->imp_connection;
+               if (conn)
+                       count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
+               else
+                       count = sprintf(buf, "%s\n", "<none>");
+       }
 
-       LPROCFS_CLIMP_EXIT(obd);
        return count;
 }
 
@@ -791,7 +798,7 @@ LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
 
-LPROC_SEQ_FOPS_RW_TYPE(osp, import);
+LDEBUGFS_SEQ_FOPS_RW_TYPE(osp, import);
 LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
 
 /**
@@ -832,14 +839,22 @@ osp_reserved_mb_high_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);
-       __s64                   val;
+       char kernbuf[22] = "";
+       u64 val;
        int                     rc;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return -EINVAL;
 
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
-       if (rc)
+       if (count >= sizeof(kernbuf))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+       kernbuf[count] = 0;
+
+       rc = sysfs_memparse(kernbuf, count, &val, "MiB");
+       if (rc < 0)
                return rc;
        val >>= 20;
        if (val < 1)
@@ -893,14 +908,22 @@ osp_reserved_mb_low_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);
-       __s64                   val;
+       char kernbuf[22] = "";
+       u64 val;
        int                     rc;
 
        if (osp == NULL || osp->opd_pre == NULL)
                return -EINVAL;
 
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
-       if (rc)
+       if (count >= sizeof(kernbuf))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+       kernbuf[count] = 0;
+
+       rc = sysfs_memparse(kernbuf, count, &val, "MiB");
+       if (rc < 0)
                return rc;
        val >>= 20;
 
@@ -933,7 +956,7 @@ static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_WO_ATTR(force_sync);
 
-static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
+static struct ldebugfs_vars ldebugfs_osp_obd_vars[] = {
        { .name =       "connect_flags",
          .fops =       &osp_connect_flags_fops         },
        { .name =       "ost_server_uuid",
@@ -951,7 +974,7 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
        { NULL }
 };
 
-static struct lprocfs_vars lprocfs_osp_md_vars[] = {
+static struct ldebugfs_vars ldebugfs_osp_md_vars[] = {
        { .name =       "connect_flags",
          .fops =       &osp_connect_flags_fops         },
        { .name =       "mdt_server_uuid",
@@ -1016,13 +1039,13 @@ void osp_tunables_fini(struct osp_device *osp)
                kobject_put(osc);
        }
 
-       if (!IS_ERR_OR_NULL(osp->opd_debugfs))
-               ldebugfs_remove(&osp->opd_debugfs);
+       debugfs_remove_recursive(osp->opd_debugfs);
+       osp->opd_debugfs = NULL;
 
        ptlrpc_lprocfs_unregister_obd(obd);
 
-       if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
-               ldebugfs_remove(&obd->obd_debugfs_entry);
+       debugfs_remove_recursive(obd->obd_debugfs_entry);
+       obd->obd_debugfs_entry = NULL;
 
        dt_tunables_fini(&osp->opd_dt_dev);
 }
@@ -1040,10 +1063,10 @@ void osp_tunables_init(struct osp_device *osp)
 
        if (osp->opd_connect_mdt) {
                osp->opd_dt_dev.dd_ktype.default_attrs = osp_md_attrs;
-               obd->obd_vars = lprocfs_osp_md_vars;
+               obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
        } else {
                osp->opd_dt_dev.dd_ktype.default_attrs = osp_obd_attrs;
-               obd->obd_vars = lprocfs_osp_obd_vars;
+               obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
        }
 
        rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
@@ -1057,18 +1080,9 @@ void osp_tunables_init(struct osp_device *osp)
        /* Since we register the obd device with ptlrpc / sptlrpc we
         * have to register debugfs with obd_device
         */
-       obd->obd_debugfs_entry = ldebugfs_register(obd->obd_name,
-                                                  obd->obd_type->typ_debugfs_entry,
-                                                  obd->obd_vars, obd);
-       if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
-               rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
-                                           : -ENOMEM;
-               CERROR("%s: error %d setting up debugfs\n",
-                      obd->obd_name, rc);
-               obd->obd_debugfs_entry = NULL;
-               dt_tunables_fini(&osp->opd_dt_dev);
-               return;
-       }
+       obd->obd_debugfs_entry = debugfs_create_dir(
+               obd->obd_name, obd->obd_type->typ_debugfs_entry);
+       ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, obd);
 
        sptlrpc_lprocfs_cliobd_attach(obd);
        ptlrpc_lprocfs_register_obd(obd);