Linux Device Mapper development
 help / color / mirror / Atom feed
From: Coly Li <colyli@gmail.com>
To: dm-devel@redhat.com
Cc: Tao Ma <boyu.mt@taobao.com>, Robin Dong <sanbai@alibaba-inc.com>,
	Laurence Oberman <loberman@redhat.com>,
	Alasdair Kergon <agk@redhat.com>
Subject: [PATCH 4/4] dm-latency: add reset function to dm-latency in sysfs interface
Date: Thu, 26 Feb 2015 14:43:21 +0800	[thread overview]
Message-ID: <54EEC089.9000802@gmail.com> (raw)

From: Coly Li <bosong.ly@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@alibaba-inc.com>
Reviewed-by: Robin Dong <sanbai@alibaba-inc.com>
Reviewed-by: Tao Ma <boyu.mt@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,
+
  };

  /*

                 reply	other threads:[~2015-02-26  6:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54EEC089.9000802@gmail.com \
    --to=colyli@gmail.com \
    --cc=agk@redhat.com \
    --cc=boyu.mt@taobao.com \
    --cc=dm-devel@redhat.com \
    --cc=loberman@redhat.com \
    --cc=sanbai@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox