diff options
author | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2009-04-14 22:28:27 +0300 |
---|---|---|
committer | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2009-04-14 22:28:27 +0300 |
commit | dea12e2529ecdcab3a382fc71e7430326b74d6a6 (patch) | |
tree | b6687c3868f668a25cf19ed1eb3159c5cd5af3ce | |
parent | c9110f9c7d71fa9b157540a7aa2ade7f34b79968 (diff) |
Made nsmux wait until dynamic translators finish
Previously, a settrans -gR on a node on which nsmux resides
would only kill the dynamic translators, without shutting
down nsmux, because it didn't wait for the children to close
their ports, which made a check in netfs_shutdown fail. Now
nsmux waits for the dynamic translator to finish, so
settrans -gR does its job as expected: shuts down everything.
-rw-r--r-- | node.c | 11 | ||||
-rw-r--r-- | nsmux.c | 6 | ||||
-rw-r--r-- | trans.c | 31 | ||||
-rw-r--r-- | trans.h | 24 |
4 files changed, 48 insertions, 24 deletions
@@ -747,6 +747,9 @@ error_t /*The control port for the active translator */ mach_port_t active_control; + /*The PID of the started translator */ + pid_t trans_pid; + /*A copy of the user information, supplied in `user` */ struct iouser * user; @@ -841,6 +844,9 @@ error_t /*Drop our reference to the port */ ports_port_deref (newpi); + /*Store the task ID of the new translator */ + trans_pid = task2pid(task); + /* char buf[256]; char *_buf = buf; @@ -914,7 +920,10 @@ error_t return err; /*Register the new translator*/ - err = trans_register (active_control, &np->nn->dyntrans); + err = trans_register (active_control, trans_pid, &np->nn->dyntrans); + LOG_MSG ("node_set_translator: Translator PID: %d", (int)trans_pid); + if (err) + return err; /*Obtain the port to the top of the newly-set translator */ err = fsys_getroot @@ -1675,17 +1675,13 @@ netfs_shutdown (int flags) && S_ISDIR (netfs_root_node->nn_stat.st_mode)) return EBUSY; - if (flags & FSYS_GOAWAY_NOWAIT) - LOG_MSG("NOWAIT"); - LOG_MSG("WAIT"); - if (flags & FSYS_GOAWAY_RECURSE) { /*nsmux has been requested shut down recursively. Shut down all dynamic translators. Statically set translators will not be shut down, because libnetfs does not (yet?) do this itself, as different from libdiskfs. */ - err = trans_shutdown_all (flags); + err = trans_shutdown_all (flags, 1); #ifdef NOTYET err = netfs_node_iterate (helper); @@ -27,6 +27,7 @@ /*---------------------------------------------------------------------------*/ #include <stdlib.h> #include <hurd/fsys.h> +#include <sys/wait.h> /*---------------------------------------------------------------------------*/ #include "trans.h" /*---------------------------------------------------------------------------*/ @@ -39,10 +40,10 @@ trans_el_t * dyntrans = NULL; /*---------------------------------------------------------------------------*/ /*---------Functions---------------------------------------------------------*/ -/*Adds a translator control port to the list of ports. One should use - only this function to add a new element to the list of ports. */ +/*Adds a translator to the list of translators. One should use only + this function to add a new element to the list. */ error_t -trans_register (fsys_t cntl, trans_el_t ** new_trans) +trans_register (fsys_t cntl, pid_t pid, trans_el_t ** new_trans) { /*The new entry in the list */ trans_el_t * el; @@ -52,6 +53,7 @@ trans_register (fsys_t cntl, trans_el_t ** new_trans) return ENOMEM; el->cntl = cntl; + el->pid = pid; el->prev = NULL; el->next = dyntrans; @@ -63,9 +65,9 @@ trans_register (fsys_t cntl, trans_el_t ** new_trans) } /*trans_register */ /*---------------------------------------------------------------------------*/ -/*Removes a translator control port from the list of ports. One should - use only this function to remove an element from the list of - ports. This function does not shut down the translator. */ +/*Removes a translator from the list. One should use only this + function to remove an element from the list. This function does not + shut down the translator. */ void trans_unregister (trans_el_t * trans) { @@ -78,16 +80,21 @@ trans_unregister (trans_el_t * trans) } /*trans_unregister */ /*---------------------------------------------------------------------------*/ -/*Gracefully shuts down all the translators registered in the - list with `flags`. */ +/*Gracefully shuts down all the translators registered in the list + with `flags`. If wait is nonzero, waits for each translator to + finish. */ error_t -trans_shutdown_all (int flags) +trans_shutdown_all (int flags, int wait) { error_t err; /*The element being dealt with now. */ trans_el_t * el; + /*The exit status of the dynamic translator, in case we are waiting + for it to finish. */ + int exit_status; + for (el = dyntrans; el; el = el->next) { err = fsys_goaway (el->cntl, flags); @@ -101,6 +108,12 @@ trans_shutdown_all (int flags) dyntrans = el; return err; } + + if (wait) + { + /*Wait for the translator process to stop, if needed. */ + waitpid (el->pid, &exit_status, 0); + } } dyntrans = NULL; @@ -28,6 +28,8 @@ #include <hurd.h> #include <error.h> /*---------------------------------------------------------------------------*/ +#include "lib.h" +/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /*---------Types-------------------------------------------------------------*/ @@ -37,6 +39,9 @@ struct trans_el /*the control port to the translator */ fsys_t cntl; + /*the PID of the translator */ + pid_t pid; + /*the next and the previous elements in the list */ struct trans_el * next, * prev; }; /*struct trans_el */ @@ -52,21 +57,22 @@ extern trans_el_t * dyntrans; /*---------------------------------------------------------------------------*/ /*---------Functions---------------------------------------------------------*/ -/*Adds a translator control port to the list of ports. One should use - only this function to add a new element to the list of ports. */ +/*Adds a translator to the list of translators. One should use only + this function to add a new element to the list. */ error_t -trans_register (fsys_t cntl, trans_el_t ** new_trans); +trans_register (fsys_t cntl, pid_t pid, trans_el_t ** new_trans); /*---------------------------------------------------------------------------*/ -/*Removes a translator control port from the list of ports. One should - use only this function to remove an element from the list of - ports. This function does not shut down the translator. */ +/*Removes a translator from the list. One should use only this + function to remove an element from the list. This function does not + shut down the translator. */ void trans_unregister (trans_el_t * trans); /*---------------------------------------------------------------------------*/ -/*Gracefully shuts down all the translators registered in the - list with `flags`. */ +/*Gracefully shuts down all the translators registered in the list + with `flags`. If wait is nonzero, waits for each translator to + finish. */ error_t -trans_shutdown_all (int flags); +trans_shutdown_all (int flags, int wait); /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ |