UPSTREAM: io_uring: io_kiocb_update_pos() should not touch file for non -1 offset
commit 6f83ab22adcb77a5824d2c274dace0d99e21319f upstream.
-1 tells use to use the current position, but we check if the file is
a stream regardless of that. Fix up io_kiocb_update_pos() to only
dip into file if we need to. This is both more efficient and also drops
12 bytes of text on aarch64 and 64 bytes on x86-64.
Fixes: b4aec4001595 ("io_uring: do not recalculate ppos unnecessarily")
Change-Id: I5c22ce8122b0e1f0ad423a5b3aa520ee416feff1
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 268174392
(cherry picked from commit 89a77271d2
)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:

committed by
Treehugger Robot

parent
0c50a117bf
commit
403642c036
@@ -3021,19 +3021,18 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
|
|||||||
static inline loff_t *io_kiocb_update_pos(struct io_kiocb *req)
|
static inline loff_t *io_kiocb_update_pos(struct io_kiocb *req)
|
||||||
{
|
{
|
||||||
struct kiocb *kiocb = &req->rw.kiocb;
|
struct kiocb *kiocb = &req->rw.kiocb;
|
||||||
bool is_stream = req->file->f_mode & FMODE_STREAM;
|
|
||||||
|
|
||||||
if (kiocb->ki_pos == -1) {
|
if (kiocb->ki_pos != -1)
|
||||||
if (!is_stream) {
|
return &kiocb->ki_pos;
|
||||||
|
|
||||||
|
if (!(req->file->f_mode & FMODE_STREAM)) {
|
||||||
req->flags |= REQ_F_CUR_POS;
|
req->flags |= REQ_F_CUR_POS;
|
||||||
kiocb->ki_pos = req->file->f_pos;
|
kiocb->ki_pos = req->file->f_pos;
|
||||||
return &kiocb->ki_pos;
|
return &kiocb->ki_pos;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
kiocb->ki_pos = 0;
|
kiocb->ki_pos = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
|
||||||
return is_stream ? NULL : &kiocb->ki_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kiocb_done(struct kiocb *kiocb, ssize_t ret,
|
static void kiocb_done(struct kiocb *kiocb, ssize_t ret,
|
||||||
|
Reference in New Issue
Block a user