Skip to content

Commit d9a08a9

Browse files
nmtadamAl Viro
authored andcommitted
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. Signed-off-by: Adam Manzanares <adam.manzanares@wdc.com> Reviewed-by: Jeff Moyer <jmoyer@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent fc28724 commit d9a08a9

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

drivers/block/loop.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
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,
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,22 @@ static int aio_prep_rw(struct kiocb *req, struct iocb *iocb)
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
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 {
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)
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum {
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 {

0 commit comments

Comments
 (0)