[LTP] [PATCH 6/8] lapi: add safe *xattrat macros
Andrea Cervesato
andrea.cervesato@suse.de
Mon Jan 27 15:08:24 CET 2025
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 | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/include/lapi/xattr.h b/include/lapi/xattr.h
index b30b24ac0dce04ee225a7609e92fb7af8b545283..8bf8a5de2c25e9ed8727b78ec0488779f4b65403 100644
--- a/include/lapi/xattr.h
+++ b/include/lapi/xattr.h
@@ -7,6 +7,8 @@
#define LAPI_XATTR_H__
#include <stdint.h>
+#include <stddef.h>
+#include "lapi/syscalls.h"
#ifndef STRUCT_XATTR_ARGS
struct xattr_args {
@@ -16,4 +18,100 @@ struct xattr_args {
};
#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 = tst_syscall(__NR_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 = tst_syscall(__NR_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 = tst_syscall(__NR_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.43.0
More information about the ltp
mailing list