[CRIU] [RFC] criu: Drop prlimit compat layer

Cyrill Gorcunov gorcunov at openvz.org
Sat Apr 2 12:21:06 PDT 2016


Previously when we've been on early stage we
tried to workaround lack of prlimit libc call
simply providing own implementation,  but it
cause problems on some libc configurations so
simply use rlimit64 and __NR_prlimit64 syscall
directly.

The kernel must support __NR_prlimit64 syscall
and provide rlimit64 structure as well.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---

Guys, take a look please, I think this would be better
than emulating prlimit libc's function. I run on x86
only, so help from other arch people would be appreciated.

 criu/Makefile.config                       |  2 +-
 criu/arch/ppc64/include/asm/prlimit.h      | 14 ------
 criu/arch/ppc64/syscalls/syscall-ppc64.tbl |  1 -
 criu/arch/x86/Makefile                     |  1 -
 criu/arch/x86/include/asm/prlimit.h        | 14 ------
 criu/arch/x86/include/asm/types.h          |  1 -
 criu/arch/x86/prlimit.c                    | 68 ------------------------------
 criu/arch/x86/syscalls/syscall_32.tbl      |  1 -
 criu/arch/x86/syscalls/syscall_64.tbl      |  1 -
 criu/cr-dump.c                             |  4 +-
 criu/cr-restore.c                          |  2 +-
 criu/include/restorer.h                    |  2 +-
 criu/include/syscall-types.h               |  3 --
 criu/util.c                                |  4 +-
 scripts/feature-tests.mak                  | 18 --------
 15 files changed, 7 insertions(+), 129 deletions(-)
 delete mode 100644 criu/arch/ppc64/include/asm/prlimit.h
 delete mode 100644 criu/arch/x86/include/asm/prlimit.h
 delete mode 100644 criu/arch/x86/prlimit.c

diff --git a/criu/Makefile.config b/criu/Makefile.config
index aaaca1f924a2..15af65f28f6b 100644
--- a/criu/Makefile.config
+++ b/criu/Makefile.config
@@ -14,7 +14,7 @@ ifeq ($(call pkg-config-check,libselinux),y)
         DEFINES	+= -DCONFIG_HAS_SELINUX
 endif
 
-FEATURES_LIST	:= TCP_REPAIR PRLIMIT STRLCPY STRLCAT PTRACE_PEEKSIGINFO \
+FEATURES_LIST	:= TCP_REPAIR STRLCPY STRLCAT PTRACE_PEEKSIGINFO \
 	SETPROCTITLE_INIT MEMFD
 
 # $1 - config name
diff --git a/criu/arch/ppc64/include/asm/prlimit.h b/criu/arch/ppc64/include/asm/prlimit.h
deleted file mode 100644
index 6746ba0e6f19..000000000000
--- a/criu/arch/ppc64/include/asm/prlimit.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __CR_PRLIMIT_H__
-#define __CR_PRLIMIT_H__
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-
-#include "config.h"
-
-#ifndef CONFIG_HAS_PRLIMIT
-extern int prlimit(pid_t pid, int resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit);
-#endif
-
-#endif /* __CR_PRLIMIT_H__ */
diff --git a/criu/arch/ppc64/syscalls/syscall-ppc64.tbl b/criu/arch/ppc64/syscalls/syscall-ppc64.tbl
index 331937973f72..274e7cea4a6c 100644
--- a/criu/arch/ppc64/syscalls/syscall-ppc64.tbl
+++ b/criu/arch/ppc64/syscalls/syscall-ppc64.tbl
@@ -94,7 +94,6 @@ __NR_signalfd4		313		sys_signalfd		(int fd, k_rtsigset_t *mask, size_t sizemask,
 __NR_rt_tgsigqueueinfo	322		sys_rt_tgsigqueueinfo	(pid_t tgid, pid_t pid, int sig, siginfo_t *info)
 __NR_fanotify_init	323		sys_fanotify_init	(unsigned int flags, unsigned int event_f_flags)
 __NR_fanotify_mark	324		sys_fanotify_mark	(int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname)
-__NR_prlimit64		325		sys_prlimit64		(pid_t pid, unsigned int resource, const struct rlimit64 *new_rlim, struct rlimit64 *old_rlim)
 __NR_open_by_handle_at	346		sys_open_by_handle_at	(int mountdirfd, struct file_handle *handle, int flags)
 __NR_setns		350		sys_setns		(int fd, int nstype)
 __NR_kcmp		354		sys_kcmp		(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
diff --git a/criu/arch/x86/Makefile b/criu/arch/x86/Makefile
index 369b41f28b6a..5db577340a7d 100644
--- a/criu/arch/x86/Makefile
+++ b/criu/arch/x86/Makefile
@@ -4,4 +4,3 @@ ccflags-y		+= -iquote $(obj) -iquote $(SRC_DIR) -iquote $(obj)/include -iquote $
 
 obj-y			+= cpu.o
 obj-y			+= crtools.o
-obj-y			+= prlimit.o
diff --git a/criu/arch/x86/include/asm/prlimit.h b/criu/arch/x86/include/asm/prlimit.h
deleted file mode 100644
index 6746ba0e6f19..000000000000
--- a/criu/arch/x86/include/asm/prlimit.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __CR_PRLIMIT_H__
-#define __CR_PRLIMIT_H__
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-
-#include "config.h"
-
-#ifndef CONFIG_HAS_PRLIMIT
-extern int prlimit(pid_t pid, int resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit);
-#endif
-
-#endif /* __CR_PRLIMIT_H__ */
diff --git a/criu/arch/x86/include/asm/types.h b/criu/arch/x86/include/asm/types.h
index 56f967fe35f8..c8e76964e430 100644
--- a/criu/arch/x86/include/asm/types.h
+++ b/criu/arch/x86/include/asm/types.h
@@ -7,7 +7,6 @@
 #include "asm/page.h"
 #include "asm/bitops.h"
 #include "asm/int.h"
-#include "asm/prlimit.h"
 
 #include "images/core.pb-c.h"
 
diff --git a/criu/arch/x86/prlimit.c b/criu/arch/x86/prlimit.c
deleted file mode 100644
index 8bc4aba9f6a6..000000000000
--- a/criu/arch/x86/prlimit.c
+++ /dev/null
@@ -1,68 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "asm/types.h"
-#include "asm/prlimit.h"
-
-#include "compiler.h"
-#include "config.h"
-
-#ifndef CONFIG_HAS_PRLIMIT
-
-#ifndef RLIM64_INFINITY
-# define RLIM64_INFINITY	(~0ULL)
-#endif
-
-int prlimit(pid_t pid, int resource, const struct rlimit *new_rlimit, struct rlimit *old_rlimit)
-{
-	struct rlimit64 new_rlimit64_mem;
-	struct rlimit64 old_rlimit64_mem;
-	struct rlimit64 *new_rlimit64 = NULL;
-	struct rlimit64 *old_rlimit64 = NULL;
-	int ret;
-
-	if (old_rlimit)
-		old_rlimit64 = &old_rlimit64_mem;
-
-	if (new_rlimit) {
-		if (new_rlimit->rlim_cur == RLIM_INFINITY)
-			new_rlimit64_mem.rlim_cur = RLIM64_INFINITY;
-		else
-			new_rlimit64_mem.rlim_cur = new_rlimit->rlim_cur;
-		if (new_rlimit->rlim_max == RLIM_INFINITY)
-			new_rlimit64_mem.rlim_max = RLIM64_INFINITY;
-		else
-			new_rlimit64_mem.rlim_max = new_rlimit->rlim_max;
-		new_rlimit64 = &new_rlimit64_mem;
-	}
-
-	ret = sys_prlimit64(pid, resource, new_rlimit64, old_rlimit64);
-
-	if (ret == 0 && old_rlimit) {
-		old_rlimit->rlim_cur = old_rlimit64_mem.rlim_cur;
-		if (old_rlimit->rlim_cur != old_rlimit64_mem.rlim_cur) {
-			if (new_rlimit) {
-				errno = EOVERFLOW;
-				return -1;
-			}
-			old_rlimit->rlim_cur = RLIM_INFINITY;
-		}
-		old_rlimit->rlim_max = old_rlimit64_mem.rlim_max;
-		if (old_rlimit->rlim_max != old_rlimit64_mem.rlim_max) {
-			if (new_rlimit) {
-				errno = EOVERFLOW;
-				return -1;
-			}
-			old_rlimit->rlim_max = RLIM_INFINITY;
-		}
-	} else if (ret) {
-		errno = -ret;
-		ret = -1;
-	}
-
-	return ret;
-}
-
-#endif /* CONFIG_HAS_PRLIMIT */
diff --git a/criu/arch/x86/syscalls/syscall_32.tbl b/criu/arch/x86/syscalls/syscall_32.tbl
index c52712290993..8ebe5b1fa3b8 100644
--- a/criu/arch/x86/syscalls/syscall_32.tbl
+++ b/criu/arch/x86/syscalls/syscall_32.tbl
@@ -85,7 +85,6 @@ __NR_timerfd_settime	325		sys_timerfd_settime	(int ufd, int flags, const struct
 __NR_rt_tgsigqueueinfo	335		sys_rt_tgsigqueueinfo	(pid_t tgid, pid_t pid, int sig, siginfo_t *uinfo)
 __NR_fanotify_init	338		sys_fanotify_init	(unsigned int flags, unsigned int event_f_flags)
 __NR_fanotify_mark	339		sys_fanotify_mark	(int fanotify_fd, unsigned int flag, u32 mask, int dfd, const char *pathname)
-__NR_prlimit64		340		sys_prlimit64		(pid_t pid, unsigned int resource, const struct rlimit64 *new_rlim, struct rlimit64 *old_rlim)
 __NR_open_by_handle_at	342		sys_open_by_handle_at	(int mountdirfd, struct file_handle *handle, int flags)
 __NR_setns		346		sys_setns		(int fd, int nstype)
 __NR_kcmp		349		sys_kcmp		(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
diff --git a/criu/arch/x86/syscalls/syscall_64.tbl b/criu/arch/x86/syscalls/syscall_64.tbl
index 5c32d4c46c75..543ec0afd5d8 100644
--- a/criu/arch/x86/syscalls/syscall_64.tbl
+++ b/criu/arch/x86/syscalls/syscall_64.tbl
@@ -96,7 +96,6 @@ __NR_signalfd4			289		sys_signalfd		(int fd, k_rtsigset_t *mask, size_t sizemask
 __NR_rt_tgsigqueueinfo		297		sys_rt_tgsigqueueinfo	(pid_t tgid, pid_t pid, int sig, siginfo_t *info)
 __NR_fanotify_init		300		sys_fanotify_init	(unsigned int flags, unsigned int event_f_flags)
 __NR_fanotify_mark		301		sys_fanotify_mark	(int fanotify_fd, unsigned int flags, u64 mask, int dfd, const char *pathname)
-__NR_prlimit64			302		sys_prlimit64		(pid_t pid, unsigned int resource, const struct rlimit64 *new_rlim, struct rlimit64 *old_rlim)
 __NR_open_by_handle_at		304		sys_open_by_handle_at	(int mountdirfd, struct file_handle *handle, int flags)
 __NR_setns			308		sys_setns		(int fd, int nstype)
 __NR_kcmp			312		sys_kcmp		(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 75592ca01862..13ceaa4e271c 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -307,9 +307,9 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls)
 	int res;
 
 	for (res = 0; res <rls->n_rlimits ; res++) {
-		struct rlimit lim;
+		struct rlimit64 lim;
 
-		if (prlimit(pid, res, NULL, &lim)) {
+		if (syscall(__NR_prlimit64, pid, res, NULL, &lim)) {
 			pr_perror("Can't get rlimit %d", res);
 			return -1;
 		}
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 027232be91a2..01d4e7e621ab 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2660,7 +2660,7 @@ static int prepare_rlimits(int pid, CoreEntry *core)
 {
 	int i;
 	TaskRlimitsEntry *rls = core->tc->rlimits;
-	struct rlimit *r;
+	struct rlimit64 *r;
 
 	rlims_cpos = rst_mem_align_cpos(RM_PRIVATE);
 
diff --git a/criu/include/restorer.h b/criu/include/restorer.h
index 9896aa1f5dc3..b4e5b47ff82a 100644
--- a/criu/include/restorer.h
+++ b/criu/include/restorer.h
@@ -151,7 +151,7 @@ struct task_restore_args {
 	struct rst_aio_ring		*rings;
 	unsigned int			rings_n;
 
-	struct rlimit			*rlims;
+	struct rlimit64			*rlims;
 	unsigned int			rlims_n;
 
 	pid_t				*helpers /* the TASK_HELPERS to wait on at the end of restore */;
diff --git a/criu/include/syscall-types.h b/criu/include/syscall-types.h
index fdfed9a08921..fb5d8e7b7920 100644
--- a/criu/include/syscall-types.h
+++ b/criu/include/syscall-types.h
@@ -71,9 +71,6 @@ struct itimerspec;
 
 #define CLONE_ALLNS	(CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWCGROUP)
 
-struct rlimit;
-struct rlimit64;
-
 struct krlimit {
 	unsigned long rlim_cur;
 	unsigned long rlim_max;
diff --git a/criu/util.c b/criu/util.c
index 0148240a80ed..89c629f20fb5 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -385,14 +385,14 @@ static int service_fd_id = 0;
 
 int init_service_fd(void)
 {
-	struct rlimit rlimit;
+	struct rlimit64 rlimit;
 
 	/*
 	 * Service FDs are those that most likely won't
 	 * conflict with any 'real-life' ones
 	 */
 
-	if (getrlimit(RLIMIT_NOFILE, &rlimit)) {
+	if (syscall(__NR_prlimit64, getpid(), RLIMIT_NOFILE, NULL, &rlimit)) {
 		pr_perror("Can't get rlimit");
 		return -1;
 	}
diff --git a/scripts/feature-tests.mak b/scripts/feature-tests.mak
index 3587e07f388b..c3dc85e257b1 100644
--- a/scripts/feature-tests.mak
+++ b/scripts/feature-tests.mak
@@ -12,24 +12,6 @@ int main(void)
 }
 endef
 
-define FEATURE_TEST_PRLIMIT
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-
-int main(void)
-{
-	struct rlimit limit = {
-		.rlim_cur = RLIM_INFINITY,
-		.rlim_max = RLIM_INFINITY,
-	};
-
-	return prlimit(getpid(), RLIMIT_CPU, &limit, NULL);
-}
-endef
-
 define FEATURE_TEST_LIBBSD_DEV
 #include <bsd/string.h>
 
-- 
2.5.5



More information about the CRIU mailing list