linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: <jaegeuk@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] f2fs_io: support compress blocks ioctls
Date: Fri, 6 Mar 2020 14:38:25 +0800	[thread overview]
Message-ID: <20200306063825.22643-1-yuchao0@huawei.com> (raw)

Adds to support below three commands to operate reserved blocks
in compressed inode.
- get_cblocks
- release_cblocks
- reserve_cblocks

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 tools/f2fs_io/f2fs_io.c | 78 +++++++++++++++++++++++++++++++++++++++++
 tools/f2fs_io/f2fs_io.h |  6 ++++
 2 files changed, 84 insertions(+)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 68e27ed..c1edef1 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -697,6 +697,81 @@ static void do_copy(int argc, char **argv, const struct cmd_desc *cmd)
 	close(dst_fd);
 }
 
+#define get_cblocks_desc "get number of reserved blocks on compress inode"
+#define get_cblocks_help "f2fs_io get_cblocks [file]\n\n"
+
+static void do_get_cblocks(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	unsigned long long blkcnt;
+	int ret, fd;
+
+	if (argc != 2) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	fd = xopen(argv[1], O_RDONLY, 0);
+
+	ret = ioctl(fd, F2FS_IOC_GET_COMPRESS_BLOCKS, &blkcnt);
+	if (ret < 0)
+		die_errno("F2FS_IOC_GET_COMPRESS_BLOCKS failed");
+
+	printf("%llu\n", blkcnt);
+
+	exit(0);
+}
+
+#define release_cblocks_desc "release reserved blocks on compress inode"
+#define release_cblocks_help "f2fs_io release_cblocks [file]\n\n"
+
+static void do_release_cblocks(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	unsigned long long blkcnt;
+	int ret, fd;
+
+	if (argc != 2) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	fd = xopen(argv[1], O_RDONLY, 0);
+
+	ret = ioctl(fd, F2FS_IOC_RELEASE_COMPRESS_BLOCKS, &blkcnt);
+	if (ret < 0)
+		die_errno("F2FS_IOC_RELEASE_COMPRESS_BLOCKS failed");
+
+	printf("%llu\n", blkcnt);
+
+	exit(0);
+}
+
+#define reserve_cblocks_desc "reserve blocks on compress inode"
+#define reserve_cblocks_help "f2fs_io reserve_cblocks [file]\n\n"
+
+static void do_reserve_cblocks(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	unsigned long long blkcnt;
+	int ret, fd;
+
+	if (argc != 2) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	fd = xopen(argv[1], O_RDONLY, 0);
+
+	ret = ioctl(fd, F2FS_IOC_RESERVE_COMPRESS_BLOCKS, &blkcnt);
+	if (ret < 0)
+		die_errno("F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed");
+
+	printf("%llu\n", blkcnt);
+
+	exit(0);
+}
+
 
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
@@ -717,6 +792,9 @@ const struct cmd_desc cmd_list[] = {
 	CMD(gc_urgent),
 	CMD(defrag_file),
 	CMD(copy),
+	CMD(get_cblocks),
+	CMD(release_cblocks),
+	CMD(reserve_cblocks),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index 3b2892c..c6ea7ff 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -68,6 +68,12 @@ typedef u32	__be32;
 #define F2FS_IOC_SET_PIN_FILE		_IOW(F2FS_IOCTL_MAGIC, 13, __u32)
 #define F2FS_IOC_GET_PIN_FILE		_IOR(F2FS_IOCTL_MAGIC, 14, __u32)
 #define F2FS_IOC_PRECACHE_EXTENTS	_IO(F2FS_IOCTL_MAGIC, 15)
+#define F2FS_IOC_RESIZE_FS		_IOW(F2FS_IOCTL_MAGIC, 16, __u64)
+#define F2FS_IOC_GET_COMPRESS_BLOCKS	_IOR(F2FS_IOCTL_MAGIC, 17, __u64)
+#define F2FS_IOC_RELEASE_COMPRESS_BLOCKS				\
+					_IOR(F2FS_IOCTL_MAGIC, 18, __u64)
+#define F2FS_IOC_RESERVE_COMPRESS_BLOCKS				\
+					_IOR(F2FS_IOCTL_MAGIC, 19, __u64)
 
 #define F2FS_IOC_SET_ENCRYPTION_POLICY	FS_IOC_SET_ENCRYPTION_POLICY
 #define F2FS_IOC_GET_ENCRYPTION_POLICY	FS_IOC_GET_ENCRYPTION_POLICY
-- 
2.18.0.rc1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

                 reply	other threads:[~2020-03-06  6:38 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=20200306063825.22643-1-yuchao0@huawei.com \
    --to=yuchao0@huawei.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).