summaryrefslogtreecommitdiff
path: root/libfshelp
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2017-08-22 13:07:54 +0200
committerJustus Winter <justus@gnupg.org>2017-09-12 10:41:35 +0200
commite08859424e01697fe556e277283e8e1905327ce7 (patch)
tree93bf0ad8e0af70cffa177c4271a31a5b15d533c8 /libfshelp
parent04aaffbd6353e7cec04073783cc8cbd22ac2f675 (diff)
libfshelp: Use node instead of name as key.
Previously, libfshelp used the name of an translator as key in the hash table. This however is flawed, because a translator is bound to a node, and a node can have zero or more links in the file system. Use the nodes address (or rather, the address of the transbox embedded in the node) as key instead. * libfshelp/fshelp.h (fshelp_set_active_translator): Instead of the control port, hand the whole transbox to the function. * libfshelp/translator-list.c (struct translator): New field 'locp'. (hash): Hash pointer. (compare): Compare pointer. (translator_ihash): Use an location pointer. (fshelp_set_active_translator): Use the address of the transbox as key. (fshelp_remove_active_translator): Remove using the location pointer. * libdiskfs/dir-lookup.c (diskfs_S_dir_lookup): Fix callsite. * libdiskfs/file-set-trans.c (diskfs_S_file_set_translator): Likewise. * libnetfs/dir-lookup.c (netfs_S_dir_lookup): Likewise. * libnetfs/file-set-translator.c (netfs_S_file_set_translator): Likewise.
Diffstat (limited to 'libfshelp')
-rw-r--r--libfshelp/fshelp.h10
-rw-r--r--libfshelp/translator-list.c50
2 files changed, 31 insertions, 29 deletions
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h
index d1dd49c4..7663ba1d 100644
--- a/libfshelp/fshelp.h
+++ b/libfshelp/fshelp.h
@@ -38,16 +38,16 @@
require multi threading but depend on the ports library. */
struct port_info;
+struct transbox;
/* Record an active translator being bound to the given file name
- NAME. ACTIVE is the control port of the translator. PI references
- a receive port that is used to request dead name notifications,
- typically the port for the underlying node passed to the
- translator. */
+ NAME. TRANSBOX is the nodes transbox. PI references a receive
+ port that is used to request dead name notifications, typically the
+ port for the underlying node passed to the translator. */
error_t
fshelp_set_active_translator (struct port_info *pi,
const char *name,
- mach_port_t active);
+ const struct transbox *transbox);
/* Remove the active translator specified by its control port ACTIVE.
If there is no active translator with the given control port, this
diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c
index a3603300..7077b217 100644
--- a/libfshelp/translator-list.c
+++ b/libfshelp/translator-list.c
@@ -35,9 +35,13 @@
struct translator
{
- struct port_info *pi;
- char *name;
- mach_port_t active;
+ hurd_ihash_locp_t locp; /* Slot in the hash table. */
+ struct port_info *pi; /* We get dead-name notifications
+ here. */
+ char *name; /* The path to the node the translator
+ is bound to, relative to the root.
+ This is a best effort. */
+ mach_port_t active; /* Translator control port. */
};
/* The hash table requires some callback functions. */
@@ -56,41 +60,43 @@ cleanup (void *value, void *arg)
static hurd_ihash_key_t
hash (const void *key)
{
- return (hurd_ihash_key_t) hurd_ihash_hash32 (key, strlen (key), 0);
+ return (hurd_ihash_key_t) hurd_ihash_hash32 (key, sizeof (void *), 0);
}
static int
compare (const void *a, const void *b)
{
- return strcmp ((const char *) a, (const char *) b) == 0;
+ return *(void **) a == *(void **) b;
}
/* The list of active translators. */
static struct hurd_ihash translator_ihash
- = HURD_IHASH_INITIALIZER_GKI (HURD_IHASH_NO_LOCP, cleanup, NULL,
- hash, compare);
+ = HURD_IHASH_INITIALIZER_GKI (offsetof (struct translator, locp),
+ cleanup, NULL, hash, compare);
/* The lock protecting the translator_ihash. */
static pthread_mutex_t translator_ihash_lock = PTHREAD_MUTEX_INITIALIZER;
/* Record an active translator being bound to the given file name
- NAME. ACTIVE is the control port of the translator. */
+ NAME. TRANSBOX is the nodes transbox. PI references a receive
+ port that is used to request dead name notifications, typically the
+ port for the underlying node passed to the translator. */
error_t
fshelp_set_active_translator (struct port_info *pi,
const char *name,
- mach_port_t active)
+ const struct transbox *transbox)
{
error_t err = 0;
struct translator *t;
hurd_ihash_locp_t slot;
pthread_mutex_lock (&translator_ihash_lock);
- t = hurd_ihash_locp_find (&translator_ihash, (hurd_ihash_key_t) name,
+ t = hurd_ihash_locp_find (&translator_ihash, (hurd_ihash_key_t) transbox,
&slot);
if (t)
goto update; /* Entry exists. */
- if (! MACH_PORT_VALID (active))
+ if (! MACH_PORT_VALID (transbox->active))
/* Avoid allocating an entry just to delete it. */
goto out;
@@ -112,7 +118,7 @@ fshelp_set_active_translator (struct port_info *pi,
}
err = hurd_ihash_locp_add (&translator_ihash, slot,
- (hurd_ihash_key_t) t->name, t);
+ (hurd_ihash_key_t) transbox, t);
if (err)
{
free (t->name);
@@ -121,17 +127,17 @@ fshelp_set_active_translator (struct port_info *pi,
}
update:
- if (MACH_PORT_VALID (active) && active != t->active)
+ if (MACH_PORT_VALID (transbox->active) && transbox->active != t->active)
{
mach_port_t old;
- err = mach_port_request_notification (mach_task_self (), active,
+ err = mach_port_request_notification (mach_task_self (), transbox->active,
MACH_NOTIFY_DEAD_NAME, 0,
pi->port_right,
MACH_MSG_TYPE_MAKE_SEND_ONCE,
&old);
if (err)
goto out;
- if (old != MACH_PORT_NULL)
+ if (MACH_PORT_VALID (old))
mach_port_deallocate (mach_task_self (), old);
if (t->pi)
@@ -142,14 +148,14 @@ fshelp_set_active_translator (struct port_info *pi,
if (MACH_PORT_VALID (t->active))
mach_port_deallocate (mach_task_self (), t->active);
- mach_port_mod_refs (mach_task_self (), active,
+ mach_port_mod_refs (mach_task_self (), transbox->active,
MACH_PORT_RIGHT_SEND, +1);
- t->active = active;
+ t->active = transbox->active;
}
- else if (! MACH_PORT_VALID (active))
+ else if (! MACH_PORT_VALID (transbox->active))
{
int ok;
- ok = hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) t->name);
+ ok = hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) transbox);
assert_backtrace (ok);
}
@@ -179,11 +185,7 @@ fshelp_remove_active_translator (mach_port_t active)
}
if (t)
- {
- int ok;
- ok = hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) t->name);
- assert_backtrace (ok);
- }
+ hurd_ihash_locp_remove (&translator_ihash, t->locp);
pthread_mutex_unlock (&translator_ihash_lock);
return err;