From: Fotis Xenakis <[email protected]> Committer: Waldemar Kozaczuk <[email protected]> Branch: master
vfs: homogenize mount_rofs_rootfs and mount_zfs_rootfs Signed-off-by: Fotis Xenakis <[email protected]> Message-Id: <am0pr03mb6292abec8fc7c3a24e86fc85a6...@am0pr03mb6292.eurprd03.prod.outlook.com> --- diff --git a/fs/vfs/main.cc b/fs/vfs/main.cc --- a/fs/vfs/main.cc +++ b/fs/vfs/main.cc @@ -1593,7 +1593,7 @@ int faccessat(int dirfd, const char *pathname, int mode, int flags) return error; } -extern "C" +extern "C" int euidaccess(const char *pathname, int mode) { return access(pathname, mode); @@ -2375,45 +2375,53 @@ extern "C" void unmount_devfs() extern "C" int mount_rofs_rootfs(bool pivot_root) { - int ret; - - if (mkdir("/rofs", 0755) < 0) - kprintf("failed to create /rofs, error = %s\n", strerror(errno)); + constexpr char* mp = "/rofs"; - ret = sys_mount("/dev/vblk0.1", "/rofs", "rofs", MNT_RDONLY, 0); + if (mkdir(mp, 0755) < 0) { + int ret = errno; + kprintf("failed to create %s, error = %s\n", mp, strerror(errno)); + return ret; + } + int ret = sys_mount("/dev/vblk0.1", mp, "rofs", MNT_RDONLY, nullptr); if (ret) { - kprintf("failed to mount /rofs, error = %s\n", strerror(ret)); - rmdir("/rofs"); + kprintf("failed to mount %s, error = %s\n", mp, strerror(ret)); + rmdir(mp); return ret; } if (pivot_root) { - pivot_rootfs("/rofs"); + pivot_rootfs(mp); } return 0; } -extern "C" void mount_zfs_rootfs(bool pivot_root, bool extra_zfs_pools) +extern "C" int mount_zfs_rootfs(bool pivot_root, bool extra_zfs_pools) { - if (mkdir("/zfs", 0755) < 0) - kprintf("failed to create /zfs, error = %s\n", strerror(errno)); + constexpr char* mp = "/zfs"; - int ret = sys_mount("/dev/vblk0.1", "/zfs", "zfs", 0, (void *)"osv/zfs"); - - if (ret) - kprintf("failed to mount /zfs, error = %s\n", strerror(ret)); - - if (!pivot_root) { - return; + if (mkdir(mp, 0755) < 0) { + int ret = errno; + kprintf("failed to create %s, error = %s\n", mp, strerror(errno)); + return ret; } - pivot_rootfs("/zfs"); + int ret = sys_mount("/dev/vblk0.1", mp, "zfs", 0, (void *)"osv/zfs"); + if (ret) { + kprintf("failed to mount %s, error = %s\n", mp, strerror(ret)); + rmdir(mp); + return ret; + } - if (extra_zfs_pools) { - import_extra_zfs_pools(); + if (pivot_root) { + pivot_rootfs(mp); + if (extra_zfs_pools) { + import_extra_zfs_pools(); + } } + + return 0; } extern "C" void unmount_rootfs(void) diff --git a/loader.cc b/loader.cc --- a/loader.cc +++ b/loader.cc @@ -87,7 +87,7 @@ extern "C" { void premain(); void vfs_init(void); void unmount_devfs(); - void mount_zfs_rootfs(bool,bool); + int mount_zfs_rootfs(bool, bool); int mount_rofs_rootfs(bool); void rofs_disable_cache(); } @@ -396,19 +396,20 @@ void* do_main_thread(void *_main_args) if (opt_mount) { unmount_devfs(); - // + // Try to mount rofs - if(mount_rofs_rootfs(opt_pivot) != 0) { - // + if (mount_rofs_rootfs(opt_pivot) != 0) { // Failed -> try to mount zfs zfsdev::zfsdev_init(); - mount_zfs_rootfs(opt_pivot, opt_extra_zfs_pools); + auto error = mount_zfs_rootfs(opt_pivot, opt_extra_zfs_pools); + if (error) { + debug("Could not mount zfs root filesystem.\n"); + } bsd_shrinker_init(); boot_time.event("ZFS mounted"); - } - else { - if(opt_disable_rofs_cache) { + } else { + if (opt_disable_rofs_cache) { debug("Disabling ROFS memory cache.\n"); rofs_disable_cache(); } @@ -491,8 +492,7 @@ void* do_main_thread(void *_main_args) if (opt_bootchart) { boot_time.print_chart(); - } - else { + } else { boot_time.print_total_time(); } -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/000000000000ee8ef805adf96e14%40google.com.
