From ce016e523b8facdfc7924cf675c2d1696c7db319 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sun, 26 Jul 2020 17:37:20 +1000 Subject: libdiskfs: Refactor fsys_startup invokation for bootstrapping When we will have a rump translator before the root filesystem translator, we will want to give to the former a control port on the latter. Message-Id: <20200726073721.202405-1-damien@zamaudio.com> --- libdiskfs/init-startup.c | 58 +++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'libdiskfs/init-startup.c') diff --git a/libdiskfs/init-startup.c b/libdiskfs/init-startup.c index a2e3638d..92ef8f94 100644 --- a/libdiskfs/init-startup.c +++ b/libdiskfs/init-startup.c @@ -32,12 +32,35 @@ char *_diskfs_chroot_directory; -mach_port_t -diskfs_startup_diskfs (mach_port_t bootstrap, int flags) +static void +diskfs_call_fsys_startup (mach_port_t bootstrap, int flags, + mach_port_t *realnode) { error_t err; - mach_port_t realnode, right; struct port_info *newpi; + mach_port_t right; + + err = ports_create_port (diskfs_control_class, diskfs_port_bucket, + sizeof (struct port_info), &newpi); + if (! err) + { + right = ports_get_send_right (newpi); + err = fsys_startup (bootstrap, flags, right, + MACH_MSG_TYPE_COPY_SEND, realnode); + mach_port_deallocate (mach_task_self (), right); + ports_port_deref (newpi); + } + if (err) + error (1, err, "Translator startup failure: fsys_startup"); + + _diskfs_ncontrol_ports++; +} + +mach_port_t +diskfs_startup_diskfs (mach_port_t fs_bootstrap, int flags) +{ + error_t err; + mach_port_t realnode, bootstrap; if (_diskfs_chroot_directory != NULL) { @@ -88,24 +111,11 @@ diskfs_startup_diskfs (mach_port_t bootstrap, int flags) diskfs_nput (old); } - if (bootstrap != MACH_PORT_NULL) + if (fs_bootstrap != MACH_PORT_NULL) { - err = ports_create_port (diskfs_control_class, diskfs_port_bucket, - sizeof (struct port_info), &newpi); - if (! err) - { - right = ports_get_send_right (newpi); - err = fsys_startup (bootstrap, flags, right, - MACH_MSG_TYPE_COPY_SEND, &realnode); - mach_port_deallocate (mach_task_self (), right); - ports_port_deref (newpi); - } - if (err) - error (1, err, "Translator startup failure: fsys_startup"); - - mach_port_deallocate (mach_task_self (), bootstrap); - _diskfs_ncontrol_ports++; - + /* We do the startup from filesystem's bootstrap */ + diskfs_call_fsys_startup (fs_bootstrap, flags, &realnode); + mach_port_deallocate (mach_task_self (), fs_bootstrap); _diskfs_init_completed (); } else @@ -114,6 +124,14 @@ diskfs_startup_diskfs (mach_port_t bootstrap, int flags) /* We are the bootstrap filesystem; do special boot-time setup. */ diskfs_start_bootstrap (); + + /* If we have a bootstrap port we must call fsys_startup */ + task_get_bootstrap_port (mach_task_self (), &bootstrap); + if (bootstrap != MACH_PORT_NULL) + { + diskfs_call_fsys_startup (bootstrap, flags, &realnode); + mach_port_deallocate (mach_task_self (), bootstrap); + } } if (diskfs_default_sync_interval) -- cgit v1.2.3