From: Petr Vorel <pvorel@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 1/2] libswap: add two methods to create swapfile
Date: Fri, 22 Mar 2024 06:00:46 +0100 [thread overview]
Message-ID: <20240322050046.GA572447@pevik> (raw)
In-Reply-To: <20240322030208.3278120-1-liwang@redhat.com>
Hi Li,
...
> Signed-off-by: Li Wang <liwang@redhat.com>
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
...
-int make_swapfile(const char *swapfile, int blocks, int safe)
+int make_swapfile_(const char *file, const int lineno,
+ const char *swapfile, unsigned int num,
+ int safe, enum swapfile_method method)
{
struct statvfs fs_info;
- unsigned long blk_size, bs;
+ unsigned long blk_size;
+ unsigned int blocks = 0;
size_t pg_size = sysconf(_SC_PAGESIZE);
- char mnt_path[100];
+ char mnt_path[128];
nit: why this increase to 128? Why not PATH_MAX?
> /* To guarantee at least one page can be swapped out */
> - if (blk_size * blocks < pg_size)
> - bs = pg_size;
> - else
> - bs = blk_size;
> + if (blk_size * blocks < pg_size) {
> + tst_res(TWARN, "Swapfile size is less than the system page size. \
> + Using page size (%lu bytes) instead of block size (%lu bytes).",
libswap.c:163: WARNING: Avoid line continuations in quoted strings
This will fix it:
tst_res(TWARN, "Swapfile size is less than the system page size. "
"Using page size (%lu bytes) instead of block size (%lu bytes).",
> + (unsigned long)pg_size, blk_size);
> + blk_size = pg_size;
> + }
> if (sscanf(swapfile, "%[^/]", mnt_path) != 1)
> - tst_brk(TBROK, "sscanf failed");
> + tst_brk_(file, lineno, TBROK, "sscanf failed");
> - if (!tst_fs_has_free(mnt_path, bs * blocks, TST_BYTES))
> - tst_brk(TCONF, "Insufficient disk space to create swap file");
> + if (!tst_fs_has_free(mnt_path, blk_size * blocks, TST_BYTES))
> + tst_brk_(file, lineno, TCONF, "Insufficient disk space to create swap file");
> /* create file */
> - if (prealloc_contiguous_file(swapfile, bs, blocks) != 0)
> - tst_brk(TBROK, "Failed to create swapfile");
> + if (prealloc_contiguous_file(swapfile, blk_size, blocks) != 0)
> + tst_brk_(file, lineno, TBROK, "Failed to create swapfile");
> /* Fill the file if needed (specific to old xfs filesystems) */
> if (tst_fs_type(swapfile) == TST_XFS_MAGIC) {
> - if (tst_fill_file(swapfile, 0, bs, blocks) != 0)
> - tst_brk(TBROK, "Failed to fill swapfile");
> + if (tst_fill_file(swapfile, 0, blk_size, blocks) != 0)
> + tst_brk_(file, lineno, TBROK, "Failed to fill swapfile");
> }
> /* make the file swapfile */
> - const char *argv[2 + 1];
> -
> - argv[0] = "mkswap";
> - argv[1] = swapfile;
> - argv[2] = NULL;
> + const char *argv[] = {"mkswap", swapfile, NULL};
libswap.c:186: WARNING: char * array declaration might be better as static const
This will fix it:
const char *const argv[] = {"mkswap", swapfile, NULL};
> return tst_cmd(argv, "/dev/null", "/dev/null", safe ?
> - TST_CMD_PASS_RETVAL | TST_CMD_TCONF_ON_MISSING : 0);
> + TST_CMD_PASS_RETVAL | TST_CMD_TCONF_ON_MISSING : 0);
The rest LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-03-22 5:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 3:02 [LTP] [PATCH v3 1/2] libswap: add two methods to create swapfile Li Wang
2024-03-22 3:02 ` [LTP] [PATCH v3 2/2] swapon01: create 128MB swapfile Li Wang
2024-03-22 5:00 ` Petr Vorel [this message]
2024-03-22 5:26 ` [LTP] [PATCH v3 1/2] libswap: add two methods to create swapfile Li Wang
2024-03-22 5:32 ` Petr Vorel
2024-03-25 2:53 ` Li Wang
2024-04-15 15:20 ` Petr Vorel
2024-04-16 6:35 ` Li Wang
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=20240322050046.GA572447@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.