Skip to content

Commit 43939b1

Browse files
foxengwkozaczuk
authored andcommitted
vfs: homogenize mount_rofs_rootfs and mount_zfs_rootfs
Signed-off-by: Fotis Xenakis <[email protected]> Message-Id: <AM0PR03MB6292ABEC8FC7C3A24E86FC85A65D0@AM0PR03MB6292.eurprd03.prod.outlook.com>
1 parent 0aa552c commit 43939b1

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

fs/vfs/main.cc

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ int faccessat(int dirfd, const char *pathname, int mode, int flags)
15931593
return error;
15941594
}
15951595

1596-
extern "C"
1596+
extern "C"
15971597
int euidaccess(const char *pathname, int mode)
15981598
{
15991599
return access(pathname, mode);
@@ -2375,45 +2375,53 @@ extern "C" void unmount_devfs()
23752375

23762376
extern "C" int mount_rofs_rootfs(bool pivot_root)
23772377
{
2378-
int ret;
2379-
2380-
if (mkdir("/rofs", 0755) < 0)
2381-
kprintf("failed to create /rofs, error = %s\n", strerror(errno));
2378+
constexpr char* mp = "/rofs";
23822379

2383-
ret = sys_mount("/dev/vblk0.1", "/rofs", "rofs", MNT_RDONLY, 0);
2380+
if (mkdir(mp, 0755) < 0) {
2381+
int ret = errno;
2382+
kprintf("failed to create %s, error = %s\n", mp, strerror(errno));
2383+
return ret;
2384+
}
23842385

2386+
int ret = sys_mount("/dev/vblk0.1", mp, "rofs", MNT_RDONLY, nullptr);
23852387
if (ret) {
2386-
kprintf("failed to mount /rofs, error = %s\n", strerror(ret));
2387-
rmdir("/rofs");
2388+
kprintf("failed to mount %s, error = %s\n", mp, strerror(ret));
2389+
rmdir(mp);
23882390
return ret;
23892391
}
23902392

23912393
if (pivot_root) {
2392-
pivot_rootfs("/rofs");
2394+
pivot_rootfs(mp);
23932395
}
23942396

23952397
return 0;
23962398
}
23972399

2398-
extern "C" void mount_zfs_rootfs(bool pivot_root, bool extra_zfs_pools)
2400+
extern "C" int mount_zfs_rootfs(bool pivot_root, bool extra_zfs_pools)
23992401
{
2400-
if (mkdir("/zfs", 0755) < 0)
2401-
kprintf("failed to create /zfs, error = %s\n", strerror(errno));
2402+
constexpr char* mp = "/zfs";
24022403

2403-
int ret = sys_mount("/dev/vblk0.1", "/zfs", "zfs", 0, (void *)"osv/zfs");
2404-
2405-
if (ret)
2406-
kprintf("failed to mount /zfs, error = %s\n", strerror(ret));
2407-
2408-
if (!pivot_root) {
2409-
return;
2404+
if (mkdir(mp, 0755) < 0) {
2405+
int ret = errno;
2406+
kprintf("failed to create %s, error = %s\n", mp, strerror(errno));
2407+
return ret;
24102408
}
24112409

2412-
pivot_rootfs("/zfs");
2410+
int ret = sys_mount("/dev/vblk0.1", mp, "zfs", 0, (void *)"osv/zfs");
2411+
if (ret) {
2412+
kprintf("failed to mount %s, error = %s\n", mp, strerror(ret));
2413+
rmdir(mp);
2414+
return ret;
2415+
}
24132416

2414-
if (extra_zfs_pools) {
2415-
import_extra_zfs_pools();
2417+
if (pivot_root) {
2418+
pivot_rootfs(mp);
2419+
if (extra_zfs_pools) {
2420+
import_extra_zfs_pools();
2421+
}
24162422
}
2423+
2424+
return 0;
24172425
}
24182426

24192427
extern "C" void unmount_rootfs(void)

loader.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extern "C" {
8787
void premain();
8888
void vfs_init(void);
8989
void unmount_devfs();
90-
void mount_zfs_rootfs(bool,bool);
90+
int mount_zfs_rootfs(bool, bool);
9191
int mount_rofs_rootfs(bool);
9292
void rofs_disable_cache();
9393
}
@@ -396,19 +396,20 @@ void* do_main_thread(void *_main_args)
396396

397397
if (opt_mount) {
398398
unmount_devfs();
399-
//
399+
400400
// Try to mount rofs
401-
if(mount_rofs_rootfs(opt_pivot) != 0) {
402-
//
401+
if (mount_rofs_rootfs(opt_pivot) != 0) {
403402
// Failed -> try to mount zfs
404403
zfsdev::zfsdev_init();
405-
mount_zfs_rootfs(opt_pivot, opt_extra_zfs_pools);
404+
auto error = mount_zfs_rootfs(opt_pivot, opt_extra_zfs_pools);
405+
if (error) {
406+
debug("Could not mount zfs root filesystem.\n");
407+
}
406408
bsd_shrinker_init();
407409

408410
boot_time.event("ZFS mounted");
409-
}
410-
else {
411-
if(opt_disable_rofs_cache) {
411+
} else {
412+
if (opt_disable_rofs_cache) {
412413
debug("Disabling ROFS memory cache.\n");
413414
rofs_disable_cache();
414415
}
@@ -491,8 +492,7 @@ void* do_main_thread(void *_main_args)
491492

492493
if (opt_bootchart) {
493494
boot_time.print_chart();
494-
}
495-
else {
495+
} else {
496496
boot_time.print_total_time();
497497
}
498498

0 commit comments

Comments
 (0)