Skip to content

Commit

Permalink
vfs: homogenize mount_rofs_rootfs and mount_zfs_rootfs
Browse files Browse the repository at this point in the history
Signed-off-by: Fotis Xenakis <[email protected]>
Message-Id: <AM0PR03MB6292ABEC8FC7C3A24E86FC85A65D0@AM0PR03MB6292.eurprd03.prod.outlook.com>
  • Loading branch information
foxeng authored and wkozaczuk committed Aug 28, 2020
1 parent 0aa552c commit 43939b1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
52 changes: 30 additions & 22 deletions fs/vfs/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 43939b1

Please sign in to comment.