diff options
author | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> | 2014-04-07 18:38:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-07 19:36:00 -0400 |
commit | a68eb3b65e658406d386bebef02277f4007b2f45 (patch) | |
tree | 26e8c5a63560e39a7a79275c4fc7a851f0922f02 /drivers/block | |
parent | 90a7806ea9b9f7cb4751859cc2506e2d80e36ef1 (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.c | 82 |
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) */ |
43 | static unsigned int num_devices = 1; | 43 | static unsigned int num_devices = 1; |
44 | 44 | ||
45 | #define ZRAM_ATTR_RO(name) \ | ||
46 | static 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 | } \ | ||
53 | static struct device_attribute dev_attr_##name = \ | ||
54 | __ATTR(name, S_IRUGO, zram_attr_##name##_show, NULL); | ||
55 | |||
45 | static inline int init_done(struct zram *zram) | 56 | static 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, | |||
63 | static ssize_t initstate_show(struct device *dev, | 74 | static 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); | |
71 | static 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 | |||
80 | static 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 | |||
89 | static 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 | |||
98 | static 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 | |||
107 | static 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 | ||
115 | static ssize_t orig_data_size_show(struct device *dev, | 87 | static 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 | ||
124 | static 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 | |||
133 | static ssize_t mem_used_total_show(struct device *dev, | 96 | static 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); |
763 | static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL); | 726 | static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL); |
764 | static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store); | 727 | static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store); |
765 | static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL); | ||
766 | static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL); | ||
767 | static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL); | ||
768 | static DEVICE_ATTR(notify_free, S_IRUGO, notify_free_show, NULL); | ||
769 | static DEVICE_ATTR(zero_pages, S_IRUGO, zero_pages_show, NULL); | ||
770 | static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL); | 728 | static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL); |
771 | static DEVICE_ATTR(compr_data_size, S_IRUGO, compr_data_size_show, NULL); | ||
772 | static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL); | 729 | static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL); |
773 | 730 | ||
731 | ZRAM_ATTR_RO(num_reads); | ||
732 | ZRAM_ATTR_RO(num_writes); | ||
733 | ZRAM_ATTR_RO(invalid_io); | ||
734 | ZRAM_ATTR_RO(notify_free); | ||
735 | ZRAM_ATTR_RO(zero_pages); | ||
736 | ZRAM_ATTR_RO(compr_data_size); | ||
737 | |||
774 | static struct attribute *zram_disk_attrs[] = { | 738 | static 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, |