diff mbox series

[f2fs-dev] f2fs_io: override setxattr value for system.advise

Message ID 20240216001711.2492906-1-jaegeuk@kernel.org (mailing list archive)
State New
Headers show
Series [f2fs-dev] f2fs_io: override setxattr value for system.advise | expand

Commit Message

Jaegeuk Kim Feb. 16, 2024, 12:17 a.m. UTC
From: Konstantin Vyshetsky <vkon@google.com>

Adjust behavior to match kernel.

Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 tools/f2fs_io/f2fs_io.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index a5e151d06b10..1df9034acdd9 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1588,10 +1588,13 @@  static void do_listxattr(int argc, char **argv, const struct cmd_desc *cmd)
 
 #define setxattr_desc "setxattr"
 #define setxattr_help "f2fs_io setxattr [name] [value] [file_path]\n\n"
+#define F2FS_SYSTEM_ADVISE_NAME	"system.advise"
 
 static void do_setxattr(int argc, char **argv, const struct cmd_desc *cmd)
 {
 	int ret;
+	char *value;
+	unsigned char tmp;
 
 	if (argc != 4) {
 		fputs("Excess arguments\n\n", stderr);
@@ -1599,11 +1602,18 @@  static void do_setxattr(int argc, char **argv, const struct cmd_desc *cmd)
 		exit(1);
 	}
 
-	ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), XATTR_CREATE);
+	if (!strcmp(argv[1], F2FS_SYSTEM_ADVISE_NAME)) {
+		tmp = strtoul(argv[2], NULL, 0);
+		value = (char *)&tmp;
+	} else {
+		value = argv[2];
+	}
+
+	ret = setxattr(argv[3], argv[1], value, strlen(argv[2]), XATTR_CREATE);
 	printf("setxattr %s CREATE: name: %s, value: %s: ret=%d\n",
 			argv[3], argv[1], argv[2], ret);
 	if (ret < 0 && errno == EEXIST) {
-		ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), XATTR_REPLACE);
+		ret = setxattr(argv[3], argv[1], value, strlen(argv[2]), XATTR_REPLACE);
 		printf("setxattr %s REPLACE: name: %s, value: %s: ret=%d\n",
 				argv[3], argv[1], argv[2], ret);
 	}