[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 5/7] procfs: generalize the translator linkage code
From: |
Samuel Thibault |
Subject: |
Re: [PATCH 5/7] procfs: generalize the translator linkage code |
Date: |
Mon, 29 Sep 2014 01:26:24 +0200 |
User-agent: |
Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30) |
Justus Winter, le Mon 22 Sep 2014 11:38:42 +0200, a écrit :
> Generalize the translator linkage code previously introduced for the
> `mounts' node.
Ack.
> * procfs/rootdir.c (struct procfs_translated_node_ops): New
> specialized node operations structure for translated nodes.
> (rootdir_mounts_make_node): Generalize and rename to
> rootdir_make_translated_node. Also, pass the entry_hook to
> procfs_make_node so that...
> (rootdir_mounts_get_translator): ... can be generalized to
> rootdir_translated_node_get_translator and read the argz vector from
> the hooked structure.
> (ROOTDIR_DEFINE_TRANSLATED_NODE): New convenience macro to define
> translated nodes.
> (rootdir_entries): Use the new code for the `mounts' node.
> ---
> procfs/rootdir.c | 62
> ++++++++++++++++++++++++++++++++++++++------------------
> 1 file changed, 42 insertions(+), 20 deletions(-)
>
> diff --git a/procfs/rootdir.c b/procfs/rootdir.c
> index 81e36f7..a04fb3e 100644
> --- a/procfs/rootdir.c
> +++ b/procfs/rootdir.c
> @@ -409,17 +409,29 @@ rootdir_gc_fakeself (void *hook, char **contents,
> ssize_t *contents_len)
> }
>
> static struct node *rootdir_mounts_node;
> -static pthread_spinlock_t rootdir_mounts_node_lock =
> +
> +/* Translator linkage. */
> +static pthread_spinlock_t rootdir_translated_node_lock =
> PTHREAD_SPINLOCK_INITIALIZER;
>
> +struct procfs_translated_node_ops
> +{
> + struct procfs_node_ops node_ops;
> +
> + struct node **npp;
> + char *argz;
> + size_t argz_len;
> +};
> +
> static struct node *
> -rootdir_mounts_make_node (void *dir_hook, const void *entry_hook)
> +rootdir_make_translated_node (void *dir_hook, const void *entry_hook)
> {
> + const struct procfs_translated_node_ops *ops = entry_hook;
> struct node *np, *prev;
>
> - pthread_spin_lock (&rootdir_mounts_node_lock);
> - np = rootdir_mounts_node;
> - pthread_spin_unlock (&rootdir_mounts_node_lock);
> + pthread_spin_lock (&rootdir_translated_node_lock);
> + np = *ops->npp;
> + pthread_spin_unlock (&rootdir_translated_node_lock);
>
> if (np != NULL)
> {
> @@ -427,18 +439,18 @@ rootdir_mounts_make_node (void *dir_hook, const void
> *entry_hook)
> return np;
> }
>
> - np = procfs_make_node (entry_hook, dir_hook);
> + np = procfs_make_node (entry_hook, entry_hook);
> if (np == NULL)
> return NULL;
>
> procfs_node_chtype (np, S_IFREG | S_IPTRANS);
> procfs_node_chmod (np, 0444);
>
> - pthread_spin_lock (&rootdir_mounts_node_lock);
> - prev = rootdir_mounts_node;
> - if (rootdir_mounts_node == NULL)
> - rootdir_mounts_node = np;
> - pthread_spin_unlock (&rootdir_mounts_node_lock);
> + pthread_spin_lock (&rootdir_translated_node_lock);
> + prev = *ops->npp;
> + if (*ops->npp == NULL)
> + *ops->npp = np;
> + pthread_spin_unlock (&rootdir_translated_node_lock);
>
> if (prev != NULL)
> {
> @@ -450,19 +462,30 @@ rootdir_mounts_make_node (void *dir_hook, const void
> *entry_hook)
> }
>
> static error_t
> -rootdir_mounts_get_translator (void *hook, char **argz, size_t *argz_len)
> +rootdir_translated_node_get_translator (void *hook, char **argz,
> + size_t *argz_len)
> {
> - static const char const mtab_argz[] = _HURD_MTAB "\0/";
> + const struct procfs_translated_node_ops *ops = hook;
>
> - *argz = malloc (sizeof mtab_argz);
> + *argz = malloc (ops->argz_len);
> if (! *argz)
> return ENOMEM;
>
> - memcpy (*argz, mtab_argz, sizeof mtab_argz);
> - *argz_len = sizeof mtab_argz;
> + memcpy (*argz, ops->argz, ops->argz_len);
> + *argz_len = ops->argz_len;
> return 0;
> }
>
> +#define ROOTDIR_DEFINE_TRANSLATED_NODE(NPP, ARGZ) \
> + &(struct procfs_translated_node_ops) { \
> + .node_ops = { \
> + .get_translator = rootdir_translated_node_get_translator, \
> + }, \
> + .npp = NPP, \
> + .argz = (ARGZ), \
> + .argz_len = sizeof (ARGZ), \
> + }
> +
> static error_t
> rootdir_gc_slabinfo (void *hook, char **contents, ssize_t *contents_len)
> {
> @@ -660,11 +683,10 @@ static const struct procfs_dir_entry rootdir_entries[]
> = {
> },
> {
> .name = "mounts",
> - .hook = & (struct procfs_node_ops) {
> - .get_translator = rootdir_mounts_get_translator,
> - },
> + .hook = ROOTDIR_DEFINE_TRANSLATED_NODE (&rootdir_mounts_node,
> + _HURD_MTAB "\0/"),
> .ops = {
> - .make_node = rootdir_mounts_make_node,
> + .make_node = rootdir_make_translated_node,
> }
> },
> {
> --
> 2.1.0
>
--
Samuel
<g> r: et la marmotte, elle écrit un papier IPDPS
- [PATCH 4/6] procfs: generalize the translator linkage code, (continued)
- [PATCH 4/6] procfs: generalize the translator linkage code, Justus Winter, 2014/09/21
- Re: [PATCH 4/6] procfs: generalize the translator linkage code, Justus Winter, 2014/09/21
- [PATCH 1/7] procfs: implement /proc/N/maps, Justus Winter, 2014/09/22
- [PATCH 3/7] procfs: implement /proc/N/mounts, Justus Winter, 2014/09/22
- Re: [PATCH 3/7] procfs: implement /proc/N/mounts, Samuel Thibault, 2014/09/28
- [PATCH 4/7] procfs: do not test whether /hurd/mtab exists, Justus Winter, 2014/09/22
- Re: [PATCH 4/7] procfs: do not test whether /hurd/mtab exists, Samuel Thibault, 2014/09/28
- [PATCH 2/7] procfs: implement /proc/filesystems, Justus Winter, 2014/09/22
- Re: [PATCH 2/7] procfs: implement /proc/filesystems, Samuel Thibault, 2014/09/28
- [PATCH 5/7] procfs: generalize the translator linkage code, Justus Winter, 2014/09/22
- Re: [PATCH 5/7] procfs: generalize the translator linkage code,
Samuel Thibault <=
- [PATCH 6/7] procfs: reorganize rootdir.c, Justus Winter, 2014/09/22
- Re: [PATCH 6/7] procfs: reorganize rootdir.c, Samuel Thibault, 2014/09/28
- [PATCH 7/7] procfs: provide magic retry response for /proc/self, Justus Winter, 2014/09/22
- Re: [PATCH 7/7] procfs: provide magic retry response for /proc/self, Samuel Thibault, 2014/09/30
- And the libc patch, Justus Winter, 2014/09/22
- [PATCH] hurd: Handle `proc/self' magical lookup retry, Justus Winter, 2014/09/22
- Re: [PATCH 1/7] procfs: implement /proc/N/maps, Samuel Thibault, 2014/09/28
- [PATCH 5/6] procfs: reorganize rootdir.c, Justus Winter, 2014/09/21
- [PATCH 6/6] procfs: provide magic retry response for /proc/self, Justus Winter, 2014/09/21