From: Jeff Garzik <jgarzik@pobox.com>
To: Netdev <netdev@oss.sgi.com>
Subject: [Fwd: [PATCH] add sysfs class support for raw devices [06/10]]
Date: Thu, 15 Jan 2004 16:11:10 -0500 [thread overview]
Message-ID: <400701EE.3060707@pobox.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 80 bytes --]
Regarding the recent discussion on bonding/vlan/bridge/blah configuration...
[-- Attachment #2: [PATCH] add sysfs class support for raw devices [06/10] --]
[-- Type: message/rfc822, Size: 6233 bytes --]
From: Greg KH <greg@kroah.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, linux-hotplug-devel@lists.sourceforge.net
Subject: [PATCH] add sysfs class support for raw devices [06/10]
Date: Thu, 15 Jan 2004 12:42:41 -0800
Message-ID: <20040115204241.GG22199@kroah.com>
This adds class/raw/ support for all raw devices. It also provides a
symlink to the block device that the raw device is mapped to. For
example:
$ tree /sys/class/raw/
/sys/class/raw/
|-- raw1
| |-- dev
| `-- device -> ../../../block/sda
|-- raw2
| |-- dev
| `-- device -> ../../../block/sda/sda2
`-- rawctl
`-- dev
Note, in order to get that symlink, I had to export get_gendisk() so that
modules can use it. I hope this is ok with everyone.
This is based on a patch originally written by
Leann Ogasawara <ogasawara@osdl.org>
diff -Nru a/drivers/block/genhd.c b/drivers/block/genhd.c
--- a/drivers/block/genhd.c Thu Jan 15 11:05:57 2004
+++ b/drivers/block/genhd.c Thu Jan 15 11:05:57 2004
@@ -224,6 +224,8 @@
return kobj ? to_disk(kobj) : NULL;
}
+EXPORT_SYMBOL(get_gendisk);
+
#ifdef CONFIG_PROC_FS
/* iterator */
static void *part_start(struct seq_file *part, loff_t *pos)
diff -Nru a/drivers/char/raw.c b/drivers/char/raw.c
--- a/drivers/char/raw.c Thu Jan 15 11:05:47 2004
+++ b/drivers/char/raw.c Thu Jan 15 11:05:47 2004
@@ -17,6 +17,8 @@
#include <linux/raw.h>
#include <linux/capability.h>
#include <linux/uio.h>
+#include <linux/device.h>
+#include <linux/genhd.h>
#include <asm/uaccess.h>
@@ -25,6 +27,7 @@
int inuse;
};
+static struct class_simple *raw_class;
static struct raw_device_data raw_devices[MAX_RAW_MINORS];
static DECLARE_MUTEX(raw_mutex);
static struct file_operations raw_ctl_fops; /* forward declaration */
@@ -119,6 +122,29 @@
return ioctl_by_bdev(bdev, command, arg);
}
+static void bind_device(struct raw_config_request rq)
+{
+ int part;
+ struct gendisk *gen;
+ struct class_device *dev;
+ struct kobject *target = NULL;
+
+ gen = get_gendisk(MKDEV(rq.block_major, rq.block_minor), &part);
+ if (gen) {
+ if (part && gen->part[part])
+ target = &gen->part[part]->kobj;
+ else
+ target = &gen->kobj;
+ }
+
+ class_simple_device_remove(MKDEV(RAW_MAJOR, rq.raw_minor));
+ dev = class_simple_device_add(raw_class, MKDEV(RAW_MAJOR, rq.raw_minor),
+ NULL, "raw%d", rq.raw_minor);
+ if (dev && target) {
+ sysfs_create_link(&dev->kobj, target, "device");
+ }
+}
+
/*
* Deal with ioctls against the raw-device control interface, to bind
* and unbind other raw devices.
@@ -187,12 +213,15 @@
if (rq.block_major == 0 && rq.block_minor == 0) {
/* unbind */
rawdev->binding = NULL;
+ class_simple_device_remove(MKDEV(RAW_MAJOR, rq.raw_minor));
} else {
rawdev->binding = bdget(dev);
if (rawdev->binding == NULL)
err = -ENOMEM;
- else
+ else {
__module_get(THIS_MODULE);
+ bind_device(rq);
+ }
}
up(&raw_mutex);
} else {
@@ -262,6 +291,14 @@
int i;
register_chrdev(RAW_MAJOR, "raw", &raw_fops);
+
+ raw_class = class_simple_create(THIS_MODULE, "raw");
+ if (IS_ERR(raw_class)) {
+ printk (KERN_ERR "Error creating raw class.\n");
+ return PTR_ERR(raw_class);
+ }
+ class_simple_device_add(raw_class, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
+
devfs_mk_cdev(MKDEV(RAW_MAJOR, 0),
S_IFCHR | S_IRUGO | S_IWUGO,
"raw/rawctl");
@@ -280,6 +317,8 @@
devfs_remove("raw/raw%d", i);
devfs_remove("raw/rawctl");
devfs_remove("raw");
+ class_simple_device_remove(MKDEV(RAW_MAJOR, 0));
+ class_simple_destroy(raw_class);
unregister_chrdev(RAW_MAJOR, "raw");
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
reply other threads:[~2004-01-15 21:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=400701EE.3060707@pobox.com \
--to=jgarzik@pobox.com \
--cc=netdev@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.