ALSA: hda - Remove superfluous init verb entries for ALC88[235]
[firewire-audio.git] / drivers / md / dm-sysfs.c
blobf53392df7b97984438e8ec823abccb59d4386ee9
1 /*
2 * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
5 */
7 #include <linux/sysfs.h>
8 #include <linux/dm-ioctl.h>
9 #include "dm.h"
11 struct dm_sysfs_attr {
12 struct attribute attr;
13 ssize_t (*show)(struct mapped_device *, char *);
14 ssize_t (*store)(struct mapped_device *, char *);
17 #define DM_ATTR_RO(_name) \
18 struct dm_sysfs_attr dm_attr_##_name = \
19 __ATTR(_name, S_IRUGO, dm_attr_##_name##_show, NULL)
21 static ssize_t dm_attr_show(struct kobject *kobj, struct attribute *attr,
22 char *page)
24 struct dm_sysfs_attr *dm_attr;
25 struct mapped_device *md;
26 ssize_t ret;
28 dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
29 if (!dm_attr->show)
30 return -EIO;
32 md = dm_get_from_kobject(kobj);
33 if (!md)
34 return -EINVAL;
36 ret = dm_attr->show(md, page);
37 dm_put(md);
39 return ret;
42 static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
44 if (dm_copy_name_and_uuid(md, buf, NULL))
45 return -EIO;
47 strcat(buf, "\n");
48 return strlen(buf);
51 static ssize_t dm_attr_uuid_show(struct mapped_device *md, char *buf)
53 if (dm_copy_name_and_uuid(md, NULL, buf))
54 return -EIO;
56 strcat(buf, "\n");
57 return strlen(buf);
60 static ssize_t dm_attr_suspended_show(struct mapped_device *md, char *buf)
62 sprintf(buf, "%d\n", dm_suspended_md(md));
64 return strlen(buf);
67 static DM_ATTR_RO(name);
68 static DM_ATTR_RO(uuid);
69 static DM_ATTR_RO(suspended);
71 static struct attribute *dm_attrs[] = {
72 &dm_attr_name.attr,
73 &dm_attr_uuid.attr,
74 &dm_attr_suspended.attr,
75 NULL,
78 static struct sysfs_ops dm_sysfs_ops = {
79 .show = dm_attr_show,
83 * The sysfs structure is embedded in md struct, nothing to do here
85 static void dm_sysfs_release(struct kobject *kobj)
90 * dm kobject is embedded in mapped_device structure
91 * no need to define release function here
93 static struct kobj_type dm_ktype = {
94 .sysfs_ops = &dm_sysfs_ops,
95 .default_attrs = dm_attrs,
96 .release = dm_sysfs_release
100 * Initialize kobj
101 * because nobody using md yet, no need to call explicit dm_get/put
103 int dm_sysfs_init(struct mapped_device *md)
105 return kobject_init_and_add(dm_kobject(md), &dm_ktype,
106 &disk_to_dev(dm_disk(md))->kobj,
107 "%s", "dm");
111 * Remove kobj, called after all references removed
113 void dm_sysfs_exit(struct mapped_device *md)
115 kobject_put(dm_kobject(md));