]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Add support to mount initramfs to root
authorAlexander Jung <a.jung@lancs.ac.uk>
Mon, 12 Apr 2021 10:43:26 +0000 (12:43 +0200)
committerUnikraft <monkey@unikraft.io>
Mon, 5 Jul 2021 04:47:27 +0000 (04:47 +0000)
Modify vfscore boot operation to run cpio extraction algorithm on initrd
memory region and mount the resulting filesystem at root.

Signed-off-by: Robert Hrusecky <roberth@cs.utexas.edu>
Signed-off-by: Omar Jamil <omarj2898@gmail.com>
Signed-off-by: Sachin Beldona <sachinbeldona@utexas.edu>
Signed-off-by: Gabriel Mocanu <gabi.mocanu98@gmail.com>
Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #179

lib/vfscore/Config.uk
lib/vfscore/rootfs.c

index 212575c0bec34546ba97f5c07801ddf00478ede9..1140e7950772c0ab2963135c0f1c7d72139995fa 100644 (file)
@@ -38,6 +38,11 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
                select LIBUK9P
                select LIB9PFS
 
+               config LIBVFSCORE_ROOTFS_INITRD
+               bool "InitRD"
+               select LIBRAMFS
+               select LIBUKCPIO
+
                config LIBVFSCORE_ROOTFS_CUSTOM
                bool "Custom argument"
                help
@@ -61,13 +66,14 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
        string
        default "ramfs" if LIBVFSCORE_ROOTFS_RAMFS
        default "9pfs" if LIBVFSCORE_ROOTFS_9PFS
+       default "initrd" if LIBVFSCORE_ROOTFS_INITRD
        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
+       depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_INITRD
        default "rootfs" if LIBVFSCORE_ROOTFS_9PFS
        default ""
        help
@@ -78,7 +84,7 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
        # The root flags is hidden for RamFS
        config LIBVFSCORE_ROOTFLAGS
        hex "Default root mount flags"
-       depends on !LIBVFSCORE_ROOTFS_RAMFS
+       depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_INITRD
        default 0x0
        help
                Mount flags.
@@ -86,7 +92,7 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
        # The root options are hidden for RamFS
        config LIBVFSCORE_ROOTOPTS
        string "Default root mount options"
-       depends on !LIBVFSCORE_ROOTFS_RAMFS
+       depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_INITRD
        default ""
        help
                Usually a comma-separated list of additional mount
index 8a6e099f4a96e1e50bde1f28dd694d79d7580fd2..6eb20531e7876dec40db36f08d76b905bc4b4f22 100644 (file)
@@ -3,7 +3,9 @@
  * Mount VFS root
  *
  * Authors: Simon Kuenzer <simon.kuenzer@neclab.eu>
- *
+ *          Robert Hrusecky <roberth@cs.utexas.edu>
+ *          Omar Jamil <omarj2898@gmail.com>
+ *          Sachin Beldona <sachinbeldona@utexas.edu>
  *
  * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
  *                     All rights reserved.
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <uk/init.h>
+#ifdef CONFIG_LIBVFSCORE_ROOTFS_INITRD
+#include <uk/plat/memory.h>
+#include <uk/cpio.h>
+#include <string.h>
+#endif /* CONFIG_LIBVFSCORE_ROOTFS_INITRD */
 
 static const char *rootfs   = CONFIG_LIBVFSCORE_ROOTFS;
 
@@ -78,17 +85,44 @@ static int vfscore_rootfs(void)
                return -1;
        }
 
+#if CONFIG_LIBVFSCORE_ROOTFS_INITRD
+       if (strncmp(rootfs, "initrd", 5) == 0) {
+               struct ukplat_memregion_desc initrd;
+               enum ukcpio_error error;
+
+               if (ukplat_memregion_find_initrd0(&initrd) < 0) {
+                       uk_pr_crit("Could not find an initrd!\n");
+                       return -1;
+               }
+
+               uk_pr_info("Mount ramfs to /...\n");
+
+               if (mount("", "/", "ramfs", 0, NULL) != 0) {
+                       uk_pr_crit("Failed to mount ramfs to /: %d\n",
+                                  errno);
+                       return -1;
+               }
+
+               uk_pr_info("Extracting initrd @ %p (%"__PRIsz" bytes) to /...\n",
+                          initrd.base, initrd.len);
+
+               error = ukcpio_extract("/", initrd.base, initrd.len);
+               if (error < 0) {
+                       uk_pr_crit("Failed to extract cpio archive to /: %d\n",
+                                  error);
+                       return -1;
+               }
+
+               return 0;
+       }
+#endif /* CONFIG_LIBVFSCORE_ROOTFS_INITRD */
+
        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;
 }