bug-hurd
[Top][All Lists]
Advanced

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

[PATCH 2/4] Go away when the mountee has been shut down.


From: Sergiu Ivanov
Subject: [PATCH 2/4] Go away when the mountee has been shut down.
Date: Fri, 17 Jul 2009 13:57:33 +0300
User-agent: Mutt/1.5.18 (2008-05-17)

>From ba1a38092c3b79c5c4668c159a7a1640c6d94c51 Mon Sep 17 00:00:00 2001
From: Sergiu Ivanov <unlimitedscolobb@gmail.com>
Date: Tue, 14 Jul 2009 19:41:41 +0000
Subject: [PATCH 2/4] Go away when the mountee has been shut down.

* mount.c (mountee_control): New variable.
(mountee_listen_port): Likewise.
(start_mountee): Store the control port of the mountee in
mountee_control.
(mountee_server): New function.
(_mountee_listen_thread_proc): Likewise.
(setup_unionmount): Request to be notified when the mountee goes
away.  Detach a separate thread to wait for the notification.
* mount.h (mountee_control): New variable.
---
 mount.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 mount.h |    1 +
 2 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/mount.c b/mount.c
index 4d12cd6..26cbd9f 100644
--- a/mount.c
+++ b/mount.c
@@ -24,6 +24,7 @@
 
 #include <hurd/fsys.h>
 #include <fcntl.h>
+#include <cthreads.h>
 
 #include "mount.h"
 #include "lib.h"
@@ -37,6 +38,7 @@ size_t mountee_argz_len;
 node_t * unionmount_proxy;
 
 mach_port_t mountee_port;
+mach_port_t mountee_control = MACH_PORT_NULL;
 
 int mountee_started = 0;
 
@@ -44,6 +46,10 @@ int mountee_started = 0;
    operates (transparent/non-transparent).  */
 int transparent_mount = 1;
 
+/* The port for receiving the notification about the shutdown of the
+   mountee.  */
+mach_port_t mountee_listen_port;
+
 /* Starts the mountee (given by `argz` and `argz_len`), sets it on
    node `np` and opens a port `port` to with `flags`.  `port` is not
    modified when an error occurs.  */
@@ -176,10 +182,35 @@ start_mountee (node_t * np, char * argz, size_t argz_len, 
int flags,
     }
 
   *port = res_port;
+  mountee_control = control;
 
   return 0;
 }                              /* start_mountee */
 
+/* Listens to the MACH_NOTIFY_NO_SENDERS notification for the port to
+   the root of the mountee.  */
+error_t
+mountee_server (mach_msg_header_t * inp, mach_msg_header_t * outp)
+{
+  if (inp->msgh_id == MACH_NOTIFY_DEAD_NAME)
+    {
+      /* Terminate operations conducted by unionfs and shut down.  */
+      netfs_shutdown (FSYS_GOAWAY_FORCE);
+      exit (0);
+    }
+
+  return 1;
+}                              /* mountee_server */
+
+/* The main proc of thread for listening for the MACH_NOTIFY_DEAD_NAME
+   notification on the control port of the mountee.  */
+static void
+_mountee_listen_thread_proc (any_t * arg)
+{
+  while (1)
+    mach_msg_server (mountee_server, 0, mountee_listen_port);
+}                              /* _mountee_listen_thread */
+
 /* Sets up a proxy node, sets the translator on it, and registers the
    filesystem published by the translator in the list of merged
    filesystems.  */
@@ -214,6 +245,39 @@ setup_unionmount (void)
 
   mountee_started = 1;
 
+  /* The previously registered send-once right (used to hold the value
+     returned from mach_port_request_notification) */
+  mach_port_t prev;
+
+  /* Setup the port for receiving notifications.  */
+  err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
+                     &mountee_listen_port);
+  if (err)
+    return err;
+  err = mach_port_insert_right (mach_task_self (), mountee_listen_port,
+                               mountee_listen_port, MACH_MSG_TYPE_MAKE_SEND);
+  if (err)
+    {
+      mach_port_deallocate (mach_task_self (), mountee_listen_port);
+      return err;
+    }
+
+  /* Request to be notified when the mountee goes away and
+     `mountee_control` becomes a dead name.  */
+  err = mach_port_request_notification (mach_task_self (), mountee_control,
+                                       MACH_NOTIFY_DEAD_NAME, 1, 
mountee_listen_port,
+                                       MACH_MSG_TYPE_MAKE_SEND_ONCE, &prev);
+  if (prev != MACH_PORT_NULL)
+    mach_port_deallocate (mach_task_self(), prev);
+  if(err)
+    {
+      mach_port_deallocate (mach_task_self(), mountee_listen_port);
+      return err;
+    }
+
+  /* Create a new thread for listening to the notification.  */
+  cthread_detach (cthread_fork ((cthread_fn_t) _mountee_listen_thread_proc, 
NULL));
+
   return err;
 }                              /* setup_unionmount */
 
diff --git a/mount.h b/mount.h
index d01b234..fd8408b 100644
--- a/mount.h
+++ b/mount.h
@@ -37,6 +37,7 @@ extern size_t mountee_argz_len;
 extern node_t * unionmount_proxy;
 
 extern mach_port_t mountee_port;
+extern mach_port_t mountee_control;
 
 extern int mountee_started;
 
-- 
1.6.3.3





reply via email to

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