Comments (9)
Here's the updated commit:
Only difference is that it adds IORING_FEAT_RW_CUR_POS as a feature flag, since this feature is otherwise not that easy to detect.
from liburing.
What if a user does submit 2 seeking readv ops for the same fd once? Just behaves like 2 plain readv in different threads.
from liburing.
Better late than never... Here's the simple patch to do that, you just have to set offset to -1 and it'll use the current file position. This strictly relies on the application doing the right thing, of course. If it submits multiple reads at the same time, then it'll get multiple reads done at the SAME offset, and the end file position will NOT be pos + bytes_read.
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 4ee53ad80110..930be17bece2 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -494,6 +494,7 @@ struct io_kiocb {
#define REQ_F_COMP_LOCKED 32768 /* completion under lock */
#define REQ_F_HARDLINK 65536 /* doesn't sever on completion < 0 */
#define REQ_F_FORCE_ASYNC 131072 /* IOSQE_ASYNC */
+#define REQ_F_CUR_POS 262144 /* read/write uses file position */
u64 user_data;
u32 result;
u32 sequence;
@@ -1710,6 +1711,10 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
req->flags |= REQ_F_ISREG;
kiocb->ki_pos = READ_ONCE(sqe->off);
+ if (kiocb->ki_pos == -1 && !(req->file->f_mode & FMODE_STREAM)) {
+ req->flags |= REQ_F_CUR_POS;
+ kiocb->ki_pos = req->file->f_pos;
+ }
kiocb->ki_flags = iocb_flags(kiocb->ki_filp);
kiocb->ki_hint = ki_hint_validate(file_write_hint(kiocb->ki_filp));
@@ -1781,6 +1786,10 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
static void kiocb_done(struct kiocb *kiocb, ssize_t ret, struct io_kiocb **nxt,
bool in_async)
{
+ struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);
+
+ if (req->flags & REQ_F_CUR_POS)
+ req->file->f_pos = kiocb->ki_pos;
if (in_async && ret >= 0 && kiocb->ki_complete == io_complete_rw)
*nxt = __io_complete_rw(kiocb, ret);
else
from liburing.
I'll add this to the 5.6 mix, no promises yet.
from liburing.
If it submits multiple reads at the same time, then it'll get multiple reads done at the SAME offset, and the end file position will NOT be pos + bytes_read.
What about IOSQE_IO_LINK?
read(fd1, buf, size, -1, IOSQE_IO_LINK);
write(fd2, buf, size, -1, IOSQE_IO_LINK);
read(fd1, buf, size, -1, IOSQE_IO_LINK);
write(fd2, buf, size, -1);
Will it work as expected?
from liburing.
Yes, those are serialized with each other internally, hence that will work as expected. Only concurrent reads or writes will not. If you do:
sqe1 = io_uring_get_sqe(ring);
io_uring_prep_readv(sqe1, fd, &iov, 1, -1);
sqe2 = io_uring_get_sqe(ring);
io_uring_prep_readv(sqe2, fd, &iov, 1, -1);
io_uring_submit(ring);
Then all bets are off, since you don't know if sqe1 or sqe2 is completed first, and they are probably both issued at the same time and will get the same offset assigned. Whichever completes the last will set the file position. But that's the general caveat.
from liburing.
Perfect! It's better to document those feature flag in the man page.
Thanks!
from liburing.
Question 1:
The Linux manual said that the preadv and pwritev are atomic.
So what about the io_uring_prep_writev and io_uring_prep_readv ?
from liburing.
Question 2:
The Linux manual said when opening with O_APPEND
,
Before each write, the file offset is positioned at the end of the file, as if with lseek.
Does this rule applies to io_uring as well, if I passed -1 as the offset?
from liburing.
Related Issues (20)
- SPDX license expressions
- SOCKET_URING_OP_GETSOCKOPT hangs HOT 13
- `io_uring_prep_recv` does not return `0`? HOT 2
- Question: will io_uring block in this scenario in the same way as libaio? HOT 7
- io_uring read multishot fails when trying to read a tty HOT 8
- Is there a way to synchronously wait for a completion of a submitted write for a particular FD HOT 2
- redefinition of 'struct in6_pktinfo' when building on ubi7 with gcc/g++ 9.5.0 HOT 5
- Can we know how many bytes we have read by using io_uring_prep_readv method? HOT 1
- RCU calls made by the NAPI busy poll code generates context switches occupying 50% of the time of the CPU hosting the sqp thread HOT 92
- Per-iovec zero-copy and fixed buffer settings for writev/sendmsg HOT 5
- possible socket leakage with direct file descriptors HOT 21
- Ordering guarantees between accept and close? HOT 11
- SYSCHK(syscall(__NR_io_uring_setup, 10, ¶ms)): Invalid argument HOT 3
- io_uring openat non-existing file, cqe->res returns -2, outside of specification HOT 2
- io_uring_prep_recv with IORING_RECVSEND_BUNDLE always fills only one buffer at a time HOT 13
- io_uring_prep_send_bundle should not have len argument HOT 5
- Wrong number of arguments in io_uring_prep_fixed_fd_install man
- test buf-ring-nommap.t failed with -12 (-ENOMEM) in ppc64le arch.
- Long tail between submit event to complete event exceed 1 second
- SQE timeout with IORING_TIMEOUT_ETIME_SUCCESS set return a CQE with res field equal to -ETIME HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liburing.