mirror of
https://github.com/torvalds/linux.git
synced 2026-10-12 05:17:15 +02:00
dm vdo: add sysfs support for setting parameters and fetching stats
Add data and methods setting run time parameters via sysfs, and to make state and statistics information available through sysfs. Co-developed-by: J. corwin Coburn <corwin@hurlbutnet.net> Signed-off-by: J. corwin Coburn <corwin@hurlbutnet.net> Co-developed-by: Michael Sclafani <dm-devel@lists.linux.dev> Signed-off-by: Michael Sclafani <dm-devel@lists.linux.dev> Co-developed-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me> Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me> Co-developed-by: Bruce Johnston <bjohnsto@redhat.com> Signed-off-by: Bruce Johnston <bjohnsto@redhat.com> Signed-off-by: Matthew Sakai <msakai@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
This commit is contained in:
parent
a9457ab9d0
commit
92f8d7a94f
2063
drivers/md/dm-vdo/pool-sysfs-stats.c
Normal file
2063
drivers/md/dm-vdo/pool-sysfs-stats.c
Normal file
File diff suppressed because it is too large
Load Diff
198
drivers/md/dm-vdo/pool-sysfs.c
Normal file
198
drivers/md/dm-vdo/pool-sysfs.c
Normal file
|
|
@ -0,0 +1,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)
|
||||
{
|
||||
uds_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,
|
||||
};
|
||||
19
drivers/md/dm-vdo/pool-sysfs.h
Normal file
19
drivers/md/dm-vdo/pool-sysfs.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* Copyright 2023 Red Hat
|
||||
*/
|
||||
|
||||
#ifndef VDO_POOL_SYSFS_H
|
||||
#define VDO_POOL_SYSFS_H
|
||||
|
||||
#include <linux/kobject.h>
|
||||
|
||||
/* The kobj_type used for setting up the kernel layer kobject. */
|
||||
extern const struct kobj_type vdo_directory_type;
|
||||
|
||||
/* The sysfs_ops used for the "statistics" subdirectory. */
|
||||
extern const struct sysfs_ops vdo_pool_stats_sysfs_ops;
|
||||
/* The attribute used for the "statistics" subdirectory. */
|
||||
extern struct attribute *vdo_pool_stats_attrs[];
|
||||
|
||||
#endif /* VDO_POOL_SYSFS_H */
|
||||
82
drivers/md/dm-vdo/sysfs.c
Normal file
82
drivers/md/dm-vdo/sysfs.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright 2023 Red Hat
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "dedupe.h"
|
||||
#include "vdo.h"
|
||||
|
||||
static int vdo_log_level_show(char *buf, const struct kernel_param *kp)
|
||||
{
|
||||
return sprintf(buf, "%s\n", uds_log_priority_to_string(uds_get_log_level()));
|
||||
}
|
||||
|
||||
static int vdo_log_level_store(const char *buf, const struct kernel_param *kp)
|
||||
{
|
||||
static char internal_buf[11];
|
||||
|
||||
int n = strlen(buf);
|
||||
|
||||
if (n > 10)
|
||||
return -EINVAL;
|
||||
|
||||
memset(internal_buf, '\000', sizeof(internal_buf));
|
||||
memcpy(internal_buf, buf, n);
|
||||
if (internal_buf[n - 1] == '\n')
|
||||
internal_buf[n - 1] = '\000';
|
||||
uds_set_log_level(uds_log_string_to_priority(internal_buf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int vdo_dedupe_timeout_interval_store(const char *buf,
|
||||
const struct kernel_param *kp)
|
||||
{
|
||||
int result = param_set_uint(buf, kp);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
vdo_set_dedupe_index_timeout_interval(*(uint *)kp->arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vdo_min_dedupe_timer_interval_store(const char *buf,
|
||||
const struct kernel_param *kp)
|
||||
{
|
||||
int result = param_set_uint(buf, kp);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
vdo_set_dedupe_index_min_timer_interval(*(uint *)kp->arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct kernel_param_ops log_level_ops = {
|
||||
.set = vdo_log_level_store,
|
||||
.get = vdo_log_level_show,
|
||||
};
|
||||
|
||||
|
||||
static const struct kernel_param_ops dedupe_timeout_ops = {
|
||||
.set = vdo_dedupe_timeout_interval_store,
|
||||
.get = param_get_uint,
|
||||
};
|
||||
|
||||
static const struct kernel_param_ops dedupe_timer_ops = {
|
||||
.set = vdo_min_dedupe_timer_interval_store,
|
||||
.get = param_get_uint,
|
||||
};
|
||||
|
||||
module_param_cb(log_level, &log_level_ops, NULL, 0644);
|
||||
|
||||
|
||||
module_param_cb(deduplication_timeout_interval, &dedupe_timeout_ops,
|
||||
&vdo_dedupe_index_timeout_interval, 0644);
|
||||
|
||||
module_param_cb(min_deduplication_timer_interval, &dedupe_timer_ops,
|
||||
&vdo_dedupe_index_min_timer_interval, 0644);
|
||||
Loading…
Reference in New Issue
Block a user