summaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-04-18 11:00:07 +1000
committerNeilBrown <neilb@suse.de>2012-04-18 11:00:07 +1000
commitc2ecf5f61aca2d73b7d5a6cb3a26973916d5c0d1 (patch)
tree747e82e252a746c42c01879ec41587ae6c336935 /lib.c
parent480f3566411675ec41f18e5f6e15429f891e144c (diff)
Add --prefer option for --detail and --monitor
Both --detail and --monitor can report the names of member devices on an array, and do so by searching /dev and finding the shortest name that matches. If --prefer=foo is given, they will instead prefer a name that contain /foo/. So mdadm --detail /dev/md0 --prefer=by-path will list the component devices via their /dev/disk/by-path/xxx names. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 2739b3d3..c04f6a07 100644
--- a/lib.c
+++ b/lib.c
@@ -188,8 +188,11 @@ int nftw(const char *path, int (*han)(const char *name, const struct stat *stb,
* If we find multiple names, choose the shortest.
* If we find a name in /dev/md/, we prefer that.
* This applies only to names for MD devices.
+ * If 'prefer' is set (normally to e.g. /by-path/)
+ * then we prefer a name which contains that string.
*/
-char *map_dev(int major, int minor, int create)
+char *map_dev_preferred(int major, int minor, int create,
+ char *prefer)
{
struct devmap *p;
char *regular = NULL, *preferred=NULL;
@@ -219,7 +222,8 @@ char *map_dev(int major, int minor, int create)
for (p=devlist; p; p=p->next)
if (p->major == major &&
p->minor == minor) {
- if (strncmp(p->name, "/dev/md/",8) == 0) {
+ if (strncmp(p->name, "/dev/md/",8) == 0
+ || (prefer && strstr(p->name, prefer))) {
if (preferred == NULL ||
strlen(p->name) < strlen(preferred))
preferred = p->name;
@@ -243,6 +247,7 @@ char *map_dev(int major, int minor, int create)
}
+
/* conf_word gets one word from the conf file.
* if "allow_key", then accept words at the start of a line,
* otherwise stop when such a word is found.