summaryrefslogtreecommitdiff
path: root/libdiskfs
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-10-05 15:38:58 +0200
committerJustus Winter <justus@gnupg.org>2017-09-12 10:41:35 +0200
commit5fef1b7f22ec0ee3730b80bbf972dbf9a8995091 (patch)
tree29890aef362b5a8ebffb4721a1967b818a22a3af /libdiskfs
parent116552c075abf1d22057a608fee9d27684bcbbe5 (diff)
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.
Diffstat (limited to 'libdiskfs')
-rw-r--r--libdiskfs/file-syncfs.c35
-rw-r--r--libdiskfs/fsys-options.c44
-rw-r--r--libdiskfs/fsys-syncfs.c33
-rw-r--r--libdiskfs/shutdown.c45
4 files changed, 74 insertions, 83 deletions
diff --git a/libdiskfs/file-syncfs.c b/libdiskfs/file-syncfs.c
index 2faab6ad..8cd4003b 100644
--- a/libdiskfs/file-syncfs.c
+++ b/libdiskfs/file-syncfs.c
@@ -19,34 +19,33 @@
#include "fs_S.h"
#include <hurd/fsys.h>
+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;
+}
+
/* Implement file_syncfs as described in <hurd/fs.defs>. */
kern_return_t
diskfs_S_file_syncfs (struct protid *cred,
int wait,
int dochildren)
{
- error_t
- helper (struct node *np)
- {
- error_t err;
- mach_port_t control;
-
- err = fshelp_fetch_control (&np->transbox, &control);
- pthread_mutex_unlock (&np->lock);
- if (!err && (control != MACH_PORT_NULL))
- {
- fsys_syncfs (control, wait, 1);
- mach_port_deallocate (mach_task_self (), control);
- }
- pthread_mutex_lock (&np->lock);
- return 0;
- }
-
+ struct args args = { wait };
+
if (!cred)
return EOPNOTSUPP;
if (dochildren)
- diskfs_node_iterate (helper);
+ fshelp_map_active_translators (helper, &args);
if (diskfs_synchronous)
wait = 1;
diff --git a/libdiskfs/fsys-options.c b/libdiskfs/fsys-options.c
index f676ed07..61148823 100644
--- a/libdiskfs/fsys-options.c
+++ b/libdiskfs/fsys-options.c
@@ -26,6 +26,25 @@
#include "priv.h"
#include "fsys_S.h"
+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 <hurd/fsys.defs>. */
kern_return_t
diskfs_S_fsys_set_options (struct diskfs_control *pt,
@@ -35,28 +54,7 @@ diskfs_S_fsys_set_options (struct diskfs_control *pt,
int do_children)
{
error_t err = 0;
-
- 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, 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;
- }
+ struct args args = { data, len, do_children };
if (!pt)
return EOPNOTSUPP;
@@ -64,7 +62,7 @@ diskfs_S_fsys_set_options (struct diskfs_control *pt,
if (do_children)
{
pthread_rwlock_wrlock (&diskfs_fsys_lock);
- err = diskfs_node_iterate (helper);
+ err = fshelp_map_active_translators (helper, &args);
pthread_rwlock_unlock (&diskfs_fsys_lock);
}
diff --git a/libdiskfs/fsys-syncfs.c b/libdiskfs/fsys-syncfs.c
index 17b83ee0..1a40fcda 100644
--- a/libdiskfs/fsys-syncfs.c
+++ b/libdiskfs/fsys-syncfs.c
@@ -22,6 +22,20 @@
#include "fsys_S.h"
#include <hurd/fsys.h>
+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;
+}
+
/* Implement fsys_syncfs as described in <hurd/fsys.defs>. */
kern_return_t
diskfs_S_fsys_syncfs (struct diskfs_control *pi,
@@ -30,22 +44,7 @@ diskfs_S_fsys_syncfs (struct diskfs_control *pi,
int wait,
int children)
{
- 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))
- {
- fsys_syncfs (control, wait, 1);
- mach_port_deallocate (mach_task_self (), control);
- }
- pthread_mutex_lock (&np->lock);
- return 0;
- }
+ struct args args = { wait };
if (!pi)
return EOPNOTSUPP;
@@ -53,7 +52,7 @@ diskfs_S_fsys_syncfs (struct diskfs_control *pi,
pthread_rwlock_rdlock (&diskfs_fsys_lock);
if (children)
- diskfs_node_iterate (helper);
+ fshelp_map_active_translators (helper, &args);
if (diskfs_synchronous)
wait = 1;
diff --git a/libdiskfs/shutdown.c b/libdiskfs/shutdown.c
index 2436d528..3f774c31 100644
--- a/libdiskfs/shutdown.c
+++ b/libdiskfs/shutdown.c
@@ -22,35 +22,30 @@
#include "priv.h"
#include <hurd/fsys.h>
+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
diskfs_shutdown (int flags)
{
int nports = -1;
- int err;
-
- 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_goaway (control, flags);
- 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;
- }
+ error_t err;
+ struct args args = { flags };
if ((flags & FSYS_GOAWAY_UNLINK)
&& S_ISDIR (diskfs_root_node->dn_stat.st_mode))
@@ -58,7 +53,7 @@ diskfs_shutdown (int flags)
if (flags & FSYS_GOAWAY_RECURSE)
{
- err = diskfs_node_iterate (helper);
+ err = fshelp_map_active_translators (helper, &args);
if (err)
return err;
}