From: Petr Vorel <pvorel@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 1/2] libswap: add two methods to create swapfile
Date: Wed, 20 Mar 2024 08:31:16 +0100 [thread overview]
Message-ID: <20240320073116.GA452876@pevik> (raw)
In-Reply-To: <20240319100822.3243785-2-liwang@redhat.com>
Hi Li,
Generally LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
...
> /*
> - * Make a swap file
> + * Create a swapfile of a specified size or number of blocks.
> */
> -int make_swapfile(const char *swapfile, int blocks, int safe);
> +int make_swapfile(const char *swapfile, unsigned int num,
> + int safe, enum swapfile_method method);
I wonder if it would help to add const char *file, const int lineno here.
> +
> +#define MAKE_SWAPFILE_SIZE(swapfile, size, safe) \
> + make_swapfile(swapfile, size, safe, SWAPFILE_BY_SIZE)
nit: I like the name but one have to search which units (kB vs. MB vs. GB) are used.
> +
> +#define MAKE_SWAPFILE_BLKS(swapfile, blocks, safe) \
> + make_swapfile(swapfile, blocks, safe, SWAPFILE_BY_BLKS)
And we could also have SAFE_ variants.
Therefore maybe rename make_swapfile() to make_swapfile_()
(approach in LTP for functions to be wrapped) and define macros:
int make_swapfile_(const char *file, const int lineno,
const char *swapfile, unsigned int num,
int safe, enum swapfile_method method);
#define MAKE_SWAPFILE_SIZE(swapfile, size, safe) \
make_swapfile_(__FILE__, __LINE__, swapfile, size, 0, SWAPFILE_BY_SIZE)
#define MAKE_SWAPFILE_BLKS(swapfile, blocks, safe) \
make_swapfile_(__FILE__, __LINE__, swapfile, blocks, 0, SWAPFILE_BY_BLKS)
#define SAFE_MAKE_SWAPFILE_SIZE(swapfile, size, safe) \
make_swapfile_(__FILE__, __LINE__, swapfile, size, 1, SWAPFILE_BY_SIZE)
#define SAFE_MAKE_SWAPFILE_BLKS(swapfile, blocks, safe) \
make_swapfile_(__FILE__, __LINE__, swapfile, blocks, 1, SWAPFILE_BY_BLKS)
> /*
> * Check swapon/swapoff support status of filesystems or files
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index a26ea25e4..0e2476ec2 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -133,18 +133,26 @@ out:
> return contiguous;
> }
> -int make_swapfile(const char *swapfile, int blocks, int safe)
> +int make_swapfile(const char *swapfile, unsigned int num, int safe, enum swapfile_method method)
> {
> struct statvfs fs_info;
> unsigned long blk_size, bs;
> size_t pg_size = sysconf(_SC_PAGESIZE);
> char mnt_path[100];
> + unsigned int blocks = 0;
> if (statvfs(".", &fs_info) == -1)
> return -1;
> blk_size = fs_info.f_bsize;
> + if (method == SWAPFILE_BY_SIZE)
> + blocks = num * 1024 * 1024 / blk_size;
> + else if (method == SWAPFILE_BY_BLKS)
> + blocks = num;
> + else
> + tst_brk(TBROK, "Invalid method, please see include/libswap.h");
nit: I would print the method.
Using const char *file, const int lineno and tst_brk_() would help
later to point out which file actually contains wrong method.
...
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-03-20 7:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 10:08 [LTP] [PATCH v2 0/2] add method to create swapfile by MB size Li Wang
2024-03-19 10:08 ` [LTP] [PATCH v2 1/2] libswap: add two methods to create swapfile Li Wang
2024-03-20 7:31 ` Petr Vorel [this message]
2024-03-21 9:49 ` Li Wang
2024-03-21 12:41 ` Petr Vorel
2024-03-19 10:08 ` [LTP] [PATCH v2 2/2] swapon01: create 128MB swapfile Li Wang
2024-03-20 7:32 ` Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240320073116.GA452876@pevik \
--to=pvorel@suse.cz \
--cc=liwang@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.