Whamcloud - gitweb
LU-12043 llite: switch to use ll_fsname directly
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index eeb3ad1..c177569 100644 (file)
 static struct kobject *llite_kobj;
 static struct dentry *llite_root;
 
+static void llite_kobj_release(struct kobject *kobj)
+{
+       if (!IS_ERR_OR_NULL(llite_root)) {
+               debugfs_remove(llite_root);
+               llite_root = NULL;
+       }
+
+       kfree(kobj);
+}
+
+static struct kobj_type llite_kobj_ktype = {
+       .release        = llite_kobj_release,
+       .sysfs_ops      = &lustre_sysfs_ops,
+};
+
 int llite_tunables_register(void)
 {
-       int rc = 0;
+       int rc;
 
-       llite_kobj = class_setup_tunables("llite");
-       if (IS_ERR(llite_kobj))
-               return PTR_ERR(llite_kobj);
+       llite_kobj = kzalloc(sizeof(*llite_kobj), GFP_KERNEL);
+       if (!llite_kobj)
+               return -ENOMEM;
+
+       llite_kobj->kset = lustre_kset;
+       rc = kobject_init_and_add(llite_kobj, &llite_kobj_ktype,
+                                 &lustre_kset->kobj, "%s", "llite");
+       if (rc)
+               goto free_kobj;
 
        llite_root = debugfs_create_dir("llite", debugfs_lustre_root);
        if (IS_ERR_OR_NULL(llite_root)) {
                rc = llite_root ? PTR_ERR(llite_root) : -ENOMEM;
                llite_root = NULL;
+free_kobj:
                kobject_put(llite_kobj);
                llite_kobj = NULL;
        }
@@ -67,15 +89,8 @@ int llite_tunables_register(void)
 
 void llite_tunables_unregister(void)
 {
-       if (llite_kobj) {
-               kobject_put(llite_kobj);
-               llite_kobj = NULL;
-       }
-
-       if (!IS_ERR_OR_NULL(llite_root)) {
-               debugfs_remove(llite_root);
-               llite_root = NULL;
-       }
+       kobject_put(llite_kobj);
+       llite_kobj = NULL;
 }
 
 /* <debugfs>/lustre/llite mount point registration */
@@ -341,7 +356,7 @@ ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
        if (pages_number < 0 || pages_number > totalram_pages / 2) {
                /* 1/2 of RAM */
                CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
-                      ll_get_fsname(sb, NULL, 0),
+                      sbi->ll_fsname,
                       (unsigned long)pages_number >> (20 - PAGE_SHIFT),
                       totalram_pages >> (20 - PAGE_SHIFT + 1));
                return -ERANGE;
@@ -390,7 +405,7 @@ ll_max_readahead_per_file_mb_seq_write(struct file *file,
 
        if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
                CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
-                      "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
+                      "max_read_ahead_mb=%lu\n", sbi->ll_fsname,
                       (unsigned long)pages_number >> (20 - PAGE_SHIFT),
                       sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
                return -ERANGE;
@@ -444,7 +459,7 @@ ll_max_read_ahead_whole_mb_seq_write(struct file *file,
                int pages_shift = 20 - PAGE_SHIFT;
                CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
                       "max_read_ahead_per_file_mb=%lu\n",
-                      ll_get_fsname(sb, NULL, 0),
+                      sbi->ll_fsname,
                       (unsigned long)pages_number >> pages_shift,
                       sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
                return -ERANGE;
@@ -517,7 +532,7 @@ static ssize_t ll_max_cached_mb_seq_write(struct file *file,
 
        if (pages_number < 0 || pages_number > totalram_pages) {
                CERROR("%s: can't set max cache more than %lu MB\n",
-                      ll_get_fsname(sb, NULL, 0),
+                      sbi->ll_fsname,
                       totalram_pages >> (20 - PAGE_SHIFT));
                RETURN(-ERANGE);
        }
@@ -964,7 +979,7 @@ static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
        while (flags != 0) {
                if (ARRAY_SIZE(str) <= i) {
                        CERROR("%s: Revise array LL_SBI_FLAGS to match sbi "
-                               "flags please.\n", ll_get_fsname(sb, NULL, 0));
+                               "flags please.\n", ll_s2sbi(sb)->ll_fsname);
                        return -EINVAL;
                }
 
@@ -1083,20 +1098,21 @@ static ssize_t fast_read_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(fast_read);
 
-static ssize_t pio_show(struct kobject *kobj,
-                       struct attribute *attr,
-                       char *buf)
+static ssize_t file_heat_show(struct kobject *kobj,
+                             struct attribute *attr,
+                             char *buf)
 {
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
 
-       return sprintf(buf, "%u\n", !!(sbi->ll_flags & LL_SBI_PIO));
+       return snprintf(buf, PAGE_SIZE, "%u\n",
+                       !!(sbi->ll_flags & LL_SBI_FILE_HEAT));
 }
 
-static ssize_t pio_store(struct kobject *kobj,
-                        struct attribute *attr,
-                        const char *buffer,
-                        size_t count)
+static ssize_t file_heat_store(struct kobject *kobj,
+                              struct attribute *attr,
+                              const char *buffer,
+                              size_t count)
 {
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
@@ -1109,14 +1125,81 @@ static ssize_t pio_store(struct kobject *kobj,
 
        spin_lock(&sbi->ll_lock);
        if (val)
-               sbi->ll_flags |= LL_SBI_PIO;
+               sbi->ll_flags |= LL_SBI_FILE_HEAT;
        else
-               sbi->ll_flags &= ~LL_SBI_PIO;
+               sbi->ll_flags &= ~LL_SBI_FILE_HEAT;
        spin_unlock(&sbi->ll_lock);
 
        return count;
 }
-LUSTRE_RW_ATTR(pio);
+LUSTRE_RW_ATTR(file_heat);
+
+static ssize_t heat_decay_percentage_show(struct kobject *kobj,
+                                         struct attribute *attr,
+                                         char *buf)
+{
+       struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
+                                             ll_kset.kobj);
+
+       return snprintf(buf, PAGE_SIZE, "%u\n",
+                      (sbi->ll_heat_decay_weight * 100 + 128) / 256);
+}
+
+static ssize_t heat_decay_percentage_store(struct kobject *kobj,
+                                          struct attribute *attr,
+                                          const char *buffer,
+                                          size_t count)
+{
+       struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
+                                             ll_kset.kobj);
+       unsigned long val;
+       int rc;
+
+       rc = kstrtoul(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       if (val < 0 || val > 100)
+               return -ERANGE;
+
+       sbi->ll_heat_decay_weight = (val * 256 + 50) / 100;
+
+       return count;
+}
+LUSTRE_RW_ATTR(heat_decay_percentage);
+
+static ssize_t heat_period_second_show(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      char *buf)
+{
+       struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
+                                             ll_kset.kobj);
+
+       return snprintf(buf, PAGE_SIZE, "%u\n", sbi->ll_heat_period_second);
+}
+
+static ssize_t heat_period_second_store(struct kobject *kobj,
+                                       struct attribute *attr,
+                                       const char *buffer,
+                                       size_t count)
+{
+       struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
+                                             ll_kset.kobj);
+       unsigned long val;
+       int rc;
+
+       rc = kstrtoul(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       if (val <= 0)
+               return -ERANGE;
+
+       sbi->ll_heat_period_second = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(heat_period_second);
 
 static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
 {
@@ -1190,8 +1273,7 @@ static ssize_t ll_root_squash_seq_write(struct file *file,
        struct ll_sb_info *sbi = ll_s2sbi(sb);
        struct root_squash_info *squash = &sbi->ll_squash;
 
-       return lprocfs_wr_root_squash(buffer, count, squash,
-                                     ll_get_fsname(sb, NULL, 0));
+       return lprocfs_wr_root_squash(buffer, count, squash, sbi->ll_fsname);
 }
 
 LDEBUGFS_SEQ_FOPS(ll_root_squash);
@@ -1227,8 +1309,7 @@ static ssize_t ll_nosquash_nids_seq_write(struct file *file,
        struct root_squash_info *squash = &sbi->ll_squash;
        int rc;
 
-       rc = lprocfs_wr_nosquash_nids(buffer, count, squash,
-                                     ll_get_fsname(sb, NULL, 0));
+       rc = lprocfs_wr_nosquash_nids(buffer, count, squash, sbi->ll_fsname);
        if (rc < 0)
                return rc;
 
@@ -1289,22 +1370,24 @@ static struct attribute *llite_attrs[] = {
        &lustre_attr_default_easize.attr,
        &lustre_attr_xattr_cache.attr,
        &lustre_attr_fast_read.attr,
-       &lustre_attr_pio.attr,
        &lustre_attr_tiny_write.attr,
+       &lustre_attr_file_heat.attr,
+       &lustre_attr_heat_decay_percentage.attr,
+       &lustre_attr_heat_period_second.attr,
        NULL,
 };
 
-static void llite_kobj_release(struct kobject *kobj)
+static void sbi_kobj_release(struct kobject *kobj)
 {
        struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
                                              ll_kset.kobj);
        complete(&sbi->ll_kobj_unregister);
 }
 
-static struct kobj_type llite_ktype = {
+static struct kobj_type sbi_ktype = {
        .default_attrs  = llite_attrs,
        .sysfs_ops      = &lustre_sysfs_ops,
-       .release        = llite_kobj_release,
+       .release        = sbi_kobj_release,
 };
 
 static const struct llite_file_opcode {
@@ -1479,7 +1562,7 @@ int ll_debugfs_register_super(struct super_block *sb, const char *name)
 out_ll_kset:
        /* Yes we also register sysfs mount kset here as well */
        sbi->ll_kset.kobj.parent = llite_kobj;
-       sbi->ll_kset.kobj.ktype = &llite_ktype;
+       sbi->ll_kset.kobj.ktype = &sbi_ktype;
        init_completion(&sbi->ll_kobj_unregister);
        err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name);
        if (err)