]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add --auto-detect for in-kernel autodetect.
authorNeil Brown <neilb@suse.de>
Mon, 21 May 2007 04:25:44 +0000 (14:25 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 21 May 2007 04:25:44 +0000 (14:25 +1000)
This is equivalent to raidautorun that some distros provide.

ChangeLog
Manage.c
ReadMe.c
mdadm.8
mdadm.c
mdadm.h
test
tests/07autodetect

index a25463e2bb24930be2300aeece4f3fda39237f87..2d81c3da7842538ba029c67ac910c0f019b17bdd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ Changes Prior to this release
     -   --help now goes to stdout so you can direct it to a pager.
     -   Various manpage updates.
     -   Make "--grow --add" for linear arrays really work.
+    -   --auto-detect to trigger in-kernel autodetect.
 
 Changes Prior to 2.6.1 release
     -   --monitor was producing some meaningless warnings due to a bug.
index 3deb8ead690d8a2af899e1fc366626192f1a529a..d857c99ea568c0f391c19649897d003f8dfd50fa 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -507,4 +507,17 @@ int Manage_subdevs(char *devname, int fd,
        return 0;
        
 }
+
+int autodetect(void)
+{
+       /* Open any md device, and issue the RAID_AUTORUN ioctl */
+       int rv = 1;
+       int fd = dev_open("9:0", O_RDONLY);
+       if (fd >= 0) {
+               if (ioctl(fd, RAID_AUTORUN, 0) == 0)
+                       rv = 0;
+               close(fd);
+       }
+       return rv;
+}
 #endif
index a967b3fa32af0876ee818017171a7800bd80bdef..679778ce36fbde06355d5583099907d57eec67fa 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -109,6 +109,7 @@ struct option long_options[] = {
     {"zero-superblock", 0, 0, 'K'}, /* deliberately no a short_option */
     {"query",    0, 0, 'Q'},
     {"examine-bitmap", 0, 0, 'X'},
+    {"auto-detect", 0, 0, AutoDetect},
 
     /* synonyms */
     {"monitor",   0, 0, 'F'},
@@ -255,6 +256,7 @@ char OptionHelp[] =
 "  --incremental -I   : add a single device to an array as appropriate\n"
 "  --query       -Q   : Display general information about how a\n"
 "                       device relates to the md driver\n"
+"  --auto-detect      : Start arrays auto-detected by the kernel\n"
 ;
 /*
 "\n"
@@ -624,6 +626,7 @@ mapping_t modes[] = {
        { "monitor", MONITOR},
        { "grow", GROW},
        { "incremental", INCREMENTAL},
+       { "auto-detect", AUTODETECT},
 };
 
 mapping_t faultylayout[] = {
diff --git a/mdadm.8 b/mdadm.8
index 16f71f20b8cd9177dde4bc2c49d6ff891b457c83..e70a1a92cb53201319c5d1eafda3bb61571872c1 100644 (file)
--- a/mdadm.8
+++ b/mdadm.8
@@ -154,6 +154,10 @@ information gathering operations.
 '''This mode allows operations on independent devices such as examine MD
 '''superblocks, erasing old superblocks and stopping active arrays.
 
+.TP
+.B Auto-detect
+This mode does not act on a specific device or array, but rather it
+requests the Linux Kernel to activate any auto-detected arrays.
 .SH OPTIONS
 
 .SH Options for selecting a mode are:
@@ -181,9 +185,24 @@ mode.
 Change the size or shape of an active array.
 
 .TP
-.BE \-I ", " \-\-incremental
+.BR \-I ", " \-\-incremental
 Add a single device into an appropriate array, and possibly start the array.
 
+.TP
+.B \-\-auto-detect
+Request that the kernel starts any auto-detected arrays.  This can only
+work if
+.I md
+is compiled into the kernel \(em not if it is a module.
+Arrays can be auto-detected by the kernel if all the components are in
+primary MS-DOS partitions with partition type
+.BR FD .
+In-kernel autodetect is not recommended for new installations.  Using
+.I mdadm
+to detect and assemble arrays \(em possibly in an
+.I initrd
+\(em is substantially more flexible and should be preferred.
+
 .P
 If a device is given before any options, or if the first option is
 .BR \-\-add ,
diff --git a/mdadm.c b/mdadm.c
index 2abf86bb74f98fe382043fb68b9bf1c0ba154aa5..43620b7163bd17e7be050f763d9bdc3d271aed36 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -198,6 +198,8 @@ int main(int argc, char *argv[])
                case 'F': newmode = MONITOR;break;
                case 'G': newmode = GROW; shortopt = short_bitmap_auto_options; break;
                case 'I': newmode = INCREMENTAL; break;
+               case AutoDetect:
+                       newmode = AUTODETECT; break;
 
                case '#':
                case 'D':
@@ -277,6 +279,7 @@ int main(int argc, char *argv[])
                case 'F':
                case 'G':
                case 'I':
+               case AutoDetect:
                        continue;
                }
                if (opt == 1) {
@@ -1344,6 +1347,10 @@ int main(int argc, char *argv[])
                }
                rv = Incremental(devlist->devname, verbose-quiet, runstop,
                                 ss, homehost, autof);
+               break;
+       case AUTODETECT:
+               autodetect();
+               break;
        }
        exit(rv);
 }
diff --git a/mdadm.h b/mdadm.h
index da6b3b231e91d0706ab4495ebfbbbae4d962e4e0..e6b03c58c5d4cef213ee832ea022575c7f99f34e 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -151,6 +151,7 @@ enum mode {
        MONITOR,
        GROW,
        INCREMENTAL,
+       AUTODETECT,
 };
 
 extern char short_options[];
@@ -175,6 +176,7 @@ enum special_options {
        HomeHost,
        AutoHomeHost,
        Symlinks,
+       AutoDetect,
 };
 
 /* structures read from config file */
@@ -415,6 +417,7 @@ extern int Manage_resize(char *devname, int fd, long long size, int raid_disks);
 extern int Manage_reconfig(char *devname, int fd, int layout);
 extern int Manage_subdevs(char *devname, int fd,
                          mddev_dev_t devlist, int verbose);
+extern int autodetect(void);
 extern int Grow_Add_device(char *devname, int fd, char *newdev);
 extern int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int write_behind, int force);
 extern int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
diff --git a/test b/test
index 3029b69395e57bcc0dfcba63c18263857beca048..d2719854717a08ffbf2eaa5a292886f7b8dee9f6 100644 (file)
--- a/test
+++ b/test
@@ -21,6 +21,8 @@ fi
 
 # assume md0, md1, md2 exist in /dev
 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
+mdp0=/dev/md_d0
+mdp1=/dev/md_d1
 
 # We test mdadm on loop-back block devices.
 # dir for storing files should be settable by command line maybe
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..3e338f860243651b6717abae25e254d74299fc61 100644 (file)
@@ -0,0 +1,25 @@
+
+#
+# Test in-kernel autodetect.
+# Create a partitionable array on each of two devices,
+# put a partition on each, create an array, and see if we can
+# use autodetect to restart the array.
+
+mdadm -CR $mdp0 -l0 -f -n1 $dev0
+mdadm -CR $mdp1 -l0 -f -n1 $dev1
+sfdisk $mdp0 >&2 << END
+,,FD
+END
+sfdisk $mdp1 >&2 << END
+,,FD
+END
+mdadm -CR $md0 -l1 -n2 ${mdp0}p1 ${mdp1}p1
+check resync
+check raid1
+check wait
+mdadm -S $md0
+mdadm --auto-detect
+check raid1
+
+mdadm -Ss
+exit 0