dm sysfs: introduce ability to add writable attributes
Add DM_ATTR_RW() macro and establish .store method in dm_sysfs_ops. Signed-off-by: Mike Snitzer <snitzer@redhat.com>
This commit is contained in:
parent
de3ec86dff
commit
b898320d68
|
@ -11,7 +11,7 @@
|
||||||
struct dm_sysfs_attr {
|
struct dm_sysfs_attr {
|
||||||
struct attribute attr;
|
struct attribute attr;
|
||||||
ssize_t (*show)(struct mapped_device *, char *);
|
ssize_t (*show)(struct mapped_device *, char *);
|
||||||
ssize_t (*store)(struct mapped_device *, char *);
|
ssize_t (*store)(struct mapped_device *, const char *, size_t count);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DM_ATTR_RO(_name) \
|
#define DM_ATTR_RO(_name) \
|
||||||
|
@ -39,6 +39,31 @@ static ssize_t dm_attr_show(struct kobject *kobj, struct attribute *attr,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DM_ATTR_RW(_name) \
|
||||||
|
struct dm_sysfs_attr dm_attr_##_name = \
|
||||||
|
__ATTR(_name, S_IRUGO | S_IWUSR, dm_attr_##_name##_show, dm_attr_##_name##_store)
|
||||||
|
|
||||||
|
static ssize_t dm_attr_store(struct kobject *kobj, struct attribute *attr,
|
||||||
|
const char *page, size_t count)
|
||||||
|
{
|
||||||
|
struct dm_sysfs_attr *dm_attr;
|
||||||
|
struct mapped_device *md;
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
|
||||||
|
if (!dm_attr->store)
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
|
md = dm_get_from_kobject(kobj);
|
||||||
|
if (!md)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
ret = dm_attr->store(md, page, count);
|
||||||
|
dm_put(md);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
|
static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
|
||||||
{
|
{
|
||||||
if (dm_copy_name_and_uuid(md, buf, NULL))
|
if (dm_copy_name_and_uuid(md, buf, NULL))
|
||||||
|
@ -77,12 +102,9 @@ static struct attribute *dm_attrs[] = {
|
||||||
|
|
||||||
static const struct sysfs_ops dm_sysfs_ops = {
|
static const struct sysfs_ops dm_sysfs_ops = {
|
||||||
.show = dm_attr_show,
|
.show = dm_attr_show,
|
||||||
|
.store = dm_attr_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* dm kobject is embedded in mapped_device structure
|
|
||||||
* no need to define release function here
|
|
||||||
*/
|
|
||||||
static struct kobj_type dm_ktype = {
|
static struct kobj_type dm_ktype = {
|
||||||
.sysfs_ops = &dm_sysfs_ops,
|
.sysfs_ops = &dm_sysfs_ops,
|
||||||
.default_attrs = dm_attrs,
|
.default_attrs = dm_attrs,
|
||||||
|
|
Loading…
Reference in New Issue