diff options
author | NeilBrown <neilb@suse.de> | 2013-07-02 02:24:50 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-07-02 02:24:50 +0200 |
commit | 289c74f8d7912f8b7e0d98f152c3f5a9a70514f7 (patch) | |
tree | 3ea61c087e12500c574a0eb2337934228ba60e3d /mdopen.c | |
parent | Move conf_line and free_line from conf.c to lib.c (diff) | |
download | mdadm-289c74f8d7912f8b7e0d98f152c3f5a9a70514f7.tar.xz mdadm-289c74f8d7912f8b7e0d98f152c3f5a9a70514f7.zip |
Move find_free_devnum to mdopen.c
There is only one called to find_free_devnum and it is in mdopen.c
The removes a dependency between util.c and config.c which allows
us to now drop config.o from mdmon.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mdopen.c')
-rw-r--r-- | mdopen.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -438,3 +438,36 @@ int open_mddev(char *dev, int report_errors) } return mdfd; } + +char *find_free_devnm(int use_partitions) +{ + static char devnm[32]; + int devnum; + for (devnum = 127; devnum != 128; + devnum = devnum ? devnum-1 : (1<<20)-1) { + + if (use_partitions) + sprintf(devnm, "md_d%d", devnum); + else + sprintf(devnm, "md%d", devnum); + if (mddev_busy(devnm)) + continue; + if (!conf_name_is_free(devnm)) + continue; + if (!use_udev()) { + /* make sure it is new to /dev too, at least as a + * non-standard */ + int devid = devnm2devid(devnm); + if (devid) { + char *dn = map_dev(major(devid), + minor(devid), 0); + if (dn && ! is_standard(dn, NULL)) + continue; + } + } + break; + } + if (devnum == 128) + return NULL; + return devnm; +} |