[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] ios: track sub IOS devices
From: |
Mohammad-Reza Nabipoor |
Subject: |
Re: [PATCH 1/2] ios: track sub IOS devices |
Date: |
Sat, 24 Sep 2022 10:11:06 +0330 |
ping
On Wed, Aug 10, 2022 at 02:39:26AM +0430, Mohammad-Reza Nabipoor wrote:
> In each `struct ios' there's a list of all active sub devices.
> This list is used to invalidate sub devices when user closes
> the base IOS.
>
> 2022-08-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
>
> * bootstrap.conf (libpoke_modules): Add `array-list'.
> * libpoke/ios.h (ios_sub_claim): New function to track sub
> IO spaces.
> (ios_sub_unclaim): Likewise.
> * libpoke/ios.c (include): Include "gl_array_list.h".
> (struct ios): Add new field `sub_devs'.
> (ios_sub_claim): New function definition.
> (ios_sub_unclaim): Likewise.
> (ios_open): Intialize `sub_devs' field.
> (ios_close): Invalidate all active sub IOS devices.
> * libpoke/ios-dev-sub.c (struct ios_dev_sub): Use `ios' instead of
> ios id.
> (ios_dev_sub_open): Update to track base IOS.
> (ios_dev_sub_close): Likewise.
> (ios_dev_sub_pread): Use base IOS directly instead of searching
> using id.
> (ios_dev_sub_pwrite): Likewise.
> (ios_dev_sub_invalidate): New global function to report
> invalidation of a sub IOS device.
> ---
> ChangeLog | 22 ++++++++++++++++++++++
> bootstrap.conf | 1 +
> libpoke/ios-dev-sub.c | 29 +++++++++++++++++++----------
> libpoke/ios.c | 29 +++++++++++++++++++++++++++++
> libpoke/ios.h | 5 +++++
> 5 files changed, 76 insertions(+), 10 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index ef9187f5..834441ee 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,25 @@
> +2022-08-10 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
> +
> + * bootstrap.conf (libpoke_modules): Add `array-list'.
> + * libpoke/ios.h (ios_sub_claim): New function to track sub
> + IO spaces.
> + (ios_sub_unclaim): Likewise.
> + * libpoke/ios.c (include): Include "gl_array_list.h".
> + (struct ios): Add new field `sub_devs'.
> + (ios_sub_claim): New function definition.
> + (ios_sub_unclaim): Likewise.
> + (ios_open): Intialize `sub_devs' field.
> + (ios_close): Invalidate all active sub IOS devices.
> + * libpoke/ios-dev-sub.c (struct ios_dev_sub): Use `ios' instead of
> + ios id.
> + (ios_dev_sub_open): Update to track base IOS.
> + (ios_dev_sub_close): Likewise.
> + (ios_dev_sub_pread): Use base IOS directly instead of searching
> + using id.
> + (ios_dev_sub_pwrite): Likewise.
> + (ios_dev_sub_invalidate): New global function to report
> + invalidation of a sub IOS device.
> +
> 2022-07-25 Jose E. Marchesi <jemarch@gnu.org>
>
> * configure.ac: Bump version to 2.4.
> diff --git a/bootstrap.conf b/bootstrap.conf
> index 8a16795c..c924a170 100644
> --- a/bootstrap.conf
> +++ b/bootstrap.conf
> @@ -70,6 +70,7 @@ gnulib_modules="
>
> # gnulib modules used in libpoke/.
> libpoke_modules="
> + array-list
> basename-lgpl
> byteswap
> errno
> diff --git a/libpoke/ios-dev-sub.c b/libpoke/ios-dev-sub.c
> index d7f7d5de..bdfb3fc8 100644
> --- a/libpoke/ios-dev-sub.c
> +++ b/libpoke/ios-dev-sub.c
> @@ -32,7 +32,7 @@
>
> struct ios_dev_sub
> {
> - int base_ios_id;
> + ios base_ios;
> ios_dev_off base;
> ios_dev_off size;
> char *name;
> @@ -76,6 +76,7 @@ ios_dev_sub_open (const char *handler, uint64_t flags, int
> *error, void *data)
> struct ios_dev_sub *sub = malloc (sizeof (struct ios_dev_sub));
> const char *p;
> char *end;
> + int base_ios_id;
> int explicit_flags_p = (flags != 0);
>
> if (sub == NULL)
> @@ -86,6 +87,7 @@ ios_dev_sub_open (const char *handler, uint64_t flags, int
> *error, void *data)
> }
>
> sub->name = NULL; /* To ease error management below. */
> + sub->base_ios = NULL;
>
> /* Flags: only IOS_F_READ and IOS_F_WRITE are allowed. */
> sub->flags = explicit_flags_p ? flags : IOS_F_READ | IOS_F_WRITE;
> @@ -104,7 +106,7 @@ ios_dev_sub_open (const char *handler, uint64_t flags,
> int *error, void *data)
> p = handler + 6;
>
> /* Parse the Id of the base IOS. This is an integer. */
> - sub->base_ios_id = strtol (p, &end, 0);
> + base_ios_id = strtol (p, &end, 0);
> if (*p != '\0' && *end == '/')
> /* Valid integer found. */;
> else
> @@ -146,7 +148,7 @@ ios_dev_sub_open (const char *handler, uint64_t flags,
> int *error, void *data)
> uint64_t iflags;
>
> /* The referred IOS should exist. */
> - base_ios = ios_search_by_id (sub->base_ios_id);
> + base_ios = ios_search_by_id (base_ios_id);
> if (base_ios == NULL)
> goto error;
>
> @@ -170,6 +172,8 @@ ios_dev_sub_open (const char *handler, uint64_t flags,
> int *error, void *data)
> free (sub);
> return NULL;
> }
> + sub->base_ios = base_ios;
> + ios_sub_claim (base_ios, sub);
> }
>
> if (error)
> @@ -189,6 +193,8 @@ ios_dev_sub_close (void *iod)
> {
> struct ios_dev_sub *sub = iod;
>
> + if (sub->base_ios)
> + ios_sub_unclaim (sub->base_ios, sub);
> free (sub->name);
> free (sub);
> return IOD_OK;
> @@ -201,16 +207,11 @@ ios_dev_sub_get_flags (void *iod)
> return sub->flags;
> }
>
> -/* XXX search_by_id to get the base IOS in pread and pwrite is slow as
> - shit. It would be good to cache the IOS at open time, but then we
> - have to make ios.c aware of subios so it will mark all sub-ios of a
> - given IOS when the later is closed. */
> -
> static int
> ios_dev_sub_pread (void *iod, void *buf, size_t count, ios_dev_off offset)
> {
> struct ios_dev_sub *sub = iod;
> - ios ios = ios_search_by_id (sub->base_ios_id);
> + ios ios = sub->base_ios;
>
> if (ios == NULL || !(sub->flags & IOS_F_READ))
> return IOD_ERROR;
> @@ -228,7 +229,7 @@ ios_dev_sub_pwrite (void *iod, const void *buf, size_t
> count,
> ios_dev_off offset)
> {
> struct ios_dev_sub *sub = iod;
> - ios ios = ios_search_by_id (sub->base_ios_id);
> + ios ios = sub->base_ios;
>
> if (ios == NULL || !(sub->flags & IOS_F_WRITE))
> return IOD_ERROR;
> @@ -255,6 +256,14 @@ ios_dev_sub_flush (void *iod, ios_dev_off offset)
> return IOS_OK;
> }
>
> +void
> +ios_dev_sub_invalidate (void *iod)
> +{
> + struct ios_dev_sub *sub = iod;
> +
> + sub->base_ios = NULL;
> +}
> +
> struct ios_dev_if ios_dev_sub =
> {
> .get_if_name = ios_dev_sub_get_if_name,
> diff --git a/libpoke/ios.c b/libpoke/ios.c
> index 9bf46452..464a75b4 100644
> --- a/libpoke/ios.c
> +++ b/libpoke/ios.c
> @@ -26,6 +26,7 @@
> #define _(str) gettext (str)
> #include <streq.h>
>
> +#include "gl_array_list.h"
> #include "byteswap.h"
>
> #include "pk-utils.h"
> @@ -74,6 +75,7 @@ struct ios
> void *dev;
> struct ios_dev_if *dev_if;
> ios_off bias;
> + gl_list_t sub_devs;
>
> struct ios *next;
> };
> @@ -149,6 +151,7 @@ ios_open (const char *handler, uint64_t flags, int
> set_cur)
> io->handler = NULL;
> io->next = NULL;
> io->bias = 0;
> + io->sub_devs = gl_list_nx_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL,
> true);
>
> /* Look for a device interface suitable to operate on the given
> handler. */
> @@ -241,6 +244,16 @@ ios_close (ios io)
> if (io == cur_io)
> cur_io = io_list;
>
> + /* Invalidate the sub-devices. */
> + {
> + size_t n = gl_list_size (io->sub_devs);
> + extern void ios_dev_sub_invalidate (void *);
> +
> + for (size_t i = 0; i < n; ++i)
> + ios_dev_sub_invalidate ((void *)gl_list_get_at (io->sub_devs, i));
> + gl_list_free (io->sub_devs);
> + }
> +
> free (io);
>
> return IOD_ERROR_TO_IOS_ERROR (ret);
> @@ -1643,3 +1656,19 @@ ios_register_foreign_iod (struct ios_dev_if *iod_if)
> ios_dev_ifs[0] = iod_if;
> return IOS_OK;
> }
> +
> +void
> +ios_sub_claim (ios ios, void *sub_dev)
> +{
> + gl_list_node_t node = gl_list_nx_add_last (ios->sub_devs, sub_dev);
> +
> + assert (node);
> +}
> +
> +void
> +ios_sub_unclaim (ios ios, void *sub_dev)
> +{
> + bool ok = gl_list_remove (ios->sub_devs, sub_dev);
> +
> + assert (ok);
> +}
> diff --git a/libpoke/ios.h b/libpoke/ios.h
> index a942c43f..478cf030 100644
> --- a/libpoke/ios.h
> +++ b/libpoke/ios.h
> @@ -366,4 +366,9 @@ struct ios_dev_if *ios_foreign_iod (void);
> struct ios_dev_if;
> int ios_register_foreign_iod (struct ios_dev_if *iod_if);
>
> +/* **************** Sub IO space **************** */
> +
> +void ios_sub_claim (ios ios, void *sub_dev);
> +void ios_sub_unclaim (ios ios, void *sub_dev);
> +
> #endif /* ! IOS_H */
> --
> 2.37.1
>
>
>
- Re: [PATCH 1/2] ios: track sub IOS devices,
Mohammad-Reza Nabipoor <=