diff mbox series

[v6,1/2] Hugetlb: Safe macro for posix_fadvise call

Message ID 20221125223740.80580-1-tsahu@linux.ibm.com
State Accepted
Headers show
Series [v6,1/2] Hugetlb: Safe macro for posix_fadvise call | expand

Commit Message

Tarun Sahu Nov. 25, 2022, 10:37 p.m. UTC
This patch adds SAFE_POSIX_FADVISE for posix_fadvise call.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 include/tst_safe_macros.h | 17 +++++++++++++++++
 include/tst_test.h        | 24 ++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)

Comments

Cyril Hrubis Nov. 29, 2022, 4:21 p.m. UTC | #1
Hi!
I did split this patch into two, one that touches tst_test.h and one
that adds the safe macro and pushed the patchset, thanks.

The cleanest way how to split changes into patchset is that each patch
does one logical change and properly explains why the change is needed
in the commit message too.
Tarun Sahu Dec. 1, 2022, 8:35 a.m. UTC | #2
On Nov 29 2022, Cyril Hrubis wrote:
> Hi!
> I did split this patch into two, one that touches tst_test.h and one
> that adds the safe macro and pushed the patchset, thanks.
> 

> The cleanest way how to split changes into patchset is that each patch
> does one logical change and properly explains why the change is needed
> in the commit message too.
>
Ok. I will keep it in mind..
Thanks.
> -- 
> Cyril Hrubis
> chrubis@suse.cz
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
diff mbox series

Patch

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 81c4b0844..ab00dd14a 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,
+			"posix_fadvise(%d,%ld,%ld,%d) failed: %s",
+			fd, (long)offset, (long)len, advice, tst_strerrno(rval));
+
+	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)
 {
diff --git a/include/tst_test.h b/include/tst_test.h
index a62515bfe..2de9301e5 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -95,6 +95,18 @@  pid_t safe_fork(const char *filename, unsigned int lineno);
 	({int ret = expr;                                           \
 	  ret != 0 ? tst_res(TINFO, #expr " failed"), ret : ret; }) \
 
+/*
+ * Functions to convert ERRNO to its name and SIGNAL to its name.
+ */
+const char *tst_strerrno(int err);
+const char *tst_strsig(int sig);
+/*
+ * Returns string describing status as returned by wait().
+ *
+ * BEWARE: Not thread safe.
+ */
+const char *tst_strstatus(int status);
+
 #include "tst_safe_macros.h"
 #include "tst_safe_file_ops.h"
 #include "tst_safe_net.h"
@@ -333,18 +345,6 @@  void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
  */
 void tst_reinit(void);
 
-/*
- * Functions to convert ERRNO to its name and SIGNAL to its name.
- */
-const char *tst_strerrno(int err);
-const char *tst_strsig(int sig);
-/*
- * Returns string describing status as returned by wait().
- *
- * BEWARE: Not thread safe.
- */
-const char *tst_strstatus(int status);
-
 unsigned int tst_multiply_timeout(unsigned int timeout);
 
 /*