[PATCH] mdev: do not remove device nodes from devtmpfs
Floris Bos
bos at je-eigen-domein.nl
Sat Apr 18 22:28:45 UTC 2015
Upon receiving notice of the removal of a device check if /dev is
using devtmpfs. If so, do not remove the device node file, but
let devtmpfs take care of that.
Solves the following problem:
The kernel sometimes sends a REMOVE and ADD event after each other,
for example after a partition is added to storage, and the partition
table is re-read.
When letting mdev delete device node files, there is a high
probability that it processes the two events out-of-order
resulting in the unjust removal of device node files.
Devtmpfs is not affected by that, and if deletion is really
justified will do so anyway, so is the better choice for
this particular task.
Signed-off-by: Floris Bos <bos at je-eigen-domein.nl>
---
util-linux/mdev.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index ccc00d3..f58e76f 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -98,6 +98,7 @@
#include "libbb.h"
#include "xregex.h"
+#include <mntent.h>
/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
* file (it is of the form "M:m\n"). Example: /sys/class/tty/tty0/dev
@@ -539,6 +540,18 @@ static char *build_alias(char *alias, const char *device_name)
return alias;
}
+/* Returns TRUE if /dev is on a devtmpfs file system
+ */
+static int using_devtmpfs(void)
+{
+ struct mntent *mnt = find_mount_point("/dev", 0);
+
+ if (mnt && strcmp(mnt->mnt_type, "devtmpfs") == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
/* mknod in /dev based on a path like "/sys/block/hda/hda1"
* NB1: path parameter needs to have SCRATCH_SIZE scratch bytes
* after NUL, but we promise to not mangle (IOW: to restore NUL if needed)
@@ -793,8 +806,10 @@ static void make_device(char *device_name, char *path, int operation)
unlink(device_name);
}
}
- dbg1("unlink: %s", node_name);
- unlink(node_name);
+ if (!using_devtmpfs()) {
+ dbg1("unlink: %s", node_name);
+ unlink(node_name);
+ }
}
if (ENABLE_FEATURE_MDEV_RENAME)
--
1.9.1
More information about the busybox
mailing list