All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] libswap: Move file & line macros to macros
@ 2024-04-17 12:31 Petr Vorel
  2024-04-17 12:31 ` [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res() Petr Vorel
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Petr Vorel @ 2024-04-17 12:31 UTC (permalink / raw)
  To: ltp

Having __FILE__ and __LINE__ in C function does not help,
they must be in macros to help identify the caller.

Therefore make_swapfile_() wrapper is not needed.

Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/libswap.h         | 16 +++++-----------
 libs/libltpswap/libswap.c |  2 +-
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/include/libswap.h b/include/libswap.h
index 96e718542..87e32328e 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -19,41 +19,35 @@ enum swapfile_method {
 /*
  * Create a swapfile of a specified size or number of blocks.
  */
-int make_swapfile_(const char *file, const int lineno,
+int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method);
 
-static inline int make_swapfile(const char *swapfile, unsigned int num,
-			int safe, enum swapfile_method method)
-{
-	return make_swapfile_(__FILE__, __LINE__, swapfile, num, safe, method);
-}
-
 /**
  * Macro to create swapfile size in megabytes (MB).
  */
 #define MAKE_SWAPFILE_SIZE(swapfile, size) \
-    make_swapfile(swapfile, size, 0, SWAPFILE_BY_SIZE)
+    make_swapfile(__FILE__, __LINE__, swapfile, size, 0, SWAPFILE_BY_SIZE)
 
 /**
  * Macro to create swapfile size in block numbers.
  */
 #define MAKE_SWAPFILE_BLKS(swapfile, blocks) \
-    make_swapfile(swapfile, blocks, 0, SWAPFILE_BY_BLKS)
+    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 0, SWAPFILE_BY_BLKS)
 
 /**
  * Macro to safely create swapfile size in megabytes (MB).
  * Includes safety checks to handle potential errors.
  */
 #define SAFE_MAKE_SWAPFILE_SIZE(swapfile, size) \
-    make_swapfile(swapfile, size, 1, SWAPFILE_BY_SIZE)
+    make_swapfile(__FILE__, __LINE__, swapfile, size, 1, SWAPFILE_BY_SIZE)
 
 /**
  * Macro to safely create swapfile size in block numbers.
  * Includes safety checks to handle potential errors.
  */
 #define SAFE_MAKE_SWAPFILE_BLKS(swapfile, blocks) \
-    make_swapfile(swapfile, blocks, 1, SWAPFILE_BY_BLKS)
+    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 313a15f24..b4233be0d 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -133,7 +133,7 @@ out:
 	return contiguous;
 }
 
-int make_swapfile_(const char *file, const int lineno,
+int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method)
 {
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res()
  2024-04-17 12:31 [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Petr Vorel
@ 2024-04-17 12:31 ` Petr Vorel
  2024-04-18  5:32   ` Li Wang
  2024-04-18 11:24   ` Cyril Hrubis
  2024-04-18  5:32 ` [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Li Wang
  2024-04-18 11:23 ` Cyril Hrubis
  2 siblings, 2 replies; 7+ messages in thread
From: Petr Vorel @ 2024-04-17 12:31 UTC (permalink / raw)
  To: ltp

That allows to identify the caller of the function. That is the reason
why tst_brk_() was already used instead of tst_brk().

Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 libs/libltpswap/libswap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index b4233be0d..aed76dfe2 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -149,18 +149,18 @@ int make_swapfile(const char *file, const int lineno,
 	blk_size = fs_info.f_bsize;
 
 	if (method == SWAPFILE_BY_SIZE) {
-		tst_res(TINFO, "create a swapfile size of %u megabytes (MB)", num);
+		tst_res_(file, lineno, TINFO, "create a swapfile size of %u megabytes (MB)", num);
 		blocks = num * 1024 * 1024 / blk_size;
 	} else if (method == SWAPFILE_BY_BLKS) {
 		blocks = num;
-		tst_res(TINFO, "create a swapfile with %u block numbers", blocks);
+		tst_res_(file, lineno, TINFO, "create a swapfile with %u block numbers", blocks);
 	} else {
 		tst_brk_(file, lineno, TBROK, "Invalid method, please see include/libswap.h");
 	}
 
 	/* To guarantee at least one page can be swapped out */
 	if (blk_size * blocks < pg_size) {
-		tst_res(TWARN, "Swapfile size is less than the system page size. "
+		tst_res_(file, lineno, 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;
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH 1/2] libswap: Move file & line macros to macros
  2024-04-17 12:31 [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Petr Vorel
  2024-04-17 12:31 ` [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res() Petr Vorel
@ 2024-04-18  5:32 ` Li Wang
  2024-04-18 11:23 ` Cyril Hrubis
  2 siblings, 0 replies; 7+ messages in thread
From: Li Wang @ 2024-04-18  5:32 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Wed, Apr 17, 2024 at 8:31 PM Petr Vorel <pvorel@suse.cz> wrote:

> Having __FILE__ and __LINE__ in C function does not help,
> they must be in macros to help identify the caller.
>
> Therefore make_swapfile_() wrapper is not needed.
>
> Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
>

Reviewed-by: Li Wang <liwang@redhat.com>


> ---
>  include/libswap.h         | 16 +++++-----------
>  libs/libltpswap/libswap.c |  2 +-
>  2 files changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/include/libswap.h b/include/libswap.h
> index 96e718542..87e32328e 100644
> --- a/include/libswap.h
> +++ b/include/libswap.h
> @@ -19,41 +19,35 @@ enum swapfile_method {
>  /*
>   * Create a swapfile of a specified size or number of blocks.
>   */
> -int make_swapfile_(const char *file, const int lineno,
> +int make_swapfile(const char *file, const int lineno,
>                         const char *swapfile, unsigned int num,
>                         int safe, enum swapfile_method method);
>
> -static inline int make_swapfile(const char *swapfile, unsigned int num,
> -                       int safe, enum swapfile_method method)
> -{
> -       return make_swapfile_(__FILE__, __LINE__, swapfile, num, safe,
> method);
> -}
> -
>  /**
>   * Macro to create swapfile size in megabytes (MB).
>   */
>  #define MAKE_SWAPFILE_SIZE(swapfile, size) \
> -    make_swapfile(swapfile, size, 0, SWAPFILE_BY_SIZE)
> +    make_swapfile(__FILE__, __LINE__, swapfile, size, 0, SWAPFILE_BY_SIZE)
>
>  /**
>   * Macro to create swapfile size in block numbers.
>   */
>  #define MAKE_SWAPFILE_BLKS(swapfile, blocks) \
> -    make_swapfile(swapfile, blocks, 0, SWAPFILE_BY_BLKS)
> +    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 0,
> SWAPFILE_BY_BLKS)
>
>  /**
>   * Macro to safely create swapfile size in megabytes (MB).
>   * Includes safety checks to handle potential errors.
>   */
>  #define SAFE_MAKE_SWAPFILE_SIZE(swapfile, size) \
> -    make_swapfile(swapfile, size, 1, SWAPFILE_BY_SIZE)
> +    make_swapfile(__FILE__, __LINE__, swapfile, size, 1, SWAPFILE_BY_SIZE)
>
>  /**
>   * Macro to safely create swapfile size in block numbers.
>   * Includes safety checks to handle potential errors.
>   */
>  #define SAFE_MAKE_SWAPFILE_BLKS(swapfile, blocks) \
> -    make_swapfile(swapfile, blocks, 1, SWAPFILE_BY_BLKS)
> +    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 313a15f24..b4233be0d 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -133,7 +133,7 @@ out:
>         return contiguous;
>  }
>
> -int make_swapfile_(const char *file, const int lineno,
> +int make_swapfile(const char *file, const int lineno,
>                         const char *swapfile, unsigned int num,
>                         int safe, enum swapfile_method method)
>  {
> --
> 2.43.0
>
>

-- 
Regards,
Li Wang

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res()
  2024-04-17 12:31 ` [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res() Petr Vorel
@ 2024-04-18  5:32   ` Li Wang
  2024-04-18 11:24   ` Cyril Hrubis
  1 sibling, 0 replies; 7+ messages in thread
From: Li Wang @ 2024-04-18  5:32 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Wed, Apr 17, 2024 at 8:31 PM Petr Vorel <pvorel@suse.cz> wrote:

> That allows to identify the caller of the function. That is the reason
> why tst_brk_() was already used instead of tst_brk().
>
> Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
>

Reviewed-by: Li Wang <liwang@redhat.com>

---
>  libs/libltpswap/libswap.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index b4233be0d..aed76dfe2 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -149,18 +149,18 @@ int make_swapfile(const char *file, const int lineno,
>         blk_size = fs_info.f_bsize;
>
>         if (method == SWAPFILE_BY_SIZE) {
> -               tst_res(TINFO, "create a swapfile size of %u megabytes
> (MB)", num);
> +               tst_res_(file, lineno, TINFO, "create a swapfile size of
> %u megabytes (MB)", num);
>                 blocks = num * 1024 * 1024 / blk_size;
>         } else if (method == SWAPFILE_BY_BLKS) {
>                 blocks = num;
> -               tst_res(TINFO, "create a swapfile with %u block numbers",
> blocks);
> +               tst_res_(file, lineno, TINFO, "create a swapfile with %u
> block numbers", blocks);
>         } else {
>                 tst_brk_(file, lineno, TBROK, "Invalid method, please see
> include/libswap.h");
>         }
>
>         /* To guarantee at least one page can be swapped out */
>         if (blk_size * blocks < pg_size) {
> -               tst_res(TWARN, "Swapfile size is less than the system page
> size. "
> +               tst_res_(file, lineno, 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;
> --
> 2.43.0
>
>

-- 
Regards,
Li Wang

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH 1/2] libswap: Move file & line macros to macros
  2024-04-17 12:31 [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Petr Vorel
  2024-04-17 12:31 ` [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res() Petr Vorel
  2024-04-18  5:32 ` [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Li Wang
@ 2024-04-18 11:23 ` Cyril Hrubis
  2 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2024-04-18 11:23 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res()
  2024-04-17 12:31 ` [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res() Petr Vorel
  2024-04-18  5:32   ` Li Wang
@ 2024-04-18 11:24   ` Cyril Hrubis
  2024-04-18 11:43     ` Petr Vorel
  1 sibling, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2024-04-18 11:24 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
Reviewed-by; Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res()
  2024-04-18 11:24   ` Cyril Hrubis
@ 2024-04-18 11:43     ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2024-04-18 11:43 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Li, Cyril,

thanks, patchset merged!

I'll send fix for too low block size on 64K shortly.

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-18 11:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 12:31 [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Petr Vorel
2024-04-17 12:31 ` [LTP] [PATCH 2/2] libswap: Use tst_res_() instead of tst_res() Petr Vorel
2024-04-18  5:32   ` Li Wang
2024-04-18 11:24   ` Cyril Hrubis
2024-04-18 11:43     ` Petr Vorel
2024-04-18  5:32 ` [LTP] [PATCH 1/2] libswap: Move file & line macros to macros Li Wang
2024-04-18 11:23 ` Cyril Hrubis

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.