[CRIU] [RFC PATCH 1/6] reserve the extra room in fstypes[]
Pavel Emelyanov
xemul at parallels.com
Mon Mar 30 02:42:14 PDT 2015
On 03/27/2015 08:55 PM, Oleg Nesterov wrote:
> Preparation. Enlarge fstypes[] to make it possible to add the new
> fstype's dynamically.
>
> This means ths find_fstype_by_name() and decode_fstype() need the
> additional ->name == NULL check to terminate the search.
>
> Also change them to start with "i == 1", we rely on the fact that
> fstypes[0] is FSTYPE__UNSUPPORTED anyway.
>
> Signed-off-by: Oleg Nesterov <oleg at redhat.com>
> ---
> mount.c | 26 +++++++++++++++++++-------
> 1 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/mount.c b/mount.c
> index 021c6e3..ff2bce5 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -1033,7 +1033,7 @@ out:
> return ret;
> }
>
> -static struct fstype fstypes[] = {
> +static struct fstype fstypes[32] = {
This means that we can only add "32 - current_amount" of FSs run time.
This is not bad at the moment, but once we add more in this list we
will likely forget to extend this :)
Can we better make this thing dynamically allocated?
> {
> .name = "unsupported",
> .code = FSTYPE__UNSUPPORTED,
> @@ -1107,9 +1107,15 @@ struct fstype *find_fstype_by_name(char *fst)
> * names anyway)
> */
>
> - for (i = 0; i < ARRAY_SIZE(fstypes); i++)
> - if (!strcmp(fstypes[i].name, fst))
> - return fstypes + i;
> + for (i = 1; i < ARRAY_SIZE(fstypes); i++) {
> + struct fstype *fstype = fstypes + i;
> +
> + if (!fstype->name)
> + break;
> +
> + if (!strcmp(fstype->name, fst))
> + return fstype;
> + }
>
> return &fstypes[0];
> }
> @@ -1121,9 +1127,15 @@ static struct fstype *decode_fstype(u32 fst)
> if (fst == FSTYPE__UNSUPPORTED)
> goto uns;
>
> - for (i = 0; i < ARRAY_SIZE(fstypes); i++)
> - if (fstypes[i].code == fst)
> - return fstypes + i;
> + for (i = 1; i < ARRAY_SIZE(fstypes); i++) {
> + struct fstype *fstype = fstypes + i;
> +
> + if (!fstype->name)
> + break;
> +
> + if (fstype->code == fst)
> + return fstype;
> + }
> uns:
> return &fstypes[0];
> }
>
More information about the CRIU
mailing list