[PATCHSET v1 RFC liburing 5/6] Add `liburing_getrlimit()` and `liburing_setrlimit()`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Do not use `getrlimit()` and `mumap()` directly from the libc in the
liburing internal sources. Wrap them in `src/syscall.c`. This is the
part of implementing the kernel style return value (which later is
supposed to support no libc environment).

`liburing_getrlimit()` and `liburing_setrlimit()` do the same thing
with `getrlimit()` and `setrlimit()` from the libc. The only different
is when error happens, the return value is of `liburing_{get,set}rlimit()`
will be a negative error code.

Signed-off-by: Ammar Faizi <ammar.faizi@xxxxxxxxxxxxxxxxxxxxx>
---
 src/register.c |  4 ++--
 src/syscall.c  | 16 ++++++++++++++++
 src/syscall.h  |  4 ++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/register.c b/src/register.c
index 944852e..0908e3e 100644
--- a/src/register.c
+++ b/src/register.c
@@ -107,11 +107,11 @@ static int increase_rlimit_nofile(unsigned nr)
 {
 	struct rlimit rlim;
 
-	if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
+	if (liburing_getrlimit(RLIMIT_NOFILE, &rlim) < 0)
 		return -errno;
 	if (rlim.rlim_cur < nr) {
 		rlim.rlim_cur += nr;
-		setrlimit(RLIMIT_NOFILE, &rlim);
+		liburing_setrlimit(RLIMIT_NOFILE, &rlim);
 	}
 
 	return 0;
diff --git a/src/syscall.c b/src/syscall.c
index 44861f6..b8e7cb3 100644
--- a/src/syscall.c
+++ b/src/syscall.c
@@ -141,3 +141,19 @@ int liburing_madvise(void *addr, size_t length, int advice)
 	ret = madvise(addr, length, advice);
 	return (ret < 0) ? -errno : ret;
 }
+
+int liburing_getrlimit(int resource, struct rlimit *rlim)
+{
+	int ret;
+
+	ret = getrlimit(resource, rlim);
+	return (ret < 0) ? -errno : ret;
+}
+
+int liburing_setrlimit(int resource, const struct rlimit *rlim)
+{
+	int ret;
+
+	ret = setrlimit(resource, rlim);
+	return (ret < 0) ? -errno : ret;
+}
diff --git a/src/syscall.h b/src/syscall.h
index 32381ce..1ac56f9 100644
--- a/src/syscall.h
+++ b/src/syscall.h
@@ -3,6 +3,8 @@
 #define LIBURING_SYSCALL_H
 
 #include <signal.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include "kernel_err.h"
 
 struct io_uring_params;
@@ -30,5 +32,7 @@ void *liburing_mmap(void *addr, size_t length, int prot, int flags, int fd,
 		    off_t offset);
 int liburing_munmap(void *addr, size_t length);
 int liburing_madvise(void *addr, size_t length, int advice);
+int liburing_getrlimit(int resource, struct rlimit *rlim);
+int liburing_setrlimit(int resource, const struct rlimit *rlim);
 
 #endif
-- 
2.30.2




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux