[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v4 4/5] lib/devfs: Automount through inittab



The automount option of devfs to `/dev` is moved to an inittab entry.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/devfs/devfs_vnops.c          | 30 +++++++++++++++++++++---------
 lib/devfs/include/devfs/device.h |  9 +++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/lib/devfs/devfs_vnops.c b/lib/devfs/devfs_vnops.c
index d872e622..1e49e6bf 100644
--- a/lib/devfs/devfs_vnops.c
+++ b/lib/devfs/devfs_vnops.c
@@ -59,7 +59,8 @@
 
 #include <vfscore/fs.h>
 
-#include <uk/ctors.h>
+#include <uk/init.h>
+#include <uk/print.h>
 
 #include "devfs.h"
 #include <devfs/device.h>
@@ -310,21 +311,32 @@ static struct vfscore_fs_type fs_devfs = {
 
 UK_FS_REGISTER(fs_devfs);
 
-__constructor_prio(101) static void devfs_init(void)
-{
 #ifdef CONFIG_LIBDEVFS_AUTOMOUNT
+static int devfs_automount(void)
+{
        int ret;
 
+       uk_pr_info("Mount devfs to /dev...");
+
+       /*
+        * Try to create target mountpoint `/dev`. If creation fails
+        * because it already exists, we are continuing.
+        */
        ret =  mkdir("/dev", S_IRWXU);
-       if (ret != 0) {
-               uk_pr_debug("Failed to mkdir /dev in %s\n", __func__);
-               return;
+       if (ret != 0 && errno != EEXIST) {
+               uk_pr_err("Failed to create /dev: %d\n", errno);
+               return -1;
        }
 
        ret = mount("", "/dev", "devfs", 0, NULL);
        if (ret != 0) {
-               uk_pr_debug("Failed to mount /dev as devfs in %s\n", __func__);
-               return;
+               uk_pr_err("Failed to mount devfs to /dev: %d\n", errno);
+               return -1;
        }
-#endif
+
+       return 0;
 }
+
+/* after vfscore mounted '/' (priority 4): */
+uk_rootfs_initcall_prio(devfs_automount, 5);
+#endif
diff --git a/lib/devfs/include/devfs/device.h b/lib/devfs/include/devfs/device.h
index 29889e4e..46a6a85a 100644
--- a/lib/devfs/include/devfs/device.h
+++ b/lib/devfs/include/devfs/device.h
@@ -34,6 +34,7 @@
 #define _DEVICE_H
 
 #include <sys/types.h>
+#include <uk/init.h>
 
 #include <vfscore/uio.h>
 
@@ -208,4 +209,12 @@ int device_destroy_locked(struct device *dev);
 void device_register(struct device *device, const char *name, int flags);
 void read_partition_table(struct device *device);
 
+/*
+ * Ideally, any dev node registration should happen before we mount devfs.
+ * vfscore mounts '/' at priority 4, '/dev' is mounted at priority 5.
+ * To be on the safe side, we do the registration to devfs before both,
+ * at priority '3'.
+ */
+#define devfs_initcall(fn) uk_rootfs_initcall_prio(devfs_automount, 3)
+
 #endif /* !_DEVICE_H */
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.