Skip to content

Commit 4a18998

Browse files
committed
Merge branch 'work.aio' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull aio iopriority support from Al Viro: "The rest of aio stuff for this cycle - Adam's aio ioprio series" * 'work.aio' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: fs: aio ioprio use ioprio_check_cap ret val fs: aio ioprio add explicit block layer dependence fs: iomap dio set bio prio from kiocb prio fs: blkdev set bio prio from kiocb prio fs: Add aio iopriority support fs: Convert kiocb rw_hint from enum to u16 block: add ioprio_check_cap function
2 parents 4189b86 + 9a6d9a6 commit 4a18998

File tree

8 files changed

+63
-9
lines changed

8 files changed

+63
-9
lines changed

block/ioprio.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,10 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
6161
}
6262
EXPORT_SYMBOL_GPL(set_task_ioprio);
6363

64-
SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
64+
int ioprio_check_cap(int ioprio)
6565
{
6666
int class = IOPRIO_PRIO_CLASS(ioprio);
6767
int data = IOPRIO_PRIO_DATA(ioprio);
68-
struct task_struct *p, *g;
69-
struct user_struct *user;
70-
struct pid *pgrp;
71-
kuid_t uid;
72-
int ret;
7368

7469
switch (class) {
7570
case IOPRIO_CLASS_RT:
@@ -92,6 +87,21 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
9287
return -EINVAL;
9388
}
9489

90+
return 0;
91+
}
92+
93+
SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
94+
{
95+
struct task_struct *p, *g;
96+
struct user_struct *user;
97+
struct pid *pgrp;
98+
kuid_t uid;
99+
int ret;
100+
101+
ret = ioprio_check_cap(ioprio);
102+
if (ret)
103+
return ret;
104+
95105
ret = -ESRCH;
96106
rcu_read_lock();
97107
switch (which) {

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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,23 @@ static int aio_prep_rw(struct kiocb *req, struct iocb *iocb)
14341434
req->ki_flags = iocb_flags(req->ki_filp);
14351435
if (iocb->aio_flags & IOCB_FLAG_RESFD)
14361436
req->ki_flags |= IOCB_EVENTFD;
1437-
req->ki_hint = file_write_hint(req->ki_filp);
1437+
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: %d\n", ret);
1447+
return ret;
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);

fs/block_dev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
216216
bio.bi_write_hint = iocb->ki_hint;
217217
bio.bi_private = current;
218218
bio.bi_end_io = blkdev_bio_end_io_simple;
219+
bio.bi_ioprio = iocb->ki_ioprio;
219220

220221
ret = bio_iov_iter_get_pages(&bio, iter);
221222
if (unlikely(ret))
@@ -355,6 +356,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
355356
bio->bi_write_hint = iocb->ki_hint;
356357
bio->bi_private = dio;
357358
bio->bi_end_io = blkdev_bio_end_io;
359+
bio->bi_ioprio = iocb->ki_ioprio;
358360

359361
ret = bio_iov_iter_get_pages(bio, iter);
360362
if (unlikely(ret)) {

fs/iomap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length,
10461046
bio_set_dev(bio, iomap->bdev);
10471047
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
10481048
bio->bi_write_hint = dio->iocb->ki_hint;
1049+
bio->bi_ioprio = dio->iocb->ki_ioprio;
10491050
bio->bi_private = dio;
10501051
bio->bi_end_io = iomap_dio_bio_end_io;
10511052

include/linux/fs.h

Lines changed: 14 additions & 2 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>
@@ -299,7 +300,8 @@ struct kiocb {
299300
void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
300301
void *private;
301302
int ki_flags;
302-
enum rw_hint ki_hint;
303+
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)
@@ -1934,12 +1936,22 @@ static inline enum rw_hint file_write_hint(struct file *file)
19341936

19351937
static inline int iocb_flags(struct file *file);
19361938

1939+
static inline u16 ki_hint_validate(enum rw_hint hint)
1940+
{
1941+
typeof(((struct kiocb *)0)->ki_hint) max_hint = -1;
1942+
1943+
if (hint <= max_hint)
1944+
return hint;
1945+
return 0;
1946+
}
1947+
19371948
static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
19381949
{
19391950
*kiocb = (struct kiocb) {
19401951
.ki_filp = filp,
19411952
.ki_flags = iocb_flags(filp),
1942-
.ki_hint = file_write_hint(filp),
1953+
.ki_hint = ki_hint_validate(file_write_hint(filp)),
1954+
.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0),
19431955
};
19441956
}
19451957

include/linux/ioprio.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ extern int ioprio_best(unsigned short aprio, unsigned short bprio);
7777

7878
extern int set_task_ioprio(struct task_struct *task, int ioprio);
7979

80+
#ifdef CONFIG_BLOCK
81+
extern int ioprio_check_cap(int ioprio);
82+
#else
83+
static inline int ioprio_check_cap(int ioprio)
84+
{
85+
return -ENOTBLK;
86+
}
87+
#endif /* CONFIG_BLOCK */
88+
8089
#endif

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)