aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2014-04-07 18:38:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-07 19:36:00 -0400
commita68eb3b65e658406d386bebef02277f4007b2f45 (patch)
tree26e8c5a63560e39a7a79275c4fc7a851f0922f02 /drivers/block
parent90a7806ea9b9f7cb4751859cc2506e2d80e36ef1 (diff)
zram: remove zram stats code duplication
Introduce ZRAM_ATTR_RO macro that generates device_attribute and default ATTR show() function for existing atomic64_t zram stats. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/zram/zram_drv.c82
1 files changed, 23 insertions, 59 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 1bf97b2f8f3f..29c35119e82a 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -42,6 +42,17 @@ static struct zram *zram_devices;
42/* Module params (documentation at end) */ 42/* Module params (documentation at end) */
43static unsigned int num_devices = 1; 43static unsigned int num_devices = 1;
44 44
45#define ZRAM_ATTR_RO(name) \
46static ssize_t zram_attr_##name##_show(struct device *d, \
47 struct device_attribute *attr, char *b) \
48{ \
49 struct zram *zram = dev_to_zram(d); \
50 return sprintf(b, "%llu\n", \
51 (u64)atomic64_read(&zram->stats.name)); \
52} \
53static struct device_attribute dev_attr_##name = \
54 __ATTR(name, S_IRUGO, zram_attr_##name##_show, NULL);
55
45static inline int init_done(struct zram *zram) 56static inline int init_done(struct zram *zram)
46{ 57{
47 return zram->meta != NULL; 58 return zram->meta != NULL;
@@ -63,53 +74,14 @@ static ssize_t disksize_show(struct device *dev,
63static ssize_t initstate_show(struct device *dev, 74static ssize_t initstate_show(struct device *dev,
64 struct device_attribute *attr, char *buf) 75 struct device_attribute *attr, char *buf)
65{ 76{
77 u32 val;
66 struct zram *zram = dev_to_zram(dev); 78 struct zram *zram = dev_to_zram(dev);
67 79
68 return sprintf(buf, "%u\n", init_done(zram)); 80 down_read(&zram->init_lock);
69} 81 val = init_done(zram);
70 82 up_read(&zram->init_lock);
71static ssize_t num_reads_show(struct device *dev,
72 struct device_attribute *attr, char *buf)
73{
74 struct zram *zram = dev_to_zram(dev);
75
76 return sprintf(buf, "%llu\n",
77 (u64)atomic64_read(&zram->stats.num_reads));
78}
79
80static ssize_t num_writes_show(struct device *dev,
81 struct device_attribute *attr, char *buf)
82{
83 struct zram *zram = dev_to_zram(dev);
84
85 return sprintf(buf, "%llu\n",
86 (u64)atomic64_read(&zram->stats.num_writes));
87}
88
89static ssize_t invalid_io_show(struct device *dev,
90 struct device_attribute *attr, char *buf)
91{
92 struct zram *zram = dev_to_zram(dev);
93
94 return sprintf(buf, "%llu\n",
95 (u64)atomic64_read(&zram->stats.invalid_io));
96}
97
98static ssize_t notify_free_show(struct device *dev,
99 struct device_attribute *attr, char *buf)
100{
101 struct zram *zram = dev_to_zram(dev);
102
103 return sprintf(buf, "%llu\n",
104 (u64)atomic64_read(&zram->stats.notify_free));
105}
106
107static ssize_t zero_pages_show(struct device *dev,
108 struct device_attribute *attr, char *buf)
109{
110 struct zram *zram = dev_to_zram(dev);
111 83
112 return sprintf(buf, "%llu\n", (u64)atomic64_read(&zram->stats.zero_pages)); 84 return sprintf(buf, "%u\n", val);
113} 85}
114 86
115static ssize_t orig_data_size_show(struct device *dev, 87static ssize_t orig_data_size_show(struct device *dev,
@@ -121,15 +93,6 @@ static ssize_t orig_data_size_show(struct device *dev,
121 (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT); 93 (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
122} 94}
123 95
124static ssize_t compr_data_size_show(struct device *dev,
125 struct device_attribute *attr, char *buf)
126{
127 struct zram *zram = dev_to_zram(dev);
128
129 return sprintf(buf, "%llu\n",
130 (u64)atomic64_read(&zram->stats.compr_data_size));
131}
132
133static ssize_t mem_used_total_show(struct device *dev, 96static ssize_t mem_used_total_show(struct device *dev,
134 struct device_attribute *attr, char *buf) 97 struct device_attribute *attr, char *buf)
135{ 98{
@@ -762,15 +725,16 @@ static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
762 disksize_show, disksize_store); 725 disksize_show, disksize_store);
763static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL); 726static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
764static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store); 727static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
765static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL);
766static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL);
767static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL);
768static DEVICE_ATTR(notify_free, S_IRUGO, notify_free_show, NULL);
769static DEVICE_ATTR(zero_pages, S_IRUGO, zero_pages_show, NULL);
770static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL); 728static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
771static DEVICE_ATTR(compr_data_size, S_IRUGO, compr_data_size_show, NULL);
772static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL); 729static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
773 730
731ZRAM_ATTR_RO(num_reads);
732ZRAM_ATTR_RO(num_writes);
733ZRAM_ATTR_RO(invalid_io);
734ZRAM_ATTR_RO(notify_free);
735ZRAM_ATTR_RO(zero_pages);
736ZRAM_ATTR_RO(compr_data_size);
737
774static struct attribute *zram_disk_attrs[] = { 738static struct attribute *zram_disk_attrs[] = {
775 &dev_attr_disksize.attr, 739 &dev_attr_disksize.attr,
776 &dev_attr_initstate.attr, 740 &dev_attr_initstate.attr,