Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  3 *
  4 * This file is released under the GPL.
  5 */
  6
  7#include <linux/sysfs.h>
  8#include <linux/dm-ioctl.h>
  9#include "dm.h"
 
 10
 11struct dm_sysfs_attr {
 12	struct attribute attr;
 13	ssize_t (*show)(struct mapped_device *, char *);
 14	ssize_t (*store)(struct mapped_device *, char *);
 15};
 16
 17#define DM_ATTR_RO(_name) \
 18struct dm_sysfs_attr dm_attr_##_name = \
 19	__ATTR(_name, S_IRUGO, dm_attr_##_name##_show, NULL)
 20
 21static ssize_t dm_attr_show(struct kobject *kobj, struct attribute *attr,
 22			    char *page)
 23{
 24	struct dm_sysfs_attr *dm_attr;
 25	struct mapped_device *md;
 26	ssize_t ret;
 27
 28	dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
 29	if (!dm_attr->show)
 30		return -EIO;
 31
 32	md = dm_get_from_kobject(kobj);
 33	if (!md)
 34		return -EINVAL;
 35
 36	ret = dm_attr->show(md, page);
 37	dm_put(md);
 38
 39	return ret;
 40}
 41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 42static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
 43{
 44	if (dm_copy_name_and_uuid(md, buf, NULL))
 45		return -EIO;
 46
 47	strcat(buf, "\n");
 48	return strlen(buf);
 49}
 50
 51static ssize_t dm_attr_uuid_show(struct mapped_device *md, char *buf)
 52{
 53	if (dm_copy_name_and_uuid(md, NULL, buf))
 54		return -EIO;
 55
 56	strcat(buf, "\n");
 57	return strlen(buf);
 58}
 59
 60static ssize_t dm_attr_suspended_show(struct mapped_device *md, char *buf)
 61{
 62	sprintf(buf, "%d\n", dm_suspended_md(md));
 63
 64	return strlen(buf);
 65}
 66
 
 
 
 
 
 
 
 
 67static DM_ATTR_RO(name);
 68static DM_ATTR_RO(uuid);
 69static DM_ATTR_RO(suspended);
 
 
 70
 71static struct attribute *dm_attrs[] = {
 72	&dm_attr_name.attr,
 73	&dm_attr_uuid.attr,
 74	&dm_attr_suspended.attr,
 
 
 75	NULL,
 76};
 
 77
 78static const struct sysfs_ops dm_sysfs_ops = {
 79	.show	= dm_attr_show,
 
 80};
 81
 82/*
 83 * dm kobject is embedded in mapped_device structure
 84 * no need to define release function here
 85 */
 86static struct kobj_type dm_ktype = {
 87	.sysfs_ops	= &dm_sysfs_ops,
 88	.default_attrs	= dm_attrs,
 
 89};
 90
 91/*
 92 * Initialize kobj
 93 * because nobody using md yet, no need to call explicit dm_get/put
 94 */
 95int dm_sysfs_init(struct mapped_device *md)
 96{
 97	return kobject_init_and_add(dm_kobject(md), &dm_ktype,
 98				    &disk_to_dev(dm_disk(md))->kobj,
 99				    "%s", "dm");
100}
101
102/*
103 * Remove kobj, called after all references removed
104 */
105void dm_sysfs_exit(struct mapped_device *md)
106{
107	kobject_put(dm_kobject(md));
 
 
 
108}
v6.9.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  4 *
  5 * This file is released under the GPL.
  6 */
  7
  8#include <linux/sysfs.h>
  9#include <linux/dm-ioctl.h>
 10#include "dm-core.h"
 11#include "dm-rq.h"
 12
 13struct dm_sysfs_attr {
 14	struct attribute attr;
 15	ssize_t (*show)(struct mapped_device *md, char *p);
 16	ssize_t (*store)(struct mapped_device *md, const char *p, size_t count);
 17};
 18
 19#define DM_ATTR_RO(_name) \
 20struct dm_sysfs_attr dm_attr_##_name = \
 21	__ATTR(_name, 0444, dm_attr_##_name##_show, NULL)
 22
 23static ssize_t dm_attr_show(struct kobject *kobj, struct attribute *attr,
 24			    char *page)
 25{
 26	struct dm_sysfs_attr *dm_attr;
 27	struct mapped_device *md;
 28	ssize_t ret;
 29
 30	dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
 31	if (!dm_attr->show)
 32		return -EIO;
 33
 34	md = dm_get_from_kobject(kobj);
 35	if (!md)
 36		return -EINVAL;
 37
 38	ret = dm_attr->show(md, page);
 39	dm_put(md);
 40
 41	return ret;
 42}
 43
 44#define DM_ATTR_RW(_name) \
 45struct dm_sysfs_attr dm_attr_##_name = \
 46	__ATTR(_name, 0644, dm_attr_##_name##_show, dm_attr_##_name##_store)
 47
 48static ssize_t dm_attr_store(struct kobject *kobj, struct attribute *attr,
 49			     const char *page, size_t count)
 50{
 51	struct dm_sysfs_attr *dm_attr;
 52	struct mapped_device *md;
 53	ssize_t ret;
 54
 55	dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
 56	if (!dm_attr->store)
 57		return -EIO;
 58
 59	md = dm_get_from_kobject(kobj);
 60	if (!md)
 61		return -EINVAL;
 62
 63	ret = dm_attr->store(md, page, count);
 64	dm_put(md);
 65
 66	return ret;
 67}
 68
 69static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
 70{
 71	if (dm_copy_name_and_uuid(md, buf, NULL))
 72		return -EIO;
 73
 74	strcat(buf, "\n");
 75	return strlen(buf);
 76}
 77
 78static ssize_t dm_attr_uuid_show(struct mapped_device *md, char *buf)
 79{
 80	if (dm_copy_name_and_uuid(md, NULL, buf))
 81		return -EIO;
 82
 83	strcat(buf, "\n");
 84	return strlen(buf);
 85}
 86
 87static ssize_t dm_attr_suspended_show(struct mapped_device *md, char *buf)
 88{
 89	sprintf(buf, "%d\n", dm_suspended_md(md));
 90
 91	return strlen(buf);
 92}
 93
 94static ssize_t dm_attr_use_blk_mq_show(struct mapped_device *md, char *buf)
 95{
 96	/* Purely for userspace compatibility */
 97	sprintf(buf, "%d\n", true);
 98
 99	return strlen(buf);
100}
101
102static DM_ATTR_RO(name);
103static DM_ATTR_RO(uuid);
104static DM_ATTR_RO(suspended);
105static DM_ATTR_RO(use_blk_mq);
106static DM_ATTR_RW(rq_based_seq_io_merge_deadline);
107
108static struct attribute *dm_attrs[] = {
109	&dm_attr_name.attr,
110	&dm_attr_uuid.attr,
111	&dm_attr_suspended.attr,
112	&dm_attr_use_blk_mq.attr,
113	&dm_attr_rq_based_seq_io_merge_deadline.attr,
114	NULL,
115};
116ATTRIBUTE_GROUPS(dm);
117
118static const struct sysfs_ops dm_sysfs_ops = {
119	.show	= dm_attr_show,
120	.store	= dm_attr_store,
121};
122
123static const struct kobj_type dm_ktype = {
 
 
 
 
124	.sysfs_ops	= &dm_sysfs_ops,
125	.default_groups	= dm_groups,
126	.release	= dm_kobject_release,
127};
128
129/*
130 * Initialize kobj
131 * because nobody using md yet, no need to call explicit dm_get/put
132 */
133int dm_sysfs_init(struct mapped_device *md)
134{
135	return kobject_init_and_add(dm_kobject(md), &dm_ktype,
136				    &disk_to_dev(dm_disk(md))->kobj,
137				    "%s", "dm");
138}
139
140/*
141 * Remove kobj, called after all references removed
142 */
143void dm_sysfs_exit(struct mapped_device *md)
144{
145	struct kobject *kobj = dm_kobject(md);
146
147	kobject_put(kobj);
148	wait_for_completion(dm_get_completion_from_kobject(kobj));
149}