summaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-vdo/pool-sysfs.c
blob: 6769c5711cbcf412abfdf3cfbfbc51ef19e693cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2023 Red Hat
 */

#include "pool-sysfs.h"

#include <linux/kstrtox.h>

#include "memory-alloc.h"
#include "string-utils.h"

#include "data-vio.h"
#include "dedupe.h"
#include "vdo.h"

struct pool_attribute {
	struct attribute attr;
	ssize_t (*show)(struct vdo *vdo, char *buf);
	ssize_t (*store)(struct vdo *vdo, const char *value, size_t count);
};

static ssize_t vdo_pool_attr_show(struct kobject *directory, struct attribute *attr,
				  char *buf)
{
	struct pool_attribute *pool_attr = container_of(attr, struct pool_attribute,
							attr);
	struct vdo *vdo = container_of(directory, struct vdo, vdo_directory);

	if (pool_attr->show == NULL)
		return -EINVAL;
	return pool_attr->show(vdo, buf);
}

static ssize_t vdo_pool_attr_store(struct kobject *directory, struct attribute *attr,
				   const char *buf, size_t length)
{
	struct pool_attribute *pool_attr = container_of(attr, struct pool_attribute,
							attr);
	struct vdo *vdo = container_of(directory, struct vdo, vdo_directory);

	if (pool_attr->store == NULL)
		return -EINVAL;
	return pool_attr->store(vdo, buf, length);
}

static const struct sysfs_ops vdo_pool_sysfs_ops = {
	.show = vdo_pool_attr_show,
	.store = vdo_pool_attr_store,
};

static ssize_t pool_compressing_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%s\n", (vdo_get_compressing(vdo) ? "1" : "0"));
}

static ssize_t pool_discards_active_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n",
		       get_data_vio_pool_active_discards(vdo->data_vio_pool));
}

static ssize_t pool_discards_limit_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n", get_data_vio_pool_discard_limit(vdo->data_vio_pool));
}

static ssize_t pool_discards_limit_store(struct vdo *vdo, const char *buf, size_t length)
{
	unsigned int value;
	int result;

	if ((length > 12) || (kstrtouint(buf, 10, &value) < 0) || (value < 1))
		return -EINVAL;

	result = set_data_vio_pool_discard_limit(vdo->data_vio_pool, value);
	if (result != VDO_SUCCESS)
		return -EINVAL;

	return length;
}

static ssize_t pool_discards_maximum_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n",
		       get_data_vio_pool_maximum_discards(vdo->data_vio_pool));
}

static ssize_t pool_instance_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n", vdo->instance);
}

static ssize_t pool_requests_active_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n",
		       get_data_vio_pool_active_requests(vdo->data_vio_pool));
}

static ssize_t pool_requests_limit_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n", get_data_vio_pool_request_limit(vdo->data_vio_pool));
}

static ssize_t pool_requests_maximum_show(struct vdo *vdo, char *buf)
{
	return sprintf(buf, "%u\n",
		       get_data_vio_pool_maximum_requests(vdo->data_vio_pool));
}

static void vdo_pool_release(struct kobject *directory)
{
	vdo_free(container_of(directory, struct vdo, vdo_directory));
}

static struct pool_attribute vdo_pool_compressing_attr = {
	.attr = {
			.name = "compressing",
			.mode = 0444,
		},
	.show = pool_compressing_show,
};

static struct pool_attribute vdo_pool_discards_active_attr = {
	.attr = {
			.name = "discards_active",
			.mode = 0444,
		},
	.show = pool_discards_active_show,
};

static struct pool_attribute vdo_pool_discards_limit_attr = {
	.attr = {
			.name = "discards_limit",
			.mode = 0644,
		},
	.show = pool_discards_limit_show,
	.store = pool_discards_limit_store,
};

static struct pool_attribute vdo_pool_discards_maximum_attr = {
	.attr = {
			.name = "discards_maximum",
			.mode = 0444,
		},
	.show = pool_discards_maximum_show,
};

static struct pool_attribute vdo_pool_instance_attr = {
	.attr = {
			.name = "instance",
			.mode = 0444,
		},
	.show = pool_instance_show,
};

static struct pool_attribute vdo_pool_requests_active_attr = {
	.attr = {
			.name = "requests_active",
			.mode = 0444,
		},
	.show = pool_requests_active_show,
};

static struct pool_attribute vdo_pool_requests_limit_attr = {
	.attr = {
			.name = "requests_limit",
			.mode = 0444,
		},
	.show = pool_requests_limit_show,
};

static struct pool_attribute vdo_pool_requests_maximum_attr = {
	.attr = {
			.name = "requests_maximum",
			.mode = 0444,
		},
	.show = pool_requests_maximum_show,
};

static struct attribute *pool_attrs[] = {
	&vdo_pool_compressing_attr.attr,
	&vdo_pool_discards_active_attr.attr,
	&vdo_pool_discards_limit_attr.attr,
	&vdo_pool_discards_maximum_attr.attr,
	&vdo_pool_instance_attr.attr,
	&vdo_pool_requests_active_attr.attr,
	&vdo_pool_requests_limit_attr.attr,
	&vdo_pool_requests_maximum_attr.attr,
	NULL,
};
ATTRIBUTE_GROUPS(pool);

const struct kobj_type vdo_directory_type = {
	.release = vdo_pool_release,
	.sysfs_ops = &vdo_pool_sysfs_ops,
	.default_groups = pool_groups,
};