From 5fef1b7f22ec0ee3730b80bbf972dbf9a8995091 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 5 Oct 2016 15:38:58 +0200 Subject: libfshelp: Add function to map over all active translators. * libdiskfs/file-syncfs.c (diskfs_S_file_syncfs): Use the new function. * libdiskfs/fsys-options.c (diskfs_S_fsys_set_options): Likewise. * libdiskfs/fsys-syncfs.c (diskfs_S_fsys_syncfs): Likewise. * libdiskfs/shutdown.c (diskfs_shutdown): Likewise. * libfshelp/fshelp.h (fshelp_map_active_translators): New declaration. * libfshelp/translator-list.c (fshelp_map_active_translators): New function. * libnetfs/file-syncfs.c (netfs_S_file_syncfs): Use the new function. * libnetfs/fsys-set-options.c (netfs_S_fsys_set_options): Likewise. * libnetfs/fsys-syncfs.c (netfs_S_fsys_syncfs): Likewise. * libnetfs/shutdown.c (netfs_shutdown): Likewise. --- libnetfs/file-syncfs.c | 23 +++++++++++++++++--- libnetfs/fsys-set-options.c | 53 +++++++++++++++++++++------------------------ libnetfs/fsys-syncfs.c | 22 +++++++++++++++++++ libnetfs/shutdown.c | 45 ++++++++++++++++---------------------- 4 files changed, 86 insertions(+), 57 deletions(-) (limited to 'libnetfs') diff --git a/libnetfs/file-syncfs.c b/libnetfs/file-syncfs.c index 2302e926..0b14bb87 100644 --- a/libnetfs/file-syncfs.c +++ b/libnetfs/file-syncfs.c @@ -20,6 +20,21 @@ #include "netfs.h" #include "fs_S.h" +#include + +struct args +{ + int wait; +}; + +static error_t +helper (void *cookie, const char *name, mach_port_t control) +{ + struct args *args = cookie; + (void) name; + fsys_syncfs (control, args->wait, 1); + return 0; +} error_t netfs_S_file_syncfs (struct protid *user, @@ -27,11 +42,13 @@ netfs_S_file_syncfs (struct protid *user, int dochildren) { error_t err; - + struct args args = { wait }; + if (!user) return EOPNOTSUPP; - - /* Translators not yet supported by netfs. XXX */ + + if (dochildren) + fshelp_map_active_translators (helper, &args); pthread_mutex_lock (&user->po->np->lock); err = netfs_attempt_syncfs (user->user, wait); diff --git a/libnetfs/fsys-set-options.c b/libnetfs/fsys-set-options.c index fb1c87ef..afa480f8 100644 --- a/libnetfs/fsys-set-options.c +++ b/libnetfs/fsys-set-options.c @@ -26,8 +26,24 @@ #include "netfs.h" #include "fsys_S.h" -/* This code is originally from libdiskfs; things surrounded by `#if NOT_YET' - are pending libnetfs being fleshed out some more. */ +struct args +{ + char *data; + mach_msg_type_number_t len; + int do_children; +}; + +static error_t +helper (void *cookie, const char *name, mach_port_t control) +{ + struct args *args = cookie; + error_t err; + (void) name; + err = fsys_set_options (control, args->data, args->len, args->do_children); + if (err == MIG_SERVER_DIED || err == MACH_SEND_INVALID_DEST) + err = 0; + return err; +} /* Implement fsys_set_options as described in . */ error_t @@ -38,40 +54,21 @@ netfs_S_fsys_set_options (struct netfs_control *pt, int do_children) { error_t err = 0; + struct args args = { data, data_len, do_children }; + if (!pt) return EOPNOTSUPP; - error_t - helper (struct node *np) - { - error_t error; - mach_port_t control; - - error = fshelp_fetch_control (&np->transbox, &control); - pthread_mutex_unlock (&np->lock); - if (!error && (control != MACH_PORT_NULL)) - { - error = fsys_set_options (control, data, data_len, do_children); - mach_port_deallocate (mach_task_self (), control); - } - else - error = 0; - pthread_mutex_lock (&np->lock); - - if ((error == MIG_SERVER_DIED) || (error == MACH_SEND_INVALID_DEST)) - error = 0; - - return error; - } - -#if NOT_YET if (do_children) { +#if NOT_YET pthread_rwlock_wrlock (&netfs_fsys_lock); - err = netfs_node_iterate (helper); +#endif + err = fshelp_map_active_translators (helper, &args); +#if NOT_YET pthread_rwlock_unlock (&netfs_fsys_lock); - } #endif + } if (!err) { diff --git a/libnetfs/fsys-syncfs.c b/libnetfs/fsys-syncfs.c index e232936e..904e9246 100644 --- a/libnetfs/fsys-syncfs.c +++ b/libnetfs/fsys-syncfs.c @@ -20,6 +20,21 @@ #include "netfs.h" #include "fsys_S.h" +#include + +struct args +{ + int wait; +}; + +static error_t +helper (void *cookie, const char *name, mach_port_t control) +{ + struct args *args = cookie; + (void) name; + fsys_syncfs (control, args->wait, 1); + return 0; +} error_t netfs_S_fsys_syncfs (struct netfs_control *cntl, @@ -30,6 +45,13 @@ netfs_S_fsys_syncfs (struct netfs_control *cntl, { struct iouser *cred; error_t err; + struct args args = { wait }; + + if (! cntl) + return EOPNOTSUPP; + + if (children) + fshelp_map_active_translators (helper, &args); err = iohelp_create_simple_iouser (&cred, 0, 0); if (err) diff --git a/libnetfs/shutdown.c b/libnetfs/shutdown.c index 7fa05cdb..082f2bcd 100644 --- a/libnetfs/shutdown.c +++ b/libnetfs/shutdown.c @@ -26,33 +26,28 @@ #include #include +struct args +{ + int flags; +}; + +static error_t +helper (void *cookie, const char *name, mach_port_t control) +{ + struct args *args = cookie; + error_t err; + (void) name; + err = fsys_goaway (control, args->flags); + if (err == MIG_SERVER_DIED || err == MACH_SEND_INVALID_DEST) + err = 0; + return err; +} + /* Shutdown the filesystem; flags are as for fsys_goaway. */ error_t netfs_shutdown (int flags) { - error_t - helper (struct node *node) - { - error_t err; - mach_port_t control; - - err = fshelp_fetch_control (&node->transbox, &control); - if (!err && (control != MACH_PORT_NULL)) - { - pthread_mutex_unlock (&node->lock); - err = fsys_goaway (control, flags); - mach_port_deallocate (mach_task_self (), control); - pthread_mutex_lock (&node->lock); - } - else - err = 0; - - if ((err == MIG_SERVER_DIED) || (err == MACH_SEND_INVALID_DEST)) - err = 0; - - return err; - } - + struct args args = { flags }; int nports; int err; @@ -60,14 +55,12 @@ netfs_shutdown (int flags) && S_ISDIR (netfs_root_node->nn_stat.st_mode)) return EBUSY; -#ifdef NOTYET if (flags & FSYS_GOAWAY_RECURSE) { - err = netfs_node_iterate (helper); + err = fshelp_map_active_translators (helper, &args); if (err) return err; } -#endif #ifdef NOTYET pthread_rwlock_wrlock (&netfs_fsys_lock); -- cgit v1.2.3