]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Re-enable the mounting of `initrd`'s through `fstab`
authorSergiu Moga <sergiu@unikraft.io>
Mon, 23 Oct 2023 13:41:54 +0000 (16:41 +0300)
committerSergiu Moga <sergiu@unikraft.io>
Fri, 27 Oct 2023 13:39:46 +0000 (16:39 +0300)
After commit 9946c9329346 ("lib/vfscore: Embedded initrd"), the
mounting of `initrd`'s became dependent on having the option
`CONFIG_LIBVFSCORE_AUTOMOUNT_ROOTFS` enabled. Thus, if someone
wanted to mount an `initrd` through `fstab` only and with that
configuration option disabled, their build would fail.

Solve this dependency misconfiguration by making
`vfscore_mount_initrd_volume` only depend on  the
`CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS` options instead.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
lib/vfscore/automount.c

index b0a8c84573ee2e6576218dd574a95fc91f30ee83..c94b39f34b3dccb96e46bde97a420bc0abde7035 100644 (file)
@@ -78,6 +78,53 @@ struct vfscore_volume {
 #endif /* CONFIG_LIBVFSCORE_FSTAB */
 };
 
+#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
+static int do_mount_initrd(const void *initrd, size_t len, const char *path)
+{
+       int rc;
+
+       UK_ASSERT(path);
+
+       rc = mount("", path, "ramfs", 0x0, NULL);
+       if (unlikely(rc)) {
+               uk_pr_crit("Failed to mount ramfs to \"%s\": %d\n",
+                          path, errno);
+               return -1;
+       }
+
+       uk_pr_info("Extracting initrd @ %p (%"__PRIsz" bytes) to %s...\n",
+                  (void *)initrd, len, path);
+       rc = ukcpio_extract(path, (void *)initrd, len);
+       if (unlikely(rc)) {
+               uk_pr_crit("Failed to extract cpio archive to %s: %d\n",
+                          path, rc);
+               return -1;
+       }
+
+       return 0;
+}
+
+static int vfscore_mount_initrd_volume(struct vfscore_volume *vv)
+{
+       struct ukplat_memregion_desc *initrd;
+       int rc;
+
+       UK_ASSERT(vv);
+       UK_ASSERT(vv->path);
+
+       /* TODO: Support multiple Initial RAM Disks */
+       rc = ukplat_memregion_find_initrd0(&initrd);
+       if (unlikely(rc < 0)) {
+               uk_pr_crit("Could not find an initrd!\n");
+
+               return -1;
+       }
+
+       return do_mount_initrd((void *)initrd->vbase, initrd->len,
+                              vv->path);
+}
+#endif /* CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS */
+
 #if CONFIG_LIBVFSCORE_FSTAB
 /* Handle `mkmp` Unikraft Mount Option */
 static int vfscore_volume_process_ukopts_do_mkmp(char *path)
@@ -178,11 +225,20 @@ static int vfscore_volume_process_ukopts(struct vfscore_volume *vv)
 
 static inline int vfscore_mount_volume(struct vfscore_volume *vv)
 {
+       UK_ASSERT(vv);
+
 #if CONFIG_LIBVFSCORE_FSTAB
        vfscore_volume_process_ukopts(vv);
 #endif /* CONFIG_LIBVFSCORE_FSTAB */
 
-       return mount(vv->sdev, vv->path, vv->drv, vv->flags, vv->opts);
+#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
+       if (!strncmp(vv->drv, "initrd", sizeof("initrd") - 1)) {
+               return vfscore_mount_initrd_volume(vv);
+       } else
+#endif /* CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS */
+       {
+               return mount(vv->sdev, vv->path, vv->drv, vv->flags, vv->opts);
+       }
 }
 
 #ifdef CONFIG_LIBVFSCORE_FSTAB
@@ -282,34 +338,6 @@ static void vfscore_fstab_fetch_volume_args(char *v, struct vfscore_volume *vv)
 }
 #endif /* CONFIG_LIBVFSCORE_FSTAB */
 
-#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
-static int do_mount_initrd(const void *initrd, size_t len, const char *path)
-{
-       int rc;
-
-       UK_ASSERT(initrd);
-       UK_ASSERT(path);
-
-       rc = mount("", path, "ramfs", 0x0, NULL);
-       if (unlikely(rc)) {
-               uk_pr_crit("Failed to mount ramfs to \"%s\": %d\n",
-                          path, errno);
-               return -1;
-       }
-
-       uk_pr_info("Extracting initrd @ %p (%"__PRIsz" bytes) to %s...\n",
-                  (void *)initrd, len, path);
-       rc = ukcpio_extract(path, (void *)initrd, len);
-       if (unlikely(rc)) {
-               uk_pr_crit("Failed to extract cpio archive to %s: %d\n",
-                          path, rc);
-               return -1;
-       }
-
-       return 0;
-}
-#endif /* CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS */
-
 #if CONFIG_LIBVFSCORE_AUTOMOUNT_ROOTFS
 #if CONFIG_LIBVFSCORE_ROOTFS_EINITRD
 extern const char vfscore_einitrd_start[];
@@ -328,27 +356,6 @@ static int vfscore_automount_rootfs(void)
 }
 
 #else /* !CONFIG_LIBVFSCORE_ROOTFS_EINITRD */
-#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
-static int vfscore_mount_initrd_volume(struct vfscore_volume *vv)
-{
-       struct ukplat_memregion_desc *initrd;
-       int rc;
-
-       UK_ASSERT(vv);
-
-       /* TODO: Support multiple Initial RAM Disks */
-       rc = ukplat_memregion_find_initrd0(&initrd);
-       if (unlikely(rc < 0)) {
-               uk_pr_crit("Could not find an initrd!\n");
-
-               return -1;
-       }
-
-       return do_mount_initrd((void *)initrd->vbase, initrd->len,
-                              vv->path);
-}
-#endif /* CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS */
-
 static int vfscore_automount_rootfs(void)
 {
        /* Convert to `struct vfscore_volume` */
@@ -383,11 +390,6 @@ static int vfscore_automount_rootfs(void)
        if (!vv.drv || vv.drv[0] == '\0')
                return 0;
 
-#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
-       if (!strncmp(vv.drv, "initrd", sizeof("initrd") - 1))
-               return vfscore_mount_initrd_volume(&vv);
-#endif /* CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS */
-
        rc = vfscore_mount_volume(&vv);
        if (unlikely(rc))
                uk_pr_crit("Failed to mount %s (%s) at /: %d\n", vv.sdev,
@@ -412,14 +414,7 @@ static int vfscore_automount_fstab_volumes(void)
        for (i = 0; i < CONFIG_LIBVFSCORE_FSTAB_SIZE && vfscore_fstab[i]; i++) {
                vfscore_fstab_fetch_volume_args(vfscore_fstab[i], &vv);
 
-#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
-               if (!strncmp(vv.drv, "initrd", sizeof("initrd") - 1)) {
-                       rc = vfscore_mount_initrd_volume(&vv);
-               } else
-#endif /* CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS */
-               {
-                       rc = vfscore_mount_volume(&vv);
-               }
+               rc = vfscore_mount_volume(&vv);
                if (unlikely(rc)) {
                        uk_pr_err("Failed to mount %s: error %d\n", vv.sdev,
                                  rc);