Whamcloud - gitweb
LU-8066 obd_type: discard obd_types linked list.
[fs/lustre-release.git] / lustre / mdd / mdd_lproc.c
index d17d3c9..829afc7 100644 (file)
@@ -430,8 +430,8 @@ static ssize_t changelog_deniednext_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(changelog_deniednext);
 
-static ssize_t sync_perm_show(struct kobject *kobj, struct attribute *attr,
-                             char *buf)
+static ssize_t sync_permission_show(struct kobject *kobj,
+                                   struct attribute *attr, char *buf)
 {
        struct mdd_device *mdd = container_of(kobj, struct mdd_device,
                                              mdd_kobj);
@@ -439,8 +439,9 @@ static ssize_t sync_perm_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%d\n", mdd->mdd_sync_permission);
 }
 
-static ssize_t sync_perm_store(struct kobject *kobj, struct attribute *attr,
-                              const char *buffer, size_t count)
+static ssize_t sync_permission_store(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    const char *buffer, size_t count)
 {
        struct mdd_device *mdd = container_of(kobj, struct mdd_device,
                                              mdd_kobj);
@@ -455,7 +456,7 @@ static ssize_t sync_perm_store(struct kobject *kobj, struct attribute *attr,
 
        return count;
 }
-LUSTRE_RW_ATTR(sync_perm);
+LUSTRE_RW_ATTR(sync_permission);
 
 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
                                      struct attribute *attr, char *buf)
@@ -532,6 +533,117 @@ static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
 }
 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_layout);
 
+/**
+ * Show default number of stripes for O_APPEND files.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success,
+ * \retval negative    error code if failed
+ */
+static ssize_t append_stripe_count_show(struct kobject *kobj,
+                                       struct attribute *attr, char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", mdd->mdd_append_stripe_count);
+}
+
+/**
+ * Set default number of stripes for O_APPEND files.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the default number of stripes
+ *                     for new files
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code otherwise
+ */
+static ssize_t append_stripe_count_store(struct kobject *kobj,
+                                        struct attribute *attr,
+                                        const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       int stripe_count;
+       int rc;
+
+       rc = kstrtoint(buffer, 0, &stripe_count);
+       if (rc)
+               return rc;
+
+       if (stripe_count < -1)
+               return -ERANGE;
+
+       mdd->mdd_append_stripe_count = stripe_count;
+
+       return count;
+}
+LUSTRE_RW_ATTR(append_stripe_count);
+
+/**
+ * Show default OST pool for O_APPEND files.
+ *
+ * \param[in] kobject  proc object
+ * \param[in] attribute proc attribute
+ * \param[in] buf      output buffer
+ *
+ * \retval 0           on success,
+ * \retval negative    error code if failed
+ */
+static ssize_t append_pool_show(struct kobject *kobj,
+                               struct attribute *attr, char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return snprintf(buf, LOV_MAXPOOLNAME + 1, "%s\n", mdd->mdd_append_pool);
+}
+
+/**
+ * Set default OST pool for O_APPEND files.
+ *
+ * \param[in] kobject  proc object
+ * \param[in] attribute proc attribute
+ * \param[in] buffer   user inputted pool name
+ * \param[in] count    @buffer length
+ *
+ * \retval @count      on success
+ * \retval negative    error code otherwise
+ */
+static ssize_t append_pool_store(struct kobject *kobj, struct attribute *attr,
+                                const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       if (!count || count > LOV_MAXPOOLNAME + 1)
+               return -EINVAL;
+
+       /* clear previous value */
+       memset(mdd->mdd_append_pool, 0, LOV_MAXPOOLNAME + 1);
+
+       /* entering "none" clears the pool, otherwise copy the new pool */
+       if (strncmp("none", buffer, 4)) {
+               memcpy(mdd->mdd_append_pool, buffer, count);
+
+               /* Trim the trailing '\n' if any */
+               if (mdd->mdd_append_pool[count - 1] == '\n') {
+                       /* Don't echo just a newline */
+                       if (count == 1)
+                               return -EINVAL;
+                       mdd->mdd_append_pool[count - 1] = 0;
+               }
+       }
+
+       return count;
+}
+LUSTRE_RW_ATTR(append_pool);
+
 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
        { .name =       "changelog_mask",
          .fops =       &mdd_changelog_mask_fops        },
@@ -556,7 +668,9 @@ static struct attribute *mdd_attrs[] = {
        &lustre_attr_changelog_deniednext.attr,
        &lustre_attr_lfsck_async_windows.attr,
        &lustre_attr_lfsck_speed_limit.attr,
-       &lustre_attr_sync_perm.attr,
+       &lustre_attr_sync_permission.attr,
+       &lustre_attr_append_stripe_count.attr,
+       &lustre_attr_append_pool.attr,
        NULL,
 };
 
@@ -564,6 +678,10 @@ static void mdd_sysfs_release(struct kobject *kobj)
 {
        struct mdd_device *mdd = container_of(kobj, struct mdd_device,
                                              mdd_kobj);
+       struct obd_device *obd = mdd2obd_dev(mdd);
+
+       debugfs_remove_recursive(obd->obd_debugfs_entry);
+       obd->obd_debugfs_entry = NULL;
 
        complete(&mdd->mdd_kobj_unregister);
 }
@@ -584,6 +702,9 @@ int mdd_procfs_init(struct mdd_device *mdd, const char *name)
        LASSERT(type != NULL);
        LASSERT(obd  != NULL);
 
+       /* put reference taken by class_search_type */
+       kobject_put(&type->typ_kobj);
+
        mdd->mdd_ktype.default_attrs = mdd_attrs;
        mdd->mdd_ktype.release = mdd_sysfs_release;
        mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
@@ -614,11 +735,6 @@ int mdd_procfs_init(struct mdd_device *mdd, const char *name)
 
 void mdd_procfs_fini(struct mdd_device *mdd)
 {
-       struct obd_device *obd = mdd2obd_dev(mdd);
-
        kobject_put(&mdd->mdd_kobj);
        wait_for_completion(&mdd->mdd_kobj_unregister);
-
-       if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
-               ldebugfs_remove(&obd->obd_debugfs_entry);
 }