dm vdo errors: remove unused error codes
[linux-block.git] / drivers / md / dm-vdo / pool-sysfs.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2023 Red Hat
4  */
5
6 #include "pool-sysfs.h"
7
8 #include <linux/kstrtox.h>
9
10 #include "memory-alloc.h"
11 #include "string-utils.h"
12
13 #include "data-vio.h"
14 #include "dedupe.h"
15 #include "vdo.h"
16
17 struct pool_attribute {
18         struct attribute attr;
19         ssize_t (*show)(struct vdo *vdo, char *buf);
20         ssize_t (*store)(struct vdo *vdo, const char *value, size_t count);
21 };
22
23 static ssize_t vdo_pool_attr_show(struct kobject *directory, struct attribute *attr,
24                                   char *buf)
25 {
26         struct pool_attribute *pool_attr = container_of(attr, struct pool_attribute,
27                                                         attr);
28         struct vdo *vdo = container_of(directory, struct vdo, vdo_directory);
29
30         if (pool_attr->show == NULL)
31                 return -EINVAL;
32         return pool_attr->show(vdo, buf);
33 }
34
35 static ssize_t vdo_pool_attr_store(struct kobject *directory, struct attribute *attr,
36                                    const char *buf, size_t length)
37 {
38         struct pool_attribute *pool_attr = container_of(attr, struct pool_attribute,
39                                                         attr);
40         struct vdo *vdo = container_of(directory, struct vdo, vdo_directory);
41
42         if (pool_attr->store == NULL)
43                 return -EINVAL;
44         return pool_attr->store(vdo, buf, length);
45 }
46
47 static const struct sysfs_ops vdo_pool_sysfs_ops = {
48         .show = vdo_pool_attr_show,
49         .store = vdo_pool_attr_store,
50 };
51
52 static ssize_t pool_compressing_show(struct vdo *vdo, char *buf)
53 {
54         return sprintf(buf, "%s\n", (vdo_get_compressing(vdo) ? "1" : "0"));
55 }
56
57 static ssize_t pool_discards_active_show(struct vdo *vdo, char *buf)
58 {
59         return sprintf(buf, "%u\n",
60                        get_data_vio_pool_active_discards(vdo->data_vio_pool));
61 }
62
63 static ssize_t pool_discards_limit_show(struct vdo *vdo, char *buf)
64 {
65         return sprintf(buf, "%u\n", get_data_vio_pool_discard_limit(vdo->data_vio_pool));
66 }
67
68 static ssize_t pool_discards_limit_store(struct vdo *vdo, const char *buf, size_t length)
69 {
70         unsigned int value;
71         int result;
72
73         if ((length > 12) || (kstrtouint(buf, 10, &value) < 0) || (value < 1))
74                 return -EINVAL;
75
76         result = set_data_vio_pool_discard_limit(vdo->data_vio_pool, value);
77         if (result != VDO_SUCCESS)
78                 return -EINVAL;
79
80         return length;
81 }
82
83 static ssize_t pool_discards_maximum_show(struct vdo *vdo, char *buf)
84 {
85         return sprintf(buf, "%u\n",
86                        get_data_vio_pool_maximum_discards(vdo->data_vio_pool));
87 }
88
89 static ssize_t pool_instance_show(struct vdo *vdo, char *buf)
90 {
91         return sprintf(buf, "%u\n", vdo->instance);
92 }
93
94 static ssize_t pool_requests_active_show(struct vdo *vdo, char *buf)
95 {
96         return sprintf(buf, "%u\n",
97                        get_data_vio_pool_active_requests(vdo->data_vio_pool));
98 }
99
100 static ssize_t pool_requests_limit_show(struct vdo *vdo, char *buf)
101 {
102         return sprintf(buf, "%u\n", get_data_vio_pool_request_limit(vdo->data_vio_pool));
103 }
104
105 static ssize_t pool_requests_maximum_show(struct vdo *vdo, char *buf)
106 {
107         return sprintf(buf, "%u\n",
108                        get_data_vio_pool_maximum_requests(vdo->data_vio_pool));
109 }
110
111 static void vdo_pool_release(struct kobject *directory)
112 {
113         vdo_free(container_of(directory, struct vdo, vdo_directory));
114 }
115
116 static struct pool_attribute vdo_pool_compressing_attr = {
117         .attr = {
118                         .name = "compressing",
119                         .mode = 0444,
120                 },
121         .show = pool_compressing_show,
122 };
123
124 static struct pool_attribute vdo_pool_discards_active_attr = {
125         .attr = {
126                         .name = "discards_active",
127                         .mode = 0444,
128                 },
129         .show = pool_discards_active_show,
130 };
131
132 static struct pool_attribute vdo_pool_discards_limit_attr = {
133         .attr = {
134                         .name = "discards_limit",
135                         .mode = 0644,
136                 },
137         .show = pool_discards_limit_show,
138         .store = pool_discards_limit_store,
139 };
140
141 static struct pool_attribute vdo_pool_discards_maximum_attr = {
142         .attr = {
143                         .name = "discards_maximum",
144                         .mode = 0444,
145                 },
146         .show = pool_discards_maximum_show,
147 };
148
149 static struct pool_attribute vdo_pool_instance_attr = {
150         .attr = {
151                         .name = "instance",
152                         .mode = 0444,
153                 },
154         .show = pool_instance_show,
155 };
156
157 static struct pool_attribute vdo_pool_requests_active_attr = {
158         .attr = {
159                         .name = "requests_active",
160                         .mode = 0444,
161                 },
162         .show = pool_requests_active_show,
163 };
164
165 static struct pool_attribute vdo_pool_requests_limit_attr = {
166         .attr = {
167                         .name = "requests_limit",
168                         .mode = 0444,
169                 },
170         .show = pool_requests_limit_show,
171 };
172
173 static struct pool_attribute vdo_pool_requests_maximum_attr = {
174         .attr = {
175                         .name = "requests_maximum",
176                         .mode = 0444,
177                 },
178         .show = pool_requests_maximum_show,
179 };
180
181 static struct attribute *pool_attrs[] = {
182         &vdo_pool_compressing_attr.attr,
183         &vdo_pool_discards_active_attr.attr,
184         &vdo_pool_discards_limit_attr.attr,
185         &vdo_pool_discards_maximum_attr.attr,
186         &vdo_pool_instance_attr.attr,
187         &vdo_pool_requests_active_attr.attr,
188         &vdo_pool_requests_limit_attr.attr,
189         &vdo_pool_requests_maximum_attr.attr,
190         NULL,
191 };
192 ATTRIBUTE_GROUPS(pool);
193
194 const struct kobj_type vdo_directory_type = {
195         .release = vdo_pool_release,
196         .sysfs_ops = &vdo_pool_sysfs_ops,
197         .default_groups = pool_groups,
198 };