io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ammar Faizi <ammar.faizi@students.amikom.ac.id>
To: Jens Axboe <axboe@kernel.dk>, Pavel Begunkov <asml.silence@gmail.com>
Cc: io-uring Mailing List <io-uring@vger.kernel.org>,
	Louvian Lyndal <louvianlyndal@gmail.com>,
	Ammar Faizi <ammarfaizi2@gmail.com>,
	Ammar Faizi <ammar.faizi@students.amikom.ac.id>
Subject: [PATCHSET v1 RFC liburing 5/6] Add `liburing_getrlimit()` and `liburing_setrlimit()`
Date: Wed, 29 Sep 2021 17:16:05 +0700	[thread overview]
Message-ID: <20210929101606.62822-6-ammar.faizi@students.amikom.ac.id> (raw)
In-Reply-To: <20210929101606.62822-1-ammar.faizi@students.amikom.ac.id>

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@students.amikom.ac.id>
---
 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


  parent reply	other threads:[~2021-09-29 10:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 10:16 [PATCHSET v1 RFC liburing 0/6] Implement the kernel style return value Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 1/6] src/syscall: " Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 2/6] Add kernel error header `src/kernel_err.h` Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 3/6] Add `liburing_mmap()` and `liburing_munmap()` Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 4/6] Add `liburing_madvise()` Ammar Faizi
2021-09-29 10:16 ` Ammar Faizi [this message]
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 6/6] src/{queue,register,setup}: Remove `#include <errno.h>` Ammar Faizi
2021-09-29 10:21 ` [PATCHSET v1 RFC liburing 0/6] Implement the kernel style return value Ammar Faizi
2021-10-01  6:44   ` Louvian Lyndal
2021-10-01  7:36     ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210929101606.62822-6-ammar.faizi@students.amikom.ac.id \
    --to=ammar.faizi@students.amikom.ac.id \
    --cc=ammarfaizi2@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=louvianlyndal@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).