History

fs: Add aio iopriority support

This is the per-I/O equivalent of the ioprio_set system call. When IOCB_FLAG_IOPRIO is set on the iocb aio_flags field, then we set the newly added kiocb ki_ioprio field to the value in the iocb aio_reqprio field. This patch depends on block: add ioprio_check_cap function.

Adam Manzanares committed 8 years ago

Commit d9a08a91 parent fc287244 files · +23 −0Browse files

Unified · Split

4 files
  1. drivers/block/loop.c +3 −0
  2. fs/aio.c +16 −0
  3. include/linux/fs.h +3 −0
  4. include/uapi/linux/aio_abi.h +1 −0
drivers/block/loop.c+3−0
@@ -76,6 +76,8 @@ · 75 unmodified lines
7676 #include <linux/miscdevice.h>
7777 #include <linux/falloc.h>
7878 #include <linux/uio.h>
79+#include <linux/ioprio.h>
80+
7981 #include "loop.h"
8082
8183 #include <linux/uaccess.h>
@@ -559,6 +561,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, · 477 unmodified lines
559561 cmd->iocb.ki_filp = file;
560562 cmd->iocb.ki_complete = lo_rw_aio_complete;
561563 cmd->iocb.ki_flags = IOCB_DIRECT;
564+ cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
562565 if (cmd->css)
563566 kthread_associate_blkcg(cmd->css);
564567
fs/aio.c+16−0
@@ -1435,6 +1435,22 @@ static int aio_prep_rw(struct kiocb *req, struct iocb *iocb) · 1434 unmodified lines
14351435 if (iocb->aio_flags & IOCB_FLAG_RESFD)
14361436 req->ki_flags |= IOCB_EVENTFD;
14371437 req->ki_hint = ki_hint_validate(file_write_hint(req->ki_filp));
1438+ if (iocb->aio_flags & IOCB_FLAG_IOPRIO) {
1439+ /*
1440+ * If the IOCB_FLAG_IOPRIO flag of aio_flags is set, then
1441+ * aio_reqprio is interpreted as an I/O scheduling
1442+ * class and priority.
1443+ */
1444+ ret = ioprio_check_cap(iocb->aio_reqprio);
1445+ if (ret) {
1446+ pr_debug("aio ioprio check cap error\n");
1447+ return -EINVAL;
1448+ }
1449+
1450+ req->ki_ioprio = iocb->aio_reqprio;
1451+ } else
1452+ req->ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
1453+
14381454 ret = kiocb_set_rw_flags(req, iocb->aio_rw_flags);
14391455 if (unlikely(ret))
14401456 fput(req->ki_filp);
include/linux/fs.h+3−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636 #include <linux/delayed_call.h>
3737 #include <linux/uuid.h>
3838 #include <linux/errseq.h>
39+#include <linux/ioprio.h>
3940
4041 #include <asm/byteorder.h>
4142 #include <uapi/linux/fs.h>
@@ -300,6 +301,7 @@ struct kiocb { · 258 unmodified lines
300301 void *private;
301302 int ki_flags;
302303 u16 ki_hint;
304+ u16 ki_ioprio; /* See linux/ioprio.h */
303305 } __randomize_layout;
304306
305307 static inline bool is_sync_kiocb(struct kiocb *kiocb)
@@ -1944,6 +1946,7 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) · 1638 unmodified lines
19441946 .ki_filp = filp,
19451947 .ki_flags = iocb_flags(filp),
19461948 .ki_hint = ki_hint_validate(file_write_hint(filp)),
1949+ .ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0),
19471950 };
19481951 }
19491952
include/uapi/linux/aio_abi.h+1−0
@@ -53,6 +53,7 @@ enum { · 52 unmodified lines
5353 * is valid.
5454 */
5555 #define IOCB_FLAG_RESFD (1 << 0)
56+#define IOCB_FLAG_IOPRIO (1 << 1)
5657
5758 /* read() from /dev/aio returns these structures. */
5859 struct io_event {