From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] f2fs_io: support get_advise command
Date: Thu, 7 Mar 2024 14:29:13 +0800 [thread overview]
Message-ID: <20240307062913.3259249-1-chao@kernel.org> (raw)
Support get_advise command to get i_advise field value and info
in file.
For example:
f2fs_io get_advise /mnt/f2fs/foo.so
i_advise=0x11, advise_type: cold keep_size
Signed-off-by: Chao Yu <chao@kernel.org>
---
man/f2fs_io.8 | 3 +++
tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++++++++++++++++++++++
tools/f2fs_io/f2fs_io.h | 6 ++++++
3 files changed, 50 insertions(+)
diff --git a/man/f2fs_io.8 b/man/f2fs_io.8
index ecaab02..f097bde 100644
--- a/man/f2fs_io.8
+++ b/man/f2fs_io.8
@@ -171,6 +171,9 @@ Move a range of data blocks from source file to destination file
.TP
\fBgc_range\fR \fI[sync_mode] [start in 4kb] [length in 4kb] [file]\fR
Trigger gc to move data blocks from specified address range
+.TP
+\fBget_advise\fR \fI[file]\fR
+Get i_advise value and info in file
.SH AUTHOR
This version of
.B f2fs_io
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 7059cbf..b8e4f02 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1743,6 +1743,46 @@ static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define get_advise_desc "get_advise"
+#define get_advise_help "f2fs_io get_advise [file_path]\n\n"
+
+static void do_get_advise(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ int ret;
+ unsigned char value;
+
+ if (argc != 2) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ ret = getxattr(argv[1], F2FS_SYSTEM_ADVISE_NAME, &value, sizeof(value));
+ if (ret != sizeof(value)) {
+ perror("getxattr");
+ exit(1);
+ }
+
+ printf("i_advise=0x%x, advise_type: ", value);
+ if (value & FADVISE_COLD_BIT)
+ printf("cold ");
+ if (value & FADVISE_LOST_PINO_BIT)
+ printf("lost_pino ");
+ if (value & FADVISE_ENCRYPT_BIT)
+ printf("encrypt ");
+ if (value & FADVISE_ENC_NAME_BIT)
+ printf("enc_name ");
+ if (value & FADVISE_KEEP_SIZE_BIT)
+ printf("keep_size ");
+ if (value & FADVISE_HOT_BIT)
+ printf("hot ");
+ if (value & FADVISE_VERITY_BIT)
+ printf("verity ");
+ if (value & FADVISE_TRUNC_BIT)
+ printf("trunc ");
+ printf("\n");
+}
+
#define CMD_HIDDEN 0x0001
#define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
#define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -1786,6 +1826,7 @@ const struct cmd_desc cmd_list[] = {
CMD(setxattr),
CMD(removexattr),
CMD(lseek),
+ CMD(get_advise),
{ NULL, NULL, NULL, NULL, 0 }
};
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index d2641cb..b5c82f5 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -169,7 +169,13 @@ struct fscrypt_get_policy_ex_arg {
#define F2FS_SYSTEM_ADVISE_NAME "system.advise"
#define FADVISE_COLD_BIT 0x01
+#define FADVISE_LOST_PINO_BIT 0x02
+#define FADVISE_ENCRYPT_BIT 0x04
+#define FADVISE_ENC_NAME_BIT 0x08
+#define FADVISE_KEEP_SIZE_BIT 0x10
#define FADVISE_HOT_BIT 0x20
+#define FADVISE_VERITY_BIT 0x40
+#define FADVISE_TRUNC_BIT 0x80
#ifndef FS_IMMUTABLE_FL
#define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
--
2.40.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
reply other threads:[~2024-03-07 6:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240307062913.3259249-1-chao@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.