summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2007-05-21 14:25:44 +1000
committerNeil Brown <neilb@suse.de>2007-05-21 14:25:44 +1000
commit1f48664b8e65cafa65d121bb626649a6310cfaf2 (patch)
tree83ecb51e0102d5ae4e4a7bd50930ade1301bfd75
parent69646c1483b7b728d77ae2c944d624f8c05ad4db (diff)
downloadmdadm-1f48664b8e65cafa65d121bb626649a6310cfaf2.tar.gz
mdadm-1f48664b8e65cafa65d121bb626649a6310cfaf2.tar.xz
mdadm-1f48664b8e65cafa65d121bb626649a6310cfaf2.zip
Add --auto-detect for in-kernel autodetect.
This is equivalent to raidautorun that some distros provide.
-rw-r--r--ChangeLog1
-rw-r--r--Manage.c13
-rw-r--r--ReadMe.c3
-rw-r--r--mdadm.821
-rw-r--r--mdadm.c7
-rw-r--r--mdadm.h3
-rw-r--r--test2
-rw-r--r--tests/07autodetect25
8 files changed, 74 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a25463e..2d81c3d 100644
--- 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.
diff --git a/Manage.c b/Manage.c
index 3deb8ea..d857c99 100644
--- 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
diff --git a/ReadMe.c b/ReadMe.c
index a967b3f..679778c 100644
--- 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 16f71f2..e70a1a9 100644
--- 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 2abf86b..43620b7 100644
--- 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 da6b3b2..e6b03c5 100644
--- 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 3029b69..d271985 100644
--- 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
diff --git a/tests/07autodetect b/tests/07autodetect
index e69de29..3e338f8 100644
--- a/tests/07autodetect
+++ b/tests/07autodetect
@@ -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