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

[Minios-devel] [UNIKRAFT PATCH v4 3/5] lib/vfscore: Automount option



Moves the option of automatically a rootfs to lib/vfscore. This
feature is not only useful for initializing devfs. Library parameters
to influence the default settings are provided.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/devfs/Config.uk     |  9 ++--
 lib/devfs/devfs_vnops.c |  8 +---
 lib/vfscore/Config.uk   | 81 +++++++++++++++++++++++++++++++++-
 lib/vfscore/Makefile.uk |  5 +++
 lib/vfscore/rootfs.c    | 97 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 188 insertions(+), 12 deletions(-)
 create mode 100644 lib/vfscore/rootfs.c

diff --git a/lib/devfs/Config.uk b/lib/devfs/Config.uk
index e38a616e..6f21c01c 100644
--- a/lib/devfs/Config.uk
+++ b/lib/devfs/Config.uk
@@ -1,10 +1,11 @@
-config LIBDEVFS
+menuconfig LIBDEVFS
        bool "devfs: devfs file system"
        default n
        depends on LIBVFSCORE
+
 if LIBDEVFS
-        config LIBDEVFS_USE_RAMFS
-        bool "Use ramfs as root"
+       config LIBDEVFS_AUTOMOUNT
+        bool "Mount /dev during boot"
+       depends on LIBVFSCORE_AUTOMOUNT_ROOTFS
         default n
-        select LIBRAMFS
 endif
diff --git a/lib/devfs/devfs_vnops.c b/lib/devfs/devfs_vnops.c
index 11a3ea05..d872e622 100644
--- a/lib/devfs/devfs_vnops.c
+++ b/lib/devfs/devfs_vnops.c
@@ -312,15 +312,9 @@ UK_FS_REGISTER(fs_devfs);
 
 __constructor_prio(101) static void devfs_init(void)
 {
-#ifdef CONFIG_LIBDEVFS_USE_RAMFS
+#ifdef CONFIG_LIBDEVFS_AUTOMOUNT
        int ret;
 
-       ret = mount("", "/", "ramfs", 0, NULL);
-       if (ret != 0) {
-               uk_pr_debug("Failed to mount / in %s\n", __func__);
-               return;
-       }
-
        ret =  mkdir("/dev", S_IRWXU);
        if (ret != 0) {
                uk_pr_debug("Failed to mkdir /dev in %s\n", __func__);
diff --git a/lib/vfscore/Config.uk b/lib/vfscore/Config.uk
index 5deb7d04..527922da 100644
--- a/lib/vfscore/Config.uk
+++ b/lib/vfscore/Config.uk
@@ -1,4 +1,4 @@
-menuconfig LIBVFSCORE
+config LIBVFSCORE
        bool "vfscore: VFS Core Interface"
        default n
        select LIBNOLIBC if !HAVE_LIBC
@@ -6,6 +6,7 @@ menuconfig LIBVFSCORE
        select LIBUKLOCK
 
 if LIBVFSCORE
+menu "vfscore: Configuration"
 
 config LIBVFSCORE_PIPE_SIZE_ORDER
        int "Pipe size order"
@@ -13,4 +14,82 @@ config LIBVFSCORE_PIPE_SIZE_ORDER
        help
                The size of the internal buffer for anonymous pipes is 2^order.
 
+config LIBVFSCORE_AUTOMOUNT_ROOTFS
+bool "Automatically mount a root filesysytem (/)"
+default n
+help
+       Automatically mounts '/' during boot. If `libuklibparam` is
+       compiled in, the default root filesystem and mount options can
+       be changed with the following library parameters:
+       'vfs.rootfs', 'vfs.rootdev', 'vfs.rootflags', and 'vfs.rootopts'
+
+if LIBVFSCORE_AUTOMOUNT_ROOTFS
+       choice LIBVFSCORE_ROOTFS
+       prompt "Default root filesystem"
+       default LIBVFSCORE_ROOTFS_RAMFS
+
+               config LIBVFSCORE_ROOTFS_RAMFS
+               bool "RamFS"
+               select LIBRAMFS
+
+               config LIBVFSCORE_ROOTFS_9PFS
+               bool "9PFS"
+               select LIBUK9P
+               select LIB9PFS
+
+               config LIBVFSCORE_ROOTFS_CUSTOM
+               bool "Custom argument"
+               help
+                       Please set LIBVFSCORE_ROOTFS_CUSTOM_ARG
+                       to a filesystem name that should be used
+                       as default.
+       endchoice
+
+       config LIBVFSCORE_ROOTFS_CUSTOM_ARG
+       string "Default custom root filesystem"
+       default ""
+       depends on LIBVFSCORE_ROOTFS_CUSTOM
+       help
+               Custom name of a filesystem to mount (e.g., ramfs,
+               9pfs). Make sure that the specified filesystem
+               is available for libvfscore.
+
+       # Hidden configuration option that gets automatically filled
+       # with the selected filesystem name
+       config LIBVFSCORE_ROOTFS
+       string
+       default "ramfs" if LIBVFSCORE_ROOTFS_RAMFS
+       default "9pfs" if LIBVFSCORE_ROOTFS_9PFS
+       default LIBVFSCORE_ROOTFS_CUSTOM_ARG if LIBVFSCORE_ROOTFS_CUSTOM
+       default ""
+
+       # The root device option is hidden for RamFS and 9PFS
+       config LIBVFSCORE_ROOTDEV
+       string "Default root device"
+       depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_9PFS
+       default ""
+       help
+               Device to mount the filesystem from. Depending on the
+               selected filesystem, this option may not be required.
+
+       # The root flags is hidden for RamFS
+       config LIBVFSCORE_ROOTFLAGS
+       hex "Default root mount flags"
+       depends on !LIBVFSCORE_ROOTFS_RAMFS
+       default 0x0
+       help
+               Mount flags.
+
+       # The root options are hidden for RamFS
+       config LIBVFSCORE_ROOTOPTS
+       string "Default root mount options"
+       depends on !LIBVFSCORE_ROOTFS_RAMFS
+       default ""
+       help
+               Usually a comma-separated list of additional mount
+               options that are directly interpreted by the target
+               filesystem.
+endif
+
+endmenu
 endif
diff --git a/lib/vfscore/Makefile.uk b/lib/vfscore/Makefile.uk
index 0a3974fe..e0daa5fa 100644
--- a/lib/vfscore/Makefile.uk
+++ b/lib/vfscore/Makefile.uk
@@ -1,5 +1,8 @@
 $(eval $(call addlib_s,libvfscore,$(CONFIG_LIBVFSCORE)))
 
+# Register to uklibparam, sets "vfs" as parameter prefix (vfs.*)
+$(eval $(call addlib_paramprefix,libvfscore,vfs))
+
 CINCLUDES-y += -I$(LIBVFSCORE_BASE)/include
 
 LIBVFSCORE_CFLAGS-$(call gcc_version_ge,8,0) += -Wno-cast-function-type
@@ -18,6 +21,8 @@ LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/fops.c
 LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/subr_uio.c
 LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/pipe.c
 LIBVFSCORE_SRCS-y += $(LIBVFSCORE_BASE)/extra.ld
+LIBVFSCORE_SRCS-$(CONFIG_LIBVFSCORE_AUTOMOUNT_ROOTFS) += \
+       $(LIBVFSCORE_BASE)/rootfs.c
 
 
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += writev-3
diff --git a/lib/vfscore/rootfs.c b/lib/vfscore/rootfs.c
new file mode 100644
index 00000000..4b9512a4
--- /dev/null
+++ b/lib/vfscore/rootfs.c
@@ -0,0 +1,97 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Mount VFS root
+ *
+ * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ *
+ *
+ * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
+ *                     All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <errno.h>
+#include <uk/config.h>
+#include <uk/arch/types.h>
+#include <uk/libparam.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <uk/init.h>
+
+static const char *rootfs   = CONFIG_LIBVFSCORE_ROOTFS;
+
+#ifndef CONFIG_LIBVFSCORE_ROOTDEV
+static const char *rootdev  = "";
+#else
+static const char *rootdev  = CONFIG_LIBVFSCORE_ROOTDEV;
+#endif
+
+#ifndef CONFIG_LIBVFSCORE_ROOTOPTS
+static const char *rootopts = "";
+#else
+static const char *rootopts = CONFIG_LIBVFSCORE_ROOTOPTS;
+#endif
+
+#ifndef CONFIG_LIBVFSCORE_ROOTFLAGS
+static __u64 rootflags;
+#else
+static __u64 rootflags      = (__u64) CONFIG_LIBVFSCORE_ROOTFLAGS;
+#endif
+
+UK_LIB_PARAM_STR(rootfs);
+UK_LIB_PARAM_STR(rootdev);
+UK_LIB_PARAM_STR(rootopts);
+UK_LIB_PARAM(rootflags, __u64);
+
+static int vfscore_rootfs(void)
+{
+       /*
+        * Initialization of the root filesystem '/'
+        * NOTE: Any additional sub mount points (like '/dev' with devfs)
+        * have to be mounted later.
+        */
+       if (!rootfs || rootfs[0] == '\0') {
+               uk_pr_crit("Parameter 'vfs.rootfs' is invalid\n");
+               return -1;
+       }
+
+       uk_pr_info("Mount %s to /...\n", rootfs);
+       if (mount(rootdev, "/", rootfs, rootflags, rootopts) != 0) {
+               uk_pr_crit("Failed to mount /: %d\n", errno);
+               return -1;
+       }
+
+       /*
+        * TODO: Alternatively we could extract an archive found
+        * as initrd to a ramfs '/' if we have got fsname 'initrd'
+        */
+
+       return 0;
+}
+
+uk_rootfs_initcall_prio(vfscore_rootfs, 4);
-- 
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®.