Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit f047d1b

Browse files
nmtadamKujouYuko
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 <[email protected]> Reviewed-by: Jeff Moyer <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]> (cherry picked from commit d9a08a9e616beeccdbd0e7262b7225ffdfa49e92) Signed-off-by: alk3pInjection <[email protected]>
1 parent 33f9faf commit f047d1b

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>
@@ -539,6 +541,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
539541
cmd->iocb.ki_filp = file;
540542
cmd->iocb.ki_complete = lo_rw_aio_complete;
541543
cmd->iocb.ki_flags = IOCB_DIRECT;
544+
cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
542545

543546
if (rw == WRITE)
544547
ret = call_write_iter(file, &cmd->iocb, &iter);

fs/aio.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,22 @@ static int aio_prep_rw(struct kiocb *req, struct iocb *iocb)
14711471
if (iocb->aio_flags & IOCB_FLAG_RESFD)
14721472
req->ki_flags |= IOCB_EVENTFD;
14731473
req->ki_hint = ki_hint_validate(file_write_hint(req->ki_filp));
1474+
if (iocb->aio_flags & IOCB_FLAG_IOPRIO) {
1475+
/*
1476+
* If the IOCB_FLAG_IOPRIO flag of aio_flags is set, then
1477+
* aio_reqprio is interpreted as an I/O scheduling
1478+
* class and priority.
1479+
*/
1480+
ret = ioprio_check_cap(iocb->aio_reqprio);
1481+
if (ret) {
1482+
pr_debug("aio ioprio check cap error\n");
1483+
return -EINVAL;
1484+
}
1485+
1486+
req->ki_ioprio = iocb->aio_reqprio;
1487+
} else
1488+
req->ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
1489+
14741490
ret = kiocb_set_rw_flags(req, iocb->aio_rw_flags);
14751491
if (unlikely(ret))
14761492
fput(req->ki_filp);

include/linux/fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/delayed_call.h>
3636
#include <linux/uuid.h>
3737
#include <linux/errseq.h>
38+
#include <linux/ioprio.h>
3839

3940
#include <asm/byteorder.h>
4041
#include <uapi/linux/fs.h>
@@ -306,6 +307,7 @@ struct kiocb {
306307
void *private;
307308
int ki_flags;
308309
u16 ki_hint;
310+
u16 ki_ioprio; /* See linux/ioprio.h */
309311
} __randomize_layout;
310312

311313
static inline bool is_sync_kiocb(struct kiocb *kiocb)
@@ -1982,6 +1984,7 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
19821984
.ki_filp = filp,
19831985
.ki_flags = iocb_flags(filp),
19841986
.ki_hint = ki_hint_validate(file_write_hint(filp)),
1987+
.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0),
19851988
};
19861989
}
19871990

include/uapi/linux/aio_abi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum {
5454
* is valid.
5555
*/
5656
#define IOCB_FLAG_RESFD (1 << 0)
57+
#define IOCB_FLAG_IOPRIO (1 << 1)
5758

5859
/* read() from /dev/aio returns these structures. */
5960
struct io_event {

0 commit comments

Comments
 (0)