Whamcloud - gitweb
LU-14286 osd-ldiskfs: fallocate with unwritten extents
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_lproc.c
index 082816b..97efb36 100644 (file)
@@ -285,7 +285,7 @@ static ssize_t read_cache_enable_store(struct kobject *kobj,
        if (rc)
                return rc;
 
-       osd->od_read_cache = val;
+       osd->od_read_cache = !!val;
        return count;
 }
 LUSTRE_RW_ATTR(read_cache_enable);
@@ -324,11 +324,58 @@ static ssize_t writethrough_cache_enable_store(struct kobject *kobj,
        if (rc)
                return rc;
 
-       osd->od_writethrough_cache = val;
+       osd->od_writethrough_cache = !!val;
        return count;
 }
 LUSTRE_RW_ATTR(writethrough_cache_enable);
 
+static ssize_t fallocate_zero_blocks_show(struct kobject *kobj,
+                                         struct attribute *attr,
+                                         char *buf)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osd_device *osd = osd_dt_dev(dt);
+
+       LASSERT(osd);
+       if (unlikely(!osd->od_mnt))
+               return -EINPROGRESS;
+
+       return scnprintf(buf, PAGE_SIZE, "%d\n", osd->od_fallocate_zero_blocks);
+}
+
+/*
+ * Set how fallocate() interacts with the backing filesystem:
+ * -1: fallocate is disabled and returns -EOPNOTSUPP
+ *  0: fallocate allocates unwritten extents (like ext4)
+ *  1: fallocate zeroes allocated extents on disk
+ */
+static ssize_t fallocate_zero_blocks_store(struct kobject *kobj,
+                                          struct attribute *attr,
+                                          const char *buffer, size_t count)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osd_device *osd = osd_dt_dev(dt);
+       long val;
+       int rc;
+
+       LASSERT(osd);
+       if (unlikely(!osd->od_mnt))
+               return -EINPROGRESS;
+
+       rc = kstrtol(buffer, 0, &val);
+       if (rc)
+               return rc;
+
+       if (val < -1 || val > 1)
+               return -EINVAL;
+
+       osd->od_fallocate_zero_blocks = val;
+       return count;
+}
+LUSTRE_RW_ATTR(fallocate_zero_blocks);
+
 ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
                         const char *buffer, size_t count)
 {
@@ -792,7 +839,7 @@ ssize_t index_backup_store(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_RW_ATTR(index_backup);
 
-struct lprocfs_vars lprocfs_osd_obd_vars[] = {
+struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
        { .name =       "oi_scrub",
          .fops =       &ldiskfs_osd_oi_scrub_fops      },
        { .name =       "readcache_max_filesize",
@@ -809,6 +856,7 @@ static struct attribute *ldiskfs_attrs[] = {
        &lustre_attr_writethrough_cache_enable.attr,
        &lustre_attr_fstype.attr,
        &lustre_attr_mntdev.attr,
+       &lustre_attr_fallocate_zero_blocks.attr,
        &lustre_attr_force_sync.attr,
        &lustre_attr_nonrotational.attr,
        &lustre_attr_index_backup.attr,
@@ -834,14 +882,14 @@ int osd_procfs_init(struct osd_device *osd, const char *name)
        LASSERT(name);
        LASSERT(type);
 
-       LCONSOLE_INFO("osd-ldiskfs create tunables for %s\n", name);
+       CDEBUG(D_CONFIG, "%s: register osd-ldiskfs tunable parameters\n", name);
 
        /* put reference taken by class_search_type */
        kobject_put(&type->typ_kobj);
 
        osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
        rc = dt_tunables_init(&osd->od_dt_dev, type, name,
-                             lprocfs_osd_obd_vars);
+                             ldebugfs_osd_obd_vars);
        if (rc) {
                CERROR("%s: cannot setup sysfs / debugfs entry: %d\n",
                       name, rc);