summaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2018-05-15 12:11:18 +0100
committerDimitri John Ledkov <xnox@ubuntu.com>2018-05-15 12:11:18 +0100
commitf0819c18672a939ad2a6c00c6fa37f73be7a54f3 (patch)
tree8e82f1fe6b2f2979c2329eb5e2b72cb8f108048a /lib.c
parent22464b6f492163fabe1041b09e1d2f753fd0d31a (diff)
New upstream release.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index b640634..60890b9 100644
--- a/lib.c
+++ b/lib.c
@@ -61,7 +61,7 @@ int get_mdp_major(void)
return mdp_major;
}
-char *devid2kname(int devid)
+char *devid2kname(dev_t devid)
{
char path[30];
char link[PATH_MAX];
@@ -73,8 +73,7 @@ char *devid2kname(int devid)
* /sys/dev/block/%d:%d link which must look like
* and take the last component.
*/
- sprintf(path, "/sys/dev/block/%d:%d", major(devid),
- minor(devid));
+ sprintf(path, "/sys/dev/block/%d:%d", major(devid), minor(devid));
n = readlink(path, link, sizeof(link) - 1);
if (n > 0) {
link[n] = 0;
@@ -163,6 +162,35 @@ char *fd2devnm(int fd)
return NULL;
}
+/* When we create a new array, we don't want the content to
+ * be immediately examined by udev - it is probably meaningless.
+ * So create /run/mdadm/creating-mdXXX and expect that a udev
+ * rule will noticed this and act accordingly.
+ */
+static char block_path[] = "/run/mdadm/creating-%s";
+static char *unblock_path = NULL;
+void udev_block(char *devnm)
+{
+ int fd;
+ char *path = NULL;
+
+ xasprintf(&path, block_path, devnm);
+ fd = open(path, O_CREAT|O_RDWR, 0600);
+ if (fd >= 0) {
+ close(fd);
+ unblock_path = path;
+ } else
+ free(path);
+}
+
+void udev_unblock(void)
+{
+ if (unblock_path)
+ unlink(unblock_path);
+ free(unblock_path);
+ unblock_path = NULL;
+}
+
/*
* convert a major/minor pair for a block device into a name in /dev, if possible.
* On the first call, walk /dev collecting name.