Skip to content

Commit 2bb874c

Browse files
author
Al Viro
committed
aio: store event at final iocb_put()
Instead of having aio_complete() set ->ki_res.{res,res2}, do that explicitly in its callers, drop the reference (as aio_complete() used to do) and delay the rest until the final iocb_put(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a9339b7 commit 2bb874c

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

fs/aio.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,25 +1077,17 @@ static inline void iocb_destroy(struct aio_kiocb *iocb)
10771077
kmem_cache_free(kiocb_cachep, iocb);
10781078
}
10791079

1080-
static inline void iocb_put(struct aio_kiocb *iocb)
1081-
{
1082-
if (refcount_dec_and_test(&iocb->ki_refcnt))
1083-
iocb_destroy(iocb);
1084-
}
1085-
10861080
/* aio_complete
10871081
* Called when the io request on the given iocb is complete.
10881082
*/
1089-
static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
1083+
static void aio_complete(struct aio_kiocb *iocb)
10901084
{
10911085
struct kioctx *ctx = iocb->ki_ctx;
10921086
struct aio_ring *ring;
10931087
struct io_event *ev_page, *event;
10941088
unsigned tail, pos, head;
10951089
unsigned long flags;
10961090

1097-
iocb->ki_res.res = res;
1098-
iocb->ki_res.res2 = res2;
10991091
/*
11001092
* Add a completion event to the ring buffer. Must be done holding
11011093
* ctx->completion_lock to prevent other code from messing with the tail
@@ -1161,7 +1153,14 @@ static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
11611153

11621154
if (waitqueue_active(&ctx->wait))
11631155
wake_up(&ctx->wait);
1164-
iocb_put(iocb);
1156+
}
1157+
1158+
static inline void iocb_put(struct aio_kiocb *iocb)
1159+
{
1160+
if (refcount_dec_and_test(&iocb->ki_refcnt)) {
1161+
aio_complete(iocb);
1162+
iocb_destroy(iocb);
1163+
}
11651164
}
11661165

11671166
/* aio_read_events_ring
@@ -1435,7 +1434,9 @@ static void aio_complete_rw(struct kiocb *kiocb, long res, long res2)
14351434
file_end_write(kiocb->ki_filp);
14361435
}
14371436

1438-
aio_complete(iocb, res, res2);
1437+
iocb->ki_res.res = res;
1438+
iocb->ki_res.res2 = res2;
1439+
iocb_put(iocb);
14391440
}
14401441

14411442
static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb)
@@ -1583,11 +1584,10 @@ static ssize_t aio_write(struct kiocb *req, const struct iocb *iocb,
15831584

15841585
static void aio_fsync_work(struct work_struct *work)
15851586
{
1586-
struct fsync_iocb *req = container_of(work, struct fsync_iocb, work);
1587-
int ret;
1587+
struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work);
15881588

1589-
ret = vfs_fsync(req->file, req->datasync);
1590-
aio_complete(container_of(req, struct aio_kiocb, fsync), ret, 0);
1589+
iocb->ki_res.res = vfs_fsync(iocb->fsync.file, iocb->fsync.datasync);
1590+
iocb_put(iocb);
15911591
}
15921592

15931593
static int aio_fsync(struct fsync_iocb *req, const struct iocb *iocb,
@@ -1608,7 +1608,8 @@ static int aio_fsync(struct fsync_iocb *req, const struct iocb *iocb,
16081608

16091609
static inline void aio_poll_complete(struct aio_kiocb *iocb, __poll_t mask)
16101610
{
1611-
aio_complete(iocb, mangle_poll(mask), 0);
1611+
iocb->ki_res.res = mangle_poll(mask);
1612+
iocb_put(iocb);
16121613
}
16131614

16141615
static void aio_poll_complete_work(struct work_struct *work)

0 commit comments

Comments
 (0)