[dm-devel] [PATCH 4/4] dm-latency: add reset function to dm-latency in sysfs interface

Coly Li colyli at gmail.com
Thu Feb 26 06:43:21 UTC 2015


From: Coly Li <bosong.ly at alibaba-inc.com>

Now echo any thing into /sys/block/dm-X/dm/io_latency_reset may
reset all counters in /sys/block/dm-X/dm/io_latency_{s,ms, us} to 0.

This function might be helpful to application developers.

Signed-off-by: Coly Li <bosong.ly at alibaba-inc.com>
Reviewed-by: Robin Dong <sanbai at alibaba-inc.com>
Reviewed-by: Tao Ma <boyu.mt at taobao.com>
---
  drivers/md/dm-sysfs.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c
index eab2dde..1a4864d 100644
--- a/drivers/md/dm-sysfs.c
+++ b/drivers/md/dm-sysfs.c
@@ -12,13 +12,17 @@
  struct dm_sysfs_attr {
  	struct attribute attr;
  	ssize_t (*show)(struct mapped_device *, char *);
-	ssize_t (*store)(struct mapped_device *, char *);
+	ssize_t (*store)(struct mapped_device *, const char *, size_t len);
  };

  #define DM_ATTR_RO(_name) \
  struct dm_sysfs_attr dm_attr_##_name = \
  	__ATTR(_name, S_IRUGO, dm_attr_##_name##_show, NULL)

+#define DM_ATTR_RW(_name) \
+struct dm_sysfs_attr dm_attr_##_name = \
+	__ATTR(_name, S_IRUGO | S_IWUSR, NULL, dm_attr_##_name##_store)
+
  static ssize_t dm_attr_show(struct kobject *kobj, struct attribute *attr,
  			    char *page)
  {
@@ -40,6 +44,27 @@ static ssize_t dm_attr_show(struct kobject *kobj,
struct attribute *attr,
  	return ret;
  }

+static ssize_t dm_attr_store(struct kobject *kobj, struct attribute *attr,
+			     const char *page, size_t len)
+{
+	struct dm_sysfs_attr *dm_attr;
+	struct mapped_device *md;
+	ssize_t ret;
+
+	dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
+	if (!dm_attr->store)
+		return -EIO;
+
+	md = dm_get_from_kobject(kobj);
+	if (!md)
+		return -EINVAL;
+
+	ret = dm_attr->store(md, page, len);
+	dm_put(md);
+
+	return ret;
+}
+
  static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
  {
  	if (dm_copy_name_and_uuid(md, buf, NULL))
@@ -128,12 +153,27 @@ static ssize_t dm_attr_io_latency_s_show(struct
mapped_device *md, char *buf)
  	return strlen(buf);
  }

+static ssize_t dm_attr_io_latency_reset_store(struct mapped_device *md,
+					      const char *buf,
+					      size_t len)
+{
+	int i;
+	for (i = 0; i < DM_LATENCY_STATS_US_NR; i++)
+		atomic_set(&md->latency_stats_us[i], 0);
+	for (i = 0; i < DM_LATENCY_STATS_MS_NR; i++)
+		atomic_set(&md->latency_stats_ms[i], 0);
+	for (i = 0; i < DM_LATENCY_STATS_S_NR; i++)
+		atomic_set(&md->latency_stats_s[i], 0);
+	return len;
+}
+
  static DM_ATTR_RO(name);
  static DM_ATTR_RO(uuid);
  static DM_ATTR_RO(suspended);
  static DM_ATTR_RO(io_latency_us);
  static DM_ATTR_RO(io_latency_ms);
  static DM_ATTR_RO(io_latency_s);
+static DM_ATTR_RW(io_latency_reset);

  static struct attribute *dm_attrs[] = {
  	&dm_attr_name.attr,
@@ -142,11 +182,14 @@ static struct attribute *dm_attrs[] = {
  	&dm_attr_io_latency_us.attr,
  	&dm_attr_io_latency_ms.attr,
  	&dm_attr_io_latency_s.attr,
+	&dm_attr_io_latency_reset.attr,
  	NULL,
  };

  static const struct sysfs_ops dm_sysfs_ops = {
  	.show	= dm_attr_show,
+	.store	= dm_attr_store,
+
  };

  /*





More information about the dm-devel mailing list