* [PATCH] add "autorun" interface to md
@ 2001-07-24 16:24 Kees Cook
2001-07-25 13:13 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2001-07-24 16:24 UTC (permalink / raw)
To: linux-kernel
I sent this to the linux-raid list, but the list appears dead? I guess
I'll go here instead. Flame me nicely if I should send it elsewhere. :)
After boot-up (or as a module) the "md" driver has no interface to run the
"autostart_arrays" function. In the case of removable disks (eg USB, or
in my case, FireWire), since the disks may not appear in the same place,
or in the same order, the standard raidtools' "raidstart" will not work
(calling the md.c "raidstart" interface) because the device names don't
match up.
While I have this sneaking worry that md's persistant superblock may be
the part of this design that needs adjusting, the existing code lacks an
interface to the "autorun" feature available during boot time. The
interface I've made depends on the user to hand md.c the partitions to use
for the auto-starting (normally this is done by the "partitions" code).
I'm not sure if this is done properly (we used the proc interface example
from /proc/scsi/scsi), but I'd like to at least start a discussion so I
can autorun my removable raid the "right" way. ;)
Thanks go to Aaron Botsis who got me started by writing the proc-write
skeleton while I was agonizing over how to parse the input.
For reference, this would auto-run a raid on the sdd1, sde1, sdf1,
sdg1 partitions:
echo "autorun 8:49 8:65 8:81 8:97" > /proc/mdstat
---begin---
--- linux-2.4.7/drivers/md/md.orig.c Wed Jul 18 09:32:13 2001
+++ linux-2.4.7/drivers/md/md.c Sat Jul 21 09:19:35 2001
@@ -52,6 +52,11 @@
#define MAJOR_NR MD_MAJOR
#define MD_DRIVER
+#define PROC_BLOCK_SIZE (3*1024) /* 4K page size, but our output routines
+ * use some slack for overruns
+ */
+
+
#include <linux/blk.h>
#define DEBUG 0
@@ -61,9 +66,7 @@
# define dprintk(x...) do { } while(0)
#endif
-#ifndef MODULE
static void autostart_arrays (void);
-#endif
static mdk_personality_t *pers[MAX_PERSONALITY];
@@ -1086,8 +1089,10 @@
mdk_rdev_t *rdev;
unsigned int size;
- if (find_rdev_all(newdev))
+ if (find_rdev_all(newdev)) {
+ printk("find_rdev_all failed for %s!\n", partition_name(newdev));
return -EEXIST;
+ }
rdev = (mdk_rdev_t *) kmalloc(sizeof(*rdev), GFP_KERNEL);
if (!rdev) {
@@ -1103,8 +1108,10 @@
goto abort_free;
}
- if ((err = alloc_disk_sb(rdev)))
+ if ((err = alloc_disk_sb(rdev))) {
+ printk("alloc_disk_sb failed for %s!\n", partition_name(newdev));
goto abort_free;
+ }
rdev->dev = newdev;
if (lock_rdev(rdev)) {
@@ -1721,15 +1728,15 @@
#define STILL_MOUNTED KERN_WARNING \
"md: md%d still mounted.\n"
#define STILL_IN_USE \
-"md: md%d still in use.\n"
+"md: md%d still in use(%d).\n"
static int do_md_stop (mddev_t * mddev, int ro)
{
- int err = 0, resync_interrupted = 0;
+ int active, err = 0, resync_interrupted = 0;
kdev_t dev = mddev_to_kdev(mddev);
- if (atomic_read(&mddev->active)>1) {
- printk(STILL_IN_USE, mdidx(mddev));
+ if ((active=atomic_read(&mddev->active))>1) {
+ printk(STILL_IN_USE, mdidx(mddev), active);
OUT(-EBUSY);
}
@@ -2777,6 +2784,7 @@
static int md_release (struct inode *inode, struct file * file)
{
mddev_t *mddev = kdev_to_mddev(inode->i_rdev);
+
if (mddev)
atomic_dec(&mddev->active);
return 0;
@@ -3038,6 +3046,53 @@
return sz;
}
+static int md_status_write_proc(struct file *file, const char *buf,
+ unsigned long count, void *data)
+{
+ char *page;
+ char *ptr;
+
+ if (count > PROC_BLOCK_SIZE)
+ return -EOVERFLOW;
+
+ if (!(page=(char *) __get_free_page(GFP_KERNEL)))
+ return -ENOMEM;
+
+ copy_from_user(page, buf, count);
+
+
+ if (count > 0 && page[count-1]=='\n') {
+ page[count-1]='\0';
+ }
+ else return -EINVAL;
+
+ if (count<11)
+ return -EINVAL;
+
+ if (!strncmp("autorun ",page,8)) {
+ char * devstr;
+ char * major, * minor;
+ int dev;
+
+ ptr=page+8;
+
+ while ((devstr=strsep(&ptr," \n"))) {
+ printk("md: adding %s...\n",devstr);
+ major=strsep(&devstr,":");
+ minor=strsep(&devstr,":");
+
+ dev=MKDEV(simple_strtoul(major,NULL,0),
+ simple_strtoul(minor,NULL,0));
+ md_autodetect_dev(dev);
+ }
+
+ autostart_arrays();
+ }
+
+
+ free_page((ulong) page);
+ return count;
+}
static int md_status_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
@@ -3489,6 +3544,7 @@
static void md_geninit (void)
{
int i;
+ struct proc_dir_entry *p;
for(i = 0; i < MAX_MD_DEVS; i++) {
md_blocksizes[i] = 1024;
@@ -3504,7 +3560,8 @@
dprintk("md: sizeof(mdp_super_t) = %d\n", (int)sizeof(mdp_super_t));
#ifdef CONFIG_PROC_FS
- create_proc_read_entry("mdstat", 0, NULL, md_status_read_proc, NULL);
+ p=create_proc_read_entry("mdstat", 0, NULL, md_status_read_proc, NULL);
+ p->write_proc=md_status_write_proc;
#endif
}
@@ -3553,8 +3610,6 @@
}
-#ifndef MODULE
-
/*
* When md (and any require personalities) are compiled into the kernel
* (not a module), arrays can be assembles are boot time using with AUTODETECT
@@ -3617,6 +3672,7 @@
autorun_devices(-1);
}
+#ifndef MODULE
static struct {
char device_set [MAX_MD_DEVS];
int pers[MAX_MD_DEVS];
---end---
--
Kees Cook @outflux.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add "autorun" interface to md
2001-07-24 16:24 [PATCH] add "autorun" interface to md Kees Cook
@ 2001-07-25 13:13 ` Kees Cook
2001-07-26 1:34 ` Neil Brown
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2001-07-25 13:13 UTC (permalink / raw)
To: linux-kernel
Any one out there working on the "md" driver?
--
Kees Cook @outflux.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add "autorun" interface to md
2001-07-25 13:13 ` Kees Cook
@ 2001-07-26 1:34 ` Neil Brown
0 siblings, 0 replies; 3+ messages in thread
From: Neil Brown @ 2001-07-26 1:34 UTC (permalink / raw)
To: Kees Cook; +Cc: linux-kernel
On Wednesday July 25, linux-kernel@outflux.net wrote:
>
> Any one out there working on the "md" driver?
>
Yes, I'm doing a fair bit.
If you are interested in the "md" driver, you really should join
linux-raid@vger.kernel.org
With reguard to your patch, the short answer is that you really don't
want to do that (or atleast, I don't want to, and I think that you
should agree with me:-)
autorun/autodetect just doesn't belong in the kernel. It should be
done in user space. The only time the kernel should assemble a raid
array itself is for the root device, and this is best done with
md=0,/dev/whatever,etc
If I could start with a clean slate, I would rip out the autodetect
stuff completely. But lots of people are depending on it so I cannot.
It is true that there is not currently any userlevel tool which does
the equivalent of autodetect, but there will be soon. It has been
mentioned on linux-raid and an announcement will go there when it is
ready for wider testing.
You can find the current pre-release at:
http://www.cse.unsw.edu.au/~neilb/source/mdctl/
NeilBrown
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-07-26 1:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-24 16:24 [PATCH] add "autorun" interface to md Kees Cook
2001-07-25 13:13 ` Kees Cook
2001-07-26 1:34 ` Neil Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).