public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Tarun Sahu <tsahu@linux.ibm.com>
Cc: sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com,
	geetika@linux.ibm.com, vaibhav@linux.ibm.com, ltp@lists.linux.it,
	mike.kravetz@oracle.com
Subject: Re: [LTP] [PATCH v5 4/7] Hugetlb: Safe macro for posix_fadvise call
Date: Thu, 24 Nov 2022 12:59:32 +0100	[thread overview]
Message-ID: <Y39cpPahJWYvQ4cT@yuki> (raw)
In-Reply-To: <20221120191533.164848-5-tsahu@linux.ibm.com>

Hi!
>  include/tst_safe_macros.h | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
> index 81c4b0844..4965e44d0 100644
> --- a/include/tst_safe_macros.h
> +++ b/include/tst_safe_macros.h
> @@ -298,6 +298,23 @@ static inline int safe_ftruncate(const char *file, const int lineno,
>  #define SAFE_FTRUNCATE(fd, length) \
>  	safe_ftruncate(__FILE__, __LINE__, (fd), (length))
>  
> +static inline int safe_posix_fadvise(const char *file, const int lineno,
> +                                int fd, off_t offset, off_t len, int advice)
> +{
> +	int rval;
> +
> +	rval = posix_fadvise(fd, offset, len, advice);
> +
> +	if (rval)
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"posix_fadvise(%d,%ld,%ld,%d) failed",
> +			fd, (long)offset, (long)len, advice);

I did a closer look at the posix_fadvise() manual and it returns an
error in case of a failure, so the TERRNO is wrong here since that
would print whatever was the last error stored in there.

So we either have to do errno = rval; in the if (rval) branch or use
tst_strerrno() to print the errno ourselves.

Looking at the code we have the safe_pthread.c does use tst_strerrno()
to print the error, so I would be inclined to do so here as well.

Also LKML coding style prefers curly braces around multiline blocks, so
I would enclose the multiline tst_brk_() into curly braces, but that is
very minor.

> +	return rval;
> +}
> +#define SAFE_POSIX_FADVISE(fd, offset, len, advice) \
> +	safe_posix_fadvise(__FILE__, __LINE__, (fd), (offset), (len), (advice))
> +
>  static inline int safe_truncate(const char *file, const int lineno,
>                                  const char *path, off_t length)
>  {
> -- 
> 2.31.1
> 

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2022-11-24 11:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-20 19:15 [LTP] [PATCH v5 0/7][PART 2] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 1/7] Hugetlb: Add new argument flags in tst_creat_unlinked Tarun Sahu
2022-11-24 11:55   ` Cyril Hrubis
2022-11-20 19:15 ` [LTP] [PATCH v5 2/7] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 3/7] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 4/7] Hugetlb: Safe macro for posix_fadvise call Tarun Sahu
2022-11-24 11:59   ` Cyril Hrubis [this message]
2022-11-25 17:34     ` Tarun Sahu
2022-11-25 18:59       ` Cyril Hrubis
2022-11-20 19:15 ` [LTP] [PATCH v5 5/7] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 6/7] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
2022-11-24 14:51   ` Cyril Hrubis
2022-11-20 19:15 ` [LTP] [PATCH v5 7/7] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu
2022-11-25 22:37 ` [LTP] [PATCH v6 1/2] Hugetlb: Safe macro for posix_fadvise call Tarun Sahu
2022-11-25 22:37   ` [LTP] [PATCH v6 2/2] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-11-29 16:21   ` [LTP] [PATCH v6 1/2] Hugetlb: Safe macro for posix_fadvise call Cyril Hrubis
2022-12-01  8:35     ` Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 0/8][PART 3] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 1/8] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 2/8] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 3/8] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 4/8] Hugetlb: Migrating libhugetlbfs icache-hygiene Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 5/8] Hugetlb: Migrating libhugetlbfs madvise_reserve Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 6/8] Hugetlb: Migrating libhugetlbfs map_high_truncate_2 Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 7/8] Hugetlb: Migrating libhugetlbfs misalign Tarun Sahu
2022-12-01 12:02   ` [LTP] [PATCH 8/8] Hugetlb: Migrating libhugetlbfs misaligned_offset Tarun Sahu

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=Y39cpPahJWYvQ4cT@yuki \
    --to=chrubis@suse.cz \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=geetika@linux.ibm.com \
    --cc=ltp@lists.linux.it \
    --cc=mike.kravetz@oracle.com \
    --cc=sbhat@linux.ibm.com \
    --cc=tsahu@linux.ibm.com \
    --cc=vaibhav@linux.ibm.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