2 * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
7 #include <linux/sysfs.h>
8 #include <linux/dm-ioctl.h>
12 struct dm_sysfs_attr
{
13 struct attribute attr
;
14 ssize_t (*show
)(struct mapped_device
*, char *);
15 ssize_t (*store
)(struct mapped_device
*, const char *, size_t count
);
18 #define DM_ATTR_RO(_name) \
19 struct dm_sysfs_attr dm_attr_##_name = \
20 __ATTR(_name, S_IRUGO, dm_attr_##_name##_show, NULL)
22 static ssize_t
dm_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
25 struct dm_sysfs_attr
*dm_attr
;
26 struct mapped_device
*md
;
29 dm_attr
= container_of(attr
, struct dm_sysfs_attr
, attr
);
33 md
= dm_get_from_kobject(kobj
);
37 ret
= dm_attr
->show(md
, page
);
43 #define DM_ATTR_RW(_name) \
44 struct dm_sysfs_attr dm_attr_##_name = \
45 __ATTR(_name, S_IRUGO | S_IWUSR, dm_attr_##_name##_show, dm_attr_##_name##_store)
47 static ssize_t
dm_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
48 const char *page
, size_t count
)
50 struct dm_sysfs_attr
*dm_attr
;
51 struct mapped_device
*md
;
54 dm_attr
= container_of(attr
, struct dm_sysfs_attr
, attr
);
58 md
= dm_get_from_kobject(kobj
);
62 ret
= dm_attr
->store(md
, page
, count
);
68 static ssize_t
dm_attr_name_show(struct mapped_device
*md
, char *buf
)
70 if (dm_copy_name_and_uuid(md
, buf
, NULL
))
77 static ssize_t
dm_attr_uuid_show(struct mapped_device
*md
, char *buf
)
79 if (dm_copy_name_and_uuid(md
, NULL
, buf
))
86 static ssize_t
dm_attr_suspended_show(struct mapped_device
*md
, char *buf
)
88 sprintf(buf
, "%d\n", dm_suspended_md(md
));
93 static ssize_t
dm_attr_use_blk_mq_show(struct mapped_device
*md
, char *buf
)
95 sprintf(buf
, "%d\n", dm_use_blk_mq(md
));
100 static DM_ATTR_RO(name
);
101 static DM_ATTR_RO(uuid
);
102 static DM_ATTR_RO(suspended
);
103 static DM_ATTR_RO(use_blk_mq
);
104 static DM_ATTR_RW(rq_based_seq_io_merge_deadline
);
106 static struct attribute
*dm_attrs
[] = {
109 &dm_attr_suspended
.attr
,
110 &dm_attr_use_blk_mq
.attr
,
111 &dm_attr_rq_based_seq_io_merge_deadline
.attr
,
115 static const struct sysfs_ops dm_sysfs_ops
= {
116 .show
= dm_attr_show
,
117 .store
= dm_attr_store
,
120 static struct kobj_type dm_ktype
= {
121 .sysfs_ops
= &dm_sysfs_ops
,
122 .default_attrs
= dm_attrs
,
123 .release
= dm_kobject_release
,
128 * because nobody using md yet, no need to call explicit dm_get/put
130 int dm_sysfs_init(struct mapped_device
*md
)
132 return kobject_init_and_add(dm_kobject(md
), &dm_ktype
,
133 &disk_to_dev(dm_disk(md
))->kobj
,
138 * Remove kobj, called after all references removed
140 void dm_sysfs_exit(struct mapped_device
*md
)
142 struct kobject
*kobj
= dm_kobject(md
);
144 wait_for_completion(dm_get_completion_from_kobject(kobj
));