bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] machdev,pci,rump: Reuse shutdown notify from machdev


From: Damien Zammit
Subject: [PATCH] machdev,pci,rump: Reuse shutdown notify from machdev
Date: Fri, 12 Mar 2021 23:04:47 +1100

This set of changes allows the fsys_init flow of RPCs to work better
during bootstrap.  It also removes duplicated code for the
startup shutdown notify between machdev and the arbiter.

However, I am still unsure why the lookup of _SERVERS_STARTUP fails
in the arbiter's fsys_init, see the WARNING at bootup.

---
 libmachdev/ds_routines.c   |  2 ++
 libmachdev/machdev.h       |  5 ++++
 libmachdev/trivfs_server.c | 43 +++++++++++++++++++++++++--
 pci-arbiter/Makefile       |  2 +-
 pci-arbiter/main.c         | 18 +-----------
 pci-arbiter/startup.c      | 60 --------------------------------------
 pci-arbiter/startup.h      | 31 --------------------
 rumpdisk/main.c            |  6 +---
 8 files changed, 51 insertions(+), 116 deletions(-)
 delete mode 100644 pci-arbiter/startup.c
 delete mode 100644 pci-arbiter/startup.h

diff --git a/libmachdev/ds_routines.c b/libmachdev/ds_routines.c
index c2de4b26..3ef81805 100644
--- a/libmachdev/ds_routines.c
+++ b/libmachdev/ds_routines.c
@@ -62,6 +62,7 @@
 #include <string.h>
 #include <error.h>
 #include <assert.h>
+#include <unistd.h>
 
 #include <hurd.h>
 #include <mach.h>
@@ -75,6 +76,7 @@
 
 struct port_bucket *machdev_device_bucket;
 struct port_class *machdev_device_class;
+mach_port_t machdev_bootport;
 
 #define MAX_NUM_EMULATION 32
 
diff --git a/libmachdev/machdev.h b/libmachdev/machdev.h
index 8f613b35..80e1e3c2 100644
--- a/libmachdev/machdev.h
+++ b/libmachdev/machdev.h
@@ -27,6 +27,8 @@
 #include "machdev-device_emul.h"
 #include "machdev-dev_hdr.h"
 
+extern mach_port_t machdev_bootport;
+
 void machdev_register (struct machdev_device_emulation_ops *ops);
 
 void machdev_device_init(void);
@@ -36,5 +38,8 @@ error_t machdev_create_device_port (size_t size, void 
*result);
 int machdev_trivfs_init(mach_port_t bootstrap_resume_task, const char *name, 
const char *path, mach_port_t *bootstrap);
 void machdev_trivfs_server(mach_port_t bootstrap);
 boolean_t machdev_is_master_device (mach_port_t port);
+error_t machdev_fsys_init(mach_port_t proc, mach_port_t auth);
+void machdev_use_this_port(mach_port_t bootstrap);
+void machdev_get_ports(void);
 
 #endif
diff --git a/libmachdev/trivfs_server.c b/libmachdev/trivfs_server.c
index e3e4045d..8ee6be65 100644
--- a/libmachdev/trivfs_server.c
+++ b/libmachdev/trivfs_server.c
@@ -245,6 +245,39 @@ trivfs_S_fsys_startup (mach_port_t bootport,
   return 0;
 }
 
+error_t
+machdev_fsys_init(mach_port_t proc, mach_port_t auth)
+{
+  /* No more nesting of servers */
+  if (!machdev_bootport)
+    return 0;
+
+  return fsys_init (machdev_bootport, proc, MACH_MSG_TYPE_COPY_SEND, auth);
+}
+
+void
+machdev_use_this_port(mach_port_t bootstrap)
+{
+  machdev_bootport = bootstrap;
+}
+
+void
+machdev_get_ports(void)
+{
+  int i;
+  task_t parent_task;
+
+  /* If we are not the bootstrap filesystem, get this port from parent */
+  if (!machdev_bootport)
+    {
+      /* Need to synchronise with parent to wait for fsys_startup */
+      for (i = 0; i < 5 && machdev_bootport == MACH_PORT_NULL; i++, sleep(1))
+        task_get_bootstrap_port (mach_task_self (), &machdev_bootport);
+
+    }
+  fsys_getpriv (machdev_bootport, &_hurd_host_priv, &_hurd_device_master, 
&parent_task);
+}
+
 kern_return_t
 trivfs_S_fsys_init (struct trivfs_control *fsys,
                     mach_port_t reply, mach_msg_type_name_t replytype,
@@ -260,6 +293,10 @@ trivfs_S_fsys_init (struct trivfs_control *fsys,
   string_t retry_name;
   mach_port_t right = MACH_PORT_NULL;
 
+  /* Traverse to the bootstrapping server first */
+  err = machdev_fsys_init (procserver, authhandle);
+  assert_perror_backtrace (err);
+
   err = fsys_getroot (control_port, MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND,
                       idlist, 3, idlist, 3, 0,
                       &retry, retry_name, &root);
@@ -278,7 +315,6 @@ trivfs_S_fsys_init (struct trivfs_control *fsys,
   portarray[INIT_PORT_CWDIR] = root;
   _hurd_init (0, NULL, portarray, INIT_PORT_MAX, NULL, 0);
 
-  arrange_shutdown_notification ();
 
   /* Install the bootstrap port on /dev/something so users
    * can still access the bootstrapped device */
@@ -288,6 +324,9 @@ trivfs_S_fsys_init (struct trivfs_control *fsys,
       install_as_translator (right);
       control->underlying = underlying;
     }
+
+  arrange_shutdown_notification ();
+
   return 0;
 }
 
@@ -380,7 +419,7 @@ resume_bootstrap_server(mach_port_t server_task, const char 
*server_name)
   stdout = stderr = mach_open_devstream (cons, "w");
   mach_port_deallocate (mach_task_self (), cons);
 
-  printf ("Hurd bootstrap %s ", server_name);
+  printf ("%s ", server_name);
   fflush (stdout);
 }
 
diff --git a/pci-arbiter/Makefile b/pci-arbiter/Makefile
index b32bc579..d3d205ec 100644
--- a/pci-arbiter/Makefile
+++ b/pci-arbiter/Makefile
@@ -21,7 +21,7 @@ makemode      = server
 PORTDIR = $(srcdir)/port
 
 SRCS           = main.c pci-ops.c netfs_impl.c \
-                 pcifs.c ncache.c options.c func_files.c startup.c \
+                 pcifs.c ncache.c options.c func_files.c \
                  pciServer.c startup_notifyServer.c
 OBJS           = $(SRCS:.c=.o) $(MIGSTUBS)
 
diff --git a/pci-arbiter/main.c b/pci-arbiter/main.c
index efb9f65c..3d1456fa 100644
--- a/pci-arbiter/main.c
+++ b/pci-arbiter/main.c
@@ -43,7 +43,6 @@
 #include <pciaccess.h>
 #include <pthread.h>
 #include "pcifs.h"
-#include "startup.h"
 
 struct pcifs *fs;
 volatile struct mapped_time_value *pcifs_maptime;
@@ -106,17 +105,9 @@ pci_device_close (void *d)
 static void
 pci_device_shutdown (mach_port_t dosync_handle)
 {
-  struct port_info *inpi = ports_lookup_port (netfs_port_bucket, dosync_handle,
-                                             pci_shutdown_notify_class);
-
-  if (!inpi)
-    return;
-
   // Free all libpciaccess resources
   pci_system_cleanup ();
 
-  ports_port_deref (inpi);
-
   ports_destroy_right (&pci_control_port);
 
   netfs_shutdown (FSYS_GOAWAY_FORCE);
@@ -182,7 +173,6 @@ netfs_server_func (void *arg)
   return NULL;
 }
 
-
 static mach_port_t
 pcifs_startup(mach_port_t bootstrap, int flags)
 {
@@ -221,6 +211,7 @@ main (int argc, char **argv)
   if (disk_server_task != MACH_PORT_NULL)
     {
       machdev_register (&pci_arbiter_emulation_ops);
+      machdev_use_this_port (MACH_PORT_NULL);
       machdev_device_init ();
       machdev_trivfs_init (disk_server_task, "pci", "/servers/bus/pci", 
&bootstrap);
       err = pthread_create (&t, NULL, machdev_server, NULL);
@@ -250,7 +241,6 @@ main (int argc, char **argv)
 
   if (disk_server_task != MACH_PORT_NULL)
     machdev_trivfs_server(bootstrap);
-    /* Timer started, quickly do all these next, before we call rump_init */
 
   /* Create the root node first */
   err = init_root_node ();
@@ -278,12 +268,6 @@ main (int argc, char **argv)
     error (1, err, "Creating netfs loop thread");
   pthread_detach (nt);
 
-  /*
-   * Ask init to tell us when the system is going down,
-   * so we can try to be friendly to our correspondents on the network.
-   */
-  arrange_shutdown_notification ();
-
   /* Let the other threads do their job */
   pthread_exit(NULL);
   /* Never reached */
diff --git a/pci-arbiter/startup.c b/pci-arbiter/startup.c
deleted file mode 100644
index 421c9e24..00000000
--- a/pci-arbiter/startup.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-   Copyright (C) 2017 Free Software Foundation, Inc.
-   Written by Michael I. Bushnell, p/BSG.
-
-   This file is part of the GNU Hurd.
-
-   The GNU Hurd is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2, or (at
-   your option) any later version.
-
-   The GNU Hurd is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Startup and shutdown notifications management */
-
-#include "startup.h"
-
-#include <unistd.h>
-#include <hurd/paths.h>
-#include <hurd/startup.h>
-#include <hurd/netfs.h>
-
-struct port_class *pci_shutdown_notify_class;
-
-void
-arrange_shutdown_notification ()
-{
-  error_t err;
-  mach_port_t initport, notify;
-  struct port_info *pi;
-
-  pci_shutdown_notify_class = ports_create_class (0, 0);
-
-  /* Arrange to get notified when the system goes down,
-     but if we fail for some reason, just silently give up.  No big deal. */
-
-  err = ports_create_port (pci_shutdown_notify_class, netfs_port_bucket,
-                          sizeof (struct port_info), &pi);
-  if (err)
-    return;
-
-  initport = file_name_lookup (_SERVERS_STARTUP, 0, 0);
-  if (initport == MACH_PORT_NULL)
-    return;
-
-  notify = ports_get_send_right (pi);
-  ports_port_deref (pi);
-  startup_request_notification (initport, notify,
-                               MACH_MSG_TYPE_MAKE_SEND,
-                               program_invocation_short_name);
-  mach_port_deallocate (mach_task_self (), notify);
-  mach_port_deallocate (mach_task_self (), initport);
-}
diff --git a/pci-arbiter/startup.h b/pci-arbiter/startup.h
deleted file mode 100644
index 416b84d6..00000000
--- a/pci-arbiter/startup.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-   Copyright (C) 2017 Free Software Foundation, Inc.
-   Written by Michael I. Bushnell, p/BSG.
-
-   This file is part of the GNU Hurd.
-
-   The GNU Hurd is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2, or (at
-   your option) any later version.
-
-   The GNU Hurd is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef STARTUP_H
-#define STARTUP_H
-
-/* Startup and shutdown notifications management */
-
-/* Port class for startup requests */
-extern struct port_class *pci_shutdown_notify_class;
-
-void arrange_shutdown_notification (void);
-
-#endif /* STARTUP_H */
diff --git a/rumpdisk/main.c b/rumpdisk/main.c
index a26e17cb..8bed7a50 100644
--- a/rumpdisk/main.c
+++ b/rumpdisk/main.c
@@ -31,11 +31,6 @@
 #include <pthread.h>
 #include <mach.h>
 
-/* TODO: Add api to pciaccess to allow selecting backend.
- * For now we pretend to be the arbiter and claim x86 method.
- */
-char *netfs_server_name = "pci-arbiter";
-
 mach_port_t bootstrap_resume_task = MACH_PORT_NULL;
 
 static const struct argp_option options[] = {
@@ -117,6 +112,7 @@ main (int argc, char **argv)
     }
 
   rump_register_block ();
+  machdev_get_ports();
   machdev_device_init ();
   machdev_trivfs_init (bootstrap_resume_task, "rumpdisk", "/dev/rumpdisk", 
&bootstrap);
   err = pthread_create (&t, NULL, machdev_server, NULL);
-- 
2.30.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]