This patch adds an ioctl to give a per-file priority hint to attach
REQ_PRIO.

Signed-off-by: Jaegeuk Kim <jaeg...@kernel.org>
---
 fs/f2fs/data.c            |  6 ++++++
 fs/f2fs/f2fs.h            |  1 +
 fs/f2fs/file.c            | 20 ++++++++++++++++++++
 include/uapi/linux/f2fs.h |  7 +++++++
 4 files changed, 34 insertions(+)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 07b46b444d31..24c5cb1f5ada 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -413,6 +413,7 @@ int f2fs_target_device_index(struct f2fs_sb_info *sbi, 
block_t blkaddr)
 static blk_opf_t f2fs_io_flags(struct f2fs_io_info *fio)
 {
        unsigned int temp_mask = GENMASK(NR_TEMP_TYPE - 1, 0);
+       struct folio *fio_folio = page_folio(fio->page);
        unsigned int fua_flag, meta_flag, io_flag;
        blk_opf_t op_flags = 0;
 
@@ -438,6 +439,11 @@ static blk_opf_t f2fs_io_flags(struct f2fs_io_info *fio)
                op_flags |= REQ_META;
        if (BIT(fio->temp) & fua_flag)
                op_flags |= REQ_FUA;
+
+       if (fio->type == DATA &&
+           F2FS_I(fio_folio->mapping->host)->ioprio_hint == F2FS_IOPRIO_WRITE)
+               op_flags |= REQ_PRIO;
+
        return op_flags;
 }
 
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 493dda2d4b66..395f9d37449c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -830,6 +830,7 @@ struct f2fs_inode_info {
 
        /* Use below internally in f2fs*/
        unsigned long flags[BITS_TO_LONGS(FI_MAX)];     /* use to pass per-file 
flags */
+       unsigned int ioprio_hint;       /* hint for IO priority */
        struct f2fs_rwsem i_sem;        /* protect fi info */
        atomic_t dirty_pages;           /* # of dirty pages */
        f2fs_hash_t chash;              /* hash value of given file name */
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index f92a9fba9991..a92c347841e6 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3446,6 +3446,23 @@ static int f2fs_ioc_get_dev_alias_file(struct file 
*filp, unsigned long arg)
                        (u32 __user *)arg);
 }
 
+static int f2fs_ioc_io_prio(struct file *filp, unsigned long arg)
+{
+       struct inode *inode = file_inode(filp);
+       __u32 level;
+
+       if (get_user(level, (__u32 __user *)arg))
+               return -EFAULT;
+
+       if (!S_ISREG(inode->i_mode) || level >= F2FS_IOPRIO_MAX)
+               return -EINVAL;
+
+       inode_lock(inode);
+       F2FS_I(inode)->ioprio_hint = level;
+       inode_unlock(inode);
+       return 0;
+}
+
 int f2fs_precache_extents(struct inode *inode)
 {
        struct f2fs_inode_info *fi = F2FS_I(inode);
@@ -4547,6 +4564,8 @@ static long __f2fs_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
                return f2fs_ioc_compress_file(filp);
        case F2FS_IOC_GET_DEV_ALIAS_FILE:
                return f2fs_ioc_get_dev_alias_file(filp, arg);
+       case F2FS_IOC_IO_PRIO:
+               return f2fs_ioc_io_prio(filp, arg);
        default:
                return -ENOTTY;
        }
@@ -5261,6 +5280,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
        case F2FS_IOC_DECOMPRESS_FILE:
        case F2FS_IOC_COMPRESS_FILE:
        case F2FS_IOC_GET_DEV_ALIAS_FILE:
+       case F2FS_IOC_IO_PRIO:
                break;
        default:
                return -ENOIOCTLCMD;
diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h
index f7aaf8d23e20..795e26258355 100644
--- a/include/uapi/linux/f2fs.h
+++ b/include/uapi/linux/f2fs.h
@@ -44,6 +44,7 @@
 #define F2FS_IOC_COMPRESS_FILE         _IO(F2FS_IOCTL_MAGIC, 24)
 #define F2FS_IOC_START_ATOMIC_REPLACE  _IO(F2FS_IOCTL_MAGIC, 25)
 #define F2FS_IOC_GET_DEV_ALIAS_FILE    _IOR(F2FS_IOCTL_MAGIC, 26, __u32)
+#define F2FS_IOC_IO_PRIO               _IOW(F2FS_IOCTL_MAGIC, 27, __u32)
 
 /*
  * should be same as XFS_IOC_GOINGDOWN.
@@ -63,6 +64,12 @@
 #define F2FS_TRIM_FILE_ZEROOUT         0x2     /* zero out */
 #define F2FS_TRIM_FILE_MASK            0x3
 
+/* for F2FS_IOC_IO_PRIO */
+enum {
+       F2FS_IOPRIO_WRITE = 1,  /* high write priority */
+       F2FS_IOPRIO_MAX,
+};
+
 struct f2fs_gc_range {
        __u32 sync;
        __u64 start;
-- 
2.48.1.601.g30ceb7b040-goog



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

Reply via email to