public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 08/10] lapi: add safe *xattrat macros
Date: Tue, 07 Oct 2025 08:47:00 +0200	[thread overview]
Message-ID: <20251007-xattrat-v2-8-bf458fa66358@suse.com> (raw)
In-Reply-To: <20251007-xattrat-v2-0-bf458fa66358@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

Introduce the following new safe macros:

- SAFE_SETXATTRAT
- SAFE_GETXATTRAT
- SAFE_REMOVEXATTRAT

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/lapi/xattr.h | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/include/lapi/xattr.h b/include/lapi/xattr.h
index 2ca05c787..cfd1cca40 100644
--- a/include/lapi/xattr.h
+++ b/include/lapi/xattr.h
@@ -59,4 +59,98 @@ static inline int removexattrat(int dfd, const char *pathname,
 }
 #endif
 
+int safe_setxattrat(const char *file, const int lineno,
+		int dfd, const char *path, int at_flags,
+		const char *key, struct xattr_args *args, size_t size)
+{
+	int rval;
+
+	rval = setxattrat(dfd, path, at_flags, key, args, size);
+
+	if (rval == -1) {
+		if (errno == ENOTSUP) {
+			tst_brk_(file, lineno, TCONF,
+				"no xattr support in fs, mounted without user_xattr option "
+				"or invalid namespace/name format");
+			return rval;
+		}
+
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"setxattrat(%d, %s, %d, %s, %p, %zu) failed",
+			dfd, path, at_flags, key, args, size);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid setxattrat(%d, %s, %d, %s, %p, %zu) return value %d",
+			dfd, path, at_flags, key, args, size, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_SETXATTRAT(dfd, path, at_flags, key, args, size) \
+	safe_setxattrat(__FILE__, __LINE__, \
+		 (dfd), (path), (at_flags), (key), (args), (size))
+
+int safe_getxattrat(const char *file, const int lineno,
+		int dfd, const char *path, int at_flags,
+		const char *key, struct xattr_args *args, size_t size)
+{
+	int rval;
+
+	rval = getxattrat(dfd, path, at_flags, key, args, size);
+
+	if (rval == -1) {
+		if (errno == ENOTSUP) {
+			tst_brk_(file, lineno, TCONF,
+				"no xattr support in fs, mounted without user_xattr option "
+				"or invalid namespace/name format");
+			return rval;
+		}
+
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"getxattrat(%d, %s, %d, %s, %p, %zu) failed",
+			dfd, path, at_flags, key, args, size);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid getxattrat(%d, %s, %d, %s, %p, %zu) return value %d",
+			dfd, path, at_flags, key, args, size, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_GETXATTRAT(dfd, path, at_flags, key, args, size) \
+	safe_getxattrat(__FILE__, __LINE__, \
+		 (dfd), (path), (at_flags), (key), (args), (size))
+
+int safe_removexattrat(const char *file, const int lineno,
+		int dfd, const char *path, int at_flags, const char *name)
+{
+	int rval;
+
+	rval = removexattrat(dfd, path, at_flags, name);
+
+	if (rval == -1) {
+		if (errno == ENOTSUP) {
+			tst_brk_(file, lineno, TCONF,
+				"no xattr support in fs or mounted without user_xattr option");
+			return rval;
+		}
+
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"removexattrat(%d, %s, %d, %s) failed",
+			dfd, path, at_flags, name);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid removexattrat(%d, %s, %d, %s) return value %d",
+			dfd, path, at_flags, name, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_REMOVEXATTRAT(dfd, path, at_flags, name) \
+	safe_removexattrat(__FILE__, __LINE__, \
+		 (dfd), (path), (at_flags), (name))
+
 #endif /* LAPI_XATTR_H__ */

-- 
2.51.0


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

  parent reply	other threads:[~2025-10-07  6:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  6:46 [LTP] [PATCH v2 00/10] setxattrat coverage Andrea Cervesato
2025-10-07  6:46 ` [LTP] [PATCH v2 01/10] lapi: add struct xattr_args fallback Andrea Cervesato
2025-10-07 11:50   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 02/10] lapi: add setxattrat() fallback definition Andrea Cervesato
2025-10-07 12:05   ` Cyril Hrubis
2025-10-07 15:16   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant Andrea Cervesato
2025-10-07 12:29   ` Cyril Hrubis
2025-10-07 13:16     ` Andrea Cervesato via ltp
2025-10-07 14:35       ` Cyril Hrubis
2025-10-08 10:40         ` Andrea Cervesato via ltp
2025-10-08 12:16           ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 04/10] setxattr02: " Andrea Cervesato
2025-10-07 12:40   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 05/10] setxattr03: " Andrea Cervesato
2025-10-07 15:11   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 06/10] lapi: add getxattrat() fallback Andrea Cervesato
2025-10-07 15:21   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 07/10] lapi: add removexattrat() fallback Andrea Cervesato
2025-10-07 15:26   ` Cyril Hrubis
2025-10-07  6:47 ` Andrea Cervesato [this message]
2025-10-08  9:36   ` [LTP] [PATCH v2 08/10] lapi: add safe *xattrat macros Cyril Hrubis
2025-10-07  6:47 ` [LTP] [PATCH v2 09/10] Add setxattrat01 test Andrea Cervesato
2025-10-08  9:44   ` Cyril Hrubis
2025-10-13  7:54     ` Andrea Cervesato via ltp
2025-10-07  6:47 ` [LTP] [PATCH v2 10/10] Add setxattrat02 test Andrea Cervesato
2025-10-08 10:02   ` Cyril Hrubis
2025-10-10 11:05     ` Andrea Cervesato via ltp

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=20251007-xattrat-v2-8-bf458fa66358@suse.com \
    --to=andrea.cervesato@suse.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox