* [PATCH 4/4] dm-latency: add reset function to dm-latency in sysfs interface
@ 2015-02-26 6:43 Coly Li
0 siblings, 0 replies; only message in thread
From: Coly Li @ 2015-02-26 6:43 UTC (permalink / raw)
To: dm-devel; +Cc: Tao Ma, Robin Dong, Laurence Oberman, Alasdair Kergon
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,
+
};
/*
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-02-26 6:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-26 6:43 [PATCH 4/4] dm-latency: add reset function to dm-latency in sysfs interface Coly Li
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.