public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 2/7] libltpswap: alter tst_count_swaps api
Date: Fri, 23 Feb 2024 10:37:18 +0100	[thread overview]
Message-ID: <20240223093718.GD1423688@pevik> (raw)
In-Reply-To: <20240220074218.13487-2-xuyang2018.jy@fujitsu.com>

Hi Yang Xu,

> Like we count the ipc resource total, we can also add a
nit: s/ipc/IPC/

> similar api for swapfiles, so we can use it for swapon03 case.
nit: s/api/API/

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> +
> +/*
> + * Get the used swapfiles number
> + */
> +int tst_count_swaps(void)
> +{
> +	FILE *fp;
> +	int used = -1;
> +	char c;
> +
> +	fp = fopen("/proc/swaps", "r");
> +	if (fp == NULL) {
> +		return -1;
Shouldn't we tst_brk(TCONF, "missing /proc/swaps, no swap support?");
This can happen if CONFIG_SWAP is not configured. We have in swapon03.c:

	if (access("/proc/swaps", F_OK))
		tst_brk(TCONF, "swap not supported by kernel");

Once this patchset is solved, I'll add to this code to a function
is_swap_supported in libswap.c, which will be used in all swapo{n,ff}* tests.
(That will be better than require CONFIG_SWAP kconfig.)
Then we can use SAFE_FOPEN() here.

> +	}
> +
> +	while ((c = fgetc(fp)) != EOF) {
> +		if (c == '\n')
> +			used++;
So you read number of lines in /proc/swaps, -1 because file has header.
> +	}
> +
> +	fclose(fp);
Maybe SAFE_FCLOSE() ?

> +	if (used < 0) {
> +		tst_brk(TBROK, "can't read /proc/swaps to get used swapfiles resource total");
> +	}
nit: no need for { }

Kind regards,
Petr

> +
> +	return used;
> +}

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-02-23  9:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20  7:42 [LTP] [PATCH v4 1/7] libltpswap: Add tst_max_swapfiles api Yang Xu via ltp
2024-02-20  7:42 ` [LTP] [PATCH v4 2/7] libltpswap: alter tst_count_swaps api Yang Xu via ltp
2024-02-23  9:37   ` Petr Vorel [this message]
2024-02-20  7:42 ` [LTP] [PATCH v4 3/7] syscalls/swapon03: use tst_max_swapfiles() and GET_USED_SWAPFILES() api Yang Xu via ltp
2024-02-21  9:37   ` Petr Vorel
2024-02-22  1:27     ` Yang Xu (Fujitsu) via ltp
2024-02-23  9:48   ` Petr Vorel
2024-02-20  7:42 ` [LTP] [PATCH v4 4/7] swaponoff.h: Remove useless header Yang Xu via ltp
2024-02-23 10:15   ` Petr Vorel
2024-02-20  7:42 ` [LTP] [PATCH v4 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu via ltp
2024-02-23 10:48   ` Petr Vorel
2024-02-20  7:42 ` [LTP] [PATCH v4 6/7] syscalls/swapon03: Simply this case Yang Xu via ltp
2024-02-23 11:48   ` Petr Vorel
2024-02-20  7:42 ` [LTP] [PATCH v4 7/7] Add fallback for RHEL9 Yang Xu via ltp
2024-02-23 11:54   ` Petr Vorel
2024-02-23  9:04 ` [LTP] [PATCH v4 1/7] libltpswap: Add tst_max_swapfiles api Petr Vorel
2024-02-23 11:56 ` 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=20240223093718.GD1423688@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=xuyang2018.jy@fujitsu.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox