[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 06/15: libfshelp: Add function to map over all active translators
From: |
Samuel Thibault |
Subject: |
[hurd] 06/15: libfshelp: Add function to map over all active translators. |
Date: |
Sun, 19 Nov 2017 15:27:05 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch dde
in repository hurd.
commit 5fef1b7f22ec0ee3730b80bbf972dbf9a8995091
Author: Justus Winter <address@hidden>
Date: Wed Oct 5 15:38:58 2016 +0200
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.
---
libdiskfs/file-syncfs.c | 35 +++++++++++++++---------------
libdiskfs/fsys-options.c | 44 ++++++++++++++++++-------------------
libdiskfs/fsys-syncfs.c | 33 ++++++++++++++--------------
libdiskfs/shutdown.c | 45 +++++++++++++++++---------------------
libfshelp/fshelp.h | 10 +++++++++
libfshelp/translator-list.c | 26 ++++++++++++++++++++++
libnetfs/file-syncfs.c | 23 +++++++++++++++++---
libnetfs/fsys-set-options.c | 53 +++++++++++++++++++++------------------------
libnetfs/fsys-syncfs.c | 22 +++++++++++++++++++
libnetfs/shutdown.c | 45 ++++++++++++++++----------------------
10 files changed, 196 insertions(+), 140 deletions(-)
diff --git a/libdiskfs/file-syncfs.c b/libdiskfs/file-syncfs.c
index 2faab6a..8cd4003 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 f676ed0..6114882 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 17b83ee..1a40fcd 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 2436d52..3f774c3 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;
}
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h
index ecd9335..d1dd49c 100644
--- a/libfshelp/fshelp.h
+++ b/libfshelp/fshelp.h
@@ -71,6 +71,16 @@ fshelp_get_active_translators (char **translators,
fshelp_filter filter,
const char *prefix);
+/* Call FUN for each active translator. If FUN returns non-zero, the
+ iteration immediately stops, and returns that value. FUN is called
+ with COOKIE, the name of the translator, and the translators
+ control port. */
+error_t
+fshelp_map_active_translators (error_t (*fun)(void *cookie,
+ const char *name,
+ mach_port_t control),
+ void *cookie);
+
/* Passive translator linkage */
/* These routines are self-contained and start passive translators,
diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c
index b8fe3f9..c64e174 100644
--- a/libfshelp/translator-list.c
+++ b/libfshelp/translator-list.c
@@ -229,3 +229,29 @@ fshelp_get_active_translators (char **translators,
pthread_mutex_unlock (&translator_ihash_lock);
return err;
}
+
+/* Call FUN for each active translator. If FUN returns non-zero, the
+ iteration immediately stops, and returns that value. FUN is called
+ with COOKIE, the name of the translator, and the translators
+ control port. */
+error_t
+fshelp_map_active_translators (error_t (*fun)(void *cookie,
+ const char *name,
+ mach_port_t control),
+ void *cookie)
+{
+ error_t err = 0;
+ pthread_mutex_lock (&translator_ihash_lock);
+
+ HURD_IHASH_ITERATE (&translator_ihash, value)
+ {
+ struct translator *t = value;
+
+ err = fun (cookie, t->name, t->active);
+ if (err)
+ break;
+ }
+
+ pthread_mutex_unlock (&translator_ihash_lock);
+ return err;
+}
diff --git a/libnetfs/file-syncfs.c b/libnetfs/file-syncfs.c
index 2302e92..0b14bb8 100644
--- a/libnetfs/file-syncfs.c
+++ b/libnetfs/file-syncfs.c
@@ -20,6 +20,21 @@
#include "netfs.h"
#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;
+}
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 fb1c87e..afa480f 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 <hurd/fsys.defs>. */
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 e232936..904e924 100644
--- a/libnetfs/fsys-syncfs.c
+++ b/libnetfs/fsys-syncfs.c
@@ -20,6 +20,21 @@
#include "netfs.h"
#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;
+}
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 7fa05cd..082f2bc 100644
--- a/libnetfs/shutdown.c
+++ b/libnetfs/shutdown.c
@@ -26,33 +26,28 @@
#include <hurd/fshelp.h>
#include <pthread.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
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);
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] branch dde updated (4d4175c -> e3c726d), Samuel Thibault, 2017/11/19
- [hurd] 04/15: libfshelp: Avoid useless allocations., Samuel Thibault, 2017/11/19
- [hurd] 05/15: libfshelp: Always register dead-name notifications., Samuel Thibault, 2017/11/19
- [hurd] 07/15: Normalize path of translators., Samuel Thibault, 2017/11/19
- [hurd] 09/15: libfshelp: Avoid some right diddling., Samuel Thibault, 2017/11/19
- [hurd] 08/15: libfshelp: Improve error handling., Samuel Thibault, 2017/11/19
- [hurd] 12/15: libdiskfs: Shutdown pagers on startup_dosync., Samuel Thibault, 2017/11/19
- [hurd] 10/15: libfshelp: Use node instead of name as key., Samuel Thibault, 2017/11/19
- [hurd] 06/15: libfshelp: Add function to map over all active translators.,
Samuel Thibault <=
- [hurd] 02/15: libfshelp: improve translator list, Samuel Thibault, 2017/11/19
- [hurd] 01/15: pflocal: Use default stub implementations., Samuel Thibault, 2017/11/19
- [hurd] 15/15: Merge branch 'dde-upstream' into dde, Samuel Thibault, 2017/11/19
- [hurd] 03/15: Fix active translator registration., Samuel Thibault, 2017/11/19
- [hurd] 13/15: Merge remote-tracking branch 'mainline/master' into dde, Samuel Thibault, 2017/11/19
- [hurd] 14/15: Merge branch 'dde' of git.savannah.gnu.org:/srv/git/hurd/incubator into dde-upstream, Samuel Thibault, 2017/11/19
- [hurd] 11/15: Traverse translator hierarchies using the fsys protocol., Samuel Thibault, 2017/11/19