diff options
author | Usama Arif <usama.arif@bytedance.com> | 2022-05-31 22:21:43 +0100 |
---|---|---|
committer | Usama Arif <usama.arif@bytedance.com> | 2022-06-01 11:06:56 +0100 |
commit | 7b7a2014ec5fe1b492ca71f482001bb443575ec6 (patch) | |
tree | cf6b16fa483885cf066b74ea199e9f2cbfc9b5fc | |
parent | 66b727b1fa4b06986c8ac682e0c13a4f9a1e6708 (diff) | |
download | liburing-7b7a2014ec5fe1b492ca71f482001bb443575ec6.tar.gz |
io_uring: add prep functions for current working directory
This is done for unlink, rename, mkdir, symlink and link.
Signed-off-by: Usama Arif <usama.arif@bytedance.com>
-rw-r--r-- | man/io_uring_prep_linkat.3 | 23 | ||||
-rw-r--r-- | man/io_uring_prep_mkdirat.3 | 26 | ||||
-rw-r--r-- | man/io_uring_prep_renameat.3 | 23 | ||||
-rw-r--r-- | man/io_uring_prep_symlinkat.3 | 20 | ||||
-rw-r--r-- | man/io_uring_prep_unlinkat.3 | 21 | ||||
-rw-r--r-- | src/include/liburing.h | 31 | ||||
-rw-r--r-- | test/rename.c | 7 | ||||
-rw-r--r-- | test/unlink.c | 2 |
8 files changed, 135 insertions, 18 deletions
diff --git a/man/io_uring_prep_linkat.3 b/man/io_uring_prep_linkat.3 index 04c3d78..c10dd64 100644 --- a/man/io_uring_prep_linkat.3 +++ b/man/io_uring_prep_linkat.3 @@ -17,6 +17,11 @@ io_uring_prep_linkat \- prepare a linkat request .BI " int " newdirfd "," .BI " const char *" newpath "," .BI " int " flags ");" +.PP +.BI "void io_uring_prep_link(struct io_uring_sqe *" sqe "," +.BI " const char *" oldpath "," +.BI " const char *" newpath "," +.BI " int " flags ");" .fi .SH DESCRIPTION .PP @@ -34,11 +39,24 @@ and the new path pointed to by .I newpath and using the specified flags in .IR flags . - This function prepares an async .BR linkat (2) request. See that man page for details. +The +.BR io_uring_prep_link (3) +function prepares a link request. The submission queue entry +.I sqe +is setup to use the old path pointed to by +.I oldpath +and the new path pointed to by +.IR newpath , +both relative to the current working directory and using the specified flags in +.IR flags . +This function prepares an async +.BR link (2) +request. See that man page for details. + .SH RETURN VALUE None .SH ERRORS @@ -69,4 +87,5 @@ flag passed back from .SH SEE ALSO .BR io_uring_get_sqe (3), .BR io_uring_submit (3), -.BR linkat (2) +.BR linkat (2), +.BR link (2) diff --git a/man/io_uring_prep_mkdirat.3 b/man/io_uring_prep_mkdirat.3 index 6afda65..13ea2c0 100644 --- a/man/io_uring_prep_mkdirat.3 +++ b/man/io_uring_prep_mkdirat.3 @@ -15,24 +15,41 @@ io_uring_prep_mkdirat \- prepare an mkdirat request .BI " int " dirfd "," .BI " const char *" path "," .BI " mode_t " mode ");" +.PP +.BI "void io_uring_prep_mkdir(struct io_uring_sqe *" sqe "," +.BI " const char *" path "," +.BI " mode_t " mode ");" .fi .SH DESCRIPTION .PP The .BR io_uring_prep_mkdirat (3) -function prepares an mkdirat request. The submission queue entry +function prepares a mkdirat request. The submission queue entry .I sqe is setup to use the directory file descriptor pointed to by .I dirfd -to start an mkdirat operation on the path identified by +to start a mkdirat operation on the path identified by .I path with the mode given in .IR mode . - This function prepares an async .BR mkdirat (2) request. See that man page for details. +The +.BR io_uring_prep_mkdir (3) +function prepares a mkdir request. The submission queue entry +.I sqe +is setup to use the current working directory to start a mkdir +operation on the path identified by +.I path +with the mode given in +.IR mode . +This function prepares an async +.BR mkdir (2) +request. See that man page for details. + + .SH RETURN VALUE None .SH ERRORS @@ -63,4 +80,5 @@ flag passed back from .SH SEE ALSO .BR io_uring_get_sqe (3), .BR io_uring_submit (3), -.BR mkdirat (2) +.BR mkdirat (2), +.BR mkdir (2) diff --git a/man/io_uring_prep_renameat.3 b/man/io_uring_prep_renameat.3 index 96bbf88..25608ee 100644 --- a/man/io_uring_prep_renameat.3 +++ b/man/io_uring_prep_renameat.3 @@ -17,6 +17,11 @@ io_uring_prep_renameat \- prepare a renameat request .BI " int " newdirfd "," .BI " const char *" newpath "," .BI " int " flags ");" +.PP +.BI "void io_uring_prep_rename(struct io_uring_sqe *" sqe "," +.BI " const char *" oldpath "," +.BI " const char *" newpath "," +.BI " int " flags ");" .fi .SH DESCRIPTION .PP @@ -34,7 +39,6 @@ and the new path pointed to by .I newpath and using the specified flags in .IR flags . - This function prepares an async .BR renameat2 (2) request. If @@ -43,6 +47,20 @@ is zero, then this call is similar to the .BR renameat (2) system call. See those man page for details. +The +.BR io_uring_prep_rename (3) +function prepares a rename request. The submission queue entry +.I sqe +is setup to use the old path pointed to by +.I oldpath +with the new path pointed to by +.IR newpath , +both relative to the current working directory and using the specified flags in +.IR flags . +This function prepares an async +.BR rename (2) +request See that man page for details. + .SH RETURN VALUE None .SH ERRORS @@ -74,4 +92,5 @@ flag passed back from .BR io_uring_get_sqe (3), .BR io_uring_submit (3), .BR renameat (2), -.BR renameat2 (2) +.BR renameat2 (2), +.BR rename (2) diff --git a/man/io_uring_prep_symlinkat.3 b/man/io_uring_prep_symlinkat.3 index 40a0271..ae40b75 100644 --- a/man/io_uring_prep_symlinkat.3 +++ b/man/io_uring_prep_symlinkat.3 @@ -15,6 +15,10 @@ io_uring_prep_symlinkat \- prepare a symlinkat request .BI " const char *" target "," .BI " int " newdirfd "," .BI " const char *" linkpath ");" +.PP +.BI "void io_uring_prep_symlink(struct io_uring_sqe *" sqe "," +.BI " const char *" target "," +.BI " const char *" linkpath ");" .fi .SH DESCRIPTION .PP @@ -28,11 +32,22 @@ to the new destination indicated by .I newdirfd and .IR linkpath . - This function prepares an async .BR symlinkat (2) request. See that man page for details. +The +.BR io_uring_prep_symlink (3) +function prepares a symlink request. The submission queue entry +.I sqe +is setup to symlink the target path pointed to by +.I target +to the new destination indicated by +.I linkpath +relative to the the current working directory. This function prepares an async +.BR symlink (2) +request. See that man page for details. + .SH RETURN VALUE None .SH ERRORS @@ -63,4 +78,5 @@ flag passed back from .SH SEE ALSO .BR io_uring_get_sqe (3), .BR io_uring_submit (3), -.BR symlinkat (2) +.BR symlinkat (2), +.BR symlink (2) diff --git a/man/io_uring_prep_unlinkat.3 b/man/io_uring_prep_unlinkat.3 index dba8fbc..dfd98cb 100644 --- a/man/io_uring_prep_unlinkat.3 +++ b/man/io_uring_prep_unlinkat.3 @@ -15,6 +15,10 @@ io_uring_prep_unlinkat \- prepare an unlinkat request .BI " int " dirfd "," .BI " const char *" path "," .BI " int " flags ");" +.PP +.BI "void io_uring_prep_unlink(struct io_uring_sqe *" sqe "," +.BI " const char *" path "," +.BI " int " flags ");" .fi .SH DESCRIPTION .PP @@ -28,11 +32,23 @@ to start an unlinkat operation on the path identified by .I path and using the flags given in .IR flags . - This function prepares an async .BR unlinkat (2) request. See that man page for details. +The +.BR io_uring_prep_unlink (3) +function prepares an unlink request. The submission queue entry +.I sqe +is setup to start an unlinkat operation on the path identified by +.I path +relative to the current working directory and using the flags given in +.IR flags . +This function prepares an async +.BR unlink (2) +request. See that man page for details. + + .SH RETURN VALUE None .SH ERRORS @@ -63,4 +79,5 @@ flag passed back from .SH SEE ALSO .BR io_uring_get_sqe (3), .BR io_uring_submit (3), -.BR unlinkat (2) +.BR unlinkat (2), +.BR unlink (2) diff --git a/src/include/liburing.h b/src/include/liburing.h index 771e150..6eece30 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -18,6 +18,7 @@ #include <stdbool.h> #include <inttypes.h> #include <time.h> +#include <fcntl.h> #include <sched.h> #include <linux/swab.h> #include "liburing/compat.h" @@ -729,6 +730,12 @@ static inline void io_uring_prep_unlinkat(struct io_uring_sqe *sqe, int dfd, sqe->unlink_flags = (__u32) flags; } +static inline void io_uring_prep_unlink(struct io_uring_sqe *sqe, + const char *path, int flags) +{ + io_uring_prep_unlinkat(sqe, AT_FDCWD, path, flags); +} + static inline void io_uring_prep_renameat(struct io_uring_sqe *sqe, int olddfd, const char *oldpath, int newdfd, const char *newpath, int flags) @@ -739,6 +746,12 @@ static inline void io_uring_prep_renameat(struct io_uring_sqe *sqe, int olddfd, sqe->rename_flags = (__u32) flags; } +static inline void io_uring_prep_rename(struct io_uring_sqe *sqe, + const char *oldpath, const char *newpath) +{ + io_uring_prep_renameat(sqe, AT_FDCWD, oldpath, AT_FDCWD, newpath, 0); +} + static inline void io_uring_prep_sync_file_range(struct io_uring_sqe *sqe, int fd, unsigned len, __u64 offset, int flags) @@ -753,6 +766,12 @@ static inline void io_uring_prep_mkdirat(struct io_uring_sqe *sqe, int dfd, io_uring_prep_rw(IORING_OP_MKDIRAT, sqe, dfd, path, mode, 0); } +static inline void io_uring_prep_mkdir(struct io_uring_sqe *sqe, + const char *path, mode_t mode) +{ + io_uring_prep_mkdirat(sqe, AT_FDCWD, path, mode); +} + static inline void io_uring_prep_symlinkat(struct io_uring_sqe *sqe, const char *target, int newdirfd, const char *linkpath) @@ -761,6 +780,12 @@ static inline void io_uring_prep_symlinkat(struct io_uring_sqe *sqe, (uint64_t) (uintptr_t) linkpath); } +static inline void io_uring_prep_symlink(struct io_uring_sqe *sqe, + const char *target, const char *linkpath) +{ + io_uring_prep_symlinkat(sqe, target, AT_FDCWD, linkpath); +} + static inline void io_uring_prep_linkat(struct io_uring_sqe *sqe, int olddfd, const char *oldpath, int newdfd, const char *newpath, int flags) @@ -770,6 +795,12 @@ static inline void io_uring_prep_linkat(struct io_uring_sqe *sqe, int olddfd, sqe->hardlink_flags = (__u32) flags; } +static inline void io_uring_prep_link(struct io_uring_sqe *sqe, + const char *oldpath, const char *newpath, int flags) +{ + io_uring_prep_linkat(sqe, AT_FDCWD, oldpath, AT_FDCWD, newpath, flags); +} + static inline void io_uring_prep_msg_ring(struct io_uring_sqe *sqe, int fd, unsigned int len, __u64 data, unsigned int flags) diff --git a/test/rename.c b/test/rename.c index 7798d43..67d4e9c 100644 --- a/test/rename.c +++ b/test/rename.c @@ -26,11 +26,8 @@ static int test_rename(struct io_uring *ring, const char *old, const char *new) } memset(sqe, 0, sizeof(*sqe)); - sqe->opcode = IORING_OP_RENAMEAT; - sqe->fd = AT_FDCWD; - sqe->addr2 = (unsigned long) new; - sqe->addr = (unsigned long) old; - sqe->len = AT_FDCWD; + + io_uring_prep_rename(sqe, old, new); ret = io_uring_submit(ring); if (ret <= 0) { diff --git a/test/unlink.c b/test/unlink.c index e4c210b..8e7d2f4 100644 --- a/test/unlink.c +++ b/test/unlink.c @@ -24,7 +24,7 @@ static int test_unlink(struct io_uring *ring, const char *old) fprintf(stderr, "get sqe failed\n"); goto err; } - io_uring_prep_unlinkat(sqe, AT_FDCWD, old, 0); + io_uring_prep_unlink(sqe, old, 0); ret = io_uring_submit(ring); if (ret <= 0) { |