diff options
author | Adrian Reber <areber@redhat.com> | 2021-07-19 10:28:38 +0300 |
---|---|---|
committer | Andrei Vagin <avagin@gmail.com> | 2021-09-03 20:31:00 +0300 |
commit | 93dd984ca0ee0e31a5650f64328222e748152bcb (patch) | |
tree | 024483c121704ec8d106c9bf596441b51e51a67c | |
parent | 1e26f170caa8b2c26f5d09a78ffe9fdea70d38d0 (diff) |
Run 'make indent' on all C files
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Adrian Reber <areber@redhat.com>
542 files changed, 9422 insertions, 11681 deletions
diff --git a/compel/arch/aarch64/src/lib/cpu.c b/compel/arch/aarch64/src/lib/cpu.c index cfaab1e65..538a29887 100644 --- a/compel/arch/aarch64/src/lib/cpu.c +++ b/compel/arch/aarch64/src/lib/cpu.c @@ -7,7 +7,7 @@ #include "log.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; @@ -22,11 +22,24 @@ static void fetch_rt_cpuinfo(void) } } -void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } -void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } -int compel_test_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { return 0; } -int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) { return 0; } -int compel_cpuid(compel_cpuinfo_t *info) { return 0; } +void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ +} +void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ +} +int compel_test_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ + return 0; +} +int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ + return 0; +} +int compel_cpuid(compel_cpuinfo_t *info) +{ + return 0; +} bool compel_cpu_has_feature(unsigned int feature) { diff --git a/compel/arch/aarch64/src/lib/handle-elf.c b/compel/arch/aarch64/src/lib/handle-elf.c index 1ee65ee2c..206aef4cd 100644 --- a/compel/arch/aarch64/src/lib/handle-elf.c +++ b/compel/arch/aarch64/src/lib/handle-elf.c @@ -5,15 +5,13 @@ #include "piegen.h" #include "log.h" -static const unsigned char __maybe_unused -elf_ident_64_le[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64_le[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static const unsigned char __maybe_unused -elf_ident_64_be[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64_be[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/compel/arch/aarch64/src/lib/infect.c b/compel/arch/aarch64/src/lib/infect.c index 586eedac0..7cfa637eb 100644 --- a/compel/arch/aarch64/src/lib/infect.c +++ b/compel/arch/aarch64/src/lib/infect.c @@ -18,12 +18,11 @@ unsigned __page_shift = 0; * Injected syscall instruction */ const char code_syscall[] = { - 0x01, 0x00, 0x00, 0xd4, /* SVC #0 */ - 0x00, 0x00, 0x20, 0xd4 /* BRK #0 */ + 0x01, 0x00, 0x00, 0xd4, /* SVC #0 */ + 0x00, 0x00, 0x20, 0xd4 /* BRK #0 */ }; -static const int -code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long)); +static const int code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long)); static inline void __always_unused __check_code_syscall(void) { @@ -31,17 +30,15 @@ static inline void __always_unused __check_code_syscall(void) BUILD_BUG_ON(!is_log2(sizeof(code_syscall))); } -int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, - user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { struct fpsimd_context *fpsimd = RT_SIGFRAME_FPU(sigframe); memcpy(sigframe->uc.uc_mcontext.regs, regs->regs, sizeof(regs->regs)); - sigframe->uc.uc_mcontext.sp = regs->sp; - sigframe->uc.uc_mcontext.pc = regs->pc; - sigframe->uc.uc_mcontext.pstate = regs->pstate; + sigframe->uc.uc_mcontext.sp = regs->sp; + sigframe->uc.uc_mcontext.pc = regs->pc; + sigframe->uc.uc_mcontext.pstate = regs->pstate; memcpy(fpsimd->vregs, fpregs->vregs, 32 * sizeof(__uint128_t)); @@ -54,15 +51,13 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, return 0; } -int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } -int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *ext_regs, save_regs_t save, - void *arg, __maybe_unused unsigned long flags) +int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *ext_regs, save_regs_t save, + void *arg, __maybe_unused unsigned long flags) { user_fpregs_struct_t tmp, *fpsimd = ext_regs ? ext_regs : &tmp; struct iovec iov; @@ -104,13 +99,8 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) return 0; } -int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5, - unsigned long arg6) +int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) { user_regs_struct_t regs = ctl->orig.regs; int err; @@ -131,15 +121,12 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, return err; } -void *remote_mmap(struct parasite_ctl *ctl, - void *addr, size_t length, int prot, - int flags, int fd, off_t offset) +void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { long map; int err; - err = compel_syscall(ctl, __NR_mmap, &map, - (unsigned long)addr, length, prot, flags, fd, offset); + err = compel_syscall(ctl, __NR_mmap, &map, (unsigned long)addr, length, prot, flags, fd, offset); if (err < 0 || (long)map < 0) map = 0; @@ -166,9 +153,7 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) long ret; int err; - err = compel_syscall(ctl, __NR_sigaltstack, - &ret, 0, (unsigned long)&s->uc.uc_stack, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_sigaltstack, &ret, 0, (unsigned long)&s->uc.uc_stack, 0, 0, 0, 0); return err ? err : ret; } @@ -191,4 +176,3 @@ unsigned long compel_task_size(void) break; return task_size; } - diff --git a/compel/arch/arm/src/lib/handle-elf.c b/compel/arch/arm/src/lib/handle-elf.c index 5b8d00a6f..a84524abd 100644 --- a/compel/arch/arm/src/lib/handle-elf.c +++ b/compel/arch/arm/src/lib/handle-elf.c @@ -5,9 +5,8 @@ #include "piegen.h" #include "log.h" -static const unsigned char __maybe_unused -elf_ident_32[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_32[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/compel/arch/arm/src/lib/infect.c b/compel/arch/arm/src/lib/infect.c index 1ddb48654..6715afdb3 100644 --- a/compel/arch/arm/src/lib/infect.c +++ b/compel/arch/arm/src/lib/infect.c @@ -17,12 +17,11 @@ * Injected syscall instruction */ const char code_syscall[] = { - 0x00, 0x00, 0x00, 0xef, /* SVC #0 */ - 0xf0, 0x01, 0xf0, 0xe7 /* UDF #32 */ + 0x00, 0x00, 0x00, 0xef, /* SVC #0 */ + 0xf0, 0x01, 0xf0, 0xe7 /* UDF #32 */ }; -static const int -code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long)); +static const int code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long)); static inline __always_unused void __check_code_syscall(void) { @@ -30,9 +29,7 @@ static inline __always_unused void __check_code_syscall(void) BUILD_BUG_ON(!is_log2(sizeof(code_syscall))); } -int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, - user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { struct aux_sigframe *aux = (struct aux_sigframe *)(void *)&sigframe->sig.uc.uc_regspace; @@ -62,16 +59,14 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, return 0; } -int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } #define PTRACE_GETVFPREGS 27 -int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *ext_regs, save_regs_t save, - void *arg, __maybe_unused unsigned long flags) +int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *ext_regs, save_regs_t save, + void *arg, __maybe_unused unsigned long flags) { user_fpregs_struct_t tmp, *vfp = ext_regs ? ext_regs : &tmp; int ret = -1; @@ -116,13 +111,8 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) return 0; } -int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5, - unsigned long arg6) +int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) { user_regs_struct_t regs = ctl->orig.regs; int err; @@ -141,9 +131,7 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, return err; } -void *remote_mmap(struct parasite_ctl *ctl, - void *addr, size_t length, int prot, - int flags, int fd, off_t offset) +void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { long map; int err; @@ -151,8 +139,7 @@ void *remote_mmap(struct parasite_ctl *ctl, if (offset & ~PAGE_MASK) return 0; - err = compel_syscall(ctl, __NR_mmap2, &map, - (unsigned long)addr, length, prot, flags, fd, offset >> 12); + err = compel_syscall(ctl, __NR_mmap2, &map, (unsigned long)addr, length, prot, flags, fd, offset >> 12); if (err < 0 || map > ctl->ictx.task_size) map = 0; @@ -182,9 +169,7 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) long ret; int err; - err = compel_syscall(ctl, __NR_sigaltstack, - &ret, 0, (unsigned long)&s->sig.uc.uc_stack, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_sigaltstack, &ret, 0, (unsigned long)&s->sig.uc.uc_stack, 0, 0, 0, 0); return err ? err : ret; } @@ -193,9 +178,9 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) * arch/arm/include/asm/memory.h * arch/arm/Kconfig (PAGE_OFFSET values in Memory split section) */ -#define TASK_SIZE_MIN 0x3f000000 -#define TASK_SIZE_MAX 0xbf000000 -#define SZ_1G 0x40000000 +#define TASK_SIZE_MIN 0x3f000000 +#define TASK_SIZE_MAX 0xbf000000 +#define SZ_1G 0x40000000 unsigned long compel_task_size(void) { @@ -207,4 +192,3 @@ unsigned long compel_task_size(void) return task_size; } - diff --git a/compel/arch/mips/src/lib/cpu.c b/compel/arch/mips/src/lib/cpu.c index bdb65ff9f..172b90e27 100644 --- a/compel/arch/mips/src/lib/cpu.c +++ b/compel/arch/mips/src/lib/cpu.c @@ -6,22 +6,27 @@ #include "common/compiler.h" #include "log.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; static bool rt_info_done = false; -void compel_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature){ } +void compel_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) +{ +} -void compel_clear_cpu_cap(compel_cpuinfo_t *c, unsigned int feature){ } +void compel_clear_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) +{ +} int compel_test_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { return 0; } -int compel_cpuid(compel_cpuinfo_t *c){ +int compel_cpuid(compel_cpuinfo_t *c) +{ return 0; } diff --git a/compel/arch/mips/src/lib/handle-elf.c b/compel/arch/mips/src/lib/handle-elf.c index 988985151..a605a5a45 100644 --- a/compel/arch/mips/src/lib/handle-elf.c +++ b/compel/arch/mips/src/lib/handle-elf.c @@ -5,9 +5,8 @@ #include "piegen.h" #include "log.h" -static const unsigned char __maybe_unused -elf_ident_64_le[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64_le[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/compel/arch/mips/src/lib/infect.c b/compel/arch/mips/src/lib/infect.c index d8c03c33a..68d0a2728 100644 --- a/compel/arch/mips/src/lib/infect.c +++ b/compel/arch/mips/src/lib/infect.c @@ -23,8 +23,8 @@ * mips64el is Little Endian */ const char code_syscall[] = { - 0x0c, 0x00, 0x00, 0x00, /* syscall */ - 0x0d, 0x00, 0x00, 0x00 /* break */ + 0x0c, 0x00, 0x00, 0x00, /* syscall */ + 0x0d, 0x00, 0x00, 0x00 /* break */ }; /* 10-byte legacy floating point register */ @@ -40,10 +40,7 @@ struct fpxreg { uint16_t padding[3]; }; - -int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, - user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { sigframe->rs_uc.uc_mcontext.sc_regs[0] = regs->regs[0]; sigframe->rs_uc.uc_mcontext.sc_regs[1] = regs->regs[1]; @@ -117,17 +114,15 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, return 0; } -int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } -int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *ext_regs, save_regs_t save, - void *arg, __maybe_unused unsigned long flags) +int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *ext_regs, save_regs_t save, + void *arg, __maybe_unused unsigned long flags) { - user_fpregs_struct_t xsave = { }, *xs = ext_regs ? ext_regs : &xsave; + user_fpregs_struct_t xsave = {}, *xs = ext_regs ? ext_regs : &xsave; int ret = -1; pr_info("Dumping GP/FPU registers for %d\n", pid); @@ -143,7 +138,7 @@ int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, case ERESTARTNOHAND: case ERESTARTSYS: case ERESTARTNOINTR: - regs->regs[2] = regs->regs[0]; + regs->regs[2] = regs->regs[0]; regs->regs[7] = regs->regs[26]; regs->cp0_epc -= 4; break; @@ -170,13 +165,8 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) return 0; } -int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5, - unsigned long arg6) +int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) { /*refer to glibc-2.20/sysdeps/unix/sysv/linux/mips/mips64/syscall.S*/ user_regs_struct_t regs = ctl->orig.regs; @@ -193,18 +183,15 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, err = compel_execute_syscall(ctl, ®s, code_syscall); *ret = regs.regs[2]; - return err; + return err; } -void *remote_mmap(struct parasite_ctl *ctl, - void *addr, size_t length, int prot, - int flags, int fd, off_t offset) +void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { long map; int err; - err = compel_syscall(ctl, __NR_mmap, &map, - (unsigned long)addr, length, prot, flags, fd, offset >> PAGE_SHIFT); + err = compel_syscall(ctl, __NR_mmap, &map, (unsigned long)addr, length, prot, flags, fd, offset >> PAGE_SHIFT); if (err < 0 || IS_ERR_VALUE(map)) { pr_err("remote mmap() failed: %s\n", strerror(-map)); @@ -236,13 +223,10 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) long ret; int err; - err = compel_syscall(ctl, __NR_sigaltstack, - &ret, 0, (unsigned long)&s->rs_uc.uc_stack, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_sigaltstack, &ret, 0, (unsigned long)&s->rs_uc.uc_stack, 0, 0, 0, 0); return err ? err : ret; } - int ptrace_set_breakpoint(pid_t pid, void *addr) { return 0; @@ -256,9 +240,12 @@ int ptrace_flush_breakpoints(pid_t pid) /*refer to kernel linux-3.10/arch/mips/include/asm/processor.h*/ #define TASK_SIZE32 0x7fff8000UL #define TASK_SIZE64 0x10000000000UL -#define TASK_SIZE TASK_SIZE64 +#define TASK_SIZE TASK_SIZE64 -unsigned long compel_task_size(void) { return TASK_SIZE; } +unsigned long compel_task_size(void) +{ + return TASK_SIZE; +} /* * Get task registers (overwrites weak function) @@ -292,30 +279,31 @@ void compel_relocs_apply_mips(void *mem, void *vbase, struct parasite_blob_desc for (i = 0, j = 0; i < nr_relocs; i++) { if (elf_relocs[i].type & COMPEL_TYPE_MIPS_26) { int *where = (mem + elf_relocs[i].offset); - *where = *where | ((elf_relocs[i].addend + ((unsigned long)vbase & 0x00fffffff) /*low 28 bit*/)>>2); + *where = *where | + ((elf_relocs[i].addend + ((unsigned long)vbase & 0x00fffffff) /*low 28 bit*/) >> 2); } else if (elf_relocs[i].type & COMPEL_TYPE_MIPS_64) { unsigned long *where = (mem + elf_relocs[i].offset); *where = elf_relocs[i].addend + (unsigned long)vbase; } else if (elf_relocs[i].type & COMPEL_TYPE_MIPS_HI16) { /* refer to binutils mips.cc */ int *where = (mem + elf_relocs[i].offset); - int v_lo16 = (unsigned long)vbase &0x00ffff; + int v_lo16 = (unsigned long)vbase & 0x00ffff; - if ((v_lo16+elf_relocs[i].value+elf_relocs[i].addend) >= 0x8000) { - *where = *where | ((((unsigned long)vbase>>16) &0xffff)+0x1); + if ((v_lo16 + elf_relocs[i].value + elf_relocs[i].addend) >= 0x8000) { + *where = *where | ((((unsigned long)vbase >> 16) & 0xffff) + 0x1); } else { - *where = *where | ((((unsigned long)vbase>>16) &0xffff)); + *where = *where | ((((unsigned long)vbase >> 16) & 0xffff)); } } else if (elf_relocs[i].type & COMPEL_TYPE_MIPS_LO16) { int *where = (mem + elf_relocs[i].offset); - int v_lo16 = (unsigned long)vbase &0x00ffff; + int v_lo16 = (unsigned long)vbase & 0x00ffff; *where = *where | ((v_lo16 + elf_relocs[i].addend) & 0xffff); } else if (elf_relocs[i].type & COMPEL_TYPE_MIPS_HIGHER) { int *where = (mem + elf_relocs[i].offset); - *where = *where | ((( (unsigned long)vbase + (uint64_t) 0x80008000) >> 32) & 0xffff); + *where = *where | ((((unsigned long)vbase + (uint64_t)0x80008000) >> 32) & 0xffff); } else if (elf_relocs[i].type & COMPEL_TYPE_MIPS_HIGHEST) { int *where = (mem + elf_relocs[i].offset); - *where = *where | ((( (unsigned long)vbase + (uint64_t) 0x800080008000llu) >> 48) & 0xffff); + *where = *where | ((((unsigned long)vbase + (uint64_t)0x800080008000llu) >> 48) & 0xffff); } else { BUG(); } diff --git a/compel/arch/ppc64/src/lib/cpu.c b/compel/arch/ppc64/src/lib/cpu.c index 7a3972790..f7a128ca3 100644 --- a/compel/arch/ppc64/src/lib/cpu.c +++ b/compel/arch/ppc64/src/lib/cpu.c @@ -10,7 +10,7 @@ #include "log.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; @@ -25,10 +25,20 @@ static void fetch_rt_cpuinfo(void) } } -void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } -void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { } -int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) { return 0; } -int compel_test_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) { return 0; } +void compel_set_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ +} +void compel_clear_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ +} +int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ + return 0; +} +int compel_test_cpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ + return 0; +} int compel_cpuid(compel_cpuinfo_t *info) { diff --git a/compel/arch/ppc64/src/lib/handle-elf.c b/compel/arch/ppc64/src/lib/handle-elf.c index f29fdc8a3..84a360c43 100644 --- a/compel/arch/ppc64/src/lib/handle-elf.c +++ b/compel/arch/ppc64/src/lib/handle-elf.c @@ -5,15 +5,13 @@ #include "piegen.h" #include "log.h" -static const unsigned char __maybe_unused -elf_ident_64_le[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64_le[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static const unsigned char __maybe_unused -elf_ident_64_be[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64_be[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/compel/arch/ppc64/src/lib/infect.c b/compel/arch/ppc64/src/lib/infect.c index 5797fb16d..fc174d0dd 100644 --- a/compel/arch/ppc64/src/lib/infect.c +++ b/compel/arch/ppc64/src/lib/infect.c @@ -15,11 +15,11 @@ #include "infect-priv.h" #ifndef NT_PPC_TM_SPR -#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */ -#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */ -#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */ -#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */ -#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */ +#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */ +#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */ +#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */ +#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */ +#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */ #endif unsigned __page_size = 0; @@ -29,8 +29,8 @@ unsigned __page_shift = 0; * Injected syscall instruction */ const uint32_t code_syscall[] = { - 0x44000002, /* sc */ - 0x0fe00000 /* twi 31,0,0 */ + 0x44000002, /* sc */ + 0x0fe00000 /* twi 31,0,0 */ }; static inline __always_unused void __check_code_syscall(void) @@ -43,14 +43,14 @@ static void prep_gp_regs(mcontext_t *dst, user_regs_struct_t *regs) { memcpy(dst->gp_regs, regs->gpr, sizeof(regs->gpr)); - dst->gp_regs[PT_NIP] = regs->nip; - dst->gp_regs[PT_MSR] = regs->msr; - dst->gp_regs[PT_ORIG_R3] = regs->orig_gpr3; - dst->gp_regs[PT_CTR] = regs->ctr; - dst->gp_regs[PT_LNK] = regs->link; - dst->gp_regs[PT_XER] = regs->xer; - dst->gp_regs[PT_CCR] = regs->ccr; - dst->gp_regs[PT_TRAP] = regs->trap; + dst->gp_regs[PT_NIP] = regs->nip; + dst->gp_regs[PT_MSR] = regs->msr; + dst->gp_regs[PT_ORIG_R3] = regs->orig_gpr3; + dst->gp_regs[PT_CTR] = regs->ctr; + dst->gp_regs[PT_LNK] = regs->link; + dst->gp_regs[PT_XER] = regs->xer; + dst->gp_regs[PT_CCR] = regs->ccr; + dst->gp_regs[PT_TRAP] = regs->trap; } static void put_fpu_regs(mcontext_t *mc, uint64_t *fpregs) @@ -74,9 +74,7 @@ static void put_vsx_regs(mcontext_t *mc, uint64_t *vsxregs) memcpy((uint64_t *)(mc->v_regs + 1), vsxregs, sizeof(*vsxregs) * NVSXREG); } -int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, - user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { mcontext_t *dst_tc = &sigframe->uc_transact.uc_mcontext; mcontext_t *dst = &sigframe->uc.uc_mcontext; @@ -134,14 +132,12 @@ static void update_vregs(mcontext_t *lcontext, mcontext_t *rcontext) uint64_t offset = (uint64_t)(lcontext->v_regs) - (uint64_t)lcontext; lcontext->v_regs = (vrregset_t *)((uint64_t)rcontext + offset); - pr_debug("Updated v_regs:%llx (rcontext:%llx)\n", - (unsigned long long)lcontext->v_regs, + pr_debug("Updated v_regs:%llx (rcontext:%llx)\n", (unsigned long long)lcontext->v_regs, (unsigned long long)rcontext); } } -int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *frame, - struct rt_sigframe *rframe) +int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *frame, struct rt_sigframe *rframe) { uint64_t msr = frame->uc.uc_mcontext.gp_regs[PT_MSR]; @@ -155,9 +151,8 @@ int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *frame, /* Updating the transactional state address if any */ if (frame->uc.uc_link) { - update_vregs(&frame->uc_transact.uc_mcontext, - &rframe->uc_transact.uc_mcontext); - frame->uc.uc_link = &rframe->uc_transact; + update_vregs(&frame->uc_transact.uc_mcontext, &rframe->uc_transact.uc_mcontext); + frame->uc.uc_link = &rframe->uc_transact; } return 0; @@ -214,7 +209,7 @@ static int get_fpu_regs(pid_t pid, user_fpregs_struct_t *fp) static int get_altivec_regs(pid_t pid, user_fpregs_struct_t *fp) { - if (ptrace(PTRACE_GETVRREGS, pid, 0, (void*)&fp->vrregs) < 0) { + if (ptrace(PTRACE_GETVRREGS, pid, 0, (void *)&fp->vrregs) < 0) { /* PTRACE_GETVRREGS returns EIO if Altivec is not supported. * This should not happen if msr_vec is set. */ if (errno != EIO) { @@ -240,7 +235,7 @@ static int get_altivec_regs(pid_t pid, user_fpregs_struct_t *fp) */ static int get_vsx_regs(pid_t pid, user_fpregs_struct_t *fp) { - if (ptrace(PTRACE_GETVSRREGS, pid, 0, (void*)fp->vsxregs) < 0) { + if (ptrace(PTRACE_GETVSRREGS, pid, 0, (void *)fp->vsxregs) < 0) { /* * EIO is returned in the case PTRACE_GETVRREGS is not * supported. @@ -263,22 +258,23 @@ static int get_tm_regs(pid_t pid, user_fpregs_struct_t *fpregs) pr_debug("Dumping TM registers\n"); -#define TM_REQUIRED 0 -#define TM_OPTIONAL 1 -#define PTRACE_GET_TM(s,n,c,u) do { \ - iov.iov_base = &s; \ - iov.iov_len = sizeof(s); \ - if (ptrace(PTRACE_GETREGSET, pid, c, &iov)) { \ - if (!u || errno != EIO) { \ - pr_perror("Couldn't get TM "n); \ - pr_err("Your kernel seems to not support the " \ - "new TM ptrace API (>= 4.8)\n"); \ - goto out_free; \ - } \ - pr_debug("TM "n" not supported.\n"); \ - iov.iov_base = NULL; \ - } \ -} while(0) +#define TM_REQUIRED 0 +#define TM_OPTIONAL 1 +#define PTRACE_GET_TM(s, n, c, u) \ + do { \ + iov.iov_base = &s; \ + iov.iov_len = sizeof(s); \ + if (ptrace(PTRACE_GETREGSET, pid, c, &iov)) { \ + if (!u || errno != EIO) { \ + pr_perror("Couldn't get TM " n); \ + pr_err("Your kernel seems to not support the " \ + "new TM ptrace API (>= 4.8)\n"); \ + goto out_free; \ + } \ + pr_debug("TM " n " not supported.\n"); \ + iov.iov_base = NULL; \ + } \ + } while (0) /* Get special registers */ PTRACE_GET_TM(fpregs->tm.tm_spr_regs, "SPR", NT_PPC_TM_SPR, TM_REQUIRED); @@ -304,11 +300,10 @@ static int get_tm_regs(pid_t pid, user_fpregs_struct_t *fpregs) return 0; out_free: - return -1; /* still failing the checkpoint */ + return -1; /* still failing the checkpoint */ } -static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { pr_info("Dumping GP/FPU registers for %d\n", pid); @@ -317,7 +312,7 @@ static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, * arch/powerpc/kernel/signal.c */ #ifndef TRAP -#define TRAP(r) ((r).trap & ~0xF) +#define TRAP(r) ((r).trap & ~0xF) #endif if (TRAP(*regs) == 0x0C00 && regs->ccr & 0x10000000) { @@ -347,10 +342,8 @@ static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, * impossible) or suspended (easy to get). */ if (MSR_TM_ACTIVE(regs->msr)) { - pr_debug("Task %d has %s TM operation at 0x%lx\n", - pid, - (regs->msr & MSR_TMS) ? "a suspended" : "an active", - regs->nip); + pr_debug("Task %d has %s TM operation at 0x%lx\n", pid, + (regs->msr & MSR_TMS) ? "a suspended" : "an active", regs->nip); if (get_tm_regs(pid, fpregs)) return -1; fpregs->flags = USER_FPREGS_FL_TM; @@ -372,9 +365,8 @@ static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, return 0; } -int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *ext_regs, save_regs_t save, - void *arg, __maybe_unused unsigned long flags) +int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *ext_regs, save_regs_t save, + void *arg, __maybe_unused unsigned long flags) { user_fpregs_struct_t tmp, *fpregs = ext_regs ? ext_regs : &tmp; int ret; @@ -401,11 +393,11 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) } if (ext_regs->flags & USER_FPREGS_FL_ALTIVEC) { - if (ptrace(PTRACE_SETVRREGS, pid, 0, (void*)&ext_regs->vrregs) < 0) { + if (ptrace(PTRACE_SETVRREGS, pid, 0, (void *)&ext_regs->vrregs) < 0) { pr_perror("Couldn't set Altivec registers"); ret = -1; } - if (ptrace(PTRACE_SETVSRREGS, pid, 0, (void*)ext_regs->vsxregs) < 0) { + if (ptrace(PTRACE_SETVSRREGS, pid, 0, (void *)ext_regs->vsxregs) < 0) { pr_perror("Couldn't set VSX registers"); ret = -1; } @@ -414,13 +406,8 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) return ret; } -int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5, - unsigned long arg6) +int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) { user_regs_struct_t regs = ctl->orig.regs; int err; @@ -433,21 +420,18 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, regs.gpr[7] = arg5; regs.gpr[8] = arg6; - err = compel_execute_syscall(ctl, ®s, (char*)code_syscall); + err = compel_execute_syscall(ctl, ®s, (char *)code_syscall); *ret = regs.gpr[3]; return err; } -void *remote_mmap(struct parasite_ctl *ctl, - void *addr, size_t length, int prot, - int flags, int fd, off_t offset) +void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { long map = 0; int err; - err = compel_syscall(ctl, __NR_mmap, &map, - (unsigned long)addr, length, prot, flags, fd, offset); + err = compel_syscall(ctl, __NR_mmap, &map, (unsigned long)addr, length, prot, flags, fd, offset); if (err < 0 || (long)map < 0) map = 0; @@ -463,7 +447,7 @@ void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t * regs->gpr[12] = new_ip; regs->nip = new_ip; if (stack) - regs->gpr[1] = (unsigned long) stack; + regs->gpr[1] = (unsigned long)stack; regs->trap = 0; } @@ -480,9 +464,7 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) long ret; int err; - err = compel_syscall(ctl, __NR_sigaltstack, - &ret, 0, (unsigned long)&s->uc.uc_stack, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_sigaltstack, &ret, 0, (unsigned long)&s->uc.uc_stack, 0, 0, 0, 0); return err ? err : ret; } @@ -491,7 +473,7 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) * * NOTE: 32bit tasks are not supported. */ -#define TASK_SIZE_64TB (0x0000400000000000UL) +#define TASK_SIZE_64TB (0x0000400000000000UL) #define TASK_SIZE_512TB (0x0002000000000000UL) #define TASK_SIZE_MIN TASK_SIZE_64TB diff --git a/compel/arch/s390/plugins/std/syscalls/syscalls-s390.c b/compel/arch/s390/plugins/std/syscalls/syscalls-s390.c index 2b35cca4a..11c3284ab 100644 --- a/compel/arch/s390/plugins/std/syscalls/syscalls-s390.c +++ b/compel/arch/s390/plugins/std/syscalls/syscalls-s390.c @@ -3,14 +3,13 @@ /* * Define prototype because of compile error if we include uapi/std/syscall.h */ -long sys_old_mmap (struct mmap_arg_struct *); +long sys_old_mmap(struct mmap_arg_struct *); /* * On s390 we have defined __ARCH_WANT_SYS_OLD_MMAP - Therefore implement * system call with one parameter "mmap_arg_struct". */ -unsigned long sys_mmap(void *addr, unsigned long len, unsigned long prot, - unsigned long flags, unsigned long fd, +unsigned long sys_mmap(void *addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long offset) { struct mmap_arg_struct arg_struct; diff --git a/compel/arch/s390/src/lib/cpu.c b/compel/arch/s390/src/lib/cpu.c index 5d86bf239..c98607e16 100644 --- a/compel/arch/s390/src/lib/cpu.c +++ b/compel/arch/s390/src/lib/cpu.c @@ -9,7 +9,7 @@ #include "log.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; @@ -23,10 +23,20 @@ static void fetch_rt_cpuinfo(void) } } -void compel_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { } -void compel_clear_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { } -int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) { return 0; } -int compel_test_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) { return 0; } +void compel_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) +{ +} +void compel_clear_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) +{ +} +int compel_test_fpu_cap(compel_cpuinfo_t *info, unsigned int feature) +{ + return 0; +} +int compel_test_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) +{ + return 0; +} int compel_cpuid(compel_cpuinfo_t *info) { diff --git a/compel/arch/s390/src/lib/handle-elf.c b/compel/arch/s390/src/lib/handle-elf.c index 6ed382c92..8e766dc1b 100644 --- a/compel/arch/s390/src/lib/handle-elf.c +++ b/compel/arch/s390/src/lib/handle-elf.c @@ -5,9 +5,8 @@ #include "piegen.h" #include "log.h" -static const unsigned char __maybe_unused -elf_ident_64[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x02, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/compel/arch/s390/src/lib/infect.c b/compel/arch/s390/src/lib/infect.c index a928c72c3..77ace713a 100644 --- a/compel/arch/s390/src/lib/infect.c +++ b/compel/arch/s390/src/lib/infect.c @@ -17,25 +17,23 @@ #include "ptrace.h" #include "infect-priv.h" -#define NT_PRFPREG 2 -#define NT_S390_VXRS_LOW 0x309 -#define NT_S390_VXRS_HIGH 0x30a -#define NT_S390_GS_CB 0x30b -#define NT_S390_GS_BC 0x30c -#define NT_S390_RI_CB 0x30d +#define NT_PRFPREG 2 +#define NT_S390_VXRS_LOW 0x309 +#define NT_S390_VXRS_HIGH 0x30a +#define NT_S390_GS_CB 0x30b +#define NT_S390_GS_BC 0x30c +#define NT_S390_RI_CB 0x30d /* * Print general purpose and access registers */ -static void print_user_regs_struct(const char *msg, int pid, - user_regs_struct_t *regs) +static void print_user_regs_struct(const char *msg, int pid, user_regs_struct_t *regs) { int i; pr_debug("%s: Registers for pid=%d\n", msg, pid); - pr_debug("system_call %08lx\n", (unsigned long) regs->system_call); - pr_debug(" psw %016lx %016lx\n", regs->prstatus.psw.mask, - regs->prstatus.psw.addr); + pr_debug("system_call %08lx\n", (unsigned long)regs->system_call); + pr_debug(" psw %016lx %016lx\n", regs->prstatus.psw.mask, regs->prstatus.psw.addr); pr_debug(" orig_gpr2 %016lx\n", regs->prstatus.orig_gpr2); for (i = 0; i < 16; i++) pr_debug(" g%02d %016lx\n", i, regs->prstatus.gprs[i]); @@ -57,9 +55,7 @@ static void print_vxrs(user_fpregs_struct_t *fpregs) for (i = 0; i < 16; i++) pr_debug(" vx_low%02d %016lx\n", i, fpregs->vxrs_low[i]); for (i = 0; i < 16; i++) - pr_debug(" vx_high%02d %016lx %016lx\n", i, - fpregs->vxrs_high[i].part1, - fpregs->vxrs_high[i].part2); + pr_debug(" vx_high%02d %016lx %016lx\n", i, fpregs->vxrs_high[i].part1, fpregs->vxrs_high[i].part2); } /* @@ -111,8 +107,7 @@ static void print_ri_cb(user_fpregs_struct_t *fpregs) * Print FP registers, VX registers, guarded-storage, and * runtime-instrumentation */ -static void print_user_fpregs_struct(const char *msg, int pid, - user_fpregs_struct_t *fpregs) +static void print_user_fpregs_struct(const char *msg, int pid, user_fpregs_struct_t *fpregs) { int i; @@ -126,28 +121,19 @@ static void print_user_fpregs_struct(const char *msg, int pid, print_ri_cb(fpregs); } -int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, - user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { _sigregs_ext *dst_ext = &sigframe->uc.uc_mcontext_ext; _sigregs *dst = &sigframe->uc.uc_mcontext; - memcpy(dst->regs.gprs, regs->prstatus.gprs, - sizeof(regs->prstatus.gprs)); - memcpy(dst->regs.acrs, regs->prstatus.acrs, - sizeof(regs->prstatus.acrs)); - memcpy(&dst->regs.psw, ®s->prstatus.psw, - sizeof(regs->prstatus.psw)); - memcpy(&dst->fpregs.fpc, &fpregs->prfpreg.fpc, - sizeof(fpregs->prfpreg.fpc)); - memcpy(&dst->fpregs.fprs, &fpregs->prfpreg.fprs, - sizeof(fpregs->prfpreg.fprs)); + memcpy(dst->regs.gprs, regs->prstatus.gprs, sizeof(regs->prstatus.gprs)); + memcpy(dst->regs.acrs, regs->prstatus.acrs, sizeof(regs->prstatus.acrs)); + memcpy(&dst->regs.psw, ®s->prstatus.psw, sizeof(regs->prstatus.psw)); + memcpy(&dst->fpregs.fpc, &fpregs->prfpreg.fpc, sizeof(fpregs->prfpreg.fpc)); + memcpy(&dst->fpregs.fprs, &fpregs->prfpreg.fprs, sizeof(fpregs->prfpreg.fprs)); if (fpregs->flags & USER_FPREGS_VXRS) { - memcpy(&dst_ext->vxrs_low, &fpregs->vxrs_low, - sizeof(fpregs->vxrs_low)); - memcpy(&dst_ext->vxrs_high, &fpregs->vxrs_high, - sizeof(fpregs->vxrs_high)); + memcpy(&dst_ext->vxrs_low, &fpregs->vxrs_low, sizeof(fpregs->vxrs_low)); + memcpy(&dst_ext->vxrs_high, &fpregs->vxrs_high, sizeof(fpregs->vxrs_high)); } else { memset(&dst_ext->vxrs_low, 0, sizeof(dst_ext->vxrs_low)); memset(&dst_ext->vxrs_high, 0, sizeof(dst_ext->vxrs_high)); @@ -155,8 +141,7 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, return 0; } -int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } @@ -169,9 +154,7 @@ static inline void rewind_psw(psw_t *psw, unsigned long bytes) unsigned long mask; pr_debug("Rewind psw: %016lx bytes=%lu\n", psw->addr, bytes); - mask = (psw->mask & PSW_MASK_EA) ? -1UL : - (psw->mask & PSW_MASK_BA) ? (1UL << 31) - 1 : - (1UL << 24) - 1; + mask = (psw->mask & PSW_MASK_EA) ? -1UL : (psw->mask & PSW_MASK_BA) ? (1UL << 31) - 1 : (1UL << 24) - 1; psw->addr = (psw->addr - bytes) & mask; } @@ -310,9 +293,8 @@ static int s390_disable_ri_bit(pid_t pid, user_regs_struct_t *regs) /* * Prepare task registers for restart */ -int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *ext_regs, save_regs_t save, - void *arg, __maybe_unused unsigned long flags) +int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *ext_regs, save_regs_t save, + void *arg, __maybe_unused unsigned long flags) { user_fpregs_struct_t tmp, *fpregs = ext_regs ? ext_regs : &tmp; struct iovec iov; @@ -429,10 +411,10 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) * Injected syscall instruction */ const char code_syscall[] = { - 0x0a, 0x00, /* sc 0 */ - 0x00, 0x01, /* S390_BREAKPOINT_U16 */ - 0x00, 0x01, /* S390_BREAKPOINT_U16 */ - 0x00, 0x01, /* S390_BREAKPOINT_U16 */ + 0x0a, 0x00, /* sc 0 */ + 0x00, 0x01, /* S390_BREAKPOINT_U16 */ + 0x00, 0x01, /* S390_BREAKPOINT_U16 */ + 0x00, 0x01, /* S390_BREAKPOINT_U16 */ }; static inline void __check_code_syscall(void) @@ -444,19 +426,14 @@ static inline void __check_code_syscall(void) /* * Issue s390 system call */ -int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5, - unsigned long arg6) +int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) { user_regs_struct_t regs = ctl->orig.regs; int err; /* Load syscall number into %r1 */ - regs.prstatus.gprs[1] = (unsigned long) nr; + regs.prstatus.gprs[1] = (unsigned long)nr; /* Load parameter registers %r2-%r7 */ regs.prstatus.gprs[2] = arg1; regs.prstatus.gprs[3] = arg2; @@ -465,7 +442,7 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, regs.prstatus.gprs[6] = arg5; regs.prstatus.gprs[7] = arg6; - err = compel_execute_syscall(ctl, ®s, (char *) code_syscall); + err = compel_execute_syscall(ctl, ®s, (char *)code_syscall); /* Return code from system is in %r2 */ if (ret) @@ -476,9 +453,7 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, /* * Issue s390 mmap call */ -void *remote_mmap(struct parasite_ctl *ctl, - void *addr, size_t length, int prot, - int flags, int fd, off_t offset) +void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { void *where = (void *)ctl->ictx.syscall_ip + BUILTIN_SYSCALL_SIZE; struct mmap_arg_struct arg_struct; @@ -501,8 +476,7 @@ void *remote_mmap(struct parasite_ctl *ctl, } /* Do syscall */ - err = compel_syscall(ctl, __NR_mmap, &map, (unsigned long) where, - 0, 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_mmap, &map, (unsigned long)where, 0, 0, 0, 0, 0); if (err < 0 || (long)map < 0) map = 0; @@ -510,8 +484,7 @@ void *remote_mmap(struct parasite_ctl *ctl, if (ptrace_poke_area(pid, &arg_struct, where, sizeof(arg_struct))) { pr_err("Can't restore mmap args (pid: %d)\n", pid); if (map != 0) { - err = compel_syscall(ctl, __NR_munmap, NULL, map, - length, 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_munmap, NULL, map, length, 0, 0, 0, 0); if (err) pr_err("Can't munmap %d\n", err); map = 0; @@ -524,14 +497,12 @@ void *remote_mmap(struct parasite_ctl *ctl, /* * Setup registers for parasite call */ -void parasite_setup_regs(unsigned long new_ip, void *stack, - user_regs_struct_t *regs) +void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs) { regs->prstatus.psw.addr = new_ip; if (!stack) return; - regs->prstatus.gprs[15] = ((unsigned long) stack) - - STACK_FRAME_OVERHEAD; + regs->prstatus.gprs[15] = ((unsigned long)stack) - STACK_FRAME_OVERHEAD; } /* @@ -579,9 +550,7 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) long ret; int err; - err = compel_syscall(ctl, __NR_sigaltstack, - &ret, 0, (unsigned long)&s->uc.uc_stack, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR_sigaltstack, &ret, 0, (unsigned long)&s->uc.uc_stack, 0, 0, 0, 0); return err ? err : ret; } @@ -655,9 +624,9 @@ enum kernel_ts_level { }; /* See arch/s390/include/asm/processor.h */ -#define TASK_SIZE_LEVEL_3 0x40000000000UL /* 4 TB */ -#define TASK_SIZE_LEVEL_4 0x20000000000000UL /* 8 PB */ -#define TASK_SIZE_LEVEL_5 0xffffffffffffefffUL /* 16 EB - 0x1000 */ +#define TASK_SIZE_LEVEL_3 0x40000000000UL /* 4 TB */ +#define TASK_SIZE_LEVEL_4 0x20000000000000UL /* 8 PB */ +#define TASK_SIZE_LEVEL_5 0xffffffffffffefffUL /* 16 EB - 0x1000 */ /* * Return detected kernel version regarding task size level @@ -671,12 +640,12 @@ static enum kernel_ts_level get_kernel_ts_level(void) /* Check for 5 levels */ if (criu_end_addr >= TASK_SIZE_LEVEL_4) return KERNEL_TS_LEVEL_5; - else if (munmap((void *) TASK_SIZE_LEVEL_4, 0x1000) == 0) + else if (munmap((void *)TASK_SIZE_LEVEL_4, 0x1000) == 0) return KERNEL_TS_LEVEL_5; if (criu_end_addr < TASK_SIZE_LEVEL_3) { /* Check for 4 level kernel with fix */ - if (munmap((void *) TASK_SIZE_LEVEL_3, 0x1000) == 0) + if (munmap((void *)TASK_SIZE_LEVEL_3, 0x1000) == 0) return KERNEL_TS_LEVEL_4_FIX_YES; else return KERNEL_TS_LEVEL_4_FIX_NO; diff --git a/compel/arch/x86/plugins/std/syscalls/syscall32.c b/compel/arch/x86/plugins/std/syscalls/syscall32.c index e172cacff..0f2fec3ff 100644 --- a/compel/arch/x86/plugins/std/syscalls/syscall32.c +++ b/compel/arch/x86/plugins/std/syscalls/syscall32.c @@ -1,16 +1,16 @@ #include "asm/types.h" #include "syscall-32.h" -#define SYS_SOCKET 1 /* sys_socket(2) */ -#define SYS_BIND 2 /* sys_bind(2) */ -#define SYS_CONNECT 3 /* sys_connect(2) */ -#define SYS_SENDTO 11 /* sys_sendto(2) */ -#define SYS_RECVFROM 12 /* sys_recvfrom(2) */ -#define SYS_SHUTDOWN 13 /* sys_shutdown(2) */ -#define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */ -#define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */ -#define SYS_SENDMSG 16 /* sys_sendmsg(2) */ -#define SYS_RECVMSG 17 /* sys_recvmsg(2) */ +#define SYS_SOCKET 1 /* sys_socket(2) */ +#define SYS_BIND 2 /* sys_bind(2) */ +#define SYS_CONNECT 3 /* sys_connect(2) */ +#define SYS_SENDTO 11 /* sys_sendto(2) */ +#define SYS_RECVFROM 12 /* sys_recvfrom(2) */ +#define SYS_SHUTDOWN 13 /* sys_shutdown(2) */ +#define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */ +#define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */ +#define SYS_SENDMSG 16 /* sys_sendmsg(2) */ +#define SYS_RECVMSG 17 /* sys_recvmsg(2) */ long sys_socket(int domain, int type, int protocol) { @@ -20,59 +20,61 @@ long sys_socket(int domain, int type, int protocol) long sys_connect(int sockfd, struct sockaddr *addr, int addrlen) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)addr, (uint32_t)addrlen}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)addr, (uint32_t)addrlen }; return sys_socketcall(SYS_CONNECT, (unsigned long *)a); } long sys_sendto(int sockfd, void *buff, size_t len, unsigned int flags, struct sockaddr *addr, int addr_len) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)buff, (uint32_t)len, (uint32_t)flags, (uint32_t)addr, (uint32_t)addr_len}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)buff, (uint32_t)len, + (uint32_t)flags, (uint32_t)addr, (uint32_t)addr_len }; return sys_socketcall(SYS_SENDTO, (unsigned long *)a); } long sys_recvfrom(int sockfd, void *ubuf, size_t size, unsigned int flags, struct sockaddr *addr, int *addr_len) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)ubuf, (uint32_t)size, (uint32_t)flags, (uint32_t)addr, (uint32_t)addr_len}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)ubuf, (uint32_t)size, + (uint32_t)flags, (uint32_t)addr, (uint32_t)addr_len }; return sys_socketcall(SYS_RECVFROM, (unsigned long *)a); } long sys_sendmsg(int sockfd, const struct msghdr *msg, int flags) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)msg, (uint32_t)flags}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)msg, (uint32_t)flags }; return sys_socketcall(SYS_SENDMSG, (unsigned long *)a); } long sys_recvmsg(int sockfd, struct msghdr *msg, int flags) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)msg, (uint32_t)flags}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)msg, (uint32_t)flags }; return sys_socketcall(SYS_RECVMSG, (unsigned long *)a); } long sys_shutdown(int sockfd, int how) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)how}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)how }; return sys_socketcall(SYS_SHUTDOWN, (unsigned long *)a); } long sys_bind(int sockfd, const struct sockaddr *addr, int addrlen) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)addr, (uint32_t)addrlen}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)addr, (uint32_t)addrlen }; return sys_socketcall(SYS_BIND, (unsigned long *)a); } long sys_setsockopt(int sockfd, int level, int optname, const void *optval, unsigned int optlen) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)level, (uint32_t)optname, (uint32_t)optval, (uint32_t)optlen}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)level, (uint32_t)optname, (uint32_t)optval, (uint32_t)optlen }; return sys_socketcall(SYS_SETSOCKOPT, (unsigned long *)a); } long sys_getsockopt(int sockfd, int level, int optname, const void *optval, unsigned int *optlen) { - uint32_t a[] = {(uint32_t)sockfd, (uint32_t)level, (uint32_t)optname, (uint32_t)optval, (uint32_t)optlen}; + uint32_t a[] = { (uint32_t)sockfd, (uint32_t)level, (uint32_t)optname, (uint32_t)optval, (uint32_t)optlen }; return sys_socketcall(SYS_GETSOCKOPT, (unsigned long *)a); } -#define SHMAT 21 +#define SHMAT 21 long sys_shmat(int shmid, void *shmaddr, int shmflag) { diff --git a/compel/arch/x86/src/lib/cpu.c b/compel/arch/x86/src/lib/cpu.c index c96f01353..5ca794ea0 100644 --- a/compel/arch/x86/src/lib/cpu.c +++ b/compel/arch/x86/src/lib/cpu.c @@ -8,7 +8,7 @@ #include "log.h" #include "common/bug.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_info; @@ -29,32 +29,24 @@ static void fetch_rt_cpuinfo(void) * to save/restore PT state in Linux. */ -static const char * const xfeature_names[] = { - "x87 floating point registers" , - "SSE registers" , - "AVX registers" , - "MPX bounds registers" , - "MPX CSR" , - "AVX-512 opmask" , - "AVX-512 Hi256" , - "AVX-512 ZMM_Hi256" , - "Processor Trace" , +static const char *const xfeature_names[] = { + "x87 floating point registers", + "SSE registers", + "AVX registers", + "MPX bounds registers", + "MPX CSR", + "AVX-512 opmask", + "AVX-512 Hi256", + "AVX-512 ZMM_Hi256", + "Processor Trace", "Protection Keys User registers", - "Hardware Duty Cycling" , + "Hardware Duty Cycling", }; static short xsave_cpuid_features[] = { - X86_FEATURE_FPU, - X86_FEATURE_XMM, - X86_FEATURE_AVX, - X86_FEATURE_MPX, - X86_FEATURE_MPX, - X86_FEATURE_AVX512F, - X86_FEATURE_AVX512F, - X86_FEATURE_AVX512F, - X86_FEATURE_INTEL_PT, - X86_FEATURE_PKU, - X86_FEATURE_HDC, + X86_FEATURE_FPU, X86_FEATURE_XMM, X86_FEATURE_AVX, X86_FEATURE_MPX, + X86_FEATURE_MPX, X86_FEATURE_AVX512F, X86_FEATURE_AVX512F, X86_FEATURE_AVX512F, + X86_FEATURE_INTEL_PT, X86_FEATURE_PKU, X86_FEATURE_HDC, }; void compel_set_cpu_cap(compel_cpuinfo_t *c, unsigned int feature) @@ -89,8 +81,7 @@ static int compel_fpuid(compel_cpuinfo_t *c) uint32_t eax, ebx, ecx, edx; size_t i; - BUILD_BUG_ON(ARRAY_SIZE(xsave_cpuid_features) != - ARRAY_SIZE(xfeature_names)); + BUILD_BUG_ON(ARRAY_SIZE(xsave_cpuid_features) != ARRAY_SIZE(xfeature_names)); if (!compel_test_cpu_cap(c, X86_FEATURE_FPU)) { pr_err("fpu: No FPU detected\n"); @@ -98,9 +89,7 @@ static int compel_fpuid(compel_cpuinfo_t *c) } if (!compel_test_cpu_cap(c, X86_FEATURE_XSAVE)) { - pr_info("fpu: x87 FPU will use %s\n", - compel_test_cpu_cap(c, X86_FEATURE_FXSR) ? - "FXSAVE" : "FSAVE"); + pr_info("fpu: x87 FPU will use %s\n", compel_test_cpu_cap(c, X86_FEATURE_FXSR) ? "FXSAVE" : "FSAVE"); return 0; } @@ -140,12 +129,11 @@ static int compel_fpuid(compel_cpuinfo_t *c) c->xsaves_size = ebx; pr_debug("fpu: xfeatures_mask 0x%llx xsave_size %u xsave_size_max %u xsaves_size %u\n", - (unsigned long long)c->xfeatures_mask, - c->xsave_size, c->xsave_size_max, c->xsaves_size); + (unsigned long long)c->xfeatures_mask, c->xsave_size, c->xsave_size_max, c->xsaves_size); if (c->xsave_size_max > sizeof(struct xsave_struct)) - pr_warn_once("fpu: max xsave frame exceed xsave_struct (%u %u)\n", - c->xsave_size_max, (unsigned)sizeof(struct xsave_struct)); + pr_warn_once("fpu: max xsave frame exceed xsave_struct (%u %u)\n", c->xsave_size_max, + (unsigned)sizeof(struct xsave_struct)); memset(c->xstate_offsets, 0xff, sizeof(c->xstate_offsets)); memset(c->xstate_sizes, 0xff, sizeof(c->xstate_sizes)); @@ -160,10 +148,10 @@ static int compel_fpuid(compel_cpuinfo_t *c) * in the fixed offsets in the xsave area in either compacted form * or standard form. */ - c->xstate_offsets[0] = 0; - c->xstate_sizes[0] = offsetof(struct i387_fxsave_struct, xmm_space); - c->xstate_offsets[1] = c->xstate_sizes[0]; - c->xstate_sizes[1] = FIELD_SIZEOF(struct i387_fxsave_struct, xmm_space); + c->xstate_offsets[0] = 0; + c->xstate_sizes[0] = offsetof(struct i387_fxsave_struct, xmm_space); + c->xstate_offsets[1] = c->xstate_sizes[0]; + c->xstate_sizes[1] = FIELD_SIZEOF(struct i387_fxsave_struct, xmm_space); for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { if (!(c->xfeatures_mask & (1UL << i))) @@ -189,8 +177,7 @@ static int compel_fpuid(compel_cpuinfo_t *c) * highest offset in the buffer. Ensure it does. */ if (last_good_offset > c->xstate_offsets[i]) - pr_warn_once("fpu: misordered xstate %d %d\n", - last_good_offset, c->xstate_offsets[i]); + pr_warn_once("fpu: misordered xstate %d %d\n", last_good_offset, c->xstate_offsets[i]); last_good_offset = c->xstate_offsets[i]; } @@ -198,10 +185,10 @@ static int compel_fpuid(compel_cpuinfo_t *c) BUILD_BUG_ON(sizeof(c->xstate_offsets) != sizeof(c->xstate_sizes)); BUILD_BUG_ON(sizeof(c->xstate_comp_offsets) != sizeof(c->xstate_comp_sizes)); - c->xstate_comp_offsets[0] = 0; - c->xstate_comp_sizes[0] = offsetof(struct i387_fxsave_struct, xmm_space); - c->xstate_comp_offsets[1] = c->xstate_comp_sizes[0]; - c->xstate_comp_sizes[1] = FIELD_SIZEOF(struct i387_fxsave_struct, xmm_space); + c->xstate_comp_offsets[0] = 0; + c->xstate_comp_sizes[0] = offsetof(struct i387_fxsave_struct, xmm_space); + c->xstate_comp_offsets[1] = c->xstate_comp_sizes[0]; + c->xstate_comp_sizes[1] = FIELD_SIZEOF(struct i387_fxsave_struct, xmm_space); if (!compel_test_cpu_cap(c, X86_FEATURE_XSAVES)) { for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { @@ -211,8 +198,7 @@ static int compel_fpuid(compel_cpuinfo_t *c) } } } else { - c->xstate_comp_offsets[FIRST_EXTENDED_XFEATURE] = - FXSAVE_SIZE + XSAVE_HDR_SIZE; + c->xstate_comp_offsets[FIRST_EXTENDED_XFEATURE] = FXSAVE_SIZE + XSAVE_HDR_SIZE; for (i = FIRST_EXTENDED_XFEATURE; i < XFEATURE_MAX; i++) { if ((c->xfeatures_mask & (1UL << i))) @@ -221,8 +207,7 @@ static int compel_fpuid(compel_cpuinfo_t *c) c->xstate_comp_sizes[i] = 0; if (i > FIRST_EXTENDED_XFEATURE) { - c->xstate_comp_offsets[i] = c->xstate_comp_offsets[i-1] - + c->xstate_comp_sizes[i-1]; + c->xstate_comp_offsets[i] = c->xstate_comp_offsets[i - 1] + c->xstate_comp_sizes[i - 1]; /* * The value returned by ECX[1] indicates the alignment @@ -240,9 +225,9 @@ static int compel_fpuid(compel_cpuinfo_t *c) for (i = 0; i < ARRAY_SIZE(c->xstate_offsets); i++) { if (!(c->xfeatures_mask & (1UL << i))) continue; - pr_debug("fpu: %-32s xstate_offsets %6d / %-6d xstate_sizes %6d / %-6d\n", - xfeature_names[i], c->xstate_offsets[i], c->xstate_comp_offsets[i], - c->xstate_sizes[i], c->xstate_comp_sizes[i]); + pr_debug("fpu: %-32s xstate_offsets %6d / %-6d xstate_sizes %6d / %-6d\n", xfeature_names[i], + c->xstate_offsets[i], c->xstate_comp_offsets[i], c->xstate_sizes[i], + c->xstate_comp_sizes[i]); } } @@ -261,20 +246,15 @@ int compel_cpuid(compel_cpuinfo_t *c) */ /* Get vendor name */ - cpuid(0x00000000, - (unsigned int *)&c->cpuid_level, - (unsigned int *)&c->x86_vendor_id[0], - (unsigned int *)&c->x86_vendor_id[8], - (unsigned int *)&c->x86_vendor_id[4]); + cpuid(0x00000000, (unsigned int *)&c->cpuid_level, (unsigned int *)&c->x86_vendor_id[0], + (unsigned int *)&c->x86_vendor_id[8], (unsigned int *)&c->x86_vendor_id[4]); if (!strcmp(c->x86_vendor_id, "GenuineIntel")) { c->x86_vendor = X86_VENDOR_INTEL; - } else if (!strcmp(c->x86_vendor_id, "AuthenticAMD") || - !strcmp(c->x86_vendor_id, "HygonGenuine")) { + } else if (!strcmp(c->x86_vendor_id, "AuthenticAMD") || !strcmp(c->x86_vendor_id, "HygonGenuine")) { c->x86_vendor = X86_VENDOR_AMD; } else { - pr_err("Unsupported CPU vendor %s\n", - c->x86_vendor_id); + pr_err("Unsupported CPU vendor %s\n", c->x86_vendor_id); return -1; } @@ -369,7 +349,7 @@ int compel_cpuid(compel_cpuinfo_t *c) while (*p) *q++ = *p++; while (q <= &c->x86_model_id[48]) - *q++ = '\0'; /* Zero-pad the rest */ + *q++ = '\0'; /* Zero-pad the rest */ } } @@ -440,8 +420,7 @@ int compel_cpuid(compel_cpuinfo_t *c) break; } - pr_debug("x86_family %u x86_vendor_id %s x86_model_id %s\n", - c->x86_family, c->x86_vendor_id, c->x86_model_id); + pr_debug("x86_family %u x86_vendor_id %s x86_model_id %s\n", c->x86_family, c->x86_vendor_id, c->x86_model_id); return compel_fpuid(c); } @@ -461,8 +440,7 @@ bool compel_fpu_has_feature(unsigned int feature) uint32_t compel_fpu_feature_size(unsigned int feature) { fetch_rt_cpuinfo(); - if (feature >= FIRST_EXTENDED_XFEATURE && - feature < XFEATURE_MAX) + if (feature >= FIRST_EXTENDED_XFEATURE && feature < XFEATURE_MAX) return rt_info.xstate_sizes[feature]; return 0; } @@ -470,8 +448,7 @@ uint32_t compel_fpu_feature_size(unsigned int feature) uint32_t compel_fpu_feature_offset(unsigned int feature) { fetch_rt_cpuinfo(); - if (feature >= FIRST_EXTENDED_XFEATURE && - feature < XFEATURE_MAX) + if (feature >= FIRST_EXTENDED_XFEATURE && feature < XFEATURE_MAX) return rt_info.xstate_offsets[feature]; return 0; } diff --git a/compel/arch/x86/src/lib/handle-elf.c b/compel/arch/x86/src/lib/handle-elf.c index 938999b2e..78b23f28a 100644 --- a/compel/arch/x86/src/lib/handle-elf.c +++ b/compel/arch/x86/src/lib/handle-elf.c @@ -5,9 +5,8 @@ #include "piegen.h" #include "log.h" -static const unsigned char __maybe_unused -elf_ident_64_le[EI_NIDENT] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, +static const unsigned char __maybe_unused elf_ident_64_le[EI_NIDENT] = { + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, /* clang-format */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/compel/arch/x86/src/lib/infect.c b/compel/arch/x86/src/lib/infect.c index 566238d2d..1e344bf3a 100644 --- a/compel/arch/x86/src/lib/infect.c +++ b/compel/arch/x86/src/lib/infect.c @@ -24,29 +24,27 @@ #include "log.h" #ifndef NT_X86_XSTATE -#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ +#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ #endif #ifndef NT_PRSTATUS -#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ +#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ #endif /* * Injected syscall instruction */ const char code_syscall[] = { - 0x0f, 0x05, /* syscall */ - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc /* int 3, ... */ + 0x0f, 0x05, /* syscall */ + 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc /* int 3, ... */ }; const char code_int_80[] = { - 0xcd, 0x80, /* int $0x80 */ - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc /* int 3, ... */ + 0xcd, 0x80, /* int $0x80 */ + 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc /* int 3, ... */ }; -static const int -code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long)); -static const int -code_int_80_aligned = round_up(sizeof(code_syscall), sizeof(long)); +static const int code_syscall_aligned = round_up(sizeof(code_syscall), sizeof(long)); +static const int code_int_80_aligned = round_up(sizeof(code_syscall), sizeof(long)); static inline __always_unused void __check_code_syscall(void) { @@ -57,22 +55,22 @@ static inline __always_unused void __check_code_syscall(void) /* 10-byte legacy floating point register */ struct fpreg { - uint16_t significand[4]; - uint16_t exponent; + uint16_t significand[4]; + uint16_t exponent; }; /* 16-byte floating point register */ struct fpxreg { - uint16_t significand[4]; - uint16_t exponent; - uint16_t padding[3]; + uint16_t significand[4]; + uint16_t exponent; + uint16_t padding[3]; }; -#define FPREG_ADDR(f, n) ((void *)&(f)->st_space + (n) * 16) -#define FP_EXP_TAG_VALID 0 -#define FP_EXP_TAG_ZERO 1 -#define FP_EXP_TAG_SPECIAL 2 -#define FP_EXP_TAG_EMPTY 3 +#define FPREG_ADDR(f, n) ((void *)&(f)->st_space + (n)*16) +#define FP_EXP_TAG_VALID 0 +#define FP_EXP_TAG_ZERO 1 +#define FP_EXP_TAG_SPECIAL 2 +#define FP_EXP_TAG_EMPTY 3 static inline uint32_t twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) { @@ -92,9 +90,7 @@ static inline uint32_t twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) tag = FP_EXP_TAG_SPECIAL; break; case 0x0000: - if (!st->significand[0] && - !st->significand[1] && - !st->significand[2] && + if (!st->significand[0] && !st->significand[1] && !st->significand[2] && !st->significand[3]) tag = FP_EXP_TAG_ZERO; else @@ -115,8 +111,7 @@ static inline uint32_t twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) return ret; } -void compel_convert_from_fxsr(struct user_i387_ia32_struct *env, - struct i387_fxsave_struct *fxsave) +void compel_convert_from_fxsr(struct user_i387_ia32_struct *env, struct i387_fxsave_struct *fxsave) { struct fpxreg *from = (struct fpxreg *)&fxsave->st_space[0]; struct fpreg *to = (struct fpreg *)env->st_space; @@ -140,16 +135,12 @@ void compel_convert_from_fxsr(struct user_i387_ia32_struct *env, memcpy(&to[i], &from[i], sizeof(to[0])); } -int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, - user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs) +int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { bool is_native = user_regs_native(regs); - fpu_state_t *fpu_state = is_native ? - &sigframe->native.fpu_state : - &sigframe->compat.fpu_state; + fpu_state_t *fpu_state = is_native ? &sigframe->native.fpu_state : &sigframe->compat.fpu_state; if (is_native) { -#define cpreg64_native(d, s) sigframe->native.uc.uc_mcontext.d = regs->native.s +#define cpreg64_native(d, s) sigframe->native.uc.uc_mcontext.d = regs->native.s cpreg64_native(rdi, di); cpreg64_native(rsi, si); cpreg64_native(rbp, bp); @@ -173,7 +164,7 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, sigframe->is_native = true; #undef cpreg64_native } else { -#define cpreg32_compat(d) sigframe->compat.uc.uc_mcontext.d = regs->compat.d +#define cpreg32_compat(d) sigframe->compat.uc.uc_mcontext.d = regs->compat.d cpreg32_compat(gs); cpreg32_compat(fs); cpreg32_compat(es); @@ -206,34 +197,28 @@ int sigreturn_prep_regs_plain(struct rt_sigframe *sigframe, return 0; } -int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame_plain(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { - fpu_state_t *fpu_state = (sigframe->is_native) ? - &rsigframe->native.fpu_state : - &rsigframe->compat.fpu_state; + fpu_state_t *fpu_state = (sigframe->is_native) ? &rsigframe->native.fpu_state : &rsigframe->compat.fpu_state; if (sigframe->is_native) { unsigned long addr = (unsigned long)(void *)&fpu_state->fpu_state_64.xsave; if ((addr % 64ul)) { - pr_err("Unaligned address passed: %lx (native %d)\n", - addr, sigframe->is_native); + pr_err("Unaligned address passed: %lx (native %d)\n", addr, sigframe->is_native); return -1; } sigframe->native.uc.uc_mcontext.fpstate = (uint64_t)addr; } else if (!sigframe->is_native) { - sigframe->compat.uc.uc_mcontext.fpstate = - (uint32_t)(unsigned long)(void *)&fpu_state->fpu_state_ia32; + sigframe->compat.uc.uc_mcontext.fpstate = (uint32_t)(unsigned long)(void *)&fpu_state->fpu_state_ia32; } return 0; } -#define get_signed_user_reg(pregs, name) \ - ((user_regs_native(pregs)) ? (int64_t)((pregs)->native.name) : \ - (int32_t)((pregs)->compat.name)) +#define get_signed_user_reg(pregs, name) \ + ((user_regs_native(pregs)) ? (int64_t)((pregs)->native.name) : (int32_t)((pregs)->compat.name)) static int get_task_xsave(pid_t pid, user_fpregs_struct_t *xsave) { @@ -310,8 +295,7 @@ static int corrupt_extregs(pid_t pid) * - zdtm.py will grep it auto-magically from logs * (and the seed will be known from an automatical testing) */ - pr_err("Corrupting %s for %d, seed %u\n", - use_xsave ? "xsave" : "fpuregs", pid, seed); + pr_err("Corrupting %s for %d, seed %u\n", use_xsave ? "xsave" : "fpuregs", pid, seed); if (!use_xsave) { if (ptrace(PTRACE_SETFPREGS, pid, NULL, &ext_regs)) { @@ -334,15 +318,13 @@ static int corrupt_extregs(pid_t pid) return 0; } -int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, - user_fpregs_struct_t *ext_regs, save_regs_t save, - void *arg, unsigned long flags) +int compel_get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *ext_regs, save_regs_t save, + void *arg, unsigned long flags) { - user_fpregs_struct_t xsave = { }, *xs = ext_regs ? ext_regs : &xsave; + user_fpregs_struct_t xsave = {}, *xs = ext_regs ? ext_regs : &xsave; int ret = -1; - pr_info("Dumping general registers for %d in %s mode\n", pid, - user_regs_native(regs) ? "native" : "compat"); + pr_info("Dumping general registers for %d in %s mode\n", pid, user_regs_native(regs) ? "native" : "compat"); /* Did we come from a system call? */ if (get_signed_user_reg(regs, orig_ax) >= 0) { @@ -423,13 +405,8 @@ int compel_set_task_ext_regs(pid_t pid, user_fpregs_struct_t *ext_regs) return 0; } -int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5, - unsigned long arg6) +int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) { user_regs_struct_t regs = ctl->orig.regs; bool native = user_regs_native(®s); @@ -438,51 +415,47 @@ int compel_syscall(struct parasite_ctl *ctl, int nr, long *ret, if (native) { user_regs_struct64 *r = ®s.native; - r->ax = (uint64_t)nr; - r->di = arg1; - r->si = arg2; - r->dx = arg3; + r->ax = (uint64_t)nr; + r->di = arg1; + r->si = arg2; + r->dx = arg3; r->r10 = arg4; - r->r8 = arg5; - r->r9 = arg6; + r->r8 = arg5; + r->r9 = arg6; err = compel_execute_syscall(ctl, ®s, code_syscall); } else { user_regs_struct32 *r = ®s.compat; - r->ax = (uint32_t)nr; - r->bx = arg1; - r->cx = arg2; - r->dx = arg3; - r->si = arg4; - r->di = arg5; - r->bp = arg6; + r->ax = (uint32_t)nr; + r->bx = arg1; + r->cx = arg2; + r->dx = arg3; + r->si = arg4; + r->di = arg5; + r->bp = arg6; err = compel_execute_syscall(ctl, ®s, code_int_80); } - *ret = native ? - (long)get_user_reg(®s, ax) : - (int)get_user_reg(®s, ax); + *ret = native ? (long)get_user_reg(®s, ax) : (int)get_user_reg(®s, ax); return err; } -void *remote_mmap(struct parasite_ctl *ctl, - void *addr, size_t length, int prot, - int flags, int fd, off_t offset) +void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { long map; int err; bool compat_task = !user_regs_native(&ctl->orig.regs); - err = compel_syscall(ctl, __NR(mmap, compat_task), &map, - (unsigned long)addr, length, prot, flags, fd, offset); + err = compel_syscall(ctl, __NR(mmap, compat_task), &map, (unsigned long)addr, length, prot, flags, fd, offset); if (err < 0) return NULL; if (map == -EACCES && (prot & PROT_WRITE) && (prot & PROT_EXEC)) { pr_warn("mmap(PROT_WRITE | PROT_EXEC) failed for %d, " - "check selinux execmem policy\n", ctl->rpid); + "check selinux execmem policy\n", + ctl->rpid); return NULL; } if (IS_ERR_VALUE(map)) { @@ -507,18 +480,17 @@ void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t * { set_user_reg(regs, ip, new_ip); if (stack) - set_user_reg(regs, sp, (unsigned long) stack); + set_user_reg(regs, sp, (unsigned long)stack); /* Avoid end of syscall processing */ set_user_reg(regs, orig_ax, -1); /* Make sure flags are in known state */ - set_user_reg(regs, flags, get_user_reg(regs, flags) & - ~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF)); + set_user_reg(regs, flags, get_user_reg(regs, flags) & ~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF)); } -#define USER32_CS 0x23 -#define USER_CS 0x33 +#define USER32_CS 0x23 +#define USER_CS 0x33 static bool ldt_task_selectors(pid_t pid) { @@ -574,30 +546,26 @@ bool arch_can_dump_task(struct parasite_ctl *ctl) int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) { int native = compel_mode_native(ctl); - void *where = native ? - (void *)&s->native.uc.uc_stack : - (void *)&s->compat.uc.uc_stack; + void *where = native ? (void *)&s->native.uc.uc_stack : (void *)&s->compat.uc.uc_stack; long ret; int err; - err = compel_syscall(ctl, __NR(sigaltstack, !native), - &ret, 0, (unsigned long)where, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR(sigaltstack, !native), &ret, 0, (unsigned long)where, 0, 0, 0, 0); return err ? err : ret; } /* Copied from the gdb header gdb/nat/x86-dregs.h */ /* Debug registers' indices. */ -#define DR_FIRSTADDR 0 -#define DR_LASTADDR 3 -#define DR_NADDR 4 /* The number of debug address registers. */ -#define DR_STATUS 6 /* Index of debug status register (DR6). */ -#define DR_CONTROL 7 /* Index of debug control register (DR7). */ +#define DR_FIRSTADDR 0 +#define DR_LASTADDR 3 +#define DR_NADDR 4 /* The number of debug address registers. */ +#define DR_STATUS 6 /* Index of debug status register (DR6). */ +#define DR_CONTROL 7 /* Index of debug control register (DR7). */ -#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ -#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ -#define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ +#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ +#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ +#define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ /* Locally enable the break/watchpoint in the I'th debug register. */ #define X86_DR_LOCAL_ENABLE(i) (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))) @@ -607,17 +575,14 @@ int ptrace_set_breakpoint(pid_t pid, void *addr) int ret; /* Set a breakpoint */ - if (ptrace(PTRACE_POKEUSER, pid, - offsetof(struct user, u_debugreg[DR_FIRSTADDR]), - addr)) { + if (ptrace(PTRACE_POKEUSER, pid, offsetof(struct user, u_debugreg[DR_FIRSTADDR]), addr)) { pr_perror("Unable to setup a breakpoint into %d", pid); return -1; } /* Enable the breakpoint */ - if (ptrace(PTRACE_POKEUSER, pid, - offsetof(struct user, u_debugreg[DR_CONTROL]), - X86_DR_LOCAL_ENABLE(DR_FIRSTADDR))) { + if (ptrace(PTRACE_POKEUSER, pid, offsetof(struct user, u_debugreg[DR_CONTROL]), + X86_DR_LOCAL_ENABLE(DR_FIRSTADDR))) { pr_perror("Unable to enable the breakpoint for %d", pid); return -1; } @@ -634,9 +599,7 @@ int ptrace_set_breakpoint(pid_t pid, void *addr) int ptrace_flush_breakpoints(pid_t pid) { /* Disable the breakpoint */ - if (ptrace(PTRACE_POKEUSER, pid, - offsetof(struct user, u_debugreg[DR_CONTROL]), - 0)) { + if (ptrace(PTRACE_POKEUSER, pid, offsetof(struct user, u_debugreg[DR_CONTROL]), 0)) { pr_perror("Unable to disable the breakpoint for %d", pid); return -1; } @@ -668,8 +631,7 @@ int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs) } pr_err("PTRACE_GETREGSET read %zu bytes for pid %d, but native/compat regs sizes are %zu/%zu bytes\n", - iov.iov_len, pid, - sizeof(regs->native), sizeof(regs->compat)); + iov.iov_len, pid, sizeof(regs->native), sizeof(regs->compat)); return -1; } @@ -687,11 +649,14 @@ int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs) return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov); } -#define TASK_SIZE ((1UL << 47) - PAGE_SIZE) +#define TASK_SIZE ((1UL << 47) - PAGE_SIZE) /* * Task size may be limited to 3G but we need a * higher limit, because it's backward compatible. */ -#define TASK_SIZE_IA32 (0xffffe000) +#define TASK_SIZE_IA32 (0xffffe000) -unsigned long compel_task_size(void) { return TASK_SIZE; } +unsigned long compel_task_size(void) +{ + return TASK_SIZE; +} diff --git a/compel/arch/x86/src/lib/thread_area.c b/compel/arch/x86/src/lib/thread_area.c index 3ff5dc5d4..4750c6cdd 100644 --- a/compel/arch/x86/src/lib/thread_area.c +++ b/compel/arch/x86/src/lib/thread_area.c @@ -8,7 +8,7 @@ #include "infect-priv.h" #ifndef PTRACE_GET_THREAD_AREA -# define PTRACE_GET_THREAD_AREA 25 +#define PTRACE_GET_THREAD_AREA 25 #endif /* @@ -49,12 +49,10 @@ int __compel_arch_fetch_thread_area(int tid, struct thread_ctx *th) d->entry_number = GDT_ENTRY_TLS_MIN + i; } - for (i = 0; i < GDT_ENTRY_TLS_NUM; i++) - { + for (i = 0; i < GDT_ENTRY_TLS_NUM; i++) { user_desc_t *d = &ptls->desc[i]; - err = ptrace(PTRACE_GET_THREAD_AREA, tid, - GDT_ENTRY_TLS_MIN + i, d); + err = ptrace(PTRACE_GET_THREAD_AREA, tid, GDT_ENTRY_TLS_MIN + i, d); /* * Ignoring absent syscall on !CONFIG_IA32_EMULATION * where such mixed code can't run. diff --git a/compel/plugins/fds/fds.c b/compel/plugins/fds/fds.c index 7ed94509d..c0c6a2131 100644 --- a/compel/plugins/fds/fds.c +++ b/compel/plugins/fds/fds.c @@ -9,8 +9,8 @@ #include "common/compiler.h" #include "common/bug.h" -#define __sys(foo) sys_##foo -#define __sys_err(ret) ret +#define __sys(foo) sys_##foo +#define __sys_err(ret) ret #include "common/scm.h" diff --git a/compel/plugins/shmem/shmem.c b/compel/plugins/shmem/shmem.c index 695d1931f..2b402f926 100644 --- a/compel/plugins/shmem/shmem.c +++ b/compel/plugins/shmem/shmem.c @@ -12,8 +12,7 @@ void *shmem_create(unsigned long size) void *mem; struct shmem_plugin_msg spi; - mem = (void *)sys_mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + mem = (void *)sys_mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (mem == MAP_FAILED) return NULL; diff --git a/compel/plugins/std/fds.c b/compel/plugins/std/fds.c index 499102788..6a0757992 100644 --- a/compel/plugins/std/fds.c +++ b/compel/plugins/std/fds.c @@ -10,7 +10,7 @@ #include "common/compiler.h" #include "common/bug.h" -#define __sys(foo) sys_##foo -#define __sys_err(ret) ret +#define __sys(foo) sys_##foo +#define __sys_err(ret) ret #include "common/scm-code.c" diff --git a/compel/plugins/std/infect.c b/compel/plugins/std/infect.c index 9749db7b7..abecc140f 100644 --- a/compel/plugins/std/infect.c +++ b/compel/plugins/std/infect.c @@ -5,9 +5,9 @@ #include "common/lock.h" #include "common/page.h" -#define pr_err(fmt, ...) print_on_level(1, fmt, ##__VA_ARGS__) -#define pr_info(fmt, ...) print_on_level(3, fmt, ##__VA_ARGS__) -#define pr_debug(fmt, ...) print_on_level(4, fmt, ##__VA_ARGS__) +#define pr_err(fmt, ...) print_on_level(1, fmt, ##__VA_ARGS__) +#define pr_info(fmt, ...) print_on_level(3, fmt, ##__VA_ARGS__) +#define pr_debug(fmt, ...) print_on_level(4, fmt, ##__VA_ARGS__) #include "common/bug.h" @@ -51,8 +51,7 @@ static int __parasite_daemon_reply_ack(unsigned int cmd, int err) return -1; } - pr_debug("__sent ack msg: %d %d %d\n", - m.cmd, m.ack, m.err); + pr_debug("__sent ack msg: %d %d %d\n", m.cmd, m.ack, m.err); return 0; } @@ -64,16 +63,14 @@ static int __parasite_daemon_wait_msg(struct ctl_msg *m) pr_debug("Daemon waits for command\n"); while (1) { - *m = (struct ctl_msg){ }; + *m = (struct ctl_msg){}; ret = sys_recvfrom(tsock, m, sizeof(*m), MSG_WAITALL, NULL, 0); if (ret != sizeof(*m)) { - pr_err("Trimmed message received (%d/%d)\n", - (int)sizeof(*m), ret); + pr_err("Trimmed message received (%d/%d)\n", (int)sizeof(*m), ret); return -1; } - pr_debug("__fetched msg: %d %d %d\n", - m->cmd, m->ack, m->err); + pr_debug("__fetched msg: %d %d %d\n", m->cmd, m->ack, m->err); return 0; } @@ -94,8 +91,7 @@ static int fini(void) parasite_cleanup(); new_sp = (long)sigframe + RT_SIGFRAME_OFFSET(sigframe); - pr_debug("%ld: new_sp=%lx ip %lx\n", sys_gettid(), - new_sp, RT_SIGFRAME_REGIP(sigframe)); + pr_debug("%ld: new_sp=%lx ip %lx\n", sys_gettid(), new_sp, RT_SIGFRAME_REGIP(sigframe)); sys_close(tsock); std_log_set_fd(-1); @@ -155,7 +151,7 @@ static noinline __used int parasite_init_daemon(void *data) int ret; args->sigreturn_addr = (uint64_t)(uintptr_t)fini_sigreturn; - sigframe = (void*)(uintptr_t)args->sigframe; + sigframe = (void *)(uintptr_t)args->sigframe; #ifdef ARCH_HAS_LONG_PAGES __page_size = args->page_size; #endif @@ -193,7 +189,7 @@ err: } #ifndef __parasite_entry -# define __parasite_entry +#define __parasite_entry #endif /* @@ -205,7 +201,7 @@ err: * initialization. Otherwise, we end up with COMMON symbols. */ unsigned int __export_parasite_service_cmd = 0; -void * __export_parasite_service_args_ptr = NULL; +void *__export_parasite_service_args_ptr = NULL; int __used __parasite_entry parasite_service(void) { diff --git a/compel/plugins/std/std.c b/compel/plugins/std/std.c index 82f51eac4..01f88ef80 100644 --- a/compel/plugins/std/std.c +++ b/compel/plugins/std/std.c @@ -46,11 +46,9 @@ err: return ret; } -#define plugin_init_count(size) ((size) / (sizeof(plugin_init_t *))) +#define plugin_init_count(size) ((size) / (sizeof(plugin_init_t *))) -int __export_std_compel_start(struct prologue_init_args *args, - const plugin_init_t * const *init_array, - size_t init_size) +int __export_std_compel_start(struct prologue_init_args *args, const plugin_init_t *const *init_array, size_t init_size) { unsigned int i; int ret = 0; diff --git a/compel/plugins/std/string.c b/compel/plugins/std/string.c index 85bede803..bde1bc68b 100644 --- a/compel/plugins/std/string.c +++ b/compel/plugins/std/string.c @@ -100,18 +100,11 @@ void std_vdprintf(int fd, const char *format, va_list args) std_dputs(fd, va_arg(args, char *)); break; case 'd': - __std_vprint_long(buf, sizeof(buf), - along ? - va_arg(args, long) : - (long)va_arg(args, int), - &t); + __std_vprint_long(buf, sizeof(buf), along ? va_arg(args, long) : (long)va_arg(args, int), &t); std_dputs(fd, t); break; case 'x': - __std_vprint_long_hex(buf, sizeof(buf), - along ? - va_arg(args, long) : - (long)va_arg(args, int), + __std_vprint_long_hex(buf, sizeof(buf), along ? va_arg(args, long) : (long)va_arg(args, int), &t); std_dputs(fd, t); break; @@ -130,9 +123,7 @@ void std_dprintf(int fd, const char *format, ...) static inline bool __isspace(unsigned char c) { - return c == ' ' || c == '\f' || - c == '\n' || c == '\r' || - c == '\t' || c == '\v'; + return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'; } static unsigned char __tolower(unsigned char c) @@ -142,8 +133,7 @@ static unsigned char __tolower(unsigned char c) static inline bool __isalpha(unsigned char c) { - return ((c <= 'Z' && c >= 'A') || - (c <= 'z' && c >= 'a')); + return ((c <= 'Z' && c >= 'A') || (c <= 'z' && c >= 'a')); } static inline bool __isdigit(unsigned char c) @@ -208,7 +198,7 @@ unsigned long std_strtoul(const char *nptr, char **endptr, int base) if (__isspace(*s)) continue; if (!__isalnum(*s)) - goto fin; + goto fin; v = __conv_val(*s); if (v == -1u || v > base) goto fin; @@ -222,7 +212,6 @@ fin: return neg ? (unsigned long)-num : (unsigned long)num; } - /* * C compiler is free to insert implicit calls to memcmp, memset, * memcpy and memmove, assuming they are available during linking. @@ -267,7 +256,7 @@ void *memset(void *s, const int c, size_t count) size_t i = 0; while (i < count) - dest[i++] = (char) c; + dest[i++] = (char)c; return s; } diff --git a/compel/src/lib/handle-elf.c b/compel/src/lib/handle-elf.c index 9a972bee6..9662751e0 100644 --- a/compel/src/lib/handle-elf.c +++ b/compel/src/lib/handle-elf.c @@ -28,44 +28,39 @@ static bool __ptr_oob(const uintptr_t ptr, const uintptr_t start, const size_t s } /* Check if pointed structure's end is out-of-bound */ -static bool __ptr_struct_end_oob(const uintptr_t ptr, const size_t struct_size, - const uintptr_t start, const size_t size) +static bool __ptr_struct_end_oob(const uintptr_t ptr, const size_t struct_size, const uintptr_t start, + const size_t size) { /* the last byte of the structure should be inside [begin, end) */ return __ptr_oob(ptr + struct_size - 1, start, size); } /* Check if pointed structure is out-of-bound */ -static bool __ptr_struct_oob(const uintptr_t ptr, const size_t struct_size, - const uintptr_t start, const size_t size) +static bool __ptr_struct_oob(const uintptr_t ptr, const size_t struct_size, const uintptr_t start, const size_t size) { - return __ptr_oob(ptr, start, size) || - __ptr_struct_end_oob(ptr, struct_size, start, size); + return __ptr_oob(ptr, start, size) || __ptr_struct_end_oob(ptr, struct_size, start, size); } -static bool test_pointer(const void *ptr, const void *start, const size_t size, - const char *name, const char *file, const int line) +static bool test_pointer(const void *ptr, const void *start, const size_t size, const char *name, const char *file, + const int line) { if (__ptr_oob((const uintptr_t)ptr, (const uintptr_t)start, size)) { - pr_err("Corrupted pointer %p (%s) at %s:%d\n", - ptr, name, file, line); + pr_err("Corrupted pointer %p (%s) at %s:%d\n", ptr, name, file, line); return true; } return false; } -#define ptr_func_exit(__ptr) \ - do { \ - if (test_pointer((__ptr), mem, size, #__ptr, \ - __FILE__, __LINE__)) { \ - free(sec_hdrs); \ - return -1; \ - } \ +#define ptr_func_exit(__ptr) \ + do { \ + if (test_pointer((__ptr), mem, size, #__ptr, __FILE__, __LINE__)) { \ + free(sec_hdrs); \ + return -1; \ + } \ } while (0) #ifdef ELF_PPC64 -static int do_relative_toc(long value, uint16_t *location, - unsigned long mask, int complain_signed) +static int do_relative_toc(long value, uint16_t *location, unsigned long mask, int complain_signed) { if (complain_signed && (value + 0x8000 > 0xffff)) { pr_err("TOC16 relocation overflows (%ld)\n", value); @@ -73,8 +68,7 @@ static int do_relative_toc(long value, uint16_t *location, } if ((~mask & 0xffff) & value) { - pr_err("bad TOC16 relocation (%ld) (0x%lx)\n", - value, (~mask & 0xffff) & value); + pr_err("bad TOC16 relocation (%ld) (0x%lx)\n", value, (~mask & 0xffff) & value); return -1; } @@ -89,23 +83,24 @@ static bool is_header_supported(Elf_Ehdr *hdr) return false; if ((hdr->e_type != ET_REL #ifdef NO_RELOCS - && hdr->e_type != ET_EXEC + && hdr->e_type != ET_EXEC #endif - ) || hdr->e_version != EV_CURRENT) + ) || + hdr->e_version != EV_CURRENT) return false; return true; } static const char *get_strings_section(Elf_Ehdr *hdr, uintptr_t mem, size_t size) { - size_t sec_table_size = ((size_t) hdr->e_shentsize) * hdr->e_shnum; + size_t sec_table_size = ((size_t)hdr->e_shentsize) * hdr->e_shnum; uintptr_t sec_table = mem + hdr->e_shoff; Elf_Shdr *secstrings_hdr; uintptr_t addr; if (__ptr_struct_oob(sec_table, sec_table_size, mem, size)) { - pr_err("Section table [%#zx, %#zx) is out of [%#zx, %#zx)\n", - sec_table, sec_table + sec_table_size, mem, mem + size); + pr_err("Section table [%#zx, %#zx) is out of [%#zx, %#zx)\n", sec_table, sec_table + sec_table_size, + mem, mem + size); return NULL; } @@ -113,24 +108,22 @@ static const char *get_strings_section(Elf_Ehdr *hdr, uintptr_t mem, size_t size * strings section header's offset in section headers table is * (size of section header * index of string section header) */ - addr = sec_table + ((size_t) hdr->e_shentsize) * hdr->e_shstrndx; - if (__ptr_struct_oob(addr, sizeof(Elf_Shdr), - sec_table, sec_table_size)) { - pr_err("String section header @%#zx is out of [%#zx, %#zx)\n", - addr, sec_table, sec_table + sec_table_size); + addr = sec_table + ((size_t)hdr->e_shentsize) * hdr->e_shstrndx; + if (__ptr_struct_oob(addr, sizeof(Elf_Shdr), sec_table, sec_table_size)) { + pr_err("String section header @%#zx is out of [%#zx, %#zx)\n", addr, sec_table, + sec_table + sec_table_size); return NULL; } - secstrings_hdr = (void*)addr; + secstrings_hdr = (void *)addr; addr = mem + secstrings_hdr->sh_offset; if (__ptr_struct_oob(addr, secstrings_hdr->sh_size, mem, size)) { - pr_err("String section @%#zx size %#lx is out of [%#zx, %#zx)\n", - addr, (unsigned long)secstrings_hdr->sh_size, - mem, mem + size); + pr_err("String section @%#zx size %#lx is out of [%#zx, %#zx)\n", addr, + (unsigned long)secstrings_hdr->sh_size, mem, mem + size); return NULL; } - return (void*)addr; + return (void *)addr; } /* @@ -159,8 +152,7 @@ int __handle_elf(void *mem, size_t size) pr_debug("Header\n"); pr_debug("------------\n"); - pr_debug("\ttype 0x%x machine 0x%x version 0x%x\n", - (unsigned)hdr->e_type, (unsigned)hdr->e_machine, + pr_debug("\ttype 0x%x machine 0x%x version 0x%x\n", (unsigned)hdr->e_type, (unsigned)hdr->e_machine, (unsigned)hdr->e_version); if (!is_header_supported(hdr)) { @@ -189,8 +181,7 @@ int __handle_elf(void *mem, size_t size) symtab_hdr = sh; ptr_func_exit(&secstrings[sh->sh_name]); - pr_debug("\t index %-2zd type 0x%-2x name %s\n", i, - (unsigned)sh->sh_type, &secstrings[sh->sh_name]); + pr_debug("\t index %-2zd type 0x%-2x name %s\n", i, (unsigned)sh->sh_type, &secstrings[sh->sh_name]); sec_hdrs[i] = sh; @@ -214,9 +205,7 @@ int __handle_elf(void *mem, size_t size) } if (sh->sh_addr && sh->sh_addr != k) pr_info("Overriding unexpected precalculated address of section (section %s addr 0x%lx expected 0x%lx)\n", - &secstrings[sh->sh_name], - (unsigned long) sh->sh_addr, - (unsigned long) k); + &secstrings[sh->sh_name], (unsigned long)sh->sh_addr, (unsigned long)k); sh->sh_addr = k; k += sh->sh_size; } @@ -262,8 +251,8 @@ int __handle_elf(void *mem, size_t size) continue; pr_debug("\ttype 0x%-2x bind 0x%-2x shndx 0x%-4x value 0x%-2lx name %s\n", - (unsigned)ELF_ST_TYPE(sym->st_info), (unsigned)ELF_ST_BIND(sym->st_info), - (unsigned)sym->st_shndx, (unsigned long)sym->st_value, name); + (unsigned)ELF_ST_TYPE(sym->st_info), (unsigned)ELF_ST_BIND(sym->st_info), + (unsigned)sym->st_shndx, (unsigned long)sym->st_value, name); #ifdef ELF_PPC64 if (!sym->st_value && !strncmp(name, ".TOC.", 6)) { if (!toc_offset) { @@ -276,18 +265,15 @@ int __handle_elf(void *mem, size_t size) #endif if (strncmp(name, "__export", 8)) continue; - if ((sym->st_shndx && sym->st_shndx < hdr->e_shnum) || - sym->st_shndx == SHN_ABS) { + if ((sym->st_shndx && sym->st_shndx < hdr->e_shnum) || sym->st_shndx == SHN_ABS) { if (sym->st_shndx == SHN_ABS) { sh_src = NULL; } else { sh_src = sec_hdrs[sym->st_shndx]; ptr_func_exit(sh_src); } - pr_out("#define %s_sym%s 0x%lx\n", - opts.prefix, name, - (unsigned long)(sym->st_value + - (sh_src ? sh_src->sh_addr : 0))); + pr_out("#define %s_sym%s 0x%lx\n", opts.prefix, name, + (unsigned long)(sym->st_value + (sh_src ? sh_src->sh_addr : 0))); } } @@ -305,9 +291,8 @@ int __handle_elf(void *mem, size_t size) sh_rel = sec_hdrs[sh->sh_info]; ptr_func_exit(sh_rel); - pr_debug("\tsection %2zd type 0x%-2x link 0x%-2x info 0x%-2x name %s\n", i, - (unsigned)sh->sh_type, (unsigned)sh->sh_link, - (unsigned)sh->sh_info, &secstrings[sh->sh_name]); + pr_debug("\tsection %2zd type 0x%-2x link 0x%-2x info 0x%-2x name %s\n", i, (unsigned)sh->sh_type, + (unsigned)sh->sh_link, (unsigned)sh->sh_info, &secstrings[sh->sh_name]); for (k = 0; k < sh->sh_size / sh->sh_entsize; k++) { int64_t __maybe_unused addend64, __maybe_unused value64; @@ -334,8 +319,7 @@ int __handle_elf(void *mem, size_t size) pr_debug("\t\tr_offset 0x%-4lx r_info 0x%-4lx / sym 0x%-2lx type 0x%-2lx symsecoff 0x%-4lx\n", (unsigned long)r->rel.r_offset, (unsigned long)r->rel.r_info, - (unsigned long)ELF_R_SYM(r->rel.r_info), - (unsigned long)ELF_R_TYPE(r->rel.r_info), + (unsigned long)ELF_R_SYM(r->rel.r_info), (unsigned long)ELF_R_TYPE(r->rel.r_info), (unsigned long)sh_rel->sh_addr); if (sym->st_shndx == SHN_UNDEF) { @@ -345,8 +329,7 @@ int __handle_elf(void *mem, size_t size) * Their type is STT_NOTYPE, so report any * other one. */ - if (ELF32_ST_TYPE(sym->st_info) != STT_NOTYPE - || strncmp(name, ".TOC.", 6)) { + if (ELF32_ST_TYPE(sym->st_info) != STT_NOTYPE || strncmp(name, ".TOC.", 6)) { pr_err("Unexpected undefined symbol:%s\n", name); goto err; } @@ -385,8 +368,8 @@ int __handle_elf(void *mem, size_t size) Elf_Shdr *sh_src; if ((unsigned)sym->st_shndx > (unsigned)hdr->e_shnum) { - pr_err("Unexpected symbol section index %u/%u\n", - (unsigned)sym->st_shndx, hdr->e_shnum); + pr_err("Unexpected symbol section index %u/%u\n", (unsigned)sym->st_shndx, + hdr->e_shnum); goto err; } sh_src = sec_hdrs[sym->st_shndx]; @@ -419,11 +402,10 @@ int __handle_elf(void *mem, size_t size) * * Here we are only handle the case '3' which is the most commonly seen. */ -#define LOCAL_OFFSET(s) ((s->st_other >> 5) & 0x7) +#define LOCAL_OFFSET(s) ((s->st_other >> 5) & 0x7) if (LOCAL_OFFSET(sym)) { if (LOCAL_OFFSET(sym) != 3) { - pr_err("Unexpected local offset value %d\n", - LOCAL_OFFSET(sym)); + pr_err("Unexpected local offset value %d\n", LOCAL_OFFSET(sym)); goto err; } pr_debug("\t\t\tUsing local offset\n"); @@ -435,28 +417,28 @@ int __handle_elf(void *mem, size_t size) switch (ELF_R_TYPE(r->rel.r_info)) { #ifdef CONFIG_MIPS case R_MIPS_PC16: - /* s+a-p relative */ - *((int32_t *)where) = *((int32_t *)where) | ((value32 + addend32 - place)>>2); - break; + /* s+a-p relative */ + *((int32_t *)where) = *((int32_t *)where) | ((value32 + addend32 - place) >> 2); + break; case R_MIPS_26: - /* local : (((A << 2) | (P & 0xf0000000) + S) >> 2 + /* local : (((A << 2) | (P & 0xf0000000) + S) >> 2 * external : (sign–extend(A < 2) + S) >> 2 */ - if (((unsigned)ELF_ST_BIND(sym->st_info) == 0x1) - || ((unsigned)ELF_ST_BIND(sym->st_info) == 0x2)){ - /* bind type local is 0x0 ,global is 0x1,WEAK is 0x2 */ - addend32 = value32; - } - pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_26, " - ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_26 */\n", - (unsigned int)place, addend32, value32); - break; + if (((unsigned)ELF_ST_BIND(sym->st_info) == 0x1) || + ((unsigned)ELF_ST_BIND(sym->st_info) == 0x2)) { + /* bind type local is 0x0 ,global is 0x1,WEAK is 0x2 */ + addend32 = value32; + } + pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_26, " + ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_26 */\n", + (unsigned int)place, addend32, value32); + break; case R_MIPS_32: - /* S+A */ - break; + /* S+A */ + break; case R_MIPS_64: pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_64, " @@ -465,39 +447,38 @@ int __handle_elf(void *mem, size_t size) break; case R_MIPS_HIGHEST: - pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_HIGHEST, " - ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_HIGHEST */\n", - (unsigned int)place, addend32, value32); - break; + pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_HIGHEST, " + ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_HIGHEST */\n", + (unsigned int)place, addend32, value32); + break; case R_MIPS_HIGHER: - pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_HIGHER, " - ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_HIGHER */\n", - (unsigned int)place, addend32, value32); - break; + pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_HIGHER, " + ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_HIGHER */\n", + (unsigned int)place, addend32, value32); + break; case R_MIPS_HI16: - pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_HI16, " - ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_HI16 */\n", - (unsigned int)place, addend32, value32); - break; + pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_HI16, " + ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_HI16 */\n", + (unsigned int)place, addend32, value32); + break; case R_MIPS_LO16: - if((unsigned)ELF_ST_BIND(sym->st_info) == 0x1){ - /* bind type local is 0x0 ,global is 0x1 */ - addend32 = value32; - } - pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_LO16, " - ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_LO16 */\n", - (unsigned int)place, addend32, value32); - break; + if ((unsigned)ELF_ST_BIND(sym->st_info) == 0x1) { + /* bind type local is 0x0 ,global is 0x1 */ + addend32 = value32; + } + pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_MIPS_LO16, " + ".addend = %-8d, .value = 0x%-16x, }, /* R_MIPS_LO16 */\n", + (unsigned int)place, addend32, value32); + break; #endif #ifdef ELF_PPC64 case R_PPC64_REL24: /* Update PC relative offset, linker has not done this yet */ - pr_debug("\t\t\tR_PPC64_REL24 at 0x%-4lx val 0x%lx\n", - place, value64); + pr_debug("\t\t\tR_PPC64_REL24 at 0x%-4lx val 0x%lx\n", place, value64); /* Convert value to relative */ value64 -= place; if (value64 + 0x2000000 > 0x3ffffff || (value64 & 3) != 0) { @@ -505,60 +486,54 @@ int __handle_elf(void *mem, size_t size) goto err; } /* Only replace bits 2 through 26 */ - *(uint32_t *)where = (*(uint32_t *)where & ~0x03fffffc) | - (value64 & 0x03fffffc); + *(uint32_t *)where = (*(uint32_t *)where & ~0x03fffffc) | (value64 & 0x03fffffc); break; case R_PPC64_ADDR32: case R_PPC64_REL32: - pr_debug("\t\t\tR_PPC64_ADDR32 at 0x%-4lx val 0x%x\n", - place, (unsigned int)(value32 + addend32)); + pr_debug("\t\t\tR_PPC64_ADDR32 at 0x%-4lx val 0x%x\n", place, + (unsigned int)(value32 + addend32)); pr_out(" { .offset = 0x%-8x, .type = COMPEL_TYPE_INT, " " .addend = %-8d, .value = 0x%-16x, " "}, /* R_PPC64_ADDR32 */\n", - (unsigned int) place, addend32, value32); + (unsigned int)place, addend32, value32); break; case R_PPC64_ADDR64: case R_PPC64_REL64: - pr_debug("\t\t\tR_PPC64_ADDR64 at 0x%-4lx val 0x%lx\n", - place, value64 + addend64); + pr_debug("\t\t\tR_PPC64_ADDR64 at 0x%-4lx val 0x%lx\n", place, value64 + addend64); pr_out("\t{ .offset = 0x%-8x, .type = COMPEL_TYPE_LONG," " .addend = %-8ld, .value = 0x%-16lx, " "}, /* R_PPC64_ADDR64 */\n", - (unsigned int) place, (long)addend64, (long)value64); + (unsigned int)place, (long)addend64, (long)value64); break; case R_PPC64_TOC16_HA: - pr_debug("\t\t\tR_PPC64_TOC16_HA at 0x%-4lx val 0x%lx\n", - place, value64 + addend64 - toc_offset + 0x8000); - if (do_relative_toc((value64 + addend64 - toc_offset + 0x8000) >> 16, - where, 0xffff, 1)) + pr_debug("\t\t\tR_PPC64_TOC16_HA at 0x%-4lx val 0x%lx\n", place, + value64 + addend64 - toc_offset + 0x8000); + if (do_relative_toc((value64 + addend64 - toc_offset + 0x8000) >> 16, where, 0xffff, 1)) goto err; break; case R_PPC64_TOC16_LO: - pr_debug("\t\t\tR_PPC64_TOC16_LO at 0x%-4lx val 0x%lx\n", - place, value64 + addend64 - toc_offset); - if (do_relative_toc(value64 + addend64 - toc_offset, - where, 0xffff, 1)) + pr_debug("\t\t\tR_PPC64_TOC16_LO at 0x%-4lx val 0x%lx\n", place, + value64 + addend64 - toc_offset); + if (do_relative_toc(value64 + addend64 - toc_offset, where, 0xffff, 1)) goto err; break; case R_PPC64_TOC16_LO_DS: - pr_debug("\t\t\tR_PPC64_TOC16_LO_DS at 0x%-4lx val 0x%lx\n", - place, value64 + addend64 - toc_offset); - if (do_relative_toc(value64 + addend64 - toc_offset, - where, 0xfffc, 0)) + pr_debug("\t\t\tR_PPC64_TOC16_LO_DS at 0x%-4lx val 0x%lx\n", place, + value64 + addend64 - toc_offset); + if (do_relative_toc(value64 + addend64 - toc_offset, where, 0xfffc, 0)) goto err; break; case R_PPC64_REL16_HA: value64 += addend64 - place; - pr_debug("\t\t\tR_PPC64_REL16_HA at 0x%-4lx val 0x%lx\n", - place, value64); + pr_debug("\t\t\tR_PPC64_REL16_HA at 0x%-4lx val 0x%lx\n", place, value64); /* check that we are dealing with the addis 2,12 instruction */ - if (((*(uint32_t*)where) & 0xffff0000) != 0x3c4c0000) { + if (((*(uint32_t *)where) & 0xffff0000) != 0x3c4c0000) { pr_err("Unexpected instruction for R_PPC64_REL16_HA\n"); goto err; } @@ -567,10 +542,9 @@ int __handle_elf(void *mem, size_t size) case R_PPC64_REL16_LO: value64 += addend64 - place; - pr_debug("\t\t\tR_PPC64_REL16_LO at 0x%-4lx val 0x%lx\n", - place, value64); + pr_debug("\t\t\tR_PPC64_REL16_LO at 0x%-4lx val 0x%lx\n", place, value64); /* check that we are dealing with the addi 2,2 instruction */ - if (((*(uint32_t*)where) & 0xffff0000) != 0x38420000) { + if (((*(uint32_t *)where) & 0xffff0000) != 0x38420000) { pr_err("Unexpected instruction for R_PPC64_REL16_LO\n"); goto err; } @@ -594,14 +568,16 @@ int __handle_elf(void *mem, size_t size) (unsigned int)place, (long)addend64, (long)value64); break; case R_X86_64_PC32: /* Symbol + Addend - Place (4 bytes) */ - pr_debug("\t\t\t\tR_X86_64_PC32 at 0x%-4lx val 0x%x\n", place, value32 + addend32 - (int32_t)place); + pr_debug("\t\t\t\tR_X86_64_PC32 at 0x%-4lx val 0x%x\n", place, + value32 + addend32 - (int32_t)place); /* * R_X86_64_PC32 are relative, patch them inplace. */ *((int32_t *)where) = value32 + addend32 - place; break; case R_X86_64_PLT32: /* ProcLinkage + Addend - Place (4 bytes) */ - pr_debug("\t\t\t\tR_X86_64_PLT32 at 0x%-4lx val 0x%x\n", place, value32 + addend32 - (int32_t)place); + pr_debug("\t\t\t\tR_X86_64_PLT32 at 0x%-4lx val 0x%x\n", place, + value32 + addend32 - (int32_t)place); /* * R_X86_64_PLT32 are relative, patch them inplace. */ @@ -626,7 +602,8 @@ int __handle_elf(void *mem, size_t size) (unsigned int)place, addend32, value32); break; case R_386_PC32: /* Symbol + Addend - Place */ - pr_debug("\t\t\t\tR_386_PC32 at 0x%-4lx val 0x%x\n", place, value32 + addend32 - (int32_t)place); + pr_debug("\t\t\t\tR_386_PC32 at 0x%-4lx val 0x%x\n", place, + value32 + addend32 - (int32_t)place); /* * R_386_PC32 are relative, patch them inplace. */ @@ -661,7 +638,7 @@ int __handle_elf(void *mem, size_t size) #endif default: pr_err("Unsupported relocation of type %lu\n", - (unsigned long)ELF_R_TYPE(r->rel.r_info)); + (unsigned long)ELF_R_TYPE(r->rel.r_info)); goto err; } } @@ -679,11 +656,11 @@ int __handle_elf(void *mem, size_t size) if (!(sh->sh_flags & SHF_ALLOC) || !sh->sh_size) continue; - shdata = mem + sh->sh_offset; + shdata = mem + sh->sh_offset; pr_debug("Copying section '%s'\n" "\tstart:0x%lx (gap:0x%lx) size:0x%lx\n", - &secstrings[sh->sh_name], (unsigned long) sh->sh_addr, - (unsigned long)(sh->sh_addr - k), (unsigned long) sh->sh_size); + &secstrings[sh->sh_name], (unsigned long)sh->sh_addr, (unsigned long)(sh->sh_addr - k), + (unsigned long)sh->sh_size); /* write 0 in the gap between the 2 sections */ for (; k < sh->sh_addr; k++) { @@ -704,21 +681,20 @@ int __handle_elf(void *mem, size_t size) pr_out("};\n"); pr_out("\n"); pr_out("static void __maybe_unused %s_setup_c_header_desc(struct parasite_blob_desc *pbd, bool native)\n", - opts.prefix); - pr_out( -"{\n" -" pbd->parasite_type = COMPEL_BLOB_CHEADER;\n" -); + opts.prefix); + pr_out("{\n" + " pbd->parasite_type = COMPEL_BLOB_CHEADER;\n"); pr_out("\tpbd->hdr.mem = %s_blob;\n", opts.prefix); - pr_out("\tpbd->hdr.bsize = sizeof(%s_blob);\n", - opts.prefix); + pr_out("\tpbd->hdr.bsize = sizeof(%s_blob);\n", opts.prefix); pr_out("\tif (native)\n"); pr_out("\t\tpbd->hdr.parasite_ip_off = " - "%s_sym__export_parasite_head_start;\n", opts.prefix); + "%s_sym__export_parasite_head_start;\n", + opts.prefix); pr_out("#ifdef CONFIG_COMPAT\n"); pr_out("\telse\n"); pr_out("\t\tpbd->hdr.parasite_ip_off = " - "%s_sym__export_parasite_head_start_compat;\n", opts.prefix); + "%s_sym__export_parasite_head_start_compat;\n", + opts.prefix); pr_out("#endif /* CONFIG_COMPAT */\n"); pr_out("\tpbd->hdr.cmd_off = %s_sym__export_parasite_service_cmd;\n", opts.prefix); pr_out("\tpbd->hdr.args_ptr_off = %s_sym__export_parasite_service_args_ptr;\n", opts.prefix); @@ -727,12 +703,11 @@ int __handle_elf(void *mem, size_t size) pr_out("\tpbd->hdr.data_off = %#lx;\n", data_off); pr_out("\tpbd->hdr.relocs = %s_relocs;\n", opts.prefix); pr_out("\tpbd->hdr.nr_relocs = " - "sizeof(%s_relocs) / sizeof(%s_relocs[0]);\n", - opts.prefix, opts.prefix); + "sizeof(%s_relocs) / sizeof(%s_relocs[0]);\n", + opts.prefix, opts.prefix); pr_out("}\n"); pr_out("\n"); - pr_out("static void __maybe_unused %s_setup_c_header(struct parasite_ctl *ctl)\n", - opts.prefix); + pr_out("static void __maybe_unused %s_setup_c_header(struct parasite_ctl *ctl)\n", opts.prefix); pr_out("{\n"); pr_out("\t%s_setup_c_header_desc(compel_parasite_blob_desc(ctl), compel_mode_native(ctl));\n", opts.prefix); pr_out("}\n"); diff --git a/compel/src/lib/infect-rpc.c b/compel/src/lib/infect-rpc.c index 265a4ad2f..6b19fa6bd 100644 --- a/compel/src/lib/infect-rpc.c +++ b/compel/src/lib/infect-rpc.c @@ -19,8 +19,7 @@ static int __parasite_send_cmd(int sockfd, struct ctl_msg *m) pr_perror("Failed to send command %d to daemon", m->cmd); return -1; } else if (ret != sizeof(*m)) { - pr_err("Message to daemon is trimmed (%d/%d)\n", - (int)sizeof(*m), ret); + pr_err("Message to daemon is trimmed (%d/%d)\n", (int)sizeof(*m), ret); return -1; } @@ -42,12 +41,10 @@ int parasite_wait_ack(int sockfd, unsigned int cmd, struct ctl_msg *m) pr_perror("Failed to read ack"); return -1; } else if (ret != sizeof(*m)) { - pr_err("Message reply from daemon is trimmed (%d/%d)\n", - (int)sizeof(*m), ret); + pr_err("Message reply from daemon is trimmed (%d/%d)\n", (int)sizeof(*m), ret); return -1; } - pr_debug("Fetched ack: %d %d %d\n", - m->cmd, m->ack, m->err); + pr_debug("Fetched ack: %d %d %d\n", m->cmd, m->ack, m->err); if (m->cmd != cmd || m->ack != cmd) { pr_err("Communication error, this is not " @@ -68,8 +65,7 @@ int compel_rpc_sync(unsigned int cmd, struct parasite_ctl *ctl) return -1; if (m.err != 0) { - pr_err("Command %d for daemon failed with %d\n", - cmd, m.err); + pr_err("Command %d for daemon failed with %d\n", cmd, m.err); return -1; } diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c index a15b99ad6..0fb9e715c 100644 --- a/compel/src/lib/infect.c +++ b/compel/src/lib/infect.c @@ -27,18 +27,17 @@ #include "rpc-pie-priv.h" #include "infect-util.h" -#define __sys(foo) foo -#define __sys_err(ret) (-errno) +#define __sys(foo) foo +#define __sys_err(ret) (-errno) #include "common/scm.h" #include "common/scm-code.c" #ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - \ - (size_t)((struct sockaddr_un *) 0)->sun_path) +#define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - (size_t)((struct sockaddr_un *)0)->sun_path) #endif -#define PARASITE_STACK_SIZE (16 << 10) +#define PARASITE_STACK_SIZE (16 << 10) #ifndef SECCOMP_MODE_DISABLED #define SECCOMP_MODE_DISABLED 0 @@ -193,10 +192,9 @@ static int skip_sigstop(int pid, int nr_signals) * of it so the task would not know if it was saddled * up with someone else. */ -int compel_wait_task(int pid, int ppid, - int (*get_status)(int pid, struct seize_task_status *, void *), - void (*free_status)(int pid, struct seize_task_status *, void *), - struct seize_task_status *ss, void *data) +int compel_wait_task(int pid, int ppid, int (*get_status)(int pid, struct seize_task_status *, void *), + void (*free_status)(int pid, struct seize_task_status *, void *), struct seize_task_status *ss, + void *data) { siginfo_t si; int status, nr_sigstop; @@ -232,8 +230,8 @@ try_again: if (pid == getpid()) pr_err("The criu itself is within dumped tree.\n"); else - pr_err("Unseizable non-zombie %d found, state %c, err %d/%d\n", - pid, ss->state, ret, wait_errno); + pr_err("Unseizable non-zombie %d found, state %c, err %d/%d\n", pid, ss->state, ret, + wait_errno); return -1; } @@ -244,8 +242,7 @@ try_again: } if ((ppid != -1) && (ss->ppid != ppid)) { - pr_err("Task pid reused while suspending (%d: %d -> %d)\n", - pid, ppid, ss->ppid); + pr_err("Task pid reused while suspending (%d: %d -> %d)\n", pid, ppid, ss->ppid); goto err; } @@ -267,8 +264,7 @@ try_again: * handle one and repeat. */ - if (ptrace(PTRACE_CONT, pid, NULL, - (void *)(unsigned long)si.si_signo)) { + if (ptrace(PTRACE_CONT, pid, NULL, (void *)(unsigned long)si.si_signo)) { pr_perror("Can't continue signal handling, aborting"); goto err; } @@ -368,8 +364,7 @@ static int gen_parasite_saddr(struct sockaddr_un *saddr, int key) int sun_len; saddr->sun_family = AF_UNIX; - snprintf(saddr->sun_path, UNIX_PATH_MAX, - "X/crtools-pr-%d", key); + snprintf(saddr->sun_path, UNIX_PATH_MAX, "X/crtools-pr-%d", key); sun_len = SUN_LEN(saddr); *saddr->sun_path = '\0'; @@ -377,8 +372,7 @@ static int gen_parasite_saddr(struct sockaddr_un *saddr, int key) return sun_len; } -static int prepare_tsock(struct parasite_ctl *ctl, pid_t pid, - struct parasite_init_args *args) +static int prepare_tsock(struct parasite_ctl *ctl, pid_t pid, struct parasite_init_args *args) { int ssock = -1; socklen_t sk_len; @@ -395,7 +389,7 @@ static int prepare_tsock(struct parasite_ctl *ctl, pid_t pid, goto err; } - if (getsockname(ssock, (struct sockaddr *) &addr, &sk_len) < 0) { + if (getsockname(ssock, (struct sockaddr *)&addr, &sk_len) < 0) { pr_perror("Unable to get name for a socket"); return -1; } @@ -430,8 +424,8 @@ err: static int setup_child_handler(struct parasite_ctl *ctl) { struct sigaction sa = { - .sa_sigaction = ctl->ictx.child_handler, - .sa_flags = SA_SIGINFO | SA_RESTART, + .sa_sigaction = ctl->ictx.child_handler, + .sa_flags = SA_SIGINFO | SA_RESTART, }; sigemptyset(&sa.sa_mask); @@ -454,8 +448,8 @@ static int restore_child_handler(struct parasite_ctl *ctl) return 0; } -static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, - user_regs_struct_t *regs, struct thread_ctx *octx) +static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, user_regs_struct_t *regs, + struct thread_ctx *octx) { k_rtsigset_t block; @@ -493,8 +487,7 @@ err_sig: return -1; } -static int restore_thread_ctx(int pid, struct thread_ctx *ctx, - bool restore_ext_regs) +static int restore_thread_ctx(int pid, struct thread_ctx *ctx, bool restore_ext_regs) { int ret = 0; @@ -515,10 +508,8 @@ static int restore_thread_ctx(int pid, struct thread_ctx *ctx, } /* we run at @regs->ip */ -static int parasite_trap(struct parasite_ctl *ctl, pid_t pid, - user_regs_struct_t *regs, - struct thread_ctx *octx, - bool may_use_extended_regs) +static int parasite_trap(struct parasite_ctl *ctl, pid_t pid, user_regs_struct_t *regs, struct thread_ctx *octx, + bool may_use_extended_regs) { siginfo_t siginfo; int status; @@ -546,12 +537,11 @@ static int parasite_trap(struct parasite_ctl *ctl, pid_t pid, if (ptrace_get_regs(pid, regs)) { pr_perror("Can't obtain registers (pid: %d)", pid); - goto err; + goto err; } if (WSTOPSIG(status) != SIGTRAP || siginfo.si_code != ARCH_SI_TRAP) { - pr_debug("** delivering signal %d si_code=%d\n", - siginfo.si_signo, siginfo.si_code); + pr_debug("** delivering signal %d si_code=%d\n", siginfo.si_signo, siginfo.si_code); pr_err("Unexpected %d task interruption, aborting\n", pid); goto err; @@ -569,9 +559,7 @@ err: return ret; } - -int compel_execute_syscall(struct parasite_ctl *ctl, - user_regs_struct_t *regs, const char *code_syscall) +int compel_execute_syscall(struct parasite_ctl *ctl, user_regs_struct_t *regs, const char *code_syscall) { pid_t pid = ctl->rpid; int err; @@ -582,8 +570,7 @@ int compel_execute_syscall(struct parasite_ctl *ctl, * we will need it to restore original program content. */ memcpy(code_orig, code_syscall, sizeof(code_orig)); - if (ptrace_swap_area(pid, (void *)ctl->ictx.syscall_ip, - (void *)code_orig, sizeof(code_orig))) { + if (ptrace_swap_area(pid, (void *)ctl->ictx.syscall_ip, (void *)code_orig, sizeof(code_orig))) { pr_err("Can't inject syscall blob (pid: %d)\n", pid); return -1; } @@ -592,8 +579,7 @@ int compel_execute_syscall(struct parasite_ctl *ctl, if (!err) err = parasite_trap(ctl, pid, regs, &ctl->orig, false); - if (ptrace_poke_area(pid, (void *)code_orig, - (void *)ctl->ictx.syscall_ip, sizeof(code_orig))) { + if (ptrace_poke_area(pid, (void *)code_orig, (void *)ctl->ictx.syscall_ip, sizeof(code_orig))) { pr_err("Can't restore syscall blob (pid: %d)\n", ctl->rpid); err = -1; } @@ -633,7 +619,7 @@ static int parasite_init_daemon(struct parasite_ctl *ctl) struct parasite_init_args *args; pid_t pid = ctl->rpid; user_regs_struct_t regs; - struct ctl_msg m = { }; + struct ctl_msg m = {}; *ctl->cmd = PARASITE_CMD_INIT_DAEMON; @@ -674,12 +660,11 @@ static int parasite_init_daemon(struct parasite_ctl *ctl) pr_info("Wait for parasite being daemonized...\n"); if (parasite_wait_ack(ctl->tsock, PARASITE_CMD_INIT_DAEMON, &m)) { - pr_err("Can't switch parasite %d to daemon mode %d\n", - pid, m.err); + pr_err("Can't switch parasite %d to daemon mode %d\n", pid, m.err); goto err; } - ctl->sigreturn_addr = (void*)(uintptr_t)args->sigreturn_addr; + ctl->sigreturn_addr = (void *)(uintptr_t)args->sigreturn_addr; ctl->daemonized = true; pr_info("Parasite %d has been switched to daemon mode\n", pid); return 0; @@ -698,8 +683,7 @@ static int parasite_start_daemon(struct parasite_ctl *ctl) * while in daemon it is not such. */ - if (compel_get_task_regs(pid, &ctl->orig.regs, NULL, ictx->save_regs, - ictx->regs_arg, ictx->flags)) { + if (compel_get_task_regs(pid, &ctl->orig.regs, NULL, ictx->save_regs, ictx->regs_arg, ictx->flags)) { pr_err("Can't obtain regs for thread %d\n", pid); return -1; } @@ -722,8 +706,7 @@ static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size, { int fd; - ctl->remote_map = remote_mmap(ctl, NULL, size, remote_prot, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); + ctl->remote_map = remote_mmap(ctl, NULL, size, remote_prot, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (!ctl->remote_map) { pr_err("Can't allocate memory for parasite blob (pid: %d)\n", ctl->rpid); return -1; @@ -731,13 +714,12 @@ static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size, ctl->map_length = round_up(size, page_size()); - fd = ctl->ictx.open_proc(ctl->rpid, O_RDWR, "map_files/%lx-%lx", - (long)ctl->remote_map, (long)ctl->remote_map + ctl->map_length); + fd = ctl->ictx.open_proc(ctl->rpid, O_RDWR, "map_files/%lx-%lx", (long)ctl->remote_map, + (long)ctl->remote_map + ctl->map_length); if (fd < 0) return -1; - ctl->local_map = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, fd, 0); + ctl->local_map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FILE, fd, 0); close(fd); if (ctl->local_map == MAP_FAILED) { @@ -779,8 +761,7 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size, return -1; } - ret = compel_syscall(ctl, __NR(memfd_create, compat_task), &sret, - (unsigned long)where, 0, 0, 0, 0, 0); + ret = compel_syscall(ctl, __NR(memfd_create, compat_task), &sret, (unsigned long)where, 0, 0, 0, 0, 0); if (ptrace_poke_area(pid, orig_code, where, sizeof(orig_code))) { fd = (int)sret; @@ -812,15 +793,13 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size, goto err_cure; } - ctl->remote_map = remote_mmap(ctl, NULL, size, remote_prot, - MAP_FILE | MAP_SHARED, fd, 0); + ctl->remote_map = remote_mmap(ctl, NULL, size, remote_prot, MAP_FILE | MAP_SHARED, fd, 0); if (!ctl->remote_map) { pr_err("Can't rmap memfd for parasite blob\n"); goto err_curef; } - ctl->local_map = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FILE, lfd, 0); + ctl->local_map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FILE, lfd, 0); if (ctl->local_map == MAP_FAILED) { ctl->local_map = NULL; pr_perror("Can't lmap memfd for parasite blob"); @@ -867,7 +846,8 @@ void compel_relocs_apply(void *mem, void *vbase, struct parasite_blob_desc *pbd) int rel; got[j] = vbase + elf_relocs[i].value; - rel = (unsigned)((void *)&got[j] - (void *)mem) - elf_relocs[i].offset + elf_relocs[i].addend; + rel = (unsigned)((void *)&got[j] - (void *)mem) - elf_relocs[i].offset + + elf_relocs[i].addend; *value = rel; j++; @@ -888,8 +868,7 @@ long remote_mprotect(struct parasite_ctl *ctl, void *addr, size_t len, int prot) int err; bool compat_task = !user_regs_native(&ctl->orig.regs); - err = compel_syscall(ctl, __NR(mprotect, compat_task), &ret, - (unsigned long)addr, len, prot, 0, 0, 0); + err = compel_syscall(ctl, __NR(mprotect, compat_task), &ret, (unsigned long)addr, len, prot, 0, 0, 0); if (err < 0) { pr_err("compel_syscall for mprotect failed\n"); return -1; @@ -917,8 +896,7 @@ static int compel_map_exchange(struct parasite_ctl *ctl, unsigned long size) if (!ctl->pblob.hdr.data_off) return 0; - ret = remote_mprotect(ctl, ctl->remote_map + ctl->pblob.hdr.data_off, - size - ctl->pblob.hdr.data_off, + ret = remote_mprotect(ctl, ctl->remote_map + ctl->pblob.hdr.data_off, size - ctl->pblob.hdr.data_off, PROT_READ | PROT_WRITE); if (ret) pr_err("remote_mprotect failed\n"); @@ -1000,7 +978,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l * already the case, as args follows the GOT table, which is 8 bytes * aligned. */ - if ((unsigned long)ctl->args & (4-1)) { + if ((unsigned long)ctl->args & (4 - 1)) { pr_err("BUG: args are not 4 bytes aligned: %p\n", ctl->args); goto err; } @@ -1010,8 +988,8 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l p = parasite_size; - ctl->rsigframe = ctl->remote_map + p; - ctl->sigframe = ctl->local_map + p; + ctl->rsigframe = ctl->remote_map + p; + ctl->sigframe = ctl->local_map + p; p += RESTORE_STACK_SIGFRAME; p += PARASITE_STACK_SIZE; @@ -1022,12 +1000,11 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l * It is already the case as RESTORE_STACK_SIGFRAME is a multiple of * 64, and PARASITE_STACK_SIZE is 0x4000. */ - if ((unsigned long)ctl->rstack & (16-1)) { + if ((unsigned long)ctl->rstack & (16 - 1)) { pr_err("BUG: stack is not 16 bytes aligned: %p\n", ctl->rstack); goto err; } - if (nr_threads > 1) { p += PARASITE_STACK_SIZE; ctl->r_thread_stack = ctl->remote_map + p; @@ -1035,8 +1012,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l ret = arch_fetch_sas(ctl, ctl->rsigframe); if (ret) { - pr_err("Can't fetch sigaltstack for task %d (ret %d)\n", - ctl->rpid, ret); + pr_err("Can't fetch sigaltstack for task %d (ret %d)\n", ctl->rpid, ret); goto err; } @@ -1227,14 +1203,12 @@ static void handle_sigchld(int signal, siginfo_t *siginfo, void *data) if (pid <= 0) return; - pr_err("si_code=%d si_pid=%d si_status=%d\n", - siginfo->si_code, siginfo->si_pid, siginfo->si_status); + pr_err("si_code=%d si_pid=%d si_status=%d\n", siginfo->si_code, siginfo->si_pid, siginfo->si_status); if (WIFEXITED(status)) pr_err("%d exited with %d unexpectedly\n", pid, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) - pr_err("%d was killed by %d unexpectedly: %s\n", - pid, WTERMSIG(status), strsignal(WTERMSIG(status))); + pr_err("%d was killed by %d unexpectedly: %s\n", pid, WTERMSIG(status), strsignal(WTERMSIG(status))); else if (WIFSTOPPED(status)) pr_err("%d was stopped by %d unexpectedly\n", pid, WSTOPSIG(status)); @@ -1325,9 +1299,8 @@ err: static bool task_in_parasite(struct parasite_ctl *ctl, user_regs_struct_t *regs) { - void *addr = (void *) REG_IP(*regs); - return addr >= ctl->remote_map && - addr < ctl->remote_map + ctl->map_length; + void *addr = (void *)REG_IP(*regs); + return addr >= ctl->remote_map && addr < ctl->remote_map + ctl->map_length; } static int parasite_fini_seized(struct parasite_ctl *ctl) @@ -1376,13 +1349,11 @@ static int parasite_fini_seized(struct parasite_ctl *ctl) return -1; /* Go to sigreturn as closer as we can */ - ret = compel_stop_pie(pid, ctl->sigreturn_addr, &flag, - ctl->ictx.flags & INFECT_NO_BREAKPOINTS); + ret = compel_stop_pie(pid, ctl->sigreturn_addr, &flag, ctl->ictx.flags & INFECT_NO_BREAKPOINTS); if (ret < 0) return ret; - if (compel_stop_on_syscall(1, __NR(rt_sigreturn, 0), - __NR(rt_sigreturn, 1), flag)) + if (compel_stop_on_syscall(1, __NR(rt_sigreturn, 0), __NR(rt_sigreturn, 1), flag)) return -1; if (ptrace_flush_breakpoints(pid)) @@ -1429,15 +1400,13 @@ int compel_cure_remote(struct parasite_ctl *ctl) if (!ctl->remote_map) return 0; - err = compel_syscall(ctl, __NR(munmap, !compel_mode_native(ctl)), &ret, - (unsigned long)ctl->remote_map, ctl->map_length, - 0, 0, 0, 0); + err = compel_syscall(ctl, __NR(munmap, !compel_mode_native(ctl)), &ret, (unsigned long)ctl->remote_map, + ctl->map_length, 0, 0, 0, 0); if (err) return err; if (ret) { - pr_err("munmap for remote map %p, %lu returned %lu\n", - ctl->remote_map, ctl->map_length, ret); + pr_err("munmap for remote map %p, %lu returned %lu\n", ctl->remote_map, ctl->map_length, ret); return -1; } @@ -1519,8 +1488,7 @@ int compel_unmap(struct parasite_ctl *ctl, unsigned long addr) if (ret) goto err; - ret = compel_stop_on_syscall(1, __NR(munmap, 0), - __NR(munmap, 1), TRACE_ENTER); + ret = compel_stop_on_syscall(1, __NR(munmap, 0), __NR(munmap, 1), TRACE_ENTER); /* * Don't touch extended registers here: they were restored @@ -1576,25 +1544,22 @@ static bool task_is_trapped(int status, pid_t pid) if (WIFEXITED(status)) pr_err("Task exited with %d\n", WEXITSTATUS(status)); if (WIFSIGNALED(status)) - pr_err("Task signaled with %d: %s\n", - WTERMSIG(status), strsignal(WTERMSIG(status))); + pr_err("Task signaled with %d: %s\n", WTERMSIG(status), strsignal(WTERMSIG(status))); if (WIFSTOPPED(status)) - pr_err("Task stopped with %d: %s\n", - WSTOPSIG(status), strsignal(WSTOPSIG(status))); + pr_err("Task stopped with %d: %s\n", WSTOPSIG(status), strsignal(WSTOPSIG(status))); if (WIFCONTINUED(status)) pr_err("Task continued\n"); return false; } -static inline int is_required_syscall(user_regs_struct_t *regs, pid_t pid, - const int sys_nr, const int sys_nr_compat) +static inline int is_required_syscall(user_regs_struct_t *regs, pid_t pid, const int sys_nr, const int sys_nr_compat) { const char *mode = user_regs_native(regs) ? "native" : "compat"; int req_sysnr = user_regs_native(regs) ? sys_nr : sys_nr_compat; - pr_debug("%d (%s) is going to execute the syscall %lu, required is %d\n", - pid, mode, REG_SYSCALL_NR(*regs), req_sysnr); + pr_debug("%d (%s) is going to execute the syscall %lu, required is %d\n", pid, mode, REG_SYSCALL_NR(*regs), + req_sysnr); return (REG_SYSCALL_NR(*regs) == req_sysnr); } @@ -1606,9 +1571,7 @@ static inline int is_required_syscall(user_regs_struct_t *regs, pid_t pid, * sys_nr - the required syscall number * sys_nr_compat - the required compatible syscall number */ -int compel_stop_on_syscall(int tasks, - const int sys_nr, const int sys_nr_compat, - enum trace_flags trace) +int compel_stop_on_syscall(int tasks, const int sys_nr, const int sys_nr_compat, enum trace_flags trace) { user_regs_struct_t regs; int status, ret; @@ -1668,7 +1631,7 @@ int compel_stop_on_syscall(int tasks, tasks--; continue; } -goon: + goon: ret = ptrace(PTRACE_SYSCALL, pid, NULL, NULL); if (ret) { pr_perror("ptrace"); @@ -1699,10 +1662,9 @@ k_rtsigset_t *compel_task_sigmask(struct parasite_ctl *ctl) return thread_ctx_sigmask(&ctl->orig); } -int compel_get_thread_regs(struct parasite_thread_ctl *tctl, save_regs_t save, void * arg) +int compel_get_thread_regs(struct parasite_thread_ctl *tctl, save_regs_t save, void *arg) { - return compel_get_task_regs(tctl->tid, &tctl->th.regs, &tctl->th.ext_regs, - save, arg, tctl->ctl->ictx.flags); + return compel_get_task_regs(tctl->tid, &tctl->th.regs, &tctl->th.ext_regs, save, arg, tctl->ctl->ictx.flags); } struct infect_ctx *compel_infect_ctx(struct parasite_ctl *ctl) diff --git a/compel/src/lib/ptrace.c b/compel/src/lib/ptrace.c index 4c3530c85..49b685d70 100644 --- a/compel/src/lib/ptrace.c +++ b/compel/src/lib/ptrace.c @@ -93,8 +93,7 @@ int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes) if (err) { int err2; - pr_err("Can't poke %d @ %p from %p sized %ld\n", - pid, dst, src, bytes); + pr_err("Can't poke %d @ %p from %p sized %ld\n", pid, dst, src, bytes); err2 = ptrace_poke_area(pid, t, dst, bytes); if (err2) { @@ -109,7 +108,8 @@ int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes) return 0; } -int __attribute__((weak)) ptrace_get_regs(int pid, user_regs_struct_t *regs) { +int __attribute__((weak)) ptrace_get_regs(int pid, user_regs_struct_t *regs) +{ struct iovec iov; iov.iov_base = regs; diff --git a/compel/src/main.c b/compel/src/main.c index 2c98659cc..a9a50959f 100644 --- a/compel/src/main.c +++ b/compel/src/main.c @@ -17,44 +17,44 @@ #include "piegen.h" #include "log.h" -#define CFLAGS_DEFAULT_SET \ - "-Wstrict-prototypes " \ +#define CFLAGS_DEFAULT_SET \ + "-Wstrict-prototypes " \ "-fno-stack-protector -nostdlib -fomit-frame-pointer " -#define COMPEL_CFLAGS_PIE CFLAGS_DEFAULT_SET "-fpie" -#define COMPEL_CFLAGS_NOPIC CFLAGS_DEFAULT_SET "-fno-pic" +#define COMPEL_CFLAGS_PIE CFLAGS_DEFAULT_SET "-fpie" +#define COMPEL_CFLAGS_NOPIC CFLAGS_DEFAULT_SET "-fno-pic" #ifdef NO_RELOCS -#define COMPEL_LDFLAGS_COMMON "-z noexecstack -T " +#define COMPEL_LDFLAGS_COMMON "-z noexecstack -T " #else -#define COMPEL_LDFLAGS_COMMON "-r -z noexecstack -T " +#define COMPEL_LDFLAGS_COMMON "-r -z noexecstack -T " #endif typedef struct { - const char *arch; // dir name under arch/ - const char *cflags; - const char *cflags_compat; + const char *arch; // dir name under arch/ + const char *cflags; + const char *cflags_compat; } flags_t; static const flags_t flags = { #if defined CONFIG_X86_64 - .arch = "x86", - .cflags = COMPEL_CFLAGS_PIE, - .cflags_compat = COMPEL_CFLAGS_NOPIC, + .arch = "x86", + .cflags = COMPEL_CFLAGS_PIE, + .cflags_compat = COMPEL_CFLAGS_NOPIC, #elif defined CONFIG_AARCH64 - .arch = "aarch64", - .cflags = COMPEL_CFLAGS_PIE, + .arch = "aarch64", + .cflags = COMPEL_CFLAGS_PIE, #elif defined(CONFIG_ARMV6) || defined(CONFIG_ARMV7) - .arch = "arm", - .cflags = COMPEL_CFLAGS_PIE, + .arch = "arm", + .cflags = COMPEL_CFLAGS_PIE, #elif defined CONFIG_PPC64 - .arch = "ppc64", - .cflags = COMPEL_CFLAGS_PIE, + .arch = "ppc64", + .cflags = COMPEL_CFLAGS_PIE, #elif defined CONFIG_S390 - .arch = "s390", - .cflags = COMPEL_CFLAGS_PIE, + .arch = "s390", + .cflags = COMPEL_CFLAGS_PIE, #elif defined CONFIG_MIPS - .arch = "mips", + .arch = "mips", #else #error "CONFIG_<ARCH> not defined, or unsupported ARCH" #endif @@ -123,23 +123,23 @@ static void cli_log(unsigned int lvl, const char *fmt, va_list parms) vfprintf(f, fmt, parms); } -static int usage(int rc) { +static int usage(int rc) +{ FILE *out = (rc == 0) ? stdout : stderr; fprintf(out, -"Usage:\n" -" compel [--compat] includes | cflags | ldflags\n" -" compel plugins [PLUGIN_NAME ...]\n" -" compel [--compat] [--static] libs\n" -" compel -f FILE -o FILE [-p NAME] [-l N] hgen\n" -" -f, --file FILE input (parasite object) file name\n" -" -o, --output FILE output (header) file name\n" -" -p, --prefix NAME prefix for var names\n" -" -l, --log-level NUM log level (default: %d)\n" -" compel -h|--help\n" -" compel -V|--version\n" -, COMPEL_DEFAULT_LOGLEVEL -); + "Usage:\n" + " compel [--compat] includes | cflags | ldflags\n" + " compel plugins [PLUGIN_NAME ...]\n" + " compel [--compat] [--static] libs\n" + " compel -f FILE -o FILE [-p NAME] [-l N] hgen\n" + " -f, --file FILE input (parasite object) file name\n" + " -o, --output FILE output (header) file name\n" + " -p, --prefix NAME prefix for var names\n" + " -l, --log-level NUM log level (default: %d)\n" + " compel -h|--help\n" + " compel -V|--version\n", + COMPEL_DEFAULT_LOGLEVEL); return rc; } @@ -182,12 +182,9 @@ static void print_ldflags(bool compat) printf("%s", COMPEL_LDFLAGS_COMMON); if (uninst_root) { - printf("%s/arch/%s/scripts/compel-pack%s.lds.S\n", - uninst_root, flags.arch, compat_str); + printf("%s/arch/%s/scripts/compel-pack%s.lds.S\n", uninst_root, flags.arch, compat_str); } else { - printf("%s/compel/scripts/compel-pack%s.lds.S\n", - LIBEXECDIR, compat_str); - + printf("%s/compel/scripts/compel-pack%s.lds.S\n", LIBEXECDIR, compat_str); } } @@ -196,8 +193,7 @@ static void print_plugin(const char *name) const char suffix[] = ".lib.a"; if (uninst_root) - printf("%s/plugins/%s%s\n", - uninst_root, name, suffix); + printf("%s/plugins/%s%s\n", uninst_root, name, suffix); else printf("%s/compel/%s%s\n", LIBEXECDIR, name, suffix); } @@ -307,15 +303,15 @@ int main(int argc, char *argv[]) static const char short_opts[] = "csf:o:p:hVl:"; static struct option long_opts[] = { - { "compat", no_argument, 0, 'c' }, - { "static", no_argument, 0, 's' }, - { "file", required_argument, 0, 'f' }, - { "output", required_argument, 0, 'o' }, - { "prefix", required_argument, 0, 'p' }, - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'V' }, - { "log-level", required_argument, 0, 'l' }, - { }, + { "compat", no_argument, 0, 'c' }, + { "static", no_argument, 0, 's' }, + { "file", required_argument, 0, 'f' }, + { "output", required_argument, 0, 'o' }, + { "prefix", required_argument, 0, 'p' }, + { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'V' }, + { "log-level", required_argument, 0, 'l' }, + {}, }; uninst_root = getenv("COMPEL_UNINSTALLED_ROOTDIR"); @@ -347,9 +343,7 @@ int main(int argc, char *argv[]) case 'h': return usage(0); case 'V': - printf("Version: %d.%d.%d\n", - COMPEL_SO_VERSION_MAJOR, - COMPEL_SO_VERSION_MINOR, + printf("Version: %d.%d.%d\n", COMPEL_SO_VERSION_MAJOR, COMPEL_SO_VERSION_MINOR, COMPEL_SO_VERSION_SUBLEVEL); exit(0); break; diff --git a/compel/test/fdspy/parasite.c b/compel/test/fdspy/parasite.c index 7933d29ae..2399cc3ba 100644 --- a/compel/test/fdspy/parasite.c +++ b/compel/test/fdspy/parasite.c @@ -6,11 +6,19 @@ /* * Stubs for std compel plugin. */ -int compel_main(void *arg_p, unsigned int arg_s) { return 0; } -int parasite_trap_cmd(int cmd, void *args) { return 0; } -void parasite_cleanup(void) { } +int compel_main(void *arg_p, unsigned int arg_s) +{ + return 0; +} +int parasite_trap_cmd(int cmd, void *args) +{ + return 0; +} +void parasite_cleanup(void) +{ +} -#define PARASITE_CMD_GETFD PARASITE_USER_CMDS +#define PARASITE_CMD_GETFD PARASITE_USER_CMDS int parasite_daemon_cmd(int cmd, void *args) { diff --git a/compel/test/fdspy/spy.c b/compel/test/fdspy/spy.c index bbb9eb418..7f20ea2a7 100644 --- a/compel/test/fdspy/spy.c +++ b/compel/test/fdspy/spy.c @@ -11,7 +11,7 @@ #include "parasite.h" -#define PARASITE_CMD_GETFD PARASITE_USER_CMDS +#define PARASITE_CMD_GETFD PARASITE_USER_CMDS static void print_vmsg(unsigned int lvl, const char *fmt, va_list parms) { @@ -21,7 +21,11 @@ static void print_vmsg(unsigned int lvl, const char *fmt, va_list parms) static int do_infection(int pid, int *stolen_fd) { -#define err_and_ret(msg) do { fprintf(stderr, msg); return -1; } while (0) +#define err_and_ret(msg) \ + do { \ + fprintf(stderr, msg); \ + return -1; \ + } while (0) int state; struct parasite_ctl *ctl; @@ -135,14 +139,22 @@ int main(int argc, char **argv) printf("Run the victim\n"); pid = vfork(); if (pid == 0) { - close(p_in[1]); dup2(p_in[0], 0); close(p_in[0]); - close(p_out[0]); dup2(p_out[1], 1); close(p_out[1]); - close(p_err[0]); dup2(p_err[1], 2); close(p_err[1]); + close(p_in[1]); + dup2(p_in[0], 0); + close(p_in[0]); + close(p_out[0]); + dup2(p_out[1], 1); + close(p_out[1]); + close(p_err[0]); + dup2(p_err[1], 2); + close(p_err[1]); execl("./victim", "victim", NULL); exit(1); } - close(p_in[0]); close(p_out[1]); close(p_err[1]); + close(p_in[0]); + close(p_out[1]); + close(p_err[1]); /* * Now do the infection with parasite.c diff --git a/compel/test/infect/parasite.c b/compel/test/infect/parasite.c index f18580966..ad13bd25d 100644 --- a/compel/test/infect/parasite.c +++ b/compel/test/infect/parasite.c @@ -6,11 +6,16 @@ /* * Stubs for std compel plugin. */ -int parasite_trap_cmd(int cmd, void *args) { return 0; } -void parasite_cleanup(void) { } +int parasite_trap_cmd(int cmd, void *args) +{ + return 0; +} +void parasite_cleanup(void) +{ +} -#define PARASITE_CMD_INC PARASITE_USER_CMDS -#define PARASITE_CMD_DEC PARASITE_USER_CMDS + 1 +#define PARASITE_CMD_INC PARASITE_USER_CMDS +#define PARASITE_CMD_DEC PARASITE_USER_CMDS + 1 int parasite_daemon_cmd(int cmd, void *args) { diff --git a/compel/test/infect/spy.c b/compel/test/infect/spy.c index 8be6925c5..e7273b446 100644 --- a/compel/test/infect/spy.c +++ b/compel/test/infect/spy.c @@ -8,8 +8,8 @@ #include "parasite.h" -#define PARASITE_CMD_INC PARASITE_USER_CMDS -#define PARASITE_CMD_DEC PARASITE_USER_CMDS + 1 +#define PARASITE_CMD_INC PARASITE_USER_CMDS +#define PARASITE_CMD_DEC PARASITE_USER_CMDS + 1 static void print_vmsg(unsigned int lvl, const char *fmt, va_list parms) { @@ -19,7 +19,11 @@ static void print_vmsg(unsigned int lvl, const char *fmt, va_list parms) static int do_infection(int pid) { -#define err_and_ret(msg) do { fprintf(stderr, msg); return -1; } while (0) +#define err_and_ret(msg) \ + do { \ + fprintf(stderr, msg); \ + return -1; \ + } while (0) int state; struct parasite_ctl *ctl; @@ -110,14 +114,22 @@ int main(int argc, char **argv) pid = vfork(); if (pid == 0) { - close(p_in[1]); dup2(p_in[0], 0); close(p_in[0]); - close(p_out[0]); dup2(p_out[1], 1); close(p_out[1]); - close(p_err[0]); dup2(p_err[1], 2); close(p_err[1]); + close(p_in[1]); + dup2(p_in[0], 0); + close(p_in[0]); + close(p_out[0]); + dup2(p_out[1], 1); + close(p_out[1]); + close(p_err[0]); + dup2(p_err[1], 2); + close(p_err[1]); execl("./victim", "victim", NULL); exit(1); } - close(p_in[0]); close(p_out[1]); close(p_err[1]); + close(p_in[0]); + close(p_out[1]); + close(p_err[1]); /* * Tell the little guy some numbers diff --git a/compel/test/rsys/spy.c b/compel/test/rsys/spy.c index dd89005f1..4a6fcef29 100644 --- a/compel/test/rsys/spy.c +++ b/compel/test/rsys/spy.c @@ -15,7 +15,11 @@ static void print_vmsg(unsigned int lvl, const char *fmt, va_list parms) static int do_rsetsid(int pid) { -#define err_and_ret(msg) do { fprintf(stderr, msg); return -1; } while (0) +#define err_and_ret(msg) \ + do { \ + fprintf(stderr, msg); \ + return -1; \ + } while (0) int state; long ret; @@ -85,14 +89,22 @@ int main(int argc, char **argv) pid = vfork(); if (pid == 0) { - close(p_in[1]); dup2(p_in[0], 0); close(p_in[0]); - close(p_out[0]); dup2(p_out[1], 1); close(p_out[1]); - close(p_err[0]); dup2(p_err[1], 2); close(p_err[1]); + close(p_in[1]); + dup2(p_in[0], 0); + close(p_in[0]); + close(p_out[0]); + dup2(p_out[1], 1); + close(p_out[1]); + close(p_err[0]); + dup2(p_err[1], 2); + close(p_err[1]); execl("./victim", "victim", NULL); exit(1); } - close(p_in[0]); close(p_out[1]); close(p_err[1]); + close(p_in[0]); + close(p_out[1]); + close(p_err[1]); sid = getsid(0); /* diff --git a/criu/action-scripts.c b/criu/action-scripts.c index 7a6fa56b7..cc0118353 100644 --- a/criu/action-scripts.c +++ b/criu/action-scripts.c @@ -18,18 +18,18 @@ #include "common/scm.h" static const char *action_names[ACT_MAX] = { - [ ACT_PRE_DUMP ] = "pre-dump", - [ ACT_POST_DUMP ] = "post-dump", - [ ACT_PRE_RESTORE ] = "pre-restore", - [ ACT_POST_RESTORE ] = "post-restore", - [ ACT_NET_LOCK ] = "network-lock", - [ ACT_NET_UNLOCK ] = "network-unlock", - [ ACT_SETUP_NS ] = "setup-namespaces", - [ ACT_POST_SETUP_NS ] = "post-setup-namespaces", - [ ACT_PRE_RESUME ] = "pre-resume", - [ ACT_POST_RESUME ] = "post-resume", - [ ACT_ORPHAN_PTS_MASTER ] = "orphan-pts-master", - [ ACT_STATUS_READY ] = "status-ready", + [ACT_PRE_DUMP] = "pre-dump", + [ACT_POST_DUMP] = "post-dump", + [ACT_PRE_RESTORE] = "pre-restore", + [ACT_POST_RESTORE] = "post-restore", + [ACT_NET_LOCK] = "network-lock", + [ACT_NET_UNLOCK] = "network-unlock", + [ACT_SETUP_NS] = "setup-namespaces", + [ACT_POST_SETUP_NS] = "post-setup-namespaces", + [ACT_PRE_RESUME] = "pre-resume", + [ACT_POST_RESUME] = "post-resume", + [ACT_ORPHAN_PTS_MASTER] = "orphan-pts-master", + [ACT_STATUS_READY] = "status-ready", }; struct script { @@ -37,11 +37,7 @@ struct script { char *path; }; -enum { - SCRIPTS_NONE, - SCRIPTS_SHELL, - SCRIPTS_RPC -}; +enum { SCRIPTS_NONE, SCRIPTS_SHELL, SCRIPTS_RPC }; static int scripts_mode = SCRIPTS_NONE; static LIST_HEAD(scripts); @@ -52,8 +48,8 @@ static int run_shell_scripts(const char *action) struct script *script; static unsigned env_set = 0; -#define ENV_IMGDIR 0x1 -#define ENV_ROOTPID 0x2 +#define ENV_IMGDIR 0x1 +#define ENV_ROOTPID 0x2 if (setenv("CRTOOLS_SCRIPT_ACTION", action, 1)) { pr_perror("Can't set CRTOOLS_SCRIPT_ACTION=%s", action); @@ -62,7 +58,7 @@ static int run_shell_scripts(const char *action) if (!(env_set & ENV_IMGDIR)) { char image_dir[PATH_MAX]; - sprintf(image_dir, "/proc/%ld/fd/%d", (long) getpid(), get_service_fd(IMG_FD_OFF)); + sprintf(image_dir, "/proc/%ld/fd/%d", (long)getpid(), get_service_fd(IMG_FD_OFF)); if (setenv("CRTOOLS_IMAGE_DIR", image_dir, 1)) { pr_perror("Can't set CRTOOLS_IMAGE_DIR=%s", image_dir); return -1; @@ -88,8 +84,7 @@ static int run_shell_scripts(const char *action) list_for_each_entry(script, &scripts, node) { int err; pr_debug("\t[%s]\n", script->path); - err = cr_system(-1, -1, -1, script->path, - (char *[]) { script->path, NULL }, 0); + err = cr_system(-1, -1, -1, script->path, (char *[]){ script->path, NULL }, 0); if (err) pr_err("Script %s exited with %d\n", script->path, err); retval |= err; diff --git a/criu/aio.c b/criu/aio.c index 6ee65d5f4..d2831a204 100644 --- a/criu/aio.c +++ b/criu/aio.c @@ -38,8 +38,7 @@ int dump_aio_ring(MmEntry *mme, struct vma_area *vma) } mme->aios[nr] = re; mme->n_aios = nr + 1; - pr_info("Dumping AIO ring @%"PRIx64"-%"PRIx64"\n", - vma->e->start, vma->e->end); + pr_info("Dumping AIO ring @%" PRIx64 "-%" PRIx64 "\n", vma->e->start, vma->e->end); return 0; } @@ -56,7 +55,7 @@ void free_aios(MmEntry *mme) unsigned int aio_estimate_nr_reqs(unsigned int size) { - unsigned int k_max_reqs = NR_IOEVENTS_IN_NPAGES(size/PAGE_SIZE); + unsigned int k_max_reqs = NR_IOEVENTS_IN_NPAGES(size / PAGE_SIZE); if (size & ~PAGE_MASK) { pr_err("Ring size is not aligned\n"); @@ -82,8 +81,7 @@ unsigned int aio_estimate_nr_reqs(unsigned int size) unsigned long aio_rings_args_size(struct vm_area_list *vmas) { - return sizeof(struct parasite_check_aios_args) + - vmas->nr_aios * sizeof(struct parasite_aio); + return sizeof(struct parasite_check_aios_args) + vmas->nr_aios * sizeof(struct parasite_aio); } int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas) @@ -111,8 +109,7 @@ int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas) if (!vma_area_is(vma, VMA_AREA_AIORING)) continue; - pr_debug(" `- Ring #%ld @%"PRIx64"\n", - (long)(pa - &aa->ring[0]), vma->e->start); + pr_debug(" `- Ring #%ld @%" PRIx64 "\n", (long)(pa - &aa->ring[0]), vma->e->start); pa->ctx = vma->e->start; pa->size = vma->e->end - vma->e->start; pa++; diff --git a/criu/arch/aarch64/cpu.c b/criu/arch/aarch64/cpu.c index 34313fb15..97a883b8c 100644 --- a/criu/arch/aarch64/cpu.c +++ b/criu/arch/aarch64/cpu.c @@ -1,4 +1,4 @@ -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " #include <errno.h> diff --git a/criu/arch/aarch64/crtools.c b/criu/arch/aarch64/crtools.c index 76bd1fea7..e87b8629a 100644 --- a/criu/arch/aarch64/crtools.c +++ b/criu/arch/aarch64/crtools.c @@ -21,7 +21,7 @@ #include "restorer.h" #include "compel/infect.h" -#define assign_reg(dst, src, e) dst->e = (__typeof__(dst->e))(src)->e +#define assign_reg(dst, src, e) dst->e = (__typeof__(dst->e))(src)->e int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpsimd) { @@ -35,12 +35,10 @@ int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpsi assign_reg(core->ti_aarch64->gpregs, regs, pc); assign_reg(core->ti_aarch64->gpregs, regs, pstate); - // Save the FP/SIMD state - for (i = 0; i < 32; ++i) - { - core->ti_aarch64->fpsimd->vregs[2*i] = fpsimd->vregs[i]; - core->ti_aarch64->fpsimd->vregs[2*i + 1] = fpsimd->vregs[i] >> 64; + for (i = 0; i < 32; ++i) { + core->ti_aarch64->fpsimd->vregs[2 * i] = fpsimd->vregs[i]; + core->ti_aarch64->fpsimd->vregs[2 * i + 1] = fpsimd->vregs[i] >> 64; } assign_reg(core->ti_aarch64->fpsimd, fpsimd, fpsr); assign_reg(core->ti_aarch64->fpsimd, fpsimd, fpcr); @@ -65,7 +63,7 @@ int arch_alloc_thread_info(CoreEntry *core) goto err; user_aarch64_regs_entry__init(gpregs); - gpregs->regs = xmalloc(31*sizeof(uint64_t)); + gpregs->regs = xmalloc(31 * sizeof(uint64_t)); if (!gpregs->regs) goto err; gpregs->n_regs = 31; @@ -77,7 +75,7 @@ int arch_alloc_thread_info(CoreEntry *core) goto err; user_aarch64_fpsimd_context_entry__init(fpsimd); ti_aarch64->fpsimd = fpsimd; - fpsimd->vregs = xmalloc(64*sizeof(fpsimd->vregs[0])); + fpsimd->vregs = xmalloc(64 * sizeof(fpsimd->vregs[0])); fpsimd->n_vregs = 64; if (!fpsimd->vregs) goto err; @@ -110,8 +108,8 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) return 1; for (i = 0; i < 32; ++i) - fpsimd->vregs[i] = (__uint128_t)core->ti_aarch64->fpsimd->vregs[2*i] | - ((__uint128_t)core->ti_aarch64->fpsimd->vregs[2*i + 1] << 64); + fpsimd->vregs[i] = (__uint128_t)core->ti_aarch64->fpsimd->vregs[2 * i] | + ((__uint128_t)core->ti_aarch64->fpsimd->vregs[2 * i + 1] << 64); assign_reg(fpsimd, core->ti_aarch64->fpsimd, fpsr); assign_reg(fpsimd, core->ti_aarch64->fpsimd, fpcr); @@ -123,7 +121,7 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) int restore_gpregs(struct rt_sigframe *f, UserRegsEntry *r) { -#define CPREG1(d) f->uc.uc_mcontext.d = r->d +#define CPREG1(d) f->uc.uc_mcontext.d = r->d int i; diff --git a/criu/arch/aarch64/sigframe.c b/criu/arch/aarch64/sigframe.c index be57c1670..8096fab66 100644 --- a/criu/arch/aarch64/sigframe.c +++ b/criu/arch/aarch64/sigframe.c @@ -2,8 +2,7 @@ #include <compel/asm/infect-types.h> #include "asm/sigframe.h" -int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } diff --git a/criu/arch/aarch64/vdso-pie.c b/criu/arch/aarch64/vdso-pie.c index 53d83cbe7..8b9d97274 100644 --- a/criu/arch/aarch64/vdso-pie.c +++ b/criu/arch/aarch64/vdso-pie.c @@ -8,13 +8,12 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " -int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, - struct vdso_symtable *to, struct vdso_symtable *from, - bool __always_unused compat_vdso) +int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, struct vdso_symtable *to, + struct vdso_symtable *from, bool __always_unused compat_vdso) { unsigned int i; @@ -22,12 +21,10 @@ int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, if (vdso_symbol_empty(&from->symbols[i])) continue; - pr_debug("br: %lx/%lx -> %lx/%lx (index %d)\n", - base_from, from->symbols[i].offset, - base_to, to->symbols[i].offset, i); + pr_debug("br: %lx/%lx -> %lx/%lx (index %d)\n", base_from, from->symbols[i].offset, base_to, + to->symbols[i].offset, i); - write_intraprocedure_branch(base_to + to->symbols[i].offset, - base_from + from->symbols[i].offset); + write_intraprocedure_branch(base_to + to->symbols[i].offset, base_from + from->symbols[i].offset); } return 0; diff --git a/criu/arch/arm/cpu.c b/criu/arch/arm/cpu.c index 34313fb15..97a883b8c 100644 --- a/criu/arch/arm/cpu.c +++ b/criu/arch/arm/cpu.c @@ -1,4 +1,4 @@ -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " #include <errno.h> diff --git a/criu/arch/arm/crtools.c b/criu/arch/arm/crtools.c index 840d489a6..26b94e157 100644 --- a/criu/arch/arm/crtools.c +++ b/criu/arch/arm/crtools.c @@ -20,7 +20,7 @@ #include "restorer.h" #include "compel/infect.h" -#define assign_reg(dst, src, e) dst->e = (__typeof__(dst->e))((src)->ARM_##e) +#define assign_reg(dst, src, e) dst->e = (__typeof__(dst->e))((src)->ARM_##e) int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { @@ -47,7 +47,6 @@ int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpre assign_reg(core->ti_arm->gpregs, regs, cpsr); core->ti_arm->gpregs->orig_r0 = regs->ARM_ORIG_r0; - // Save the VFP state memcpy(CORE_THREAD_ARCH_INFO(core)->fpstate->vfp_regs, &fpregs->fpregs, sizeof(fpregs->fpregs)); @@ -77,7 +76,7 @@ int arch_alloc_thread_info(CoreEntry *core) goto err; user_arm_vfpstate_entry__init(fpstate); ti_arm->fpstate = fpstate; - fpstate->vfp_regs = xmalloc(32*sizeof(unsigned long long)); + fpstate->vfp_regs = xmalloc(32 * sizeof(unsigned long long)); fpstate->n_vfp_regs = 32; if (!fpstate->vfp_regs) goto err; @@ -113,8 +112,8 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) int restore_gpregs(struct rt_sigframe *f, UserArmRegsEntry *r) { -#define CPREG1(d) f->sig.uc.uc_mcontext.arm_##d = r->d -#define CPREG2(d, s) f->sig.uc.uc_mcontext.arm_##d = r->s +#define CPREG1(d) f->sig.uc.uc_mcontext.arm_##d = r->d +#define CPREG2(d, s) f->sig.uc.uc_mcontext.arm_##d = r->s CPREG1(r0); CPREG1(r1); diff --git a/criu/arch/arm/restorer.c b/criu/arch/arm/restorer.c index 588c1c074..fd4b636b0 100644 --- a/criu/arch/arm/restorer.c +++ b/criu/arch/arm/restorer.c @@ -41,8 +41,7 @@ int restore_nonsigframe_gpregs(UserArmRegsEntry *r) * allocated with shmat(shmid, NULL, shmflg). */ #define SHMLBA (4UL * PAGE_SIZE) -unsigned long arch_shmat(int shmid, void *shmaddr, - int shmflg, unsigned long size) +unsigned long arch_shmat(int shmid, void *shmaddr, int shmflg, unsigned long size) { unsigned long smap; @@ -65,8 +64,7 @@ unsigned long arch_shmat(int shmid, void *shmaddr, pr_warn("Make sure that you don't migrate shmem from non-VIPT cached CPU to VIPT cached (e.g., ARMv7 -> ARMv6)\n"); pr_warn("Otherwise YOU HAVE A CHANCE OF DATA CORRUPTIONS in writeable shmem\n"); - smap = sys_mremap(smap, size, size, - MREMAP_FIXED | MREMAP_MAYMOVE, (unsigned long)shmaddr); + smap = sys_mremap(smap, size, size, MREMAP_FIXED | MREMAP_MAYMOVE, (unsigned long)shmaddr); if (IS_ERR_VALUE(smap)) pr_err("mremap() for shmem failed: %d\n", (int)smap); return smap; diff --git a/criu/arch/arm/sigframe.c b/criu/arch/arm/sigframe.c index be57c1670..8096fab66 100644 --- a/criu/arch/arm/sigframe.c +++ b/criu/arch/arm/sigframe.c @@ -2,8 +2,7 @@ #include <compel/asm/infect-types.h> #include "asm/sigframe.h" -int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } diff --git a/criu/arch/arm/vdso-pie.c b/criu/arch/arm/vdso-pie.c index 0ec8bd9a8..ecfe6a498 100644 --- a/criu/arch/arm/vdso-pie.c +++ b/criu/arch/arm/vdso-pie.c @@ -9,32 +9,31 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " static void insert_trampoline(uintptr_t from, uintptr_t to) { struct { - uint32_t ldr_pc; - uint32_t imm32; - uint32_t guards; + uint32_t ldr_pc; + uint32_t imm32; + uint32_t guards; } __packed jmp = { - .ldr_pc = 0xe51ff004, /* ldr pc, [pc, #-4] */ - .imm32 = to, - .guards = 0xe1200070, /* bkpt 0x0000 */ + .ldr_pc = 0xe51ff004, /* ldr pc, [pc, #-4] */ + .imm32 = to, + .guards = 0xe1200070, /* bkpt 0x0000 */ }; - void *iflush_start = (void *)from; - void *iflush_end = iflush_start + sizeof(jmp); + void *iflush_start = (void *)from; + void *iflush_end = iflush_start + sizeof(jmp); memcpy((void *)from, &jmp, sizeof(jmp)); __builtin___clear_cache(iflush_start, iflush_end); } -int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, - struct vdso_symtable *sto, struct vdso_symtable *sfrom, - bool compat_vdso) +int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, struct vdso_symtable *sto, + struct vdso_symtable *sfrom, bool compat_vdso) { unsigned int i; @@ -44,9 +43,8 @@ int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, if (vdso_symbol_empty(&sfrom->symbols[i])) continue; - pr_debug("jmp: %lx/%lx -> %lx/%lx (index %d)\n", - base_from, sfrom->symbols[i].offset, - base_to, sto->symbols[i].offset, i); + pr_debug("jmp: %lx/%lx -> %lx/%lx (index %d)\n", base_from, sfrom->symbols[i].offset, base_to, + sto->symbols[i].offset, i); from = base_from + sfrom->symbols[i].offset; to = base_to + sto->symbols[i].offset; diff --git a/criu/arch/mips/cpu.c b/criu/arch/mips/cpu.c index f76afc2a2..55b385d09 100644 --- a/criu/arch/mips/cpu.c +++ b/criu/arch/mips/cpu.c @@ -20,7 +20,7 @@ #include "protobuf.h" #include "images/cpuinfo.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " int cpu_init(void) diff --git a/criu/arch/mips/crtools.c b/criu/arch/mips/crtools.c index 72bd2c303..ed4da9b7e 100644 --- a/criu/arch/mips/crtools.c +++ b/criu/arch/mips/crtools.c @@ -27,7 +27,6 @@ #include "images/core.pb-c.h" #include "images/creds.pb-c.h" - int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { CoreEntry *core = x; @@ -203,7 +202,6 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) return 0; } - int restore_gpregs(struct rt_sigframe *f, UserMipsRegsEntry *r) { f->rs_uc.uc_mcontext.sc_regs[0] = r->r0; diff --git a/criu/arch/mips/restorer.c b/criu/arch/mips/restorer.c index d840c8913..45a0f0a64 100644 --- a/criu/arch/mips/restorer.c +++ b/criu/arch/mips/restorer.c @@ -17,8 +17,7 @@ int restore_nonsigframe_gpregs(UserMipsRegsEntry *r) } #define SHMLBA 0x40000 -unsigned long arch_shmat(int shmid, void *shmaddr, - int shmflg, unsigned long size) +unsigned long arch_shmat(int shmid, void *shmaddr, int shmflg, unsigned long size) { unsigned long smap; @@ -36,13 +35,12 @@ unsigned long arch_shmat(int shmid, void *shmaddr, if (smap == (unsigned long)shmaddr) return smap; - /* Warn ALOUD */ + /* Warn ALOUD */ pr_warn("Restoring shmem %p unaligned to SHMLBA.\n", shmaddr); pr_warn("Make sure that you don't migrate shmem from non-VIPT cached CPU to VIPT cached \n"); pr_warn("Otherwise YOU HAVE A CHANCE OF DATA CORRUPTIONS in writeable shmem\n"); - smap = sys_mremap(smap, size, size, - MREMAP_FIXED | MREMAP_MAYMOVE, (unsigned long)shmaddr); + smap = sys_mremap(smap, size, size, MREMAP_FIXED | MREMAP_MAYMOVE, (unsigned long)shmaddr); if (IS_ERR_VALUE(smap)) pr_err("mremap() for shmem failed: %d\n", (int)smap); return smap; diff --git a/criu/arch/mips/sigaction_compat.c b/criu/arch/mips/sigaction_compat.c index cd9c9559d..b389b7b73 100644 --- a/criu/arch/mips/sigaction_compat.c +++ b/criu/arch/mips/sigaction_compat.c @@ -5,7 +5,7 @@ #include <compel/plugins/std/syscall-codes.h> #ifdef CR_NOGLIBC -# include <compel/plugins/std/string.h> +#include <compel/plugins/std/string.h> #endif #include "cpu.h" @@ -16,4 +16,3 @@ int arch_compat_rt_sigaction(void *stack32, int sig, rt_sigaction_t_compat *act) { return 0; } - diff --git a/criu/arch/mips/sigframe.c b/criu/arch/mips/sigframe.c index 4950613dc..18983ff13 100644 --- a/criu/arch/mips/sigframe.c +++ b/criu/arch/mips/sigframe.c @@ -6,8 +6,7 @@ #include "log.h" #include <stdio.h> -int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } diff --git a/criu/arch/mips/vdso-pie.c b/criu/arch/mips/vdso-pie.c index 5fd15f3dc..3bb92d857 100644 --- a/criu/arch/mips/vdso-pie.c +++ b/criu/arch/mips/vdso-pie.c @@ -8,31 +8,30 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " static void insert_trampoline(uintptr_t from, uintptr_t to) { struct { - uint32_t ldr_pc; - uint32_t imm32; - uint32_t guards; + uint32_t ldr_pc; + uint32_t imm32; + uint32_t guards; } __packed jmp = { - .ldr_pc = 0x1000fffe, /* b -4 */ - .imm32 = to, - .guards = 0x0000000d, /* break */ + .ldr_pc = 0x1000fffe, /* b -4 */ + .imm32 = to, + .guards = 0x0000000d, /* break */ }; - void *iflush_start = (void *)from; - void *iflush_end = iflush_start + sizeof(jmp); + void *iflush_start = (void *)from; + void *iflush_end = iflush_start + sizeof(jmp); memcpy((void *)from, &jmp, sizeof(jmp)); sys_cacheflush(iflush_start, sizeof(jmp), 0); } -int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, - struct vdso_symtable *sto, struct vdso_symtable *sfrom, - bool compat_vdso) +int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, struct vdso_symtable *sto, + struct vdso_symtable *sfrom, bool compat_vdso) { unsigned int i; @@ -42,9 +41,8 @@ int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, if (vdso_symbol_empty(&sfrom->symbols[i])) continue; - pr_debug("jmp: %lx/%lx -> %lx/%lx (index %d)\n", - base_from, sfrom->symbols[i].offset, - base_to, sto->symbols[i].offset, i); + pr_debug("jmp: %lx/%lx -> %lx/%lx (index %d)\n", base_from, sfrom->symbols[i].offset, base_to, + sto->symbols[i].offset, i); from = base_from + sfrom->symbols[i].offset; to = base_to + sto->symbols[i].offset; diff --git a/criu/arch/ppc64/cpu.c b/criu/arch/ppc64/cpu.c index 4fcfb065a..bb5b7256e 100644 --- a/criu/arch/ppc64/cpu.c +++ b/criu/arch/ppc64/cpu.c @@ -1,4 +1,4 @@ -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " #include <sys/auxv.h> @@ -19,9 +19,9 @@ static compel_cpuinfo_t rt_cpuinfo; #ifdef __LITTLE_ENDIAN__ -#define CURRENT_ENDIANNESS CPUINFO_PPC64_ENTRY__ENDIANNESS__LITTLEENDIAN +#define CURRENT_ENDIANNESS CPUINFO_PPC64_ENTRY__ENDIANNESS__LITTLEENDIAN #else -#define CURRENT_ENDIANNESS CPUINFO_PPC64_ENTRY__ENDIANESS__BIGENDIAN +#define CURRENT_ENDIANNESS CPUINFO_PPC64_ENTRY__ENDIANESS__BIGENDIAN #endif int cpu_init(void) @@ -83,21 +83,23 @@ int cpu_validate_cpuinfo(void) goto error; } -#define CHECK_FEATURE(s,f) do { \ - if ((cpu_ppc64_entry->hwcap[s] & f) && \ - !(rt_cpuinfo.hwcap[s] & f)) { \ - pr_err("CPU Feature %s required by image " \ - "is not supported on host.\n", #f); \ - goto error; \ - } \ - } while(0) - -#define REQUIRE_FEATURE(s,f) do { \ - if (!(cpu_ppc64_entry->hwcap[s] & f)) { \ +#define CHECK_FEATURE(s, f) \ + do { \ + if ((cpu_ppc64_entry->hwcap[s] & f) && !(rt_cpuinfo.hwcap[s] & f)) { \ + pr_err("CPU Feature %s required by image " \ + "is not supported on host.\n", \ + #f); \ + goto error; \ + } \ + } while (0) + +#define REQUIRE_FEATURE(s, f) \ + do { \ + if (!(cpu_ppc64_entry->hwcap[s] & f)) { \ pr_err("CPU Feature %s missing in image.\n", #f); \ - goto error; \ - } \ - } while(0) + goto error; \ + } \ + } while (0) REQUIRE_FEATURE(0, PPC_FEATURE_64); REQUIRE_FEATURE(0, PPC_FEATURE_HAS_FPU); diff --git a/criu/arch/ppc64/crtools.c b/criu/arch/ppc64/crtools.c index 631150c3e..a08a2ca5b 100644 --- a/criu/arch/ppc64/crtools.c +++ b/criu/arch/ppc64/crtools.c @@ -53,7 +53,7 @@ static void put_fpu_regs(mcontext_t *mc, UserPpc64FpstateEntry *fpe) size_t i; for (i = 0; i < fpe->n_fpregs; i++) - mcfp[i] = fpe->fpregs[i]; + mcfp[i] = fpe->fpregs[i]; } static UserPpc64VrstateEntry *copy_altivec_regs(__vector128 *vrregs) @@ -69,7 +69,7 @@ static UserPpc64VrstateEntry *copy_altivec_regs(__vector128 *vrregs) user_ppc64_vrstate_entry__init(vse); /* protocol buffer store only 64bit entries and we need 128bit */ - vse->n_vrregs = (NVRREG-1) * 2; + vse->n_vrregs = (NVRREG - 1) * 2; vse->vrregs = xmalloc(vse->n_vrregs * sizeof(vse->vrregs[0])); if (!vse->vrregs) { xfree(vse); @@ -77,13 +77,13 @@ static UserPpc64VrstateEntry *copy_altivec_regs(__vector128 *vrregs) } /* Vectors are 2*64bits entries */ - for (i = 0; i < (NVRREG-1); i++) { - p64 = (uint64_t*) &vrregs[i]; - vse->vrregs[i*2] = p64[0]; - vse->vrregs[i*2 + 1] = p64[1]; + for (i = 0; i < (NVRREG - 1); i++) { + p64 = (uint64_t *)&vrregs[i]; + vse->vrregs[i * 2] = p64[0]; + vse->vrregs[i * 2 + 1] = p64[1]; } - p32 = (uint32_t*) &vrregs[NVRREG-1]; + p32 = (uint32_t *)&vrregs[NVRREG - 1]; vse->vrsave = *p32; return vse; @@ -95,7 +95,7 @@ static int put_altivec_regs(mcontext_t *mc, UserPpc64VrstateEntry *vse) pr_debug("Restoring Altivec registers\n"); - if (vse->n_vrregs != (NVRREG-1)*2) { + if (vse->n_vrregs != (NVRREG - 1) * 2) { pr_err("Corrupted Altivec dump data\n"); return -1; } @@ -103,8 +103,7 @@ static int put_altivec_regs(mcontext_t *mc, UserPpc64VrstateEntry *vse) /* Note that this should only be done in the case MSR_VEC is set but * this is not a big deal to do that in all cases. */ - memcpy(&v_regs->vrregs[0][0], vse->vrregs, - sizeof(uint64_t) * 2 * (NVRREG-1)); + memcpy(&v_regs->vrregs[0][0], vse->vrregs, sizeof(uint64_t) * 2 * (NVRREG - 1)); /* vscr has been restored with the previous memcpy which copied 32 * 128bits registers + a 128bits field containing the vscr value in * the low part. @@ -116,7 +115,7 @@ static int put_altivec_regs(mcontext_t *mc, UserPpc64VrstateEntry *vse) return 0; } -static UserPpc64VsxstateEntry* copy_vsx_regs(uint64_t *vsregs) +static UserPpc64VsxstateEntry *copy_vsx_regs(uint64_t *vsregs) { UserPpc64VsxstateEntry *vse; int i; @@ -128,7 +127,7 @@ static UserPpc64VsxstateEntry* copy_vsx_regs(uint64_t *vsregs) user_ppc64_vsxstate_entry__init(vse); vse->n_vsxregs = NVSXREG; - vse->vsxregs = xmalloc(vse->n_vsxregs*sizeof(vse->vsxregs[0])); + vse->vsxregs = xmalloc(vse->n_vsxregs * sizeof(vse->vsxregs[0])); if (!vse->vsxregs) { xfree(vse); return NULL; @@ -153,25 +152,25 @@ static int put_vsx_regs(mcontext_t *mc, UserPpc64VsxstateEntry *vse) } /* point after the Altivec registers */ - buf = (uint64_t*) (mc->v_regs + 1); + buf = (uint64_t *)(mc->v_regs + 1); /* Copy the value saved by get_vsx_regs in the sigframe */ - for (i=0; i < vse->n_vsxregs; i++) + for (i = 0; i < vse->n_vsxregs; i++) buf[i] = vse->vsxregs[i]; return 0; } - static void copy_gp_regs(UserPpc64RegsEntry *dst, user_regs_struct_t *src) { int i; -#define assign_reg(e) do { \ - dst->e = (__typeof__(dst->e))src->e; \ -} while (0) +#define assign_reg(e) \ + do { \ + dst->e = (__typeof__(dst->e))src->e; \ + } while (0) - for (i=0; i<32; i++) + for (i = 0; i < 32; i++) assign_reg(gpr[i]); assign_reg(nip); assign_reg(msr); @@ -189,17 +188,17 @@ static void restore_gp_regs(mcontext_t *dst, UserPpc64RegsEntry *src) int i; /* r0 to r31 */ - for (i=0; i<32; i++) - dst->gp_regs[i] = src->gpr[i]; - - dst->gp_regs[PT_NIP] = src->nip; - dst->gp_regs[PT_MSR] = src->msr; - dst->gp_regs[PT_ORIG_R3] = src->orig_gpr3; - dst->gp_regs[PT_CTR] = src->ctr; - dst->gp_regs[PT_LNK] = src->link; - dst->gp_regs[PT_XER] = src->xer; - dst->gp_regs[PT_CCR] = src->ccr; - dst->gp_regs[PT_TRAP] = src->trap; + for (i = 0; i < 32; i++) + dst->gp_regs[i] = src->gpr[i]; + + dst->gp_regs[PT_NIP] = src->nip; + dst->gp_regs[PT_MSR] = src->msr; + dst->gp_regs[PT_ORIG_R3] = src->orig_gpr3; + dst->gp_regs[PT_CTR] = src->ctr; + dst->gp_regs[PT_LNK] = src->link; + dst->gp_regs[PT_XER] = src->xer; + dst->gp_regs[PT_CCR] = src->ccr; + dst->gp_regs[PT_TRAP] = src->trap; } static UserPpc64RegsEntry *allocate_gp_regs(void) @@ -250,7 +249,7 @@ static void xfree_tm_state(UserPpc64TmRegsEntry *tme) static int put_tm_regs(struct rt_sigframe *f, UserPpc64TmRegsEntry *tme) { -/* + /* * WARNING: As stated in kernel's restore_tm_sigcontexts, TEXASR has to be * restored by the process itself : * TEXASR was set by the signal delivery reclaim, as was TFIAR. @@ -261,20 +260,17 @@ static int put_tm_regs(struct rt_sigframe *f, UserPpc64TmRegsEntry *tme) */ ucontext_t *tm_uc = &f->uc_transact; - pr_debug("Restoring TM registers FP:%d VR:%d VSX:%d\n", - !!(tme->fpstate), !!(tme->vrstate), !!(tme->vsxstate)); + pr_debug("Restoring TM registers FP:%d VR:%d VSX:%d\n", !!(tme->fpstate), !!(tme->vrstate), !!(tme->vsxstate)); restore_gp_regs(&tm_uc->uc_mcontext, tme->gpregs); if (tme->fpstate) put_fpu_regs(&tm_uc->uc_mcontext, tme->fpstate); - if (tme->vrstate && put_altivec_regs(&tm_uc->uc_mcontext, - tme->vrstate)) + if (tme->vrstate && put_altivec_regs(&tm_uc->uc_mcontext, tme->vrstate)) return -1; - if (tme->vsxstate && put_vsx_regs(&tm_uc->uc_mcontext, - tme->vsxstate)) + if (tme->vsxstate && put_vsx_regs(&tm_uc->uc_mcontext, tme->vsxstate)) return -1; f->uc.uc_link = tm_uc; @@ -282,8 +278,7 @@ static int put_tm_regs(struct rt_sigframe *f, UserPpc64TmRegsEntry *tme) } /****************************************************************************/ -static int copy_tm_regs(user_regs_struct_t *regs, user_fpregs_struct_t *fpregs, - CoreEntry *core) +static int copy_tm_regs(user_regs_struct_t *regs, user_fpregs_struct_t *fpregs, CoreEntry *core) { UserPpc64TmRegsEntry *tme; UserPpc64RegsEntry *gpregs = core->ti_ppc64->gpregs; @@ -299,13 +294,12 @@ static int copy_tm_regs(user_regs_struct_t *regs, user_fpregs_struct_t *fpregs, if (!tme->gpregs) goto out_free; - gpregs->has_tfhar = true; - gpregs->tfhar = fpregs->tm.tm_spr_regs.tfhar; - gpregs->has_texasr = true; - gpregs->texasr = fpregs->tm.tm_spr_regs.texasr; - gpregs->has_tfiar = true; - gpregs->tfiar = fpregs->tm.tm_spr_regs.tfiar; - + gpregs->has_tfhar = true; + gpregs->tfhar = fpregs->tm.tm_spr_regs.tfhar; + gpregs->has_texasr = true; + gpregs->texasr = fpregs->tm.tm_spr_regs.texasr; + gpregs->has_tfiar = true; + gpregs->tfiar = fpregs->tm.tm_spr_regs.tfiar; /* This is the checkpointed state, we must save it in place of the * current state because the signal handler is made in this way. @@ -352,9 +346,7 @@ out_free: return -1; } -static int __copy_task_regs(user_regs_struct_t *regs, - user_fpregs_struct_t *fpregs, - CoreEntry *core) +static int __copy_task_regs(user_regs_struct_t *regs, user_fpregs_struct_t *fpregs, CoreEntry *core) { UserPpc64RegsEntry *gpregs; UserPpc64FpstateEntry **fpstate; @@ -423,7 +415,7 @@ int arch_alloc_thread_info(CoreEntry *core) ThreadInfoPpc64 *ti_ppc64; ti_ppc64 = xmalloc(sizeof(*ti_ppc64)); - if(!ti_ppc64) + if (!ti_ppc64) return -1; thread_info_ppc64__init(ti_ppc64); @@ -466,28 +458,24 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) int ret = 0; if (CORE_THREAD_ARCH_INFO(core)->fpstate) - put_fpu_regs(&sigframe->uc.uc_mcontext, - CORE_THREAD_ARCH_INFO(core)->fpstate); + put_fpu_regs(&sigframe->uc.uc_mcontext, CORE_THREAD_ARCH_INFO(core)->fpstate); if (CORE_THREAD_ARCH_INFO(core)->vrstate) - ret = put_altivec_regs(&sigframe->uc.uc_mcontext, - CORE_THREAD_ARCH_INFO(core)->vrstate); + ret = put_altivec_regs(&sigframe->uc.uc_mcontext, CORE_THREAD_ARCH_INFO(core)->vrstate); else if (core->ti_ppc64->gpregs->msr & MSR_VEC) { pr_err("Register's data mismatch, corrupted image ?\n"); ret = -1; } if (!ret && CORE_THREAD_ARCH_INFO(core)->vsxstate) - ret = put_vsx_regs(&sigframe->uc.uc_mcontext, - CORE_THREAD_ARCH_INFO(core)->vsxstate); + ret = put_vsx_regs(&sigframe->uc.uc_mcontext, CORE_THREAD_ARCH_INFO(core)->vsxstate); else if (core->ti_ppc64->gpregs->msr & MSR_VSX) { pr_err("VSX register's data mismatch, corrupted image ?\n"); ret = -1; } if (!ret && CORE_THREAD_ARCH_INFO(core)->tmstate) - ret = put_tm_regs(sigframe, - CORE_THREAD_ARCH_INFO(core)->tmstate); + ret = put_tm_regs(sigframe, CORE_THREAD_ARCH_INFO(core)->tmstate); else if (MSR_TM_ACTIVE(core->ti_ppc64->gpregs->msr)) { pr_err("TM register's data mismatch, corrupted image ?\n"); ret = -1; diff --git a/criu/arch/ppc64/restorer.c b/criu/arch/ppc64/restorer.c index 7172e44c3..c17ba1669 100644 --- a/criu/arch/ppc64/restorer.c +++ b/criu/arch/ppc64/restorer.c @@ -9,35 +9,32 @@ int restore_nonsigframe_gpregs(UserPpc64RegsEntry *r) { -#define SPRN_TFHAR 128 -#define SPRN_TFIAR 129 -#define SPRN_TEXASR 130 +#define SPRN_TFHAR 128 +#define SPRN_TFIAR 129 +#define SPRN_TEXASR 130 if (r->has_tfhar) { - asm __volatile__ ( - "ld 3, %[value] ;" - "mtspr %[sprn],3 ;" - : [value]"=m"(r->tfhar) - : [sprn]"i"(SPRN_TFHAR) - : "r3"); + asm __volatile__("ld 3, %[value] ;" + "mtspr %[sprn],3 ;" + : [value] "=m"(r->tfhar) + : [sprn] "i"(SPRN_TFHAR) + : "r3"); } if (r->has_tfiar) { - asm __volatile__ ( - "ld 3, %[value] ;" - "mtspr %[sprn],3 ;" - : [value]"=m"(r->tfiar) - : [sprn]"i"(SPRN_TFIAR) - : "r3"); + asm __volatile__("ld 3, %[value] ;" + "mtspr %[sprn],3 ;" + : [value] "=m"(r->tfiar) + : [sprn] "i"(SPRN_TFIAR) + : "r3"); } if (r->has_texasr) { - asm __volatile__ ( - "ld 3, %[value] ;" - "mtspr %[sprn],3 ;" - : [value]"=m"(r->texasr) - : [sprn]"i"(SPRN_TEXASR) - : "r3"); + asm __volatile__("ld 3, %[value] ;" + "mtspr %[sprn],3 ;" + : [value] "=m"(r->texasr) + : [sprn] "i"(SPRN_TEXASR) + : "r3"); } return 0; @@ -48,15 +45,14 @@ unsigned long sys_shmat(int shmid, const void *shmaddr, int shmflg) unsigned long raddr; int ret; - ret = sys_ipc(21 /*SHMAT */, - shmid, /* first */ - shmflg, /* second */ - (unsigned long)&raddr, /* third */ - shmaddr, /* ptr */ - 0 /* fifth not used */); + ret = sys_ipc(21 /*SHMAT */, shmid, /* first */ + shmflg, /* second */ + (unsigned long)&raddr, /* third */ + shmaddr, /* ptr */ + 0 /* fifth not used */); if (ret) - raddr = (unsigned long) ret; + raddr = (unsigned long)ret; return raddr; } diff --git a/criu/arch/ppc64/sigframe.c b/criu/arch/ppc64/sigframe.c index 52fad2e9a..5a98eb8b9 100644 --- a/criu/arch/ppc64/sigframe.c +++ b/criu/arch/ppc64/sigframe.c @@ -18,14 +18,12 @@ static inline void update_vregs(mcontext_t *lcontext, mcontext_t *rcontext) uint64_t offset = (uint64_t)(lcontext->v_regs) - (uint64_t)lcontext; lcontext->v_regs = (vrregset_t *)((uint64_t)rcontext + offset); - pr_debug("Updated v_regs:%llx (rcontext:%llx)\n", - (unsigned long long) lcontext->v_regs, - (unsigned long long) rcontext); + pr_debug("Updated v_regs:%llx (rcontext:%llx)\n", (unsigned long long)lcontext->v_regs, + (unsigned long long)rcontext); } } -int sigreturn_prep_fpu_frame(struct rt_sigframe *frame, - struct rt_sigframe *rframe) +int sigreturn_prep_fpu_frame(struct rt_sigframe *frame, struct rt_sigframe *rframe) { uint64_t msr = frame->uc.uc_mcontext.gp_regs[PT_MSR]; @@ -39,9 +37,8 @@ int sigreturn_prep_fpu_frame(struct rt_sigframe *frame, /* Updating the transactional state address if any */ if (frame->uc.uc_link) { - update_vregs(&frame->uc_transact.uc_mcontext, - &rframe->uc_transact.uc_mcontext); - frame->uc.uc_link = &rframe->uc_transact; + update_vregs(&frame->uc_transact.uc_mcontext, &rframe->uc_transact.uc_mcontext); + frame->uc.uc_link = &rframe->uc_transact; } return 0; diff --git a/criu/arch/ppc64/vdso-pie.c b/criu/arch/ppc64/vdso-pie.c index 910c3d38b..f01123efe 100644 --- a/criu/arch/ppc64/vdso-pie.c +++ b/criu/arch/ppc64/vdso-pie.c @@ -9,7 +9,7 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " @@ -18,15 +18,15 @@ extern char *vdso_trampoline, *vdso_trampoline_end; static inline void invalidate_caches(unsigned long at) { - asm volatile("isync \n" \ - "li 3,0 \n" \ - "dcbf 3,%0 \n" \ - "sync \n" \ - "icbi 3,%0 \n" \ - "isync \n" \ - : /* no output */ \ - : "r"(at) \ - :"memory", "r3"); + asm volatile("isync \n" + "li 3,0 \n" + "dcbf 3,%0 \n" + "sync \n" + "icbi 3,%0 \n" + "isync \n" + : /* no output */ + : "r"(at) + : "memory", "r3"); } /* This is the size of the trampoline call : @@ -34,7 +34,7 @@ static inline void invalidate_caches(unsigned long at) * bl trampoline * <64 bit address> */ -#define TRAMP_CALL_SIZE (2*sizeof(uint32_t) + sizeof(uint64_t)) +#define TRAMP_CALL_SIZE (2 * sizeof(uint32_t) + sizeof(uint64_t)) /* * put_trampoline does 2 things : @@ -53,39 +53,35 @@ static inline void invalidate_caches(unsigned long at) */ static unsigned long put_trampoline(unsigned long at, struct vdso_symtable *sym) { - int i,j; + int i, j; unsigned long size; unsigned long trampoline = 0; /* First of all we have to find a place where to put the trampoline * code. */ - size = (unsigned long)&vdso_trampoline_end - - (unsigned long)&vdso_trampoline; + size = (unsigned long)&vdso_trampoline_end - (unsigned long)&vdso_trampoline; for (i = 0; i < ARRAY_SIZE(sym->symbols); i++) { if (vdso_symbol_empty(&sym->symbols[i])) continue; - pr_debug("Checking '%s' at %lx\n", sym->symbols[i].name, - sym->symbols[i].offset); + pr_debug("Checking '%s' at %lx\n", sym->symbols[i].name, sym->symbols[i].offset); /* find the nearest following symbol we are interested in */ - for (j=0; j < ARRAY_SIZE(sym->symbols); j++) { - if (i==j || vdso_symbol_empty(&sym->symbols[j])) + for (j = 0; j < ARRAY_SIZE(sym->symbols); j++) { + if (i == j || vdso_symbol_empty(&sym->symbols[j])) continue; if (sym->symbols[j].offset <= sym->symbols[i].offset) /* this symbol is above the current one */ continue; - if ((sym->symbols[i].offset+TRAMP_CALL_SIZE) > - sym->symbols[j].offset) { + if ((sym->symbols[i].offset + TRAMP_CALL_SIZE) > sym->symbols[j].offset) { /* we have a major issue here since we cannot * even put the trampoline call for this symbol */ - pr_err("Can't handle small vDSO symbol %s\n", - sym->symbols[i].name); + pr_err("Can't handle small vDSO symbol %s\n", sym->symbols[i].name); return 0; } @@ -93,8 +89,7 @@ static unsigned long put_trampoline(unsigned long at, struct vdso_symtable *sym) /* no need to put it twice */ continue; - if ((sym->symbols[j].offset - - (sym->symbols[i].offset+TRAMP_CALL_SIZE)) <= size) + if ((sym->symbols[j].offset - (sym->symbols[i].offset + TRAMP_CALL_SIZE)) <= size) /* not enough place */ continue; @@ -102,10 +97,8 @@ static unsigned long put_trampoline(unsigned long at, struct vdso_symtable *sym) trampoline = at + sym->symbols[i].offset; trampoline += TRAMP_CALL_SIZE; - pr_debug("Putting vDSO trampoline in %s at %lx\n", - sym->symbols[i].name, trampoline); - memcpy((void *)trampoline, &vdso_trampoline, - size); + pr_debug("Putting vDSO trampoline in %s at %lx\n", sym->symbols[i].name, trampoline); + memcpy((void *)trampoline, &vdso_trampoline, size); invalidate_caches(trampoline); } } @@ -113,21 +106,19 @@ static unsigned long put_trampoline(unsigned long at, struct vdso_symtable *sym) return trampoline; } -static inline void put_trampoline_call(unsigned long at, unsigned long to, - unsigned long tr) +static inline void put_trampoline_call(unsigned long at, unsigned long to, unsigned long tr) { - uint32_t *addr = (uint32_t *)at; + uint32_t *addr = (uint32_t *)at; - *addr++ = 0x7C0802a6; /* mflr r0 */ - *addr++ = 0x48000001 | ((long)(tr-at-4) & 0x3fffffc); /* bl tr */ - *(uint64_t *)addr = to; /* the address to read by the trampoline */ + *addr++ = 0x7C0802a6; /* mflr r0 */ + *addr++ = 0x48000001 | ((long)(tr - at - 4) & 0x3fffffc); /* bl tr */ + *(uint64_t *)addr = to; /* the address to read by the trampoline */ - invalidate_caches(at); + invalidate_caches(at); } -int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, - struct vdso_symtable *to, struct vdso_symtable *from, - bool __always_unused compat_vdso) +int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, struct vdso_symtable *to, + struct vdso_symtable *from, bool __always_unused compat_vdso) { unsigned int i; unsigned long trampoline; @@ -140,14 +131,10 @@ int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, if (vdso_symbol_empty(&from->symbols[i])) continue; - pr_debug("br: %lx/%lx -> %lx/%lx (index %d) '%s'\n", - base_from, from->symbols[i].offset, - base_to, to->symbols[i].offset, i, - from->symbols[i].name); + pr_debug("br: %lx/%lx -> %lx/%lx (index %d) '%s'\n", base_from, from->symbols[i].offset, base_to, + to->symbols[i].offset, i, from->symbols[i].name); - put_trampoline_call(base_from + from->symbols[i].offset, - base_to + to->symbols[i].offset, - trampoline); + put_trampoline_call(base_from + from->symbols[i].offset, base_to + to->symbols[i].offset, trampoline); } return 0; diff --git a/criu/arch/s390/cpu.c b/criu/arch/s390/cpu.c index f93666ed6..3f430f455 100644 --- a/criu/arch/s390/cpu.c +++ b/criu/arch/s390/cpu.c @@ -1,4 +1,4 @@ -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " #include <sys/auxv.h> @@ -18,22 +18,11 @@ static compel_cpuinfo_t rt_cpuinfo; static const char *hwcap_str1[64] = { - "HWCAP_S390_ESAN3", - "HWCAP_S390_ZARCH", - "HWCAP_S390_STFLE", - "HWCAP_S390_MSA", - "HWCAP_S390_LDISP", - "HWCAP_S390_EIMM", - "HWCAP_S390_DFP", - "HWCAP_S390_HPAGE", - "HWCAP_S390_ETF3EH", - "HWCAP_S390_HIGH_GPRS", - "HWCAP_S390_TE", - "HWCAP_S390_VXRS", - "HWCAP_S390_VXRS_BCD", - "HWCAP_S390_VXRS_EXT", + "HWCAP_S390_ESAN3", "HWCAP_S390_ZARCH", "HWCAP_S390_STFLE", "HWCAP_S390_MSA", "HWCAP_S390_LDISP", + "HWCAP_S390_EIMM", "HWCAP_S390_DFP", "HWCAP_S390_HPAGE", "HWCAP_S390_ETF3EH", "HWCAP_S390_HIGH_GPRS", + "HWCAP_S390_TE", "HWCAP_S390_VXRS", "HWCAP_S390_VXRS_BCD", "HWCAP_S390_VXRS_EXT", }; -static const char *hwcap_str2[64] = { }; +static const char *hwcap_str2[64] = {}; static const char **hwcap_str[2] = { hwcap_str1, hwcap_str2 }; @@ -73,7 +62,7 @@ int cpu_dump_cpuinfo(void) img = open_image(CR_FD_CPUINFO, O_DUMP); if (!img) - return -1; + return -1; cpu_info.s390_entry = &cpu_s390_info_ptr; cpu_info.n_s390_entry = 1; @@ -124,11 +113,9 @@ int cpu_validate_cpuinfo(void) if (rt_cpuinfo.hwcap[nr] & (1 << cap)) continue; if (hwcap_str[nr][cap]) - pr_err("CPU Feature %s not supported on host\n", - hwcap_str[nr][cap]); + pr_err("CPU Feature %s not supported on host\n", hwcap_str[nr][cap]); else - pr_err("CPU Feature %d/%x not supported on host\n", - nr, 1 << cap); + pr_err("CPU Feature %d/%x not supported on host\n", nr, 1 << cap); ret = -1; } } diff --git a/criu/arch/s390/crtools.c b/criu/arch/s390/crtools.c index 000b7779f..b22b64e2b 100644 --- a/criu/arch/s390/crtools.c +++ b/criu/arch/s390/crtools.c @@ -26,12 +26,12 @@ #include "pstree.h" #include "image.h" -#define NT_PRFPREG 2 -#define NT_S390_VXRS_LOW 0x309 -#define NT_S390_VXRS_HIGH 0x30a -#define NT_S390_GS_CB 0x30b -#define NT_S390_GS_BC 0x30c -#define NT_S390_RI_CB 0x30d +#define NT_PRFPREG 2 +#define NT_S390_VXRS_LOW 0x309 +#define NT_S390_VXRS_HIGH 0x30a +#define NT_S390_GS_CB 0x30b +#define NT_S390_GS_BC 0x30c +#define NT_S390_RI_CB 0x30d /* * Print general purpose and access registers @@ -41,8 +41,7 @@ static void print_core_gpregs(const char *msg, UserS390RegsEntry *gpregs) int i; pr_debug("%s: General purpose registers\n", msg); - pr_debug(" psw %016lx %016lx\n", - gpregs->psw_mask, gpregs->psw_addr); + pr_debug(" psw %016lx %016lx\n", gpregs->psw_mask, gpregs->psw_addr); pr_debug(" orig_gpr2 %016lx\n", gpregs->orig_gpr2); for (i = 0; i < 16; i++) pr_debug(" g%02d %016lx\n", i, gpregs->gprs[i]); @@ -69,8 +68,7 @@ static void print_core_vx_regs(CoreEntry *core) for (i = 0; i < 16; i++) pr_debug(" vx_low%02d %016lx\n", i, vxrs_low->regs[i]); for (i = 0; i < 32; i += 2) - pr_debug(" vx_high%02d %016lx %016lx\n", i / 2, - vxrs_high->regs[i], vxrs_high->regs[i + 1]); + pr_debug(" vx_high%02d %016lx %016lx\n", i / 2, vxrs_high->regs[i], vxrs_high->regs[i + 1]); } /* @@ -395,10 +393,8 @@ int restore_fpu(struct rt_sigframe *f, CoreEntry *core) dst->fpregs.fpc = fpregs->fpc; memcpy(dst->fpregs.fprs, fpregs->fprs, sizeof(dst->fpregs.fprs)); if (vxrs_low) { - memcpy(&dst_ext->vxrs_low, vxrs_low->regs, - sizeof(dst_ext->vxrs_low)); - memcpy(&dst_ext->vxrs_high, vxrs_high->regs, - sizeof(dst_ext->vxrs_high)); + memcpy(&dst_ext->vxrs_low, vxrs_low->regs, sizeof(dst_ext->vxrs_low)); + memcpy(&dst_ext->vxrs_high, vxrs_high->regs, sizeof(dst_ext->vxrs_high)); } return 0; } @@ -697,10 +693,8 @@ static int set_task_regs(pid_t pid, CoreEntry *core) if (!cvxrs_high) return -1; fpregs.flags |= USER_FPREGS_VXRS; - memcpy(&fpregs.vxrs_low, cvxrs_low->regs, - sizeof(fpregs.vxrs_low)); - memcpy(&fpregs.vxrs_high, cvxrs_high->regs, - sizeof(fpregs.vxrs_high)); + memcpy(&fpregs.vxrs_low, cvxrs_low->regs, sizeof(fpregs.vxrs_low)); + memcpy(&fpregs.vxrs_high, cvxrs_high->regs, sizeof(fpregs.vxrs_high)); if (set_vx_regs(pid, &fpregs) < 0) return -1; } @@ -720,19 +714,15 @@ int arch_set_thread_regs(struct pstree_item *item, bool with_threads) int i; for_each_pstree_item(item) { - if (item->pid->state == TASK_DEAD || - item->pid->state == TASK_ZOMBIE) + if (item->pid->state == TASK_DEAD || item->pid->state == TASK_ZOMBIE) continue; for (i = 0; i < item->nr_threads; i++) { - if (item->threads[i].state == TASK_DEAD || - item->threads[i].state == TASK_ZOMBIE) + if (item->threads[i].state == TASK_DEAD || item->threads[i].state == TASK_ZOMBIE) continue; if (!with_threads && i > 0) continue; - if (set_task_regs(item->threads[i].real, - item->core[i])) { - pr_perror("Not set registers for task %d", - item->threads[i].real); + if (set_task_regs(item->threads[i].real, item->core[i])) { + pr_perror("Not set registers for task %d", item->threads[i].real); return -1; } } diff --git a/criu/arch/s390/restorer.c b/criu/arch/s390/restorer.c index 3823fda98..6907ad75b 100644 --- a/criu/arch/s390/restorer.c +++ b/criu/arch/s390/restorer.c @@ -23,15 +23,14 @@ unsigned long sys_shmat(int shmid, const void *shmaddr, int shmflg) unsigned long raddr; int ret; - ret = sys_ipc(21 /*SHMAT */, - shmid, /* first */ - shmflg, /* second */ - (unsigned long)&raddr, /* third */ - shmaddr, /* ptr */ - 0 /* fifth not used */); + ret = sys_ipc(21 /*SHMAT */, shmid, /* first */ + shmflg, /* second */ + (unsigned long)&raddr, /* third */ + shmaddr, /* ptr */ + 0 /* fifth not used */); if (ret) - raddr = (unsigned long) ret; + raddr = (unsigned long)ret; return raddr; } diff --git a/criu/arch/s390/sigframe.c b/criu/arch/s390/sigframe.c index 03f206a8d..89a897260 100644 --- a/criu/arch/s390/sigframe.c +++ b/criu/arch/s390/sigframe.c @@ -13,8 +13,7 @@ * - sigframe : Pointer to local signal frame * - rsigframe: Pointer to remote signal frame of inferior */ -int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { return 0; } diff --git a/criu/arch/s390/vdso-pie.c b/criu/arch/s390/vdso-pie.c index 0667668ee..ad504beda 100644 --- a/criu/arch/s390/vdso-pie.c +++ b/criu/arch/s390/vdso-pie.c @@ -9,7 +9,7 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " @@ -17,11 +17,11 @@ * Trampoline instruction sequence */ typedef struct { - u8 larl[6]; /* Load relative address of imm64 */ - u8 lg[6]; /* Load %r1 with imm64 */ - u8 br[2]; /* Branch to %r1 */ - u64 addr; /* Jump address */ - u32 guards; /* Guard bytes */ + u8 larl[6]; /* Load relative address of imm64 */ + u8 lg[6]; /* Load %r1 with imm64 */ + u8 br[2]; /* Branch to %r1 */ + u64 addr; /* Jump address */ + u32 guards; /* Guard bytes */ } __packed jmp_t; /* @@ -29,21 +29,20 @@ typedef struct { */ jmp_t jmp = { /* larl %r1,e (addr) */ - .larl = {0xc0, 0x10, 0x00, 0x00, 0x00, 0x07}, + .larl = { 0xc0, 0x10, 0x00, 0x00, 0x00, 0x07 }, /* lg %r1,0(%r1) */ - .lg = {0xe3, 0x10, 0x10, 0x00, 0x00, 0x04}, + .lg = { 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04 }, /* br %r1 */ - .br = {0x07, 0xf1}, - .guards = 0xcccccccc, + .br = { 0x07, 0xf1 }, + .guards = 0xcccccccc, }; /* * Insert trampoline code into old vdso entry points to * jump to new vdso functions. */ -int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, - struct vdso_symtable *to, struct vdso_symtable *from, - bool __always_unused compat_vdso) +int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, struct vdso_symtable *to, + struct vdso_symtable *from, bool __always_unused compat_vdso) { unsigned int i; @@ -51,14 +50,11 @@ int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, if (vdso_symbol_empty(&from->symbols[i])) continue; - pr_debug("jmp: %s: %lx/%lx -> %lx/%lx (index %d)\n", - from->symbols[i].name, base_from, - from->symbols[i].offset, - base_to, to->symbols[i].offset, i); + pr_debug("jmp: %s: %lx/%lx -> %lx/%lx (index %d)\n", from->symbols[i].name, base_from, + from->symbols[i].offset, base_to, to->symbols[i].offset, i); jmp.addr = base_to + to->symbols[i].offset; - memcpy((void *)(base_from + from->symbols[i].offset), &jmp, - sizeof(jmp)); + memcpy((void *)(base_from + from->symbols[i].offset), &jmp, sizeof(jmp)); } return 0; diff --git a/criu/arch/x86/cpu.c b/criu/arch/x86/cpu.c index 72c5bd59c..d02f4abd5 100644 --- a/criu/arch/x86/cpu.c +++ b/criu/arch/x86/cpu.c @@ -23,7 +23,7 @@ #include "protobuf.h" #include "images/cpuinfo.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cpu: " static compel_cpuinfo_t rt_cpu_info; @@ -55,12 +55,9 @@ int cpu_init(void) } pr_debug("fpu:%d fxsr:%d xsave:%d xsaveopt:%d xsavec:%d xgetbv1:%d xsaves:%d\n", - !!compel_cpu_has_feature(X86_FEATURE_FPU), - !!compel_cpu_has_feature(X86_FEATURE_FXSR), - !!compel_cpu_has_feature(X86_FEATURE_OSXSAVE), - !!compel_cpu_has_feature(X86_FEATURE_XSAVEOPT), - !!compel_cpu_has_feature(X86_FEATURE_XSAVEC), - !!compel_cpu_has_feature(X86_FEATURE_XGETBV1), + !!compel_cpu_has_feature(X86_FEATURE_FPU), !!compel_cpu_has_feature(X86_FEATURE_FXSR), + !!compel_cpu_has_feature(X86_FEATURE_OSXSAVE), !!compel_cpu_has_feature(X86_FEATURE_XSAVEOPT), + !!compel_cpu_has_feature(X86_FEATURE_XSAVEC), !!compel_cpu_has_feature(X86_FEATURE_XGETBV1), !!compel_cpu_has_feature(X86_FEATURE_XSAVES)); return cpu_has_unsupported_features() ? -1 : 0; @@ -77,25 +74,24 @@ int cpu_dump_cpuinfo(void) if (!img) return -1; - cpu_info.x86_entry = &cpu_x86_info_ptr; - cpu_info.n_x86_entry = 1; - - cpu_x86_info.vendor_id = (rt_cpu_info.x86_vendor == X86_VENDOR_INTEL) ? - CPUINFO_X86_ENTRY__VENDOR__INTEL : - CPUINFO_X86_ENTRY__VENDOR__AMD; - - cpu_x86_info.cpu_family = rt_cpu_info.x86_family; - cpu_x86_info.model = rt_cpu_info.x86_model; - cpu_x86_info.stepping = rt_cpu_info.x86_mask; - cpu_x86_info.capability_ver = 2; - cpu_x86_info.n_capability = ARRAY_SIZE(rt_cpu_info.x86_capability); - cpu_x86_info.capability = (void *)rt_cpu_info.x86_capability; - cpu_x86_info.has_xfeatures_mask = true; - cpu_x86_info.xfeatures_mask = rt_cpu_info.xfeatures_mask; - cpu_x86_info.has_xsave_size = true; - cpu_x86_info.xsave_size = rt_cpu_info.xsave_size; - cpu_x86_info.has_xsave_size_max = true; - cpu_x86_info.xsave_size_max = rt_cpu_info.xsave_size_max; + cpu_info.x86_entry = &cpu_x86_info_ptr; + cpu_info.n_x86_entry = 1; + + cpu_x86_info.vendor_id = (rt_cpu_info.x86_vendor == X86_VENDOR_INTEL) ? CPUINFO_X86_ENTRY__VENDOR__INTEL : + CPUINFO_X86_ENTRY__VENDOR__AMD; + + cpu_x86_info.cpu_family = rt_cpu_info.x86_family; + cpu_x86_info.model = rt_cpu_info.x86_model; + cpu_x86_info.stepping = rt_cpu_info.x86_mask; + cpu_x86_info.capability_ver = 2; + cpu_x86_info.n_capability = ARRAY_SIZE(rt_cpu_info.x86_capability); + cpu_x86_info.capability = (void *)rt_cpu_info.x86_capability; + cpu_x86_info.has_xfeatures_mask = true; + cpu_x86_info.xfeatures_mask = rt_cpu_info.xfeatures_mask; + cpu_x86_info.has_xsave_size = true; + cpu_x86_info.xsave_size = rt_cpu_info.xsave_size; + cpu_x86_info.has_xsave_size_max = true; + cpu_x86_info.xsave_size_max = rt_cpu_info.xsave_size_max; if (rt_cpu_info.x86_model_id[0]) cpu_x86_info.model_id = rt_cpu_info.x86_model_id; @@ -109,102 +105,65 @@ int cpu_dump_cpuinfo(void) return 0; } -#define __ins_bit(__l, __v) (1u << ((__v) - 32u * (__l))) +#define __ins_bit(__l, __v) (1u << ((__v)-32u * (__l))) static uint32_t x86_ins_capability_mask[NCAPINTS] = { - [CPUID_1_EDX] = - __ins_bit(CPUID_1_EDX, X86_FEATURE_FPU) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_TSC) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_CX8) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_SEP) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_CMOV) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_CLFLUSH) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_MMX) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_FXSR) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_XMM) | - __ins_bit(CPUID_1_EDX, X86_FEATURE_XMM2), - - [CPUID_8000_0001_EDX] = - __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_SYSCALL) | - __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_MMXEXT) | - __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_RDTSCP) | - __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_3DNOWEXT) | - __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_3DNOW), - - [CPUID_LNX_1] = - __ins_bit(CPUID_LNX_1, X86_FEATURE_REP_GOOD) | - __ins_bit(CPUID_LNX_1, X86_FEATURE_NOPL), - - [CPUID_1_ECX] = - __ins_bit(CPUID_1_ECX, X86_FEATURE_XMM3) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_PCLMULQDQ) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_MWAIT) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_SSSE3) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_CX16) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_XMM4_1) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_XMM4_2) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_MOVBE) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_POPCNT) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_AES) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_XSAVE) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_OSXSAVE) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_AVX) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_F16C) | - __ins_bit(CPUID_1_ECX, X86_FEATURE_RDRAND), + [CPUID_1_EDX] = __ins_bit(CPUID_1_EDX, X86_FEATURE_FPU) | __ins_bit(CPUID_1_EDX, X86_FEATURE_TSC) | + __ins_bit(CPUID_1_EDX, X86_FEATURE_CX8) | __ins_bit(CPUID_1_EDX, X86_FEATURE_SEP) | + __ins_bit(CPUID_1_EDX, X86_FEATURE_CMOV) | __ins_bit(CPUID_1_EDX, X86_FEATURE_CLFLUSH) | + __ins_bit(CPUID_1_EDX, X86_FEATURE_MMX) | __ins_bit(CPUID_1_EDX, X86_FEATURE_FXSR) | + __ins_bit(CPUID_1_EDX, X86_FEATURE_XMM) | __ins_bit(CPUID_1_EDX, X86_FEATURE_XMM2), + + [CPUID_8000_0001_EDX] = __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_SYSCALL) | + __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_MMXEXT) | + __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_RDTSCP) | + __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_3DNOWEXT) | + __ins_bit(CPUID_8000_0001_EDX, X86_FEATURE_3DNOW), + + [CPUID_LNX_1] = __ins_bit(CPUID_LNX_1, X86_FEATURE_REP_GOOD) | __ins_bit(CPUID_LNX_1, X86_FEATURE_NOPL), + + [CPUID_1_ECX] = __ins_bit(CPUID_1_ECX, X86_FEATURE_XMM3) | __ins_bit(CPUID_1_ECX, X86_FEATURE_PCLMULQDQ) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_MWAIT) | __ins_bit(CPUID_1_ECX, X86_FEATURE_SSSE3) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_CX16) | __ins_bit(CPUID_1_ECX, X86_FEATURE_XMM4_1) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_XMM4_2) | __ins_bit(CPUID_1_ECX, X86_FEATURE_MOVBE) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_POPCNT) | __ins_bit(CPUID_1_ECX, X86_FEATURE_AES) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_XSAVE) | __ins_bit(CPUID_1_ECX, X86_FEATURE_OSXSAVE) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_AVX) | __ins_bit(CPUID_1_ECX, X86_FEATURE_F16C) | + __ins_bit(CPUID_1_ECX, X86_FEATURE_RDRAND), [CPUID_8000_0001_ECX] = - __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_ABM) | - __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_SSE4A) | - __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_MISALIGNSSE) | - __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_3DNOWPREFETCH) | - __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_XOP) | - __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_FMA4) | + __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_ABM) | __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_SSE4A) | + __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_MISALIGNSSE) | + __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_3DNOWPREFETCH) | + __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_XOP) | __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_FMA4) | __ins_bit(CPUID_8000_0001_ECX, X86_FEATURE_TBM), [CPUID_7_0_EBX] = - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_FSGSBASE) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_BMI1) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_HLE) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX2) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_BMI2) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_ERMS) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_RTM) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_MPX) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512F) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512DQ) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_RDSEED) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_ADX) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_CLFLUSHOPT) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512PF) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512ER) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512CD) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_SHA_NI) | - __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512BW) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_FSGSBASE) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_BMI1) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_HLE) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX2) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_BMI2) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_ERMS) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_RTM) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_MPX) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512F) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512DQ) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_RDSEED) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_ADX) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_CLFLUSHOPT) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512PF) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512ER) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512CD) | + __ins_bit(CPUID_7_0_EBX, X86_FEATURE_SHA_NI) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512BW) | __ins_bit(CPUID_7_0_EBX, X86_FEATURE_AVX512VL), - [CPUID_D_1_EAX] = - __ins_bit(CPUID_D_1_EAX, X86_FEATURE_XSAVEOPT) | - __ins_bit(CPUID_D_1_EAX, X86_FEATURE_XSAVEC) | - __ins_bit(CPUID_D_1_EAX, X86_FEATURE_XGETBV1), + [CPUID_D_1_EAX] = __ins_bit(CPUID_D_1_EAX, X86_FEATURE_XSAVEOPT) | + __ins_bit(CPUID_D_1_EAX, X86_FEATURE_XSAVEC) | __ins_bit(CPUID_D_1_EAX, X86_FEATURE_XGETBV1), [CPUID_7_0_ECX] = - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512VBMI) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_VBMI2) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_GFNI) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_VAES) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_VPCLMULQDQ) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_VNNI) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_BITALG) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_TME) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_VPOPCNTDQ) | - __ins_bit(CPUID_7_0_ECX, X86_FEATURE_RDPID), - - [CPUID_8000_0008_EBX] = - __ins_bit(CPUID_8000_0008_EBX, X86_FEATURE_CLZERO), - - [CPUID_7_0_EDX] = - __ins_bit(CPUID_7_0_EDX, X86_FEATURE_AVX512_4VNNIW) | - __ins_bit(CPUID_7_0_EDX, X86_FEATURE_AVX512_4FMAPS), + __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512VBMI) | __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_VBMI2) | + __ins_bit(CPUID_7_0_ECX, X86_FEATURE_GFNI) | __ins_bit(CPUID_7_0_ECX, X86_FEATURE_VAES) | + __ins_bit(CPUID_7_0_ECX, X86_FEATURE_VPCLMULQDQ) | __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_VNNI) | + __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_BITALG) | __ins_bit(CPUID_7_0_ECX, X86_FEATURE_TME) | + __ins_bit(CPUID_7_0_ECX, X86_FEATURE_AVX512_VPOPCNTDQ) | __ins_bit(CPUID_7_0_ECX, X86_FEATURE_RDPID), + + [CPUID_8000_0008_EBX] = __ins_bit(CPUID_8000_0008_EBX, X86_FEATURE_CLZERO), + + [CPUID_7_0_EDX] = __ins_bit(CPUID_7_0_EDX, X86_FEATURE_AVX512_4VNNIW) | + __ins_bit(CPUID_7_0_EDX, X86_FEATURE_AVX512_4FMAPS), }; #undef __ins_bit @@ -243,20 +202,14 @@ static int cpu_validate_features(compel_cpuinfo_t *cpu_info) * rest of mismatches won't cause problems. */ -#define __mismatch_fpu_bit(__bit) \ - (test_bit(__bit, (void *)cpu_info->x86_capability) && \ - !compel_cpu_has_feature(__bit)) - if (__mismatch_fpu_bit(X86_FEATURE_FPU) || - __mismatch_fpu_bit(X86_FEATURE_FXSR) || - __mismatch_fpu_bit(X86_FEATURE_OSXSAVE) || - __mismatch_fpu_bit(X86_FEATURE_XSAVES)) { +#define __mismatch_fpu_bit(__bit) (test_bit(__bit, (void *)cpu_info->x86_capability) && !compel_cpu_has_feature(__bit)) + if (__mismatch_fpu_bit(X86_FEATURE_FPU) || __mismatch_fpu_bit(X86_FEATURE_FXSR) || + __mismatch_fpu_bit(X86_FEATURE_OSXSAVE) || __mismatch_fpu_bit(X86_FEATURE_XSAVES)) { pr_err("FPU feature required by image " "is not supported on host " "(fpu:%d fxsr:%d osxsave:%d xsaves:%d)\n", - __mismatch_fpu_bit(X86_FEATURE_FPU), - __mismatch_fpu_bit(X86_FEATURE_FXSR), - __mismatch_fpu_bit(X86_FEATURE_OSXSAVE), - __mismatch_fpu_bit(X86_FEATURE_XSAVES)); + __mismatch_fpu_bit(X86_FEATURE_FPU), __mismatch_fpu_bit(X86_FEATURE_FXSR), + __mismatch_fpu_bit(X86_FEATURE_OSXSAVE), __mismatch_fpu_bit(X86_FEATURE_XSAVES)); return -1; } #undef __mismatch_fpu_bit @@ -266,10 +219,8 @@ static int cpu_validate_features(compel_cpuinfo_t *cpu_info) * the destination there are all the features which were on the * source. */ - if ((m = cpu_info->xfeatures_mask & - ~rt_cpu_info.xfeatures_mask)) { - pr_err("CPU xfeatures has unsupported bits (%#" - PRIx64")\n", m); + if ((m = cpu_info->xfeatures_mask & ~rt_cpu_info.xfeatures_mask)) { + pr_err("CPU xfeatures has unsupported bits (%#" PRIx64 ")\n", m); return -1; } @@ -281,13 +232,11 @@ static int cpu_validate_features(compel_cpuinfo_t *cpu_info) * greedy feature mask causing programs to misbehave. */ if (cpu_info->xsave_size != rt_cpu_info.xsave_size) { - pr_err("CPU xsave size mismatch (%u/%u)\n", - cpu_info->xsave_size, rt_cpu_info.xsave_size); + pr_err("CPU xsave size mismatch (%u/%u)\n", cpu_info->xsave_size, rt_cpu_info.xsave_size); return -1; } if (cpu_info->xsave_size_max != rt_cpu_info.xsave_size_max) { - pr_err("CPU xsave max size mismatch (%u/%u)\n", - cpu_info->xsave_size_max, + pr_err("CPU xsave max size mismatch (%u/%u)\n", cpu_info->xsave_size_max, rt_cpu_info.xsave_size_max); return -1; } @@ -305,8 +254,7 @@ static int cpu_validate_features(compel_cpuinfo_t *cpu_info) * Strict capability mode. Everything must match. */ if (opts.cpu_cap & CPU_CAP_CPU) { - if (memcmp(cpu_info->x86_capability, rt_cpu_info.x86_capability, - sizeof(cpu_info->x86_capability))) { + if (memcmp(cpu_info->x86_capability, rt_cpu_info.x86_capability, sizeof(cpu_info->x86_capability))) { pr_err("CPU capabilities do not match run time\n"); return -1; } @@ -316,8 +264,8 @@ static int cpu_validate_features(compel_cpuinfo_t *cpu_info) } static const struct { - const uint32_t capability_ver; - const uint32_t ncapints; + const uint32_t capability_ver; + const uint32_t ncapints; } ncapints[] = { { .capability_ver = 1, .ncapints = NCAPINTS_V1 }, { .capability_ver = 2, .ncapints = NCAPINTS_V2 }, @@ -328,14 +276,12 @@ static compel_cpuinfo_t *img_to_cpuinfo(CpuinfoX86Entry *img_x86_entry) compel_cpuinfo_t *cpu_info; size_t size, i; - BUILD_BUG_ON(sizeof(img_x86_entry->capability[0]) != - sizeof(cpu_info->x86_capability[0])); + BUILD_BUG_ON(sizeof(img_x86_entry->capability[0]) != sizeof(cpu_info->x86_capability[0])); BUILD_BUG_ON(ARRAY_SIZE(rt_cpu_info.x86_capability) != NCAPINTS); if (img_x86_entry->vendor_id != CPUINFO_X86_ENTRY__VENDOR__INTEL && img_x86_entry->vendor_id != CPUINFO_X86_ENTRY__VENDOR__AMD) { - pr_err("Image carries unknown vendor %u\n", - (unsigned)img_x86_entry->vendor_id); + pr_err("Image carries unknown vendor %u\n", (unsigned)img_x86_entry->vendor_id); return NULL; } @@ -343,8 +289,7 @@ static compel_cpuinfo_t *img_to_cpuinfo(CpuinfoX86Entry *img_x86_entry) if (img_x86_entry->capability_ver == ncapints[i].capability_ver) { if (img_x86_entry->n_capability != ncapints[i].ncapints) { pr_err("Image carries %u words while %u expected\n", - (unsigned)img_x86_entry->n_capability, - (unsigned)ncapints[i].ncapints); + (unsigned)img_x86_entry->n_capability, (unsigned)ncapints[i].ncapints); return NULL; } break; @@ -352,8 +297,7 @@ static compel_cpuinfo_t *img_to_cpuinfo(CpuinfoX86Entry *img_x86_entry) } if (i >= ARRAY_SIZE(ncapints)) { - pr_err("Image carries unknown capability version %d\n", - (unsigned)img_x86_entry->capability_ver); + pr_err("Image carries unknown capability version %d\n", (unsigned)img_x86_entry->capability_ver); return NULL; } @@ -368,21 +312,20 @@ static compel_cpuinfo_t *img_to_cpuinfo(CpuinfoX86Entry *img_x86_entry) size = sizeof(img_x86_entry->capability[0]) * img_x86_entry->n_capability; memcpy(cpu_info->x86_capability, img_x86_entry->capability, size); if (img_x86_entry->capability_ver == 1) { - memcpy(&cpu_info->x86_capability[NCAPINTS_V1], - &rt_cpu_info.x86_capability[NCAPINTS_V1], + memcpy(&cpu_info->x86_capability[NCAPINTS_V1], &rt_cpu_info.x86_capability[NCAPINTS_V1], (NCAPINTS_V2 - NCAPINTS_V1) * sizeof(rt_cpu_info.x86_capability[0])); } if (img_x86_entry->vendor_id == CPUINFO_X86_ENTRY__VENDOR__INTEL) - cpu_info->x86_vendor = X86_VENDOR_INTEL; + cpu_info->x86_vendor = X86_VENDOR_INTEL; else - cpu_info->x86_vendor = X86_VENDOR_AMD; - cpu_info->x86_family = img_x86_entry->cpu_family; - cpu_info->x86_model = img_x86_entry->model; - cpu_info->x86_mask = img_x86_entry->stepping; - cpu_info->extended_cpuid_level = rt_cpu_info.extended_cpuid_level; - cpu_info->cpuid_level = rt_cpu_info.cpuid_level; - cpu_info->x86_power = rt_cpu_info.x86_power; + cpu_info->x86_vendor = X86_VENDOR_AMD; + cpu_info->x86_family = img_x86_entry->cpu_family; + cpu_info->x86_model = img_x86_entry->model; + cpu_info->x86_mask = img_x86_entry->stepping; + cpu_info->extended_cpuid_level = rt_cpu_info.extended_cpuid_level; + cpu_info->cpuid_level = rt_cpu_info.cpuid_level; + cpu_info->x86_power = rt_cpu_info.x86_power; memcpy(cpu_info->x86_vendor_id, rt_cpu_info.x86_model_id, sizeof(cpu_info->x86_vendor_id)); strncpy(cpu_info->x86_model_id, img_x86_entry->model_id, sizeof(cpu_info->x86_model_id) - 1); diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c index bc8022535..f177b9e7b 100644 --- a/criu/arch/x86/crtools.c +++ b/criu/arch/x86/crtools.c @@ -13,30 +13,31 @@ #undef LOG_PREFIX #define LOG_PREFIX "x86: " -#define XSAVE_PB_NELEMS(__s, __obj, __member) \ - (sizeof(__s) / sizeof(*(__obj)->__member)) +#define XSAVE_PB_NELEMS(__s, __obj, __member) (sizeof(__s) / sizeof(*(__obj)->__member)) int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs) { CoreEntry *core = x; - UserX86RegsEntry *gpregs = core->thread_info->gpregs; - -#define assign_reg(dst, src, e) do { dst->e = (__typeof__(dst->e))src.e; } while (0) -#define assign_array(dst, src, e) memcpy(dst->e, &src.e, sizeof(src.e)) -#define assign_xsave(feature, xsave, member, area) \ - do { \ - if (compel_fpu_has_feature(feature)) { \ - uint32_t off = compel_fpu_feature_offset(feature); \ - void *from = &area[off]; \ - size_t size = pb_repeated_size(xsave, member); \ - size_t xsize = (size_t)compel_fpu_feature_size(feature); \ - if (xsize != size) { \ - pr_err("%s reported %zu bytes (expecting %zu)\n", \ - # feature, xsize, size); \ - return -1; \ - } \ - memcpy(xsave->member, from, size); \ - } \ + UserX86RegsEntry *gpregs = core->thread_info->gpregs; + +#define assign_reg(dst, src, e) \ + do { \ + dst->e = (__typeof__(dst->e))src.e; \ + } while (0) +#define assign_array(dst, src, e) memcpy(dst->e, &src.e, sizeof(src.e)) +#define assign_xsave(feature, xsave, member, area) \ + do { \ + if (compel_fpu_has_feature(feature)) { \ + uint32_t off = compel_fpu_feature_offset(feature); \ + void *from = &area[off]; \ + size_t size = pb_repeated_size(xsave, member); \ + size_t xsize = (size_t)compel_fpu_feature_size(feature); \ + if (xsize != size) { \ + pr_err("%s reported %zu bytes (expecting %zu)\n", #feature, xsize, size); \ + return -1; \ + } \ + memcpy(xsave->member, from, size); \ + } \ } while (0) if (user_regs_native(regs)) { @@ -119,13 +120,13 @@ int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpre */ assign_reg(xsave, fpregs->xsave_hdr, xstate_bv); - assign_xsave(XFEATURE_YMM, xsave, ymmh_space, extended_state_area); - assign_xsave(XFEATURE_BNDREGS, xsave, bndreg_state, extended_state_area); - assign_xsave(XFEATURE_BNDCSR, xsave, bndcsr_state, extended_state_area); - assign_xsave(XFEATURE_OPMASK, xsave, opmask_reg, extended_state_area); - assign_xsave(XFEATURE_ZMM_Hi256,xsave, zmm_upper, extended_state_area); - assign_xsave(XFEATURE_Hi16_ZMM, xsave, hi16_zmm, extended_state_area); - assign_xsave(XFEATURE_PKRU, xsave, pkru, extended_state_area); + assign_xsave(XFEATURE_YMM, xsave, ymmh_space, extended_state_area); + assign_xsave(XFEATURE_BNDREGS, xsave, bndreg_state, extended_state_area); + assign_xsave(XFEATURE_BNDCSR, xsave, bndcsr_state, extended_state_area); + assign_xsave(XFEATURE_OPMASK, xsave, opmask_reg, extended_state_area); + assign_xsave(XFEATURE_ZMM_Hi256, xsave, zmm_upper, extended_state_area); + assign_xsave(XFEATURE_Hi16_ZMM, xsave, hi16_zmm, extended_state_area); + assign_xsave(XFEATURE_PKRU, xsave, pkru, extended_state_area); } #undef assign_reg @@ -139,7 +140,7 @@ static void alloc_tls(ThreadInfoX86 *ti, void **mempool) { int i; - ti->tls = xptr_pull_s(mempool, GDT_ENTRY_TLS_NUM*sizeof(UserDescT*)); + ti->tls = xptr_pull_s(mempool, GDT_ENTRY_TLS_NUM * sizeof(UserDescT *)); ti->n_tls = GDT_ENTRY_TLS_NUM; for (i = 0; i < GDT_ENTRY_TLS_NUM; i++) { ti->tls[i] = xptr_pull(mempool, UserDescT); @@ -150,50 +151,50 @@ static void alloc_tls(ThreadInfoX86 *ti, void **mempool) static int alloc_xsave_extends(UserX86XsaveEntry *xsave) { if (compel_fpu_has_feature(XFEATURE_YMM)) { - xsave->n_ymmh_space = XSAVE_PB_NELEMS(struct ymmh_struct, xsave, ymmh_space); - xsave->ymmh_space = xzalloc(pb_repeated_size(xsave, ymmh_space)); + xsave->n_ymmh_space = XSAVE_PB_NELEMS(struct ymmh_struct, xsave, ymmh_space); + xsave->ymmh_space = xzalloc(pb_repeated_size(xsave, ymmh_space)); if (!xsave->ymmh_space) goto err; } if (compel_fpu_has_feature(XFEATURE_BNDREGS)) { - xsave->n_bndreg_state = XSAVE_PB_NELEMS(struct mpx_bndreg_state, xsave, bndreg_state); - xsave->bndreg_state = xzalloc(pb_repeated_size(xsave, bndreg_state)); + xsave->n_bndreg_state = XSAVE_PB_NELEMS(struct mpx_bndreg_state, xsave, bndreg_state); + xsave->bndreg_state = xzalloc(pb_repeated_size(xsave, bndreg_state)); if (!xsave->bndreg_state) goto err; } if (compel_fpu_has_feature(XFEATURE_BNDCSR)) { - xsave->n_bndcsr_state = XSAVE_PB_NELEMS(struct mpx_bndcsr_state, xsave, bndcsr_state); - xsave->bndcsr_state = xzalloc(pb_repeated_size(xsave, bndcsr_state)); + xsave->n_bndcsr_state = XSAVE_PB_NELEMS(struct mpx_bndcsr_state, xsave, bndcsr_state); + xsave->bndcsr_state = xzalloc(pb_repeated_size(xsave, bndcsr_state)); if (!xsave->bndcsr_state) goto err; } if (compel_fpu_has_feature(XFEATURE_OPMASK)) { - xsave->n_opmask_reg = XSAVE_PB_NELEMS(struct avx_512_opmask_state, xsave, opmask_reg); - xsave->opmask_reg = xzalloc(pb_repeated_size(xsave, opmask_reg)); + xsave->n_opmask_reg = XSAVE_PB_NELEMS(struct avx_512_opmask_state, xsave, opmask_reg); + xsave->opmask_reg = xzalloc(pb_repeated_size(xsave, opmask_reg)); if (!xsave->opmask_reg) goto err; } if (compel_fpu_has_feature(XFEATURE_ZMM_Hi256)) { - xsave->n_zmm_upper = XSAVE_PB_NELEMS(struct avx_512_zmm_uppers_state, xsave, zmm_upper); - xsave->zmm_upper = xzalloc(pb_repeated_size(xsave, zmm_upper)); + xsave->n_zmm_upper = XSAVE_PB_NELEMS(struct avx_512_zmm_uppers_state, xsave, zmm_upper); + xsave->zmm_upper = xzalloc(pb_repeated_size(xsave, zmm_upper)); if (!xsave->zmm_upper) goto err; } if (compel_fpu_has_feature(XFEATURE_Hi16_ZMM)) { - xsave->n_hi16_zmm = XSAVE_PB_NELEMS(struct avx_512_hi16_state, xsave, hi16_zmm); - xsave->hi16_zmm = xzalloc(pb_repeated_size(xsave, hi16_zmm)); + xsave->n_hi16_zmm = XSAVE_PB_NELEMS(struct avx_512_hi16_state, xsave, hi16_zmm); + xsave->hi16_zmm = xzalloc(pb_repeated_size(xsave, hi16_zmm)); if (!xsave->hi16_zmm) goto err; } if (compel_fpu_has_feature(XFEATURE_PKRU)) { - xsave->n_pkru = XSAVE_PB_NELEMS(struct pkru_state, xsave, pkru); - xsave->pkru = xzalloc(pb_repeated_size(xsave, pkru)); + xsave->n_pkru = XSAVE_PB_NELEMS(struct pkru_state, xsave, pkru); + xsave->pkru = xzalloc(pb_repeated_size(xsave, pkru)); if (!xsave->pkru) goto err; } @@ -210,12 +211,10 @@ int arch_alloc_thread_info(CoreEntry *core) void *m; ThreadInfoX86 *ti = NULL; - with_fpu = compel_cpu_has_feature(X86_FEATURE_FPU); - sz = sizeof(ThreadInfoX86) + sizeof(UserX86RegsEntry) + - GDT_ENTRY_TLS_NUM*sizeof(UserDescT) + - GDT_ENTRY_TLS_NUM*sizeof(UserDescT*); + sz = sizeof(ThreadInfoX86) + sizeof(UserX86RegsEntry) + GDT_ENTRY_TLS_NUM * sizeof(UserDescT) + + GDT_ENTRY_TLS_NUM * sizeof(UserDescT *); if (with_fpu) { sz += sizeof(UserX86FpregsEntry); with_xsave = compel_cpu_has_feature(X86_FEATURE_OSXSAVE); @@ -240,11 +239,11 @@ int arch_alloc_thread_info(CoreEntry *core) user_x86_fpregs_entry__init(fpregs); /* These are numbers from kernel */ - fpregs->n_st_space = 32; - fpregs->n_xmm_space = 64; + fpregs->n_st_space = 32; + fpregs->n_xmm_space = 64; - fpregs->st_space = xzalloc(pb_repeated_size(fpregs, st_space)); - fpregs->xmm_space = xzalloc(pb_repeated_size(fpregs, xmm_space)); + fpregs->st_space = xzalloc(pb_repeated_size(fpregs, st_space)); + fpregs->xmm_space = xzalloc(pb_repeated_size(fpregs, xmm_space)); if (!fpregs->st_space || !fpregs->xmm_space) goto err; @@ -293,16 +292,14 @@ static bool valid_xsave_frame(CoreEntry *core) if (core->thread_info->fpregs->n_st_space < ARRAY_SIZE(x->i387.st_space)) { pr_err("Corruption in FPU st_space area " "(got %li but %li expected)\n", - (long)core->thread_info->fpregs->n_st_space, - (long)ARRAY_SIZE(x->i387.st_space)); + (long)core->thread_info->fpregs->n_st_space, (long)ARRAY_SIZE(x->i387.st_space)); return false; } if (core->thread_info->fpregs->n_xmm_space < ARRAY_SIZE(x->i387.xmm_space)) { pr_err("Corruption in FPU xmm_space area " "(got %li but %li expected)\n", - (long)core->thread_info->fpregs->n_st_space, - (long)ARRAY_SIZE(x->i387.xmm_space)); + (long)core->thread_info->fpregs->n_st_space, (long)ARRAY_SIZE(x->i387.xmm_space)); return false; } @@ -310,46 +307,52 @@ static bool valid_xsave_frame(CoreEntry *core) if (xsave) { size_t i; struct { - const char *name; - size_t expected; - size_t obtained; - void *ptr; + const char *name; + size_t expected; + size_t obtained; + void *ptr; } features[] = { { - .name = __stringify_1(XFEATURE_YMM), - .expected = XSAVE_PB_NELEMS(struct ymmh_struct, xsave, ymmh_space), - .obtained = xsave->n_ymmh_space, - .ptr = xsave->ymmh_space, - }, { - .name = __stringify_1(XFEATURE_BNDREGS), - .expected = XSAVE_PB_NELEMS(struct mpx_bndreg_state, xsave, bndreg_state), - .obtained = xsave->n_bndreg_state, - .ptr = xsave->bndreg_state, - }, { - .name = __stringify_1(XFEATURE_BNDCSR), - .expected = XSAVE_PB_NELEMS(struct mpx_bndcsr_state, xsave, bndcsr_state), - .obtained = xsave->n_bndcsr_state, - .ptr = xsave->bndcsr_state, - }, { - .name = __stringify_1(XFEATURE_OPMASK), - .expected = XSAVE_PB_NELEMS(struct avx_512_opmask_state, xsave, opmask_reg), - .obtained = xsave->n_opmask_reg, - .ptr = xsave->opmask_reg, - }, { - .name = __stringify_1(XFEATURE_ZMM_Hi256), - .expected = XSAVE_PB_NELEMS(struct avx_512_zmm_uppers_state, xsave, zmm_upper), - .obtained = xsave->n_zmm_upper, - .ptr = xsave->zmm_upper, - }, { - .name = __stringify_1(XFEATURE_Hi16_ZMM), - .expected = XSAVE_PB_NELEMS(struct avx_512_hi16_state, xsave, hi16_zmm), - .obtained = xsave->n_hi16_zmm, - .ptr = xsave->hi16_zmm, - }, { - .name = __stringify_1(XFEATURE_PKRU), - .expected = XSAVE_PB_NELEMS(struct pkru_state, xsave, pkru), - .obtained = xsave->n_pkru, - .ptr = xsave->pkru, + .name = __stringify_1(XFEATURE_YMM), + .expected = XSAVE_PB_NELEMS(struct ymmh_struct, xsave, ymmh_space), + .obtained = xsave->n_ymmh_space, + .ptr = xsave->ymmh_space, + }, + { + .name = __stringify_1(XFEATURE_BNDREGS), + .expected = XSAVE_PB_NELEMS(struct mpx_bndreg_state, xsave, bndreg_state), + .obtained = xsave->n_bndreg_state, + .ptr = xsave->bndreg_state, + }, + { + .name = __stringify_1(XFEATURE_BNDCSR), + .expected = XSAVE_PB_NELEMS(struct mpx_bndcsr_state, xsave, bndcsr_state), + .obtained = xsave->n_bndcsr_state, + .ptr = xsave->bndcsr_state, + }, + { + .name = __stringify_1(XFEATURE_OPMASK), + .expected = XSAVE_PB_NELEMS(struct avx_512_opmask_state, xsave, opmask_reg), + .obtained = xsave->n_opmask_reg, + .ptr = xsave->opmask_reg, + }, + { + .name = __stringify_1(XFEATURE_ZMM_Hi256), + .expected = XSAVE_PB_NELEMS(struct avx_512_zmm_uppers_state, xsave, zmm_upper), + .obtained = xsave->n_zmm_upper, + .ptr = xsave->zmm_upper, + }, + { + .name = __stringify_1(XFEATURE_Hi16_ZMM), + .expected = XSAVE_PB_NELEMS(struct avx_512_hi16_state, xsave, hi16_zmm), + .obtained = xsave->n_hi16_zmm, + .ptr = xsave->hi16_zmm, + }, + { + .name = __stringify_1(XFEATURE_PKRU), + .expected = XSAVE_PB_NELEMS(struct pkru_state, xsave, pkru), + .obtained = xsave->n_pkru, + .ptr = xsave->pkru, }, }; @@ -392,12 +395,11 @@ static void show_rt_xsave_frame(struct xsave_struct *x) pr_debug("xsave runtime structure\n"); pr_debug("-----------------------\n"); - pr_debug("cwd:%#x swd:%#x twd:%#x fop:%#x mxcsr:%#x mxcsr_mask:%#x\n", - (int)i387->cwd, (int)i387->swd, (int)i387->twd, - (int)i387->fop, (int)i387->mxcsr, (int)i387->mxcsr_mask); + pr_debug("cwd:%#x swd:%#x twd:%#x fop:%#x mxcsr:%#x mxcsr_mask:%#x\n", (int)i387->cwd, (int)i387->swd, + (int)i387->twd, (int)i387->fop, (int)i387->mxcsr, (int)i387->mxcsr_mask); - pr_debug("magic1:%#x extended_size:%u xstate_bv:%#lx xstate_size:%u\n", - fpx->magic1, fpx->extended_size, (long)fpx->xstate_bv, fpx->xstate_size); + pr_debug("magic1:%#x extended_size:%u xstate_bv:%#lx xstate_size:%u\n", fpx->magic1, fpx->extended_size, + (long)fpx->xstate_bv, fpx->xstate_size); pr_debug("xstate_bv: %#lx\n", (long)xsave_hdr->xstate_bv); pr_debug("-----------------------\n"); @@ -405,12 +407,9 @@ static void show_rt_xsave_frame(struct xsave_struct *x) int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) { - fpu_state_t *fpu_state = core_is_compat(core) ? - &sigframe->compat.fpu_state : - &sigframe->native.fpu_state; - struct xsave_struct *x = core_is_compat(core) ? - (void *)&fpu_state->fpu_state_ia32.xsave : - (void *)&fpu_state->fpu_state_64.xsave; + fpu_state_t *fpu_state = core_is_compat(core) ? &sigframe->compat.fpu_state : &sigframe->native.fpu_state; + struct xsave_struct *x = core_is_compat(core) ? (void *)&fpu_state->fpu_state_ia32.xsave : + (void *)&fpu_state->fpu_state_64.xsave; /* * If no FPU information provided -- we're restoring @@ -427,32 +426,33 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) fpu_state->has_fpu = true; -#define assign_reg(dst, src, e) do { dst.e = (__typeof__(dst.e))src->e; } while (0) -#define assign_array(dst, src, e) memcpy(dst.e, (src)->e, sizeof(dst.e)) -#define assign_xsave(feature, xsave, member, area) \ - do { \ - if (compel_fpu_has_feature(feature)) { \ - uint32_t off = compel_fpu_feature_offset(feature); \ - void *to = &area[off]; \ - void *from = xsave->member; \ - size_t size = pb_repeated_size(xsave, member); \ - size_t xsize = (size_t)compel_fpu_feature_size(feature); \ - size_t xstate_size_next = off + xsize; \ - if (xsize != size) { \ - if (size) { \ - pr_err("%s reported %zu bytes (expecting %zu)\n",\ - # feature, xsize, size); \ - return -1; \ - } else { \ - pr_debug("%s is not present in image, ignore\n",\ - # feature); \ - } \ - } \ - xstate_bv |= (1UL << feature); \ - BUG_ON(xstate_size > xstate_size_next); \ - xstate_size = xstate_size_next; \ - memcpy(to, from, size); \ - } \ +#define assign_reg(dst, src, e) \ + do { \ + dst.e = (__typeof__(dst.e))src->e; \ + } while (0) +#define assign_array(dst, src, e) memcpy(dst.e, (src)->e, sizeof(dst.e)) +#define assign_xsave(feature, xsave, member, area) \ + do { \ + if (compel_fpu_has_feature(feature)) { \ + uint32_t off = compel_fpu_feature_offset(feature); \ + void *to = &area[off]; \ + void *from = xsave->member; \ + size_t size = pb_repeated_size(xsave, member); \ + size_t xsize = (size_t)compel_fpu_feature_size(feature); \ + size_t xstate_size_next = off + xsize; \ + if (xsize != size) { \ + if (size) { \ + pr_err("%s reported %zu bytes (expecting %zu)\n", #feature, xsize, size); \ + return -1; \ + } else { \ + pr_debug("%s is not present in image, ignore\n", #feature); \ + } \ + } \ + xstate_bv |= (1UL << feature); \ + BUG_ON(xstate_size > xstate_size_next); \ + xstate_size = xstate_size_next; \ + memcpy(to, from, size); \ + } \ } while (0) assign_reg(x->i387, core->thread_info->fpregs, cwd); @@ -492,21 +492,21 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) * to the increasing offsets of XFEATURE_x * inside memory layout (xstate_size calculation). */ - assign_xsave(XFEATURE_YMM, xsave, ymmh_space, extended_state_area); - assign_xsave(XFEATURE_BNDREGS, xsave, bndreg_state, extended_state_area); - assign_xsave(XFEATURE_BNDCSR, xsave, bndcsr_state, extended_state_area); - assign_xsave(XFEATURE_OPMASK, xsave, opmask_reg, extended_state_area); - assign_xsave(XFEATURE_ZMM_Hi256,xsave, zmm_upper, extended_state_area); - assign_xsave(XFEATURE_Hi16_ZMM, xsave, hi16_zmm, extended_state_area); - assign_xsave(XFEATURE_PKRU, xsave, pkru, extended_state_area); + assign_xsave(XFEATURE_YMM, xsave, ymmh_space, extended_state_area); + assign_xsave(XFEATURE_BNDREGS, xsave, bndreg_state, extended_state_area); + assign_xsave(XFEATURE_BNDCSR, xsave, bndcsr_state, extended_state_area); + assign_xsave(XFEATURE_OPMASK, xsave, opmask_reg, extended_state_area); + assign_xsave(XFEATURE_ZMM_Hi256, xsave, zmm_upper, extended_state_area); + assign_xsave(XFEATURE_Hi16_ZMM, xsave, hi16_zmm, extended_state_area); + assign_xsave(XFEATURE_PKRU, xsave, pkru, extended_state_area); } - x->xsave_hdr.xstate_bv = xstate_bv; + x->xsave_hdr.xstate_bv = xstate_bv; - fpx_sw->magic1 = FP_XSTATE_MAGIC1; - fpx_sw->xstate_bv = xstate_bv; - fpx_sw->xstate_size = xstate_size; - fpx_sw->extended_size = xstate_size + FP_XSTATE_MAGIC2_SIZE; + fpx_sw->magic1 = FP_XSTATE_MAGIC1; + fpx_sw->xstate_bv = xstate_bv; + fpx_sw->xstate_size = xstate_size; + fpx_sw->extended_size = xstate_size + FP_XSTATE_MAGIC2_SIZE; /* * This should be at the end of xsave frame. @@ -524,7 +524,7 @@ int restore_fpu(struct rt_sigframe *sigframe, CoreEntry *core) return 0; } -#define CPREG32(d) f->compat.uc.uc_mcontext.d = r->d +#define CPREG32(d) f->compat.uc.uc_mcontext.d = r->d static void restore_compat_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) { CPREG32(gs); @@ -532,8 +532,15 @@ static void restore_compat_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) CPREG32(es); CPREG32(ds); - CPREG32(di); CPREG32(si); CPREG32(bp); CPREG32(sp); CPREG32(bx); - CPREG32(dx); CPREG32(cx); CPREG32(ip); CPREG32(ax); + CPREG32(di); + CPREG32(si); + CPREG32(bp); + CPREG32(sp); + CPREG32(bx); + CPREG32(dx); + CPREG32(cx); + CPREG32(ip); + CPREG32(ax); CPREG32(cs); CPREG32(ss); CPREG32(flags); @@ -542,7 +549,7 @@ static void restore_compat_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) } #undef CPREG32 -#define CPREG64(d, s) f->native.uc.uc_mcontext.d = r->s +#define CPREG64(d, s) f->native.uc.uc_mcontext.d = r->s static void restore_native_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) { CPREG64(rdi, di); @@ -575,15 +582,15 @@ static void restore_native_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) { switch (r->mode) { - case USER_X86_REGS_MODE__NATIVE: - restore_native_gpregs(f, r); - break; - case USER_X86_REGS_MODE__COMPAT: - restore_compat_gpregs(f, r); - break; - default: - pr_err("Can't prepare rt_sigframe: registers mode corrupted (%d)\n", r->mode); - return -1; + case USER_X86_REGS_MODE__NATIVE: + restore_native_gpregs(f, r); + break; + case USER_X86_REGS_MODE__COMPAT: + restore_compat_gpregs(f, r); + break; + default: + pr_err("Can't prepare rt_sigframe: registers mode corrupted (%d)\n", r->mode); + return -1; } return 0; } @@ -591,10 +598,10 @@ int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) static int get_robust_list32(pid_t pid, uintptr_t head, uintptr_t len) { struct syscall_args32 s = { - .nr = __NR32_get_robust_list, - .arg0 = pid, - .arg1 = (uint32_t)head, - .arg2 = (uint32_t)len, + .nr = __NR32_get_robust_list, + .arg0 = pid, + .arg1 = (uint32_t)head, + .arg2 = (uint32_t)len, }; return do_full_int80(&s); @@ -603,9 +610,9 @@ static int get_robust_list32(pid_t pid, uintptr_t head, uintptr_t len) static int set_robust_list32(uint32_t head, uint32_t len) { struct syscall_args32 s = { - .nr = __NR32_set_robust_list, - .arg0 = head, - .arg1 = len, + .nr = __NR32_set_robust_list, + .arg0 = head, + .arg1 = len, }; return do_full_int80(&s); @@ -625,19 +632,18 @@ int get_task_futex_robust_list_compat(pid_t pid, ThreadCoreEntry *info) if (ret == -ENOSYS) { /* Check native get_task_futex_robust_list() for details. */ if (set_robust_list32(0, 0) == (uint32_t)-ENOSYS) { - info->futex_rla = 0; - info->futex_rla_len = 0; + info->futex_rla = 0; + info->futex_rla_len = 0; ret = 0; } } else if (ret == 0) { - uint32_t *arg1 = (uint32_t*)mmap32; + uint32_t *arg1 = (uint32_t *)mmap32; - info->futex_rla = *arg1; - info->futex_rla_len = *(arg1 + 1); + info->futex_rla = *arg1; + info->futex_rla_len = *(arg1 + 1); ret = 0; } - free_compat_syscall_stack(mmap32); return ret; } diff --git a/criu/arch/x86/kerndat.c b/criu/arch/x86/kerndat.c index ac627ac00..a98797d39 100644 --- a/criu/arch/x86/kerndat.c +++ b/criu/arch/x86/kerndat.c @@ -58,22 +58,20 @@ int kdat_can_map_vdso(void) return -1; return WEXITSTATUS(stat); - } #ifdef CONFIG_COMPAT -void *mmap_ia32(void *addr, size_t len, int prot, - int flags, int fildes, off_t off) +void *mmap_ia32(void *addr, size_t len, int prot, int flags, int fildes, off_t off) { struct syscall_args32 s; - s.nr = __NR32_mmap2; - s.arg0 = (uint32_t)(uintptr_t)addr; - s.arg1 = (uint32_t)len; - s.arg2 = prot; - s.arg3 = flags; - s.arg4 = fildes; - s.arg5 = (uint32_t)off; + s.nr = __NR32_mmap2; + s.arg0 = (uint32_t)(uintptr_t)addr; + s.arg1 = (uint32_t)len; + s.arg2 = prot; + s.arg3 = flags; + s.arg4 = fildes; + s.arg5 = (uint32_t)off; return (void *)(uintptr_t)do_full_int80(&s); } @@ -101,7 +99,7 @@ static void mmap_bug_test(void) void *map1, *map2; int err; - map1 = mmap_ia32(0, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + map1 = mmap_ia32(0, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); /* 32-bit error, not sign-extended - can't use IS_ERR_VALUE() here */ err = (uintptr_t)map1 % PAGE_SIZE; if (err) { @@ -114,7 +112,7 @@ static void mmap_bug_test(void) exit(1); } - map2 = mmap_ia32(0, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + map2 = mmap_ia32(0, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); err = (uintptr_t)map2 % PAGE_SIZE; if (err) { pr_err("ia32 mmap() failed: %d\n", err); @@ -200,7 +198,7 @@ static int kdat_x86_has_ptrace_fpu_xsave_bug_child(void *arg) */ int kdat_x86_has_ptrace_fpu_xsave_bug(void) { - user_fpregs_struct_t xsave = { }; + user_fpregs_struct_t xsave = {}; struct iovec iov; char stack[PAGE_SIZE]; int flags = CLONE_VM | CLONE_FILES | CLONE_UNTRACED | SIGCHLD; @@ -212,8 +210,7 @@ int kdat_x86_has_ptrace_fpu_xsave_bug(void) if (!compel_cpu_has_feature(X86_FEATURE_OSXSAVE)) return 0; - child = clone(kdat_x86_has_ptrace_fpu_xsave_bug_child, - stack + ARRAY_SIZE(stack), flags, 0); + child = clone(kdat_x86_has_ptrace_fpu_xsave_bug_child, stack + ARRAY_SIZE(stack), flags, 0); if (child < 0) { pr_perror("%s(): failed to clone()", __func__); return -1; diff --git a/criu/arch/x86/restorer.c b/criu/arch/x86/restorer.c index b2c3b3668..2ceb26fca 100644 --- a/criu/arch/x86/restorer.c +++ b/criu/arch/x86/restorer.c @@ -17,8 +17,7 @@ int arch_map_vdso(unsigned long map_at, bool compatible) { int vdso_type = compatible ? ARCH_MAP_VDSO_32 : ARCH_MAP_VDSO_64; - pr_debug("Mapping %s vDSO at %lx\n", - compatible ? "compatible" : "native", map_at); + pr_debug("Mapping %s vDSO at %lx\n", compatible ? "compatible" : "native", map_at); return sys_arch_prctl(vdso_type, map_at); } @@ -49,9 +48,9 @@ int restore_nonsigframe_gpregs(UserX86RegsEntry *r) int set_compat_robust_list(uint32_t head_ptr, uint32_t len) { struct syscall_args32 s = { - .nr = __NR32_set_robust_list, - .arg0 = head_ptr, - .arg1 = len, + .nr = __NR32_set_robust_list, + .arg0 = head_ptr, + .arg1 = len, }; return do_full_int80(&s); @@ -95,18 +94,16 @@ void restore_tls(tls_t *ptls) return; memcpy(stack32, desc, sizeof(user_desc_t)); - asm volatile ( - " mov %1,%%eax \n" - " mov %2,%%ebx \n" - " int $0x80 \n" - " mov %%eax,%0 \n" - : "=g"(ret) - : "r"(__NR32_set_thread_area), "r"((uint32_t)(uintptr_t)stack32) - : "eax", "ebx", "r8", "r9", "r10", "r11", "memory"); + asm volatile(" mov %1,%%eax \n" + " mov %2,%%ebx \n" + " int $0x80 \n" + " mov %%eax,%0 \n" + : "=g"(ret) + : "r"(__NR32_set_thread_area), "r"((uint32_t)(uintptr_t)stack32) + : "eax", "ebx", "r8", "r9", "r10", "r11", "memory"); if (ret) - pr_err("Failed to restore TLS descriptor %u in GDT: %d\n", - desc->entry_number, ret); + pr_err("Failed to restore TLS descriptor %u in GDT: %d\n", desc->entry_number, ret); } if (stack32) diff --git a/criu/arch/x86/sigaction_compat.c b/criu/arch/x86/sigaction_compat.c index f467da490..f02b2cc0e 100644 --- a/criu/arch/x86/sigaction_compat.c +++ b/criu/arch/x86/sigaction_compat.c @@ -5,21 +5,21 @@ #include <compel/plugins/std/syscall-codes.h> #ifdef CR_NOGLIBC -# include <compel/plugins/std/string.h> +#include <compel/plugins/std/string.h> #endif #include "cpu.h" -asm ( " .pushsection .text \n" - " .global restore_rt_sigaction \n" - " .code32 \n" - "restore_rt_sigaction: \n" - " mov %edx, %esi \n" - " mov $0, %edx \n" - " movl $"__stringify(__NR32_rt_sigaction)",%eax \n" - " int $0x80 \n" - " ret \n" - " .popsection \n" - " .code64"); +asm(" .pushsection .text \n" + " .global restore_rt_sigaction \n" + " .code32 \n" + "restore_rt_sigaction: \n" + " mov %edx, %esi \n" + " mov $0, %edx \n" + " movl $" __stringify(__NR32_rt_sigaction) ",%eax \n" + " int $0x80 \n" + " ret \n" + " .popsection \n" + " .code64"); extern char restore_rt_sigaction; /* @@ -42,11 +42,11 @@ int arch_compat_rt_sigaction(void *stack32, int sig, rt_sigaction_t_compat *act) * coping it on the bottom of the stack. */ memcpy(stack32, act, sizeof(rt_sigaction_t_compat)); - arg.nr = __NR32_rt_sigaction; - arg.arg0 = sig; - arg.arg1 = (uint32_t)act_stack; /* act */ - arg.arg2 = 0; /* oldact */ - arg.arg3 = (uint32_t)sizeof(act->rt_sa_mask); /* sigsetsize */ + arg.nr = __NR32_rt_sigaction; + arg.arg0 = sig; + arg.arg1 = (uint32_t)act_stack; /* act */ + arg.arg2 = 0; /* oldact */ + arg.arg3 = (uint32_t)sizeof(act->rt_sa_mask); /* sigsetsize */ return do_full_int80(&arg); } diff --git a/criu/arch/x86/sigframe.c b/criu/arch/x86/sigframe.c index 33ba14387..4fa7eb3dc 100644 --- a/criu/arch/x86/sigframe.c +++ b/criu/arch/x86/sigframe.c @@ -6,34 +6,28 @@ #include "log.h" -int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe) +int sigreturn_prep_fpu_frame(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe) { /* * Use local sigframe to check native/compat type, * but set address for rsigframe. */ - fpu_state_t *fpu_state = (sigframe->is_native) ? - &rsigframe->native.fpu_state : - &rsigframe->compat.fpu_state; + fpu_state_t *fpu_state = (sigframe->is_native) ? &rsigframe->native.fpu_state : &rsigframe->compat.fpu_state; if (sigframe->is_native) { unsigned long addr = (unsigned long)(void *)&fpu_state->fpu_state_64.xsave; if ((addr % 64ul)) { - pr_err("Unaligned address passed: %lx (native %d)\n", - addr, sigframe->is_native); + pr_err("Unaligned address passed: %lx (native %d)\n", addr, sigframe->is_native); return -1; } sigframe->native.uc.uc_mcontext.fpstate = (uint64_t)addr; } else if (!sigframe->is_native) { unsigned long addr = (unsigned long)(void *)&fpu_state->fpu_state_ia32.xsave; - sigframe->compat.uc.uc_mcontext.fpstate = - (uint32_t)(unsigned long)(void *)&fpu_state->fpu_state_ia32; + sigframe->compat.uc.uc_mcontext.fpstate = (uint32_t)(unsigned long)(void *)&fpu_state->fpu_state_ia32; if ((addr % 64ul)) { - pr_err("Unaligned address passed: %lx (native %d)\n", - addr, sigframe->is_native); + pr_err("Unaligned address passed: %lx (native %d)\n", addr, sigframe->is_native); return -1; } } diff --git a/criu/arch/x86/sys-exec-tbl.c b/criu/arch/x86/sys-exec-tbl.c index 225b8a153..cd7cda47c 100644 --- a/criu/arch/x86/sys-exec-tbl.c +++ b/criu/arch/x86/sys-exec-tbl.c @@ -1,20 +1,19 @@ static struct syscall_exec_desc sc_exec_table_64[] = { #include "sys-exec-tbl-64.c" - { }, /* terminator */ + {}, /* terminator */ }; #ifdef CONFIG_COMPAT static struct syscall_exec_desc sc_exec_table_32[] = { #include "sys-exec-tbl-32.c" - { }, /* terminator */ + {}, /* terminator */ }; #endif struct syscall_exec_desc; -static inline struct syscall_exec_desc * -find_syscall_table(char *name, struct syscall_exec_desc *tbl) +static inline struct syscall_exec_desc *find_syscall_table(char *name, struct syscall_exec_desc *tbl) { int i; @@ -27,7 +26,7 @@ find_syscall_table(char *name, struct syscall_exec_desc *tbl) #define ARCH_HAS_FIND_SYSCALL /* overwrite default to search in two tables above */ #ifdef CONFIG_COMPAT -struct syscall_exec_desc * find_syscall(char *name, struct parasite_ctl *ctl) +struct syscall_exec_desc *find_syscall(char *name, struct parasite_ctl *ctl) { if (compel_mode_native(ctl)) return find_syscall_table(name, sc_exec_table_64); @@ -35,8 +34,7 @@ struct syscall_exec_desc * find_syscall(char *name, struct parasite_ctl *ctl) return find_syscall_table(name, sc_exec_table_32); } #else -struct syscall_exec_desc * -find_syscall(char *name, __always_unused struct parasite_ctl *ctl) +struct syscall_exec_desc *find_syscall(char *name, __always_unused struct parasite_ctl *ctl) { return find_syscall_table(name, sc_exec_table_64); } diff --git a/criu/arch/x86/vdso-pie.c b/criu/arch/x86/vdso-pie.c index 988cf0869..6b4b82b02 100644 --- a/criu/arch/x86/vdso-pie.c +++ b/criu/arch/x86/vdso-pie.c @@ -9,22 +9,22 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " static void insert_trampoline32(uintptr_t from, uintptr_t to) { struct { - u8 movl; - u32 imm32; - u16 jmp_eax; - u32 guards; + u8 movl; + u32 imm32; + u16 jmp_eax; + u32 guards; } __packed jmp = { - .movl = 0xb8, - .imm32 = (uint32_t)to, - .jmp_eax = 0xe0ff, - .guards = 0xcccccccc, + .movl = 0xb8, + .imm32 = (uint32_t)to, + .jmp_eax = 0xe0ff, + .guards = 0xcccccccc, }; memcpy((void *)from, &jmp, sizeof(jmp)); @@ -33,23 +33,22 @@ static void insert_trampoline32(uintptr_t from, uintptr_t to) static void insert_trampoline64(uintptr_t from, uintptr_t to) { struct { - u16 movabs; - u64 imm64; - u16 jmp_rax; - u32 guards; + u16 movabs; + u64 imm64; + u16 jmp_rax; + u32 guards; } __packed jmp = { - .movabs = 0xb848, - .imm64 = to, - .jmp_rax = 0xe0ff, - .guards = 0xcccccccc, + .movabs = 0xb848, + .imm64 = to, + .jmp_rax = 0xe0ff, + .guards = 0xcccccccc, }; memcpy((void *)from, &jmp, sizeof(jmp)); } -int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, - struct vdso_symtable *sto, struct vdso_symtable *sfrom, - bool compat_vdso) +int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, struct vdso_symtable *sto, + struct vdso_symtable *sfrom, bool compat_vdso) { unsigned int i; @@ -59,9 +58,8 @@ int vdso_redirect_calls(unsigned long base_to, unsigned long base_from, if (vdso_symbol_empty(&sfrom->symbols[i])) continue; - pr_debug("jmp: %lx/%lx -> %lx/%lx (index %d)\n", - base_from, sfrom->symbols[i].offset, - base_to, sto->symbols[i].offset, i); + pr_debug("jmp: %lx/%lx -> %lx/%lx (index %d)\n", base_from, sfrom->symbols[i].offset, base_to, + sto->symbols[i].offset, i); from = base_from + sfrom->symbols[i].offset; to = base_to + sto->symbols[i].offset; diff --git a/criu/autofs.c b/criu/autofs.c index 8b25308d9..046d51d48 100644 --- a/criu/autofs.c +++ b/criu/autofs.c @@ -18,13 +18,13 @@ #include "images/autofs.pb-c.h" -#define AUTOFS_OPT_UNKNOWN INT_MIN +#define AUTOFS_OPT_UNKNOWN INT_MIN -#define AUTOFS_MODE_DIRECT 0 -#define AUTOFS_MODE_INDIRECT 1 -#define AUTOFS_MODE_OFFSET 2 +#define AUTOFS_MODE_DIRECT 0 +#define AUTOFS_MODE_INDIRECT 1 +#define AUTOFS_MODE_OFFSET 2 -#define AUTOFS_CATATONIC_FD -1 +#define AUTOFS_CATATONIC_FD -1 static int autofs_mnt_open(const char *mnt_path, dev_t devid); @@ -111,8 +111,7 @@ free: return ret; } -static int autofs_check_fd_stat(struct stat *stat, int prgp, int fd, - long ino, int *mode) +static int autofs_check_fd_stat(struct stat *stat, int prgp, int fd, long ino, int *mode) { struct fdinfo_common fdinfo; @@ -209,13 +208,15 @@ static int autofs_find_read_fd(int pgrp, long pipe_ino) /* We need to find read end and make sure, that it's empty */ if (autofs_find_pipe_read_end(pgrp, pipe_ino, &read_fd) < 0) { pr_err("Failed to find read pipe fd (ino %ld) " - "in process %d\n", pipe_ino, pgrp); + "in process %d\n", + pipe_ino, pgrp); return -1; } if (read_fd == -1) { pr_err("Master %d doesn't have a read end of the pipe with " - "inode %ld opened\n", pgrp, pipe_ino); + "inode %ld opened\n", + pgrp, pipe_ino); pr_err("Abandoned mount or control was delegated to child?\n"); return -ENOENT; } @@ -226,8 +227,7 @@ static int autofs_find_read_fd(int pgrp, long pipe_ino) return -1; if (fd_has_data(fd)) { - pr_err("Process %d autofs pipe fd %d is not empty.\n", pgrp, - read_fd); + pr_err("Process %d autofs pipe fd %d is not empty.\n", pgrp, read_fd); pr_err("Try again later.\n"); return -1; } @@ -348,7 +348,7 @@ static int autofs_revisit_options(struct mount_info *pm) char *token; /* Removing '/n' */ - str[strlen(str)-1] = '\0'; + str[strlen(str) - 1] = '\0'; while ((token = strsep(&str, " ")) != NULL) { if (mnt_id == -1) { @@ -427,16 +427,15 @@ static int access_autofs_mount(struct mount_info *pm) pid = fork(); switch (pid) { - case -1: - pr_err("failed to fork\n"); - goto close_autofs_mnt; - case 0: - /* We don't care about results. + case -1: + pr_err("failed to fork\n"); + goto close_autofs_mnt; + case 0: + /* We don't care about results. * All we need is to "touch" */ - /* coverity[check_return] */ - openat(autofs_mnt, mnt_path, O_RDONLY|O_NONBLOCK|O_DIRECTORY); - _exit(0); - + /* coverity[check_return] */ + openat(autofs_mnt, mnt_path, O_RDONLY | O_NONBLOCK | O_DIRECTORY); + _exit(0); } /* Here we also don't care about results */ waitpid(pid, &status, 0); @@ -499,24 +498,21 @@ static int autofs_create_entry(struct mount_info *pm, AutofsEntry *entry) * options, then we can read them again and dump it. */ if (access_autofs_mount(pm)) { - pr_err("failed to access autofs %s\n", - pm->mountpoint + 1); + pr_err("failed to access autofs %s\n", pm->mountpoint + 1); return -1; } if (parse_options(pm->options, entry, &pipe_ino)) return -1; if (entry->fd == AUTOFS_CATATONIC_FD) return 0; - pr_err("Autofs %d is alive, but unreachable.\n", - pm->mnt_id); + pr_err("Autofs %d is alive, but unreachable.\n", pm->mnt_id); return -1; } /* Let' check whether write end is still open */ found = autofs_kernel_pipe_alive(entry->pgrp, entry->fd, pipe_ino); if (found < 0) { - pr_err("Failed to check fd %d in process %d\n", - entry->fd, entry->pgrp); + pr_err("Failed to check fd %d in process %d\n", entry->fd, entry->pgrp); return -1; } /* Write end is absent. we need to carry read end to restore. */ @@ -528,8 +524,7 @@ static int autofs_create_entry(struct mount_info *pm, AutofsEntry *entry) /* We need to get virtual pgrp to restore mount */ virt_pgrp = pid_to_virt(entry->pgrp); if (!virt_pgrp) { - pr_err("failed to find pstree item with pid %d\n", - entry->pgrp); + pr_err("failed to find pstree item with pid %d\n", entry->pgrp); pr_err("Non-catatonic mount without master?\n"); return -1; } @@ -551,7 +546,6 @@ static int autofs_dump_entry(struct mount_info *pm, AutofsEntry *entry) return ret; } - int autofs_dump(struct mount_info *pm) { AutofsEntry *entry; @@ -582,8 +576,7 @@ typedef struct autofs_info_s { struct pprep_head ph; } autofs_info_t; -static int dup_pipe_info(struct pipe_info *pi, int flags, - struct file_desc_ops *ops) +static int dup_pipe_info(struct pipe_info *pi, int flags, struct file_desc_ops *ops) { struct pipe_info *new; PipeEntry *pe; @@ -609,9 +602,7 @@ static int dup_pipe_info(struct pipe_info *pi, int flags, return 0; } -static int autofs_dup_pipe(struct pstree_item *task, - struct fdinfo_list_entry *ple, - int new_fd) +static int autofs_dup_pipe(struct pstree_item *task, struct fdinfo_list_entry *ple, int new_fd) { struct pipe_info *pi = container_of(ple->desc, struct pipe_info, d); unsigned flags = O_WRONLY; @@ -619,23 +610,19 @@ static int autofs_dup_pipe(struct pstree_item *task, new_fd = find_unused_fd(task, new_fd); if (dup_pipe_info(pi, flags, pi->d.ops) < 0) { - pr_err("Failed to dup pipe entry ID %#x PIPE_ID %#x\n", - pi->pe->id, pi->pe->pipe_id); + pr_err("Failed to dup pipe entry ID %#x PIPE_ID %#x\n", pi->pe->id, pi->pe->pipe_id); return -1; } if (dup_fle(task, ple, new_fd, flags) < 0) { - pr_err("Failed to add fd %d to process %d\n", - new_fd, vpid(task)); + pr_err("Failed to add fd %d to process %d\n", new_fd, vpid(task)); return -1; } - pr_info("autofs: added pipe fd %d, flags %#x to %d\n", - new_fd, flags, vpid(task)); + pr_info("autofs: added pipe fd %d, flags %#x to %d\n", new_fd, flags, vpid(task)); return new_fd; } - static int autofs_ioctl(const char *path, int fd, int cmd, const void *param) { int err; @@ -649,7 +636,7 @@ static int autofs_ioctl(const char *path, int fd, int cmd, const void *param) static int autofs_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) { - char *path = "/dev/"AUTOFS_DEVICE_NAME; + char *path = "/dev/" AUTOFS_DEVICE_NAME; int fd, err; fd = open(path, O_RDONLY); @@ -670,8 +657,7 @@ static int autofs_mnt_make_catatonic(const char *mnt_path, int mnt_fd) return autofs_ioctl(mnt_path, mnt_fd, AUTOFS_IOC_CATATONIC, NULL); } -static int autofs_mnt_set_timeout(time_t timeout, - const char *mnt_path, int mnt_fd) +static int autofs_mnt_set_timeout(time_t timeout, const char *mnt_path, int mnt_fd) { pr_info("%s: set timeout %ld for %s\n", __func__, timeout, mnt_path); return autofs_ioctl(mnt_path, mnt_fd, AUTOFS_IOC_SETTIMEOUT, &timeout); @@ -685,8 +671,7 @@ static int autofs_mnt_set_pipefd(const autofs_info_t *i, int mnt_fd) if (i->entry->fd == AUTOFS_CATATONIC_FD) return 0; - pr_info("%s: set pipe fd %d (pgrp %d) for mount %s\n", __func__, - i->entry->fd, getpgrp(), i->mnt_path); + pr_info("%s: set pipe fd %d (pgrp %d) for mount %s\n", __func__, i->entry->fd, getpgrp(), i->mnt_path); init_autofs_dev_ioctl(¶m); param.ioctlfd = mnt_fd; @@ -699,8 +684,7 @@ static int autofs_mnt_close(const char *mnt_path, int mnt_fd) { struct autofs_dev_ioctl param; - pr_info("%s: closing fd %d for mount %s\n", __func__, mnt_fd, - mnt_path); + pr_info("%s: closing fd %d for mount %s\n", __func__, mnt_fd, mnt_path); init_autofs_dev_ioctl(¶m); param.ioctlfd = mnt_fd; @@ -730,8 +714,7 @@ static int autofs_mnt_open(const char *mnt_path, dev_t devid) fd = param->ioctlfd; free(param); if (err < 0) { - pr_err("Failed to get %s fd (devid: %ld)\n", - mnt_path, (long)devid); + pr_err("Failed to get %s fd (devid: %ld)\n", mnt_path, (long)devid); return -1; } return fd; @@ -746,8 +729,7 @@ static int autofs_create_dentries(const struct mount_info *mi, char *mnt_path) basename = strrchr(c->mountpoint, '/'); if (!basename) { - pr_info("%s: mount path \"%s\" doesn't have '/'\n", - __func__, c->mountpoint); + pr_info("%s: mount path \"%s\" doesn't have '/'\n", __func__, c->mountpoint); return -1; } path = xsprintf("%s%s", mnt_path, basename); @@ -763,8 +745,7 @@ static int autofs_create_dentries(const struct mount_info *mi, char *mnt_path) return 0; } -static int autofs_populate_mount(const struct mount_info *mi, - const AutofsEntry *entry) +static int autofs_populate_mount(const struct mount_info *mi, const AutofsEntry *entry) { if (entry->mode != AUTOFS_MODE_INDIRECT) return 0; @@ -772,13 +753,11 @@ static int autofs_populate_mount(const struct mount_info *mi, return autofs_create_dentries(mi, mi->mountpoint); } -static int autofs_post_mount(const char *mnt_path, dev_t mnt_dev, - time_t timeout) +static int autofs_post_mount(const char *mnt_path, dev_t mnt_dev, time_t timeout) { int mnt_fd; - pr_info("%s: set timeout for %s and make it catatonic\n", - __func__, mnt_path); + pr_info("%s: set timeout for %s and make it catatonic\n", __func__, mnt_path); mnt_fd = autofs_mnt_open(mnt_path, mnt_dev); if (mnt_fd < 0) { @@ -787,8 +766,7 @@ static int autofs_post_mount(const char *mnt_path, dev_t mnt_dev, } if (autofs_mnt_set_timeout(timeout, mnt_path, mnt_fd)) { - pr_err("Failed to set timeout %ld for %s\n", - timeout, mnt_path); + pr_err("Failed to set timeout %ld for %s\n", timeout, mnt_path); return -1; } @@ -830,23 +808,19 @@ static int autofs_post_open(struct file_desc *d, int fd) return -1; } - pr_info("autofs mount %s owner restored: pgrp=%d, fd=%d\n", - i->mnt_path, getpgrp(), i->entry->fd); + pr_info("autofs mount %s owner restored: pgrp=%d, fd=%d\n", i->mnt_path, getpgrp(), i->entry->fd); if (i->entry->has_read_fd) { - pr_info("%s: pid %d, closing write end %d\n", __func__, - getpid(), i->entry->fd); + pr_info("%s: pid %d, closing write end %d\n", __func__, getpid(), i->entry->fd); close(i->entry->fd); } - pr_info("%s: pid %d, closing artificial pipe end %d\n", __func__, - getpid(), fd); + pr_info("%s: pid %d, closing artificial pipe end %d\n", __func__, getpid(), fd); close(fd); return 0; } -static autofs_info_t *autofs_create_info(const struct mount_info *mi, - const struct file_desc *desc, +static autofs_info_t *autofs_create_info(const struct mount_info *mi, const struct file_desc *desc, const autofs_info_t *info) { autofs_info_t *i; @@ -876,8 +850,7 @@ static autofs_info_t *autofs_create_info(const struct mount_info *mi, return i; } -static struct fdinfo_list_entry *autofs_pipe_le(struct pstree_item *master, - AutofsEntry *entry) +static struct fdinfo_list_entry *autofs_pipe_le(struct pstree_item *master, AutofsEntry *entry) { struct fdinfo_list_entry *ple; int pipe_fd = entry->fd; @@ -887,13 +860,11 @@ static struct fdinfo_list_entry *autofs_pipe_le(struct pstree_item *master, ple = find_used_fd(master, pipe_fd); if (!ple) { - pr_err("Failed to find pipe fd %d in process %d\n", - pipe_fd, vpid(master)); + pr_err("Failed to find pipe fd %d in process %d\n", pipe_fd, vpid(master)); return NULL; } if (ple->fe->type != FD_TYPES__PIPE) { - pr_err("Fd %d in process %d is not a pipe: %d\n", pipe_fd, - vpid(master), ple->fe->type); + pr_err("Fd %d in process %d is not a pipe: %d\n", pipe_fd, vpid(master), ple->fe->type); return NULL; } return ple; @@ -915,8 +886,7 @@ static int autofs_open_pipefd(struct file_desc *d, int *new_fd) return autofs_post_open(d, fle->fe->fd); } -static int autofs_create_pipe(struct pstree_item *task, autofs_info_t *i, - struct fdinfo_list_entry *ple) +static int autofs_create_pipe(struct pstree_item *task, autofs_info_t *i, struct fdinfo_list_entry *ple) { struct pipe_info *pi = container_of(ple->desc, struct pipe_info, d); int fd = -1; @@ -953,8 +923,7 @@ static int autofs_create_pipe(struct pstree_item *task, autofs_info_t *i, return -1; fe->type = FD_TYPES__AUTOFS_PIPE; - pr_info("autofs: adding pipe fd %d, flags %#x to %d (with post_open)\n", - fe->fd, fe->flags, vpid(task)); + pr_info("autofs: adding pipe fd %d, flags %#x to %d (with post_open)\n", fe->fd, fe->flags, vpid(task)); return collect_fd(vpid(task), fe, rsti(task), false); } @@ -985,8 +954,7 @@ static int autofs_add_mount_info(struct pprep_head *ph) entry->fd = autofs_dup_pipe(master, ple, entry->fd); if (entry->fd < 0) { - pr_err("Failed to find free fd in process %d\n", - vpid(master)); + pr_err("Failed to find free fd in process %d\n", vpid(master)); return -1; } } @@ -1025,8 +993,7 @@ static int autofs_restore_entry(struct mount_info *mi, AutofsEntry **entry) return 0; } -int autofs_mount(struct mount_info *mi, const char *source, const - char *filesystemtype, unsigned long mountflags) +int autofs_mount(struct mount_info *mi, const char *source, const char *filesystemtype, unsigned long mountflags) { AutofsEntry *entry; autofs_info_t *info; @@ -1048,8 +1015,7 @@ int autofs_mount(struct mount_info *mi, const char *source, const if (entry->mode == AUTOFS_MODE_OFFSET) mode = "offset"; - opts = xsprintf("fd=%d,pgrp=%d,minproto=%d,maxproto=%d,%s", - control_pipe[1], getpgrp(), entry->minproto, + opts = xsprintf("fd=%d,pgrp=%d,minproto=%d,maxproto=%d,%s", control_pipe[1], getpgrp(), entry->minproto, entry->maxproto, mode); if (opts && entry->has_uid) opts = xstrcat(opts, ",uid=%d", entry->uid); @@ -1060,8 +1026,7 @@ int autofs_mount(struct mount_info *mi, const char *source, const goto close_pipe; } - pr_info("autofs: mounting to %s with options: \"%s\"\n", - mi->mountpoint, opts); + pr_info("autofs: mounting to %s with options: \"%s\"\n", mi->mountpoint, opts); if (mount(source, mi->mountpoint, filesystemtype, mountflags, opts) < 0) { pr_perror("Failed to mount autofs to %s", mi->mountpoint); @@ -1118,4 +1083,3 @@ umount: pr_perror("Failed to umount %s", mi->mountpoint); goto close_pipe; } - diff --git a/criu/bfd.c b/criu/bfd.c index e0d9ede7a..2c5f5b64a 100644 --- a/criu/bfd.c +++ b/criu/bfd.c @@ -16,14 +16,14 @@ #include "xmalloc.h" #include "page.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "bfd: " /* * Kernel doesn't produce more than one page of * date per one read call on proc files. */ -#define BUFSIZE (PAGE_SIZE) +#define BUFSIZE (PAGE_SIZE) struct bfd_buf { char *mem; @@ -32,7 +32,7 @@ struct bfd_buf { static LIST_HEAD(bufs); -#define BUFBATCH (16) +#define BUFBATCH (16) static int buf_get(struct xbuf *xb) { @@ -42,8 +42,7 @@ static int buf_get(struct xbuf *xb) void *mem; int i; - mem = mmap(NULL, BUFBATCH * BUFSIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + mem = mmap(NULL, BUFBATCH * BUFSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (mem == MAP_FAILED) { pr_perror("No buf"); return -1; diff --git a/criu/bitmap.c b/criu/bitmap.c index a28a89d8d..d81c93409 100644 --- a/criu/bitmap.c +++ b/criu/bitmap.c @@ -1,17 +1,12 @@ #include "common/bitsperlong.h" -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define BITMAP_FIRST_WORD_MASK(start) (~0ul << ((start) % BITS_PER_LONG)) -#define BITMAP_LAST_WORD_MASK(nbits) \ -( \ - ((nbits) % BITS_PER_LONG) ? \ - (1ul << ((nbits) % BITS_PER_LONG)) - 1 : ~0ul \ -) +#define BITMAP_LAST_WORD_MASK(nbits) (((nbits) % BITS_PER_LONG) ? (1ul << ((nbits) % BITS_PER_LONG)) - 1 : ~0ul) -#define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) +#define small_const_nbits(nbits) (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) void bitmap_set(unsigned long *map, int start, int nr) { diff --git a/criu/bpfmap.c b/criu/bpfmap.c index 9a133f8bc..55b381c18 100644 --- a/criu/bpfmap.c +++ b/criu/bpfmap.c @@ -19,8 +19,8 @@ int is_bpfmap_link(char *link) static void pr_info_bpfmap(char *action, BpfmapFileEntry *bpf) { - pr_info("%sbpfmap: id %#08x map_id %#08x map_type %d flags %"PRIx32"\n", - action, bpf->id, bpf->map_id, bpf->map_type, bpf->map_flags); + pr_info("%sbpfmap: id %#08x map_id %#08x map_type %d flags %" PRIx32 "\n", action, bpf->id, bpf->map_id, + bpf->map_type, bpf->map_flags); } struct bpfmap_data_rst *bpfmap_data_hash_table[BPFMAP_DATA_TABLE_SIZE]; @@ -31,8 +31,7 @@ static int bpfmap_data_read(struct cr_img *img, struct bpfmap_data_rst *r) if (!bytes) return 0; - r->data = mmap(NULL, bytes, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + r->data = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (r->data == MAP_FAILED) { pr_perror("Can't map mem for bpfmap buffers"); return -1; @@ -41,8 +40,8 @@ static int bpfmap_data_read(struct cr_img *img, struct bpfmap_data_rst *r) return read_img_buf(img, r->data, bytes); } -int do_collect_bpfmap_data(struct bpfmap_data_rst *r, ProtobufCMessage *msg, - struct cr_img *img, struct bpfmap_data_rst **bpf_hash_table) +int do_collect_bpfmap_data(struct bpfmap_data_rst *r, ProtobufCMessage *msg, struct cr_img *img, + struct bpfmap_data_rst **bpf_hash_table) { int ret; int table_index; @@ -67,14 +66,9 @@ int restore_bpfmap_data(int map_fd, uint32_t map_id, struct bpfmap_data_rst **bp void *keys = NULL; void *values = NULL; unsigned int count; - DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, - .elem_flags = 0, - .flags = 0, - ); - - for (map_data = bpf_hash_table[map_id & BPFMAP_DATA_HASH_MASK]; map_data != NULL; - map_data = map_data->next) { + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, ); + for (map_data = bpf_hash_table[map_id & BPFMAP_DATA_HASH_MASK]; map_data != NULL; map_data = map_data->next) { if (map_data->bde->map_id == map_id) break; } @@ -87,16 +81,14 @@ int restore_bpfmap_data(int map_fd, uint32_t map_id, struct bpfmap_data_rst **bp bde = map_data->bde; count = bde->count; - keys = mmap(NULL, bde->keys_bytes, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + keys = mmap(NULL, bde->keys_bytes, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (keys == MAP_FAILED) { pr_perror("Can't map memory for BPF map keys"); goto err; } memcpy(keys, map_data->data, bde->keys_bytes); - values = mmap(NULL, bde->values_bytes, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + values = mmap(NULL, bde->values_bytes, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (values == MAP_FAILED) { pr_perror("Can't map memory for BPF map values"); goto err; @@ -157,10 +149,7 @@ int dump_one_bpfmap_data(BpfmapFileEntry *bpf, int lfd, const struct fd_parms *p void *keys = NULL, *values = NULL; void *in_batch = NULL, *out_batch = NULL; BpfmapDataEntry bde = BPFMAP_DATA_ENTRY__INIT; - DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, - .elem_flags = 0, - .flags = 0, - ); + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, ); int ret; key_size = bpf->key_size; @@ -168,22 +157,19 @@ int dump_one_bpfmap_data(BpfmapFileEntry *bpf, int lfd, const struct fd_parms *p max_entries = bpf->max_entries; count = max_entries; - keys = mmap(NULL, key_size * max_entries, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + keys = mmap(NULL, key_size * max_entries, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (keys == MAP_FAILED) { pr_perror("Can't map memory for BPF map keys"); goto err; } - values = mmap(NULL, value_size * max_entries, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + values = mmap(NULL, value_size * max_entries, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (values == MAP_FAILED) { pr_perror("Can't map memory for BPF map values"); goto err; } - out_batch = mmap(NULL, key_size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + out_batch = mmap(NULL, key_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (out_batch == MAP_FAILED) { pr_perror("Can't map memory for BPF map out_batch"); goto err; @@ -244,38 +230,36 @@ static int dump_one_bpfmap(int lfd, u32 id, const struct fd_parms *p) } switch (bpf.map_type) { - - case BPF_MAP_TYPE_HASH: - case BPF_MAP_TYPE_ARRAY: - bpf.id = id; - bpf.flags = p->flags; - bpf.fown = (FownEntry *)&p->fown; - bpf.map_name = xstrdup(map_info.name); - bpf.ifindex = map_info.ifindex; - - fe.type = FD_TYPES__BPFMAP; - fe.id = bpf.id; - fe.bpf = &bpf; - - pr_info_bpfmap("Dumping ", &bpf); - if (pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE)) - return -1; - pr_info_bpfmap("Dumping data for ", &bpf); - ret = dump_one_bpfmap_data(&bpf, lfd, p); - break; - - default: - pr_err("CRIU does not currently support dumping BPF map type %u!\n", bpf.map_type); - ret = -1; + case BPF_MAP_TYPE_HASH: + case BPF_MAP_TYPE_ARRAY: + bpf.id = id; + bpf.flags = p->flags; + bpf.fown = (FownEntry *)&p->fown; + bpf.map_name = xstrdup(map_info.name); + bpf.ifindex = map_info.ifindex; + + fe.type = FD_TYPES__BPFMAP; + fe.id = bpf.id; + fe.bpf = &bpf; + + pr_info_bpfmap("Dumping ", &bpf); + if (pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE)) + return -1; + pr_info_bpfmap("Dumping data for ", &bpf); + ret = dump_one_bpfmap_data(&bpf, lfd, p); + break; + + default: + pr_err("CRIU does not currently support dumping BPF map type %u!\n", bpf.map_type); + ret = -1; } return ret; - } const struct fdtype_ops bpfmap_dump_ops = { - .type = FD_TYPES__BPFMAP, - .dump = dump_one_bpfmap, + .type = FD_TYPES__BPFMAP, + .dump = dump_one_bpfmap, }; static int bpfmap_open(struct file_desc *d, int *new_fd) diff --git a/criu/cgroup-props.c b/criu/cgroup-props.c index 2f628f4ee..5bed7dd9d 100644 --- a/criu/cgroup-props.c +++ b/criu/cgroup-props.c @@ -20,7 +20,7 @@ #include "log.h" #include "common/bug.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "cg-prop: " enum { @@ -36,14 +36,14 @@ static const char *____criu_global_props____[] = { }; cgp_t cgp_global = { - .name = "____criu_global_props____", - .nr_props = ARRAY_SIZE(____criu_global_props____), - .props = ____criu_global_props____, + .name = "____criu_global_props____", + .nr_props = ARRAY_SIZE(____criu_global_props____), + .props = ____criu_global_props____, }; typedef struct { - struct list_head list; - cgp_t cgp; + struct list_head list; + cgp_t cgp; } cgp_list_entry_t; static LIST_HEAD(cgp_list); @@ -91,9 +91,7 @@ static int cgp_handle_props(cgp_list_entry_t **p, int strategy) if (strcmp(t->cgp.name, s->cgp.name)) continue; - pr_debug("%s \"%s\" controller properties\n", - strategy == CGP_MERGE ? - "Merging" : "Replacing", + pr_debug("%s \"%s\" controller properties\n", strategy == CGP_MERGE ? "Merging" : "Replacing", s->cgp.name); if (strategy == CGP_MERGE) { @@ -258,21 +256,18 @@ static int cgp_parse_stream(char *stream, size_t len) } if (!eat_symbols(&stream, &len, ":\n - ", 5, true)) { - pr_err("Expected \':\\n - \' sequence controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected \':\\n - \' sequence controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; } if (!eat_word(&stream, &len, "\"strategy\":", 11, true)) { - pr_err("Expected \'strategy:\' keyword in controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected \'strategy:\' keyword in controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; } p = get_quoted(&stream, &len, true); if (!p) { - pr_err("Expected strategy in controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected strategy in controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; }; @@ -281,8 +276,7 @@ static int cgp_parse_stream(char *stream, size_t len) } else if (!strcmp(p, "replace")) { strategy = CGP_REPLACE; } else { - pr_err("Unknown strategy \"%s\" in controller's %s stream\n", - p, cgp_entry->cgp.name); + pr_err("Unknown strategy \"%s\" in controller's %s stream\n", p, cgp_entry->cgp.name); xfree(p); goto err_parse; } @@ -291,34 +285,28 @@ static int cgp_parse_stream(char *stream, size_t len) xfree(p); if (!eat_symbols(&stream, &len, "\n - ", 4, true)) { - pr_err("Expected \':\\n - \' sequence controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected \':\\n - \' sequence controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; } if (!eat_word(&stream, &len, "\"properties\":", 13, true)) { - pr_err("Expected \"properties:\" keyword in controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected \"properties:\" keyword in controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; } if (!eat_symbol(&stream, &len, '[', true)) { - pr_err("Expected \'[\' sequence controller's %s properties stream\n", - cgp_entry->cgp.name); + pr_err("Expected \'[\' sequence controller's %s properties stream\n", cgp_entry->cgp.name); goto err_parse; } while ((p = get_quoted(&stream, &len, true))) { if (!p) { - pr_err("Expected property name for controller %s\n", - cgp_entry->cgp.name); + pr_err("Expected property name for controller %s\n", cgp_entry->cgp.name); goto err_parse; } - if (xrealloc_safe(&cgp_entry->cgp.props, - (cgp_entry->cgp.nr_props + 1) * sizeof(char *))) { - pr_err("Can't allocate property for controller %s\n", - cgp_entry->cgp.name); + if (xrealloc_safe(&cgp_entry->cgp.props, (cgp_entry->cgp.nr_props + 1) * sizeof(char *))) { + pr_err("Can't allocate property for controller %s\n", cgp_entry->cgp.name); xfree(p); goto err_parse; } @@ -331,8 +319,7 @@ static int cgp_parse_stream(char *stream, size_t len) stream++, len--; break; } - pr_err("Expected ']' in controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected ']' in controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; } } @@ -343,8 +330,7 @@ static int cgp_parse_stream(char *stream, size_t len) } if (!eat_symbol(&stream, &len, '\n', true) && len) { - pr_err("Expected \'\\n\' symbol in controller's %s stream\n", - cgp_entry->cgp.name); + pr_err("Expected \'\\n\' symbol in controller's %s stream\n", cgp_entry->cgp.name); goto err_parse; } @@ -402,96 +388,94 @@ err: static int cgp_parse_builtins(void) { - static const char predefined_stream[] = - "\"cpu\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"cpu.shares\", " - "\"cpu.cfs_period_us\", " - "\"cpu.cfs_quota_us\", " - "\"cpu.rt_period_us\", " - "\"cpu.rt_runtime_us\" " - "]\n" - /* limit_in_bytes and memsw.limit_in_bytes must be set in this order */ - "\"memory\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"memory.limit_in_bytes\", " - "\"memory.memsw.limit_in_bytes\", " - "\"memory.swappiness\", " - "\"memory.soft_limit_in_bytes\", " - "\"memory.move_charge_at_immigrate\", " - "\"memory.oom_control\", " - "\"memory.use_hierarchy\", " - "\"memory.kmem.limit_in_bytes\", " - "\"memory.kmem.tcp.limit_in_bytes\" " - "]\n" - /* + static const char predefined_stream[] = "\"cpu\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"cpu.shares\", " + "\"cpu.cfs_period_us\", " + "\"cpu.cfs_quota_us\", " + "\"cpu.rt_period_us\", " + "\"cpu.rt_runtime_us\" " + "]\n" + /* limit_in_bytes and memsw.limit_in_bytes must be set in this order */ + "\"memory\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"memory.limit_in_bytes\", " + "\"memory.memsw.limit_in_bytes\", " + "\"memory.swappiness\", " + "\"memory.soft_limit_in_bytes\", " + "\"memory.move_charge_at_immigrate\", " + "\"memory.oom_control\", " + "\"memory.use_hierarchy\", " + "\"memory.kmem.limit_in_bytes\", " + "\"memory.kmem.tcp.limit_in_bytes\" " + "]\n" + /* * cpuset.cpus and cpuset.mems must be set before the process moves * into its cgroup; they are "initialized" below to whatever the root * values are in copy_special_cg_props so as not to cause ENOSPC when * values are restored via this code. */ - "\"cpuset\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"cpuset.cpus\", " - "\"cpuset.mems\", " - "\"cpuset.memory_migrate\", " - "\"cpuset.cpu_exclusive\", " - "\"cpuset.mem_exclusive\", " - "\"cpuset.mem_hardwall\", " - "\"cpuset.memory_spread_page\", " - "\"cpuset.memory_spread_slab\", " - "\"cpuset.sched_load_balance\", " - "\"cpuset.sched_relax_domain_level\" " - "]\n" - "\"blkio\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"blkio.weight\" " - "]\n" - "\"freezer\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "]\n" - "\"perf_event\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "]\n" - "\"net_cls\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"net_cls.classid\" " - "]\n" - "\"net_prio\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"net_prio.ifpriomap\" " - "]\n" - "\"pids\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"pids.max\" " - "]\n" - "\"devices\":\n" - " - \"strategy\": \"replace\"\n" - " - \"properties\": " - "[ " - "\"devices.list\" " - "]\n"; - - return cgp_parse_stream((void *)predefined_stream, - strlen(predefined_stream)); + "\"cpuset\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"cpuset.cpus\", " + "\"cpuset.mems\", " + "\"cpuset.memory_migrate\", " + "\"cpuset.cpu_exclusive\", " + "\"cpuset.mem_exclusive\", " + "\"cpuset.mem_hardwall\", " + "\"cpuset.memory_spread_page\", " + "\"cpuset.memory_spread_slab\", " + "\"cpuset.sched_load_balance\", " + "\"cpuset.sched_relax_domain_level\" " + "]\n" + "\"blkio\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"blkio.weight\" " + "]\n" + "\"freezer\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "]\n" + "\"perf_event\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "]\n" + "\"net_cls\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"net_cls.classid\" " + "]\n" + "\"net_prio\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"net_prio.ifpriomap\" " + "]\n" + "\"pids\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"pids.max\" " + "]\n" + "\"devices\":\n" + " - \"strategy\": \"replace\"\n" + " - \"properties\": " + "[ " + "\"devices.list\" " + "]\n"; + + return cgp_parse_stream((void *)predefined_stream, strlen(predefined_stream)); } int cgp_init(char *stream, size_t len, char *path) diff --git a/criu/cgroup.c b/criu/cgroup.c index fa088858f..73461d6a0 100644 --- a/criu/cgroup.c +++ b/criu/cgroup.c @@ -1,4 +1,4 @@ -#define LOG_PREFIX "cg: " +#define LOG_PREFIX "cg: " #include <sys/types.h> #include <stdio.h> #include <string.h> @@ -36,10 +36,10 @@ */ struct cg_set { - u32 id; - struct list_head l; - unsigned int n_ctls; - struct list_head ctls; + u32 id; + struct list_head l; + unsigned int n_ctls; + struct list_head ctls; }; static LIST_HEAD(cg_sets); @@ -66,8 +66,8 @@ static CgSetEntry *find_rst_set_by_id(u32 id) return NULL; } -#define CGCMP_MATCH 1 /* check for exact match */ -#define CGCMP_ISSUB 2 /* check set is subset of ctls */ +#define CGCMP_MATCH 1 /* check for exact match */ +#define CGCMP_ISSUB 2 /* check set is subset of ctls */ static bool cg_set_compare(struct cg_set *set, struct list_head *ctls, int what) { @@ -189,8 +189,7 @@ int parse_cg_info(void) /* Check that co-mounted controllers from /proc/cgroups (e.g. cpu and cpuacct) * are contained in a comma separated string (e.g. from /proc/self/cgroup or * mount options). */ -static bool cgroup_contains(char **controllers, - unsigned int n_controllers, char *name, u64 *mask) +static bool cgroup_contains(char **controllers, unsigned int n_controllers, char *name, u64 *mask) { unsigned int i; bool all_match = true; @@ -230,12 +229,12 @@ static bool cgroup_contains(char **controllers, /* This is for use in add_cgroup() as additional arguments for the ftw() * callback */ -static struct cg_controller *current_controller; -static unsigned int path_pref_len; +static struct cg_controller *current_controller; +static unsigned int path_pref_len; -#define EXACT_MATCH 0 -#define PARENT_MATCH 1 -#define NO_MATCH 2 +#define EXACT_MATCH 0 +#define PARENT_MATCH 1 +#define NO_MATCH 2 static int find_dir(const char *path, struct list_head *dirs, struct cgroup_dir **rdir) { @@ -253,7 +252,6 @@ static int find_dir(const char *path, struct list_head *dirs, struct cgroup_dir return PARENT_MATCH; } return ret; - } } @@ -431,8 +429,7 @@ static int dump_cg_props_array(const char *fpath, struct cgroup_dir *ncd, const return 0; } -static int add_cgroup_properties(const char *fpath, struct cgroup_dir *ncd, - struct cg_controller *controller) +static int add_cgroup_properties(const char *fpath, struct cgroup_dir *ncd, struct cg_controller *controller) { int i; @@ -527,7 +524,7 @@ static int add_freezer_state(struct cg_controller *controller) { struct cgroup_dir *it; - /* There is one more case, that cgroup namespaces might + /* There is one more case, that cgroup namespaces might * generate "multiple" heads if nothing is actually in the * root freezer cgroup, e.g. --freeze-cgroup=/lxc/foo and all * tasks in either /lxc/foo/a or /lxc/foo/b. @@ -570,12 +567,11 @@ static int __new_open_cgroupfs(struct cg_ctl *cc) } if (strstartswith(cc->name, namestr)) { - if (sys_fsconfig(fsfd, FSCONFIG_SET_STRING, - "name", cc->name + strlen(namestr), 0)) { + if (sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "name", cc->name + strlen(namestr), 0)) { pr_perror("Unable to configure the cgroup (%s) file system", cc->name); goto err; } - } else if (cc->name[0] != 0) { /* cgroup v1 */ + } else if (cc->name[0] != 0) { /* cgroup v1 */ char *saveptr = NULL, *buf = strdupa(cc->name); name = strtok_r(buf, ",", &saveptr); while (name) { @@ -723,8 +719,7 @@ static int collect_cgroups(struct list_head *ctls) if (ret < 0) return ret; - if (opts.freeze_cgroup && !strcmp(cc->name, "freezer") && - add_freezer_state(current_controller)) + if (opts.freeze_cgroup && !strcmp(cc->name, "freezer") && add_freezer_state(current_controller)) return -1; } @@ -776,7 +771,8 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_ continue; if (strlen(stray->path) < root->cgns_prefix) { - pr_err("cg %s shorter than path prefix %d?\n", stray->path, root->cgns_prefix); + pr_err("cg %s shorter than path prefix %d?\n", stray->path, + root->cgns_prefix); return -1; } @@ -790,8 +786,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_ return 0; } -static int dump_cg_dir_props(struct list_head *props, size_t n_props, - CgroupPropEntry ***ents) +static int dump_cg_dir_props(struct list_head *props, size_t n_props, CgroupPropEntry ***ents) { struct cgroup_prop *prop_cur; CgroupPropEntry *cpe; @@ -876,8 +871,7 @@ static int dump_cg_dirs(struct list_head *dirs, size_t n_dirs, CgroupDirEntry ** cde->n_properties = cur->n_properties; if (cde->n_properties > 0) { - if (dump_cg_dir_props(&cur->properties, - cde->n_properties, &cde->properties) < 0) { + if (dump_cg_dir_props(&cur->properties, cde->n_properties, &cde->properties) < 0) { xfree(*ents); return -1; } @@ -931,7 +925,6 @@ static void free_sets(CgroupEntry *cg, unsigned nr) xfree(cg->sets); } - static int dump_sets(CgroupEntry *cg) { struct cg_set *set; @@ -1024,8 +1017,7 @@ err: return ret; } -static int ctrl_dir_and_opt(CgControllerEntry *ctl, char *dir, int ds, - char *opt, int os) +static int ctrl_dir_and_opt(CgControllerEntry *ctl, char *dir, int ds, char *opt, int os) { int i, doff = 0, ooff = 0; bool none_opt = false; @@ -1062,14 +1054,8 @@ static int ctrl_dir_and_opt(CgControllerEntry *ctl, char *dir, int ds, * it. We restore these properties as soon as the cgroup is created. */ static const char *special_props[] = { - "cpuset.cpus", - "cpuset.mems", - "devices.list", - "memory.kmem.limit_in_bytes", - "memory.swappiness", - "memory.oom_control", - "memory.use_hierarchy", - NULL, + "cpuset.cpus", "cpuset.mems", "devices.list", "memory.kmem.limit_in_bytes", + "memory.swappiness", "memory.oom_control", "memory.use_hierarchy", NULL, }; bool is_special_property(const char *prop) @@ -1165,7 +1151,6 @@ static int prepare_cgns(CgSetEntry *se) do_unshare = true; } - } if (do_unshare && unshare(CLONE_NEWCGROUP) < 0) { @@ -1294,13 +1279,12 @@ static int restore_perms(int fd, const char *path, CgroupPerms *perms) * allowed to chmod some cgroup props (e.g. the read only ones), so we * don't want to try if the perms already match. */ - if (sb.st_mode != (mode_t) perms->mode && fchmod(fd, perms->mode) < 0) { + if (sb.st_mode != (mode_t)perms->mode && fchmod(fd, perms->mode) < 0) { pr_perror("chmod of %s failed", path); return -1; } - if ((sb.st_uid != perms->uid || sb.st_gid != perms->gid) && - fchown(fd, perms->uid, perms->gid)) { + if ((sb.st_uid != perms->uid || sb.st_gid != perms->gid) && fchown(fd, perms->uid, perms->gid)) { pr_perror("chown of %s failed", path); return -1; } @@ -1309,8 +1293,8 @@ static int restore_perms(int fd, const char *path, CgroupPerms *perms) return 0; } -static int restore_cgroup_prop(const CgroupPropEntry *cg_prop_entry_p, - char *path, int off, bool split_lines, bool skip_fails) +static int restore_cgroup_prop(const CgroupPropEntry *cg_prop_entry_p, char *path, int off, bool split_lines, + bool skip_fails) { int cg, fd, ret = -1; CgroupPerms *perms = cg_prop_entry_p->perms; @@ -1358,7 +1342,7 @@ static int restore_cgroup_prop(const CgroupPropEntry *cg_prop_entry_p, goto out; } line = next_line + 1; - } while(*next_line != '\0'); + } while (*next_line != '\0'); } else { size_t len = strlen(cg_prop_entry_p->value); @@ -1389,8 +1373,7 @@ int restore_freezer_state(void) return 0; freezer_path_len = strlen(freezer_path); - return restore_cgroup_prop(freezer_state_entry, freezer_path, - freezer_path_len, false, false); + return restore_cgroup_prop(freezer_state_entry, freezer_path, freezer_path_len, false, false); } static void add_freezer_state_for_restore(CgroupPropEntry *entry, char *path, size_t path_len) @@ -1455,9 +1438,9 @@ static int filter_ifpriomap(char *out, char *line) strncpy(out, line, len + 1); out += len + 1; written = true; -next: + next: line = next_line + 1; - } while(*next_line != '\0'); + } while (*next_line != '\0'); if (written) *(out - 1) = '\0'; @@ -1486,8 +1469,7 @@ out: return ret; } -static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **ents, - unsigned int n_ents) +static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **ents, unsigned int n_ents) { unsigned int i, j; @@ -1528,7 +1510,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e if (restore_cgroup_prop(p, path, off2, false, false) < 0) return -1; } -skip: + skip: if (prepare_cgroup_dir_properties(path, off2, e->children, e->n_children) < 0) return -1; } @@ -1655,8 +1637,8 @@ static int prepare_dir_perms(int cg, char *path, CgroupPerms *perms) return ret; } -static int prepare_cgroup_dirs(char **controllers, int n_controllers, char *paux, size_t off, - CgroupDirEntry **ents, size_t n_ents) +static int prepare_cgroup_dirs(char **controllers, int n_controllers, char *paux, size_t off, CgroupDirEntry **ents, + size_t n_ents) { size_t i, j; CgroupDirEntry *e; @@ -1689,9 +1671,8 @@ static int prepare_cgroup_dirs(char **controllers, int n_controllers, char *paux return -1; for (j = 0; j < n_controllers; j++) { - if (!strcmp(controllers[j], "cpuset") - || !strcmp(controllers[j], "memory") - || !strcmp(controllers[j], "devices")) { + if (!strcmp(controllers[j], "cpuset") || !strcmp(controllers[j], "memory") || + !strcmp(controllers[j], "devices")) { if (restore_special_props(paux, off2, e) < 0) { pr_err("Restoring special cpuset props failed!\n"); return -1; @@ -1715,13 +1696,11 @@ static int prepare_cgroup_dirs(char **controllers, int n_controllers, char *paux } } - if (!(opts.manage_cgroups & CG_MODE_NONE) && - prepare_dir_perms(cg, paux, e->dir_perms) < 0) + if (!(opts.manage_cgroups & CG_MODE_NONE) && prepare_dir_perms(cg, paux, e->dir_perms) < 0) return -1; } - if (prepare_cgroup_dirs(controllers, n_controllers, paux, off2, - e->children, e->n_children) < 0) + if (prepare_cgroup_dirs(controllers, n_controllers, paux, off2, e->children, e->n_children) < 0) return -1; } @@ -1754,8 +1733,7 @@ static int prepare_cgroup_sfd(CgroupEntry *ce) if (!opts.manage_cgroups) return 0; - pr_info("Preparing cgroups yard (cgroups restore mode %#x)\n", - opts.manage_cgroups); + pr_info("Preparing cgroups yard (cgroups restore mode %#x)\n", opts.manage_cgroups); if (opts.cgroup_yard) { off = sprintf(paux, "%s", opts.cgroup_yard); @@ -1803,9 +1781,7 @@ static int prepare_cgroup_sfd(CgroupEntry *ce) return -1; } - ctl_off += ctrl_dir_and_opt(ctrl, - paux + ctl_off, sizeof(paux) - ctl_off, - opt, sizeof(opt)); + ctl_off += ctrl_dir_and_opt(ctrl, paux + ctl_off, sizeof(paux) - ctl_off, opt, sizeof(opt)); /* Create controller if not yet present */ if (access(paux, F_OK)) { @@ -1831,16 +1807,14 @@ static int prepare_cgroup_sfd(CgroupEntry *ce) yard = paux + strlen(cg_yard) + 1; yard_off = ctl_off - (strlen(cg_yard) + 1); if (opts.manage_cgroups && - prepare_cgroup_dirs(ctrl->cnames, ctrl->n_cnames, yard, yard_off, - ctrl->dirs, ctrl->n_dirs)) + prepare_cgroup_dirs(ctrl->cnames, ctrl->n_cnames, yard, yard_off, ctrl->dirs, ctrl->n_dirs)) return -1; } return 0; } -static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controllers, - char **dir_name, char *newroot) +static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controllers, char **dir_name, char *newroot) { size_t dirlen = strlen(*dir_name); char *dir = *dir_name; @@ -1877,7 +1851,7 @@ static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controller * "/" is matching to be renamed. */ if (!(cgroup_contains(controllers, n_controllers, cg->name, NULL) && - strstartswith(cg->path + 1, dir))) + strstartswith(cg->path + 1, dir))) continue; if (cg->has_cgns_prefix && cg->cgns_prefix) { @@ -1905,8 +1879,7 @@ static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controller * root but make sure the rest of path is * untouched. */ - cg->path = xsprintf("%s%s", newroot, - cg->path + dirlen + 1); + cg->path = xsprintf("%s%s", newroot, cg->path + dirlen + 1); if (!cg->path) { cg->path = prev; xfree(dirnew); @@ -1943,12 +1916,10 @@ static int rewrite_cgroup_roots(CgroupEntry *cge) unsigned old_mask = ctrl_mask; /* coverity[check_return] */ - cgroup_contains(ctrl->cnames, ctrl->n_cnames, - o->controller, &ctrl_mask); + cgroup_contains(ctrl->cnames, ctrl->n_cnames, o->controller, &ctrl_mask); if (old_mask != ctrl_mask) { if (newroot && strcmp(newroot, o->newroot)) { - pr_err("CG paths mismatch: %s %s\n", - newroot, o->newroot); + pr_err("CG paths mismatch: %s %s\n", newroot, o->newroot); return -1; } newroot = o->newroot; diff --git a/criu/clone-noasan.c b/criu/clone-noasan.c index 35c40c21d..d657ea2e8 100644 --- a/criu/clone-noasan.c +++ b/criu/clone-noasan.c @@ -46,8 +46,7 @@ int clone_noasan(int (*fn)(void *), int flags, void *arg) return clone(fn, stack_ptr, flags, arg); } -int clone3_with_pid_noasan(int (*fn)(void *), void *arg, int flags, - int exit_signal, pid_t pid) +int clone3_with_pid_noasan(int (*fn)(void *), void *arg, int flags, int exit_signal, pid_t pid) { struct _clone_args c_args = {}; diff --git a/criu/config.c b/criu/config.c index 4c7fcab0a..4561c3d70 100644 --- a/criu/config.c +++ b/criu/config.c @@ -131,7 +131,7 @@ int parse_statement(int i, char *line, char **configuration) /* We got "" as value */ configuration[i] = xstrdup(""); if (unlikely(!configuration[i])) { - xfree(configuration[i -1]); + xfree(configuration[i - 1]); return -1; } offset = 0; @@ -152,7 +152,7 @@ int parse_statement(int i, char *line, char **configuration) found_second_quote = true; configuration[i] = xzalloc(quote_offset - offset + 1); if (unlikely(!configuration[i])) { - xfree(configuration[i -1]); + xfree(configuration[i - 1]); return -1; } memcpy(configuration[i], quote_start, quote_offset - offset); @@ -185,7 +185,7 @@ int parse_statement(int i, char *line, char **configuration) } else { /* Does not start with a quote. */ if (unlikely(asprintf(&configuration[i], "%s", input + offset) == -1)) { - xfree(configuration[i -1]); + xfree(configuration[i - 1]); return -1; } @@ -249,10 +249,10 @@ out: } /* Parse a configuration file */ -static char ** parse_config(char *filepath) +static char **parse_config(char *filepath) { -#define DEFAULT_CONFIG_SIZE 10 - FILE* configfile = fopen(filepath, "r"); +#define DEFAULT_CONFIG_SIZE 10 + FILE *configfile = fopen(filepath, "r"); int config_size = DEFAULT_CONFIG_SIZE; int i = 1; size_t line_size = 0; @@ -315,8 +315,7 @@ static char ** parse_config(char *filepath) return configuration; } -static int next_config(char **argv, char ***_argv, bool no_default_config, - int state, char *cfg_file) +static int next_config(char **argv, char ***_argv, bool no_default_config, int state, char *cfg_file) { char local_filepath[PATH_MAX + 1]; char *home_dir = NULL; @@ -325,52 +324,51 @@ static int next_config(char **argv, char ***_argv, bool no_default_config, if (state >= PARSING_LAST) return 0; - switch(state) { - case PARSING_GLOBAL_CONF: - if (no_default_config) - break; - *_argv = parse_config(GLOBAL_CONFIG_DIR DEFAULT_CONFIG_FILENAME); - break; - case PARSING_USER_CONF: - if (no_default_config) - break; - home_dir = getenv("HOME"); - if (!home_dir) { - pr_info("Unable to get $HOME directory, local configuration file will not be used.\n"); - } else { - snprintf(local_filepath, PATH_MAX, "%s/%s%s", - home_dir, USER_CONFIG_DIR, DEFAULT_CONFIG_FILENAME); - *_argv = parse_config(local_filepath); - } - break; - case PARSING_ENV_CONF: - cfg_from_env = getenv("CRIU_CONFIG_FILE"); - if (!cfg_from_env) - break; - *_argv = parse_config(cfg_from_env); - break; - case PARSING_CMDLINE_CONF: - if (!cfg_file) - break; - *_argv = parse_config(cfg_file); - break; - case PARSING_ARGV: - *_argv = argv; - break; - case PARSING_RPC_CONF: - if (!rpc_cfg_file) - break; - *_argv = parse_config(rpc_cfg_file); - break; - default: - break; + switch (state) { + case PARSING_GLOBAL_CONF: + if (no_default_config) + break; + *_argv = parse_config(GLOBAL_CONFIG_DIR DEFAULT_CONFIG_FILENAME); + break; + case PARSING_USER_CONF: + if (no_default_config) + break; + home_dir = getenv("HOME"); + if (!home_dir) { + pr_info("Unable to get $HOME directory, local configuration file will not be used.\n"); + } else { + snprintf(local_filepath, PATH_MAX, "%s/%s%s", home_dir, USER_CONFIG_DIR, + DEFAULT_CONFIG_FILENAME); + *_argv = parse_config(local_filepath); + } + break; + case PARSING_ENV_CONF: + cfg_from_env = getenv("CRIU_CONFIG_FILE"); + if (!cfg_from_env) + break; + *_argv = parse_config(cfg_from_env); + break; + case PARSING_CMDLINE_CONF: + if (!cfg_file) + break; + *_argv = parse_config(cfg_file); + break; + case PARSING_ARGV: + *_argv = argv; + break; + case PARSING_RPC_CONF: + if (!rpc_cfg_file) + break; + *_argv = parse_config(rpc_cfg_file); + break; + default: + break; } return ++state; } -static int pre_parse(int argc, char **argv, bool *usage_error, bool *no_default_config, - char **cfg_file) +static int pre_parse(int argc, char **argv, bool *usage_error, bool *no_default_config, char **cfg_file) { int i; /* @@ -447,12 +445,12 @@ static int parse_cpu_cap(struct cr_options *opts, const char *optarg) { bool inverse = false; -#define ____cpu_set_cap(__opts, __cap, __inverse) \ - do { \ - if ((__inverse)) \ - (__opts)->cpu_cap &= ~(__cap); \ - else \ - (__opts)->cpu_cap |= (__cap); \ +#define ____cpu_set_cap(__opts, __cap, __inverse) \ + do { \ + if ((__inverse)) \ + (__opts)->cpu_cap &= ~(__cap); \ + else \ + (__opts)->cpu_cap |= (__cap); \ } while (0) if (!optarg) { @@ -594,8 +592,7 @@ Esyntax: * correct, '1' if something failed and '2' if the CRIU help text should * be displayed. */ -int parse_options(int argc, char **argv, bool *usage_error, - bool *has_exec_cmd, int state) +int parse_options(int argc, char **argv, bool *usage_error, bool *has_exec_cmd, int state) { int ret; int opt = -1; @@ -605,99 +602,99 @@ int parse_options(int argc, char **argv, bool *usage_error, char **_argv = NULL; int _argc = 0; - -#define BOOL_OPT(OPT_NAME, SAVE_TO) \ - {OPT_NAME, no_argument, SAVE_TO, true},\ - {"no-" OPT_NAME, no_argument, SAVE_TO, false} +#define BOOL_OPT(OPT_NAME, SAVE_TO) \ + { OPT_NAME, no_argument, SAVE_TO, true }, \ + { \ + "no-" OPT_NAME, no_argument, SAVE_TO, false \ + } static const char short_opts[] = "dSsRt:hD:o:v::x::Vr:jJ:lW:L:M:"; static struct option long_opts[] = { - { "tree", required_argument, 0, 't' }, - { "leave-stopped", no_argument, 0, 's' }, - { "leave-running", no_argument, 0, 'R' }, + { "tree", required_argument, 0, 't' }, + { "leave-stopped", no_argument, 0, 's' }, + { "leave-running", no_argument, 0, 'R' }, BOOL_OPT("restore-detached", &opts.restore_detach), BOOL_OPT("restore-sibling", &opts.restore_sibling), BOOL_OPT("daemon", &opts.restore_detach), - { "images-dir", required_argument, 0, 'D' }, - { "work-dir", required_argument, 0, 'W' }, - { "log-file", required_argument, 0, 'o' }, - { "join-ns", required_argument, 0, 'J' }, - { "root", required_argument, 0, 'r' }, - { USK_EXT_PARAM, optional_argument, 0, 'x' }, - { "help", no_argument, 0, 'h' }, + { "images-dir", required_argument, 0, 'D' }, + { "work-dir", required_argument, 0, 'W' }, + { "log-file", required_argument, 0, 'o' }, + { "join-ns", required_argument, 0, 'J' }, + { "root", required_argument, 0, 'r' }, + { USK_EXT_PARAM, optional_argument, 0, 'x' }, + { "help", no_argument, 0, 'h' }, BOOL_OPT(SK_EST_PARAM, &opts.tcp_established_ok), - { "close", required_argument, 0, 1043 }, + { "close", required_argument, 0, 1043 }, BOOL_OPT("log-pid", &opts.log_file_per_pid), - { "version", no_argument, 0, 'V' }, + { "version", no_argument, 0, 'V' }, BOOL_OPT("evasive-devices", &opts.evasive_devices), - { "pidfile", required_argument, 0, 1046 }, - { "veth-pair", required_argument, 0, 1047 }, - { "action-script", required_argument, 0, 1049 }, + { "pidfile", required_argument, 0, 1046 }, + { "veth-pair", required_argument, 0, 1047 }, + { "action-script", required_argument, 0, 1049 }, BOOL_OPT(LREMAP_PARAM, &opts.link_remap_ok), BOOL_OPT(OPT_SHELL_JOB, &opts.shell_job), BOOL_OPT(OPT_FILE_LOCKS, &opts.handle_file_locks), BOOL_OPT("page-server", &opts.use_page_server), - { "address", required_argument, 0, 1051 }, - { "port", required_argument, 0, 1052 }, - { "prev-images-dir", required_argument, 0, 1053 }, - { "ms", no_argument, 0, 1054 }, + { "address", required_argument, 0, 1051 }, + { "port", required_argument, 0, 1052 }, + { "prev-images-dir", required_argument, 0, 1053 }, + { "ms", no_argument, 0, 1054 }, BOOL_OPT("track-mem", &opts.track_mem), BOOL_OPT("auto-dedup", &opts.auto_dedup), - { "libdir", required_argument, 0, 'L' }, - { "cpu-cap", optional_argument, 0, 1057 }, + { "libdir", required_argument, 0, 'L' }, + { "cpu-cap", optional_argument, 0, 1057 }, BOOL_OPT("force-irmap", &opts.force_irmap), - { "ext-mount-map", required_argument, 0, 'M' }, - { "exec-cmd", no_argument, 0, 1059 }, - { "manage-cgroups", optional_argument, 0, 1060 }, - { "cgroup-root", required_argument, 0, 1061 }, - { "inherit-fd", required_argument, 0, 1062 }, - { "feature", required_argument, 0, 1063 }, - { "skip-mnt", required_argument, 0, 1064 }, - { "enable-fs", required_argument, 0, 1065 }, - { "enable-external-sharing", no_argument, &opts.enable_external_sharing, true }, - { "enable-external-masters", no_argument, &opts.enable_external_masters, true }, - { "freeze-cgroup", required_argument, 0, 1068 }, - { "ghost-limit", required_argument, 0, 1069 }, - { "irmap-scan-path", required_argument, 0, 1070 }, - { "lsm-profile", required_argument, 0, 1071 }, - { "timeout", required_argument, 0, 1072 }, - { "external", required_argument, 0, 1073 }, - { "empty-ns", required_argument, 0, 1074 }, - { "lazy-pages", no_argument, 0, 1076 }, + { "ext-mount-map", required_argument, 0, 'M' }, + { "exec-cmd", no_argument, 0, 1059 }, + { "manage-cgroups", optional_argument, 0, 1060 }, + { "cgroup-root", required_argument, 0, 1061 }, + { "inherit-fd", required_argument, 0, 1062 }, + { "feature", required_argument, 0, 1063 }, + { "skip-mnt", required_argument, 0, 1064 }, + { "enable-fs", required_argument, 0, 1065 }, + { "enable-external-sharing", no_argument, &opts.enable_external_sharing, true }, + { "enable-external-masters", no_argument, &opts.enable_external_masters, true }, + { "freeze-cgroup", required_argument, 0, 1068 }, + { "ghost-limit", required_argument, 0, 1069 }, + { "irmap-scan-path", required_argument, 0, 1070 }, + { "lsm-profile", required_argument, 0, 1071 }, + { "timeout", required_argument, 0, 1072 }, + { "external", required_argument, 0, 1073 }, + { "empty-ns", required_argument, 0, 1074 }, + { "lazy-pages", no_argument, 0, 1076 }, BOOL_OPT("extra", &opts.check_extra_features), BOOL_OPT("experimental", &opts.check_experimental_features), - { "all", no_argument, 0, 1079 }, - { "cgroup-props", required_argument, 0, 1080 }, - { "cgroup-props-file", required_argument, 0, 1081 }, - { "cgroup-dump-controller", required_argument, 0, 1082 }, + { "all", no_argument, 0, 1079 }, + { "cgroup-props", required_argument, 0, 1080 }, + { "cgroup-props-file", required_argument, 0, 1081 }, + { "cgroup-dump-controller", required_argument, 0, 1082 }, BOOL_OPT(SK_INFLIGHT_PARAM, &opts.tcp_skip_in_flight), BOOL_OPT("deprecated", &opts.deprecated_ok), BOOL_OPT("display-stats", &opts.display_stats), BOOL_OPT("weak-sysctls", &opts.weak_sysctls), - { "status-fd", required_argument, 0, 1088 }, + { "status-fd", required_argument, 0, 1088 }, BOOL_OPT(SK_CLOSE_PARAM, &opts.tcp_close), - { "verbosity", optional_argument, 0, 'v' }, - { "ps-socket", required_argument, 0, 1091}, + { "verbosity", optional_argument, 0, 'v' }, + { "ps-socket", required_argument, 0, 1091 }, BOOL_OPT("stream", &opts.stream), - { "config", required_argument, 0, 1089}, - { "no-default-config", no_argument, 0, 1090}, - { "tls-cacert", required_argument, 0, 1092}, - { "tls-cacrl", required_argument, 0, 1093}, - { "tls-cert", required_argument, 0, 1094}, - { "tls-key", required_argument, 0, 1095}, + { "config", required_argument, 0, 1089 }, + { "no-default-config", no_argument, 0, 1090 }, + { "tls-cacert", required_argument, 0, 1092 }, + { "tls-cacrl", required_argument, 0, 1093 }, + { "tls-cert", required_argument, 0, 1094 }, + { "tls-key", required_argument, 0, 1095 }, BOOL_OPT("tls", &opts.tls), - {"tls-no-cn-verify", no_argument, &opts.tls_no_cn_verify, true}, - { "cgroup-yard", required_argument, 0, 1096 }, - { "pre-dump-mode", required_argument, 0, 1097}, - { "file-validation", required_argument, 0, 1098 }, - { "lsm-mount-context", required_argument, 0, 1099 }, - { }, + { "tls-no-cn-verify", no_argument, &opts.tls_no_cn_verify, true }, + { "cgroup-yard", required_argument, 0, 1096 }, + { "pre-dump-mode", required_argument, 0, 1097 }, + { "file-validation", required_argument, 0, 1098 }, + { "lsm-mount-context", required_argument, 0, 1099 }, + {}, }; #undef BOOL_OPT - ret = pre_parse(argc, argv, usage_error, &no_default_config, - &cfg_file); + ret = pre_parse(argc, argv, usage_error, &no_default_config, &cfg_file); if (ret) return 2; @@ -709,7 +706,7 @@ int parse_options(int argc, char **argv, bool *usage_error, /* Do not free any memory if it points to argv */ if (state != PARSING_ARGV + 1) { int i; - for (i=1; i < _argc; i++) { + for (i = 1; i < _argc; i++) { free(_argv[i]); } free(_argv); @@ -809,21 +806,19 @@ int parse_options(int argc, char **argv, bool *usage_error, case 1046: SET_CHAR_OPTS(pidfile, optarg); break; - case 1047: - { - char *aux; - - aux = strchr(optarg, '='); - if (aux == NULL) - goto bad_arg; - - *aux = '\0'; - if (veth_pair_add(optarg, aux + 1)) { - pr_err("Failed to add veth pair: %s, %s.\n", optarg, aux + 1); - return 1; - } + case 1047: { + char *aux; + + aux = strchr(optarg, '='); + if (aux == NULL) + goto bad_arg; + + *aux = '\0'; + if (veth_pair_add(optarg, aux + 1)) { + pr_err("Failed to add veth pair: %s, %s.\n", optarg, aux + 1); + return 1; } - break; + } break; case 1049: if (add_script(optarg)) { pr_err("Failed to add action-script: %s.\n", optarg); @@ -868,33 +863,31 @@ int parse_options(int argc, char **argv, bool *usage_error, if (parse_manage_cgroups(&opts, optarg)) return 2; break; - case 1061: - { - char *path, *ctl; - - path = strchr(optarg, ':'); - if (path) { - *path = '\0'; - path++; - ctl = optarg; - } else { - path = optarg; - ctl = NULL; - } + case 1061: { + char *path, *ctl; - if (new_cg_root_add(ctl, path)) - return -1; + path = strchr(optarg, ':'); + if (path) { + *path = '\0'; + path++; + ctl = optarg; + } else { + path = optarg; + ctl = NULL; } - break; + + if (new_cg_root_add(ctl, path)) + return -1; + } break; case 1062: if (inherit_fd_parse(optarg) < 0) return 1; break; case 1063: ret = check_add_feature(optarg); - if (ret < 0) /* invalid kernel feature name */ + if (ret < 0) /* invalid kernel feature name */ return 1; - if (ret > 0) /* list kernel features and exit */ + if (ret > 0) /* list kernel features and exit */ return 0; break; case 1064: @@ -931,26 +924,25 @@ int parse_options(int argc, char **argv, bool *usage_error, case 1076: opts.lazy_pages = true; break; - case 'M': - { - char *aux; + case 'M': { + char *aux; - if (strcmp(optarg, "auto") == 0) { - opts.autodetect_ext_mounts = true; - break; - } + if (strcmp(optarg, "auto") == 0) { + opts.autodetect_ext_mounts = true; + break; + } - aux = strchr(optarg, ':'); - if (aux == NULL) - goto bad_arg; + aux = strchr(optarg, ':'); + if (aux == NULL) + goto bad_arg; - *aux = '\0'; - if (ext_mount_add(optarg, aux + 1)) { - pr_err("Could not add external mount when initializing config: %s, %s\n", optarg, aux + 1); - return 1; - } + *aux = '\0'; + if (ext_mount_add(optarg, aux + 1)) { + pr_err("Could not add external mount when initializing config: %s, %s\n", optarg, + aux + 1); + return 1; } - break; + } break; case 1073: if (add_external(optarg)) { pr_err("Could not add external resource when initializing config: %s\n", optarg); @@ -961,8 +953,7 @@ int parse_options(int argc, char **argv, bool *usage_error, if (!strcmp("net", optarg)) opts.empty_ns |= CLONE_NEWNET; else { - pr_err("Unsupported empty namespace: %s\n", - optarg); + pr_err("Unsupported empty namespace: %s\n", optarg); return 1; } break; @@ -1040,11 +1031,9 @@ int parse_options(int argc, char **argv, bool *usage_error, bad_arg: if (idx < 0) /* short option */ - pr_err("invalid argument for -%c: %s\n", - opt, optarg); + pr_err("invalid argument for -%c: %s\n", opt, optarg); else /* long option */ - pr_err("invalid argument for --%s: %s\n", - long_opts[idx].name, optarg); + pr_err("invalid argument for --%s: %s\n", long_opts[idx].name, optarg); return 1; } @@ -1079,7 +1068,7 @@ int check_options(void) "combination with --ps-socket is obsolete\n"); if (opts.ps_socket <= STDERR_FILENO && opts.daemon_mode) { pr_err("Standard file descriptors will be closed" - " in daemon mode\n"); + " in daemon mode\n"); return 1; } } diff --git a/criu/cr-check.c b/criu/cr-check.c index d35b1bffe..6583b6ea0 100644 --- a/criu/cr-check.c +++ b/criu/cr-check.c @@ -63,9 +63,8 @@ static int check_tty(void) if (ARRAY_SIZE(t.c_cc) < TERMIOS_NCC) { pr_err("struct termios has %d @c_cc while " - "at least %d expected.\n", - (int)ARRAY_SIZE(t.c_cc), - TERMIOS_NCC); + "at least %d expected.\n", + (int)ARRAY_SIZE(t.c_cc), TERMIOS_NCC); goto out; } @@ -293,8 +292,7 @@ static int check_fdinfo_eventfd(void) } if (fe.counter != cnt) { - pr_err("Counter mismatch (or not met) %d want %d\n", - (int)fe.counter, cnt); + pr_err("Counter mismatch (or not met) %d want %d\n", (int)fe.counter, cnt); return -1; } @@ -468,7 +466,7 @@ err: } #ifndef SO_GET_FILTER -#define SO_GET_FILTER SO_ATTACH_FILTER +#define SO_GET_FILTER SO_ATTACH_FILTER #endif static int check_so_gets(void) @@ -612,9 +610,9 @@ static int check_ptrace_peeksiginfo(void) } struct special_mapping { - const char *name; - void *addr; - size_t size; + const char *name; + void *addr; + size_t size; }; static int parse_special_maps(struct special_mapping *vmas, size_t nr) @@ -632,8 +630,7 @@ static int parse_special_maps(struct special_mapping *vmas, size_t nr) int r, tail; size_t i; - r = sscanf(buf, "%lx-%lx %*s %*s %*s %*s %n\n", - &start, &end, &tail); + r = sscanf(buf, "%lx-%lx %*s %*s %*s %*s %n\n", &start, &end, &tail); if (r != 2) { fclose(maps); pr_err("Bad maps format %d.%d (%s)\n", r, tail, buf + tail); @@ -674,8 +671,7 @@ static void dummy_sighandler(int sig) * And we definitely mremap() support by the fact that those special_mappings * are subjects for ASLR. (See #288 as a reference) */ -static void check_special_mapping_mremap_child(struct special_mapping *vmas, - size_t nr) +static void check_special_mapping_mremap_child(struct special_mapping *vmas, size_t nr) { size_t i, parking_size = 0; void *parking_lot; @@ -691,8 +687,7 @@ static void check_special_mapping_mremap_child(struct special_mapping *vmas, exit(1); } - parking_lot = mmap(NULL, parking_size, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + parking_lot = mmap(NULL, parking_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (parking_lot == MAP_FAILED) { pr_perror("mmap(%zu) failed", parking_size); exit(1); @@ -704,10 +699,8 @@ static void check_special_mapping_mremap_child(struct special_mapping *vmas, if (vmas[i].addr == MAP_FAILED) continue; - ret = syscall(__NR_mremap, (unsigned long)vmas[i].addr, - vmas[i].size, vmas[i].size, - MREMAP_FIXED | MREMAP_MAYMOVE, - (unsigned long)parking_lot); + ret = syscall(__NR_mremap, (unsigned long)vmas[i].addr, vmas[i].size, vmas[i].size, + MREMAP_FIXED | MREMAP_MAYMOVE, (unsigned long)parking_lot); if (ret != (unsigned long)parking_lot) syscall(__NR_exit, 1); parking_lot += vmas[i].size; @@ -807,19 +800,19 @@ static int check_ptrace_suspend_seccomp(void) static int setup_seccomp_filter(void) { struct sock_filter filter[] = { - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, nr)), /* Allow all syscalls except ptrace */ - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_ptrace, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __NR_ptrace, 0, 1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_KILL), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), }; struct sock_fprog bpf_prog = { - .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), + .len = (unsigned short)(sizeof(filter) / sizeof(filter[0])), .filter = filter, }; - if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long) &bpf_prog, 0, 0) < 0) + if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long)&bpf_prog, 0, 0) < 0) return -1; return 0; @@ -912,7 +905,7 @@ static int check_aio_remap(void) return -1; } - len = get_ring_len((unsigned long) ctx); + len = get_ring_len((unsigned long)ctx); if (!len) return -1; @@ -956,7 +949,8 @@ struct clone_arg { char stack_ptr[0]; }; -static int clone_cb(void *_arg) { +static int clone_cb(void *_arg) +{ exit(0); } @@ -1016,8 +1010,7 @@ static int check_autofs(void) ret = -1; - options = xsprintf("fd=%d,pgrp=%d,minproto=5,maxproto=5,direct", - pfd[1], getpgrp()); + options = xsprintf("fd=%d,pgrp=%d,minproto=5,maxproto=5,direct", pfd[1], getpgrp()); if (!options) { pr_err("failed to allocate autofs options\n"); goto close_pipe; @@ -1129,7 +1122,7 @@ static int kerndat_tcp_repair_window(void) pr_perror("Unable to set TCP_REPAIR_WINDOW"); goto err; } -now: + now: val = 0; } else val = 1; @@ -1327,8 +1320,8 @@ static int check_newifindex(void) static int check_net_diag_raw(void) { check_sock_diag(); - return (socket_test_collect_bit(AF_INET, IPPROTO_RAW) && - socket_test_collect_bit(AF_INET6, IPPROTO_RAW)) ? 0 : -1; + return (socket_test_collect_bit(AF_INET, IPPROTO_RAW) && socket_test_collect_bit(AF_INET6, IPPROTO_RAW)) ? 0 : + -1; } static int check_pidfd_store(void) @@ -1371,17 +1364,19 @@ static int (*chk_feature)(void); * We fail if any feature in category 1 is missing but tolerate failures * in the other categories. Currently, there is nothing in category 3. */ -#define CHECK_GOOD "Looks good." -#define CHECK_BAD "Does not look good." -#define CHECK_MAYBE "Looks good but some kernel features are missing\n" \ - "which, depending on your process tree, may cause\n" \ - "dump or restore failure." -#define CHECK_CAT1(fn) do { \ - if ((ret = fn) != 0) { \ - pr_warn("%s\n", CHECK_BAD); \ - return ret; \ - } \ - } while (0) +#define CHECK_GOOD "Looks good." +#define CHECK_BAD "Does not look good." +#define CHECK_MAYBE \ + "Looks good but some kernel features are missing\n" \ + "which, depending on your process tree, may cause\n" \ + "dump or restore failure." +#define CHECK_CAT1(fn) \ + do { \ + if ((ret = fn) != 0) { \ + pr_warn("%s\n", CHECK_BAD); \ + return ret; \ + } \ + } while (0) int cr_check(void) { struct ns_id *ns; @@ -1566,17 +1561,17 @@ static struct feature_list feature_list[] = { { "compat_cr", check_compat_cr }, { "uffd", check_uffd }, { "uffd-noncoop", check_uffd_noncoop }, - { "can_map_vdso", check_can_map_vdso}, + { "can_map_vdso", check_can_map_vdso }, { "sk_ns", check_sk_netns }, { "sk_unix_file", check_sk_unix_file }, { "net_diag_raw", check_net_diag_raw }, { "nsid", check_nsid }, - { "link_nsid", check_link_nsid}, - { "kcmp_epoll", check_kcmp_epoll}, - { "timens", check_time_namespace}, - { "external_net_ns", check_external_net_ns}, - { "clone3_set_tid", check_clone3_set_tid}, - { "newifindex", check_newifindex}, + { "link_nsid", check_link_nsid }, + { "kcmp_epoll", check_kcmp_epoll }, + { "timens", check_time_namespace }, + { "external_net_ns", check_external_net_ns }, + { "clone3_set_tid", check_clone3_set_tid }, + { "newifindex", check_newifindex }, { "nftables", check_nftables_cr }, { "has_ipt_legacy", check_ipt_legacy }, { "pidfd_store", check_pidfd_store }, diff --git a/criu/cr-dedup.c b/criu/cr-dedup.c index a09873f94..c0c21f53e 100644 --- a/criu/cr-dedup.c +++ b/criu/cr-dedup.c @@ -14,7 +14,7 @@ int cr_dedup(void) { int close_ret, ret = 0; unsigned long img_id; - DIR * dirp; + DIR *dirp; struct dirent *ent; dirp = opendir(CR_PARENT_LINK); @@ -71,7 +71,7 @@ static int cr_dedup_one_pagemap(unsigned long img_id, int flags) { int ret; struct page_read pr; - struct page_read * prp; + struct page_read *prp; flags |= PR_MOD; ret = open_page_read(img_id, &pr, flags); @@ -87,11 +87,9 @@ static int cr_dedup_one_pagemap(unsigned long img_id, int flags) if (ret <= 0) goto exit; - pr_debug("dedup iovec base=%"PRIx64", len=%lu\n", - pr.pe->vaddr, pagemap_len(pr.pe)); + pr_debug("dedup iovec base=%" PRIx64 ", len=%lu\n", pr.pe->vaddr, pagemap_len(pr.pe)); if (!pagemap_in_parent(pr.pe)) { - ret = dedup_one_iovec(prp, pr.pe->vaddr, - pagemap_len(pr.pe)); + ret = dedup_one_iovec(prp, pr.pe->vaddr, pagemap_len(pr.pe)); if (ret) goto exit; } diff --git a/criu/cr-dump.c b/criu/cr-dump.c index eece51cff..54a426cc1 100644 --- a/criu/cr-dump.c +++ b/criu/cr-dump.c @@ -15,7 +15,6 @@ #include <sys/time.h> #include <sys/wait.h> - #include <sched.h> #include <sys/resource.h> @@ -93,13 +92,12 @@ * with_threads = true : The register sets of the tasks with all their threads * are restored */ -int __attribute__((weak)) arch_set_thread_regs(struct pstree_item *item, - bool with_threads) +int __attribute__((weak)) arch_set_thread_regs(struct pstree_item *item, bool with_threads) { return 0; } -#define PERSONALITY_LENGTH 9 +#define PERSONALITY_LENGTH 9 static char loc_buf[PERSONALITY_LENGTH]; void free_mappings(struct vm_area_list *vma_area_list) @@ -115,8 +113,7 @@ void free_mappings(struct vm_area_list *vma_area_list) vm_area_list_init(vma_area_list); } -int collect_mappings(pid_t pid, struct vm_area_list *vma_area_list, - dump_filemap_t dump_file) +int collect_mappings(pid_t pid, struct vm_area_list *vma_area_list, dump_filemap_t dump_file) { int ret = -1; @@ -128,8 +125,7 @@ int collect_mappings(pid_t pid, struct vm_area_list *vma_area_list, if (ret < 0) goto err; - pr_info("Collected, longest area occupies %lu pages\n", - vma_area_list->nr_priv_pages_longest); + pr_info("Collected, longest area occupies %lu pages\n", vma_area_list->nr_priv_pages_longest); pr_info_vma_list(&vma_area_list->h); pr_info("----------------------------------------\n"); @@ -325,8 +321,7 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_im close(fd); - pr_info("Dumping task cwd id %#x root id %#x\n", - fe.cwd_id, fe.root_id); + pr_info("Dumping task cwd id %#x root id %#x\n", fe.cwd_id, fe.root_id); return pb_write_one(img_from_set(imgset, CR_FD_FS), &fe, PB_FS); } @@ -340,7 +335,7 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls) { int res; - for (res = 0; res <rls->n_rlimits ; res++) { + for (res = 0; res < rls->n_rlimits; res++) { struct rlimit64 lim; if (syscall(__NR_prlimit64, pid, res, NULL, &lim)) { @@ -412,8 +407,7 @@ static int dump_filemap(struct vma_area *vma_area, int fd) if (vma_area->aufs_rpath) { struct fd_link aufs_link; - strlcpy(aufs_link.name, vma_area->aufs_rpath, - sizeof(aufs_link.name)); + strlcpy(aufs_link.name, vma_area->aufs_rpath, sizeof(aufs_link.name)); aufs_link.len = strlen(aufs_link.name); p.link = &aufs_link; } @@ -434,8 +428,7 @@ static int check_sysvipc_map_dump(pid_t pid, VmaEntry *vma) if (root_ns_mask & CLONE_NEWIPC) return 0; - pr_err("Task %d with SysVIPC shmem map @%"PRIx64" doesn't live in IPC ns\n", - pid, vma->start); + pr_err("Task %d with SysVIPC shmem map @%" PRIx64 " doesn't live in IPC ns\n", pid, vma->start); return -1; } @@ -467,10 +460,8 @@ err: return ret; } -static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat, - const struct parasite_dump_misc *misc, - const struct vm_area_list *vma_area_list, - const struct cr_imgset *imgset) +static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat, const struct parasite_dump_misc *misc, + const struct vm_area_list *vma_area_list, const struct cr_imgset *imgset) { MmEntry mme = MM_ENTRY__INIT; struct vma_area *vma_area; @@ -578,8 +569,8 @@ static int get_task_futex_robust_list(pid_t pid, ThreadCoreEntry *info) goto err; } - info->futex_rla = encode_pointer(head); - info->futex_rla_len = (u32)len; + info->futex_rla = encode_pointer(head); + info->futex_rla_len = (u32)len; return 0; @@ -713,8 +704,7 @@ int dump_thread_core(int pid, CoreEntry *core, const struct parasite_dump_thread ret = dump_sched_info(pid, tc); if (!ret) { core_put_tls(core, ti->tls); - CORE_THREAD_ARCH_INFO(core)->clear_tid_addr = - encode_pointer(ti->tid_addr); + CORE_THREAD_ARCH_INFO(core)->clear_tid_addr = encode_pointer(ti->tid_addr); BUG_ON(!tc->sas); copy_sas(tc->sas, &ti->sas); if (ti->pdeath_sig) { @@ -731,11 +721,8 @@ int dump_thread_core(int pid, CoreEntry *core, const struct parasite_dump_thread return ret; } -static int dump_task_core_all(struct parasite_ctl *ctl, - struct pstree_item *item, - const struct proc_pid_stat *stat, - const struct cr_imgset *cr_imgset, - const struct parasite_dump_misc *misc) +static int dump_task_core_all(struct parasite_ctl *ctl, struct pstree_item *item, const struct proc_pid_stat *stat, + const struct cr_imgset *cr_imgset, const struct parasite_dump_misc *misc) { struct cr_img *img; CoreEntry *core = item->core[0]; @@ -805,7 +792,9 @@ static int collect_pstree_ids_predump(void) struct { struct pstree_item i; struct dmp_info d; - } crt = { .i.pid = &pid, }; + } crt = { + .i.pid = &pid, + }; /* * This thing is normally done inside @@ -845,8 +834,7 @@ static int collect_file_locks(void) return parse_file_locks(); } -static int dump_task_thread(struct parasite_ctl *parasite_ctl, - const struct pstree_item *item, int id) +static int dump_task_thread(struct parasite_ctl *parasite_ctl, const struct pstree_item *item, int id) { struct parasite_thread_ctl *tctl = dmpi(item)->thread_ctls[id]; struct pid *tid = &item->threads[id]; @@ -878,8 +866,7 @@ err: return ret; } -static int dump_one_zombie(const struct pstree_item *item, - const struct proc_pid_stat *pps) +static int dump_one_zombie(const struct pstree_item *item, const struct proc_pid_stat *pps) { CoreEntry *core; int ret = -1; @@ -904,7 +891,7 @@ err: return ret; } -#define SI_BATCH 32 +#define SI_BATCH 32 static int dump_signal_queue(pid_t tid, SignalQueueEntry **sqe, bool group) { @@ -961,8 +948,7 @@ static int dump_signal_queue(pid_t tid, SignalQueueEntry **sqe, bool group) break; } - for (si_pos = queue->n_signals - nr; - si_pos < queue->n_signals; si_pos++) { + for (si_pos = queue->n_signals - nr; si_pos < queue->n_signals; si_pos++) { SiginfoEntry *se; se = xmalloc(sizeof(*se)); @@ -1014,8 +1000,7 @@ static int dump_task_signals(pid_t pid, struct pstree_item *item) static struct proc_pid_stat pps_buf; -static int dump_task_threads(struct parasite_ctl *parasite_ctl, - const struct pstree_item *item) +static int dump_task_threads(struct parasite_ctl *parasite_ctl, const struct pstree_item *item) { int i; @@ -1348,12 +1333,10 @@ static int dump_one_task(struct pstree_item *item, InventoryEntry *parent_ie) item->sid = misc.sid; item->pgid = misc.pgid; - pr_info("sid=%d pgid=%d pid=%d\n", - item->sid, item->pgid, vpid(item)); + pr_info("sid=%d pgid=%d pid=%d\n", item->sid, item->pgid, vpid(item)); if (item->sid == 0) { - pr_err("A session leader of %d(%d) is outside of its pid namespace\n", - item->pid->real, vpid(item)); + pr_err("A session leader of %d(%d) is outside of its pid namespace\n", item->pid->real, vpid(item)); goto err_cure; } @@ -1469,13 +1452,13 @@ err_cure_imgset: static int alarm_attempts = 0; -bool alarm_timeouted(void) { +bool alarm_timeouted(void) +{ return alarm_attempts > 0; } static void alarm_handler(int signo) { - pr_err("Timeout reached. Try to interrupt: %d\n", alarm_attempts); if (alarm_attempts++ < 5) { alarm(1); @@ -1489,8 +1472,7 @@ static void alarm_handler(int signo) static int setup_alarm_handler(void) { struct sigaction sa = { - .sa_handler = alarm_handler, - .sa_flags = 0, /* Don't restart syscalls */ + .sa_handler = alarm_handler, .sa_flags = 0, /* Don't restart syscalls */ }; sigemptyset(&sa.sa_mask); @@ -1552,8 +1534,7 @@ static int cr_pre_dump_finish(int status) if (opts.pre_dump_mode == PRE_DUMP_READ) { timing_stop(TIME_MEMWRITE); - ret = page_xfer_predump_pages(item->pid->real, - &xfer, mem_pp); + ret = page_xfer_predump_pages(item->pid->real, &xfer, mem_pp); } else { ret = page_xfer_dump_pages(&xfer, mem_pp); } @@ -1772,9 +1753,7 @@ static int cr_dump_finish(int ret) if (arch_set_thread_regs(root_item, true) < 0) return -1; - pstree_switch_state(root_item, - (ret || post_dump_ret) ? - TASK_ALIVE : opts.final_state); + pstree_switch_state(root_item, (ret || post_dump_ret) ? TASK_ALIVE : opts.final_state); timing_stop(TIME_FROZEN); free_pstree(root_item); seccomp_free_entries(); @@ -1792,7 +1771,7 @@ static int cr_dump_finish(int ret) write_stats(DUMP_STATS); pr_info("Dumping finished successfully\n"); } - return post_dump_ret ? : (ret != 0); + return post_dump_ret ?: (ret != 0); } int cr_dump_tasks(pid_t pid) @@ -1842,10 +1821,7 @@ int cr_dump_tasks(pid_t pid) if (vdso_init_dump()) goto err; - if (cgp_init(opts.cgroup_props, - opts.cgroup_props ? - strlen(opts.cgroup_props) : 0, - opts.cgroup_props_file)) + if (cgp_init(opts.cgroup_props, opts.cgroup_props ? strlen(opts.cgroup_props) : 0, opts.cgroup_props_file)) goto err; if (parse_cg_info()) diff --git a/criu/cr-restore.c b/criu/cr-restore.c index 93765966c..82dbaa0dc 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -18,7 +18,6 @@ #include <sys/prctl.h> #include <sched.h> - #include "types.h" #include <compel/ptrace.h> #include "common/compiler.h" @@ -98,16 +97,16 @@ #include "cr-errno.h" #ifndef arch_export_restore_thread -#define arch_export_restore_thread __export_restore_thread +#define arch_export_restore_thread __export_restore_thread #endif #ifndef arch_export_restore_task -#define arch_export_restore_task __export_restore_task +#define arch_export_restore_task __export_restore_task #endif #ifndef arch_export_unmap -#define arch_export_unmap __export_unmap -#define arch_export_unmap_compat __export_unmap_compat +#define arch_export_unmap __export_unmap +#define arch_export_unmap_compat __export_unmap_compat #endif struct pstree_item *current; @@ -202,16 +201,14 @@ static int restore_wait_other_tasks(void) static inline void __restore_switch_stage_nw(int next_stage) { - futex_set(&task_entries->nr_in_progress, - stage_participants(next_stage)); + futex_set(&task_entries->nr_in_progress, stage_participants(next_stage)); futex_set(&task_entries->start, next_stage); } static inline void __restore_switch_stage(int next_stage) { if (next_stage != CR_STATE_COMPLETE) - futex_set(&task_entries->nr_in_progress, - stage_participants(next_stage)); + futex_set(&task_entries->nr_in_progress, stage_participants(next_stage)); futex_set_and_wake(&task_entries->start, next_stage); } @@ -266,34 +263,17 @@ static int crtools_prepare_shared(void) */ static struct collect_image_info *cinfos[] = { - &file_locks_cinfo, - &pipe_data_cinfo, - &fifo_data_cinfo, - &sk_queues_cinfo, + &file_locks_cinfo, &pipe_data_cinfo, &fifo_data_cinfo, &sk_queues_cinfo, #ifdef CONFIG_HAS_LIBBPF &bpfmap_data_cinfo, #endif }; static struct collect_image_info *cinfos_files[] = { - &unix_sk_cinfo, - &fifo_cinfo, - &pipe_cinfo, - &nsfile_cinfo, - &packet_sk_cinfo, - &netlink_sk_cinfo, - &eventfd_cinfo, - &epoll_cinfo, - &epoll_tfd_cinfo, - &signalfd_cinfo, - &tunfile_cinfo, - &timerfd_cinfo, - &inotify_cinfo, - &inotify_mark_cinfo, - &fanotify_cinfo, - &fanotify_mark_cinfo, - &ext_file_cinfo, - &memfd_cinfo, + &unix_sk_cinfo, &fifo_cinfo, &pipe_cinfo, &nsfile_cinfo, &packet_sk_cinfo, + &netlink_sk_cinfo, &eventfd_cinfo, &epoll_cinfo, &epoll_tfd_cinfo, &signalfd_cinfo, + &tunfile_cinfo, &timerfd_cinfo, &inotify_cinfo, &inotify_mark_cinfo, &fanotify_cinfo, + &fanotify_mark_cinfo, &ext_file_cinfo, &memfd_cinfo, }; /* These images are required to restore namespaces */ @@ -337,8 +317,7 @@ static int root_prepare_shared(void) if (collect_images(cinfos, ARRAY_SIZE(cinfos))) return -1; - if (!files_collected() && - collect_images(cinfos_files, ARRAY_SIZE(cinfos_files))) + if (!files_collected() && collect_images(cinfos_files, ARRAY_SIZE(cinfos_files))) return -1; for_each_pstree_item(pi) { @@ -451,9 +430,8 @@ static bool sa_inherited(int sig, rt_sigaction_t *sa) if (pa->rt_sa_mask.sig[i] != sa->rt_sa_mask.sig[i]) return false; - return pa->rt_sa_handler == sa->rt_sa_handler && - pa->rt_sa_flags == sa->rt_sa_flags && - pa->rt_sa_restorer == sa->rt_sa_restorer; + return pa->rt_sa_handler == sa->rt_sa_handler && pa->rt_sa_flags == sa->rt_sa_flags && + pa->rt_sa_restorer == sa->rt_sa_restorer; } static int restore_native_sigaction(int sig, SaEntry *e) @@ -466,7 +444,7 @@ static int restore_native_sigaction(int sig, SaEntry *e) ASSIGN_TYPED(act.rt_sa_restorer, decode_pointer(e->restorer)); #ifdef CONFIG_MIPS e->has_mask_extended = 1; - BUILD_BUG_ON(sizeof(e->mask)* 2 != sizeof(act.rt_sa_mask.sig)); + BUILD_BUG_ON(sizeof(e->mask) * 2 != sizeof(act.rt_sa_mask.sig)); memcpy(&(act.rt_sa_mask.sig[0]), &e->mask, sizeof(act.rt_sa_mask.sig[0])); memcpy(&(act.rt_sa_mask.sig[1]), &e->mask_extended, sizeof(act.rt_sa_mask.sig[1])); @@ -522,9 +500,8 @@ static bool sa_compat_inherited(int sig, rt_sigaction_t_compat *sa) if (pa->rt_sa_mask.sig[i] != sa->rt_sa_mask.sig[i]) return false; - return pa->rt_sa_handler == sa->rt_sa_handler && - pa->rt_sa_flags == sa->rt_sa_flags && - pa->rt_sa_restorer == sa->rt_sa_restorer; + return pa->rt_sa_handler == sa->rt_sa_handler && pa->rt_sa_flags == sa->rt_sa_flags && + pa->rt_sa_restorer == sa->rt_sa_restorer; } static int restore_compat_sigaction(int sig, SaEntry *e) @@ -576,8 +553,7 @@ static int prepare_sigactions_from_core(TaskCoreEntry *tc) int sig, i; if (tc->n_sigactions != SIGMAX - 2) { - pr_err("Bad number of sigactions in the image (%d, want %d)\n", - (int)tc->n_sigactions, SIGMAX - 2); + pr_err("Bad number of sigactions in the image (%d, want %d)\n", (int)tc->n_sigactions, SIGMAX - 2); return -1; } @@ -661,8 +637,7 @@ static int prepare_sigactions_from_image(void) rst++; } - pr_info("Restored %d/%d sigacts\n", rst, - SIGMAX - 3 /* KILL, STOP and CHLD */); + pr_info("Restored %d/%d sigacts\n", rst, SIGMAX - 3 /* KILL, STOP and CHLD */); close_image(img); return ret; @@ -722,8 +697,7 @@ static int collect_child_pids(int state, unsigned int *n) if (current == root_item) { for_each_pstree_item(pi) { - if (pi->pid->state != TASK_HELPER && - pi->pid->state != TASK_DEAD) + if (pi->pid->state != TASK_HELPER && pi->pid->state != TASK_DEAD) continue; if (__collect_child_pids(pi, state, n)) return -1; @@ -801,7 +775,7 @@ static int open_cores(int pid, CoreEntry *leader_core) int i, tpid; CoreEntry **cores = NULL; - cores = xmalloc(sizeof(*cores)*current->nr_threads); + cores = xmalloc(sizeof(*cores) * current->nr_threads); if (!cores) goto err; @@ -867,8 +841,7 @@ static int prepare_proc_misc(pid_t pid, TaskCoreEntry *tc, struct task_restore_a args->child_subreaper = tc->child_subreaper; /* loginuid value is critical to restore */ - if (kdat.luid == LUID_FULL && tc->has_loginuid && - tc->loginuid != INVALID_UID) { + if (kdat.luid == LUID_FULL && tc->has_loginuid && tc->loginuid != INVALID_UID) { ret = prepare_loginuid(tc->loginuid); if (ret < 0) { pr_err("Setting loginuid for %d task failed\n", pid); @@ -894,8 +867,7 @@ static int restore_one_alive_task(int pid, CoreEntry *core) rst_mem_switch_to_private(); - args_len = round_up(sizeof(*ta) + sizeof(struct thread_restore_args) * - current->nr_threads, page_size()); + args_len = round_up(sizeof(*ta) + sizeof(struct thread_restore_args) * current->nr_threads, page_size()); ta = mmap(NULL, args_len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); if (!ta) return -1; @@ -996,33 +968,12 @@ static void zombie_prepare_signals(void) sigaction(sig, &act, NULL); } -#define SIG_FATAL_MASK ( \ - (1 << SIGHUP) |\ - (1 << SIGINT) |\ - (1 << SIGQUIT) |\ - (1 << SIGILL) |\ - (1 << SIGTRAP) |\ - (1 << SIGABRT) |\ - (1 << SIGIOT) |\ - (1 << SIGBUS) |\ - (1 << SIGFPE) |\ - (1 << SIGKILL) |\ - (1 << SIGUSR1) |\ - (1 << SIGSEGV) |\ - (1 << SIGUSR2) |\ - (1 << SIGPIPE) |\ - (1 << SIGALRM) |\ - (1 << SIGTERM) |\ - (1 << SIGXCPU) |\ - (1 << SIGXFSZ) |\ - (1 << SIGVTALRM)|\ - (1 << SIGPROF) |\ - (1 << SIGPOLL) |\ - (1 << SIGIO) |\ - (1 << SIGSYS) |\ - (1 << SIGSTKFLT)|\ - (1 << SIGPWR) \ - ) +#define SIG_FATAL_MASK \ + ((1 << SIGHUP) | (1 << SIGINT) | (1 << SIGQUIT) | (1 << SIGILL) | (1 << SIGTRAP) | (1 << SIGABRT) | \ + (1 << SIGIOT) | (1 << SIGBUS) | (1 << SIGFPE) | (1 << SIGKILL) | (1 << SIGUSR1) | (1 << SIGSEGV) | \ + (1 << SIGUSR2) | (1 << SIGPIPE) | (1 << SIGALRM) | (1 << SIGTERM) | (1 << SIGXCPU) | (1 << SIGXFSZ) | \ + (1 << SIGVTALRM) | (1 << SIGPROF) | (1 << SIGPOLL) | (1 << SIGIO) | (1 << SIGSYS) | (1 << SIGSTKFLT) | \ + (1 << SIGPWR)) static inline int sig_fatal(int sig) { @@ -1111,8 +1062,7 @@ static int setup_newborn_fds(struct pstree_item *me) if (clone_service_fd(me)) return -1; - if (!me->parent || - (rsti(me->parent)->fdt && !(rsti(me)->clone_flags & CLONE_FILES))) { + if (!me->parent || (rsti(me->parent)->fdt && !(rsti(me)->clone_flags & CLONE_FILES))) { /* * When our parent has shared fd table, some of the table owners * may be already created. Files, they open, will be inherited @@ -1295,8 +1245,7 @@ struct cr_clone_arg { CoreEntry *core; }; -static void maybe_clone_parent(struct pstree_item *item, - struct cr_clone_arg *ca) +static void maybe_clone_parent(struct pstree_item *item, struct cr_clone_arg *ca) { /* * zdtm runs in kernel 3.11, which has the problem described below. We @@ -1353,8 +1302,7 @@ static int set_next_pid(void *arg) len = snprintf(buf, sizeof(buf), "%d", *pid - 1); if (write(fd, buf, len) != len) { - pr_perror("Failed to write %s to /proc/%s", - buf, LAST_PID_PATH); + pr_perror("Failed to write %s to /proc/%s", buf, LAST_PID_PATH); close(fd); return -1; } @@ -1466,18 +1414,16 @@ static inline int fork_with_pid(struct pstree_item *item) } else { if (!external_pidns) { if (pid != INIT_PID) { - pr_err("First PID in a PID namespace needs to be %d and not %d\n", - pid, INIT_PID); + pr_err("First PID in a PID namespace needs to be %d and not %d\n", pid, INIT_PID); return -1; } } } if (kdat.has_clone3_set_tid) { - ret = clone3_with_pid_noasan(restore_task_with_children, - &ca, (ca.clone_flags & - ~(CLONE_NEWNET | CLONE_NEWCGROUP | CLONE_NEWTIME)), - SIGCHLD, pid); + ret = clone3_with_pid_noasan(restore_task_with_children, &ca, + (ca.clone_flags & ~(CLONE_NEWNET | CLONE_NEWCGROUP | CLONE_NEWTIME)), + SIGCHLD, pid); } else { /* * Some kernel modules, such as network packet generator @@ -1493,9 +1439,7 @@ static inline int fork_with_pid(struct pstree_item *item) */ close_pid_proc(); ret = clone_noasan(restore_task_with_children, - (ca.clone_flags & - ~(CLONE_NEWNET | CLONE_NEWCGROUP | CLONE_NEWTIME)) | SIGCHLD, - &ca); + (ca.clone_flags & ~(CLONE_NEWNET | CLONE_NEWCGROUP | CLONE_NEWTIME)) | SIGCHLD, &ca); } if (ret < 0) { @@ -1505,11 +1449,9 @@ static inline int fork_with_pid(struct pstree_item *item) goto err_unlock; } - if (item == root_item) { item->pid->real = ret; - pr_debug("PID: real %d virt %d\n", - item->pid->real, vpid(item)); + pr_debug("PID: real %d virt %d\n", item->pid->real, vpid(item)); } err_unlock: @@ -1644,8 +1586,7 @@ static void restore_sid(void) /* Skip the root task if it's not init */ if (current == root_item && vpid(root_item) != INIT_PID) return; - pr_err("Requested sid %d doesn't match inherited %d\n", - current->sid, sid); + pr_err("Requested sid %d doesn't match inherited %d\n", current->sid, sid); exit(1); } } @@ -1804,8 +1745,7 @@ static int restore_task_with_children(void *_arg) buf[ret] = '\0'; current->pid->real = atoi(buf); - pr_debug("PID: real %d virt %d\n", - current->pid->real, vpid(current)); + pr_debug("PID: real %d virt %d\n", current->pid->real, vpid(current)); } pid = getpid(); @@ -1993,7 +1933,6 @@ static int attach_to_tasks(bool root_seized) return -1; } - if (wait4(pid, &status, __WALL, NULL) != pid) { pr_perror("waitpid(%d) failed", pid); return -1; @@ -2009,7 +1948,7 @@ static int attach_to_tasks(bool root_seized) if (rsti(item)->has_seccomp && ptrace_suspend_seccomp(pid) < 0) pr_err("failed to suspend seccomp, restore will probably fail...\n"); - if (ptrace(PTRACE_CONT, pid, NULL, NULL) ) { + if (ptrace(PTRACE_CONT, pid, NULL, NULL)) { pr_perror("Unable to resume %d", pid); return -1; } @@ -2049,8 +1988,7 @@ static int catch_tasks(bool root_seized, enum trace_flags *flag) return -1; } - ret = compel_stop_pie(pid, rsti(item)->breakpoint, - flag, fault_injected(FI_NO_BREAKPOINTS)); + ret = compel_stop_pie(pid, rsti(item)->breakpoint, flag, fault_injected(FI_NO_BREAKPOINTS)); if (ret < 0) return -1; } @@ -2100,8 +2038,7 @@ static void finalize_restore(void) xfree(ctl); - if ((item->pid->state == TASK_STOPPED) || - (opts.final_state == TASK_STOPPED)) + if ((item->pid->state == TASK_STOPPED) || (opts.final_state == TASK_STOPPED)) kill(item->pid->real, SIGSTOP); } } @@ -2249,9 +2186,9 @@ static int restore_root_task(struct pstree_item *init) if (vpid(init) == INIT_PID) { if (!(root_ns_mask & CLONE_NEWPID)) { pr_err("This process tree can only be restored " - "in a new pid namespace.\n" - "criu should be re-executed with the " - "\"--namespace pid\" option.\n"); + "in a new pid namespace.\n" + "criu should be re-executed with the " + "\"--namespace pid\" option.\n"); return -1; } } else if (root_ns_mask & CLONE_NEWPID) { @@ -2437,8 +2374,7 @@ skip_ns_bouncing: __restore_switch_stage(CR_STATE_COMPLETE); - ret = compel_stop_on_syscall(task_entries->nr_threads, - __NR(rt_sigreturn, 0), __NR(rt_sigreturn, 1), flag); + ret = compel_stop_on_syscall(task_entries->nr_threads, __NR(rt_sigreturn, 0), __NR(rt_sigreturn, 1), flag); if (ret) { pr_err("Can't stop all tasks on rt_sigreturn\n"); goto out_kill_network_unlocked; @@ -2491,8 +2427,7 @@ out_kill: kill(root_item->pid->real, SIGKILL); if (waitpid(root_item->pid->real, &status, 0) < 0) - pr_warn("Unable to wait %d: %s\n", - root_item->pid->real, strerror(errno)); + pr_warn("Unable to wait %d: %s\n", root_item->pid->real, strerror(errno)); } else { struct pstree_item *pi; @@ -2608,8 +2543,7 @@ err: return ret; } -static long restorer_get_vma_hint(struct list_head *tgt_vma_list, - struct list_head *self_vma_list, long vma_len) +static long restorer_get_vma_hint(struct list_head *tgt_vma_list, struct list_head *self_vma_list, long vma_len) { struct vma_area *t_vma, *s_vma; long prev_vma_end = 0; @@ -2693,9 +2627,8 @@ static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val) return -1; } - pr_info("Restored %s timer to %ld.%ld -> %ld.%ld\n", n, - val->it_value.tv_sec, val->it_value.tv_usec, - val->it_interval.tv_sec, val->it_interval.tv_usec); + pr_info("Restored %s timer to %ld.%ld -> %ld.%ld\n", n, val->it_value.tv_sec, val->it_value.tv_usec, + val->it_interval.tv_sec, val->it_interval.tv_usec); return 0; } @@ -2765,8 +2698,7 @@ static inline int timespec_valid(struct timespec *ts) return (ts->tv_sec >= 0) && ((unsigned long)ts->tv_nsec < NSEC_PER_SEC); } -static inline int decode_posix_timer(PosixTimerEntry *pte, - struct restore_posix_timer *pt) +static inline int decode_posix_timer(PosixTimerEntry *pte, struct restore_posix_timer *pt) { pt->val.it_interval.tv_sec = pte->isec; pt->val.it_interval.tv_nsec = pte->insec; @@ -2822,9 +2754,7 @@ static void sort_posix_timers(struct task_restore_args *ta) if (ta->posix_timers_n > 0) { tmem = rst_mem_remap_ptr((unsigned long)ta->posix_timers, RM_PRIVATE); - qsort(tmem, ta->posix_timers_n, - sizeof(struct restore_posix_timer), - cmp_posix_timer_proc_id); + qsort(tmem, ta->posix_timers_n, sizeof(struct restore_posix_timer), cmp_posix_timer_proc_id); } } @@ -2901,8 +2831,8 @@ out: static inline int verify_cap_size(CredsEntry *ce) { - return ((ce->n_cap_inh == CR_CAP_SIZE) && (ce->n_cap_eff == CR_CAP_SIZE) && - (ce->n_cap_prm == CR_CAP_SIZE) && (ce->n_cap_bnd == CR_CAP_SIZE)); + return ((ce->n_cap_inh == CR_CAP_SIZE) && (ce->n_cap_eff == CR_CAP_SIZE) && (ce->n_cap_prm == CR_CAP_SIZE) && + (ce->n_cap_bnd == CR_CAP_SIZE)); } static int prepare_mm(pid_t pid, struct task_restore_args *args) @@ -2919,7 +2849,7 @@ static int prepare_mm(pid_t pid, struct task_restore_args *args) goto out; } - args->mm_saved_auxv_size = mm->n_mm_saved_auxv*sizeof(auxv_t); + args->mm_saved_auxv_size = mm->n_mm_saved_auxv * sizeof(auxv_t); for (i = 0; i < mm->n_mm_saved_auxv; ++i) { args->mm_saved_auxv[i] = (auxv_t)mm->mm_saved_auxv[i]; } @@ -2965,9 +2895,7 @@ static int prepare_restorer_blob(void) */ restorer_len = round_up(pbd.hdr.args_off, page_size()); - restorer = mmap(NULL, restorer_len, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + restorer = mmap(NULL, restorer_len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (restorer == MAP_FAILED) { pr_perror("Can't map restorer code"); return -1; @@ -2983,8 +2911,7 @@ static int remap_restorer_blob(void *addr) struct parasite_blob_desc pbd; void *mem; - mem = mremap(restorer, restorer_len, restorer_len, - MREMAP_FIXED | MREMAP_MAYMOVE, addr); + mem = mremap(restorer, restorer_len, restorer_len, MREMAP_FIXED | MREMAP_MAYMOVE, addr); if (mem != addr) { pr_perror("Can't remap restorer blob"); return -1; @@ -3033,8 +2960,7 @@ static int prep_sched_info(struct rst_sched_param *sp, ThreadCoreEntry *tc) sp->prio = tc->sched_prio; if (!validate_sched_parm(sp)) { - pr_err("Inconsistent sched params received (%d.%d.%d)\n", - sp->policy, sp->nice, sp->prio); + pr_err("Inconsistent sched params received (%d.%d.%d)\n", sp->policy, sp->nice, sp->prio); return -1; } @@ -3076,16 +3002,14 @@ static int prepare_rlimits_from_fd(int pid, struct task_restore_args *ta) r = rst_mem_alloc(sizeof(*r), RM_PRIVATE); if (!r) { - pr_err("Can't allocate memory for resource %d\n", - ta->rlims_n); + pr_err("Can't allocate memory for resource %d\n", ta->rlims_n); return -1; } r->rlim_cur = decode_rlim(re->cur); r->rlim_max = decode_rlim(re->max); if (r->rlim_cur > r->rlim_max) { - pr_err("Can't restore cur > max for %d.%d\n", - pid, ta->rlims_n); + pr_err("Can't restore cur > max for %d.%d\n", pid, ta->rlims_n); r->rlim_cur = r->rlim_max; } @@ -3134,7 +3058,7 @@ static int signal_to_mem(SiginfoEntry *sie) { siginfo_t *info, *t; - info = (siginfo_t *) sie->siginfo.data; + info = (siginfo_t *)sie->siginfo.data; t = rst_mem_alloc(sizeof(siginfo_t), RM_PRIVATE); if (!t) return -1; @@ -3177,7 +3101,7 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr) close_image(img); - return ret ? : 0; + return ret ?: 0; } static int prepare_one_signal_queue(SignalQueueEntry *sqe, unsigned int *nr) @@ -3205,7 +3129,7 @@ static int prepare_signals(int pid, struct task_restore_args *ta, CoreEntry *lea goto out; /* Prepare shared signals */ - if (!leader_core->tc->signals_s)/*backward compatibility*/ + if (!leader_core->tc->signals_s) /*backward compatibility*/ ret = open_signal_image(CR_FD_SIGNAL, pid, &ta->siginfo_n); else ret = prepare_one_signal_queue(leader_core->tc->signals_s, &ta->siginfo_n); @@ -3214,12 +3138,10 @@ static int prepare_signals(int pid, struct task_restore_args *ta, CoreEntry *lea goto out; for (i = 0; i < current->nr_threads; i++) { - if (!current->core[i]->thread_core->signals_p)/*backward compatibility*/ - ret = open_signal_image(CR_FD_PSIGNAL, - current->threads[i].ns[0].virt, &siginfo_priv_nr[i]); + if (!current->core[i]->thread_core->signals_p) /*backward compatibility*/ + ret = open_signal_image(CR_FD_PSIGNAL, current->threads[i].ns[0].virt, &siginfo_priv_nr[i]); else - ret = prepare_one_signal_queue(current->core[i]->thread_core->signals_p, - &siginfo_priv_nr[i]); + ret = prepare_one_signal_queue(current->core[i]->thread_core->signals_p, &siginfo_priv_nr[i]); if (ret < 0) goto out; } @@ -3228,10 +3150,11 @@ out: } extern void __gcov_flush(void) __attribute__((weak)); -void __gcov_flush(void) {} +void __gcov_flush(void) +{ +} -static void rst_reloc_creds(struct thread_restore_args *thread_args, - unsigned long *creds_pos_next) +static void rst_reloc_creds(struct thread_restore_args *thread_args, unsigned long *creds_pos_next) { struct thread_creds_args *args; @@ -3251,11 +3174,11 @@ static void rst_reloc_creds(struct thread_restore_args *thread_args, thread_args->creds_args = args; } -static bool groups_match(gid_t* groups, int n_groups) +static bool groups_match(gid_t *groups, int n_groups) { int n, len; bool ret; - gid_t* gids; + gid_t *gids; n = getgroups(0, NULL); if (n == -1) { @@ -3285,16 +3208,14 @@ static bool groups_match(gid_t* groups, int n_groups) return ret; } -static struct thread_creds_args * -rst_prep_creds_args(CredsEntry *ce, unsigned long *prev_pos) +static struct thread_creds_args *rst_prep_creds_args(CredsEntry *ce, unsigned long *prev_pos) { unsigned long this_pos; struct thread_creds_args *args; if (!verify_cap_size(ce)) { - pr_err("Caps size mismatch %d %d %d %d\n", - (int)ce->n_cap_inh, (int)ce->n_cap_eff, - (int)ce->n_cap_prm, (int)ce->n_cap_bnd); + pr_err("Caps size mismatch %d %d %d %d\n", (int)ce->n_cap_inh, (int)ce->n_cap_eff, (int)ce->n_cap_prm, + (int)ce->n_cap_bnd); return ERR_PTR(-EINVAL); } @@ -3537,8 +3458,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns /* Wait when all tasks restored all files */ if (restore_wait_other_tasks()) goto err_nv; - if (root_ns_mask & CLONE_NEWNS && - remount_readonly_mounts()) + if (root_ns_mask & CLONE_NEWNS && remount_readonly_mounts()) goto err_nv; } @@ -3556,8 +3476,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns memzone_size = round_up(sizeof(struct restore_mem_zone) * current->nr_threads, page_size()); task_args->bootstrap_len = restorer_len + memzone_size + alen + rst_mem_size; BUG_ON(task_args->bootstrap_len & (PAGE_SIZE - 1)); - pr_info("%d threads require %ldK of memory\n", - current->nr_threads, KBYTES(task_args->bootstrap_len)); + pr_info("%d threads require %ldK of memory\n", current->nr_threads, KBYTES(task_args->bootstrap_len)); if (core_is_compat(core)) vdso_maps_rt = vdso_maps_compat; @@ -3585,16 +3504,13 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns * or inited from scratch). */ - mem = (void *)restorer_get_vma_hint(&vmas->h, &self_vmas.h, - task_args->bootstrap_len); + mem = (void *)restorer_get_vma_hint(&vmas->h, &self_vmas.h, task_args->bootstrap_len); if (mem == (void *)-1) { - pr_err("No suitable area for task_restore bootstrap (%ldK)\n", - task_args->bootstrap_len); + pr_err("No suitable area for task_restore bootstrap (%ldK)\n", task_args->bootstrap_len); goto err; } - pr_info("Found bootstrap VMA hint at: %p (needs ~%ldK)\n", - mem, KBYTES(task_args->bootstrap_len)); + pr_info("Found bootstrap VMA hint at: %p (needs ~%ldK)\n", mem, KBYTES(task_args->bootstrap_len)); ret = remap_restorer_blob(mem); if (ret < 0) @@ -3604,16 +3520,15 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns * Prepare a memory map for restorer. Note a thread space * might be completely unused so it's here just for convenience. */ - task_args->clone_restore_fn = restorer_sym(mem, arch_export_restore_thread); - restore_task_exec_start = restorer_sym(mem, arch_export_restore_task); - rsti(current)->munmap_restorer = restorer_munmap_addr(core, mem); + task_args->clone_restore_fn = restorer_sym(mem, arch_export_restore_thread); + restore_task_exec_start = restorer_sym(mem, arch_export_restore_task); + rsti(current)->munmap_restorer = restorer_munmap_addr(core, mem); task_args->bootstrap_start = mem; mem += restorer_len; /* VMA we need for stacks and sigframes for threads */ - if (mmap(mem, memzone_size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0) != mem) { + if (mmap(mem, memzone_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0) != mem) { pr_perror("Can't mmap section for restore code"); goto err; } @@ -3623,7 +3538,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns mem += memzone_size; /* New home for task_restore_args and thread_restore_args */ - task_args = mremap(task_args, alen, alen, MREMAP_MAYMOVE|MREMAP_FIXED, mem); + task_args = mremap(task_args, alen, alen, MREMAP_MAYMOVE | MREMAP_FIXED, mem); if (task_args != mem) { pr_perror("Can't move task args"); goto err; @@ -3699,10 +3614,10 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns BUG_ON(core->mtype != CORE_ENTRY__MARCH); - task_args->logfd = log_get_fd(); - task_args->loglevel = log_get_loglevel(); + task_args->logfd = log_get_fd(); + task_args->loglevel = log_get_loglevel(); log_get_logstart(&task_args->logstart); - task_args->sigchld_act = sigchld_act; + task_args->sigchld_act = sigchld_act; strncpy(task_args->comm, core->tc->comm, TASK_COMM_LEN - 1); task_args->comm[TASK_COMM_LEN - 1] = 0; @@ -3750,27 +3665,25 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns } if ((tcore->tc || tcore->ids) && thread_args[i].pid != pid) { - pr_err("Thread has optional fields present %d\n", - thread_args[i].pid); + pr_err("Thread has optional fields present %d\n", thread_args[i].pid); ret = -1; } if (ret < 0) { - pr_err("Can't read core data for thread %d\n", - thread_args[i].pid); + pr_err("Can't read core data for thread %d\n", thread_args[i].pid); goto err; } - thread_args[i].ta = task_args; - thread_args[i].gpregs = *CORE_THREAD_ARCH_INFO(tcore)->gpregs; - thread_args[i].clear_tid_addr = CORE_THREAD_ARCH_INFO(tcore)->clear_tid_addr; + thread_args[i].ta = task_args; + thread_args[i].gpregs = *CORE_THREAD_ARCH_INFO(tcore)->gpregs; + thread_args[i].clear_tid_addr = CORE_THREAD_ARCH_INFO(tcore)->clear_tid_addr; core_get_tls(tcore, &thread_args[i].tls); rst_reloc_creds(&thread_args[i], &creds_pos_next); - thread_args[i].futex_rla = tcore->thread_core->futex_rla; - thread_args[i].futex_rla_len = tcore->thread_core->futex_rla_len; - thread_args[i].pdeath_sig = tcore->thread_core->pdeath_sig; + thread_args[i].futex_rla = tcore->thread_core->futex_rla; + thread_args[i].futex_rla_len = tcore->thread_core->futex_rla_len; + thread_args[i].pdeath_sig = tcore->thread_core->pdeath_sig; if (tcore->thread_core->pdeath_sig > _KNSIG) { pr_err("Pdeath signal is too big\n"); goto err; @@ -3802,9 +3715,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns if (thread_args[i].pid != pid) core_entry__free_unpacked(tcore, NULL); - pr_info("Thread %4d stack %8p rt_sigframe %8p\n", - i, mz[i].stack, mz[i].rt_sigframe); - + pr_info("Thread %4d stack %8p rt_sigframe %8p\n", i, mz[i].stack, mz[i].rt_sigframe); } /* @@ -3829,17 +3740,17 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns /* * Now prepare run-time data for threads restore. */ - task_args->nr_threads = current->nr_threads; - task_args->thread_args = thread_args; + task_args->nr_threads = current->nr_threads; + task_args->thread_args = thread_args; - task_args->auto_dedup = opts.auto_dedup; + task_args->auto_dedup = opts.auto_dedup; /* * In the restorer we need to know if it is SELinux or not. For SELinux * we must change the process context before creating threads. For * Apparmor we can change each thread after they have been created. */ - task_args->lsm_type = kdat.lsm; + task_args->lsm_type = kdat.lsm; /* * Make root and cwd restore _that_ late not to break any @@ -3866,9 +3777,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns "task_args->nr_threads: %d\n" "task_args->clone_restore_fn: %p\n" "task_args->thread_args: %p\n", - task_args, task_args->t->pid, - task_args->nr_threads, - task_args->clone_restore_fn, + task_args, task_args->t->pid, task_args->nr_threads, task_args->clone_restore_fn, task_args->thread_args); /* diff --git a/criu/cr-service.c b/criu/cr-service.c index 888d6b7e4..38a8ea365 100644 --- a/criu/cr-service.c +++ b/criu/cr-service.c @@ -491,14 +491,14 @@ static int setup_opts_from_req(int sk, CriuOpts *req) if (req->has_pre_dump_mode) { switch (req->pre_dump_mode) { - case CRIU_PRE_DUMP_MODE__SPLICE: - opts.pre_dump_mode = PRE_DUMP_SPLICE; - break; - case CRIU_PRE_DUMP_MODE__VM_READ: - opts.pre_dump_mode = PRE_DUMP_READ; - break; - default: - goto err; + case CRIU_PRE_DUMP_MODE__SPLICE: + opts.pre_dump_mode = PRE_DUMP_SPLICE; + break; + case CRIU_PRE_DUMP_MODE__VM_READ: + opts.pre_dump_mode = PRE_DUMP_READ; + break; + default: + goto err; } } @@ -553,8 +553,7 @@ static int setup_opts_from_req(int sk, CriuOpts *req) goto err; for (i = 0; i < req->n_cg_root; i++) { - if (new_cg_root_add(req->cg_root[i]->ctrl, - req->cg_root[i]->path)) + if (new_cg_root_add(req->cg_root[i]->ctrl, req->cg_root[i]->path)) goto err; } @@ -698,7 +697,6 @@ static int setup_opts_from_req(int sk, CriuOpts *req) if (req->orphan_pts_master) opts.orphan_pts_master = true; - /* Evaluate additional configuration file a second time to overwrite * all RPC settings. */ if (req->config_file) { @@ -744,7 +742,7 @@ static int dump_using_req(int sk, CriuOpts *req) exit: free_pidfd_store(); pidfd_store_err: - if (req->leave_running || !self_dump || !success) { + if (req->leave_running || !self_dump || !success) { if (send_criu_dump_resp(sk, success, false) == -1) { pr_perror("Can't send response"); success = false; @@ -776,8 +774,7 @@ static int restore_using_req(int sk, CriuOpts *req) success = true; exit: - if (send_criu_restore_resp(sk, success, - root_item ? root_item->pid->real : -1) == -1) { + if (send_criu_restore_resp(sk, success, root_item ? root_item->pid->real : -1) == -1) { pr_perror("Can't send response"); success = false; } @@ -861,9 +858,9 @@ static int pre_dump_using_req(int sk, CriuOpts *req) goto cout; ret = 0; -cout: + cout: free_pidfd_store(); -pidfd_store_err: + pidfd_store_err: exit(ret); } @@ -947,7 +944,7 @@ static int start_page_server_req(int sk, CriuOpts *req, bool daemon_mode) } ret = 0; -out_ch: + out_ch: if (daemon_mode && ret < 0 && pid > 0) kill(pid, SIGKILL); close(start_pipe[1]); @@ -1012,8 +1009,7 @@ static int chk_keepopen_req(CriuReq *msg) if (msg->type == CRIU_REQ_TYPE__PAGE_SERVER_CHLD) /* This just fork()-s so no leaks */ return 0; - else if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP || - msg->type == CRIU_REQ_TYPE__CPUINFO_CHECK) + else if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP || msg->type == CRIU_REQ_TYPE__CPUINFO_CHECK) return 0; else if (msg->type == CRIU_REQ_TYPE__FEATURE_CHECK) return 0; @@ -1027,7 +1023,7 @@ static int chk_keepopen_req(CriuReq *msg) * Return the version information, depending on the information * available in version.h */ -static int handle_version(int sk, CriuReq * msg) +static int handle_version(int sk, CriuReq *msg) { CriuResp resp = CRIU_RESP__INIT; CriuVersion version = CRIU_VERSION__INIT; @@ -1065,7 +1061,7 @@ static int handle_version(int sk, CriuReq * msg) * For each feature which has been requested in msg->features * the corresponding parameter will be set in resp.features. */ -static int handle_feature_check(int sk, CriuReq * msg) +static int handle_feature_check(int sk, CriuReq *msg) { CriuResp resp = CRIU_RESP__INIT; CriuFeatures feat = CRIU_FEATURES__INIT; @@ -1092,16 +1088,13 @@ static int handle_feature_check(int sk, CriuReq * msg) setproctitle("feature-check --rpc"); - if ((msg->features->has_mem_track == 1) && - (msg->features->mem_track == true)) + if ((msg->features->has_mem_track == 1) && (msg->features->mem_track == true)) feat.mem_track = kdat.has_dirty_track; - if ((msg->features->has_lazy_pages == 1) && - (msg->features->lazy_pages == true)) + if ((msg->features->has_lazy_pages == 1) && (msg->features->lazy_pages == true)) feat.lazy_pages = kdat.has_uffd && uffd_noncooperative(); - if ((msg->features->has_pidfd_store == 1) && - (msg->features->pidfd_store == true)) + if ((msg->features->has_pidfd_store == 1) && (msg->features->pidfd_store == true)) feat.pidfd_store = kdat.has_pidfd_getfd && kdat.has_pidfd_open; resp.features = &feat; @@ -1179,16 +1172,14 @@ static int handle_cpuinfo(int sk, CriuReq *msg) if (setup_opts_from_req(sk, msg->opts)) goto cout; - setproctitle("cpuinfo %s --rpc -D %s", - msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ? - "dump" : "check", + setproctitle("cpuinfo %s --rpc -D %s", msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ? "dump" : "check", images_dir); if (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP) ret = cpuinfo_dump(); else ret = cpuinfo_check(); -cout: + cout: exit(ret); } @@ -1255,7 +1246,7 @@ more: ret = start_page_server_req(sk, msg->opts, false); break; case CRIU_REQ_TYPE__WAIT_PID: - ret = handle_wait_pid(sk, msg->pid); + ret = handle_wait_pid(sk, msg->pid); break; case CRIU_REQ_TYPE__CPUINFO_DUMP: case CRIU_REQ_TYPE__CPUINFO_CHECK: @@ -1304,11 +1295,10 @@ static void reap_worker(int signo) } if (WIFEXITED(status)) - pr_info("Worker(pid %d) exited with %d\n", - pid, WEXITSTATUS(status)); + pr_info("Worker(pid %d) exited with %d\n", pid, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) - pr_info("Worker(pid %d) was killed by %d: %s\n", pid, - WTERMSIG(status), strsignal(WTERMSIG(status))); + pr_info("Worker(pid %d) was killed by %d: %s\n", pid, WTERMSIG(status), + strsignal(WTERMSIG(status))); } } @@ -1318,8 +1308,8 @@ static int setup_sigchld_handler(void) sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGCHLD); - action.sa_handler = reap_worker; - action.sa_flags = SA_RESTART; + action.sa_handler = reap_worker; + action.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &action, NULL)) { pr_perror("Can't setup SIGCHLD handler"); @@ -1335,8 +1325,8 @@ static int restore_sigchld_handler(void) sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGCHLD); - action.sa_handler = SIG_DFL; - action.sa_flags = SA_RESTART; + action.sa_handler = SIG_DFL; + action.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &action, NULL)) { pr_perror("Can't restore SIGCHLD handler"); @@ -1373,17 +1363,14 @@ int cr_service(bool daemon_mode) SET_CHAR_OPTS(addr, CR_DEFAULT_SERVICE_ADDRESS); } - strncpy(server_addr.sun_path, opts.addr, - sizeof(server_addr.sun_path) - 1); + strncpy(server_addr.sun_path, opts.addr, sizeof(server_addr.sun_path) - 1); - server_addr_len = strlen(server_addr.sun_path) - + sizeof(server_addr.sun_family); + server_addr_len = strlen(server_addr.sun_path) + sizeof(server_addr.sun_family); client_addr_len = sizeof(client_addr); unlink(server_addr.sun_path); - if (bind(server_fd, (struct sockaddr *) &server_addr, - server_addr_len) == -1) { + if (bind(server_fd, (struct sockaddr *)&server_addr, server_addr_len) == -1) { pr_perror("Can't bind"); goto err; } diff --git a/criu/crtools.c b/criu/crtools.c index 778a1f3af..ba41d382d 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -56,8 +56,7 @@ void flush_early_log_to_stderr(void) static int image_dir_mode(char *argv[], int optind) { - if (!strcmp(argv[optind], "dump") || - !strcmp(argv[optind], "pre-dump") || + if (!strcmp(argv[optind], "dump") || !strcmp(argv[optind], "pre-dump") || (!strcmp(argv[optind], "cpuinfo") && !strcmp(argv[optind + 1], "dump"))) return O_DUMP; @@ -79,8 +78,7 @@ int main(int argc, char *argv[], char *envp[]) BUILD_BUG_ON(CTL_32 != SYSCTL_TYPE__CTL_32); BUILD_BUG_ON(__CTL_STR != SYSCTL_TYPE__CTL_STR); /* We use it for fd overlap handling in clone_service_fd() */ - BUG_ON(get_service_fd(SERVICE_FD_MIN+1) < - get_service_fd(SERVICE_FD_MAX-1)); + BUG_ON(get_service_fd(SERVICE_FD_MIN + 1) < get_service_fd(SERVICE_FD_MAX - 1)); if (fault_injection_init()) { pr_err("Failed to initialize fault injection when initializing crtools.\n"); @@ -95,7 +93,6 @@ int main(int argc, char *argv[], char *envp[]) init_opts(); - ret = parse_options(argc, argv, &usage_error, &has_exec_cmd, state); if (ret == 1) @@ -110,7 +107,7 @@ int main(int argc, char *argv[], char *envp[]) log_set_loglevel(opts.log_level); if (optind < argc && !strcmp(argv[optind], "swrk")) { - if (argc != optind+2) { + if (argc != optind + 2) { fprintf(stderr, "Usage: criu swrk <fd>\n"); return 1; } @@ -121,7 +118,7 @@ int main(int argc, char *argv[], char *envp[]) * corresponding lib call change. */ opts.swrk_restore = true; - return cr_service_work(atoi(argv[optind+1])); + return cr_service_work(atoi(argv[optind + 1])); } if (check_options()) @@ -159,8 +156,7 @@ int main(int argc, char *argv[], char *envp[]) } else { /* No subcommands except for cpuinfo and restore --exec-cmd */ if (strcmp(argv[optind], "cpuinfo") && has_sub_command) { - pr_err("excessive parameter%s for command %s\n", - (argc - optind) > 2 ? "s" : "", argv[optind]); + pr_err("excessive parameter%s for command %s\n", (argc - optind) > 2 ? "s" : "", argv[optind]); goto usage; } } @@ -198,10 +194,8 @@ int main(int argc, char *argv[], char *envp[]) * When a process group becomes an orphan, * its processes are sent a SIGHUP signal */ - if (!strcmp(argv[optind], "restore") && - opts.restore_detach && - opts.final_state == TASK_STOPPED && - opts.shell_job) + if (!strcmp(argv[optind], "restore") && opts.restore_detach && opts.final_state == TASK_STOPPED && + opts.shell_job) pr_warn("Stopped and detached shell job will get SIGHUP from OS.\n"); if (chdir(opts.work_dir)) { @@ -305,26 +299,25 @@ int main(int argc, char *argv[], char *envp[]) pr_err("unknown command: %s\n", argv[optind]); usage: pr_msg("\n" -"Usage:\n" -" criu dump|pre-dump -t PID [<options>]\n" -" criu restore [<options>]\n" -" criu check [--feature FEAT]\n" -" criu page-server\n" -" criu service [<options>]\n" -" criu dedup\n" -" criu lazy-pages -D DIR [<options>]\n" -"\n" -"Commands:\n" -" dump checkpoint a process/tree identified by pid\n" -" pre-dump pre-dump task(s) minimizing their frozen time\n" -" restore restore a process/tree\n" -" check checks whether the kernel support is up-to-date\n" -" page-server launch page server\n" -" service launch service\n" -" dedup remove duplicates in memory dump\n" -" cpuinfo dump writes cpu information into image file\n" -" cpuinfo check validates cpu information read from image file\n" - ); + "Usage:\n" + " criu dump|pre-dump -t PID [<options>]\n" + " criu restore [<options>]\n" + " criu check [--feature FEAT]\n" + " criu page-server\n" + " criu service [<options>]\n" + " criu dedup\n" + " criu lazy-pages -D DIR [<options>]\n" + "\n" + "Commands:\n" + " dump checkpoint a process/tree identified by pid\n" + " pre-dump pre-dump task(s) minimizing their frozen time\n" + " restore restore a process/tree\n" + " check checks whether the kernel support is up-to-date\n" + " page-server launch page server\n" + " service launch service\n" + " dedup remove duplicates in memory dump\n" + " cpuinfo dump writes cpu information into image file\n" + " cpuinfo check validates cpu information read from image file\n"); if (usage_error) { pr_msg("\nTry -h|--help for more info\n"); @@ -333,178 +326,175 @@ usage: pr_msg("\n" -"Most of the true / false long options (the ones without arguments) can be\n" -"prefixed with --no- to negate the option (example: --display-stats and\n" -"--no-display-stats).\n" -"\n" -"Dump/Restore options:\n" -"\n" -"* Generic:\n" -" -t|--tree PID checkpoint a process tree identified by PID\n" -" -d|--restore-detached detach after restore\n" -" -S|--restore-sibling restore root task as sibling\n" -" -s|--leave-stopped leave tasks in stopped state after checkpoint\n" -" -R|--leave-running leave tasks in running state after checkpoint\n" -" -D|--images-dir DIR directory for image files\n" -" --pidfile FILE write root task, service or page-server pid to FILE\n" -" -W|--work-dir DIR directory to cd and write logs/pidfiles/stats to\n" -" (if not specified, value of --images-dir is used)\n" -" --cpu-cap [CAP] CPU capabilities to write/check. CAP is comma-separated\n" -" list of: cpu, fpu, all, ins, none. To disable\n" -" a capability, use ^CAP. Empty argument implies all\n" -" --exec-cmd execute the command specified after '--' on successful\n" -" restore making it the parent of the restored process\n" -" --freeze-cgroup use cgroup freezer to collect processes\n" -" --weak-sysctls skip restoring sysctls that are not available\n" -" --lazy-pages restore pages on demand\n" -" this requires running a second instance of criu\n" -" in lazy-pages mode: 'criu lazy-pages -D DIR'\n" -" --lazy-pages and lazy-pages mode require userfaultfd\n" -" --stream dump/restore images using criu-image-streamer\n" -"\n" -"* External resources support:\n" -" --external RES dump objects from this list as external resources:\n" -" Formats of RES on dump:\n" -" tty[rdev:dev]\n" -" file[mnt_id:inode]\n" -" dev[major/minor]:NAME\n" -" unix[ino]\n" -" mnt[MOUNTPOINT]:COOKIE\n" -" mnt[]{:AUTO_OPTIONS}\n" -" Formats of RES on restore:\n" -" dev[NAME]:DEVPATH\n" -" veth[IFNAME]:OUTNAME{@BRIDGE}\n" -" macvlan[IFNAME]:OUTNAME\n" -" mnt[COOKIE]:ROOT\n" -" netdev[IFNAME]:ORIGNAME\n" -"\n" -"* Special resources support:\n" -" --" SK_EST_PARAM " checkpoint/restore established TCP connections\n" -" --" SK_INFLIGHT_PARAM " skip (ignore) in-flight TCP connections\n" -" --" SK_CLOSE_PARAM " don't dump the state of, or block, established tcp\n" -" connections, and restore them in closed state.\n" -" -r|--root PATH change the root filesystem (when run in mount namespace)\n" -" --evasive-devices use any path to a device file if the original one\n" -" is inaccessible\n" -" --link-remap allow one to link unlinked files back when possible\n" -" --ghost-limit size limit max size of deleted file contents inside image\n" -" --action-script FILE add an external action script\n" -" -j|--" OPT_SHELL_JOB " allow one to dump and restore shell jobs\n" -" -l|--" OPT_FILE_LOCKS " handle file locks, for safety, only used for container\n" -" -L|--libdir path to a plugin directory (by default " CR_PLUGIN_DEFAULT ")\n" -" --force-irmap force resolving names for inotify/fsnotify watches\n" -" --irmap-scan-path FILE\n" -" add a path the irmap hints to scan\n" -" --manage-cgroups [m] dump/restore process' cgroups; argument can be one of\n" -" 'none', 'props', 'soft' (default), 'full', 'strict'\n" -" or 'ignore'\n" -" --cgroup-root [controller:]/newroot\n" -" on dump: change the root for the controller that will\n" -" be dumped. By default, only the paths with tasks in\n" -" them and below will be dumped.\n" -" on restore: change the root cgroup the controller will\n" -" be installed into. No controller means that root is the\n" -" default for all controllers not specified\n" -" --cgroup-props STRING\n" -" define cgroup controllers and properties\n" -" to be checkpointed, which are described\n" -" via STRING using simplified YAML format\n" -" --cgroup-props-file FILE\n" -" same as --cgroup-props, but taking description\n" -" from the path specified\n" -" --cgroup-dump-controller NAME\n" -" define cgroup controller to be dumped\n" -" and skip anything else present in system\n" -" --cgroup-yard PATH\n" -" instead of trying to mount cgroups in CRIU, provide\n" -" a path to a directory with already created cgroup yard.\n" -" Useful if you don't want to grant CAP_SYS_ADMIN to CRIU\n" -" --lsm-profile TYPE:NAME\n" -" Specify an LSM profile to be used during restore.\n" -" The type can be either 'apparmor' or 'selinux'.\n" -" --lsm-mount-context CTX\n" -" Specify a mount context to be used during restore.\n" -" Only mounts with an existing context will have their\n" -" mount context replaced with CTX.\n" -" --skip-mnt PATH ignore this mountpoint when dumping the mount namespace\n" -" --enable-fs FSNAMES a comma separated list of filesystem names or \"all\"\n" -" force criu to (try to) dump/restore these filesystem's\n" -" mountpoints even if fs is not supported\n" -" --inherit-fd fd[NUM]:RES\n" -" Inherit file descriptors, treating fd NUM as being\n" -" already opened via an existing RES, which can be:\n" -" tty[rdev:dev]\n" -" pipe[inode]\n" -" socket[inode]\n" -" file[mnt_id:inode]\n" -" /memfd:name\n" -" path/to/file\n" -" --empty-ns net Create a namespace, but don't restore its properties\n" -" (assuming it will be restored by action scripts)\n" -" -J|--join-ns NS:{PID|NS_FILE}[,OPTIONS]\n" -" Join existing namespace and restore process in it.\n" -" Namespace can be specified as either pid or file path.\n" -" OPTIONS can be used to specify parameters for userns:\n" -" user:PID,UID,GID\n" -" --file-validation METHOD\n" -" pass the validation method to be used; argument\n" -" can be 'filesize' or 'buildid' (default).\n" -"\n" -"Check options:\n" -" Without options, \"criu check\" checks availability of absolutely required\n" -" kernel features, critical for performing dump and restore.\n" -" --extra add check for extra kernel features\n" -" --experimental add check for experimental kernel features\n" -" --all same as --extra --experimental\n" -" --feature FEAT only check a particular feature, one of:" - ); + "Most of the true / false long options (the ones without arguments) can be\n" + "prefixed with --no- to negate the option (example: --display-stats and\n" + "--no-display-stats).\n" + "\n" + "Dump/Restore options:\n" + "\n" + "* Generic:\n" + " -t|--tree PID checkpoint a process tree identified by PID\n" + " -d|--restore-detached detach after restore\n" + " -S|--restore-sibling restore root task as sibling\n" + " -s|--leave-stopped leave tasks in stopped state after checkpoint\n" + " -R|--leave-running leave tasks in running state after checkpoint\n" + " -D|--images-dir DIR directory for image files\n" + " --pidfile FILE write root task, service or page-server pid to FILE\n" + " -W|--work-dir DIR directory to cd and write logs/pidfiles/stats to\n" + " (if not specified, value of --images-dir is used)\n" + " --cpu-cap [CAP] CPU capabilities to write/check. CAP is comma-separated\n" + " list of: cpu, fpu, all, ins, none. To disable\n" + " a capability, use ^CAP. Empty argument implies all\n" + " --exec-cmd execute the command specified after '--' on successful\n" + " restore making it the parent of the restored process\n" + " --freeze-cgroup use cgroup freezer to collect processes\n" + " --weak-sysctls skip restoring sysctls that are not available\n" + " --lazy-pages restore pages on demand\n" + " this requires running a second instance of criu\n" + " in lazy-pages mode: 'criu lazy-pages -D DIR'\n" + " --lazy-pages and lazy-pages mode require userfaultfd\n" + " --stream dump/restore images using criu-image-streamer\n" + "\n" + "* External resources support:\n" + " --external RES dump objects from this list as external resources:\n" + " Formats of RES on dump:\n" + " tty[rdev:dev]\n" + " file[mnt_id:inode]\n" + " dev[major/minor]:NAME\n" + " unix[ino]\n" + " mnt[MOUNTPOINT]:COOKIE\n" + " mnt[]{:AUTO_OPTIONS}\n" + " Formats of RES on restore:\n" + " dev[NAME]:DEVPATH\n" + " veth[IFNAME]:OUTNAME{@BRIDGE}\n" + " macvlan[IFNAME]:OUTNAME\n" + " mnt[COOKIE]:ROOT\n" + " netdev[IFNAME]:ORIGNAME\n" + "\n" + "* Special resources support:\n" + " --" SK_EST_PARAM " checkpoint/restore established TCP connections\n" + " --" SK_INFLIGHT_PARAM " skip (ignore) in-flight TCP connections\n" + " --" SK_CLOSE_PARAM " don't dump the state of, or block, established tcp\n" + " connections, and restore them in closed state.\n" + " -r|--root PATH change the root filesystem (when run in mount namespace)\n" + " --evasive-devices use any path to a device file if the original one\n" + " is inaccessible\n" + " --link-remap allow one to link unlinked files back when possible\n" + " --ghost-limit size limit max size of deleted file contents inside image\n" + " --action-script FILE add an external action script\n" + " -j|--" OPT_SHELL_JOB " allow one to dump and restore shell jobs\n" + " -l|--" OPT_FILE_LOCKS " handle file locks, for safety, only used for container\n" + " -L|--libdir path to a plugin directory (by default " CR_PLUGIN_DEFAULT ")\n" + " --force-irmap force resolving names for inotify/fsnotify watches\n" + " --irmap-scan-path FILE\n" + " add a path the irmap hints to scan\n" + " --manage-cgroups [m] dump/restore process' cgroups; argument can be one of\n" + " 'none', 'props', 'soft' (default), 'full', 'strict'\n" + " or 'ignore'\n" + " --cgroup-root [controller:]/newroot\n" + " on dump: change the root for the controller that will\n" + " be dumped. By default, only the paths with tasks in\n" + " them and below will be dumped.\n" + " on restore: change the root cgroup the controller will\n" + " be installed into. No controller means that root is the\n" + " default for all controllers not specified\n" + " --cgroup-props STRING\n" + " define cgroup controllers and properties\n" + " to be checkpointed, which are described\n" + " via STRING using simplified YAML format\n" + " --cgroup-props-file FILE\n" + " same as --cgroup-props, but taking description\n" + " from the path specified\n" + " --cgroup-dump-controller NAME\n" + " define cgroup controller to be dumped\n" + " and skip anything else present in system\n" + " --cgroup-yard PATH\n" + " instead of trying to mount cgroups in CRIU, provide\n" + " a path to a directory with already created cgroup yard.\n" + " Useful if you don't want to grant CAP_SYS_ADMIN to CRIU\n" + " --lsm-profile TYPE:NAME\n" + " Specify an LSM profile to be used during restore.\n" + " The type can be either 'apparmor' or 'selinux'.\n" + " --lsm-mount-context CTX\n" + " Specify a mount context to be used during restore.\n" + " Only mounts with an existing context will have their\n" + " mount context replaced with CTX.\n" + " --skip-mnt PATH ignore this mountpoint when dumping the mount namespace\n" + " --enable-fs FSNAMES a comma separated list of filesystem names or \"all\"\n" + " force criu to (try to) dump/restore these filesystem's\n" + " mountpoints even if fs is not supported\n" + " --inherit-fd fd[NUM]:RES\n" + " Inherit file descriptors, treating fd NUM as being\n" + " already opened via an existing RES, which can be:\n" + " tty[rdev:dev]\n" + " pipe[inode]\n" + " socket[inode]\n" + " file[mnt_id:inode]\n" + " /memfd:name\n" + " path/to/file\n" + " --empty-ns net Create a namespace, but don't restore its properties\n" + " (assuming it will be restored by action scripts)\n" + " -J|--join-ns NS:{PID|NS_FILE}[,OPTIONS]\n" + " Join existing namespace and restore process in it.\n" + " Namespace can be specified as either pid or file path.\n" + " OPTIONS can be used to specify parameters for userns:\n" + " user:PID,UID,GID\n" + " --file-validation METHOD\n" + " pass the validation method to be used; argument\n" + " can be 'filesize' or 'buildid' (default).\n" + "\n" + "Check options:\n" + " Without options, \"criu check\" checks availability of absolutely required\n" + " kernel features, critical for performing dump and restore.\n" + " --extra add check for extra kernel features\n" + " --experimental add check for experimental kernel features\n" + " --all same as --extra --experimental\n" + " --feature FEAT only check a particular feature, one of:"); pr_check_features(" ", ", ", 80); - pr_msg( -"\n" -"* Logging:\n" -" -o|--log-file FILE log file name\n" -" --log-pid enable per-process logging to separate FILE.pid files\n" -" -v[v...]|--verbosity increase verbosity (can use multiple v)\n" -" -vNUM|--verbosity=NUM set verbosity to NUM (higher level means more output):\n" -" -v1 - only errors and messages\n" -" -v2 - also warnings (default level)\n" -" -v3 - also information messages and timestamps\n" -" -v4 - lots of debug\n" -" --display-stats print out dump/restore stats\n" -"\n" -"* Memory dumping options:\n" -" --track-mem turn on memory changes tracker in kernel\n" -" --prev-images-dir DIR path to images from previous dump (relative to -D)\n" -" --page-server send pages to page server (see options below as well)\n" -" --auto-dedup when used on dump it will deduplicate \"old\" data in\n" -" pages images of previous dump\n" -" when used on restore, as soon as page is restored, it\n" -" will be punched from the image\n" -" --pre-dump-mode splice - parasite based pre-dumping (default)\n" -" read - process_vm_readv syscall based pre-dumping\n" -"\n" -"Page/Service server options:\n" -" --address ADDR address of server or service\n" -" --port PORT port of page server\n" -" --ps-socket FD use specified FD as page server socket\n" -" -d|--daemon run in the background after creating socket\n" -" --status-fd FD write \\0 to the FD and close it once process is ready\n" -" to handle requests\n" -" --tls-cacert FILE trust certificates signed only by this CA\n" -" --tls-cacrl FILE path to CA certificate revocation list file\n" -" --tls-cert FILE path to TLS certificate file\n" -" --tls-key FILE path to TLS private key file\n" -" --tls use TLS to secure remote connection\n" -" --tls-no-cn-verify do not verify common name in server certificate\n" -"\n" -"Configuration file options:\n" -" --config FILEPATH pass a specific configuration file\n" -" --no-default-config forbid usage of default configuration files\n" -"\n" -"Other options:\n" -" -h|--help show this text\n" -" -V|--version show version\n" - ); + pr_msg("\n" + "* Logging:\n" + " -o|--log-file FILE log file name\n" + " --log-pid enable per-process logging to separate FILE.pid files\n" + " -v[v...]|--verbosity increase verbosity (can use multiple v)\n" + " -vNUM|--verbosity=NUM set verbosity to NUM (higher level means more output):\n" + " -v1 - only errors and messages\n" + " -v2 - also warnings (default level)\n" + " -v3 - also information messages and timestamps\n" + " -v4 - lots of debug\n" + " --display-stats print out dump/restore stats\n" + "\n" + "* Memory dumping options:\n" + " --track-mem turn on memory changes tracker in kernel\n" + " --prev-images-dir DIR path to images from previous dump (relative to -D)\n" + " --page-server send pages to page server (see options below as well)\n" + " --auto-dedup when used on dump it will deduplicate \"old\" data in\n" + " pages images of previous dump\n" + " when used on restore, as soon as page is restored, it\n" + " will be punched from the image\n" + " --pre-dump-mode splice - parasite based pre-dumping (default)\n" + " read - process_vm_readv syscall based pre-dumping\n" + "\n" + "Page/Service server options:\n" + " --address ADDR address of server or service\n" + " --port PORT port of page server\n" + " --ps-socket FD use specified FD as page server socket\n" + " -d|--daemon run in the background after creating socket\n" + " --status-fd FD write \\0 to the FD and close it once process is ready\n" + " to handle requests\n" + " --tls-cacert FILE trust certificates signed only by this CA\n" + " --tls-cacrl FILE path to CA certificate revocation list file\n" + " --tls-cert FILE path to TLS certificate file\n" + " --tls-key FILE path to TLS private key file\n" + " --tls use TLS to secure remote connection\n" + " --tls-no-cn-verify do not verify common name in server certificate\n" + "\n" + "Configuration file options:\n" + " --config FILEPATH pass a specific configuration file\n" + " --no-default-config forbid usage of default configuration files\n" + "\n" + "Other options:\n" + " -h|--help show this text\n" + " -V|--version show version\n"); return 0; diff --git a/criu/eventfd.c b/criu/eventfd.c index da31ce9f5..a5d51a189 100644 --- a/criu/eventfd.c +++ b/criu/eventfd.c @@ -22,12 +22,12 @@ #include "protobuf.h" #include "images/eventfd.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "eventfd: " struct eventfd_file_info { - EventfdFileEntry *efe; - struct file_desc d; + EventfdFileEntry *efe; + struct file_desc d; }; /* Checks if file descriptor @lfd is eventfd */ @@ -38,8 +38,7 @@ int is_eventfd_link(char *link) static void pr_info_eventfd(char *action, EventfdFileEntry *efe) { - pr_info("%s: id %#08x flags %#04x counter %#016"PRIx64"\n", - action, efe->id, efe->flags, efe->counter); + pr_info("%s: id %#08x flags %#04x counter %#016" PRIx64 "\n", action, efe->id, efe->flags, efe->counter); } static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p) @@ -63,8 +62,8 @@ static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops eventfd_dump_ops = { - .type = FD_TYPES__EVENTFD, - .dump = dump_one_eventfd, + .type = FD_TYPES__EVENTFD, + .dump = dump_one_eventfd, }; static int eventfd_open(struct file_desc *d, int *new_fd) @@ -76,14 +75,12 @@ static int eventfd_open(struct file_desc *d, int *new_fd) tmp = eventfd(info->efe->counter, 0); if (tmp < 0) { - pr_perror("Can't create eventfd %#08x", - info->efe->id); + pr_perror("Can't create eventfd %#08x", info->efe->id); return -1; } if (rst_file_params(tmp, info->efe->fown, info->efe->flags)) { - pr_perror("Can't restore params on eventfd %#08x", - info->efe->id); + pr_perror("Can't restore params on eventfd %#08x", info->efe->id); goto err_close; } diff --git a/criu/eventpoll.c b/criu/eventpoll.c index 9818f24dd..978dca5be 100644 --- a/criu/eventpoll.c +++ b/criu/eventpoll.c @@ -30,33 +30,33 @@ #include "protobuf.h" #include "images/eventpoll.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "epoll: " static LIST_HEAD(dinfo_list); typedef struct { - uint32_t tfd; - uint32_t off; - uint32_t idx; + uint32_t tfd; + uint32_t off; + uint32_t idx; } toff_t; struct eventpoll_dinfo { - struct list_head list; + struct list_head list; - FileEntry *fe; - EventpollFileEntry *e; + FileEntry *fe; + EventpollFileEntry *e; - toff_t *toff; - FownEntry fown; + toff_t *toff; + FownEntry fown; - pid_t pid; - int efd; + pid_t pid; + int efd; }; struct eventpoll_file_info { - EventpollFileEntry *efe; - struct file_desc d; + EventpollFileEntry *efe; + struct file_desc d; }; /* Checks if file descriptor @lfd is eventfd */ @@ -67,8 +67,8 @@ int is_eventpoll_link(char *link) static void pr_info_eventpoll_tfd(char *action, uint32_t id, EventpollTfdEntry *e) { - pr_info("%seventpoll-tfd: id %#08x tfd %8d events %#08x data %#016"PRIx64"\n", - action, id, e->tfd, e->events, e->data); + pr_info("%seventpoll-tfd: id %#08x tfd %8d events %#08x data %#016" PRIx64 "\n", action, id, e->tfd, e->events, + e->data); } static void pr_info_eventpoll(char *action, EventpollFileEntry *e) @@ -90,16 +90,16 @@ static int queue_dinfo(FileEntry **fe, EventpollFileEntry **e, toff_t **toff, co INIT_LIST_HEAD(&dinfo->list); - dinfo->fe = *fe; - dinfo->e = *e; - dinfo->toff = *toff; - dinfo->e->fown = &dinfo->fown; - dinfo->pid = p->pid; - dinfo->efd = p->fd; + dinfo->fe = *fe; + dinfo->e = *e; + dinfo->toff = *toff; + dinfo->e->fown = &dinfo->fown; + dinfo->pid = p->pid; + dinfo->efd = p->fd; - *fe = NULL; - *e = NULL; - *toff = NULL; + *fe = NULL; + *e = NULL; + *toff = NULL; list_add_tail(&dinfo->list, &dinfo_list); return 0; @@ -133,31 +133,29 @@ int flush_eventpoll_dinfo_queue(void) for (i = 0; i < e->n_tfd; i++) { EventpollTfdEntry *tfde = e->tfd[i]; struct kid_elem ke = { - .pid = dinfo->pid, - .genid = make_gen_id(tfde->dev, - tfde->inode, - tfde->pos), - .idx = tfde->tfd, + .pid = dinfo->pid, + .genid = make_gen_id(tfde->dev, tfde->inode, tfde->pos), + .idx = tfde->tfd, }; kcmp_epoll_slot_t slot = { - .efd = dinfo->efd, - .tfd = tfde->tfd, - .toff = dinfo->toff[i].off, + .efd = dinfo->efd, + .tfd = tfde->tfd, + .toff = dinfo->toff[i].off, }; struct kid_elem *t = kid_lookup_epoll_tfd(&fd_tree, &ke, &slot); if (!t) { - pr_debug("kid_lookup_epoll: no match pid %d efd %d tfd %d toff %u\n", - dinfo->pid, dinfo->efd, tfde->tfd, dinfo->toff[i].off); + pr_debug("kid_lookup_epoll: no match pid %d efd %d tfd %d toff %u\n", dinfo->pid, + dinfo->efd, tfde->tfd, dinfo->toff[i].off); goto err; } - pr_debug("kid_lookup_epoll: rbsearch match pid %d efd %d tfd %d toff %u -> %d\n", - dinfo->pid, dinfo->efd, tfde->tfd, dinfo->toff[i].off, t->idx); + pr_debug("kid_lookup_epoll: rbsearch match pid %d efd %d tfd %d toff %u -> %d\n", dinfo->pid, + dinfo->efd, tfde->tfd, dinfo->toff[i].off, t->idx); /* Make sure the pid matches */ if (t->pid != dinfo->pid) { - pr_debug("kid_lookup_epoll: pid mismatch %d %d efd %d tfd %d toff %u\n", - dinfo->pid, t->pid, dinfo->efd, tfde->tfd, dinfo->toff[i].off); + pr_debug("kid_lookup_epoll: pid mismatch %d %d efd %d tfd %d toff %u\n", dinfo->pid, + t->pid, dinfo->efd, tfde->tfd, dinfo->toff[i].off); goto err; } @@ -218,13 +216,12 @@ static int toff_cmp_idx(const void *a, const void *b) * fds in fd_parms are sorted so we can use binary search * for better performance. */ -static int find_tfd_bsearch(pid_t pid, int efd, int fds[], size_t nr_fds, - int tfd, unsigned int toff) +static int find_tfd_bsearch(pid_t pid, int efd, int fds[], size_t nr_fds, int tfd, unsigned int toff) { kcmp_epoll_slot_t slot = { - .efd = efd, - .tfd = tfd, - .toff = toff, + .efd = efd, + .tfd = tfd, + .toff = toff, }; int *tfd_found; @@ -243,14 +240,13 @@ static int find_tfd_bsearch(pid_t pid, int efd, int fds[], size_t nr_fds, return tfd; } } else { - pr_debug("find_tfd_bsearch (kcmp-no): bsearch match pid %d efd %d tfd %d toff %u\n", - pid, efd, tfd, toff); + pr_debug("find_tfd_bsearch (kcmp-no): bsearch match pid %d efd %d tfd %d toff %u\n", pid, efd, + tfd, toff); return tfd; } } - pr_debug("find_tfd_bsearch: no match pid %d efd %d tfd %d toff %u\n", - pid, efd, tfd, toff); + pr_debug("find_tfd_bsearch: no match pid %d efd %d tfd %d toff %u\n", pid, efd, tfd, toff); return -1; } @@ -272,16 +268,16 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) goto out; file_entry__init(fe); - e->id = id; - e->flags = p->flags; - e->fown = (FownEntry *)&p->fown; + e->id = id; + e->flags = p->flags; + e->fown = (FownEntry *)&p->fown; if (parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, e)) goto out; - fe->type = FD_TYPES__EVENTPOLL; - fe->id = e->id; - fe->epfd = e; + fe->type = FD_TYPES__EVENTPOLL; + fe->id = e->id; + fe->epfd = e; /* * In regular case there is no so many dup'ed @@ -293,9 +289,9 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) if (!toff) goto out; for (i = 0; i < e->n_tfd; i++) { - toff[i].idx = i; - toff[i].tfd = e->tfd[i]->tfd; - toff[i].off = 0; + toff[i].idx = i; + toff[i].tfd = e->tfd[i]->tfd; + toff[i].off = 0; } qsort(toff, e->n_tfd, sizeof(*toff), toff_cmp); @@ -317,14 +313,13 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) */ if (p->dfds) { for (i = 0; i < e->n_tfd; i++) { - int tfd = find_tfd_bsearch(p->pid, p->fd, p->dfds->fds, - p->dfds->nr_fds, e->tfd[i]->tfd, toff[i].off); + int tfd = find_tfd_bsearch(p->pid, p->fd, p->dfds->fds, p->dfds->nr_fds, e->tfd[i]->tfd, + toff[i].off); if (tfd == -1) { if (kdat.has_kcmp_epoll_tfd) { ret = queue_dinfo(&fe, &e, &toff, p); } else { - pr_err("Escaped/closed fd descriptor %d on pid %d\n", - e->tfd[i]->tfd, p->pid); + pr_err("Escaped/closed fd descriptor %d on pid %d\n", e->tfd[i]->tfd, p->pid); } goto out; } @@ -352,8 +347,8 @@ out: } const struct fdtype_ops eventpoll_dump_ops = { - .type = FD_TYPES__EVENTPOLL, - .dump = dump_one_eventpoll, + .type = FD_TYPES__EVENTPOLL, + .dump = dump_one_eventpoll, }; static int eventpoll_post_open(struct file_desc *d, int fd); @@ -373,14 +368,12 @@ static int eventpoll_open(struct file_desc *d, int *new_fd) tmp = epoll_create(1); if (tmp < 0) { - pr_perror("Can't create epoll %#08x", - info->efe->id); + pr_perror("Can't create epoll %#08x", info->efe->id); return -1; } if (rst_file_params(tmp, info->efe->fown, info->efe->flags)) { - pr_perror("Can't restore file params on epoll %#08x", - info->efe->id); + pr_perror("Can't restore file params on epoll %#08x", info->efe->id); goto err_close; } @@ -418,8 +411,8 @@ static int eventpoll_retore_tfd(int fd, int id, EventpollTfdEntry *tdefe) pr_info_eventpoll_tfd("Restore ", id, tdefe); - event.events = tdefe->events; - event.data.u64 = tdefe->data; + event.events = tdefe->events; + event.data.u64 = tdefe->data; if (epoll_ctl(fd, EPOLL_CTL_ADD, tdefe->tfd, &event)) { pr_perror("Can't add event on %#08x", id); return -1; @@ -448,8 +441,8 @@ static int eventpoll_post_open(struct file_desc *d, int fd) } static struct file_desc_ops desc_ops = { - .type = FD_TYPES__EVENTPOLL, - .open = eventpoll_open, + .type = FD_TYPES__EVENTPOLL, + .open = eventpoll_open, }; static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg, struct cr_img *i) @@ -484,10 +477,10 @@ static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg, struct cr_img * } struct collect_image_info epoll_tfd_cinfo = { - .fd_type = CR_FD_EVENTPOLL_TFD, - .pb_type = PB_EVENTPOLL_TFD, - .collect = collect_one_epoll_tfd, - .flags = COLLECT_NOFREE, + .fd_type = CR_FD_EVENTPOLL_TFD, + .pb_type = PB_EVENTPOLL_TFD, + .collect = collect_one_epoll_tfd, + .flags = COLLECT_NOFREE, }; static int collect_one_epoll(void *o, ProtobufCMessage *msg, struct cr_img *i) @@ -500,8 +493,8 @@ static int collect_one_epoll(void *o, ProtobufCMessage *msg, struct cr_img *i) } struct collect_image_info epoll_cinfo = { - .fd_type = CR_FD_EVENTPOLL_FILE, - .pb_type = PB_EVENTPOLL_FILE, - .priv_size = sizeof(struct eventpoll_file_info), - .collect = collect_one_epoll, + .fd_type = CR_FD_EVENTPOLL_FILE, + .pb_type = PB_EVENTPOLL_FILE, + .priv_size = sizeof(struct eventpoll_file_info), + .collect = collect_one_epoll, }; diff --git a/criu/fdstore.c b/criu/fdstore.c index 40c4b90cd..77935484f 100644 --- a/criu/fdstore.c +++ b/criu/fdstore.c @@ -16,7 +16,7 @@ static struct fdstore_desc { int next_id; mutex_t lock; /* to protect a peek offset */ -} *desc; +} * desc; int fdstore_init(void) { @@ -54,7 +54,7 @@ int fdstore_init(void) } addr.sun_family = AF_UNIX; - addrlen = snprintf(addr.sun_path, sizeof(addr.sun_path), "X/criu-fdstore-%"PRIx64, st.st_ino); + addrlen = snprintf(addr.sun_path, sizeof(addr.sun_path), "X/criu-fdstore-%" PRIx64, st.st_ino); addrlen += sizeof(addr.sun_family); addr.sun_path[0] = 0; @@ -66,12 +66,12 @@ int fdstore_init(void) * a queue and remember its sequence number. Then we can set SO_PEEK_OFF * to get a file descriptor without dequeuing it. */ - if (bind(sk, (struct sockaddr *) &addr, addrlen)) { + if (bind(sk, (struct sockaddr *)&addr, addrlen)) { pr_perror("Unable to bind a socket"); close(sk); return -1; } - if (connect(sk, (struct sockaddr *) &addr, addrlen)) { + if (connect(sk, (struct sockaddr *)&addr, addrlen)) { pr_perror("Unable to connect a socket"); close(sk); return -1; diff --git a/criu/fifo.c b/criu/fifo.c index a26934319..bb291c14e 100644 --- a/criu/fifo.c +++ b/criu/fifo.c @@ -30,14 +30,16 @@ */ struct fifo_info { - struct list_head list; - struct file_desc d; - FifoEntry *fe; - bool restore_data; + struct list_head list; + struct file_desc d; + FifoEntry *fe; + bool restore_data; }; static LIST_HEAD(fifo_head); -static struct pipe_data_dump pd_fifo = { .img_type = CR_FD_FIFO_DATA, }; +static struct pipe_data_dump pd_fifo = { + .img_type = CR_FD_FIFO_DATA, +}; static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p) { @@ -56,13 +58,12 @@ static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p) if (dump_one_reg_file(lfd, rf_id, p)) return -1; - pr_info("Dumping fifo %d with id %#x pipe_id %#x\n", - lfd, id, pipe_id(p)); + pr_info("Dumping fifo %d with id %#x pipe_id %#x\n", lfd, id, pipe_id(p)); - e.id = id; - e.pipe_id = pipe_id(p); - e.has_regf_id = true; - e.regf_id = rf_id; + e.id = id; + e.pipe_id = pipe_id(p); + e.has_regf_id = true; + e.regf_id = rf_id; fe.type = FD_TYPES__FIFO; fe.id = e.id; @@ -75,8 +76,8 @@ static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops fifo_dump_ops = { - .type = FD_TYPES__FIFO, - .dump = dump_one_fifo, + .type = FD_TYPES__FIFO, + .dump = dump_one_fifo, }; static struct pipe_data_rst *pd_hash_fifo[PIPE_DATA_HASH_SIZE]; @@ -105,8 +106,7 @@ static int do_open_fifo(int ns_root_fd, struct reg_file_info *rfi, void *arg) } if (info->restore_data) - if (restore_pipe_data(CR_FD_FIFO_DATA, fake_fifo, - info->fe->pipe_id, pd_hash_fifo)) { + if (restore_pipe_data(CR_FD_FIFO_DATA, fake_fifo, info->fe->pipe_id, pd_hash_fifo)) { close(new_fifo); new_fifo = -1; } @@ -122,8 +122,7 @@ static int open_fifo_fd(struct file_desc *d, int *new_fd) struct file_desc *reg_d; int fd; - reg_d = collect_special_file(info->fe->has_regf_id ? - info->fe->regf_id : info->fe->id); + reg_d = collect_special_file(info->fe->has_regf_id ? info->fe->regf_id : info->fe->id); if (!reg_d) return -1; @@ -135,8 +134,8 @@ static int open_fifo_fd(struct file_desc *d, int *new_fd) } static struct file_desc_ops fifo_desc_ops = { - .type = FD_TYPES__FIFO, - .open = open_fifo_fd, + .type = FD_TYPES__FIFO, + .open = open_fifo_fd, }; static int collect_one_fifo(void *o, ProtobufCMessage *base, struct cr_img *i) @@ -144,8 +143,7 @@ static int collect_one_fifo(void *o, ProtobufCMessage *base, struct cr_img *i) struct fifo_info *info = o, *f; info->fe = pb_msg(base, FifoEntry); - pr_info("Collected fifo entry ID %#x PIPE ID %#x\n", - info->fe->id, info->fe->pipe_id); + pr_info("Collected fifo entry ID %#x PIPE ID %#x\n", info->fe->id, info->fe->pipe_id); /* check who will restore the fifo data */ list_for_each_entry(f, &fifo_head, list) @@ -161,7 +159,6 @@ static int collect_one_fifo(void *o, ProtobufCMessage *base, struct cr_img *i) } return file_desc_add(&info->d, info->fe->id, &fifo_desc_ops); - } struct collect_image_info fifo_cinfo = { diff --git a/criu/file-ids.c b/criu/file-ids.c index 006e47d64..1b9d68888 100644 --- a/criu/file-ids.c +++ b/criu/file-ids.c @@ -21,9 +21,9 @@ DECLARE_KCMP_TREE(fd_tree, KCMP_FILE); -#define FDID_BITS 5 -#define FDID_SIZE (1 << FDID_BITS) -#define FDID_MASK (FDID_SIZE - 1) +#define FDID_BITS 5 +#define FDID_SIZE (1 << FDID_BITS) +#define FDID_MASK (FDID_SIZE - 1) static inline int fdid_hashfn(unsigned int s_dev, unsigned long i_ino) { @@ -63,11 +63,8 @@ static struct fd_id *fd_id_cache_lookup(struct fd_parms *p) struct stat *st = &p->stat; struct fd_id *fi; - for (fi = fd_id_cache[fdid_hashfn(st->st_dev, st->st_ino)]; - fi; fi = fi->n) - if (fi->dev == st->st_dev && - fi->ino == st->st_ino && - fi->mnt_id == p->mnt_id) + for (fi = fd_id_cache[fdid_hashfn(st->st_dev, st->st_ino)]; fi; fi = fi->n) + if (fi->dev == st->st_dev && fi->ino == st->st_ino && fi->mnt_id == p->mnt_id) return fi; return NULL; diff --git a/criu/file-lock.c b/criu/file-lock.c index f6601c974..6334462b6 100644 --- a/criu/file-lock.c +++ b/criu/file-lock.c @@ -76,11 +76,10 @@ void free_file_locks(void) static int dump_one_file_lock(FileLockEntry *fle) { - pr_info("LOCK flag: %d,type: %d,pid: %d,fd: %d,start: %8"PRIx64",len: %8"PRIx64"\n", - fle->flag, fle->type, fle->pid, fle->fd, fle->start, fle->len); + pr_info("LOCK flag: %d,type: %d,pid: %d,fd: %d,start: %8" PRIx64 ",len: %8" PRIx64 "\n", fle->flag, fle->type, + fle->pid, fle->fd, fle->start, fle->len); - return pb_write_one(img_from_set(glob_imgset, CR_FD_FILE_LOCKS), - fle, PB_FILE_LOCK); + return pb_write_one(img_from_set(glob_imgset, CR_FD_FILE_LOCKS), fle, PB_FILE_LOCK); } static void fill_flock_entry(FileLockEntry *fle, int fl_kind, int fl_ltype) @@ -91,17 +90,16 @@ static void fill_flock_entry(FileLockEntry *fle, int fl_kind, int fl_ltype) int dump_file_locks(void) { - FileLockEntry fle; + FileLockEntry fle; struct file_lock *fl; - int ret = 0; + int ret = 0; pr_info("Dumping file-locks\n"); list_for_each_entry(fl, &file_lock_list, list) { if (fl->real_owner == -1) { if (fl->fl_kind == FL_POSIX) { - pr_err("Unresolved lock found pid %d ino %ld\n", - fl->fl_owner, fl->i_no); + pr_err("Unresolved lock found pid %d ino %ld\n", fl->fl_owner, fl->i_no); return -1; } @@ -110,7 +108,7 @@ int dump_file_locks(void) if (!opts.handle_file_locks) { pr_err("Some file locks are hold by dumping tasks! " - "You can try --" OPT_FILE_LOCKS " to dump them.\n"); + "You can try --" OPT_FILE_LOCKS " to dump them.\n"); return -1; } @@ -154,7 +152,7 @@ static int lock_btrfs_file_match(pid_t pid, int fd, struct file_lock *fl, struct link[ret] = 0; ns = lookup_nsid_by_mnt_id(p->mnt_id); - return phys_stat_dev_match(p->stat.st_dev, phys_dev, ns, link); + return phys_stat_dev_match(p->stat.st_dev, phys_dev, ns, link); } static inline int lock_file_match(pid_t pid, int fd, struct file_lock *fl, struct fd_parms *p) @@ -224,11 +222,7 @@ static int lock_ofd_check_fd(int lfd, struct file_lock *fl) { int ret; - struct flock lck = { - .l_whence = SEEK_SET, - .l_type = F_WRLCK, - .l_start = fl->start - }; + struct flock lck = { .l_whence = SEEK_SET, .l_type = F_WRLCK, .l_start = fl->start }; if (strcmp(fl->end, "EOF")) { unsigned long end; @@ -366,7 +360,7 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p) if (!opts.handle_file_locks) { pr_err("Some file locks are hold by dumping tasks!" - "You can try --" OPT_FILE_LOCKS " to dump them.\n"); + "You can try --" OPT_FILE_LOCKS " to dump them.\n"); return -1; } @@ -380,8 +374,7 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p) } else if (fl->fl_kind == FL_LEASE) { if (fl->owners_fd >= 0) continue; - if (fl->fl_owner != pid->real && - fl->real_owner != -1) + if (fl->fl_owner != pid->real && fl->real_owner != -1) continue; ret = lease_check_fd(lfd, p->flags, fl); @@ -399,8 +392,7 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p) * anyway. */ - if (fl->fl_owner != pid->real && - fl->real_owner != -1) + if (fl->fl_owner != pid->real && fl->real_owner != -1) continue; pr_debug("Checking lock holder %d:%d\n", pid->real, fd); @@ -419,9 +411,7 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p) fl->real_owner = pid->ns[0].virt; fl->owners_fd = fd; - pr_info("Found lock entry %d.%d %d vs %d\n", - pid->real, pid->ns[0].virt, fd, - fl->fl_owner); + pr_info("Found lock entry %d.%d %d vs %d\n", pid->real, pid->ns[0].virt, fd, fl->fl_owner); } return 0; @@ -450,8 +440,7 @@ int correct_file_leases_type(struct pid *pid, int fd, int lfd) if (fl->fl_holder != pid->real || fl->owners_fd != fd) continue; - if (fl->fl_kind == FL_LEASE && - (fl->fl_ltype & LEASE_BREAKING)) { + if (fl->fl_kind == FL_LEASE && (fl->fl_ltype & LEASE_BREAKING)) { /* * Set lease type to actual 'target lease type' * instead of 'READ' returned by procfs. @@ -538,8 +527,7 @@ static int restore_lease_prebreaking_state(int fd, int fd_type) return set_file_lease(fd, lease_type); } -static struct fdinfo_list_entry *find_fd_unordered(struct pstree_item *task, - int fd) +static struct fdinfo_list_entry *find_fd_unordered(struct pstree_item *task, int fd) { struct list_head *head = &rsti(task)->fds; struct fdinfo_list_entry *fle; @@ -592,9 +580,8 @@ static int restore_file_lease(FileLockEntry *fle) pr_perror("Can't get file i/o signum"); return -1; } - if (sigemptyset(&blockmask) || - sigaddset(&blockmask, signum) || - sigprocmask(SIG_BLOCK, &blockmask, &oldmask)) { + if (sigemptyset(&blockmask) || sigaddset(&blockmask, signum) || + sigprocmask(SIG_BLOCK, &blockmask, &oldmask)) { pr_perror("Can't block file i/o signal"); return -1; } @@ -633,8 +620,8 @@ static int restore_file_lock(FileLockEntry *fle) goto err; } - pr_info("(flock)flag: %d, type: %d, cmd: %d, pid: %d, fd: %d\n", - fle->flag, fle->type, cmd, fle->pid, fle->fd); + pr_info("(flock)flag: %d, type: %d, cmd: %d, pid: %d, fd: %d\n", fle->flag, fle->type, cmd, fle->pid, + fle->fd); ret = flock(fle->fd, cmd); if (ret < 0) { @@ -646,15 +633,14 @@ static int restore_file_lock(FileLockEntry *fle) memset(&flk, 0, sizeof(flk)); flk.l_whence = SEEK_SET; - flk.l_start = fle->start; - flk.l_len = fle->len; - flk.l_pid = fle->pid; - flk.l_type = fle->type; + flk.l_start = fle->start; + flk.l_len = fle->len; + flk.l_pid = fle->pid; + flk.l_type = fle->type; pr_info("(posix)flag: %d, type: %d, pid: %d, fd: %d, " - "start: %8"PRIx64", len: %8"PRIx64"\n", - fle->flag, fle->type, fle->pid, fle->fd, - fle->start, fle->len); + "start: %8" PRIx64 ", len: %8" PRIx64 "\n", + fle->flag, fle->type, fle->pid, fle->fd, fle->start, fle->len); ret = fcntl(fle->fd, F_SETLKW, &flk); if (ret < 0) { @@ -663,17 +649,12 @@ static int restore_file_lock(FileLockEntry *fle) } } else if (fle->flag & FL_OFD) { struct flock flk = { - .l_whence = SEEK_SET, - .l_start = fle->start, - .l_len = fle->len, - .l_pid = 0, - .l_type = fle->type + .l_whence = SEEK_SET, .l_start = fle->start, .l_len = fle->len, .l_pid = 0, .l_type = fle->type }; pr_info("(ofd)flag: %d, type: %d, pid: %d, fd: %d, " - "start: %8"PRIx64", len: %8"PRIx64"\n", - fle->flag, fle->type, fle->pid, fle->fd, - fle->start, fle->len); + "start: %8" PRIx64 ", len: %8" PRIx64 "\n", + fle->flag, fle->type, fle->pid, fle->fd, fle->start, fle->len); ret = fcntl(fle->fd, F_OFD_SETLK, &flk); if (ret < 0) { @@ -682,9 +663,8 @@ static int restore_file_lock(FileLockEntry *fle) } } else if (fle->flag & FL_LEASE) { pr_info("(lease)flag: %d, type: %d, pid: %d, fd: %d, " - "start: %8"PRIx64", len: %8"PRIx64"\n", - fle->flag, fle->type, fle->pid, fle->fd, - fle->start, fle->len); + "start: %8" PRIx64 ", len: %8" PRIx64 "\n", + fle->flag, fle->type, fle->pid, fle->fd, fle->start, fle->len); ret = restore_file_lease(fle); if (ret < 0) goto err; @@ -720,5 +700,4 @@ int prepare_file_locks(int pid) return 0; return restore_file_locks(pid); - } diff --git a/criu/files-ext.c b/criu/files-ext.c index a6247d673..95ec8e37c 100644 --- a/criu/files-ext.c +++ b/criu/files-ext.c @@ -20,8 +20,8 @@ static int dump_one_ext_file(int lfd, u32 id, const struct fd_parms *p) if (ret < 0) return ret; - xfe.id = id; - xfe.fown = (FownEntry *)&p->fown; + xfe.id = id; + xfe.fown = (FownEntry *)&p->fown; fe.type = FD_TYPES__EXT; fe.id = xfe.id; @@ -32,13 +32,13 @@ static int dump_one_ext_file(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops ext_dump_ops = { - .type = FD_TYPES__EXT, - .dump = dump_one_ext_file, + .type = FD_TYPES__EXT, + .dump = dump_one_ext_file, }; struct ext_file_info { - struct file_desc d; - ExtFileEntry *xfe; + struct file_desc d; + ExtFileEntry *xfe; }; static int open_fd(struct file_desc *d, int *new_fd) @@ -83,8 +83,7 @@ struct collect_image_info ext_file_cinfo = { .collect = collect_one_ext, }; -int dump_unsupp_fd(struct fd_parms *p, int lfd, - char *more, char *info, FdinfoEntry *e) +int dump_unsupp_fd(struct fd_parms *p, int lfd, char *more, char *info, FdinfoEntry *e) { int ret; @@ -92,7 +91,6 @@ int dump_unsupp_fd(struct fd_parms *p, int lfd, if (ret == 0) return 0; if (ret == -ENOTSUP) - pr_err("Can't dump file %d of that type [%o] (%s %s)\n", - p->fd, p->stat.st_mode, more, info); + pr_err("Can't dump file %d of that type [%o] (%s %s)\n", p->fd, p->stat.st_mode, more, info); return -1; } diff --git a/criu/files-reg.c b/criu/files-reg.c index d0a6fae60..b4d6f6f9a 100644 --- a/criu/files-reg.c +++ b/criu/files-reg.c @@ -15,12 +15,12 @@ #include <elf.h> #ifndef SEEK_DATA -#define SEEK_DATA 3 -#define SEEK_HOLE 4 +#define SEEK_DATA 3 +#define SEEK_HOLE 4 #endif /* Stolen from kernel/fs/nfs/unlink.c */ -#define SILLYNAME_PREF ".nfs" +#define SILLYNAME_PREF ".nfs" #define SILLYNAME_SUFF_LEN (((unsigned)sizeof(u64) << 1) + ((unsigned)sizeof(unsigned int) << 1)) /* @@ -63,13 +63,13 @@ int setfsgid(gid_t fsuid); * us. Any brave soul to implement link unlinked file back? */ struct ghost_file { - struct list_head list; - u32 id; + struct list_head list; + u32 id; - u32 dev; - u32 ino; + u32 dev; + u32 ino; - struct file_remap remap; + struct file_remap remap; }; static u32 ghost_file_ids = 1; @@ -102,9 +102,9 @@ static LIST_HEAD(remaps); * we keep all data in memory. */ struct link_remap_rlb { - struct list_head list; - struct ns_id *mnt_ns; - char *path; + struct list_head list; + struct ns_id *mnt_ns; + char *path; }; static int note_link_remap(char *path, struct ns_id *nsid) @@ -158,7 +158,7 @@ static int trim_last_parent(char *path) return 0; } -#define BUFSIZE (4096) +#define BUFSIZE (4096) static int copy_chunk_from_file(int fd, int img, off_t off, size_t len) { @@ -369,7 +369,7 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_im } /* Add a '/' only if we have no at the end */ - if (path[root_len-1] != '/') { + if (path[root_len - 1] != '/') { path[root_len++] = '/'; path[root_len] = '\0'; } @@ -429,14 +429,12 @@ err: return ret; } -static inline void ghost_path(char *path, int plen, - struct reg_file_info *rfi, RemapFilePathEntry *rpe) +static inline void ghost_path(char *path, int plen, struct reg_file_info *rfi, RemapFilePathEntry *rpe) { snprintf(path, plen, "%s.cr.%x.ghost", rfi->path, rpe->remap_id); } -static int collect_remap_ghost(struct reg_file_info *rfi, - RemapFilePathEntry *rpe) +static int collect_remap_ghost(struct reg_file_info *rfi, RemapFilePathEntry *rpe) { struct ghost_file *gf; @@ -476,8 +474,7 @@ gf_found: return 0; } -static int open_remap_ghost(struct reg_file_info *rfi, - RemapFilePathEntry *rpe) +static int open_remap_ghost(struct reg_file_info *rfi, RemapFilePathEntry *rpe) { struct ghost_file *gf = container_of(rfi->remap, struct ghost_file, remap); GhostFileEntry *gfe = NULL; @@ -527,8 +524,7 @@ err: return -1; } -static int collect_remap_linked(struct reg_file_info *rfi, - RemapFilePathEntry *rpe) +static int collect_remap_linked(struct reg_file_info *rfi, RemapFilePathEntry *rpe) { struct file_remap *rm; struct file_desc *rdesc; @@ -575,8 +571,7 @@ static int open_remap_linked(struct reg_file_info *rfi) return 0; } -static int collect_remap_dead_process(struct reg_file_info *rfi, - RemapFilePathEntry *rfe) +static int collect_remap_dead_process(struct reg_file_info *rfi, RemapFilePathEntry *rfe) { struct pstree_item *helper; @@ -589,7 +584,6 @@ static int collect_remap_dead_process(struct reg_file_info *rfi, return 0; } - helper->sid = root_item->sid; helper->pgid = root_item->pgid; helper->pid->ns[0].virt = rfe->remap_id; @@ -777,7 +771,7 @@ static struct collect_image_info remap_cinfo = { }; /* Tiny files don't need to generate chunks in ghost image. */ -#define GHOST_CHUNKS_THRESH (3 * 4096) +#define GHOST_CHUNKS_THRESH (3 * 4096) static int dump_ghost_file(int _fd, u32 id, const struct stat *st, dev_t phys_dev) { @@ -841,8 +835,8 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st, dev_t phys_de pathbuf[ret] = 0; if (ret != st->st_size) { - pr_err("Buffer for readlinkat is too small: ret %zd, st_size %"PRId64", buf %u %s\n", - ret, st->st_size, PATH_MAX, pathbuf); + pr_err("Buffer for readlinkat is too small: ret %zd, st_size %" PRId64 ", buf %u %s\n", ret, + st->st_size, PATH_MAX, pathbuf); goto err_out; } @@ -893,8 +887,7 @@ struct file_remap *lookup_ghost_remap(u32 dev, u32 ino) return NULL; } -static int dump_ghost_remap(char *path, const struct stat *st, - int lfd, u32 id, struct ns_id *nsid) +static int dump_ghost_remap(char *path, const struct stat *st, int lfd, u32 id, struct ns_id *nsid) { struct ghost_file *gf; RemapFilePathEntry rpe = REMAP_FILE_PATH_ENTRY__INIT; @@ -903,8 +896,7 @@ static int dump_ghost_remap(char *path, const struct stat *st, pr_info("Dumping ghost file for fd %d id %#x\n", lfd, id); if (st->st_size > opts.ghost_limit) { - pr_err("Can't dump ghost file %s of %"PRIu64" size, increase limit\n", - path, st->st_size); + pr_err("Can't dump ghost file %s of %" PRIu64 " size, increase limit\n", path, st->st_size); return -1; } @@ -934,8 +926,7 @@ dump_entry: rpe.has_remap_type = true; rpe.remap_type = REMAP_TYPE__GHOST; - return pb_write_one(img_from_set(glob_imgset, CR_FD_REMAP_FPATH), - &rpe, PB_REMAP_FPATH); + return pb_write_one(img_from_set(glob_imgset, CR_FD_REMAP_FPATH), &rpe, PB_REMAP_FPATH); } static void __rollback_link_remaps(bool do_unlink) @@ -958,13 +949,17 @@ static void __rollback_link_remaps(bool do_unlink) } } -void delete_link_remaps(void) { __rollback_link_remaps(true); } -void free_link_remaps(void) { __rollback_link_remaps(false); } +void delete_link_remaps(void) +{ + __rollback_link_remaps(true); +} +void free_link_remaps(void) +{ + __rollback_link_remaps(false); +} static int linkat_hard(int odir, char *opath, int ndir, char *npath, uid_t uid, gid_t gid, int flags); -static int create_link_remap(char *path, int len, int lfd, - u32 *idp, struct ns_id *nsid, - const struct stat *st) +static int create_link_remap(char *path, int len, int lfd, u32 *idp, struct ns_id *nsid, const struct stat *st) { char link_name[PATH_MAX], *tmp; FileEntry fe = FILE_ENTRY__INIT; @@ -975,7 +970,8 @@ static int create_link_remap(char *path, int len, int lfd, if (!opts.link_remap_ok) { pr_err("Can't create link remap for %s. " - "Use " LREMAP_PARAM " option.\n", path); + "Use " LREMAP_PARAM " option.\n", + path); return -1; } @@ -997,11 +993,11 @@ static int create_link_remap(char *path, int len, int lfd, } fd_id_generate_special(NULL, idp); - rfe.id = *idp; - rfe.flags = 0; - rfe.pos = 0; - rfe.fown = &fwn; - rfe.name = link_name + 1; + rfe.id = *idp; + rfe.flags = 0; + rfe.pos = 0; + rfe.fown = &fwn; + rfe.name = link_name + 1; /* Any 'unique' name works here actually. Remap works by reg-file ids. */ snprintf(tmp + 1, sizeof(link_name) - (size_t)(tmp - link_name - 1), "link_remap.%d", rfe.id); @@ -1009,8 +1005,7 @@ static int create_link_remap(char *path, int len, int lfd, mntns_root = mntns_get_root_fd(nsid); again: - ret = linkat_hard(lfd, "", mntns_root, link_name, - st->st_uid, st->st_gid, AT_EMPTY_PATH); + ret = linkat_hard(lfd, "", mntns_root, link_name, st->st_uid, st->st_gid, AT_EMPTY_PATH); if (ret < 0 && errno == ENOENT) { /* Use grand parent, if parent directory does not exist. */ if (trim_last_parent(link_name) < 0) { @@ -1033,8 +1028,7 @@ again: return pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE); } -static int dump_linked_remap(char *path, int len, const struct stat *ost, - int lfd, u32 id, struct ns_id *nsid) +static int dump_linked_remap(char *path, int len, const struct stat *ost, int lfd, u32 id, struct ns_id *nsid) { u32 lid; RemapFilePathEntry rpe = REMAP_FILE_PATH_ENTRY__INIT; @@ -1047,8 +1041,7 @@ static int dump_linked_remap(char *path, int len, const struct stat *ost, rpe.has_remap_type = true; rpe.remap_type = REMAP_TYPE__LINKED; - return pb_write_one(img_from_set(glob_imgset, CR_FD_REMAP_FPATH), - &rpe, PB_REMAP_FPATH); + return pb_write_one(img_from_set(glob_imgset, CR_FD_REMAP_FPATH), &rpe, PB_REMAP_FPATH); } static pid_t *dead_pids; @@ -1071,7 +1064,7 @@ int dead_pid_conflict(void) continue; pr_err("Conflict with a dead task with the same PID as of this thread (virt %d, real %d).\n", - node->ns[0].virt, node->real); + node->ns[0].virt, node->real); return -1; } @@ -1112,8 +1105,7 @@ static int dump_dead_process_remap(pid_t pid, u32 id) rpe.has_remap_type = true; rpe.remap_type = REMAP_TYPE__PROCFS; - return pb_write_one(img_from_set(glob_imgset, CR_FD_REMAP_FPATH), - &rpe, PB_REMAP_FPATH); + return pb_write_one(img_from_set(glob_imgset, CR_FD_REMAP_FPATH), &rpe, PB_REMAP_FPATH); } static bool is_sillyrename_name(char *name) @@ -1150,8 +1142,7 @@ static inline bool nfs_silly_rename(char *rpath, const struct fd_parms *parms) return (parms->fs_type == NFS_SUPER_MAGIC) && is_sillyrename_name(rpath); } -static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, - int lfd, u32 id, struct ns_id *nsid) +static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, int lfd, u32 id, struct ns_id *nsid) { char *rpath = link->name; int plen = link->len; @@ -1269,8 +1260,7 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, if (errno == ENOENT) { link_strip_deleted(link); - return dump_linked_remap(rpath + 1, plen - 1, - ost, lfd, id, nsid); + return dump_linked_remap(rpath + 1, plen - 1, ost, lfd, id, nsid); } pr_perror("Can't stat path"); @@ -1278,8 +1268,7 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, } if ((pst.st_ino != ost->st_ino) || (pst.st_dev != ost->st_dev)) { - if (opts.evasive_devices && - (S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) && + if (opts.evasive_devices && (S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) && pst.st_rdev == ost->st_rdev) return 0; /* @@ -1292,9 +1281,8 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, * have the "(deleted)" suffix in proc and name conflict * is unlikely :) */ - pr_err("Unaccessible path opened %u:%u, need %u:%u\n", - (int)pst.st_dev, (int)pst.st_ino, - (int)ost->st_dev, (int)ost->st_ino); + pr_err("Unaccessible path opened %u:%u, need %u:%u\n", (int)pst.st_dev, (int)pst.st_ino, + (int)ost->st_dev, (int)ost->st_ino); return -1; } @@ -1308,8 +1296,7 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, static bool should_check_size(int flags) { /* Skip size if file has O_APPEND and O_WRONLY flags (e.g. log file). */ - if (((flags & O_ACCMODE) == O_WRONLY) && - (flags & O_APPEND)) + if (((flags & O_ACCMODE) == O_WRONLY) && (flags & O_APPEND)) return false; return true; @@ -1320,15 +1307,14 @@ static bool should_check_size(int flags) * Returns the number of bytes of the build-id if it could * be obtained, else -1. */ -static int get_build_id_32(Elf32_Ehdr *file_header, unsigned char **build_id, - const int fd, size_t mapped_size) +static int get_build_id_32(Elf32_Ehdr *file_header, unsigned char **build_id, const int fd, size_t mapped_size) { int size, num_iterations; size_t file_header_end; Elf32_Phdr *program_header, *program_header_end; Elf32_Nhdr *note_header_end, *note_header = NULL; - file_header_end = (size_t) file_header + mapped_size; + file_header_end = (size_t)file_header + mapped_size; if (sizeof(Elf32_Ehdr) > mapped_size) return -1; @@ -1341,11 +1327,11 @@ static int get_build_id_32(Elf32_Ehdr *file_header, unsigned char **build_id, return -1; } - program_header = (Elf32_Phdr *) (file_header->e_phoff + (char *) file_header); - if (program_header <= (Elf32_Phdr *) file_header) + program_header = (Elf32_Phdr *)(file_header->e_phoff + (char *)file_header); + if (program_header <= (Elf32_Phdr *)file_header) return -1; - program_header_end = (Elf32_Phdr *) (file_header_end - sizeof(Elf32_Phdr)); + program_header_end = (Elf32_Phdr *)(file_header_end - sizeof(Elf32_Phdr)); /* * If the file has a build-id, it will be in the PT_NOTE program header @@ -1357,21 +1343,19 @@ static int get_build_id_32(Elf32_Ehdr *file_header, unsigned char **build_id, if (program_header->p_type != PT_NOTE) continue; - note_header = (Elf32_Nhdr *) (program_header->p_offset + (char *) file_header); - if (note_header <= (Elf32_Nhdr *) file_header) { + note_header = (Elf32_Nhdr *)(program_header->p_offset + (char *)file_header); + if (note_header <= (Elf32_Nhdr *)file_header) { note_header = NULL; continue; } - note_header_end = (Elf32_Nhdr *) min_t(char*, - (char *) note_header + program_header->p_filesz, - (char *) (file_header_end - sizeof(Elf32_Nhdr))); + note_header_end = (Elf32_Nhdr *)min_t(char *, (char *)note_header + program_header->p_filesz, + (char *)(file_header_end - sizeof(Elf32_Nhdr))); /* The note type for the build-id is NT_GNU_BUILD_ID. */ while (note_header <= note_header_end && note_header->n_type != NT_GNU_BUILD_ID) - note_header = (Elf32_Nhdr *) ((char *) note_header + sizeof(Elf32_Nhdr) + - ALIGN(note_header->n_namesz, 4) + - ALIGN(note_header->n_descsz, 4)); + note_header = (Elf32_Nhdr *)((char *)note_header + sizeof(Elf32_Nhdr) + + ALIGN(note_header->n_namesz, 4) + ALIGN(note_header->n_descsz, 4)); if (note_header > note_header_end) { note_header = NULL; @@ -1395,17 +1379,16 @@ static int get_build_id_32(Elf32_Ehdr *file_header, unsigned char **build_id, } size = note_header->n_descsz; - note_header = (Elf32_Nhdr *) ((char *) note_header + sizeof(Elf32_Nhdr) + - ALIGN(note_header->n_namesz, 4)); - note_header_end = (Elf32_Nhdr *) (file_header_end - size); - if (note_header <= (Elf32_Nhdr *) file_header || note_header > note_header_end) + note_header = (Elf32_Nhdr *)((char *)note_header + sizeof(Elf32_Nhdr) + ALIGN(note_header->n_namesz, 4)); + note_header_end = (Elf32_Nhdr *)(file_header_end - size); + if (note_header <= (Elf32_Nhdr *)file_header || note_header > note_header_end) return -1; - *build_id = (unsigned char *) xmalloc(size); + *build_id = (unsigned char *)xmalloc(size); if (!*build_id) return -1; - memcpy(*build_id, (void *) note_header, size); + memcpy(*build_id, (void *)note_header, size); return size; } @@ -1414,15 +1397,14 @@ static int get_build_id_32(Elf32_Ehdr *file_header, unsigned char **build_id, * Returns the number of bytes of the build-id if it could * be obtained, else -1. */ -static int get_build_id_64(Elf64_Ehdr *file_header, unsigned char **build_id, - const int fd, size_t mapped_size) +static int get_build_id_64(Elf64_Ehdr *file_header, unsigned char **build_id, const int fd, size_t mapped_size) { int size, num_iterations; size_t file_header_end; Elf64_Phdr *program_header, *program_header_end; Elf64_Nhdr *note_header_end, *note_header = NULL; - file_header_end = (size_t) file_header + mapped_size; + file_header_end = (size_t)file_header + mapped_size; if (sizeof(Elf64_Ehdr) > mapped_size) return -1; @@ -1435,11 +1417,11 @@ static int get_build_id_64(Elf64_Ehdr *file_header, unsigned char **build_id, return -1; } - program_header = (Elf64_Phdr *) (file_header->e_phoff + (char *) file_header); - if (program_header <= (Elf64_Phdr *) file_header) + program_header = (Elf64_Phdr *)(file_header->e_phoff + (char *)file_header); + if (program_header <= (Elf64_Phdr *)file_header) return -1; - program_header_end = (Elf64_Phdr *) (file_header_end - sizeof(Elf64_Phdr)); + program_header_end = (Elf64_Phdr *)(file_header_end - sizeof(Elf64_Phdr)); /* * If the file has a build-id, it will be in the PT_NOTE program header @@ -1451,21 +1433,19 @@ static int get_build_id_64(Elf64_Ehdr *file_header, unsigned char **build_id, if (program_header->p_type != PT_NOTE) continue; - note_header = (Elf64_Nhdr *) (program_header->p_offset + (char *) file_header); - if (note_header <= (Elf64_Nhdr *) file_header) { + note_header = (Elf64_Nhdr *)(program_header->p_offset + (char *)file_header); + if (note_header <= (Elf64_Nhdr *)file_header) { note_header = NULL; continue; } - note_header_end = (Elf64_Nhdr *) min_t(char*, - (char *) note_header + program_header->p_filesz, - (char *) (file_header_end - sizeof(Elf64_Nhdr))); + note_header_end = (Elf64_Nhdr *)min_t(char *, (char *)note_header + program_header->p_filesz, + (char *)(file_header_end - sizeof(Elf64_Nhdr))); /* The note type for the build-id is NT_GNU_BUILD_ID. */ while (note_header <= note_header_end && note_header->n_type != NT_GNU_BUILD_ID) - note_header = (Elf64_Nhdr *) ((char *) note_header + sizeof(Elf64_Nhdr) + - ALIGN(note_header->n_namesz, 4) + - ALIGN(note_header->n_descsz, 4)); + note_header = (Elf64_Nhdr *)((char *)note_header + sizeof(Elf64_Nhdr) + + ALIGN(note_header->n_namesz, 4) + ALIGN(note_header->n_descsz, 4)); if (note_header > note_header_end) { note_header = NULL; @@ -1489,17 +1469,16 @@ static int get_build_id_64(Elf64_Ehdr *file_header, unsigned char **build_id, } size = note_header->n_descsz; - note_header = (Elf64_Nhdr *) ((char *) note_header + sizeof(Elf64_Nhdr) + - ALIGN(note_header->n_namesz, 4)); - note_header_end = (Elf64_Nhdr *) (file_header_end - size); - if (note_header <= (Elf64_Nhdr *) file_header || note_header > note_header_end) + note_header = (Elf64_Nhdr *)((char *)note_header + sizeof(Elf64_Nhdr) + ALIGN(note_header->n_namesz, 4)); + note_header_end = (Elf64_Nhdr *)(file_header_end - size); + if (note_header <= (Elf64_Nhdr *)file_header || note_header > note_header_end) return -1; - *build_id = (unsigned char *) xmalloc(size); + *build_id = (unsigned char *)xmalloc(size); if (!*build_id) return -1; - memcpy(*build_id, (void *) note_header, size); + memcpy(*build_id, (void *)note_header, size); return size; } @@ -1509,15 +1488,14 @@ static int get_build_id_64(Elf64_Ehdr *file_header, unsigned char **build_id, * Returns the number of bytes of the build-id if it could be * obtained, else -1. */ -static int get_build_id(const int fd, const struct stat *fd_status, - unsigned char **build_id) +static int get_build_id(const int fd, const struct stat *fd_status, unsigned char **build_id) { - char buf[SELFMAG+1]; + char buf[SELFMAG + 1]; void *start_addr; size_t mapped_size; int ret = -1; - if (read(fd, buf, SELFMAG+1) != SELFMAG+1) + if (read(fd, buf, SELFMAG + 1) != SELFMAG + 1) return -1; /* @@ -1555,8 +1533,7 @@ static int get_build_id(const int fd, const struct stat *fd_status, * Returns 1 if the build-id of the file could be stored, -1 if there was an error * or 0 if the build-id could not be obtained. */ -static int store_validation_data_build_id(RegFileEntry *rfe, int lfd, - const struct fd_parms *p) +static int store_validation_data_build_id(RegFileEntry *rfe, int lfd, const struct fd_parms *p) { unsigned char *build_id = NULL; int build_id_size, allocated_size; @@ -1567,13 +1544,13 @@ static int store_validation_data_build_id(RegFileEntry *rfe, int lfd, * four (SELFMAG) bytes which should correspond to the ELF magic number * and the next byte which indicates whether the file is 32-bit or 64-bit. */ - if (p->stat.st_size < SELFMAG+1) + if (p->stat.st_size < SELFMAG + 1) return 0; fd = open_proc(PROC_SELF, "fd/%d", lfd); if (fd < 0) { pr_err("Build-ID (For validation) could not be obtained for file %s because can't open the file\n", - rfe->name); + rfe->name); return -1; } @@ -1585,14 +1562,13 @@ static int store_validation_data_build_id(RegFileEntry *rfe, int lfd, allocated_size = round_up(build_id_size, sizeof(uint32_t)); rfe->build_id = xzalloc(allocated_size); if (!rfe->build_id) { - pr_warn("Build-ID (For validation) could not be set for file %s\n", - rfe->name); + pr_warn("Build-ID (For validation) could not be set for file %s\n", rfe->name); xfree(build_id); return -1; } rfe->n_build_id = allocated_size / sizeof(uint32_t); - memcpy(rfe->build_id, (void *) build_id, build_id_size); + memcpy(rfe->build_id, (void *)build_id, build_id_size); xfree(build_id); return 1; @@ -1604,8 +1580,7 @@ static int store_validation_data_build_id(RegFileEntry *rfe, int lfd, * being restored. * Returns true if atleast some metadata was stored, if there was an error it returns false. */ -static bool store_validation_data(RegFileEntry *rfe, - const struct fd_parms *p, int lfd) +static bool store_validation_data(RegFileEntry *rfe, const struct fd_parms *p, int lfd) { int result = 1; @@ -1619,8 +1594,7 @@ static bool store_validation_data(RegFileEntry *rfe, return false; if (!result) - pr_info("Only file size could be stored for validation for file %s\n", - rfe->name); + pr_info("Only file size could be stored for validation for file %s\n", rfe->name); return true; } @@ -1641,9 +1615,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) } else link = p->link; - - - snprintf(ext_id, sizeof(ext_id), "file[%x:%"PRIx64"]", p->mnt_id, p->stat.st_ino); + snprintf(ext_id, sizeof(ext_id), "file[%x:%" PRIx64 "]", p->mnt_id, p->stat.st_ino); if (external_lookup_id(ext_id)) { /* the first symbol will be cut on restore to get an relative path*/ rfe.name = xstrdup(ext_id); @@ -1654,8 +1626,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) mi = lookup_mnt_id(p->mnt_id); if (mi == NULL) { - pr_err("Can't lookup mount=%d for fd=%d path=%s\n", - p->mnt_id, p->fd, link->name + 1); + pr_err("Can't lookup mount=%d for fd=%d path=%s\n", p->mnt_id, p->fd, link->name + 1); return -1; } @@ -1669,8 +1640,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) rfe.has_mnt_id = true; } - pr_info("Dumping path for %d fd via self %d [%s]\n", - p->fd, lfd, &link->name[1]); + pr_info("Dumping path for %d fd via self %d [%s]\n", p->fd, lfd, &link->name[1]); /* * The regular path we can handle should start with slash. @@ -1682,17 +1652,16 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) if (check_path_remap(link, p, lfd, id, mi->nsid)) return -1; - rfe.name = &link->name[1]; + rfe.name = &link->name[1]; ext: - rfe.id = id; - rfe.flags = p->flags; - rfe.pos = p->pos; - rfe.fown = (FownEntry *)&p->fown; - rfe.has_mode = true; - rfe.mode = p->stat.st_mode; + rfe.id = id; + rfe.flags = p->flags; + rfe.pos = p->pos; + rfe.fown = (FownEntry *)&p->fown; + rfe.has_mode = true; + rfe.mode = p->stat.st_mode; - if (S_ISREG(p->stat.st_mode) && should_check_size(rfe.flags) && - !store_validation_data(&rfe, p, lfd)) + if (S_ISREG(p->stat.st_mode) && should_check_size(rfe.flags) && !store_validation_data(&rfe, p, lfd)) return -1; fe.type = FD_TYPES__REG; @@ -1709,13 +1678,11 @@ ext: } const struct fdtype_ops regfile_dump_ops = { - .type = FD_TYPES__REG, - .dump = dump_one_reg_file, + .type = FD_TYPES__REG, + .dump = dump_one_reg_file, }; -static void convert_path_from_another_mp(char *src, char *dst, int dlen, - struct mount_info *smi, - struct mount_info *dmi) +static void convert_path_from_another_mp(char *src, char *dst, int dlen, struct mount_info *smi, struct mount_info *dmi) { int off; @@ -1732,10 +1699,7 @@ static void convert_path_from_another_mp(char *src, char *dst, int dlen, * Absolute path to the mount point + difference between source * and destination roots + path relative to the mountpoint. */ - snprintf(dst, dlen, "./%s/%s/%s", - dmi->ns_mountpoint + 1, - smi->root + strlen(dmi->root), - src + off); + snprintf(dst, dlen, "./%s/%s/%s", dmi->ns_mountpoint + 1, smi->root + strlen(dmi->root), src + off); } static int linkat_hard(int odir, char *opath, int ndir, char *npath, uid_t uid, gid_t gid, int flags) @@ -1749,7 +1713,7 @@ static int linkat_hard(int odir, char *opath, int ndir, char *npath, uid_t uid, if (ret == 0) return 0; - if (!( (errno == EPERM || errno == EOVERFLOW) && (root_ns_mask & CLONE_NEWUSER) )) { + if (!((errno == EPERM || errno == EOVERFLOW) && (root_ns_mask & CLONE_NEWUSER))) { errno_save = errno; pr_warn("Can't link %s -> %s\n", opath, npath); errno = errno_save; @@ -1964,8 +1928,7 @@ out_root: if (*level < 0) return -1; - if (linkat_hard(mntns_root, rpath, mntns_root, path, - rfi->remap->uid, rfi->remap->gid, 0) < 0) { + if (linkat_hard(mntns_root, rpath, mntns_root, path, rfi->remap->uid, rfi->remap->gid, 0) < 0) { int errno_saved = errno; rm_parent_dirs(mntns_root, path, *level); errno = errno_saved; @@ -1981,8 +1944,7 @@ out_root: * while dumping, -1 if there is a mismatch or 0 if the build-id has not been * stored or could not be obtained. */ -static int validate_with_build_id(const int fd, const struct stat *fd_status, - const struct reg_file_info *rfi) +static int validate_with_build_id(const int fd, const struct stat *fd_status, const struct reg_file_info *rfi) { unsigned char *build_id; int build_id_size; @@ -2000,8 +1962,7 @@ static int validate_with_build_id(const int fd, const struct stat *fd_status, if (round_up(build_id_size, sizeof(uint32_t)) != rfi->rfe->n_build_id * sizeof(uint32_t)) { pr_err("File %s has bad build-ID length %d (expect %d)\n", rfi->path, - round_up(build_id_size, sizeof(uint32_t)), - (int) (rfi->rfe->n_build_id * sizeof(uint32_t))); + round_up(build_id_size, sizeof(uint32_t)), (int)(rfi->rfe->n_build_id * sizeof(uint32_t))); xfree(build_id); return -1; } @@ -2024,14 +1985,13 @@ static int validate_with_build_id(const int fd, const struct stat *fd_status, * Returns true if the metadata of the file matches the metadata stored while * dumping else returns false. */ -static bool validate_file(const int fd, const struct stat *fd_status, - const struct reg_file_info *rfi) +static bool validate_file(const int fd, const struct stat *fd_status, const struct reg_file_info *rfi) { int result = 1; if (rfi->rfe->has_size && (fd_status->st_size != rfi->rfe->size)) { - pr_err("File %s has bad size %"PRIu64" (expect %"PRIu64")\n", - rfi->path, fd_status->st_size, rfi->rfe->size); + pr_err("File %s has bad size %" PRIu64 " (expect %" PRIu64 ")\n", rfi->path, fd_status->st_size, + rfi->rfe->size); return false; } @@ -2042,13 +2002,11 @@ static bool validate_file(const int fd, const struct stat *fd_status, return false; if (!result) - pr_info("File %s could only be validated with file size\n", - rfi->path); + pr_info("File %s could only be validated with file size\n", rfi->path); return true; } -int open_path(struct file_desc *d, - int(*open_cb)(int mntns_root, struct reg_file_info *, void *), void *arg) +int open_path(struct file_desc *d, int (*open_cb)(int mntns_root, struct reg_file_info *, void *), void *arg) { int tmp, mntns_root, level = 0; struct reg_file_info *rfi; @@ -2095,8 +2053,7 @@ int open_path(struct file_desc *d, static char tmp_path[PATH_MAX]; if (errno != EEXIST) { - pr_perror("Can't link %s -> %s", - rfi->remap->rpath, rfi->path); + pr_perror("Can't link %s -> %s", rfi->remap->rpath, rfi->path); return -1; } @@ -2132,8 +2089,7 @@ ext: } close_safe(&inh_fd); - if ((rfi->rfe->has_size || rfi->rfe->has_mode) && - !rfi->size_mode_checked) { + if ((rfi->rfe->has_size || rfi->rfe->has_mode) && !rfi->size_mode_checked) { struct stat st; if (fstat(tmp, &st) < 0) { @@ -2145,9 +2101,7 @@ ext: return -1; if (rfi->rfe->has_mode && (st.st_mode != rfi->rfe->mode)) { - pr_err("File %s has bad mode 0%o (expect 0%o)\n", - rfi->path, (int)st.st_mode, - rfi->rfe->mode); + pr_err("File %s has bad mode 0%o (expect 0%o)\n", rfi->path, (int)st.st_mode, rfi->rfe->mode); return -1; } @@ -2211,8 +2165,7 @@ static int do_open_reg(int ns_root_fd, struct reg_file_info *rfi, void *arg) * just ignore positioning at all. */ if (!(rfi->rfe->flags & O_PATH)) { - if (rfi->rfe->pos != -1ULL && - lseek(fd, rfi->rfe->pos, SEEK_SET) < 0) { + if (rfi->rfe->pos != -1ULL && lseek(fd, rfi->rfe->pos, SEEK_SET) < 0) { pr_perror("Can't restore file pos"); close(fd); return -1; @@ -2282,10 +2235,10 @@ static struct filemap_ctx ctx; void filemap_ctx_init(bool auto_close) { - ctx.desc = NULL; /* to fail the first comparison in open_ */ - ctx.fd = -1; /* not to close random fd in _fini */ - ctx.vma = NULL; /* not to put spurious VMA_CLOSE in _fini */ - /* flags may remain any */ + ctx.desc = NULL; /* to fail the first comparison in open_ */ + ctx.fd = -1; /* not to close random fd in _fini */ + ctx.vma = NULL; /* not to put spurious VMA_CLOSE in _fini */ + /* flags may remain any */ ctx.close = auto_close; } @@ -2341,8 +2294,7 @@ int collect_filemap(struct vma_area *vma) if (!vma->e->has_fdflags) { /* Make a wild guess for the fdflags */ vma->e->has_fdflags = true; - if ((vma->e->prot & PROT_WRITE) && - vma_area_is(vma, VMA_FILE_SHARED)) + if ((vma->e->prot & PROT_WRITE) && vma_area_is(vma, VMA_FILE_SHARED)) vma->e->fdflags = O_RDWR; else vma->e->fdflags = O_RDONLY; diff --git a/criu/files.c b/criu/files.c index 1d4ac8941..93754fb44 100644 --- a/criu/files.c +++ b/criu/files.c @@ -57,7 +57,7 @@ #include "plugin.h" -#define FDESC_HASH_SIZE 64 +#define FDESC_HASH_SIZE 64 static struct hlist_head file_desc_hash[FDESC_HASH_SIZE]; /* file_desc's, which fle is not owned by a process, that is able to open them */ static LIST_HEAD(fake_master_head); @@ -78,8 +78,8 @@ void file_desc_init(struct file_desc *d, u32 id, struct file_desc_ops *ops) INIT_LIST_HEAD(&d->fake_master_list); INIT_HLIST_NODE(&d->hash); - d->id = id; - d->ops = ops; + d->id = id; + d->ops = ops; } int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops) @@ -100,8 +100,7 @@ struct file_desc *find_file_desc_raw(int type, u32 id) chain = &file_desc_hash[id % FDESC_HASH_SIZE]; hlist_for_each_entry(d, chain, hash) - if ((d->id == id) && - (d->ops->type == type || type == FD_TYPES__UND)) + if ((d->id == id) && (d->ops->type == type || type == FD_TYPES__UND)) /* * Warning -- old CRIU might generate matching IDs * for different file types! So any code that uses @@ -219,8 +218,7 @@ struct fdinfo_list_entry *try_file_master(struct file_desc *d) if (list_empty(&d->fd_info_head)) return NULL; - return list_first_entry(&d->fd_info_head, - struct fdinfo_list_entry, desc_list); + return list_first_entry(&d->fd_info_head, struct fdinfo_list_entry, desc_list); } struct fdinfo_list_entry *file_master(struct file_desc *d) @@ -229,8 +227,7 @@ struct fdinfo_list_entry *file_master(struct file_desc *d) fle = try_file_master(d); if (!fle) { - pr_err("Empty list on file desc id %#x(%d)\n", d->id, - d->ops ? d->ops->type : -1); + pr_err("Empty list on file desc id %#x(%d)\n", d->id, d->ops ? d->ops->type : -1); BUG(); } @@ -319,16 +316,13 @@ uint32_t make_gen_id(uint32_t st_dev, uint32_t st_ino, uint64_t pos) return st_dev ^ st_ino ^ pos_hi ^ pos_low; } -int do_dump_gen_file(struct fd_parms *p, int lfd, - const struct fdtype_ops *ops, FdinfoEntry *e) +int do_dump_gen_file(struct fd_parms *p, int lfd, const struct fdtype_ops *ops, FdinfoEntry *e) { int ret = -1; - e->type = ops->type; - e->id = make_gen_id((uint32_t)p->stat.st_dev, - (uint32_t)p->stat.st_ino, - (uint64_t)p->pos); - e->fd = p->fd; + e->type = ops->type; + e->id = make_gen_id((uint32_t)p->stat.st_dev, (uint32_t)p->stat.st_ino, (uint64_t)p->pos); + e->fd = p->fd; e->flags = p->fd_flags; ret = fd_id_generate(p->pid, e, p); @@ -361,8 +355,7 @@ int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link) return 0; } -static int fill_fd_params(struct pid *owner_pid, int fd, int lfd, - struct fd_opts *opts, struct fd_parms *p) +static int fill_fd_params(struct pid *owner_pid, int fd, int lfd, struct fd_opts *opts, struct fd_parms *p) { int ret; struct statfs fsbuf; @@ -381,24 +374,24 @@ static int fill_fd_params(struct pid *owner_pid, int fd, int lfd, if (parse_fdinfo_pid(owner_pid->real, fd, FD_TYPES__UND, &fdinfo)) return -1; - p->fs_type = fsbuf.f_type; - p->fd = fd; - p->pos = fdinfo.pos; + p->fs_type = fsbuf.f_type; + p->fd = fd; + p->pos = fdinfo.pos; /* * The kernel artificially adds the O_CLOEXEC flag on the file pointer * flags by looking at the flags on the file descriptor (see kernel * code fs/proc/fd.c). FD_CLOEXEC is a file descriptor property, which * is saved in fd_flags. */ - p->flags = fdinfo.flags & ~O_CLOEXEC; - p->mnt_id = fdinfo.mnt_id; - p->pid = owner_pid->real; - p->fd_flags = opts->flags; + p->flags = fdinfo.flags & ~O_CLOEXEC; + p->mnt_id = fdinfo.mnt_id; + p->pid = owner_pid->real; + p->fd_flags = opts->flags; fown_entry__init(&p->fown); - pr_info("%d fdinfo %d: pos: %#16"PRIx64" flags: %16o/%#x\n", - owner_pid->real, fd, p->pos, p->flags, (int)p->fd_flags); + pr_info("%d fdinfo %d: pos: %#16" PRIx64 " flags: %16o/%#x\n", owner_pid->real, fd, p->pos, p->flags, + (int)p->fd_flags); if (p->flags & O_PATH) ret = 0; @@ -413,10 +406,10 @@ static int fill_fd_params(struct pid *owner_pid, int fd, int lfd, if (opts->fown.pid == 0) return 0; - p->fown.pid = opts->fown.pid; + p->fown.pid = opts->fown.pid; p->fown.pid_type = opts->fown.pid_type; - p->fown.uid = opts->fown.uid; - p->fown.euid = opts->fown.euid; + p->fown.uid = opts->fown.uid; + p->fown.euid = opts->fown.euid; return 0; } @@ -489,9 +482,8 @@ static int dump_chrdev(struct fd_parms *p, int lfd, FdinfoEntry *e) return err; } -static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts, - struct parasite_ctl *ctl, FdinfoEntry *e, - struct parasite_drain_fd *dfds) +static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts, struct parasite_ctl *ctl, + FdinfoEntry *e, struct parasite_drain_fd *dfds) { struct fd_parms p = FD_PARMS_INIT; const struct fdtype_ops *ops; @@ -550,8 +542,7 @@ static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts, return do_dump_gen_file(&p, lfd, ops, e); } - if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode) || - S_ISLNK(p.stat.st_mode)) { + if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode) || S_ISLNK(p.stat.st_mode)) { if (fill_fdlink(lfd, &p, &link)) return -1; @@ -606,14 +597,13 @@ int dump_my_file(int lfd, u32 *id, int *type) return 0; } -int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, - struct parasite_drain_fd *dfds) +int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, struct parasite_drain_fd *dfds) { int *lfds = NULL; struct cr_img *img = NULL; struct fd_opts *opts = NULL; int i, ret = -1; - int off, nr_fds = min((int) PARASITE_MAX_FDS, dfds->nr_fds); + int off, nr_fds = min((int)PARASITE_MAX_FDS, dfds->nr_fds); pr_info("\n"); pr_info("Dumping opened files (pid: %d)\n", item->pid->real); @@ -636,16 +626,14 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, if (nr_fds + off > dfds->nr_fds) nr_fds = dfds->nr_fds - off; - ret = parasite_drain_fds_seized(ctl, dfds, nr_fds, - off, lfds, opts); + ret = parasite_drain_fds_seized(ctl, dfds, nr_fds, off, lfds, opts); if (ret) goto err; for (i = 0; i < nr_fds; i++) { FdinfoEntry e = FDINFO_ENTRY__INIT; - ret = dump_one_file(item->pid, dfds->fds[i + off], - lfds[i], opts + i, ctl, &e, dfds); + ret = dump_one_file(item->pid, dfds->fds[i + off], lfds[i], opts + i, ctl, &e, dfds); if (ret) break; @@ -810,8 +798,7 @@ static void __collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_des list_add(&new_le->desc_list, &le->desc_list); } -static void collect_desc_fle(struct fdinfo_list_entry *new_le, - struct file_desc *fdesc, bool force_master) +static void collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc *fdesc, bool force_master) { new_le->desc = fdesc; @@ -823,9 +810,8 @@ static void collect_desc_fle(struct fdinfo_list_entry *new_le, } } -struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e, - struct rst_info *rst_info, struct file_desc *fdesc, - bool fake, bool force_master) +struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e, struct rst_info *rst_info, struct file_desc *fdesc, + bool fake, bool force_master) { struct fdinfo_list_entry *new_le; @@ -843,8 +829,7 @@ int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake) { struct file_desc *fdesc; - pr_info("Collect fdinfo pid=%d fd=%d id=%#x\n", - pid, e->fd, e->id); + pr_info("Collect fdinfo pid=%d fd=%d id=%#x\n", pid, e->fd, e->id); fdesc = find_file_desc(e); if (fdesc == NULL) { @@ -868,15 +853,14 @@ FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags) fdinfo_entry__init(e); - e->id = old->id; - e->type = old->type; - e->fd = fd; - e->flags = flags; + e->id = old->id; + e->type = old->type; + e->fd = fd; + e->flags = flags; return e; } -int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple, - int fd, unsigned flags) +int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple, int fd, unsigned flags) { FdinfoEntry *e; @@ -952,7 +936,8 @@ int set_fd_flags(int fd, int flags) if (ret != flags) { pr_err("fcntl call on fd %d (flags %#o) succeeded, " - "but some flags were dropped: %#o\n", fd, flags, ret); + "but some flags were dropped: %#o\n", + fd, flags, ret); return -1; } return 0; @@ -1134,7 +1119,7 @@ static int open_fd(struct fdinfo_list_entry *fle) flem = file_master(d); if (fle != flem) { - BUG_ON (fle->stage != FLE_INITIALIZED); + BUG_ON(fle->stage != FLE_INITIALIZED); ret = receive_fd(fle); if (ret != 0) return ret; @@ -1212,8 +1197,7 @@ static int open_fdinfos(struct pstree_item *me) BUG_ON(st == FLE_RESTORED); ret = open_fd(fle); if (ret == -1) { - pr_err("Unable to open fd=%d id=%#x\n", - fle->fe->fd, fle->fe->id); + pr_err("Unable to open fd=%d id=%#x\n", fle->fe->fd, fle->fe->id); goto splice; } if (st != fle->stage || ret == 0) @@ -1231,7 +1215,7 @@ static int open_fdinfos(struct pstree_item *me) list_add(&fle->ps_list, &fake); } if (ret == 1) - again = true; + again = true; } if (!progress && again) wait_fds_event(); @@ -1501,8 +1485,8 @@ int shared_fdt_prepare(struct pstree_item *item) struct inherit_fd { struct list_head inh_list; - char *inh_id; /* file identifier */ - int inh_fd; /* criu's descriptor to inherit */ + char *inh_id; /* file identifier */ + int inh_fd; /* criu's descriptor to inherit */ int inh_fd_id; }; @@ -1541,8 +1525,7 @@ int inherit_fd_parse(char *optarg) if (dbg) { n = strlen(cp); if (write(fd, cp, n) != n) { - pr_err("Can't write debug message %s to inherit fd %d\n", - cp, fd); + pr_err("Can't write debug message %s to inherit fd %d\n", cp, fd); return -1; } return 0; @@ -1586,8 +1569,7 @@ void inherit_fd_log(void) struct inherit_fd *inh; list_for_each_entry(inh, &opts.inherit_fds, inh_list) { - pr_info("File %s will be restored from inherit fd %d\n", - inh->inh_id, inh->inh_fd); + pr_info("File %s will be restored from inherit fd %d\n", inh->inh_id, inh->inh_fd); } } @@ -1617,8 +1599,7 @@ int inherit_fd_lookup_id(char *id) list_for_each_entry(inh, &opts.inherit_fds, inh_list) { if (!strcmp(inh->inh_id, id)) { ret = fdstore_get(inh->inh_fd_id); - pr_debug("Found id %s (fd %d) in inherit fd list\n", - id, ret); + pr_debug("Found id %s (fd %d) in inherit fd list\n", id, ret); break; } } @@ -1643,7 +1624,8 @@ bool inherited_fd(struct file_desc *d, int *fd_p) *fd_p = i_fd; pr_info("File %s will be restored from fd %d dumped " - "from inherit fd %d\n", id_str, *fd_p, i_fd); + "from inherit fd %d\n", + id_str, *fd_p, i_fd); return true; } @@ -1673,8 +1655,7 @@ out: return ret; } -static int collect_one_file_entry(FileEntry *fe, u_int32_t id, ProtobufCMessage *base, - struct collect_image_info *cinfo) +static int collect_one_file_entry(FileEntry *fe, u_int32_t id, ProtobufCMessage *base, struct collect_image_info *cinfo) { if (fe->id != id) { pr_err("ID mismatch %u != %u\n", fe->id, id); diff --git a/criu/filesystems.c b/criu/filesystems.c index 94d348a8e..ee766a2f4 100644 --- a/criu/filesystems.c +++ b/criu/filesystems.c @@ -44,7 +44,6 @@ static int binfmt_misc_parse_or_collect(struct mount_info *pm) { opts.has_binfmt_misc = true; return 0; - } static int binfmt_misc_virtual(struct mount_info *pm) @@ -78,13 +77,13 @@ static int parse_binfmt_misc_entry(struct bfd *f, BinfmtMiscEntry *bme) continue; } -#define DUP_EQUAL_AS(key, member) \ - if (!strncmp(str, key, strlen(key))) { \ - bme->member = xstrdup(str + strlen(key)); \ - if (!bme->member) \ - return -1; \ - continue; \ - } +#define DUP_EQUAL_AS(key, member) \ + if (!strncmp(str, key, strlen(key))) { \ + bme->member = xstrdup(str + strlen(key)); \ + if (!bme->member) \ + return -1; \ + continue; \ + } DUP_EQUAL_AS("interpreter ", interpreter) DUP_EQUAL_AS("flags: ", flags) DUP_EQUAL_AS("extension .", extension) @@ -130,7 +129,6 @@ err: free(bme.mask); bclose(&f); return ret; - } static int binfmt_misc_dump(struct mount_info *pm) @@ -192,7 +190,7 @@ out: static int write_binfmt_misc_entry(char *mp, char *buf, BinfmtMiscEntry *bme) { int fd, len, ret = -1; - char path[PATH_MAX+1]; + char path[PATH_MAX + 1]; snprintf(path, PATH_MAX, "%s/register", mp); @@ -243,9 +241,9 @@ static int make_bfmtm_magic_str(char *buf, BinfmtMiscEntry *bme) * dump them without changes. But for registering a new entry * it expects every byte is prepended with \x, i.e. \x61\x62\x63. */ - len = strlen(bme->name) + 3 /* offset < 128 */ + 2 * strlen(bme->magic) - + (bme->mask ? 2 * strlen(bme->mask) : 0) + strlen(bme->interpreter) - + (bme->flags ? strlen(bme->flags) : 0) + strlen(":::::::"); + len = strlen(bme->name) + 3 /* offset < 128 */ + 2 * strlen(bme->magic) + + (bme->mask ? 2 * strlen(bme->mask) : 0) + strlen(bme->interpreter) + + (bme->flags ? strlen(bme->flags) : 0) + strlen(":::::::"); if ((len > BINFMT_MISC_STR - 1) || bme->offset > 128) return -1; @@ -264,7 +262,7 @@ static int make_bfmtm_magic_str(char *buf, BinfmtMiscEntry *bme) buf += sprintf(buf, "\\x%c%c", bme->mask[i], bme->mask[i + 1]); } - sprintf(buf, ":%s:%s", bme->interpreter, bme->flags ? : "\0"); + sprintf(buf, ":%s:%s", bme->interpreter, bme->flags ?: "\0"); return 1; } @@ -281,9 +279,8 @@ static int binfmt_misc_restore_bme(struct mount_info *mi, BinfmtMiscEntry *bme, ret = make_bfmtm_magic_str(buf, bme); } else if (bme->extension) { /* :name:E::extension::interpreter:flags */ - ret = snprintf(buf, BINFMT_MISC_STR, ":%s:E::%s::%s:%s", - bme->name, bme->extension, bme->interpreter, - bme->flags ? : "\0"); + ret = snprintf(buf, BINFMT_MISC_STR, ":%s:E::%s::%s:%s", bme->name, bme->extension, bme->interpreter, + bme->flags ?: "\0"); if (ret >= BINFMT_MISC_STR) /* output truncated */ ret = -1; } else @@ -374,8 +371,8 @@ int collect_binfmt_misc(void) return collect_image(&binfmt_misc_cinfo); } #else -#define binfmt_misc_dump NULL -#define binfmt_misc_restore NULL +#define binfmt_misc_dump NULL +#define binfmt_misc_restore NULL #define binfmt_misc_parse_or_collect NULL #endif @@ -419,17 +416,11 @@ static int tmpfs_dump(struct mount_info *pm) if (root_ns_mask & CLONE_NEWUSER) userns_pid = root_item->pid->real; - ret = cr_system_userns(fd, img_raw_fd(img), -1, "tar", (char *[]) - { "tar", "--create", - "--gzip", - "--no-unquote", - "--no-wildcards", - "--one-file-system", - "--check-links", - "--preserve-permissions", - "--sparse", - "--numeric-owner", - "--directory", "/proc/self/fd/0", ".", NULL }, 0, userns_pid); + ret = cr_system_userns(fd, img_raw_fd(img), -1, "tar", + (char *[]){ "tar", "--create", "--gzip", "--no-unquote", "--no-wildcards", + "--one-file-system", "--check-links", "--preserve-permissions", "--sparse", + "--numeric-owner", "--directory", "/proc/self/fd/0", ".", NULL }, + 0, userns_pid); if (ret) pr_err("Can't dump tmpfs content\n"); @@ -460,9 +451,9 @@ static int tmpfs_restore(struct mount_info *pm) } ret = cr_system(img_raw_fd(img), -1, -1, "tar", - (char *[]) {"tar", "--extract", "--gzip", - "--no-unquote", "--no-wildcards", - "--directory", pm->mountpoint, NULL}, 0); + (char *[]){ "tar", "--extract", "--gzip", "--no-unquote", "--no-wildcards", "--directory", + pm->mountpoint, NULL }, + 0); close_image(img); if (ret) { @@ -556,8 +547,7 @@ static int fusectl_dump(struct mount_info *pm) } for (it = mntinfo; it; it = it->next) { - if (it->fstype->code == FSTYPE__FUSE && - id == kdev_minor(it->s_dev) && !it->external) { + if (it->fstype->code == FSTYPE__FUSE && id == kdev_minor(it->s_dev) && !it->external) { pr_err("%s is a fuse mount but not external\n", it->mountpoint); goto out; } @@ -588,8 +578,7 @@ static int tracefs_parse(struct mount_info *pm) static bool cgroup_sb_equal(struct mount_info *a, struct mount_info *b) { - if (a->private && b->private && - strcmp(a->private, b->private)) + if (a->private && b->private && strcmp(a->private, b->private)) return false; if (strcmp(a->options, b->options)) return false; @@ -670,8 +659,7 @@ static int dump_empty_fs(struct mount_info *pm) */ static int always_fail(struct mount_info *pm) { - pr_err("failed to dump fs %s (%s): always fail\n", pm->mountpoint, - pm->fstype->name); + pr_err("failed to dump fs %s (%s): always fail\n", pm->mountpoint, pm->fstype->name); return -1; } @@ -679,92 +667,113 @@ static struct fstype fstypes[] = { { .name = "unsupported", .code = FSTYPE__UNSUPPORTED, - }, { + }, + { .name = "auto_cr", .code = FSTYPE__AUTO, - }, { + }, + { .name = "proc", .code = FSTYPE__PROC, - }, { + }, + { .name = "sysfs", .code = FSTYPE__SYSFS, - }, { + }, + { .name = "devtmpfs", .code = FSTYPE__DEVTMPFS, .dump = devtmpfs_dump, .restore = devtmpfs_restore, - }, { + }, + { .name = "binfmt_misc", .parse = binfmt_misc_parse_or_collect, .collect = binfmt_misc_parse_or_collect, .code = FSTYPE__BINFMT_MISC, .dump = binfmt_misc_dump, .restore = binfmt_misc_restore, - }, { + }, + { .name = "tmpfs", .code = FSTYPE__TMPFS, .dump = tmpfs_dump, .restore = tmpfs_restore, - }, { + }, + { .name = "devpts", .parse = devpts_parse, .code = FSTYPE__DEVPTS, .restore = devpts_restore, .check_bindmount = devpts_check_bindmount, - }, { + }, + { .name = "simfs", .code = FSTYPE__SIMFS, - }, { + }, + { .name = "btrfs", .code = FSTYPE__UNSUPPORTED, .sb_equal = btrfs_sb_equal, - }, { + }, + { .name = "pstore", .dump = dump_empty_fs, .code = FSTYPE__PSTORE, - }, { + }, + { .name = "mqueue", .dump = dump_empty_fs, .code = FSTYPE__MQUEUE, - }, { + }, + { .name = "securityfs", .code = FSTYPE__SECURITYFS, - }, { + }, + { .name = "fusectl", .dump = fusectl_dump, .code = FSTYPE__FUSECTL, - }, { + }, + { .name = "debugfs", .code = FSTYPE__DEBUGFS, .parse = debugfs_parse, - }, { + }, + { .name = "tracefs", .code = FSTYPE__TRACEFS, .parse = tracefs_parse, - }, { + }, + { .name = "cgroup", .code = FSTYPE__CGROUP, .parse = cgroup_parse, .sb_equal = cgroup_sb_equal, - }, { + }, + { .name = "cgroup2", .code = FSTYPE__CGROUP2, .parse = cgroup_parse, .sb_equal = cgroup_sb_equal, - }, { + }, + { .name = "aufs", .code = FSTYPE__AUFS, .parse = aufs_parse, - }, { + }, + { .name = "fuse", .code = FSTYPE__FUSE, .dump = always_fail, .restore = always_fail, - }, { + }, + { .name = "overlay", .code = FSTYPE__OVERLAYFS, .parse = overlayfs_parse, - }, { + }, + { .name = "autofs", .code = FSTYPE__AUTOFS, .parse = autofs_parse, @@ -773,7 +782,10 @@ static struct fstype fstypes[] = { }, }; -struct fstype *fstype_auto(void) { return &fstypes[1]; } +struct fstype *fstype_auto(void) +{ + return &fstypes[1]; +} static char fsauto_all[] = "all"; static char *fsauto_names; @@ -871,4 +883,3 @@ struct fstype *decode_fstype(u32 fst) uns: return &fstypes[0]; } - diff --git a/criu/fsnotify.c b/criu/fsnotify.c index 00a6a32c1..b5dd15dd8 100644 --- a/criu/fsnotify.c +++ b/criu/fsnotify.c @@ -46,26 +46,26 @@ #include "images/fsnotify.pb-c.h" #include "images/mnt.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "fsnotify: " struct fsnotify_mark_info { - struct list_head list; + struct list_head list; union { - InotifyWdEntry *iwe; - FanotifyMarkEntry *fme; + InotifyWdEntry *iwe; + FanotifyMarkEntry *fme; }; - struct pprep_head prep; /* XXX union with remap */ - struct file_remap *remap; + struct pprep_head prep; /* XXX union with remap */ + struct file_remap *remap; }; struct fsnotify_file_info { union { - InotifyFileEntry *ife; - FanotifyFileEntry *ffe; + InotifyFileEntry *ife; + FanotifyFileEntry *ffe; }; - struct list_head marks; - struct file_desc d; + struct list_head marks; + struct file_desc d; }; /* File handle */ @@ -91,12 +91,10 @@ static void decode_handle(fh_t *handle, FhEntry *img) { memzero(handle, sizeof(*handle)); - handle->type = img->type; - handle->bytes = img->bytes; + handle->type = img->type; + handle->bytes = img->bytes; - memcpy(handle->__handle, img->handle, - min(pb_repeated_size(img, handle), - sizeof(handle->__handle))); + memcpy(handle->__handle, img->handle, min(pb_repeated_size(img, handle), sizeof(handle->__handle))); } static int open_by_handle(void *arg, int fd, int pid) @@ -104,11 +102,7 @@ static int open_by_handle(void *arg, int fd, int pid) return syscall(__NR_open_by_handle_at, fd, arg, O_PATH); } -enum { - ERR_NO_MOUNT = -1, - ERR_NO_PATH_IN_MOUNT = -2, - ERR_GENERIC = -3 -}; +enum { ERR_NO_MOUNT = -1, ERR_NO_PATH_IN_MOUNT = -2, ERR_GENERIC = -3 }; static char *alloc_openable(unsigned int s_dev, unsigned long i_ino, FhEntry *f_handle) { @@ -139,13 +133,12 @@ static char *alloc_openable(unsigned int s_dev, unsigned long i_ino, FhEntry *f_ continue; mntfd = __open_mountpoint(m, -1); - pr_debug("\t\tTrying via mntid %d root %s ns_mountpoint @%s (%d)\n", - m->mnt_id, m->root, m->ns_mountpoint, mntfd); + pr_debug("\t\tTrying via mntid %d root %s ns_mountpoint @%s (%d)\n", m->mnt_id, m->root, + m->ns_mountpoint, mntfd); if (mntfd < 0) continue; - fd = userns_call(open_by_handle, UNS_FDOUT, &handle, - sizeof(handle), mntfd); + fd = userns_call(open_by_handle, UNS_FDOUT, &handle, sizeof(handle), mntfd); close(mntfd); if (fd < 0) continue; @@ -176,9 +169,8 @@ static char *alloc_openable(unsigned int s_dev, unsigned long i_ino, FhEntry *f_ } close(openable_fd); - pr_debug("\t\t\topenable (inode %s) as %s\n", - st.st_ino == i_ino ? - "match" : "don't match", __path); + pr_debug("\t\t\topenable (inode %s) as %s\n", st.st_ino == i_ino ? "match" : "don't match", + __path); if (st.st_ino == i_ino) { path = xstrdup(buf); @@ -200,8 +192,7 @@ err: return ERR_PTR(ERR_NO_MOUNT); } -static int open_handle(unsigned int s_dev, unsigned long i_ino, - FhEntry *f_handle) +static int open_handle(unsigned int s_dev, unsigned long i_ino, FhEntry *f_handle) { struct mount_info *m; int mntfd, fd = -1; @@ -209,8 +200,7 @@ static int open_handle(unsigned int s_dev, unsigned long i_ino, decode_handle(&handle, f_handle); - pr_debug("Opening fhandle %x:%llx...\n", - s_dev, (unsigned long long)handle.__handle[0]); + pr_debug("Opening fhandle %x:%llx...\n", s_dev, (unsigned long long)handle.__handle[0]); for (m = mntinfo; m; m = m->next) { if (m->s_dev != s_dev || !mnt_is_dir(m)) @@ -233,8 +223,7 @@ out: return fd; } -int check_open_handle(unsigned int s_dev, unsigned long i_ino, - FhEntry *f_handle) +int check_open_handle(unsigned int s_dev, unsigned long i_ino, FhEntry *f_handle) { char *path, *irmap_path; struct mount_info *mi; @@ -270,10 +259,9 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino, goto err; } - if ((mi->fstype->code == FSTYPE__TMPFS) || - (mi->fstype->code == FSTYPE__DEVTMPFS)) { - pr_err("Can't find suitable path for handle (dev %#x ino %#lx): %d\n", - s_dev, i_ino, (int)PTR_ERR(path)); + if ((mi->fstype->code == FSTYPE__TMPFS) || (mi->fstype->code == FSTYPE__DEVTMPFS)) { + pr_err("Can't find suitable path for handle (dev %#x ino %#lx): %d\n", s_dev, i_ino, + (int)PTR_ERR(path)); goto err; } @@ -310,11 +298,9 @@ err: static int check_one_wd(InotifyWdEntry *we) { - pr_info("wd: wd %#08x s_dev %#08x i_ino %#16"PRIx64" mask %#08x\n", - we->wd, we->s_dev, we->i_ino, we->mask); - pr_info("\t[fhandle] bytes %#08x type %#08x __handle %#016"PRIx64":%#016"PRIx64"\n", - we->f_handle->bytes, we->f_handle->type, - we->f_handle->handle[0], we->f_handle->handle[1]); + pr_info("wd: wd %#08x s_dev %#08x i_ino %#16" PRIx64 " mask %#08x\n", we->wd, we->s_dev, we->i_ino, we->mask); + pr_info("\t[fhandle] bytes %#08x type %#08x __handle %#016" PRIx64 ":%#016" PRIx64 "\n", we->f_handle->bytes, + we->f_handle->type, we->f_handle->handle[0], we->f_handle->handle[1]); if (we->mask & KERNEL_FS_EVENT_ON_CHILD) pr_warn_once("\t\tDetected FS_EVENT_ON_CHILD bit " @@ -387,23 +373,21 @@ static int pre_dump_one_inotify(int pid, int lfd) } const struct fdtype_ops inotify_dump_ops = { - .type = FD_TYPES__INOTIFY, - .dump = dump_one_inotify, - .pre_dump = pre_dump_one_inotify, + .type = FD_TYPES__INOTIFY, + .dump = dump_one_inotify, + .pre_dump = pre_dump_one_inotify, }; static int check_one_mark(FanotifyMarkEntry *fme) { if (fme->type == MARK_TYPE__INODE) { - BUG_ON(!fme->ie); - pr_info("mark: s_dev %#08x i_ino %#016"PRIx64" mask %#08x\n", - fme->s_dev, fme->ie->i_ino, fme->mask); + pr_info("mark: s_dev %#08x i_ino %#016" PRIx64 " mask %#08x\n", fme->s_dev, fme->ie->i_ino, fme->mask); - pr_info("\t[fhandle] bytes %#08x type %#08x __handle %#016"PRIx64":%#016"PRIx64"\n", - fme->ie->f_handle->bytes, fme->ie->f_handle->type, - fme->ie->f_handle->handle[0], fme->ie->f_handle->handle[1]); + pr_info("\t[fhandle] bytes %#08x type %#08x __handle %#016" PRIx64 ":%#016" PRIx64 "\n", + fme->ie->f_handle->bytes, fme->ie->f_handle->type, fme->ie->f_handle->handle[0], + fme->ie->f_handle->handle[1]); if (check_open_handle(fme->s_dev, fme->ie->i_ino, fme->ie->f_handle)) return -1; @@ -423,9 +407,7 @@ static int check_one_mark(FanotifyMarkEntry *fme) fme->me->path = m->mountpoint + 1; fme->s_dev = m->s_dev; - pr_info("mark: s_dev %#08x mnt_id %#08x mask %#08x\n", - fme->s_dev, fme->me->mnt_id, fme->mask); - + pr_info("mark: s_dev %#08x mnt_id %#08x mask %#08x\n", fme->s_dev, fme->me->mnt_id, fme->mask); } return 0; @@ -480,9 +462,7 @@ static int pre_dump_one_fanotify(int pid, int lfd) for (i = 0; i < fe.n_mark; i++) { FanotifyMarkEntry *me = fe.mark[i]; - if (me->type == MARK_TYPE__INODE && - irmap_queue_cache(me->s_dev, me->ie->i_ino, - me->ie->f_handle)) + if (me->type == MARK_TYPE__INODE && irmap_queue_cache(me->s_dev, me->ie->i_ino, me->ie->f_handle)) return -1; xfree(me); @@ -492,13 +472,12 @@ static int pre_dump_one_fanotify(int pid, int lfd) } const struct fdtype_ops fanotify_dump_ops = { - .type = FD_TYPES__FANOTIFY, - .dump = dump_one_fanotify, - .pre_dump = pre_dump_one_fanotify, + .type = FD_TYPES__FANOTIFY, + .dump = dump_one_fanotify, + .pre_dump = pre_dump_one_fanotify, }; -static char *get_mark_path(const char *who, struct file_remap *remap, - FhEntry *f_handle, unsigned long i_ino, +static char *get_mark_path(const char *who, struct file_remap *remap, FhEntry *f_handle, unsigned long i_ino, unsigned int s_dev, char *buf, int *target) { char *path = NULL; @@ -508,11 +487,10 @@ static char *get_mark_path(const char *who, struct file_remap *remap, mntns_root = mntns_get_root_by_mnt_id(remap->rmnt_id); - pr_debug("\t\tRestore %s watch for %#08x:%#016lx (via %s)\n", - who, s_dev, i_ino, remap->rpath); + pr_debug("\t\tRestore %s watch for %#08x:%#016lx (via %s)\n", who, s_dev, i_ino, remap->rpath); *target = openat(mntns_root, remap->rpath, O_PATH); } else if (f_handle->path) { - int mntns_root; + int mntns_root; char *path = "."; uint32_t mnt_id = f_handle->has_mnt_id ? f_handle->mnt_id : -1; @@ -550,8 +528,7 @@ static char *get_mark_path(const char *who, struct file_remap *remap, if (read_fd_link(*target, link, sizeof(link)) < 0) link[0] = '\0'; - pr_debug("\t\tRestore %s watch for %#08x:%#016lx (via %s -> %s)\n", - who, s_dev, i_ino, path, link); + pr_debug("\t\tRestore %s watch for %#08x:%#016lx (via %s -> %s)\n", who, s_dev, i_ino, path, link); } err: return path; @@ -564,15 +541,13 @@ static int restore_one_inotify(int inotify_fd, struct fsnotify_mark_info *info) char buf[PSFDS], *path; uint32_t mask; - path = get_mark_path("inotify", info->remap, iwe->f_handle, - iwe->i_ino, iwe->s_dev, buf, &target); + path = get_mark_path("inotify", info->remap, iwe->f_handle, iwe->i_ino, iwe->s_dev, buf, &target); if (!path) goto err; mask = iwe->mask & IN_ALL_EVENTS; if (iwe->mask & ~IN_ALL_EVENTS) { - pr_info("\t\tfilter event mask %#x -> %#x\n", - iwe->mask, mask); + pr_info("\t\tfilter event mask %#x -> %#x\n", iwe->mask, mask); } if (kdat.has_inotify_setnextwd) { @@ -643,9 +618,8 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark) snprintf(buf, sizeof(buf), "/proc/self/fd/%d", target); path = buf; } else if (fme->type == MARK_TYPE__INODE) { - path = get_mark_path("fanotify", mark->remap, - fme->ie->f_handle, fme->ie->i_ino, - fme->s_dev, buf, &target); + path = get_mark_path("fanotify", mark->remap, fme->ie->f_handle, fme->ie->i_ino, fme->s_dev, buf, + &target); if (!path) goto err; } else { @@ -658,18 +632,16 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark) if (mark->fme->mask) { ret = fanotify_mark(fd, flags, fme->mask, AT_FDCWD, path); if (ret) { - pr_err("Adding fanotify mask 0x%x on 0x%x/%s failed (%d)\n", - fme->mask, fme->id, path, ret); + pr_err("Adding fanotify mask 0x%x on 0x%x/%s failed (%d)\n", fme->mask, fme->id, path, ret); goto err; } } if (fme->ignored_mask) { - ret = fanotify_mark(fd, flags | FAN_MARK_IGNORED_MASK, - fme->ignored_mask, AT_FDCWD, path); + ret = fanotify_mark(fd, flags | FAN_MARK_IGNORED_MASK, fme->ignored_mask, AT_FDCWD, path); if (ret) { - pr_err("Adding fanotify ignored-mask 0x%x on 0x%x/%s failed (%d)\n", - fme->ignored_mask, fme->id, path, ret); + pr_err("Adding fanotify ignored-mask 0x%x on 0x%x/%s failed (%d)\n", fme->ignored_mask, fme->id, + path, ret); goto err; } } @@ -791,8 +763,7 @@ static int __collect_inotify_mark(struct fsnotify_file_info *p, struct fsnotify_ return 0; } -static int __collect_fanotify_mark(struct fsnotify_file_info *p, - struct fsnotify_mark_info *mark) +static int __collect_fanotify_mark(struct fsnotify_file_info *p, struct fsnotify_mark_info *mark) { list_add(&mark->list, &p->marks); if (mark->fme->type == MARK_TYPE__INODE) { @@ -830,10 +801,10 @@ static int collect_one_inotify(void *o, ProtobufCMessage *msg, struct cr_img *im } struct collect_image_info inotify_cinfo = { - .fd_type = CR_FD_INOTIFY_FILE, - .pb_type = PB_INOTIFY_FILE, - .priv_size = sizeof(struct fsnotify_file_info), - .collect = collect_one_inotify, + .fd_type = CR_FD_INOTIFY_FILE, + .pb_type = PB_INOTIFY_FILE, + .priv_size = sizeof(struct fsnotify_file_info), + .collect = collect_one_inotify, }; static int collect_one_fanotify(void *o, ProtobufCMessage *msg, struct cr_img *img) @@ -864,10 +835,10 @@ static int collect_one_fanotify(void *o, ProtobufCMessage *msg, struct cr_img *i } struct collect_image_info fanotify_cinfo = { - .fd_type = CR_FD_FANOTIFY_FILE, - .pb_type = PB_FANOTIFY_FILE, - .priv_size = sizeof(struct fsnotify_file_info), - .collect = collect_one_fanotify, + .fd_type = CR_FD_FANOTIFY_FILE, + .pb_type = PB_FANOTIFY_FILE, + .priv_size = sizeof(struct fsnotify_file_info), + .collect = collect_one_fanotify, }; static int collect_one_inotify_mark(void *o, ProtobufCMessage *msg, struct cr_img *i) @@ -902,10 +873,10 @@ static int collect_one_inotify_mark(void *o, ProtobufCMessage *msg, struct cr_im } struct collect_image_info inotify_mark_cinfo = { - .fd_type = CR_FD_INOTIFY_WD, - .pb_type = PB_INOTIFY_WD, - .priv_size = sizeof(struct fsnotify_mark_info), - .collect = collect_one_inotify_mark, + .fd_type = CR_FD_INOTIFY_WD, + .pb_type = PB_INOTIFY_WD, + .priv_size = sizeof(struct fsnotify_mark_info), + .collect = collect_one_inotify_mark, }; static int collect_one_fanotify_mark(void *o, ProtobufCMessage *msg, struct cr_img *i) @@ -930,8 +901,8 @@ static int collect_one_fanotify_mark(void *o, ProtobufCMessage *msg, struct cr_i } struct collect_image_info fanotify_mark_cinfo = { - .fd_type = CR_FD_FANOTIFY_MARK, - .pb_type = PB_FANOTIFY_MARK, - .priv_size = sizeof(struct fsnotify_mark_info), - .collect = collect_one_fanotify_mark, + .fd_type = CR_FD_FANOTIFY_MARK, + .pb_type = PB_FANOTIFY_MARK, + .priv_size = sizeof(struct fsnotify_mark_info), + .collect = collect_one_fanotify_mark, }; diff --git a/criu/image-desc.c b/criu/image-desc.c index 26e6b27bc..03842934f 100644 --- a/criu/image-desc.c +++ b/criu/image-desc.c @@ -11,17 +11,17 @@ * for more details. */ -#define FD_ENTRY(_name, _fmt) \ - [CR_FD_##_name] = { \ - .fmt = _fmt ".img", \ - .magic = _name##_MAGIC, \ +#define FD_ENTRY(_name, _fmt) \ + [CR_FD_##_name] = { \ + .fmt = _fmt ".img", \ + .magic = _name##_MAGIC, \ } -#define FD_ENTRY_F(_name, _fmt, _f) \ - [CR_FD_##_name] = { \ - .fmt = _fmt ".img", \ - .magic = _name##_MAGIC, \ - .oflags = _f, \ +#define FD_ENTRY_F(_name, _fmt, _f) \ + [CR_FD_##_name] = { \ + .fmt = _fmt ".img", \ + .magic = _name##_MAGIC, \ + .oflags = _f, \ } struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = { diff --git a/criu/image.c b/criu/image.c index 84101b610..3a85eb532 100644 --- a/criu/image.c +++ b/criu/image.c @@ -274,8 +274,7 @@ void close_cr_imgset(struct cr_imgset **cr_imgset) *cr_imgset = NULL; } -struct cr_imgset *cr_imgset_open_range(int pid, int from, int to, - unsigned long flags) +struct cr_imgset *cr_imgset_open_range(int pid, int from, int to, unsigned long flags) { struct cr_imgset *imgset; unsigned int i; @@ -403,10 +402,10 @@ static int img_write_magic(struct cr_img *img, int oflags, int type) } struct openat_args { - char path[PATH_MAX]; - int flags; - int err; - int mode; + char path[PATH_MAX]; + int flags; + int err; + int mode; }; static int userns_openat(void *arg, int dfd, int pid) @@ -430,8 +429,7 @@ static int do_open_image(struct cr_img *img, int dfd, int type, unsigned long of if (opts.stream && !(oflags & O_FORCE_LOCAL)) { ret = img_streamer_open(path, flags); errno = EIO; /* errno value is meaningless, only the ret value is meaningful */ - } else if (root_ns_mask & CLONE_NEWUSER && - type == CR_FD_PAGES && oflags & O_RDWR) { + } else if (root_ns_mask & CLONE_NEWUSER && type == CR_FD_PAGES && oflags & O_RDWR) { /* * For pages images dedup we need to open images read-write on * restore, that may require proper capabilities, so we ask @@ -574,7 +572,7 @@ int open_image_dir(char *dir, int mode) if (opts.img_parent[0] == '/') pr_warn("Absolute paths for parent links " - "may not work on restore!\n"); + "may not work on restore!\n"); } return 0; diff --git a/criu/img-streamer.c b/criu/img-streamer.c index bcf6e6818..7e36eae01 100644 --- a/criu/img-streamer.c +++ b/criu/img-streamer.c @@ -21,7 +21,7 @@ * (e.g., streamer is in capture more, while CRIU is in restore mode). */ #define IMG_STREAMER_CAPTURE_SOCKET_NAME "streamer-capture.sock" -#define IMG_STREAMER_SERVE_SOCKET_NAME "streamer-serve.sock" +#define IMG_STREAMER_SERVE_SOCKET_NAME "streamer-serve.sock" /* All requests go through the same socket connection. We must synchronize */ static mutex_t *img_streamer_fd_lock; @@ -32,9 +32,13 @@ static int img_streamer_mode; static const char *socket_name_for_mode(int mode) { switch (mode) { - case O_DUMP: return IMG_STREAMER_CAPTURE_SOCKET_NAME; - case O_RSTR: return IMG_STREAMER_SERVE_SOCKET_NAME; - default: BUG(); return NULL; + case O_DUMP: + return IMG_STREAMER_CAPTURE_SOCKET_NAME; + case O_RSTR: + return IMG_STREAMER_SERVE_SOCKET_NAME; + default: + BUG(); + return NULL; } } @@ -57,8 +61,7 @@ int img_streamer_init(const char *image_dir, int mode) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", - image_dir, socket_name_for_mode(mode)); + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", image_dir, socket_name_for_mode(mode)); if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { pr_perror("Unable to connect to image streamer socket: %s", addr.sun_path); @@ -132,15 +135,13 @@ static int send_file_request(char *filename) { ImgStreamerRequestEntry req = IMG_STREAMER_REQUEST_ENTRY__INIT; req.filename = filename; - return pb_write_one_fd(get_service_fd(IMG_STREAMER_FD_OFF), - &req, PB_IMG_STREAMER_REQUEST); + return pb_write_one_fd(get_service_fd(IMG_STREAMER_FD_OFF), &req, PB_IMG_STREAMER_REQUEST); } static int recv_file_reply(bool *exists) { ImgStreamerReplyEntry *reply; - int ret = pb_read_one_fd(get_service_fd(IMG_STREAMER_FD_OFF), - (void **)&reply, PB_IMG_STREAMER_REPLY); + int ret = pb_read_one_fd(get_service_fd(IMG_STREAMER_FD_OFF), (void **)&reply, PB_IMG_STREAMER_REPLY); if (ret < 0) return ret; @@ -155,8 +156,8 @@ static int recv_file_reply(bool *exists) * image streamer, greatly improving performance. * Transfer rates of up to 15GB/s can be seen with this technique. */ -#define READ_PIPE 0 /* index of the read pipe returned by pipe() */ -#define WRITE_PIPE 1 +#define READ_PIPE 0 /* index of the read pipe returned by pipe() */ +#define WRITE_PIPE 1 static int establish_streamer_file_pipe(void) { /* @@ -174,8 +175,7 @@ static int establish_streamer_file_pipe(void) return -1; } - if (send_fd(get_service_fd(IMG_STREAMER_FD_OFF), - NULL, 0, fds[streamer_pipe_direction]) < 0) + if (send_fd(get_service_fd(IMG_STREAMER_FD_OFF), NULL, 0, fds[streamer_pipe_direction]) < 0) close(fds[criu_pipe_direction]); else ret = fds[criu_pipe_direction]; diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c index 1c8de41a8..a2eb72f28 100644 --- a/criu/ipc_ns.c +++ b/criu/ipc_ns.c @@ -22,26 +22,25 @@ #include "images/ipc-sem.pb-c.h" #include "images/ipc-msg.pb-c.h" -#if defined (__GLIBC__) && __GLIBC__ >= 2 +#if defined(__GLIBC__) && __GLIBC__ >= 2 #define KEY __key #else #define KEY key #endif #ifndef MSGMAX -#define MSGMAX 8192 +#define MSGMAX 8192 #endif #ifndef MSG_COPY -#define MSG_COPY 040000 +#define MSG_COPY 040000 #endif static void pr_ipc_desc_entry(const IpcDescEntry *desc) { pr_info("id: %-10d key: %#08x uid: %-10d gid: %-10d " - "cuid: %-10d cgid: %-10d mode: %-10o ", - desc->id, desc->key, desc->uid, desc->gid, - desc->cuid, desc->cgid, desc->mode); + "cuid: %-10d cgid: %-10d mode: %-10o ", + desc->id, desc->key, desc->uid, desc->gid, desc->cuid, desc->cgid, desc->mode); } static void fill_ipc_desc(int id, IpcDescEntry *desc, const struct ipc_perm *ipcp) @@ -62,7 +61,7 @@ static void pr_ipc_sem_array(int nr, u16 *values) pr_info("\n"); } -#define pr_info_ipc_sem_array(nr, values) pr_ipc_sem_array(nr, values) +#define pr_info_ipc_sem_array(nr, values) pr_ipc_sem_array(nr, values) static void pr_info_ipc_sem_entry(const IpcSemEntry *sem) { @@ -160,8 +159,7 @@ static int dump_ipc_sem(struct cr_img *img) static void pr_info_ipc_msg(int nr, const IpcMsg *msg) { - pr_info(" %-5d: type: %-20"PRId64" size: %-10d\n", - nr++, msg->mtype, msg->msize); + pr_info(" %-5d: type: %-20" PRId64 " size: %-10d\n", nr++, msg->mtype, msg->msize); } static void pr_info_ipc_msg_entry(const IpcMsgEntry *msg) @@ -170,8 +168,7 @@ static void pr_info_ipc_msg_entry(const IpcMsgEntry *msg) pr_info("qbytes: %-10d qnum: %-10d\n", msg->qbytes, msg->qnum); } -static int dump_ipc_msg_queue_messages(struct cr_img *img, const IpcMsgEntry *msq, - unsigned int msg_nr) +static int dump_ipc_msg_queue_messages(struct cr_img *img, const IpcMsgEntry *msq, unsigned int msg_nr) { struct msgbuf *message = NULL; unsigned int msgmax; @@ -287,7 +284,7 @@ static int dump_ipc_msg(struct cr_img *img) static void pr_info_ipc_shm(const IpcShmEntry *shm) { pr_ipc_desc_entry(shm->desc); - pr_info("size: %-10"PRIu64"\n", shm->size); + pr_info("size: %-10" PRIu64 "\n", shm->size); } #define NR_MANDATORY_IPC_SYSCTLS 9 @@ -295,24 +292,24 @@ static void pr_info_ipc_shm(const IpcShmEntry *shm) static int ipc_sysctl_req(IpcVarEntry *e, int op) { struct sysctl_req req[] = { - { "kernel/sem", e->sem_ctls, CTL_U32A(e->n_sem_ctls) }, - { "kernel/msgmax", &e->msg_ctlmax, CTL_U32 }, - { "kernel/msgmnb", &e->msg_ctlmnb, CTL_U32 }, - { "kernel/auto_msgmni", &e->auto_msgmni, CTL_U32 }, - { "kernel/msgmni", &e->msg_ctlmni, CTL_U32 }, - { "kernel/shmmax", &e->shm_ctlmax, CTL_U64 }, - { "kernel/shmall", &e->shm_ctlall, CTL_U64 }, - { "kernel/shmmni", &e->shm_ctlmni, CTL_U32 }, - { "kernel/shm_rmid_forced", &e->shm_rmid_forced, CTL_U32 }, + { "kernel/sem", e->sem_ctls, CTL_U32A(e->n_sem_ctls) }, + { "kernel/msgmax", &e->msg_ctlmax, CTL_U32 }, + { "kernel/msgmnb", &e->msg_ctlmnb, CTL_U32 }, + { "kernel/auto_msgmni", &e->auto_msgmni, CTL_U32 }, + { "kernel/msgmni", &e->msg_ctlmni, CTL_U32 }, + { "kernel/shmmax", &e->shm_ctlmax, CTL_U64 }, + { "kernel/shmall", &e->shm_ctlall, CTL_U64 }, + { "kernel/shmmni", &e->shm_ctlmni, CTL_U32 }, + { "kernel/shm_rmid_forced", &e->shm_rmid_forced, CTL_U32 }, /* We have 9 mandatory sysctls above and 8 optional below */ - { "fs/mqueue/queues_max", &e->mq_queues_max, CTL_U32 }, - { "fs/mqueue/msg_max", &e->mq_msg_max, CTL_U32 }, - { "fs/mqueue/msgsize_max", &e->mq_msgsize_max, CTL_U32 }, - { "fs/mqueue/msg_default", &e->mq_msg_default, CTL_U32 }, - { "fs/mqueue/msgsize_default", &e->mq_msgsize_default, CTL_U32 }, - { "kernel/msg_next_id", &e->msg_next_id, CTL_U32 }, - { "kernel/sem_next_id", &e->sem_next_id, CTL_U32 }, - { "kernel/shm_next_id", &e->shm_next_id, CTL_U32 }, + { "fs/mqueue/queues_max", &e->mq_queues_max, CTL_U32 }, + { "fs/mqueue/msg_max", &e->mq_msg_max, CTL_U32 }, + { "fs/mqueue/msgsize_max", &e->mq_msgsize_max, CTL_U32 }, + { "fs/mqueue/msg_default", &e->mq_msg_default, CTL_U32 }, + { "fs/mqueue/msgsize_default", &e->mq_msgsize_default, CTL_U32 }, + { "kernel/msg_next_id", &e->msg_next_id, CTL_U32 }, + { "kernel/sem_next_id", &e->sem_next_id, CTL_U32 }, + { "kernel/shm_next_id", &e->shm_next_id, CTL_U32 }, }; int nr = NR_MANDATORY_IPC_SYSCTLS; @@ -408,8 +405,7 @@ static int dump_ipc_shm(struct cr_img *img) slot++; } if (slot != info.used_ids) { - pr_err("Failed to collect %d (only %d succeeded)\n", - info.used_ids, slot); + pr_err("Failed to collect %d (only %d succeeded)\n", info.used_ids, slot); return -EFAULT; } return 0; @@ -420,8 +416,8 @@ static int dump_ipc_var(struct cr_img *img) IpcVarEntry var = IPC_VAR_ENTRY__INIT; int ret = -1; - var.n_sem_ctls = 4; - var.sem_ctls = xmalloc(pb_repeated_size(&var, sem_ctls)); + var.n_sem_ctls = 4; + var.sem_ctls = xmalloc(pb_repeated_size(&var, sem_ctls)); if (!var.sem_ctls) goto err; var.has_mq_msg_default = true; @@ -543,16 +539,14 @@ static int prepare_ipc_sem_desc(struct cr_img *img, const IpcSemEntry *sem) return ret; } - id = semget(sem->desc->key, sem->nsems, - sem->desc->mode | IPC_CREAT | IPC_EXCL); + id = semget(sem->desc->key, sem->nsems, sem->desc->mode | IPC_CREAT | IPC_EXCL); if (id == -1) { pr_perror("Failed to create sem set"); return -errno; } if (id != sem->desc->id) { - pr_err("Failed to restore sem id (%d instead of %d)\n", - id, sem->desc->id); + pr_err("Failed to restore sem id (%d instead of %d)\n", id, sem->desc->id); return -EFAULT; } @@ -639,8 +633,7 @@ static int prepare_ipc_msg_queue_messages(struct cr_img *img, const IpcMsgEntry if (msg->msize > MSGMAX) { ret = -1; - pr_err("Unsupported message size: %d (MAX: %d)\n", - msg->msize, MSGMAX); + pr_err("Unsupported message size: %d (MAX: %d)\n", msg->msize, MSGMAX); break; } @@ -686,8 +679,7 @@ static int prepare_ipc_msg_queue(struct cr_img *img, const IpcMsgEntry *msq) } if (id != msq->desc->id) { - pr_err("Failed to restore msg id (%d instead of %d)\n", - id, msq->desc->id); + pr_err("Failed to restore msg id (%d instead of %d)\n", id, msq->desc->id); return -EFAULT; } @@ -821,16 +813,14 @@ static int prepare_ipc_shm_seg(struct cr_img *img, const IpcShmEntry *shm) return ret; } - id = shmget(shm->desc->key, shm->size, - shm->desc->mode | IPC_CREAT | IPC_EXCL); + id = shmget(shm->desc->key, shm->size, shm->desc->mode | IPC_CREAT | IPC_EXCL); if (id == -1) { pr_perror("Failed to create shm set"); return -errno; } if (id != shm->desc->id) { - pr_err("Failed to restore shm id (%d instead of %d)\n", - id, shm->desc->id); + pr_err("Failed to restore shm id (%d instead of %d)\n", id, shm->desc->id); return -EFAULT; } diff --git a/criu/irmap.c b/criu/irmap.c index c9bfdbe22..09570c593 100644 --- a/criu/irmap.c +++ b/criu/irmap.c @@ -30,12 +30,12 @@ #include "images/fsnotify.pb-c.h" #include "images/fh.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "irmap: " -#define IRMAP_CACHE_BITS 5 -#define IRMAP_CACHE_SIZE (1 << IRMAP_CACHE_BITS) -#define IRMAP_CACHE_MASK (IRMAP_CACHE_SIZE - 1) +#define IRMAP_CACHE_BITS 5 +#define IRMAP_CACHE_SIZE (1 << IRMAP_CACHE_BITS) +#define IRMAP_CACHE_MASK (IRMAP_CACHE_SIZE - 1) static inline int irmap_hashfn(unsigned int s_dev, unsigned long i_ino) { @@ -55,16 +55,34 @@ struct irmap { static struct irmap *cache[IRMAP_CACHE_SIZE]; static struct irmap hints[] = { - { .path = "/etc", .nr_kids = -1, }, - { .path = "/var/spool", .nr_kids = -1, }, - { .path = "/var/log", .nr_kids = -1, }, + { + .path = "/etc", + .nr_kids = -1, + }, + { + .path = "/var/spool", + .nr_kids = -1, + }, + { + .path = "/var/log", + .nr_kids = -1, + }, { .path = "/usr/share/dbus-1/system-services", .nr_kids = -1 }, { .path = "/var/lib/polkit-1/localauthority", .nr_kids = -1 }, { .path = "/usr/share/polkit-1/actions", .nr_kids = -1 }, - { .path = "/lib/udev", .nr_kids = -1, }, - { .path = "/.", .nr_kids = 0, }, - { .path = "/no-such-path", .nr_kids = -1, }, - { }, + { + .path = "/lib/udev", + .nr_kids = -1, + }, + { + .path = "/.", + .nr_kids = 0, + }, + { + .path = "/no-such-path", + .nr_kids = -1, + }, + {}, }; /* @@ -142,8 +160,8 @@ static int irmap_update_dir(struct irmap *t) k = &t->kids[nr - 1]; - k->kids = NULL; /* for xrealloc above */ - k->ino = 0; /* for irmap_update_stat */ + k->kids = NULL; /* for xrealloc above */ + k->ino = 0; /* for irmap_update_stat */ k->nr_kids = -1; /* for irmap_update_dir */ k->path = xsprintf("%s/%s", t->path, de->d_name); if (!k->path) @@ -235,14 +253,13 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino) * But the root service fd is already set by the * irmap_predump_prep, so we just go ahead and scan. */ - if (!doing_predump && - __mntns_get_root_fd(root_item->pid->real) < 0) + if (!doing_predump && __mntns_get_root_fd(root_item->pid->real) < 0) goto out; timing_start(TIME_IRMAP_RESOLVE); hv = irmap_hashfn(s_dev, i_ino); - for (p = &cache[hv]; *p; ) { + for (p = &cache[hv]; *p;) { c = *p; if (!(c->dev == s_dev && c->ino == i_ino)) { p = &(*p)->next; @@ -298,8 +315,7 @@ struct irmap_predump { static struct irmap_predump *predump_queue; -int irmap_queue_cache(unsigned int dev, unsigned long ino, - FhEntry *fh) +int irmap_queue_cache(unsigned int dev, unsigned long ino, FhEntry *fh) { struct irmap_predump *ip; @@ -310,8 +326,7 @@ int irmap_queue_cache(unsigned int dev, unsigned long ino, ip->dev = dev; ip->ino = ino; ip->fh = *fh; - ip->fh.handle = xmemdup(fh->handle, - FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); + ip->fh.handle = xmemdup(fh->handle, FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); if (!ip->fh.handle) { xfree(ip); return -1; diff --git a/criu/kcmp-ids.c b/criu/kcmp-ids.c index 4fde10e67..1569b9d40 100644 --- a/criu/kcmp-ids.c +++ b/criu/kcmp-ids.c @@ -52,13 +52,13 @@ */ struct kid_entry { - struct rb_node node; + struct rb_node node; - struct rb_root subtree_root; - struct rb_node subtree_node; + struct rb_root subtree_root; + struct rb_node subtree_node; - uint32_t subid; /* subid is always unique */ - struct kid_elem elem; + uint32_t subid; /* subid is always unique */ + struct kid_elem elem; } __aligned(sizeof(long)); static struct kid_entry *alloc_kid_entry(struct kid_tree *tree, struct kid_elem *elem) @@ -69,8 +69,8 @@ static struct kid_entry *alloc_kid_entry(struct kid_tree *tree, struct kid_elem if (!e) goto err; - e->subid = tree->subid++; - e->elem = *elem; + e->subid = tree->subid++; + e->elem = *elem; /* Make sure no overflow here */ BUG_ON(!e->subid); @@ -78,14 +78,12 @@ static struct kid_entry *alloc_kid_entry(struct kid_tree *tree, struct kid_elem rb_init_node(&e->node); rb_init_node(&e->subtree_node); e->subtree_root = RB_ROOT; - rb_link_and_balance(&e->subtree_root, &e->subtree_node, - NULL, &e->subtree_root.rb_node); + rb_link_and_balance(&e->subtree_root, &e->subtree_node, NULL, &e->subtree_root.rb_node); err: return e; } -static uint32_t kid_generate_sub(struct kid_tree *tree, struct kid_entry *e, - struct kid_elem *elem, int *new_id) +static uint32_t kid_generate_sub(struct kid_tree *tree, struct kid_entry *e, struct kid_elem *elem, int *new_id) { struct rb_node *node = e->subtree_root.rb_node; struct kid_entry *sub = NULL; @@ -97,8 +95,7 @@ static uint32_t kid_generate_sub(struct kid_tree *tree, struct kid_entry *e, while (node) { struct kid_entry *this = rb_entry(node, struct kid_entry, subtree_node); - int ret = syscall(SYS_kcmp, this->elem.pid, elem->pid, tree->kcmp_type, - this->elem.idx, elem->idx); + int ret = syscall(SYS_kcmp, this->elem.pid, elem->pid, tree->kcmp_type, this->elem.idx, elem->idx); parent = *new; if (ret == 1) @@ -108,9 +105,8 @@ static uint32_t kid_generate_sub(struct kid_tree *tree, struct kid_entry *e, else if (ret == 0) return this->subid; else { - pr_perror("kcmp failed: pid (%d %d) type %u idx (%u %u)", - this->elem.pid, elem->pid, tree->kcmp_type, - this->elem.idx, elem->idx); + pr_perror("kcmp failed: pid (%d %d) type %u idx (%u %u)", this->elem.pid, elem->pid, + tree->kcmp_type, this->elem.idx, elem->idx); return 0; } } @@ -124,8 +120,7 @@ static uint32_t kid_generate_sub(struct kid_tree *tree, struct kid_entry *e, return sub->subid; } -uint32_t kid_generate_gen(struct kid_tree *tree, - struct kid_elem *elem, int *new_id) +uint32_t kid_generate_gen(struct kid_tree *tree, struct kid_elem *elem, int *new_id) { struct rb_node *node = tree->root.rb_node; struct kid_entry *e = NULL; @@ -154,9 +149,7 @@ uint32_t kid_generate_gen(struct kid_tree *tree, return e->subid; } -static struct kid_elem *kid_lookup_epoll_tfd_sub(struct kid_tree *tree, - struct kid_entry *e, - struct kid_elem *elem, +static struct kid_elem *kid_lookup_epoll_tfd_sub(struct kid_tree *tree, struct kid_entry *e, struct kid_elem *elem, kcmp_epoll_slot_t *slot) { struct rb_node *node = e->subtree_root.rb_node; @@ -166,8 +159,7 @@ static struct kid_elem *kid_lookup_epoll_tfd_sub(struct kid_tree *tree, while (node) { struct kid_entry *this = rb_entry(node, struct kid_entry, subtree_node); - int ret = syscall(SYS_kcmp, this->elem.pid, elem->pid, KCMP_EPOLL_TFD, - this->elem.idx, slot); + int ret = syscall(SYS_kcmp, this->elem.pid, elem->pid, KCMP_EPOLL_TFD, this->elem.idx, slot); if (ret == 1) node = node->rb_left, new = &((*new)->rb_left); @@ -176,9 +168,8 @@ static struct kid_elem *kid_lookup_epoll_tfd_sub(struct kid_tree *tree, else if (ret == 0) return &this->elem; else { - pr_perror("kcmp-epoll failed: pid (%d %d) type %u idx (%u %u)", - this->elem.pid, elem->pid, KCMP_EPOLL_TFD, - this->elem.idx, elem->idx); + pr_perror("kcmp-epoll failed: pid (%d %d) type %u idx (%u %u)", this->elem.pid, elem->pid, + KCMP_EPOLL_TFD, this->elem.idx, elem->idx); return NULL; } } @@ -186,9 +177,7 @@ static struct kid_elem *kid_lookup_epoll_tfd_sub(struct kid_tree *tree, return NULL; } -struct kid_elem *kid_lookup_epoll_tfd(struct kid_tree *tree, - struct kid_elem *elem, - kcmp_epoll_slot_t *slot) +struct kid_elem *kid_lookup_epoll_tfd(struct kid_tree *tree, struct kid_elem *elem, kcmp_epoll_slot_t *slot) { struct rb_node *node = tree->root.rb_node; struct rb_node **new = &tree->root.rb_node; diff --git a/criu/kerndat.c b/criu/kerndat.c index f418f42bd..4d28dac98 100644 --- a/criu/kerndat.c +++ b/criu/kerndat.c @@ -10,11 +10,10 @@ #include <sys/sysmacros.h> #include <stdint.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <sys/prctl.h> #include <sys/inotify.h> - #include "common/config.h" #include "int.h" #include "log.h" @@ -43,8 +42,7 @@ #include "sched.h" #include "memfd.h" -struct kerndat_s kdat = { -}; +struct kerndat_s kdat = {}; static int check_pagemap(void) { @@ -133,29 +131,26 @@ static void kerndat_mmap_min_addr(void) struct sysctl_req req[] = { { - .name = "vm/mmap_min_addr", - .arg = &value, - .type = CTL_U64, + .name = "vm/mmap_min_addr", + .arg = &value, + .type = CTL_U64, }, }; if (sysctl_op(req, ARRAY_SIZE(req), CTL_READ, 0)) { - pr_warn("Can't fetch %s value, use default %#lx\n", - req[0].name, (unsigned long)default_mmap_min_addr); + pr_warn("Can't fetch %s value, use default %#lx\n", req[0].name, (unsigned long)default_mmap_min_addr); kdat.mmap_min_addr = default_mmap_min_addr; return; } if (value < default_mmap_min_addr) { - pr_debug("Adjust mmap_min_addr %#lx -> %#lx\n", - (unsigned long)value, + pr_debug("Adjust mmap_min_addr %#lx -> %#lx\n", (unsigned long)value, (unsigned long)default_mmap_min_addr); kdat.mmap_min_addr = default_mmap_min_addr; } else kdat.mmap_min_addr = value; - pr_debug("Found mmap_min_addr %#lx\n", - (unsigned long)kdat.mmap_min_addr); + pr_debug("Found mmap_min_addr %#lx\n", (unsigned long)kdat.mmap_min_addr); } static int kerndat_files_stat(void) @@ -165,9 +160,9 @@ static int kerndat_files_stat(void) struct sysctl_req req[] = { { - .name = "fs/nr_open", - .arg = &nr_open, - .type = CTL_U32, + .name = "fs/nr_open", + .arg = &nr_open, + .type = CTL_U32, }, }; @@ -178,8 +173,7 @@ static int kerndat_files_stat(void) kdat.sysctl_nr_open = nr_open; - pr_debug("files stat: %s %u\n", - req[0].name, kdat.sysctl_nr_open); + pr_debug("files stat: %s %u\n", req[0].name, kdat.sysctl_nr_open); return 0; } @@ -191,15 +185,13 @@ static int kerndat_get_shmemdev(void) struct stat buf; dev_t dev; - map = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + map = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (map == MAP_FAILED) { pr_perror("Can't mmap memory for shmemdev test"); return -1; } - sprintf(maps, "/proc/self/map_files/%lx-%lx", - (unsigned long)map, (unsigned long)map + page_size()); + sprintf(maps, "/proc/self/map_files/%lx-%lx", (unsigned long)map, (unsigned long)map + page_size()); if (stat(maps, &buf) < 0) { int e = errno; if (errno == EPERM) { @@ -221,7 +213,7 @@ static int kerndat_get_shmemdev(void) munmap(map, PAGE_SIZE); kdat.shmem_dev = dev; - pr_info("Found anon-shmem device at %"PRIx64"\n", kdat.shmem_dev); + pr_info("Found anon-shmem device at %" PRIx64 "\n", kdat.shmem_dev); return 0; err: @@ -232,10 +224,10 @@ err: static dev_t get_host_dev(unsigned int which) { static struct kst { - const char *name; - const char *path; - unsigned int magic; - dev_t fs_dev; + const char *name; + const char *path; + unsigned int magic; + dev_t fs_dev; } kstat[KERNDAT_FS_STAT_MAX] = { [KERNDAT_FS_STAT_DEVPTS] = { .name = "devpts", @@ -314,8 +306,7 @@ static int kerndat_get_dirty_track(void) u64 pmap = 0; int ret = -1; - map = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + map = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (map == MAP_FAILED) { pr_perror("Can't mmap memory for pagemap test"); return ret; @@ -353,7 +344,7 @@ static int kerndat_get_dirty_track(void) pr_info("Dirty track supported on kernel\n"); kdat.has_dirty_track = true; } else { -no_dt: + no_dt: pr_info("Dirty tracking support is OFF\n"); if (opts.track_mem) { pr_err("Tracking memory is not available\n"); @@ -382,7 +373,7 @@ static int init_zero_page_pfn(void) return 0; } - if (*((int *) addr) != 0) { + if (*((int *)addr) != 0) { BUG(); return -1; } @@ -535,7 +526,7 @@ int kerndat_tcp_repair(void) struct sockaddr_in addr; socklen_t aux; - memset(&addr,0,sizeof(addr)); + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; inet_pton(AF_INET, "127.0.0.1", &(addr.sin_addr)); addr.sin_port = 0; @@ -545,13 +536,13 @@ int kerndat_tcp_repair(void) return -1; } - if (bind(sock, (struct sockaddr *) &addr, sizeof(addr))) { + if (bind(sock, (struct sockaddr *)&addr, sizeof(addr))) { pr_perror("Unable to bind a socket"); goto err; } aux = sizeof(addr); - if (getsockname(sock, (struct sockaddr *) &addr, &aux)) { + if (getsockname(sock, (struct sockaddr *)&addr, &aux)) { pr_perror("Unable to get a socket name"); goto err; } @@ -567,7 +558,7 @@ int kerndat_tcp_repair(void) goto err; } - if (connect(clnt, (struct sockaddr *) &addr, sizeof(addr))) { + if (connect(clnt, (struct sockaddr *)&addr, sizeof(addr))) { pr_perror("Unable to connect a socket"); goto err; } @@ -641,8 +632,7 @@ static int kerndat_detect_stack_guard_gap(void) FILE *maps; void *mem; - mem = mmap(NULL, (3ul << 20), PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0); + mem = mmap(NULL, (3ul << 20), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0); if (mem == MAP_FAILED) { pr_perror("Can't mmap stack area"); return -1; @@ -664,8 +654,7 @@ static int kerndat_detect_stack_guard_gap(void) } while (fgets(buf, sizeof(buf), maps)) { - num = sscanf(buf, "%lx-%lx %c%c%c%c", - &start, &end, &r, &w, &x, &s); + num = sscanf(buf, "%lx-%lx %c%c%c%c", &start, &end, &r, &w, &x, &s); if (num < 6) { pr_err("Can't parse: %s\n", buf); goto err; @@ -746,7 +735,7 @@ static int kerndat_has_fsopen(void) static int has_kcmp_epoll_tfd(void) { - kcmp_epoll_slot_t slot = { }; + kcmp_epoll_slot_t slot = {}; int ret = -1, efd, tfd; pid_t pid = getpid(); struct epoll_event ev; @@ -822,8 +811,8 @@ static int kerndat_x86_has_ptrace_fpu_xsave_bug(void) return 0; } -#define KERNDAT_CACHE_FILE KDAT_RUNDIR"/criu.kdat" -#define KERNDAT_CACHE_FILE_TMP KDAT_RUNDIR"/.criu.kdat" +#define KERNDAT_CACHE_FILE KDAT_RUNDIR "/criu.kdat" +#define KERNDAT_CACHE_FILE_TMP KDAT_RUNDIR "/.criu.kdat" static int kerndat_try_load_cache(void) { @@ -831,7 +820,7 @@ static int kerndat_try_load_cache(void) fd = open(KERNDAT_CACHE_FILE, O_RDONLY); if (fd < 0) { - if(ENOENT == errno) + if (ENOENT == errno) pr_debug("File %s does not exist\n", KERNDAT_CACHE_FILE); else pr_warn("Can't load %s\n", KERNDAT_CACHE_FILE); @@ -847,9 +836,7 @@ static int kerndat_try_load_cache(void) close(fd); - if (ret != sizeof(kdat) || - kdat.magic1 != KDAT_MAGIC || - kdat.magic2 != KDAT_MAGIC_2) { + if (ret != sizeof(kdat) || kdat.magic1 != KDAT_MAGIC || kdat.magic2 != KDAT_MAGIC_2) { pr_warn("Stale %s file\n", KERNDAT_CACHE_FILE); unlink(KERNDAT_CACHE_FILE); return 1; @@ -898,7 +885,7 @@ static void kerndat_save_cache(void) if (ret < 0) { pr_perror("Couldn't save %s", KERNDAT_CACHE_FILE); -unl: + unl: unlink(KERNDAT_CACHE_FILE_TMP); } } @@ -957,8 +944,7 @@ int kerndat_has_thp_disable(void) return 0; } - addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (addr == MAP_FAILED) { pr_perror("Can't mmap memory for THP disable test"); return -1; diff --git a/criu/libnetlink.c b/criu/libnetlink.c index f9da58e9a..6dad7551a 100644 --- a/criu/libnetlink.c +++ b/criu/libnetlink.c @@ -10,9 +10,8 @@ #include "libnetlink.h" #include "util.h" -static int nlmsg_receive(char *buf, int len, - int (*cb)(struct nlmsghdr *, struct ns_id *ns, void *), - int (*err_cb)(int, struct ns_id *, void *), struct ns_id *ns, void *arg) +static int nlmsg_receive(char *buf, int len, int (*cb)(struct nlmsghdr *, struct ns_id *ns, void *), + int (*err_cb)(int, struct ns_id *, void *), struct ns_id *ns, void *arg) { struct nlmsghdr *hdr; @@ -56,8 +55,7 @@ static int rtnl_return_err(int err, struct ns_id *ns, void *arg) return err; } -int do_rtnl_req(int nl, void *req, int size, - int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *), +int do_rtnl_req(int nl, void *req, int size, int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *), int (*error_callback)(int err, struct ns_id *ns, void *arg), struct ns_id *ns, void *arg) { struct msghdr msg; @@ -70,16 +68,16 @@ int do_rtnl_req(int nl, void *req, int size, error_callback = rtnl_return_err; memset(&msg, 0, sizeof(msg)); - msg.msg_name = &nladdr; - msg.msg_namelen = sizeof(nladdr); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + msg.msg_name = &nladdr; + msg.msg_namelen = sizeof(nladdr); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; - iov.iov_base = req; - iov.iov_len = size; + iov.iov_base = req; + iov.iov_len = size; if (sendmsg(nl, &msg, 0) < 0) { err = -errno; @@ -87,16 +85,15 @@ int do_rtnl_req(int nl, void *req, int size, goto err; } - iov.iov_base = buf; - iov.iov_len = sizeof(buf); + iov.iov_base = buf; + iov.iov_len = sizeof(buf); while (1) { - memset(&msg, 0, sizeof(msg)); - msg.msg_name = &nladdr; - msg.msg_namelen = sizeof(nladdr); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + msg.msg_name = &nladdr; + msg.msg_namelen = sizeof(nladdr); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; err = recvmsg(nl, &msg, 0); if (err < 0) { @@ -130,8 +127,7 @@ err: return err; } -int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, - int alen) +int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen) { int len = nla_attr_size(alen); struct rtattr *rta; @@ -172,8 +168,7 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, * @see nla_validate * @return 0 on success or a negative error code. */ -int __wrap_nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, - struct nla_policy *policy) +int __wrap_nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, struct nla_policy *policy) { struct nlattr *nla; int rem; @@ -188,14 +183,16 @@ int __wrap_nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int if (tb[type]) pr_warn("Attribute of type %#x found multiple times in message, " - "previous attribute is being ignored.\n", type); + "previous attribute is being ignored.\n", + type); tb[type] = nla; } if (rem > 0) pr_warn("netlink: %d bytes leftover after parsing " - "attributes.\n", rem); + "attributes.\n", + rem); return 0; } @@ -210,17 +207,15 @@ int __wrap_nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int * * See nla_parse() */ -int __wrap_nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], - int maxtype, struct nla_policy *policy) +int __wrap_nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy) { if (!nlmsg_valid_hdr(nlh, hdrlen)) return -NLE_MSG_TOOSHORT; - return nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen), - nlmsg_attrlen(nlh, hdrlen), policy); + return nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen), nlmsg_attrlen(nlh, hdrlen), policy); } int32_t nla_get_s32(const struct nlattr *nla) { - return *(const int32_t *) nla_data(nla); + return *(const int32_t *)nla_data(nla); } diff --git a/criu/log.c b/criu/log.c index 439a899f0..c4ce90ec0 100644 --- a/criu/log.c +++ b/criu/log.c @@ -26,12 +26,11 @@ #include "../soccr/soccr.h" #include "compel/log.h" - -#define DEFAULT_LOGFD STDERR_FILENO +#define DEFAULT_LOGFD STDERR_FILENO /* Enable timestamps if verbosity is increased from default */ -#define LOG_TIMESTAMP (DEFAULT_LOGLEVEL + 1) -#define LOG_BUF_LEN (8*1024) -#define EARLY_LOG_BUF_LEN 1024 +#define LOG_TIMESTAMP (DEFAULT_LOGLEVEL + 1) +#define LOG_BUF_LEN (8 * 1024) +#define EARLY_LOG_BUF_LEN 1024 static unsigned int current_loglevel = DEFAULT_LOGLEVEL; static void vprint_on_level(unsigned int, const char *, va_list); @@ -53,7 +52,7 @@ static struct timeval start; * Manual buf len as sprintf will _always_ put '\0' at the end, * but we want a "constant" pid to be there on restore */ -#define TS_BUF_OFF 12 +#define TS_BUF_OFF 12 static void timediff(struct timeval *from, struct timeval *to) { @@ -72,8 +71,7 @@ static void print_ts(void) gettimeofday(&t, NULL); timediff(&start, &t); - snprintf(buffer, TS_BUF_OFF, - "(%02u.%06u)", (unsigned)t.tv_sec, (unsigned)t.tv_usec); + snprintf(buffer, TS_BUF_OFF, "(%02u.%06u)", (unsigned)t.tv_sec, (unsigned)t.tv_usec); buffer[TS_BUF_OFF - 1] = ' '; /* kill the '\0' produced by snprintf */ } @@ -162,8 +160,7 @@ static void print_versions(void) return; } - pr_info("Running on %s %s %s %s %s\n", buf.nodename, buf.sysname, - buf.release, buf.version, buf.machine); + pr_info("Running on %s %s %s %s %s\n", buf.nodename, buf.sysname, buf.release, buf.version, buf.machine); } struct early_log_hdr { @@ -191,8 +188,7 @@ void flush_early_log_buffer(int fd) if (hdr->level <= current_loglevel) { size_t size = 0; while (size < hdr->len) { - ret = write(fd, early_log_buffer + pos + size, - hdr->len - size); + ret = write(fd, early_log_buffer + pos + size, hdr->len - size); if (ret <= 0) break; size += ret; @@ -219,7 +215,7 @@ int log_init(const char *output) return -1; } } else if (output) { - new_logfd = open(output, O_CREAT|O_TRUNC|O_WRONLY|O_APPEND, 0600); + new_logfd = open(output, O_CREAT | O_TRUNC | O_WRONLY | O_APPEND, 0600); if (new_logfd < 0) { pr_perror("Can't create log file %s", output); return -1; @@ -327,7 +323,7 @@ static void early_vprint(const char *format, unsigned int loglevel, va_list para /* Save loglevel */ hdr = (void *)early_log_buffer + early_log_buf_off; - hdr->level = loglevel; + hdr->level = loglevel; /* Skip the log entry size */ early_log_buf_off += sizeof(hdr); if (loglevel >= LOG_TIMESTAMP) { @@ -337,14 +333,12 @@ static void early_vprint(const char *format, unsigned int loglevel, va_list para * keep the same format as the other messages on * log levels with timestamps (>=LOG_TIMESTAMP). */ - log_size = snprintf(early_log_buffer + early_log_buf_off, - sizeof(early_log_buffer) - early_log_buf_off, - "(00.000000) "); + log_size = snprintf(early_log_buffer + early_log_buf_off, sizeof(early_log_buffer) - early_log_buf_off, + "(00.000000) "); } log_size += vsnprintf(early_log_buffer + early_log_buf_off + log_size, - sizeof(early_log_buffer) - early_log_buf_off - log_size, - format, params); + sizeof(early_log_buffer) - early_log_buf_off - log_size, format, params); /* Save log entry size */ hdr->len = log_size; @@ -375,7 +369,7 @@ static void vprint_on_level(unsigned int loglevel, const char *format, va_list p print_ts(); } - size = vsnprintf(buffer + buf_off, sizeof buffer - buf_off, format, params); + size = vsnprintf(buffer + buf_off, sizeof buffer - buf_off, format, params); size += buf_off; while (off < size) { @@ -389,7 +383,7 @@ static void vprint_on_level(unsigned int loglevel, const char *format, va_list p if (loglevel == LOG_ERROR) log_note_err(buffer + buf_off); - errno = _errno; + errno = _errno; } void print_on_level(unsigned int loglevel, const char *format, ...) diff --git a/criu/lsm.c b/criu/lsm.c index 20c015b54..a352f9adf 100644 --- a/criu/lsm.c +++ b/criu/lsm.c @@ -79,7 +79,7 @@ static int verify_selinux_label(char *ctx) * * unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 */ - pos = (char*)ctx; + pos = (char *)ctx; for (i = 0; i < 3; i++) { pos = strstr(pos, ":"); if (!pos) @@ -213,7 +213,6 @@ int dump_xattr_security_selinux(int fd, FdinfoEntry *e) void kerndat_lsm(void) { - if (access(AA_SECURITYFS_PATH, F_OK) == 0) { kdat.lsm = LSMTYPE__APPARMOR; return; diff --git a/criu/mem.c b/criu/mem.c index b0a76e4da..ca74bfbb6 100644 --- a/criu/mem.c +++ b/criu/mem.c @@ -80,9 +80,8 @@ int do_task_reset_dirty_track(int pid) unsigned long dump_pages_args_size(struct vm_area_list *vmas) { /* In the worst case I need one iovec for each page */ - return sizeof(struct parasite_dump_pages_args) + - vmas->nr * sizeof(struct parasite_vma_entry) + - (vmas->nr_priv_pages + 1) * sizeof(struct iovec); + return sizeof(struct parasite_dump_pages_args) + vmas->nr * sizeof(struct parasite_vma_entry) + + (vmas->nr_priv_pages + 1) * sizeof(struct iovec); } static inline bool __page_is_zero(u64 pme) @@ -165,7 +164,8 @@ static bool is_stack(struct pstree_item *item, unsigned long vaddr) * the memory contents is present in the pagent image set. */ -static int generate_iovs(struct pstree_item *item, struct vma_area *vma, struct page_pipe *pp, u64 *map, u64 *off, bool has_parent) +static int generate_iovs(struct pstree_item *item, struct vma_area *vma, struct page_pipe *pp, u64 *map, u64 *off, + bool has_parent) { u64 *at = &map[PAGE_PFN(*off)]; unsigned long pfn, nr_to_scan; @@ -221,13 +221,12 @@ static int generate_iovs(struct pstree_item *item, struct vma_area *vma, struct cnt_add(CNT_PAGES_LAZY, pages[1]); cnt_add(CNT_PAGES_WRITTEN, pages[2]); - pr_info("Pagemap generated: %lu pages (%lu lazy) %lu holes\n", - pages[2] + pages[1], pages[1], pages[0]); + pr_info("Pagemap generated: %lu pages (%lu lazy) %lu holes\n", pages[2] + pages[1], pages[1], pages[0]); return ret; } -static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl *ctl, - struct vm_area_list *vma_area_list, bool skip_non_trackable) +static struct parasite_dump_pages_args * +prep_dump_pages_args(struct parasite_ctl *ctl, struct vm_area_list *vma_area_list, bool skip_non_trackable) { struct parasite_dump_pages_args *args; struct parasite_vma_entry *p_vma; @@ -261,8 +260,7 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl return args; } -static int drain_pages(struct page_pipe *pp, struct parasite_ctl *ctl, - struct parasite_dump_pages_args *args) +static int drain_pages(struct page_pipe *pp, struct parasite_ctl *ctl, struct parasite_dump_pages_args *args) { struct page_pipe_buf *ppb; int ret = 0; @@ -273,8 +271,8 @@ static int drain_pages(struct page_pipe *pp, struct parasite_ctl *ctl, list_for_each_entry(ppb, &pp->bufs, l) { args->nr_segs = ppb->nr_segs; args->nr_pages = ppb->pages_in; - pr_debug("PPB: %d pages %d segs %u pipe %d off\n", - args->nr_pages, args->nr_segs, ppb->pipe_size, args->off); + pr_debug("PPB: %d pages %d segs %u pipe %d off\n", args->nr_pages, args->nr_segs, ppb->pipe_size, + args->off); ret = compel_rpc_call(PARASITE_CMD_DUMPPAGES, ctl); if (ret < 0) @@ -308,9 +306,7 @@ static int xfer_pages(struct page_pipe *pp, struct page_xfer *xfer) return ret; } -static int detect_pid_reuse(struct pstree_item *item, - struct proc_pid_stat* pps, - InventoryEntry *parent_ie) +static int detect_pid_reuse(struct pstree_item *item, struct proc_pid_stat *pps, InventoryEntry *parent_ie) { unsigned long long dump_ticks; struct proc_pid_stat pps_buf; @@ -322,7 +318,7 @@ static int detect_pid_reuse(struct pstree_item *item, return pidfd_store_check_pid_reuse(item->pid->real); if (!parent_ie) { - pr_err("Pid-reuse detection failed: no parent inventory, " \ + pr_err("Pid-reuse detection failed: no parent inventory, " "check warnings in get_parent_inventory\n"); return -1; } @@ -340,31 +336,25 @@ static int detect_pid_reuse(struct pstree_item *item, return -1; } - dump_ticks = parent_ie->dump_uptime/(USEC_PER_SEC/tps); + dump_ticks = parent_ie->dump_uptime / (USEC_PER_SEC / tps); if (pps->start_time >= dump_ticks) { /* Print "*" if unsure */ - pr_warn("Pid reuse%s detected for pid %d\n", - pps->start_time == dump_ticks ? "*" : "", - item->pid->real); + pr_warn("Pid reuse%s detected for pid %d\n", pps->start_time == dump_ticks ? "*" : "", item->pid->real); return 1; } return 0; } -static int generate_vma_iovs(struct pstree_item *item, struct vma_area *vma, - struct page_pipe *pp, struct page_xfer *xfer, - struct parasite_dump_pages_args *args, - struct parasite_ctl *ctl, pmc_t *pmc, - bool has_parent, bool pre_dump, - int parent_predump_mode) +static int generate_vma_iovs(struct pstree_item *item, struct vma_area *vma, struct page_pipe *pp, + struct page_xfer *xfer, struct parasite_dump_pages_args *args, struct parasite_ctl *ctl, + pmc_t *pmc, bool has_parent, bool pre_dump, int parent_predump_mode) { u64 off = 0; u64 *map; int ret; - if (!vma_area_is_private(vma, kdat.task_size) && - !vma_area_is(vma, VMA_ANON_SHARED)) + if (!vma_area_is_private(vma, kdat.task_size) && !vma_area_is(vma, VMA_ANON_SHARED)) return 0; /* @@ -408,8 +398,7 @@ static int generate_vma_iovs(struct pstree_item *item, struct vma_area *vma, if (!(vma->e->prot & PROT_READ)) { if (opts.pre_dump_mode == PRE_DUMP_READ && pre_dump) return 0; - if ((parent_predump_mode == PRE_DUMP_READ && - opts.pre_dump_mode == PRE_DUMP_SPLICE) || !pre_dump) + if ((parent_predump_mode == PRE_DUMP_READ && opts.pre_dump_mode == PRE_DUMP_SPLICE) || !pre_dump) has_parent = false; } @@ -427,7 +416,7 @@ static int generate_vma_iovs(struct pstree_item *item, struct vma_area *vma, return add_shmem_area(item->pid->real, vma->e, map); again: - ret = generate_iovs(item,vma, pp, map, &off, has_parent); + ret = generate_iovs(item, vma, pp, map, &off, has_parent); if (ret == -EAGAIN) { BUG_ON(!(pp->flags & PP_CHUNK_MODE)); @@ -443,11 +432,9 @@ again: return ret; } -static int __parasite_dump_pages_seized(struct pstree_item *item, - struct parasite_dump_pages_args *args, - struct vm_area_list *vma_area_list, - struct mem_dump_ctl *mdc, - struct parasite_ctl *ctl) +static int __parasite_dump_pages_seized(struct pstree_item *item, struct parasite_dump_pages_args *args, + struct vm_area_list *vma_area_list, struct mem_dump_ctl *mdc, + struct parasite_ctl *ctl) { pmc_t pmc = PMC_INIT; struct page_pipe *pp; @@ -466,17 +453,14 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, timing_start(TIME_MEMDUMP); - pr_debug(" Private vmas %lu/%lu pages\n", - vma_area_list->nr_priv_pages_longest, vma_area_list->nr_priv_pages); + pr_debug(" Private vmas %lu/%lu pages\n", vma_area_list->nr_priv_pages_longest, vma_area_list->nr_priv_pages); /* * Step 0 -- prepare */ - pmc_size = max(vma_area_list->nr_priv_pages_longest, - vma_area_list->nr_shared_pages_longest); - if (pmc_init(&pmc, item->pid->real, &vma_area_list->h, - pmc_size * PAGE_SIZE)) + pmc_size = max(vma_area_list->nr_priv_pages_longest, vma_area_list->nr_shared_pages_longest); + if (pmc_init(&pmc, item->pid->real, &vma_area_list->h, pmc_size * PAGE_SIZE)) return -1; if (!(mdc->pre_dump || mdc->lazy)) @@ -486,9 +470,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, * use, i.e. on non-lazy non-predump. */ cpp_flags |= PP_CHUNK_MODE; - pp = create_page_pipe(vma_area_list->nr_priv_pages, - mdc->lazy ? NULL : pargs_iovs(args), - cpp_flags); + pp = create_page_pipe(vma_area_list->nr_priv_pages, mdc->lazy ? NULL : pargs_iovs(args), cpp_flags); if (!pp) goto out; @@ -513,32 +495,28 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, } if (xfer.parent) { - possible_pid_reuse = detect_pid_reuse(item, mdc->stat, - mdc->parent_ie); + possible_pid_reuse = detect_pid_reuse(item, mdc->stat, mdc->parent_ie); if (possible_pid_reuse == -1) goto out_xfer; } - /* * Step 1 -- generate the pagemap */ args->off = 0; has_parent = !!xfer.parent && !possible_pid_reuse; - if(mdc->parent_ie) + if (mdc->parent_ie) parent_predump_mode = mdc->parent_ie->pre_dump_mode; list_for_each_entry(vma_area, &vma_area_list->h, list) { - ret = generate_vma_iovs(item, vma_area, pp, &xfer, args, ctl, - &pmc, has_parent, mdc->pre_dump, + ret = generate_vma_iovs(item, vma_area, pp, &xfer, args, ctl, &pmc, has_parent, mdc->pre_dump, parent_predump_mode); if (ret < 0) goto out_xfer; } if (mdc->lazy) - memcpy(pargs_iovs(args), pp->iovs, - sizeof(struct iovec) * pp->nr_iovs); + memcpy(pargs_iovs(args), pp->iovs, sizeof(struct iovec) * pp->nr_iovs); /* * Faking drain_pages for pre-dump here. Actual drain_pages for pre-dump @@ -580,10 +558,8 @@ out: return exit_code; } -int parasite_dump_pages_seized(struct pstree_item *item, - struct vm_area_list *vma_area_list, - struct mem_dump_ctl *mdc, - struct parasite_ctl *ctl) +int parasite_dump_pages_seized(struct pstree_item *item, struct vm_area_list *vma_area_list, struct mem_dump_ctl *mdc, + struct parasite_ctl *ctl) { int ret; struct parasite_dump_pages_args *pargs; @@ -692,7 +668,6 @@ int prepare_mm_pid(struct pstree_item *i) return -1; } - while (vn < ri->mm->n_vmas || img != NULL) { struct vma_area *vma; @@ -721,12 +696,11 @@ int prepare_mm_pid(struct pstree_item *i) ri->vmas.rst_priv_size += PAGE_SIZE; } - pr_info("vma 0x%"PRIx64" 0x%"PRIx64"\n", vma->e->start, vma->e->end); + pr_info("vma 0x%" PRIx64 " 0x%" PRIx64 "\n", vma->e->start, vma->e->end); if (vma_area_is(vma, VMA_ANON_SHARED)) ret = collect_shmem(pid, vma); - else if (vma_area_is(vma, VMA_FILE_PRIVATE) || - vma_area_is(vma, VMA_FILE_SHARED)) + else if (vma_area_is(vma, VMA_FILE_PRIVATE) || vma_area_is(vma, VMA_FILE_SHARED)) ret = collect_filemap(vma); else if (vma_area_is(vma, VMA_AREA_SOCKET)) ret = collect_socket_map(vma); @@ -766,7 +740,7 @@ static inline bool check_cow_vmas(struct vma_area *vma, struct vma_area *pvma) if (!(vma->e->flags & MAP_ANONYMOUS) && vma->e->shmid != pvma->e->shmid) return false; - pr_debug("Found two COW VMAs @0x%"PRIx64"-0x%"PRIx64"\n", vma->e->start, pvma->e->end); + pr_debug("Found two COW VMAs @0x%" PRIx64 "-0x%" PRIx64 "\n", vma->e->start, pvma->e->end); return true; } @@ -886,10 +860,8 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void * bits there. Ideally we'd check for the whole COW-chain * having any data in. */ - addr = mmap(*tgt_addr, size, - vma->e->prot | PROT_WRITE, - vma->e->flags | MAP_FIXED | flag, - vma->e->fd, vma->e->pgoff); + addr = mmap(*tgt_addr, size, vma->e->prot | PROT_WRITE, vma->e->flags | MAP_FIXED | flag, vma->e->fd, + vma->e->pgoff); if (addr == MAP_FAILED) { pr_perror("Unable to map ANON_VMA"); @@ -909,8 +881,7 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void if (vma_has_guard_gap_hidden(vma)) paddr -= PAGE_SIZE; - addr = mremap(paddr, size, size, - MREMAP_FIXED | MREMAP_MAYMOVE, *tgt_addr); + addr = mremap(paddr, size, size, MREMAP_FIXED | MREMAP_MAYMOVE, *tgt_addr); if (addr != *tgt_addr) { pr_perror("Unable to remap a private vma"); return -1; @@ -918,9 +889,9 @@ static int premap_private_vma(struct pstree_item *t, struct vma_area *vma, void } vma->e->status |= VMA_PREMMAPED; - vma->premmaped_addr = (unsigned long) addr; - pr_debug("\tpremap %#016"PRIx64"-%#016"PRIx64" -> %016lx\n", - vma->e->start, vma->e->end, (unsigned long)addr); + vma->premmaped_addr = (unsigned long)addr; + pr_debug("\tpremap %#016" PRIx64 "-%#016" PRIx64 " -> %016lx\n", vma->e->start, vma->e->end, + (unsigned long)addr); if (vma_has_guard_gap_hidden(vma)) { /* Skip guard page */ vma->e->start += PAGE_SIZE; @@ -951,8 +922,7 @@ static inline bool vma_force_premap(struct vma_area *vma, struct list_head *head prev = list_entry(vma->list.prev, struct vma_area, list); if (prev->e->end == vma->e->start) { - pr_debug("Force premmap for 0x%"PRIx64":0x%"PRIx64"\n", - vma->e->start, vma->e->end); + pr_debug("Force premmap for 0x%" PRIx64 ":0x%" PRIx64 "\n", vma->e->start, vma->e->end); return true; } } @@ -969,15 +939,15 @@ static int task_size_check(pid_t pid, VmaEntry *entry) #ifdef __s390x__ if (entry->end <= kdat.task_size) return 0; - pr_err("Can't restore high memory region %lx-%lx because kernel does only support vmas up to %lx\n", entry->start, entry->end, kdat.task_size); + pr_err("Can't restore high memory region %lx-%lx because kernel does only support vmas up to %lx\n", + entry->start, entry->end, kdat.task_size); return -1; #else return 0; #endif } -static int premap_priv_vmas(struct pstree_item *t, struct vm_area_list *vmas, - void **at, struct page_read *pr) +static int premap_priv_vmas(struct pstree_item *t, struct vm_area_list *vmas, void **at, struct page_read *pr) { struct vma_area *vma; unsigned long pstart = 0; @@ -1099,13 +1069,11 @@ static int restore_priv_vma_content(struct pstree_item *t, struct page_read *pr) } if (!vma_area_is(vma, VMA_PREMMAPED)) { - unsigned long len = min_t(unsigned long, - (nr_pages - i) * PAGE_SIZE, - vma->e->end - va); + unsigned long len = min_t(unsigned long, (nr_pages - i) * PAGE_SIZE, vma->e->end - va); if (vma->e->status & VMA_NO_PROT_WRITE) { - pr_debug("VMA 0x%"PRIx64":0x%"PRIx64" RO %#lx:%lu IO\n", - vma->e->start, vma->e->end, va, nr_pages); + pr_debug("VMA 0x%" PRIx64 ":0x%" PRIx64 " RO %#lx:%lu IO\n", vma->e->start, + vma->e->end, va, nr_pages); BUG(); } @@ -1127,8 +1095,7 @@ static int restore_priv_vma_content(struct pstree_item *t, struct page_read *pr) */ off = (va - vma->e->start) / PAGE_SIZE; - p = decode_pointer((off) * PAGE_SIZE + - vma->premmaped_addr); + p = decode_pointer((off)*PAGE_SIZE + vma->premmaped_addr); set_bit(off, vma->page_bitmap); if (vma_inherited(vma)) { @@ -1172,7 +1139,6 @@ static int restore_priv_vma_content(struct pstree_item *t, struct page_read *pr) bitmap_set(vma->page_bitmap, off + 1, nr - 1); } - } } @@ -1197,11 +1163,10 @@ err_read: /* Find all pages, which are not shared with this child */ i = find_next_bit(vma->pvma->page_bitmap, size, i); - if ( i >= size) + if (i >= size) break; - ret = madvise(addr + PAGE_SIZE * i, - PAGE_SIZE, MADV_DONTNEED); + ret = madvise(addr + PAGE_SIZE * i, PAGE_SIZE, MADV_DONTNEED); if (ret < 0) { pr_perror("madvise failed"); return -1; @@ -1223,8 +1188,7 @@ err_read: return 0; err_addr: - pr_err("Page entry address %lx outside of VMA %lx-%lx\n", - va, (long)vma->e->start, (long)vma->e->end); + pr_err("Page entry address %lx outside of VMA %lx-%lx\n", va, (long)vma->e->start, (long)vma->e->end); return -1; } @@ -1309,8 +1273,7 @@ int prepare_mappings(struct pstree_item *t) if (old_premmapped_addr) { ret = munmap(old_premmapped_addr, old_premmapped_len); if (ret < 0) - pr_perror("Unable to unmap %p(%lx)", - old_premmapped_addr, old_premmapped_len); + pr_perror("Unable to unmap %p(%lx)", old_premmapped_addr, old_premmapped_len); } /* @@ -1326,8 +1289,7 @@ int prepare_mappings(struct pstree_item *t) if (ret < 0) pr_perror("Unable to unmap %p(%lx)", addr, tail); rsti(t)->premmapped_len = old_premmapped_len; - pr_info("Shrunk premap area to %p(%lx)\n", - rsti(t)->premmapped_addr, rsti(t)->premmapped_len); + pr_info("Shrunk premap area to %p(%lx)\n", rsti(t)->premmapped_addr, rsti(t)->premmapped_len); } out: @@ -1380,9 +1342,8 @@ int open_vmas(struct pstree_item *t) if (!vma_area_is(vma, VMA_AREA_REGULAR) || !vma->vm_open) continue; - pr_info("Opening %#016"PRIx64"-%#016"PRIx64" %#016"PRIx64" (%x) vma\n", - vma->e->start, vma->e->end, - vma->e->pgoff, vma->e->status); + pr_info("Opening %#016" PRIx64 "-%#016" PRIx64 " %#016" PRIx64 " (%x) vma\n", vma->e->start, + vma->e->end, vma->e->pgoff, vma->e->status); if (vma->vm_open(pid, vma)) { pr_err("`- Can't open vma\n"); @@ -1394,8 +1355,7 @@ int open_vmas(struct pstree_item *t) * turn, puts the VMA_CLOSE bit itself. For all the rest we * need to put it by hands, so that the restorer closes the fd */ - if (!(vma_area_is(vma, VMA_FILE_PRIVATE) || - vma_area_is(vma, VMA_FILE_SHARED))) + if (!(vma_area_is(vma, VMA_FILE_PRIVATE) || vma_area_is(vma, VMA_FILE_SHARED))) vma->e->status |= VMA_CLOSE; } @@ -1426,8 +1386,7 @@ static int prepare_vma_ios(struct pstree_item *t, struct task_restore_args *ta) * If auto-dedup is on we need RDWR mode to be able to punch holes in * the input files (in restorer.c) */ - pages = open_image(CR_FD_PAGES, opts.auto_dedup ? O_RDWR : O_RSTR, - rsti(t)->pages_img_id); + pages = open_image(CR_FD_PAGES, opts.auto_dedup ? O_RDWR : O_RSTR, rsti(t)->pages_img_id); if (!pages) return -1; diff --git a/criu/memfd.c b/criu/memfd.c index 48245eb75..cb3704499 100644 --- a/criu/memfd.c +++ b/criu/memfd.c @@ -22,29 +22,29 @@ #include "protobuf.h" #include "images/memfd.pb-c.h" -#define MEMFD_PREFIX "/memfd:" -#define MEMFD_PREFIX_LEN (sizeof(MEMFD_PREFIX)-1) +#define MEMFD_PREFIX "/memfd:" +#define MEMFD_PREFIX_LEN (sizeof(MEMFD_PREFIX) - 1) -#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ -#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ -#define F_SEAL_GROW 0x0004 /* prevent file from growing */ -#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ /* Linux 5.1+ */ -#define F_SEAL_FUTURE_WRITE 0x0010 /* prevent future writes while mapped */ +#define F_SEAL_FUTURE_WRITE 0x0010 /* prevent future writes while mapped */ struct memfd_dump_inode { - struct list_head list; - u32 id; - u32 dev; - u32 ino; + struct list_head list; + u32 id; + u32 dev; + u32 ino; }; struct memfd_restore_inode { - struct list_head list; - mutex_t lock; - int fdstore_id; - unsigned int pending_seals; - MemfdInodeEntry *mie; + struct list_head list; + mutex_t lock; + int fdstore_id; + unsigned int pending_seals; + MemfdInodeEntry *mie; }; static LIST_HEAD(memfd_inodes); @@ -65,14 +65,13 @@ int is_memfd(dev_t dev) return dev == kdat.shmem_dev; } -static int dump_memfd_inode(int fd, struct memfd_dump_inode *inode, - const char *name, const struct stat *st) +static int dump_memfd_inode(int fd, struct memfd_dump_inode *inode, const char *name, const struct stat *st) { MemfdInodeEntry mie = MEMFD_INODE_ENTRY__INIT; int ret = -1; u32 shmid; - /* + /* * shmids are chosen as the inode number of the corresponding mmaped * file. See handle_vma() in proc_parse.c. * It works for memfd too, because we share the same device as the @@ -80,8 +79,8 @@ static int dump_memfd_inode(int fd, struct memfd_dump_inode *inode, */ shmid = inode->ino; - pr_info("Dumping memfd:%s contents (id %#x, shmid: %#x, size: %"PRIu64")\n", - name, inode->id, shmid, st->st_size); + pr_info("Dumping memfd:%s contents (id %#x, shmid: %#x, size: %" PRIu64 ")\n", name, inode->id, shmid, + st->st_size); if (dump_one_memfd_shmem(fd, shmid, st->st_size) < 0) goto out; @@ -106,8 +105,7 @@ out: return ret; } -static struct memfd_dump_inode * -dump_unique_memfd_inode(int lfd, const char *name, const struct stat *st) +static struct memfd_dump_inode *dump_unique_memfd_inode(int lfd, const char *name, const struct stat *st) { struct memfd_dump_inode *inode; int fd; @@ -189,19 +187,18 @@ int dump_one_memfd_cond(int lfd, u32 *id, struct fd_parms *parms) } const struct fdtype_ops memfd_dump_ops = { - .type = FD_TYPES__MEMFD, - .dump = dump_one_memfd, + .type = FD_TYPES__MEMFD, + .dump = dump_one_memfd, }; - /* * Restore only */ struct memfd_info { - MemfdFileEntry *mfe; - struct file_desc d; - struct memfd_restore_inode *inode; + MemfdFileEntry *mfe; + struct file_desc d; + struct memfd_restore_inode *inode; }; static struct memfd_restore_inode *memfd_alloc_inode(int id) @@ -271,8 +268,7 @@ static int memfd_open_inode_nocache(struct memfd_restore_inode *inode) goto out; if (fchown(fd, mie->uid, mie->gid)) { - pr_perror("Can't change uid %d gid %d of memfd:%s", - (int)mie->uid, (int)mie->gid, mie->name); + pr_perror("Can't change uid %d gid %d of memfd:%s", (int)mie->uid, (int)mie->gid, mie->name); goto out; } diff --git a/criu/mount.c b/criu/mount.c index ffa14fcd1..9bd3b27d9 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -36,14 +36,14 @@ * debugging. */ #define AUTODETECTED_MOUNT "CRIU:AUTOGENERATED" -#define NO_ROOT_MOUNT "CRIU:NO_ROOT" -#define MS_PROPAGATE (MS_SHARED | MS_PRIVATE | MS_UNBINDABLE | MS_SLAVE) +#define NO_ROOT_MOUNT "CRIU:NO_ROOT" +#define MS_PROPAGATE (MS_SHARED | MS_PRIVATE | MS_UNBINDABLE | MS_SLAVE) -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "mnt: " #define BINFMT_MISC_HOME "proc/sys/fs/binfmt_misc" -#define CRTIME_MNT_ID 0 +#define CRTIME_MNT_ID 0 #define CONTEXT_OPT "context=" @@ -126,9 +126,8 @@ static void mntinfo_add_list(struct mount_info *new) } } -static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpath, - unsigned int st_dev, unsigned int st_ino, - unsigned int mnt_id) +static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpath, unsigned int st_dev, + unsigned int st_ino, unsigned int mnt_id) { /* * Goes through all entries in the mountinfo table @@ -196,8 +195,7 @@ static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpat * correct device id and node number. If that is the case, we update the * mount id and link variables with the correct values. */ -struct mount_info *lookup_overlayfs(char *rpath, unsigned int st_dev, - unsigned int st_ino, unsigned int mnt_id) +struct mount_info *lookup_overlayfs(char *rpath, unsigned int st_dev, unsigned int st_ino, unsigned int mnt_id) { struct mount_info *m; @@ -280,12 +278,10 @@ dev_t phys_stat_resolve_dev(struct ns_id *ns, dev_t st_dev, const char *path) * superblock dev-id, in such case return device * obtained from mountinfo (ie subvolume0). */ - return strcmp(m->fstype->name, "btrfs") ? - MKKDEV(major(st_dev), minor(st_dev)) : m->s_dev; + return strcmp(m->fstype->name, "btrfs") ? MKKDEV(major(st_dev), minor(st_dev)) : m->s_dev; } -bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev, - struct ns_id *ns, const char *path) +bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev, struct ns_id *ns, const char *path) { if (st_dev == kdev_to_odev(phys_dev)) return true; @@ -361,8 +357,7 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list) continue; } - pr_err("No parent found for mountpoint %d (@%s)\n", - m->mnt_id, m->mountpoint); + pr_err("No parent found for mountpoint %d (@%s)\n", m->mnt_id, m->mountpoint); return NULL; } @@ -426,11 +421,10 @@ static void __mnt_resort_children(struct mount_info *parent) list_splice(&list, &parent->children); } -static struct mount_info *mnt_subtree_next(struct mount_info *mi, - struct mount_info *root); +static struct mount_info *mnt_subtree_next(struct mount_info *mi, struct mount_info *root); -static void resort_siblings(struct mount_info *root, - void (*resort_children)(struct mount_info *)) { +static void resort_siblings(struct mount_info *root, void (*resort_children)(struct mount_info *)) +{ struct mount_info *mi = root; while (1) { /* @@ -452,8 +446,7 @@ static void mnt_tree_show(struct mount_info *tree, int off) { struct mount_info *m; - pr_info("%*s[%s](%d->%d)\n", off, "", - tree->mountpoint, tree->mnt_id, tree->parent_mnt_id); + pr_info("%*s[%s](%d->%d)\n", off, "", tree->mountpoint, tree->mnt_id, tree->parent_mnt_id); list_for_each_entry(m, &tree->children, siblings) mnt_tree_show(m, off + 1); @@ -469,14 +462,12 @@ static int try_resolve_ext_mount(struct mount_info *info) ext = ext_mount_lookup(info->mountpoint + 1 /* trim the . */); if (ext) { - pr_info("Found %s mapping for %s mountpoint\n", - ext, info->mountpoint); + pr_info("Found %s mapping for %s mountpoint\n", ext, info->mountpoint); info->external = ext; return 1; } - snprintf(devstr, sizeof(devstr), "dev[%d/%d]", - kdev_major(info->s_dev), kdev_minor(info->s_dev)); + snprintf(devstr, sizeof(devstr), "dev[%d/%d]", kdev_major(info->s_dev), kdev_minor(info->s_dev)); if (info->fstype->code == FSTYPE__UNSUPPORTED) { char *val; @@ -514,9 +505,7 @@ static struct mount_info *find_fsroot_mount_for(struct mount_info *bm) struct mount_info *sm; list_for_each_entry(sm, &bm->mnt_bind, mnt_bind) - if (fsroot_mounted(sm) || - (sm->parent == root_yard_mp && - strstartswith(bm->root, sm->root))) + if (fsroot_mounted(sm) || (sm->parent == root_yard_mp && strstartswith(bm->root, sm->root))) return sm; return NULL; @@ -633,8 +622,8 @@ static int validate_mounts(struct mount_info *info, bool for_dump) if (fsroot_mounted(m)) { if (m->fstype->code == FSTYPE__UNSUPPORTED) { - pr_err("FS mnt %s dev %#x root %s unsupported id %d\n", - m->mountpoint, m->s_dev, m->root, m->mnt_id); + pr_err("FS mnt %s dev %#x root %s unsupported id %d\n", m->mountpoint, m->s_dev, + m->root, m->mnt_id); return -1; } } else { @@ -662,8 +651,8 @@ static int validate_mounts(struct mount_info *info, bool for_dump) if (ret < 0) { if (ret == -ENOTSUP) - pr_err("%d:%s doesn't have a proper root mount\n", - m->mnt_id, m->mountpoint); + pr_err("%d:%s doesn't have a proper root mount\n", m->mnt_id, + m->mountpoint); return -1; } } @@ -738,8 +727,7 @@ static struct ns_id *find_ext_ns_id(void) for (ns = ns_ids; ns->next; ns = ns->next) if (ns->type == NS_CRIU && ns->nd == &mnt_ns_desc) { - if (!ns->mnt.mntinfo_list && - !collect_mntinfo(ns, true)) + if (!ns->mnt.mntinfo_list && !collect_mntinfo(ns, true)) break; return ns; } @@ -836,7 +824,7 @@ static int root_path_from_parent(struct mount_info *m, char *buf, int size) return -1; BUG_ON(len <= 0); - if (buf[len-1] == '/') + if (buf[len - 1] == '/') tail_slash = true; size -= len; @@ -848,8 +836,7 @@ static int root_path_from_parent(struct mount_info *m, char *buf, int size) if (m->mountpoint[p_len] == '/') head_slash = true; - len = snprintf(buf, size, "%s%s", - (!tail_slash && !head_slash) ? "/" : "", + len = snprintf(buf, size, "%s%s", (!tail_slash && !head_slash) ? "/" : "", m->mountpoint + p_len + (tail_slash && head_slash)); if (len >= size) return -1; @@ -858,7 +845,8 @@ static int root_path_from_parent(struct mount_info *m, char *buf, int size) return 0; } -static int same_propagation_group(struct mount_info *a, struct mount_info *b) { +static int same_propagation_group(struct mount_info *a, struct mount_info *b) +{ char root_path_a[PATH_MAX], root_path_b[PATH_MAX]; /* @@ -866,8 +854,7 @@ static int same_propagation_group(struct mount_info *a, struct mount_info *b) { * 1) Their parents should be different * 2) Their parents should be together in same shared group */ - if (!a->parent || !b->parent || a->parent == b->parent || - a->parent->shared_id != b->parent->shared_id) + if (!a->parent || !b->parent || a->parent == b->parent || a->parent->shared_id != b->parent->shared_id) return 0; if (root_path_from_parent(a, root_path_a, PATH_MAX)) { @@ -909,15 +896,14 @@ static int resolve_shared_mounts(struct mount_info *info, int root_master_id) need_share = m->shared_id && list_empty(&m->mnt_share); need_master = m->master_id > 0; - pr_debug("Inspecting sharing on %2d shared_id %d master_id %d (@%s)\n", - m->mnt_id, m->shared_id, m->master_id, m->mountpoint); + pr_debug("Inspecting sharing on %2d shared_id %d master_id %d (@%s)\n", m->mnt_id, m->shared_id, + m->master_id, m->mountpoint); for (t = info; t && (need_share || need_master); t = t->next) { if (t == m) continue; if (need_master && t->shared_id == m->master_id) { - pr_debug("\tThe mount %3d is slave for %3d (@%s -> @%s)\n", - m->mnt_id, t->mnt_id, + pr_debug("\tThe mount %3d is slave for %3d (@%s -> @%s)\n", m->mnt_id, t->mnt_id, m->mountpoint, t->mountpoint); list_add(&m->mnt_slave, &t->mnt_slave_list); m->mnt_master = t; @@ -926,9 +912,8 @@ static int resolve_shared_mounts(struct mount_info *info, int root_master_id) /* Collect all mounts from this group */ if (need_share && t->shared_id == m->shared_id) { - pr_debug("\tMount %3d is shared with %3d group %3d (@%s -> @%s)\n", - m->mnt_id, t->mnt_id, m->shared_id, - t->mountpoint, m->mountpoint); + pr_debug("\tMount %3d is shared with %3d group %3d (@%s -> @%s)\n", m->mnt_id, + t->mnt_id, m->shared_id, t->mountpoint, m->mountpoint); list_add(&t->mnt_share, &m->mnt_share); } } @@ -939,8 +924,8 @@ static int resolve_shared_mounts(struct mount_info *info, int root_master_id) */ if (need_master && m->parent && !mnt_is_external(m)) { pr_err("Mount %d %s (master_id: %d shared_id: %d) " - "has unreachable sharing. Try --enable-external-masters.\n", m->mnt_id, - m->mountpoint, m->master_id, m->shared_id); + "has unreachable sharing. Try --enable-external-masters.\n", + m->mnt_id, m->mountpoint, m->master_id, m->shared_id); return -1; } @@ -953,8 +938,7 @@ static int resolve_shared_mounts(struct mount_info *info, int root_master_id) for (t = m->next; t; t = t->next) { if (mounts_sb_equal(m, t)) { list_add(&t->mnt_bind, &m->mnt_bind); - pr_debug("\tThe mount %3d is bind for %3d (@%s -> @%s)\n", - t->mnt_id, m->mnt_id, + pr_debug("\tThe mount %3d is bind for %3d (@%s -> @%s)\n", t->mnt_id, m->mnt_id, t->mountpoint, m->mountpoint); } } @@ -1064,8 +1048,7 @@ int __open_mountpoint(struct mount_info *pm, int mnt_fd) } if (pm->s_dev_rt == MOUNT_INVALID_DEV) { - pr_err("Resolving over invalid device for %#x %s %s\n", - pm->s_dev, pm->fstype->name, pm->ns_mountpoint); + pr_err("Resolving over invalid device for %#x %s %s\n", pm->s_dev, pm->fstype->name, pm->ns_mountpoint); goto err; } @@ -1077,8 +1060,7 @@ int __open_mountpoint(struct mount_info *pm, int mnt_fd) * allocates new device ID). */ if (dev != pm->s_dev_rt) { - pr_err("The file system %#x %#x (%#x) %s %s is inaccessible\n", - pm->s_dev, pm->s_dev_rt, dev, + pr_err("The file system %#x %#x (%#x) %s %s is inaccessible\n", pm->s_dev, pm->s_dev_rt, dev, pm->fstype->name, pm->ns_mountpoint); goto err; } @@ -1114,8 +1096,7 @@ static char *get_clean_mnt(struct mount_info *mi, char *mnt_path_tmp, char *mnt_ } if (mount(mi->mountpoint, mnt_path, NULL, MS_BIND, NULL)) { - pr_warn("Can't bind-mount %d:%s to %s: %s\n", - mi->mnt_id, mi->mountpoint, mnt_path, strerror(errno)); + pr_warn("Can't bind-mount %d:%s to %s: %s\n", mi->mnt_id, mi->mountpoint, mnt_path, strerror(errno)); rmdir(mnt_path); return NULL; } @@ -1317,8 +1298,7 @@ int ns_open_mountpoint(void *arg) * unmount them (see CL_UNPRIVILEGED in sys_umount(), clone_mnt() and * copy_mnt_ns() in linux kernel code). */ - if ((root_ns_mask & CLONE_NEWUSER) && - switch_ns(root_item->pid->real, &user_ns_desc, NULL) < 0) + if ((root_ns_mask & CLONE_NEWUSER) && switch_ns(root_item->pid->real, &user_ns_desc, NULL) < 0) goto err; /* @@ -1331,7 +1311,7 @@ int ns_open_mountpoint(void *arg) } /* Remount all mounts as private to disable propagation */ - if (mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL)) { + if (mount("none", "/", NULL, MS_REC | MS_PRIVATE, NULL)) { pr_perror("Unable to remount"); goto err; } @@ -1346,7 +1326,7 @@ int ns_open_mountpoint(void *arg) * explicitly as when last process exits mntns all mounts in it are * cleaned from their children, and we are exactly the last process. */ - *fd = open(mi->mountpoint, O_DIRECTORY|O_RDONLY); + *fd = open(mi->mountpoint, O_DIRECTORY | O_RDONLY); if (*fd < 0) { pr_perror("Unable to open %s", mi->mountpoint); goto err; @@ -1398,13 +1378,9 @@ int open_mountpoint(struct mount_info *pm) */ if (fd < 0) { int pid, status; - struct clone_arg ca = { - .mi = pm, - .fd = &fd - }; + struct clone_arg ca = { .mi = pm, .fd = &fd }; - pr_info("\tmount is overmounted or has children %s\n", - pm->mountpoint); + pr_info("\tmount is overmounted or has children %s\n", pm->mountpoint); /* * We are overmounted - not accessible in a regular way. We @@ -1415,19 +1391,17 @@ int open_mountpoint(struct mount_info *pm) * to create helper process here as entering user namespace is * irreversible operation. */ - pid = clone_noasan(ns_open_mountpoint, CLONE_VFORK | CLONE_VM - | CLONE_FILES | CLONE_IO | CLONE_SIGHAND - | CLONE_SYSVSEM, &ca); + pid = clone_noasan(ns_open_mountpoint, + CLONE_VFORK | CLONE_VM | CLONE_FILES | CLONE_IO | CLONE_SIGHAND | CLONE_SYSVSEM, + &ca); if (pid == -1) { pr_perror("Can't clone helper process"); goto err; } errno = 0; - if (waitpid(pid, &status, __WALL) != pid || !WIFEXITED(status) - || WEXITSTATUS(status)) { - pr_err("Can't wait or bad status: errno=%d, status=%d\n", - errno, status); + if (waitpid(pid, &status, __WALL) != pid || !WIFEXITED(status) || WEXITSTATUS(status)) { + pr_err("Can't wait or bad status: errno=%d, status=%d\n", errno, status); goto err; } } @@ -1525,8 +1499,7 @@ static __maybe_unused int add_cr_time_mount(struct mount_info *root, char *fsnam mi->next = parent->next; parent->next = mi; list_add(&mi->siblings, &parent->children); - pr_info("Add cr-time mountpoint %s with parent %s(%u)\n", - mi->mountpoint, parent->mountpoint, parent->mnt_id); + pr_info("Add cr-time mountpoint %s with parent %s(%u)\n", mi->mountpoint, parent->mountpoint, parent->mnt_id); return 0; err: @@ -1536,7 +1509,7 @@ err: /* Returns 1 in case of success, -errno in case of mount fail, and 0 on other errors */ static __maybe_unused int mount_cr_time_mount(struct ns_id *ns, unsigned int *s_dev, const char *source, - const char *target, const char *type) + const char *target, const char *type) { int mnt_fd, ret, exit_code = 0; struct stat st; @@ -1554,8 +1527,8 @@ static __maybe_unused int mount_cr_time_mount(struct ns_id *ns, unsigned int *s_ goto restore_ns; } else { if (stat(target, &st) < 0) { - pr_perror("Can't stat %s", target); - exit_code = 0; + pr_perror("Can't stat %s", target); + exit_code = 0; } else { *s_dev = MKKDEV(major(st.st_dev), minor(st.st_dev)); exit_code = 1; @@ -1568,8 +1541,6 @@ out: return ret < 0 ? 0 : exit_code; } - - static int dump_one_fs(struct mount_info *mi) { struct mount_info *pm = mi; @@ -1580,8 +1551,7 @@ static int dump_one_fs(struct mount_info *mi) return 0; /* mnt_bind is a cycled list, so list_for_each can't be used here. */ - for (; &pm->mnt_bind != &mi->mnt_bind || first; - pm = list_entry(pm->mnt_bind.next, typeof(*pm), mnt_bind)) { + for (; &pm->mnt_bind != &mi->mnt_bind || first; pm = list_entry(pm->mnt_bind.next, typeof(*pm), mnt_bind)) { int ret; first = false; @@ -1600,8 +1570,7 @@ static int dump_one_fs(struct mount_info *mi) return 0; } - pr_err("Unable to dump a file system for %d:%s\n", - mi->mnt_id, mi->mountpoint); + pr_err("Unable to dump a file system for %d:%s\n", mi->mnt_id, mi->mountpoint); return -1; } @@ -1609,10 +1578,9 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img) { MntEntry me = MNT_ENTRY__INIT; - pr_info("\t%d: %x:%s @ %s\n", pm->mnt_id, pm->s_dev, - pm->root, pm->mountpoint); + pr_info("\t%d: %x:%s @ %s\n", pm->mnt_id, pm->s_dev, pm->root, pm->mountpoint); - me.fstype = pm->fstype->code; + me.fstype = pm->fstype->code; if (me.fstype == FSTYPE__AUTO) me.fsname = pm->fsname; @@ -1621,8 +1589,7 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img) if (!pm->dumped && dump_one_fs(pm)) return -1; - if (!fsroot_mounted(pm) && - pm->fstype->check_bindmount && pm->fstype->check_bindmount(pm)) + if (!fsroot_mounted(pm) && pm->fstype->check_bindmount && pm->fstype->check_bindmount(pm)) return -1; } @@ -1631,26 +1598,26 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img) return 0; } - me.mnt_id = pm->mnt_id; - me.root_dev = pm->s_dev; - me.parent_mnt_id = pm->parent_mnt_id; - me.flags = pm->flags; - me.sb_flags = pm->sb_flags; - me.has_sb_flags = true; - me.mountpoint = pm->mountpoint + 1; - me.source = pm->source; - me.options = pm->options; - me.shared_id = pm->shared_id; - me.has_shared_id = true; - me.master_id = pm->master_id; - me.has_master_id = true; + me.mnt_id = pm->mnt_id; + me.root_dev = pm->s_dev; + me.parent_mnt_id = pm->parent_mnt_id; + me.flags = pm->flags; + me.sb_flags = pm->sb_flags; + me.has_sb_flags = true; + me.mountpoint = pm->mountpoint + 1; + me.source = pm->source; + me.options = pm->options; + me.shared_id = pm->shared_id; + me.has_shared_id = true; + me.master_id = pm->master_id; + me.has_master_id = true; if (pm->need_plugin) { me.has_with_plugin = true; me.with_plugin = true; } if (pm->deleted) { - me.has_deleted = true; - me.deleted = true; + me.has_deleted = true; + me.deleted = true; } if (pm->internal_sharing) { @@ -1734,48 +1701,45 @@ err: * _plist - a postpone list. _el is added to this list, if _fn_f returns * a positive value, and all lower elements are not enumerated. */ -#define MNT_TREE_WALK(_r, _el, _fn_f, _fn_r, _plist, _prgs) do { \ - struct mount_info *_mi = _r; \ - \ - while (1) { \ - int ret; \ - \ - list_del_init(&_mi->postpone); \ - \ - ret = _fn_f(_mi); \ - if (ret < 0) \ - return -1; \ - else if (ret > 0) { \ - list_add_tail(&_mi->postpone, _plist); \ - goto up; \ - } \ - \ - _prgs++; \ - \ - if (!list_empty(&_mi->children)) { \ - _mi = list_entry(_mi->children._el, \ - struct mount_info, siblings); \ - continue; \ - } \ - up: \ - if (_fn_r(_mi)) \ - return -1; \ - if (_mi == _r) \ - break; \ - if (_mi->siblings._el == &_mi->parent->children) { \ - _mi = _mi->parent; \ - goto up; \ - } \ - _mi = list_entry(_mi->siblings._el, \ - struct mount_info, siblings); \ - } \ +#define MNT_TREE_WALK(_r, _el, _fn_f, _fn_r, _plist, _prgs) \ + do { \ + struct mount_info *_mi = _r; \ + \ + while (1) { \ + int ret; \ + \ + list_del_init(&_mi->postpone); \ + \ + ret = _fn_f(_mi); \ + if (ret < 0) \ + return -1; \ + else if (ret > 0) { \ + list_add_tail(&_mi->postpone, _plist); \ + goto up; \ + } \ + \ + _prgs++; \ + \ + if (!list_empty(&_mi->children)) { \ + _mi = list_entry(_mi->children._el, struct mount_info, siblings); \ + continue; \ + } \ + up: \ + if (_fn_r(_mi)) \ + return -1; \ + if (_mi == _r) \ + break; \ + if (_mi->siblings._el == &_mi->parent->children) { \ + _mi = _mi->parent; \ + goto up; \ + } \ + _mi = list_entry(_mi->siblings._el, struct mount_info, siblings); \ + } \ } while (0) -#define MNT_WALK_NONE 0 && +#define MNT_WALK_NONE 0 && - -static int mnt_tree_for_each(struct mount_info *start, - int (*fn)(struct mount_info *)) +static int mnt_tree_for_each(struct mount_info *start, int (*fn)(struct mount_info *)) { struct mount_info *tmp; LIST_HEAD(postpone); @@ -1796,9 +1760,7 @@ again: pr_err("A few mount points can't be mounted\n"); list_for_each_entry(m, &postpone2, postpone) { - pr_err("%d:%d %s %s %s\n", m->mnt_id, - m->parent_mnt_id, m->root, - m->mountpoint, m->source); + pr_err("%d:%d %s %s %s\n", m->mnt_id, m->parent_mnt_id, m->root, m->mountpoint, m->source); } return -1; } @@ -1809,15 +1771,13 @@ again: goto again; return 0; - } -static int mnt_tree_for_each_reverse(struct mount_info *m, - int (*fn)(struct mount_info *)) +static int mnt_tree_for_each_reverse(struct mount_info *m, int (*fn)(struct mount_info *)) { int progress = 0; - MNT_TREE_WALK(m, prev, MNT_WALK_NONE, fn, (struct list_head *) NULL, progress); + MNT_TREE_WALK(m, prev, MNT_WALK_NONE, fn, (struct list_head *)NULL, progress); return 0; } @@ -1839,8 +1799,7 @@ static char *resolve_source(struct mount_info *mi) if (!IS_ERR_OR_NULL(val)) return val; - if (!stat(mi->source, &st) && S_ISBLK(st.st_mode) && - major(st.st_rdev) == kdev_major(mi->s_dev) && + if (!stat(mi->source, &st) && S_ISBLK(st.st_mode) && major(st.st_rdev) == kdev_major(mi->s_dev) && minor(st.st_rdev) == kdev_minor(mi->s_dev)) return mi->source; } @@ -1851,8 +1810,7 @@ static char *resolve_source(struct mount_info *mi) static int restore_shared_options(struct mount_info *mi, bool private, bool shared, bool slave) { - pr_debug("%d:%s private %d shared %d slave %d\n", - mi->mnt_id, mi->mountpoint, private, shared, slave); + pr_debug("%d:%s private %d shared %d slave %d\n", mi->mnt_id, mi->mountpoint, private, shared, slave); if (mi->flags & MS_UNBINDABLE) { if (shared || slave) { @@ -2027,11 +1985,9 @@ static int fetch_rt_stat(struct mount_info *m, const char *where) * MS_RDONLY is set for both mnt ans sb flags, so we can restore it for one * mount call only if it set for both masks. */ -#define MS_MNT_KNOWN_FLAGS (MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_NOATIME | \ - MS_NODIRATIME | MS_RELATIME | MS_RDONLY) +#define MS_MNT_KNOWN_FLAGS (MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_NOATIME | MS_NODIRATIME | MS_RELATIME | MS_RDONLY) -static int do_simple_mount(struct mount_info *mi, const char *src, const - char *fstype, unsigned long mountflags) +static int do_simple_mount(struct mount_info *mi, const char *src, const char *fstype, unsigned long mountflags) { int ret = mount(src, mi->mountpoint, fstype, mountflags, mi->options); if (ret) @@ -2048,7 +2004,7 @@ static char *mnt_fsname(struct mount_info *mi) static int userns_mount(char *src, void *args, int fd, pid_t pid) { - unsigned long flags = *(unsigned long *) args; + unsigned long flags = *(unsigned long *)args; int rst = -1, err = -1; char target[PSFDS]; @@ -2061,7 +2017,7 @@ static int userns_mount(char *src, void *args, int fd, pid_t pid) if (err) pr_perror("Unable to mount %s", target); - if (rst >= 0 && restore_ns(rst, &mnt_ns_desc)) + if (rst >= 0 && restore_ns(rst, &mnt_ns_desc)) return -1; return err; @@ -2126,16 +2082,14 @@ static int do_new_mount(struct mount_info *mi) } sflags |= MS_RDONLY | MS_REMOUNT; if (userns_call(apply_sb_flags, 0, &sflags, sizeof(sflags), fd)) { - pr_err("Unable to apply mount flags %d for %s", - mi->sb_flags, mi->mountpoint); + pr_err("Unable to apply mount flags %d for %s\n", mi->sb_flags, mi->mountpoint); close(fd); return -1; } close(fd); } - if (mflags && mount(NULL, mi->mountpoint, NULL, - MS_REMOUNT | MS_BIND | mflags, NULL)) { + if (mflags && mount(NULL, mi->mountpoint, NULL, MS_REMOUNT | MS_BIND | mflags, NULL)) { pr_perror("Unable to apply bind-mount options"); return -1; } @@ -2215,7 +2169,7 @@ static int do_bind_mount(struct mount_info *mi) int exit_code = -1, mp_len; bool shared = false; bool master = false; - bool private = false; + bool priv = false; char *mnt_path = NULL; struct stat st; bool umount_mnt_path = false; @@ -2235,13 +2189,13 @@ static int do_bind_mount(struct mount_info *mi) * to proper location in the namespace we restore. */ root = mi->external; - private = !mi->master_id && (mi->internal_sharing || !mi->shared_id); + priv = !mi->master_id && (mi->internal_sharing || !mi->shared_id); goto do_bind; } shared = mi->shared_id && mi->shared_id == mi->bind->shared_id; master = mi->master_id && mi->master_id == mi->bind->master_id; - private = !mi->master_id && !shared; + priv = !mi->master_id && !shared; cut_root = cut_root_for_bind(mi->root, mi->bind->root); /* Mount private can be initialized on mount() callback, which is @@ -2255,8 +2209,7 @@ static int do_bind_mount(struct mount_info *mi) /* Access a mount by fd if mi->bind->mountpoint is overmounted */ if (mi->bind->fd >= 0) { - snprintf(mnt_fd_path, sizeof(mnt_fd_path), - "/proc/self/fd/%d", mi->bind->fd); + snprintf(mnt_fd_path, sizeof(mnt_fd_path), "/proc/self/fd/%d", mi->bind->fd); mnt_path = mnt_fd_path; } @@ -2281,8 +2234,7 @@ static int do_bind_mount(struct mount_info *mi) if (&c->siblings != &mi->bind->children) { /* Get a copy of mi->bind without child mounts */ if (mount(mnt_path, mnt_clean_path, NULL, MS_BIND, NULL)) { - pr_perror("Unable to bind-mount %s to %s", - mnt_path, mnt_clean_path); + pr_perror("Unable to bind-mount %s to %s", mnt_path, mnt_clean_path); return -1; } mnt_path = mnt_clean_path; @@ -2293,8 +2245,7 @@ static int do_bind_mount(struct mount_info *mi) return -1; skip_overmount_check: - snprintf(rpath, sizeof(rpath), "%s/%s", - mnt_path, cut_root); + snprintf(rpath, sizeof(rpath), "%s/%s", mnt_path, cut_root); root = rpath; do_bind: pr_info("\tBind %s to %s\n", root, mi->mountpoint); @@ -2311,16 +2262,14 @@ do_bind: goto err; } } else if (S_ISREG(st.st_mode)) { - int fd = open(root, O_WRONLY | O_CREAT | O_EXCL, - st.st_mode & ~S_IFMT); + int fd = open(root, O_WRONLY | O_CREAT | O_EXCL, st.st_mode & ~S_IFMT); if (fd < 0) { pr_perror("Can't re-create deleted file %s", root); goto err; } close(fd); } else { - pr_err("Unsupported st_mode 0%o deleted root %s\n", - (int)st.st_mode, root); + pr_err("Unsupported st_mode 0%o deleted root %s\n", (int)st.st_mode, root); goto err; } } @@ -2355,9 +2304,7 @@ out: * shared - the mount is in the same shared group with mi->bind * mi->shared_id && !shared - create a new shared group */ - if (restore_shared_options(mi, private, - mi->shared_id && !shared, - mi->master_id && !master)) + if (restore_shared_options(mi, priv, mi->shared_id && !shared, mi->master_id && !master)) goto err; mi->mounted = true; @@ -2490,8 +2437,7 @@ shared: static int do_mount_root(struct mount_info *mi) { - if (restore_shared_options(mi, !mi->shared_id && !mi->master_id, - mi->shared_id, mi->master_id)) + if (restore_shared_options(mi, !mi->shared_id && !mi->master_id, mi->shared_id, mi->master_id)) return -1; return fetch_rt_stat(mi, mi->mountpoint); @@ -2599,7 +2545,7 @@ static int do_umount_one(struct mount_info *mi) if (!mi->parent) return 0; - if (mount("none", mi->parent->mountpoint, "none", MS_REC|MS_PRIVATE, NULL)) { + if (mount("none", mi->parent->mountpoint, "none", MS_REC | MS_PRIVATE, NULL)) { pr_perror("Can't mark %s as private", mi->parent->mountpoint); return -1; } @@ -2732,7 +2678,7 @@ static int cr_pivot_root(char *root) int exit_code = -1; struct stat st; - pr_info("Move the root to %s\n", root ? : "."); + pr_info("Move the root to %s\n", root ?: "."); if (root) { if (chdir(root)) { @@ -2765,7 +2711,7 @@ static int cr_pivot_root(char *root) goto err_tmpfs; } - if (mount("none", put_root, "none", MS_REC|MS_SLAVE, NULL)) { + if (mount("none", put_root, "none", MS_REC | MS_SLAVE, NULL)) { pr_perror("Can't remount root with MS_PRIVATE"); return -1; } @@ -2914,8 +2860,7 @@ static int get_mp_root(MntEntry *me, struct mount_info *mi) mi->external = ext; out: - pr_debug("\t\tWill mount %d from %s%s\n", - mi->mnt_id, ext ? : mi->root, ext ? " (E)" : ""); + pr_debug("\t\tWill mount %d from %s%s\n", mi->mnt_id, ext ?: mi->root, ext ? " (E)" : ""); return 0; } @@ -2923,7 +2868,7 @@ static int get_mp_mountpoint(char *mountpoint, struct mount_info *mi, char *root { int len; - len = strlen(mountpoint) + root_len + 1; + len = strlen(mountpoint) + root_len + 1; mi->mountpoint = xmalloc(len); if (!mi->mountpoint) return -1; @@ -2995,8 +2940,8 @@ static char *mount_update_lsm_context(char *mount_opts) return NULL; before_context[context_start - mount_opts] = 0; - ret = asprintf(&new_options, "%s\"%s\"%s", before_context, - opts.lsm_mount_context, other_options ? other_options : ""); + ret = asprintf(&new_options, "%s\"%s\"%s", before_context, opts.lsm_mount_context, + other_options ? other_options : ""); if (unlikely(ret < 0)) return NULL; pr_debug("\t\tChanged mount 'context=' to %s\n", new_options); @@ -3017,8 +2962,7 @@ static int collect_mnt_from_image(struct mount_info **head, struct mount_info ** root_len = print_ns_root(nsid, 0, root, sizeof(root)); - pr_debug("Reading mountpoint images (id %d pid %d)\n", - nsid->id, (int)nsid->ns_pid); + pr_debug("Reading mountpoint images (id %d pid %d)\n", nsid->id, (int)nsid->ns_pid); while (1) { struct mount_info *pm; @@ -3037,16 +2981,14 @@ static int collect_mnt_from_image(struct mount_info **head, struct mount_info ** if (!*tail) *tail = pm; - pm->mnt_id = me->mnt_id; - pm->parent_mnt_id = me->parent_mnt_id; - pm->s_dev = me->root_dev; - pm->flags = me->flags; - pm->sb_flags = me->sb_flags; + pm->mnt_id = me->mnt_id; + pm->parent_mnt_id = me->parent_mnt_id; + pm->s_dev = me->root_dev; + pm->flags = me->flags; + pm->sb_flags = me->sb_flags; if (!me->has_sb_flags) { - const unsigned int mflags = MS_SHARED | MS_PRIVATE | - MS_SLAVE | MS_UNBINDABLE | - MS_NOSUID | MS_NODEV | MS_NOEXEC | - MS_NOATIME | MS_NODIRATIME | MS_RELATIME; + const unsigned int mflags = MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE | MS_NOSUID | + MS_NODEV | MS_NOEXEC | MS_NOATIME | MS_NODIRATIME | MS_RELATIME; /* * In old images mnt and sb flags are saved together. @@ -3056,11 +2998,11 @@ static int collect_mnt_from_image(struct mount_info **head, struct mount_info ** pm->sb_flags = pm->flags & ~mflags; pm->flags = pm->flags & mflags; } - pm->shared_id = me->shared_id; - pm->master_id = me->master_id; - pm->need_plugin = me->with_plugin; - pm->deleted = me->deleted; - pm->is_ns_root = is_root(me->mountpoint); + pm->shared_id = me->shared_id; + pm->master_id = me->master_id; + pm->need_plugin = me->with_plugin; + pm->deleted = me->deleted; + pm->is_ns_root = is_root(me->mountpoint); if (me->has_internal_sharing) pm->internal_sharing = me->internal_sharing; @@ -3082,7 +3024,6 @@ static int collect_mnt_from_image(struct mount_info **head, struct mount_info ** if (pm->fstype->collect && (pm->fstype->collect(pm) < 0)) goto err; - if (me->fsname) { pm->fsname = xstrdup(me->fsname); if (!pm->fsname) @@ -3251,17 +3192,15 @@ static int merge_mount_trees(struct mount_info *root_yard) if (!first) first = root; - else if (!mounts_sb_equal(root, first) || - strcmp(root->root, first->root)) { + else if (!mounts_sb_equal(root, first) || strcmp(root->root, first->root)) { pr_err("Nested mount namespaces with different " "roots %d (@%s %s) %d (@%s %s) are not supported yet\n", - root->mnt_id, root->mountpoint, root->root, - first->mnt_id, first->mountpoint, first->root); + root->mnt_id, root->mountpoint, root->root, first->mnt_id, first->mountpoint, + first->root); return -1; } - pr_debug("Mountpoint %d (@%s) moved to the root yard\n", - root->mnt_id, root->mountpoint); + pr_debug("Mountpoint %d (@%s) moved to the root yard\n", root->mnt_id, root->mountpoint); root->parent = root_yard; list_add(&root->siblings, &root_yard->children); } @@ -3377,7 +3316,7 @@ static int __depopulate_roots_yard(void) if (mnt_roots == NULL) return 0; - if (mount("none", mnt_roots, "none", MS_REC|MS_PRIVATE, NULL)) { + if (mount("none", mnt_roots, "none", MS_REC | MS_PRIVATE, NULL)) { pr_perror("Can't remount root with MS_PRIVATE"); ret = 1; } @@ -3592,7 +3531,6 @@ static int mntns_set_root_fd(pid_t pid, int fd) int __mntns_get_root_fd(pid_t pid) { - int fd, pfd; int ret; char path[PATH_MAX + 1]; @@ -3764,8 +3702,7 @@ int collect_mnt_namespaces(bool for_dump) } if (ns) { - ret = mount_cr_time_mount(ns, &s_dev, "binfmt_misc", "/" BINFMT_MISC_HOME, - "binfmt_misc"); + ret = mount_cr_time_mount(ns, &s_dev, "binfmt_misc", "/" BINFMT_MISC_HOME, "binfmt_misc"); if (ret == -EPERM) pr_info("Can't mount binfmt_misc: EPERM. Running in user_ns?\n"); else if (ret < 0 && ret != -EBUSY && ret != -ENODEV && ret != -ENOENT) { @@ -3774,8 +3711,8 @@ int collect_mnt_namespaces(bool for_dump) } else if (ret == 0) { ret = -1; goto err; - } else if (ret > 0 && add_cr_time_mount(ns->mnt.mntinfo_tree, "binfmt_misc", - BINFMT_MISC_HOME, s_dev) < 0) { + } else if (ret > 0 && add_cr_time_mount(ns->mnt.mntinfo_tree, "binfmt_misc", BINFMT_MISC_HOME, + s_dev) < 0) { ret = -1; goto err; } @@ -3814,7 +3751,7 @@ int dump_mnt_namespaces(void) if ((nsid->type == NS_OTHER) && check_mnt_id()) { pr_err("Nested mount namespaces are not supported " - "without mnt_id in fdinfo\n"); + "without mnt_id in fdinfo\n"); return -1; } @@ -3863,8 +3800,7 @@ static int call_helper_process(int (*call)(void *), void *arg) */ lock_last_pid(); - pid = clone_noasan(call, CLONE_VFORK | CLONE_VM | CLONE_FILES | - CLONE_IO | CLONE_SIGHAND | CLONE_SYSVSEM, arg); + pid = clone_noasan(call, CLONE_VFORK | CLONE_VM | CLONE_FILES | CLONE_IO | CLONE_SIGHAND | CLONE_SYSVSEM, arg); if (pid == -1) { pr_perror("Can't clone helper process"); goto out; @@ -3896,8 +3832,8 @@ static int ns_remount_writable(void *arg) return 1; pr_debug("Switched to mntns %u:%u\n", ns->id, ns->kid); - if (mount(NULL, mi->ns_mountpoint, NULL, MS_REMOUNT | MS_BIND | - (mi->flags & ~(MS_PROPAGATE | MS_RDONLY)), NULL) == -1) { + if (mount(NULL, mi->ns_mountpoint, NULL, MS_REMOUNT | MS_BIND | (mi->flags & ~(MS_PROPAGATE | MS_RDONLY)), + NULL) == -1) { pr_perror("Failed to remount %d:%s writable", mi->mnt_id, mi->mountpoint); return 1; } @@ -3929,8 +3865,8 @@ int try_remount_writable(struct mount_info *mi, bool ns) pr_info("Remount %d:%s writable\n", mi->mnt_id, mi->mountpoint); if (!ns) { - if (mount(NULL, mi->mountpoint, NULL, MS_REMOUNT | MS_BIND | - (mi->flags & ~(MS_PROPAGATE | MS_RDONLY)), NULL) == -1) { + if (mount(NULL, mi->mountpoint, NULL, + MS_REMOUNT | MS_BIND | (mi->flags & ~(MS_PROPAGATE | MS_RDONLY)), NULL) == -1) { pr_perror("Failed to remount %d:%s writable", mi->mnt_id, mi->mountpoint); return -1; } @@ -3969,11 +3905,8 @@ static int __remount_readonly_mounts(struct ns_id *ns) } pr_info("Remount %d:%s back to readonly\n", mi->mnt_id, mi->mountpoint); - if (mount(NULL, mi->ns_mountpoint, NULL, - MS_REMOUNT | MS_BIND | (mi->flags & ~MS_PROPAGATE), - NULL)) { - pr_perror("Failed to restore %d:%s mount flags %x", - mi->mnt_id, mi->mountpoint, mi->flags); + if (mount(NULL, mi->ns_mountpoint, NULL, MS_REMOUNT | MS_BIND | (mi->flags & ~MS_PROPAGATE), NULL)) { + pr_perror("Failed to restore %d:%s mount flags %x", mi->mnt_id, mi->mountpoint, mi->flags); return -1; } } @@ -4005,19 +3938,16 @@ int remount_readonly_mounts(void) return call_helper_process(ns_remount_readonly_mounts, NULL); } -static struct mount_info *mnt_subtree_next(struct mount_info *mi, - struct mount_info *root) +static struct mount_info *mnt_subtree_next(struct mount_info *mi, struct mount_info *root) { if (!list_empty(&mi->children)) - return list_entry(mi->children.next, - struct mount_info, siblings); + return list_entry(mi->children.next, struct mount_info, siblings); while (mi->parent && mi != root) { if (mi->siblings.next == &mi->parent->children) mi = mi->parent; else - return list_entry(mi->siblings.next, - struct mount_info, siblings); + return list_entry(mi->siblings.next, struct mount_info, siblings); } return NULL; diff --git a/criu/namespaces.c b/criu/namespaces.c index b441d2a60..b1a15dde8 100644 --- a/criu/namespaces.c +++ b/criu/namespaces.c @@ -36,14 +36,8 @@ #include "images/pidns.pb-c.h" static struct ns_desc *ns_desc_array[] = { - &net_ns_desc, - &uts_ns_desc, - &ipc_ns_desc, - &pid_ns_desc, - &user_ns_desc, - &mnt_ns_desc, - &time_ns_desc, - &cgroup_ns_desc, + &net_ns_desc, &uts_ns_desc, &ipc_ns_desc, &pid_ns_desc, + &user_ns_desc, &mnt_ns_desc, &time_ns_desc, &cgroup_ns_desc, }; static unsigned int join_ns_flags; @@ -79,9 +73,7 @@ static int check_int_str(char *str) errno = EINVAL; val = strtol(str, &endptr, 10); - if ((errno == ERANGE) || (endptr == str) - || (*endptr != '\0') - || (val < 0) || (val > 65535)) { + if ((errno == ERANGE) || (endptr == str) || (*endptr != '\0') || (val < 0) || (val > 65535)) { str = NULL; return -1; } @@ -102,8 +94,7 @@ static int check_ns_file(char *ns_file) } proc_dir = open_pid_proc(pid); if (proc_dir < 0) { - pr_err("Invalid join_ns pid: /proc/%s not found\n", - ns_file); + pr_err("Invalid join_ns pid: /proc/%s not found\n", ns_file); return -1; } return 0; @@ -300,8 +291,7 @@ static void nsid_add(struct ns_id *ns, struct ns_desc *nd, unsigned int id, pid_ pr_info("Add %s ns %d pid %d\n", nd->str, ns->id, ns->ns_pid); } -static struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, - struct ns_desc *nd, enum ns_type type) +static struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd, enum ns_type type) { struct ns_id *nsid; @@ -333,8 +323,7 @@ int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd) return 0; } - nsid = rst_new_ns_id(id, pid, nd, - i == root_item ? NS_ROOT : NS_OTHER); + nsid = rst_new_ns_id(id, pid, nd, i == root_item ? NS_ROOT : NS_OTHER); if (nsid == NULL) return -1; @@ -403,8 +392,7 @@ int walk_namespaces(struct ns_desc *nd, int (*cb)(struct ns_id *, void *), void return ret; } -static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd, - struct ns_id **ns_ret) +static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd, struct ns_id **ns_ret) { struct ns_id *nsid; enum ns_type type; @@ -421,8 +409,7 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd root_ns_mask |= nd->cflag; type = NS_ROOT; } else if (nd->cflag & ~CLONE_SUBNS) { - pr_err("Can't dump nested %s namespace for %d\n", - nd->str, pid); + pr_err("Can't dump nested %s namespace for %d\n", nd->str, pid); return 0; } } else @@ -498,10 +485,10 @@ int dump_one_ns_file(int lfd, u32 id, const struct fd_parms *p) return -1; } - nfe.id = id; - nfe.ns_id = nsid->id; - nfe.ns_cflag = link->ns_d->cflag; - nfe.flags = p->flags; + nfe.id = id; + nfe.ns_id = nsid->id; + nfe.ns_cflag = link->ns_d->cflag; + nfe.flags = p->flags; fe.type = FD_TYPES__NS; fe.id = nfe.id; @@ -512,13 +499,13 @@ int dump_one_ns_file(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops nsfile_dump_ops = { - .type = FD_TYPES__NS, - .dump = dump_one_ns_file, + .type = FD_TYPES__NS, + .dump = dump_one_ns_file, }; struct ns_file_info { - struct file_desc d; - NsFileEntry *nfe; + struct file_desc d; + NsFileEntry *nfe; }; static int open_ns_fd(struct file_desc *d, int *new_fd) @@ -740,8 +727,7 @@ static unsigned int userns_id(unsigned int id, UidGidExtent **map, int n) return id; for (i = 0; i < n; i++) { - if (map[i]->lower_first <= id && - map[i]->lower_first + map[i]->count > id) + if (map[i]->lower_first <= id && map[i]->lower_first + map[i]->count > id) return map[i]->first + (id - map[i]->lower_first); } @@ -756,8 +742,7 @@ static unsigned int host_id(unsigned int id, UidGidExtent **map, int n) return id; for (i = 0; i < n; i++) { - if (map[i]->first <= id && - map[i]->first + map[i]->count > id) + if (map[i]->first <= id && map[i]->first + map[i]->count > id) return map[i]->lower_first + (id - map[i]->first); } @@ -815,8 +800,7 @@ static int parse_id_map(pid_t pid, char *name, UidGidExtent ***pb_exts) ext = &extents[len]; uid_gid_extent__init(ext); - ret = fscanf(f, "%d %d %d", &ext->first, - &ext->lower_first, &ext->count); + ret = fscanf(f, "%d %d %d", &ext->first, &ext->lower_first, &ext->count); if (ret != 3) { if (ferror(f)) { pr_perror("Unable to parse extents: %d", ret); @@ -943,20 +927,15 @@ static int check_user_ns(int pid) if (switch_ns(pid, &user_ns_desc, NULL)) exit(1); - if ((root_ns_mask & CLONE_NEWNET) && - switch_ns(pid, &net_ns_desc, NULL)) + if ((root_ns_mask & CLONE_NEWNET) && switch_ns(pid, &net_ns_desc, NULL)) exit(1); - if ((root_ns_mask & CLONE_NEWUTS) && - switch_ns(pid, &uts_ns_desc, NULL)) + if ((root_ns_mask & CLONE_NEWUTS) && switch_ns(pid, &uts_ns_desc, NULL)) exit(1); - if ((root_ns_mask & CLONE_NEWTIME) && - switch_ns(pid, &time_ns_desc, NULL)) + if ((root_ns_mask & CLONE_NEWTIME) && switch_ns(pid, &time_ns_desc, NULL)) exit(1); - if ((root_ns_mask & CLONE_NEWIPC) && - switch_ns(pid, &ipc_ns_desc, NULL)) + if ((root_ns_mask & CLONE_NEWIPC) && switch_ns(pid, &ipc_ns_desc, NULL)) exit(1); - if ((root_ns_mask & CLONE_NEWNS) && - switch_ns(pid, &mnt_ns_desc, NULL)) + if ((root_ns_mask & CLONE_NEWNS) && switch_ns(pid, &mnt_ns_desc, NULL)) exit(1); exit(0); } @@ -1036,23 +1015,19 @@ static int do_dump_namespaces(struct ns_id *ns) switch (ns->nd->cflag) { case CLONE_NEWUTS: - pr_info("Dump UTS namespace %d via %d\n", - ns->id, ns->ns_pid); + pr_info("Dump UTS namespace %d via %d\n", ns->id, ns->ns_pid); ret = dump_uts_ns(ns->id); break; case CLONE_NEWTIME: - pr_info("Dump TIME namespace %d via %d\n", - ns->id, ns->ns_pid); + pr_info("Dump TIME namespace %d via %d\n", ns->id, ns->ns_pid); ret = dump_time_ns(ns->id); break; case CLONE_NEWIPC: - pr_info("Dump IPC namespace %d via %d\n", - ns->id, ns->ns_pid); + pr_info("Dump IPC namespace %d via %d\n", ns->id, ns->ns_pid); ret = dump_ipc_ns(ns->id); break; case CLONE_NEWNET: - pr_info("Dump NET namespace info %d via %d\n", - ns->id, ns->ns_pid); + pr_info("Dump NET namespace info %d via %d\n", ns->id, ns->ns_pid); ret = dump_net_ns(ns); break; default: @@ -1061,7 +1036,6 @@ static int do_dump_namespaces(struct ns_id *ns) } return ret; - } int dump_namespaces(struct pstree_item *item, unsigned int ns_flags) @@ -1108,15 +1082,15 @@ int dump_namespaces(struct pstree_item *item, unsigned int ns_flags) continue; switch (ns->nd->cflag) { - /* No data for pid namespaces to dump */ - case CLONE_NEWPID: - /* Dumped explicitly with dump_mnt_namespaces() */ - case CLONE_NEWNS: - /* Userns is dumped before dumping tasks */ - case CLONE_NEWUSER: - /* handled separately in cgroup dumping code */ - case CLONE_NEWCGROUP: - continue; + /* No data for pid namespaces to dump */ + case CLONE_NEWPID: + /* Dumped explicitly with dump_mnt_namespaces() */ + case CLONE_NEWNS: + /* Userns is dumped before dumping tasks */ + case CLONE_NEWUSER: + /* handled separately in cgroup dumping code */ + case CLONE_NEWCGROUP: + continue; } pid = fork(); @@ -1167,10 +1141,8 @@ static int write_id_map(pid_t pid, UidGidExtent **extents, int n, char *id_map) for (i = 0; i < n; i++) { int len; - len = snprintf(buf + off, sizeof(buf) - off, - "%u %u %u\n", extents[i]->first, - extents[i]->lower_first, - extents[i]->count); + len = snprintf(buf + off, sizeof(buf) - off, "%u %u %u\n", extents[i]->first, extents[i]->lower_first, + extents[i]->count); if (len < 0) { pr_perror("Unable to form the user/group mappings buffer"); return -1; @@ -1207,8 +1179,7 @@ struct unsc_msg { static int usernsd_pid; -static inline void unsc_msg_init(struct unsc_msg *m, uns_call_t *c, - int *x, void *arg, size_t asize, int fd) +static inline void unsc_msg_init(struct unsc_msg *m, uns_call_t *c, int *x, void *arg, size_t asize, int fd) { struct cmsghdr *ch; struct ucred *ucred; @@ -1245,7 +1216,7 @@ static inline void unsc_msg_init(struct unsc_msg *m, uns_call_t *c, ch->cmsg_level = SOL_SOCKET; ch->cmsg_type = SCM_CREDENTIALS; - ucred = (struct ucred *) CMSG_DATA(ch); + ucred = (struct ucred *)CMSG_DATA(ch); ucred->pid = getpid(); ucred->uid = getuid(); ucred->gid = getgid(); @@ -1273,7 +1244,7 @@ static void unsc_msg_pid_fd(struct unsc_msg *um, pid_t *pid, int *fd) BUG_ON(ch->cmsg_type != SCM_CREDENTIALS); if (pid) { - ucred = (struct ucred *) CMSG_DATA(ch); + ucred = (struct ucred *)CMSG_DATA(ch); *pid = ucred->pid; } @@ -1360,8 +1331,7 @@ static int usernsd(int sk) } } -int __userns_call(const char *func_name, uns_call_t call, int flags, - void *arg, size_t arg_size, int fd) +int __userns_call(const char *func_name, uns_call_t call, int flags, void *arg, size_t arg_size, int fd) { int ret, res, sk; bool async = flags & UNS_ASYNC; @@ -1753,8 +1723,7 @@ int prepare_namespace(struct pstree_item *item, unsigned long clone_flags) sigset_t sig_mask; int id, ret = -1; - pr_info("Restoring namespaces %d flags 0x%lx\n", - vpid(item), clone_flags); + pr_info("Restoring namespaces %d flags 0x%lx\n", vpid(item), clone_flags); if (block_sigmask(&sig_mask, SIGCHLD) < 0) return -1; diff --git a/criu/net.c b/criu/net.c index 51b02efe7..144e9b5c5 100644 --- a/criu/net.c +++ b/criu/net.c @@ -51,17 +51,17 @@ #include "images/inventory.pb-c.h" #ifndef IFLA_NEW_IFINDEX -#define IFLA_NEW_IFINDEX 49 +#define IFLA_NEW_IFINDEX 49 #endif #ifndef IFLA_LINK_NETNSID -#define IFLA_LINK_NETNSID 37 +#define IFLA_LINK_NETNSID 37 #undef IFLA_MAX #define IFLA_MAX IFLA_LINK_NETNSID #endif #ifndef RTM_NEWNSID -#define RTM_NEWNSID 88 +#define RTM_NEWNSID 88 #endif #ifndef IFLA_MACVLAN_FLAGS @@ -90,7 +90,7 @@ enum { IFLA_IPTUN_ENCAP_DPORT, __IFLA_IPTUN_MAX, }; -#define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1) +#define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1) static int ns_sysfs_fd = -1; @@ -126,11 +126,11 @@ static bool sysctl_entries_equal(SysctlEntry *a, SysctlEntry *b) return false; switch (a->type) { - case SYSCTL_TYPE__CTL_32: - return a->has_iarg && b->has_iarg && a->iarg == b->iarg; - case SYSCTL_TYPE__CTL_STR: - return a->sarg && b->sarg && !strcmp(a->sarg, b->sarg); - default:; + case SYSCTL_TYPE__CTL_32: + return a->has_iarg && b->has_iarg && a->iarg == b->iarg; + case SYSCTL_TYPE__CTL_STR: + return a->sarg && b->sarg && !strcmp(a->sarg, b->sarg); + default:; } return false; @@ -214,9 +214,9 @@ char *devconfs6[] = { "use_tempaddr", }; -#define CONF_OPT_PATH "net/%s/conf/%s/%s" -#define MAX_CONF_OPT_PATH IFNAMSIZ+60 -#define MAX_STR_CONF_LEN 200 +#define CONF_OPT_PATH "net/%s/conf/%s/%s" +#define MAX_CONF_OPT_PATH IFNAMSIZ + 60 +#define MAX_STR_CONF_LEN 200 static const char *unix_conf_entries[] = { "max_dgram_qlen", @@ -226,14 +226,13 @@ static const char *unix_conf_entries[] = { * MAX_CONF_UNIX_PATH = (sizeof(CONF_UNIX_FMT) - strlen("%s")) * + MAX_CONF_UNIX_OPT_PATH */ -#define CONF_UNIX_BASE "net/unix" -#define CONF_UNIX_FMT CONF_UNIX_BASE"/%s" -#define MAX_CONF_UNIX_OPT_PATH 32 -#define MAX_CONF_UNIX_PATH (sizeof(CONF_UNIX_FMT) + MAX_CONF_UNIX_OPT_PATH - 2) +#define CONF_UNIX_BASE "net/unix" +#define CONF_UNIX_FMT CONF_UNIX_BASE "/%s" +#define MAX_CONF_UNIX_OPT_PATH 32 +#define MAX_CONF_UNIX_PATH (sizeof(CONF_UNIX_FMT) + MAX_CONF_UNIX_OPT_PATH - 2) -static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto, - struct sysctl_req *req, char (*path)[MAX_CONF_OPT_PATH], int size, - char **devconfs, SysctlEntry **def_conf) +static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto, struct sysctl_req *req, + char (*path)[MAX_CONF_OPT_PATH], int size, char **devconfs, SysctlEntry **def_conf) { int i, ri, ar = -1; int ret, flags = op == CTL_READ ? CTL_FLAGS_OPTIONAL : 0; @@ -259,8 +258,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto * mtu may be changed by disable_ipv6 so we can not skip * it's restore */ - if (def_conf && sysctl_entries_equal(conf[i], def_conf[i]) - && strcmp(devconfs[i], "mtu")) { + if (def_conf && sysctl_entries_equal(conf[i], def_conf[i]) && strcmp(devconfs[i], "mtu")) { pr_debug("Skip %s/%s, coincides with default\n", tgt, devconfs[i]); continue; } @@ -278,36 +276,34 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto req[ri].name = path[i]; req[ri].flags = flags; switch (conf[i]->type) { - case SYSCTL_TYPE__CTL_32: - req[ri].type = CTL_32; - - /* skip non-existing sysctl */ - if (op == CTL_WRITE && !conf[i]->has_iarg) - continue; - - req[ri].arg = &conf[i]->iarg; - break; - case SYSCTL_TYPE__CTL_STR: - req[ri].type = CTL_STR(MAX_STR_CONF_LEN); - req[ri].flags |= op == CTL_READ && !strcmp(devconfs[i], "stable_secret") - ? CTL_FLAGS_READ_EIO_SKIP : 0; - - /* skip non-existing sysctl */ - if (op == CTL_WRITE && !conf[i]->sarg) - continue; - - req[ri].arg = conf[i]->sarg; - break; - default: + case SYSCTL_TYPE__CTL_32: + req[ri].type = CTL_32; + + /* skip non-existing sysctl */ + if (op == CTL_WRITE && !conf[i]->has_iarg) + continue; + + req[ri].arg = &conf[i]->iarg; + break; + case SYSCTL_TYPE__CTL_STR: + req[ri].type = CTL_STR(MAX_STR_CONF_LEN); + req[ri].flags |= + op == CTL_READ && !strcmp(devconfs[i], "stable_secret") ? CTL_FLAGS_READ_EIO_SKIP : 0; + + /* skip non-existing sysctl */ + if (op == CTL_WRITE && !conf[i]->sarg) continue; + + req[ri].arg = conf[i]->sarg; + break; + default: + continue; } rconf[ri] = conf[i]; ri++; } - if (ar != -1 - && conf[ar]->type == SYSCTL_TYPE__CTL_32 - && conf[ar]->has_iarg) { + if (ar != -1 && conf[ar]->type == SYSCTL_TYPE__CTL_32 && conf[ar]->has_iarg) { snprintf(path[ar], MAX_CONF_OPT_PATH, CONF_OPT_PATH, proto, tgt, devconfs[ar]); req[ri].name = path[ar]; req[ri].type = CTL_32; @@ -319,7 +315,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto ret = sysctl_op(req, ri, op, CLONE_NEWNET); if (ret < 0) { - pr_err("Failed to %s %s/<confs>\n", (op == CTL_READ)?"read":"write", tgt); + pr_err("Failed to %s %s/<confs>\n", (op == CTL_READ) ? "read" : "write", tgt); goto err_free; } @@ -345,9 +341,7 @@ static int ipv4_conf_op(char *tgt, SysctlEntry **conf, int n, int op, SysctlEntr struct sysctl_req req[ARRAY_SIZE(devconfs4)]; char path[ARRAY_SIZE(devconfs4)][MAX_CONF_OPT_PATH]; - return net_conf_op(tgt, conf, n, op, "ipv4", - req, path, ARRAY_SIZE(devconfs4), - devconfs4, def_conf); + return net_conf_op(tgt, conf, n, op, "ipv4", req, path, ARRAY_SIZE(devconfs4), devconfs4, def_conf); } static int ipv6_conf_op(char *tgt, SysctlEntry **conf, int n, int op, SysctlEntry **def_conf) @@ -355,21 +349,18 @@ static int ipv6_conf_op(char *tgt, SysctlEntry **conf, int n, int op, SysctlEntr struct sysctl_req req[ARRAY_SIZE(devconfs6)]; char path[ARRAY_SIZE(devconfs6)][MAX_CONF_OPT_PATH]; - return net_conf_op(tgt, conf, n, op, "ipv6", - req, path, ARRAY_SIZE(devconfs6), - devconfs6, def_conf); + return net_conf_op(tgt, conf, n, op, "ipv6", req, path, ARRAY_SIZE(devconfs6), devconfs6, def_conf); } static int unix_conf_op(SysctlEntry ***rconf, size_t *n, int op) { int i, ret = -1, flags = 0; - char path[ARRAY_SIZE(unix_conf_entries)][MAX_CONF_UNIX_PATH] = { }; - struct sysctl_req req[ARRAY_SIZE(unix_conf_entries)] = { }; + char path[ARRAY_SIZE(unix_conf_entries)][MAX_CONF_UNIX_PATH] = {}; + struct sysctl_req req[ARRAY_SIZE(unix_conf_entries)] = {}; SysctlEntry **conf = *rconf; if (*n != ARRAY_SIZE(unix_conf_entries)) { - pr_err("unix: Unexpected entries in config (%zu %zu)\n", - *n, ARRAY_SIZE(unix_conf_entries)); + pr_err("unix: Unexpected entries in config (%zu %zu)\n", *n, ARRAY_SIZE(unix_conf_entries)); return -EINVAL; } @@ -377,8 +368,7 @@ static int unix_conf_op(SysctlEntry ***rconf, size_t *n, int op) flags = CTL_FLAGS_OPTIONAL; for (i = 0; i < *n; i++) { - snprintf(path[i], MAX_CONF_UNIX_PATH, CONF_UNIX_FMT, - unix_conf_entries[i]); + snprintf(path[i], MAX_CONF_UNIX_PATH, CONF_UNIX_FMT, unix_conf_entries[i]); req[i].name = path[i]; req[i].flags = flags; @@ -388,17 +378,14 @@ static int unix_conf_op(SysctlEntry ***rconf, size_t *n, int op) req[i].arg = &conf[i]->iarg; break; default: - pr_err("unix: Unknown config type %d\n", - conf[i]->type); + pr_err("unix: Unknown config type %d\n", conf[i]->type); return -1; } } ret = sysctl_op(req, *n, op, CLONE_NEWNET); if (ret < 0) { - pr_err("unix: Failed to %s %s/<confs>\n", - (op == CTL_READ) ? "read" : "write", - CONF_UNIX_BASE); + pr_err("unix: Failed to %s %s/<confs>\n", (op == CTL_READ) ? "read" : "write", CONF_UNIX_BASE); return -1; } @@ -431,7 +418,7 @@ static int unix_conf_op(SysctlEntry ***rconf, size_t *n, int op) * the kernel, simply write DEVCONFS_UNUSED * into the image so we would skip it. */ -#define DEVCONFS_UNUSED (-1u) +#define DEVCONFS_UNUSED (-1u) static int ipv4_conf_op_old(char *tgt, int *conf, int n, int op, int *def_conf) { @@ -471,7 +458,7 @@ static int ipv4_conf_op_old(char *tgt, int *conf, int n, int op, int *def_conf) ret = sysctl_op(req, ri, op, CLONE_NEWNET); if (ret < 0) { - pr_err("Failed to %s %s/<confs>\n", (op == CTL_READ)?"read":"write", tgt); + pr_err("Failed to %s %s/<confs>\n", (op == CTL_READ) ? "read" : "write", tgt); return -1; } return 0; @@ -493,9 +480,8 @@ static int lookup_net_by_netid(struct ns_id *ns, int net_id) return -1; } -static int dump_one_netdev(int type, struct ifinfomsg *ifi, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds, - int (*dump)(NetDeviceEntry *, struct cr_imgset *, struct nlattr **info)) +static int dump_one_netdev(int type, struct ifinfomsg *ifi, struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds, + int (*dump)(NetDeviceEntry *, struct cr_imgset *, struct nlattr **info)) { int ret = -1, i, peer_ifindex; NetDeviceEntry netdev = NET_DEVICE_ENTRY__INIT; @@ -530,16 +516,14 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi, if (tb[IFLA_LINK_NETNSID]) nsid = nla_get_s32(tb[IFLA_LINK_NETNSID]); - pr_debug("The peer link is in the %d netns with the %u index\n", - nsid, netdev.peer_ifindex); + pr_debug("The peer link is in the %d netns with the %u index\n", nsid, netdev.peer_ifindex); if (nsid == -1) nsid = ns->id; else nsid = lookup_net_by_netid(ns, nsid); if (nsid < 0) { - pr_warn("The %s veth is in an external netns\n", - netdev.name); + pr_warn("The %s veth is in an external netns\n", netdev.name); } else { netdev.has_peer_nsid = true; netdev.peer_nsid = nsid; @@ -554,9 +538,8 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi, netdev.has_address = true; netdev.address.data = nla_data(tb[IFLA_ADDRESS]); netdev.address.len = nla_len(tb[IFLA_ADDRESS]); - pr_info("Found ll addr (%02x:../%d) for %s\n", - (int)netdev.address.data[0], - (int)netdev.address.len, netdev.name); + pr_info("Found ll addr (%02x:../%d) for %s\n", (int)netdev.address.data[0], (int)netdev.address.len, + netdev.name); } if (tb[IFLA_MASTER]) { @@ -646,8 +629,8 @@ static char *link_kind(struct ifinfomsg *ifi, struct nlattr **tb) return nla_data(linkinfo[IFLA_INFO_KIND]); } -static int dump_unknown_device(struct ifinfomsg *ifi, char *kind, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) +static int dump_unknown_device(struct ifinfomsg *ifi, char *kind, struct nlattr **tb, struct ns_id *ns, + struct cr_imgset *fds) { int ret; @@ -656,8 +639,7 @@ static int dump_unknown_device(struct ifinfomsg *ifi, char *kind, return dump_one_netdev(ND_TYPE__EXTLINK, ifi, tb, ns, fds, NULL); if (ret == -ENOTSUP) - pr_err("Unsupported link %d (type %d kind %s)\n", - ifi->ifi_index, ifi->ifi_type, kind); + pr_err("Unsupported link %d (type %d kind %s)\n", ifi->ifi_index, ifi->ifi_type, kind); return -1; } @@ -670,7 +652,7 @@ static int dump_macvlan(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nl { MacvlanLinkEntry macvlan = MACVLAN_LINK_ENTRY__INIT; int ret; - struct nlattr *data[IFLA_MACVLAN_FLAGS+1]; + struct nlattr *data[IFLA_MACVLAN_FLAGS + 1]; if (!info || !info[IFLA_INFO_DATA]) { pr_err("no data for macvlan\n"); @@ -691,14 +673,14 @@ static int dump_macvlan(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nl macvlan.mode = *((u32 *)RTA_DATA(data[IFLA_MACVLAN_MODE])); if (data[IFLA_MACVLAN_FLAGS]) - macvlan.flags = *((u16 *) RTA_DATA(data[IFLA_MACVLAN_FLAGS])); + macvlan.flags = *((u16 *)RTA_DATA(data[IFLA_MACVLAN_FLAGS])); nde->macvlan = &macvlan; return write_netdev_img(nde, imgset, info); } -static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) +static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind, struct nlattr **tb, struct ns_id *ns, + struct cr_imgset *fds) { if (!strcmp(kind, "veth")) /* @@ -735,8 +717,8 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind, return dump_unknown_device(ifi, kind, tb, ns, fds); } -static int dump_one_gendev(struct ifinfomsg *ifi, char *kind, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) +static int dump_one_gendev(struct ifinfomsg *ifi, char *kind, struct nlattr **tb, struct ns_id *ns, + struct cr_imgset *fds) { if (!strcmp(kind, "tun")) return dump_one_netdev(ND_TYPE__TUN, ifi, tb, ns, fds, dump_tun_link); @@ -744,8 +726,8 @@ static int dump_one_gendev(struct ifinfomsg *ifi, char *kind, return dump_unknown_device(ifi, kind, tb, ns, fds); } -static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) +static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind, struct nlattr **tb, struct ns_id *ns, + struct cr_imgset *fds) { if (!strcmp(kind, "venet")) return dump_one_netdev(ND_TYPE__VENET, ifi, tb, ns, fds, NULL); @@ -753,8 +735,7 @@ static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind, return dump_unknown_device(ifi, kind, tb, ns, fds); } -static int dump_one_gre(struct ifinfomsg *ifi, char *kind, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) +static int dump_one_gre(struct ifinfomsg *ifi, char *kind, struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) { if (!strcmp(kind, "gre")) { char *name = (char *)RTA_DATA(tb[IFLA_IFNAME]); @@ -794,11 +775,12 @@ static int dump_sit(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nlattr return -1; } -#define ENCODE_ENTRY(__type, __ifla, __proto) do { \ - if (data[__ifla]) { \ - se.__proto = *(__type *)nla_data(data[__ifla]); \ - se.has_##__proto = true; \ - } \ +#define ENCODE_ENTRY(__type, __ifla, __proto) \ + do { \ + if (data[__ifla]) { \ + se.__proto = *(__type *)nla_data(data[__ifla]); \ + se.has_##__proto = true; \ + } \ } while (0) if (data[IFLA_IPTUN_LOCAL]) { @@ -817,11 +799,11 @@ static int dump_sit(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nlattr } } - ENCODE_ENTRY(u32, IFLA_IPTUN_LINK, link); - ENCODE_ENTRY(u8, IFLA_IPTUN_TTL, ttl); - ENCODE_ENTRY(u8, IFLA_IPTUN_TOS, tos); + ENCODE_ENTRY(u32, IFLA_IPTUN_LINK, link); + ENCODE_ENTRY(u8, IFLA_IPTUN_TTL, ttl); + ENCODE_ENTRY(u8, IFLA_IPTUN_TOS, tos); ENCODE_ENTRY(u16, IFLA_IPTUN_FLAGS, flags); - ENCODE_ENTRY(u8, IFLA_IPTUN_PROTO, proto); + ENCODE_ENTRY(u8, IFLA_IPTUN_PROTO, proto); if (data[IFLA_IPTUN_PMTUDISC]) { u8 v; @@ -831,7 +813,7 @@ static int dump_sit(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nlattr se.pmtudisc = se.has_pmtudisc = true; } - ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_TYPE, encap_type); + ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_TYPE, encap_type); ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_FLAGS, encap_flags); ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_SPORT, encap_sport); ENCODE_ENTRY(u16, IFLA_IPTUN_ENCAP_DPORT, encap_dport); @@ -864,7 +846,7 @@ static int dump_sit(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nlattr memcpy(&rl_prefix, nla_data(data[IFLA_IPTUN_6RD_RELAY_PREFIX]), sizeof(rl_prefix)); se.n_relay_prefix = 1; se.relay_prefix = &rl_prefix; -skip:; + skip:; } #undef ENCODE_ENTRY @@ -873,8 +855,7 @@ skip:; return write_netdev_img(nde, imgset, info); } -static int dump_one_sit(struct ifinfomsg *ifi, char *kind, - struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) +static int dump_one_sit(struct ifinfomsg *ifi, char *kind, struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds) { char *name; @@ -944,7 +925,7 @@ static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg) ret = dump_one_sit(ifi, kind, tb, ns, fds); break; default: -unk: + unk: ret = dump_unknown_device(ifi, kind, tb, ns, fds); break; } @@ -968,7 +949,7 @@ static int dump_one_nf(struct nlmsghdr *hdr, struct ns_id *ns, void *arg) static int ct_restore_callback(struct nlmsghdr *nlh) { struct nfgenmsg *msg; - struct nlattr *tb[CTA_MAX+1], *tbp[CTA_PROTOINFO_MAX + 1], *tb_tcp[CTA_PROTOINFO_TCP_MAX+1]; + struct nlattr *tb[CTA_MAX + 1], *tbp[CTA_PROTOINFO_MAX + 1], *tb_tcp[CTA_PROTOINFO_TCP_MAX + 1]; int err; msg = NLMSG_DATA(nlh); @@ -1064,7 +1045,7 @@ static int restore_nf_ct(int pid, int type) if (ct_restore_callback(nlh)) goto out; - nlh->nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK|NLM_F_CREATE; + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE; ret = do_rtnl_req(sk, nlh, nlh->nlmsg_len, NULL, NULL, NULL, NULL); if (ret) goto out; @@ -1118,7 +1099,6 @@ static int dump_nf_ct(struct cr_imgset *fds, int type) close(sk); out: return ret; - } /* @@ -1141,7 +1121,7 @@ static int list_links(int rtsk, void *args) memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = RTM_GETLINK; - req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; + req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; req.nlh.nlmsg_pid = 0; req.nlh.nlmsg_seq = CR_NLMSG_SEQ; req.g.rtgen_family = AF_PACKET; @@ -1161,7 +1141,7 @@ static int dump_links(int rtsk, struct ns_id *ns, struct cr_imgset *fds) memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = RTM_GETLINK; - req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; + req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; req.nlh.nlmsg_pid = 0; req.nlh.nlmsg_seq = CR_NLMSG_SEQ; req.g.rtgen_family = AF_PACKET; @@ -1191,22 +1171,21 @@ struct newlink_req { * request. */ struct newlink_extras { - int link; /* IFLA_LINK */ - int target_netns; /* IFLA_NET_NS_FD */ + int link; /* IFLA_LINK */ + int target_netns; /* IFLA_NET_NS_FD */ }; typedef int (*link_info_t)(struct ns_id *ns, struct net_link *, struct newlink_req *); -static int populate_newlink_req(struct ns_id *ns, struct newlink_req *req, - int msg_type, struct net_link * link, - link_info_t link_info, struct newlink_extras *extras) +static int populate_newlink_req(struct ns_id *ns, struct newlink_req *req, int msg_type, struct net_link *link, + link_info_t link_info, struct newlink_extras *extras) { NetDeviceEntry *nde = link->nde; memset(req, 0, sizeof(*req)); req->h.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); - req->h.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK|NLM_F_CREATE; + req->h.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE; req->h.nlmsg_type = msg_type; req->h.nlmsg_seq = CR_NLMSG_SEQ; req->i.ifi_family = AF_PACKET; @@ -1224,18 +1203,16 @@ static int populate_newlink_req(struct ns_id *ns, struct newlink_req *req, addattr_l(&req->h, sizeof(*req), IFLA_LINK, &extras->link, sizeof(extras->link)); if (extras->target_netns >= 0) - addattr_l(&req->h, sizeof(*req), IFLA_NET_NS_FD, &extras->target_netns, sizeof(extras->target_netns)); - + addattr_l(&req->h, sizeof(*req), IFLA_NET_NS_FD, &extras->target_netns, + sizeof(extras->target_netns)); } addattr_l(&req->h, sizeof(*req), IFLA_IFNAME, nde->name, strlen(nde->name)); addattr_l(&req->h, sizeof(*req), IFLA_MTU, &nde->mtu, sizeof(nde->mtu)); if (nde->has_address) { - pr_debug("Restore ll addr (%02x:../%d) for device\n", - (int)nde->address.data[0], (int)nde->address.len); - addattr_l(&req->h, sizeof(*req), IFLA_ADDRESS, - nde->address.data, nde->address.len); + pr_debug("Restore ll addr (%02x:../%d) for device\n", (int)nde->address.data[0], (int)nde->address.len); + addattr_l(&req->h, sizeof(*req), IFLA_ADDRESS, nde->address.data, nde->address.len); } if (link_info) { @@ -1286,7 +1263,7 @@ int kerndat_has_newifindex(void) memset(&req, 0, sizeof(req)); req.h.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); - req.h.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK|NLM_F_CREATE; + req.h.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE; req.h.nlmsg_type = RTM_SETLINK; req.h.nlmsg_seq = CR_NLMSG_SEQ; req.i.ifi_family = AF_UNSPEC; @@ -1295,21 +1272,17 @@ int kerndat_has_newifindex(void) * ifindex is negative, so the kernel will return ERANGE if * IFLA_NEW_IFINDEX is supported. */ - addattr_l(&req.h, sizeof(req), IFLA_NEW_IFINDEX, - &ifindex, sizeof(ifindex)); + addattr_l(&req.h, sizeof(req), IFLA_NEW_IFINDEX, &ifindex, sizeof(ifindex)); /* criu-kdat doesn't exist, so the kernel will return ENODEV. */ addattr_l(&req.h, sizeof(req), IFLA_IFNAME, "criu-kdat", 9); - ret = do_rtnl_req(sk, &req, sizeof(req), restore_link_cb, - kerndat_newifindex_err_cb, NULL, NULL); + ret = do_rtnl_req(sk, &req, sizeof(req), restore_link_cb, kerndat_newifindex_err_cb, NULL, NULL); close(sk); return ret; } - -static int do_rtm_link_req(int msg_type, - struct net_link *link, int nlsk, struct ns_id *ns, - link_info_t link_info, struct newlink_extras *extras) +static int do_rtm_link_req(int msg_type, struct net_link *link, int nlsk, struct ns_id *ns, link_info_t link_info, + struct newlink_extras *extras) { struct newlink_req req; @@ -1324,8 +1297,8 @@ int restore_link_parms(struct net_link *link, int nlsk) return do_rtm_link_req(RTM_SETLINK, link, nlsk, NULL, NULL, NULL); } -static int restore_one_link(struct ns_id *ns, struct net_link *link, int nlsk, - link_info_t link_info, struct newlink_extras *extras) +static int restore_one_link(struct ns_id *ns, struct net_link *link, int nlsk, link_info_t link_info, + struct newlink_extras *extras) { pr_info("Restoring netdev %s idx %d\n", link->nde->name, link->nde->ifindex); return do_rtm_link_req(RTM_NEWLINK, link, nlsk, ns, link_info, extras); @@ -1374,10 +1347,8 @@ out: return ret; } -static int move_veth(const char *netdev, struct ns_id *ns, - struct net_link *link, int nlsk) +static int move_veth(const char *netdev, struct ns_id *ns, struct net_link *link, int nlsk) { - NetDeviceEntry *nde = link->nde; struct newlink_req *req; struct move_req mvreq; @@ -1400,31 +1371,27 @@ static int move_veth(const char *netdev, struct ns_id *ns, memset(&mvreq.req, 0, sizeof(mvreq.req)); req = &mvreq.req; - req->h.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); - req->h.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK; - req->h.nlmsg_type = RTM_NEWLINK; - req->h.nlmsg_seq = CR_NLMSG_SEQ; + req->h.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); + req->h.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + req->h.nlmsg_type = RTM_NEWLINK; + req->h.nlmsg_seq = CR_NLMSG_SEQ; - req->i.ifi_family = AF_UNSPEC; - req->i.ifi_flags = nde->flags; + req->i.ifi_family = AF_UNSPEC; + req->i.ifi_flags = nde->flags; /* Tell netlink what name we want in the target netns. */ - addattr_l(&req->h, sizeof(*req), IFLA_IFNAME, - nde->name, strlen(nde->name)); + addattr_l(&req->h, sizeof(*req), IFLA_IFNAME, nde->name, strlen(nde->name)); /* Tell netlink what mtu we want in the target netns. */ - addattr_l(&req->h, sizeof(*req), IFLA_MTU, - &nde->mtu, sizeof(nde->mtu)); + addattr_l(&req->h, sizeof(*req), IFLA_MTU, &nde->mtu, sizeof(nde->mtu)); /* Tell netlink what ifindex we want in the target netns. */ - addattr_l(&req->h, sizeof(*req), IFLA_NEW_IFINDEX, - &nde->ifindex, sizeof(nde->ifindex)); + addattr_l(&req->h, sizeof(*req), IFLA_NEW_IFINDEX, &nde->ifindex, sizeof(nde->ifindex)); if (nde->has_address) { - pr_debug("Restore ll addr (%02x:../%d) for device with target ifindex %d\n", - (int)nde->address.data[0], (int)nde->address.len, nde->ifindex); - addattr_l(&req->h, sizeof(*req), IFLA_ADDRESS, - nde->address.data, nde->address.len); + pr_debug("Restore ll addr (%02x:../%d) for device with target ifindex %d\n", (int)nde->address.data[0], + (int)nde->address.len, nde->ifindex); + addattr_l(&req->h, sizeof(*req), IFLA_ADDRESS, nde->address.data, nde->address.len); } len_val = strlen(netdev); @@ -1446,16 +1413,15 @@ enum { VETH_INFO_PEER, __VETH_INFO_MAX -#define VETH_INFO_MAX (__VETH_INFO_MAX - 1) +#define VETH_INFO_MAX (__VETH_INFO_MAX - 1) }; #endif #if IFLA_MAX <= 28 -#define IFLA_NET_NS_FD 28 +#define IFLA_NET_NS_FD 28 #endif -static int veth_peer_info(struct net_link *link, struct newlink_req *req, - struct ns_id *ns, int ns_fd) +static int veth_peer_info(struct net_link *link, struct newlink_req *req, struct ns_id *ns, int ns_fd) { NetDeviceEntry *nde = link->nde; char key[100], *val; @@ -1654,7 +1620,7 @@ static int restore_one_macvlan(struct ns_id *ns, struct net_link *link, int nlsk * CAP_NET_ADMIN is required in both namespaces, which we don't have in * the userns case, and usernsd doesn't exist in the non-userns case. */ - extras.link = (int) (unsigned long) val; + extras.link = (int)(unsigned long)val; my_netns = open_proc(PROC_SELF, "ns/net"); if (my_netns < 0) @@ -1694,14 +1660,14 @@ static int sit_link_info(struct ns_id *ns, struct net_link *link, struct newlink sit_data = NLMSG_TAIL(&req->h); addattr_l(&req->h, sizeof(*req), IFLA_INFO_DATA, NULL, 0); -#define DECODE_ENTRY(__type, __ifla, __proto) do { \ - __type aux; \ - if (se->has_##__proto) { \ - aux = se->__proto; \ - addattr_l(&req->h, sizeof(*req), __ifla, \ - &aux, sizeof(__type)); \ - } \ - } while (0) +#define DECODE_ENTRY(__type, __ifla, __proto) \ + do { \ + __type aux; \ + if (se->has_##__proto) { \ + aux = se->__proto; \ + addattr_l(&req->h, sizeof(*req), __ifla, &aux, sizeof(__type)); \ + } \ + } while (0) if (se->n_local) { if (se->n_local != 1) { @@ -1719,18 +1685,18 @@ static int sit_link_info(struct ns_id *ns, struct net_link *link, struct newlink addattr_l(&req->h, sizeof(*req), IFLA_IPTUN_REMOTE, se->remote, sizeof(u32)); } - DECODE_ENTRY(u32, IFLA_IPTUN_LINK, link); - DECODE_ENTRY(u8, IFLA_IPTUN_TTL, ttl); - DECODE_ENTRY(u8, IFLA_IPTUN_TOS, tos); + DECODE_ENTRY(u32, IFLA_IPTUN_LINK, link); + DECODE_ENTRY(u8, IFLA_IPTUN_TTL, ttl); + DECODE_ENTRY(u8, IFLA_IPTUN_TOS, tos); DECODE_ENTRY(u16, IFLA_IPTUN_FLAGS, flags); - DECODE_ENTRY(u8, IFLA_IPTUN_PROTO, proto); + DECODE_ENTRY(u8, IFLA_IPTUN_PROTO, proto); if (se->has_pmtudisc && se->pmtudisc) { u8 aux = 1; addattr_l(&req->h, sizeof(*req), IFLA_IPTUN_PMTUDISC, &aux, sizeof(u8)); } - DECODE_ENTRY(u16, IFLA_IPTUN_ENCAP_TYPE, encap_type); + DECODE_ENTRY(u16, IFLA_IPTUN_ENCAP_TYPE, encap_type); DECODE_ENTRY(u16, IFLA_IPTUN_ENCAP_FLAGS, encap_flags); DECODE_ENTRY(u16, IFLA_IPTUN_ENCAP_SPORT, encap_sport); DECODE_ENTRY(u16, IFLA_IPTUN_ENCAP_DPORT, encap_dport); @@ -1758,7 +1724,7 @@ static int sit_link_info(struct ns_id *ns, struct net_link *link, struct newlink aux = se->relay_prefixlen; addattr_l(&req->h, sizeof(*req), IFLA_IPTUN_6RD_RELAY_PREFIXLEN, &aux, sizeof(u16)); addattr_l(&req->h, sizeof(*req), IFLA_IPTUN_6RD_RELAY_PREFIX, se->relay_prefix, sizeof(u32)); -skip:; + skip:; } #undef DECODE_ENTRY @@ -1777,7 +1743,7 @@ static int __restore_link(struct ns_id *ns, struct net_link *link, int nlsk) switch (nde->type) { case ND_TYPE__LOOPBACK: /* fallthrough */ - case ND_TYPE__EXTLINK: /* see comment in images/netdev.proto */ + case ND_TYPE__EXTLINK: /* see comment in images/netdev.proto */ return restore_link_parms(link, nlsk); case ND_TYPE__VENET: return restore_one_link(ns, link, nlsk, venet_link_info, NULL); @@ -1859,14 +1825,17 @@ static int restore_link(int nlsk, struct ns_id *ns, struct net_link *link) def_netns = NULL; if (nde->conf4) - ret = ipv4_conf_op(nde->name, nde->conf4, nde->n_conf4, CTL_WRITE, def_netns ? (*def_netns)->def_conf4 : NULL); + ret = ipv4_conf_op(nde->name, nde->conf4, nde->n_conf4, CTL_WRITE, + def_netns ? (*def_netns)->def_conf4 : NULL); else if (nde->conf) - ret = ipv4_conf_op_old(nde->name, nde->conf, nde->n_conf, CTL_WRITE, def_netns ? (*def_netns)->def_conf : NULL); + ret = ipv4_conf_op_old(nde->name, nde->conf, nde->n_conf, CTL_WRITE, + def_netns ? (*def_netns)->def_conf : NULL); if (ret) goto exit; if (nde->conf6) - ret = ipv6_conf_op(nde->name, nde->conf6, nde->n_conf6, CTL_WRITE, def_netns ? (*def_netns)->def_conf6 : NULL); + ret = ipv6_conf_op(nde->name, nde->conf6, nde->n_conf6, CTL_WRITE, + def_netns ? (*def_netns)->def_conf6 : NULL); exit: return ret; } @@ -1878,15 +1847,14 @@ static int restore_master_link(int nlsk, struct ns_id *ns, struct net_link *link memset(&req, 0, sizeof(req)); req.h.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); - req.h.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK|NLM_F_CREATE; + req.h.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE; req.h.nlmsg_type = RTM_SETLINK; req.h.nlmsg_seq = CR_NLMSG_SEQ; req.i.ifi_family = AF_PACKET; req.i.ifi_index = link->nde->ifindex; req.i.ifi_flags = link->nde->flags; - addattr_l(&req.h, sizeof(req), IFLA_MASTER, - &link->nde->master, sizeof(link->nde->master)); + addattr_l(&req.h, sizeof(req), IFLA_MASTER, &link->nde->master, sizeof(link->nde->master)); return do_rtnl_req(nlsk, &req, req.h.nlmsg_len, restore_link_cb, NULL, NULL, NULL); } @@ -1915,8 +1883,7 @@ static int __restore_links(struct ns_id *nsid, int *nrlinks, int *nrcreated) (*nrlinks)++; - pr_debug("Try to restore a link %d:%d:%s", - nsid->id, link->nde->ifindex, link->nde->name); + pr_debug("Try to restore a link %d:%d:%s\n", nsid->id, link->nde->ifindex, link->nde->name); if (link->nde->has_master) { mlink = lookup_net_link(nsid, link->nde->master); if (mlink == NULL) { @@ -1925,8 +1892,8 @@ static int __restore_links(struct ns_id *nsid, int *nrlinks, int *nrcreated) } if (!mlink->created) { - pr_debug("The master %d:%d:%s isn't created yet", - nsid->id, mlink->nde->ifindex, mlink->nde->name); + pr_debug("The master %d:%d:%s isn't created yet", nsid->id, mlink->nde->ifindex, + mlink->nde->name); continue; } } @@ -1977,23 +1944,21 @@ static int restore_links(void) return 0; } - static int run_ip_tool(char *arg1, char *arg2, char *arg3, char *arg4, int fdin, int fdout, unsigned flags) { char *ip_tool_cmd; int ret; - pr_debug("\tRunning ip %s %s %s %s\n", arg1, arg2, arg3 ? : "", arg4 ? : ""); + pr_debug("\tRunning ip %s %s %s %s\n", arg1, arg2, arg3 ?: "", arg4 ?: ""); ip_tool_cmd = getenv("CR_IP_TOOL"); if (!ip_tool_cmd) ip_tool_cmd = "ip"; - ret = cr_system(fdin, fdout, -1, ip_tool_cmd, - (char *[]) { "ip", arg1, arg2, arg3, arg4, NULL }, flags); + ret = cr_system(fdin, fdout, -1, ip_tool_cmd, (char *[]){ "ip", arg1, arg2, arg3, arg4, NULL }, flags); if (ret) { if (!(flags & CRS_CAN_FAIL)) - pr_err("IP tool failed on %s %s %s %s\n", arg1, arg2, arg3 ? : "", arg4 ? : ""); + pr_err("IP tool failed on %s %s %s %s\n", arg1, arg2, arg3 ?: "", arg4 ?: ""); return -1; } @@ -2009,7 +1974,7 @@ static int run_iptables_tool(char *def_cmd, int fdin, int fdout) if (!cmd) cmd = def_cmd; pr_debug("\tRunning %s for %s\n", cmd, def_cmd); - ret = cr_system(fdin, fdout, -1, "sh", (char *[]) { "sh", "-c", cmd, NULL }, 0); + ret = cr_system(fdin, fdout, -1, "sh", (char *[]){ "sh", "-c", cmd, NULL }, 0); if (ret) pr_err("%s failed\n", def_cmd); @@ -2169,23 +2134,21 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds) int size6 = ARRAY_SIZE(devconfs6); char def_stable_secret[MAX_STR_CONF_LEN + 1] = {}; char all_stable_secret[MAX_STR_CONF_LEN + 1] = {}; - NetnsId *ids; + NetnsId *ids; struct netns_id *p; i = 0; list_for_each_entry(p, &ns->net.ids, node) i++; - o_buf = buf = xmalloc( - i * (sizeof(NetnsId*) + sizeof(NetnsId)) + - size4 * (sizeof(SysctlEntry*) + sizeof(SysctlEntry)) * 2 + - size6 * (sizeof(SysctlEntry*) + sizeof(SysctlEntry)) * 2 + - sizex * (sizeof(SysctlEntry*) + sizeof(SysctlEntry)) - ); + o_buf = buf = xmalloc(i * (sizeof(NetnsId *) + sizeof(NetnsId)) + + size4 * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)) * 2 + + size6 * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)) * 2 + + sizex * (sizeof(SysctlEntry *) + sizeof(SysctlEntry))); if (!buf) goto out; - netns.nsids = xptr_pull_s(&buf, i * sizeof(NetnsId*)); + netns.nsids = xptr_pull_s(&buf, i * sizeof(NetnsId *)); ids = xptr_pull_s(&buf, i * sizeof(NetnsId)); i = 0; list_for_each_entry(p, &ns->net.ids, node) { @@ -2199,8 +2162,8 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds) netns.n_def_conf4 = size4; netns.n_all_conf4 = size4; - netns.def_conf4 = xptr_pull_s(&buf, size4 * sizeof(SysctlEntry*)); - netns.all_conf4 = xptr_pull_s(&buf, size4 * sizeof(SysctlEntry*)); + netns.def_conf4 = xptr_pull_s(&buf, size4 * sizeof(SysctlEntry *)); + netns.all_conf4 = xptr_pull_s(&buf, size4 * sizeof(SysctlEntry *)); def_confs4 = xptr_pull_s(&buf, size4 * sizeof(SysctlEntry)); all_confs4 = xptr_pull_s(&buf, size4 * sizeof(SysctlEntry)); @@ -2215,8 +2178,8 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds) netns.n_def_conf6 = size6; netns.n_all_conf6 = size6; - netns.def_conf6 = xptr_pull_s(&buf, size6 * sizeof(SysctlEntry*)); - netns.all_conf6 = xptr_pull_s(&buf, size6 * sizeof(SysctlEntry*)); + netns.def_conf6 = xptr_pull_s(&buf, size6 * sizeof(SysctlEntry *)); + netns.all_conf6 = xptr_pull_s(&buf, size6 * sizeof(SysctlEntry *)); def_confs6 = xptr_pull_s(&buf, size6 * sizeof(SysctlEntry)); all_confs6 = xptr_pull_s(&buf, size6 * sizeof(SysctlEntry)); @@ -2237,7 +2200,7 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds) } netns.n_unix_conf = sizex; - netns.unix_conf = xptr_pull_s(&buf, sizex * sizeof(SysctlEntry*)); + netns.unix_conf = xptr_pull_s(&buf, sizex * sizeof(SysctlEntry *)); unix_confs = xptr_pull_s(&buf, sizex * sizeof(SysctlEntry)); for (i = 0; i < sizex; i++) { @@ -2298,7 +2261,8 @@ static int restore_ip_dump(int type, int pid, char *cmd) written = fwrite(buf, sizeof(char), n, tmp_file); if (written < n) { pr_perror("Failed to write to tmpfile " - "[written: %d; total: %d]", written, n); + "[written: %d; total: %d]", + written, n); goto close; } } @@ -2314,7 +2278,7 @@ static int restore_ip_dump(int type, int pid, char *cmd) } close: - if(fclose(tmp_file)) { + if (fclose(tmp_file)) { pr_perror("Failed to close tmpfile"); } @@ -2355,7 +2319,7 @@ static inline int restore_rule(int pid) * Delete 3 default rules to prevent duplicates. See kernel's * function fib_default_rules_init() for the details. */ - run_ip_tool("rule", "flush", NULL, NULL, -1, -1, 0); + run_ip_tool("rule", "flush", NULL, NULL, -1, -1, 0); run_ip_tool("rule", "delete", "table", "local", -1, -1, 0); if (restore_ip_dump(CR_FD_RULE, pid, "rule")) @@ -2389,7 +2353,7 @@ static int prepare_xtable_lock(void) return -1; } - if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL)) { + if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL)) { pr_perror("Unable to conver mounts to slave mounts"); return -1; } @@ -2471,9 +2435,9 @@ static inline int restore_nftables(int pid) if (nft_ctx_buffer_output(nft) || nft_ctx_buffer_error(nft) || #if defined(CONFIG_HAS_NFTABLES_LIB_API_0) - nft_run_cmd_from_buffer(nft, buf, strlen(buf))) + nft_run_cmd_from_buffer(nft, buf, strlen(buf))) #elif defined(CONFIG_HAS_NFTABLES_LIB_API_1) - nft_run_cmd_from_buffer(nft, buf)) + nft_run_cmd_from_buffer(nft, buf)) #else { BUILD_BUG_ON(1); @@ -2655,8 +2619,7 @@ static int dump_netns_ids(int rtsk, struct ns_id *ns) .ns = ns, .sk = rtsk, }; - return walk_namespaces(&net_ns_desc, collect_netns_id, - (void *)&arg); + return walk_namespaces(&net_ns_desc, collect_netns_id, (void *)&arg); } int net_set_ext(struct ns_id *ns) @@ -2918,7 +2881,6 @@ static int __prepare_net_namespaces(void *unused) pr_perror("Can't create nlk socket"); goto err; } - } if (restore_links()) @@ -2944,7 +2906,6 @@ err: return -1; } - int prepare_net_namespaces(void) { if (!(root_ns_mask & CLONE_NEWNET)) @@ -3031,8 +2992,8 @@ int netns_keep_nsfd(void) static int iptables_restore(bool ipv6, char *buf, int size) { int pfd[2], ret = -1; - char *cmd4[] = {"iptables-restore", "-w", "--noflush", NULL}; - char *cmd6[] = {"ip6tables-restore", "-w", "--noflush", NULL}; + char *cmd4[] = { "iptables-restore", "-w", "--noflush", NULL }; + char *cmd6[] = { "ip6tables-restore", "-w", "--noflush", NULL }; char **cmd = ipv6 ? cmd6 : cmd4; if (pipe(pfd) < 0) { @@ -3055,28 +3016,28 @@ err: int network_lock_internal(void) { - char conf[] = "*filter\n" - ":CRIU - [0:0]\n" - "-I INPUT -j CRIU\n" - "-I OUTPUT -j CRIU\n" - "-A CRIU -m mark --mark " __stringify(SOCCR_MARK) " -j ACCEPT\n" - "-A CRIU -j DROP\n" - "COMMIT\n"; + char conf[] = "*filter\n" + ":CRIU - [0:0]\n" + "-I INPUT -j CRIU\n" + "-I OUTPUT -j CRIU\n" + "-A CRIU -m mark --mark " __stringify(SOCCR_MARK) " -j ACCEPT\n" + "-A CRIU -j DROP\n" + "COMMIT\n"; int ret = 0, nsret; if (switch_ns(root_item->pid->real, &net_ns_desc, &nsret)) return -1; - ret |= iptables_restore(false, conf, sizeof(conf) - 1); if (kdat.ipv6) ret |= iptables_restore(true, conf, sizeof(conf) - 1); if (ret) pr_err("Locking network failed: iptables-restore returned %d. " - "This may be connected to disabled " - "CONFIG_NETFILTER_XT_MARK kernel build config " - "option.\n", ret); + "This may be connected to disabled " + "CONFIG_NETFILTER_XT_MARK kernel build config " + "option.\n", + ret); if (restore_ns(nsret, &net_ns_desc)) ret = -1; @@ -3086,18 +3047,17 @@ int network_lock_internal(void) static int network_unlock_internal(void) { - char conf[] = "*filter\n" - ":CRIU - [0:0]\n" - "-D INPUT -j CRIU\n" - "-D OUTPUT -j CRIU\n" - "-X CRIU\n" - "COMMIT\n"; + char conf[] = "*filter\n" + ":CRIU - [0:0]\n" + "-D INPUT -j CRIU\n" + "-D OUTPUT -j CRIU\n" + "-X CRIU\n" + "COMMIT\n"; int ret = 0, nsret; if (switch_ns(root_item->pid->real, &net_ns_desc, &nsret)) return -1; - ret |= iptables_restore(false, conf, sizeof(conf) - 1); if (kdat.ipv6) ret |= iptables_restore(true, conf, sizeof(conf) - 1); @@ -3113,7 +3073,7 @@ int network_lock(void) pr_info("Lock network\n"); /* Each connection will be locked on dump */ - if (!(root_ns_mask & CLONE_NEWNET)) + if (!(root_ns_mask & CLONE_NEWNET)) return 0; if (run_scripts(ACT_NET_LOCK)) @@ -3149,7 +3109,7 @@ int veth_pair_add(char *in, char *out) int macvlan_ext_add(struct external *ext) { - ext->data = (void *) (unsigned long) if_nametoindex(external_val(ext)); + ext->data = (void *)(unsigned long)if_nametoindex(external_val(ext)); if (ext->data == 0) { pr_perror("can't get ifindex of %s", ext->id); return -1; @@ -3222,16 +3182,14 @@ static int prep_ns_sockets(struct ns_id *ns, bool for_dump) if (kdat.lsm == LSMTYPE__SELINUX) { ret = getpidcon_raw(root_item->pid->real, &ctx); if (ret < 0) { - pr_perror("Getting SELinux context for PID %d failed", - root_item->pid->real); + pr_perror("Getting SELinux context for PID %d failed", root_item->pid->real); goto err_sq; } ret = setsockcreatecon(ctx); freecon(ctx); if (ret < 0) { - pr_perror("Setting SELinux socket context for PID %d failed", - root_item->pid->real); + pr_perror("Setting SELinux socket context for PID %d failed", root_item->pid->real); goto err_sq; } } @@ -3309,8 +3267,7 @@ static int collect_net_ns(struct ns_id *ns, void *oarg) int collect_net_namespaces(bool for_dump) { - return walk_namespaces(&net_ns_desc, collect_net_ns, - (void *)(for_dump ? 1UL : 0)); + return walk_namespaces(&net_ns_desc, collect_net_ns, (void *)(for_dump ? 1UL : 0)); } struct ns_desc net_ns_desc = NS_DESC_ENTRY(CLONE_NEWNET, "net"); @@ -3415,7 +3372,7 @@ static int move_to_bridge(struct external *ext, void *arg) pr_debug("\tMoving dev %s to bridge %s\n", out, br); if (s == -1) { - s = socket(AF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0); + s = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); if (s < 0) { pr_perror("Can't create control socket"); return -1; @@ -3493,14 +3450,14 @@ enum { __NETNSA_MAX, }; -#define NETNSA_MAX (__NETNSA_MAX - 1) +#define NETNSA_MAX (__NETNSA_MAX - 1) #endif static struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = { - [NETNSA_NONE] = { .type = NLA_UNSPEC }, - [NETNSA_NSID] = { .type = NLA_S32 }, - [NETNSA_PID] = { .type = NLA_U32 }, - [NETNSA_FD] = { .type = NLA_U32 }, + [NETNSA_NONE] = { .type = NLA_UNSPEC }, + [NETNSA_NSID] = { .type = NLA_S32 }, + [NETNSA_PID] = { .type = NLA_U32 }, + [NETNSA_FD] = { .type = NLA_U32 }, }; static int nsid_cb(struct nlmsghdr *msg, struct ns_id *ns, void *arg) @@ -3508,8 +3465,7 @@ static int nsid_cb(struct nlmsghdr *msg, struct ns_id *ns, void *arg) struct nlattr *tb[NETNSA_MAX + 1]; int err; - err = nlmsg_parse(msg, sizeof(struct rtgenmsg), tb, - NETNSA_MAX, rtnl_net_policy); + err = nlmsg_parse(msg, sizeof(struct rtgenmsg), tb, NETNSA_MAX, rtnl_net_policy); if (err < 0) return NL_STOP; @@ -3560,7 +3516,7 @@ int net_get_nsid(int rtsk, int pid, int *nsid) if (addattr_l(&req.nlh, sizeof(req), NETNSA_PID, &pid, sizeof(pid))) return -1; - if (do_rtnl_req(rtsk, &req, req.nlh.nlmsg_len, nsid_cb, NULL, NULL, (void *) &id) < 0) + if (do_rtnl_req(rtsk, &req, req.nlh.nlmsg_len, nsid_cb, NULL, NULL, (void *)&id) < 0) return -1; if (id == INT_MIN) @@ -3571,7 +3527,6 @@ int net_get_nsid(int rtsk, int pid, int *nsid) return 0; } - static int nsid_link_info(struct ns_id *ns, struct net_link *link, struct newlink_req *req) { NetDeviceEntry *nde = link->nde; @@ -3630,7 +3585,7 @@ static int check_link_nsid(int rtsk, void *args) memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = RTM_GETLINK; - req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; + req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; req.nlh.nlmsg_pid = 0; req.nlh.nlmsg_seq = CR_NLMSG_SEQ; req.g.rtgen_family = AF_PACKET; diff --git a/criu/netfilter.c b/criu/netfilter.c index 368651c71..b9b013456 100644 --- a/criu/netfilter.c +++ b/criu/netfilter.c @@ -22,7 +22,8 @@ static char buf[512]; * Any brave soul to write it using xtables-devel? */ -#define NF_CONN_CMD "%s %s -t filter %s %s --protocol tcp " \ +#define NF_CONN_CMD \ + "%s %s -t filter %s %s --protocol tcp " \ "-m mark ! --mark " __stringify(SOCCR_MARK) " --source %s --sport %d --destination %s --dport %d -j DROP" static char iptable_cmd_ipv4[] = "iptables"; @@ -40,10 +41,8 @@ void preload_netfilter_modules(void) fd = -1; pr_perror("failed to open /dev/null, using log fd for net module preload"); } - cr_system(fd, fd, fd, iptable_cmd_ipv4, - (char *[]) { iptable_cmd_ipv4, "-L", "-n", NULL}, 0); - cr_system(fd, fd, fd, iptable_cmd_ipv6, - (char *[]) { iptable_cmd_ipv6, "-L", "-n", NULL}, 0); + cr_system(fd, fd, fd, iptable_cmd_ipv4, (char *[]){ iptable_cmd_ipv4, "-L", "-n", NULL }, 0); + cr_system(fd, fd, fd, iptable_cmd_ipv6, (char *[]){ iptable_cmd_ipv6, "-L", "-n", NULL }, 0); close_safe(&fd); } @@ -53,9 +52,8 @@ static int ipv6_addr_mapped(u32 *addr) return (addr[2] == htonl(0x0000ffff)); } -static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port, - u32 *dst_addr, u16 dst_port, - bool input, bool lock) +static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port, u32 *dst_addr, u16 dst_port, bool input, + bool lock) { char sip[INET_ADDR_LEN], dip[INET_ADDR_LEN]; char *cmd; @@ -81,16 +79,13 @@ static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port, }; if (!inet_ntop(family, (void *)src_addr, sip, INET_ADDR_LEN) || - !inet_ntop(family, (void *)dst_addr, dip, INET_ADDR_LEN)) { + !inet_ntop(family, (void *)dst_addr, dip, INET_ADDR_LEN)) { pr_perror("nf: Can't translate ip addr"); return -1; } - snprintf(buf, sizeof(buf), NF_CONN_CMD, cmd, - kdat.has_xtlocks ? "-w" : "", - lock ? "-I" : "-D", - input ? "INPUT" : "OUTPUT", - dip, (int)dst_port, sip, (int)src_port); + snprintf(buf, sizeof(buf), NF_CONN_CMD, cmd, kdat.has_xtlocks ? "-w" : "", lock ? "-I" : "-D", + input ? "INPUT" : "OUTPUT", dip, (int)dst_port, sip, (int)src_port); pr_debug("\tRunning iptables [%s]\n", buf); @@ -104,8 +99,7 @@ static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port, return -1; } - pr_info("%s %s:%d - %s:%d connection\n", lock ? "Locked" : "Unlocked", - sip, (int)src_port, dip, (int)dst_port); + pr_info("%s %s:%d - %s:%d connection\n", lock ? "Locked" : "Unlocked", sip, (int)src_port, dip, (int)dst_port); return 0; } @@ -113,19 +107,16 @@ static int nf_connection_switch(struct inet_sk_desc *sk, bool lock) { int ret = 0; - ret = nf_connection_switch_raw(sk->sd.family, - sk->src_addr, sk->src_port, - sk->dst_addr, sk->dst_port, true, lock); + ret = nf_connection_switch_raw(sk->sd.family, sk->src_addr, sk->src_port, sk->dst_addr, sk->dst_port, true, + lock); if (ret) return -1; - ret = nf_connection_switch_raw(sk->sd.family, - sk->dst_addr, sk->dst_port, - sk->src_addr, sk->src_port, false, lock); + ret = nf_connection_switch_raw(sk->sd.family, sk->dst_addr, sk->dst_port, sk->src_addr, sk->src_port, false, + lock); if (ret) /* rollback */ - nf_connection_switch_raw(sk->sd.family, - sk->src_addr, sk->src_port, - sk->dst_addr, sk->dst_port, true, !lock); + nf_connection_switch_raw(sk->sd.family, sk->src_addr, sk->src_port, sk->dst_addr, sk->dst_port, true, + !lock); return ret; } @@ -143,12 +134,10 @@ int nf_unlock_connection_info(struct inet_sk_info *si) { int ret = 0; - ret |= nf_connection_switch_raw(si->ie->family, - si->ie->src_addr, si->ie->src_port, - si->ie->dst_addr, si->ie->dst_port, true, false); - ret |= nf_connection_switch_raw(si->ie->family, - si->ie->dst_addr, si->ie->dst_port, - si->ie->src_addr, si->ie->src_port, false, false); + ret |= nf_connection_switch_raw(si->ie->family, si->ie->src_addr, si->ie->src_port, si->ie->dst_addr, + si->ie->dst_port, true, false); + ret |= nf_connection_switch_raw(si->ie->family, si->ie->dst_addr, si->ie->dst_port, si->ie->src_addr, + si->ie->src_port, false, false); /* * rollback nothing in case of any error, * because nobody checks errors of this function diff --git a/criu/page-pipe.c b/criu/page-pipe.c index 439c180e4..5a7e50bc1 100644 --- a/criu/page-pipe.c +++ b/criu/page-pipe.c @@ -68,8 +68,7 @@ static inline int ppb_resize_pipe(struct page_pipe_buf *ppb) return 0; } -static struct page_pipe_buf *pp_prev_ppb(struct page_pipe *pp, - unsigned int ppb_flags) +static struct page_pipe_buf *pp_prev_ppb(struct page_pipe *pp, unsigned int ppb_flags) { int type = 0; @@ -86,8 +85,7 @@ static struct page_pipe_buf *pp_prev_ppb(struct page_pipe *pp, return pp->prev[type]; } -static void pp_update_prev_ppb(struct page_pipe *pp, struct page_pipe_buf *ppb, - unsigned int ppb_flags) +static void pp_update_prev_ppb(struct page_pipe *pp, struct page_pipe_buf *ppb, unsigned int ppb_flags) { int type = 0; @@ -97,8 +95,7 @@ static void pp_update_prev_ppb(struct page_pipe *pp, struct page_pipe_buf *ppb, pp->prev[type] = ppb; } -static struct page_pipe_buf *ppb_alloc(struct page_pipe *pp, - unsigned int ppb_flags) +static struct page_pipe_buf *ppb_alloc(struct page_pipe *pp, unsigned int ppb_flags) { struct page_pipe_buf *prev = pp_prev_ppb(pp, ppb_flags); struct page_pipe_buf *ppb; @@ -144,8 +141,7 @@ static void ppb_destroy(struct page_pipe_buf *ppb) xfree(ppb); } -static void ppb_init(struct page_pipe_buf *ppb, unsigned int pages_in, - unsigned int nr_segs, unsigned int flags, +static void ppb_init(struct page_pipe_buf *ppb, unsigned int pages_in, unsigned int nr_segs, unsigned int flags, struct iovec *iov) { ppb->pages_in = pages_in; @@ -249,8 +245,8 @@ void page_pipe_reinit(struct page_pipe *pp) BUG(); /* It can't fail, because ppb is in free_bufs */ } -static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *ppb, - unsigned long addr, unsigned int flags) +static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *ppb, unsigned long addr, + unsigned int flags) { if (ppb->flags != flags) return 1; @@ -259,10 +255,9 @@ static inline int try_add_page_to(struct page_pipe *pp, struct page_pipe_buf *pp return 1; if (ppb->nr_segs && iov_grow_page(&ppb->iov[ppb->nr_segs - 1], addr)) - goto out; + goto out; - pr_debug("Add iov to page pipe (%u iovs, %u/%u total)\n", - ppb->nr_segs, pp->free_iov, pp->nr_iovs); + pr_debug("Add iov to page pipe (%u iovs, %u/%u total)\n", ppb->nr_segs, pp->free_iov, pp->nr_iovs); iov_init(&ppb->iov[ppb->nr_segs++], addr); pp->free_iov++; BUG_ON(pp->free_iov > pp->nr_iovs); @@ -271,15 +266,13 @@ out: return 0; } -static inline int try_add_page(struct page_pipe *pp, unsigned long addr, - unsigned int flags) +static inline int try_add_page(struct page_pipe *pp, unsigned long addr, unsigned int flags) { BUG_ON(list_empty(&pp->bufs)); return try_add_page_to(pp, list_entry(pp->bufs.prev, struct page_pipe_buf, l), addr, flags); } -int page_pipe_add_page(struct page_pipe *pp, unsigned long addr, - unsigned int flags) +int page_pipe_add_page(struct page_pipe *pp, unsigned long addr, unsigned int flags) { int ret; @@ -296,10 +289,9 @@ int page_pipe_add_page(struct page_pipe *pp, unsigned long addr, return ret; } -#define PP_HOLES_BATCH 32 +#define PP_HOLES_BATCH 32 -int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr, - unsigned int flags) +int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr, unsigned int flags) { if (pp->free_hole >= pp->nr_holes) { size_t new_size = (pp->nr_holes + PP_HOLES_BATCH) * sizeof(struct iovec); @@ -313,8 +305,7 @@ int page_pipe_add_hole(struct page_pipe *pp, unsigned long addr, pp->nr_holes += PP_HOLES_BATCH; } - if (pp->free_hole && - pp->hole_flags[pp->free_hole - 1] == flags && + if (pp->free_hole && pp->hole_flags[pp->free_hole - 1] == flags && iov_grow_page(&pp->holes[pp->free_hole - 1], addr)) goto out; @@ -330,8 +321,7 @@ out: * Get ppb and iov that contain addr and count amount of data between * beginning of the pipe belonging to the ppb and addr */ -static struct page_pipe_buf *get_ppb(struct page_pipe *pp, unsigned long addr, - struct iovec **iov_ret, +static struct page_pipe_buf *get_ppb(struct page_pipe *pp, unsigned long addr, struct iovec **iov_ret, unsigned long *len) { struct page_pipe_buf *ppb; @@ -384,8 +374,7 @@ int pipe_read_dest_init(struct pipe_read_dest *prd) return 0; } -int page_pipe_read(struct page_pipe *pp, struct pipe_read_dest *prd, - unsigned long addr, unsigned int *nr_pages, +int page_pipe_read(struct page_pipe *pp, struct pipe_read_dest *prd, unsigned long addr, unsigned int *nr_pages, unsigned int ppb_flags) { struct page_pipe_buf *ppb; @@ -410,8 +399,7 @@ int page_pipe_read(struct page_pipe *pp, struct pipe_read_dest *prd, } /* clamp the request if it passes the end of iovec */ - len = min((unsigned long)iov->iov_base + iov->iov_len - addr, - (unsigned long)(*nr_pages) * PAGE_SIZE); + len = min((unsigned long)iov->iov_base + iov->iov_len - addr, (unsigned long)(*nr_pages) * PAGE_SIZE); *nr_pages = len / PAGE_SIZE; skip += ppb->pipe_off * PAGE_SIZE; @@ -449,15 +437,13 @@ void debug_show_page_pipe(struct page_pipe *pp) return; pr_debug("Page pipe:\n"); - pr_debug("* %u pipes %u/%u iovs:\n", - pp->nr_pipes, pp->free_iov, pp->nr_iovs); + pr_debug("* %u pipes %u/%u iovs:\n", pp->nr_pipes, pp->free_iov, pp->nr_iovs); list_for_each_entry(ppb, &pp->bufs, l) { - pr_debug("\tbuf %u pages, %u iovs, flags: %x pipe_off: %x :\n", - ppb->pages_in, ppb->nr_segs, ppb->flags, ppb->pipe_off); + pr_debug("\tbuf %u pages, %u iovs, flags: %x pipe_off: %x :\n", ppb->pages_in, ppb->nr_segs, ppb->flags, + ppb->pipe_off); for (i = 0; i < ppb->nr_segs; i++) { iov = &ppb->iov[i]; - pr_debug("\t\t%p %lu\n", iov->iov_base, - iov->iov_len / PAGE_SIZE); + pr_debug("\t\t%p %lu\n", iov->iov_base, iov->iov_len / PAGE_SIZE); } } diff --git a/criu/page-xfer.c b/criu/page-xfer.c index 34f6a0967..9adf2c8b2 100644 --- a/criu/page-xfer.c +++ b/criu/page-xfer.c @@ -30,10 +30,10 @@ static int page_server_sk = -1; struct page_server_iov { - u32 cmd; - u32 nr_pages; - u64 vaddr; - u64 dst_id; + u32 cmd; + u32 nr_pages; + u64 vaddr; + u64 dst_id; }; static void psi2iovec(struct page_server_iov *ps, struct iovec *iov) @@ -42,25 +42,25 @@ static void psi2iovec(struct page_server_iov *ps, struct iovec *iov) iov->iov_len = ps->nr_pages * PAGE_SIZE; } -#define PS_IOV_ADD 1 -#define PS_IOV_HOLE 2 -#define PS_IOV_OPEN 3 -#define PS_IOV_OPEN2 4 -#define PS_IOV_PARENT 5 -#define PS_IOV_ADD_F 6 -#define PS_IOV_GET 7 +#define PS_IOV_ADD 1 +#define PS_IOV_HOLE 2 +#define PS_IOV_OPEN 3 +#define PS_IOV_OPEN2 4 +#define PS_IOV_PARENT 5 +#define PS_IOV_ADD_F 6 +#define PS_IOV_GET 7 -#define PS_IOV_FLUSH 0x1023 -#define PS_IOV_FLUSH_N_CLOSE 0x1024 +#define PS_IOV_FLUSH 0x1023 +#define PS_IOV_FLUSH_N_CLOSE 0x1024 -#define PS_CMD_BITS 16 -#define PS_CMD_MASK ((1 << PS_CMD_BITS) - 1) +#define PS_CMD_BITS 16 +#define PS_CMD_MASK ((1 << PS_CMD_BITS) - 1) -#define PS_TYPE_BITS 8 -#define PS_TYPE_MASK ((1 << PS_TYPE_BITS) - 1) +#define PS_TYPE_BITS 8 +#define PS_TYPE_MASK ((1 << PS_TYPE_BITS) - 1) -#define PS_TYPE_PID (1) -#define PS_TYPE_SHMEM (2) +#define PS_TYPE_PID (1) +#define PS_TYPE_SHMEM (2) /* * XXX: When adding new types here check decode_pm for legacy * numbers that can be met from older CRIUs @@ -158,31 +158,26 @@ static inline int send_psi(int sk, struct page_server_iov *pi) } /* page-server xfer */ -static int write_pages_to_server(struct page_xfer *xfer, - int p, unsigned long len) +static int write_pages_to_server(struct page_xfer *xfer, int p, unsigned long len) { ssize_t ret, left = len; if (opts.tls) { - pr_debug("Sending %lu bytes / %lu pages\n", - len, len / PAGE_SIZE); + pr_debug("Sending %lu bytes / %lu pages\n", len, len / PAGE_SIZE); if (tls_send_data_from_fd(p, len)) return -1; } else { - pr_debug("Splicing %lu bytes / %lu pages into socket\n", - len, len / PAGE_SIZE); + pr_debug("Splicing %lu bytes / %lu pages into socket\n", len, len / PAGE_SIZE); while (left > 0) { - ret = splice(p, NULL, xfer->sk, NULL, left, - SPLICE_F_MOVE); + ret = splice(p, NULL, xfer->sk, NULL, left, SPLICE_F_MOVE); if (ret < 0) { pr_perror("Can't write pages to socket"); return -1; } - pr_debug("\tSpliced: %lu bytes sent\n", - (unsigned long)ret); + pr_debug("\tSpliced: %lu bytes sent\n", (unsigned long)ret); left -= ret; } } @@ -236,14 +231,13 @@ static int open_page_server_xfer(struct page_xfer *xfer, int fd_type, unsigned l } if (has_parent) - xfer->parent = (void *) 1; /* This is required for generate_iovs() */ + xfer->parent = (void *)1; /* This is required for generate_iovs() */ return 0; } /* local xfer */ -static int write_pages_loc(struct page_xfer *xfer, - int p, unsigned long len) +static int write_pages_loc(struct page_xfer *xfer, int p, unsigned long len) { ssize_t ret; ssize_t curr = 0; @@ -291,7 +285,7 @@ static int check_pagehole_in_parent(struct page_read *p, struct iovec *iov) return -1; } - pr_debug("\tFound %"PRIx64"/%lu\n", p->pe->vaddr, pagemap_len(p->pe)); + pr_debug("\tFound %" PRIx64 "/%lu\n", p->pe->vaddr, pagemap_len(p->pe)); /* * The pagemap entry in parent may happen to be @@ -320,8 +314,7 @@ static int write_pagemap_loc(struct page_xfer *xfer, struct iovec *iov, u32 flag if (flags & PE_PRESENT) { if (opts.auto_dedup && xfer->parent != NULL) { - ret = dedup_one_iovec(xfer->parent, pe.vaddr, - pagemap_len(&pe)); + ret = dedup_one_iovec(xfer->parent, pe.vaddr, pagemap_len(&pe)); if (ret == -1) { pr_perror("Auto-deduplication failed"); return ret; @@ -331,8 +324,7 @@ static int write_pagemap_loc(struct page_xfer *xfer, struct iovec *iov, u32 flag if (xfer->parent != NULL) { ret = check_pagehole_in_parent(xfer->parent, iov); if (ret) { - pr_err("Hole %p/%zu not found in parent\n", - iov->iov_base, iov->iov_len); + pr_err("Hole %p/%zu not found in parent\n", iov->iov_base, iov->iov_len); return -1; } } @@ -430,13 +422,11 @@ int open_page_xfer(struct page_xfer *xfer, int fd_type, unsigned long img_id) return open_page_local_xfer(xfer, fd_type, img_id); } -static int page_xfer_dump_hole(struct page_xfer *xfer, - struct iovec *hole, u32 flags) +static int page_xfer_dump_hole(struct page_xfer *xfer, struct iovec *hole, u32 flags) { BUG_ON(hole->iov_base < (void *)xfer->offset); hole->iov_base -= xfer->offset; - pr_debug("\th %p [%u]\n", hole->iov_base, - (unsigned int)(hole->iov_len / PAGE_SIZE)); + pr_debug("\th %p [%u]\n", hole->iov_base, (unsigned int)(hole->iov_len / PAGE_SIZE)); if (xfer->write_pagemap(xfer, hole, flags)) return -1; @@ -456,12 +446,11 @@ static int get_hole_flags(struct page_pipe *pp, int n) return -1; } -static int dump_holes(struct page_xfer *xfer, struct page_pipe *pp, - unsigned int *cur_hole, void *limit) +static int dump_holes(struct page_xfer *xfer, struct page_pipe *pp, unsigned int *cur_hole, void *limit) { int ret; - for (; *cur_hole < pp->free_hole ; (*cur_hole)++) { + for (; *cur_hole < pp->free_hole; (*cur_hole)++) { struct iovec hole = pp->holes[*cur_hole]; u32 hole_flags; @@ -627,11 +616,8 @@ static inline u32 ppb_xfer_flags(struct page_xfer *xfer, struct page_pipe_buf *p * aux_iov: {A,1}{B,1}{C,2}*{C+3,1}* */ -unsigned long handle_faulty_iov(int pid, struct iovec* riov, - unsigned long faulty_index, - struct iovec *bufvec, struct iovec* aux_iov, - unsigned long* aux_len, - unsigned long partial_read_bytes) +unsigned long handle_faulty_iov(int pid, struct iovec *riov, unsigned long faulty_index, struct iovec *bufvec, + struct iovec *aux_iov, unsigned long *aux_len, unsigned long partial_read_bytes) { struct iovec dummy; ssize_t bytes_read; @@ -645,7 +631,7 @@ unsigned long handle_faulty_iov(int pid, struct iovec* riov, } /* Handling Case 3-Part 3.2*/ - offset = (partial_read_bytes)? partial_read_bytes : PAGE_SIZE; + offset = (partial_read_bytes) ? partial_read_bytes : PAGE_SIZE; dummy.iov_base = riov[faulty_index].iov_base + offset; dummy.iov_len = riov[faulty_index].iov_len - offset; @@ -654,10 +640,9 @@ unsigned long handle_faulty_iov(int pid, struct iovec* riov, cnt_sub(CNT_PAGES_WRITTEN, 1); while (dummy.iov_len) { - bytes_read = process_vm_readv(pid, bufvec, 1, &dummy, 1, 0); - if(bytes_read == -1) { + if (bytes_read == -1) { /* Handling faulty page read in faulty iov */ cnt_sub(CNT_PAGES_WRITTEN, 1); dummy.iov_base += PAGE_SIZE; @@ -666,9 +651,8 @@ unsigned long handle_faulty_iov(int pid, struct iovec* riov, } /* If aux-iov can merge and expand or new entry required */ - if (aux_iov[(*aux_len)-1].iov_base + - aux_iov[(*aux_len)-1].iov_len == dummy.iov_base) - aux_iov[(*aux_len)-1].iov_len += bytes_read; + if (aux_iov[(*aux_len) - 1].iov_base + aux_iov[(*aux_len) - 1].iov_len == dummy.iov_base) + aux_iov[(*aux_len) - 1].iov_len += bytes_read; else { aux_iov[*aux_len].iov_base = dummy.iov_base; aux_iov[*aux_len].iov_len = bytes_read; @@ -690,8 +674,7 @@ unsigned long handle_faulty_iov(int pid, struct iovec* riov, * successfully read iov in iovec. In case of partial read it * returns partial_read_bytes, otherwise 0. */ -static unsigned long analyze_iov(ssize_t bytes_read, struct iovec* riov, - unsigned long *index, struct iovec *aux_iov, +static unsigned long analyze_iov(ssize_t bytes_read, struct iovec *riov, unsigned long *index, struct iovec *aux_iov, unsigned long *aux_len) { ssize_t processed_bytes = 0; @@ -699,7 +682,6 @@ static unsigned long analyze_iov(ssize_t bytes_read, struct iovec* riov, /* correlating iovs with read bytes */ while (processed_bytes < bytes_read) { - processed_bytes += riov[*index].iov_len; aux_iov[*aux_len].iov_base = riov[*index].iov_base; aux_iov[*aux_len].iov_len = riov[*index].iov_len; @@ -710,12 +692,10 @@ static unsigned long analyze_iov(ssize_t bytes_read, struct iovec* riov, /* handling partially processed faulty iov*/ if (processed_bytes - bytes_read) { - (*index) -= 1; - partial_read_bytes = riov[*index].iov_len - - (processed_bytes - bytes_read); - aux_iov[*aux_len-1].iov_len = partial_read_bytes; + partial_read_bytes = riov[*index].iov_len - (processed_bytes - bytes_read); + aux_iov[*aux_len - 1].iov_len = partial_read_bytes; } return partial_read_bytes; @@ -736,10 +716,8 @@ static unsigned long analyze_iov(ssize_t bytes_read, struct iovec* riov, * skip processing further any entry in iovec. This is handled by * handle_faulty_iov function. */ -static long fill_userbuf(int pid, struct page_pipe_buf *ppb, - struct iovec *bufvec, - struct iovec* aux_iov, - unsigned long *aux_len) +static long fill_userbuf(int pid, struct page_pipe_buf *ppb, struct iovec *bufvec, struct iovec *aux_iov, + unsigned long *aux_len) { struct iovec *riov = ppb->iov; ssize_t bytes_read; @@ -748,9 +726,7 @@ static long fill_userbuf(int pid, struct page_pipe_buf *ppb, unsigned long partial_read_bytes = 0; while (start < ppb->nr_segs) { - - bytes_read = process_vm_readv(pid, bufvec, 1, &riov[start], - ppb->nr_segs - start, 0); + bytes_read = process_vm_readv(pid, bufvec, 1, &riov[start], ppb->nr_segs - start, 0); if (bytes_read == -1) { /* Handling Case 1*/ @@ -767,9 +743,7 @@ static long fill_userbuf(int pid, struct page_pipe_buf *ppb, partial_read_bytes = 0; if (bytes_read > 0) { - partial_read_bytes = analyze_iov(bytes_read, riov, - &start, aux_iov, - aux_len); + partial_read_bytes = analyze_iov(bytes_read, riov, &start, aux_iov, aux_len); bufvec->iov_base += bytes_read; bufvec->iov_len -= bytes_read; total_read += bytes_read; @@ -780,9 +754,7 @@ static long fill_userbuf(int pid, struct page_pipe_buf *ppb, * it means some iov in between has failed. */ if (start < ppb->nr_segs) - total_read += handle_faulty_iov(pid, riov, start, bufvec, - aux_iov, aux_len, - partial_read_bytes); + total_read += handle_faulty_iov(pid, riov, start, bufvec, aux_iov, aux_len, partial_read_bytes); start += 1; } @@ -800,8 +772,7 @@ static long fill_userbuf(int pid, struct page_pipe_buf *ppb, * along with unmodified entries are present in aux_iov array. */ -int page_xfer_predump_pages(int pid, struct page_xfer *xfer, - struct page_pipe *pp) +int page_xfer_predump_pages(int pid, struct page_xfer *xfer, struct page_pipe *pp) { struct page_pipe_buf *ppb; unsigned int cur_hole = 0, i; @@ -811,8 +782,7 @@ int page_xfer_predump_pages(int pid, struct page_xfer *xfer, struct iovec aux_iov[PIPE_MAX_SIZE]; unsigned long aux_len; - char *userbuf = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + char *userbuf = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (userbuf == MAP_FAILED) { pr_perror("Unable to mmap a buffer"); @@ -820,7 +790,6 @@ int page_xfer_predump_pages(int pid, struct page_xfer *xfer, } list_for_each_entry(ppb, &pp->bufs, l) { - timing_start(TIME_MEMDUMP); aux_len = 0; @@ -849,7 +818,6 @@ int page_xfer_predump_pages(int pid, struct page_xfer *xfer, /* generating pagemap */ for (i = 0; i < aux_len; i++) { - struct iovec iov = aux_iov[i]; u32 flags; @@ -861,8 +829,7 @@ int page_xfer_predump_pages(int pid, struct page_xfer *xfer, BUG_ON(iov.iov_base < (void *)xfer->offset); iov.iov_base -= xfer->offset; - pr_debug("\t p %p [%u]\n", iov.iov_base, - (unsigned int)(iov.iov_len / PAGE_SIZE)); + pr_debug("\t p %p [%u]\n", iov.iov_base, (unsigned int)(iov.iov_len / PAGE_SIZE)); flags = ppb_xfer_flags(xfer, ppb); @@ -909,15 +876,13 @@ int page_xfer_dump_pages(struct page_xfer *xfer, struct page_pipe *pp) BUG_ON(iov.iov_base < (void *)xfer->offset); iov.iov_base -= xfer->offset; - pr_debug("\tp %p [%u]\n", iov.iov_base, - (unsigned int)(iov.iov_len / PAGE_SIZE)); + pr_debug("\tp %p [%u]\n", iov.iov_base, (unsigned int)(iov.iov_len / PAGE_SIZE)); flags = ppb_xfer_flags(xfer, ppb); if (xfer->write_pagemap(xfer, &iov, flags)) return -1; - if ((flags & PE_PRESENT) && xfer->write_pages(xfer, - ppb->p[0], iov.iov_len)) + if ((flags & PE_PRESENT) && xfer->write_pages(xfer, ppb->p[0], iov.iov_len)) return -1; } } @@ -1012,8 +977,8 @@ int check_parent_page_xfer(int fd_type, unsigned long img_id) } struct page_xfer_job { - u64 dst_id; - int p[2]; + u64 dst_id; + int p[2]; unsigned pipe_size; struct page_xfer loc_xfer; }; @@ -1084,7 +1049,7 @@ static int page_server_add(int sk, struct page_server_iov *pi, u32 flags) struct page_xfer *lxfer = &cxfer.loc_xfer; struct iovec iov; - pr_debug("Adding %"PRIx64"/%u\n", pi->vaddr, pi->nr_pages); + pr_debug("Adding %" PRIx64 "/%u\n", pi->vaddr, pi->nr_pages); if (prep_loc_xfer(pi)) return -1; @@ -1119,13 +1084,12 @@ static int page_server_add(int sk, struct page_server_iov *pi, u32 flags) } if (opts.tls) { - if(tls_recv_data_to_fd(cxfer.p[1], chunk)) { + if (tls_recv_data_to_fd(cxfer.p[1], chunk)) { pr_err("Can't read from socket\n"); return -1; } } else { - chunk = splice(sk, NULL, cxfer.p[1], NULL, chunk, - SPLICE_F_MOVE | SPLICE_F_NONBLOCK); + chunk = splice(sk, NULL, cxfer.p[1], NULL, chunk, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); if (chunk < 0) { pr_perror("Can't read from socket"); @@ -1156,8 +1120,7 @@ static int page_server_get_pages(int sk, struct page_server_iov *pi) item = pstree_item_by_virt(pi->dst_id); pp = dmpi(item)->mem_pp; - ret = page_pipe_read(pp, &pipe_read_dest, pi->vaddr, - &pi->nr_pages, PPB_LAZY); + ret = page_pipe_read(pp, &pipe_read_dest, pi->vaddr, &pi->nr_pages, PPB_LAZY); if (ret) return ret; @@ -1181,8 +1144,7 @@ static int page_server_get_pages(int sk, struct page_server_iov *pi) if (tls_send_data_from_fd(pipe_read_dest.p[0], len)) return -1; } else { - ret = splice(pipe_read_dest.p[0], NULL, sk, NULL, len, - SPLICE_F_MOVE); + ret = splice(pipe_read_dest.p[0], NULL, sk, NULL, len, SPLICE_F_MOVE); if (ret != len) return -1; } @@ -1248,23 +1210,21 @@ static int page_server_serve(int sk) break; case PS_IOV_ADD_F: case PS_IOV_ADD: - case PS_IOV_HOLE: - { + case PS_IOV_HOLE: { u32 flags; if (likely(cmd == PS_IOV_ADD_F)) flags = decode_ps_flags(pi.cmd); else if (cmd == PS_IOV_ADD) flags = PE_PRESENT; - else /* PS_IOV_HOLE */ + else /* PS_IOV_HOLE */ flags = PE_PARENT; ret = page_server_add(sk, &pi, flags); break; } case PS_IOV_FLUSH: - case PS_IOV_FLUSH_N_CLOSE: - { + case PS_IOV_FLUSH_N_CLOSE: { int32_t status = 0; ret = 0; @@ -1347,8 +1307,8 @@ static int fill_page_pipe(struct page_read *pr, struct page_pipe *pp) for (i = 0; i < ppb->nr_segs; i++) { struct iovec iov = ppb->iov[i]; - if (splice(img_raw_fd(pr->pi), NULL, ppb->p[1], NULL, - iov.iov_len, SPLICE_F_MOVE) != iov.iov_len) { + if (splice(img_raw_fd(pr->pi), NULL, ppb->p[1], NULL, iov.iov_len, SPLICE_F_MOVE) != + iov.iov_len) { pr_perror("Splice failed"); return -1; } @@ -1447,7 +1407,7 @@ int cr_page_server(bool daemon_mode, bool lazy_dump, int cfd) no_server: if (!daemon_mode && cfd >= 0) { - struct ps_info info = {.pid = getpid(), .port = opts.port}; + struct ps_info info = { .pid = getpid(), .port = opts.port }; int count; count = write(cfd, &info, sizeof(info)); @@ -1512,7 +1472,7 @@ int connect_to_page_server_to_send(void) int disconnect_from_page_server(void) { - struct page_server_iov pi = { }; + struct page_server_iov pi = {}; int32_t status = -1; int ret = -1; @@ -1547,7 +1507,7 @@ out: tls_terminate_session(); close_safe(&page_server_sk); - return ret ? : status; + return ret ?: status; } struct ps_async_read { @@ -1572,8 +1532,8 @@ static inline void async_read_set_goal(struct ps_async_read *ar, int nr_pages) ar->nr_pages = nr_pages; } -static void init_ps_async_read(struct ps_async_read *ar, void *buf, - int nr_pages, ps_async_read_complete complete, void *priv) +static void init_ps_async_read(struct ps_async_read *ar, void *buf, int nr_pages, ps_async_read_complete complete, + void *priv) { ar->pages = buf; ar->rb = 0; @@ -1582,8 +1542,7 @@ static void init_ps_async_read(struct ps_async_read *ar, void *buf, async_read_set_goal(ar, nr_pages); } -static int page_server_start_async_read(void *buf, int nr_pages, - ps_async_read_complete complete, void *priv) +static int page_server_start_async_read(void *buf, int nr_pages, ps_async_read_complete complete, void *priv) { struct ps_async_read *ar; @@ -1641,8 +1600,7 @@ static int page_server_read(struct ps_async_read *ar, int flags) * IO complete -- notify the caller and drop the request */ BUG_ON(ar->rb > ar->goal); - return ar->complete((int)ar->pi.dst_id, (unsigned long)ar->pi.vaddr, - (int)ar->pi.nr_pages, ar->priv); + return ar->complete((int)ar->pi.dst_id, (unsigned long)ar->pi.vaddr, (int)ar->pi.nr_pages, ar->priv); } static int page_server_async_read(struct epoll_rfd *f) @@ -1687,10 +1645,10 @@ int connect_to_page_server_to_recv(int epfd) int request_remote_pages(unsigned long img_id, unsigned long addr, int nr_pages) { struct page_server_iov pi = { - .cmd = PS_IOV_GET, - .nr_pages = nr_pages, - .vaddr = addr, - .dst_id = img_id, + .cmd = PS_IOV_GET, + .nr_pages = nr_pages, + .vaddr = addr, + .dst_id = img_id, }; /* XXX: why MSG_DONTWAIT here? */ @@ -1701,8 +1659,7 @@ int request_remote_pages(unsigned long img_id, unsigned long addr, int nr_pages) return 0; } -static int page_server_start_sync_read(void *buf, int nr, - ps_async_read_complete complete, void *priv) +static int page_server_start_sync_read(void *buf, int nr, ps_async_read_complete complete, void *priv) { struct ps_async_read ar; int ret = 1; @@ -1713,8 +1670,7 @@ static int page_server_start_sync_read(void *buf, int nr, return ret; } -int page_server_start_read(void *buf, int nr, - ps_async_read_complete complete, void *priv, unsigned flags) +int page_server_start_read(void *buf, int nr, ps_async_read_complete complete, void *priv, unsigned flags) { if (flags & PR_ASYNC) return page_server_start_async_read(buf, nr, complete, priv); diff --git a/criu/pagemap-cache.c b/criu/pagemap-cache.c index d7915f99c..00f088ff3 100644 --- a/criu/pagemap-cache.c +++ b/criu/pagemap-cache.c @@ -11,16 +11,16 @@ #include "mem.h" #include "kerndat.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "pagemap-cache: " /* To carry up to 2M of physical memory */ -#define PMC_SHIFT (21) -#define PMC_SIZE (1ul << PMC_SHIFT) -#define PMC_MASK (~(PMC_SIZE - 1)) -#define PMC_SIZE_GAP (PMC_SIZE / 4) +#define PMC_SHIFT (21) +#define PMC_SIZE (1ul << PMC_SHIFT) +#define PMC_MASK (~(PMC_SIZE - 1)) +#define PMC_SIZE_GAP (PMC_SIZE / 4) -#define PAGEMAP_LEN(addr) (PAGE_PFN(addr) * sizeof(u64)) +#define PAGEMAP_LEN(addr) (PAGE_PFN(addr) * sizeof(u64)) /* * It's a workaround for a kernel bug. In the 3.19 kernel when pagemap are read @@ -47,9 +47,9 @@ int pmc_init(pmc_t *pmc, pid_t pid, const struct list_head *vma_head, size_t siz BUG_ON(!vma_head); - pmc->pid = pid; - pmc->map_len = PAGEMAP_LEN(map_size); - pmc->vma_head = vma_head; + pmc->pid = pid; + pmc->map_len = PAGEMAP_LEN(map_size); + pmc->vma_head = vma_head; pmc->map = xmalloc(pmc->map_len); if (!pmc->map) @@ -105,8 +105,8 @@ static int pmc_fill_cache(pmc_t *pmc, const struct vma_area *vma) pmc->start = vma->e->start; pmc->end = vma->e->end; - pr_debug("%d: filling VMA %lx-%lx (%zuK) [l:%lx h:%lx]\n", - pmc->pid, (long)vma->e->start, (long)vma->e->end, len >> 10, low, high); + pr_debug("%d: filling VMA %lx-%lx (%zuK) [l:%lx h:%lx]\n", pmc->pid, (long)vma->e->start, (long)vma->e->end, + len >> 10, low, high); /* * If we meet a small VMA, lets try to fit 2M cache @@ -118,13 +118,12 @@ static int pmc_fill_cache(pmc_t *pmc, const struct vma_area *vma) * The benefit (apart redusing the number of read() calls) * is to walk page tables less. */ - if (!pagemap_cache_disabled && - len < PMC_SIZE && (vma->e->start - low) < PMC_SIZE_GAP) { + if (!pagemap_cache_disabled && len < PMC_SIZE && (vma->e->start - low) < PMC_SIZE_GAP) { size_t size_cov = len; size_t nr_vmas = 1; - pr_debug("\t%d: %16lx-%-16lx nr:%-5zu cov:%zu\n", - pmc->pid, (long)vma->e->start, (long)vma->e->end, nr_vmas, size_cov); + pr_debug("\t%d: %16lx-%-16lx nr:%-5zu cov:%zu\n", pmc->pid, (long)vma->e->start, (long)vma->e->end, + nr_vmas, size_cov); list_for_each_entry_continue(vma, pmc->vma_head, list) { if (vma->e->start > high || vma->e->end > high) @@ -134,8 +133,8 @@ static int pmc_fill_cache(pmc_t *pmc, const struct vma_area *vma) size_cov += vma_area_len(vma); nr_vmas++; - pr_debug("\t%d: %16lx-%-16lx nr:%-5zu cov:%zu\n", - pmc->pid, (long)vma->e->start, (long)vma->e->end, nr_vmas, size_cov); + pr_debug("\t%d: %16lx-%-16lx nr:%-5zu cov:%zu\n", pmc->pid, (long)vma->e->start, + (long)vma->e->end, nr_vmas, size_cov); } if (nr_vmas > 1) { @@ -171,8 +170,7 @@ u64 *pmc_get_map(pmc_t *pmc, const struct vma_area *vma) /* Miss, refill the cache */ if (pmc_fill_cache(pmc, vma)) { - pr_err("Failed to fill cache for %d (%lx-%lx)\n", - pmc->pid, (long)vma->e->start, (long)vma->e->end); + pr_err("Failed to fill cache for %d (%lx-%lx)\n", pmc->pid, (long)vma->e->start, (long)vma->e->end); return NULL; } diff --git a/criu/pagemap.c b/criu/pagemap.c index 1d849a1b9..77e519dd1 100644 --- a/criu/pagemap.c +++ b/criu/pagemap.c @@ -20,8 +20,8 @@ #include "images/pagemap.pb-c.h" #ifndef SEEK_DATA -#define SEEK_DATA 3 -#define SEEK_HOLE 4 +#define SEEK_DATA 3 +#define SEEK_HOLE 4 #endif #define MAX_BUNCH_SIZE 256 @@ -30,32 +30,30 @@ * One "job" for the preadv() syscall in pagemap.c */ struct page_read_iov { - off_t from; /* offset in pi file where to start reading from */ - off_t end; /* the end of the read == sum to.iov_len -s */ - struct iovec *to; /* destination iovs */ - unsigned int nr; /* their number */ + off_t from; /* offset in pi file where to start reading from */ + off_t end; /* the end of the read == sum to.iov_len -s */ + struct iovec *to; /* destination iovs */ + unsigned int nr; /* their number */ struct list_head l; }; -static inline bool can_extend_bunch(struct iovec *bunch, - unsigned long off, unsigned long len) +static inline bool can_extend_bunch(struct iovec *bunch, unsigned long off, unsigned long len) { - return /* The next region is the continuation of the existing */ + return /* The next region is the continuation of the existing */ ((unsigned long)bunch->iov_base + bunch->iov_len == off) && /* The resulting region is non empty and is small enough */ (bunch->iov_len == 0 || bunch->iov_len + len < MAX_BUNCH_SIZE * PAGE_SIZE); } -static int punch_hole(struct page_read *pr, unsigned long off, - unsigned long len, bool cleanup) +static int punch_hole(struct page_read *pr, unsigned long off, unsigned long len, bool cleanup) { int ret; - struct iovec * bunch = &pr->bunch; + struct iovec *bunch = &pr->bunch; if (!cleanup && can_extend_bunch(bunch, off, len)) { - pr_debug("pr%lu-%u:Extend bunch len from %zu to %lu\n", pr->img_id, - pr->id, bunch->iov_len, bunch->iov_len + len); + pr_debug("pr%lu-%u:Extend bunch len from %zu to %lu\n", pr->img_id, pr->id, bunch->iov_len, + bunch->iov_len + len); bunch->iov_len += len; } else { if (bunch->iov_len > 0) { @@ -82,17 +80,15 @@ int dedup_one_iovec(struct page_read *pr, unsigned long off, unsigned long len) while (1) { int ret; unsigned long piov_end; - struct page_read * prp; + struct page_read *prp; ret = pr->seek_pagemap(pr, off); if (ret == 0) { if (off < pr->cvaddr && pr->cvaddr < iov_end) { - pr_debug("pr%lu-%u:No range %lx-%lx in pagemap\n", - pr->img_id, pr->id, off, pr->cvaddr); + pr_debug("pr%lu-%u:No range %lx-%lx in pagemap\n", pr->img_id, pr->id, off, pr->cvaddr); off = pr->cvaddr; } else { - pr_debug("pr%lu-%u:No range %lx-%lx in pagemap\n", - pr->img_id, pr->id, off, iov_end); + pr_debug("pr%lu-%u:No range %lx-%lx in pagemap\n", pr->img_id, pr->id, off, iov_end); return 0; } } @@ -109,8 +105,7 @@ int dedup_one_iovec(struct page_read *pr, unsigned long off, unsigned long len) prp = pr->parent; if (prp) { /* recursively */ - pr_debug("pr%lu-%u:Go to next parent level\n", - pr->img_id, pr->id); + pr_debug("pr%lu-%u:Go to next parent level\n", pr->img_id, pr->id); len = min(piov_end, iov_end) - off; ret = dedup_one_iovec(prp, off, len); if (ret != 0) @@ -167,8 +162,7 @@ static int seek_pagemap(struct page_read *pr, unsigned long vaddr) if (end <= vaddr) skip_pagemap_pages(pr, end - pr->cvaddr); -adv: - ; /* otherwise "label at end of compound stmt" gcc error */ + adv:; /* otherwise "label at end of compound stmt" gcc error */ } while (advance(pr)); return 0; @@ -177,14 +171,12 @@ adv: static inline void pagemap_bound_check(PagemapEntry *pe, unsigned long vaddr, int nr) { if (vaddr < pe->vaddr || (vaddr - pe->vaddr) / PAGE_SIZE + nr > pe->nr_pages) { - pr_err("Page read err %"PRIx64":%u vs %lx:%u\n", - pe->vaddr, pe->nr_pages, vaddr, nr); + pr_err("Page read err %" PRIx64 ":%u vs %lx:%u\n", pe->vaddr, pe->nr_pages, vaddr, nr); BUG(); } } -static int read_parent_page(struct page_read *pr, unsigned long vaddr, - int nr, void *buf, unsigned flags) +static int read_parent_page(struct page_read *pr, unsigned long vaddr, int nr, void *buf, unsigned flags) { struct page_read *ppr = pr->parent; int ret; @@ -239,8 +231,7 @@ static int read_parent_page(struct page_read *pr, unsigned long vaddr, return 0; } -static int read_local_page(struct page_read *pr, unsigned long vaddr, - unsigned long len, void *buf) +static int read_local_page(struct page_read *pr, unsigned long vaddr, unsigned long len, void *buf) { int fd; ssize_t ret; @@ -258,7 +249,7 @@ static int read_local_page(struct page_read *pr, unsigned long vaddr, if (pr->sync(pr)) return -1; - pr_debug("\tpr%lu-%u Read page from self %lx/%"PRIx64"\n", pr->img_id, pr->id, pr->cvaddr, pr->pi_off); + pr_debug("\tpr%lu-%u Read page from self %lx/%" PRIx64 "\n", pr->img_id, pr->id, pr->cvaddr, pr->pi_off); while (1) { ret = pread(fd, buf + curr, len - curr, pr->pi_off + curr); if (ret < 1) { @@ -279,8 +270,7 @@ static int read_local_page(struct page_read *pr, unsigned long vaddr, return 0; } -static int enqueue_async_iov(struct page_read *pr, void *buf, - unsigned long len, struct list_head *to) +static int enqueue_async_iov(struct page_read *pr, void *buf, unsigned long len, struct list_head *to) { struct page_read_iov *pr_iov; struct iovec *iov; @@ -319,8 +309,7 @@ int pagemap_render_iovec(struct list_head *from, struct task_restore_args *ta) list_for_each_entry(piov, from, l) { struct restore_vma_io *rio; - pr_info("`- render %d iovs (%p:%zd...)\n", piov->nr, - piov->to[0].iov_base, piov->to[0].iov_len); + pr_info("`- render %d iovs (%p:%zd...)\n", piov->nr, piov->to[0].iov_base, piov->to[0].iov_len); rio = rst_mem_alloc(RIO_SIZE(piov->nr), RM_PRIVATE); if (!rio) return -1; @@ -335,8 +324,7 @@ int pagemap_render_iovec(struct list_head *from, struct task_restore_args *ta) return 0; } -int pagemap_enqueue_iovec(struct page_read *pr, void *buf, - unsigned long len, struct list_head *to) +int pagemap_enqueue_iovec(struct page_read *pr, void *buf, unsigned long len, struct list_head *to) { struct page_read_iov *cur_async = NULL; struct iovec *iov; @@ -386,8 +374,7 @@ int pagemap_enqueue_iovec(struct page_read *pr, void *buf, return 0; } -static int maybe_read_page_local(struct page_read *pr, unsigned long vaddr, - int nr, void *buf, unsigned flags) +static int maybe_read_page_local(struct page_read *pr, unsigned long vaddr, int nr, void *buf, unsigned flags) { int ret; unsigned long len = nr * PAGE_SIZE; @@ -398,7 +385,7 @@ static int maybe_read_page_local(struct page_read *pr, unsigned long vaddr, * for us for urgent async read, just do the regular * cached read. */ - if ((flags & (PR_ASYNC|PR_ASAP)) == PR_ASYNC) + if ((flags & (PR_ASYNC | PR_ASAP)) == PR_ASYNC) ret = pagemap_enqueue_iovec(pr, buf, len, &pr->async); else { ret = read_local_page(pr, vaddr, len, buf); @@ -415,8 +402,7 @@ static int maybe_read_page_local(struct page_read *pr, unsigned long vaddr, * We cannot use maybe_read_page_local() for streaming images as it uses * pread(), seeking in the file. Instead, we use this custom page reader. */ -static int maybe_read_page_img_streamer(struct page_read *pr, unsigned long vaddr, - int nr, void *buf, unsigned flags) +static int maybe_read_page_img_streamer(struct page_read *pr, unsigned long vaddr, int nr, void *buf, unsigned flags) { unsigned long len = nr * PAGE_SIZE; int fd; @@ -429,8 +415,7 @@ static int maybe_read_page_img_streamer(struct page_read *pr, unsigned long vadd return -1; } - pr_debug("\tpr%lu-%u Read page from self %lx/%"PRIx64"\n", - pr->img_id, pr->id, pr->cvaddr, pr->pi_off); + pr_debug("\tpr%lu-%u Read page from self %lx/%" PRIx64 "\n", pr->img_id, pr->id, pr->cvaddr, pr->pi_off); /* We can't seek. The requested address better match */ BUG_ON(pr->cvaddr != vaddr); @@ -466,8 +451,7 @@ static int read_page_complete(unsigned long img_id, unsigned long vaddr, int nr_ struct page_read *pr = priv; if (pr->img_id != img_id) { - pr_err("Out of order read completed (want %lu have %lu)\n", - pr->img_id, img_id); + pr_err("Out of order read completed (want %lu have %lu)\n", pr->img_id, img_id); return -1; } @@ -479,21 +463,18 @@ static int read_page_complete(unsigned long img_id, unsigned long vaddr, int nr_ return ret; } -static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr, - int nr, void *buf, unsigned flags) +static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr, int nr, void *buf, unsigned flags) { int ret; /* We always do PR_ASAP mode here (FIXME?) */ ret = request_remote_pages(pr->img_id, vaddr, nr); if (!ret) - ret = page_server_start_read(buf, nr, - read_page_complete, pr, flags); + ret = page_server_start_read(buf, nr, read_page_complete, pr, flags); return ret; } -static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr, - void *buf, unsigned flags) +static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr, void *buf, unsigned flags) { pr_info("pr%lu-%u Read %lx %u pages\n", pr->img_id, pr->id, vaddr, nr); pagemap_bound_check(pr->pe, vaddr, nr); @@ -543,8 +524,7 @@ static void advance_piov(struct page_read_iov *piov, ssize_t len) break; } - pr_debug("Advanced iov %zu bytes, %d->%d iovs, %zu tail\n", - olen, onr, piov->nr, len); + pr_debug("Advanced iov %zu bytes, %d->%d iovs, %zu tail\n", olen, onr, piov->nr, len); } static int process_async_reads(struct page_read *pr) @@ -558,10 +538,9 @@ static int process_async_reads(struct page_read *pr) off_t start = piov->from; struct iovec *iovs = piov->to; - pr_debug("Read piov iovs %d, from %ju, len %ju, first %p:%zu\n", - piov->nr, piov->from, piov->end - piov->from, - piov->to->iov_base, piov->to->iov_len); -more: + pr_debug("Read piov iovs %d, from %ju, len %ju, first %p:%zu\n", piov->nr, piov->from, + piov->end - piov->from, piov->to->iov_base, piov->to->iov_len); + more: ret = preadv(fd, piov->to, piov->nr, piov->from); if (fault_injected(FI_PARTIAL_PAGES)) { /* @@ -577,8 +556,8 @@ more: if (ret != piov->end - piov->from) { if (ret < 0) { - pr_err("Can't read async pr bytes (%zd / %ju read, %ju off, %d iovs)\n", - ret, piov->end - piov->from, piov->from, piov->nr); + pr_err("Can't read async pr bytes (%zd / %ju read, %ju off, %d iovs)\n", ret, + piov->end - piov->from, piov->from, piov->nr); return -1; } @@ -746,8 +725,7 @@ static int init_pagemaps(struct page_read *pr) pr->curr_pme = -1; while (1) { - int ret = pb_read_one_eof(pr->pmi, &pr->pmes[pr->nr_pmes], - PB_PAGEMAP); + int ret = pb_read_one_eof(pr->pmi, &pr->pmes[pr->nr_pmes], PB_PAGEMAP); if (ret < 0) goto free_pagemaps; if (ret == 0) @@ -759,8 +737,7 @@ static int init_pagemaps(struct page_read *pr) if (pr->nr_pmes >= nr_pmes) { PagemapEntry **new; nr_pmes += nr_realloc; - new = xrealloc(pr->pmes, - nr_pmes * sizeof(*pr->pmes)); + new = xrealloc(pr->pmes, nr_pmes * sizeof(*pr->pmes)); if (!new) goto free_pagemaps; pr->pmes = new; @@ -863,8 +840,7 @@ int open_page_read_at(int dfd, unsigned long img_id, struct page_read *pr, int p pr->pieok = true; } - pr_debug("Opened %s page read %u (parent %u)\n", - remote ? "remote" : "local", pr->id, + pr_debug("Opened %s page read %u (parent %u)\n", remote ? "remote" : "local", pr->id, pr->parent ? pr->parent->id : 0); return 1; @@ -875,7 +851,6 @@ int open_page_read(unsigned long img_id, struct page_read *pr, int pr_flags) return open_page_read_at(get_service_fd(IMG_FD_OFF), img_id, pr, pr_flags); } - #define DUP_IDS_BASE 1000 void dup_page_read(struct page_read *src, struct page_read *dst) diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c index 2513dceec..7175adee1 100644 --- a/criu/parasite-syscall.c +++ b/criu/parasite-syscall.c @@ -85,14 +85,12 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) if (pid <= 0) return; - pr_err("si_code=%d si_pid=%d si_status=%d\n", - siginfo->si_code, siginfo->si_pid, siginfo->si_status); + pr_err("si_code=%d si_pid=%d si_status=%d\n", siginfo->si_code, siginfo->si_pid, siginfo->si_status); if (WIFEXITED(status)) pr_err("%d exited with %d unexpectedly\n", pid, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) - pr_err("%d was killed by %d unexpectedly: %s\n", - pid, WTERMSIG(status), strsignal(WTERMSIG(status))); + pr_err("%d was killed by %d unexpectedly: %s\n", pid, WTERMSIG(status), strsignal(WTERMSIG(status))); else if (WIFSTOPPED(status)) pr_err("%d was stopped by %d unexpectedly\n", pid, WSTOPSIG(status)); @@ -117,19 +115,19 @@ static int alloc_groups_copy_creds(CredsEntry *ce, struct parasite_dump_creds *c memcpy(ce->cap_eff, c->cap_eff, sizeof(c->cap_eff[0]) * CR_CAP_SIZE); memcpy(ce->cap_bnd, c->cap_bnd, sizeof(c->cap_bnd[0]) * CR_CAP_SIZE); - ce->secbits = c->secbits; - ce->n_groups = c->ngroups; + ce->secbits = c->secbits; + ce->n_groups = c->ngroups; - ce->groups = xmemdup(c->groups, sizeof(c->groups[0]) * c->ngroups); + ce->groups = xmemdup(c->groups, sizeof(c->groups[0]) * c->ngroups); - ce->uid = c->uids[0]; - ce->gid = c->gids[0]; - ce->euid = c->uids[1]; - ce->egid = c->gids[1]; - ce->suid = c->uids[2]; - ce->sgid = c->gids[2]; - ce->fsuid = c->uids[3]; - ce->fsgid = c->gids[3]; + ce->uid = c->uids[0]; + ce->gid = c->gids[0]; + ce->euid = c->uids[1]; + ce->egid = c->gids[1]; + ce->suid = c->uids[2]; + ce->sgid = c->gids[2]; + ce->fsuid = c->uids[3]; + ce->fsgid = c->gids[3]; return ce->groups ? 0 : -ENOMEM; } @@ -161,9 +159,8 @@ int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, CoreEn return dump_thread_core(pid, core, args); } -int parasite_dump_thread_seized(struct parasite_thread_ctl *tctl, - struct parasite_ctl *ctl, int id, - struct pid *tid, CoreEntry *core) +int parasite_dump_thread_seized(struct parasite_thread_ctl *tctl, struct parasite_ctl *ctl, int id, struct pid *tid, + CoreEntry *core) { struct parasite_dump_thread *args; pid_t pid = tid->real; @@ -182,7 +179,7 @@ int parasite_dump_thread_seized(struct parasite_thread_ctl *tctl, tc->has_blk_sigset = true; #ifdef CONFIG_MIPS memcpy(&tc->blk_sigset, (unsigned long *)compel_thread_sigmask(tctl), sizeof(tc->blk_sigset)); - memcpy(&tc->blk_sigset_extended, (unsigned long *)compel_thread_sigmask(tctl)+1, sizeof(tc->blk_sigset)); + memcpy(&tc->blk_sigset_extended, (unsigned long *)compel_thread_sigmask(tctl) + 1, sizeof(tc->blk_sigset)); #else memcpy(&tc->blk_sigset, compel_thread_sigmask(tctl), sizeof(k_rtsigset_t)); #endif @@ -292,15 +289,14 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct pstree_item *i if (ret < 0) return ret; - encode_itimer((&args->real), (core->tc->timers->real)); \ - encode_itimer((&args->virt), (core->tc->timers->virt)); \ - encode_itimer((&args->prof), (core->tc->timers->prof)); \ + encode_itimer((&args->real), (core->tc->timers->real)); + encode_itimer((&args->virt), (core->tc->timers->virt)); + encode_itimer((&args->prof), (core->tc->timers->prof)); return 0; } -static int core_alloc_posix_timers(TaskTimersEntry *tte, int n, - PosixTimerEntry **pte) +static int core_alloc_posix_timers(TaskTimersEntry *tte, int n, PosixTimerEntry **pte) { int sz; @@ -318,9 +314,7 @@ static int core_alloc_posix_timers(TaskTimersEntry *tte, int n, return 0; } -static int encode_notify_thread_id(pid_t rtid, - struct pstree_item *item, - PosixTimerEntry *pte) +static int encode_notify_thread_id(pid_t rtid, struct pstree_item *item, PosixTimerEntry *pte) { pid_t vtid = 0; int i; @@ -359,8 +353,8 @@ static int encode_notify_thread_id(pid_t rtid, return 0; } -static int encode_posix_timer(struct pstree_item *item, struct posix_timer *v, - struct proc_posix_timer *vp, PosixTimerEntry *pte) +static int encode_posix_timer(struct pstree_item *item, struct posix_timer *v, struct proc_posix_timer *vp, + PosixTimerEntry *pte) { pte->it_id = vp->spt.it_id; pte->clock_id = vp->spt.clock_id; @@ -375,15 +369,14 @@ static int encode_posix_timer(struct pstree_item *item, struct posix_timer *v, pte->vsec = v->val.it_value.tv_sec; pte->vnsec = v->val.it_value.tv_nsec; - if (encode_notify_thread_id(vp->spt.notify_thread_id, - item, pte)) + if (encode_notify_thread_id(vp->spt.notify_thread_id, item, pte)) return -1; return 0; } -int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args, - struct parasite_ctl *ctl, struct pstree_item *item) +int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args, struct parasite_ctl *ctl, + struct pstree_item *item) { CoreEntry *core = item->core[0]; TaskTimersEntry *tte = core->tc->timers; @@ -452,9 +445,8 @@ struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd, in return p; } -int parasite_drain_fds_seized(struct parasite_ctl *ctl, - struct parasite_drain_fd *dfds, int nr_fds, int off, - int *lfds, struct fd_opts *opts) +int parasite_drain_fds_seized(struct parasite_ctl *ctl, struct parasite_drain_fd *dfds, int nr_fds, int off, int *lfds, + struct fd_opts *opts) { int ret = -1, size, sk; struct parasite_drain_fd *args; @@ -532,8 +524,7 @@ static int make_sigframe(void *arg, struct rt_sigframe *sf, struct rt_sigframe * return construct_sigframe(sf, rtsf, bs, (CoreEntry *)arg); } -static int parasite_prepare_threads(struct parasite_ctl *ctl, - struct pstree_item *item) +static int parasite_prepare_threads(struct parasite_ctl *ctl, struct pstree_item *item) { struct parasite_thread_ctl **thread_ctls; uint64_t *thread_sp; @@ -574,8 +565,7 @@ free_ctls: return -1; } -struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item, - struct vm_area_list *vma_area_list) +struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item, struct vm_area_list *vma_area_list) { struct parasite_ctl *ctl; struct infect_ctx *ictx; @@ -642,8 +632,10 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item, parasite_args_size = PARASITE_ARG_SIZE_MIN; /* reset for next task */ #ifdef CONFIG_MIPS - memcpy(&item->core[0]->tc->blk_sigset, (unsigned long *)compel_task_sigmask(ctl), sizeof(item->core[0]->tc->blk_sigset)); - memcpy(&item->core[0]->tc->blk_sigset_extended, (unsigned long *)compel_task_sigmask(ctl)+1, sizeof(item->core[0]->tc->blk_sigset)); + memcpy(&item->core[0]->tc->blk_sigset, (unsigned long *)compel_task_sigmask(ctl), + sizeof(item->core[0]->tc->blk_sigset)); + memcpy(&item->core[0]->tc->blk_sigset_extended, (unsigned long *)compel_task_sigmask(ctl) + 1, + sizeof(item->core[0]->tc->blk_sigset)); #else memcpy(&item->core[0]->tc->blk_sigset, compel_task_sigmask(ctl), sizeof(k_rtsigset_t)); #endif diff --git a/criu/path.c b/criu/path.c index 637d0fae2..1b71c4cb1 100644 --- a/criu/path.c +++ b/criu/path.c @@ -38,8 +38,7 @@ out: return path; } -char *mnt_get_sibling_path(struct mount_info *m, - struct mount_info *p, char *buf, int len) +char *mnt_get_sibling_path(struct mount_info *m, struct mount_info *p, char *buf, int len) { struct mount_info *pa = m->parent; char *rpath, *cut_root, *path = buf; diff --git a/criu/pidfd-store.c b/criu/pidfd-store.c index 211cdcf17..98b478b30 100644 --- a/criu/pidfd-store.c +++ b/criu/pidfd-store.c @@ -15,13 +15,13 @@ #include "pidfd-store.h" struct pidfd_entry { - pid_t pid; - int pidfd; - struct hlist_node hash; /* To lookup pidfd by pid */ + pid_t pid; + int pidfd; + struct hlist_node hash; /* To lookup pidfd by pid */ }; static int pidfd_store_sk = -1; -#define PIDFD_HASH_SIZE 32 +#define PIDFD_HASH_SIZE 32 static struct hlist_head pidfd_hash[PIDFD_HASH_SIZE]; /* @@ -95,7 +95,7 @@ int init_pidfd_store_sk(pid_t pid, int sk) */ if (addrlen == sizeof(sa_family_t)) { if (setsockopt(pidfd_store_sk, SOL_SOCKET, SO_SNDBUFFORCE, &buf[0], sizeof(buf[0])) < 0 || - setsockopt(pidfd_store_sk, SOL_SOCKET, SO_RCVBUFFORCE, &buf[1], sizeof(buf[1])) < 0) { + setsockopt(pidfd_store_sk, SOL_SOCKET, SO_RCVBUFFORCE, &buf[1], sizeof(buf[1])) < 0) { pr_perror("Unable to set SO_SNDBUFFORCE/SO_RCVBUFFORCE"); goto err; } diff --git a/criu/pie/parasite-vdso.c b/criu/pie/parasite-vdso.c index 3f5cb1431..355007fa9 100644 --- a/criu/pie/parasite-vdso.c +++ b/criu/pie/parasite-vdso.c @@ -21,7 +21,7 @@ #include "common/bug.h" #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " @@ -96,7 +96,7 @@ void vdso_update_gtod_addr(struct vdso_maps *rt) return; } - gtod = (void*)(rt->vdso_start + gtod_sym->offset); + gtod = (void *)(rt->vdso_start + gtod_sym->offset); pr_info("Using gettimeofday() on vdso at %p\n", gtod); std_log_set_gettimeofday(gtod); @@ -125,8 +125,7 @@ int vdso_do_park(struct vdso_maps *rt, unsigned long addr, unsigned long space) } #ifndef CONFIG_COMPAT -static int __vdso_fill_symtable(uintptr_t mem, size_t size, - struct vdso_symtable *t, bool __always_unused compat_vdso) +static int __vdso_fill_symtable(uintptr_t mem, size_t size, struct vdso_symtable *t, bool __always_unused compat_vdso) { return vdso_fill_symtable(mem, size, t); } @@ -142,27 +141,25 @@ static int __vdso_fill_symtable(uintptr_t mem, size_t size, * b) Symbols offsets must match * c) Have same number of vDSO zones */ -static bool blobs_matches(VmaEntry *vdso_img, VmaEntry *vvar_img, - struct vdso_symtable *sym_img, struct vdso_symtable *sym_rt) +static bool blobs_matches(VmaEntry *vdso_img, VmaEntry *vvar_img, struct vdso_symtable *sym_img, + struct vdso_symtable *sym_rt) { unsigned long vdso_size = vma_entry_len(vdso_img); unsigned long rt_vdso_size = sym_rt->vdso_size; size_t i; if (vdso_size != rt_vdso_size) { - pr_info("size differs: %lx != %lx (rt)\n", - vdso_size, rt_vdso_size); + pr_info("size differs: %lx != %lx (rt)\n", vdso_size, rt_vdso_size); return false; } for (i = 0; i < ARRAY_SIZE(sym_img->symbols); i++) { - unsigned long sym_offset = sym_img->symbols[i].offset; - unsigned long rt_sym_offset = sym_rt->symbols[i].offset; - char *sym_name = sym_img->symbols[i].name; + unsigned long sym_offset = sym_img->symbols[i].offset; + unsigned long rt_sym_offset = sym_rt->symbols[i].offset; + char *sym_name = sym_img->symbols[i].name; if (sym_offset != rt_sym_offset) { - pr_info("[%zu]`%s` offset differs: %lx != %lx (rt)\n", - i, sym_name, sym_offset, rt_sym_offset); + pr_info("[%zu]`%s` offset differs: %lx != %lx (rt)\n", i, sym_name, sym_offset, rt_sym_offset); return false; } } @@ -173,14 +170,12 @@ static bool blobs_matches(VmaEntry *vdso_img, VmaEntry *vvar_img, unsigned long rt_vvar_size = sym_rt->vvar_size; if (vvar_size != rt_vvar_size) { - pr_info("vvar size differs: %lx != %lx (rt)\n", - vdso_size, rt_vdso_size); + pr_info("vvar size differs: %lx != %lx (rt)\n", vdso_size, rt_vdso_size); return false; } if (vdso_firstly != sym_rt->vdso_before_vvar) { - pr_info("[%s] pair has different order\n", - vdso_firstly ? "vdso/vvar" : "vvar/vdso"); + pr_info("[%s] pair has different order\n", vdso_firstly ? "vdso/vvar" : "vvar/vdso"); return false; } } @@ -193,8 +188,7 @@ static bool blobs_matches(VmaEntry *vdso_img, VmaEntry *vvar_img, * order and size as runtime vdso, so we simply remap runtime vdso * to dumpee position without generating any proxy. */ -static int remap_rt_vdso(VmaEntry *vma_vdso, VmaEntry *vma_vvar, - struct vdso_maps *rt) +static int remap_rt_vdso(VmaEntry *vma_vdso, VmaEntry *vma_vvar, struct vdso_maps *rt) { void *remap_addr; @@ -227,12 +221,10 @@ static int remap_rt_vdso(VmaEntry *vma_vdso, VmaEntry *vma_vvar, * calls from dumpee vdso to runtime vdso, making dumpee * to operate as proxy vdso. */ -static int add_vdso_proxy(VmaEntry *vma_vdso, VmaEntry *vma_vvar, - struct vdso_symtable *sym_img, struct vdso_maps *rt, - bool compat_vdso) +static int add_vdso_proxy(VmaEntry *vma_vdso, VmaEntry *vma_vvar, struct vdso_symtable *sym_img, struct vdso_maps *rt, + bool compat_vdso) { - unsigned long orig_vvar_addr = - vma_vvar ? vma_vvar->start : VVAR_BAD_ADDR; + unsigned long orig_vvar_addr = vma_vvar ? vma_vvar->start : VVAR_BAD_ADDR; pr_info("Runtime vdso mismatches dumpee, generate proxy\n"); @@ -244,8 +236,7 @@ static int add_vdso_proxy(VmaEntry *vma_vdso, VmaEntry *vma_vvar, * jumps, so we can't remove them if on the following migration * found that number of symbols in vdso has decreased. */ - if (vdso_redirect_calls(rt->vdso_start, vma_vdso->start, - &rt->sym, sym_img, compat_vdso)) { + if (vdso_redirect_calls(rt->vdso_start, vma_vdso->start, &rt->sym, sym_img, compat_vdso)) { pr_err("Failed to proxify dumpee contents\n"); return -1; } @@ -256,16 +247,14 @@ static int add_vdso_proxy(VmaEntry *vma_vdso, VmaEntry *vma_vvar, * it's auto-generated every new session if proxy required. */ sys_mprotect((void *)rt->vdso_start, rt->sym.vdso_size, PROT_WRITE); - vdso_put_mark((void *)rt->vdso_start, rt->vvar_start, - vma_vdso->start, orig_vvar_addr); + vdso_put_mark((void *)rt->vdso_start, rt->vvar_start, vma_vdso->start, orig_vvar_addr); sys_mprotect((void *)rt->vdso_start, rt->sym.vdso_size, VDSO_PROT); return 0; } -int vdso_proxify(struct vdso_maps *rt, bool *added_proxy, - VmaEntry *vmas, size_t nr_vmas, - bool compat_vdso, bool force_trampolines) +int vdso_proxify(struct vdso_maps *rt, bool *added_proxy, VmaEntry *vmas, size_t nr_vmas, bool compat_vdso, + bool force_trampolines) { VmaEntry *vma_vdso = NULL, *vma_vvar = NULL; struct vdso_symtable s = VDSO_SYMTABLE_INIT; @@ -313,12 +302,10 @@ int vdso_proxify(struct vdso_maps *rt, bool *added_proxy, /* * Find symbols in vDSO zone read from image. */ - if (__vdso_fill_symtable((uintptr_t)vma_vdso->start, - vma_entry_len(vma_vdso), &s, compat_vdso)) + if (__vdso_fill_symtable((uintptr_t)vma_vdso->start, vma_entry_len(vma_vdso), &s, compat_vdso)) return -1; - pr_debug("image [vdso] %lx-%lx [vvar] %lx-%lx\n", - (unsigned long)vma_vdso->start, (unsigned long)vma_vdso->end, + pr_debug("image [vdso] %lx-%lx [vvar] %lx-%lx\n", (unsigned long)vma_vdso->start, (unsigned long)vma_vdso->end, vma_vvar ? (unsigned long)vma_vvar->start : VVAR_BAD_ADDR, vma_vvar ? (unsigned long)vma_vvar->end : VVAR_BAD_ADDR); diff --git a/criu/pie/parasite.c b/criu/pie/parasite.c index 59e838544..bc0a33cd4 100644 --- a/criu/pie/parasite.c +++ b/criu/pie/parasite.c @@ -32,15 +32,15 @@ static struct parasite_dump_pages_args *mprotect_args = NULL; #ifndef SPLICE_F_GIFT -#define SPLICE_F_GIFT 0x08 +#define SPLICE_F_GIFT 0x08 #endif #ifndef PR_GET_PDEATHSIG -#define PR_GET_PDEATHSIG 2 +#define PR_GET_PDEATHSIG 2 #endif #ifndef PR_GET_CHILD_SUBREAPER -#define PR_GET_CHILD_SUBREAPER 37 +#define PR_GET_CHILD_SUBREAPER 37 #endif static int mprotect_vmas(struct parasite_dump_pages_args *args) @@ -53,8 +53,7 @@ static int mprotect_vmas(struct parasite_dump_pages_args *args) vma = vmas + i; ret = sys_mprotect((void *)vma->start, vma->len, vma->prot | args->add_prot); if (ret) { - pr_err("mprotect(%08lx, %ld) failed with code %d\n", - vma->start, vma->len, ret); + pr_err("mprotect(%08lx, %ld) failed with code %d\n", vma->start, vma->len, ret); break; } } @@ -85,12 +84,10 @@ static int dump_pages(struct parasite_dump_pages_args *args) if (nr_segs > UIO_MAXIOV) nr_segs = UIO_MAXIOV; while (1) { - ret = sys_vmsplice(p, &iovs[args->off + off], nr_segs, - SPLICE_F_GIFT | SPLICE_F_NONBLOCK); + ret = sys_vmsplice(p, &iovs[args->off + off], nr_segs, SPLICE_F_GIFT | SPLICE_F_NONBLOCK); if (ret < 0) { sys_close(p); - pr_err("Can't splice pages to pipe (%d/%d/%d)\n", - ret, nr_segs, args->off + off); + pr_err("Can't splice pages to pipe (%d/%d/%d)\n", ret, nr_segs, args->off + off); return -1; } spliced_bytes += ret; @@ -151,7 +148,7 @@ static int dump_posix_timers(struct parasite_dump_posix_timers_args *args) int i; int ret = 0; - for(i = 0; i < args->timer_n; i++) { + for (i = 0; i < args->timer_n; i++) { ret = sys_timer_gettime(args->timer[i].it_id, &args->timer[i].val); if (ret < 0) { pr_err("sys_timer_gettime failed (%d)\n", ret); @@ -176,7 +173,7 @@ static int dump_thread_common(struct parasite_dump_thread *ti) int ret; arch_get_tls(&ti->tls); - ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long) &ti->tid_addr, 0, 0, 0); + ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long)&ti->tid_addr, 0, 0, 0); if (ret) { pr_err("Unable to get the clear_child_tid address: %d\n", ret); goto out; @@ -194,7 +191,7 @@ static int dump_thread_common(struct parasite_dump_thread *ti) goto out; } - ret = sys_prctl(PR_GET_NAME, (unsigned long) &ti->comm, 0, 0, 0); + ret = sys_prctl(PR_GET_NAME, (unsigned long)&ti->comm, 0, 0, 0); if (ret) { pr_err("Unable to get the thread name: %d\n", ret); goto out; @@ -230,7 +227,7 @@ static int dump_creds(struct parasite_dump_creds *args) { int ret, i, j; struct cap_data data[_LINUX_CAPABILITY_U32S_3]; - struct cap_header hdr = {_LINUX_CAPABILITY_VERSION_3, 0}; + struct cap_header hdr = { _LINUX_CAPABILITY_VERSION_3, 0 }; ret = sys_capget(&hdr, data); if (ret < 0) { @@ -254,8 +251,7 @@ static int dump_creds(struct parasite_dump_creds *args) break; ret = sys_prctl(PR_CAPBSET_READ, j + i * 32, 0, 0, 0); if (ret < 0) { - pr_err("Unable to read capability %d: %d\n", - j + i * 32, ret); + pr_err("Unable to read capability %d: %d\n", j + i * 32, ret); return -1; } if (ret) @@ -280,8 +276,7 @@ static int dump_creds(struct parasite_dump_creds *args) goto grps_err; if (ret != args->ngroups) { - pr_err("Groups changed on the fly %d -> %d\n", - args->ngroups, ret); + pr_err("Groups changed on the fly %d -> %d\n", args->ngroups, ret); return -1; } @@ -357,10 +352,10 @@ static int fill_fds_fown(int fd, struct fd_opts *p) return -1; } - p->fown.uid = v[0]; - p->fown.euid = v[1]; + p->fown.uid = v[0]; + p->fown.euid = v[1]; p->fown.pid_type = owner_ex.type; - p->fown.pid = owner_ex.pid; + p->fown.pid = owner_ex.pid; return 0; } @@ -404,8 +399,7 @@ static int drain_fds(struct parasite_drain_fd *args) return ret; tsock = parasite_get_rpc_sock(); - ret = send_fds(tsock, NULL, 0, - args->fds, args->nr_fds, opts, sizeof(struct fd_opts)); + ret = send_fds(tsock, NULL, 0, args->fds, args->nr_fds, opts, sizeof(struct fd_opts)); if (ret) pr_err("send_fds failed (%d)\n", ret); @@ -506,9 +500,9 @@ static inline int tty_ioctl(int fd, int cmd, int *arg) * as libaio does the same. */ -#define AIO_RING_MAGIC 0xa10a10a1 -#define AIO_RING_COMPAT_FEATURES 1 -#define AIO_RING_INCOMPAT_FEATURES 0 +#define AIO_RING_MAGIC 0xa10a10a1 +#define AIO_RING_COMPAT_FEATURES 1 +#define AIO_RING_INCOMPAT_FEATURES 0 static int sane_ring(struct parasite_aio *aio) { @@ -517,11 +511,9 @@ static int sane_ring(struct parasite_aio *aio) nr = (aio->size - sizeof(struct aio_ring)) / sizeof(struct io_event); - return ring->magic == AIO_RING_MAGIC && - ring->compat_features == AIO_RING_COMPAT_FEATURES && - ring->incompat_features == AIO_RING_INCOMPAT_FEATURES && - ring->header_length == sizeof(struct aio_ring) && - ring->nr == nr; + return ring->magic == AIO_RING_MAGIC && ring->compat_features == AIO_RING_COMPAT_FEATURES && + ring->incompat_features == AIO_RING_INCOMPAT_FEATURES && + ring->header_length == sizeof(struct aio_ring) && ring->nr == nr; } static int parasite_check_aios(struct parasite_check_aios_args *args) @@ -553,15 +545,15 @@ static int parasite_dump_tty(struct parasite_tty_args *args) int ret; #ifndef TIOCGPKT -# define TIOCGPKT _IOR('T', 0x38, int) +#define TIOCGPKT _IOR('T', 0x38, int) #endif #ifndef TIOCGPTLCK -# define TIOCGPTLCK _IOR('T', 0x39, int) +#define TIOCGPTLCK _IOR('T', 0x39, int) #endif #ifndef TIOCGEXCL -# define TIOCGEXCL _IOR('T', 0x40, int) +#define TIOCGEXCL _IOR('T', 0x40, int) #endif args->sid = 0; @@ -570,26 +562,26 @@ static int parasite_dump_tty(struct parasite_tty_args *args) args->st_lock = 0; args->st_excl = 0; -#define __tty_ioctl(cmd, arg) \ - do { \ - ret = tty_ioctl(args->fd, cmd, &arg); \ - if (ret < 0) { \ - if (ret == -ENOTTY) \ - arg = 0; \ - else if (ret == -EIO) \ - goto err_io; \ - else \ - goto err; \ - } \ +#define __tty_ioctl(cmd, arg) \ + do { \ + ret = tty_ioctl(args->fd, cmd, &arg); \ + if (ret < 0) { \ + if (ret == -ENOTTY) \ + arg = 0; \ + else if (ret == -EIO) \ + goto err_io; \ + else \ + goto err; \ + } \ } while (0) __tty_ioctl(TIOCGSID, args->sid); __tty_ioctl(TIOCGPGRP, args->pgrp); - __tty_ioctl(TIOCGEXCL, args->st_excl); + __tty_ioctl(TIOCGEXCL, args->st_excl); if (args->type == TTY_TYPE__PTY) { - __tty_ioctl(TIOCGPKT, args->st_pckt); - __tty_ioctl(TIOCGPTLCK, args->st_lock); + __tty_ioctl(TIOCGPKT, args->st_pckt); + __tty_ioctl(TIOCGPTLCK, args->st_lock); } args->hangup = false; @@ -620,15 +612,15 @@ static int parasite_check_vdso_mark(struct parasite_vdso_vma_entry *args) pr_err("vdso: Mark version mismatch!\n"); return -EINVAL; } - args->is_marked = 1; - args->orig_vdso_addr = m->orig_vdso_addr; - args->orig_vvar_addr = m->orig_vvar_addr; - args->rt_vvar_addr = m->rt_vvar_addr; + args->is_marked = 1; + args->orig_vdso_addr = m->orig_vdso_addr; + args->orig_vvar_addr = m->orig_vvar_addr; + args->rt_vvar_addr = m->rt_vvar_addr; } else { - args->is_marked = 0; - args->orig_vdso_addr = VDSO_BAD_ADDR; - args->orig_vvar_addr = VVAR_BAD_ADDR; - args->rt_vvar_addr = VVAR_BAD_ADDR; + args->is_marked = 0; + args->orig_vdso_addr = VDSO_BAD_ADDR; + args->orig_vvar_addr = VVAR_BAD_ADDR; + args->rt_vvar_addr = VVAR_BAD_ADDR; if (args->try_fill_symtable) { struct vdso_symtable t; diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c index de0cdb8f5..4304691bb 100644 --- a/criu/pie/restorer.c +++ b/criu/pie/restorer.c @@ -59,20 +59,19 @@ #endif #ifndef FALLOC_FL_KEEP_SIZE -#define FALLOC_FL_KEEP_SIZE 0x01 +#define FALLOC_FL_KEEP_SIZE 0x01 #endif #ifndef FALLOC_FL_PUNCH_HOLE -#define FALLOC_FL_PUNCH_HOLE 0x02 +#define FALLOC_FL_PUNCH_HOLE 0x02 #endif - -#define sys_prctl_safe(opcode, val1, val2, val3) \ - ({ \ - long __ret = sys_prctl(opcode, val1, val2, val3, 0); \ - if (__ret) \ - pr_err("prctl failed @%d with %ld\n", __LINE__, __ret);\ - __ret; \ +#define sys_prctl_safe(opcode, val1, val2, val3) \ + ({ \ + long __ret = sys_prctl(opcode, val1, val2, val3, 0); \ + if (__ret) \ + pr_err("prctl failed @%d with %ld\n", __LINE__, __ret); \ + __ret; \ }) static struct task_entries *task_entries_local; @@ -116,8 +115,7 @@ void parasite_cleanup(void) { } -extern void cr_restore_rt (void) asm ("__cr_restore_rt") - __attribute__ ((visibility ("hidden"))); +extern void cr_restore_rt(void) asm("__cr_restore_rt") __attribute__((visibility("hidden"))); static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) { @@ -186,8 +184,7 @@ static int lsm_set_label(char *label, char *type, int procfd) return 0; } -static int restore_creds(struct thread_creds_args *args, int procfd, - int lsm_type) +static int restore_creds(struct thread_creds_args *args, int procfd, int lsm_type) { CredsEntry *ce = &args->creds; int b, i, ret; @@ -275,8 +272,7 @@ static int restore_creds(struct thread_creds_args *args, int procfd, continue; ret = sys_prctl(PR_CAPBSET_DROP, i + b * 32, 0, 0, 0); if (ret) { - pr_err("Unable to drop capability %d: %d\n", - i + b * 32, ret); + pr_err("Unable to drop capability %d: %d\n", i + b * 32, ret); return -1; } } @@ -388,8 +384,7 @@ static void restore_sched_info(struct rst_sched_param *p) { struct sched_param parm; - pr_info("Restoring scheduler params %d.%d.%d\n", - p->policy, p->nice, p->prio); + pr_info("Restoring scheduler params %d.%d.%d\n", p->policy, p->nice, p->prio); sys_setpriority(PRIO_PROCESS, 0, p->nice); parm.sched_priority = p->prio; @@ -420,11 +415,9 @@ static int restore_signals(siginfo_t *ptr, int nr, bool group) if (group) ret = sys_rt_sigqueueinfo(sys_getpid(), info->si_signo, info); else - ret = sys_rt_tgsigqueueinfo(sys_getpid(), - sys_gettid(), info->si_signo, info); + ret = sys_rt_tgsigqueueinfo(sys_getpid(), sys_gettid(), info->si_signo, info); if (ret) { - pr_err("Unable to send siginfo %d %x with code %d\n", - info->si_signo, info->si_code, ret); + pr_err("Unable to send siginfo %d %x with code %d\n", info->si_signo, info->si_code, ret); return -1; } } @@ -441,24 +434,22 @@ static int restore_seccomp_filter(pid_t tid, struct thread_restore_args *args) for (i = 0; i < args->seccomp_filters_n; i++) { struct thread_seccomp_filter *filter = &args->seccomp_filters[i]; - pr_debug("seccomp: Restoring mode %d flags %x on tid %d filter %d\n", - SECCOMP_SET_MODE_FILTER, (filter->flags | flags), tid, (int)i); + pr_debug("seccomp: Restoring mode %d flags %x on tid %d filter %d\n", SECCOMP_SET_MODE_FILTER, + (filter->flags | flags), tid, (int)i); ret = sys_seccomp(SECCOMP_SET_MODE_FILTER, filter->flags | flags, (void *)&filter->sock_fprog); if (ret < 0) { if (ret == -ENOSYS) { pr_debug("seccomp: sys_seccomp is not supported in kernel, " "switching to prctl interface\n"); - ret = sys_prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, - (long)(void *)&filter->sock_fprog, 0, 0); + ret = sys_prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long)(void *)&filter->sock_fprog, + 0, 0); if (ret) { - pr_err("seccomp: PR_SET_SECCOMP returned %d on tid %d\n", - ret, tid); + pr_err("seccomp: PR_SET_SECCOMP returned %d on tid %d\n", ret, tid); return -1; } } else { - pr_err("seccomp: SECCOMP_SET_MODE_FILTER returned %d on tid %d\n", - ret, tid); + pr_err("seccomp: SECCOMP_SET_MODE_FILTER returned %d on tid %d\n", ret, tid); return -1; } } @@ -497,23 +488,20 @@ static int restore_seccomp(struct thread_restore_args *args) std_log_set_gettimeofday(NULL); ret = sys_prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT, 0, 0, 0); if (ret < 0) { - pr_err("seccomp: SECCOMP_MODE_STRICT returned %d on tid %d\n", - ret, tid); + pr_err("seccomp: SECCOMP_MODE_STRICT returned %d on tid %d\n", ret, tid); } break; case SECCOMP_MODE_FILTER: ret = restore_seccomp_filter(tid, args); break; default: - pr_err("seccomp: Unknown seccomp mode %d on tid %d\n", - args->seccomp_mode, tid); + pr_err("seccomp: Unknown seccomp mode %d on tid %d\n", args->seccomp_mode, tid); ret = -1; break; } if (!ret) { - pr_debug("seccomp: Restored mode %d on tid %d\n", - args->seccomp_mode, tid); + pr_debug("seccomp: Restored mode %d on tid %d\n", args->seccomp_mode, tid); } return ret; @@ -564,8 +552,7 @@ static int restore_thread_common(struct thread_restore_args *args) return 0; } -static void noinline rst_sigreturn(unsigned long new_sp, - struct rt_sigframe *sigframe) +static void noinline rst_sigreturn(unsigned long new_sp, struct rt_sigframe *sigframe) { ARCH_RT_SIGRETURN(new_sp, sigframe); } @@ -600,7 +587,7 @@ long __export_restore_thread(struct thread_restore_args *args) if (restore_thread_common(args)) goto core_restore_end; - ret = sys_prctl(PR_SET_NAME, (unsigned long) &args->comm, 0, 0, 0); + ret = sys_prctl(PR_SET_NAME, (unsigned long)&args->comm, 0, 0, 0); if (ret) { pr_err("Unable to set a thread name: %d\n", ret); goto core_restore_end; @@ -622,8 +609,7 @@ long __export_restore_thread(struct thread_restore_args *args) if (restore_seccomp(args)) BUG(); - ret = restore_creds(args->creds_args, args->ta->proc_fd, - args->ta->lsm_type); + ret = restore_creds(args->creds_args, args->ta->proc_fd, args->ta->lsm_type); ret = ret || restore_dumpable_flag(&args->ta->mm); ret = ret || restore_pdeath_sig(args); if (ret) @@ -657,8 +643,7 @@ static long restore_self_exe_late(struct task_restore_args *args) } #ifndef ARCH_HAS_SHMAT_HOOK -unsigned long arch_shmat(int shmid, void *shmaddr, - int shmflg, unsigned long size) +unsigned long arch_shmat(int shmid, void *shmaddr, int shmflg, unsigned long size) { return sys_shmat(shmid, shmaddr, shmflg); } @@ -666,8 +651,8 @@ unsigned long arch_shmat(int shmid, void *shmaddr, static unsigned long restore_mapping(VmaEntry *vma_entry) { - int prot = vma_entry->prot; - int flags = vma_entry->flags | MAP_FIXED; + int prot = vma_entry->prot; + int flags = vma_entry->flags | MAP_FIXED; unsigned long addr; if (vma_entry_is(vma_entry, VMA_AREA_SYSVIPC)) { @@ -687,7 +672,7 @@ static unsigned long restore_mapping(VmaEntry *vma_entry) } else att_flags = SHM_RDONLY; - pr_info("Attach SYSV shmem %d at %"PRIx64"\n", (int)vma_entry->fd, vma_entry->start); + pr_info("Attach SYSV shmem %d at %" PRIx64 "\n", (int)vma_entry->fd, vma_entry->start); return arch_shmat(vma_entry->fd, shmaddr, att_flags, shmsize); } @@ -705,8 +690,7 @@ static unsigned long restore_mapping(VmaEntry *vma_entry) flags |= MAP_ANONYMOUS; /* A mapping of file with MAP_SHARED is up to date */ - if ((vma_entry->fd == -1 || !(vma_entry->flags & MAP_SHARED)) && - !(vma_entry->status & VMA_NO_PROT_WRITE)) + if ((vma_entry->fd == -1 || !(vma_entry->flags & MAP_SHARED)) && !(vma_entry->status & VMA_NO_PROT_WRITE)) prot |= PROT_WRITE; /* TODO: Drop MAP_LOCKED bit and restore it after reading memory. @@ -717,22 +701,17 @@ static unsigned long restore_mapping(VmaEntry *vma_entry) * that mechanism as it causes the process to be charged for memory * immediately upon mmap, not later upon preadv(). */ - pr_debug("\tmmap(%"PRIx64" -> %"PRIx64", %x %x %d)\n", - vma_entry->start, vma_entry->end, - prot, flags, (int)vma_entry->fd); + pr_debug("\tmmap(%" PRIx64 " -> %" PRIx64 ", %x %x %d)\n", vma_entry->start, vma_entry->end, prot, flags, + (int)vma_entry->fd); /* * Should map memory here. Note we map them as * writable since we're going to restore page * contents. */ - addr = sys_mmap(decode_pointer(vma_entry->start), - vma_entry_len(vma_entry), - prot, flags, - vma_entry->fd, + addr = sys_mmap(decode_pointer(vma_entry->start), vma_entry_len(vma_entry), prot, flags, vma_entry->fd, vma_entry->pgoff); - if ((vma_entry->fd != -1) && - (vma_entry->status & VMA_CLOSE)) + if ((vma_entry->fd != -1) && (vma_entry->status & VMA_CLOSE)) sys_close(vma_entry->fd); return addr; @@ -764,10 +743,9 @@ static int restore_aio_ring(struct rst_aio_ring *raio) new = (struct aio_ring *)ctx; i = (raio->len - sizeof(struct aio_ring)) / sizeof(struct io_event); - if (tail >= ring->nr || head >= ring->nr || ring->nr != i || - new->nr != ring->nr) { - pr_err("wrong aio: tail=%x head=%x req=%x old_nr=%x new_nr=%x expect=%x\n", - tail, head, raio->nr_req, ring->nr, new->nr, i); + if (tail >= ring->nr || head >= ring->nr || ring->nr != i || new->nr != ring->nr) { + pr_err("wrong aio: tail=%x head=%x req=%x old_nr=%x new_nr=%x expect=%x\n", tail, head, raio->nr_req, + ring->nr, new->nr, i); return -1; } @@ -794,15 +772,14 @@ static int restore_aio_ring(struct rst_aio_ring *raio) count = ring->nr + tail; else count = tail; - maxr = min_t(unsigned, count, ring->nr-1); + maxr = min_t(unsigned, count, ring->nr - 1); /* * Since we only interested in moving the tail, the requests * may be any. We submit count identical requests. */ size = sizeof(struct iocb) + maxr * sizeof(struct iocb *); - iocb = (void *)sys_mmap(NULL, size, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + iocb = (void *)sys_mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); iocbp = (void *)iocb + sizeof(struct iocb); if (IS_ERR(iocb)) { @@ -827,7 +804,7 @@ static int restore_aio_ring(struct rst_aio_ring *raio) } i += ret; - /* + /* * We may submit less than requested, because of too big * count OR behaviour of get_reqs_available(), which * takes available requests only if their number is @@ -859,9 +836,7 @@ populate: * Also, this unmaps temporary anonymous area on raio->addr. */ - ctx = sys_mremap(ctx, raio->len, raio->len, - MREMAP_FIXED | MREMAP_MAYMOVE, - raio->addr); + ctx = sys_mremap(ctx, raio->len, raio->len, MREMAP_FIXED | MREMAP_MAYMOVE, raio->addr); if (ctx != raio->addr) { pr_err("Ring remap failed with %ld\n", ctx); return -1; @@ -909,7 +884,7 @@ static int enable_uffd(int uffd, unsigned long addr, unsigned long len) pr_info("lazy-pages: register: %lx, len %lx\n", addr, len); - rc = sys_ioctl(uffd, UFFDIO_REGISTER, (unsigned long) &uffdio_register); + rc = sys_ioctl(uffd, UFFDIO_REGISTER, (unsigned long)&uffdio_register); if (rc != 0) { pr_err("lazy-pages: register %lx failed: rc:%d, \n", addr, rc); return -1; @@ -924,7 +899,6 @@ static int enable_uffd(int uffd, unsigned long addr, unsigned long len) return 0; } - static int vma_remap(VmaEntry *vma_entry, int uffd) { unsigned long src = vma_premmaped_start(vma_entry); @@ -970,23 +944,20 @@ static int vma_remap(VmaEntry *vma_entry, int uffd) unsigned long addr; /* Map guard page (step 2) */ - tmp = sys_mmap((void *) guard, PAGE_SIZE, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + tmp = sys_mmap((void *)guard, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (tmp != guard) { pr_err("Unable to map a guard page %lx (%lx)\n", guard, tmp); return -1; } /* Move src to non-overlapping place (step 3) */ - addr = sys_mmap(NULL, len, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - if (addr == (unsigned long) MAP_FAILED) { + addr = sys_mmap(NULL, len, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + if (addr == (unsigned long)MAP_FAILED) { pr_err("Unable to reserve memory (%lx)\n", addr); return -1; } - tmp = sys_mremap(src, len, len, - MREMAP_MAYMOVE | MREMAP_FIXED, addr); + tmp = sys_mremap(src, len, len, MREMAP_MAYMOVE | MREMAP_FIXED, addr); if (tmp != addr) { pr_err("Unable to remap %lx -> %lx (%lx)\n", src, addr, tmp); return -1; @@ -1042,14 +1013,13 @@ static int timerfd_arm(struct task_restore_args *args) t->val.it_value.tv_sec += (time_t)ts.tv_sec; - pr_debug("Adjust id %#x it_value(%llu, %llu) -> it_value(%llu, %llu)\n", - t->id, (unsigned long long)ts.tv_sec, - (unsigned long long)ts.tv_nsec, + pr_debug("Adjust id %#x it_value(%llu, %llu) -> it_value(%llu, %llu)\n", t->id, + (unsigned long long)ts.tv_sec, (unsigned long long)ts.tv_nsec, (unsigned long long)t->val.it_value.tv_sec, (unsigned long long)t->val.it_value.tv_nsec); } - ret = sys_timerfd_settime(t->fd, t->settime_flags, &t->val, NULL); + ret = sys_timerfd_settime(t->fd, t->settime_flags, &t->val, NULL); if (t->ticks) ret |= sys_ioctl(t->fd, TFD_IOC_SET_TICKS, (unsigned long)&t->ticks); if (ret) { @@ -1143,9 +1113,8 @@ void __export_unmap(void) * [ 1st end -- 2nd start ] * [ 2nd start -- task_size ] */ -static int unmap_old_vmas(void *premmapped_addr, unsigned long premmapped_len, - void *bootstrap_start, unsigned long bootstrap_len, - unsigned long task_size) +static int unmap_old_vmas(void *premmapped_addr, unsigned long premmapped_len, void *bootstrap_start, + unsigned long bootstrap_len, unsigned long task_size) { unsigned long s1, s2; void *p1, *p2; @@ -1177,8 +1146,7 @@ static int unmap_old_vmas(void *premmapped_addr, unsigned long premmapped_len, ret = sys_munmap(p2 + s2, task_size - (unsigned long)(p2 + s2)); if (ret) { - pr_err("Unable to unmap (%p-%p): %d\n", - p2 + s2, (void *)task_size, ret); + pr_err("Unable to unmap (%p-%p): %d\n", p2 + s2, (void *)task_size, ret); return -1; } @@ -1199,8 +1167,7 @@ static int wait_helpers(struct task_restore_args *task_args) continue; } if (!WIFEXITED(status) || WEXITSTATUS(status)) { - pr_err("%d exited with non-zero code (%d,%d)\n", pid, - WEXITSTATUS(status), WTERMSIG(status)); + pr_err("%d exited with non-zero code (%d,%d)\n", pid, WEXITSTATUS(status), WTERMSIG(status)); return -1; } } @@ -1223,8 +1190,7 @@ static int wait_zombies(struct task_restore_args *task_args) * Let's wait when someone complete this stage * and try again. */ - futex_wait_while_eq(&task_entries_local->nr_in_progress, - nr_in_progress); + futex_wait_while_eq(&task_entries_local->nr_in_progress, nr_in_progress); i--; continue; } @@ -1232,8 +1198,7 @@ static int wait_zombies(struct task_restore_args *task_args) pr_err("Wait on %d zombie failed: %d\n", task_args->zombies[i], ret); return -1; } - pr_debug("%ld: Collect a zombie with pid %d\n", - sys_getpid(), task_args->zombies[i]); + pr_debug("%ld: Collect a zombie with pid %d\n", sys_getpid(), task_args->zombies[i]); } return 0; @@ -1319,8 +1284,8 @@ static int map_vdso(struct task_restore_args *args, bool compatible) static int fd_poll(int inotify_fd) { - struct pollfd pfd = {inotify_fd, POLLIN, 0}; - struct timespec tmo = {0, 0}; + struct pollfd pfd = { inotify_fd, POLLIN, 0 }; + struct timespec tmo = { 0, 0 }; return sys_ppoll(&pfd, 1, &tmo, NULL, sizeof(sigset_t)); } @@ -1341,7 +1306,7 @@ static int cleanup_inotify_events(int inotify_fd) int ret; /* Limit buf to be lesser than half of restorer's stack */ - BUILD_BUG_ON(ARRAY_SIZE(buf) >= RESTORE_STACK_SIZE/2); + BUILD_BUG_ON(ARRAY_SIZE(buf) >= RESTORE_STACK_SIZE / 2); while (1) { ret = fd_poll(inotify_fd); @@ -1408,9 +1373,9 @@ long __export_restore_task(struct task_restore_args *args) bool has_vdso_proxy; bootstrap_start = args->bootstrap_start; - bootstrap_len = args->bootstrap_len; + bootstrap_len = args->bootstrap_len; - vdso_rt_size = args->vdso_rt_size; + vdso_rt_size = args->vdso_rt_size; fi_strategy = args->fault_strategy; @@ -1467,13 +1432,12 @@ long __export_restore_task(struct task_restore_args *args) } if (!can_restore_vdso(args)) goto core_restore_end; - if (vdso_do_park(&args->vdso_maps_rt, - args->vdso_rt_parked_at, vdso_rt_size)) + if (vdso_do_park(&args->vdso_maps_rt, args->vdso_rt_parked_at, vdso_rt_size)) goto core_restore_end; } - if (unmap_old_vmas((void *)args->premmapped_addr, args->premmapped_len, - bootstrap_start, bootstrap_len, args->task_size)) + if (unmap_old_vmas((void *)args->premmapped_addr, args->premmapped_len, bootstrap_start, bootstrap_len, + args->task_size)) goto core_restore_end; /* Map vdso that wasn't parked */ @@ -1542,8 +1506,7 @@ long __export_restore_task(struct task_restore_args *args) for (i = 0; i < args->vmas_n; i++) { vma_entry = args->vmas + i; - if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR) && - !vma_entry_is(vma_entry, VMA_AREA_AIORING)) + if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR) && !vma_entry_is(vma_entry, VMA_AREA_AIORING)) continue; if (vma_entry_is(vma_entry, VMA_PREMMAPED)) @@ -1552,7 +1515,7 @@ long __export_restore_task(struct task_restore_args *args) va = restore_mapping(vma_entry); if (va != vma_entry->start) { - pr_err("Can't restore %"PRIx64" mapping with %lx\n", vma_entry->start, va); + pr_err("Can't restore %" PRIx64 " mapping with %lx\n", vma_entry->start, va); goto core_restore_end; } } @@ -1568,9 +1531,7 @@ long __export_restore_task(struct task_restore_args *args) ssize_t r; while (nr) { - pr_debug("Preadv %lx:%d... (%d iovs)\n", - (unsigned long)iovs->iov_base, - (int)iovs->iov_len, nr); + pr_debug("Preadv %lx:%d... (%d iovs)\n", (unsigned long)iovs->iov_base, (int)iovs->iov_len, nr); r = sys_preadv(args->vma_ios_fd, iovs, nr, rio->off); if (r < 0) { pr_err("Can't read pages data (%d)\n", (int)r); @@ -1581,8 +1542,8 @@ long __export_restore_task(struct task_restore_args *args) /* If the file is open for writing, then it means we should punch holes * in it. */ if (r > 0 && args->auto_dedup) { - int fr = sys_fallocate(args->vma_ios_fd, FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE, - rio->off, r); + int fr = sys_fallocate(args->vma_ios_fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, + rio->off, r); if (fr < 0) { pr_debug("Failed to punch holes with fallocate: %d\n", fr); } @@ -1613,9 +1574,8 @@ long __export_restore_task(struct task_restore_args *args) /* * Proxify vDSO. */ - if (vdso_proxify(&args->vdso_maps_rt, &has_vdso_proxy, - args->vmas, args->vmas_n, args->compatible_mode, - fault_injected(FI_VDSO_TRAMPOLINES))) + if (vdso_proxify(&args->vdso_maps_rt, &has_vdso_proxy, args->vmas, args->vmas_n, args->compatible_mode, + fault_injected(FI_VDSO_TRAMPOLINES))) goto core_restore_end; /* unmap rt-vdso with restorer blob after restore's finished */ @@ -1632,13 +1592,10 @@ long __export_restore_task(struct task_restore_args *args) if (!(vma_entry_is(vma_entry, VMA_AREA_REGULAR))) continue; - if ((vma_entry->prot & PROT_WRITE) || - (vma_entry->status & VMA_NO_PROT_WRITE)) + if ((vma_entry->prot & PROT_WRITE) || (vma_entry->status & VMA_NO_PROT_WRITE)) continue; - sys_mprotect(decode_pointer(vma_entry->start), - vma_entry_len(vma_entry), - vma_entry->prot); + sys_mprotect(decode_pointer(vma_entry->start), vma_entry_len(vma_entry), vma_entry->prot); } /* @@ -1662,15 +1619,11 @@ long __export_restore_task(struct task_restore_args *args) for (m = 0; m < sizeof(vma_entry->madv) * 8; m++) { if (vma_entry->madv & (1ul << m)) { - ret = sys_madvise(vma_entry->start, - vma_entry_len(vma_entry), - m); + ret = sys_madvise(vma_entry->start, vma_entry_len(vma_entry), m); if (ret) { - pr_err("madvise(%"PRIx64", %"PRIu64", %ld) " + pr_err("madvise(%" PRIx64 ", %" PRIu64 ", %ld) " "failed with %ld\n", - vma_entry->start, - vma_entry_len(vma_entry), - m, ret); + vma_entry->start, vma_entry_len(vma_entry), m, ret); goto core_restore_end; } } @@ -1689,36 +1642,36 @@ long __export_restore_task(struct task_restore_args *args) * more widespread once kernel get deployed over the world. * Thus lets be opportunistic and use new interface as a try. */ - prctl_map = (struct prctl_mm_map) { - .start_code = args->mm.mm_start_code, - .end_code = args->mm.mm_end_code, - .start_data = args->mm.mm_start_data, - .end_data = args->mm.mm_end_data, - .start_stack = args->mm.mm_start_stack, - .start_brk = args->mm.mm_start_brk, - .brk = args->mm.mm_brk, - .arg_start = args->mm.mm_arg_start, - .arg_end = args->mm.mm_arg_end, - .env_start = args->mm.mm_env_start, - .env_end = args->mm.mm_env_end, - .auxv = (void *)args->mm_saved_auxv, - .auxv_size = args->mm_saved_auxv_size, - .exe_fd = args->fd_exe_link, + prctl_map = (struct prctl_mm_map){ + .start_code = args->mm.mm_start_code, + .end_code = args->mm.mm_end_code, + .start_data = args->mm.mm_start_data, + .end_data = args->mm.mm_end_data, + .start_stack = args->mm.mm_start_stack, + .start_brk = args->mm.mm_start_brk, + .brk = args->mm.mm_brk, + .arg_start = args->mm.mm_arg_start, + .arg_end = args->mm.mm_arg_end, + .env_start = args->mm.mm_env_start, + .env_end = args->mm.mm_env_end, + .auxv = (void *)args->mm_saved_auxv, + .auxv_size = args->mm_saved_auxv_size, + .exe_fd = args->fd_exe_link, }; ret = sys_prctl(PR_SET_MM, PR_SET_MM_MAP, (long)&prctl_map, sizeof(prctl_map), 0); if (ret == -EINVAL) { - ret = sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_CODE, (long)args->mm.mm_start_code, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_END_CODE, (long)args->mm.mm_end_code, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_DATA, (long)args->mm.mm_start_data, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_END_DATA, (long)args->mm.mm_end_data, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_STACK, (long)args->mm.mm_start_stack, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_BRK, (long)args->mm.mm_start_brk, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_BRK, (long)args->mm.mm_brk, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ARG_START, (long)args->mm.mm_arg_start, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ARG_END, (long)args->mm.mm_arg_end, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ENV_START, (long)args->mm.mm_env_start, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ENV_END, (long)args->mm.mm_env_end, 0); - ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_AUXV, (long)args->mm_saved_auxv, args->mm_saved_auxv_size); + ret = sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_CODE, (long)args->mm.mm_start_code, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_END_CODE, (long)args->mm.mm_end_code, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_DATA, (long)args->mm.mm_start_data, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_END_DATA, (long)args->mm.mm_end_data, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_STACK, (long)args->mm.mm_start_stack, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_BRK, (long)args->mm.mm_start_brk, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_BRK, (long)args->mm.mm_brk, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ARG_START, (long)args->mm.mm_arg_start, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ARG_END, (long)args->mm.mm_arg_end, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ENV_START, (long)args->mm.mm_env_start, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ENV_END, (long)args->mm.mm_env_end, 0); + ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_AUXV, (long)args->mm_saved_auxv, args->mm_saved_auxv_size); /* * Because of requirements applied from kernel side @@ -1739,8 +1692,7 @@ long __export_restore_task(struct task_restore_args *args) /* SELinux (1) process context needs to be set before creating threads. */ if (args->lsm_type == LSMTYPE__SELINUX) { /* Only for SELinux */ - if (lsm_set_label(args->t->creds_args->lsm_profile, - "current", args->proc_fd) < 0) + if (lsm_set_label(args->t->creds_args->lsm_profile, "current", args->proc_fd) < 0) goto core_restore_end; } @@ -1775,8 +1727,7 @@ long __export_restore_task(struct task_restore_args *args) if (args->nr_threads > 1) { struct thread_restore_args *thread_args = args->thread_args; - long clone_flags = CLONE_VM | CLONE_FILES | CLONE_SIGHAND | - CLONE_THREAD | CLONE_SYSVSEM | CLONE_FS; + long clone_flags = CLONE_VM | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM | CLONE_FS; long last_pid_len; pid_t thread_pid; long parent_tid; @@ -1789,7 +1740,6 @@ long __export_restore_task(struct task_restore_args *args) pr_err("can't open last pid fd %d\n", fd); goto core_restore_end; } - } mutex_lock(&task_entries_local->last_pid_mutex); @@ -1813,9 +1763,11 @@ long __export_restore_task(struct task_restore_args *args) c_args.child_tid = ptr_to_u64(&thread_args[i].pid); c_args.parent_tid = ptr_to_u64(&parent_tid); pr_debug("Using clone3 to restore the process\n"); - RUN_CLONE3_RESTORE_FN(ret, c_args, sizeof(c_args), &thread_args[i], args->clone_restore_fn); + RUN_CLONE3_RESTORE_FN(ret, c_args, sizeof(c_args), &thread_args[i], + args->clone_restore_fn); } else { - last_pid_len = std_vprint_num(last_pid_buf, sizeof(last_pid_buf), thread_args[i].pid - 1, &s); + last_pid_len = + std_vprint_num(last_pid_buf, sizeof(last_pid_buf), thread_args[i].pid - 1, &s); sys_lseek(fd, 0, SEEK_SET); ret = sys_write(fd, s, last_pid_len); if (ret < 0) { @@ -1831,7 +1783,8 @@ long __export_restore_task(struct task_restore_args *args) * thread will run with own stack and we must not * have any additional instructions... oh, dear... */ - RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, thread_args, args->clone_restore_fn); + RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, thread_args, + args->clone_restore_fn); } if (ret != thread_args[i].pid) { pr_err("Unable to create a thread: %ld\n", ret); @@ -1879,8 +1832,7 @@ long __export_restore_task(struct task_restore_args *args) goto core_restore_end; if (!args->compatible_mode) { - ret = sys_sigaction(SIGCHLD, &args->sigchld_act, - NULL, sizeof(k_rtsigset_t)); + ret = sys_sigaction(SIGCHLD, &args->sigchld_act, NULL, sizeof(k_rtsigset_t)); } else { void *stack = alloc_compat_syscall_stack(); @@ -1888,8 +1840,7 @@ long __export_restore_task(struct task_restore_args *args) pr_err("Failed to allocate 32-bit stack for sigaction\n"); goto core_restore_end; } - ret = arch_compat_rt_sigaction(stack, SIGCHLD, - (void*)&args->sigchld_act); + ret = arch_compat_rt_sigaction(stack, SIGCHLD, (void *)&args->sigchld_act); free_compat_syscall_stack(stack); } if (ret) { @@ -1921,8 +1872,7 @@ long __export_restore_task(struct task_restore_args *args) * turning off TCP repair is CAP_SYS_NED_ADMIN protected, * thus restore* creds _after_ all of the above. */ - ret = restore_creds(args->t->creds_args, args->proc_fd, - args->lsm_type); + ret = restore_creds(args->t->creds_args, args->proc_fd, args->lsm_type); ret = ret || restore_dumpable_flag(&args->mm); ret = ret || restore_pdeath_sig(args->t); ret = ret || restore_child_subreaper(args->child_subreaper); @@ -1945,9 +1895,7 @@ long __export_restore_task(struct task_restore_args *args) * code below doesn't fail due to bad timing values. */ -#define itimer_armed(args, i) \ - (args->itimers[i].it_interval.tv_sec || \ - args->itimers[i].it_interval.tv_usec) +#define itimer_armed(args, i) (args->itimers[i].it_interval.tv_sec || args->itimers[i].it_interval.tv_usec) if (itimer_armed(args, 0)) sys_setitimer(ITIMER_REAL, &args->itimers[0], NULL); diff --git a/criu/pie/util-vdso.c b/criu/pie/util-vdso.c index 5e1f128e8..f1e3239ff 100644 --- a/criu/pie/util-vdso.c +++ b/criu/pie/util-vdso.c @@ -17,14 +17,14 @@ #include "common/bug.h" #ifdef CR_NOGLIBC -# include <compel/plugins/std/string.h> +#include <compel/plugins/std/string.h> #else -# include <string.h> -# define std_strncmp strncmp +#include <string.h> +#define std_strncmp strncmp #endif #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " @@ -37,18 +37,15 @@ static bool __ptr_oob(uintptr_t ptr, uintptr_t start, size_t size) } /* Check if pointed structure's end is out-of-bound */ -static bool __ptr_struct_end_oob(uintptr_t ptr, size_t struct_size, - uintptr_t start, size_t size) +static bool __ptr_struct_end_oob(uintptr_t ptr, size_t struct_size, uintptr_t start, size_t size) { return __ptr_oob(ptr + struct_size - 1, start, size); } /* Check if pointed structure is out-of-bound */ -static bool __ptr_struct_oob(uintptr_t ptr, size_t struct_size, - uintptr_t start, size_t size) +static bool __ptr_struct_oob(uintptr_t ptr, size_t struct_size, uintptr_t start, size_t size) { - return __ptr_oob(ptr, start, size) || - __ptr_struct_end_oob(ptr, struct_size, start, size); + return __ptr_oob(ptr, start, size) || __ptr_struct_end_oob(ptr, struct_size, start, size); } /* @@ -81,13 +78,11 @@ static int has_elf_identity(Ehdr_t *ehdr) */ #if defined(CONFIG_VDSO_32) static const char elf_ident[] = { - 0x7f, 0x45, 0x4c, 0x46, 0x01, BORD, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0x45, 0x4c, 0x46, 0x01, BORD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #else static const char elf_ident[] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, BORD, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0x45, 0x4c, 0x46, 0x02, BORD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #endif @@ -101,8 +96,7 @@ static int has_elf_identity(Ehdr_t *ehdr) return true; } -static int parse_elf_phdr(uintptr_t mem, size_t size, - Phdr_t **dynamic, Phdr_t **load) +static int parse_elf_phdr(uintptr_t mem, size_t size, Phdr_t **dynamic, Phdr_t **load) { Ehdr_t *ehdr = (void *)mem; uintptr_t addr; @@ -157,8 +151,8 @@ err_oob: * @dyn_symtab - address of the string table section * @dyn_hash - address of the symbol hash table */ -static int parse_elf_dynamic(uintptr_t mem, size_t size, Phdr_t *dynamic, - Dyn_t **dyn_strtab, Dyn_t **dyn_symtab, Dyn_t **dyn_hash) +static int parse_elf_dynamic(uintptr_t mem, size_t size, Phdr_t *dynamic, Dyn_t **dyn_strtab, Dyn_t **dyn_symtab, + Dyn_t **dyn_hash) { Dyn_t *dyn_syment = NULL; Dyn_t *dyn_strsz = NULL; @@ -170,8 +164,7 @@ static int parse_elf_dynamic(uintptr_t mem, size_t size, Phdr_t *dynamic, if (__ptr_oob(addr, mem, size)) goto err_oob; - for (i = 0; i < dynamic->p_filesz / sizeof(*d); - i++, addr += sizeof(Dyn_t)) { + for (i = 0; i < dynamic->p_filesz / sizeof(*d); i++, addr += sizeof(Dyn_t)) { if (__ptr_struct_end_oob(addr, sizeof(Dyn_t), mem, size)) goto err_oob; d = (void *)addr; @@ -215,15 +208,12 @@ typedef unsigned long Hash_t; typedef Word_t Hash_t; #endif -static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load, - struct vdso_symtable *t, uintptr_t dynsymbol_names, - Hash_t *hash, Dyn_t *dyn_symtab) +static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load, struct vdso_symtable *t, + uintptr_t dynsymbol_names, Hash_t *hash, Dyn_t *dyn_symtab) { ARCH_VDSO_SYMBOLS_LIST - const char *vdso_symbols[VDSO_SYMBOL_MAX] = { - ARCH_VDSO_SYMBOLS - }; + const char *vdso_symbols[VDSO_SYMBOL_MAX] = { ARCH_VDSO_SYMBOLS }; const size_t vdso_symbol_length = sizeof(t->symbols[0].name) - 1; Hash_t nbucket, nchain; @@ -237,11 +227,11 @@ static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load, bucket = &hash[2]; chain = &hash[nbucket + 2]; - pr_debug("nbucket %lx nchain %lx bucket %lx chain %lx\n", - (long)nbucket, (long)nchain, (unsigned long)bucket, (unsigned long)chain); + pr_debug("nbucket %lx nchain %lx bucket %lx chain %lx\n", (long)nbucket, (long)nchain, (unsigned long)bucket, + (unsigned long)chain); for (i = 0; i < VDSO_SYMBOL_MAX; i++) { - const char * symbol = vdso_symbols[i]; + const char *symbol = vdso_symbols[i]; k = elf_hash((const unsigned char *)symbol); for (j = bucket[k % nbucket]; j < nchain && j != STN_UNDEF; j = chain[j]) { @@ -250,13 +240,12 @@ static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load, addr = mem + dyn_symtab->d_un.d_ptr - load->p_vaddr; - addr += sizeof(Sym_t)*j; + addr += sizeof(Sym_t) * j; if (__ptr_struct_oob(addr, sizeof(Sym_t), mem, size)) continue; sym = (void *)addr; - if (ELF_ST_TYPE(sym->st_info) != STT_FUNC && - ELF_ST_BIND(sym->st_info) != STB_GLOBAL) + if (ELF_ST_TYPE(sym->st_info) != STT_FUNC && ELF_ST_BIND(sym->st_info) != STB_GLOBAL) continue; addr = dynsymbol_names + sym->st_name; @@ -307,8 +296,7 @@ int vdso_fill_symtable(uintptr_t mem, size_t size, struct vdso_symtable *t) * needed. Note that we're interested in a small set of tags. */ - ret = parse_elf_dynamic(mem, size, dynamic, - &dyn_strtab, &dyn_symtab, &dyn_hash); + ret = parse_elf_dynamic(mem, size, dynamic, &dyn_strtab, &dyn_symtab, &dyn_hash); if (ret < 0) return ret; @@ -330,4 +318,3 @@ err_oob: pr_err("Corrupted Elf symbols/hash\n"); return -EFAULT; } - diff --git a/criu/pie/util.c b/criu/pie/util.c index 4945483f6..e7a5a9f23 100644 --- a/criu/pie/util.c +++ b/criu/pie/util.c @@ -13,10 +13,10 @@ #include "util-pie.h" #ifdef CR_NOGLIBC -# include <compel/plugins/std/syscall.h> -# define __sys(foo) sys_##foo +#include <compel/plugins/std/syscall.h> +#define __sys(foo) sys_##foo #else -# define __sys(foo) foo +#define __sys(foo) foo #endif #ifdef CR_NOGLIBC diff --git a/criu/pipes.c b/criu/pipes.c index 5787fdc53..43ff06e3d 100644 --- a/criu/pipes.c +++ b/criu/pipes.c @@ -46,8 +46,7 @@ static int pipe_data_read(struct cr_img *img, struct pipe_data_rst *r) * anyway we don't increase memory consumption :) */ - r->data = mmap(NULL, bytes, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + r->data = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (r->data == MAP_FAILED) { pr_perror("Can't map mem for pipe buffers"); return -1; @@ -56,8 +55,8 @@ static int pipe_data_read(struct cr_img *img, struct pipe_data_rst *r) return read_img_buf(img, r->data, bytes); } -int do_collect_pipe_data(struct pipe_data_rst *r, ProtobufCMessage *msg, - struct cr_img *img, struct pipe_data_rst **hash) +int do_collect_pipe_data(struct pipe_data_rst *r, ProtobufCMessage *msg, struct cr_img *img, + struct pipe_data_rst **hash) { int aux; @@ -69,8 +68,7 @@ int do_collect_pipe_data(struct pipe_data_rst *r, ProtobufCMessage *msg, aux = r->pde->pipe_id & PIPE_DATA_HASH_MASK; r->next = hash[aux]; hash[aux] = r; - pr_info("Collected pipe data for %#x (chain %u)\n", - r->pde->pipe_id, aux); + pr_info("Collected pipe data for %#x (chain %u)\n", r->pde->pipe_id, aux); return 0; } @@ -161,8 +159,7 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash } if (pd->pde->has_size) { - pr_info("Restoring size %#x for %#x\n", - pd->pde->size, pd->pde->pipe_id); + pr_info("Restoring size %#x for %#x\n", pd->pde->size, pd->pde->pipe_id); ret = fcntl(pfd, F_SETPIPE_SZ, pd->pde->size); if (ret < 0) { pr_perror("Can't restore pipe size"); @@ -189,8 +186,7 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash } if (ret == 0 || ret > iov.iov_len /* sanity */) { - pr_err("%#x: Wanted to restore %zu bytes, but got %d\n", id, - iov.iov_len, ret); + pr_err("%#x: Wanted to restore %zu bytes, but got %d\n", id, iov.iov_len, ret); return -1; } @@ -216,7 +212,7 @@ int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash static int userns_reopen(void *_arg, int fd, pid_t pid) { char path[PSFDS]; - int ret, flags = *(int*)_arg; + int ret, flags = *(int *)_arg; sprintf(path, "/proc/self/fd/%d", fd); ret = open(path, flags); @@ -237,8 +233,7 @@ static int reopen_pipe(int fd, int flags) if (ret < 0) { if (errno == EACCES) { /* It may be an external pipe from an another userns */ - ret = userns_call(userns_reopen, UNS_FDOUT, - &flags, sizeof(flags), fd); + ret = userns_call(userns_reopen, UNS_FDOUT, &flags, sizeof(flags), fd); } else pr_perror("Unable to reopen the pipe %s", path); } @@ -279,8 +274,7 @@ static char *pipe_d_name(struct file_desc *d, char *buf, size_t s) pi = container_of(d, struct pipe_info, d); if (snprintf(buf, s, "pipe:[%u]", pi->pe->pipe_id) >= s) { - pr_err("Not enough room for pipe %u identifier string\n", - pi->pe->pipe_id); + pr_err("Not enough room for pipe %u identifier string\n", pi->pe->pipe_id); return NULL; } @@ -311,8 +305,7 @@ int open_pipe(struct file_desc *d, int *new_fd) return -1; } - ret = restore_pipe_data(CR_FD_PIPES_DATA, pfd[1], - pi->pe->pipe_id, pd_hash_pipes); + ret = restore_pipe_data(CR_FD_PIPES_DATA, pfd[1], pi->pe->pipe_id, pd_hash_pipes); if (ret) return -1; @@ -342,9 +335,9 @@ reopen: } static struct file_desc_ops pipe_desc_ops = { - .type = FD_TYPES__PIPE, - .open = open_pipe, - .name = pipe_d_name, + .type = FD_TYPES__PIPE, + .open = open_pipe, + .name = pipe_d_name, }; int collect_one_pipe_ops(void *o, ProtobufCMessage *base, struct file_desc_ops *ops) @@ -355,8 +348,7 @@ int collect_one_pipe_ops(void *o, ProtobufCMessage *base, struct file_desc_ops * pi->create = 0; pi->reopen = 1; - pr_info("Collected pipe entry ID %#x PIPE ID %#x\n", - pi->pe->id, pi->pe->pipe_id); + pr_info("Collected pipe entry ID %#x PIPE ID %#x\n", pi->pe->id, pi->pe->pipe_id); if (file_desc_add(&pi->d, pi->pe->id, ops)) return -1; @@ -455,10 +447,10 @@ int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms bytes = 0; } - pde.pipe_id = pipe_id(p); - pde.bytes = bytes; - pde.has_size = true; - pde.size = pipe_size; + pde.pipe_id = pipe_id(p); + pde.bytes = bytes; + pde.has_size = true; + pde.size = pipe_size; if (pb_write_one(img, &pde, PB_PIPE_DATA)) goto err_close; @@ -483,25 +475,26 @@ err: return ret; } -static struct pipe_data_dump pd_pipes = { .img_type = CR_FD_PIPES_DATA, }; +static struct pipe_data_dump pd_pipes = { + .img_type = CR_FD_PIPES_DATA, +}; static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p) { FileEntry fe = FILE_ENTRY__INIT; PipeEntry pe = PIPE_ENTRY__INIT; - pr_info("Dumping pipe %d with id %#x pipe_id %#x\n", - lfd, id, pipe_id(p)); + pr_info("Dumping pipe %d with id %#x pipe_id %#x\n", lfd, id, pipe_id(p)); if ((p->flags & O_DIRECT) && !is_autofs_pipe(pipe_id(p))) { pr_err("The packetized mode for pipes is not supported yet\n"); return -1; } - pe.id = id; - pe.pipe_id = pipe_id(p); - pe.flags = p->flags & ~O_DIRECT; - pe.fown = (FownEntry *)&p->fown; + pe.id = id; + pe.pipe_id = pipe_id(p); + pe.flags = p->flags & ~O_DIRECT; + pe.fown = (FownEntry *)&p->fown; fe.type = FD_TYPES__PIPE; fe.id = pe.id; @@ -514,6 +507,6 @@ static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops pipe_dump_ops = { - .type = FD_TYPES__PIPE, - .dump = dump_one_pipe, + .type = FD_TYPES__PIPE, + .dump = dump_one_pipe, }; diff --git a/criu/plugin.c b/criu/plugin.c index f35a04fc9..3fe03c7cd 100644 --- a/criu/plugin.c +++ b/criu/plugin.c @@ -30,29 +30,30 @@ static cr_plugin_desc_t *cr_gen_plugin_desc(void *h, char *path) if (!d) return NULL; - d->name = xstrdup(path); - d->max_hooks = CR_PLUGIN_HOOK__MAX; - d->version = CRIU_PLUGIN_VERSION_OLD; + d->name = xstrdup(path); + d->max_hooks = CR_PLUGIN_HOOK__MAX; + d->version = CRIU_PLUGIN_VERSION_OLD; pr_warn("Generating dynamic descriptor for plugin `%s'." "Won't work in next version of the program." - "Please update your plugin.\n", path); - -#define __assign_hook(__hook, __name) \ - do { \ - void *name; \ - name = dlsym(h, __name); \ - if (name) \ - d->hooks[CR_PLUGIN_HOOK__ ##__hook] = name; \ + "Please update your plugin.\n", + path); + +#define __assign_hook(__hook, __name) \ + do { \ + void *name; \ + name = dlsym(h, __name); \ + if (name) \ + d->hooks[CR_PLUGIN_HOOK__##__hook] = name; \ } while (0) - __assign_hook(DUMP_UNIX_SK, "cr_plugin_dump_unix_sk"); - __assign_hook(RESTORE_UNIX_SK, "cr_plugin_restore_unix_sk"); - __assign_hook(DUMP_EXT_FILE, "cr_plugin_dump_file"); - __assign_hook(RESTORE_EXT_FILE, "cr_plugin_restore_file"); - __assign_hook(DUMP_EXT_MOUNT, "cr_plugin_dump_ext_mount"); - __assign_hook(RESTORE_EXT_MOUNT, "cr_plugin_restore_ext_mount"); - __assign_hook(DUMP_EXT_LINK, "cr_plugin_dump_ext_link"); + __assign_hook(DUMP_UNIX_SK, "cr_plugin_dump_unix_sk"); + __assign_hook(RESTORE_UNIX_SK, "cr_plugin_restore_unix_sk"); + __assign_hook(DUMP_EXT_FILE, "cr_plugin_dump_file"); + __assign_hook(RESTORE_EXT_FILE, "cr_plugin_restore_file"); + __assign_hook(DUMP_EXT_MOUNT, "cr_plugin_dump_ext_mount"); + __assign_hook(RESTORE_EXT_MOUNT, "cr_plugin_restore_ext_mount"); + __assign_hook(DUMP_EXT_LINK, "cr_plugin_dump_ext_link"); #undef __assign_hook @@ -66,8 +67,7 @@ static void show_plugin_desc(cr_plugin_desc_t *d) { size_t i; - pr_debug("Plugin \"%s\" (version %u hooks %u)\n", - d->name, d->version, d->max_hooks); + pr_debug("Plugin \"%s\" (version %u hooks %u)\n", d->name, d->version, d->max_hooks); for (i = 0; i < d->max_hooks; i++) { if (d->hooks[i]) pr_debug("\t%4zu -> %p\n", i, d->hooks[i]); @@ -77,14 +77,13 @@ static void show_plugin_desc(cr_plugin_desc_t *d) static int verify_plugin(cr_plugin_desc_t *d) { if (d->version > CRIU_PLUGIN_VERSION) { - pr_debug("Plugin %s has version %x while max %x supported\n", - d->name, d->version, CRIU_PLUGIN_VERSION); + pr_debug("Plugin %s has version %x while max %x supported\n", d->name, d->version, CRIU_PLUGIN_VERSION); return -1; } if (d->max_hooks > CR_PLUGIN_HOOK__MAX) { - pr_debug("Plugin %s has %u assigned while max %u supported\n", - d->name, d->max_hooks, CR_PLUGIN_HOOK__MAX); + pr_debug("Plugin %s has %u assigned while max %u supported\n", d->name, d->max_hooks, + CR_PLUGIN_HOOK__MAX); return -1; } @@ -243,8 +242,7 @@ int cr_plugin_init(int stage) if (len < 3 || strncmp(de->d_name + len - 3, ".so", 3)) continue; - if (snprintf(path, sizeof(path), "%s/%s", opts.libdir, de->d_name) >= - sizeof(path)) { + if (snprintf(path, sizeof(path), "%s/%s", opts.libdir, de->d_name) >= sizeof(path)) { pr_err("Unable to build plugin path\n"); goto err; } diff --git a/criu/proc_parse.c b/criu/proc_parse.c index cdfefe361..f3491e781 100644 --- a/criu/proc_parse.c +++ b/criu/proc_parse.c @@ -49,19 +49,19 @@ #include <stdlib.h> #ifndef SIGEV_SIGNAL -#define SIGEV_SIGNAL 0 /* notify via signal */ +#define SIGEV_SIGNAL 0 /* notify via signal */ #endif #ifndef SIGEV_NONE -#define SIGEV_NONE 1 /* other notification: meaningless */ +#define SIGEV_NONE 1 /* other notification: meaningless */ #endif #ifndef SIGEV_THREAD -#define SIGEV_THREAD 2 /* deliver via thread creation */ +#define SIGEV_THREAD 2 /* deliver via thread creation */ #endif #ifndef SIGEV_THREAD_ID -#define SIGEV_THREAD_ID 4 /* deliver to thread */ +#define SIGEV_THREAD_ID 4 /* deliver to thread */ #endif -#define BUF_SIZE 4096 /* Good enough value - can be changed */ +#define BUF_SIZE 4096 /* Good enough value - can be changed */ struct buffer { char buf[BUF_SIZE]; @@ -75,14 +75,12 @@ static char *buf = __buf.buf; * This is how AIO ring buffers look like in proc */ -#define AIO_FNAME "/[aio]" +#define AIO_FNAME "/[aio]" /* check the @line starts with "%lx-%lx" format */ static bool __is_vma_range_fmt(char *line) { -#define ____is_vma_addr_char(__c) \ - (((__c) <= '9' && (__c) >= '0') || \ - ((__c) <= 'f' && (__c) >= 'a')) +#define ____is_vma_addr_char(__c) (((__c) <= '9' && (__c) >= '0') || ((__c) <= 'f' && (__c) >= 'a')) while (*line && ____is_vma_addr_char(*line)) line++; @@ -173,8 +171,7 @@ static void parse_vma_vmflags(char *buf, struct vma_area *vma_area) * only exception is VVAR area that mapped by the kernel as * VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP */ - if (io_pf && !vma_area_is(vma_area, VMA_AREA_VVAR) && - !vma_entry_is(vma_area->e, VMA_FILE_SHARED)) + if (io_pf && !vma_area_is(vma_area, VMA_AREA_VVAR) && !vma_entry_is(vma_area->e, VMA_FILE_SHARED)) vma_area->e->status |= VMA_UNSUPP; if (vma_area->e->madv) @@ -195,9 +192,7 @@ struct vma_file_info { static inline int vfi_equal(struct vma_file_info *a, struct vma_file_info *b) { - return ((a->ino ^ b->ino) | - (a->dev_maj ^ b->dev_maj) | - (a->dev_min ^ b->dev_min)) == 0; + return ((a->ino ^ b->ino) | (a->dev_maj ^ b->dev_maj) | (a->dev_min ^ b->dev_min)) == 0; } static int vma_get_mapfile_flags(struct vma_area *vma, DIR *mfd, char *path) @@ -209,20 +204,20 @@ static int vma_get_mapfile_flags(struct vma_area *vma, DIR *mfd, char *path) /* Just mapping w/o map_files link */ return 0; } - pr_perror("Failed fstatat on map %"PRIx64"", vma->e->start); + pr_perror("Failed fstatat on map %" PRIx64 "", vma->e->start); return -1; } - switch(stat.st_mode & 0600) { - case 0200: - vma->e->fdflags = O_WRONLY; - break; - case 0400: - vma->e->fdflags = O_RDONLY; - break; - case 0600: - vma->e->fdflags = O_RDWR; - break; + switch (stat.st_mode & 0600) { + case 0200: + vma->e->fdflags = O_WRONLY; + break; + case 0400: + vma->e->fdflags = O_RDONLY; + break; + case 0600: + vma->e->fdflags = O_RDWR; + break; } vma->e->has_fdflags = true; return 0; @@ -254,16 +249,15 @@ static int vma_stat(struct vma_area *vma, int fd) } if (fstat(fd, vma->vmst) < 0) { - pr_perror("Failed fstat on map %"PRIx64"", vma->e->start); + pr_perror("Failed fstat on map %" PRIx64 "", vma->e->start); return -1; } return 0; } -static int vma_get_mapfile_user(const char *fname, struct vma_area *vma, - struct vma_file_info *vfi, int *vm_file_fd, - const char *path) +static int vma_get_mapfile_user(const char *fname, struct vma_area *vma, struct vma_file_info *vfi, int *vm_file_fd, + const char *path) { int fd; dev_t vfi_dev; @@ -286,8 +280,7 @@ static int vma_get_mapfile_user(const char *fname, struct vma_area *vma, */ if (vfi->dev_maj != 0 || vfi->dev_min != 0 || vfi->ino != 0) { - pr_err("Strange file mapped at %lx [%s]:%d.%d.%ld\n", - (unsigned long)vma->e->start, fname, + pr_err("Strange file mapped at %lx [%s]:%d.%d.%ld\n", (unsigned long)vma->e->start, fname, vfi->dev_maj, vfi->dev_min, vfi->ino); return -1; } @@ -327,7 +320,7 @@ static int vma_get_mapfile_user(const char *fname, struct vma_area *vma, if (!(vma->e->flags & MAP_SHARED)) return -1; - vma->e->flags |= MAP_ANONYMOUS; + vma->e->flags |= MAP_ANONYMOUS; vma->e->status |= VMA_ANON_SHARED; vma->e->shmid = vfi->ino; @@ -353,10 +346,8 @@ static int vma_get_mapfile_user(const char *fname, struct vma_area *vma, return -1; } - if (vma->vmst->st_dev != vfi_dev || - vma->vmst->st_ino != vfi->ino) { - pr_err("Failed to resolve mapping %lx filename\n", - (unsigned long)vma->e->start); + if (vma->vmst->st_dev != vfi_dev || vma->vmst->st_ino != vfi->ino) { + pr_err("Failed to resolve mapping %lx filename\n", (unsigned long)vma->e->start); close(fd); return -1; } @@ -365,16 +356,14 @@ static int vma_get_mapfile_user(const char *fname, struct vma_area *vma, return 0; } -static int vma_get_mapfile(const char *fname, struct vma_area *vma, DIR *mfd, - struct vma_file_info *vfi, - struct vma_file_info *prev_vfi, - int *vm_file_fd) +static int vma_get_mapfile(const char *fname, struct vma_area *vma, DIR *mfd, struct vma_file_info *vfi, + struct vma_file_info *prev_vfi, int *vm_file_fd) { char path[32]; int flags; /* Figure out if it's file mapping */ - snprintf(path, sizeof(path), "%"PRIx64"-%"PRIx64, vma->e->start, vma->e->end); + snprintf(path, sizeof(path), "%" PRIx64 "-%" PRIx64, vma->e->start, vma->e->end); if (vma_get_mapfile_flags(vma, mfd, path)) return -1; @@ -389,8 +378,7 @@ static int vma_get_mapfile(const char *fname, struct vma_area *vma, DIR *mfd, if (*vm_file_fd < 0) return 0; - pr_debug("vma %"PRIx64" borrows vfi from previous %"PRIx64"\n", - vma->e->start, prev->e->start); + pr_debug("vma %" PRIx64 " borrows vfi from previous %" PRIx64 "\n", vma->e->start, prev->e->start); if (prev->e->status & VMA_AREA_SOCKET) vma->e->status |= VMA_AREA_SOCKET | VMA_AREA_REGULAR; @@ -436,7 +424,7 @@ static int vma_get_mapfile(const char *fname, struct vma_area *vma, DIR *mfd, return -1; if (S_ISSOCK(buf.st_mode)) { - pr_info("Found socket mapping @%"PRIx64"\n", vma->e->start); + pr_info("Found socket mapping @%" PRIx64 "\n", vma->e->start); vma->vm_socket_id = buf.st_ino; vma->e->status |= VMA_AREA_SOCKET | VMA_AREA_REGULAR; return 0; @@ -511,7 +499,7 @@ int parse_self_maps_lite(struct vm_area_list *vms) prev = vma; } - pr_debug("Parsed %"PRIx64"-%"PRIx64" vma\n", prev->e->start, prev->e->end); + pr_debug("Parsed %" PRIx64 "-%" PRIx64 " vma\n", prev->e->start, prev->e->end); } bclose(&maps); @@ -538,21 +526,16 @@ static inline int handle_vvar_vma(struct vma_area *vma) return 0; } -static int handle_vma(pid_t pid, struct vma_area *vma_area, - const char *file_path, DIR *map_files_dir, - struct vma_file_info *vfi, - struct vma_file_info *prev_vfi, - int *vm_file_fd) +static int handle_vma(pid_t pid, struct vma_area *vma_area, const char *file_path, DIR *map_files_dir, + struct vma_file_info *vfi, struct vma_file_info *prev_vfi, int *vm_file_fd) { - if (vma_get_mapfile(file_path, vma_area, map_files_dir, - vfi, prev_vfi, vm_file_fd)) + if (vma_get_mapfile(file_path, vma_area, map_files_dir, vfi, prev_vfi, vm_file_fd)) goto err_bogus_mapfile; if (vma_area->e->status != 0) return 0; - if (!strcmp(file_path, "[vsyscall]") || - !strcmp(file_path, "[vectors]")) { + if (!strcmp(file_path, "[vsyscall]") || !strcmp(file_path, "[vectors]")) { vma_area->e->status |= VMA_AREA_VSYSCALL; } else if (!strcmp(file_path, "[vdso]")) { if (handle_vdso_vma(vma_area)) @@ -599,12 +582,12 @@ static int handle_vma(pid_t pid, struct vma_area *vma_area, else if (S_ISCHR(st_buf->st_mode) && (st_buf->st_rdev == DEVZERO)) /* devzero mapping -- also makes sense */; else { - pr_err("Can't handle non-regular mapping on %d's map %"PRIx64"\n", pid, vma_area->e->start); + pr_err("Can't handle non-regular mapping on %d's map %" PRIx64 "\n", pid, vma_area->e->start); goto err; } if (is_anon_shmem_map(st_buf->st_dev) && !strncmp(file_path, "/SYSV", 5)) { - vma_area->e->flags |= MAP_ANONYMOUS; + vma_area->e->flags |= MAP_ANONYMOUS; vma_area->e->status |= VMA_ANON_SHARED; vma_area->e->shmid = st_buf->st_ino; if (!(vma_area->e->flags & MAP_SHARED)) @@ -631,8 +614,7 @@ static int handle_vma(pid_t pid, struct vma_area *vma_area, * mnt_id to -1 to mimic pre-3.15 kernels that didn't * have mnt_id. */ - if (vma_area->mnt_id != -1 && - get_fd_mntid(*vm_file_fd, &vma_area->mnt_id)) + if (vma_area->mnt_id != -1 && get_fd_mntid(*vm_file_fd, &vma_area->mnt_id)) return -1; } else { /* @@ -644,37 +626,33 @@ static int handle_vma(pid_t pid, struct vma_area *vma_area, } else { vma_area->e->status |= VMA_ANON_PRIVATE; } - vma_area->e->flags |= MAP_ANONYMOUS; + vma_area->e->flags |= MAP_ANONYMOUS; } return 0; err: return -1; err_bogus_mapping: - pr_err("Bogus mapping 0x%"PRIx64"-0x%"PRIx64" (flags: %#x vm_file_fd: %d)\n", - vma_area->e->start, vma_area->e->end, - vma_area->e->flags, *vm_file_fd); + pr_err("Bogus mapping 0x%" PRIx64 "-0x%" PRIx64 " (flags: %#x vm_file_fd: %d)\n", vma_area->e->start, + vma_area->e->end, vma_area->e->flags, *vm_file_fd); goto err; err_bogus_mapfile: - pr_perror("Can't open %d's mapfile link %"PRIx64, pid, vma_area->e->start); + pr_perror("Can't open %d's mapfile link %" PRIx64, pid, vma_area->e->start); goto err; } -static int vma_list_add(struct vma_area *vma_area, - struct vm_area_list *vma_area_list, - unsigned long *prev_end, +static int vma_list_add(struct vma_area *vma_area, struct vm_area_list *vma_area_list, unsigned long *prev_end, struct vma_file_info *vfi, struct vma_file_info *prev_vfi) { if (vma_area->e->status & VMA_UNSUPP) { - pr_err("Unsupported mapping found %016"PRIx64"-%016"PRIx64"\n", - vma_area->e->start, vma_area->e->end); + pr_err("Unsupported mapping found %016" PRIx64 "-%016" PRIx64 "\n", vma_area->e->start, + vma_area->e->end); return -1; } /* Add a guard page only if here is enough space for it */ - if (vma_has_guard_gap_hidden(vma_area) && - *prev_end < vma_area->e->start) + if (vma_has_guard_gap_hidden(vma_area) && *prev_end < vma_area->e->start) vma_area->e->start -= PAGE_SIZE; /* Guard page */ *prev_end = vma_area->e->end; @@ -685,14 +663,12 @@ static int vma_list_add(struct vma_area *vma_area, pages = vma_area_len(vma_area) / PAGE_SIZE; vma_area_list->nr_priv_pages += pages; - vma_area_list->nr_priv_pages_longest = - max(vma_area_list->nr_priv_pages_longest, pages); + vma_area_list->nr_priv_pages_longest = max(vma_area_list->nr_priv_pages_longest, pages); } else if (vma_area_is(vma_area, VMA_ANON_SHARED)) { unsigned long pages; pages = vma_area_len(vma_area) / PAGE_SIZE; - vma_area_list->nr_shared_pages_longest = - max(vma_area_list->nr_shared_pages_longest, pages); + vma_area_list->nr_shared_pages_longest = max(vma_area_list->nr_shared_pages_longest, pages); } *prev_vfi = *vfi; @@ -710,15 +686,15 @@ static int task_size_check(pid_t pid, VmaEntry *entry) #ifdef __s390x__ if (entry->end <= kdat.task_size) return 0; - pr_err("Can't dump high memory region %lx-%lx of task %d because kernel commit ee71d16d22bb is missing\n", entry->start, entry->end, pid); + pr_err("Can't dump high memory region %lx-%lx of task %d because kernel commit ee71d16d22bb is missing\n", + entry->start, entry->end, pid); return -1; #else return 0; #endif } -int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, - dump_filemap_t dump_filemap) +int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, dump_filemap_t dump_filemap) { struct vma_area *vma_area = NULL; unsigned long start, end, pgoff, prev_end = 0; @@ -756,8 +732,8 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, if (!eof && !__is_vma_range_fmt(str)) { if (!strncmp(str, "Nonlinear", 9)) { BUG_ON(!vma_area); - pr_err("Nonlinear mapping found %016"PRIx64"-%016"PRIx64"\n", - vma_area->e->start, vma_area->e->end); + pr_err("Nonlinear mapping found %016" PRIx64 "-%016" PRIx64 "\n", vma_area->e->start, + vma_area->e->end); /* * VMA is already on list and will be * freed later as list get destroyed. @@ -772,8 +748,7 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, continue; } - if (vma_area && vma_list_add(vma_area, vma_area_list, - &prev_end, &vfi, &prev_vfi)) + if (vma_area && vma_list_add(vma_area, vma_area_list, &prev_end, &vfi, &prev_vfi)) goto err; if (eof) @@ -783,18 +758,17 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, if (!vma_area) goto err; - num = sscanf(str, "%lx-%lx %c%c%c%c %lx %x:%x %lu %n", - &start, &end, &r, &w, &x, &s, &pgoff, + num = sscanf(str, "%lx-%lx %c%c%c%c %lx %x:%x %lu %n", &start, &end, &r, &w, &x, &s, &pgoff, &vfi.dev_maj, &vfi.dev_min, &vfi.ino, &path_off); if (num < 10) { pr_err("Can't parse: %s\n", str); goto err; } - vma_area->e->start = start; - vma_area->e->end = end; - vma_area->e->pgoff = pgoff; - vma_area->e->prot = PROT_NONE; + vma_area->e->start = start; + vma_area->e->end = end; + vma_area->e->pgoff = pgoff; + vma_area->e->prot = PROT_NONE; if (task_size_check(pid, vma_area->e)) goto err; @@ -815,12 +789,10 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, goto err; } - if (handle_vma(pid, vma_area, str + path_off, map_files_dir, - &vfi, &prev_vfi, &vm_file_fd)) + if (handle_vma(pid, vma_area, str + path_off, map_files_dir, &vfi, &prev_vfi, &vm_file_fd)) goto err; - if (vma_entry_is(vma_area->e, VMA_FILE_PRIVATE) || - vma_entry_is(vma_area->e, VMA_FILE_SHARED)) { + if (vma_entry_is(vma_area->e, VMA_FILE_PRIVATE) || vma_entry_is(vma_area->e, VMA_FILE_SHARED)) { if (dump_filemap && dump_filemap(vma_area, vm_file_fd)) goto err; } else if (vma_entry_is(vma_area->e, VMA_AREA_AIORING)) @@ -839,7 +811,6 @@ err_n: xfree(vma_area); return ret; - } int parse_pid_stat(pid_t pid, struct proc_pid_stat *s) @@ -879,60 +850,17 @@ int parse_pid_stat(pid_t pid, struct proc_pid_stat *s) strlcpy(s->comm, tok + 1, sizeof(s->comm)); n = sscanf(p + 1, - " %c %d %d %d %d %d %u %lu %lu %lu %lu " - "%lu %lu %ld %ld %ld %ld %d %d %llu %lu %ld %lu %lu %lu %lu " - "%lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld " - "%lu %lu %lu %lu %lu %lu %lu %d", - &s->state, - &s->ppid, - &s->pgid, - &s->sid, - &s->tty_nr, - &s->tty_pgrp, - &s->flags, - &s->min_flt, - &s->cmin_flt, - &s->maj_flt, - &s->cmaj_flt, - &s->utime, - &s->stime, - &s->cutime, - &s->cstime, - &s->priority, - &s->nice, - &s->num_threads, - &s->zero0, - &s->start_time, - &s->vsize, - &s->mm_rss, - &s->rsslim, - &s->start_code, - &s->end_code, - &s->start_stack, - &s->esp, - &s->eip, - &s->sig_pending, - &s->sig_blocked, - &s->sig_ignored, - &s->sig_handled, - &s->wchan, - &s->zero1, - &s->zero2, - &s->exit_signal, - &s->task_cpu, - &s->rt_priority, - &s->policy, - &s->delayacct_blkio_ticks, - &s->gtime, - &s->cgtime, - &s->start_data, - &s->end_data, - &s->start_brk, - &s->arg_start, - &s->arg_end, - &s->env_start, - &s->env_end, - &s->exit_code); + " %c %d %d %d %d %d %u %lu %lu %lu %lu " + "%lu %lu %ld %ld %ld %ld %d %d %llu %lu %ld %lu %lu %lu %lu " + "%lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld " + "%lu %lu %lu %lu %lu %lu %lu %d", + &s->state, &s->ppid, &s->pgid, &s->sid, &s->tty_nr, &s->tty_pgrp, &s->flags, &s->min_flt, + &s->cmin_flt, &s->maj_flt, &s->cmaj_flt, &s->utime, &s->stime, &s->cutime, &s->cstime, &s->priority, + &s->nice, &s->num_threads, &s->zero0, &s->start_time, &s->vsize, &s->mm_rss, &s->rsslim, + &s->start_code, &s->end_code, &s->start_stack, &s->esp, &s->eip, &s->sig_pending, &s->sig_blocked, + &s->sig_ignored, &s->sig_handled, &s->wchan, &s->zero1, &s->zero2, &s->exit_signal, &s->task_cpu, + &s->rt_priority, &s->policy, &s->delayacct_blkio_ticks, &s->gtime, &s->cgtime, &s->start_data, + &s->end_data, &s->start_brk, &s->arg_start, &s->arg_end, &s->env_start, &s->env_end, &s->exit_code); if (n < 50) goto err; @@ -955,8 +883,7 @@ int prepare_loginuid(unsigned int value) snprintf(buf, 11, "%u", value); if (write(fd, buf, 11) < 0) { - pr_warn("Write %s to /proc/self/loginuid failed: %s\n", - buf, strerror(errno)); + pr_warn("Write %s to /proc/self/loginuid failed: %s\n", buf, strerror(errno)); ret = -1; } close(fd); @@ -969,8 +896,7 @@ unsigned int parse_pid_loginuid(pid_t pid, int *err, bool ignore_noent) ssize_t num; *err = 0; - fd = __open_proc(pid, (ignore_noent) ? ENOENT : 0, - O_RDONLY, "loginuid"); + fd = __open_proc(pid, (ignore_noent) ? ENOENT : 0, O_RDONLY, "loginuid"); if (fd < 0) goto out; @@ -1216,9 +1142,8 @@ static bool sb_opt_cb(char *opt, char *unknown, size_t *uoff) return false; } -static int do_opt2flag(char *opt, unsigned *flags, - const struct opt2flag *opts, char *unknown, - bool (*cb)(char *opt, char *unknown, size_t *uoff)) +static int do_opt2flag(char *opt, unsigned *flags, const struct opt2flag *opts, char *unknown, + bool (*cb)(char *opt, char *unknown, size_t *uoff)) { int i; char *end; @@ -1263,15 +1188,39 @@ static int do_opt2flag(char *opt, unsigned *flags, static int parse_mnt_flags(char *opt, unsigned *flags) { static const struct opt2flag mnt_opt2flag[] = { - { "rw", 0, }, - { "ro", MS_RDONLY, }, - { "nosuid", MS_NOSUID, }, - { "nodev", MS_NODEV, }, - { "noexec", MS_NOEXEC, }, - { "noatime", MS_NOATIME, }, - { "nodiratime", MS_NODIRATIME, }, - { "relatime", MS_RELATIME, }, - { }, + { + "rw", + 0, + }, + { + "ro", + MS_RDONLY, + }, + { + "nosuid", + MS_NOSUID, + }, + { + "nodev", + MS_NODEV, + }, + { + "noexec", + MS_NOEXEC, + }, + { + "noatime", + MS_NOATIME, + }, + { + "nodiratime", + MS_NODIRATIME, + }, + { + "relatime", + MS_RELATIME, + }, + {}, }; if (do_opt2flag(opt, flags, mnt_opt2flag, NULL, NULL)) @@ -1287,12 +1236,27 @@ static int parse_mnt_flags(char *opt, unsigned *flags) static int parse_sb_opt(char *opt, unsigned *flags, char *uopt) { static const struct opt2flag sb_opt2flag[] = { - { "rw", 0, }, - { "ro", MS_RDONLY, }, - { "sync", MS_SYNC, }, - { "dirsync", MS_DIRSYNC, }, - { "mad", MS_MANDLOCK, }, - { }, + { + "rw", + 0, + }, + { + "ro", + MS_RDONLY, + }, + { + "sync", + MS_SYNC, + }, + { + "dirsync", + MS_DIRSYNC, + }, + { + "mad", + MS_MANDLOCK, + }, + {}, }; return do_opt2flag(opt, flags, sb_opt2flag, uopt, sb_opt_cb); @@ -1360,7 +1324,7 @@ static void cure_path(char *path) if (off) path[i - off] = path[i]; continue; -replace: + replace: off += 3; i += 3; } @@ -1379,10 +1343,8 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname) goto err; new->mountpoint[0] = '.'; - ret = sscanf(str, "%i %i %u:%u %ms %s %ms %n", - &new->mnt_id, &new->parent_mnt_id, - &kmaj, &kmin, &new->root, new->mountpoint + 1, - &opt, &n); + ret = sscanf(str, "%i %i %u:%u %ms %s %ms %n", &new->mnt_id, &new->parent_mnt_id, &kmaj, &kmin, &new->root, + new->mountpoint + 1, &opt, &n); if (ret != 7) goto err; @@ -1471,8 +1433,7 @@ struct str_node { bool add_skip_mount(const char *mountpoint) { - struct str_node *skip = xmalloc(sizeof(struct str_node) + - strlen(mountpoint) + 1); + struct str_node *skip = xmalloc(sizeof(struct str_node) + strlen(mountpoint) + 1); if (!skip) return false; @@ -1507,19 +1468,17 @@ int parse_timens_offsets(struct timespec *boff, struct timespec *moff) int64_t sec, nsec; char clockid[10]; - if (sscanf(buf, "%9s %"PRId64" %"PRId64"\n", clockid, &sec, &nsec) != 3) { + if (sscanf(buf, "%9s %" PRId64 " %" PRId64 "\n", clockid, &sec, &nsec) != 3) { pr_err("Unable to parse: %s\n", buf); goto out; } clockid[sizeof(clockid) - 1] = 0; - if (strcmp(clockid, "monotonic") == 0 || - strcmp(clockid, __stringify(CLOCK_MONOTONIC)) == 0) { + if (strcmp(clockid, "monotonic") == 0 || strcmp(clockid, __stringify(CLOCK_MONOTONIC)) == 0) { moff->tv_sec = sec; moff->tv_nsec = nsec; continue; } - if (strcmp(clockid, "boottime") == 0 || - strcmp(clockid, __stringify(CLOCK_BOOTTIME)) == 0) { + if (strcmp(clockid, "boottime") == 0 || strcmp(clockid, __stringify(CLOCK_BOOTTIME)) == 0) { boff->tv_sec = sec; boff->tv_nsec = nsec; continue; @@ -1565,22 +1524,19 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump) * depends on this one. */ if (for_dump && should_skip_mount(new->mountpoint + 1)) { - pr_info("\tskip %s @ %s\n", fsname, new->mountpoint); + pr_info("\tskip %s @ %s\n", fsname, new->mountpoint); mnt_entry_free(new); new = NULL; goto end; } - pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n", - fsname, new->source, - new->mnt_id, new->s_dev, new->root, new->mountpoint, - new->flags, new->options); + pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n", fsname, new->source, + new->mnt_id, new->s_dev, new->root, new->mountpoint, new->flags, new->options); if (new->fstype->parse) { ret = new->fstype->parse(new); if (ret < 0) { - pr_err("Failed to parse FS specific data on %s\n", - new->mountpoint); + pr_err("Failed to parse FS specific data on %s\n", new->mountpoint); mnt_entry_free(new); new = NULL; goto end; @@ -1592,10 +1548,9 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump) new = NULL; ret = 0; goto end; - } } -end: + end: if (fsname) free(fsname); @@ -1683,16 +1638,14 @@ static int parse_timerfd(struct bfd *f, char *str, TimerfdEntry *tfy) str = breadline(f); if (IS_ERR_OR_NULL(str)) goto nodata; - if (sscanf(str, "it_value: (%llu, %llu)", - (unsigned long long *)&tfy->vsec, + if (sscanf(str, "it_value: (%llu, %llu)", (unsigned long long *)&tfy->vsec, (unsigned long long *)&tfy->vnsec) != 2) goto parse_err; str = breadline(f); if (IS_ERR_OR_NULL(str)) goto nodata; - if (sscanf(str, "it_interval: (%llu, %llu)", - (unsigned long long *)&tfy->isec, + if (sscanf(str, "it_interval: (%llu, %llu)", (unsigned long long *)&tfy->isec, (unsigned long long *)&tfy->insec) != 2) goto parse_err; return 0; @@ -1725,14 +1678,14 @@ static int parse_bpfmap(struct bfd *f, char *str, BpfmapFileEntry *bpf) */ bpfmap_fmt map[] = { - {"map_type: %u", &bpf->map_type }, - {"key_size: %u", &bpf->key_size }, - {"value_size: %u", &bpf->value_size }, - {"max_entries: %u", &bpf->max_entries }, - {"map_flags: %"PRIx32"", &bpf->map_flags }, - {"memlock: %"PRIu64"", &bpf->memlock }, - {"map_id: %u", &bpf->map_id }, - {"frozen: %d", &bpf->frozen }, + { "map_type: %u", &bpf->map_type }, + { "key_size: %u", &bpf->key_size }, + { "value_size: %u", &bpf->value_size }, + { "max_entries: %u", &bpf->max_entries }, + { "map_flags: %" PRIx32 "", &bpf->map_flags }, + { "memlock: %" PRIu64 "", &bpf->memlock }, + { "map_id: %u", &bpf->map_id }, + { "frozen: %d", &bpf->frozen }, }; size_t n = sizeof(map) / sizeof(bpfmap_fmt); @@ -1755,10 +1708,9 @@ static int parse_bpfmap(struct bfd *f, char *str, BpfmapFileEntry *bpf) return 0; } -#define fdinfo_field(str, field) !strncmp(str, field":", sizeof(field)) +#define fdinfo_field(str, field) !strncmp(str, field ":", sizeof(field)) -static int parse_file_lock_buf(char *buf, struct file_lock *fl, - bool is_blocked); +static int parse_file_lock_buf(char *buf, struct file_lock *fl, bool is_blocked); static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) { struct bfd f; @@ -1780,9 +1732,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (IS_ERR(str)) goto out; - if (fdinfo_field(str, "pos") || - fdinfo_field(str, "flags") || - fdinfo_field(str, "mnt_id")) { + if (fdinfo_field(str, "pos") || fdinfo_field(str, "flags") || fdinfo_field(str, "mnt_id")) { unsigned long long val; struct fdinfo_common *fdinfo = arg; @@ -1806,7 +1756,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (fdinfo_field(str, "lock")) { struct file_lock *fl; struct fdinfo_common *fdinfo = arg; - char *flock_status = str+sizeof("lock:\t")-1; + char *flock_status = str + sizeof("lock:\t") - 1; if (type != FD_TYPES__UND) continue; @@ -1831,11 +1781,8 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) goto parse_err; } - pr_info("lockinfo: %lld:%d %x %d %02x:%02x:%ld %lld %s\n", - fl->fl_id, fl->fl_kind, fl->fl_ltype, - fl->fl_owner, fl->maj, fl->min, fl->i_no, - fl->start, fl->end); - + pr_info("lockinfo: %lld:%d %x %d %02x:%02x:%ld %lld %s\n", fl->fl_id, fl->fl_kind, fl->fl_ltype, + fl->fl_owner, fl->maj, fl->min, fl->i_no, fl->start, fl->end); if (fl->fl_kind == FL_UNKNOWN) { pr_err("Unknown file lock!\n"); @@ -1857,8 +1804,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (type != FD_TYPES__EVENTFD) goto parse_err; - ret = sscanf(str, "eventfd-count: %"PRIx64, - &efd->counter); + ret = sscanf(str, "eventfd-count: %" PRIx64, &efd->counter); if (ret != 1) goto parse_err; @@ -1891,11 +1837,11 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) eventpoll_tfd_entry__init(e); - ret = sscanf(str, "tfd: %d events: %x data: %llx" + ret = sscanf(str, + "tfd: %d events: %x data: %llx" " pos:%lli ino:%lx sdev:%x", - &e->tfd, &e->events, (long long *)&e->data, - (long long *)&e->pos, (long *)&e->inode, - &e->dev); + &e->tfd, &e->events, (long long *)&e->data, (long long *)&e->pos, + (long *)&e->inode, &e->dev); if (ret < 3 || ret > 6) { eventpoll_tfd_entry__free_unpacked(e, NULL); goto parse_err; @@ -1925,8 +1871,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (type != FD_TYPES__SIGNALFD) goto parse_err; - ret = sscanf(str, "sigmask: %llx", - (unsigned long long *)&sfd->sigmask); + ret = sscanf(str, "sigmask: %llx", (unsigned long long *)&sfd->sigmask); if (ret != 1) goto parse_err; @@ -1939,8 +1884,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (type != FD_TYPES__FANOTIFY) goto parse_err; - ret = sscanf(str, "fanotify flags:%x event-flags:%x", - &fe->faflags, &fe->evflags); + ret = sscanf(str, "fanotify flags:%x event-flags:%x", &fe->faflags, &fe->evflags); if (ret != 2) goto parse_err; entry_met = true; @@ -1955,10 +1899,8 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (type != FD_TYPES__FANOTIFY) goto parse_err; - ob = buf = xmalloc(sizeof(FanotifyMarkEntry) + - sizeof(FanotifyInodeMarkEntry) + - sizeof(FhEntry) + - FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); + ob = buf = xmalloc(sizeof(FanotifyMarkEntry) + sizeof(FanotifyInodeMarkEntry) + + sizeof(FhEntry) + FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); if (!buf) goto out; @@ -1969,16 +1911,13 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) me->ie->f_handle = xptr_pull(&buf, FhEntry); fh_entry__init(me->ie->f_handle); me->ie->f_handle->n_handle = FH_ENTRY_SIZES__min_entries; - me->ie->f_handle->handle = xptr_pull_s(&buf, - FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); + me->ie->f_handle->handle = xptr_pull_s(&buf, FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); ret = sscanf(str, - "fanotify ino:%"PRIx64" sdev:%x mflags:%x mask:%x ignored_mask:%x " + "fanotify ino:%" PRIx64 " sdev:%x mflags:%x mask:%x ignored_mask:%x " "fhandle-bytes:%x fhandle-type:%x f_handle: %n", - &me->ie->i_ino, &me->s_dev, - &me->mflags, &me->mask, &me->ignored_mask, - &me->ie->f_handle->bytes, &me->ie->f_handle->type, - &hoff); + &me->ie->i_ino, &me->s_dev, &me->mflags, &me->mask, &me->ignored_mask, + &me->ie->f_handle->bytes, &me->ie->f_handle->type, &hoff); if (ret != 7 || hoff == 0) { xfree(ob); goto parse_err; @@ -2006,9 +1945,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (type != FD_TYPES__FANOTIFY) goto parse_err; - - ob = buf = xmalloc(sizeof(FanotifyMarkEntry) + - sizeof(FanotifyMountMarkEntry)); + ob = buf = xmalloc(sizeof(FanotifyMarkEntry) + sizeof(FanotifyMountMarkEntry)); if (!buf) goto out; @@ -2017,10 +1954,8 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) me->me = xptr_pull(&buf, FanotifyMountMarkEntry); fanotify_mount_mark_entry__init(me->me); - ret = sscanf(str, - "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x", - &me->me->mnt_id, &me->mflags, - &me->mask, &me->ignored_mask); + ret = sscanf(str, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x", &me->me->mnt_id, + &me->mflags, &me->mask, &me->ignored_mask); if (ret != 4) { xfree(ob); goto parse_err; @@ -2047,9 +1982,8 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) if (type != FD_TYPES__INOTIFY) goto parse_err; - ob = buf = xmalloc(sizeof(InotifyWdEntry) + - sizeof(FhEntry) + - FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); + ob = buf = xmalloc(sizeof(InotifyWdEntry) + sizeof(FhEntry) + + FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); if (!buf) goto out; @@ -2058,18 +1992,15 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, void *arg) ify->f_handle = xptr_pull(&buf, FhEntry); fh_entry__init(ify->f_handle); ify->f_handle->n_handle = FH_ENTRY_SIZES__min_entries; - ify->f_handle->handle = xptr_pull_s(&buf, - FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); + ify->f_handle->handle = xptr_pull_s(&buf, FH_ENTRY_SIZES__min_entries * sizeof(uint64_t)); ret = sscanf(str, - "inotify wd:%x ino:%"PRIx64" sdev:%x " - "mask:%x ignored_mask:%x " - "fhandle-bytes:%x fhandle-type:%x " - "f_handle: %n", - &ify->wd, &ify->i_ino, &ify->s_dev, - &ify->mask, &ify->ignored_mask, - &ify->f_handle->bytes, &ify->f_handle->type, - &hoff); + "inotify wd:%x ino:%" PRIx64 " sdev:%x " + "mask:%x ignored_mask:%x " + "fhandle-bytes:%x fhandle-type:%x " + "f_handle: %n", + &ify->wd, &ify->i_ino, &ify->s_dev, &ify->mask, &ify->ignored_mask, + &ify->f_handle->bytes, &ify->f_handle->type, &hoff); if (ret != 7) { xfree(ob); goto parse_err; @@ -2132,7 +2063,7 @@ int parse_fdinfo(int fd, int type, void *arg) int get_fd_mntid(int fd, int *mnt_id) { - struct fdinfo_common fdinfo = { .mnt_id = -1}; + struct fdinfo_common fdinfo = { .mnt_id = -1 }; if (parse_fdinfo(fd, FD_TYPES__UND, &fdinfo)) return -1; @@ -2141,22 +2072,17 @@ int get_fd_mntid(int fd, int *mnt_id) return 0; } -static int parse_file_lock_buf(char *buf, struct file_lock *fl, - bool is_blocked) +static int parse_file_lock_buf(char *buf, struct file_lock *fl, bool is_blocked) { - int num; + int num; char fl_flag[10], fl_type[15], fl_option[10]; if (is_blocked) { - num = sscanf(buf, "%lld: -> %s %s %s %d %x:%x:%ld %lld %s", - &fl->fl_id, fl_flag, fl_type, fl_option, - &fl->fl_owner, &fl->maj, &fl->min, &fl->i_no, - &fl->start, fl->end); + num = sscanf(buf, "%lld: -> %s %s %s %d %x:%x:%ld %lld %s", &fl->fl_id, fl_flag, fl_type, fl_option, + &fl->fl_owner, &fl->maj, &fl->min, &fl->i_no, &fl->start, fl->end); } else { - num = sscanf(buf, "%lld:%s %s %s %d %x:%x:%ld %lld %s", - &fl->fl_id, fl_flag, fl_type, fl_option, - &fl->fl_owner, &fl->maj, &fl->min, &fl->i_no, - &fl->start, fl->end); + num = sscanf(buf, "%lld:%s %s %s %d %x:%x:%ld %lld %s", &fl->fl_id, fl_flag, fl_type, fl_option, + &fl->fl_owner, &fl->maj, &fl->min, &fl->i_no, &fl->start, fl->end); } if (num < 10) { @@ -2217,9 +2143,9 @@ int parse_file_locks(void) { struct file_lock *fl; - FILE *fl_locks; - int exit_code = -1; - bool is_blocked; + FILE *fl_locks; + int exit_code = -1; + bool is_blocked; if (kdat.has_fdinfo_lock) return 0; @@ -2242,11 +2168,8 @@ int parse_file_locks(void) goto err; } - pr_info("lockinfo: %lld:%d %x %d %02x:%02x:%ld %lld %s\n", - fl->fl_id, fl->fl_kind, fl->fl_ltype, - fl->fl_owner, fl->maj, fl->min, fl->i_no, - fl->start, fl->end); - + pr_info("lockinfo: %lld:%d %x %d %02x:%02x:%ld %lld %s\n", fl->fl_id, fl->fl_kind, fl->fl_ltype, + fl->fl_owner, fl->maj, fl->min, fl->i_no, fl->start, fl->end); if (fl->fl_kind == FL_UNKNOWN) { pr_err("Unknown file lock: %s!\n", buf); @@ -2264,8 +2187,7 @@ int parse_file_locks(void) continue; } - if ((fl->fl_kind == FL_POSIX) && - !pid_in_pstree(fl->fl_owner)) { + if ((fl->fl_kind == FL_POSIX) && !pid_in_pstree(fl->fl_owner)) { /* * We only care about tasks which are taken * into dump, so we only collect file locks @@ -2332,46 +2254,41 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args) if (timer == NULL) goto err; - if (sscanf(s, "ID: %ld", - &timer->spt.it_id) != 1) + if (sscanf(s, "ID: %ld", &timer->spt.it_id) != 1) goto err; break; case 1: - if (sscanf(s, "signal: %d/%16s", - &timer->spt.si_signo, pbuf) != 2) + if (sscanf(s, "signal: %d/%16s", &timer->spt.si_signo, pbuf) != 2) goto err; break; case 2: - if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n", - sigpid, tidpid, &pid_t) != 3) + if (sscanf(s, "notify: %6[a-z]/%3[a-z].%d\n", sigpid, tidpid, &pid_t) != 3) goto err; break; case 3: - if (sscanf(s, "ClockID: %d\n", - &timer->spt.clock_id) != 1) + if (sscanf(s, "ClockID: %d\n", &timer->spt.clock_id) != 1) goto err; timer->spt.sival_ptr = NULL; - if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 && - strcmp(pbuf, "(null)")) { + if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 && strcmp(pbuf, "(null)")) { pr_err("Unable to parse '%s'\n", pbuf); goto err; } - if ( tidpid[0] == 't') { + if (tidpid[0] == 't') { timer->spt.it_sigev_notify = SIGEV_THREAD_ID; timer->spt.notify_thread_id = pid_t; } else { switch (sigpid[0]) { - case 's' : - timer->spt.it_sigev_notify = SIGEV_SIGNAL; - break; - case 't' : - timer->spt.it_sigev_notify = SIGEV_THREAD; - break; - default : - timer->spt.it_sigev_notify = SIGEV_NONE; - break; + case 's': + timer->spt.it_sigev_notify = SIGEV_SIGNAL; + break; + case 't': + timer->spt.it_sigev_notify = SIGEV_THREAD; + break; + default: + timer->spt.it_sigev_notify = SIGEV_NONE; + break; } } @@ -2464,7 +2381,7 @@ int parse_cgroup_file(FILE *f, struct list_head *retl, unsigned int *n) xfree(ncc); goto err; } - path = strchr(++name, ':'); + path = strchr(++name, ':'); if (!path) { pr_err("Failed parsing cgroup %s\n", buf); xfree(ncc); @@ -2575,15 +2492,16 @@ int parse_task_cgroup(int pid, struct parasite_dump_cgroup_args *args, struct li continue; /* +1 here to chop off the leading / */ - pos = ext->path + strlen(ext->path) - strlen(intern->path+1); - if (strcmp(pos, intern->path+1)) { - pr_err("invalid cgroup configuration, %s is not a suffix of %s\n", intern->path, ext->path); + pos = ext->path + strlen(ext->path) - strlen(intern->path + 1); + if (strcmp(pos, intern->path + 1)) { + pr_err("invalid cgroup configuration, %s is not a suffix of %s\n", intern->path, + ext->path); ret = -1; goto out; } ext->cgns_prefix = pos - ext->path; - if (ext->path[ext->cgns_prefix-1] == '/') + if (ext->path[ext->cgns_prefix - 1] == '/') ext->cgns_prefix--; } } @@ -2669,10 +2587,10 @@ int collect_controllers(struct list_head *cgroups, unsigned int *n_cgroups) if (!n) goto err; - nc->controllers[nc->n_controllers-1] = n; + nc->controllers[nc->n_controllers - 1] = n; } -skip: + skip: if (!off) break; controllers = off + 1; diff --git a/criu/protobuf-desc.c b/criu/protobuf-desc.c index 8f601ea24..d1a11b295 100644 --- a/criu/protobuf-desc.c +++ b/criu/protobuf-desc.c @@ -70,39 +70,56 @@ struct cr_pb_message_desc cr_pb_descs[PB_MAX]; -#define CR_PB_DESC(__type, __vtype, __ftype) \ - CR_PB_MDESC_INIT(cr_pb_descs[PB_##__type], \ - __vtype##Entry, \ - __ftype##_entry) +#define CR_PB_DESC(__type, __vtype, __ftype) CR_PB_MDESC_INIT(cr_pb_descs[PB_##__type], __vtype##Entry, __ftype##_entry) -#define PB_PACK_TYPECHECK(__o, __fn) ({ if (0) __fn##__pack(__o, NULL); (pb_pack_t)&__fn##__pack; }) -#define PB_GPS_TYPECHECK(__o, __fn) ({ if (0) __fn##__get_packed_size(__o); (pb_getpksize_t)&__fn##__get_packed_size; }) -#define PB_UNPACK_TYPECHECK(__op, __fn) ({ if (0) *__op = __fn##__unpack(NULL, 0, NULL); (pb_unpack_t)&__fn##__unpack; }) -#define PB_FREE_TYPECHECK(__o, __fn) ({ if (0) __fn##__free_unpacked(__o, NULL); (pb_free_t)&__fn##__free_unpacked; }) +#define PB_PACK_TYPECHECK(__o, __fn) \ + ({ \ + if (0) \ + __fn##__pack(__o, NULL); \ + (pb_pack_t) & __fn##__pack; \ + }) +#define PB_GPS_TYPECHECK(__o, __fn) \ + ({ \ + if (0) \ + __fn##__get_packed_size(__o); \ + (pb_getpksize_t) & __fn##__get_packed_size; \ + }) +#define PB_UNPACK_TYPECHECK(__op, __fn) \ + ({ \ + if (0) \ + *__op = __fn##__unpack(NULL, 0, NULL); \ + (pb_unpack_t) & __fn##__unpack; \ + }) +#define PB_FREE_TYPECHECK(__o, __fn) \ + ({ \ + if (0) \ + __fn##__free_unpacked(__o, NULL); \ + (pb_free_t) & __fn##__free_unpacked; \ + }) /* * This should be explicitly "called" to do type-checking */ -#define CR_PB_MDESC_INIT(__var, __type, __name) \ - do { \ - __var.getpksize = PB_GPS_TYPECHECK((__type *)NULL, __name); \ - __var.pack = PB_PACK_TYPECHECK((__type *)NULL, __name); \ - __var.unpack = PB_UNPACK_TYPECHECK((__type **)NULL, __name); \ - __var.free = PB_FREE_TYPECHECK((__type *)NULL, __name); \ - __var.pb_desc = &__name##__descriptor; \ +#define CR_PB_MDESC_INIT(__var, __type, __name) \ + do { \ + __var.getpksize = PB_GPS_TYPECHECK((__type *)NULL, __name); \ + __var.pack = PB_PACK_TYPECHECK((__type *)NULL, __name); \ + __var.unpack = PB_UNPACK_TYPECHECK((__type **)NULL, __name); \ + __var.free = PB_FREE_TYPECHECK((__type *)NULL, __name); \ + __var.pb_desc = &__name##__descriptor; \ } while (0) void cr_pb_init(void) { - CR_PB_DESC(IDS, TaskKobjIds, task_kobj_ids); - CR_PB_DESC(SIGACT, Sa, sa); - CR_PB_DESC(SK_QUEUES, SkPacket, sk_packet); - CR_PB_MDESC_INIT(cr_pb_descs[PB_IPCNS_MSG], IpcMsg, ipc_msg); - CR_PB_DESC(IPCNS_MSG_ENT, IpcMsg, ipc_msg); - CR_PB_DESC(REMAP_FPATH, RemapFilePath, remap_file_path); - CR_PB_DESC(NETDEV, NetDevice, net_device); - CR_PB_MDESC_INIT(cr_pb_descs[PB_PAGEMAP_HEAD], PagemapHead, pagemap_head); + CR_PB_DESC(IDS, TaskKobjIds, task_kobj_ids); + CR_PB_DESC(SIGACT, Sa, sa); + CR_PB_DESC(SK_QUEUES, SkPacket, sk_packet); + CR_PB_MDESC_INIT(cr_pb_descs[PB_IPCNS_MSG], IpcMsg, ipc_msg); + CR_PB_DESC(IPCNS_MSG_ENT, IpcMsg, ipc_msg); + CR_PB_DESC(REMAP_FPATH, RemapFilePath, remap_file_path); + CR_PB_DESC(NETDEV, NetDevice, net_device); + CR_PB_MDESC_INIT(cr_pb_descs[PB_PAGEMAP_HEAD], PagemapHead, pagemap_head); #include "protobuf-desc-gen.h" } diff --git a/criu/protobuf.c b/criu/protobuf.c index 206223ca5..ef78bcec7 100644 --- a/criu/protobuf.c +++ b/criu/protobuf.c @@ -20,7 +20,7 @@ #include "protobuf.h" #include "util.h" -#define image_name(img, buf) __image_name(img, buf, sizeof(buf)) +#define image_name(img, buf) __image_name(img, buf, sizeof(buf)) static char *__image_name(struct cr_img *img, char *image_path, size_t image_path_size) { int fd = img->_x.fd; @@ -55,8 +55,7 @@ int do_pb_read_one(struct cr_img *img, void **pobj, int type, bool eof) int ret; if (!cr_pb_descs[type].pb_desc) { - pr_err("Wrong object requested %d on %s\n", - type, image_name(img, img_name_buf)); + pr_err("Wrong object requested %d on %s\n", type, image_name(img, img_name_buf)); return -1; } @@ -70,13 +69,11 @@ int do_pb_read_one(struct cr_img *img, void **pobj, int type, bool eof) if (eof) { return 0; } else { - pr_err("Unexpected EOF on %s\n", - image_name(img, img_name_buf)); + pr_err("Unexpected EOF on %s\n", image_name(img, img_name_buf)); return -1; } } else if (ret < sizeof(size)) { - pr_perror("Read %d bytes while %d expected on %s", - ret, (int)sizeof(size), + pr_perror("Read %d bytes while %d expected on %s", ret, (int)sizeof(size), image_name(img, img_name_buf)); return -1; } @@ -90,12 +87,10 @@ int do_pb_read_one(struct cr_img *img, void **pobj, int type, bool eof) ret = bread(&img->_x, buf, size); if (ret < 0) { - pr_perror("Can't read %d bytes from file %s", - size, image_name(img, img_name_buf)); + pr_perror("Can't read %d bytes from file %s", size, image_name(img, img_name_buf)); goto err; } else if (ret != size) { - pr_perror("Read %d bytes while %d expected from %s", - ret, size, image_name(img, img_name_buf)); + pr_perror("Read %d bytes while %d expected from %s", ret, size, image_name(img, img_name_buf)); ret = -1; goto err; } @@ -103,8 +98,7 @@ int do_pb_read_one(struct cr_img *img, void **pobj, int type, bool eof) *pobj = cr_pb_descs[type].unpack(NULL, size, buf); if (!*pobj) { ret = -1; - pr_err("Failed unpacking object %p from %s\n", - pobj, image_name(img, img_name_buf)); + pr_err("Failed unpacking object %p from %s\n", pobj, image_name(img, img_name_buf)); goto err; } @@ -209,8 +203,7 @@ int collect_image(struct collect_image_info *cinfo) void *(*o_alloc)(size_t size) = malloc; void (*o_free)(void *ptr) = free; - pr_info("Collecting %d/%d (flags %x)\n", - cinfo->fd_type, cinfo->pb_type, cinfo->flags); + pr_info("Collecting %d/%d (flags %x)\n", cinfo->fd_type, cinfo->pb_type, cinfo->flags); img = open_image(cinfo->fd_type, O_RSTR); if (!img) diff --git a/criu/pstree.c b/criu/pstree.c index 3ca8908b4..d5080e515 100644 --- a/criu/pstree.c +++ b/criu/pstree.c @@ -34,7 +34,7 @@ void core_entry_free(CoreEntry *core) } #ifndef RLIM_NLIMITS -# define RLIM_NLIMITS 16 +#define RLIM_NLIMITS 16 #endif CoreEntry *core_entry_alloc(int th, int tsk) @@ -118,14 +118,14 @@ CoreEntry *core_entry_alloc(int th, int tsk) ce = core->thread_core->creds = xptr_pull(&m, CredsEntry); creds_entry__init(ce); - ce->n_cap_inh = CR_CAP_SIZE; - ce->n_cap_prm = CR_CAP_SIZE; - ce->n_cap_eff = CR_CAP_SIZE; - ce->n_cap_bnd = CR_CAP_SIZE; - ce->cap_inh = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_inh[0])); - ce->cap_prm = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_prm[0])); - ce->cap_eff = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_eff[0])); - ce->cap_bnd = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_bnd[0])); + ce->n_cap_inh = CR_CAP_SIZE; + ce->n_cap_prm = CR_CAP_SIZE; + ce->n_cap_eff = CR_CAP_SIZE; + ce->n_cap_bnd = CR_CAP_SIZE; + ce->cap_inh = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_inh[0])); + ce->cap_prm = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_prm[0])); + ce->cap_eff = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_eff[0])); + ce->cap_bnd = xptr_pull_s(&m, CR_CAP_SIZE * sizeof(ce->cap_bnd[0])); if (arch_alloc_thread_info(core)) { xfree(core); @@ -294,7 +294,8 @@ int dump_pstree(struct pstree_item *root_item) if (vpid(root_item) != root_item->sid) { if (!opts.shell_job) { pr_err("The root process %d is not a session leader. " - "Consider using --" OPT_SHELL_JOB " option\n", vpid(item)); + "Consider using --" OPT_SHELL_JOB " option\n", + vpid(item)); return -1; } } @@ -306,11 +307,11 @@ int dump_pstree(struct pstree_item *root_item) for_each_pstree_item(item) { pr_info("Process: %d(%d)\n", vpid(item), item->pid->real); - e.pid = vpid(item); - e.ppid = item->parent ? vpid(item->parent) : 0; - e.pgid = item->pgid; - e.sid = item->sid; - e.n_threads = item->nr_threads; + e.pid = vpid(item); + e.ppid = item->parent ? vpid(item->parent) : 0; + e.pgid = item->pgid; + e.sid = item->sid; + e.n_threads = item->nr_threads; e.threads = xmalloc(sizeof(e.threads[0]) * e.n_threads); if (!e.threads) @@ -370,13 +371,11 @@ static int prepare_pstree_for_shell_job(pid_t pid) old_sid = root_item->sid; if (old_sid != current_sid) { - pr_info("Migrating process tree (SID %d->%d)\n", - old_sid, current_sid); + pr_info("Migrating process tree (SID %d->%d)\n", old_sid, current_sid); tmp = pstree_pid_by_virt(current_sid); if (tmp) { - pr_err("Current sid %d intersects with pid (%d) in images", - current_sid, tmp->state); + pr_err("Current sid %d intersects with pid (%d) in images\n", current_sid, tmp->state); return -1; } @@ -395,13 +394,11 @@ static int prepare_pstree_for_shell_job(pid_t pid) old_gid = root_item->pgid; if (old_gid != current_gid) { - pr_info("Migrating process tree (GID %d->%d)\n", - old_gid, current_gid); + pr_info("Migrating process tree (GID %d->%d)\n", old_gid, current_gid); tmp = pstree_pid_by_virt(current_gid); if (tmp) { - pr_err("Current gid %d intersects with pid (%d) in images", - current_gid, tmp->state); + pr_err("Current gid %d intersects with pid (%d) in images\n", current_gid, tmp->state); return -1; } @@ -456,7 +453,7 @@ static struct pid *lookup_create_pid(pid_t pid, struct pid *pid_node) void pstree_insert_pid(struct pid *pid_node) { - struct pid* n; + struct pid *n; n = lookup_create_pid(pid_node->ns[0].virt, pid_node); @@ -567,7 +564,8 @@ static int read_one_pstree_item(struct cr_img *img, pid_t *pid_max) if (e->ppid == 0) { if (root_item) { pr_err("Parent missed on non-root task " - "with pid %d, image corruption!\n", e->pid); + "with pid %d, image corruption!\n", + e->pid); goto err; } root_item = pi; @@ -641,7 +639,7 @@ static int read_pstree_image(pid_t *pid_max) return ret; } -#define RESERVED_PIDS 300 +#define RESERVED_PIDS 300 static int get_free_pid(void) { static struct pid *prev, *next; @@ -712,8 +710,7 @@ static int prepare_pstree_ids(pid_t pid) helper->parent = leader; list_add(&helper->sibling, &leader->children); - pr_info("Attach %d to the task %d\n", - vpid(helper), vpid(leader)); + pr_info("Attach %d to the task %d\n", vpid(helper), vpid(leader)); } else { helper = leader; helper->sid = item->sid; @@ -727,8 +724,7 @@ static int prepare_pstree_ids(pid_t pid) return -1; } - pr_info("Add a helper %d for restoring SID %d\n", - vpid(helper), helper->sid); + pr_info("Add a helper %d for restoring SID %d\n", vpid(helper), helper->sid); child = list_entry(item->sibling.prev, struct pstree_item, sibling); item = child; @@ -742,8 +738,7 @@ static int prepare_pstree_ids(pid_t pid) if (child->sid == vpid(child)) continue; - pr_info("Attach %d to the temporary task %d\n", - vpid(child), vpid(helper)); + pr_info("Attach %d to the temporary task %d\n", vpid(child), vpid(helper)); child->parent = helper; list_move(&child->sibling, &helper->children); @@ -769,8 +764,8 @@ static int prepare_pstree_ids(pid_t pid) while (parent && vpid(parent) != item->sid) { if (parent->born_sid != -1 && parent->born_sid != item->sid) { pr_err("Can't figure out which sid (%d or %d)" - "the process %d was born with\n", - parent->born_sid, item->sid, vpid(parent)); + "the process %d was born with\n", + parent->born_sid, item->sid, vpid(parent)); return -1; } parent->born_sid = item->sid; @@ -826,15 +821,13 @@ static int prepare_pstree_ids(pid_t pid) list_add(&helper->sibling, &item->children); rsti(item)->pgrp_leader = helper; - pr_info("Add a helper %d for restoring PGID %d\n", - vpid(helper), helper->pgid); + pr_info("Add a helper %d for restoring PGID %d\n", vpid(helper), helper->pgid); } return 0; } -static unsigned long get_clone_mask(TaskKobjIdsEntry *i, - TaskKobjIdsEntry *p) +static unsigned long get_clone_mask(TaskKobjIdsEntry *i, TaskKobjIdsEntry *p) { unsigned long mask = 0; @@ -985,12 +978,11 @@ int prepare_pstree(void) if (fd == -1) ret = -1; else { - snprintf(buf, sizeof(buf), "%u", pid_max+1); + snprintf(buf, sizeof(buf), "%u", pid_max + 1); if (write(fd, buf, strlen(buf)) < 0) { pr_perror("Can't set kernel pid_max=%s", buf); ret = -1; - } - else + } else pr_info("kernel pid_max pushed to %s\n", buf); close(fd); } diff --git a/criu/rbtree.c b/criu/rbtree.c index 64a38ea76..ad619f371 100644 --- a/criu/rbtree.c +++ b/criu/rbtree.c @@ -108,8 +108,7 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) rb_set_black(root->rb_node); } -static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, - struct rb_root *root) +static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, struct rb_root *root) { struct rb_node *other; @@ -122,7 +121,7 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, __rb_rotate_left(parent, root); other = parent->rb_right; } - if ((!other->rb_left || rb_is_black(other->rb_left)) && + if ((!other->rb_left || rb_is_black(other->rb_left)) && (!other->rb_right || rb_is_black(other->rb_right))) { rb_set_red(other); node = parent; @@ -149,7 +148,7 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, __rb_rotate_right(parent, root); other = parent->rb_left; } - if ((!other->rb_left || rb_is_black(other->rb_left)) && + if ((!other->rb_left || rb_is_black(other->rb_left)) && (!other->rb_right || rb_is_black(other->rb_right))) { rb_set_red(other); node = parent; @@ -245,7 +244,7 @@ color: */ struct rb_node *rb_first(const struct rb_root *root) { - struct rb_node *n; + struct rb_node *n; n = root->rb_node; if (!n) @@ -259,7 +258,7 @@ struct rb_node *rb_first(const struct rb_root *root) struct rb_node *rb_last(const struct rb_root *root) { - struct rb_node *n; + struct rb_node *n; n = root->rb_node; if (!n) @@ -285,7 +284,7 @@ struct rb_node *rb_next(const struct rb_node *node) if (node->rb_right) { node = node->rb_right; while (node->rb_left) - node=node->rb_left; + node = node->rb_left; return (struct rb_node *)node; } @@ -331,9 +330,7 @@ struct rb_node *rb_prev(const struct rb_node *node) return parent; } -void rb_replace_node(struct rb_node *victim, - struct rb_node *new, - struct rb_root *root) +void rb_replace_node(struct rb_node *victim, struct rb_node *new, struct rb_root *root) { struct rb_node *parent = rb_parent(victim); diff --git a/criu/rst-malloc.c b/criu/rst-malloc.c index ff96797e2..edac78137 100644 --- a/criu/rst-malloc.c +++ b/criu/rst-malloc.c @@ -43,8 +43,7 @@ static int grow_shared(struct rst_mem_type_s *t, unsigned long size) * previous chunk location and allocate a * new one */ - aux = mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + aux = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (aux == MAP_FAILED) return -1; @@ -65,8 +64,7 @@ static int grow_remap(struct rst_mem_type_s *t, int flag, unsigned long size) /* * Can't call mremap with NULL address :( */ - aux = mmap(NULL, size, PROT_READ | PROT_WRITE, - flag | MAP_ANONYMOUS, 0, 0); + aux = mmap(NULL, size, PROT_READ | PROT_WRITE, flag | MAP_ANONYMOUS, 0, 0); else { if (flag & MAP_SHARED) { /* @@ -88,8 +86,7 @@ static int grow_remap(struct rst_mem_type_s *t, int flag, unsigned long size) * a completely new one and force callers use objects' * cpos-s. */ - aux = mremap(t->buf, t->size, - t->size + size, MREMAP_MAYMOVE); + aux = mremap(t->buf, t->size, t->size + size, MREMAP_MAYMOVE); } if (aux == MAP_FAILED) return -1; @@ -142,7 +139,7 @@ void rst_mem_align(int type) struct rst_mem_type_s *t = &rst_mems[type]; void *ptr; - ptr = (void *) round_up((unsigned long)t->free_mem, sizeof(void *)); + ptr = (void *)round_up((unsigned long)t->free_mem, sizeof(void *)); t->free_bytes -= (ptr - t->free_mem); t->free_mem = ptr; } @@ -220,8 +217,7 @@ static int rst_mem_remap_one(struct rst_mem_type_s *t, void *to) */ return 0; - pr_debug("\tcall mremap(%p, %lu, %lu, MAYMOVE | FIXED, %p)\n", - t->buf, t->size, t->size, to); + pr_debug("\tcall mremap(%p, %lu, %lu, MAYMOVE | FIXED, %p)\n", t->buf, t->size, t->size, to); aux = mremap(t->buf, t->size, t->size, MREMAP_MAYMOVE | MREMAP_FIXED, to); if (aux == MAP_FAILED) { pr_perror("Can't mremap rst mem"); @@ -256,4 +252,3 @@ void shfree_last(void *ptr) { rst_mem_free_last(RM_SHARED); } - diff --git a/criu/seccomp.c b/criu/seccomp.c index 94e663d40..917f694b6 100644 --- a/criu/seccomp.c +++ b/criu/seccomp.c @@ -19,7 +19,7 @@ #include "protobuf.h" #include "images/seccomp.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "seccomp: " static struct rb_root seccomp_tid_rb_root = RB_ROOT; @@ -52,7 +52,7 @@ struct seccomp_entry *seccomp_lookup(pid_t tid_real, bool create, bool mandatory if (!entry) return NULL; rb_init_node(&entry->node); - entry->tid_real = tid_real; + entry->tid_real = tid_real; entry->next = seccomp_tid_entry_root, seccomp_tid_entry_root = entry; rb_link_and_balance(&seccomp_tid_rb_root, &entry->node, parent, new); @@ -146,8 +146,7 @@ static int collect_filter(struct seccomp_entry *entry) if (errno == ENOENT) { break; } else { - pr_perror("Can't fetch filter on tid_real %d i %zu", - entry->tid_real, i); + pr_perror("Can't fetch filter on tid_real %d i %zu", entry->tid_real, i); return -1; } } @@ -225,8 +224,7 @@ static void try_use_tsync(struct seccomp_entry *leader, struct pstree_item *item if (entry == leader) continue; - if (entry->mode != leader->mode || - entry->nr_chains != leader->nr_chains) + if (entry->mode != leader->mode || entry->nr_chains != leader->nr_chains) return; chain_a = leader->chain; @@ -235,12 +233,10 @@ static void try_use_tsync(struct seccomp_entry *leader, struct pstree_item *item for (j = 0; j < leader->nr_chains; j++) { BUG_ON((!chain_a || !chain_b)); - if (chain_a->filter.filter.len != - chain_b->filter.filter.len) + if (chain_a->filter.filter.len != chain_b->filter.filter.len) return; - if (memcmp(chain_a->filter.filter.data, - chain_b->filter.filter.data, + if (memcmp(chain_a->filter.filter.data, chain_b->filter.filter.data, chain_a->filter.filter.len)) return; @@ -250,8 +246,7 @@ static void try_use_tsync(struct seccomp_entry *leader, struct pstree_item *item } /* OK, so threads can be restored with tsync */ - pr_debug("Use SECCOMP_FILTER_FLAG_TSYNC for tid_real %d\n", - leader->tid_real); + pr_debug("Use SECCOMP_FILTER_FLAG_TSYNC for tid_real %d\n", leader->tid_real); for (chain_a = leader->chain; chain_a; chain_a = chain_a->prev) chain_a->filter.flags |= SECCOMP_FILTER_FLAG_TSYNC; @@ -263,8 +258,7 @@ static void try_use_tsync(struct seccomp_entry *leader, struct pstree_item *item if (entry == leader) continue; - pr_debug("\t Disable filter on tid_rea %d, will be propagated\n", - entry->tid_real); + pr_debug("\t Disable filter on tid_rea %d, will be propagated\n", entry->tid_real); entry->mode = SECCOMP_MODE_DISABLED; seccomp_free_chain(entry); @@ -281,16 +275,14 @@ static int collect_filters(struct pstree_item *item) leader = seccomp_find_entry(item->pid->real); if (!leader) { - pr_err("Can't collect filter on leader tid_real %d\n", - item->pid->real); + pr_err("Can't collect filter on leader tid_real %d\n", item->pid->real); return -1; } for (i = 0; i < item->nr_threads; i++) { entry = seccomp_find_entry(item->threads[i].real); if (!entry) { - pr_err("Can't collect filter on tid_real %d\n", - item->pid->real); + pr_err("Can't collect filter on tid_real %d\n", item->pid->real); return -1; } @@ -331,8 +323,7 @@ static int dump_seccomp_filters(void) for (chain = entry->chain; chain; chain = chain->prev) { if (img_filter_pos >= nr_chains) { - pr_err("Unexpected position %zu > %zu\n", - img_filter_pos, nr_chains); + pr_err("Unexpected position %zu > %zu\n", img_filter_pos, nr_chains); xfree(se.seccomp_filters); return -1; } @@ -408,8 +399,8 @@ void seccomp_rst_reloc(struct thread_restore_args *args) return; args->seccomp_filters = rst_mem_remap_ptr(args->seccomp_filters_pos, RM_PRIVATE); - args->seccomp_filters_data = (void *)args->seccomp_filters + - args->seccomp_filters_n * sizeof(struct thread_seccomp_filter); + args->seccomp_filters_data = + (void *)args->seccomp_filters + args->seccomp_filters_n * sizeof(struct thread_seccomp_filter); for (j = off = 0; j < args->seccomp_filters_n; j++) { struct thread_seccomp_filter *f = &args->seccomp_filters[j]; @@ -429,11 +420,11 @@ int seccomp_prepare_threads(struct pstree_item *item, struct task_restore_args * struct thread_restore_args *args = &args_array[i]; SeccompFilter *sf; - args->seccomp_mode = SECCOMP_MODE_DISABLED; - args->seccomp_filters_pos = 0; - args->seccomp_filters_n = 0; - args->seccomp_filters = NULL; - args->seccomp_filters_data = NULL; + args->seccomp_mode = SECCOMP_MODE_DISABLED; + args->seccomp_filters_pos = 0; + args->seccomp_filters_n = 0; + args->seccomp_filters = NULL; + args->seccomp_filters_data = NULL; if (thread_core->has_seccomp_mode) args->seccomp_mode = thread_core->seccomp_mode; @@ -442,16 +433,14 @@ int seccomp_prepare_threads(struct pstree_item *item, struct task_restore_args * continue; if (thread_core->seccomp_filter >= seccomp_img_entry->n_seccomp_filters) { - pr_err("Corrupted filter index on tid %d (%u > %zu)\n", - item->threads[i].ns[0].virt, thread_core->seccomp_filter, - seccomp_img_entry->n_seccomp_filters); + pr_err("Corrupted filter index on tid %d (%u > %zu)\n", item->threads[i].ns[0].virt, + thread_core->seccomp_filter, seccomp_img_entry->n_seccomp_filters); return -1; } sf = seccomp_img_entry->seccomp_filters[thread_core->seccomp_filter]; if (sf->filter.len % (sizeof(struct sock_filter))) { - pr_err("Corrupted filter len on tid %d (index %u)\n", - item->threads[i].ns[0].virt, + pr_err("Corrupted filter len on tid %d (index %u)\n", item->threads[i].ns[0].virt, thread_core->seccomp_filter); return -1; } @@ -460,16 +449,15 @@ int seccomp_prepare_threads(struct pstree_item *item, struct task_restore_args * while (sf->has_prev) { if (sf->prev >= seccomp_img_entry->n_seccomp_filters) { - pr_err("Corrupted filter index on tid %d (%u > %zu)\n", - item->threads[i].ns[0].virt, sf->prev, - seccomp_img_entry->n_seccomp_filters); + pr_err("Corrupted filter index on tid %d (%u > %zu)\n", item->threads[i].ns[0].virt, + sf->prev, seccomp_img_entry->n_seccomp_filters); return -1; } sf = seccomp_img_entry->seccomp_filters[sf->prev]; if (sf->filter.len % (sizeof(struct sock_filter))) { - pr_err("Corrupted filter len on tid %d (index %u)\n", - item->threads[i].ns[0].virt, sf->prev); + pr_err("Corrupted filter len on tid %d (index %u)\n", item->threads[i].ns[0].virt, + sf->prev); return -1; } filters_size += sf->filter.len; @@ -482,20 +470,20 @@ int seccomp_prepare_threads(struct pstree_item *item, struct task_restore_args * args->seccomp_filters_pos = rst_mem_align_cpos(RM_PRIVATE); args->seccomp_filters = rst_mem_alloc(rst_size, RM_PRIVATE); if (!args->seccomp_filters) { - pr_err("Can't allocate %zu bytes for filters on tid %d\n", - rst_size, item->threads[i].ns[0].virt); + pr_err("Can't allocate %zu bytes for filters on tid %d\n", rst_size, + item->threads[i].ns[0].virt); return -ENOMEM; } - args->seccomp_filters_data = (void *)args->seccomp_filters + - nr_filters * sizeof(struct thread_seccomp_filter); + args->seccomp_filters_data = + (void *)args->seccomp_filters + nr_filters * sizeof(struct thread_seccomp_filter); sf = seccomp_img_entry->seccomp_filters[thread_core->seccomp_filter]; for (j = off = 0; j < nr_filters; j++) { struct thread_seccomp_filter *f = &args->seccomp_filters[j]; - f->sock_fprog.len = sf->filter.len / sizeof(struct sock_filter); - f->sock_fprog.filter = args->seccomp_filters_data + off; - f->flags = sf->flags; + f->sock_fprog.len = sf->filter.len / sizeof(struct sock_filter); + f->sock_fprog.filter = args->seccomp_filters_data + off; + f->flags = sf->flags; memcpy(f->sock_fprog.filter, sf->filter.data, sf->filter.len); diff --git a/criu/seize.c b/criu/seize.c index e055a3796..95bf9ef0c 100644 --- a/criu/seize.c +++ b/criu/seize.c @@ -26,16 +26,11 @@ #define NR_ATTEMPTS 5 -static const char frozen[] = "FROZEN"; -static const char freezing[] = "FREEZING"; -static const char thawed[] = "THAWED"; +static const char frozen[] = "FROZEN"; +static const char freezing[] = "FREEZING"; +static const char thawed[] = "THAWED"; -enum freezer_state { - FREEZER_ERROR = -1, - THAWED, - FROZEN, - FREEZING -}; +enum freezer_state { FREEZER_ERROR = -1, THAWED, FROZEN, FREEZING }; /* Track if we are running on cgroup v2 system. */ static bool cgroup_v2 = false; @@ -45,8 +40,7 @@ static enum freezer_state get_freezer_v1_state(int fd) char state[32]; int ret; - BUILD_BUG_ON((sizeof(state) < sizeof(frozen)) || - (sizeof(state) < sizeof(freezing)) || + BUILD_BUG_ON((sizeof(state) < sizeof(frozen)) || (sizeof(state) < sizeof(freezing)) || (sizeof(state) < sizeof(thawed))); lseek(fd, 0, SEEK_SET); @@ -146,23 +140,19 @@ const char *get_real_freezer_state(void) static int freezer_write_state(int fd, enum freezer_state new_state) { - char state[32] = {0}; + char state[32] = { 0 }; int ret; if (new_state == THAWED) { if (cgroup_v2) state[0] = '0'; - else - if (strlcpy(state, thawed, sizeof(state)) >= - sizeof(state)) - return -1; + else if (strlcpy(state, thawed, sizeof(state)) >= sizeof(state)) + return -1; } else if (new_state == FROZEN) { if (cgroup_v2) state[0] = '1'; - else - if (strlcpy(state, frozen, sizeof(state)) >= - sizeof(state)) - return -1; + else if (strlcpy(state, frozen, sizeof(state)) >= sizeof(state)) + return -1; } else { return -1; } @@ -173,8 +163,7 @@ static int freezer_write_state(int fd, enum freezer_state new_state) return -1; } if (write(fd, state, sizeof(state)) != sizeof(state)) { - pr_perror("Unable to %s tasks", - (new_state == THAWED) ? "thaw" : "freeze"); + pr_perror("Unable to %s tasks", (new_state == THAWED) ? "thaw" : "freeze"); return -1; } @@ -188,8 +177,7 @@ static int freezer_open(void) char path[PATH_MAX]; int fd; - snprintf(path, sizeof(path), "%s/%s", opts.freeze_cgroup, - cgroup_v2 ? freezer_v2 : freezer_v1); + snprintf(path, sizeof(path), "%s/%s", opts.freeze_cgroup, cgroup_v2 ? freezer_v2 : freezer_v1); fd = open(path, O_RDWR); if (fd < 0) { pr_perror("Unable to open %s", path); @@ -221,8 +209,7 @@ static FILE *freezer_open_thread_list(char *root_path) char path[PATH_MAX]; FILE *f; - snprintf(path, sizeof(path), "%s/%s", root_path, - cgroup_v2 ? "cgroup.threads" : "tasks"); + snprintf(path, sizeof(path), "%s/%s", root_path, cgroup_v2 ? "cgroup.threads" : "tasks"); f = fopen(path, "r"); if (f == NULL) { pr_perror("Unable to open %s", path); @@ -425,7 +412,6 @@ static int log_unfrozen_stacks(char *root) stackbuf[ret] = '\0'; pr_debug("Task %d has stack:\n%s", pid, stackbuf); - } fclose(f); @@ -472,8 +458,8 @@ static int freeze_processes(void) unsigned long i = 0; const struct timespec req = { - .tv_nsec = step_ms * 1000000, - .tv_sec = 0, + .tv_nsec = step_ms * 1000000, + .tv_sec = 0, }; if (unlikely(!nr_attempts)) { @@ -484,8 +470,7 @@ static int freeze_processes(void) nr_attempts = (10 * 1000000) / step_ms; } - pr_debug("freezing processes: %lu attempts with %lu ms steps\n", - nr_attempts, step_ms); + pr_debug("freezing processes: %lu attempts with %lu ms steps\n", nr_attempts, step_ms); fd = freezer_open(); if (fd < 0) @@ -676,7 +661,6 @@ static void pstree_wait(struct pstree_item *root_item) int pid, status, i; for_each_pstree_item(item) { - if (item->pid->state == TASK_DEAD) continue; @@ -687,8 +671,7 @@ static void pstree_wait(struct pstree_item *root_item) break; } else { if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL) { - pr_err("Unexpected exit code %d of %d: %s\n", - status, pid, strsignal(status)); + pr_err("Unexpected exit code %d of %d: %s\n", status, pid, strsignal(status)); BUG(); } } @@ -791,8 +774,7 @@ static int collect_threads(struct pstree_item *item) nr_inprogress++; - pr_info("\tSeizing %d's %d thread\n", - item->pid->real, pid); + pr_info("\tSeizing %d's %d thread\n", item->pid->real, pid); if (!opts.freeze_cgroup && compel_interrupt_task(pid)) continue; @@ -846,8 +828,7 @@ err: return -1; } -static int collect_loop(struct pstree_item *item, - int (*collect)(struct pstree_item *)) +static int collect_loop(struct pstree_item *item, int (*collect)(struct pstree_item *)) { int attempts = NR_ATTEMPTS, nr_inprogress = 1; @@ -993,4 +974,3 @@ err: alarm(0); return ret; } - diff --git a/criu/servicefd.c b/criu/servicefd.c index 952410a8d..06a8d3eba 100644 --- a/criu/servicefd.c +++ b/criu/servicefd.c @@ -17,7 +17,7 @@ #include "rst_info.h" #include "servicefd.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "sfd: " /* Max potentially possible fd to be open by criu process */ @@ -41,21 +41,21 @@ bool sfds_protected = false; const char *sfd_type_name(enum sfd_type type) { static const char *names[] = { - [SERVICE_FD_MIN] = __stringify_1(SERVICE_FD_MIN), - [LOG_FD_OFF] = __stringify_1(LOG_FD_OFF), - [IMG_FD_OFF] = __stringify_1(IMG_FD_OFF), - [PROC_FD_OFF] = __stringify_1(PROC_FD_OFF), - [PROC_PID_FD_OFF] = __stringify_1(PROC_PID_FD_OFF), - [PROC_SELF_FD_OFF] = __stringify_1(PROC_SELF_FD_OFF), - [CR_PROC_FD_OFF] = __stringify_1(CR_PROC_FD_OFF), - [ROOT_FD_OFF] = __stringify_1(ROOT_FD_OFF), - [CGROUP_YARD] = __stringify_1(CGROUP_YARD), - [USERNSD_SK] = __stringify_1(USERNSD_SK), - [NS_FD_OFF] = __stringify_1(NS_FD_OFF), - [TRANSPORT_FD_OFF] = __stringify_1(TRANSPORT_FD_OFF), - [RPC_SK_OFF] = __stringify_1(RPC_SK_OFF), - [FDSTORE_SK_OFF] = __stringify_1(FDSTORE_SK_OFF), - [SERVICE_FD_MAX] = __stringify_1(SERVICE_FD_MAX), + [SERVICE_FD_MIN] = __stringify_1(SERVICE_FD_MIN), + [LOG_FD_OFF] = __stringify_1(LOG_FD_OFF), + [IMG_FD_OFF] = __stringify_1(IMG_FD_OFF), + [PROC_FD_OFF] = __stringify_1(PROC_FD_OFF), + [PROC_PID_FD_OFF] = __stringify_1(PROC_PID_FD_OFF), + [PROC_SELF_FD_OFF] = __stringify_1(PROC_SELF_FD_OFF), + [CR_PROC_FD_OFF] = __stringify_1(CR_PROC_FD_OFF), + [ROOT_FD_OFF] = __stringify_1(ROOT_FD_OFF), + [CGROUP_YARD] = __stringify_1(CGROUP_YARD), + [USERNSD_SK] = __stringify_1(USERNSD_SK), + [NS_FD_OFF] = __stringify_1(NS_FD_OFF), + [TRANSPORT_FD_OFF] = __stringify_1(TRANSPORT_FD_OFF), + [RPC_SK_OFF] = __stringify_1(RPC_SK_OFF), + [FDSTORE_SK_OFF] = __stringify_1(FDSTORE_SK_OFF), + [SERVICE_FD_MAX] = __stringify_1(SERVICE_FD_MAX), }; if (type < ARRAY_SIZE(names)) @@ -145,8 +145,7 @@ int service_fd_min_fd(struct pstree_item *item) static void sfds_protection_bug(enum sfd_type type) { - pr_err("Service fd %s is being modified in protected context\n", - sfd_type_name(type)); + pr_err("Service fd %s is being modified in protected context\n", sfd_type_name(type)); print_stack_trace(current ? vpid(current) : 0); BUG(); } @@ -173,8 +172,7 @@ int install_service_fd(enum sfd_type type, int fd) else tmp = dup3(fd, sfd, O_CLOEXEC); if (tmp < 0) { - pr_perror("%s dup %d -> %d failed", - sfd_type_name(type), fd, sfd); + pr_perror("%s dup %d -> %d failed", sfd_type_name(type), fd, sfd); close(fd); return -1; } else if (tmp != sfd) { @@ -219,7 +217,7 @@ void __close_service_fd(enum sfd_type type) static int move_service_fd(struct pstree_item *me, int type, int new_id, int new_base) { int old = get_service_fd(type); - int new = new_base - type - SERVICE_FD_MAX * new_id; + int new = new_base - type - SERVICE_FD_MAX *new_id; int ret; if (old < 0) @@ -230,8 +228,7 @@ static int move_service_fd(struct pstree_item *me, int type, int new_id, int new else ret = dup2(old, new); if (ret == -1) { - pr_perror("%s unable to clone %d->%d", - sfd_type_name(type), old, new); + pr_perror("%s unable to clone %d->%d", sfd_type_name(type), old, new); return -1; } else if (ret != new) { pr_err("%s busy target %d -> %d\n", sfd_type_name(type), old, new); @@ -254,8 +251,7 @@ static int choose_service_fd_base(struct pstree_item *me) } /* Now find process's max used fd number */ if (!list_empty(&rsti(me)->fds)) - nr = list_entry(rsti(me)->fds.prev, - struct fdinfo_list_entry, ps_list)->fe->fd; + nr = list_entry(rsti(me)->fds.prev, struct fdinfo_list_entry, ps_list)->fe->fd; else nr = -1; diff --git a/criu/shmem.c b/criu/shmem.c index 3de7170b8..1b83327ef 100644 --- a/criu/shmem.c +++ b/criu/shmem.c @@ -28,8 +28,8 @@ #include "images/pagemap.pb-c.h" #ifndef SEEK_DATA -#define SEEK_DATA 3 -#define SEEK_HOLE 4 +#define SEEK_DATA 3 +#define SEEK_HOLE 4 #endif /* @@ -41,23 +41,23 @@ * any tasks. Thus the heads are private (COW-ed) and the * entries are all in shmem. */ -#define SHMEM_HASH_SIZE 32 +#define SHMEM_HASH_SIZE 32 static struct hlist_head shmems_hash[SHMEM_HASH_SIZE]; -#define for_each_shmem(_i, _si) \ - for (_i = 0; _i < SHMEM_HASH_SIZE; _i++) \ +#define for_each_shmem(_i, _si) \ + for (_i = 0; _i < SHMEM_HASH_SIZE; _i++) \ hlist_for_each_entry(_si, &shmems_hash[_i], h) struct shmem_info { struct hlist_node h; - unsigned long shmid; + unsigned long shmid; /* * Owner PID. This guy creates anon shmem on restore and * from this the shmem is read on dump */ - int pid; - unsigned long size; + int pid; + unsigned long size; union { struct { /* For restore */ @@ -65,7 +65,7 @@ struct shmem_info { * Descriptor by which this shmem is opened * by the creator */ - int fd; + int fd; /* * 0. lock is initialized to zero @@ -74,38 +74,38 @@ struct shmem_info { * 3. the master waits all slaves on lock. After that * it can close the descriptor. */ - futex_t lock; + futex_t lock; /* * Here is a problem, that we don't know, which process will restore * an region. Each time when we found a process with a smaller pid, * we reset self_count, so we can't have only one counter. */ - int count; /* the number of regions */ - int self_count; /* the number of regions, which belongs to "pid" */ + int count; /* the number of regions */ + int self_count; /* the number of regions, which belongs to "pid" */ }; struct { /* For sysvipc restore */ struct list_head att; /* list of shmem_sysv_att-s */ - int want_write; + int want_write; }; struct { /* For dump */ - unsigned long start; - unsigned long end; - unsigned long *pstate_map; + unsigned long start; + unsigned long end; + unsigned long *pstate_map; }; }; }; struct shmem_sysv_att { struct list_head l; - VmaEntry *first; - unsigned long prev_end; + VmaEntry *first; + unsigned long prev_end; }; /* This is the "pid that will restore shmem" value for sysv */ -#define SYSVIPC_SHMEM_PID (-1) +#define SYSVIPC_SHMEM_PID (-1) static inline struct hlist_head *shmem_chain(unsigned long shmid) { @@ -134,12 +134,12 @@ static struct shmem_info *shmem_find(unsigned long shmid) } #define PST_DONT_DUMP 0 -#define PST_DUMP 1 -#define PST_ZERO 2 -#define PST_DIRTY 3 +#define PST_DUMP 1 +#define PST_ZERO 2 +#define PST_DIRTY 3 -#define PST_BITS 2 -#define PST_BIT0_IX(pfn) ((pfn) * PST_BITS) +#define PST_BITS 2 +#define PST_BIT0_IX(pfn) ((pfn)*PST_BITS) #define PST_BIT1_IX(pfn) (PST_BIT0_IX(pfn) + 1) /* @@ -169,8 +169,7 @@ static unsigned int get_pstate(unsigned long *pstate_map, unsigned long pfn) return (bit1 << 1) | bit0; } -static void set_pstate(unsigned long *pstate_map, unsigned long pfn, - unsigned int pstate) +static void set_pstate(unsigned long *pstate_map, unsigned long pfn, unsigned int pstate) { if (pstate & 1) set_bit(PST_BIT0_IX(pfn), pstate_map); @@ -258,7 +257,8 @@ int fixup_sysv_shmems(void) struct shmem_info *si; struct shmem_sysv_att *att; - for_each_shmem(i, si) { + for_each_shmem(i, si) + { /* It can be anon shmem */ if (si->pid != SYSVIPC_SHMEM_PID) continue; @@ -293,13 +293,12 @@ static int open_shmem_sysv(int pid, struct vma_area *vma) si = shmem_find(vme->shmid); if (!si) { - pr_err("Can't find sysv shmem for %"PRIx64"\n", vme->shmid); + pr_err("Can't find sysv shmem for %" PRIx64 "\n", vme->shmid); return -1; } if (si->pid != SYSVIPC_SHMEM_PID) { - pr_err("SysV shmem vma 0x%"PRIx64" points to anon vma %lx\n", - vme->start, si->shmid); + pr_err("SysV shmem vma 0x%" PRIx64 " points to anon vma %lx\n", vme->start, si->shmid); return -1; } @@ -360,7 +359,7 @@ static int open_shmem_sysv(int pid, struct vma_area *vma) ret_fd = SYSV_SHMEM_SKIP_FD; } - pr_info("Note 0x%"PRIx64"-0x%"PRIx64" as %lx sysvshmem\n", vme->start, vme->end, si->shmid); + pr_info("Note 0x%" PRIx64 "-0x%" PRIx64 " as %lx sysvshmem\n", vme->start, vme->end, si->shmid); att->prev_end = vme->end; if (!vme->has_fdflags || vme->fdflags == O_RDWR) @@ -394,7 +393,7 @@ int collect_shmem(int pid, struct vma_area *vma) si = shmem_find(vi->shmid); if (si) { if (si->pid == SYSVIPC_SHMEM_PID) { - pr_err("Shmem %"PRIx64" already collected as SYSVIPC\n", vi->shmid); + pr_err("Shmem %" PRIx64 " already collected as SYSVIPC\n", vi->shmid); return -1; } @@ -415,7 +414,7 @@ int collect_shmem(int pid, struct vma_area *vma) return 0; } - si->pid = pid; + si->pid = pid; si->self_count = 1; return 0; @@ -425,13 +424,12 @@ int collect_shmem(int pid, struct vma_area *vma) if (!si) return -1; - pr_info("Add new shmem 0x%"PRIx64" (%#016"PRIx64"-%#016"PRIx64")\n", - vi->shmid, vi->start, vi->end); + pr_info("Add new shmem 0x%" PRIx64 " (%#016" PRIx64 "-%#016" PRIx64 ")\n", vi->shmid, vi->start, vi->end); si->shmid = vi->shmid; - si->pid = pid; - si->size = size; - si->fd = -1; + si->pid = pid; + si->size = size; + si->fd = -1; si->count = 1; si->self_count = 1; futex_init(&si->lock); @@ -448,8 +446,7 @@ static int shmem_wait_and_open(struct shmem_info *si, VmaEntry *vi) pr_info("Waiting for the %lx shmem to appear\n", si->shmid); futex_wait_while(&si->lock, 0); - snprintf(path, sizeof(path), "/proc/%d/fd/%d", - si->pid, si->fd); + snprintf(path, sizeof(path), "/proc/%d/fd/%d", si->pid, si->fd); pr_info("Opening shmem [%s] \n", path); ret = open_proc_rw(si->pid, "fd/%d", si->fd); @@ -545,9 +542,9 @@ static int open_shmem(int pid, struct vma_area *vma) int flags; si = shmem_find(vi->shmid); - pr_info("Search for %#016"PRIx64" shmem 0x%"PRIx64" %p/%d\n", vi->start, vi->shmid, si, si ? si->pid : -1); + pr_info("Search for %#016" PRIx64 " shmem 0x%" PRIx64 " %p/%d\n", vi->start, vi->shmid, si, si ? si->pid : -1); if (!si) { - pr_err("Can't find my shmem %#016"PRIx64"\n", vi->start); + pr_err("Can't find my shmem %#016" PRIx64 "\n", vi->start); return -1; } @@ -591,8 +588,7 @@ static int open_shmem(int pid, struct vma_area *vma) */ addr = mmap(NULL, si->size, PROT_WRITE | PROT_READ, flags, f, 0); if (addr == MAP_FAILED) { - pr_perror("Can't mmap shmid=0x%"PRIx64" size=%ld", - vi->shmid, si->size); + pr_perror("Can't mmap shmid=0x%" PRIx64 " size=%ld", vi->shmid, si->size); goto err; } @@ -602,9 +598,7 @@ static int open_shmem(int pid, struct vma_area *vma) } if (f == -1) { - f = open_proc_rw(getpid(), "map_files/%lx-%lx", - (unsigned long) addr, - (unsigned long) addr + si->size); + f = open_proc_rw(getpid(), "map_files/%lx-%lx", (unsigned long)addr, (unsigned long)addr + si->size); if (f < 0) goto err; } @@ -670,9 +664,8 @@ static int dump_pages(struct page_pipe *pp, struct page_xfer *xfer) struct page_pipe_buf *ppb; list_for_each_entry(ppb, &pp->bufs, l) - if (vmsplice(ppb->p[1], ppb->iov, ppb->nr_segs, - SPLICE_F_GIFT | SPLICE_F_NONBLOCK) != - ppb->pages_in * PAGE_SIZE) { + if (vmsplice(ppb->p[1], ppb->iov, ppb->nr_segs, SPLICE_F_GIFT | SPLICE_F_NONBLOCK) != + ppb->pages_in * PAGE_SIZE) { pr_perror("Can't get shmem into page-pipe"); return -1; } @@ -680,13 +673,12 @@ static int dump_pages(struct page_pipe *pp, struct page_xfer *xfer) return page_xfer_dump_pages(xfer, pp); } -static int next_data_segment(int fd, unsigned long pfn, - unsigned long *next_data_pfn, unsigned long *next_hole_pfn) +static int next_data_segment(int fd, unsigned long pfn, unsigned long *next_data_pfn, unsigned long *next_hole_pfn) { off_t off; off = lseek(fd, pfn * PAGE_SIZE, SEEK_DATA); - if (off == (off_t) -1) { + if (off == (off_t)-1) { if (errno == ENXIO) { *next_data_pfn = ~0UL; *next_hole_pfn = ~0UL; @@ -698,7 +690,7 @@ static int next_data_segment(int fd, unsigned long pfn, *next_data_pfn = off / PAGE_SIZE; off = lseek(fd, off, SEEK_HOLE); - if (off == (off_t) -1) { + if (off == (off_t)-1) { pr_perror("Unable to lseek(SEEK_HOLE)"); return -1; } @@ -733,8 +725,7 @@ static int do_dump_one_shmem(int fd, void *addr, struct shmem_info *si) unsigned long pgaddr; int st = -1; - if (pfn >= next_hole_pfn && - next_data_segment(fd, pfn, &next_data_pnf, &next_hole_pfn)) + if (pfn >= next_hole_pfn && next_data_segment(fd, pfn, &next_data_pnf, &next_hole_pfn)) goto err_xfer; if (si->pstate_map && is_shmem_tracking_en()) { @@ -750,7 +741,7 @@ static int do_dump_one_shmem(int fd, void *addr, struct shmem_info *si) } pgaddr = (unsigned long)addr + pfn * PAGE_SIZE; -again: + again: if (pgstate == PST_ZERO) ret = 0; else if (xfer.parent && page_in_parent(pgstate == PST_DIRTY)) { @@ -801,8 +792,7 @@ static int dump_one_shmem(struct shmem_info *si) addr = mmap(NULL, si->size, PROT_READ, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { - pr_err("Can't map shmem 0x%lx (0x%lx-0x%lx)\n", - si->shmid, si->start, si->end); + pr_err("Can't map shmem 0x%lx (0x%lx-0x%lx)\n", si->shmid, si->start, si->end); goto errc; } @@ -856,8 +846,7 @@ int dump_one_sysv_shmem(void *addr, unsigned long size, unsigned long shmid) si = &det; } - fd = open_proc(PROC_SELF, "map_files/%lx-%lx", - (unsigned long)addr, (unsigned long)addr + si->size); + fd = open_proc(PROC_SELF, "map_files/%lx-%lx", (unsigned long)addr, (unsigned long)addr + si->size); if (fd < 0) return -1; @@ -871,7 +860,8 @@ int cr_dump_shmem(void) int ret = 0, i; struct shmem_info *si; - for_each_shmem(i, si) { + for_each_shmem(i, si) + { if (si->pid == SYSVIPC_SHMEM_PID) continue; ret = dump_one_shmem(si); diff --git a/criu/sigframe.c b/criu/sigframe.c index b8798efc3..0f5d891b0 100644 --- a/criu/sigframe.c +++ b/criu/sigframe.c @@ -5,23 +5,21 @@ #include "images/core.pb-c.h" #ifndef setup_sas -static inline void setup_sas(struct rt_sigframe* sigframe, ThreadSasEntry *sas) +static inline void setup_sas(struct rt_sigframe *sigframe, ThreadSasEntry *sas) { if (sas) { -#define UC RT_SIGFRAME_UC(sigframe) +#define UC RT_SIGFRAME_UC(sigframe) - UC->uc_stack.ss_sp = (void *)decode_pointer((sas)->ss_sp); - UC->uc_stack.ss_flags = (int)(sas)->ss_flags; - UC->uc_stack.ss_size = (size_t)(sas)->ss_size; + UC->uc_stack.ss_sp = (void *)decode_pointer((sas)->ss_sp); + UC->uc_stack.ss_flags = (int)(sas)->ss_flags; + UC->uc_stack.ss_size = (size_t)(sas)->ss_size; #undef UC } } #endif -int construct_sigframe(struct rt_sigframe *sigframe, - struct rt_sigframe *rsigframe, - k_rtsigset_t *blkset, - CoreEntry *core) +int construct_sigframe(struct rt_sigframe *sigframe, struct rt_sigframe *rsigframe, k_rtsigset_t *blkset, + CoreEntry *core) { /* * Copy basic register set in the first place: this will set diff --git a/criu/signalfd.c b/criu/signalfd.c index 1bb87d08c..c71ad87c7 100644 --- a/criu/signalfd.c +++ b/criu/signalfd.c @@ -15,8 +15,8 @@ #include "images/signalfd.pb-c.h" struct signalfd_info { - SignalfdEntry *sfe; - struct file_desc d; + SignalfdEntry *sfe; + struct file_desc d; }; int is_signalfd_link(char *link) @@ -44,8 +44,8 @@ static int dump_one_signalfd(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops signalfd_dump_ops = { - .type = FD_TYPES__SIGNALFD, - .dump = dump_one_signalfd, + .type = FD_TYPES__SIGNALFD, + .dump = dump_one_signalfd, }; static void sigset_fill(sigset_t *to, unsigned long long from) @@ -78,8 +78,7 @@ static int signalfd_open(struct file_desc *d, int *new_fd) } if (rst_file_params(tmp, info->sfe->fown, info->sfe->flags)) { - pr_perror("Can't restore params on signalfd %#08x", - info->sfe->id); + pr_perror("Can't restore params on signalfd %#08x", info->sfe->id); goto err_close; } diff --git a/criu/sk-inet.c b/criu/sk-inet.c index d90c53b17..e52b198c3 100644 --- a/criu/sk-inet.c +++ b/criu/sk-inet.c @@ -36,11 +36,11 @@ #include "images/inventory.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "inet: " -#define PB_ALEN_INET 1 -#define PB_ALEN_INET6 4 +#define PB_ALEN_INET 1 +#define PB_ALEN_INET6 4 static LIST_HEAD(inet_ports); @@ -87,34 +87,28 @@ static void show_one_inet(const char *act, const struct inet_sk_desc *sk) { char src_addr[INET_ADDR_LEN] = "<unknown>"; - if (inet_ntop(sk->sd.family, (void *)sk->src_addr, src_addr, - INET_ADDR_LEN) == NULL) { + if (inet_ntop(sk->sd.family, (void *)sk->src_addr, src_addr, INET_ADDR_LEN) == NULL) { pr_perror("Failed to translate address"); } pr_debug("\t%s: ino %#8x family %-10s type %-14s port %8d " - "state %-16s src_addr %s\n", act, sk->sd.ino, - ___socket_family_name(sk->sd.family), - ___socket_type_name(sk->type), sk->src_port, - ___tcp_state_name(sk->state), src_addr); + "state %-16s src_addr %s\n", + act, sk->sd.ino, ___socket_family_name(sk->sd.family), ___socket_type_name(sk->type), sk->src_port, + ___tcp_state_name(sk->state), src_addr); } static void show_one_inet_img(const char *act, const InetSkEntry *e) { char src_addr[INET_ADDR_LEN] = "<unknown>"; - if (inet_ntop(e->family, (void *)e->src_addr, src_addr, - INET_ADDR_LEN) == NULL) { + if (inet_ntop(e->family, (void *)e->src_addr, src_addr, INET_ADDR_LEN) == NULL) { pr_perror("Failed to translate address"); } pr_debug("\t%s: family %-10s type %-14s proto %-16s port %d " - "state %-16s src_addr %s\n", act, - ___socket_family_name(e->family), - ___socket_type_name(e->type), - ___socket_proto_name(e->proto), - e->src_port, ___tcp_state_name(e->state), - src_addr); + "state %-16s src_addr %s\n", + act, ___socket_family_name(e->family), ___socket_type_name(e->type), ___socket_proto_name(e->proto), + e->src_port, ___tcp_state_name(e->state), src_addr); } static int can_dump_ipproto(unsigned int ino, int proto, int type) @@ -145,26 +139,23 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk) if (sk->type == SOCK_DGRAM) { if (sk->wqlen != 0) { if (sk->cork) { - pr_err("Can't dump corked dgram socket %x\n", - sk->sd.ino); + pr_err("Can't dump corked dgram socket %x\n", sk->sd.ino); return 0; } else { - pr_warn("Write queue of the %x socket isn't empty\n", - sk->sd.ino); + pr_warn("Write queue of the %x socket isn't empty\n", sk->sd.ino); } } if (sk->rqlen) - pr_warn("Read queue is dropped for socket %x\n", - sk->sd.ino); + pr_warn("Read queue is dropped for socket %x\n", sk->sd.ino); return 1; } if (sk->type != SOCK_STREAM && sk->type != SOCK_RAW) { pr_err("Can't dump %d inet socket %x. " - "Only stream, dgram and raw are supported.\n", - sk->type, sk->sd.ino); + "Only stream, dgram and raw are supported.\n", + sk->type, sk->sd.ino); return 0; } @@ -172,8 +163,7 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk) case TCP_LISTEN: if (sk->rqlen != 0) { if (opts.tcp_skip_in_flight) { - pr_info("Skipping in-flight connection (l) for %x\n", - sk->sd.ino); + pr_info("Skipping in-flight connection (l) for %x\n", sk->sd.ino); break; } /* @@ -181,10 +171,10 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk) * requests for listen sockets. Need to pick * those up and fix the connect job respectively */ - pr_err("In-flight connection (l) for %x\n", - sk->sd.ino); + pr_err("In-flight connection (l) for %x\n", sk->sd.ino); pr_err("In-flight connections can be ignored with the " - "--%s option.\n", SK_INFLIGHT_PARAM); + "--%s option.\n", + SK_INFLIGHT_PARAM); return 0; } break; @@ -196,8 +186,7 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk) case TCP_CLOSING: case TCP_SYN_SENT: if (!opts.tcp_established_ok && !opts.tcp_close) { - pr_err("Connected TCP socket, consider using --%s option.\n", - SK_EST_PARAM); + pr_err("Connected TCP socket, consider using --%s option.\n", SK_EST_PARAM); return 0; } break; @@ -218,7 +207,8 @@ static int dump_sockaddr(union libsoccr_addr *sa, u32 *pb_port, u32 *pb_addr) memcpy(pb_addr, &sa->v4.sin_addr, sizeof(sa->v4.sin_addr)); *pb_port = ntohs(sa->v4.sin_port); return 0; - } if (sa->sa.sa_family == AF_INET6) { + } + if (sa->sa.sa_family == AF_INET6) { *pb_port = ntohs(sa->v6.sin6_port); memcpy(pb_addr, &sa->v6.sin6_addr, sizeof(sa->v6.sin6_addr)); return 0; @@ -232,7 +222,7 @@ static int dump_sockaddr(union libsoccr_addr *sa, u32 *pb_port, u32 *pb_addr) */ static int dump_tcp_uncon_shutdown(int lfd, struct inet_sk_desc *sk) { - struct pollfd pfd = {.fd = lfd, .events = POLLRDHUP | POLLHUP}; + struct pollfd pfd = { .fd = lfd, .events = POLLRDHUP | POLLHUP }; if (poll(&pfd, 1, 0) != 1) { pr_perror("Unable to poll the socket"); @@ -250,9 +240,7 @@ static int dump_tcp_uncon_shutdown(int lfd, struct inet_sk_desc *sk) return 0; } - -static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p, - int proto, int family, int type) +static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p, int proto, int family, int type) { struct inet_sk_desc *sk; union libsoccr_addr address; @@ -304,12 +292,12 @@ static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p, if (type != SOCK_RAW && proto == IPPROTO_TCP) { struct { - __u8 tcpi_state; - __u8 tcpi_ca_state; - __u8 tcpi_retransmits; - __u8 tcpi_probes; - __u8 tcpi_backoff; - __u8 tcpi_options; + __u8 tcpi_state; + __u8 tcpi_ca_state; + __u8 tcpi_retransmits; + __u8 tcpi_probes; + __u8 tcpi_backoff; + __u8 tcpi_options; } info; aux = sizeof(info); @@ -320,8 +308,7 @@ static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p, } if (info.tcpi_state != TCP_CLOSE) { - pr_err("Socket state %d obtained but expected %d\n", - info.tcpi_state, TCP_CLOSE); + pr_err("Socket state %d obtained but expected %d\n", info.tcpi_state, TCP_CLOSE); goto err; } @@ -345,14 +332,11 @@ static int ip_raw_opts_alloc(int family, int proto, IpOptsRawEntry *r) { if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) { if (family == AF_INET6) - r->n_icmpv_filter = NELEMS_AS_ARRAY(struct icmp6_filter, - r->icmpv_filter); + r->n_icmpv_filter = NELEMS_AS_ARRAY(struct icmp6_filter, r->icmpv_filter); else - r->n_icmpv_filter = NELEMS_AS_ARRAY(struct icmp_filter, - r->icmpv_filter); + r->n_icmpv_filter = NELEMS_AS_ARRAY(struct icmp_filter, r->icmpv_filter); r->icmpv_filter = xmalloc(pb_repeated_size(r, icmpv_filter)); - pr_debug("r->n_icmpv_filter %d size %d\n", - (int)r->n_icmpv_filter, + pr_debug("r->n_icmpv_filter %d size %d\n", (int)r->n_icmpv_filter, (int)pb_repeated_size(r, icmpv_filter)); if (!r->icmpv_filter) return -ENOMEM; @@ -384,8 +368,7 @@ static int dump_ip_raw_opts(int sk, int family, int proto, IpOptsRawEntry *r) ret |= dump_opt(sk, SOL_IPV6, IPV6_HDRINCL, &r->hdrincl); if (proto == IPPROTO_ICMPV6) - ret |= do_dump_opt(sk, SOL_ICMPV6, ICMPV6_FILTER, - r->icmpv_filter, + ret |= do_dump_opt(sk, SOL_ICMPV6, ICMPV6_FILTER, r->icmpv_filter, pb_repeated_size(r, icmpv_filter)); else ip_raw_opts_free(r); @@ -395,8 +378,7 @@ static int dump_ip_raw_opts(int sk, int family, int proto, IpOptsRawEntry *r) r->has_nodefrag = !!r->nodefrag; if (proto == IPPROTO_ICMP) - ret |= do_dump_opt(sk, SOL_RAW, ICMP_FILTER, - r->icmpv_filter, + ret |= do_dump_opt(sk, SOL_RAW, ICMP_FILTER, r->icmpv_filter, pb_repeated_size(r, icmpv_filter)); else ip_raw_opts_free(r); @@ -429,12 +411,12 @@ static int dump_ip_opts(int sk, int family, int type, int proto, IpOptsEntry *io * link local and (multicast + loopback + linklocal) addrs require a * scope id. */ -#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 -#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 +#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 +#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 static bool needs_scope_id(uint32_t *src_addr) { if ((src_addr[0] & htonl(0xFF00000)) == htonl(0xFF000000)) { - if (src_addr[1] & (IPV6_ADDR_SCOPE_LINKLOCAL|IPV6_ADDR_SCOPE_NODELOCAL)) + if (src_addr[1] & (IPV6_ADDR_SCOPE_LINKLOCAL | IPV6_ADDR_SCOPE_NODELOCAL)) return true; } @@ -454,8 +436,7 @@ static int do_dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p, int fa SkOptsEntry skopts = SK_OPTS_ENTRY__INIT; int ret = -1, err = -1, proto, aux, type; - ret = do_dump_opt(lfd, SOL_SOCKET, SO_PROTOCOL, - &proto, sizeof(proto)); + ret = do_dump_opt(lfd, SOL_SOCKET, SO_PROTOCOL, &proto, sizeof(proto)); if (ret) goto err; @@ -502,24 +483,24 @@ static int do_dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p, int fa BUG_ON(sk->sd.already_dumped); - ie.id = id; - ie.ino = sk->sd.ino; + ie.id = id; + ie.ino = sk->sd.ino; if (sk->sd.sk_ns) { - ie.ns_id = sk->sd.sk_ns->id; - ie.has_ns_id = true; + ie.ns_id = sk->sd.sk_ns->id; + ie.has_ns_id = true; } - ie.family = family; - ie.proto = proto; - ie.type = sk->type; - ie.src_port = sk->src_port; - ie.dst_port = sk->dst_port; - ie.backlog = sk->wqlen; - ie.flags = p->flags; - - ie.fown = (FownEntry *)&p->fown; - ie.opts = &skopts; - ie.ip_opts = &ipopts; - ie.ip_opts->raw = &ipopts_raw; + ie.family = family; + ie.proto = proto; + ie.type = sk->type; + ie.src_port = sk->src_port; + ie.dst_port = sk->dst_port; + ie.backlog = sk->wqlen; + ie.flags = p->flags; + + ie.fown = (FownEntry *)&p->fown; + ie.opts = &skopts; + ie.ip_opts = &ipopts; + ie.ip_opts->raw = &ipopts_raw; ie.n_src_addr = PB_ALEN_INET; ie.n_dst_addr = PB_ALEN_INET; @@ -620,8 +601,8 @@ static int dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops inet_dump_ops = { - .type = FD_TYPES__INETSK, - .dump = dump_one_inet_fd, + .type = FD_TYPES__INETSK, + .dump = dump_one_inet_fd, }; static int dump_one_inet6_fd(int lfd, u32 id, const struct fd_parms *p) @@ -630,15 +611,15 @@ static int dump_one_inet6_fd(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops inet6_dump_ops = { - .type = FD_TYPES__INETSK, - .dump = dump_one_inet6_fd, + .type = FD_TYPES__INETSK, + .dump = dump_one_inet6_fd, }; int inet_collect_one(struct nlmsghdr *h, int family, int type, struct ns_id *ns) { struct inet_sk_desc *d; struct inet_diag_msg *m = NLMSG_DATA(h); - struct nlattr *tb[INET_DIAG_MAX+1]; + struct nlattr *tb[INET_DIAG_MAX + 1]; int ret; nlmsg_parse(h, sizeof(struct inet_diag_msg), tb, INET_DIAG_MAX, NULL); @@ -711,19 +692,15 @@ struct collect_image_info inet_sk_cinfo = { static int inet_validate_address(InetSkEntry *ie) { if ((ie->family == AF_INET) && - /* v0.1 had 4 in ipv4 addr len */ - (ie->n_src_addr >= PB_ALEN_INET) && - (ie->n_dst_addr >= PB_ALEN_INET)) + /* v0.1 had 4 in ipv4 addr len */ + (ie->n_src_addr >= PB_ALEN_INET) && (ie->n_dst_addr >= PB_ALEN_INET)) return 0; - if ((ie->family == AF_INET6) && - (ie->n_src_addr == PB_ALEN_INET6) && - (ie->n_dst_addr == PB_ALEN_INET6)) + if ((ie->family == AF_INET6) && (ie->n_src_addr == PB_ALEN_INET6) && (ie->n_dst_addr == PB_ALEN_INET6)) return 0; - pr_err("Addr len mismatch f %d ss %zu ds %zu\n", ie->family, - pb_repeated_size(ie, src_addr), - pb_repeated_size(ie, dst_addr)); + pr_err("Addr len mismatch f %d ss %zu ds %zu\n", ie->family, pb_repeated_size(ie, src_addr), + pb_repeated_size(ie, dst_addr)); return -1; } @@ -792,8 +769,8 @@ static int restore_ip_raw_opts(int sk, int family, int proto, IpOptsRawEntry *r) if (r->icmpv_filter) { if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) { ret |= do_restore_opt(sk, family == AF_INET6 ? SOL_ICMPV6 : SOL_RAW, - family == AF_INET6 ? ICMPV6_FILTER : ICMP_FILTER, - r->icmpv_filter, pb_repeated_size(r, icmpv_filter)); + family == AF_INET6 ? ICMPV6_FILTER : ICMP_FILTER, r->icmpv_filter, + pb_repeated_size(r, icmpv_filter)); } } @@ -801,8 +778,7 @@ static int restore_ip_raw_opts(int sk, int family, int proto, IpOptsRawEntry *r) ret |= restore_opt(sk, SOL_IP, IP_NODEFRAG, &r->nodefrag); if (r->has_hdrincl) ret |= restore_opt(sk, family == AF_INET6 ? SOL_IPV6 : SOL_IP, - family == AF_INET6 ? IPV6_HDRINCL : IP_HDRINCL, - &r->hdrincl); + family == AF_INET6 ? IPV6_HDRINCL : IP_HDRINCL, &r->hdrincl); return ret; } @@ -916,8 +892,7 @@ static int open_inet_sk(struct file_desc *d, int *new_fd) mutex_unlock(&ii->port->reuseaddr_lock); } - if (ie->dst_port && - inet_connect(sk, ii)) + if (ie->dst_port && inet_connect(sk, ii)) goto err; done: dec_users_and_wake(ii->port); @@ -932,16 +907,15 @@ done: goto err; if (ie->has_shutdown && - (ie->proto == IPPROTO_UDP || - ie->proto == IPPROTO_UDPLITE || ie->proto == IPPROTO_TCP)) { + (ie->proto == IPPROTO_UDP || ie->proto == IPPROTO_UDPLITE || ie->proto == IPPROTO_TCP)) { if (shutdown(sk, sk_decode_shutdown(ie->shutdown))) { if (ie->state != TCP_CLOSE && errno != ENOTCONN) { - pr_perror("Can't shutdown socket into %d", - sk_decode_shutdown(ie->shutdown)); + pr_perror("Can't shutdown socket into %d", sk_decode_shutdown(ie->shutdown)); goto err; } else { pr_debug("Called shutdown on closed socket, " - "proto %d ino %x", ie->proto, ie->ino); + "proto %d ino %x", + ie->proto, ie->ino); } } } @@ -954,8 +928,7 @@ err: return -1; } -int restore_sockaddr(union libsoccr_addr *sa, - int family, u32 pb_port, u32 *pb_addr, u32 ifindex) +int restore_sockaddr(union libsoccr_addr *sa, int family, u32 pb_port, u32 *pb_addr, u32 ifindex) { BUILD_BUG_ON(sizeof(sa->v4.sin_addr.s_addr) > PB_ALEN_INET * sizeof(u32)); BUILD_BUG_ON(sizeof(sa->v6.sin6_addr.s6_addr) > PB_ALEN_INET6 * sizeof(u32)); @@ -1000,8 +973,7 @@ int inet_bind(int sk, struct inet_sk_info *ii) } } - addr_size = restore_sockaddr(&addr, ii->ie->family, - ii->ie->src_port, ii->ie->src_addr, ifindex); + addr_size = restore_sockaddr(&addr, ii->ie->family, ii->ie->src_port, ii->ie->src_addr, ifindex); /* * ipv6 addresses go through a “tentative” phase and @@ -1048,8 +1020,7 @@ int inet_connect(int sk, struct inet_sk_info *ii) union libsoccr_addr addr; int addr_size; - addr_size = restore_sockaddr(&addr, ii->ie->family, - ii->ie->dst_port, ii->ie->dst_addr, 0); + addr_size = restore_sockaddr(&addr, ii->ie->family, ii->ie->dst_port, ii->ie->dst_addr, 0); if (connect(sk, (struct sockaddr *)&addr, addr_size) == -1) { pr_perror("Can't connect inet socket back"); diff --git a/criu/sk-netlink.c b/criu/sk-netlink.c index 3b86a7d7b..754eed932 100644 --- a/criu/sk-netlink.c +++ b/criu/sk-netlink.c @@ -14,23 +14,23 @@ #include "libnetlink.h" #include "namespaces.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "netlink: " struct netlink_sk_desc { - struct socket_desc sd; - u32 portid; - u32 *groups; - u32 gsize; - u32 dst_portid; - u32 dst_group; - u8 state; - u8 protocol; + struct socket_desc sd; + u32 portid; + u32 *groups; + u32 gsize; + u32 dst_portid; + u32 dst_group; + u8 state; + u8 protocol; }; int netlink_receive_one(struct nlmsghdr *hdr, struct ns_id *ns, void *arg) { - struct nlattr *tb[NETLINK_DIAG_MAX+1]; + struct nlattr *tb[NETLINK_DIAG_MAX + 1]; struct netlink_diag_msg *m; struct netlink_sk_desc *sd; unsigned long *groups; @@ -105,7 +105,6 @@ static int dump_one_netlink_fd(int lfd, u32 id, const struct fd_parms *p) ne.portid = sk->portid; ne.groups = sk->groups; - ne.n_groups = sk->gsize / sizeof(ne.groups[0]); /* * On 64-bit sk->gsize is multiple to 8 bytes (sizeof(long)), @@ -164,7 +163,7 @@ static int dump_one_netlink_fd(int lfd, u32 id, const struct fd_parms *p) } ne.fown = (FownEntry *)&p->fown; - ne.opts = &skopts; + ne.opts = &skopts; if (dump_socket_opts(lfd, &skopts)) goto err; @@ -182,8 +181,8 @@ err: } const struct fdtype_ops netlink_dump_ops = { - .type = FD_TYPES__NETLINKSK, - .dump = dump_one_netlink_fd, + .type = FD_TYPES__NETLINKSK, + .dump = dump_one_netlink_fd, }; struct netlink_sock_info { diff --git a/criu/sk-packet.c b/criu/sk-packet.c index 0abe84071..1d2e23522 100644 --- a/criu/sk-packet.c +++ b/criu/sk-packet.c @@ -22,7 +22,7 @@ #include "images/fdinfo.pb-c.h" #include "namespaces.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "packet: " struct packet_sock_info { @@ -31,10 +31,10 @@ struct packet_sock_info { }; struct packet_mreq_max { - int mr_ifindex; - unsigned short mr_type; - unsigned short mr_alen; - unsigned char mr_address[MAX_ADDR_LEN]; + int mr_ifindex; + unsigned short mr_type; + unsigned short mr_alen; + unsigned char mr_address[MAX_ADDR_LEN]; }; struct packet_sock_desc { @@ -49,7 +49,7 @@ struct packet_sock_desc { struct packet_diag_ring *rx, *tx; }; -#define NO_FANOUT ((unsigned int)-1) +#define NO_FANOUT ((unsigned int)-1) static int dump_mreqs(PacketSockEntry *psk, struct packet_sock_desc *sd) { @@ -72,8 +72,7 @@ static int dump_mreqs(PacketSockEntry *psk, struct packet_sock_desc *sd) goto err; } - pr_debug("\tmr%d: idx %d type %d\n", i, - m->pdmc_index, m->pdmc_type); + pr_debug("\tmr%d: idx %d type %d\n", i, m->pdmc_index, m->pdmc_type); im = xmalloc(sizeof(*im)); if (!im) @@ -87,21 +86,21 @@ static int dump_mreqs(PacketSockEntry *psk, struct packet_sock_desc *sd) im->type = m->pdmc_type; switch (m->pdmc_type) { - case PACKET_MR_MULTICAST: - case PACKET_MR_UNICAST: - im->addr.len = m->pdmc_alen; - im->addr.data = xmalloc(m->pdmc_alen); - if (!im->addr.data) - goto err; - - memcpy(im->addr.data, m->pdmc_addr, m->pdmc_alen); - break; - case PACKET_MR_PROMISC: - case PACKET_MR_ALLMULTI: - break; - default: - pr_err("Unknown mc membership type %d\n", m->pdmc_type); + case PACKET_MR_MULTICAST: + case PACKET_MR_UNICAST: + im->addr.len = m->pdmc_alen; + im->addr.data = xmalloc(m->pdmc_alen); + if (!im->addr.data) goto err; + + memcpy(im->addr.data, m->pdmc_addr, m->pdmc_alen); + break; + case PACKET_MR_PROMISC: + case PACKET_MR_ALLMULTI: + break; + default: + pr_err("Unknown mc membership type %d\n", m->pdmc_type); + goto err; } } @@ -158,7 +157,7 @@ static int dump_one_packet_fd(int lfd, u32 id, const struct fd_parms *p) sd = (struct packet_sock_desc *)lookup_socket(p->stat.st_ino, PF_PACKET, 0); if (IS_ERR_OR_NULL(sd)) { - pr_err("Can't find packet socket %"PRIu64"\n", p->stat.st_ino); + pr_err("Can't find packet socket %" PRIu64 "\n", p->stat.st_ino); return -1; } @@ -217,8 +216,8 @@ out: } const struct fdtype_ops packet_dump_ops = { - .type = FD_TYPES__PACKETSK, - .dump = dump_one_packet_fd, + .type = FD_TYPES__PACKETSK, + .dump = dump_one_packet_fd, }; int dump_socket_map(struct vma_area *vma) @@ -236,7 +235,7 @@ int dump_socket_map(struct vma_area *vma) return -1; } - pr_info("Dumping socket map %x -> %"PRIx64"\n", sd->file_id, vma->e->start); + pr_info("Dumping socket map %x -> %" PRIx64 "\n", sd->file_id, vma->e->start); vma->e->shmid = sd->file_id; return 0; } @@ -260,8 +259,7 @@ int packet_receive_one(struct nlmsghdr *hdr, struct ns_id *ns, void *arg) struct packet_sock_desc *sd; m = NLMSG_DATA(hdr); - nlmsg_parse(hdr, sizeof(struct packet_diag_msg), - tb, PACKET_DIAG_MAX, NULL); + nlmsg_parse(hdr, sizeof(struct packet_diag_msg), tb, PACKET_DIAG_MAX, NULL); pr_info("Collect packet sock %u %u\n", m->pdiag_ino, (unsigned int)m->pdiag_num); if (!tb[PACKET_DIAG_INFO]) { @@ -321,8 +319,7 @@ static int open_socket_map(int pid, struct vma_area *vm) struct file_desc *fd; struct fdinfo_list_entry *le; - pr_info("Getting packet socket fd for %d:%x\n", - pid, (int)vma->shmid); + pr_info("Getting packet socket fd for %d:%x\n", pid, (int)vma->shmid); fd = find_file_desc_raw(FD_TYPES__PACKETSK, vma->shmid); if (!fd) { pr_err("No packet socket %x\n", (int)vma->shmid); diff --git a/criu/sk-queue.c b/criu/sk-queue.c index 776eb5aaf..dbd9d1d8b 100644 --- a/criu/sk-queue.c +++ b/criu/sk-queue.c @@ -23,15 +23,15 @@ #include "protobuf.h" #include "images/sk-packet.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "skqueue: " struct sk_packet { - struct list_head list; - SkPacketEntry *entry; - char *data; - unsigned scm_len; - int *scm; + struct list_head list; + SkPacketEntry *entry; + char *data; + unsigned scm_len; + int *scm; }; static LIST_HEAD(packets_list); @@ -43,7 +43,7 @@ static int collect_one_packet(void *obj, ProtobufCMessage *msg, struct cr_img *i pkt->entry = pb_msg(msg, SkPacketEntry); pkt->scm = NULL; pkt->data = xmalloc(pkt->entry->length); - if (pkt->data ==NULL) + if (pkt->data == NULL) return -1; /* @@ -105,7 +105,7 @@ static int dump_scm_rights(struct cmsghdr *ch, SkPacketEntry *pe) } i = pe->n_scm++; - if (xrealloc_safe(&pe->scm, pe->n_scm * sizeof(ScmEntry*))) + if (xrealloc_safe(&pe->scm, pe->n_scm * sizeof(ScmEntry *))) return -1; pe->scm[i] = scme; @@ -116,7 +116,7 @@ static int dump_scm_rights(struct cmsghdr *ch, SkPacketEntry *pe) * Maximum size of the control messages. XXX -- is there any * way to get this value out of the kernel? * */ -#define CMSG_MAX_SIZE 1024 +#define CMSG_MAX_SIZE 1024 static int dump_packet_cmsg(struct msghdr *mh, SkPacketEntry *pe) { @@ -212,14 +212,14 @@ int dump_sk_queue(int sock_fd, int sock_id) while (1) { char cmsg[CMSG_MAX_SIZE]; struct iovec iov = { - .iov_base = data, - .iov_len = size, + .iov_base = data, + .iov_len = size, }; struct msghdr msg = { - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = &cmsg, - .msg_controllen = sizeof(cmsg), + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = &cmsg, + .msg_controllen = sizeof(cmsg), }; ret = pe.length = recvmsg(sock_fd, &msg, MSG_DONTWAIT | MSG_PEEK); @@ -312,8 +312,7 @@ static int send_one_pkt(int fd, struct sk_packet *pkt) return -1; } if (ret != entry->length) { - pr_err("Restored skb trimmed to %d/%d\n", - ret, (unsigned int)entry->length); + pr_err("Restored skb trimmed to %d/%d\n", ret, (unsigned int)entry->length); return -1; } @@ -336,8 +335,7 @@ int restore_sk_queue(int fd, unsigned int peer_id) if (entry->id_for != peer_id) continue; - pr_info("\tRestoring %d-bytes skb for %u\n", - (unsigned int)entry->length, peer_id); + pr_info("\tRestoring %d-bytes skb for %u\n", (unsigned int)entry->length, peer_id); ret = send_one_pkt(fd, pkt); if (ret) @@ -379,8 +377,7 @@ int prepare_scms(void) ch->cmsg_type = SCM_RIGHTS; ch->cmsg_len = CMSG_LEN(se->n_rights * sizeof(int)); - if (unix_note_scm_rights(pe->id_for, se->rights, - (int *)CMSG_DATA(ch), se->n_rights)) + if (unix_note_scm_rights(pe->id_for, se->rights, (int *)CMSG_DATA(ch), se->n_rights)) return -1; continue; diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c index 0409e22c3..8e78fca8c 100644 --- a/criu/sk-tcp.c +++ b/criu/sk-tcp.c @@ -27,7 +27,7 @@ #include "protobuf.h" #include "images/tcp-stream.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "tcp: " static LIST_HEAD(cpt_tcp_repair_sockets); @@ -120,8 +120,7 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk) goto err_r; } if (ret != sizeof(data)) { - pr_err("This libsocr is not supported (%d vs %d)\n", - ret, (int)sizeof(data)); + pr_err("This libsocr is not supported (%d vs %d)\n", ret, (int)sizeof(data)); goto err_r; } @@ -147,16 +146,16 @@ static int dump_tcp_conn_state(struct inet_sk_desc *sk) } if (data.flags & SOCCR_FLAGS_WINDOW) { - tse.has_snd_wl1 = true; - tse.has_snd_wnd = true; - tse.has_max_window = true; - tse.has_rcv_wnd = true; - tse.has_rcv_wup = true; - tse.snd_wl1 = data.snd_wl1; - tse.snd_wnd = data.snd_wnd; - tse.max_window = data.max_window; - tse.rcv_wnd = data.rcv_wnd; - tse.rcv_wup = data.rcv_wup; + tse.has_snd_wl1 = true; + tse.has_snd_wnd = true; + tse.has_max_window = true; + tse.has_rcv_wnd = true; + tse.has_rcv_wup = true; + tse.snd_wl1 = data.snd_wl1; + tse.snd_wnd = data.snd_wnd; + tse.max_window = data.max_window; + tse.rcv_wnd = data.rcv_wnd; + tse.rcv_wup = data.rcv_wup; } /* @@ -260,8 +259,7 @@ int dump_one_tcp(int fd, struct inet_sk_desc *sk, SkOptsEntry *soe) return 0; } -static int read_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, - int queue, u32 len, struct cr_img *img) +static int read_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, int queue, u32 len, struct cr_img *img) { char *buf; @@ -351,13 +349,9 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_ data.rcv_wup = tse->rcv_wup; } - if (restore_sockaddr(&sa_src, - ii->ie->family, ii->ie->src_port, - ii->ie->src_addr, 0) < 0) + if (restore_sockaddr(&sa_src, ii->ie->family, ii->ie->src_port, ii->ie->src_addr, 0) < 0) goto err_c; - if (restore_sockaddr(&sa_dst, - ii->ie->family, ii->ie->dst_port, - ii->ie->dst_addr, 0) < 0) + if (restore_sockaddr(&sa_dst, ii->ie->family, ii->ie->dst_port, ii->ie->dst_addr, 0) < 0) goto err_c; libsoccr_set_addr(socr, 1, &sa_src, 0); @@ -403,7 +397,7 @@ int prepare_tcp_socks(struct task_restore_args *ta) { struct inet_sk_info *ii; - ta->tcp_socks = (struct rst_tcp_sock *) rst_mem_align_cpos(RM_PRIVATE); + ta->tcp_socks = (struct rst_tcp_sock *)rst_mem_align_cpos(RM_PRIVATE); ta->tcp_socks_n = 0; list_for_each_entry(ii, &rst_tcp_repair_sockets, rlist) { @@ -434,11 +428,9 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii) pr_info("Restoring TCP connection\n"); - if (opts.tcp_close && - ii->ie->state != TCP_LISTEN && ii->ie->state != TCP_CLOSE) { + if (opts.tcp_close && ii->ie->state != TCP_LISTEN && ii->ie->state != TCP_CLOSE) { if (shutdown(fd, SHUT_RDWR) && errno != ENOTCONN) { - pr_perror("Unable to shutdown the socket id %x ino %x", - ii->ie->id, ii->ie->ino); + pr_perror("Unable to shutdown the socket id %x ino %x", ii->ie->id, ii->ie->ino); } return 0; } diff --git a/criu/sk-unix.c b/criu/sk-unix.c index d62cebc46..e6ce3d696 100644 --- a/criu/sk-unix.c +++ b/criu/sk-unix.c @@ -38,7 +38,7 @@ #include "protobuf.h" #include "images/sk-unix.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "unix: " /* @@ -54,42 +54,42 @@ * as "external" and require the --ext-unix-sk option. */ -#define USK_EXTERN (1 << 0) -#define USK_SERVICE (1 << 1) -#define USK_CALLBACK (1 << 2) -#define USK_INHERIT (1 << 3) +#define USK_EXTERN (1 << 0) +#define USK_SERVICE (1 << 1) +#define USK_CALLBACK (1 << 2) +#define USK_INHERIT (1 << 3) -#define FAKE_INO 0 +#define FAKE_INO 0 struct unix_sk_desc { - struct socket_desc sd; - unsigned int type; - unsigned int state; - unsigned int peer_ino; - unsigned int rqlen; - unsigned int wqlen; - unsigned int namelen; - char *name; - unsigned int nr_icons; - unsigned int *icons; - - unsigned int vfs_dev; - unsigned int vfs_ino; - - unsigned char shutdown; - bool deleted; - - mode_t mode; - uid_t uid; - gid_t gid; - - struct list_head list; - - int fd; - struct list_head peer_list; - struct list_head peer_node; - - UnixSkEntry *ue; + struct socket_desc sd; + unsigned int type; + unsigned int state; + unsigned int peer_ino; + unsigned int rqlen; + unsigned int wqlen; + unsigned int namelen; + char *name; + unsigned int nr_icons; + unsigned int *icons; + + unsigned int vfs_dev; + unsigned int vfs_ino; + + unsigned char shutdown; + bool deleted; + + mode_t mode; + uid_t uid; + gid_t gid; + + struct list_head list; + + int fd; + struct list_head peer_list; + struct list_head peer_node; + + UnixSkEntry *ue; }; /* @@ -101,19 +101,18 @@ static mutex_t *mutex_ghost; static LIST_HEAD(unix_sockets); static LIST_HEAD(unix_ghost_addr); -static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, - UnixSkEntry *ue, const struct fd_parms *p); +static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, UnixSkEntry *ue, const struct fd_parms *p); struct unix_sk_info; static int unlink_sk(struct unix_sk_info *ui); struct unix_sk_listen_icon { - unsigned int peer_ino; - struct unix_sk_desc *sk_desc; - struct unix_sk_listen_icon *next; + unsigned int peer_ino; + struct unix_sk_desc *sk_desc; + struct unix_sk_listen_icon *next; }; -#define SK_HASH_SIZE 32 +#define SK_HASH_SIZE 32 static struct unix_sk_listen_icon *unix_listen_icons[SK_HASH_SIZE]; @@ -121,8 +120,7 @@ static struct unix_sk_listen_icon *lookup_unix_listen_icons(unsigned int peer_in { struct unix_sk_listen_icon *ic; - for (ic = unix_listen_icons[peer_ino % SK_HASH_SIZE]; - ic; ic = ic->next) + for (ic = unix_listen_icons[peer_ino % SK_HASH_SIZE]; ic; ic = ic->next) if (ic->peer_ino == peer_ino) return ic; return NULL; @@ -130,9 +128,8 @@ static struct unix_sk_listen_icon *lookup_unix_listen_icons(unsigned int peer_in static void show_one_unix(char *act, const struct unix_sk_desc *sk) { - pr_debug("\t%s: ino %u peer_ino %u family %4d type %4d state %2d name %s\n", - act, sk->sd.ino, sk->peer_ino, sk->sd.family, sk->type, sk->state, - sk->name ? : "null"); + pr_debug("\t%s: ino %u peer_ino %u family %4d type %4d state %2d name %s\n", act, sk->sd.ino, sk->peer_ino, + sk->sd.family, sk->type, sk->state, sk->name ?: "null"); if (sk->nr_icons) { int i; @@ -144,8 +141,8 @@ static void show_one_unix(char *act, const struct unix_sk_desc *sk) static void show_one_unix_img(const char *act, const UnixSkEntry *e) { - pr_info("\t%s: id %#x ino %u peer %u type %d state %d name %d bytes\n", - act, e->id, e->ino, e->peer, e->type, e->state, (int)e->name.len); + pr_info("\t%s: id %#x ino %u peer %u type %d state %d name %d bytes\n", act, e->id, e->ino, e->peer, e->type, + e->state, (int)e->name.len); } static int can_dump_unix_sk(const struct unix_sk_desc *sk) @@ -155,12 +152,10 @@ static int can_dump_unix_sk(const struct unix_sk_desc *sk) * that is connected to cr_service. We will dump * it properly below. */ - if (sk->type != SOCK_STREAM && - sk->type != SOCK_DGRAM && - sk->type != SOCK_SEQPACKET) { + if (sk->type != SOCK_STREAM && sk->type != SOCK_DGRAM && sk->type != SOCK_SEQPACKET) { pr_err("Unsupported type (%d) on socket %d.\n" - "Only stream/dgram/seqpacket are supported.\n", - sk->type, sk->sd.ino); + "Only stream/dgram/seqpacket are supported.\n", + sk->type, sk->sd.ino); return 0; } @@ -170,8 +165,7 @@ static int can_dump_unix_sk(const struct unix_sk_desc *sk) case TCP_CLOSE: break; default: - pr_err("Unknown state %d for unix socket %d\n", - sk->state, sk->sd.ino); + pr_err("Unknown state %d for unix socket %d\n", sk->state, sk->sd.ino); return 0; } @@ -286,8 +280,7 @@ static int resolve_rel_name(uint32_t id, struct unix_sk_desc *sk, const struct f return -ENOENT; } - pr_debug("Resolving relative name %s for socket %d\n", - sk->name, sk->sd.ino); + pr_debug("Resolving relative name %s for socket %d\n", sk->name, sk->sd.ino); for (i = 0; i < ARRAY_SIZE(dirs); i++) { char dir[PATH_MAX], path[PATH_MAX]; @@ -312,16 +305,15 @@ static int resolve_rel_name(uint32_t id, struct unix_sk_desc *sk, const struct f goto err; } - if ((st.st_ino == sk->vfs_ino) && - phys_stat_dev_match(st.st_dev, sk->vfs_dev, ns, &path[1])) { + if ((st.st_ino == sk->vfs_ino) && phys_stat_dev_match(st.st_dev, sk->vfs_dev, ns, &path[1])) { *pdir = xstrdup(dir); if (!*pdir) return -ENOMEM; pr_debug("Resolved relative socket name to dir %s\n", *pdir); sk->mode = st.st_mode; - sk->uid = st.st_uid; - sk->gid = st.st_gid; + sk->uid = st.st_uid; + sk->gid = st.st_gid; return 0; } } @@ -340,16 +332,13 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) FownEntry *fown; void *m; - m = xmalloc(sizeof(UnixSkEntry) + - sizeof(SkOptsEntry) + - sizeof(FilePermsEntry) + - sizeof(FownEntry)); + m = xmalloc(sizeof(UnixSkEntry) + sizeof(SkOptsEntry) + sizeof(FilePermsEntry) + sizeof(FownEntry)); if (!m) return -ENOMEM; - ue = xptr_pull(&m, UnixSkEntry); - skopts = xptr_pull(&m, SkOptsEntry); - perms = xptr_pull(&m, FilePermsEntry); - fown = xptr_pull(&m, FownEntry); + ue = xptr_pull(&m, UnixSkEntry); + skopts = xptr_pull(&m, SkOptsEntry); + perms = xptr_pull(&m, FilePermsEntry); + fown = xptr_pull(&m, FownEntry); unix_sk_entry__init(ue); sk_opts_entry__init(skopts); @@ -368,21 +357,21 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) BUG_ON(sk->sd.already_dumped); - ue->name.len = (size_t)sk->namelen; - ue->name.data = (void *)sk->name; - - ue->id = id; - ue->ino = sk->sd.ino; - ue->ns_id = sk->sd.sk_ns->id; - ue->has_ns_id = true; - ue->type = sk->type; - ue->state = sk->state; - ue->flags = p->flags; - ue->backlog = sk->wqlen; - ue->peer = sk->peer_ino; - ue->fown = fown; - ue->opts = skopts; - ue->uflags = 0; + ue->name.len = (size_t)sk->namelen; + ue->name.data = (void *)sk->name; + + ue->id = id; + ue->ino = sk->sd.ino; + ue->ns_id = sk->sd.sk_ns->id; + ue->has_ns_id = true; + ue->type = sk->type; + ue->state = sk->state; + ue->flags = p->flags; + ue->backlog = sk->wqlen; + ue->peer = sk->peer_ino; + ue->fown = fown; + ue->opts = skopts; + ue->uflags = 0; if (unix_resolve_name(lfd, id, sk, ue, p)) goto err; @@ -400,14 +389,14 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) if (sk->namelen && *sk->name) { ue->file_perms = perms; - perms->mode = sk->mode; - perms->uid = userns_uid(sk->uid); - perms->gid = userns_gid(sk->gid); + perms->mode = sk->mode; + perms->uid = userns_uid(sk->uid); + perms->gid = userns_gid(sk->gid); } if (sk->deleted) { ue->has_deleted = true; - ue->deleted = sk->deleted; + ue->deleted = sk->deleted; } sk_encode_shutdown(ue, sk->shutdown); @@ -418,8 +407,7 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) * accept()-ed. We handle them separately with the "icons" * (i stands for in-flight, cons -- for connections) things. */ - if (sk->rqlen != 0 && !(sk->type == SOCK_STREAM && - sk->state == TCP_LISTEN)) { + if (sk->rqlen != 0 && !(sk->type == SOCK_STREAM && sk->state == TCP_LISTEN)) { if (dump_sk_queue(lfd, id)) goto err; } @@ -427,8 +415,7 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) if (ue->peer) { peer = (struct unix_sk_desc *)lookup_socket(ue->peer, PF_UNIX, 0); if (IS_ERR_OR_NULL(peer)) { - pr_err("Unix socket %u without peer %u\n", - ue->ino, ue->peer); + pr_err("Unix socket %u without peer %u\n", ue->ino, ue->peer); goto err; } @@ -438,8 +425,8 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) */ if (peer->peer_ino != ue->ino) { if (!peer->name) { - pr_err("Unix socket %u with unreachable peer %u (%u)\n", - ue->ino, ue->peer, peer->peer_ino); + pr_err("Unix socket %u with unreachable peer %u (%u)\n", ue->ino, ue->peer, + peer->peer_ino); goto err; } } @@ -458,13 +445,10 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) } } - if ((ue->type != SOCK_DGRAM) && ( - ((ue->shutdown == SK_SHUTDOWN__READ) && - (peer->shutdown != SK_SHUTDOWN__WRITE)) || - ((ue->shutdown == SK_SHUTDOWN__WRITE) && - (peer->shutdown != SK_SHUTDOWN__READ)) || - ((ue->shutdown == SK_SHUTDOWN__BOTH) && - (peer->shutdown != SK_SHUTDOWN__BOTH)) )) { + if ((ue->type != SOCK_DGRAM) && + (((ue->shutdown == SK_SHUTDOWN__READ) && (peer->shutdown != SK_SHUTDOWN__WRITE)) || + ((ue->shutdown == SK_SHUTDOWN__WRITE) && (peer->shutdown != SK_SHUTDOWN__READ)) || + ((ue->shutdown == SK_SHUTDOWN__BOTH) && (peer->shutdown != SK_SHUTDOWN__BOTH)))) { /* * Usually this doesn't happen, however it's possible if * socket was shut down before connect() (see sockets03.c test). @@ -473,8 +457,8 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) * to check both ends on read()/write(). Thus mismatched sockets behave * the same way as matched. */ - pr_warn("Shutdown mismatch %u:%d -> %u:%d\n", - ue->ino, ue->shutdown, peer->sd.ino, peer->shutdown); + pr_warn("Shutdown mismatch %u:%d -> %u:%d\n", ue->ino, ue->shutdown, peer->sd.ino, + peer->shutdown); } } else if (ue->state == TCP_ESTABLISHED) { const struct unix_sk_listen_icon *e; @@ -508,14 +492,14 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p) /* e->sk_desc is _never_ NULL */ if (e->sk_desc->state != TCP_LISTEN) { pr_err("In-flight connection on " - "non-listening socket %d\n", ue->ino); + "non-listening socket %d\n", + ue->ino); goto err; } ue->peer = e->sk_desc->sd.ino; - pr_debug("\t\tFixed inflight socket %u peer %u)\n", - ue->ino, ue->peer); + pr_debug("\t\tFixed inflight socket %u peer %u)\n", ue->ino, ue->peer); } dump: if (dump_socket_opts(lfd, skopts)) @@ -556,12 +540,12 @@ err: } const struct fdtype_ops unix_dump_ops = { - .type = FD_TYPES__UNIXSK, - .dump = dump_one_unix_fd, + .type = FD_TYPES__UNIXSK, + .dump = dump_one_unix_fd, }; -static int unix_resolve_name_old(int lfd, uint32_t id, struct unix_sk_desc *d, - UnixSkEntry *ue, const struct fd_parms *p) +static int unix_resolve_name_old(int lfd, uint32_t id, struct unix_sk_desc *d, UnixSkEntry *ue, + const struct fd_parms *p) { char *name = d->name; bool deleted = false; @@ -611,26 +595,22 @@ static int unix_resolve_name_old(int lfd, uint32_t id, struct unix_sk_desc *d, snprintf(rpath, sizeof(rpath), ".%s", name); if (fstatat(mntns_root, rpath, &st, 0)) { if (errno != ENOENT) { - pr_warn("Can't stat socket %#x(%s), skipping: %m (err %d)\n", - id, rpath, errno); + pr_warn("Can't stat socket %#x(%s), skipping: %m (err %d)\n", id, rpath, errno); goto skip; } - pr_info("unix: Dropping path %s for unlinked sk %#x\n", - name, id); + pr_info("unix: Dropping path %s for unlinked sk %#x\n", name, id); deleted = true; - } else if ((st.st_ino != d->vfs_ino) || - !phys_stat_dev_match(st.st_dev, d->vfs_dev, ns, name)) { + } else if ((st.st_ino != d->vfs_ino) || !phys_stat_dev_match(st.st_dev, d->vfs_dev, ns, name)) { pr_info("unix: Dropping path %s for unlinked bound " "sk %#x.%d real %#x.%d\n", - name, (int)st.st_dev, (int)st.st_ino, - (int)d->vfs_dev, (int)d->vfs_ino); + name, (int)st.st_dev, (int)st.st_ino, (int)d->vfs_dev, (int)d->vfs_ino); deleted = true; } d->mode = st.st_mode; - d->uid = st.st_uid; - d->gid = st.st_gid; + d->uid = st.st_uid; + d->gid = st.st_gid; d->deleted = deleted; @@ -645,8 +625,7 @@ skip: goto out; } -static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, - UnixSkEntry *ue, const struct fd_parms *p) +static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, UnixSkEntry *ue, const struct fd_parms *p) { char *name = d->name; char path[PATH_MAX], tmp[PATH_MAX]; @@ -675,8 +654,8 @@ static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, return -1; } d->mode = st.st_mode; - d->uid = st.st_uid; - d->gid = st.st_gid; + d->uid = st.st_uid; + d->gid = st.st_gid; proc_fd = get_service_fd(PROC_FD_OFF); if (proc_fd < 0) { @@ -760,8 +739,7 @@ skip: return 1; } -static int unix_collect_one(const struct unix_diag_msg *m, - struct nlattr **tb, struct ns_id *ns) +static int unix_collect_one(const struct unix_diag_msg *m, struct nlattr **tb, struct ns_id *ns) { struct unix_sk_desc *d; int ret = 0; @@ -770,7 +748,7 @@ static int unix_collect_one(const struct unix_diag_msg *m, if (!d) return -1; - d->type = m->udiag_type; + d->type = m->udiag_type; d->state = m->udiag_state; INIT_LIST_HEAD(&d->list); @@ -825,8 +803,8 @@ static int unix_collect_one(const struct unix_diag_msg *m, pr_debug("\t\tCollected icon %d\n", d->icons[i]); - e->peer_ino = n; - e->sk_desc = d; + e->peer_ino = n; + e->sk_desc = d; } } @@ -855,15 +833,14 @@ skip: int unix_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg) { struct unix_diag_msg *m = NLMSG_DATA(h); - struct nlattr *tb[UNIX_DIAG_MAX+1]; + struct nlattr *tb[UNIX_DIAG_MAX + 1]; nlmsg_parse(h, sizeof(struct unix_diag_msg), tb, UNIX_DIAG_MAX, NULL); return unix_collect_one(m, tb, ns); } -static int __dump_external_socket(struct unix_sk_desc *sk, - struct unix_sk_desc *peer) +static int __dump_external_socket(struct unix_sk_desc *sk, struct unix_sk_desc *peer) { int ret; @@ -937,22 +914,21 @@ int fix_external_unix_sockets(void) FownEntry fown = FOWN_ENTRY__INIT; SkOptsEntry skopts = SK_OPTS_ENTRY__INIT; - if (sk->sd.already_dumped || - list_empty(&sk->peer_list)) + if (sk->sd.already_dumped || list_empty(&sk->peer_list)) continue; show_one_unix("Dumping extern", sk); fd_id_generate_special(NULL, &e.id); - e.ino = sk->sd.ino; - e.type = SOCK_DGRAM; - e.state = TCP_LISTEN; - e.name.data = (void *)sk->name; - e.name.len = (size_t)sk->namelen; - e.uflags = USK_EXTERN; - e.peer = 0; - e.fown = &fown; - e.opts = &skopts; + e.ino = sk->sd.ino; + e.type = SOCK_DGRAM; + e.state = TCP_LISTEN; + e.name.data = (void *)sk->name; + e.name.len = (size_t)sk->namelen; + e.uflags = USK_EXTERN; + e.peer = 0; + e.fown = &fown; + e.opts = &skopts; fe.type = FD_TYPES__UNIXSK; fe.id = e.id; @@ -973,36 +949,36 @@ err: } struct unix_sk_info { - UnixSkEntry *ue; - struct list_head list; - char *name; - char *name_dir; - unsigned flags; - int fdstore_id; - struct unix_sk_info *peer; - struct pprep_head peer_resolve; /* XXX : union with the above? */ - struct file_desc d; - struct hlist_node hash; /* To lookup socket by ino */ - struct list_head connected; /* List of sockets, connected to me */ - struct list_head node; /* To link in peer's connected list */ - struct list_head scm_fles; - struct list_head ghost_node; - size_t ghost_dir_pos; + UnixSkEntry *ue; + struct list_head list; + char *name; + char *name_dir; + unsigned flags; + int fdstore_id; + struct unix_sk_info *peer; + struct pprep_head peer_resolve; /* XXX : union with the above? */ + struct file_desc d; + struct hlist_node hash; /* To lookup socket by ino */ + struct list_head connected; /* List of sockets, connected to me */ + struct list_head node; /* To link in peer's connected list */ + struct list_head scm_fles; + struct list_head ghost_node; + size_t ghost_dir_pos; /* * For DGRAM sockets with queues, we should only restore the queue * once although it may be open by more than one tid. This is the peer * that should do the queueing. */ - struct unix_sk_info *queuer; + struct unix_sk_info *queuer; /* * These bits are set by task-owner of this unix_sk_info. * Another tasks can only read them. */ - uint8_t bound:1; - uint8_t listen:1; - uint8_t is_connected:1; - uint8_t peer_queue_restored:1; /* Set in 1 after we restore peer's queue */ + uint8_t bound : 1; + uint8_t listen : 1; + uint8_t is_connected : 1; + uint8_t peer_queue_restored : 1; /* Set in 1 after we restore peer's queue */ }; struct scm_fle { @@ -1010,11 +986,11 @@ struct scm_fle { struct fdinfo_list_entry *fle; }; -#define USK_PAIR_MASTER 0x1 -#define USK_PAIR_SLAVE 0x2 -#define USK_GHOST_FDSTORE 0x4 /* bound but removed address */ +#define USK_PAIR_MASTER 0x1 +#define USK_PAIR_SLAVE 0x2 +#define USK_GHOST_FDSTORE 0x4 /* bound but removed address */ -#define SK_INFO_HASH_SIZE 32 +#define SK_INFO_HASH_SIZE 32 static struct hlist_head sk_info_hash[SK_INFO_HASH_SIZE]; @@ -1052,8 +1028,7 @@ static struct unix_sk_info *find_queuer_for(int id) return NULL; } -static struct fdinfo_list_entry *get_fle_for_task(struct file_desc *tgt, - struct pstree_item *owner, bool force_master) +static struct fdinfo_list_entry *get_fle_for_task(struct file_desc *tgt, struct pstree_item *owner, bool force_master) { struct fdinfo_list_entry *fle; FdinfoEntry *e = NULL; @@ -1268,8 +1243,7 @@ static int revert_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *ro return ret; } -static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, - int *prev_root_fd, int *prev_mntns_fd) +static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, int *prev_root_fd, int *prev_mntns_fd) { static struct ns_id *root = NULL, *ns; int fd; @@ -1304,8 +1278,7 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, ns = lookup_nsid_by_mnt_id(ui->ue->mnt_id); } else { if (root == NULL) - root = lookup_ns_by_id(root_item->ids->mnt_ns_id, - &mnt_ns_desc); + root = lookup_ns_by_id(root_item->ids->mnt_ns_id, &mnt_ns_desc); ns = root; } if (ns == NULL) @@ -1336,8 +1309,7 @@ static int prep_unix_sk_cwd(struct unix_sk_info *ui, int *prev_cwd_fd, if (ui->name_dir) { if (chdir(ui->name_dir)) { - pr_perror("Can't change working dir %s", - ui->name_dir); + pr_perror("Can't change working dir %s", ui->name_dir); goto err; } pr_debug("Change working dir to %s\n", ui->name_dir); @@ -1360,8 +1332,7 @@ static int post_open_standalone(struct file_desc *d, int fd) int cwd_fd = -1, root_fd = -1, ns_fd = -1; ui = container_of(d, struct unix_sk_info, d); - BUG_ON((ui->flags & (USK_PAIR_MASTER | USK_PAIR_SLAVE)) || - (ui->ue->uflags & (USK_CALLBACK | USK_INHERIT))); + BUG_ON((ui->flags & (USK_PAIR_MASTER | USK_PAIR_SLAVE)) || (ui->ue->uflags & (USK_CALLBACK | USK_INHERIT))); if (chk_restored_scms(ui)) return 1; @@ -1428,9 +1399,7 @@ static int post_open_standalone(struct file_desc *d, int fd) revert_unix_sk_cwd(peer, &cwd_fd, &root_fd, &ns_fd); restore_queue: - if (peer->queuer == ui && - !(peer->ue->uflags & USK_EXTERN) && - restore_unix_queue(fd, peer)) + if (peer->queuer == ui && !(peer->ue->uflags & USK_EXTERN) && restore_unix_queue(fd, peer)) return -1; restore_sk_common: if (ui->queuer && !ui->queuer->peer_queue_restored) @@ -1478,18 +1447,15 @@ static int keep_deleted(struct unix_sk_info *ui) { int fd = open(ui->name, O_PATH); if (fd < 0) { - pr_perror("ghost: Can't open id %#x ino %u addr %s", - ui->ue->id, ui->ue->ino, ui->name); + pr_perror("ghost: Can't open id %#x ino %u addr %s", ui->ue->id, ui->ue->ino, ui->name); return -1; } ui->fdstore_id = fdstore_add(fd); - pr_debug("ghost: id %#x %d fdstore_id %d %s\n", - ui->ue->id, ui->ue->ino, ui->fdstore_id, ui->name); + pr_debug("ghost: id %#x %d fdstore_id %d %s\n", ui->ue->id, ui->ue->ino, ui->fdstore_id, ui->name); close(fd); return ui->fdstore_id; } - #define UNIX_GHOST_FMT "%s.criu-sk-ghost" /* @@ -1504,30 +1470,28 @@ static int bind_on_deleted(int sk, struct unix_sk_info *ui) int ret; if (ui->ue->name.len >= UNIX_PATH_MAX) { - pr_err("ghost: Too long name for socket id %#x ino %u name %s\n", - ui->ue->id, ui->ue->ino, ui->name); + pr_err("ghost: Too long name for socket id %#x ino %u name %s\n", ui->ue->id, ui->ue->ino, ui->name); return -ENOSPC; } memcpy(path, ui->name, ui->ue->name.len); path[ui->ue->name.len] = '\0'; - for (pos = strrchr(path, '/'); pos; - pos = strrchr(path, '/')) { + for (pos = strrchr(path, '/'); pos; pos = strrchr(path, '/')) { *pos = '\0'; ret = access(path, R_OK | W_OK | X_OK); if (ret == 0) { ui->ghost_dir_pos = pos - path; - pr_debug("ghost: socket id %#x ino %u name %s detected F_OK %s\n", - ui->ue->id, ui->ue->ino, ui->name, path); + pr_debug("ghost: socket id %#x ino %u name %s detected F_OK %s\n", ui->ue->id, ui->ue->ino, + ui->name, path); break; } if (errno != ENOENT) { ret = -errno; - pr_perror("ghost: Can't access %s for socket id %#x ino %u name %s", - path, ui->ue->id, ui->ue->ino, ui->name); + pr_perror("ghost: Can't access %s for socket id %#x ino %u name %s", path, ui->ue->id, + ui->ue->ino, ui->name); return ret; } } @@ -1536,8 +1500,7 @@ static int bind_on_deleted(int sk, struct unix_sk_info *ui) path[ui->ue->name.len] = '\0'; pos = dirname(path); - pr_debug("ghost: socket id %#x ino %u name %s creating %s\n", - ui->ue->id, ui->ue->ino, ui->name, pos); + pr_debug("ghost: socket id %#x ino %u name %s creating %s\n", ui->ue->id, ui->ue->ino, ui->name, pos); ret = mkdirpat(AT_FDCWD, pos, 0755); if (ret) { errno = -ret; @@ -1558,25 +1521,22 @@ static int bind_on_deleted(int sk, struct unix_sk_info *ui) * once ghost socket is processed. */ if (unlinkat(AT_FDCWD, path_parked, 0) == 0) - pr_debug("ghost: Unlinked stale socket id %#x ino %d name %s\n", - ui->ue->id, ui->ue->ino, path_parked); + pr_debug("ghost: Unlinked stale socket id %#x ino %d name %s\n", ui->ue->id, ui->ue->ino, + path_parked); if (rename(ui->name, path_parked)) { ret = -errno; - pr_perror("ghost: Can't rename id %#x ino %u addr %s -> %s", - ui->ue->id, ui->ue->ino, ui->name, path_parked); + pr_perror("ghost: Can't rename id %#x ino %u addr %s -> %s", ui->ue->id, ui->ue->ino, ui->name, + path_parked); return ret; } - pr_debug("ghost: id %#x ino %d renamed %s -> %s\n", - ui->ue->id, ui->ue->ino, ui->name, path_parked); + pr_debug("ghost: id %#x ino %d renamed %s -> %s\n", ui->ue->id, ui->ue->ino, ui->name, path_parked); renamed = true; } - ret = bind(sk, (struct sockaddr *)&addr, - sizeof(addr.sun_family) + ui->ue->name.len); + ret = bind(sk, (struct sockaddr *)&addr, sizeof(addr.sun_family) + ui->ue->name.len); if (ret < 0) { ret = -errno; - pr_perror("ghost: Can't bind on socket id %#x ino %d addr %s", - ui->ue->id, ui->ue->ino, ui->name); + pr_perror("ghost: Can't bind on socket id %#x ino %d addr %s", ui->ue->id, ui->ue->ino, ui->name); goto out_rename; } @@ -1586,8 +1546,7 @@ static int bind_on_deleted(int sk, struct unix_sk_info *ui) ret = keep_deleted(ui); if (ret < 0) { - pr_err("ghost: Can't save socket %#x ino %u addr %s into fdstore\n", - ui->ue->id, ui->ue->ino, ui->name); + pr_err("ghost: Can't save socket %#x ino %u addr %s into fdstore\n", ui->ue->id, ui->ue->ino, ui->name); ret = -EIO; } @@ -1599,19 +1558,18 @@ out: ret = unlinkat(AT_FDCWD, ui->name, 0); if (ret < 0) { ret = -errno; - pr_perror("ghost: Can't unlink socket %#x ino %u addr %s", - ui->ue->id, ui->ue->ino, ui->name); + pr_perror("ghost: Can't unlink socket %#x ino %u addr %s", ui->ue->id, ui->ue->ino, ui->name); } out_rename: if (renamed) { if (rename(path_parked, ui->name)) { ret = -errno; - pr_perror("ghost: Can't rename id %#x ino %u addr %s -> %s", - ui->ue->id, ui->ue->ino, path_parked, ui->name); + pr_perror("ghost: Can't rename id %#x ino %u addr %s -> %s", ui->ue->id, ui->ue->ino, + path_parked, ui->name); } else { - pr_debug("ghost: id %#x ino %d renamed %s -> %s\n", - ui->ue->id, ui->ue->ino, path_parked, ui->name); + pr_debug("ghost: id %#x ino %d renamed %s -> %s\n", ui->ue->id, ui->ue->ino, path_parked, + ui->name); } } @@ -1624,17 +1582,14 @@ out_rename: memcpy(path, ui->name, ui->ue->name.len); path[ui->ue->name.len] = '\0'; - for (pos = strrchr(path, '/'); - pos && (pos - path) > ui->ghost_dir_pos; - pos = strrchr(path, '/')) { + for (pos = strrchr(path, '/'); pos && (pos - path) > ui->ghost_dir_pos; pos = strrchr(path, '/')) { *pos = '\0'; if (rmdir(path)) { - pr_perror("ghost: Can't remove directory %s on id %#x ino %u", - path, ui->ue->id, ui->ue->ino); + pr_perror("ghost: Can't remove directory %s on id %#x ino %u", path, ui->ue->id, + ui->ue->ino); return -1; } - pr_debug("ghost: Removed %s on id %#x ino %u\n", - path, ui->ue->id, ui->ue->ino); + pr_debug("ghost: Removed %s on id %#x ino %u\n", path, ui->ue->id, ui->ue->ino); } } @@ -1681,22 +1636,18 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui) mutex_lock(mutex_ghost); if (ui->flags & USK_GHOST_FDSTORE) { - pr_debug("ghost: bind id %#x ino %u addr %s\n", - ui->ue->id, ui->ue->ino, ui->name); + pr_debug("ghost: bind id %#x ino %u addr %s\n", ui->ue->id, ui->ue->ino, ui->name); ret = bind_on_deleted(sk, ui); if (ret) errno = -ret; } else { - pr_debug("bind id %#x ino %u addr %s\n", - ui->ue->id, ui->ue->ino, ui->name); - ret = bind(sk, (struct sockaddr *)&addr, - sizeof(addr.sun_family) + ui->ue->name.len); + pr_debug("bind id %#x ino %u addr %s\n", ui->ue->id, ui->ue->ino, ui->name); + ret = bind(sk, (struct sockaddr *)&addr, sizeof(addr.sun_family) + ui->ue->name.len); if (ret == 0 && restore_file_perms(ui)) goto done; } if (ret < 0) { - pr_perror("Can't bind id %#x ino %u addr %s", - ui->ue->id, ui->ue->ino, ui->name); + pr_perror("Can't bind id %#x ino %u addr %s", ui->ue->id, ui->ue->ino, ui->name); goto done; } @@ -1741,8 +1692,8 @@ static int post_open_interconnected_master(struct unix_sk_info *ui) static void pr_info_opening(const char *prefix, struct unix_sk_info *ui, struct fdinfo_list_entry *fle) { - pr_info("Opening %s (stage %d id %#x ino %u peer %u)\n", - prefix, fle->stage, ui->ue->id, ui->ue->ino, ui->ue->peer); + pr_info("Opening %s (stage %d id %#x ino %u peer %u)\n", prefix, fle->stage, ui->ue->id, ui->ue->ino, + ui->ue->peer); } static int open_unixsk_pair_master(struct unix_sk_info *ui, int *new_fd) @@ -1899,14 +1850,12 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd) int ret, sks[2]; if (ui->ue->type != SOCK_STREAM) { - pr_err("Non-stream socket %u in established state\n", - ui->ue->ino); + pr_err("Non-stream socket %u in established state\n", ui->ue->ino); return -1; } if (ui->ue->shutdown != SK_SHUTDOWN__BOTH) { - pr_err("Wrong shutdown/peer state for %u\n", - ui->ue->ino); + pr_err("Wrong shutdown/peer state for %u\n", ui->ue->ino); return -1; } @@ -1962,11 +1911,9 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd) * Connect to external sockets requires * special option to be passed. */ - if (ui->peer && (ui->peer->ue->uflags & USK_EXTERN) && - !(opts.ext_unix_sk)) { + if (ui->peer && (ui->peer->ue->uflags & USK_EXTERN) && !(opts.ext_unix_sk)) { pr_err("External socket found in image. " - "Consider using the --" USK_EXT_PARAM - " option to allow restoring it.\n"); + "Consider using the --" USK_EXT_PARAM " option to allow restoring it.\n"); return -1; } @@ -2040,8 +1987,7 @@ static char *socket_d_name(struct file_desc *d, char *buf, size_t s) ui = container_of(d, struct unix_sk_info, d); if (snprintf(buf, s, "socket:[%u]", ui->ue->ino) >= s) { - pr_err("Not enough room for unixsk %d identifier string\n", - ui->ue->ino); + pr_err("Not enough room for unixsk %d identifier string\n", ui->ue->ino); return NULL; } @@ -2080,17 +2026,13 @@ static int unlink_sk(struct unix_sk_info *ui) ret = unlinkat(AT_FDCWD, ui->name, 0) ? -1 : 0; if (ret < 0 && errno != ENOENT) { - pr_warn("Can't unlink socket %u peer %u (name %s dir %s)\n", - ui->ue->ino, ui->ue->peer, - ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-", - ui->name_dir ? ui->name_dir : "-"); + pr_warn("Can't unlink socket %u peer %u (name %s dir %s)\n", ui->ue->ino, ui->ue->peer, + ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-", ui->name_dir ? ui->name_dir : "-"); ret = -errno; goto out; } else if (ret == 0) { - pr_debug("Unlinked socket %u peer %u (name %s dir %s)\n", - ui->ue->ino, ui->ue->peer, - ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-", - ui->name_dir ? ui->name_dir : "-"); + pr_debug("Unlinked socket %u peer %u (name %s dir %s)\n", ui->ue->ino, ui->ue->peer, + ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-", ui->name_dir ? ui->name_dir : "-"); } out: revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd); @@ -2125,14 +2067,14 @@ static int init_unix_sk_info(struct unix_sk_info *ui, UnixSkEntry *ue) ui->name = NULL; ui->name_dir = (void *)ue->name_dir; - ui->flags = 0; - ui->fdstore_id = -1; - ui->ghost_dir_pos = 0; - ui->peer = NULL; - ui->queuer = NULL; - ui->bound = 0; - ui->listen = 0; - ui->is_connected = 0; + ui->flags = 0; + ui->fdstore_id = -1; + ui->ghost_dir_pos = 0; + ui->peer = NULL; + ui->queuer = NULL; + ui->bound = 0; + ui->listen = 0; + ui->is_connected = 0; ui->peer_queue_restored = 0; memzero(&ui->peer_resolve, sizeof(ui->peer_resolve)); @@ -2165,11 +2107,9 @@ int unix_prepare_root_shared(void) char tp_name[32]; char st_name[32]; - pr_debug("ghost: id %#x type %s state %s ino %u peer %u address %s\n", - ui->ue->id, __socket_type_name(ui->ue->type, tp_name), - __tcp_state_name(ui->ue->state, st_name), - ui->ue->ino, ui->peer ? ui->peer->ue->ino : 0, - ui->name); + pr_debug("ghost: id %#x type %s state %s ino %u peer %u address %s\n", ui->ue->id, + __socket_type_name(ui->ue->type, tp_name), __tcp_state_name(ui->ue->state, st_name), + ui->ue->ino, ui->peer ? ui->peer->ue->ino : 0, ui->name); /* * Drop any existing trash on the FS and mark the @@ -2205,7 +2145,7 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i) int j; for (j = 0; j < ulen; j++) - s[j] = uname[j] ? : '@'; + s[j] = uname[j] ?: '@'; uname = s; } } else if (ulen == 0) { @@ -2213,10 +2153,9 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i) uname = "-"; } - pr_info(" `- Got id %#x ino %u type %s state %s peer %u (name %s%.*s dir %s)\n", - ui->ue->id, ui->ue->ino, ___socket_type_name(ui->ue->type), - ___tcp_state_name(ui->ue->state), ui->ue->peer, prefix, ulen, - uname, ui->name_dir ? ui->name_dir : "-"); + pr_info(" `- Got id %#x ino %u type %s state %s peer %u (name %s%.*s dir %s)\n", ui->ue->id, ui->ue->ino, + ___socket_type_name(ui->ue->type), ___tcp_state_name(ui->ue->state), ui->ue->peer, prefix, ulen, uname, + ui->name_dir ? ui->name_dir : "-"); if (ui->ue->peer || ui->name) { if (ui->ue->peer) @@ -2241,11 +2180,11 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i) } struct collect_image_info unix_sk_cinfo = { - .fd_type = CR_FD_UNIXSK, - .pb_type = PB_UNIX_SK, - .priv_size = sizeof(struct unix_sk_info), - .collect = collect_one_unixsk, - .flags = COLLECT_SHARED, + .fd_type = CR_FD_UNIXSK, + .pb_type = PB_UNIX_SK, + .priv_size = sizeof(struct unix_sk_info), + .collect = collect_one_unixsk, + .flags = COLLECT_SHARED, }; static void set_peer(struct unix_sk_info *ui, struct unix_sk_info *peer) @@ -2267,16 +2206,13 @@ static int add_fake_queuer(struct unix_sk_info *ui) if (ui->ue->ino == FAKE_INO) return 0; - peer = xzalloc(sizeof(struct unix_sk_info) + - sizeof(UnixSkEntry) + - sizeof(SkOptsEntry) + - sizeof(FownEntry)); + peer = xzalloc(sizeof(struct unix_sk_info) + sizeof(UnixSkEntry) + sizeof(SkOptsEntry) + sizeof(FownEntry)); if (peer == NULL) return -1; - peer_ue = (void *) peer + sizeof(struct unix_sk_info); - skopts = (void *) peer_ue + sizeof(UnixSkEntry); - fown = (void *) skopts + sizeof(SkOptsEntry); + peer_ue = (void *)peer + sizeof(struct unix_sk_info); + skopts = (void *)peer_ue + sizeof(UnixSkEntry); + fown = (void *)skopts + sizeof(SkOptsEntry); memcpy(skopts, ui->ue->opts, sizeof(SkOptsEntry)); memcpy(fown, ui->ue->fown, sizeof(FownEntry)); memcpy(peer_ue, ui->ue, sizeof(UnixSkEntry)); @@ -2309,8 +2245,7 @@ int add_fake_unix_queuers(void) list_for_each_entry(ui, &unix_sockets, list) { if ((ui->ue->uflags & (USK_EXTERN | USK_CALLBACK)) || ui->queuer) continue; - if (!(ui->ue->state == TCP_ESTABLISHED && !ui->peer) && - ui->ue->type != SOCK_DGRAM) + if (!(ui->ue->state == TCP_ESTABLISHED && !ui->peer) && ui->ue->type != SOCK_DGRAM) continue; if (add_fake_queuer(ui)) return -1; @@ -2339,8 +2274,7 @@ static int interconnected_pair(struct unix_sk_info *ui, struct unix_sk_info *pee * which fle->task has no permissions to restore. But * it has permissions on ui, so it has permissions on peer. */ - if (fle->task != fle_peer->task && - !get_fle_for_task(&peer->d, fle->task, true)) + if (fle->task != fle_peer->task && !get_fle_for_task(&peer->d, fle->task, true)) return -1; return 0; @@ -2351,15 +2285,12 @@ static int fixup_unix_peer(struct unix_sk_info *ui) struct unix_sk_info *peer = ui->peer; if (!peer) { - pr_err("FATAL: Peer %u unresolved for %u\n", - ui->ue->peer, ui->ue->ino); + pr_err("FATAL: Peer %u unresolved for %u\n", ui->ue->peer, ui->ue->ino); return -1; } - if (peer != ui && peer->peer == ui && - !(ui->flags & (USK_PAIR_MASTER | USK_PAIR_SLAVE))) { - pr_info("Connected %d -> %d (%d) flags %#x\n", - ui->ue->ino, ui->ue->peer, peer->ue->ino, ui->flags); + if (peer != ui && peer->peer == ui && !(ui->flags & (USK_PAIR_MASTER | USK_PAIR_SLAVE))) { + pr_info("Connected %d -> %d (%d) flags %#x\n", ui->ue->ino, ui->ue->peer, peer->ue->ino, ui->flags); /* socketpair or interconnected sockets */ if (interconnected_pair(ui, peer)) return -1; diff --git a/criu/sockets.c b/criu/sockets.c index a73967e72..9426b5b94 100644 --- a/criu/sockets.c +++ b/criu/sockets.c @@ -30,17 +30,17 @@ #include "util.h" #include "fdstore.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "sockets: " #ifndef SOCK_DIAG_BY_FAMILY #define SOCK_DIAG_BY_FAMILY 20 #endif -#define SK_HASH_SIZE 32 +#define SK_HASH_SIZE 32 #ifndef SO_GET_FILTER -#define SO_GET_FILTER SO_ATTACH_FILTER +#define SO_GET_FILTER SO_ATTACH_FILTER #endif static const char *__socket_const_name(char *dst, size_t len, const char **a, size_t n, unsigned int v) @@ -57,21 +57,14 @@ static const char *__socket_const_name(char *dst, size_t len, const char **a, si const char *socket_proto_name(unsigned int proto, char *nm, size_t size) { static const char *protos[] = { - [IPPROTO_IP] = __stringify_1(IPPROTO_IP), - [IPPROTO_ICMP] = __stringify_1(IPPROTO_ICMP), - [IPPROTO_IGMP] = __stringify_1(IPPROTO_IGMP), - [IPPROTO_IPIP] = __stringify_1(IPPROTO_IPIP), - [IPPROTO_TCP] = __stringify_1(IPPROTO_TCP), - [IPPROTO_EGP] = __stringify_1(IPPROTO_EGP), - [IPPROTO_UDP] = __stringify_1(IPPROTO_UDP), - [IPPROTO_DCCP] = __stringify_1(IPPROTO_DCCP), - [IPPROTO_IPV6] = __stringify_1(IPPROTO_IPV6), - [IPPROTO_RSVP] = __stringify_1(IPPROTO_RSVP), - [IPPROTO_GRE] = __stringify_1(IPPROTO_GRE), - [IPPROTO_ESP] = __stringify_1(IPPROTO_ESP), - [IPPROTO_AH] = __stringify_1(IPPROTO_AH), - [IPPROTO_UDPLITE] = __stringify_1(IPPROTO_UDPLITE), - [IPPROTO_RAW] = __stringify_1(IPPROTO_RAW), + [IPPROTO_IP] = __stringify_1(IPPROTO_IP), [IPPROTO_ICMP] = __stringify_1(IPPROTO_ICMP), + [IPPROTO_IGMP] = __stringify_1(IPPROTO_IGMP), [IPPROTO_IPIP] = __stringify_1(IPPROTO_IPIP), + [IPPROTO_TCP] = __stringify_1(IPPROTO_TCP), [IPPROTO_EGP] = __stringify_1(IPPROTO_EGP), + [IPPROTO_UDP] = __stringify_1(IPPROTO_UDP), [IPPROTO_DCCP] = __stringify_1(IPPROTO_DCCP), + [IPPROTO_IPV6] = __stringify_1(IPPROTO_IPV6), [IPPROTO_RSVP] = __stringify_1(IPPROTO_RSVP), + [IPPROTO_GRE] = __stringify_1(IPPROTO_GRE), [IPPROTO_ESP] = __stringify_1(IPPROTO_ESP), + [IPPROTO_AH] = __stringify_1(IPPROTO_AH), [IPPROTO_UDPLITE] = __stringify_1(IPPROTO_UDPLITE), + [IPPROTO_RAW] = __stringify_1(IPPROTO_RAW), }; return __socket_const_name(nm, size, protos, ARRAY_SIZE(protos), proto); } @@ -79,13 +72,10 @@ const char *socket_proto_name(unsigned int proto, char *nm, size_t size) const char *socket_family_name(unsigned int family, char *nm, size_t size) { static const char *families[] = { - [AF_UNIX] = __stringify_1(AF_UNIX), - [AF_INET] = __stringify_1(AF_INET), - [AF_BRIDGE] = __stringify_1(AF_BRIDGE), - [AF_INET6] = __stringify_1(AF_INET6), - [AF_KEY] = __stringify_1(AF_KEY), - [AF_NETLINK] = __stringify_1(AF_NETLINK), - [AF_PACKET] = __stringify_1(AF_PACKET), + [AF_UNIX] = __stringify_1(AF_UNIX), [AF_INET] = __stringify_1(AF_INET), + [AF_BRIDGE] = __stringify_1(AF_BRIDGE), [AF_INET6] = __stringify_1(AF_INET6), + [AF_KEY] = __stringify_1(AF_KEY), [AF_NETLINK] = __stringify_1(AF_NETLINK), + [AF_PACKET] = __stringify_1(AF_PACKET), }; return __socket_const_name(nm, size, families, ARRAY_SIZE(families), family); } @@ -93,11 +83,9 @@ const char *socket_family_name(unsigned int family, char *nm, size_t size) const char *socket_type_name(unsigned int type, char *nm, size_t size) { static const char *types[] = { - [SOCK_STREAM] = __stringify_1(SOCK_STREAM), - [SOCK_DGRAM] = __stringify_1(SOCK_DGRAM), - [SOCK_RAW] = __stringify_1(SOCK_RAW), - [SOCK_SEQPACKET] = __stringify_1(SOCK_SEQPACKET), - [SOCK_PACKET] = __stringify_1(SOCK_PACKET), + [SOCK_STREAM] = __stringify_1(SOCK_STREAM), [SOCK_DGRAM] = __stringify_1(SOCK_DGRAM), + [SOCK_RAW] = __stringify_1(SOCK_RAW), [SOCK_SEQPACKET] = __stringify_1(SOCK_SEQPACKET), + [SOCK_PACKET] = __stringify_1(SOCK_PACKET), }; return __socket_const_name(nm, size, types, ARRAY_SIZE(types), type); } @@ -105,39 +93,38 @@ const char *socket_type_name(unsigned int type, char *nm, size_t size) const char *tcp_state_name(unsigned int state, char *nm, size_t size) { static const char *states[] = { - [TCP_ESTABLISHED] = __stringify_1(TCP_ESTABLISHED), - [TCP_SYN_SENT] = __stringify_1(TCP_SYN_SENT), - [TCP_SYN_RECV] = __stringify_1(TCP_SYN_RECV), - [TCP_FIN_WAIT1] = __stringify_1(TCP_FIN_WAIT1), - [TCP_FIN_WAIT2] = __stringify_1(TCP_FIN_WAIT2), - [TCP_TIME_WAIT] = __stringify_1(TCP_TIME_WAIT), - [TCP_CLOSE] = __stringify_1(TCP_CLOSE), - [TCP_CLOSE_WAIT] = __stringify_1(TCP_CLOSE_WAIT), - [TCP_LAST_ACK] = __stringify_1(TCP_LAST_ACK), - [TCP_LISTEN] = __stringify_1(TCP_LISTEN), - [TCP_CLOSING] = __stringify_1(TCP_CLOSING), + [TCP_ESTABLISHED] = __stringify_1(TCP_ESTABLISHED), + [TCP_SYN_SENT] = __stringify_1(TCP_SYN_SENT), + [TCP_SYN_RECV] = __stringify_1(TCP_SYN_RECV), + [TCP_FIN_WAIT1] = __stringify_1(TCP_FIN_WAIT1), + [TCP_FIN_WAIT2] = __stringify_1(TCP_FIN_WAIT2), + [TCP_TIME_WAIT] = __stringify_1(TCP_TIME_WAIT), + [TCP_CLOSE] = __stringify_1(TCP_CLOSE), + [TCP_CLOSE_WAIT] = __stringify_1(TCP_CLOSE_WAIT), + [TCP_LAST_ACK] = __stringify_1(TCP_LAST_ACK), + [TCP_LISTEN] = __stringify_1(TCP_LISTEN), + [TCP_CLOSING] = __stringify_1(TCP_CLOSING), }; return __socket_const_name(nm, size, states, ARRAY_SIZE(states), state); } struct sock_diag_greq { - u8 family; - u8 protocol; + u8 family; + u8 protocol; }; struct sock_diag_req { struct nlmsghdr hdr; union { - struct unix_diag_req u; - struct inet_diag_req_v2 i; - struct packet_diag_req p; + struct unix_diag_req u; + struct inet_diag_req_v2 i; + struct packet_diag_req p; struct netlink_diag_req n; - struct sock_diag_greq g; + struct sock_diag_greq g; } r; }; -enum socket_cl_bits -{ +enum socket_cl_bits { NETLINK_CL_BIT, INET_TCP_CL_BIT, INET_UDP_CL_BIT, @@ -156,8 +143,7 @@ enum socket_cl_bits static DECLARE_BITMAP(socket_cl_bits, MAX_CL_BIT); -static inline -enum socket_cl_bits get_collect_bit_nr(unsigned int family, unsigned int proto) +static inline enum socket_cl_bits get_collect_bit_nr(unsigned int family, unsigned int proto) { if (family == AF_NETLINK) return NETLINK_CL_BIT; @@ -252,8 +238,8 @@ void preload_socket_modules(void) pr_info("Probing sock diag modules\n"); memset(&req, 0, sizeof(req)); - req.hdr.nlmsg_type = SOCK_DIAG_BY_FAMILY; - req.hdr.nlmsg_seq = CR_NLMSG_SEQ; + req.hdr.nlmsg_type = SOCK_DIAG_BY_FAMILY; + req.hdr.nlmsg_seq = CR_NLMSG_SEQ; /* * Probe UNIX, netlink and packet diag-s by feeding @@ -346,10 +332,7 @@ static void encode_filter(struct sock_filter *f, u64 *img, int n) BUILD_BUG_ON(sizeof(*f) != sizeof(*img)); for (i = 0; i < n; i++) - img[i] = ((u64)f[i].code << 48) | - ((u64)f[i].jt << 40) | - ((u64)f[i].jf << 32) | - ((u64)f[i].k << 0); + img[i] = ((u64)f[i].code << 48) | ((u64)f[i].jt << 40) | ((u64)f[i].jf << 32) | ((u64)f[i].k << 0); } static void decode_filter(u64 *img, struct sock_filter *f, int n) @@ -446,12 +429,10 @@ struct socket_desc *lookup_socket_ino(unsigned int ino, int family) return NULL; } - struct socket_desc *lookup_socket(unsigned int ino, int family, int proto) { if (!socket_test_collect_bit(family, proto)) { - pr_err("Sockets (family %d proto %d) are not collected\n", - family, proto); + pr_err("Sockets (family %d proto %d) are not collected\n", family, proto); return ERR_PTR(-EINVAL); } @@ -462,10 +443,10 @@ int sk_collect_one(unsigned ino, int family, struct socket_desc *d, struct ns_id { struct socket_desc **chain; - d->ino = ino; - d->family = family; + d->ino = ino; + d->family = family; d->already_dumped = 0; - d->sk_ns = ns; + d->sk_ns = ns; chain = &sockets[ino % SK_HASH_SIZE]; d->next = *chain; @@ -517,7 +498,7 @@ int restore_prepare_socket(int sk) pr_perror("Unable to get flags for %d", sk); return -1; } - if (fcntl(sk, F_SETFL, flags | O_NONBLOCK) ) { + if (fcntl(sk, F_SETFL, flags | O_NONBLOCK)) { pr_perror("Unable to set O_NONBLOCK for %d", sk); return -1; } @@ -531,7 +512,7 @@ int restore_socket_opts(int sk, SkOptsEntry *soe) struct timeval tv; struct linger so_linger; /* In kernel a bufsize value is doubled. */ - u32 bufs[2] = { soe->so_sndbuf / 2, soe->so_rcvbuf / 2}; + u32 bufs[2] = { soe->so_sndbuf / 2, soe->so_rcvbuf / 2 }; pr_info("%d restore sndbuf %d rcv buf %d\n", sk, soe->so_sndbuf, soe->so_rcvbuf); @@ -623,8 +604,7 @@ int do_dump_opt(int sk, int level, int name, void *val, int len) } if (aux != len) { - pr_err("Len mismatch on %d:%d : %d, want %d\n", - level, name, aux, len); + pr_err("Len mismatch on %d:%d : %d, want %d\n", level, name, aux, len); return -1; } @@ -635,7 +615,7 @@ int dump_socket_opts(int sk, SkOptsEntry *soe) { int ret = 0, val; struct timeval tv; - struct linger so_linger = {0, 0}; + struct linger so_linger = { 0, 0 }; ret |= dump_opt(sk, SOL_SOCKET, SO_SNDBUF, &soe->so_sndbuf); ret |= dump_opt(sk, SOL_SOCKET, SO_RCVBUF, &soe->so_rcvbuf); @@ -768,9 +748,8 @@ static int inet_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg) } static int do_collect_req(int nl, struct sock_diag_req *req, int size, - int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *), - int (*error_callback)(int err, struct ns_id *ns, void *), - struct ns_id *ns, void *arg) + int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *), + int (*error_callback)(int err, struct ns_id *ns, void *), struct ns_id *ns, void *arg) { int tmp = do_rtnl_req(nl, req, size, receive_callback, error_callback, ns, arg); if (tmp == 0) @@ -784,8 +763,7 @@ static int collect_err(int err, struct ns_id *ns, void *arg) char family[32], proto[32]; char msg[256]; - snprintf(msg, sizeof(msg), - "Sockects collect procedure family %s proto %s", + snprintf(msg, sizeof(msg), "Sockects collect procedure family %s proto %s", socket_family_name(gr->family, family, sizeof(family)), socket_proto_name(gr->protocol, proto, sizeof(proto))); @@ -816,9 +794,7 @@ static int collect_err(int err, struct ns_id *ns, void *arg) * may return EINVAL on older kernels. */ if (err == -EINVAL) { - if (gr->family == AF_UNIX || - gr->family == AF_PACKET || - gr->family == AF_NETLINK) { + if (gr->family == AF_UNIX || gr->family == AF_PACKET || gr->family == AF_NETLINK) { pr_debug("%s: %d\n", msg, err); return -EINVAL; } @@ -843,112 +819,107 @@ int collect_sockets(struct ns_id *ns) struct sock_diag_req req; memset(&req, 0, sizeof(req)); - req.hdr.nlmsg_len = sizeof(req); - req.hdr.nlmsg_type = SOCK_DIAG_BY_FAMILY; - req.hdr.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; - req.hdr.nlmsg_seq = CR_NLMSG_SEQ; + req.hdr.nlmsg_len = sizeof(req); + req.hdr.nlmsg_type = SOCK_DIAG_BY_FAMILY; + req.hdr.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; + req.hdr.nlmsg_seq = CR_NLMSG_SEQ; /* Collect UNIX sockets */ - req.r.u.sdiag_family = AF_UNIX; - req.r.u.udiag_states = -1; /* All */ - req.r.u.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_VFS | - UDIAG_SHOW_PEER | UDIAG_SHOW_ICONS | - UDIAG_SHOW_RQLEN; + req.r.u.sdiag_family = AF_UNIX; + req.r.u.udiag_states = -1; /* All */ + req.r.u.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_VFS | UDIAG_SHOW_PEER | UDIAG_SHOW_ICONS | UDIAG_SHOW_RQLEN; tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, collect_err, ns, &req.r.u); if (tmp) err = tmp; /* Collect IPv4 TCP sockets */ - req.r.i.sdiag_family = AF_INET; - req.r.i.sdiag_protocol = IPPROTO_TCP; - req.r.i.idiag_ext = 0; + req.r.i.sdiag_family = AF_INET; + req.r.i.sdiag_protocol = IPPROTO_TCP; + req.r.i.idiag_ext = 0; /* Only listening and established sockets supported yet */ - req.r.i.idiag_states = (1 << TCP_LISTEN) | (1 << TCP_ESTABLISHED) | - (1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) | - (1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) | - (1 << TCP_CLOSING) | (1 << TCP_SYN_SENT); + req.r.i.idiag_states = (1 << TCP_LISTEN) | (1 << TCP_ESTABLISHED) | (1 << TCP_FIN_WAIT1) | + (1 << TCP_FIN_WAIT2) | (1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) | (1 << TCP_CLOSING) | + (1 << TCP_SYN_SENT); tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv4 UDP sockets */ - req.r.i.sdiag_family = AF_INET; - req.r.i.sdiag_protocol = IPPROTO_UDP; - req.r.i.idiag_ext = 0; - req.r.i.idiag_states = -1; /* All */ + req.r.i.sdiag_family = AF_INET; + req.r.i.sdiag_protocol = IPPROTO_UDP; + req.r.i.idiag_ext = 0; + req.r.i.idiag_states = -1; /* All */ tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv4 UDP-lite sockets */ - req.r.i.sdiag_family = AF_INET; - req.r.i.sdiag_protocol = IPPROTO_UDPLITE; - req.r.i.idiag_ext = 0; - req.r.i.idiag_states = -1; /* All */ + req.r.i.sdiag_family = AF_INET; + req.r.i.sdiag_protocol = IPPROTO_UDPLITE; + req.r.i.idiag_ext = 0; + req.r.i.idiag_states = -1; /* All */ tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv4 RAW sockets */ - req.r.i.sdiag_family = AF_INET; - req.r.i.sdiag_protocol = IPPROTO_RAW; - req.r.i.idiag_ext = 0; - req.r.i.idiag_states = -1; /* All */ + req.r.i.sdiag_family = AF_INET; + req.r.i.sdiag_protocol = IPPROTO_RAW; + req.r.i.idiag_ext = 0; + req.r.i.idiag_states = -1; /* All */ tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv6 TCP sockets */ - req.r.i.sdiag_family = AF_INET6; - req.r.i.sdiag_protocol = IPPROTO_TCP; - req.r.i.idiag_ext = 0; + req.r.i.sdiag_family = AF_INET6; + req.r.i.sdiag_protocol = IPPROTO_TCP; + req.r.i.idiag_ext = 0; /* Only listening sockets supported yet */ - req.r.i.idiag_states = (1 << TCP_LISTEN) | (1 << TCP_ESTABLISHED) | - (1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) | - (1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) | - (1 << TCP_CLOSING) | (1 << TCP_SYN_SENT); + req.r.i.idiag_states = (1 << TCP_LISTEN) | (1 << TCP_ESTABLISHED) | (1 << TCP_FIN_WAIT1) | + (1 << TCP_FIN_WAIT2) | (1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) | (1 << TCP_CLOSING) | + (1 << TCP_SYN_SENT); tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv6 UDP sockets */ - req.r.i.sdiag_family = AF_INET6; - req.r.i.sdiag_protocol = IPPROTO_UDP; - req.r.i.idiag_ext = 0; - req.r.i.idiag_states = -1; /* All */ + req.r.i.sdiag_family = AF_INET6; + req.r.i.sdiag_protocol = IPPROTO_UDP; + req.r.i.idiag_ext = 0; + req.r.i.idiag_states = -1; /* All */ tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv6 UDP-lite sockets */ - req.r.i.sdiag_family = AF_INET6; - req.r.i.sdiag_protocol = IPPROTO_UDPLITE; - req.r.i.idiag_ext = 0; - req.r.i.idiag_states = -1; /* All */ + req.r.i.sdiag_family = AF_INET6; + req.r.i.sdiag_protocol = IPPROTO_UDPLITE; + req.r.i.idiag_ext = 0; + req.r.i.idiag_states = -1; /* All */ tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; /* Collect IPv6 RAW sockets */ - req.r.i.sdiag_family = AF_INET6; - req.r.i.sdiag_protocol = IPPROTO_RAW; - req.r.i.idiag_ext = 0; - req.r.i.idiag_states = -1; /* All */ + req.r.i.sdiag_family = AF_INET6; + req.r.i.sdiag_protocol = IPPROTO_RAW; + req.r.i.idiag_ext = 0; + req.r.i.idiag_states = -1; /* All */ tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i); if (tmp) err = tmp; - req.r.p.sdiag_family = AF_PACKET; - req.r.p.sdiag_protocol = 0; - req.r.p.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MCLIST | - PACKET_SHOW_FANOUT | PACKET_SHOW_RING_CFG; + req.r.p.sdiag_family = AF_PACKET; + req.r.p.sdiag_protocol = 0; + req.r.p.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MCLIST | PACKET_SHOW_FANOUT | PACKET_SHOW_RING_CFG; tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, collect_err, ns, &req.r.p); if (tmp) err = tmp; - req.r.n.sdiag_family = AF_NETLINK; - req.r.n.sdiag_protocol = NDIAG_PROTO_ALL; - req.r.n.ndiag_show = NDIAG_SHOW_GROUPS; + req.r.n.sdiag_family = AF_NETLINK; + req.r.n.sdiag_protocol = NDIAG_PROTO_ALL; + req.r.n.ndiag_show = NDIAG_SHOW_GROUPS; tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, collect_err, ns, &req.r.n); if (tmp) err = tmp; diff --git a/criu/stats.c b/criu/stats.c index ed5a19141..0a9b4f5d4 100644 --- a/criu/stats.c +++ b/criu/stats.c @@ -17,13 +17,13 @@ struct timing { }; struct dump_stats { - struct timing timings[DUMP_TIME_NR_STATS]; - unsigned long counts[DUMP_CNT_NR_STATS]; + struct timing timings[DUMP_TIME_NR_STATS]; + unsigned long counts[DUMP_CNT_NR_STATS]; }; struct restore_stats { - struct timing timings[RESTORE_TIME_NS_STATS]; - atomic_t counts[RESTORE_CNT_NR_STATS]; + struct timing timings[RESTORE_TIME_NS_STATS]; + atomic_t counts[RESTORE_CNT_NR_STATS]; }; struct dump_stats *dstats; @@ -53,8 +53,7 @@ void cnt_sub(int c, unsigned long val) BUG(); } -static void timeval_accumulate(const struct timeval *from, const struct timeval *to, - struct timeval *res) +static void timeval_accumulate(const struct timeval *from, const struct timeval *to, struct timeval *res) { suseconds_t usec; @@ -130,23 +129,22 @@ static void display_stats(int what, StatsEntry *stats) if (stats->dump->has_irmap_resolve) pr_msg("IRMAP resolve time: %d us\n", stats->dump->irmap_resolve); pr_msg("Memory pages scanned: %" PRIu64 " (0x%" PRIx64 ")\n", stats->dump->pages_scanned, - stats->dump->pages_scanned); + stats->dump->pages_scanned); pr_msg("Memory pages skipped from parent: %" PRIu64 " (0x%" PRIx64 ")\n", - stats->dump->pages_skipped_parent, - stats->dump->pages_skipped_parent); + stats->dump->pages_skipped_parent, stats->dump->pages_skipped_parent); pr_msg("Memory pages written: %" PRIu64 " (0x%" PRIx64 ")\n", stats->dump->pages_written, - stats->dump->pages_written); + stats->dump->pages_written); pr_msg("Lazy memory pages: %" PRIu64 " (0x%" PRIx64 ")\n", stats->dump->pages_lazy, - stats->dump->pages_lazy); + stats->dump->pages_lazy); } else if (what == RESTORE_STATS) { pr_msg("Displaying restore stats:\n"); pr_msg("Pages compared: %" PRIu64 " (0x%" PRIx64 ")\n", stats->restore->pages_compared, - stats->restore->pages_compared); + stats->restore->pages_compared); pr_msg("Pages skipped COW: %" PRIu64 " (0x%" PRIx64 ")\n", stats->restore->pages_skipped_cow, - stats->restore->pages_skipped_cow); + stats->restore->pages_skipped_cow); if (stats->restore->has_pages_restored) pr_msg("Pages restored: %" PRIu64 " (0x%" PRIx64 ")\n", stats->restore->pages_restored, - stats->restore->pages_restored); + stats->restore->pages_restored); pr_msg("Restore time: %d us\n", stats->restore->restore_time); pr_msg("Forking time: %d us\n", stats->restore->forking_time); } else diff --git a/criu/string.c b/criu/string.c index 543c64291..7df0b3e09 100644 --- a/criu/string.c +++ b/criu/string.c @@ -52,7 +52,7 @@ size_t strlcat(char *dest, const char *src, size_t count) dest += dsize; count -= dsize; if (len >= count) - len = count-1; + len = count - 1; memcpy(dest, src, len); dest[len] = 0; return res; diff --git a/criu/sysctl.c b/criu/sysctl.c index e48476560..b06688712 100644 --- a/criu/sysctl.c +++ b/criu/sysctl.c @@ -16,105 +16,92 @@ #define KNOWN_NS_MASK (CLONE_NEWUTS | CLONE_NEWNET | CLONE_NEWIPC) struct sysctl_userns_req { - int op; - unsigned int ns; - size_t nr_req; - struct sysctl_req *reqs; + int op; + unsigned int ns; + size_t nr_req; + struct sysctl_req *reqs; }; -#define __SYSCTL_OP(__ret, __fd, __req, __type, __nr, __op) \ -do { \ - if (__op == CTL_READ) \ - __ret = sysctl_read_##__type(__fd, __req, \ - (__type *)(__req)->arg, \ - __nr); \ - else if (__op == CTL_WRITE) \ - __ret = sysctl_write_##__type(__fd, __req, \ - (__type *)(__req)->arg, \ - __nr); \ - else \ - __ret = -1; \ -} while (0) - -#define GEN_SYSCTL_READ_FUNC(__type, __conv) \ -static int sysctl_read_##__type(int fd, \ - struct sysctl_req *req, \ - __type *arg, \ - int nr) \ -{ \ - char buf[1024] = {0}; \ - int i, ret = -1; \ - char *p = buf; \ - \ - ret = read(fd, buf, sizeof(buf)); \ - if (ret < 0) { \ - pr_perror("Can't read %s", req->name); \ - ret = -1; \ - goto err; \ - } \ - \ - for (i = 0; i < nr && p < buf + sizeof(buf); p++, i++) \ - ((__type *)arg)[i] = __conv(p, &p, 10); \ - \ - if (i != nr) { \ - pr_err("Not enough params for %s (%d != %d)\n", \ - req->name, i, nr); \ - goto err; \ - } \ - \ - ret = 0; \ - \ -err: \ - return ret; \ -} +#define __SYSCTL_OP(__ret, __fd, __req, __type, __nr, __op) \ + do { \ + if (__op == CTL_READ) \ + __ret = sysctl_read_##__type(__fd, __req, (__type *)(__req)->arg, __nr); \ + else if (__op == CTL_WRITE) \ + __ret = sysctl_write_##__type(__fd, __req, (__type *)(__req)->arg, __nr); \ + else \ + __ret = -1; \ + } while (0) + +#define GEN_SYSCTL_READ_FUNC(__type, __conv) \ + static int sysctl_read_##__type(int fd, struct sysctl_req *req, __type *arg, int nr) \ + { \ + char buf[1024] = { 0 }; \ + int i, ret = -1; \ + char *p = buf; \ + \ + ret = read(fd, buf, sizeof(buf)); \ + if (ret < 0) { \ + pr_perror("Can't read %s", req->name); \ + ret = -1; \ + goto err; \ + } \ + \ + for (i = 0; i < nr && p < buf + sizeof(buf); p++, i++) \ + ((__type *)arg)[i] = __conv(p, &p, 10); \ + \ + if (i != nr) { \ + pr_err("Not enough params for %s (%d != %d)\n", req->name, i, nr); \ + goto err; \ + } \ + \ + ret = 0; \ + \ + err: \ + return ret; \ + } -#define GEN_SYSCTL_WRITE_FUNC(__type, __fmt) \ -static int sysctl_write_##__type(int fd, \ - struct sysctl_req *req, \ - __type *arg, \ - int nr) \ -{ \ - char buf[1024]; \ - int i, ret = -1; \ - int off = 0; \ - \ - for (i = 0; i < nr && off < sizeof(buf) - 1; i++) { \ - snprintf(&buf[off], sizeof(buf) - off, __fmt, arg[i]); \ - off += strlen(&buf[off]); \ - } \ - \ - if (i != nr) { \ - pr_err("Not enough space for %s (%d != %d)\n", \ - req->name, i, nr); \ - goto err; \ - } \ - \ - /* trailing spaces in format */ \ - while (off > 0 && isspace(buf[off - 1])) \ - off--; \ - buf[off + 0] = '\n'; \ - ret = write(fd, buf, off + 1); \ - if (ret < 0) { \ - pr_perror("Can't write %s", req->name); \ - ret = -1; \ - goto err; \ - } \ - \ - ret = 0; \ -err: \ - return ret; \ -} +#define GEN_SYSCTL_WRITE_FUNC(__type, __fmt) \ + static int sysctl_write_##__type(int fd, struct sysctl_req *req, __type *arg, int nr) \ + { \ + char buf[1024]; \ + int i, ret = -1; \ + int off = 0; \ + \ + for (i = 0; i < nr && off < sizeof(buf) - 1; i++) { \ + snprintf(&buf[off], sizeof(buf) - off, __fmt, arg[i]); \ + off += strlen(&buf[off]); \ + } \ + \ + if (i != nr) { \ + pr_err("Not enough space for %s (%d != %d)\n", req->name, i, nr); \ + goto err; \ + } \ + \ + /* trailing spaces in format */ \ + while (off > 0 && isspace(buf[off - 1])) \ + off--; \ + buf[off + 0] = '\n'; \ + ret = write(fd, buf, off + 1); \ + if (ret < 0) { \ + pr_perror("Can't write %s", req->name); \ + ret = -1; \ + goto err; \ + } \ + \ + ret = 0; \ + err: \ + return ret; \ + } GEN_SYSCTL_READ_FUNC(u32, strtoul); GEN_SYSCTL_READ_FUNC(u64, strtoull); GEN_SYSCTL_READ_FUNC(s32, strtol); GEN_SYSCTL_WRITE_FUNC(u32, "%u "); -GEN_SYSCTL_WRITE_FUNC(u64, "%"PRIu64" "); +GEN_SYSCTL_WRITE_FUNC(u64, "%" PRIu64 " "); GEN_SYSCTL_WRITE_FUNC(s32, "%d "); -static int -sysctl_write_char(int fd, struct sysctl_req *req, char *arg, int nr) +static int sysctl_write_char(int fd, struct sysctl_req *req, char *arg, int nr) { pr_debug("%s nr %d\n", req->name, nr); if (dprintf(fd, "%s\n", arg) < 0) @@ -123,19 +110,18 @@ sysctl_write_char(int fd, struct sysctl_req *req, char *arg, int nr) return 0; } -static int -sysctl_read_char(int fd, struct sysctl_req *req, char *arg, int nr) +static int sysctl_read_char(int fd, struct sysctl_req *req, char *arg, int nr) { int ret = -1; pr_debug("%s nr %d\n", req->name, nr); ret = read(fd, arg, nr - 1); if (ret < 0) { - if (errno != EIO || !(req->flags & CTL_FLAGS_READ_EIO_SKIP)) + if (errno != EIO || !(req->flags & CTL_FLAGS_READ_EIO_SKIP)) pr_perror("Can't read %s", req->name); goto err; } - arg[ret]='\0'; + arg[ret] = '\0'; ret = 0; err: @@ -144,7 +130,7 @@ err: static int sysctl_userns_arg_size(int type) { - switch(CTL_TYPE(type)) { + switch (CTL_TYPE(type)) { case __CTL_U32A: return sizeof(u32) * CTL_LEN(type); case CTL_U32: @@ -204,7 +190,7 @@ static int __userns_sysctl_op(void *arg, int proc_fd, pid_t pid) pid_t worker; // fix up the pointer - req = userns_req->reqs = (struct sysctl_req *) &userns_req[1]; + req = userns_req->reqs = (struct sysctl_req *)&userns_req[1]; /* For files in the IPC/UTS namespaces, restoring is more complicated * than for net. Unprivileged users cannot even open these files, so @@ -234,17 +220,17 @@ static int __userns_sysctl_op(void *arg, int proc_fd, pid_t pid) memset(fds, -1, sizeof(int) * userns_req->nr_req); - for (i = 0; i < userns_req->nr_req; i++) { + for (i = 0; i < userns_req->nr_req; i++) { int arg_len = sysctl_userns_arg_size(req->type); - int name_len = strlen((char *) &req[1]) + 1; + int name_len = strlen((char *)&req[1]) + 1; int total_len = sizeof(*req) + arg_len + name_len; int flags; /* fix up the pointers */ - req->name = (char *) &req[1]; + req->name = (char *)&req[1]; req->arg = req->name + name_len; - if (((char *) req) + total_len >= ((char *) userns_req) + MAX_UNSFD_MSG_SIZE) { + if (((char *)req) + total_len >= ((char *)userns_req) + MAX_UNSFD_MSG_SIZE) { pr_err("bad sysctl req %s, too big: %d\n", req->name, total_len); goto out; } @@ -268,7 +254,7 @@ static int __userns_sysctl_op(void *arg, int proc_fd, pid_t pid) reqs[i] = req; fds[i] = fd; - req = (struct sysctl_req *) (((char *) req) + total_len); + req = (struct sysctl_req *)(((char *)req) + total_len); } /* @@ -436,7 +422,7 @@ int sysctl_op(struct sysctl_req *req, size_t nr_req, int op, unsigned int ns) userns_req->op = op; userns_req->nr_req = nr_req; userns_req->ns = ns; - userns_req->reqs = (struct sysctl_req *) (&userns_req[1]); + userns_req->reqs = (struct sysctl_req *)(&userns_req[1]); cur = userns_req->reqs; for (i = 0; i < nr_req; i++) { @@ -444,7 +430,7 @@ int sysctl_op(struct sysctl_req *req, size_t nr_req, int op, unsigned int ns) int name_len = strlen(req[i].name) + 1; int total_len = sizeof(*cur) + arg_len + name_len; - if (((char *) cur) + total_len >= ((char *) userns_req) + MAX_UNSFD_MSG_SIZE) { + if (((char *)cur) + total_len >= ((char *)userns_req) + MAX_UNSFD_MSG_SIZE) { pr_err("sysctl msg %s too big: %d\n", req[i].name, total_len); return -1; } @@ -453,13 +439,13 @@ int sysctl_op(struct sysctl_req *req, size_t nr_req, int op, unsigned int ns) cur->type = req[i].type; cur->flags = req[i].flags; - cur->name = (char *) &cur[1]; + cur->name = (char *)&cur[1]; strcpy(cur->name, req[i].name); cur->arg = cur->name + name_len; memcpy(cur->arg, req[i].arg, arg_len); - cur = (struct sysctl_req *) (((char *) cur) + total_len); + cur = (struct sysctl_req *)(((char *)cur) + total_len); } fd = open_proc(PROC_SELF, "ns"); diff --git a/criu/sysfs_parse.c b/criu/sysfs_parse.c index 922e5d41d..6cd765613 100644 --- a/criu/sysfs_parse.c +++ b/criu/sysfs_parse.c @@ -67,7 +67,7 @@ static int parse_aufs_sbinfo(struct mount_info *mi, char *sbinfo, int len) } /* all ok, copy */ - if (len < 4) { /* 4 for "si_" */ + if (len < 4) { /* 4 for "si_" */ pr_err("Buffer of %d bytes too small for sbinfo\n", len); return -1; } @@ -109,7 +109,7 @@ static int fixup_aufs_path(char *path, int size) } if (aufs_branches[n] == NULL) - return 0; /* not in a branch */ + return 0; /* not in a branch */ n = snprintf(rpath, PATH_MAX, "%s", &path[blen]); if (n >= min(PATH_MAX, size)) { @@ -160,7 +160,7 @@ int parse_aufs_branches(struct mount_info *mi) if (aufs_nsid) free_aufs_branches(); - strcpy(path, SYSFS_AUFS); /* /sys/fs/aufs/ */ + strcpy(path, SYSFS_AUFS); /* /sys/fs/aufs/ */ if (parse_aufs_sbinfo(mi, &path[sizeof SYSFS_AUFS - 1], SBINFO_LEN) < 0) return -1; if ((dp = opendir(path)) == NULL) { @@ -205,7 +205,7 @@ int parse_aufs_branches(struct mount_info *mi) * Allocate an array of pointers to branch pathnames to be read. * Branches are indexed from 0 and we need a NULL pointer at the end. */ - aufs_branches = xzalloc((br_max + 2) * sizeof (char *)); + aufs_branches = xzalloc((br_max + 2) * sizeof(char *)); if (!aufs_branches) return -1; @@ -227,8 +227,7 @@ int parse_aufs_branches(struct mount_info *mi) goto err; } - if (fscanf(fp, "%ms=", &aufs_branches[br_num]) != 1 || - aufs_branches[br_num] == NULL) { + if (fscanf(fp, "%ms=", &aufs_branches[br_num]) != 1 || aufs_branches[br_num] == NULL) { pr_perror("Parse error reading %s", path); goto err; } @@ -300,8 +299,7 @@ int fixup_aufs_vma_fd(struct vma_area *vma, int vm_file_fd) pr_debug("Saved AUFS paths %s and %s\n", vma->aufs_rpath, vma->aufs_fpath); if (stat(vma->aufs_fpath, vma->vmst) < 0) { - pr_perror("Failed stat on map %"PRIx64" (%s)", - vma->e->start, vma->aufs_fpath); + pr_perror("Failed stat on map %" PRIx64 " (%s)", vma->e->start, vma->aufs_fpath); return -1; } diff --git a/criu/timens.c b/criu/timens.c index f81808abf..5803fc359 100644 --- a/criu/timens.c +++ b/criu/timens.c @@ -38,17 +38,16 @@ int dump_time_ns(int ns_id) static void normalize_timespec(struct timespec *ts) { - while (ts->tv_nsec >= NSEC_PER_SEC) { - ts->tv_nsec -= NSEC_PER_SEC; - ++ts->tv_sec; - } - while (ts->tv_nsec < 0) { - ts->tv_nsec += NSEC_PER_SEC; - --ts->tv_sec; - } + while (ts->tv_nsec >= NSEC_PER_SEC) { + ts->tv_nsec -= NSEC_PER_SEC; + ++ts->tv_sec; + } + while (ts->tv_nsec < 0) { + ts->tv_nsec += NSEC_PER_SEC; + --ts->tv_sec; + } } - int prepare_timens(int id) { int exit_code = -1; @@ -86,32 +85,30 @@ int prepare_timens(int id) goto err; clock_gettime(CLOCK_MONOTONIC, &ts); - ts.tv_sec = ts.tv_sec - prev_moff.tv_sec; + ts.tv_sec = ts.tv_sec - prev_moff.tv_sec; ts.tv_nsec = ts.tv_nsec - prev_moff.tv_nsec; - ts.tv_sec = te->monotonic->tv_sec - ts.tv_sec; + ts.tv_sec = te->monotonic->tv_sec - ts.tv_sec; ts.tv_nsec = te->monotonic->tv_nsec - ts.tv_nsec; normalize_timespec(&ts); pr_debug("timens: monotonic %ld %ld\n", ts.tv_sec, ts.tv_nsec); - if (dprintf(fd, "%d %ld %ld\n", - CLOCK_MONOTONIC, ts.tv_sec, ts.tv_nsec) < 0) { + if (dprintf(fd, "%d %ld %ld\n", CLOCK_MONOTONIC, ts.tv_sec, ts.tv_nsec) < 0) { pr_perror("Unable to set a monotonic clock offset"); goto err; } clock_gettime(CLOCK_BOOTTIME, &ts); - ts.tv_sec = ts.tv_sec - prev_boff.tv_sec; + ts.tv_sec = ts.tv_sec - prev_boff.tv_sec; ts.tv_nsec = ts.tv_nsec - prev_boff.tv_nsec; - ts.tv_sec = te->boottime->tv_sec - ts.tv_sec; + ts.tv_sec = te->boottime->tv_sec - ts.tv_sec; ts.tv_nsec = te->boottime->tv_nsec - ts.tv_nsec; normalize_timespec(&ts); pr_debug("timens: boottime %ld %ld\n", ts.tv_sec, ts.tv_nsec); - if (dprintf(fd, "%d %ld %ld\n", - CLOCK_BOOTTIME, ts.tv_sec, ts.tv_nsec) < 0) { + if (dprintf(fd, "%d %ld %ld\n", CLOCK_BOOTTIME, ts.tv_sec, ts.tv_nsec) < 0) { pr_perror("Unable to set a boottime clock offset"); goto err; } @@ -132,5 +129,4 @@ err: return exit_code; } struct ns_desc time_ns_desc = NS_DESC_ENTRY(CLONE_NEWTIME, "time"); -struct ns_desc time_for_children_ns_desc = - NS_DESC_ENTRY(CLONE_NEWTIME, "time_for_children"); +struct ns_desc time_for_children_ns_desc = NS_DESC_ENTRY(CLONE_NEWTIME, "time_for_children"); diff --git a/criu/timerfd.c b/criu/timerfd.c index b5ee5d8d7..6d637e987 100644 --- a/criu/timerfd.c +++ b/criu/timerfd.c @@ -20,19 +20,19 @@ #include "log.h" #include "common/bug.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "timerfd: " struct timerfd_dump_arg { - u32 id; - const struct fd_parms *p; + u32 id; + const struct fd_parms *p; }; struct timerfd_info { - TimerfdEntry *tfe; - struct file_desc d; - int t_fd; - struct list_head rlist; + TimerfdEntry *tfe; + struct file_desc d; + int t_fd; + struct list_head rlist; }; static LIST_HEAD(rst_timerfds); @@ -75,9 +75,9 @@ static int dump_one_timerfd(int lfd, u32 id, const struct fd_parms *p) tfe.id = id; tfe.flags = p->flags; tfe.fown = (FownEntry *)&p->fown; - pr_info("Dumping id %#x clockid %d it_value(%llu, %llu) it_interval(%llu, %llu)\n", - tfe.id, tfe.clockid, (unsigned long long)tfe.vsec, (unsigned long long)tfe.vnsec, - (unsigned long long)tfe.isec, (unsigned long long)tfe.insec); + pr_info("Dumping id %#x clockid %d it_value(%llu, %llu) it_interval(%llu, %llu)\n", tfe.id, tfe.clockid, + (unsigned long long)tfe.vsec, (unsigned long long)tfe.vnsec, (unsigned long long)tfe.isec, + (unsigned long long)tfe.insec); fe.type = FD_TYPES__TIMERFD; fe.id = tfe.id; @@ -87,8 +87,8 @@ static int dump_one_timerfd(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops timerfd_dump_ops = { - .type = FD_TYPES__TIMERFD, - .dump = dump_one_timerfd, + .type = FD_TYPES__TIMERFD, + .dump = dump_one_timerfd, }; int prepare_timerfds(struct task_restore_args *ta) @@ -106,15 +106,15 @@ int prepare_timerfds(struct task_restore_args *ta) if (!t) return -1; - t->id = tfe->id; - t->fd = ti->t_fd; - t->clockid = tfe->clockid; - t->ticks = (unsigned long)tfe->ticks; - t->settime_flags = tfe->settime_flags; - t->val.it_interval.tv_sec = (time_t)tfe->isec; - t->val.it_interval.tv_nsec = (long)tfe->insec; - t->val.it_value.tv_sec = (time_t)tfe->vsec; - t->val.it_value.tv_nsec = (long)tfe->vnsec; + t->id = tfe->id; + t->fd = ti->t_fd; + t->clockid = tfe->clockid; + t->ticks = (unsigned long)tfe->ticks; + t->settime_flags = tfe->settime_flags; + t->val.it_interval.tv_sec = (time_t)tfe->isec; + t->val.it_interval.tv_nsec = (long)tfe->insec; + t->val.it_value.tv_sec = (time_t)tfe->vsec; + t->val.it_value.tv_nsec = (long)tfe->vnsec; ta->timerfd_n++; } @@ -133,8 +133,8 @@ static int timerfd_open(struct file_desc *d, int *new_fd) pr_info("Creating timerfd id %#x clockid %d settime_flags %x ticks %llu " "it_value(%llu, %llu) it_interval(%llu, %llu)\n", tfe->id, tfe->clockid, tfe->settime_flags, (unsigned long long)tfe->ticks, - (unsigned long long)tfe->vsec, (unsigned long long)tfe->vnsec, - (unsigned long long)tfe->isec, (unsigned long long)tfe->insec); + (unsigned long long)tfe->vsec, (unsigned long long)tfe->vnsec, (unsigned long long)tfe->isec, + (unsigned long long)tfe->insec); tmp = timerfd_create(tfe->clockid, 0); if (tmp < 0) { @@ -159,8 +159,8 @@ err_close: } static struct file_desc_ops timerfd_desc_ops = { - .type = FD_TYPES__TIMERFD, - .open = timerfd_open, + .type = FD_TYPES__TIMERFD, + .open = timerfd_open, }; static int collect_one_timerfd(void *o, ProtobufCMessage *msg, struct cr_img *i) @@ -179,8 +179,8 @@ static int collect_one_timerfd(void *o, ProtobufCMessage *msg, struct cr_img *i) } struct collect_image_info timerfd_cinfo = { - .fd_type = CR_FD_TIMERFD, - .pb_type = PB_TIMERFD, - .priv_size = sizeof(struct timerfd_info), - .collect = collect_one_timerfd, + .fd_type = CR_FD_TIMERFD, + .pb_type = PB_TIMERFD, + .priv_size = sizeof(struct timerfd_info), + .collect = collect_one_timerfd, }; diff --git a/criu/tls.c b/criu/tls.c index e865368c4..60bd105bc 100644 --- a/criu/tls.c +++ b/criu/tls.c @@ -10,17 +10,17 @@ /* Compatability with GnuTLS verson <3.5 */ #ifndef GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR -# define GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR GNUTLS_E_CERTIFICATE_ERROR +#define GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR GNUTLS_E_CERTIFICATE_ERROR #endif -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "tls: " #define CRIU_PKI_DIR SYSCONFDIR "/pki" -#define CRIU_CACERT CRIU_PKI_DIR "/CA/cacert.pem" -#define CRIU_CACRL CRIU_PKI_DIR "/CA/cacrl.pem" -#define CRIU_CERT CRIU_PKI_DIR "/criu/cert.pem" -#define CRIU_KEY CRIU_PKI_DIR "/criu/private/key.pem" +#define CRIU_CACERT CRIU_PKI_DIR "/CA/cacert.pem" +#define CRIU_CACRL CRIU_PKI_DIR "/CA/cacrl.pem" +#define CRIU_CERT CRIU_PKI_DIR "/criu/cert.pem" +#define CRIU_KEY CRIU_PKI_DIR "/criu/private/key.pem" #define SPLICE_BUF_SZ_MAX (PIPE_BUF * 100) @@ -42,7 +42,7 @@ void tls_terminate_session(void) do { /* don't wait for peer to close connection */ ret = gnutls_bye(session, GNUTLS_SHUT_WR); - } while(ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED); + } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED); gnutls_deinit(session); } @@ -60,7 +60,7 @@ ssize_t tls_send(const void *buf, size_t len, int flags) tls_sk_flags = 0; if (ret < 0) { - switch(ret) { + switch (ret) { case GNUTLS_E_AGAIN: errno = EAGAIN; break; @@ -103,7 +103,7 @@ int tls_send_data_from_fd(int fd, unsigned long len) goto err; } - for(sent = 0; sent < copied; sent += ret) { + for (sent = 0; sent < copied; sent += ret) { ret = tls_send((buf + sent), (copied - sent), 0); if (ret < 0) { tls_perror("Failed sending data", ret); @@ -126,8 +126,7 @@ ssize_t tls_recv(void *buf, size_t len, int flags) tls_sk_flags = 0; /* Check if there are any data to receive in the gnutls buffers. */ - if (flags == MSG_DONTWAIT - && (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED)) { + if (flags == MSG_DONTWAIT && (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED)) { size_t pending = gnutls_record_check_pending(session); if (pending > 0) { pr_debug("Receiving pending data (%zu bytes)\n", pending); @@ -177,7 +176,7 @@ int tls_recv_data_to_fd(int fd, unsigned long len) } gnutls_packet_get(packet, &pdata, NULL); - for(w = 0; w < pdata.size; w += ret) { + for (w = 0; w < pdata.size; w += ret) { ret = write(fd, (pdata.data + w), (pdata.size - w)); if (ret < 0) { pr_perror("Failed writing to fd"); @@ -219,8 +218,7 @@ static int tls_x509_verify_peer_cert(void) if (status != 0) { pr_err("Invalid certificate\n"); - tls_handshake_verification_status_print( - GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR, status); + tls_handshake_verification_status_print(GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR, status); return -1; } @@ -300,7 +298,7 @@ static int tls_x509_setup_creds(void) return 0; } -static ssize_t _tls_push_cb(void *p, const void* data, size_t sz) +static ssize_t _tls_push_cb(void *p, const void *data, size_t sz) { int fd = *(int *)(p); int ret = send(fd, data, sz, tls_sk_flags); @@ -312,7 +310,7 @@ static ssize_t _tls_push_cb(void *p, const void* data, size_t sz) return ret; } -static ssize_t _tls_pull_cb(void *p, void* data, size_t sz) +static ssize_t _tls_pull_cb(void *p, void *data, size_t sz) { int fd = *(int *)(p); int ret = recv(fd, data, sz, tls_sk_flags); diff --git a/criu/tty.c b/criu/tty.c index dee8d46bf..1598ad956 100644 --- a/criu/tty.c +++ b/criu/tty.c @@ -73,53 +73,53 @@ * it depends on "devpts" mount point path. */ -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "tty: " struct tty_data_entry { - struct list_head list; - TtyDataEntry *tde; + struct list_head list; + TtyDataEntry *tde; }; struct tty_info { - struct list_head list; - struct file_desc d; + struct list_head list; + struct file_desc d; - struct file_desc *reg_d; + struct file_desc *reg_d; - TtyFileEntry *tfe; - TtyInfoEntry *tie; + TtyFileEntry *tfe; + TtyInfoEntry *tie; - struct list_head sibling; - struct tty_driver *driver; + struct list_head sibling; + struct tty_driver *driver; - bool create; - bool inherit; + bool create; + bool inherit; - struct tty_info *ctl_tty; - struct tty_info *link; - struct tty_data_entry *tty_data; + struct tty_info *ctl_tty; + struct tty_info *link; + struct tty_data_entry *tty_data; - int fdstore_id; + int fdstore_id; }; struct tty_dump_info { - struct list_head list; - - u32 id; - pid_t sid; - pid_t pgrp; - pid_t pid_real; - int fd; - int mnt_id; - struct tty_driver *driver; - - int index; - int lfd; - int flags; - struct tty_dump_info *link; - void *tty_data; - size_t tty_data_size; + struct list_head list; + + u32 id; + pid_t sid; + pid_t pgrp; + pid_t pid_real; + int fd; + int mnt_id; + struct tty_driver *driver; + + int index; + int lfd; + int flags; + struct tty_dump_info *link; + void *tty_data; + size_t tty_data_size; }; static bool stdin_isatty = false; @@ -136,37 +136,37 @@ static int self_stdin_fdid = -1; * Pretty acceptable trade off in a sake of simplicity. */ -#define MAX_TTYS 1088 +#define MAX_TTYS 1088 /* * Custom indices should be even numbers just in case if we * need odds for pair numbering someday. */ -#define MAX_PTY_INDEX 1000 -#define CONSOLE_INDEX 1002 -#define VT_INDEX 1004 -#define CTTY_INDEX 1006 -#define STTY_INDEX 1010 -#define ETTY_INDEX 1012 -#define ETTY_INDEX_MAX 1076 -#define INDEX_ERR (MAX_TTYS + 1) +#define MAX_PTY_INDEX 1000 +#define CONSOLE_INDEX 1002 +#define VT_INDEX 1004 +#define CTTY_INDEX 1006 +#define STTY_INDEX 1010 +#define ETTY_INDEX 1012 +#define ETTY_INDEX_MAX 1076 +#define INDEX_ERR (MAX_TTYS + 1) static DECLARE_BITMAP(tty_bitmap, (MAX_TTYS << 1)); static DECLARE_BITMAP(tty_active_pairs, (MAX_TTYS << 1)); struct tty_driver { - short type; - short subtype; - char *name; - int index; - int (*fd_get_index)(int fd, const struct fd_parms *p); - int (*img_get_index)(struct tty_info *ti); - int (*open)(struct tty_info *ti); + short type; + short subtype; + char *name; + int index; + int (*fd_get_index)(int fd, const struct fd_parms *p); + int (*img_get_index)(struct tty_info *ti); + int (*open)(struct tty_info *ti); }; -#define TTY_SUBTYPE_MASTER 0x0001 -#define TTY_SUBTYPE_SLAVE 0x0002 +#define TTY_SUBTYPE_MASTER 0x0001 +#define TTY_SUBTYPE_SLAVE 0x0002 static int ptm_fd_get_index(int fd, const struct fd_parms *p) { @@ -207,51 +207,51 @@ static int ext_fd_get_index(int fd, const struct fd_parms *p) static int pty_open_ptmx(struct tty_info *info); static struct tty_driver ptm_driver = { - .type = TTY_TYPE__PTY, - .subtype = TTY_SUBTYPE_MASTER, - .name = "ptmx", - .fd_get_index = ptm_fd_get_index, - .img_get_index = pty_get_index, - .open = pty_open_ptmx, + .type = TTY_TYPE__PTY, + .subtype = TTY_SUBTYPE_MASTER, + .name = "ptmx", + .fd_get_index = ptm_fd_get_index, + .img_get_index = pty_get_index, + .open = pty_open_ptmx, }; static int open_simple_tty(struct tty_info *info); static struct tty_driver console_driver = { - .type = TTY_TYPE__CONSOLE, - .name = "console", - .index = CONSOLE_INDEX, - .open = open_simple_tty, + .type = TTY_TYPE__CONSOLE, + .name = "console", + .index = CONSOLE_INDEX, + .open = open_simple_tty, }; static struct tty_driver ctty_driver = { - .type = TTY_TYPE__CTTY, - .name = "ctty", - .index = CTTY_INDEX, - .open = open_simple_tty, + .type = TTY_TYPE__CTTY, + .name = "ctty", + .index = CTTY_INDEX, + .open = open_simple_tty, }; static struct tty_driver vt_driver = { - .type = TTY_TYPE__VT, - .name = "vt", - .index = VT_INDEX, - .open = open_simple_tty, + .type = TTY_TYPE__VT, + .name = "vt", + .index = VT_INDEX, + .open = open_simple_tty, }; static int open_ext_tty(struct tty_info *info); static struct tty_driver ext_driver = { - .type = TTY_TYPE__EXT_TTY, - .name = "ext", - .index = ETTY_INDEX, - .open = open_ext_tty, - .fd_get_index = ext_fd_get_index, + .type = TTY_TYPE__EXT_TTY, + .name = "ext", + .index = ETTY_INDEX, + .open = open_ext_tty, + .fd_get_index = ext_fd_get_index, }; static struct tty_driver serial_driver = { - .type = TTY_TYPE__SERIAL, - .name = "serial", - .index = STTY_INDEX, - .open = open_simple_tty, + .type = TTY_TYPE__SERIAL, + .name = "serial", + .index = STTY_INDEX, + .open = open_simple_tty, }; static int pts_fd_get_index(int fd, const struct fd_parms *p) @@ -275,12 +275,12 @@ static int pts_fd_get_index(int fd, const struct fd_parms *p) } static struct tty_driver pts_driver = { - .type = TTY_TYPE__PTY, - .subtype = TTY_SUBTYPE_SLAVE, - .name = "pts", - .fd_get_index = pts_fd_get_index, - .img_get_index = pty_get_index, - .open = pty_open_ptmx, + .type = TTY_TYPE__PTY, + .subtype = TTY_SUBTYPE_SLAVE, + .name = "pts", + .fd_get_index = pts_fd_get_index, + .img_get_index = pty_get_index, + .open = pty_open_ptmx, }; struct tty_driver *get_tty_driver(dev_t rdev, dev_t dev) @@ -288,7 +288,7 @@ struct tty_driver *get_tty_driver(dev_t rdev, dev_t dev) int major, minor; char id[42]; - snprintf(id, sizeof(id), "tty[%"PRIx64":%"PRIx64"]", rdev, dev); + snprintf(id, sizeof(id), "tty[%" PRIx64 ":%" PRIx64 "]", rdev, dev); if (external_lookup_id(id) || inherit_fd_lookup_id(id) >= 0) return &ext_driver; @@ -328,7 +328,7 @@ struct tty_driver *get_tty_driver(dev_t rdev, dev_t dev) case USB_SERIAL_MAJOR: case LOW_DENSE_SERIAL_MAJOR: return &serial_driver; - case UNIX98_PTY_MASTER_MAJOR ... (UNIX98_PTY_MASTER_MAJOR + UNIX98_PTY_MAJOR_COUNT - 1): + case UNIX98_PTY_MASTER_MAJOR ...(UNIX98_PTY_MASTER_MAJOR + UNIX98_PTY_MAJOR_COUNT - 1): return &ptm_driver; case UNIX98_PTY_SLAVE_MAJOR: return &pts_driver; @@ -362,26 +362,25 @@ int tty_init_restore(void) return 0; } -#define winsize_copy(d, s) \ - do { \ - ASSIGN_MEMBER((d), (s), ws_row); \ - ASSIGN_MEMBER((d), (s), ws_col); \ - ASSIGN_MEMBER((d), (s), ws_xpixel); \ - ASSIGN_MEMBER((d), (s), ws_ypixel); \ +#define winsize_copy(d, s) \ + do { \ + ASSIGN_MEMBER((d), (s), ws_row); \ + ASSIGN_MEMBER((d), (s), ws_col); \ + ASSIGN_MEMBER((d), (s), ws_xpixel); \ + ASSIGN_MEMBER((d), (s), ws_ypixel); \ } while (0) -#define termios_copy(d, s) \ - do { \ - struct termios __t; \ - \ - memcpy((d)->c_cc, (s)->c_cc, \ - sizeof(__t.c_cc)); \ - \ - ASSIGN_MEMBER((d),(s), c_iflag); \ - ASSIGN_MEMBER((d),(s), c_oflag); \ - ASSIGN_MEMBER((d),(s), c_cflag); \ - ASSIGN_MEMBER((d),(s), c_lflag); \ - ASSIGN_MEMBER((d),(s), c_line); \ +#define termios_copy(d, s) \ + do { \ + struct termios __t; \ + \ + memcpy((d)->c_cc, (s)->c_cc, sizeof(__t.c_cc)); \ + \ + ASSIGN_MEMBER((d), (s), c_iflag); \ + ASSIGN_MEMBER((d), (s), c_oflag); \ + ASSIGN_MEMBER((d), (s), c_cflag); \ + ASSIGN_MEMBER((d), (s), c_lflag); \ + ASSIGN_MEMBER((d), (s), c_line); \ } while (0) static int tty_gen_id(struct tty_driver *driver, int index) @@ -399,7 +398,8 @@ static int tty_verify_active_pairs(void) { unsigned long i, unpaired_slaves = 0; - for_each_bit(i, tty_active_pairs) { + for_each_bit(i, tty_active_pairs) + { if ((i % 2) == 0) { if (test_bit(i + 1, tty_active_pairs)) { i++; @@ -460,18 +460,17 @@ static struct file_desc *pty_alloc_reg(struct tty_info *info, bool add) if (tty_is_master(info)) strcpy(r->rfe->name, "/dev/ptmx"); else - snprintf(r->rfe->name, namelen, "/dev/pts/%u", - info->tie->pty->index); + snprintf(r->rfe->name, namelen, "/dev/pts/%u", info->tie->pty->index); if (add) file_desc_add(&r->d, tfe->id, &noops); else file_desc_init(&r->d, tfe->id, &noops); - r->rfe->id = tfe->id; - r->rfe->flags = tfe->flags; - r->rfe->fown = tfe->fown; - r->path = &r->rfe->name[1]; + r->rfe->id = tfe->id; + r->rfe->flags = tfe->flags; + r->rfe->fown = tfe->fown; + r->path = &r->rfe->name[1]; return &r->d; } @@ -495,8 +494,7 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int subty struct reg_file_info *new, *orig; struct file_desc *fake_desc; - pr_debug("Allocating fake descriptor for %#x (reg_d %p)\n", - info->tfe->id, info->reg_d); + pr_debug("Allocating fake descriptor for %#x (reg_d %p)\n", info->tfe->id, info->reg_d); BUG_ON(!info->reg_d); BUG_ON(!is_pty(info->driver)); @@ -526,11 +524,9 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int subty strcat(inverted_path, "ptmx"); } else { if (slash_at >= 3 && strncmp(&inverted_path[slash_at - 3], "pts", 3)) - snprintf(&inverted_path[slash_at + 1], 10, "pts/%u", - info->tie->pty->index); + snprintf(&inverted_path[slash_at + 1], 10, "pts/%u", info->tie->pty->index); else - snprintf(&inverted_path[slash_at + 1], 10, "%u", - info->tie->pty->index); + snprintf(&inverted_path[slash_at + 1], 10, "%u", info->tie->pty->index); } new->rfe->name = inverted_path; @@ -540,8 +536,8 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int subty return new; } -#define pty_alloc_fake_master(info) pty_alloc_fake_reg(info, TTY_SUBTYPE_MASTER) -#define pty_alloc_fake_slave(info) pty_alloc_fake_reg(info, TTY_SUBTYPE_SLAVE) +#define pty_alloc_fake_master(info) pty_alloc_fake_reg(info, TTY_SUBTYPE_MASTER) +#define pty_alloc_fake_slave(info) pty_alloc_fake_reg(info, TTY_SUBTYPE_SLAVE) static void pty_free_fake_reg(struct reg_file_info **r) { @@ -590,8 +586,7 @@ static char *path_from_reg(struct file_desc *d) return rfi->path; } -static int __pty_open_ptmx_index(int index, int flags, - int (*cb)(void *arg, int flags), void *arg, char *path) +static int __pty_open_ptmx_index(int index, int flags, int (*cb)(void *arg, int flags), void *arg, char *path) { int fds[32], i, ret = -1, cur_idx; @@ -607,8 +602,7 @@ static int __pty_open_ptmx_index(int index, int flags, } if (ioctl(fds[i], TIOCGPTN, &cur_idx)) { - pr_perror("Can't obtain current index on %s", - path); + pr_perror("Can't obtain current index on %s", path); break; } @@ -628,8 +622,7 @@ static int __pty_open_ptmx_index(int index, int flags, if (cur_idx < index && (index - cur_idx) < ARRAY_SIZE(fds)) continue; - pr_err("Unable to open %s with specified index %d\n", - path, index); + pr_err("Unable to open %s with specified index %d\n", path, index); break; } @@ -648,8 +641,7 @@ static int pty_open_ptmx_index(struct file_desc *d, struct tty_info *info, int f if (info->fdstore_id >= 0) return fdstore_get(info->fdstore_id); - return __pty_open_ptmx_index(info->tie->pty->index, flags, - open_tty_reg, d, path_from_reg(d)); + return __pty_open_ptmx_index(info->tie->pty->index, flags, open_tty_reg, d, path_from_reg(d)); } static int unlock_pty(int fd) @@ -735,8 +727,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d) } out: - pr_info("Restore session %d by %d tty (index %d)\n", - info->tie->sid, (int)getpid(), index); + pr_info("Restore session %d by %d tty (index %d)\n", info->tie->sid, (int)getpid(), index); ret = tty_set_sid(slave); if (!ret) @@ -781,10 +772,9 @@ static bool tty_is_hung(struct tty_info *info) static bool tty_has_active_pair(struct tty_info *info) { - int d = tty_is_master(info) ? -1 : + 1; + int d = tty_is_master(info) ? -1 : +1; - return test_bit(info->tfe->tty_info_id + d, - tty_active_pairs); + return test_bit(info->tfe->tty_info_id + d, tty_active_pairs); } static void tty_show_pty_info(char *prefix, struct tty_info *info) @@ -797,17 +787,16 @@ static void tty_show_pty_info(char *prefix, struct tty_info *info) else index = driver->index; - pr_info("%s driver %s id %#x index %d (master %d sid %d pgrp %d inherit %d)\n", - prefix, info->driver->name, info->tfe->id, index, - tty_is_master(info), info->tie->sid, info->tie->pgrp, info->inherit); + pr_info("%s driver %s id %#x index %d (master %d sid %d pgrp %d inherit %d)\n", prefix, info->driver->name, + info->tfe->id, index, tty_is_master(info), info->tie->sid, info->tie->pgrp, info->inherit); } struct tty_parms { int tty_id; unsigned has; -#define HAS_TERMIOS_L 0x1 -#define HAS_TERMIOS 0x2 -#define HAS_WINS 0x4 +#define HAS_TERMIOS_L 0x1 +#define HAS_TERMIOS 0x2 +#define HAS_WINS 0x4 struct termios tl; struct termios t; struct winsize w; @@ -828,16 +817,13 @@ static int do_restore_tty_parms(void *arg, int fd, pid_t pid) * on termios too. Just to be on the safe side. */ - if ((p->has & HAS_TERMIOS_L) && - ioctl(fd, TIOCSLCKTRMIOS, &p->tl) < 0) + if ((p->has & HAS_TERMIOS_L) && ioctl(fd, TIOCSLCKTRMIOS, &p->tl) < 0) goto err; - if ((p->has & HAS_TERMIOS) && - ioctl(fd, TCSETS, &p->t) < 0) + if ((p->has & HAS_TERMIOS) && ioctl(fd, TCSETS, &p->t) < 0) goto err; - if ((p->has & HAS_WINS) && - ioctl(fd, TIOCSWINSZ, &p->w) < 0) + if ((p->has & HAS_WINS) && ioctl(fd, TIOCSWINSZ, &p->w) < 0) goto err; return 0; @@ -883,9 +869,7 @@ static int restore_tty_params(int fd, struct tty_info *info) if (info->tie->has_uid && info->tie->has_gid) { if (fchown(fd, info->tie->uid, info->tie->gid)) { - pr_perror("Can't setup uid %d gid %d on %#x", - (int)info->tie->uid, - (int)info->tie->gid, + pr_perror("Can't setup uid %d gid %d on %#x", (int)info->tie->uid, (int)info->tie->gid, info->tfe->id); return -1; } @@ -906,13 +890,11 @@ static void pty_restore_queued_data(struct tty_info *info, int fd) ProtobufCBinaryData bd = info->tty_data->tde->data; int retval; - pr_debug("restore queued data on %#x (%zu bytes)\n", - info->tfe->id, (size_t)bd.len); + pr_debug("restore queued data on %#x (%zu bytes)\n", info->tfe->id, (size_t)bd.len); retval = write(fd, bd.data, bd.len); if (retval != bd.len) - pr_err("Restored %d bytes while %zu expected\n", - retval, (size_t)bd.len); + pr_err("Restored %d bytes while %zu expected\n", retval, (size_t)bd.len); } } @@ -933,8 +915,7 @@ static int pty_open_slaves(struct tty_info *info) if (restore_tty_params(fd, slave)) goto err; - pr_debug("send slave %#x fd %d connected on %s\n", - slave->tfe->id, fd, path_from_reg(slave->reg_d)); + pr_debug("send slave %#x fd %d connected on %s\n", slave->tfe->id, fd, path_from_reg(slave->reg_d)); if (send_desc_to_peer(fd, &slave->d)) { pr_err("Can't send file descriptor\n"); @@ -989,17 +970,14 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave) goto err; master = pty_open_ptmx_index(&fake->d, slave, O_RDWR); if (master < 0) { - pr_err("Can't open master pty %x (index %d)\n", - slave->tfe->id, slave->tie->pty->index); + pr_err("Can't open master pty %x (index %d)\n", slave->tfe->id, slave->tie->pty->index); goto err; } if (unlock_pty(master)) goto err; - if (opts.orphan_pts_master && - rpc_send_fd(ACT_ORPHAN_PTS_MASTER, master) == 0) { - + if (opts.orphan_pts_master && rpc_send_fd(ACT_ORPHAN_PTS_MASTER, master) == 0) { fd = open_tty_reg(slave->reg_d, slave->tfe->flags); if (fd < 0) { pr_err("Can't open slave pty %s\n", path_from_reg(slave->reg_d)); @@ -1021,16 +999,14 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave) return -1; } - pr_info("Migrated slave peer %#x -> to fd %d\n", - slave->tfe->id, fd); + pr_info("Migrated slave peer %#x -> to fd %d\n", slave->tfe->id, fd); } else { fake = pty_alloc_fake_master(slave); if (!fake) goto err; master = pty_open_ptmx_index(&fake->d, slave, O_RDONLY); if (master < 0) { - pr_err("Can't open master pty %#x (index %d)\n", - slave->tfe->id, slave->tie->pty->index); + pr_err("Can't open master pty %#x (index %d)\n", slave->tfe->id, slave->tie->pty->index); goto err; } @@ -1042,7 +1018,6 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave) pr_err("Can't open slave pty %s\n", path_from_reg(slave->reg_d)); goto err; } - } out: @@ -1071,8 +1046,7 @@ out: if (tty_set_prgp(fd, root_item->pgid)) goto err; } else { - pr_debug("Restore inherited group %d\n", - getpgid(getppid())); + pr_debug("Restore inherited group %d\n", getpgid(getppid())); if (tty_set_prgp(fd, getpgid(getppid()))) goto err; } @@ -1097,8 +1071,7 @@ static int pty_open_ptmx(struct tty_info *info) master = pty_open_ptmx_index(info->reg_d, info, info->tfe->flags); if (master < 0) { - pr_err("Can't open master pty %#x (index %d)\n", - info->tfe->id, info->tie->pty->index); + pr_err("Can't open master pty %#x (index %d)\n", info->tfe->id, info->tie->pty->index); return -1; } @@ -1112,8 +1085,7 @@ static int pty_open_ptmx(struct tty_info *info) int packet_mode = 1; if (ioctl(master, TIOCPKT, &packet_mode) < 0) { - pr_perror("Can't set packed mode on %#x", - info->tfe->id); + pr_perror("Can't set packed mode on %#x", info->tfe->id); goto err; } } @@ -1138,8 +1110,7 @@ static int open_simple_tty(struct tty_info *info) fd = open_tty_reg(info->reg_d, info->tfe->flags); if (fd < 0) { - pr_err("Can't open tty %s %#x\n", - info->driver->name, info->tfe->id); + pr_err("Can't open tty %s %#x\n", info->driver->name, info->tfe->id); return -1; } @@ -1189,8 +1160,7 @@ static bool tty_deps_restored(struct tty_info *info) tmp = container_of(fle->desc, struct tty_info, d); /* slaves wait for masters except ctty */ - if (tmp->driver->type == TTY_TYPE__CTTY || - !tty_is_master(tmp)) + if (tmp->driver->type == TTY_TYPE__CTTY || !tty_is_master(tmp)) continue; if (fle->stage != FLE_RESTORED) return false; @@ -1232,9 +1202,9 @@ static char *tty_d_name(struct file_desc *d, char *buf, size_t s) } static struct file_desc_ops tty_desc_ops = { - .type = FD_TYPES__TTY, - .open = tty_open, - .name = tty_d_name, + .type = FD_TYPES__TTY, + .open = tty_open, + .name = tty_d_name, }; static struct pstree_item *find_first_sid(int sid) @@ -1259,9 +1229,9 @@ static int add_fake_fle(struct pstree_item *item, u32 desc_id) fdinfo_entry__init(e); - e->id = desc_id; - e->fd = find_unused_fd(item, -1); - e->type = FD_TYPES__TTY; + e->id = desc_id; + e->fd = find_unused_fd(item, -1); + e->type = FD_TYPES__TTY; if (collect_fd(vpid(item), e, rsti(item), true)) { xfree(e); @@ -1310,8 +1280,8 @@ static int ctl_tty_open(struct file_desc *d, int *new_fd) * fles of type FD_TYPES__TTY indirectly. */ static struct file_desc_ops ctl_tty_desc_ops = { - .type = FD_TYPES__CTL_TTY, - .open = ctl_tty_open, + .type = FD_TYPES__CTL_TTY, + .open = ctl_tty_open, }; static int prepare_ctl_tty(struct pstree_item *item, u32 ctl_tty_id) @@ -1337,8 +1307,8 @@ static int prepare_ctl_tty(struct pstree_item *item, u32 ctl_tty_id) * Add a fake ctl_tty depending on the above fake fle, which will * actually restore the session. */ - ctl_tty = xmalloc(sizeof(*ctl_tty)); - e = xmalloc(sizeof(*e)); + ctl_tty = xmalloc(sizeof(*ctl_tty)); + e = xmalloc(sizeof(*e)); if (!ctl_tty || !e) goto err; @@ -1353,9 +1323,9 @@ static int prepare_ctl_tty(struct pstree_item *item, u32 ctl_tty_id) fdinfo_entry__init(e); - e->id = ctl_tty_id; - e->fd = find_unused_fd(item, -1); - e->type = FD_TYPES__CTL_TTY; + e->id = ctl_tty_id; + e->fd = find_unused_fd(item, -1); + e->type = FD_TYPES__CTL_TTY; if (collect_fd(vpid(item), e, rsti(item), true)) goto err; @@ -1442,8 +1412,7 @@ static int tty_find_restoring_task(struct tty_info *info) */ item = find_first_sid(info->tie->sid); if (item && vpid(item) == item->sid) { - pr_info("Set a control terminal %#x to %d\n", - info->tfe->id, info->tie->sid); + pr_info("Set a control terminal %#x to %d\n", info->tfe->id, info->tie->sid); return prepare_ctl_tty(item, info->tfe->id); } @@ -1501,8 +1470,7 @@ static int tty_setup_orphan_slavery(void) if (!has_leader) { m->create = true; - pr_debug("Found orphan slave fake leader (%#x)\n", - m->tfe->id); + pr_debug("Found orphan slave fake leader (%#x)\n", m->tfe->id); } } @@ -1542,8 +1510,7 @@ static int tty_setup_slavery(void) * terminal. */ list_for_each_entry(info, &all_ttys, list) { - if (!info->tie->sid || info->ctl_tty || - info->driver->type == TTY_TYPE__CTTY) + if (!info->tie->sid || info->ctl_tty || info->driver->type == TTY_TYPE__CTTY) continue; if (!tty_is_master(info) && info->link) @@ -1553,8 +1520,7 @@ static int tty_setup_slavery(void) pr_debug("ctl tty leader %#x\n", info->tfe->id); peer = info; list_for_each_entry_safe_continue(peer, m, &all_ttys, list) { - if (!peer->tie->sid || peer->ctl_tty || - peer->driver->type == TTY_TYPE__CTTY) + if (!peer->tie->sid || peer->ctl_tty || peer->driver->type == TTY_TYPE__CTTY) continue; if (peer->tie->sid == info->tie->sid) { pr_debug(" `- slave %#x\n", peer->tfe->id); @@ -1599,23 +1565,17 @@ static int tty_setup_slavery(void) static int verify_termios(u32 id, TermiosEntry *e) { if (e && e->n_c_cc < TERMIOS_NCC) { - pr_err("pty ID %#x n_c_cc (%d) has wrong value\n", - id, (int)e->n_c_cc); + pr_err("pty ID %#x n_c_cc (%d) has wrong value\n", id, (int)e->n_c_cc); return -1; } return 0; } -#define term_opts_missing_cmp(tie, op) \ - (!(tie)->termios op \ - !(tie)->termios_locked op \ - !(tie)->winsize) +#define term_opts_missing_cmp(tie, op) (!(tie)->termios op !(tie)->termios_locked op !(tie)->winsize) -#define term_opts_missing_any(p) \ - term_opts_missing_cmp(p, ||) +#define term_opts_missing_any(p) term_opts_missing_cmp(p, ||) -#define term_opts_missing_all(p) \ - term_opts_missing_cmp(p, &&) +#define term_opts_missing_all(p) term_opts_missing_cmp(p, &&) static int verify_info(TtyInfoEntry *tie, struct tty_driver *driver) { @@ -1634,8 +1594,7 @@ static int verify_info(TtyInfoEntry *tie, struct tty_driver *driver) } } - if (verify_termios(tie->id, tie->termios_locked) || - verify_termios(tie->id, tie->termios)) + if (verify_termios(tie->id, tie->termios_locked) || verify_termios(tie->id, tie->termios)) return -1; if (tie->termios && tie->id > (MAX_TTYS << 1)) @@ -1678,8 +1637,7 @@ static int collect_one_tty_info_entry(void *obj, ProtobufCMessage *msg, struct c driver = get_tty_driver(tie->rdev, tie->dev); if (driver == NULL) { - pr_err("Unable to find a tty driver (rdev %#x dev %#x)\n", - tie->rdev, tie->dev); + pr_err("Unable to find a tty driver (rdev %#x dev %#x)\n", tie->rdev, tie->dev); return -1; } @@ -1712,10 +1670,10 @@ static int collect_one_tty_info_entry(void *obj, ProtobufCMessage *msg, struct c } struct collect_image_info tty_info_cinfo = { - .fd_type = CR_FD_TTY_INFO, - .pb_type = PB_TTY_INFO, - .collect = collect_one_tty_info_entry, - .flags = COLLECT_NOFREE, + .fd_type = CR_FD_TTY_INFO, + .pb_type = PB_TTY_INFO, + .collect = collect_one_tty_info_entry, + .flags = COLLECT_NOFREE, }; static int prep_tty_restore_cb(struct pprep_head *ph) @@ -1761,8 +1719,7 @@ static int tty_info_setup(struct tty_info *info) * reg file rectord because they are inherited from * command line on restore. */ - info->reg_d = try_collect_special_file( info->tfe->has_regf_id ? - info->tfe->regf_id : info->tfe->id, 1); + info->reg_d = try_collect_special_file(info->tfe->has_regf_id ? info->tfe->regf_id : info->tfe->id, 1); if (!info->reg_d) { if (info->driver->type != TTY_TYPE__EXT_TTY) { if (!deprecated_ok("TTY w/o regfile")) @@ -1771,8 +1728,7 @@ static int tty_info_setup(struct tty_info *info) if (is_pty(info->driver)) { info->reg_d = pty_alloc_reg(info, true); if (!info->reg_d) { - pr_err("Can't generate new reg descriptor for id %#x\n", - info->tfe->id); + pr_err("Can't generate new reg descriptor for id %#x\n", info->tfe->id); return -1; } } else { @@ -1791,10 +1747,10 @@ static int tty_info_setup(struct tty_info *info) } struct collect_image_info tty_cinfo = { - .fd_type = CR_FD_TTY_FILES, - .pb_type = PB_TTY_FILE, - .priv_size = sizeof(struct tty_info), - .collect = collect_one_tty, + .fd_type = CR_FD_TTY_FILES, + .pb_type = PB_TTY_FILE, + .priv_size = sizeof(struct tty_info), + .collect = collect_one_tty, }; static int collect_one_tty_data(void *obj, ProtobufCMessage *msg, struct cr_img *i) @@ -1803,8 +1759,7 @@ static int collect_one_tty_data(void *obj, ProtobufCMessage *msg, struct cr_img struct tty_info *info; tdo->tde = pb_msg(msg, TtyDataEntry); - pr_debug("Collected data for id %#x (size %zu bytes)\n", - tdo->tde->tty_id, (size_t)tdo->tde->data.len); + pr_debug("Collected data for id %#x (size %zu bytes)\n", tdo->tde->tty_id, (size_t)tdo->tde->data.len); list_for_each_entry(info, &all_ttys, list) { if (tdo->tde->tty_id == info->tie->id) { @@ -1818,10 +1773,10 @@ static int collect_one_tty_data(void *obj, ProtobufCMessage *msg, struct cr_img } struct collect_image_info tty_cdata = { - .fd_type = CR_FD_TTY_DATA, - .pb_type = PB_TTY_DATA, - .priv_size = sizeof(struct tty_data_entry), - .collect = collect_one_tty_data, + .fd_type = CR_FD_TTY_DATA, + .pb_type = PB_TTY_DATA, + .priv_size = sizeof(struct tty_data_entry), + .collect = collect_one_tty_data, }; /* Make sure the ttys we're dumping do belong our process tree */ @@ -1855,16 +1810,15 @@ int dump_verify_tty_sids(void) if (!item || vpid(item) != dinfo->sid) { if (!opts.shell_job) { pr_err("Found dangling tty with sid %d pgid %d (%s) on peer fd %d.\n", - dinfo->sid, dinfo->pgrp, - dinfo->driver->name, dinfo->fd); + dinfo->sid, dinfo->pgrp, dinfo->driver->name, dinfo->fd); /* * First thing people do with criu is dump smth * run from shell. This is typical pitfall, warn * user about it explicitly. */ pr_msg("Task attached to shell terminal. " - "Consider using --" OPT_SHELL_JOB " option. " - "More details on http://criu.org/Simple_loop\n"); + "Consider using --" OPT_SHELL_JOB " option. " + "More details on http://criu.org/Simple_loop\n"); ret = -1; } } @@ -1876,11 +1830,11 @@ int dump_verify_tty_sids(void) static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_driver *driver, int index) { - TtyInfoEntry info = TTY_INFO_ENTRY__INIT; - TermiosEntry termios = TERMIOS_ENTRY__INIT; - TermiosEntry termios_locked = TERMIOS_ENTRY__INIT; - WinsizeEntry winsize = WINSIZE_ENTRY__INIT; - TtyPtyEntry pty = TTY_PTY_ENTRY__INIT; + TtyInfoEntry info = TTY_INFO_ENTRY__INIT; + TermiosEntry termios = TERMIOS_ENTRY__INIT; + TermiosEntry termios_locked = TERMIOS_ENTRY__INIT; + WinsizeEntry winsize = WINSIZE_ENTRY__INIT; + TtyPtyEntry pty = TTY_PTY_ENTRY__INIT; struct parasite_tty_args *pti; struct tty_dump_info *dinfo; @@ -1910,14 +1864,14 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d if (!dinfo) return -1; - dinfo->id = id; - dinfo->sid = pti->sid; - dinfo->pgrp = pti->pgrp; - dinfo->pid_real = p->pid; - dinfo->fd = p->fd; - dinfo->mnt_id = p->mnt_id; - dinfo->driver = driver; - dinfo->flags = p->flags; + dinfo->id = id; + dinfo->sid = pti->sid; + dinfo->pgrp = pti->pgrp; + dinfo->pid_real = p->pid; + dinfo->fd = p->fd; + dinfo->mnt_id = p->mnt_id; + dinfo->driver = driver; + dinfo->flags = p->flags; if (is_pty(driver)) { dinfo->lfd = dup(lfd); @@ -1926,33 +1880,33 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d xfree(dinfo); return -1; } - dinfo->index = index; + dinfo->index = index; } else { - dinfo->index = -1; - dinfo->lfd = -1; + dinfo->index = -1; + dinfo->lfd = -1; } list_add_tail(&dinfo->list, &all_ttys); - info.id = id; - info.sid = pti->sid; - info.pgrp = pti->pgrp; - info.rdev = p->stat.st_rdev; - info.dev = p->stat.st_dev; - info.has_dev = true; - info.locked = pti->st_lock; - info.exclusive = pti->st_excl; - info.packet_mode = pti->st_pckt; - - info.has_uid = true; - info.uid = userns_uid(p->stat.st_uid); - info.has_gid = true; - info.gid = userns_gid(p->stat.st_gid); + info.id = id; + info.sid = pti->sid; + info.pgrp = pti->pgrp; + info.rdev = p->stat.st_rdev; + info.dev = p->stat.st_dev; + info.has_dev = true; + info.locked = pti->st_lock; + info.exclusive = pti->st_excl; + info.packet_mode = pti->st_pckt; + + info.has_uid = true; + info.uid = userns_uid(p->stat.st_uid); + info.has_gid = true; + info.gid = userns_gid(p->stat.st_gid); info.type = driver->type; if (info.type == TTY_TYPE__PTY) { - info.pty = &pty; - pty.index = index; + info.pty = &pty; + pty.index = index; } /* @@ -1973,15 +1927,15 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d if (is_pty(driver)) tty_test_and_set(id, tty_active_pairs); - info.termios = &termios; - info.termios_locked = &termios_locked; - info.winsize = &winsize; + info.termios = &termios; + info.termios_locked = &termios_locked; + info.winsize = &winsize; - termios.n_c_cc = TERMIOS_NCC; - termios.c_cc = xmalloc(pb_repeated_size(&termios, c_cc)); + termios.n_c_cc = TERMIOS_NCC; + termios.c_cc = xmalloc(pb_repeated_size(&termios, c_cc)); - termios_locked.n_c_cc = TERMIOS_NCC; - termios_locked.c_cc = xmalloc(pb_repeated_size(&termios_locked, c_cc)); + termios_locked.n_c_cc = TERMIOS_NCC; + termios_locked.c_cc = xmalloc(pb_repeated_size(&termios_locked, c_cc)); if (!termios.c_cc || !termios_locked.c_cc) goto out; @@ -2033,10 +1987,10 @@ static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p) return -1; } - e.id = id; - e.tty_info_id = tty_gen_id(driver, index); - e.flags = p->flags; - e.fown = (FownEntry *)&p->fown; + e.id = id; + e.tty_info_id = tty_gen_id(driver, index); + e.flags = p->flags; + e.fown = (FownEntry *)&p->fown; if (driver->type != TTY_TYPE__EXT_TTY) { u32 rf_id; @@ -2049,7 +2003,6 @@ static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p) e.regf_id = rf_id; } - /* * FIXME * @@ -2086,8 +2039,8 @@ static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p) } const struct fdtype_ops tty_dump_ops = { - .type = FD_TYPES__TTY, - .dump = dump_one_tty, + .type = FD_TYPES__TTY, + .dump = dump_one_tty, }; static int tty_reblock(int id, int lfd, int flags) @@ -2142,30 +2095,26 @@ static int tty_do_dump_queued_data(struct tty_dump_info *dinfo) while (1) { ret = read(dinfo->lfd, &buf[off], size - off); if (ret == 0) { - pr_debug("No more data on tty (%s %#x)\n", - dinfo->driver->name, dinfo->id); + pr_debug("No more data on tty (%s %#x)\n", dinfo->driver->name, dinfo->id); break; } else if (ret < 0) { if (errno == EAGAIN) { - pr_debug("Not waiting data tty (%s %#x)\n", - dinfo->driver->name, dinfo->id); + pr_debug("Not waiting data tty (%s %#x)\n", dinfo->driver->name, dinfo->id); break; } else { ret = -errno; - pr_perror("Can't read data from tty (%s %#x)", - dinfo->driver->name, dinfo->id); + pr_perror("Can't read data from tty (%s %#x)", dinfo->driver->name, dinfo->id); xfree(buf); return ret; } } off += ret; - pr_debug("Read %d bytes (%d) from tty (%s %#x)\n", - ret, (int)off, dinfo->driver->name, dinfo->id); + pr_debug("Read %d bytes (%d) from tty (%s %#x)\n", ret, (int)off, dinfo->driver->name, dinfo->id); if (off >= size) { - pr_err("The tty (%s %#x) queued data overflow %zu bytes limit\n", - dinfo->driver->name, dinfo->id, size); + pr_err("The tty (%s %#x) queued data overflow %zu bytes limit\n", dinfo->driver->name, + dinfo->id, size); off = size; break; } @@ -2175,12 +2124,11 @@ static int tty_do_dump_queued_data(struct tty_dump_info *dinfo) dinfo->tty_data = buf; dinfo->tty_data_size = off; - e.tty_id = dinfo->id; - e.data.data = (void *)buf; - e.data.len = off; + e.tty_id = dinfo->id; + e.data.data = (void *)buf; + e.data.len = off; - ret = pb_write_one(img_from_set(glob_imgset, CR_FD_TTY_DATA), - &e, PB_TTY_DATA); + ret = pb_write_one(img_from_set(glob_imgset, CR_FD_TTY_DATA), &e, PB_TTY_DATA); } else { xfree(buf); ret = 0; @@ -2196,8 +2144,7 @@ static int tty_do_dump_queued_data(struct tty_dump_info *dinfo) static void __tty_do_writeback_queued_data(struct tty_dump_info *dinfo) { if (dinfo->tty_data) { - if (write(dinfo->link->lfd, dinfo->tty_data, - dinfo->tty_data_size) != dinfo->tty_data_size) + if (write(dinfo->link->lfd, dinfo->tty_data, dinfo->tty_data_size) != dinfo->tty_data_size) pr_perror("Can't writeback to tty (%#x)", dinfo->id); } tty_reblock(dinfo->link->id, dinfo->link->lfd, dinfo->link->flags); @@ -2300,9 +2247,7 @@ static int tty_verify_ctty(void) continue; list_for_each_entry(p, &all_ttys, list) { - if (!is_pty(p->driver) || - p->sid != d->sid || - p->pgrp != d->sid) + if (!is_pty(p->driver) || p->sid != d->sid || p->pgrp != d->sid) continue; n = p; break; @@ -2356,7 +2301,7 @@ int tty_prep_fds(void) static int open_pty(void *arg, int flags) { - int dfd = (unsigned long) arg; + int dfd = (unsigned long)arg; /* * Never set as a control terminal automatically, all * ctty magic happens only in tty_set_sid(). @@ -2371,7 +2316,7 @@ static int pty_create_ptmx_index(int dfd, int index, int flags) struct tty_info *info; int fd, id; - fd = __pty_open_ptmx_index(index, flags, open_pty, (void *)(unsigned long) dfd, "ptmx"); + fd = __pty_open_ptmx_index(index, flags, open_pty, (void *)(unsigned long)dfd, "ptmx"); if (fd < 0) return -1; @@ -2442,8 +2387,7 @@ found: } if (master_mp->nsid->type != NS_ROOT) { - pr_err("The master for %s isn't from the root mntns\n", - m->root); + pr_err("The master for %s isn't from the root mntns\n", m->root); return -1; } @@ -2462,7 +2406,6 @@ int devpts_restore(struct mount_info *pm) return -1; } - list_for_each_entry(bm, &pm->mnt_bind, mnt_bind) { int idx; struct stat st; diff --git a/criu/tun.c b/criu/tun.c index b13148b0b..2a2f950da 100644 --- a/criu/tun.c +++ b/criu/tun.c @@ -24,7 +24,7 @@ #include "images/tun.pb-c.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "tun: " #ifndef IFF_PERSIST @@ -36,7 +36,7 @@ #endif #ifndef TUNSETQUEUE -#define TUNSETQUEUE _IOW('T', 217, int) +#define TUNSETQUEUE _IOW('T', 217, int) #define IFF_ATTACH_QUEUE 0x0200 #define IFF_DETACH_QUEUE 0x0400 #endif @@ -55,7 +55,7 @@ #define TUNGETFILTER _IOR('T', 219, struct sock_fprog) #endif -#define TUN_DEV_GEN_PATH "/dev/net/tun" +#define TUN_DEV_GEN_PATH "/dev/net/tun" int check_tun_cr(int no_tun_err) { @@ -139,8 +139,7 @@ static struct tun_link *find_tun_link(char *name, unsigned int ns_id) struct tun_link *tl; list_for_each_entry(tl, &tun_links, l) { - if (!strcmp(tl->name, name) && - tl->ns_id == ns_id) + if (!strcmp(tl->name, name) && tl->ns_id == ns_id) return tl; } return NULL; @@ -322,7 +321,7 @@ static int dump_tunfile(int lfd, u32 id, const struct fd_parms *p) pr_info("Dumping tun-file %d with id %#x\n", lfd, id); - tfe.id = id; + tfe.id = id; ret = ioctl(lfd, TUNGETIFF, &ifr); if (ret < 0) { if (errno != EBADFD) { diff --git a/criu/uffd.c b/criu/uffd.c index 76873797d..18bdc040f 100644 --- a/criu/uffd.c +++ b/criu/uffd.c @@ -42,23 +42,21 @@ #include "util.h" #include "namespaces.h" -#undef LOG_PREFIX +#undef LOG_PREFIX #define LOG_PREFIX "uffd: " -#define lp_debug(lpi, fmt, arg...) pr_debug("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) -#define lp_info(lpi, fmt, arg...) pr_info("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) -#define lp_warn(lpi, fmt, arg...) pr_warn("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) -#define lp_err(lpi, fmt, arg...) pr_err("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) +#define lp_debug(lpi, fmt, arg...) pr_debug("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) +#define lp_info(lpi, fmt, arg...) pr_info("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) +#define lp_warn(lpi, fmt, arg...) pr_warn("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) +#define lp_err(lpi, fmt, arg...) pr_err("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) #define lp_perror(lpi, fmt, arg...) pr_perror("%d-%d: " fmt, lpi->pid, lpi->lpfd.fd, ##arg) -#define NEED_UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \ - UFFD_FEATURE_EVENT_REMAP | \ - UFFD_FEATURE_EVENT_UNMAP | \ - UFFD_FEATURE_EVENT_REMOVE) +#define NEED_UFFD_API_FEATURES \ + (UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP | UFFD_FEATURE_EVENT_UNMAP | UFFD_FEATURE_EVENT_REMOVE) -#define LAZY_PAGES_SOCK_NAME "lazy-pages.socket" +#define LAZY_PAGES_SOCK_NAME "lazy-pages.socket" -#define LAZY_PAGES_RESTORE_FINISHED 0x52535446 /* ReSTore Finished */ +#define LAZY_PAGES_RESTORE_FINISHED 0x52535446 /* ReSTore Finished */ /* * Backround transfer parameters. @@ -67,15 +65,15 @@ * a pipe in the page-server */ #define DEFAULT_XFER_LEN (64 << 10) -#define MAX_XFER_LEN (4 << 20) +#define MAX_XFER_LEN (4 << 20) static mutex_t *lazy_sock_mutex; struct lazy_iov { struct list_head l; - unsigned long start; /* run-time start address, tracks remaps */ - unsigned long end; /* run-time end address, tracks remaps */ - unsigned long img_start; /* start address at the dump time */ + unsigned long start; /* run-time start address, tracks remaps */ + unsigned long end; /* run-time end address, tracks remaps */ + unsigned long img_start; /* start address at the dump time */ }; struct lazy_pages_info { @@ -90,7 +88,7 @@ struct lazy_pages_info { struct page_read pr; - unsigned long xfer_len; /* in pages */ + unsigned long xfer_len; /* in pages */ unsigned long total_pages; unsigned long copied_pages; @@ -177,7 +175,6 @@ static void lpi_fini(struct lazy_pages_info *lpi) xfree(lpi); } - static int prepare_sock_addr(struct sockaddr_un *saddr) { int len; @@ -185,8 +182,7 @@ static int prepare_sock_addr(struct sockaddr_un *saddr) memset(saddr, 0, sizeof(struct sockaddr_un)); saddr->sun_family = AF_UNIX; - len = snprintf(saddr->sun_path, sizeof(saddr->sun_path), - "%s", LAZY_PAGES_SOCK_NAME); + len = snprintf(saddr->sun_path, sizeof(saddr->sun_path), "%s", LAZY_PAGES_SOCK_NAME); if (len >= sizeof(saddr->sun_path)) { pr_err("Wrong UNIX socket name: %s\n", LAZY_PAGES_SOCK_NAME); return -1; @@ -279,15 +275,13 @@ int uffd_open(int flags, unsigned long *features, int *err) if (features) uffdio_api.features = *features; - if (userns_call(uffd_api_ioctl, 0, &uffdio_api, sizeof(uffdio_api), - uffd)) { + if (userns_call(uffd_api_ioctl, 0, &uffdio_api, sizeof(uffdio_api), uffd)) { pr_perror("Failed to get uffd API"); goto close; } if (uffdio_api.api != UFFD_API) { - pr_err("Incompatible uffd API: expected %Lu, got %Lu\n", - UFFD_API, uffdio_api.api); + pr_err("Incompatible uffd API: expected %Lu, got %Lu\n", UFFD_API, uffdio_api.api); goto close; } @@ -351,7 +345,7 @@ int prepare_lazy_pages_socket(void) return -1; len = offsetof(struct sockaddr_un, sun_path) + strlen(sun.sun_path); - if (connect(fd, (struct sockaddr *) &sun, len) < 0) { + if (connect(fd, (struct sockaddr *)&sun, len) < 0) { pr_perror("connect to %s failed", sun.sun_path); goto out; } @@ -380,7 +374,7 @@ static int server_listen(struct sockaddr_un *saddr) len = offsetof(struct sockaddr_un, sun_path) + strlen(saddr->sun_path); - if (bind(fd, (struct sockaddr *) saddr, len) < 0) { + if (bind(fd, (struct sockaddr *)saddr, len) < 0) { goto out; } @@ -414,8 +408,7 @@ static MmEntry *init_mm_entry(struct lazy_pages_info *lpi) return mm; } -static struct lazy_iov *find_iov(struct lazy_pages_info *lpi, - unsigned long addr) +static struct lazy_iov *find_iov(struct lazy_pages_info *lpi, unsigned long addr) { struct lazy_iov *iov; @@ -457,8 +450,7 @@ static void iov_list_insert(struct lazy_iov *new, struct list_head *dst) list_move_tail(&new->l, &iov->l); break; } - if (list_is_last(&iov->l, dst) && - new->start > iov->start) { + if (list_is_last(&iov->l, dst) && new->start > iov->start) { list_move(&new->l, &iov->l); break; } @@ -492,7 +484,6 @@ static int __copy_iov_list(struct list_head *src, struct list_head *dst) list_add_tail(&new->l, dst); } - return 0; } @@ -594,10 +585,7 @@ static int drop_iovs(struct lazy_pages_info *lpi, unsigned long addr, int len) return 0; } - -static struct lazy_iov *extract_range(struct lazy_iov *iov, - unsigned long start, - unsigned long end) +static struct lazy_iov *extract_range(struct lazy_iov *iov, unsigned long start, unsigned long end) { /* move the IOV tail into a new IOV */ if (end < iov->end) @@ -614,8 +602,7 @@ static struct lazy_iov *extract_range(struct lazy_iov *iov, return list_entry(iov->l.next, struct lazy_iov, l); } -static int __remap_iovs(struct list_head *iovs, unsigned long from, - unsigned long to, unsigned long len) +static int __remap_iovs(struct list_head *iovs, unsigned long from, unsigned long to, unsigned long len) { LIST_HEAD(remaps); @@ -660,8 +647,7 @@ static int __remap_iovs(struct list_head *iovs, unsigned long from, return 0; } -static int remap_iovs(struct lazy_pages_info *lpi, unsigned long from, - unsigned long to, unsigned long len) +static int remap_iovs(struct lazy_pages_info *lpi, unsigned long from, unsigned long to, unsigned long len) { if (__remap_iovs(&lpi->iovs, from, to, len)) return -1; @@ -836,8 +822,7 @@ static bool uffd_recoverable_error(int mcopy_rc) return false; } -static int uffd_check_op_error(struct lazy_pages_info *lpi, const char *op, - int *nr_pages, long mcopy_rc) +static int uffd_check_op_error(struct lazy_pages_info *lpi, const char *op, int *nr_pages, long mcopy_rc) { if (errno == ENOSPC || errno == ESRCH) { handle_exit(lpi); @@ -946,8 +931,7 @@ static int uffd_zero(struct lazy_pages_info *lpi, __u64 address, int nr_pages) lp_debug(lpi, "zero page at 0x%llx\n", address); if (ioctl(lpi->lpfd.fd, UFFDIO_ZEROPAGE, &uffdio_zeropage) && - uffd_check_op_error(lpi, "zero", &nr_pages, - uffdio_zeropage.zeropage)) + uffd_check_op_error(lpi, "zero", &nr_pages, uffdio_zeropage.zeropage)) return -1; return 0; @@ -1054,17 +1038,14 @@ static int handle_remove(struct lazy_pages_info *lpi, struct uffd_msg *msg) unreg.start = msg->arg.remove.start; unreg.len = msg->arg.remove.end - msg->arg.remove.start; - lp_debug(lpi, "%s: %llx(%llx)\n", - msg->event == UFFD_EVENT_REMOVE ? "REMOVE" : "UNMAP", - unreg.start, unreg.len); + lp_debug(lpi, "%s: %llx(%llx)\n", msg->event == UFFD_EVENT_REMOVE ? "REMOVE" : "UNMAP", unreg.start, unreg.len); /* * The REMOVE event does not change the VMA, so we need to * make sure that we won't handle #PFs in the removed * range. With UNMAP, there's no VMA to worry about */ - if (msg->event == UFFD_EVENT_REMOVE && - ioctl(lpi->lpfd.fd, UFFDIO_UNREGISTER, &unreg)) { + if (msg->event == UFFD_EVENT_REMOVE && ioctl(lpi->lpfd.fd, UFFDIO_UNREGISTER, &unreg)) { /* * The kernel returns -ENOMEM when unregister is * called after the process has gone @@ -1074,8 +1055,7 @@ static int handle_remove(struct lazy_pages_info *lpi, struct uffd_msg *msg) return 0; } - pr_perror("Failed to unregister (%llx - %llx)", unreg.start, - unreg.start + unreg.len); + pr_perror("Failed to unregister (%llx - %llx)", unreg.start, unreg.start + unreg.len); return -1; } @@ -1088,7 +1068,7 @@ static int handle_remap(struct lazy_pages_info *lpi, struct uffd_msg *msg) unsigned long to = msg->arg.remap.to; unsigned long len = msg->arg.remap.len; - lp_debug(lpi, "REMAP: %lx -> %lx (%ld)\n", from , to, len); + lp_debug(lpi, "REMAP: %lx -> %lx (%ld)\n", from, to, len); return remap_iovs(lpi, from, to, len); } @@ -1248,8 +1228,7 @@ static int handle_uffd_event(struct epoll_rfd *lpfd) static void lazy_pages_summary(struct lazy_pages_info *lpi) { - lp_debug(lpi, "UFFD transferred pages: (%ld/%ld)\n", - lpi->copied_pages, lpi->total_pages); + lp_debug(lpi, "UFFD transferred pages: (%ld/%ld)\n", lpi->copied_pages, lpi->total_pages); #if 0 if ((lpi->copied_pages != lpi->total_pages) && (lpi->total_pages > 0)) { @@ -1305,7 +1284,6 @@ static int handle_requests(int epollfd, struct epoll_event **events, int nr_fds) out: return ret; - } int lazy_pages_finish_restore(void) @@ -1395,7 +1373,7 @@ static int prepare_uffds(int listen, int epollfd) /* accept new client request */ len = sizeof(struct sockaddr_un); - if ((client = accept(listen, (struct sockaddr *) &saddr, &len)) < 0) { + if ((client = accept(listen, (struct sockaddr *)&saddr, &len)) < 0) { pr_perror("server_accept error"); close(listen); return -1; diff --git a/criu/unittest/unit.c b/criu/unittest/unit.c index 41eacbffe..3ee141e25 100644 --- a/criu/unittest/unit.c +++ b/criu/unittest/unit.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <assert.h> - #include "log.h" #include "criu-log.h" @@ -46,7 +45,6 @@ int main(int argc, char *argv[], char *envp[]) assert(!strcmp(configuration[0], "--dsfa")); assert(!strcmp(configuration[1], "aaaaa \"bbbbbb\"")); - i = parse_statement(0, "verbosity 4\n", configuration); assert(i == 2); assert(!strcmp(configuration[0], "--verbosity")); diff --git a/criu/util.c b/criu/util.c index 86bc22e62..ed4557770 100644 --- a/criu/util.c +++ b/criu/util.c @@ -47,7 +47,7 @@ #include "cr-errno.h" #include "action-scripts.h" -#define VMA_OPT_LEN 128 +#define VMA_OPT_LEN 128 static int xatol_base(const char *string, long *number, int base) { @@ -56,8 +56,7 @@ static int xatol_base(const char *string, long *number, int base) errno = 0; nr = strtol(string, &endptr, base); - if ((errno == ERANGE && (nr == LONG_MAX || nr == LONG_MIN)) - || (errno != 0 && nr == 0)) { + if ((errno == ERANGE && (nr == LONG_MAX || nr == LONG_MIN)) || (errno != 0 && nr == 0)) { pr_perror("failed to convert string '%s'", string); return -EINVAL; } @@ -75,7 +74,6 @@ int xatol(const char *string, long *number) return xatol_base(string, number, 10); } - int xatoi(const char *string, int *number) { long tmp; @@ -169,9 +167,10 @@ static void vma_opt_str(const struct vma_area *v, char *opt) { int p = 0; -#define opt2s(_o, _s) do { \ - if (v->e->status & _o) \ - p += sprintf(opt + p, _s " "); \ +#define opt2s(_o, _s) \ + do { \ + if (v->e->status & _o) \ + p += sprintf(opt + p, _s " "); \ } while (0) opt[p] = '\0'; @@ -200,16 +199,11 @@ void pr_vma(const struct vma_area *vma_area) return; vma_opt_str(vma_area, opt); - pr_info("%#"PRIx64"-%#"PRIx64" (%"PRIi64"K) prot %#x flags %#x fdflags %#o st %#x off %#"PRIx64" " - "%s shmid: %#"PRIx64"\n", - vma_area->e->start, vma_area->e->end, - KBYTES(vma_area_len(vma_area)), - vma_area->e->prot, - vma_area->e->flags, - vma_area->e->fdflags, - vma_area->e->status, - vma_area->e->pgoff, - opt, vma_area->e->shmid); + pr_info("%#" PRIx64 "-%#" PRIx64 " (%" PRIi64 "K) prot %#x flags %#x fdflags %#o st %#x off %#" PRIx64 " " + "%s shmid: %#" PRIx64 "\n", + vma_area->e->start, vma_area->e->end, KBYTES(vma_area_len(vma_area)), vma_area->e->prot, + vma_area->e->flags, vma_area->e->fdflags, vma_area->e->status, vma_area->e->pgoff, opt, + vma_area->e->shmid); } int close_safe(int *fd) @@ -237,13 +231,11 @@ int reopen_fd_as_safe(char *file, int line, int new_fd, int old_fd, bool allow_r else tmp = dup2(old_fd, new_fd); if (tmp < 0) { - pr_perror("Dup %d -> %d failed (called at %s:%d)", - old_fd, new_fd, file, line); + pr_perror("Dup %d -> %d failed (called at %s:%d)", old_fd, new_fd, file, line); return tmp; } else if (tmp != new_fd) { close(tmp); - pr_err("fd %d already in use (called at %s:%d)\n", - new_fd, file, line); + pr_err("fd %d already in use (called at %s:%d)\n", new_fd, file, line); return -1; } @@ -459,8 +451,7 @@ int copy_file(int fd_in, int fd_out, size_t bytes) if (ret == 0) { if (bytes && (written != bytes)) { - pr_err("Ghost file size mismatch %zu/%zu\n", - written, bytes); + pr_err("Ghost file size mismatch %zu/%zu\n", written, bytes); return -1; } break; @@ -499,15 +490,15 @@ int is_anon_link_type(char *link, char *type) return !strcmp(link, aux); } -#define DUP_SAFE(fd, out) \ - ({ \ - int ret__; \ - ret__ = dup(fd); \ - if (ret__ == -1) { \ - pr_perror("dup(%d) failed", fd); \ - goto out; \ - } \ - ret__; \ +#define DUP_SAFE(fd, out) \ + ({ \ + int ret__; \ + ret__ = dup(fd); \ + if (ret__ == -1) { \ + pr_perror("dup(%d) failed", fd); \ + goto out; \ + } \ + ret__; \ }) /* @@ -553,8 +544,7 @@ static int close_fds(int minfd) return 0; } -int cr_system_userns(int in, int out, int err, char *cmd, - char *const argv[], unsigned flags, int userns_pid) +int cr_system_userns(int in, int out, int err, char *cmd, char *const argv[], unsigned flags, int userns_pid) { sigset_t blockmask, oldmask; int ret = -1, status; @@ -602,8 +592,7 @@ int cr_system_userns(int in, int out, int err, char *cmd, if (out == in) out = DUP_SAFE(out, out_chld); - if (move_fd_from(&out, STDIN_FILENO) || - move_fd_from(&err, STDIN_FILENO)) + if (move_fd_from(&out, STDIN_FILENO) || move_fd_from(&err, STDIN_FILENO)) goto out_chld; if (in < 0) { @@ -627,9 +616,9 @@ int cr_system_userns(int in, int out, int err, char *cmd, execvp(cmd, argv); /* We can't use pr_error() as log file fd is closed. */ - fprintf(stderr, "Error (%s:%d): " LOG_PREFIX "execvp(\"%s\", ...) failed: %s\n", - __FILE__, __LINE__, cmd, strerror(errno)); -out_chld: + fprintf(stderr, "Error (%s:%d): " LOG_PREFIX "execvp(\"%s\", ...) failed: %s\n", __FILE__, __LINE__, + cmd, strerror(errno)); + out_chld: _exit(1); } @@ -645,8 +634,7 @@ out_chld: pr_err("exited, status=%d\n", WEXITSTATUS(status)); break; } else if (WIFSIGNALED(status)) { - pr_err("killed by signal %d: %s\n", WTERMSIG(status), - strsignal(WTERMSIG(status))); + pr_err("killed by signal %d: %s\n", WTERMSIG(status), strsignal(WTERMSIG(status))); break; } else if (WIFSTOPPED(status)) { pr_err("stopped by signal %d\n", WSTOPSIG(status)); @@ -918,7 +906,6 @@ void split(char *str, char token, char ***out, int *n) if (!*out) { *n = -1; return; - } cur = str; @@ -946,12 +933,12 @@ void split(char *str, char token, char ***out, int *n) } i++; - } while(cur); + } while (cur); } int fd_has_data(int lfd) { - struct pollfd pfd = {lfd, POLLIN, 0}; + struct pollfd pfd = { lfd, POLLIN, 0 }; int ret; ret = poll(&pfd, 1, 0); @@ -1031,8 +1018,7 @@ void tcp_nodelay(int sk, bool on) pr_perror("Unable to restore TCP_NODELAY (%d)", val); } -static int get_sockaddr_in(struct sockaddr_storage *addr, char *host, - unsigned short port) +static int get_sockaddr_in(struct sockaddr_storage *addr, char *host, unsigned short port) { memset(addr, 0, sizeof(*addr)); @@ -1045,7 +1031,8 @@ static int get_sockaddr_in(struct sockaddr_storage *addr, char *host, addr->ss_family = AF_INET6; } else { pr_err("Invalid server address \"%s\". " - "The address must be in IPv4 or IPv6 format.\n", host); + "The address must be in IPv4 or IPv6 format.\n", + host); return -1; } @@ -1078,8 +1065,7 @@ int setup_tcp_server(char *type, char *addr, unsigned short *port) return -1; } - if (setsockopt( - sk, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)) == -1) { + if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)) == -1) { pr_perror("Unable to set SO_REUSEADDR"); goto out; } @@ -1152,9 +1138,8 @@ int run_tcp_server(bool daemon_mode, int *ask, int cfd, int sk) pr_perror("Can't accept connection to server"); goto err; } else - pr_info("Accepted connection from %s:%u\n", - inet_ntoa(caddr.sin_addr), - (int)ntohs(caddr.sin_port)); + pr_info("Accepted connection from %s:%u\n", inet_ntoa(caddr.sin_addr), + (int)ntohs(caddr.sin_port)); close(sk); } @@ -1190,8 +1175,7 @@ int setup_tcp_client(char *hostname) * Iterate through addr_list and try to connect. The loop stops if the * connection is successful or we reach the end of the list. */ - for(p = addr_list; p != NULL; p = p->ai_next) { - + for (p = addr_list; p != NULL; p = p->ai_next) { if (p->ai_family == AF_INET) { struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr; ip = &(ipv4->sin_addr); @@ -1344,8 +1328,7 @@ int call_in_child_process(int (*fn)(void *), void *arg) * Parent freezes till child exit, so child may use the same stack. * No SIGCHLD flag, so it's not need to block signal. */ - pid = clone_noasan(fn, CLONE_VFORK | CLONE_VM | CLONE_FILES | - CLONE_IO | CLONE_SIGHAND | CLONE_SYSVSEM, arg); + pid = clone_noasan(fn, CLONE_VFORK | CLONE_VM | CLONE_FILES | CLONE_IO | CLONE_SIGHAND | CLONE_SYSVSEM, arg); if (pid == -1) { pr_perror("Can't clone"); return -1; @@ -1381,7 +1364,6 @@ void rlimit_unlimit_nofile(void) service_fd_rlim_cur = kdat.sysctl_nr_open; } - #ifdef __GLIBC__ #include <execinfo.h> void print_stack_trace(pid_t pid) @@ -1426,17 +1408,16 @@ int mount_detached_fs(const char *fsname) int strip_deleted(char *name, int len) { struct dcache_prepends { - const char *str; - size_t len; - } static const prepends[] = { - { - .str = " (deleted)", - .len = 10, - }, { - .str = "//deleted", - .len = 9, - } - }; + const char *str; + size_t len; + } static const prepends[] = { { + .str = " (deleted)", + .len = 10, + }, + { + .str = "//deleted", + .len = 9, + } }; size_t i; for (i = 0; i < ARRAY_SIZE(prepends); i++) { @@ -1447,8 +1428,7 @@ int strip_deleted(char *name, int len) at = len - prepends[i].len; if (!strcmp(&name[at], prepends[i].str)) { - pr_debug("Strip '%s' tag from '%s'\n", - prepends[i].str, name); + pr_debug("Strip '%s' tag from '%s'\n", prepends[i].str, name); name[at] = '\0'; len -= prepends[i].len; return 1; @@ -1544,16 +1524,8 @@ char *get_legacy_iptables_bin(bool ipv6) * 1 - present. */ static int iptables_present[2] = { 0, 0 }; - char bins[2][2][32] = { - { - "iptables-save", - "iptables-legacy-save" - }, - { - "ip6tables-save", - "ip6tables-legacy-save" - } - }; + char bins[2][2][32] = { { "iptables-save", "iptables-legacy-save" }, + { "ip6tables-save", "ip6tables-legacy-save" } }; int ret; if (iptables_present[ipv6] == -1) @@ -1570,8 +1542,7 @@ char *get_legacy_iptables_bin(bool ipv6) * let's try iptables-legacy */ if (ret < 0 || ret == 1) { - memcpy(iptables_bin[ipv6], bins[ipv6][1], - strlen(bins[ipv6][1]) + 1); + memcpy(iptables_bin[ipv6], bins[ipv6][1], strlen(bins[ipv6][1]) + 1); ret = is_iptables_nft(iptables_bin[ipv6]); if (ret < 0 || ret == 1) { iptables_present[ipv6] = -1; diff --git a/criu/vdso-compat.c b/criu/vdso-compat.c index 8f5d19e10..15411ee0e 100644 --- a/criu/vdso-compat.c +++ b/criu/vdso-compat.c @@ -34,22 +34,19 @@ static void exit_on(int ret, int err_fd, char *reason) * WARN: This helper shouldn't call pr_err() or any syscall with * Glibc's wrapper function - it may very likely blow up. */ -void compat_vdso_helper(struct vdso_maps *native, int pipe_fd, - int err_fd, void *vdso_buf, size_t buf_size) +void compat_vdso_helper(struct vdso_maps *native, int pipe_fd, int err_fd, void *vdso_buf, size_t buf_size) { void *vdso_addr; long vdso_size; long ret; if (native->vdso_start != VDSO_BAD_ADDR) { - ret = syscall(__NR_munmap, - native->vdso_start, native->sym.vdso_size); + ret = syscall(__NR_munmap, native->vdso_start, native->sym.vdso_size); exit_on(ret, err_fd, "Error: Failed to unmap native vdso\n"); } if (native->vvar_start != VVAR_BAD_ADDR) { - ret = syscall(__NR_munmap, - native->vvar_start, native->sym.vvar_size); + ret = syscall(__NR_munmap, native->vvar_start, native->sym.vvar_size); exit_on(ret, err_fd, "Error: Failed to unmap native vvar\n"); } diff --git a/criu/vdso.c b/criu/vdso.c index b8a28dd63..dc70513d8 100644 --- a/criu/vdso.c +++ b/criu/vdso.c @@ -23,13 +23,13 @@ #include <compel/plugins/std/syscall.h> #ifdef LOG_PREFIX -# undef LOG_PREFIX +#undef LOG_PREFIX #endif #define LOG_PREFIX "vdso: " u64 vdso_pfn = VDSO_BAD_PFN; -struct vdso_maps vdso_maps = VDSO_MAPS_INIT; -struct vdso_maps vdso_maps_compat = VDSO_MAPS_INIT; +struct vdso_maps vdso_maps = VDSO_MAPS_INIT; +struct vdso_maps vdso_maps_compat = VDSO_MAPS_INIT; /* * Starting with 3.16 the [vdso]/[vvar] marks are reported correctly @@ -72,8 +72,7 @@ static enum vdso_check_t get_vdso_check_type(struct parasite_ctl *ctl) return VDSO_CHECK_SYMS; } -static int check_vdso_by_pfn(int pagemap_fd, struct vma_area *vma, - bool *has_vdso_pfn) +static int check_vdso_by_pfn(int pagemap_fd, struct vma_area *vma, bool *has_vdso_pfn) { u64 pfn = VDSO_BAD_PFN; @@ -125,8 +124,7 @@ struct vdso_quarter { unsigned long rt_vvar; }; -static void drop_rt_vdso(struct vm_area_list *vma_area_list, - struct vdso_quarter *addr, struct vma_area *rt_vdso_marked) +static void drop_rt_vdso(struct vm_area_list *vma_area_list, struct vdso_quarter *addr, struct vma_area *rt_vdso_marked) { struct vma_area *rt_vvar_marked = NULL; struct vma_area *vma; @@ -138,8 +136,8 @@ static void drop_rt_vdso(struct vm_area_list *vma_area_list, * There is marked vdso, it means such vdso is autogenerated * and must be dropped from vma list. */ - pr_debug("vdso: Found marked at %lx (orig vDSO at %lx VVAR at %lx)\n", - (long)rt_vdso_marked->e->start, addr->orig_vdso, addr->orig_vvar); + pr_debug("vdso: Found marked at %lx (orig vDSO at %lx VVAR at %lx)\n", (long)rt_vdso_marked->e->start, + addr->orig_vdso, addr->orig_vvar); /* * Don't forget to restore the proxy vdso/vvar status, since @@ -149,14 +147,11 @@ static void drop_rt_vdso(struct vm_area_list *vma_area_list, list_for_each_entry(vma, &vma_area_list->h, list) { if (vma->e->start == addr->orig_vdso) { vma->e->status |= VMA_AREA_REGULAR | VMA_AREA_VDSO; - pr_debug("vdso: Restore orig vDSO status at %lx\n", - (long)vma->e->start); + pr_debug("vdso: Restore orig vDSO status at %lx\n", (long)vma->e->start); } else if (vma->e->start == addr->orig_vvar) { vma->e->status |= VMA_AREA_REGULAR | VMA_AREA_VVAR; - pr_debug("vdso: Restore orig VVAR status at %lx\n", - (long)vma->e->start); - } else if (addr->rt_vvar != VVAR_BAD_ADDR && - addr->rt_vvar == vma->e->start) { + pr_debug("vdso: Restore orig VVAR status at %lx\n", (long)vma->e->start); + } else if (addr->rt_vvar != VVAR_BAD_ADDR && addr->rt_vvar == vma->e->start) { BUG_ON(rt_vvar_marked); if (not_vvar_or_vdso(vma)) { pr_warn("Mark in rt-vdso points to vma, that doesn't look like vvar - skipping unmap\n"); @@ -166,15 +161,13 @@ static void drop_rt_vdso(struct vm_area_list *vma_area_list, } } - pr_debug("vdso: Dropping marked vdso at %lx\n", - (long)rt_vdso_marked->e->start); + pr_debug("vdso: Dropping marked vdso at %lx\n", (long)rt_vdso_marked->e->start); list_del(&rt_vdso_marked->list); xfree(rt_vdso_marked); vma_area_list->nr--; if (rt_vvar_marked) { - pr_debug("vdso: Dropping marked vvar at %lx\n", - (long)rt_vvar_marked->e->start); + pr_debug("vdso: Dropping marked vvar at %lx\n", (long)rt_vvar_marked->e->start); list_del(&rt_vvar_marked->list); xfree(rt_vvar_marked); vma_area_list->nr--; @@ -190,9 +183,8 @@ static void drop_rt_vdso(struct vm_area_list *vma_area_list, * we have to scan the vma zone for vDSO elf structure * which gonna be a slow way. */ -static int check_if_vma_is_vdso(enum vdso_check_t vcheck, int pagemap_fd, - struct parasite_ctl *ctl, struct vma_area *vma, - struct vma_area **rt_vdso_marked, struct vdso_quarter *addr) +static int check_if_vma_is_vdso(enum vdso_check_t vcheck, int pagemap_fd, struct parasite_ctl *ctl, + struct vma_area *vma, struct vma_area **rt_vdso_marked, struct vdso_quarter *addr) { struct parasite_vdso_vma_entry *args; bool has_vdso_pfn = false; @@ -220,10 +212,10 @@ static int check_if_vma_is_vdso(enum vdso_check_t vcheck, int pagemap_fd, pr_err("Ow! Second vdso mark detected!\n"); return -1; } - *rt_vdso_marked = vma; - addr->orig_vdso = args->orig_vdso_addr; - addr->orig_vvar = args->orig_vvar_addr; - addr->rt_vvar = args->rt_vvar_addr; + *rt_vdso_marked = vma; + addr->orig_vdso = args->orig_vdso_addr; + addr->orig_vvar = args->orig_vvar_addr; + addr->rt_vvar = args->rt_vvar_addr; return 0; } @@ -239,14 +231,12 @@ static int check_if_vma_is_vdso(enum vdso_check_t vcheck, int pagemap_fd, if (has_vdso_pfn || args->is_vdso) { if (!vma_area_is(vma, VMA_AREA_VDSO)) { - pr_debug("Restore vDSO status by pfn/symtable at %lx\n", - (long)vma->e->start); + pr_debug("Restore vDSO status by pfn/symtable at %lx\n", (long)vma->e->start); vma->e->status |= VMA_AREA_VDSO; } } else { if (unlikely(vma_area_is(vma, VMA_AREA_VDSO))) { - pr_debug("Drop mishinted vDSO status at %lx\n", - (long)vma->e->start); + pr_debug("Drop mishinted vDSO status at %lx\n", (long)vma->e->start); vma->e->status &= ~VMA_AREA_VDSO; } } @@ -260,8 +250,7 @@ static int check_if_vma_is_vdso(enum vdso_check_t vcheck, int pagemap_fd, * them and eliminated from the VMAs list, they will be * generated again on restore if needed. */ -int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid, - struct vm_area_list *vma_area_list) +int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid, struct vm_area_list *vma_area_list) { struct vma_area *rt_vdso_marked = NULL; struct vdso_quarter addr = { @@ -292,8 +281,7 @@ int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid, * all vmas and restore potentially remapped vDSO * area status. */ - if (check_if_vma_is_vdso(vcheck, fd, ctl, vma, - &rt_vdso_marked, &addr)) { + if (check_if_vma_is_vdso(vcheck, fd, ctl, vma, &rt_vdso_marked, &addr)) { close_safe(&fd); return -1; } @@ -389,8 +377,7 @@ static int validate_vdso_addr(struct vdso_maps *s) */ if (s->vdso_start != VDSO_BAD_ADDR) { if (s->vvar_start != VVAR_BAD_ADDR) { - if (vdso_end != s->vvar_start && - vvar_end != s->vdso_start) { + if (vdso_end != s->vvar_start && vvar_end != s->vdso_start) { pr_err("Unexpected rt vDSO area bounds\n"); return -1; } @@ -414,16 +401,14 @@ static int vdso_fill_self_symtable(struct vdso_maps *s) if (validate_vdso_addr(s)) return -1; - pr_debug("rt [vdso] %lx-%lx [vvar] %lx-%lx\n", - s->vdso_start, s->vdso_start + s->sym.vdso_size, - s->vvar_start, s->vvar_start + s->sym.vvar_size); + pr_debug("rt [vdso] %lx-%lx [vvar] %lx-%lx\n", s->vdso_start, s->vdso_start + s->sym.vdso_size, s->vvar_start, + s->vvar_start + s->sym.vvar_size); return 0; } #ifdef CONFIG_COMPAT -static int vdso_mmap_compat(struct vdso_maps *native, - struct vdso_maps *compat, void *vdso_buf, size_t buf_size) +static int vdso_mmap_compat(struct vdso_maps *native, struct vdso_maps *compat, void *vdso_buf, size_t buf_size) { pid_t pid; int status, ret = -1; @@ -441,8 +426,7 @@ static int vdso_mmap_compat(struct vdso_maps *native, syscall(__NR_exit, 1); } - compat_vdso_helper(native, fds[0], log_get_fd(), - vdso_buf, buf_size); + compat_vdso_helper(native, fds[0], log_get_fd(), vdso_buf, buf_size); BUG(); } @@ -454,8 +438,7 @@ static int vdso_mmap_compat(struct vdso_maps *native, waitpid(pid, &status, WUNTRACED); if (WIFEXITED(status)) { - pr_err("Compat vdso helper exited with %d\n", - WEXITSTATUS(status)); + pr_err("Compat vdso helper exited with %d\n", WEXITSTATUS(status)); goto out_kill; } @@ -474,8 +457,7 @@ static int vdso_mmap_compat(struct vdso_maps *native, pr_perror("Failed to kill(SIGCONT) for compat vdso helper"); goto out_kill; } - if (write(fds[1], &compat->vdso_start, sizeof(void *)) != - sizeof(compat->vdso_start)) { + if (write(fds[1], &compat->vdso_start, sizeof(void *)) != sizeof(compat->vdso_start)) { pr_perror("Failed write to pipe"); goto out_kill; } @@ -497,9 +479,8 @@ out_close: return ret; } -#define COMPAT_VDSO_BUF_SZ (PAGE_SIZE*2) -static int vdso_fill_compat_symtable(struct vdso_maps *native, - struct vdso_maps *compat) +#define COMPAT_VDSO_BUF_SZ (PAGE_SIZE * 2) +static int vdso_fill_compat_symtable(struct vdso_maps *native, struct vdso_maps *compat) { void *vdso_mmap; int ret = -1; @@ -507,8 +488,7 @@ static int vdso_fill_compat_symtable(struct vdso_maps *native, if (!kdat.compat_cr) return 0; - vdso_mmap = mmap(NULL, COMPAT_VDSO_BUF_SZ, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, -1, 0); + vdso_mmap = mmap(NULL, COMPAT_VDSO_BUF_SZ, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (vdso_mmap == MAP_FAILED) { pr_perror("Failed to mmap buf for compat vdso"); return -1; @@ -519,15 +499,14 @@ static int vdso_fill_compat_symtable(struct vdso_maps *native, goto out_unmap; } - if (vdso_fill_symtable_compat((uintptr_t)vdso_mmap, - compat->sym.vdso_size, &compat->sym)) { + if (vdso_fill_symtable_compat((uintptr_t)vdso_mmap, compat->sym.vdso_size, &compat->sym)) { pr_err("Failed to parse mmaped compatible vdso blob\n"); goto out_unmap; } - pr_debug("compat [vdso] %lx-%lx [vvar] %lx-%lx\n", - compat->vdso_start, compat->vdso_start + compat->sym.vdso_size, - compat->vvar_start, compat->vvar_start + compat->sym.vvar_size); + pr_debug("compat [vdso] %lx-%lx [vvar] %lx-%lx\n", compat->vdso_start, + compat->vdso_start + compat->sym.vdso_size, compat->vvar_start, + compat->vvar_start + compat->sym.vvar_size); ret = 0; out_unmap: @@ -610,8 +589,8 @@ int vdso_init_restore(void) vdso_maps.sym = kdat.vdso_sym; #ifdef CONFIG_COMPAT - vdso_maps_compat.sym = kdat.vdso_sym_compat; - vdso_maps_compat.compatible = true; + vdso_maps_compat.sym = kdat.vdso_sym_compat; + vdso_maps_compat.compatible = true; #endif return 0; @@ -641,8 +620,8 @@ int kerndat_vdso_fill_symtable(void) pr_err("Failed to fill compat vdso symtable\n"); return -1; } - vdso_maps_compat.compatible = true; - kdat.vdso_sym_compat = vdso_maps_compat.sym; + vdso_maps_compat.compatible = true; + kdat.vdso_sym_compat = vdso_maps_compat.sym; #endif return 0; @@ -676,14 +655,13 @@ int kerndat_vdso_preserves_hint(void) unsigned long vdso_size = vdso_maps.sym.vdso_size; void *new_addr; - new_addr = mmap(0, vdso_size, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + new_addr = mmap(0, vdso_size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (new_addr == MAP_FAILED) exit(1); child = getpid(); - new_addr = (void *)syscall(SYS_mremap, vdso_addr, vdso_size, - vdso_size, MREMAP_MAYMOVE | MREMAP_FIXED, new_addr); + new_addr = (void *)syscall(SYS_mremap, vdso_addr, vdso_size, vdso_size, MREMAP_MAYMOVE | MREMAP_FIXED, + new_addr); if (new_addr == MAP_FAILED) syscall(SYS_exit, 2); syscall(SYS_kill, child, SIGSTOP); @@ -699,8 +677,7 @@ int kerndat_vdso_preserves_hint(void) } else if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - pr_err("Child unexpectedly signaled with %d: %s\n", - sig, strsignal(sig)); + pr_err("Child unexpectedly signaled with %d: %s\n", sig, strsignal(sig)); goto out; } else if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) { pr_err("Child is unstoppable or was stopped by other means\n"); diff --git a/include/common/scm-code.c b/include/common/scm-code.c index 351c405b9..d7d732587 100644 --- a/include/common/scm-code.c +++ b/include/common/scm-code.c @@ -2,16 +2,15 @@ #error "The __sys macro is required" #endif -static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, - void *data, unsigned ch_size) +static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, void *data, unsigned ch_size) { struct cmsghdr *cmsg; static char dummy; fdset->hdr.msg_controllen = CMSG_LEN(sizeof(int) * nr_fds); - cmsg = CMSG_FIRSTHDR(&fdset->hdr); - cmsg->cmsg_len = fdset->hdr.msg_controllen; + cmsg = CMSG_FIRSTHDR(&fdset->hdr); + cmsg->cmsg_len = fdset->hdr.msg_controllen; if (data) { fdset->iov.iov_base = data; @@ -22,33 +21,31 @@ static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, } } -static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr, - int saddr_len) +static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr, int saddr_len) { struct cmsghdr *cmsg; BUILD_BUG_ON(sizeof(fdset->msg_buf) < (CMSG_SPACE(sizeof(int) * CR_SCM_MAX_FD))); - fdset->iov.iov_base = (void *)0xdeadbeef; + fdset->iov.iov_base = (void *)0xdeadbeef; - fdset->hdr.msg_iov = &fdset->iov; - fdset->hdr.msg_iovlen = 1; - fdset->hdr.msg_name = (struct sockaddr *)saddr; - fdset->hdr.msg_namelen = saddr_len; + fdset->hdr.msg_iov = &fdset->iov; + fdset->hdr.msg_iovlen = 1; + fdset->hdr.msg_name = (struct sockaddr *)saddr; + fdset->hdr.msg_namelen = saddr_len; - fdset->hdr.msg_control = &fdset->msg_buf; - fdset->hdr.msg_controllen = CMSG_LEN(sizeof(int) * CR_SCM_MAX_FD); + fdset->hdr.msg_control = &fdset->msg_buf; + fdset->hdr.msg_controllen = CMSG_LEN(sizeof(int) * CR_SCM_MAX_FD); - cmsg = CMSG_FIRSTHDR(&fdset->hdr); - cmsg->cmsg_len = fdset->hdr.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; + cmsg = CMSG_FIRSTHDR(&fdset->hdr); + cmsg->cmsg_len = fdset->hdr.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; return (int *)CMSG_DATA(cmsg); } -int send_fds(int sock, struct sockaddr_un *saddr, int len, - int *fds, int nr_fds, void *data, unsigned ch_size) +int send_fds(int sock, struct sockaddr_un *saddr, int len, int *fds, int nr_fds, void *data, unsigned ch_size) { /* In musl_libc the msghdr structure has pads which has to be zeroed */ struct scm_fdset fdset = {}; @@ -63,7 +60,7 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len, ret = __sys(sendmsg)(sock, &fdset.hdr, 0); if (ret <= 0) - return ret ? : -1; + return ret ?: -1; if (data) data += min_fd * ch_size; @@ -118,4 +115,3 @@ int __recv_fds(int sock, int *fds, int nr_fds, void *data, unsigned ch_size, int return 0; } - diff --git a/lib/c/criu.c b/lib/c/criu.c index 6f7c673eb..86c9dedf3 100644 --- a/lib/c/criu.c +++ b/lib/c/criu.c @@ -21,15 +21,15 @@ const char *criu_lib_version = CRIU_VERSION; struct criu_opts { - CriuOpts *rpc; - int (*notify)(char *action, criu_notify_arg_t na); - enum criu_service_comm service_comm; + CriuOpts *rpc; + int (*notify)(char *action, criu_notify_arg_t na); + enum criu_service_comm service_comm; union { - const char *service_address; - int service_fd; - const char *service_binary; + const char *service_address; + int service_fd; + const char *service_binary; }; - int swrk_pid; + int swrk_pid; }; static criu_opts *global_opts; @@ -38,15 +38,15 @@ static int orphan_pts_master_fd = -1; void criu_free_service(criu_opts *opts) { - switch(opts->service_comm) { - case CRIU_COMM_SK: - free((void*)(opts->service_address)); - break; + switch (opts->service_comm) { + case CRIU_COMM_SK: + free((void *)(opts->service_address)); + break; case CRIU_COMM_BIN: - free((void*)(opts->service_binary)); - break; + free((void *)(opts->service_binary)); + break; default: - break; + break; } } @@ -902,7 +902,6 @@ int criu_add_enable_fs(const char *fs) return criu_local_add_enable_fs(global_opts, fs); } - int criu_local_add_skip_mnt(criu_opts *opts, const char *mnt) { int nr; @@ -1146,7 +1145,7 @@ int criu_set_page_server_address_port(const char *address, int port) static CriuResp *recv_resp(int socket_fd) { - struct msghdr msg_hdr = {0}; + struct msghdr msg_hdr = { 0 }; unsigned char *buf = NULL; struct cmsghdr *cmsg; CriuResp *msg = 0; @@ -1245,7 +1244,7 @@ static int send_req(int socket_fd, CriuReq *req) goto err; } - if (write(socket_fd, buf, len) == -1) { + if (write(socket_fd, buf, len) == -1) { perror("Can't send request"); goto err; } @@ -1278,7 +1277,7 @@ static int send_notify_ack(int socket_fd, int ret) * result of acking it. */ - return ret ? : send_ret; + return ret ?: send_ret; } static void swrk_wait(criu_opts *opts) @@ -1337,7 +1336,7 @@ static int swrk_connect(criu_opts *opts, bool d) execlp(opts->service_binary, opts->service_binary, "swrk", fds, NULL); perror("Can't exec criu swrk"); -child_err: + child_err: close(sks[1]); exit(1); } @@ -1384,8 +1383,7 @@ static int criu_connect(criu_opts *opts, bool d) addr_len = strlen(opts->service_address); if (addr_len >= sizeof(addr.sun_path)) { - fprintf(stderr, "The service address %s is too long", - opts->service_address); + fprintf(stderr, "The service address %s is too long", opts->service_address); close(fd); return -1; } @@ -1393,7 +1391,7 @@ static int criu_connect(criu_opts *opts, bool d) addr_len += sizeof(addr.sun_family); - ret = connect(fd, (struct sockaddr *) &addr, addr_len); + ret = connect(fd, (struct sockaddr *)&addr, addr_len); if (ret < 0) { saved_errno = errno; perror("Can't connect to socket"); @@ -1429,14 +1427,12 @@ again: if (!ret) { criu_resp__free_unpacked(*resp, NULL); goto again; - } - else + } else goto exit; } if ((*resp)->type != req->type) { - if ((*resp)->type == CRIU_REQ_TYPE__EMPTY && - (*resp)->success == false) + if ((*resp)->type == CRIU_REQ_TYPE__EMPTY && (*resp)->success == false) ret = -EINVAL; else { perror("Unexpected response type"); @@ -1716,13 +1712,13 @@ int criu_restore_child(void) int criu_local_get_version(criu_opts *opts) { int ret = -1; - CriuReq req = CRIU_REQ__INIT; - CriuResp *resp = NULL; + CriuReq req = CRIU_REQ__INIT; + CriuResp *resp = NULL; saved_errno = 0; - req.type = CRIU_REQ_TYPE__VERSION; - req.opts = opts->rpc; + req.type = CRIU_REQ_TYPE__VERSION; + req.opts = opts->rpc; ret = send_req_and_recv_resp(opts, &req, &resp); if (ret) diff --git a/soccr/soccr.c b/soccr/soccr.c index 20eabfbd4..f6fb1946b 100644 --- a/soccr/soccr.c +++ b/soccr/soccr.c @@ -10,21 +10,21 @@ #ifndef SIOCOUTQNSD /* MAO - Define SIOCOUTQNSD ioctl if we don't have it */ -#define SIOCOUTQNSD 0x894B +#define SIOCOUTQNSD 0x894B #endif enum { TCPF_ESTABLISHED = (1 << 1), - TCPF_SYN_SENT = (1 << 2), - TCPF_SYN_RECV = (1 << 3), - TCPF_FIN_WAIT1 = (1 << 4), - TCPF_FIN_WAIT2 = (1 << 5), - TCPF_TIME_WAIT = (1 << 6), - TCPF_CLOSE = (1 << 7), - TCPF_CLOSE_WAIT = (1 << 8), - TCPF_LAST_ACK = (1 << 9), - TCPF_LISTEN = (1 << 10), - TCPF_CLOSING = (1 << 11), + TCPF_SYN_SENT = (1 << 2), + TCPF_SYN_RECV = (1 << 3), + TCPF_FIN_WAIT1 = (1 << 4), + TCPF_FIN_WAIT2 = (1 << 5), + TCPF_TIME_WAIT = (1 << 6), + TCPF_CLOSE = (1 << 7), + TCPF_CLOSE_WAIT = (1 << 8), + TCPF_LAST_ACK = (1 << 9), + TCPF_LISTEN = (1 << 10), + TCPF_CLOSING = (1 << 11), }; /* @@ -55,7 +55,7 @@ enum { */ /* Restore a fin packet in a send queue first */ -#define SNDQ_FIRST_FIN (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | TCPF_CLOSING) +#define SNDQ_FIRST_FIN (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | TCPF_CLOSING) /* Restore fin in a send queue after restoring fi in the receive queue. */ #define SNDQ_SECOND_FIN (TCPF_LAST_ACK | TCPF_CLOSE) #define SNDQ_FIN_ACKED (TCPF_FIN_WAIT2 | TCPF_CLOSE) @@ -64,8 +64,7 @@ enum { #define RCVQ_SECOND_FIN (TCPF_CLOSING) #define RCVQ_FIN_ACKED (TCPF_CLOSE) -static void (*log)(unsigned int loglevel, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); +static void (*log)(unsigned int loglevel, const char *format, ...) __attribute__((__format__(__printf__, 2, 3))); static unsigned int log_level = 0; void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const char *fmt, ...)) @@ -74,9 +73,17 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c log = fn; } -#define loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, "Error (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__); } while (0) +#define loge(msg, ...) \ + do { \ + if (log && (log_level >= SOCCR_LOG_ERR)) \ + log(SOCCR_LOG_ERR, "Error (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__); \ + } while (0) #define logerr(msg, ...) loge(msg ": %s\n", ##__VA_ARGS__, strerror(errno)) -#define logd(msg, ...) do { if (log && (log_level >= SOCCR_LOG_DBG)) log(SOCCR_LOG_DBG, "Debug: " msg, ##__VA_ARGS__); } while (0) +#define logd(msg, ...) \ + do { \ + if (log && (log_level >= SOCCR_LOG_DBG)) \ + log(SOCCR_LOG_DBG, "Debug: " msg, ##__VA_ARGS__); \ + } while (0) static int tcp_repair_on(int fd) { @@ -109,10 +116,10 @@ struct libsoccr_sk { union libsoccr_addr *dst_addr; }; -#define SK_FLAG_FREE_RQ 0x1 -#define SK_FLAG_FREE_SQ 0x2 -#define SK_FLAG_FREE_SA 0x4 -#define SK_FLAG_FREE_DA 0x8 +#define SK_FLAG_FREE_RQ 0x1 +#define SK_FLAG_FREE_SQ 0x2 +#define SK_FLAG_FREE_SA 0x4 +#define SK_FLAG_FREE_DA 0x8 struct libsoccr_sk *libsoccr_pause(int fd) { @@ -158,17 +165,16 @@ void libsoccr_release(struct libsoccr_sk *sk) } struct soccr_tcp_info { - __u8 tcpi_state; - __u8 tcpi_ca_state; - __u8 tcpi_retransmits; - __u8 tcpi_probes; - __u8 tcpi_backoff; - __u8 tcpi_options; - __u8 tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; + __u8 tcpi_state; + __u8 tcpi_ca_state; + __u8 tcpi_retransmits; + __u8 tcpi_probes; + __u8 tcpi_backoff; + __u8 tcpi_options; + __u8 tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; }; -static int refresh_sk(struct libsoccr_sk *sk, - struct libsoccr_sk_data *data, struct soccr_tcp_info *ti) +static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, struct soccr_tcp_info *ti) { int size; socklen_t olen = sizeof(*ti); @@ -238,8 +244,7 @@ static int refresh_sk(struct libsoccr_sk *sk, return 0; } -static int get_stream_options(struct libsoccr_sk *sk, - struct libsoccr_sk_data *data, struct soccr_tcp_info *ti) +static int get_stream_options(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, struct soccr_tcp_info *ti) { int ret; socklen_t auxl; @@ -277,8 +282,7 @@ static int get_window(struct libsoccr_sk *sk, struct libsoccr_sk_data *data) struct tcp_repair_window opt; socklen_t optlen = sizeof(opt); - if (getsockopt(sk->fd, SOL_TCP, - TCP_REPAIR_WINDOW, &opt, &optlen)) { + if (getsockopt(sk->fd, SOL_TCP, TCP_REPAIR_WINDOW, &opt, &optlen)) { /* Appeared since 4.8, but TCP_repair itself is since 3.11 */ if (errno == ENOPROTOOPT) return 0; @@ -288,11 +292,11 @@ static int get_window(struct libsoccr_sk *sk, struct libsoccr_sk_data *data) } data->flags |= SOCCR_FLAGS_WINDOW; - data->snd_wl1 = opt.snd_wl1; - data->snd_wnd = opt.snd_wnd; - data->max_window = opt.max_window; - data->rcv_wnd = opt.rcv_wnd; - data->rcv_wup = opt.rcv_wup; + data->snd_wl1 = opt.snd_wl1; + data->snd_wnd = opt.snd_wnd; + data->max_window = opt.max_window; + data->rcv_wnd = opt.rcv_wnd; + data->rcv_wup = opt.rcv_wup; return 0; } @@ -321,8 +325,7 @@ static int get_window(struct libsoccr_sk *sk, struct libsoccr_sk_data *data) * */ -static int get_queue(int sk, int queue_id, - __u32 *seq, __u32 len, char **bufp) +static int get_queue(int sk, int queue_id, __u32 *seq, __u32 len, char **bufp) { int ret, aux; socklen_t auxl; @@ -373,7 +376,7 @@ err_recv: /* * This is how much data we've had in the initial libsoccr */ -#define SOCR_DATA_MIN_SIZE (17 * sizeof(__u32)) +#define SOCR_DATA_MIN_SIZE (17 * sizeof(__u32)) int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size) { @@ -406,7 +409,7 @@ int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigne return sizeof(struct libsoccr_sk_data); } -#define GET_Q_FLAGS (SOCCR_MEM_EXCL) +#define GET_Q_FLAGS (SOCCR_MEM_EXCL) char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, unsigned flags) { char **p, *ret; @@ -415,14 +418,14 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, unsigned fl return NULL; switch (queue_id) { - case TCP_RECV_QUEUE: - p = &sk->recv_queue; - break; - case TCP_SEND_QUEUE: - p = &sk->send_queue; - break; - default: - return NULL; + case TCP_RECV_QUEUE: + p = &sk->recv_queue; + break; + case TCP_SEND_QUEUE: + p = &sk->send_queue; + break; + default: + return NULL; } ret = *p; @@ -432,7 +435,7 @@ char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, unsigned fl return ret; } -#define GET_SA_FLAGS (SOCCR_MEM_EXCL) +#define GET_SA_FLAGS (SOCCR_MEM_EXCL) union libsoccr_addr *libsoccr_get_addr(struct libsoccr_sk *sk, int self, unsigned flags) { if (flags & ~GET_SA_FLAGS) @@ -463,8 +466,7 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq) #define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED #endif -static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, - struct libsoccr_sk_data *data, unsigned data_size) +static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size) { struct tcp_repair_opt opts[4]; int addr_size, mstate; @@ -505,8 +507,7 @@ static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, if (mstate & (SNDQ_FIRST_FIN | SNDQ_SECOND_FIN)) data->outq_seq--; - if (set_queue_seq(sk, TCP_RECV_QUEUE, - data->inq_seq - data->inq_len)) + if (set_queue_seq(sk, TCP_RECV_QUEUE, data->inq_seq - data->inq_len)) return -2; seq = data->outq_seq - data->outq_len; @@ -524,8 +525,7 @@ static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, if (data->state == TCP_SYN_SENT && tcp_repair_off(sk->fd)) return -1; - if (connect(sk->fd, &sk->dst_addr->sa, addr_size) == -1 && - errno != EINPROGRESS) { + if (connect(sk->fd, &sk->dst_addr->sa, addr_size) == -1 && errno != EINPROGRESS) { logerr("Can't connect inet socket back"); return -1; } @@ -563,15 +563,13 @@ static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, onr++; if (data->state != TCP_SYN_SENT && - setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_OPTIONS, - opts, onr * sizeof(struct tcp_repair_opt)) < 0) { + setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_OPTIONS, opts, onr * sizeof(struct tcp_repair_opt)) < 0) { logerr("Can't repair options"); return -2; } if (data->opt_mask & TCPI_OPT_TIMESTAMPS) { - if (setsockopt(sk->fd, SOL_TCP, TCP_TIMESTAMP, - &data->timestamp, sizeof(data->timestamp)) < 0) { + if (setsockopt(sk->fd, SOL_TCP, TCP_TIMESTAMP, &data->timestamp, sizeof(data->timestamp)) < 0) { logerr("Can't set timestamp"); return -3; } @@ -586,8 +584,7 @@ static int ipv6_addr_mapped(union libsoccr_addr *addr) return (addr->v6.sin6_addr.s6_addr32[2] == htonl(0x0000ffff)); } -static int send_fin(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, - unsigned data_size, uint8_t flags) +static int send_fin(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, uint8_t flags) { uint32_t src_v4 = sk->src_addr->v4.sin_addr.s_addr; uint32_t dst_v4 = sk->dst_addr->v4.sin_addr.s_addr; @@ -611,10 +608,9 @@ static int send_fin(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, else libnet_type = LIBNET_RAW4; - l = libnet_init( - libnet_type, /* injection type */ - NULL, /* network interface */ - errbuf); /* errbuf */ + l = libnet_init(libnet_type, /* injection type */ + NULL, /* network interface */ + errbuf); /* errbuf */ if (l == NULL) { loge("libnet_init failed (%s)\n", errbuf); return -1; @@ -625,20 +621,19 @@ static int send_fin(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, goto err; } - ret = libnet_build_tcp( - ntohs(sk->dst_addr->v4.sin_port), /* source port */ - ntohs(sk->src_addr->v4.sin_port), /* destination port */ - data->inq_seq, /* sequence number */ - data->outq_seq - data->outq_len, /* acknowledgement num */ - flags, /* control flags */ - data->rcv_wnd, /* window size */ - 0, /* checksum */ - 10, /* urgent pointer */ - LIBNET_TCP_H + 20, /* TCP packet size */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + ret = libnet_build_tcp(ntohs(sk->dst_addr->v4.sin_port), /* source port */ + ntohs(sk->src_addr->v4.sin_port), /* destination port */ + data->inq_seq, /* sequence number */ + data->outq_seq - data->outq_len, /* acknowledgement num */ + flags, /* control flags */ + data->rcv_wnd, /* window size */ + 0, /* checksum */ + 10, /* urgent pointer */ + LIBNET_TCP_H + 20, /* TCP packet size */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ if (ret == -1) { loge("Can't build TCP header: %s\n", libnet_geterror(l)); goto err; @@ -650,32 +645,29 @@ static int send_fin(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, memcpy(&dst, &sk->dst_addr->v6.sin6_addr, sizeof(dst)); memcpy(&src, &sk->src_addr->v6.sin6_addr, sizeof(src)); - ret = libnet_build_ipv6( - 0, 0, - LIBNET_TCP_H, /* length */ - IPPROTO_TCP, /* protocol */ - 64, /* hop limit */ - dst, /* source IP */ - src, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + ret = libnet_build_ipv6(0, 0, LIBNET_TCP_H, /* length */ + IPPROTO_TCP, /* protocol */ + 64, /* hop limit */ + dst, /* source IP */ + src, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ } else if (family == AF_INET) - ret = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_TCP_H + 20, /* length */ - 0, /* TOS */ - 242, /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_TCP, /* protocol */ - 0, /* checksum */ - dst_v4, /* source IP */ - src_v4, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + ret = libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_TCP_H + 20, /* length */ + 0, /* TOS */ + 242, /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_TCP, /* protocol */ + 0, /* checksum */ + dst_v4, /* source IP */ + src_v4, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ else { loge("Unknown socket family\n"); goto err; @@ -706,8 +698,7 @@ static int restore_fin_in_snd_queue(int sk, int acked) * If TCP_SEND_QUEUE is set, a fin packet will be * restored as a sent packet. */ - if (acked && - setsockopt(sk, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) { + if (acked && setsockopt(sk, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) { logerr("Can't set repair queue"); return -1; } @@ -717,8 +708,7 @@ static int restore_fin_in_snd_queue(int sk, int acked) logerr("Unable to shut down a socket"); queue = TCP_NO_QUEUE; - if (acked && - setsockopt(sk, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) { + if (acked && setsockopt(sk, SOL_TCP, TCP_REPAIR_QUEUE, &queue, sizeof(queue)) < 0) { logerr("Can't set repair queue"); return -1; } @@ -726,11 +716,10 @@ static int restore_fin_in_snd_queue(int sk, int acked) return ret; } -static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, - int queue, char *buf); +static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, int queue, + char *buf); -int libsoccr_restore(struct libsoccr_sk *sk, - struct libsoccr_sk_data *data, unsigned data_size) +int libsoccr_restore(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size) { int mstate = 1 << data->state; @@ -827,8 +816,7 @@ static int __send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len) continue; } - logerr("Can't restore %d queue data (%d), want (%d:%d:%d)", - queue, ret, chunk, len, max_chunk); + logerr("Can't restore %d queue data (%d), want (%d:%d:%d)", queue, ret, chunk, len, max_chunk); goto err; } off += ret; @@ -852,8 +840,8 @@ static int send_queue(struct libsoccr_sk *sk, int queue, char *buf, __u32 len) return __send_queue(sk, queue, buf, len); } -static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, - int queue, char *buf) +static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, int queue, + char *buf) { if (!buf) return 0; @@ -900,29 +888,29 @@ static int libsoccr_restore_queue(struct libsoccr_sk *sk, struct libsoccr_sk_dat return -5; } -#define SET_Q_FLAGS (SOCCR_MEM_EXCL) +#define SET_Q_FLAGS (SOCCR_MEM_EXCL) int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, int queue_id, char *bytes, unsigned flags) { if (flags & ~SET_Q_FLAGS) return -1; switch (queue_id) { - case TCP_RECV_QUEUE: - sk->recv_queue = bytes; - if (flags & SOCCR_MEM_EXCL) - sk->flags |= SK_FLAG_FREE_RQ; - return 0; - case TCP_SEND_QUEUE: - sk->send_queue = bytes; - if (flags & SOCCR_MEM_EXCL) - sk->flags |= SK_FLAG_FREE_SQ; - return 0; + case TCP_RECV_QUEUE: + sk->recv_queue = bytes; + if (flags & SOCCR_MEM_EXCL) + sk->flags |= SK_FLAG_FREE_RQ; + return 0; + case TCP_SEND_QUEUE: + sk->send_queue = bytes; + if (flags & SOCCR_MEM_EXCL) + sk->flags |= SK_FLAG_FREE_SQ; + return 0; } return -1; } -#define SET_SA_FLAGS (SOCCR_MEM_EXCL) +#define SET_SA_FLAGS (SOCCR_MEM_EXCL) int libsoccr_set_addr(struct libsoccr_sk *sk, int self, union libsoccr_addr *addr, unsigned flags) { if (flags & ~SET_SA_FLAGS) diff --git a/soccr/test/tcp-conn.c b/soccr/test/tcp-conn.c index cdd75129a..b1e651147 100644 --- a/soccr/test/tcp-conn.c +++ b/soccr/test/tcp-conn.c @@ -1,5 +1,5 @@ #include <sys/socket.h> -#include <arpa/inet.h> /* for srvaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for srvaddr_in and inet_ntoa() */ #include <string.h> #include <stdio.h> #include <unistd.h> @@ -35,7 +35,7 @@ int main(void) libsoccr_set_log(10, pr_printf); - memset(&addr,0,sizeof(addr)); + memset(&addr, 0, sizeof(addr)); #ifndef TEST_IPV6 addr.v4.sin_family = AF_INET; @@ -56,11 +56,11 @@ int main(void) } #ifndef TEST_IPV6 - addr.v4.sin_port = htons(8765); + addr.v4.sin_port = htons(8765); #else - addr.v6.sin6_port = htons(8765); + addr.v6.sin6_port = htons(8765); #endif - ret = bind(srv, (struct sockaddr *) &addr, sizeof(addr)); + ret = bind(srv, (struct sockaddr *)&addr, sizeof(addr)); if (ret == -1) { pr_perror("bind() failed"); return -1; @@ -81,13 +81,13 @@ int main(void) return -1; } - if (connect(clnt, (struct sockaddr *) &addr, sizeof(addr))) { + if (connect(clnt, (struct sockaddr *)&addr, sizeof(addr))) { pr_perror("connect"); return 1; } dst_let = sizeof(dst); - sock = accept(srv, (struct sockaddr *) &dst, &dst_let); + sock = accept(srv, (struct sockaddr *)&dst, &dst_let); if (sock < 0) { pr_perror("accept"); return 1; @@ -100,17 +100,16 @@ int main(void) /* Start testing */ dst_let = sizeof(addr); - if (getsockname(sock, (struct sockaddr *) &addr, &dst_let)) { + if (getsockname(sock, (struct sockaddr *)&addr, &dst_let)) { pr_perror("getsockname"); return 1; } dst_let = sizeof(addr); - if (getpeername(sock, (struct sockaddr *) &dst, &dst_let)) { + if (getpeername(sock, (struct sockaddr *)&dst, &dst_let)) { pr_perror("getpeername"); return 1; } - so = libsoccr_pause(sock); dsize = libsoccr_save(so, &data, sizeof(data)); diff --git a/soccr/test/tcp-constructor.c b/soccr/test/tcp-constructor.c index 973dbf10c..10d08e553 100644 --- a/soccr/test/tcp-constructor.c +++ b/soccr/test/tcp-constructor.c @@ -10,7 +10,11 @@ #include "soccr/soccr.h" -#define pr_perror(fmt, ...) ({ fprintf(stderr, "%s:%d: " fmt " : %m\n", __func__, __LINE__, ##__VA_ARGS__); 1; }) +#define pr_perror(fmt, ...) \ + ({ \ + fprintf(stderr, "%s:%d: " fmt " : %m\n", __func__, __LINE__, ##__VA_ARGS__); \ + 1; \ + }) struct tcp { char *addr; @@ -22,36 +26,28 @@ struct tcp { static void usage(void) { - printf( - "Usage: --addr ADDR -port PORT --seq SEQ --next --addr ADDR -port PORT --seq SEQ -- CMD ...\n" - "\t Describe a source side of a connection, then set the --next option\n" - "\t and describe a destination side.\n" - "\t --reverse - swap source and destination sides\n" - "\t The idea is that the same command line is execute on both sides,\n" - "\t but the --reverse is added to one of them.\n" - "\n" - "\t CMD ... - a user command to handle a socket, which is the descriptor 3.\n" - "\n" - "\t It prints the \"start\" on stdout when a socket is created and\n" - "\t resumes it when you write \"start\" to stdin.\n" - ); + printf("Usage: --addr ADDR -port PORT --seq SEQ --next --addr ADDR -port PORT --seq SEQ -- CMD ...\n" + "\t Describe a source side of a connection, then set the --next option\n" + "\t and describe a destination side.\n" + "\t --reverse - swap source and destination sides\n" + "\t The idea is that the same command line is execute on both sides,\n" + "\t but the --reverse is added to one of them.\n" + "\n" + "\t CMD ... - a user command to handle a socket, which is the descriptor 3.\n" + "\n" + "\t It prints the \"start\" on stdout when a socket is created and\n" + "\t resumes it when you write \"start\" to stdin.\n"); } int main(int argc, char **argv) { static const char short_opts[] = ""; static struct option long_opts[] = { - { "addr", required_argument, 0, 'a' }, - { "port", required_argument, 0, 'p' }, - { "seq", required_argument, 0, 's' }, - { "next", no_argument, 0, 'n'}, - { "reverse", no_argument, 0, 'r'}, - {}, + { "addr", required_argument, 0, 'a' }, { "port", required_argument, 0, 'p' }, + { "seq", required_argument, 0, 's' }, { "next", no_argument, 0, 'n' }, + { "reverse", no_argument, 0, 'r' }, {}, }; - struct tcp tcp[2] = { - {"127.0.0.1", 12345, 5000000, 1460, 7}, - {"127.0.0.1", 54321, 6000000, 1460, 7} - }; + struct tcp tcp[2] = { { "127.0.0.1", 12345, 5000000, 1460, 7 }, { "127.0.0.1", 54321, 6000000, 1460, 7 } }; int sk, yes = 1, val, idx, opt, i, src = 0, dst = 1; union libsoccr_addr src_addr, dst_addr; @@ -82,7 +78,8 @@ int main(int argc, char **argv) return pr_perror("--next is used twice or more"); break; case 'r': - src = 1; dst = 0; + src = 1; + dst = 0; break; default: usage(); diff --git a/test/compel/handle_binary.c b/test/compel/handle_binary.c index 4ef42ae11..138b2bc71 100644 --- a/test/compel/handle_binary.c +++ b/test/compel/handle_binary.c @@ -10,9 +10,7 @@ extern const size_t test_elf_buf_size; static uintptr_t elf_addr; static const char *test_bitness; -#define ASSERT(expected, fmt, ...) \ - launch_test((void *)elf_addr, expected, \ - fmt " %s", ##__VA_ARGS__, test_bitness) +#define ASSERT(expected, fmt, ...) launch_test((void *)elf_addr, expected, fmt " %s", ##__VA_ARGS__, test_bitness) static const unsigned int sections_nr = 1; @@ -26,12 +24,11 @@ static int test_add_strings_section(Ehdr_t *hdr) { Shdr_t *sec_strings_hdr; uintptr_t sections_table = elf_addr + hdr->e_shoff; - size_t sections_table_size = sections_nr*sizeof(hdr->e_shentsize); + size_t sections_table_size = sections_nr * sizeof(hdr->e_shentsize); hdr->e_shnum = sections_nr; hdr->e_shstrndx = sections_nr; /* off-by-one */ - if (ASSERT(-E_NO_STR_SEC, - "strings section's header oob of section table")) + if (ASSERT(-E_NO_STR_SEC, "strings section's header oob of section table")) return -1; hdr->e_shstrndx = 0; @@ -42,8 +39,7 @@ static int test_add_strings_section(Ehdr_t *hdr) return -1; /* Put strings just right after sections table. */ - sec_strings_hdr->sh_offset = sections_table - elf_addr + - sections_table_size; + sec_strings_hdr->sh_offset = sections_table - elf_addr + sections_table_size; return 0; } @@ -54,8 +50,8 @@ static int test_prepare_section_table(Ehdr_t *hdr) return -1; /* Lets put sections table right after ELF header. */ - hdr->e_shoff = (Off_t) sizeof(Ehdr_t); - hdr->e_shentsize = (Half_t) sizeof(Shdr_t); + hdr->e_shoff = (Off_t)sizeof(Ehdr_t); + hdr->e_shentsize = (Half_t)sizeof(Shdr_t); hdr->e_shnum = (Half_t)-1; if (ASSERT(-E_NO_STR_SEC, "too many sections in table")) diff --git a/test/others/app-emu/job/job.c b/test/others/app-emu/job/job.c index 44858a78b..a3c6af74c 100644 --- a/test/others/app-emu/job/job.c +++ b/test/others/app-emu/job/job.c @@ -45,8 +45,7 @@ int main(int argc, char *argv[]) gid = getgid(); sid = getsid(pid); - printf("pid %d gid %d sid %d\n", - pid, gid, sid); + printf("pid %d gid %d sid %d\n", pid, gid, sid); snprintf(buf, sizeof(buf), "/proc/%d/fd", pid); fd_dir = opendir(buf); diff --git a/test/others/app-emu/make/tmpl.c b/test/others/app-emu/make/tmpl.c index 95abdf7b6..5ebb8ff4d 100644 --- a/test/others/app-emu/make/tmpl.c +++ b/test/others/app-emu/make/tmpl.c @@ -1,16 +1,16 @@ int foo(int a, int b) { -#define A0(a, b) ((a)+(b)) -#define A1(a, b) ((a)>(b))?A0((a)-(b), (b)):A0((b)-(a), (a)) -#define A2(a, b) ((a)>(b))?A1((a)-(b), (b)):A1((b)-(a), (a)) -#define A3(a, b) ((a)>(b))?A2((a)-(b), (b)):A2((b)-(a), (a)) -#define A4(a, b) ((a)>(b))?A3((a)-(b), (b)):A3((b)-(a), (a)) -#define A5(a, b) ((a)>(b))?A4((a)-(b), (b)):A4((b)-(a), (a)) -#define A6(a, b) ((a)>(b))?A5((a)-(b), (b)):A5((b)-(a), (a)) -#define A7(a, b) ((a)>(b))?A6((a)-(b), (b)):A6((b)-(a), (a)) -#define A8(a, b) ((a)>(b))?A7((a)-(b), (b)):A7((b)-(a), (a)) -#define A9(a, b) ((a)>(b))?A8((a)-(b), (b)):A8((b)-(a), (a)) -#define A10(a, b) ((a)>(b))?A9((a)-(b), (b)):A9((b)-(a), (a)) -#define A11(a, b) ((a)>(b))?A10((a)-(b), (b)):A10((b)-(a), (a)) +#define A0(a, b) ((a) + (b)) +#define A1(a, b) ((a) > (b)) ? A0((a) - (b), (b)) : A0((b) - (a), (a)) +#define A2(a, b) ((a) > (b)) ? A1((a) - (b), (b)) : A1((b) - (a), (a)) +#define A3(a, b) ((a) > (b)) ? A2((a) - (b), (b)) : A2((b) - (a), (a)) +#define A4(a, b) ((a) > (b)) ? A3((a) - (b), (b)) : A3((b) - (a), (a)) +#define A5(a, b) ((a) > (b)) ? A4((a) - (b), (b)) : A4((b) - (a), (a)) +#define A6(a, b) ((a) > (b)) ? A5((a) - (b), (b)) : A5((b) - (a), (a)) +#define A7(a, b) ((a) > (b)) ? A6((a) - (b), (b)) : A6((b) - (a), (a)) +#define A8(a, b) ((a) > (b)) ? A7((a) - (b), (b)) : A7((b) - (a), (a)) +#define A9(a, b) ((a) > (b)) ? A8((a) - (b), (b)) : A8((b) - (a), (a)) +#define A10(a, b) ((a) > (b)) ? A9((a) - (b), (b)) : A9((b) - (a), (a)) +#define A11(a, b) ((a) > (b)) ? A10((a) - (b), (b)) : A10((b) - (a), (a)) return A10(a, b); } diff --git a/test/others/bers/bers.c b/test/others/bers/bers.c index bb0c9dbcb..37cf84dd3 100644 --- a/test/others/bers/bers.c +++ b/test/others/bers/bers.c @@ -16,71 +16,67 @@ #include <dirent.h> #include <syscall.h> -#define min(x, y) ({ \ - typeof(x) _min1 = (x); \ - typeof(y) _min2 = (y); \ - (void) (&_min1 == &_min2); \ - _min1 < _min2 ? _min1 : _min2; }) +#define min(x, y) \ + ({ \ + typeof(x) _min1 = (x); \ + typeof(y) _min2 = (y); \ + (void)(&_min1 == &_min2); \ + _min1 < _min2 ? _min1 : _min2; \ + }) -#define max(x, y) ({ \ - typeof(x) _max1 = (x); \ - typeof(y) _max2 = (y); \ - (void) (&_max1 == &_max2); \ - _max1 > _max2 ? _max1 : _max2; }) +#define max(x, y) \ + ({ \ + typeof(x) _max1 = (x); \ + typeof(y) _max2 = (y); \ + (void)(&_max1 == &_max2); \ + _max1 > _max2 ? _max1 : _max2; \ + }) -#define MAX_CHUNK 4096 -#define PAGE_SIZE 4096 +#define MAX_CHUNK 4096 +#define PAGE_SIZE 4096 -#define pr_info(fmt, ...) \ - printf("%8d: " fmt, sys_gettid(), ##__VA_ARGS__) +#define pr_info(fmt, ...) printf("%8d: " fmt, sys_gettid(), ##__VA_ARGS__) -#define pr_err(fmt, ...) \ - printf("%8d: Error (%s:%d): " fmt, sys_gettid(),\ - __FILE__, __LINE__, ##__VA_ARGS__) +#define pr_err(fmt, ...) printf("%8d: Error (%s:%d): " fmt, sys_gettid(), __FILE__, __LINE__, ##__VA_ARGS__) -#define pr_perror(fmt, ...) \ - pr_err(fmt ": %m\n", ##__VA_ARGS__) +#define pr_perror(fmt, ...) pr_err(fmt ": %m\n", ##__VA_ARGS__) -#define pr_msg(fmt, ...) \ - printf(fmt, ##__VA_ARGS__) +#define pr_msg(fmt, ...) printf(fmt, ##__VA_ARGS__) - -#define pr_trace(fmt, ...) \ - printf("%8d: %s: " fmt, sys_gettid(), __func__, \ - ##__VA_ARGS__) +#define pr_trace(fmt, ...) printf("%8d: %s: " fmt, sys_gettid(), __func__, ##__VA_ARGS__) enum { - MEM_FILL_MODE_NONE = 0, - MEM_FILL_MODE_ALL = 1, - MEM_FILL_MODE_LIGHT = 2, - MEM_FILL_MODE_DIRTIFY = 3, + MEM_FILL_MODE_NONE = 0, + MEM_FILL_MODE_ALL = 1, + MEM_FILL_MODE_LIGHT = 2, + MEM_FILL_MODE_DIRTIFY = 3, }; typedef struct { - pthread_mutex_t mutex; - pthread_mutexattr_t mutex_attr; + pthread_mutex_t mutex; + pthread_mutexattr_t mutex_attr; - size_t opt_tasks; + size_t opt_tasks; - size_t opt_files; - size_t opt_file_size; - int prev_fd[MAX_CHUNK]; + size_t opt_files; + size_t opt_file_size; + int prev_fd[MAX_CHUNK]; - size_t opt_mem; - size_t opt_mem_chunks; - size_t opt_mem_chunk_size; - int opt_mem_fill_mode; - int opt_mem_cycle_mode; - unsigned int opt_refresh_time; + size_t opt_mem; + size_t opt_mem_chunks; + size_t opt_mem_chunk_size; + int opt_mem_fill_mode; + int opt_mem_cycle_mode; + unsigned int opt_refresh_time; - char *opt_work_dir; - int work_dir_fd; - DIR *work_dir; + char *opt_work_dir; + int work_dir_fd; + DIR *work_dir; - pid_t err_pid; - int err_no; + pid_t err_pid; + int err_no; - unsigned long prev_map[MAX_CHUNK]; + unsigned long prev_map[MAX_CHUNK]; } shared_data_t; static shared_data_t *shared; @@ -90,8 +86,7 @@ static int sys_gettid(void) return syscall(__NR_gettid); } -static void dirtify_memory(unsigned long *chunks, size_t nr_chunks, - size_t chunk_size, int mode, const size_t nr_pages) +static void dirtify_memory(unsigned long *chunks, size_t nr_chunks, size_t chunk_size, int mode, const size_t nr_pages) { size_t i; @@ -164,7 +159,7 @@ static int create_files(shared_data_t *shared, int *fd, size_t nr_files) static void work_on_fork(shared_data_t *shared) { const size_t nr_pages = shared->opt_mem_chunk_size / PAGE_SIZE; - unsigned long chunks[MAX_CHUNK] = { }; + unsigned long chunks[MAX_CHUNK] = {}; int fd[MAX_CHUNK]; size_t i; void *mem; @@ -173,8 +168,7 @@ static void work_on_fork(shared_data_t *shared) pthread_mutex_lock(&shared->mutex); pr_trace("init\n"); - pr_info("\tCreating %lu mmaps each %lu K\n", - shared->opt_mem_chunks, shared->opt_mem_chunk_size >> 10); + pr_info("\tCreating %lu mmaps each %lu K\n", shared->opt_mem_chunks, shared->opt_mem_chunk_size >> 10); for (i = 0; i < shared->opt_mem_chunks; i++) { if (shared->prev_map[i]) { @@ -183,28 +177,25 @@ static void work_on_fork(shared_data_t *shared) } /* If we won't change proto here, the kernel might merge close areas */ - mem = mmap(NULL, shared->opt_mem_chunk_size, - PROT_READ | PROT_WRITE | ((i % 2) ? PROT_EXEC : 0), + mem = mmap(NULL, shared->opt_mem_chunk_size, PROT_READ | PROT_WRITE | ((i % 2) ? PROT_EXEC : 0), MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (mem != (void *)MAP_FAILED) { shared->prev_map[i] = (unsigned long)mem; chunks[i] = (unsigned long)mem; - pr_info("\t\tMap at %lx\n",(unsigned long)mem); + pr_info("\t\tMap at %lx\n", (unsigned long)mem); } else { pr_info("\t\tCan't map\n"); - shared->err_pid = sys_gettid(); - shared->err_no = -errno; + shared->err_pid = sys_gettid(); + shared->err_no = -errno; exit(1); } } if (shared->opt_mem_fill_mode) - dirtify_memory(chunks, shared->opt_mem_chunks, - shared->opt_mem_chunk_size, - shared->opt_mem_fill_mode, + dirtify_memory(chunks, shared->opt_mem_chunks, shared->opt_mem_chunk_size, shared->opt_mem_fill_mode, nr_pages); if (create_files(shared, fd, shared->opt_files)) @@ -213,16 +204,14 @@ static void work_on_fork(shared_data_t *shared) if (shared->opt_file_size) dirtify_files(fd, shared->opt_files, shared->opt_file_size); - pr_trace("releasing\n"); + pr_trace("releasing\n"); pthread_mutex_unlock(&shared->mutex); while (1) { sleep(shared->opt_refresh_time); if (shared->opt_mem_cycle_mode) - dirtify_memory(chunks, shared->opt_mem_chunks, - shared->opt_mem_chunk_size, - shared->opt_mem_cycle_mode, - nr_pages); + dirtify_memory(chunks, shared->opt_mem_chunks, shared->opt_mem_chunk_size, + shared->opt_mem_cycle_mode, nr_pages); if (shared->opt_file_size) dirtify_files(fd, shared->opt_files, shared->opt_file_size); } @@ -248,17 +237,17 @@ int main(int argc, char *argv[]) /* a - 97, z - 122, A - 65, 90 */ static const char short_opts[] = "t:d:f:m:c:h"; static struct option long_opts[] = { - {"tasks", required_argument, 0, 't'}, - {"dir", required_argument, 0, 'd'}, - {"files", required_argument, 0, 'f'}, - {"memory", required_argument, 0, 'm'}, - {"mem-chunks", required_argument, 0, 'c'}, - {"help", no_argument, 0, 'h'}, - {"mem-fill", required_argument, 0, 10}, - {"mem-cycle", required_argument, 0, 11}, - {"refresh", required_argument, 0, 12}, - {"file-size", required_argument, 0, 13}, - { }, + { "tasks", required_argument, 0, 't' }, + { "dir", required_argument, 0, 'd' }, + { "files", required_argument, 0, 'f' }, + { "memory", required_argument, 0, 'm' }, + { "mem-chunks", required_argument, 0, 'c' }, + { "help", no_argument, 0, 'h' }, + { "mem-fill", required_argument, 0, 10 }, + { "mem-cycle", required_argument, 0, 11 }, + { "refresh", required_argument, 0, 12 }, + { "file-size", required_argument, 0, 13 }, + {}, }; char workdir[PATH_MAX]; @@ -267,8 +256,7 @@ int main(int argc, char *argv[]) pid_t pid; size_t i; - shared = (void *)mmap(NULL, sizeof(*shared), PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); + shared = (void *)mmap(NULL, sizeof(*shared), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if ((void *)shared == MAP_FAILED) { pr_err("Failed to setup shared data\n"); exit(1); @@ -293,7 +281,7 @@ int main(int argc, char *argv[]) if (opt == -1) break; - switch(opt) { + switch (opt) { case 't': shared->opt_tasks = (size_t)atol(optarg); break; @@ -330,7 +318,7 @@ int main(int argc, char *argv[]) if (!shared->opt_work_dir) { shared->opt_work_dir = getcwd(workdir, sizeof(workdir)); - if (!shared->opt_work_dir) { + if (!shared->opt_work_dir) { pr_perror("Can't fetch current working dir"); exit(1); } @@ -345,16 +333,14 @@ int main(int argc, char *argv[]) shared->work_dir = opendir(shared->opt_work_dir); if (!shared->work_dir) { - pr_perror("Can't open working dir `%s'", - shared->opt_work_dir); + pr_perror("Can't open working dir `%s'", shared->opt_work_dir); exit(1); } shared->work_dir_fd = dirfd(shared->work_dir); shared->opt_mem_chunk_size = shared->opt_mem / shared->opt_mem_chunks; - if (shared->opt_mem_chunk_size && - shared->opt_mem_chunk_size < PAGE_SIZE) { + if (shared->opt_mem_chunk_size && shared->opt_mem_chunk_size < PAGE_SIZE) { pr_err("Memory chunk size is too small, provide at least %lu M of memory\n", (shared->opt_mem_chunks * PAGE_SIZE) >> 20ul); exit(1); @@ -395,8 +381,7 @@ int main(int argc, char *argv[]) sleep(1); err_child: - pr_err("Child %d exited with %d\n", - shared->err_pid, shared->err_no); + pr_err("Child %d exited with %d\n", shared->err_pid, shared->err_no); return shared->err_no; usage: diff --git a/test/others/libcriu/test_errno.c b/test/others/libcriu/test_errno.c index 8bd19fe2f..4df16c173 100644 --- a/test/others/libcriu/test_errno.c +++ b/test/others/libcriu/test_errno.c @@ -90,7 +90,6 @@ err: if (f) fclose(f); return -1; - } static int process_exists(void) diff --git a/test/others/libcriu/test_iters.c b/test/others/libcriu/test_iters.c index 660da9286..2a5ca6def 100644 --- a/test/others/libcriu/test_iters.c +++ b/test/others/libcriu/test_iters.c @@ -28,7 +28,7 @@ static int open_imgdir(void) criu_set_images_dir_fd(cur_imgdir); } -#define MAX_ITERS 2 +#define MAX_ITERS 2 static int next_iter(criu_predump_info pi) { @@ -46,7 +46,7 @@ static int next_iter(criu_predump_info pi) return cur_iter < MAX_ITERS; } -#define SUCC_ECODE 42 +#define SUCC_ECODE 42 int main(int argc, char **argv) { diff --git a/test/others/libcriu/test_notify.c b/test/others/libcriu/test_notify.c index 54fb255ce..66fe75338 100644 --- a/test/others/libcriu/test_notify.c +++ b/test/others/libcriu/test_notify.c @@ -10,7 +10,7 @@ #include "lib.h" -#define SUCC_ECODE 42 +#define SUCC_ECODE 42 static int actions_called = 0; static int notify(char *action, criu_notify_arg_t na) diff --git a/test/others/libcriu/test_self.c b/test/others/libcriu/test_self.c index 374a4b545..468edc0f7 100644 --- a/test/others/libcriu/test_self.c +++ b/test/others/libcriu/test_self.c @@ -9,8 +9,8 @@ #include <sys/wait.h> #include "lib.h" -#define SUCC_DUMP_ECODE 41 -#define SUCC_RSTR_ECODE 43 +#define SUCC_DUMP_ECODE 41 +#define SUCC_RSTR_ECODE 43 int main(int argc, char *argv[]) { @@ -105,5 +105,4 @@ errk: kill(pid, SIGKILL); err: return 1; - } diff --git a/test/others/libcriu/test_sub.c b/test/others/libcriu/test_sub.c index b435f6709..41b685847 100644 --- a/test/others/libcriu/test_sub.c +++ b/test/others/libcriu/test_sub.c @@ -15,7 +15,7 @@ static void sh(int sig) stop = 1; } -#define SUCC_ECODE 42 +#define SUCC_ECODE 42 int main(int argc, char **argv) { diff --git a/test/others/loop.c b/test/others/loop.c index 850c5dedf..736e7f8cb 100644 --- a/test/others/loop.c +++ b/test/others/loop.c @@ -47,7 +47,7 @@ int main(void) write(start_pipe[1], &res, sizeof(res)); close(start_pipe[1]); - while(1) { + while (1) { sleep(1); } } @@ -56,7 +56,7 @@ int main(void) read(start_pipe[0], &res, sizeof(res)); close(start_pipe[0]); - out: +out: if (res == EXIT_SUCCESS) printf("%d\n", pid); return res; diff --git a/test/others/mounts/ext/ext-mount.c b/test/others/mounts/ext/ext-mount.c index e5e974bfc..09347c283 100644 --- a/test/others/mounts/ext/ext-mount.c +++ b/test/others/mounts/ext/ext-mount.c @@ -9,7 +9,7 @@ #include "criu-plugin.h" #include "criu-log.h" -#define IMG_NAME "ext-mount-test-%d.img" +#define IMG_NAME "ext-mount-test-%d.img" extern cr_plugin_init_t cr_plugin_init; extern cr_plugin_dump_ext_mount_t cr_plugin_dump_ext_mount; @@ -47,8 +47,7 @@ int cr_plugin_dump_ext_mount(char *mountpoint, int id) pr_info("Dumping my mount %d\n", id); sprintf(img, IMG_NAME, id); - fd = openat(criu_get_image_dir(), img, - O_RDWR | O_CREAT | O_TRUNC, 0600); + fd = openat(criu_get_image_dir(), img, O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd < 0) { pr_perror("Can't open image"); return -1; diff --git a/test/others/mounts/ext/ns_init.c b/test/others/mounts/ext/ns_init.c index e85bf9dde..99bedc70f 100644 --- a/test/others/mounts/ext/ns_init.c +++ b/test/others/mounts/ext/ns_init.c @@ -41,7 +41,7 @@ int main(int argc, char **argv) if (chdir(argv[2])) return 1; - fd = open(argv[3], O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0600); + fd = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0600); if (fd < 0) return 1; diff --git a/test/others/pipes/pipe.c b/test/others/pipes/pipe.c index d693f4b02..07394a92f 100644 --- a/test/others/pipes/pipe.c +++ b/test/others/pipes/pipe.c @@ -62,36 +62,37 @@ typedef void (*sighandler_t)(int); typedef unsigned long ulong; /* colors */ -#define CS_PARENT "\033[00;32m" -#define CS_CHILD "\033[00;33m" -#define CS_DUMP "\033[00;34m" -#define CS_RESTORE "\033[00;35m" -#define CE "\033[0m" - -#define die(fmt, ...) do { \ - if (!qflag) \ - fprintf(stderr, fmt ": %m\n", __VA_ARGS__); \ - if (getpid() == parent_pid) { \ - (void)kill(0, 9); \ - exit(1); \ - } \ - _exit(1); \ -} while (0) - -#define READ_FD 0 /* pipe read fd */ -#define WRITE_FD 1 /* pipe write fd */ -#define CLASH_FD 3 /* force inherit fd clash */ - -#define MAX_FORKS 3 /* child, checkpoint, restore */ - -#define CRIU_BINARY "../../../criu/criu" -#define IMG_DIR "images" -#define DUMP_LOG_FILE "dump.log" -#define RESTORE_LOG_FILE "restore.log" -#define RESTORE_PID_FILE "restore.pid" -#define INHERIT_FD_OPTION "--inherit-fd" -#define OLD_LOG_FILE "/tmp/oldlog" -#define NEW_LOG_FILE "/tmp/newlog" +#define CS_PARENT "\033[00;32m" +#define CS_CHILD "\033[00;33m" +#define CS_DUMP "\033[00;34m" +#define CS_RESTORE "\033[00;35m" +#define CE "\033[0m" + +#define die(fmt, ...) \ + do { \ + if (!qflag) \ + fprintf(stderr, fmt ": %m\n", __VA_ARGS__); \ + if (getpid() == parent_pid) { \ + (void)kill(0, 9); \ + exit(1); \ + } \ + _exit(1); \ + } while (0) + +#define READ_FD 0 /* pipe read fd */ +#define WRITE_FD 1 /* pipe write fd */ +#define CLASH_FD 3 /* force inherit fd clash */ + +#define MAX_FORKS 3 /* child, checkpoint, restore */ + +#define CRIU_BINARY "../../../criu/criu" +#define IMG_DIR "images" +#define DUMP_LOG_FILE "dump.log" +#define RESTORE_LOG_FILE "restore.log" +#define RESTORE_PID_FILE "restore.pid" +#define INHERIT_FD_OPTION "--inherit-fd" +#define OLD_LOG_FILE "/tmp/oldlog" +#define NEW_LOG_FILE "/tmp/newlog" /* * Command line options (see usage()). @@ -113,21 +114,11 @@ char inh_pipe_arg[64]; char inh_file_opt[16]; char inh_file_arg[64]; -char *dump_argv[] = { - "criu", "dump", - "-D", IMG_DIR, "-o", DUMP_LOG_FILE, - "-v4", - "-t", pid_number, - NULL -}; +char *dump_argv[] = { "criu", "dump", "-D", IMG_DIR, "-o", DUMP_LOG_FILE, "-v4", "-t", pid_number, NULL }; char *restore_argv[] = { - "criu", "restore", "-d", - "-D", IMG_DIR, "-o", RESTORE_LOG_FILE, - "--pidfile", RESTORE_PID_FILE, - "-v4", - inh_pipe_opt, inh_pipe_arg, - inh_file_opt, inh_file_arg, + "criu", "restore", "-d", "-D", IMG_DIR, "-o", RESTORE_LOG_FILE, + "--pidfile", RESTORE_PID_FILE, "-v4", inh_pipe_opt, inh_pipe_arg, inh_file_opt, inh_file_arg, NULL }; @@ -167,11 +158,9 @@ int dup2_safe(int oldfd, int newfd); void usage(char *cmd) { printf("Usage: %s [%s]\n", cmd, cli_flags); - printf("-c\tcause a clash during restore by opening %s as fd %d\n", - OLD_LOG_FILE, CLASH_FD); + printf("-c\tcause a clash during restore by opening %s as fd %d\n", OLD_LOG_FILE, CLASH_FD); printf("-d\tdup the pipe and write to it\n"); - printf("-l\tchange log file from %s to %s during restore\n", - OLD_LOG_FILE, NEW_LOG_FILE); + printf("-l\tchange log file from %s to %s during restore\n", OLD_LOG_FILE, NEW_LOG_FILE); printf("\n"); printf("The following flags should cause restore failure\n"); @@ -184,28 +173,51 @@ void usage(char *cmd) printf("-h\tprint this help and exit\n"); printf("-q\tquiet mode, don't print anything\n"); printf("-v\tverbose mode (list contents of /proc/<pid>/fd)\n"); - } int main(int argc, char *argv[]) { int ret; - int opt; + int opt; int pipefd[2]; max_msgs = 4; while ((opt = getopt(argc, argv, cli_flags)) != -1) { switch (opt) { - case 'c': cflag++; break; - case 'd': dflag++; max_msgs += 4; break; - case 'h': usage(argv[0]); return 0; - case 'l': lflag++; break; - case 'n': nflag++; break; - case 'o': oflag++; max_msgs += 4; break; - case 'q': qflag++; vflag = 0;break; - case 'r': rflag++; break; - case 'v': vflag++; qflag = 0; break; - default: usage(argv[0]); return 1; + case 'c': + cflag++; + break; + case 'd': + dflag++; + max_msgs += 4; + break; + case 'h': + usage(argv[0]); + return 0; + case 'l': + lflag++; + break; + case 'n': + nflag++; + break; + case 'o': + oflag++; + max_msgs += 4; + break; + case 'q': + qflag++; + vflag = 0; + break; + case 'r': + rflag++; + break; + case 'v': + vflag++; + qflag = 0; + break; + default: + usage(argv[0]); + return 1; } } @@ -287,8 +299,7 @@ int parent(int *pipefd) ls_proc_fd(-1); if (!qflag) { - printf("%s read %s from %s\n", who(0), buf, - pipe_name(pipefd[READ_FD])); + printf("%s read %s from %s\n", who(0), buf, pipe_name(pipefd[READ_FD])); } if (nread == (max_msgs / 2)) { @@ -296,8 +307,7 @@ int parent(int *pipefd) if (!nflag) { /* save the old pipe's name before closing it */ - snprintf(old_pipe, sizeof old_pipe, "%s", - pipe_name(pipefd[READ_FD])); + snprintf(old_pipe, sizeof old_pipe, "%s", pipe_name(pipefd[READ_FD])); close_safe(pipefd[READ_FD]); /* create a new one */ @@ -340,14 +350,20 @@ int child(int *pipefd, int dupfd, int openfd) ls_proc_fd(-1); switch (i % num_wfds) { - case 0: fd = pipefd[WRITE_FD]; break; - case 1: fd = dflag ? dupfd : openfd; break; - case 2: fd = openfd; break; + case 0: + fd = pipefd[WRITE_FD]; + break; + case 1: + fd = dflag ? dupfd : openfd; + break; + case 2: + fd = openfd; + break; } - write_to_fd(fd, pipe_name(pipefd[WRITE_FD]), i+1, 0); + write_to_fd(fd, pipe_name(pipefd[WRITE_FD]), i + 1, 0); if (cflag) - write_to_fd(CLASH_FD, "log file", i+1, 1); + write_to_fd(CLASH_FD, "log file", i + 1, 1); /* * Since sleep will be interrupted by C/R, make sure @@ -376,8 +392,7 @@ void chld_handler(int signum) status = WEXITSTATUS(status); if (pid == child_pid) { if (!qflag) { - printf("%s %s exited with status %d\n", who(0), - who(pid), status); + printf("%s %s exited with status %d\n", who(0), who(pid), status); } /* if child exited successfully, we're done */ if (status == 0) @@ -402,8 +417,7 @@ void checkpoint_child(int child_pid, int *pipefd) if (WIFEXITED(status)) status = WEXITSTATUS(status); if (!qflag) { - printf("%s %s exited with status %d\n", who(0), - who(pid), status); + printf("%s %s exited with status %d\n", who(0), who(pid), status); } if (status) exit(status); @@ -430,8 +444,7 @@ void restore_child(int *new_pipefd, char *old_pipe_name) if (WIFEXITED(status)) status = WEXITSTATUS(status); if (!qflag) { - printf("%s %s exited with status %d\n", who(0), - who(pid), status); + printf("%s %s exited with status %d\n", who(0), who(pid), status); } if (status) exit(status); @@ -457,20 +470,16 @@ void restore_child(int *new_pipefd, char *old_pipe_name) } /* --inherit-fd fd[CLASH_FD]:pipe[xxxxxx] */ - snprintf(inh_pipe_opt, sizeof inh_pipe_opt, - "%s", INHERIT_FD_OPTION); - snprintf(inh_pipe_arg, sizeof inh_pipe_arg, "fd[%d]:%s", - CLASH_FD, old_pipe_name); + snprintf(inh_pipe_opt, sizeof inh_pipe_opt, "%s", INHERIT_FD_OPTION); + snprintf(inh_pipe_arg, sizeof inh_pipe_arg, "fd[%d]:%s", CLASH_FD, old_pipe_name); if (lflag) { /* create a new log file to replace the old one */ int filefd = open_safe(NEW_LOG_FILE, O_WRONLY | O_APPEND | O_CREAT); /* --inherit-fd fd[x]:tmp/oldlog */ - snprintf(inh_file_opt, sizeof inh_file_opt, - "%s", INHERIT_FD_OPTION); - snprintf(inh_file_arg, sizeof inh_file_arg, - "fd[%d]:%s", filefd, OLD_LOG_FILE + 1); + snprintf(inh_file_opt, sizeof inh_file_opt, "%s", INHERIT_FD_OPTION); + snprintf(inh_file_arg, sizeof inh_file_arg, "fd[%d]:%s", filefd, OLD_LOG_FILE + 1); restore_argv[12] = inh_file_opt; } else @@ -488,7 +497,7 @@ void restore_child(int *new_pipefd, char *old_pipe_name) void write_to_fd(int fd, char *name, int i, int newline) { int n; - char buf[16]; /* fit "hello d\n" for small d */ + char buf[16]; /* fit "hello d\n" for small d */ n = snprintf(buf, sizeof buf, "hello %d", i); if (!qflag) @@ -601,8 +610,7 @@ void close_safe(int fd) void write_safe(int fd, char *buf, int count) { if (write(fd, buf, count) != count) { - die("write: fd=%d buf=\"%s\" count=%d errno=%d", - fd, buf, count, errno); + die("write: fd=%d buf=\"%s\" count=%d errno=%d", fd, buf, count, errno); } } diff --git a/test/others/rpc/test-c.c b/test/others/rpc/test-c.c index 751f9ba9d..06f13b20f 100644 --- a/test/others/rpc/test-c.c +++ b/test/others/rpc/test-c.c @@ -43,7 +43,7 @@ static int send_req(int socket_fd, CriuReq *req) return -1; } - if (write(socket_fd, buf, len) == -1) { + if (write(socket_fd, buf, len) == -1) { perror("Can't send request"); return -1; } @@ -53,8 +53,8 @@ static int send_req(int socket_fd, CriuReq *req) int main(int argc, char *argv[]) { - CriuReq req = CRIU_REQ__INIT; - CriuResp *resp = NULL; + CriuReq req = CRIU_REQ__INIT; + CriuResp *resp = NULL; int fd, dir_fd; int ret = 0; struct sockaddr_un addr; @@ -81,11 +81,11 @@ int main(int argc, char *argv[]) * Set "DUMP" type of request. * Allocate CriuDumpReq. */ - req.type = CRIU_REQ_TYPE__DUMP; - req.opts = malloc(sizeof(CriuOpts)); + req.type = CRIU_REQ_TYPE__DUMP; + req.opts = malloc(sizeof(CriuOpts)); if (!req.opts) { - perror("Can't allocate memory for dump request"); - return -1; + perror("Can't allocate memory for dump request"); + return -1; } criu_opts__init(req.opts); @@ -94,11 +94,11 @@ int main(int argc, char *argv[]) * Set dump options. * Checkout more in protobuf/rpc.proto. */ - req.opts->has_leave_running = true; - req.opts->leave_running = true; - req.opts->images_dir_fd = dir_fd; - req.opts->has_log_level = true; - req.opts->log_level = 4; + req.opts->has_leave_running = true; + req.opts->leave_running = true; + req.opts->images_dir_fd = dir_fd; + req.opts->has_log_level = true; + req.opts->log_level = 4; /* * Connect to service socket @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) addr_len = strlen(addr.sun_path) + sizeof(addr.sun_family); - ret = connect(fd, (struct sockaddr *) &addr, addr_len); + ret = connect(fd, (struct sockaddr *)&addr, addr_len); if (ret == -1) { perror("Cant connect to socket"); goto exit; diff --git a/test/others/socketpairs/socketpair.c b/test/others/socketpairs/socketpair.c index d0c1bbd1c..db6bed406 100644 --- a/test/others/socketpairs/socketpair.c +++ b/test/others/socketpairs/socketpair.c @@ -25,35 +25,36 @@ typedef void (*sighandler_t)(int); typedef unsigned long ulong; /* colors */ -#define CS_PARENT "\033[00;32m" -#define CS_CHILD "\033[00;33m" -#define CS_DUMP "\033[00;34m" -#define CS_RESTORE "\033[00;35m" -#define CE "\033[0m" - -#define die(fmt, ...) do { \ - fprintf(stderr, fmt ": %m\n", __VA_ARGS__); \ - if (getpid() == parent_pid) { \ - (void)kill(0, 9); \ - exit(1); \ - } \ - _exit(1); \ -} while (0) - -#define READ_FD 0 /* pipe read fd */ -#define WRITE_FD 1 /* pipe write fd */ -#define CLASH_FD 3 /* force inherit fd clash */ - -#define MAX_FORKS 3 /* child, checkpoint, restore */ - -#define CRIU_BINARY "../../../criu/criu" -#define IMG_DIR "images" -#define DUMP_LOG_FILE "dump.log" -#define RESTORE_LOG_FILE "restore.log" -#define RESTORE_PID_FILE "restore.pid" -#define INHERIT_FD_OPTION "--inherit-fd" -#define OLD_LOG_FILE "/tmp/oldlog" -#define NEW_LOG_FILE "/tmp/newlog" +#define CS_PARENT "\033[00;32m" +#define CS_CHILD "\033[00;33m" +#define CS_DUMP "\033[00;34m" +#define CS_RESTORE "\033[00;35m" +#define CE "\033[0m" + +#define die(fmt, ...) \ + do { \ + fprintf(stderr, fmt ": %m\n", __VA_ARGS__); \ + if (getpid() == parent_pid) { \ + (void)kill(0, 9); \ + exit(1); \ + } \ + _exit(1); \ + } while (0) + +#define READ_FD 0 /* pipe read fd */ +#define WRITE_FD 1 /* pipe write fd */ +#define CLASH_FD 3 /* force inherit fd clash */ + +#define MAX_FORKS 3 /* child, checkpoint, restore */ + +#define CRIU_BINARY "../../../criu/criu" +#define IMG_DIR "images" +#define DUMP_LOG_FILE "dump.log" +#define RESTORE_LOG_FILE "restore.log" +#define RESTORE_PID_FILE "restore.pid" +#define INHERIT_FD_OPTION "--inherit-fd" +#define OLD_LOG_FILE "/tmp/oldlog" +#define NEW_LOG_FILE "/tmp/newlog" /* * Command line options (see usage()). @@ -70,22 +71,11 @@ char inh_unixsk_arg[64]; char external_sk_ino[32]; char *dump_argv[] = { - "criu", "dump", - "-D", IMG_DIR, "-o", DUMP_LOG_FILE, - "-v4", - external_sk_ino, - "-t", pid_number, - NULL + "criu", "dump", "-D", IMG_DIR, "-o", DUMP_LOG_FILE, "-v4", external_sk_ino, "-t", pid_number, NULL }; -char *restore_argv[] = { - "criu", "restore", "-d", - "-D", IMG_DIR, "-o", RESTORE_LOG_FILE, - "--pidfile", RESTORE_PID_FILE, - "-v4", "-x", - inh_unixsk_opt, inh_unixsk_arg, - NULL -}; +char *restore_argv[] = { "criu", "restore", "-d", "-D", IMG_DIR, "-o", RESTORE_LOG_FILE, + "--pidfile", RESTORE_PID_FILE, "-v4", "-x", inh_unixsk_opt, inh_unixsk_arg, NULL }; int max_forks; int parent_pid; @@ -151,12 +141,9 @@ int main(int argc, char *argv[]) break; case '?': if ('m' == optopt) - fprintf (stderr, "Option -%c requires an argument.\n", optopt); + fprintf(stderr, "Option -%c requires an argument.\n", optopt); else - fprintf ( - stderr, - "Unknown option character `\\x%x'.\n", - optopt); + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); return 1; default: usage(argv[0]); @@ -177,9 +164,9 @@ int main(int argc, char *argv[]) prctl_safe(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0); snprintf(external_sk_ino, sizeof(external_sk_ino), "--ext-unix-sk=%u", - (unsigned int)socket_inode(socketfd[WRITE_FD])); + (unsigned int)socket_inode(socketfd[WRITE_FD])); - char unix_sk_ino[32] = {0}; + char unix_sk_ino[32] = { 0 }; strcpy(unix_sk_ino, socket_name(socketfd[WRITE_FD])); close_safe(socketfd[WRITE_FD]); ret = parent(socketfd, unix_sk_ino); @@ -224,11 +211,7 @@ int parent(int *socketfd, const char *ino_child_sk) if (vflag && nread == 1) ls_proc_fd(-1); - printf( - "%s read %s from %s\n", - who(0), buf, - socket_name(socketfd[READ_FD])); - + printf("%s read %s from %s\n", who(0), buf, socket_name(socketfd[READ_FD])); if (nread == (max_msgs / 2)) { checkpoint_child(child_pid, socketfd); @@ -276,12 +259,18 @@ int child(int *socketfd, int dupfd, int openfd) ls_proc_fd(-1); switch (i % num_wfds) { - case 0: fd = socketfd[WRITE_FD]; break; - case 1: fd = openfd; break; - case 2: fd = openfd; break; + case 0: + fd = socketfd[WRITE_FD]; + break; + case 1: + fd = openfd; + break; + case 2: + fd = openfd; + break; } - write_to_fd(fd, socket_name(socketfd[WRITE_FD]), i+1, 0); + write_to_fd(fd, socket_name(socketfd[WRITE_FD]), i + 1, 0); /* * Since sleep will be interrupted by C/R, make sure * to sleep an entire second to minimize the chance of @@ -307,8 +296,7 @@ void chld_handler(int signum) if (WIFEXITED(status)) status = WEXITSTATUS(status); if (pid == child_pid) { - printf("%s %s exited with status %d\n", who(0), - who(pid), status); + printf("%s %s exited with status %d\n", who(0), who(pid), status); /* if child exited successfully, we're done */ if (status == 0) exit(0); @@ -331,8 +319,7 @@ void checkpoint_child(int child_pid, int *socketfd) pid = waitpid_safe(criu_dump_pid, &status, 0, 2); if (WIFEXITED(status)) status = WEXITSTATUS(status); - printf("%s %s exited with status %d\n", who(0), - who(pid), status); + printf("%s %s exited with status %d\n", who(0), who(pid), status); if (status) exit(status); } else { @@ -358,8 +345,7 @@ void restore_child(int *new_socketfd, const char *old_sock_name) if (WIFEXITED(status)) status = WEXITSTATUS(status); - printf("%s %s exited with status %d\n", who(0), - who(pid), status); + printf("%s %s exited with status %d\n", who(0), who(pid), status); if (status) exit(status); @@ -371,10 +357,8 @@ void restore_child(int *new_socketfd, const char *old_sock_name) move_fd(new_socketfd[WRITE_FD], CLASH_FD); /* --inherit-fd fd[CLASH_FD]:socket[xxxxxx] */ - snprintf(inh_unixsk_opt, sizeof inh_unixsk_opt, - "%s", INHERIT_FD_OPTION); - snprintf(inh_unixsk_arg, sizeof inh_unixsk_arg, "fd[%d]:%s", - CLASH_FD, old_sock_name); + snprintf(inh_unixsk_opt, sizeof inh_unixsk_opt, "%s", INHERIT_FD_OPTION); + snprintf(inh_unixsk_arg, sizeof inh_unixsk_arg, "fd[%d]:%s", CLASH_FD, old_sock_name); restore_argv[11] = inh_unixsk_opt; restore_argv[13] = NULL; @@ -390,7 +374,7 @@ void restore_child(int *new_socketfd, const char *old_sock_name) void write_to_fd(int fd, char *name, int i, int newline) { int n; - char buf[16]; /* fit "hello d\n" for small d */ + char buf[16]; /* fit "hello d\n" for small d */ n = snprintf(buf, sizeof buf, "hello %d", i); @@ -428,12 +412,12 @@ char *socket_name(int fd) ino_t socket_inode(int fd) { - struct stat sbuf; + struct stat sbuf; - if (fstat(fd, &sbuf) == -1) - die("fstat: fd=%i", fd); + if (fstat(fd, &sbuf) == -1) + die("fstat: fd=%i", fd); - return sbuf.st_ino; + return sbuf.st_ino; } /* @@ -510,8 +494,7 @@ void close_safe(int fd) void write_safe(int fd, char *buf, int count) { if (write(fd, buf, count) != count) { - die("write: fd=%d buf=\"%s\" count=%d errno=%d", - fd, buf, count, errno); + die("write: fd=%d buf=\"%s\" count=%d errno=%d", fd, buf, count, errno); } } diff --git a/test/others/tcp/cln.c b/test/others/tcp/cln.c index 6275d3728..412eb8209 100644 --- a/test/others/tcp/cln.c +++ b/test/others/tcp/cln.c @@ -8,7 +8,7 @@ #include <stdio.h> #include <signal.h> -#define BUF_SIZE (1024) +#define BUF_SIZE (1024) static char rbuf[BUF_SIZE]; static char buf[BUF_SIZE]; @@ -39,8 +39,7 @@ static int check_buf(int sk, char *buf, int count) for (i = 0; i < count; i++) if (buf[i] != rbuf[i]) { - printf("Mismatch on %d byte %d != %d\n", - i, (int)buf[i], (int)rbuf[i]); + printf("Mismatch on %d byte %d != %d\n", i, (int)buf[i], (int)rbuf[i]); return 1; } diff --git a/test/others/unix-callback/syslog-lib.c b/test/others/unix-callback/syslog-lib.c index c7950cad4..a0a9e91ea 100644 --- a/test/others/unix-callback/syslog-lib.c +++ b/test/others/unix-callback/syslog-lib.c @@ -21,7 +21,7 @@ int cr_plugin_dump_unix_sk(int sk, int id) char buf[4096]; int fd; - if (getsockname(sk, (struct sockaddr *) &addr, &addr_len) < 0) + if (getsockname(sk, (struct sockaddr *)&addr, &addr_len) < 0) return -1; if (strncmp(addr.sun_path, "/dev/log", addr_len - sizeof(addr.sun_family))) @@ -49,7 +49,7 @@ int cr_plugin_restore_unix_sk(int id) return -ENOTSUP; close(fd); - sk = socket(AF_FILE, SOCK_DGRAM|SOCK_CLOEXEC, 0); + sk = socket(AF_FILE, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk == -1) return sk; @@ -57,7 +57,7 @@ int cr_plugin_restore_unix_sk(int id) addr_len = strlen("/dev/log"); strncpy(addr.sun_path, "/dev/log", addr_len); addr_len += sizeof(addr.sun_family); - if (connect(sk, (struct sockaddr *) &addr, addr_len) == -1) { + if (connect(sk, (struct sockaddr *)&addr, addr_len) == -1) { close(sk); return -1; } diff --git a/test/others/unix-callback/unix-client.c b/test/others/unix-callback/unix-client.c index 676c4adbc..6e57c404d 100644 --- a/test/others/unix-callback/unix-client.c +++ b/test/others/unix-callback/unix-client.c @@ -37,7 +37,7 @@ static int create_sock(int i) addr_len = snprintf(addr.sun_path, UNIX_PATH_MAX, "%s%d", SK_NAME, id); addr_len += sizeof(addr.sun_family); - if (bind(sk, (struct sockaddr *) &addr, addr_len) < 0) { + if (bind(sk, (struct sockaddr *)&addr, addr_len) < 0) { perror("bind"); return 1; } @@ -46,7 +46,7 @@ static int create_sock(int i) addr_len = snprintf(addr.sun_path, UNIX_PATH_MAX, SK_NAME); addr_len += sizeof(addr.sun_family); - if (connect(sk, (struct sockaddr *) &addr, addr_len) < 0) { + if (connect(sk, (struct sockaddr *)&addr, addr_len) < 0) { perror("connect"); return 1; } @@ -102,7 +102,7 @@ int main(void) dprintf(fd, "%d\n", getpid()); close(fd); - openlog("test", LOG_NDELAY, LOG_USER ); + openlog("test", LOG_NDELAY, LOG_USER); sigemptyset(&set); sigaddset(&set, SIGTERM); @@ -118,4 +118,3 @@ int main(void) printf("PASS\n"); return 0; } - diff --git a/test/others/unix-callback/unix-lib.c b/test/others/unix-callback/unix-lib.c index 44b149848..b2ddf0920 100644 --- a/test/others/unix-callback/unix-lib.c +++ b/test/others/unix-callback/unix-lib.c @@ -39,7 +39,7 @@ static int get_srv_socket(void) addr_len += sizeof(addr.sun_family); unlink(addr.sun_path); - if (bind(skd, (struct sockaddr *) &addr, addr_len) < 0) { + if (bind(skd, (struct sockaddr *)&addr, addr_len) < 0) { pr_perror("bind"); return 1; } @@ -48,7 +48,7 @@ static int get_srv_socket(void) addr_len = snprintf(addr.sun_path, UNIX_PATH_MAX, SK_NAME); addr_len += sizeof(addr.sun_family); - if (connect(skd, (struct sockaddr *) &addr, addr_len) < 0) { + if (connect(skd, (struct sockaddr *)&addr, addr_len) < 0) { pr_perror("connect"); return -1; } @@ -69,7 +69,7 @@ int cr_plugin_dump_unix_sk(int sk, int sk_id) int skd, id, ret, fd, len; UnixTest e = UNIX_TEST__INIT; - if (getpeername(sk, (struct sockaddr *) &addr, &addr_len)) { + if (getpeername(sk, (struct sockaddr *)&addr, &addr_len)) { pr_perror("getpeername"); return -1; } @@ -78,8 +78,7 @@ int cr_plugin_dump_unix_sk(int sk, int sk_id) if (addr.sun_path[len - 1] == 0) len--; - if (len != strlen(SK_NAME) || - strncmp(addr.sun_path, SK_NAME, strlen(SK_NAME))) + if (len != strlen(SK_NAME) || strncmp(addr.sun_path, SK_NAME, strlen(SK_NAME))) return -ENOTSUP; pr_info("Dump the socket %x\n", sk_id); @@ -89,7 +88,7 @@ int cr_plugin_dump_unix_sk(int sk, int sk_id) addr_len = sizeof(struct sockaddr_un); - if (getsockname(sk, (struct sockaddr *) &addr, &addr_len) < 0) + if (getsockname(sk, (struct sockaddr *)&addr, &addr_len) < 0) return -1; id = atoi(addr.sun_path + strlen(SK_NAME)); @@ -120,7 +119,7 @@ int cr_plugin_dump_unix_sk(int sk, int sk_id) return -1; } - ret = unix_test__pack(&e, (uint8_t *) buf); + ret = unix_test__pack(&e, (uint8_t *)buf); if (write(fd, buf, ret) != ret) return -1; close(fd); @@ -148,7 +147,7 @@ int cr_plugin_restore_unix_sk(int sk_id) } close(fd); - e = unix_test__unpack(NULL, ret, (uint8_t *) buf); + e = unix_test__unpack(NULL, ret, (uint8_t *)buf); if (e == NULL) return -1; @@ -162,7 +161,7 @@ int cr_plugin_restore_unix_sk(int sk_id) memcpy(addr.sun_path, e->name.data, e->name.len); addr_len = sizeof(addr.sun_family) + e->name.len; - if (bind(sk, (struct sockaddr *) &addr, addr_len) < 0) { + if (bind(sk, (struct sockaddr *)&addr, addr_len) < 0) { pr_perror("bind"); return -1; } @@ -171,7 +170,7 @@ int cr_plugin_restore_unix_sk(int sk_id) addr_len = snprintf(addr.sun_path, UNIX_PATH_MAX, SK_NAME); addr_len += sizeof(addr.sun_family); - if (connect(sk, (struct sockaddr *) &addr, addr_len) < 0) { + if (connect(sk, (struct sockaddr *)&addr, addr_len) < 0) { pr_perror("connect"); return -1; } diff --git a/test/others/unix-callback/unix-server.c b/test/others/unix-callback/unix-server.c index 47bebd05d..d99bc68df 100644 --- a/test/others/unix-callback/unix-server.c +++ b/test/others/unix-callback/unix-server.c @@ -8,8 +8,7 @@ #include <sys/socket.h> #include <linux/un.h> -struct ticket -{ +struct ticket { struct ticket *next; int val; int id; @@ -40,7 +39,7 @@ int main(void) addr_len = snprintf(addr.sun_path, UNIX_PATH_MAX, SK_NAME); addr_len += sizeof(addr.sun_family); - if (bind(sk, (struct sockaddr *) &addr, addr_len) < 0) { + if (bind(sk, (struct sockaddr *)&addr, addr_len) < 0) { perror("bind"); return 1; } @@ -49,7 +48,7 @@ int main(void) while (1) { addr_len = sizeof(struct sockaddr_un); - ret = recvfrom(sk, buf, sizeof(buf), 0, (struct sockaddr *) &addr, &addr_len); + ret = recvfrom(sk, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &addr_len); if (ret == 0) return 0; if (ret < 0) { @@ -60,7 +59,7 @@ int main(void) switch (buf[0]) { case 'l': ret = sprintf(buf, "%ld", st.st_ino); - if (sendto(sk, buf, ret + 1, 0, (struct sockaddr *) &addr, addr_len) < 0) { + if (sendto(sk, buf, ret + 1, 0, (struct sockaddr *)&addr, addr_len) < 0) { perror("sendto"); return -1; } @@ -74,7 +73,7 @@ int main(void) t->val = atoi(buf + 1); t->next = tickets; - t->id = atoi(addr.sun_path +strlen(SK_NAME)); + t->id = atoi(addr.sun_path + strlen(SK_NAME)); printf("t: id %d val %d\n", t->id, t->val); tickets = t; break; @@ -90,7 +89,7 @@ int main(void) return 1; printf("r: id %d val %d\n", id, t->val); ret = sprintf(buf, "%d", t->val); - if (sendto(sk, buf, ret + 1, 0, (struct sockaddr *) &addr, addr_len) < 0) { + if (sendto(sk, buf, ret + 1, 0, (struct sockaddr *)&addr, addr_len) < 0) { perror("sendto"); return 1; } diff --git a/test/zdtm/lib/bpfmap_zdtm.c b/test/zdtm/lib/bpfmap_zdtm.c index 73a79b3f5..7fe1ed182 100644 --- a/test/zdtm/lib/bpfmap_zdtm.c +++ b/test/zdtm/lib/bpfmap_zdtm.c @@ -39,13 +39,13 @@ int parse_bpfmap_fdinfo(int fd, struct bpfmap_fdinfo_obj *obj, uint32_t expected continue; } if (fdinfo_field(str, "map_flags")) { - if (sscanf(str, "map_flags: %"PRIx32"", &obj->map_flags) != 1) + if (sscanf(str, "map_flags: %" PRIx32 "", &obj->map_flags) != 1) goto parse_err; met++; continue; } if (fdinfo_field(str, "memlock")) { - if (sscanf(str, "memlock: %"PRIu64"", &obj->memlock) != 1) + if (sscanf(str, "memlock: %" PRIu64 "", &obj->memlock) != 1) goto parse_err; met++; continue; @@ -86,17 +86,11 @@ int cmp_bpf_map_info(struct bpf_map_info *old, struct bpf_map_info *new) * the new BPF map created by CRIU (during restore) will have a different * map id than the old one */ - if ((old->type != new->type) || - (old->key_size != new->key_size) || - (old->value_size != new->value_size) || - (old->max_entries != new->max_entries) || - (old->map_flags != new->map_flags) || - (old->ifindex != new->ifindex) || - (old->netns_dev != new->netns_dev) || - (old->netns_ino != new->netns_ino) || - (old->btf_id != new->btf_id) || - (old->btf_key_type_id != new->btf_key_type_id) || - (old->btf_value_type_id != new->btf_value_type_id)) + if ((old->type != new->type) || (old->key_size != new->key_size) || (old->value_size != new->value_size) || + (old->max_entries != new->max_entries) || (old->map_flags != new->map_flags) || + (old->ifindex != new->ifindex) || (old->netns_dev != new->netns_dev) || + (old->netns_ino != new->netns_ino) || (old->btf_id != new->btf_id) || + (old->btf_key_type_id != new->btf_key_type_id) || (old->btf_value_type_id != new->btf_value_type_id)) return -1; if (strcmp(old->name, new->name) != 0) @@ -113,13 +107,9 @@ int cmp_bpfmap_fdinfo(struct bpfmap_fdinfo_obj *old, struct bpfmap_fdinfo_obj *n * the new BPF map created by CRIU (during restore) will have a different map * id than the old one */ - if ((old->map_type != new->map_type) || - (old->key_size != new->key_size) || - (old->value_size != new->value_size) || - (old->max_entries != new->max_entries) || - (old->map_flags != new->map_flags) || - (old->memlock != new->memlock) || - (old->frozen != new->frozen)) + if ((old->map_type != new->map_type) || (old->key_size != new->key_size) || + (old->value_size != new->value_size) || (old->max_entries != new->max_entries) || + (old->map_flags != new->map_flags) || (old->memlock != new->memlock) || (old->frozen != new->frozen)) return -1; return 0; diff --git a/test/zdtm/lib/datagen.c b/test/zdtm/lib/datagen.c index 83fbea285..1561820c7 100644 --- a/test/zdtm/lib/datagen.c +++ b/test/zdtm/lib/datagen.c @@ -120,10 +120,7 @@ int datachk(const uint8_t *buffer, unsigned length, uint32_t *crc) for (; length-- > 4; buffer++) *crc = crc32_le8(*crc, *buffer); - read_crc = buffer[0] | - buffer[1] << 8 | - buffer[2] << 16 | - buffer[3] << 24; + read_crc = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24; if (read_crc != *crc) { test_msg("Read: %x, Expected: %x\n", read_crc, *crc); return 1; diff --git a/test/zdtm/lib/fs.c b/test/zdtm/lib/fs.c index e82011ec8..7b8be5f9f 100644 --- a/test/zdtm/lib/fs.c +++ b/test/zdtm/lib/fs.c @@ -54,10 +54,7 @@ mnt_info_t *get_cwd_mnt_info(void) while (fgets(str, sizeof(str), f)) { char *hyphen = strchr(str, '-'); - ret = sscanf(str, "%i %i %u:%u %s %s", - &mnt_id, &parent_mnt_id, - &kmaj, &kmin, - root, mountpoint); + ret = sscanf(str, "%i %i %u:%u %s %s", &mnt_id, &parent_mnt_id, &kmaj, &kmin, root, mountpoint); if (ret != 6 || !hyphen) goto err; ret = sscanf(hyphen + 1, " %ms", &fsname); @@ -110,8 +107,7 @@ int get_cwd_check_perm(char **result) "failed for uid:%d,gid:%d, error: %d(%s). " "Bit 'x' should be set in all path components of " "this directory\n", - cwd, getuid(), getgid(), errno, strerror(errno) - ); + cwd, getuid(), getgid(), errno, strerror(errno)); return -1; } diff --git a/test/zdtm/lib/groups.c b/test/zdtm/lib/groups.c index 83b0938a4..8aa744147 100644 --- a/test/zdtm/lib/groups.c +++ b/test/zdtm/lib/groups.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Group starter"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Group starter"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/lib/lock.c b/test/zdtm/lib/lock.c index 3c3691d98..d47fc736f 100644 --- a/test/zdtm/lib/lock.c +++ b/test/zdtm/lib/lock.c @@ -8,7 +8,7 @@ #include "zdtmtst.h" -#define TASK_WAITER_INITIAL 0x0fffff +#define TASK_WAITER_INITIAL 0x0fffff static long sys_gettid(void) { @@ -34,8 +34,10 @@ void task_waiter_fini(task_waiter_t *t) void task_waiter_wait4(task_waiter_t *t, unsigned int lockid) { - struct timespec req = { .tv_nsec = TASK_WAITER_INITIAL, }; - struct timespec rem = { }; + struct timespec req = { + .tv_nsec = TASK_WAITER_INITIAL, + }; + struct timespec rem = {}; unsigned int v; for (;;) { diff --git a/test/zdtm/lib/msg.c b/test/zdtm/lib/msg.c index fe0994077..1cf92e3e0 100644 --- a/test/zdtm/lib/msg.c +++ b/test/zdtm/lib/msg.c @@ -50,8 +50,7 @@ void test_msg(const char *format, ...) gettimeofday(&tv, NULL); tm = localtime(&tv.tv_sec); if (tm == NULL) { - fprintf(stderr, "ERROR in %s: localtime() failed: %m\n", - __func__); + fprintf(stderr, "ERROR in %s: localtime() failed: %m\n", __func__); } else { off += strftime(buf, sizeof(buf), "%H:%M:%S", tm); } diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c index 0054a3040..6f6cccc99 100644 --- a/test/zdtm/lib/ns.c +++ b/test/zdtm/lib/ns.c @@ -41,7 +41,7 @@ static int prepare_mntns(void) * under them. So we need to create another mount for the * new root. */ - if (mount(root, root, NULL, MS_SLAVE , NULL)) { + if (mount(root, root, NULL, MS_SLAVE, NULL)) { fprintf(stderr, "Can't bind-mount root: %m\n"); return -1; } @@ -54,8 +54,7 @@ static int prepare_mntns(void) criu_path = getenv("ZDTM_CRIU"); if (criu_path) { snprintf(path, sizeof(path), "%s%s", root, criu_path); - if (mount(criu_path, path, NULL, MS_BIND, NULL) || - mount(NULL, path, NULL, MS_PRIVATE, NULL)) { + if (mount(criu_path, path, NULL, MS_BIND, NULL) || mount(NULL, path, NULL, MS_PRIVATE, NULL)) { pr_perror("Unable to mount %s", path); return -1; } @@ -87,7 +86,7 @@ static int prepare_mntns(void) return -1; } - if (mount("./old", "./old", NULL, MS_SLAVE | MS_REC , NULL)) { + if (mount("./old", "./old", NULL, MS_SLAVE | MS_REC, NULL)) { fprintf(stderr, "Can't bind-mount root: %m\n"); return -1; } @@ -159,7 +158,7 @@ static int prepare_namespaces(void) return 0; } -#define NS_STACK_SIZE 4096 +#define NS_STACK_SIZE 4096 /* All arguments should be above stack, because it grows down */ struct ns_exec_args { @@ -191,13 +190,11 @@ static void ns_sig_hand(int signo) if (futex_get(&sig_received)) return; futex_set_and_wake(&sig_received, signo); - len = snprintf(buf, sizeof(buf), - "All test processes exited\n"); + len = snprintf(buf, sizeof(buf), "All test processes exited\n"); } else { - len = snprintf(buf, sizeof(buf), - "wait() failed: %m\n"); + len = snprintf(buf, sizeof(buf), "wait() failed: %m\n"); } - goto write_out; + goto write_out; } if (status) fprintf(stderr, "%d return %d\n", pid, status); @@ -210,7 +207,7 @@ write_out: } #ifndef CLONE_NEWTIME -#define CLONE_NEWTIME 0x00000080 /* New time namespace */ +#define CLONE_NEWTIME 0x00000080 /* New time namespace */ #endif static inline int _settime(clockid_t clk_id, time_t offset) @@ -245,7 +242,7 @@ static inline int _settime(clockid_t clk_id, time_t offset) #define STATUS_FD 255 static int ns_exec(void *_arg) { - struct ns_exec_args *args = (struct ns_exec_args *) _arg; + struct ns_exec_args *args = (struct ns_exec_args *)_arg; char buf[4096]; int ret; @@ -304,8 +301,8 @@ static int create_timens(void) int ns_init(int argc, char **argv) { struct sigaction sa = { - .sa_handler = ns_sig_hand, - .sa_flags = SA_RESTART, + .sa_handler = ns_sig_hand, + .sa_flags = SA_RESTART, }; int ret, fd, status_pipe = STATUS_FD; char buf[128], *x; @@ -372,7 +369,7 @@ int ns_init(int argc, char **argv) break; if (pid < 0) { fprintf(stderr, "waitpid() failed: %m\n"); - exit (1); + exit(1); } if (status) fprintf(stderr, "%d return %d\n", pid, status); @@ -426,7 +423,6 @@ int ns_init(int argc, char **argv) waitpid(pid, NULL, 0); } - exit(1); } @@ -449,8 +445,7 @@ void ns_create(int argc, char **argv) exit(1); } - flags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWUTS | - CLONE_NEWNET | CLONE_NEWIPC | SIGCHLD; + flags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWNET | CLONE_NEWIPC | SIGCHLD; if (getenv("ZDTM_USERNS")) flags |= CLONE_NEWUSER; @@ -521,4 +516,3 @@ void ns_create(int argc, char **argv) exit(0); } - diff --git a/test/zdtm/lib/parseargs.c b/test/zdtm/lib/parseargs.c index d8aa4ed63..156f5a46c 100644 --- a/test/zdtm/lib/parseargs.c +++ b/test/zdtm/lib/parseargs.c @@ -20,17 +20,12 @@ void __push_opt(struct long_opt *opt) int parse_opt_bool(char *param, void *arg) { - if (param == NULL || - !strcmp(param, "on") || - !strcmp(param, "yes") || - !strcmp(param, "true")) { - * (int *) arg = 1; + if (param == NULL || !strcmp(param, "on") || !strcmp(param, "yes") || !strcmp(param, "true")) { + *(int *)arg = 1; return 0; } - if (!strcmp(param, "off") || - !strcmp(param, "no") || - !strcmp(param, "false")) { - * (int *) arg = 0; + if (!strcmp(param, "off") || !strcmp(param, "no") || !strcmp(param, "false")) { + *(int *)arg = 0; return 0; } return -EINVAL; @@ -41,7 +36,7 @@ int parse_opt_int(char *param, void *arg) char *tail; if (param == NULL || param[0] == '\0') return -EINVAL; - * (int *) arg = strtol(param, &tail, 0); + *(int *)arg = strtol(param, &tail, 0); if (tail[0] != '\0') return -EINVAL; return 0; @@ -52,7 +47,7 @@ int parse_opt_uint(char *param, void *arg) char *tail; if (param == NULL || param[0] == '\0') return -EINVAL; - * (unsigned int *) arg = strtoul(param, &tail, 0); + *(unsigned int *)arg = strtoul(param, &tail, 0); if (tail[0] != '\0') return -EINVAL; return 0; @@ -63,7 +58,7 @@ int parse_opt_long(char *param, void *arg) char *tail; if (param == NULL || param[0] == '\0') return -EINVAL; - * (long *) arg = strtol(param, &tail, 0); + *(long *)arg = strtol(param, &tail, 0); if (tail[0] != '\0') return -EINVAL; return 0; @@ -74,7 +69,7 @@ int parse_opt_ulong(char *param, void *arg) char *tail; if (param == NULL || param[0] == '\0') return -EINVAL; - * (unsigned long *) arg = strtoul(param, &tail, 0); + *(unsigned long *)arg = strtoul(param, &tail, 0); if (tail[0] != '\0') return -EINVAL; return 0; @@ -84,7 +79,7 @@ int parse_opt_string(char *param, void *arg) { if (param == NULL || param[0] == '\0') return -EINVAL; - * (char **) arg = param; + *(char **)arg = param; return 0; } @@ -97,8 +92,7 @@ static void printopt(const struct long_opt *opt) cbracket = "]"; } - fprintf(stderr, " %s--%s=%s%s\t%s\n", - obracket, opt->name, opt->type, cbracket, opt->doc); + fprintf(stderr, " %s--%s=%s%s\t%s\n", obracket, opt->name, opt->type, cbracket, opt->doc); } static void helpexit(void) @@ -113,8 +107,8 @@ static void helpexit(void) exit(1); } -const char __attribute__((weak)) *test_doc; -const char __attribute__((weak)) *test_author; +const char __attribute__((weak)) * test_doc; +const char __attribute__((weak)) * test_author; static void prdoc(void) { @@ -124,7 +118,7 @@ static void prdoc(void) fprintf(stderr, "Author: %s\n", test_author); } -void parseargs(int argc, char ** argv) +void parseargs(int argc, char **argv) { int i; struct long_opt *opt; @@ -148,10 +142,9 @@ void parseargs(int argc, char ** argv) if (opt->parse_opt(value, opt->value)) { fprintf(stderr, "%s: failed to parse\n", argv[i]); helpexit(); - } - else + } else /* -1 marks fulfilled requirement */ - opt->is_required = - opt->is_required; + opt->is_required = -opt->is_required; break; } diff --git a/test/zdtm/lib/tcp.c b/test/zdtm/lib/tcp.c index 623994bf8..cbd87521b 100644 --- a/test/zdtm/lib/tcp.c +++ b/test/zdtm/lib/tcp.c @@ -1,6 +1,6 @@ #include <string.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include "zdtmtst.h" @@ -25,11 +25,11 @@ int tcp_init_server_with_opts(int family, int *port, struct zdtm_tcp_opts *opts) int sock; int yes = 1, ret; - memset(&addr,0,sizeof(addr)); + memset(&addr, 0, sizeof(addr)); if (family == AF_INET) { addr.v4.sin_family = family; inet_pton(family, "0.0.0.0", &(addr.v4.sin_addr)); - } else if (family == AF_INET6){ + } else if (family == AF_INET6) { addr.v6.sin6_family = family; inet_pton(family, "::0", &(addr.v6.sin6_addr)); } else @@ -41,14 +41,12 @@ int tcp_init_server_with_opts(int family, int *port, struct zdtm_tcp_opts *opts) return -1; } - if (opts->reuseport && - setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(int)) == -1) { + if (opts->reuseport && setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(int)) == -1) { pr_perror("setsockopt(SO_REUSEPORT) failed"); return -1; } - if (opts->reuseaddr && - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) { + if (opts->reuseaddr && setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { pr_perror("setsockopt(SO_REUSEATTR) failed"); return -1; } @@ -59,7 +57,7 @@ int tcp_init_server_with_opts(int family, int *port, struct zdtm_tcp_opts *opts) else if (family == AF_INET6) addr.v6.sin6_port = htons(*port); - ret = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); + ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); /* criu doesn't restore sock opts, so we need this hack */ if (ret == -1 && errno == EADDRINUSE) { @@ -88,10 +86,10 @@ int tcp_accept_server(int sock) int sock2; socklen_t addrlen; #ifdef DEBUG - test_msg ("Waiting for connection..........\n"); + test_msg("Waiting for connection..........\n"); #endif addrlen = sizeof(maddr); - sock2 = accept(sock,(struct sockaddr *) &maddr, &addrlen); + sock2 = accept(sock, (struct sockaddr *)&maddr, &addrlen); if (sock2 == -1) { pr_perror("accept() failed"); @@ -99,7 +97,7 @@ int tcp_accept_server(int sock) } #ifdef DEBUG - test_msg ("Connection!!\n"); + test_msg("Connection!!\n"); #endif return sock2; } @@ -123,15 +121,15 @@ int tcp_init_client_with_fd(int sock, int family, char *servIP, unsigned short s /* Construct the server address structure */ memset(&servAddr, 0, sizeof(servAddr)); if (family == AF_INET) { - servAddr.v4.sin_family = AF_INET; - servAddr.v4.sin_port = htons(servPort); + servAddr.v4.sin_family = AF_INET; + servAddr.v4.sin_port = htons(servPort); inet_pton(AF_INET, servIP, &servAddr.v4.sin_addr); } else { - servAddr.v6.sin6_family = AF_INET6; - servAddr.v6.sin6_port = htons(servPort); + servAddr.v6.sin6_family = AF_INET6; + servAddr.v6.sin6_port = htons(servPort); inet_pton(AF_INET6, servIP, &servAddr.v6.sin6_addr); } - if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) { + if (connect(sock, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) { pr_perror("can't connect to server"); return -1; } diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c index e848091c1..81da81eba 100644 --- a/test/zdtm/lib/test.c +++ b/test/zdtm/lib/test.c @@ -22,7 +22,7 @@ futex_t sig_received; static struct { futex_t stage; -} *test_shared_state; +} * test_shared_state; enum { TEST_INIT_STAGE = 0, @@ -74,8 +74,7 @@ static void test_fini(void) static void setup_outfile(void) { if (!access(outfile, F_OK) || errno != ENOENT) { - fprintf(stderr, "Output file %s appears to exist, aborting\n", - outfile); + fprintf(stderr, "Output file %s appears to exist, aborting\n", outfile); exit(1); } @@ -214,8 +213,8 @@ void test_init(int argc, char **argv) pid_t pid; char *val; struct sigaction sa = { - .sa_handler = sig_hand, - .sa_flags = SA_RESTART, + .sa_handler = sig_hand, + .sa_flags = SA_RESTART, }; sigemptyset(&sa.sa_mask); @@ -302,7 +301,7 @@ void test_init(int argc, char **argv) } parent = 1; - if (pid) { /* parent will exit when the child is ready */ + if (pid) { /* parent will exit when the child is ready */ futex_wait_while(&test_shared_state->stage, TEST_INIT_STAGE); if (futex_get(&test_shared_state->stage) == TEST_FAIL_STAGE) { @@ -343,7 +342,7 @@ void test_init(int argc, char **argv) exit(1); } - srand48(time(NULL)); /* just in case we need it */ + srand48(time(NULL)); /* just in case we need it */ } void test_daemon(void) @@ -398,12 +397,11 @@ int test_wait_pre_dump_ack(void) return 0; } -pid_t sys_clone_unified(unsigned long flags, void *child_stack, void *parent_tid, - void *child_tid, unsigned long newtls) +pid_t sys_clone_unified(unsigned long flags, void *child_stack, void *parent_tid, void *child_tid, unsigned long newtls) { #ifdef __x86_64__ return (pid_t)syscall(__NR_clone, flags, child_stack, parent_tid, child_tid, newtls); -#elif (__i386__ || __arm__ || __aarch64__ ||__powerpc64__ || __mips__) +#elif (__i386__ || __arm__ || __aarch64__ || __powerpc64__ || __mips__) return (pid_t)syscall(__NR_clone, flags, child_stack, parent_tid, newtls, child_tid); #elif __s390x__ return (pid_t)syscall(__NR_clone, child_stack, flags, parent_tid, child_tid, newtls); diff --git a/test/zdtm/lib/unix.c b/test/zdtm/lib/unix.c index c36846cad..49773dedd 100644 --- a/test/zdtm/lib/unix.c +++ b/test/zdtm/lib/unix.c @@ -16,4 +16,3 @@ int unix_fill_sock_name(struct sockaddr_un *name, char *relFilename) ssprintf(name->sun_path, "%s/%s", cwd, relFilename); return 0; } - diff --git a/test/zdtm/static/aio00.c b/test/zdtm/static/aio00.c index 93ca7aabb..7e7b9978d 100644 --- a/test/zdtm/static/aio00.c +++ b/test/zdtm/static/aio00.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that plain io_setup works"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that plain io_setup works"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/aio01.c b/test/zdtm/static/aio01.c index fda7572a1..ed45192b9 100644 --- a/test/zdtm/static/aio01.c +++ b/test/zdtm/static/aio01.c @@ -10,20 +10,20 @@ #include "zdtmtst.h" -const char *test_doc = "Check head and tail restore correct"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; +const char *test_doc = "Check head and tail restore correct"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; struct aio_ring { - unsigned id; /* kernel internal index number */ - unsigned nr; /* number of io_events */ - unsigned head; /* Written to by userland or under ring_lock + unsigned id; /* kernel internal index number */ + unsigned nr; /* number of io_events */ + unsigned head; /* Written to by userland or under ring_lock * mutex by aio_read_events_ring(). */ - unsigned tail; - unsigned magic; - unsigned compat_features; - unsigned incompat_features; - unsigned header_length; /* size of aio_ring */ - struct io_event io_events[0]; + unsigned tail; + unsigned magic; + unsigned compat_features; + unsigned incompat_features; + unsigned header_length; /* size of aio_ring */ + struct io_event io_events[0]; }; /* 128 bytes + ring size */ int main(int argc, char **argv) diff --git a/test/zdtm/static/apparmor.c b/test/zdtm/static/apparmor.c index a06589815..713ffaa46 100644 --- a/test/zdtm/static/apparmor.c +++ b/test/zdtm/static/apparmor.c @@ -10,8 +10,8 @@ #include <signal.h> #include "zdtmtst.h" -const char *test_doc = "Check that an apparmor profile is restored"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that an apparmor profile is restored"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #define PROFILE "criu_test" diff --git a/test/zdtm/static/arm-neon00.c b/test/zdtm/static/arm-neon00.c index c58218a11..43e1d4ca3 100644 --- a/test/zdtm/static/arm-neon00.c +++ b/test/zdtm/static/arm-neon00.c @@ -3,14 +3,13 @@ #include "zdtmtst.h" -const char *test_doc = "Initialize VFP registers before a migration,\n" - "check the VFP state is the same after a restore."; -const char *test_author = "Alexander Karatshov <alekskartashov@parallels.com>"; - +const char *test_doc = "Initialize VFP registers before a migration,\n" + "check the VFP state is the same after a restore."; +const char *test_author = "Alexander Karatshov <alekskartashov@parallels.com>"; #ifdef __arm__ -int main(int argc, char ** argv) +int main(int argc, char **argv) { int a, b, c, y1, y2; @@ -19,18 +18,17 @@ int main(int argc, char ** argv) a = rand() % 100; b = rand() % 100; c = rand() % 100; - y1 = a + b*c; + y1 = a + b * c; test_init(argc, argv); - asm ( - ".fpu neon \n" - "vmov.32 d0[0], %0 \n" - "vmov.32 d1[0], %1 \n" - "vmov.32 d2[0], %2 \n" - ".fpu softvfp \n" - : : "r"(a), "r"(b), "r"(c) - ); + asm(".fpu neon \n" + "vmov.32 d0[0], %0 \n" + "vmov.32 d1[0], %1 \n" + "vmov.32 d2[0], %2 \n" + ".fpu softvfp \n" + : + : "r"(a), "r"(b), "r"(c)); test_msg("Preparing to wait...\n"); @@ -39,14 +37,12 @@ int main(int argc, char ** argv) test_msg("Restored.\n"); - asm ( - ".fpu neon \n" - "vmul.I32 d3, d1, d2 \n" - "vadd.I32 d4, d0, d3 \n" - "vmov.32 %0, d4[0] \n" - ".fpu softvfp \n" - : "=r"(y2) - ); + asm(".fpu neon \n" + "vmul.I32 d3, d1, d2 \n" + "vadd.I32 d4, d0, d3 \n" + "vmov.32 %0, d4[0] \n" + ".fpu softvfp \n" + : "=r"(y2)); if (y1 != y2) fail("VFP restoration failed: result = %d, expected = %d (a = %d, b = %d, c = %d)", y2, y1, a, b, c); diff --git a/test/zdtm/static/autofs.c b/test/zdtm/static/autofs.c index 6d261677b..2d6078627 100644 --- a/test/zdtm/static/autofs.c +++ b/test/zdtm/static/autofs.c @@ -20,14 +20,14 @@ #include "auto_dev-ioctl.h" const char *test_doc = "Autofs (v5) migration test"; -const char *test_author = "Stanislav Kinsburskii <stanislav.kinsburskiy@virtuozzo.com>"; +const char *test_author = "Stanislav Kinsburskii <stanislav.kinsburskiy@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define AUTOFS_DEV "/dev/autofs" +#define AUTOFS_DEV "/dev/autofs" -#define INDIRECT_MNT_DIR "mnt" +#define INDIRECT_MNT_DIR "mnt" int autofs_dev; task_waiter_t t; @@ -53,7 +53,7 @@ static char *xvstrcat(char *str, const char *fmt, va_list args) if (ret >= delta) { /* NOTE: vsnprintf returns the amount of bytes * * to allocate. */ - delta = ret +1; + delta = ret + 1; str = new; ret = 0; } @@ -187,53 +187,45 @@ static int check_fd(struct autofs_params *p) if (st.st_dev != p->fd_stat.st_dev) { skip("%s: st_dev differs: %llu != %llu " - "(waiting for \"device namespaces\")", p->mountpoint, - (long long unsigned)st.st_dev, - (long long unsigned)p->fd_stat.st_dev); -// ret++; + "(waiting for \"device namespaces\")", + p->mountpoint, (long long unsigned)st.st_dev, (long long unsigned)p->fd_stat.st_dev); + // ret++; } if (st.st_mode != p->fd_stat.st_mode) { - pr_err("%s: st_mode differs: 0%o != 0%o\n", p->mountpoint, - st.st_mode, p->fd_stat.st_mode); + pr_err("%s: st_mode differs: 0%o != 0%o\n", p->mountpoint, st.st_mode, p->fd_stat.st_mode); ret++; } if (st.st_nlink != p->fd_stat.st_nlink) { - pr_err("%s: st_nlink differs: %ld != %ld\n", p->mountpoint, - (long)st.st_nlink, (long)p->fd_stat.st_nlink); + pr_err("%s: st_nlink differs: %ld != %ld\n", p->mountpoint, (long)st.st_nlink, + (long)p->fd_stat.st_nlink); ret++; } if (st.st_uid != p->fd_stat.st_uid) { - pr_err("%s: st_uid differs: %u != %u\n", p->mountpoint, - st.st_uid, p->fd_stat.st_uid); + pr_err("%s: st_uid differs: %u != %u\n", p->mountpoint, st.st_uid, p->fd_stat.st_uid); ret++; } if (st.st_gid != p->fd_stat.st_gid) { - pr_err("%s: st_gid differs: %u != %u\n", p->mountpoint, - st.st_gid, p->fd_stat.st_gid); + pr_err("%s: st_gid differs: %u != %u\n", p->mountpoint, st.st_gid, p->fd_stat.st_gid); ret++; } if (st.st_rdev != p->fd_stat.st_rdev) { - pr_err("%s: st_rdev differs: %lld != %lld\n", p->mountpoint, - (long long)st.st_rdev, - (long long)p->fd_stat.st_rdev); + pr_err("%s: st_rdev differs: %lld != %lld\n", p->mountpoint, (long long)st.st_rdev, + (long long)p->fd_stat.st_rdev); ret++; } if (st.st_size != p->fd_stat.st_size) { - pr_err("%s: st_size differs: %lld != %lld\n", p->mountpoint, - (long long)st.st_size, - (long long)p->fd_stat.st_size); + pr_err("%s: st_size differs: %lld != %lld\n", p->mountpoint, (long long)st.st_size, + (long long)p->fd_stat.st_size); ret++; } if (st.st_blksize != p->fd_stat.st_blksize) { - pr_err("%s: st_blksize differs %lld != %lld:\n", p->mountpoint, - (long long)st.st_blksize, - (long long)p->fd_stat.st_blksize); + pr_err("%s: st_blksize differs %lld != %lld:\n", p->mountpoint, (long long)st.st_blksize, + (long long)p->fd_stat.st_blksize); ret++; } if (st.st_blocks != p->fd_stat.st_blocks) { - pr_err("%s: st_blocks differs: %lld != %lld\n", p->mountpoint, - (long long)st.st_blocks, - (long long)p->fd_stat.st_blocks); + pr_err("%s: st_blocks differs: %lld != %lld\n", p->mountpoint, (long long)st.st_blocks, + (long long)p->fd_stat.st_blocks); ret++; } @@ -247,8 +239,7 @@ static int check_automount(struct autofs_params *p) err = check_fd(p); if (err) { - pr_err("%s: opened file descriptor wasn't migrated properly\n", - p->mountpoint); + pr_err("%s: opened file descriptor wasn't migrated properly\n", p->mountpoint); return err; } @@ -283,8 +274,7 @@ static int check_automount(struct autofs_params *p) } if (close(p->fd)) { - pr_perror("%s: failed to close fd %d", mountpoint, - p->fd); + pr_perror("%s: failed to close fd %d", mountpoint, p->fd); return -errno; } @@ -335,11 +325,10 @@ out: return ret; } -static int autofs_report_result(int token, int devid, const char *mountpoint, - int result) +static int autofs_report_result(int token, int devid, const char *mountpoint, int result) { int ioctl_fd; - struct autofs_dev_ioctl param; + struct autofs_dev_ioctl param; int err; ioctl_fd = autofs_open_mount(devid, mountpoint); @@ -378,28 +367,24 @@ static int mount_tmpfs(const char *mountpoint) return 0; if (mount("autofs_test", mountpoint, "tmpfs", 0, "size=1M") < 0) { - pr_perror("failed to mount tmpfs to %s", - mountpoint); + pr_perror("failed to mount tmpfs to %s", mountpoint); return -errno; } return 0; } -static int autofs_mount_direct(const char *mountpoint, - const struct autofs_v5_packet *packet) +static int autofs_mount_direct(const char *mountpoint, const struct autofs_v5_packet *packet) { int err; const char *direct_mnt = mountpoint; err = mount_tmpfs(direct_mnt); if (err) - pr_err("%d: failed to mount direct autofs mountpoint\n", - getpid()); + pr_err("%d: failed to mount direct autofs mountpoint\n", getpid()); return err; } -static int autofs_mount_indirect(const char *mountpoint, - const struct autofs_v5_packet *packet) +static int autofs_mount_indirect(const char *mountpoint, const struct autofs_v5_packet *packet) { char *indirect_mnt; int err; @@ -417,40 +402,34 @@ static int autofs_mount_indirect(const char *mountpoint, err = mount_tmpfs(indirect_mnt); if (err) - pr_err("%d: failed to mount indirect autofs mountpoint\n", - getpid()); + pr_err("%d: failed to mount indirect autofs mountpoint\n", getpid()); return err; - } -static int automountd_serve(const char *mountpoint, struct autofs_params *p, - const union autofs_v5_packet_union *packet) +static int automountd_serve(const char *mountpoint, struct autofs_params *p, const union autofs_v5_packet_union *packet) { const struct autofs_v5_packet *v5_packet = &packet->v5_packet; int err, res; switch (packet->hdr.type) { - case autofs_ptype_missing_indirect: - res = autofs_mount_indirect(mountpoint, v5_packet); - break; - case autofs_ptype_missing_direct: - res = autofs_mount_direct(mountpoint, v5_packet); - break; - case autofs_ptype_expire_indirect: - pr_err("%d: expire request for indirect mount %s?\n", - getpid(), v5_packet->name); - return -EINVAL; - case autofs_ptype_expire_direct: - pr_err("%d: expire request for direct mount?\n", - getpid()); - return -EINVAL; - default: - pr_err("unknown request type: %d\n", packet->hdr.type); - return -EINVAL; + case autofs_ptype_missing_indirect: + res = autofs_mount_indirect(mountpoint, v5_packet); + break; + case autofs_ptype_missing_direct: + res = autofs_mount_direct(mountpoint, v5_packet); + break; + case autofs_ptype_expire_indirect: + pr_err("%d: expire request for indirect mount %s?\n", getpid(), v5_packet->name); + return -EINVAL; + case autofs_ptype_expire_direct: + pr_err("%d: expire request for direct mount?\n", getpid()); + return -EINVAL; + default: + pr_err("unknown request type: %d\n", packet->hdr.type); + return -EINVAL; } - err = autofs_report_result(v5_packet->wait_queue_token, v5_packet->dev, - mountpoint, res); + err = autofs_report_result(v5_packet->wait_queue_token, v5_packet->dev, mountpoint, res); if (err) return err; return res; @@ -481,8 +460,7 @@ static int automountd_loop(int pipe, const char *mountpoint, struct autofs_param continue; } if (bytes != psize) { - pr_err("read less than expected: %zd < %zd\n", - bytes, psize); + pr_err("read less than expected: %zd < %zd\n", bytes, psize); return -EINVAL; } err = automountd_serve(mountpoint, param, packet); @@ -522,22 +500,21 @@ static int automountd(struct autofs_params *p, int control_fd) } switch (p->type) { - case AUTOFS_TYPE_DIRECT: - type = "direct"; - break; - case AUTOFS_TYPE_INDIRECT: - type = "indirect"; - break; - case AUTOFS_TYPE_OFFSET: - type = "offset"; - break; - default: - pr_err("unknown autofs type: %d\n", p->type); - return -EINVAL; + case AUTOFS_TYPE_DIRECT: + type = "direct"; + break; + case AUTOFS_TYPE_INDIRECT: + type = "indirect"; + break; + case AUTOFS_TYPE_OFFSET: + type = "offset"; + break; + default: + pr_err("unknown autofs type: %d\n", p->type); + return -EINVAL; } - options = xsprintf("fd=%d,pgrp=%d,minproto=5,maxproto=5,%s", - pipes[1], getpgrp(), type); + options = xsprintf("fd=%d,pgrp=%d,minproto=5,maxproto=5,%s", pipes[1], getpgrp(), type); if (!options) { pr_err("failed to allocate autofs options\n"); goto err; @@ -550,8 +527,7 @@ static int automountd(struct autofs_params *p, int control_fd) } if (mount("autofs_test", autofs_path, "autofs", 0, options) < 0) { - pr_perror("failed to mount autofs with options \"%s\"", - options); + pr_perror("failed to mount autofs with options \"%s\"", options); goto err; } @@ -589,12 +565,12 @@ static int start_automounter(struct autofs_params *p) pid = test_fork(); switch (pid) { - case -1: - pr_perror("failed to fork"); - return -1; - case 0: - close(control_fd[0]); - exit(automountd(p, control_fd[1])); + case -1: + pr_perror("failed to fork"); + return -1; + case 0: + close(control_fd[0]); + exit(automountd(p, control_fd[1])); } task_waiter_wait4(&t, pid); p->pid = pid; @@ -608,8 +584,7 @@ static int start_automounter(struct autofs_params *p) return -errno; } if (bytes != sizeof(ret)) { - pr_err("received less than expected: %zu. Child %d died?\n", - bytes, p->pid); + pr_err("received less than expected: %zu. Child %d died?\n", bytes, p->pid); return -EINVAL; } return ret; @@ -657,8 +632,7 @@ static int reap_catatonic(struct autofs_params *p) err = umount_fs(mountpoint, AUTOFS_SUPER_MAGIC); if (!err) { if (rmdir(mountpoint) < 0) { - skip("failed to remove %s directory: %s\n", mountpoint, - strerror(errno)); + skip("failed to remove %s directory: %s\n", mountpoint, strerror(errno)); err = -errno; } } @@ -732,40 +706,34 @@ static int create_catatonic(struct autofs_params *p) static void test_exit(void) { if (rmdir(dirname) < 0) - skip("failed to remove %s directory: %s\n", dirname, - strerror(errno)); + skip("failed to remove %s directory: %s\n", dirname, strerror(errno)); } -typedef enum { - AUTOFS_START, - AUTOFS_SETUP, - AUTOFS_CHECK, - AUTOFS_STOP -} autfs_test_action; +typedef enum { AUTOFS_START, AUTOFS_SETUP, AUTOFS_CHECK, AUTOFS_STOP } autfs_test_action; static int test_action(autfs_test_action act, struct autofs_params *p) { int ret = 0; - while(p->mountpoint) { - int (*action)(struct autofs_params *p); + while (p->mountpoint) { + int (*action)(struct autofs_params * p); switch (act) { - case AUTOFS_START: - action = p->create; - break; - case AUTOFS_SETUP: - action = p->setup; - break; - case AUTOFS_CHECK: - action = p->check; - break; - case AUTOFS_STOP: - action = p->reap; - break; - default: - pr_err("unknown action: %d\n", act); - return -1; + case AUTOFS_START: + action = p->create; + break; + case AUTOFS_SETUP: + action = p->setup; + break; + case AUTOFS_CHECK: + action = p->check; + break; + case AUTOFS_STOP: + action = p->reap; + break; + default: + pr_err("unknown action: %d\n", act); + return -1; } if (action && action(p)) @@ -793,8 +761,7 @@ static void direct_exit(void) return; if (rmdir(mountpoint) < 0) - skip("failed to remove %s directory: %s\n", mountpoint, - strerror(errno)); + skip("failed to remove %s directory: %s\n", mountpoint, strerror(errno)); } static void indirect_exit(void) @@ -822,8 +789,7 @@ static void indirect_exit(void) return; if (rmdir(mountpoint) < 0) - skip("failed to remove %s directory: %s\n", mountpoint, - strerror(errno)); + skip("failed to remove %s directory: %s\n", mountpoint, strerror(errno)); } enum autofs_tests { @@ -940,4 +906,3 @@ err: pass(); return 0; } - diff --git a/test/zdtm/static/bind-mount.c b/test/zdtm/static/bind-mount.c index 06c5cf173..fed51c59b 100644 --- a/test/zdtm/static/bind-mount.c +++ b/test/zdtm/static/bind-mount.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check bind-mounts"; -const char *test_author = "Pavel Emelianov <avagin@parallels.com>"; +const char *test_doc = "Check bind-mounts"; +const char *test_author = "Pavel Emelianov <avagin@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/binfmt_misc.c b/test/zdtm/static/binfmt_misc.c index 553cc1795..036eb9fe9 100644 --- a/test/zdtm/static/binfmt_misc.c +++ b/test/zdtm/static/binfmt_misc.c @@ -9,13 +9,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check that binfmt_misc entries remain registered"; -const char *test_author = "Kirill Tkhai <ktkhai@odin.com"; +const char *test_doc = "Check that binfmt_misc entries remain registered"; +const char *test_author = "Kirill Tkhai <ktkhai@odin.com"; -#define MAX_REG_STR 256 -#define MAX_MAGIC 16 +#define MAX_REG_STR 256 +#define MAX_MAGIC 16 #define MAX_MAGIC_OFFSET 128 /* Max magic+offset */ -#define MAX_EXTENSION 128 +#define MAX_EXTENSION 128 char *dirname = "binfmt_misc.dir"; TEST_OPTION(dirname, string, "binfmt_misc mount directory name", 1); @@ -31,7 +31,7 @@ void create_magic_pattern(char *buf, const char *name) int i, magic, mask, offset; magic = rand() % (MAX_MAGIC + 1); - mask = (rand() % 2) ? magic : 0; + mask = (rand() % 2) ? magic : 0; offset = MAX_MAGIC_OFFSET - magic; offset = rand() % (offset + 1); @@ -83,7 +83,7 @@ int dump_content(const char *path, char **dump) return -1; } - len = read(fd, p, PAGE_SIZE-1); + len = read(fd, p, PAGE_SIZE - 1); close(fd); if (len <= 0) { fail("read"); @@ -98,7 +98,7 @@ int dump_content(const char *path, char **dump) int main(int argc, char **argv) { char buf[MAX_REG_STR + 1]; - char path[PATH_MAX*2 + 1]; + char path[PATH_MAX * 2 + 1]; char *dump[2]; int i, fd, len; @@ -118,7 +118,10 @@ int main(int argc, char **argv) } /* Register binfmt_entries */ - sprintf(path, "%s/" "register", dirname); + sprintf(path, + "%s/" + "register", + dirname); fd = open(path, O_WRONLY); if (fd < 0) { fail("open"); @@ -152,7 +155,7 @@ int main(int argc, char **argv) close(fd); /* Dump files content */ - for (i = 0; i < 2; i ++) { + for (i = 0; i < 2; i++) { sprintf(path, "%s/%s", dirname, NAME[i]); if (dump_content(path, &dump[i])) exit(1); @@ -162,7 +165,7 @@ int main(int argc, char **argv) test_waitsig(); /* Check */ - for (i = 0; i < 2; i ++) { + for (i = 0; i < 2; i++) { char *tmp; sprintf(path, "%s/%s", dirname, NAME[i]); diff --git a/test/zdtm/static/bpf_array.c b/test/zdtm/static/bpf_array.c index ca7796bdf..ec74a3e3b 100644 --- a/test/zdtm/static/bpf_array.c +++ b/test/zdtm/static/bpf_array.c @@ -5,17 +5,14 @@ #include "zdtmtst.h" #include "bpfmap_zdtm.h" -const char *test_doc = "Check that data and meta-data for BPF_MAP_TYPE_ARRAY" - "is correctly restored"; -const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>"; +const char *test_doc = "Check that data and meta-data for BPF_MAP_TYPE_ARRAY" + "is correctly restored"; +const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>"; static int map_batch_update(int map_fd, uint32_t max_entries, int *keys, int *values) { int i, ret; - DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, - .elem_flags = 0, - .flags = 0, - ); + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, ); for (i = 0; i < max_entries; i++) { keys[i] = i; @@ -72,17 +69,11 @@ int main(int argc, char **argv) .max_entries = max_entries, .map_flags = BPF_F_NUMA_NODE, }; - DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, - .elem_flags = 0, - .flags = 0, - ); - - keys = mmap(NULL, max_entries * sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); - values = mmap(NULL, max_entries * sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); - visited = mmap(NULL, max_entries * sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, ); + + keys = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); + values = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); + visited = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if ((keys == MAP_FAILED) || (values == MAP_FAILED) || (visited == MAP_FAILED)) { pr_perror("Can't mmap()"); diff --git a/test/zdtm/static/bpf_hash.c b/test/zdtm/static/bpf_hash.c index 4054140b8..612f69665 100644 --- a/test/zdtm/static/bpf_hash.c +++ b/test/zdtm/static/bpf_hash.c @@ -5,17 +5,14 @@ #include "zdtmtst.h" #include "bpfmap_zdtm.h" -const char *test_doc = "Check that data and meta-data for BPF_MAP_TYPE_HASH" - "is correctly restored"; -const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>"; +const char *test_doc = "Check that data and meta-data for BPF_MAP_TYPE_HASH" + "is correctly restored"; +const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>"; static int map_batch_update(int map_fd, uint32_t max_entries, int *keys, int *values) { int ret; - DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, - .elem_flags = 0, - .flags = 0, - ); + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, ); for (int i = 0; i < max_entries; i++) { keys[i] = i + 1; @@ -34,7 +31,6 @@ static int map_batch_verify(int *visited, uint32_t max_entries, int *keys, int * { memset(visited, 0, max_entries * sizeof(*visited)); for (int i = 0; i < max_entries; i++) { - if (keys[i] + 1 != values[i]) { pr_err("Key/value checking error: i=%d, key=%d, value=%d\n", i, keys[i], values[i]); return -1; @@ -71,17 +67,11 @@ int main(int argc, char **argv) .max_entries = max_entries, .map_flags = BPF_F_NO_PREALLOC | BPF_F_NUMA_NODE, }; - DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, - .elem_flags = 0, - .flags = 0, - ); - - keys = mmap(NULL, max_entries * sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); - values = mmap(NULL, max_entries * sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); - visited = mmap(NULL, max_entries * sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); + DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, ); + + keys = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); + values = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); + visited = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if ((keys == MAP_FAILED) || (values == MAP_FAILED) || (visited == MAP_FAILED)) { pr_perror("Can't mmap()"); diff --git a/test/zdtm/static/bridge.c b/test/zdtm/static/bridge.c index 983c262af..03084a296 100644 --- a/test/zdtm/static/bridge.c +++ b/test/zdtm/static/bridge.c @@ -12,8 +12,8 @@ #include <net/if.h> #include "zdtmtst.h" -const char *test_doc = "check that empty bridges are c/r'd correctly"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "check that empty bridges are c/r'd correctly"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #define BRIDGE_NAME "zdtmbr0" @@ -72,7 +72,7 @@ int main(int argc, char **argv) } addr.sin6_scope_id = if_nametoindex(BRIDGE_NAME); - if (bind(sk, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + if (bind(sk, (struct sockaddr *)&addr, sizeof(addr)) < 0) { fail("can't bind"); goto out; } diff --git a/test/zdtm/static/busyloop00.c b/test/zdtm/static/busyloop00.c index e9a065cf7..399516933 100644 --- a/test/zdtm/static/busyloop00.c +++ b/test/zdtm/static/busyloop00.c @@ -1,9 +1,9 @@ #include "zdtmtst.h" -const char *test_doc = "Run busy loop while migrating"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Run busy loop while migrating"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { test_init(argc, argv); diff --git a/test/zdtm/static/caps00.c b/test/zdtm/static/caps00.c index 7a256c08a..d652c7626 100644 --- a/test/zdtm/static/caps00.c +++ b/test/zdtm/static/caps00.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that aps are preserved"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that aps are preserved"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; struct cap_hdr { unsigned int version; @@ -15,15 +15,15 @@ struct cap_hdr { }; struct cap_data { - unsigned int eff; - unsigned int prm; - unsigned int inh; + unsigned int eff; + unsigned int prm; + unsigned int inh; }; -#define _LINUX_CAPABILITY_VERSION_3 0x20080522 -#define _LINUX_CAPABILITY_U32S_3 2 -#define CAP_CHOWN 0 -#define CAP_DAC_OVERRIDE 1 +#define _LINUX_CAPABILITY_VERSION_3 0x20080522 +#define _LINUX_CAPABILITY_U32S_3 2 +#define CAP_CHOWN 0 +#define CAP_DAC_OVERRIDE 1 int capget(struct cap_hdr *hdrp, struct cap_data *datap); int capset(struct cap_hdr *hdrp, const struct cap_data *datap); @@ -131,12 +131,12 @@ int main(int argc, char **argv) } if (prctl(PR_CAPBSET_READ, CAP_SETPCAP, 0, 0, 0) != 0) { - res='5'; + res = '5'; goto bad; } res = '0'; -bad: + bad: write(result_pipe[1], &res, 1); if (res != '0') { @@ -163,12 +163,10 @@ bad: else { read(result_pipe[0], data, sizeof(data)); read(result_pipe[0], data_2, sizeof(data_2)); - test_msg("{eff,prm,inh}[]={%08x,%08x,%08x}, {%08x,%08x,%08x}\n", - data[0].eff, data[0].prm, data[0].inh, - data[1].eff, data[1].prm, data[1].inh); - test_msg("{eff,prm,inh}[]={%08x,%08x,%08x}, {%08x,%08x,%08x}\n", - data_2[0].eff, data_2[0].prm, data_2[0].inh, - data_2[1].eff, data_2[1].prm, data_2[1].inh); + test_msg("{eff,prm,inh}[]={%08x,%08x,%08x}, {%08x,%08x,%08x}\n", data[0].eff, data[0].prm, data[0].inh, + data[1].eff, data[1].prm, data[1].inh); + test_msg("{eff,prm,inh}[]={%08x,%08x,%08x}, {%08x,%08x,%08x}\n", data_2[0].eff, data_2[0].prm, + data_2[0].inh, data_2[1].eff, data_2[1].prm, data_2[1].inh); fail("Fail: %c", res); } close(result_pipe[0]); diff --git a/test/zdtm/static/cgroup00.c b/test/zdtm/static/cgroup00.c index ee14d1fd3..2ed106094 100644 --- a/test/zdtm/static/cgroup00.c +++ b/test/zdtm/static/cgroup00.c @@ -7,14 +7,14 @@ #include <stdlib.h> #include "zdtmtst.h" -const char *test_doc = "Check that cgroups layout is preserved"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that cgroups layout is preserved"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); static const char *cgname = "zdtmtst"; -#define SUBNAME "subcg00" -#define SUBNAME2 SUBNAME"/subsubcg" +#define SUBNAME "subcg00" +#define SUBNAME2 SUBNAME "/subsubcg" static int cg_move(char *name) { diff --git a/test/zdtm/static/cgroup01.c b/test/zdtm/static/cgroup01.c index f0d00f209..bc8515264 100644 --- a/test/zdtm/static/cgroup01.c +++ b/test/zdtm/static/cgroup01.c @@ -6,8 +6,8 @@ #include <sys/mount.h> #include "zdtmtst.h" -const char *test_doc = "Check that empty cgroups are preserved"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that empty cgroups are preserved"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); diff --git a/test/zdtm/static/cgroup02.c b/test/zdtm/static/cgroup02.c index 67cc73d9e..6229a8a08 100644 --- a/test/zdtm/static/cgroup02.c +++ b/test/zdtm/static/cgroup02.c @@ -8,8 +8,8 @@ #include <sys/mount.h> #include "zdtmtst.h" -const char *test_doc = "Check that empty cgroups are preserved"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that empty cgroups are preserved"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); @@ -160,7 +160,6 @@ int main(int argc, char **argv) pass(); ret = 0; - out_close: fclose(cgf); out_umount: diff --git a/test/zdtm/static/cgroup03.c b/test/zdtm/static/cgroup03.c index 757f0c3b4..78b8b5bee 100644 --- a/test/zdtm/static/cgroup03.c +++ b/test/zdtm/static/cgroup03.c @@ -9,8 +9,8 @@ #include <limits.h> #include "zdtmtst.h" -const char *test_doc = "Check that global cgroup settings (+perms) are restored"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that global cgroup settings (+perms) are restored"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); @@ -137,7 +137,6 @@ int main(int argc, char **argv) if (chownmod(path, O_RDWR) < 0) goto out_umount; - sprintf(path, "%s/%s/test/cgroup.procs", dirname, cgname); if (chownmod(path, O_RDWR) < 0) goto out_umount; diff --git a/test/zdtm/static/cgroup04.c b/test/zdtm/static/cgroup04.c index 8ec0cff37..5a424be12 100644 --- a/test/zdtm/static/cgroup04.c +++ b/test/zdtm/static/cgroup04.c @@ -10,10 +10,10 @@ #include <limits.h> #include "zdtmtst.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -const char *test_doc = "Check that some cgroups properties in kernel controllers are preserved"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that some cgroups properties in kernel controllers are preserved"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); @@ -116,17 +116,8 @@ int main(int argc, char **argv) struct stat sb; char *dev_allow[] = { - "c *:* m", - "b *:* m", - "c 1:3 rwm", - "c 1:5 rwm", - "c 1:7 rwm", - "c 5:0 rwm", - "c 5:2 rwm", - "c 1:8 rwm", - "c 1:9 rwm", - "c 136:* rwm", - "c 10:229 rwm", + "c *:* m", "b *:* m", "c 1:3 rwm", "c 1:5 rwm", "c 1:7 rwm", "c 5:0 rwm", + "c 5:2 rwm", "c 1:8 rwm", "c 1:9 rwm", "c 136:* rwm", "c 10:229 rwm", }; test_init(argc, argv); diff --git a/test/zdtm/static/cgroup_ifpriomap.c b/test/zdtm/static/cgroup_ifpriomap.c index 24ed44f14..5f07d495b 100644 --- a/test/zdtm/static/cgroup_ifpriomap.c +++ b/test/zdtm/static/cgroup_ifpriomap.c @@ -10,20 +10,20 @@ #include "zdtmtst.h" -const char *test_doc = "Check preserving multiline cgroup controller's property net_prio/net_prio.ifpriomap"; -const char *test_author = "Dmitry Safonov <dsafonov@virtuozzo.com>"; +const char *test_doc = "Check preserving multiline cgroup controller's property net_prio/net_prio.ifpriomap"; +const char *test_author = "Dmitry Safonov <dsafonov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); static const char *cgname = "zdtmtst"; -#define BUF_SZ 1024 -#define PRIOMAPS_SZ 40 +#define BUF_SZ 1024 +#define PRIOMAPS_SZ 40 struct ifpriomap_t { - char *ifname; - uint32_t prio; + char *ifname; + uint32_t prio; }; struct ifpriomap_t maps[PRIOMAPS_SZ], new_maps[PRIOMAPS_SZ]; @@ -165,8 +165,7 @@ static int write_map(const char *path, struct ifpriomap_t *out, size_t out_sz) if (!p->ifname) break; - snprintf(buf, BUF_SZ, "%s %lu", - p->ifname, (unsigned long)p->prio); + snprintf(buf, BUF_SZ, "%s %lu", p->ifname, (unsigned long)p->prio); written = write(fd, buf, strlen(buf)); if (written < 0) { @@ -216,10 +215,8 @@ static int compare_maps(void) if (strcmp(a->ifname, b->ifname) == 0) { if (a->prio != b->prio) { - pr_err("`%s' prio: %lu != %lu\n", - a->ifname, - (unsigned long)a->prio, - (unsigned long)b->prio); + pr_err("`%s' prio: %lu != %lu\n", a->ifname, (unsigned long)a->prio, + (unsigned long)b->prio); return -1; } } @@ -296,11 +293,11 @@ static int get_controller_name(char **name) if (strstr(*name, "net_prio")) { /* erasing ':' delimiter */ - (*name)[len-1] = '\0'; + (*name)[len - 1] = '\0'; ret = 0; goto out_close; } - } while(1); + } while (1); /* self/cgroup has no mount for net_prio - try to map it */ *name = "net_prio"; @@ -328,8 +325,7 @@ int main(int argc, char **argv) if (mount_cg(controller_name) < 0) return -1; - sprintf(path, "%s/%s/%s/net_prio.ifpriomap", - dirname, controller_name, cgname); + sprintf(path, "%s/%s/%s/net_prio.ifpriomap", dirname, controller_name, cgname); if (read_map(path, maps, PRIOMAPS_SZ)) goto out_umount; diff --git a/test/zdtm/static/cgroup_stray.c b/test/zdtm/static/cgroup_stray.c index a068378ec..0c0ed93cf 100644 --- a/test/zdtm/static/cgroup_stray.c +++ b/test/zdtm/static/cgroup_stray.c @@ -13,8 +13,8 @@ #include <limits.h> #include "zdtmtst.h" -const char *test_doc = "Check that stray cgroups are c/r'd correctly"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that stray cgroups are c/r'd correctly"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname; TEST_OPTION(dirname, string, "cgroup directory name", 1); @@ -76,7 +76,8 @@ static int add_to_cg(const char *controller, const char *path) return 0; } -static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) { +static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) +{ char buf[2048]; FILE *f; bool ret = false; @@ -92,7 +93,7 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) { char *pos, *pid_controller, *pid_path; /* chop off trailing \n */ - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; /* skip hierarchy no. */ pos = strstr(buf, ":"); @@ -113,12 +114,13 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) { pos++; pid_path = pos; -test_msg("comparing %s and %s\n", controller, pid_controller); + test_msg("comparing %s and %s\n", controller, pid_controller); if (strcmp(controller, pid_controller)) continue; if (strcmp(path, pid_path)) - pr_err("task not in right cg for controller %s expected %s, got %s\n", controller, path, pid_path); + pr_err("task not in right cg for controller %s expected %s, got %s\n", controller, path, + pid_path); else ret = true; diff --git a/test/zdtm/static/cgroupns.c b/test/zdtm/static/cgroupns.c index 68b86b44b..8974f1607 100644 --- a/test/zdtm/static/cgroupns.c +++ b/test/zdtm/static/cgroupns.c @@ -14,11 +14,11 @@ #include "zdtmtst.h" #ifndef CLONE_NEWCGROUP -#define CLONE_NEWCGROUP 0x02000000 +#define CLONE_NEWCGROUP 0x02000000 #endif -const char *test_doc = "Check that cgroup NS is correctly handled."; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that cgroup NS is correctly handled."; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; /* we need dirname before test_init() here */ char *dirname = "cgroupns.test"; @@ -74,7 +74,8 @@ err_rd: return -1; } -static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) { +static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) +{ char buf[2048]; FILE *f; bool ret = false; @@ -90,7 +91,7 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) { char *pos, *pid_controller, *pid_path; /* chop off trailing \n */ - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; /* skip hierarchy no. */ pos = strstr(buf, ":"); @@ -115,7 +116,8 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) { continue; if (strcmp(path, pid_path)) - pr_err("task not in right cg for controller %s expected %s, got %s\n", controller, path, pid_path); + pr_err("task not in right cg for controller %s expected %s, got %s\n", controller, path, + pid_path); else ret = true; diff --git a/test/zdtm/static/child_opened_proc.c b/test/zdtm/static/child_opened_proc.c index 2a1fa8c79..2125cd264 100644 --- a/test/zdtm/static/child_opened_proc.c +++ b/test/zdtm/static/child_opened_proc.c @@ -9,10 +9,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check that tree prior to files opening"; -const char *test_author = "Stanislav Kinsbursky <skinsbursky@paralles.com"; +const char *test_doc = "Check that tree prior to files opening"; +const char *test_author = "Stanislav Kinsbursky <skinsbursky@paralles.com"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pid, err = 0; int proc_fd; diff --git a/test/zdtm/static/child_subreaper.c b/test/zdtm/static/child_subreaper.c index 4a27569fc..34d8c7411 100644 --- a/test/zdtm/static/child_subreaper.c +++ b/test/zdtm/static/child_subreaper.c @@ -3,8 +3,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that child subreaper attribute is restored"; -const char *test_author = "Michał Cłapiński <mclapinski@google.com>"; +const char *test_doc = "Check that child subreaper attribute is restored"; +const char *test_author = "Michał Cłapiński <mclapinski@google.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/child_subreaper_and_reparent.c b/test/zdtm/static/child_subreaper_and_reparent.c index e3955d3d9..ba03517ba 100644 --- a/test/zdtm/static/child_subreaper_and_reparent.c +++ b/test/zdtm/static/child_subreaper_and_reparent.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" #include "lock.h" -const char *test_doc = "Check that child subreaper does not affect reparenting"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check that child subreaper does not affect reparenting"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; enum { TEST_FORK, @@ -23,7 +23,7 @@ struct shared { futex_t fstate; int parent_before_cr; int parent_after_cr; -} *sh; +} * sh; int orphan(void) { diff --git a/test/zdtm/static/child_subreaper_existing_child.c b/test/zdtm/static/child_subreaper_existing_child.c index bc0047480..4805aa41d 100644 --- a/test/zdtm/static/child_subreaper_existing_child.c +++ b/test/zdtm/static/child_subreaper_existing_child.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" #include "lock.h" -const char *test_doc = "Check that property is restored for existing children"; -const char *test_author = "Michał Cłapiński <mclapinski@google.com>"; +const char *test_doc = "Check that property is restored for existing children"; +const char *test_author = "Michał Cłapiński <mclapinski@google.com>"; enum { TEST_FORK, @@ -21,8 +21,7 @@ enum { struct shared { futex_t fstate; int ppid_after_reparent; -} *sh; - +} * sh; int orphan(void) { diff --git a/test/zdtm/static/chroot-file.c b/test/zdtm/static/chroot-file.c index 94f584213..d8c0846c7 100644 --- a/test/zdtm/static/chroot-file.c +++ b/test/zdtm/static/chroot-file.c @@ -8,15 +8,15 @@ #include "zdtmtst.h" -const char *test_doc = "Check that out-of-root file survives"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that out-of-root file survives"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); char *filename; TEST_OPTION(filename, string, "file name", 1); -#define MSG "out-file-contents" +#define MSG "out-file-contents" static int make_file(char *name) { @@ -46,14 +46,14 @@ static int check_file(int fd) return 0; } -#define SUCCESS 0 -#define ERR_PIPES (char)0x7f +#define SUCCESS 0 +#define ERR_PIPES (char)0x7f /* bitmap of errors */ -#define ERR_IN_FILE 1 -#define ERR_ROOT 2 -#define ERR_DIR 4 -#define ERR_CHDIR 8 -#define ERR_ROOT2 4 +#define ERR_IN_FILE 1 +#define ERR_ROOT 2 +#define ERR_DIR 4 +#define ERR_CHDIR 8 +#define ERR_ROOT2 4 int main(int argc, char **argv) { diff --git a/test/zdtm/static/chroot.c b/test/zdtm/static/chroot.c index 439a8e7dc..861cbab3f 100644 --- a/test/zdtm/static/chroot.c +++ b/test/zdtm/static/chroot.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that root didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that root didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -17,7 +17,7 @@ char *filename; TEST_OPTION(filename, string, "file name", 1); static char *filepath; -#define MSG "chroot-file-contents" +#define MSG "chroot-file-contents" static int make_file(char *name) { @@ -47,14 +47,14 @@ static int check_file(int fd) return 0; } -#define SUCCESS 0 -#define ERR_PIPES (char)0x7f +#define SUCCESS 0 +#define ERR_PIPES (char)0x7f /* bitmap of errors */ -#define ERR_IN_FILE 1 -#define ERR_ROOT 2 -#define ERR_DIR 4 -#define ERR_OPEN 2 -#define ERR_FILE2 4 +#define ERR_IN_FILE 1 +#define ERR_ROOT 2 +#define ERR_DIR 4 +#define ERR_OPEN 2 +#define ERR_FILE2 4 int main(int argc, char **argv) { diff --git a/test/zdtm/static/clean_mntns.c b/test/zdtm/static/clean_mntns.c index 762894611..c529afd11 100644 --- a/test/zdtm/static/clean_mntns.c +++ b/test/zdtm/static/clean_mntns.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that clean mntns works"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that clean mntns works"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/clone_fs.c b/test/zdtm/static/clone_fs.c index e368aff99..78edf8095 100644 --- a/test/zdtm/static/clone_fs.c +++ b/test/zdtm/static/clone_fs.c @@ -4,7 +4,7 @@ #include "zdtmtst.h" -const char *test_doc = "Check that shared FS is migrated properly"; +const char *test_doc = "Check that shared FS is migrated properly"; const char *test_author = "Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>"; enum kcmp_type { @@ -26,28 +26,27 @@ static int kcmp(int type, pid_t pid1, pid_t pid2, unsigned long idx1, unsigned l ret = syscall(SYS_kcmp, pid1, pid2, type, idx1, idx2); switch (ret) { - case 0: - break; - case 1: - case 2: - test_msg("FS for pids %d and %d doesn't match: %d\n", pid1, pid2, ret); - break; - case -1: - pr_err("kcmp (type: %d, pid1: %d, pid2: %d, " - "idx1: %ld, idx2: %ld) failed: %d\n", - type, pid1, pid2, idx1, idx2, errno); - break; - default: - pr_err("kcmp (type: %d, pid1: %d, pid2: %d, " - "idx1: %ld, idx2: %ld) returned %d\n", - type, pid1, pid2, idx1, idx2, ret); - break; + case 0: + break; + case 1: + case 2: + test_msg("FS for pids %d and %d doesn't match: %d\n", pid1, pid2, ret); + break; + case -1: + pr_err("kcmp (type: %d, pid1: %d, pid2: %d, " + "idx1: %ld, idx2: %ld) failed: %d\n", + type, pid1, pid2, idx1, idx2, errno); + break; + default: + pr_err("kcmp (type: %d, pid1: %d, pid2: %d, " + "idx1: %ld, idx2: %ld) returned %d\n", + type, pid1, pid2, idx1, idx2, ret); + break; } return ret; } -#define gettid(code) \ - syscall(__NR_gettid) +#define gettid(code) syscall(__NR_gettid) static pthread_mutex_t init_lock; static pthread_mutex_t exit_lock; @@ -68,7 +67,7 @@ int main(int argc, char **argv) int ret; pthread_t th; - test_init(argc, argv); + test_init(argc, argv); pthread_mutex_init(&init_lock, NULL); pthread_mutex_lock(&init_lock); diff --git a/test/zdtm/static/cmdlinenv00.c b/test/zdtm/static/cmdlinenv00.c index 8fffcb3e0..fc2f0a7dc 100644 --- a/test/zdtm/static/cmdlinenv00.c +++ b/test/zdtm/static/cmdlinenv00.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test that env/cmdline/auxv restored well\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Test that env/cmdline/auxv restored well\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; static char *arg1, *arg2, *arg3; @@ -60,7 +60,7 @@ static int cmp_auxv(const void *auxv_orig, const void *auxv, size_t size) while (size > 0) { if (*new != *old) return -1; - new++; + new ++; old++; size -= sizeof(*new); } @@ -76,12 +76,12 @@ int main(int argc, char *argv[]) char auxv_orig[1024]; char auxv[1024]; - memset(cmdline_orig, 0, sizeof(cmdline_orig)); - memset(cmdline, 0, sizeof(cmdline)); - memset(env_orig, 0, sizeof(env_orig)); - memset(env, 0, sizeof(env)); - memset(auxv_orig, 0, sizeof(auxv_orig)); - memset(auxv, 0, sizeof(auxv)); + memset(cmdline_orig, 0, sizeof(cmdline_orig)); + memset(cmdline, 0, sizeof(cmdline)); + memset(env_orig, 0, sizeof(env_orig)); + memset(env, 0, sizeof(env)); + memset(auxv_orig, 0, sizeof(auxv_orig)); + memset(auxv, 0, sizeof(auxv)); test_init(argc, argv); diff --git a/test/zdtm/static/config_inotify_irmap.c b/test/zdtm/static/config_inotify_irmap.c index 3cbeba7d3..94585491a 100644 --- a/test/zdtm/static/config_inotify_irmap.c +++ b/test/zdtm/static/config_inotify_irmap.c @@ -20,16 +20,19 @@ * refer to the original test case and it's author. */ -const char *test_doc = "Default configuration files usage"; -const char *test_author = "Veronika Kabatova <vkabatov@redhat.com>"; +const char *test_doc = "Default configuration files usage"; +const char *test_author = "Veronika Kabatova <vkabatov@redhat.com>"; -#define TDIR "/etc" -char test_files[2][128] = {TDIR"/zdtm-test", TDIR"/zdtm-test1",}; -#define CONFIG_PATH "../../zdtm_test_config.conf" +#define TDIR "/etc" +char test_files[2][128] = { + TDIR "/zdtm-test", + TDIR "/zdtm-test1", +}; +#define CONFIG_PATH "../../zdtm_test_config.conf" #define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX)) -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { FILE *configfile; char buf[BUFF_SIZE]; diff --git a/test/zdtm/static/console.c b/test/zdtm/static/console.c index 026eacb2e..d40332acd 100644 --- a/test/zdtm/static/console.c +++ b/test/zdtm/static/console.c @@ -10,20 +10,20 @@ #include "zdtmtst.h" -const char *test_doc = "Check c/r for console device"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check c/r for console device"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { struct stat st1, st2; int fd; test_init(argc, argv); - if (mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, makedev(5,1))) { + if (mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, makedev(5, 1))) { pr_perror("Can't create console %s", filename); return 1; } @@ -48,9 +48,7 @@ int main(int argc, char ** argv) } if (st1.st_rdev != st2.st_rdev) { - fail("Console rdev mismatch %x != %x on %s", - (int)st1.st_rdev, (int)st2.st_rdev, - filename); + fail("Console rdev mismatch %x != %x on %s", (int)st1.st_rdev, (int)st2.st_rdev, filename); return 1; } diff --git a/test/zdtm/static/cow00.c b/test/zdtm/static/cow00.c index 92446a16c..cb0c6733e 100644 --- a/test/zdtm/static/cow00.c +++ b/test/zdtm/static/cow00.c @@ -10,13 +10,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check that cow memory are restored"; -const char *test_author = "Andrey Vagin <avagin@parallels.com"; +const char *test_doc = "Check that cow memory are restored"; +const char *test_author = "Andrey Vagin <avagin@parallels.com"; static int is_cow(void *addr, pid_t p1, pid_t p2) { char buf[PATH_MAX]; - unsigned long pfn = (unsigned long) addr / PAGE_SIZE; + unsigned long pfn = (unsigned long)addr / PAGE_SIZE; uint64_t map1, map2; int fd1, fd2, ret, i; @@ -63,7 +63,7 @@ static int is_cow(void *addr, pid_t p1, pid_t p2) return map1 == map2; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { void *addr; pid_t pid; diff --git a/test/zdtm/static/cow01.c b/test/zdtm/static/cow01.c index ce5745831..268f49e2a 100644 --- a/test/zdtm/static/cow01.c +++ b/test/zdtm/static/cow01.c @@ -13,8 +13,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that cow memory are restored"; -const char *test_author = "Andrey Vagin <avagin@parallels.com"; +const char *test_doc = "Check that cow memory are restored"; +const char *test_author = "Andrey Vagin <avagin@parallels.com"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -22,20 +22,19 @@ TEST_OPTION(filename, string, "file name", 1); struct test_case { union { struct { - uint8_t b_f_write:1; /* before fork */ - uint8_t b_f_read:1; - uint8_t a_f_write_child:1; /* after fork */ - uint8_t a_f_write_parent:1; - uint8_t a_f_read_child:1; - uint8_t a_f_read_parent:1; -#define TEST_CASES (2 << 6) + uint8_t b_f_write : 1; /* before fork */ + uint8_t b_f_read : 1; + uint8_t a_f_write_child : 1; /* after fork */ + uint8_t a_f_write_parent : 1; + uint8_t a_f_read_child : 1; + uint8_t a_f_read_parent : 1; +#define TEST_CASES (2 << 6) }; uint8_t num; }; uint32_t crc_parent; uint32_t crc_child; - }; struct test_cases { @@ -57,27 +56,28 @@ static pid_t child_pid; * file, etc.). A return code of 1 means failure, it means criu was not able * to checkpoint and/or restore the process properly. */ -#define EXECUTE_ACTION(func, fd) ({ \ - int __ret = 0; \ - __ret |= func(&sep_tcs, fd); \ - __ret |= func(&cow_tcs, fd); \ - __ret |= func(&cow_gd_tcs, fd); \ - __ret |= func(&file_tcs, fd); \ - __ret; \ -}) - -struct test_cases cow_tcs = {.init = init_cow, .tname = "cow_tcs"}, - sep_tcs = {.init = init_sep, .tname = "sep_tcs"}, - file_tcs = {.init = init_file, .tname = "file_tcs"}, - cow_gd_tcs = {.init = init_cow_gd, .tname = "cow_gd_tcs"}; +#define EXECUTE_ACTION(func, fd) \ + ({ \ + int __ret = 0; \ + __ret |= func(&sep_tcs, fd); \ + __ret |= func(&cow_tcs, fd); \ + __ret |= func(&cow_gd_tcs, fd); \ + __ret |= func(&file_tcs, fd); \ + __ret; \ + }) + +struct test_cases cow_tcs = { .init = init_cow, .tname = "cow_tcs" }, + sep_tcs = { .init = init_sep, .tname = "sep_tcs" }, + file_tcs = { .init = init_file, .tname = "file_tcs" }, + cow_gd_tcs = { .init = init_cow_gd, .tname = "cow_gd_tcs" }; uint32_t zero_crc = ~1; -static int is_cow(void *addr, pid_t pid_child, pid_t pid_parent, - uint64_t *map_child_ret, uint64_t *map_parent_ret, int fd) +static int is_cow(void *addr, pid_t pid_child, pid_t pid_parent, uint64_t *map_child_ret, uint64_t *map_parent_ret, + int fd) { char buf[PATH_MAX]; - unsigned long pfn = (unsigned long) addr / PAGE_SIZE; + unsigned long pfn = (unsigned long)addr / PAGE_SIZE; uint64_t map_child, map_parent; int fd_child, fd_parent, ret, i; off_t lseek_ret; @@ -104,30 +104,26 @@ static int is_cow(void *addr, pid_t pid_child, pid_t pid_parent, void **p = addr; lseek_ret = lseek(fd_child, pfn * sizeof(map_child), SEEK_SET); - if (lseek_ret == (off_t) -1) { - pr_perror("Unable to seek child pagemap to virtual addr %#08lx", - pfn * PAGE_SIZE); + if (lseek_ret == (off_t)-1) { + pr_perror("Unable to seek child pagemap to virtual addr %#08lx", pfn * PAGE_SIZE); return -1; } lseek_ret = lseek(fd_parent, pfn * sizeof(map_parent), SEEK_SET); - if (lseek_ret == (off_t) -1) { - pr_perror("Unable to seek parent pagemap to virtual addr %#08lx", - pfn * PAGE_SIZE); + if (lseek_ret == (off_t)-1) { + pr_perror("Unable to seek parent pagemap to virtual addr %#08lx", pfn * PAGE_SIZE); return -1; } ret = read(fd_child, &map_child, sizeof(map_child)); if (ret != sizeof(map_child)) { - pr_perror("Unable to read child pagemap at virtual addr %#08lx", - pfn * PAGE_SIZE); + pr_perror("Unable to read child pagemap at virtual addr %#08lx", pfn * PAGE_SIZE); return -1; } ret = read(fd_parent, &map_parent, sizeof(map_parent)); if (ret != sizeof(map_parent)) { - pr_perror("Unable to read parent pagemap at virtual addr %#08lx", - pfn * PAGE_SIZE); + pr_perror("Unable to read parent pagemap at virtual addr %#08lx", pfn * PAGE_SIZE); return -1; } @@ -192,8 +188,8 @@ static int child_check(struct test_cases *test_cases, int fd) datasum(addr + i * PAGE_SIZE, PAGE_SIZE, &crc); if (crc != tc->crc_child) { errno = 0; - fail("%s[%#x]: %p child data mismatch (expected [%04x] got [%04x])", - test_cases->tname, i, addr + i * PAGE_SIZE, tc->crc_child, crc); + fail("%s[%#x]: %p child data mismatch (expected [%04x] got [%04x])", test_cases->tname, i, + addr + i * PAGE_SIZE, tc->crc_child, crc); ret |= 1; } } @@ -266,29 +262,25 @@ static int parent_check(struct test_cases *test_cases, int fd) datasum(addr + i * PAGE_SIZE, PAGE_SIZE, &crc); if (crc != tc->crc_parent) { errno = 0; - fail("%s[%#x]: %p parent data mismatch (expected [%04x] got [%04x])", - test_cases->tname, i, addr + i * PAGE_SIZE, tc->crc_parent, crc); + fail("%s[%#x]: %p parent data mismatch (expected [%04x] got [%04x])", test_cases->tname, i, + addr + i * PAGE_SIZE, tc->crc_parent, crc); ret |= 1; } if (test_cases == &sep_tcs) continue; - if (!tc->a_f_write_child && - !tc->a_f_write_parent && - tc->b_f_write) { + if (!tc->a_f_write_child && !tc->a_f_write_parent && tc->b_f_write) { uint64_t map_child, map_parent; int is_cow_ret; - is_cow_ret = is_cow(addr + i * PAGE_SIZE, child_pid, getpid(), - &map_child, &map_parent, fd); + is_cow_ret = is_cow(addr + i * PAGE_SIZE, child_pid, getpid(), &map_child, &map_parent, fd); ret |= is_cow_ret; if (is_cow_ret == 1) { errno = 0; fail("%s[%#x]: %p is not COW-ed (pagemap of " - "child=[%"PRIx64"], parent=[%"PRIx64"])", - test_cases->tname, i, addr + i * PAGE_SIZE, - map_child, map_parent); + "child=[%" PRIx64 "], parent=[%" PRIx64 "])", + test_cases->tname, i, addr + i * PAGE_SIZE, map_child, map_parent); } } } @@ -301,9 +293,7 @@ static int __init_cow(struct test_cases *tcs, int flags) int i; void *addr; - addr = mmap(NULL, PAGE_SIZE * (TEST_CASES + 2), - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + addr = mmap(NULL, PAGE_SIZE * (TEST_CASES + 2), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (addr == MAP_FAILED) { pr_perror("Can't allocate memory"); return -1; @@ -314,12 +304,11 @@ static int __init_cow(struct test_cases *tcs, int flags) * In parent cow-ed and coinciding regions can be merged, but * in child they cannot be, so COW will not be restored. FIXME */ - mmap(addr, PAGE_SIZE, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + mmap(addr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); addr += PAGE_SIZE; tcs->addr = addr; - mmap(addr + PAGE_SIZE * TEST_CASES, PAGE_SIZE, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | flags, -1, 0); + mmap(addr + PAGE_SIZE * TEST_CASES, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | flags, -1, + 0); test_msg("addr[%s]=%p\n", tcs->tname, tcs->addr); for (i = 0; i < TEST_CASES; i++) { @@ -345,9 +334,7 @@ static int init_sep(struct test_cases *tcs) { int i; - tcs->addr = mmap(NULL, PAGE_SIZE * TEST_CASES, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + tcs->addr = mmap(NULL, PAGE_SIZE * TEST_CASES, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (tcs->addr == MAP_FAILED) { pr_perror("Can't allocate memory"); return -1; @@ -389,9 +376,7 @@ static int init_file(struct test_cases *tcs) tc->crc_child = crc; } - tcs->addr = mmap(NULL, PAGE_SIZE * TEST_CASES, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_FILE, fd, 0); + tcs->addr = mmap(NULL, PAGE_SIZE * TEST_CASES, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, fd, 0); if (tcs->addr == MAP_FAILED) { pr_perror("Can't allocate memory"); return -1; @@ -407,9 +392,8 @@ static int child(task_waiter_t *child_waiter, int fd) { int ret = 0; - sep_tcs.addr = mmap(sep_tcs.addr, PAGE_SIZE * TEST_CASES, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + sep_tcs.addr = mmap(sep_tcs.addr, PAGE_SIZE * TEST_CASES, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); if (sep_tcs.addr == MAP_FAILED) { pr_perror("Can't allocate memory"); return -1; @@ -445,7 +429,7 @@ static int child(task_waiter_t *child_waiter, int fd) return (ret < 0) ? 2 : (ret != 0); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { uint8_t zero_page[PAGE_SIZE]; int status = -1, ret = 0; diff --git a/test/zdtm/static/cr_veth.c b/test/zdtm/static/cr_veth.c index bc5c0cbd4..f09d52797 100644 --- a/test/zdtm/static/cr_veth.c +++ b/test/zdtm/static/cr_veth.c @@ -13,8 +13,8 @@ #include <net/if.h> #include "zdtmtst.h" -const char *test_doc = "check that veth C/R-s right"; -const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; +const char *test_doc = "check that veth C/R-s right"; +const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; #define IF_NAME "zdtmvthc0" diff --git a/test/zdtm/static/cr_veth02.c b/test/zdtm/static/cr_veth02.c index 9e75906c0..5075e062d 100644 --- a/test/zdtm/static/cr_veth02.c +++ b/test/zdtm/static/cr_veth02.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Restore with precreated veth devices."; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Restore with precreated veth devices."; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; #define IF_NAME "zdtmvthc0" diff --git a/test/zdtm/static/criu-rtc.c b/test/zdtm/static/criu-rtc.c index 8ffb0cd08..9626a6dcc 100644 --- a/test/zdtm/static/criu-rtc.c +++ b/test/zdtm/static/criu-rtc.c @@ -37,8 +37,7 @@ int cr_plugin_dump_file(int fd, int id) return -1; } - if (major(st.st_rdev) != major(st_rtc.st_rdev) || - minor(st.st_rdev) != 0) + if (major(st.st_rdev) != major(st_rtc.st_rdev) || minor(st.st_rdev) != 0) return -ENOTSUP; if (ioctl(fd, RTC_IRQP_READ, &irqp) == -1) { @@ -61,7 +60,7 @@ int cr_plugin_dump_file(int fd, int id) criu_rtc__pack(&e, buf); - ret = write(img_fd, buf, len); + ret = write(img_fd, buf, len); if (ret != len) { pr_perror("Unable to write in %s", img_path); close(img_fd); diff --git a/test/zdtm/static/cwd00.c b/test/zdtm/static/cwd00.c index d75fa6a4e..c05174d63 100644 --- a/test/zdtm/static/cwd00.c +++ b/test/zdtm/static/cwd00.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that cwd didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that cwd didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/cwd01.c b/test/zdtm/static/cwd01.c index b04032c1c..9d457e9c8 100644 --- a/test/zdtm/static/cwd01.c +++ b/test/zdtm/static/cwd01.c @@ -8,11 +8,10 @@ #include <sys/types.h> #include <fcntl.h> - #include "zdtmtst.h" -const char *test_doc = "Check that removed cwd works"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that removed cwd works"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/cwd02.c b/test/zdtm/static/cwd02.c index 0d4b276e5..916625b7b 100644 --- a/test/zdtm/static/cwd02.c +++ b/test/zdtm/static/cwd02.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that removed and opened cwd are kept"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that removed and opened cwd are kept"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -72,8 +72,7 @@ int main(int argc, char **argv) goto cleanup; } - if (stf.st_ino != std.st_ino || - stf.st_dev != std.st_dev) { + if (stf.st_ino != std.st_ino || stf.st_dev != std.st_dev) { fail("cwd and opened fd are not the same"); goto cleanup; } diff --git a/test/zdtm/static/del_standalone_un.c b/test/zdtm/static/del_standalone_un.c index f1a7a30f6..c9fa84870 100644 --- a/test/zdtm/static/del_standalone_un.c +++ b/test/zdtm/static/del_standalone_un.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that deleted unix sockets are restored correctly"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that deleted unix sockets are restored correctly"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -26,7 +26,7 @@ static int bind_and_listen(struct sockaddr_un *addr) return -1; } - if (bind(sk, (struct sockaddr *) addr, sizeof(*addr))) { + if (bind(sk, (struct sockaddr *)addr, sizeof(*addr))) { fail("bind %s", addr->sun_path); close(sk); return -1; diff --git a/test/zdtm/static/deleted_dev.c b/test/zdtm/static/deleted_dev.c index a850338d9..1819a8886 100644 --- a/test/zdtm/static/deleted_dev.c +++ b/test/zdtm/static/deleted_dev.c @@ -8,9 +8,9 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a device special file " - "open and unlinked before migration"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can migrate with a device special file " + "open and unlinked before migration"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -51,10 +51,8 @@ int main(int argc, char **argv) if (st.st_mode != mode || st.st_rdev != dev) { fail("%s is no longer the device file we had", filename); - test_msg("mode %x want %x, dev %llx want %llx\n", - st.st_mode, mode, - (long long unsigned)st.st_rdev, - (long long unsigned)dev); + test_msg("mode %x want %x, dev %llx want %llx\n", st.st_mode, mode, (long long unsigned)st.st_rdev, + (long long unsigned)dev); goto out; } diff --git a/test/zdtm/static/deleted_unix_sock.c b/test/zdtm/static/deleted_unix_sock.c index b8856b6fd..342e6586f 100644 --- a/test/zdtm/static/deleted_unix_sock.c +++ b/test/zdtm/static/deleted_unix_sock.c @@ -9,10 +9,10 @@ #include "zdtmtst.h" -const char *test_doc = "Create a unix socket, and destroy it before " - "migration; check that the child can write to it " - "and the parent can read from it after migration"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Create a unix socket, and destroy it before " + "migration; check that the child can write to it " + "and the parent can read from it after migration"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -31,7 +31,7 @@ static int setup_srv_sock(void) return -1; } - if (bind(sock, (struct sockaddr *) &name, SUN_LEN(&name)) < 0) { + if (bind(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) { pr_perror("can't bind to socket \"%s\"", filename); goto err; } @@ -59,7 +59,7 @@ static int setup_clnt_sock(void) if (sock < 0) return -1; - if (connect(sock, (struct sockaddr *) &name, SUN_LEN(&name)) < 0) + if (connect(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) goto err; return sock; @@ -68,7 +68,7 @@ err: return -1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int sock, acc_sock, ret; pid_t pid; @@ -87,7 +87,7 @@ int main(int argc, char ** argv) exit(1); } - if (pid == 0) { /* child writes to the unlinked socket and returns */ + if (pid == 0) { /* child writes to the unlinked socket and returns */ close(sock); sock = setup_clnt_sock(); @@ -157,7 +157,6 @@ int main(int argc, char ** argv) goto out; } - if (close(sock)) { fail("close failed"); goto out; diff --git a/test/zdtm/static/different_creds.c b/test/zdtm/static/different_creds.c index 44a87c43d..34c5bc648 100644 --- a/test/zdtm/static/different_creds.c +++ b/test/zdtm/static/different_creds.c @@ -11,51 +11,51 @@ #include "zdtmtst.h" -const char *test_doc = "Check that threads with different creds aren't checkpointed"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that threads with different creds aren't checkpointed"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; void *drop_caps_and_wait(void *arg) { - int fd = *((int *) arg), i; + int fd = *((int *)arg), i; void *retcode = (void *)0xdeadbeaf; cap_t caps; char c; typedef struct cap_set { - cap_flag_value_t val; - cap_flag_value_t new; - cap_flag_t flag; - cap_value_t bit; + cap_flag_value_t val; + cap_flag_value_t new; + cap_flag_t flag; + cap_value_t bit; } cap_set_t; cap_set_t src[] = { { - .val = CAP_CLEAR, - .flag = CAP_EFFECTIVE, - .bit = CAP_CHOWN, + .val = CAP_CLEAR, + .flag = CAP_EFFECTIVE, + .bit = CAP_CHOWN, }, { - .val = CAP_SET, - .flag = CAP_EFFECTIVE, - .bit = CAP_DAC_OVERRIDE, + .val = CAP_SET, + .flag = CAP_EFFECTIVE, + .bit = CAP_DAC_OVERRIDE, }, { - .val = CAP_CLEAR, - .flag = CAP_INHERITABLE, - .bit = CAP_SETPCAP, + .val = CAP_CLEAR, + .flag = CAP_INHERITABLE, + .bit = CAP_SETPCAP, }, { - .val = CAP_SET, - .flag = CAP_INHERITABLE, - .bit = CAP_NET_BIND_SERVICE, + .val = CAP_SET, + .flag = CAP_INHERITABLE, + .bit = CAP_NET_BIND_SERVICE, }, }; - caps = cap_get_proc(); - if (!caps) { - pr_perror("cap_get_proc"); - return NULL; - } + caps = cap_get_proc(); + if (!caps) { + pr_perror("cap_get_proc"); + return NULL; + } for (i = 0; i < ARRAY_SIZE(src); i++) { if (cap_set_flag(caps, src[i].flag, 1, &src[i].bit, src[i].val) < 0) { @@ -64,10 +64,10 @@ void *drop_caps_and_wait(void *arg) } } - if (cap_set_proc(caps) < 0) { - pr_perror("cap_set_proc"); - goto die; - } + if (cap_set_proc(caps) < 0) { + pr_perror("cap_set_proc"); + goto die; + } if (write(fd, "a", 1) != 1) { pr_perror("Unable to send a status"); @@ -93,11 +93,11 @@ void *drop_caps_and_wait(void *arg) retcode = NULL; die: - cap_free(caps); + cap_free(caps); return retcode; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pipefd[2]; pthread_t thr; diff --git a/test/zdtm/static/dumpable01.c b/test/zdtm/static/dumpable01.c index e5dfc9ab7..73ca17073 100644 --- a/test/zdtm/static/dumpable01.c +++ b/test/zdtm/static/dumpable01.c @@ -5,7 +5,7 @@ #include "zdtmtst.h" -const char *test_doc = "Check dumpable flag handling (dumpable case)"; +const char *test_doc = "Check dumpable flag handling (dumpable case)"; const char *test_author = "Filipe Brandenburger <filbranden@google.com>"; int main(int argc, char **argv) diff --git a/test/zdtm/static/dumpable02.c b/test/zdtm/static/dumpable02.c index cbcd5ba66..6c7df45db 100644 --- a/test/zdtm/static/dumpable02.c +++ b/test/zdtm/static/dumpable02.c @@ -10,10 +10,11 @@ #include "zdtmtst.h" -const char *test_doc = "Check dumpable flag handling (non-dumpable case)"; +const char *test_doc = "Check dumpable flag handling (non-dumpable case)"; const char *test_author = "Filipe Brandenburger <filbranden@google.com>"; -int dumpable_server(void) { +int dumpable_server(void) +{ char buf[256]; int ret; @@ -27,7 +28,8 @@ int dumpable_server(void) { return 0; } -int get_dumpable_from_pipes(int pipe_input, int pipe_output) { +int get_dumpable_from_pipes(int pipe_input, int pipe_output) +{ char buf[256]; int len; long value; @@ -57,7 +59,6 @@ int get_dumpable_from_pipes(int pipe_input, int pipe_output) { return (int)value; } - int main(int argc, char **argv) { int pipe_input[2]; @@ -156,7 +157,8 @@ int main(int argc, char **argv) close(pipe_output[1]); save_dumpable = get_dumpable_from_pipes(pipe_input[1], pipe_output[0]); - if (save_dumpable < 0) return 1; + if (save_dumpable < 0) + return 1; #ifdef DEBUG test_msg("DEBUG: before dump: dumpable=%d\n", save_dumpable); #endif @@ -166,7 +168,8 @@ int main(int argc, char **argv) test_waitsig(); dumpable = get_dumpable_from_pipes(pipe_input[1], pipe_output[0]); - if (dumpable < 0) return 1; + if (dumpable < 0) + return 1; #ifdef DEBUG test_msg("DEBUG: after restore: dumpable=%d\n", dumpable); #endif @@ -188,18 +191,15 @@ int main(int argc, char **argv) } errno = 0; if (waited != pid) { - pr_err("waited pid %d did not match child pid %d\n", - waited, pid); + pr_err("waited pid %d did not match child pid %d\n", waited, pid); return 1; } if (!WIFEXITED(status)) { - pr_err("child dumpable server returned abnormally with status=%d\n", - status); + pr_err("child dumpable server returned abnormally with status=%d\n", status); return 1; } if (WEXITSTATUS(status) != 0) { - pr_err("child dumpable server returned rc=%d\n", - WEXITSTATUS(status)); + pr_err("child dumpable server returned rc=%d\n", WEXITSTATUS(status)); return 1; } diff --git a/test/zdtm/static/env00.c b/test/zdtm/static/env00.c index 5ee995b93..a966c0418 100644 --- a/test/zdtm/static/env00.c +++ b/test/zdtm/static/env00.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that environment didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that environment didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *envname; TEST_OPTION(envname, string, "environment variable name", 1); diff --git a/test/zdtm/static/epoll.c b/test/zdtm/static/epoll.c index 5acb54094..6909935b9 100644 --- a/test/zdtm/static/epoll.c +++ b/test/zdtm/static/epoll.c @@ -19,10 +19,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check for epoll"; -const char *test_author = "Andrei Vagin <avagin@openvz.org>"; +const char *test_doc = "Check for epoll"; +const char *test_author = "Andrei Vagin <avagin@openvz.org>"; -#define DUPFDNO 999 +#define DUPFDNO 999 int main(int argc, char *argv[]) { @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) int i, ret; struct { - int pipefd[2]; + int pipefd[2]; } pipes[250]; test_init(argc, argv); @@ -108,8 +108,7 @@ int main(int argc, char *argv[]) return 1; } if (ev.data.u64 != i) { - pr_err("ev.fd=%d ev.data.u64=%#llx (%d expected)\n", - ev.data.fd, (long long)ev.data.u64, i); + pr_err("ev.fd=%d ev.data.u64=%#llx (%d expected)\n", ev.data.fd, (long long)ev.data.u64, i); ret |= 1; } @@ -118,8 +117,7 @@ int main(int argc, char *argv[]) return 1; } if (ev.data.u64 != i) { - pr_err("ev.fd=%d ev.data.u64=%#llx (%d expected)\n", - ev.data.fd, (long long)ev.data.u64, i); + pr_err("ev.fd=%d ev.data.u64=%#llx (%d expected)\n", ev.data.fd, (long long)ev.data.u64, i); ret |= 1; } diff --git a/test/zdtm/static/epoll01.c b/test/zdtm/static/epoll01.c index 23d536123..6701dbdff 100644 --- a/test/zdtm/static/epoll01.c +++ b/test/zdtm/static/epoll01.c @@ -19,12 +19,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check another case of epoll: This adds three epoll " - "targets on tfd 702 and then adds two epoll targets " - "on tfd 701. This test is for off calculation in " - "dump_one_eventpoll, the reverse order makes qsort " - "to actually work."; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check another case of epoll: This adds three epoll " + "targets on tfd 702 and then adds two epoll targets " + "on tfd 701. This test is for off calculation in " + "dump_one_eventpoll, the reverse order makes qsort " + "to actually work."; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; int main(int argc, char *argv[]) { @@ -33,15 +33,11 @@ int main(int argc, char *argv[]) int i, ret; struct { - int pipefd[2]; - int dupfd; - bool close; + int pipefd[2]; + int dupfd; + bool close; } pipes[5] = { - { {}, 702, true }, - { {}, 702, true }, - { {}, 702, false }, - { {}, 701, true }, - { {}, 701, false }, + { {}, 702, true }, { {}, 702, true }, { {}, 702, false }, { {}, 701, true }, { {}, 701, false }, }; test_init(argc, argv); @@ -102,8 +98,7 @@ int main(int argc, char *argv[]) } if (ev.data.u64 != i) { - pr_err("ev.fd=%d ev.data.u64=%#llx (%d expected)\n", - ev.data.fd, (long long)ev.data.u64, i); + pr_err("ev.fd=%d ev.data.u64=%#llx (%d expected)\n", ev.data.fd, (long long)ev.data.u64, i); ret |= 1; } diff --git a/test/zdtm/static/eventfs00.c b/test/zdtm/static/eventfs00.c index 5278777ba..8934f8aca 100644 --- a/test/zdtm/static/eventfs00.c +++ b/test/zdtm/static/eventfs00.c @@ -21,14 +21,14 @@ #include "zdtmtst.h" #ifndef F_SETSIG -#define F_SETSIG 10 /* for sockets. */ -#define F_GETSIG 11 /* for sockets. */ +#define F_SETSIG 10 /* for sockets. */ +#define F_GETSIG 11 /* for sockets. */ #endif -const char *test_doc = "Check for eventfs"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for eventfs"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; -#define EVENTFD_INITIAL 30 +#define EVENTFD_INITIAL 30 #define EVENTFD_FINAL 90 int main(int argc, char *argv[]) @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) exit(1); } - test_msg("created eventfd with %"PRIu64"\n", v); + test_msg("created eventfd with %" PRIu64 "\n", v); ret = write(efd, &v, sizeof(v)); if (ret != sizeof(v)) { diff --git a/test/zdtm/static/fanotify00.c b/test/zdtm/static/fanotify00.c index 0251e46d4..69ead43e7 100644 --- a/test/zdtm/static/fanotify00.c +++ b/test/zdtm/static/fanotify00.c @@ -17,56 +17,56 @@ #include "zdtmtst.h" #ifdef __x86_64__ -# define __NR_fanotify_init 300 -# define __NR_fanotify_mark 301 +#define __NR_fanotify_init 300 +#define __NR_fanotify_mark 301 #elif defined(__PPC64__) -# define __NR_fanotify_init 323 -# define __NR_fanotify_mark 324 +#define __NR_fanotify_init 323 +#define __NR_fanotify_mark 324 #elif __aarch64__ -# define __NR_fanotify_init 262 -# define __NR_fanotify_mark 263 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 #elif __s390x__ -# define __NR_fanotify_init 332 -# define __NR_fanotify_mark 333 +#define __NR_fanotify_init 332 +#define __NR_fanotify_mark 333 #else -# define __NR_fanotify_init 338 -# define __NR_fanotify_mark 339 +#define __NR_fanotify_init 338 +#define __NR_fanotify_mark 339 #endif -const char *test_doc = "Check for fanotify delivery"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for fanotify delivery"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; const char fanotify_path[] = "fanotify-del-after-cr"; #define BUFF_SIZE (8192) struct fanotify_mark_inode { - unsigned long i_ino; - unsigned int s_dev; - unsigned int mflags; - unsigned int mask; - unsigned int ignored_mask; - unsigned int fhandle_bytes; - unsigned int fhandle_type; - unsigned char fhandle[512]; + unsigned long i_ino; + unsigned int s_dev; + unsigned int mflags; + unsigned int mask; + unsigned int ignored_mask; + unsigned int fhandle_bytes; + unsigned int fhandle_type; + unsigned char fhandle[512]; }; struct fanotify_mark_mount { - unsigned int mnt_id; - unsigned int mflags; - unsigned int mask; - unsigned int ignored_mask; + unsigned int mnt_id; + unsigned int mflags; + unsigned int mask; + unsigned int ignored_mask; }; struct fanotify_glob { - unsigned int faflags; - unsigned int evflags; + unsigned int faflags; + unsigned int evflags; }; struct fanotify_obj { - struct fanotify_glob glob; - struct fanotify_mark_inode inode; - struct fanotify_mark_mount mount; + struct fanotify_glob glob; + struct fanotify_mark_inode inode; + struct fanotify_mark_mount mount; }; static int fanotify_init(unsigned int flags, unsigned int event_f_flags) @@ -74,8 +74,7 @@ static int fanotify_init(unsigned int flags, unsigned int event_f_flags) return syscall(__NR_fanotify_init, flags, event_f_flags); } -static int fanotify_mark(int fanotify_fd, unsigned int flags, unsigned long mask, - int dfd, const char *pathname) +static int fanotify_mark(int fanotify_fd, unsigned int flags, unsigned long mask, int dfd, const char *pathname) { #ifdef __i386__ return syscall(__NR_fanotify_mark, fanotify_fd, flags, mask, 0, dfd, pathname); @@ -84,29 +83,25 @@ static int fanotify_mark(int fanotify_fd, unsigned int flags, unsigned long mask #endif } -#define fdinfo_field(str, field) !strncmp(str, field":", sizeof(field)) +#define fdinfo_field(str, field) !strncmp(str, field ":", sizeof(field)) static void show_fanotify_obj(struct fanotify_obj *obj) { test_msg("fanotify obj at %p\n", obj); test_msg(" glob\n"); - test_msg(" faflags: %x evflags: %x\n", - obj->glob.faflags, obj->glob.evflags); + test_msg(" faflags: %x evflags: %x\n", obj->glob.faflags, obj->glob.evflags); test_msg(" inode\n"); test_msg(" i_ino: %lx s_dev: %x mflags: %x " "mask: %x ignored_mask: %x " "fhandle_bytes: %x fhandle_type: %x " "fhandle: %s", - obj->inode.i_ino, obj->inode.s_dev, - obj->inode.mflags, obj->inode.mask, - obj->inode.ignored_mask, obj->inode.fhandle_bytes, - obj->inode.fhandle_type, obj->inode.fhandle); + obj->inode.i_ino, obj->inode.s_dev, obj->inode.mflags, obj->inode.mask, obj->inode.ignored_mask, + obj->inode.fhandle_bytes, obj->inode.fhandle_type, obj->inode.fhandle); test_msg(" mount\n"); - test_msg(" mnt_id: %x mflags: %x mask: %x ignored_mask: %x\n", - obj->mount.mnt_id, obj->mount.mflags, + test_msg(" mnt_id: %x mflags: %x mask: %x ignored_mask: %x\n", obj->mount.mnt_id, obj->mount.mflags, obj->mount.mask, obj->mount.ignored_mask); } @@ -129,20 +124,15 @@ static int cmp_fanotify_obj(struct fanotify_obj *old, struct fanotify_obj *new) * moreover the backend (say PLOOP) may be re-mounted during * c/r, so exclude them. */ - if ((old->glob.faflags != new->glob.faflags) || - (old->glob.evflags != new->glob.evflags) || - (old->inode.i_ino != new->inode.i_ino) || - (old->inode.mflags != new->inode.mflags) || - (old->inode.mask != new->inode.mask) || - (old->inode.ignored_mask != new->inode.ignored_mask)) + if ((old->glob.faflags != new->glob.faflags) || (old->glob.evflags != new->glob.evflags) || + (old->inode.i_ino != new->inode.i_ino) || (old->inode.mflags != new->inode.mflags) || + (old->inode.mask != new->inode.mask) || (old->inode.ignored_mask != new->inode.ignored_mask)) return -1; - if (memcmp(old->inode.fhandle, new->inode.fhandle, - sizeof(new->inode.fhandle))) + if (memcmp(old->inode.fhandle, new->inode.fhandle, sizeof(new->inode.fhandle))) return -2; - if ((old->mount.mflags != new->mount.mflags) || - (old->mount.mask != new->mount.mask) || + if ((old->mount.mflags != new->mount.mflags) || (old->mount.mask != new->mount.mask) || (old->mount.ignored_mask != new->mount.ignored_mask)) return -3; @@ -165,18 +155,15 @@ int parse_fanotify_fdinfo(int fd, struct fanotify_obj *obj, unsigned int expecte while (fgets(str, sizeof(str), f)) { if (fdinfo_field(str, "fanotify flags")) { - ret = sscanf(str, "fanotify flags:%x event-flags:%x", - &obj->glob.faflags, &obj->glob.evflags); + ret = sscanf(str, "fanotify flags:%x event-flags:%x", &obj->glob.faflags, &obj->glob.evflags); if (ret != 2) goto parse_err; met++; continue; } if (fdinfo_field(str, "fanotify mnt_id")) { - ret = sscanf(str, - "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x", - &obj->mount.mnt_id, &obj->mount.mflags, - &obj->mount.mask, &obj->mount.ignored_mask); + ret = sscanf(str, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x", &obj->mount.mnt_id, + &obj->mount.mflags, &obj->mount.mask, &obj->mount.ignored_mask); if (ret != 4) goto parse_err; met++; @@ -187,9 +174,8 @@ int parse_fanotify_fdinfo(int fd, struct fanotify_obj *obj, unsigned int expecte ret = sscanf(str, "fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x " "fhandle-bytes:%x fhandle-type:%x f_handle: %n", - &obj->inode.i_ino, &obj->inode.s_dev, - &obj->inode.mflags, &obj->inode.mask, &obj->inode.ignored_mask, - &obj->inode.fhandle_bytes, &obj->inode.fhandle_type, + &obj->inode.i_ino, &obj->inode.s_dev, &obj->inode.mflags, &obj->inode.mask, + &obj->inode.ignored_mask, &obj->inode.fhandle_bytes, &obj->inode.fhandle_type, &hoff); if (ret != 7) goto parse_err; @@ -200,8 +186,7 @@ int parse_fanotify_fdinfo(int fd, struct fanotify_obj *obj, unsigned int expecte } if (expected_to_meet != met) { - pr_perror("Expected to meet %d entries but got %d", - expected_to_meet, met); + pr_perror("Expected to meet %d entries but got %d", expected_to_meet, met); return -1; } @@ -212,9 +197,9 @@ parse_err: return -1; } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { - struct fanotify_obj old = { }, new = { }; + struct fanotify_obj old = {}, new = {}; int fa_fd, fd, del_after; char buf[BUFF_SIZE]; ssize_t length; @@ -232,8 +217,7 @@ int main (int argc, char *argv[]) } } - fa_fd = fanotify_init(FAN_NONBLOCK | FAN_CLASS_NOTIF | FAN_UNLIMITED_QUEUE, - O_RDONLY | O_LARGEFILE); + fa_fd = fanotify_init(FAN_NONBLOCK | FAN_CLASS_NOTIF | FAN_UNLIMITED_QUEUE, O_RDONLY | O_LARGEFILE); if (fa_fd < 0) { pr_perror("fanotify_init failed"); exit(1); @@ -245,24 +229,19 @@ int main (int argc, char *argv[]) exit(1); } - if (fanotify_mark(fa_fd, FAN_MARK_ADD, - FAN_MODIFY | FAN_ACCESS | FAN_OPEN | FAN_CLOSE, - AT_FDCWD, fanotify_path)) { + if (fanotify_mark(fa_fd, FAN_MARK_ADD, FAN_MODIFY | FAN_ACCESS | FAN_OPEN | FAN_CLOSE, AT_FDCWD, + fanotify_path)) { pr_perror("fanotify_mark failed"); exit(1); } - if (fanotify_mark(fa_fd, FAN_MARK_ADD | FAN_MARK_MOUNT, - FAN_ONDIR | FAN_OPEN | FAN_CLOSE, - AT_FDCWD, "/tmp")) { + if (fanotify_mark(fa_fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_ONDIR | FAN_OPEN | FAN_CLOSE, AT_FDCWD, "/tmp")) { pr_perror("fanotify_mark failed"); exit(1); } - if (fanotify_mark(fa_fd, FAN_MARK_ADD | FAN_MARK_MOUNT | - FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY, - FAN_MODIFY | FAN_ACCESS, - AT_FDCWD, "/tmp")) { + if (fanotify_mark(fa_fd, FAN_MARK_ADD | FAN_MARK_MOUNT | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY, + FAN_MODIFY | FAN_ACCESS, AT_FDCWD, "/tmp")) { pr_perror("fanotify_mark failed"); exit(1); } @@ -306,9 +285,8 @@ int main (int argc, char *argv[]) exit(1); } - if (fanotify_mark(fa_fd, FAN_MARK_REMOVE | FAN_MARK_MOUNT, - FAN_ONDIR | FAN_OPEN | FAN_CLOSE, - AT_FDCWD, "/tmp")) { + if (fanotify_mark(fa_fd, FAN_MARK_REMOVE | FAN_MARK_MOUNT, FAN_ONDIR | FAN_OPEN | FAN_CLOSE, AT_FDCWD, + "/tmp")) { pr_perror("fanotify_mark failed"); exit(1); } diff --git a/test/zdtm/static/fd.c b/test/zdtm/static/fd.c index bf27eaf44..9059114be 100644 --- a/test/zdtm/static/fd.c +++ b/test/zdtm/static/fd.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" #include "lock.h" -const char *test_doc = "Check that criu closes up all its descriptors"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check that criu closes up all its descriptors"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; int main(int argc, char **argv) { @@ -38,7 +38,6 @@ int main(int argc, char **argv) } if (pid == 0) { - d = opendir("/proc/self/fd"); if (d == NULL) return 1; @@ -98,8 +97,7 @@ int main(int argc, char **argv) } if (status != 0) { - fail("%d:%d:%d:%d", WIFEXITED(status), WEXITSTATUS(status), - WIFSIGNALED(status), WTERMSIG(status)); + fail("%d:%d:%d:%d", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), WTERMSIG(status)); return 1; } diff --git a/test/zdtm/static/fd01.c b/test/zdtm/static/fd01.c index 4e7875110..3313ac4bd 100644 --- a/test/zdtm/static/fd01.c +++ b/test/zdtm/static/fd01.c @@ -14,8 +14,9 @@ #include "zdtmtst.h" #include "lock.h" -const char *test_doc = "Create file descriptors with different numbers. Check that they do not intersect with service fds"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; +const char *test_doc = + "Create file descriptors with different numbers. Check that they do not intersect with service fds"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; int main(int argc, char **argv) { @@ -28,7 +29,7 @@ int main(int argc, char **argv) test_init(argc, argv); - futex = mmap(NULL, sizeof(*futex), PROT_WRITE | PROT_READ, MAP_ANONYMOUS|MAP_SHARED, -1, 0); + futex = mmap(NULL, sizeof(*futex), PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (futex == MAP_FAILED) { fail("mmap"); exit(1); @@ -68,7 +69,6 @@ int main(int argc, char **argv) exit(1); } - for (i = 1; (fd = (1 << i)) < (rlim.rlim_cur >> 1); i++) { FILE *fp = tmpfile(); if (!fp) { diff --git a/test/zdtm/static/fdt_shared.c b/test/zdtm/static/fdt_shared.c index 6ccd25487..1a0d04ac7 100644 --- a/test/zdtm/static/fdt_shared.c +++ b/test/zdtm/static/fdt_shared.c @@ -9,14 +9,14 @@ #include "zdtmtst.h" -const char *test_doc = "Check a shared file descriptor table."; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check a shared file descriptor table."; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -#define STACK_SIZE 4096 -#define TEST_FD 128 +#define STACK_SIZE 4096 +#define TEST_FD 128 #define TEST_STRING "Hello World!" #define CHILDREN 4 @@ -50,8 +50,7 @@ static pid_t clone_child(int (*fn)(void *), int flags) char stack[STACK_SIZE] __stack_aligned__; pid_t pid; - pid = clone(fn, stack + STACK_SIZE, - flags | SIGCHLD, NULL); + pid = clone(fn, stack + STACK_SIZE, flags | SIGCHLD, NULL); if (pid == -1) { pr_perror("Unable to clone a new process"); return -1; @@ -134,7 +133,7 @@ static int child(void *_arg) return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int status; pid_t pid, pid2; diff --git a/test/zdtm/static/fifo-ghost.c b/test/zdtm/static/fifo-ghost.c index f5e11cfa2..cfe28111b 100644 --- a/test/zdtm/static/fifo-ghost.c +++ b/test/zdtm/static/fifo-ghost.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that a ghost fifo with data restored"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check that a ghost fifo with data restored"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/fifo-rowo-pair.c b/test/zdtm/static/fifo-rowo-pair.c index 239634381..54054961b 100644 --- a/test/zdtm/static/fifo-rowo-pair.c +++ b/test/zdtm/static/fifo-rowo-pair.c @@ -15,9 +15,9 @@ #include "zdtmtst.h" -const char *test_doc = "Test for fifo ro/wo with " - "fake fifo needed on criu side"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Test for fifo ro/wo with " + "fake fifo needed on criu side"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *name_master; TEST_OPTION(name_master, string, "master fifo name", 1); @@ -25,13 +25,15 @@ TEST_OPTION(name_master, string, "master fifo name", 1); char *name_slave; TEST_OPTION(name_slave, string, "slave fifo name", 1); -#define TEST_VALUE (00100) +#define TEST_VALUE (00100) -#define exit_shot(pid, code) \ - do { kill(pid, SIGKILL); exit(code); } while (0) +#define exit_shot(pid, code) \ + do { \ + kill(pid, SIGKILL); \ + exit(code); \ + } while (0) -#define exit_shot_parent(code) \ - exit_shot(getppid(), 1) +#define exit_shot_parent(code) exit_shot(getppid(), 1) int main(int argc, char **argv) { diff --git a/test/zdtm/static/fifo.c b/test/zdtm/static/fifo.c index 91a116619..8c627a7cf 100644 --- a/test/zdtm/static/fifo.c +++ b/test/zdtm/static/fifo.c @@ -7,9 +7,9 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a named pipe " - "open"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can migrate with a named pipe " + "open"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/fifo_ro.c b/test/zdtm/static/fifo_ro.c index d0d2cc48e..24a12f842 100644 --- a/test/zdtm/static/fifo_ro.c +++ b/test/zdtm/static/fifo_ro.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that a fifo read-only descriptor is restored with data"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check that a fifo read-only descriptor is restored with data"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/fifo_upon_unix_socket00.c b/test/zdtm/static/fifo_upon_unix_socket00.c index f75965fdd..0ef68bb66 100644 --- a/test/zdtm/static/fifo_upon_unix_socket00.c +++ b/test/zdtm/static/fifo_upon_unix_socket00.c @@ -11,8 +11,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that fifo upon ghost socket configuration is restored"; -const char *test_author = "Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>"; +const char *test_doc = "Check that fifo upon ghost socket configuration is restored"; +const char *test_author = "Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>"; char *filename; TEST_OPTION(filename, string, "socket name", 1); @@ -24,8 +24,7 @@ static int fill_sock_name(struct sockaddr_un *name, const char *filename) cwd = get_current_dir_name(); if (strlen(filename) + strlen(cwd) + 1 >= sizeof(name->sun_path)) { - pr_err("Name %s/%s is too long for socket\n", - cwd, filename); + pr_err("Name %s/%s is too long for socket\n", cwd, filename); return -1; } diff --git a/test/zdtm/static/fifo_wronly.c b/test/zdtm/static/fifo_wronly.c index 64502e187..1083549cb 100644 --- a/test/zdtm/static/fifo_wronly.c +++ b/test/zdtm/static/fifo_wronly.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a named pipe, " - "opened in WRONLY mode"; +const char *test_doc = "Check that we can migrate with a named pipe, " + "opened in WRONLY mode"; #define BUF_SIZE 256 char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -66,7 +66,6 @@ int main(int argc, char **argv) } } else { - fd = open(filename, O_WRONLY); if (fd < 0) { pr_perror("open(%s, O_WRONLY) Failed", filename); @@ -87,8 +86,7 @@ int main(int argc, char **argv) wait(&chret); chret = WEXITSTATUS(chret); if (chret) { - fail("child exited with non-zero code %d (%s)", - chret, strerror(chret)); + fail("child exited with non-zero code %d (%s)", chret, strerror(chret)); return 1; } diff --git a/test/zdtm/static/file_append.c b/test/zdtm/static/file_append.c index 14f18776c..aa93ae186 100644 --- a/test/zdtm/static/file_append.c +++ b/test/zdtm/static/file_append.c @@ -9,8 +9,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check O_APPEND preserved"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check O_APPEND preserved"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/file_attr.c b/test/zdtm/static/file_attr.c index 752c094bf..f8b3d846e 100644 --- a/test/zdtm/static/file_attr.c +++ b/test/zdtm/static/file_attr.c @@ -9,24 +9,27 @@ #include "zdtmtst.h" -const char *test_doc = "Check that attributes and content of an open, " - "written to, and then unlinked file migrate " - "correctly"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that attributes and content of an open, " + "written to, and then unlinked file migrate " + "correctly"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -#define DEF_PERMS 06604 /* -rwS--Sr--, really esoteric one */ +#define DEF_PERMS 06604 /* -rwS--Sr--, really esoteric one */ unsigned int perms = DEF_PERMS; -TEST_OPTION(perms, uint, "permissions to set on file " - "(default " __stringify(DEF_PERMS) ")", 0); -#define DEF_MTIME 123456 /* another really esoteric one */ +TEST_OPTION(perms, uint, + "permissions to set on file " + "(default " __stringify(DEF_PERMS) ")", + 0); +#define DEF_MTIME 123456 /* another really esoteric one */ unsigned int mtime = DEF_MTIME; -TEST_OPTION(mtime, uint, "mtime to set on file " - "(default " __stringify(DEF_MTIME) ")", 0); +TEST_OPTION(mtime, uint, + "mtime to set on file " + "(default " __stringify(DEF_MTIME) ")", + 0); - -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; struct utimbuf ut; @@ -49,7 +52,7 @@ int main(int argc, char ** argv) exit(1); } - ut = (struct utimbuf) { + ut = (struct utimbuf){ .actime = 0, .modtime = mtime, }; diff --git a/test/zdtm/static/file_cloexec.c b/test/zdtm/static/file_cloexec.c index b8eba39e5..6def8174a 100644 --- a/test/zdtm/static/file_cloexec.c +++ b/test/zdtm/static/file_cloexec.c @@ -10,10 +10,14 @@ #include "zdtmtst.h" -const char *test_doc = "Check FD_CLOEXEC flag"; -const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; +const char *test_doc = "Check FD_CLOEXEC flag"; +const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) static void assert_fd_flags(int fd, int mask, int value) { diff --git a/test/zdtm/static/file_fown.c b/test/zdtm/static/file_fown.c index af20a3174..eb42a826e 100644 --- a/test/zdtm/static/file_fown.c +++ b/test/zdtm/static/file_fown.c @@ -15,19 +15,19 @@ #include "zdtmtst.h" #ifndef F_SETSIG -#define F_SETSIG 10 /* for sockets. */ -#define F_GETSIG 11 /* for sockets. */ +#define F_SETSIG 10 /* for sockets. */ +#define F_GETSIG 11 /* for sockets. */ #endif -const char *test_doc = "Check for signal delivery on file owners"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for signal delivery on file owners"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; struct params { - int sigio; - int pipe_flags[2]; - int pipe_pid[2]; - int pipe_sig[2]; -} *shared; + int sigio; + int pipe_flags[2]; + int pipe_pid[2]; + int pipe_sig[2]; +} * shared; static void signal_handler_io(int status) { @@ -55,18 +55,15 @@ static int cmp_pipe_params(struct params *p1, struct params *p2) for (i = 0; i < 2; i++) { if (p1->pipe_flags[i] != p2->pipe_flags[i]) { - fail("pipe flags failed [%d] expected %08o got %08o", - i, p1->pipe_flags[i], p2->pipe_flags[i]); + fail("pipe flags failed [%d] expected %08o got %08o", i, p1->pipe_flags[i], p2->pipe_flags[i]); return -1; } if (p1->pipe_pid[i] != p2->pipe_pid[i]) { - fail("pipe pid failed [%d] expected %d got %d", - i, p1->pipe_pid[i], p2->pipe_pid[i]); + fail("pipe pid failed [%d] expected %d got %d", i, p1->pipe_pid[i], p2->pipe_pid[i]); return -1; } if (p1->pipe_sig[i] != p2->pipe_sig[i]) { - fail("pipe sig failed [%d] expected %d got %d", - i, p1->pipe_sig[i], p2->pipe_sig[i]); + fail("pipe sig failed [%d] expected %d got %d", i, p1->pipe_sig[i], p2->pipe_sig[i]); return -1; } } @@ -76,8 +73,8 @@ static int cmp_pipe_params(struct params *p1, struct params *p2) int main(int argc, char *argv[]) { - struct sigaction saio = { }; - struct params obtained = { }; + struct sigaction saio = {}; + struct params obtained = {}; uid_t ruid, euid, suid; int status, pipes[2]; pid_t pid; @@ -100,8 +97,8 @@ int main(int argc, char *argv[]) exit(1); } - saio.sa_handler = (sig_t)signal_handler_io; - saio.sa_flags = SA_RESTART; + saio.sa_handler = (sig_t)signal_handler_io; + saio.sa_flags = SA_RESTART; if (sigaction(SIGIO, &saio, 0)) { fail("sigaction failed"); exit(1); @@ -112,11 +109,9 @@ int main(int argc, char *argv[]) exit(1); } - if (fcntl(pipes[0], F_SETOWN, getpid()) || - fcntl(pipes[1], F_SETOWN, getpid()) || - fcntl(pipes[0], F_SETSIG, SIGIO) || - fcntl(pipes[1], F_SETSIG, SIGIO) || - fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_ASYNC) || + if (fcntl(pipes[0], F_SETOWN, getpid()) || fcntl(pipes[1], F_SETOWN, getpid()) || + fcntl(pipes[0], F_SETSIG, SIGIO) || fcntl(pipes[1], F_SETSIG, SIGIO) || + fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_ASYNC) || fcntl(pipes[1], F_SETFL, fcntl(pipes[1], F_GETFL) | O_ASYNC)) { fail("fcntl failed"); exit(1); @@ -136,7 +131,7 @@ int main(int argc, char *argv[]) } if (pid == 0) { - struct params p = { }; + struct params p = {}; test_waitsig(); diff --git a/test/zdtm/static/file_lease00.c b/test/zdtm/static/file_lease00.c index 3fd1a0d88..067d8d6ba 100644 --- a/test/zdtm/static/file_lease00.c +++ b/test/zdtm/static/file_lease00.c @@ -62,8 +62,7 @@ int main(int argc, char **argv) pr_err("Can't open files\n"); return -1; } - if (fcntl(fd_rd, F_SETLEASE, F_RDLCK) < 0 || - fcntl(fd_wr, F_SETLEASE, F_WRLCK) < 0) { + if (fcntl(fd_rd, F_SETLEASE, F_RDLCK) < 0 || fcntl(fd_wr, F_SETLEASE, F_WRLCK) < 0) { pr_perror("Can't set leases"); close_files(fd_rd, fd_wr); return -1; diff --git a/test/zdtm/static/file_lease01.c b/test/zdtm/static/file_lease01.c index 6f3dfe60f..bbb2acf34 100644 --- a/test/zdtm/static/file_lease01.c +++ b/test/zdtm/static/file_lease01.c @@ -3,9 +3,9 @@ #include "zdtmtst.h" -#define FD_COUNT 3 -#define FD_LEASED1 0 -#define FD_LEASED2 2 +#define FD_COUNT 3 +#define FD_LEASED1 0 +#define FD_LEASED2 2 #define FD_LEASE_FREE 1 const char *test_doc = "Check that extra leases are not set after c/r"; @@ -63,8 +63,7 @@ int main(int argc, char **argv) return -1; } - if (fcntl(fds[FD_LEASED1], F_SETLEASE, F_RDLCK) < 0 || - fcntl(fds[FD_LEASED2], F_SETLEASE, F_RDLCK) < 0) { + if (fcntl(fds[FD_LEASED1], F_SETLEASE, F_RDLCK) < 0 || fcntl(fds[FD_LEASED2], F_SETLEASE, F_RDLCK) < 0) { pr_err("Can't set leases\n"); close_files(fds); return -1; @@ -85,4 +84,3 @@ int main(int argc, char **argv) close_files(fds); return 0; } - diff --git a/test/zdtm/static/file_lease02.c b/test/zdtm/static/file_lease02.c index 87c56cfd1..c1d3c4594 100644 --- a/test/zdtm/static/file_lease02.c +++ b/test/zdtm/static/file_lease02.c @@ -5,7 +5,7 @@ #include "zdtmtst.h" -#define FD_COUNT 3 +#define FD_COUNT 3 #define BREAK_SIGNUM SIGIO const char *test_doc = "Check c/r of breaking leases"; @@ -111,9 +111,7 @@ int main(int argc, char **argv) act.sa_sigaction = break_sigaction; act.sa_flags = SA_SIGINFO; - if (sigemptyset(&act.sa_mask) || - sigaddset(&act.sa_mask, BREAK_SIGNUM) || - sigaction(BREAK_SIGNUM, &act, NULL)) { + if (sigemptyset(&act.sa_mask) || sigaddset(&act.sa_mask, BREAK_SIGNUM) || sigaction(BREAK_SIGNUM, &act, NULL)) { pr_perror("Can't set signal action"); fail(); return -1; @@ -132,9 +130,8 @@ int main(int argc, char **argv) ret = 0; if (sigaction_error) fail("Ghost signal"); - else if (check_lease_type(fds[0], F_UNLCK) || - check_lease_type(fds[1], F_RDLCK) || - check_lease_type(fds[2], F_UNLCK)) + else if (check_lease_type(fds[0], F_UNLCK) || check_lease_type(fds[1], F_RDLCK) || + check_lease_type(fds[2], F_UNLCK)) fail("Lease type doesn't match"); else pass(); @@ -142,4 +139,3 @@ done: close_files(fds); return ret; } - diff --git a/test/zdtm/static/file_lease03.c b/test/zdtm/static/file_lease03.c index 799c1b1f1..b313c5156 100644 --- a/test/zdtm/static/file_lease03.c +++ b/test/zdtm/static/file_lease03.c @@ -89,9 +89,7 @@ int main(int argc, char **argv) act.sa_sigaction = break_sigaction; act.sa_flags = SA_SIGINFO; - if (sigemptyset(&act.sa_mask) || - sigaddset(&act.sa_mask, BREAK_SIGNUM) || - sigaction(BREAK_SIGNUM, &act, NULL)) { + if (sigemptyset(&act.sa_mask) || sigaddset(&act.sa_mask, BREAK_SIGNUM) || sigaction(BREAK_SIGNUM, &act, NULL)) { pr_perror("Can't set signal action"); return -1; } @@ -143,4 +141,3 @@ done: unlink(filename); return ret; } - diff --git a/test/zdtm/static/file_lease04.c b/test/zdtm/static/file_lease04.c index 4ad9af84f..1c46c24c9 100644 --- a/test/zdtm/static/file_lease04.c +++ b/test/zdtm/static/file_lease04.c @@ -89,9 +89,7 @@ int main(int argc, char **argv) act.sa_sigaction = break_sigaction; act.sa_flags = SA_SIGINFO; - if (sigemptyset(&act.sa_mask) || - sigaddset(&act.sa_mask, BREAK_SIGNUM) || - sigaction(BREAK_SIGNUM, &act, NULL)) { + if (sigemptyset(&act.sa_mask) || sigaddset(&act.sa_mask, BREAK_SIGNUM) || sigaction(BREAK_SIGNUM, &act, NULL)) { pr_perror("Can't set signal action"); return -1; } @@ -129,4 +127,3 @@ done: unlink(filename); return ret; } - diff --git a/test/zdtm/static/file_locks00.c b/test/zdtm/static/file_locks00.c index fa98a31b3..0b5d1313b 100644 --- a/test/zdtm/static/file_locks00.c +++ b/test/zdtm/static/file_locks00.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that posix flocks are restored"; -const char *test_author = "Qiang Huang <h.huangqiang@huawei.com>"; +const char *test_doc = "Check that posix flocks are restored"; +const char *test_author = "Qiang Huang <h.huangqiang@huawei.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -19,35 +19,32 @@ TEST_OPTION(filename, string, "file name", 1); char file0[PATH_MAX]; char file1[PATH_MAX]; -static int lock_reg(int fd, int cmd, int type, int whence, - off_t offset, off_t len) +static int lock_reg(int fd, int cmd, int type, int whence, off_t offset, off_t len) { struct flock lock; - lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ - lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ - lock.l_start = offset; /* byte offset, relative to l_whence */ - lock.l_len = len; /* #bytes (0 means to EOF) */ + lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ + lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ + lock.l_start = offset; /* byte offset, relative to l_whence */ + lock.l_len = len; /* #bytes (0 means to EOF) */ errno = 0; return fcntl(fd, cmd, &lock); } -#define set_read_lock(fd, whence, offset, len) \ - lock_reg(fd, F_SETLK, F_RDLCK, whence, offset, len) -#define set_write_lock(fd, whence, offset, len) \ - lock_reg(fd, F_SETLK, F_WRLCK, whence, offset, len) +#define set_read_lock(fd, whence, offset, len) lock_reg(fd, F_SETLK, F_RDLCK, whence, offset, len) +#define set_write_lock(fd, whence, offset, len) lock_reg(fd, F_SETLK, F_WRLCK, whence, offset, len) static int check_read_lock(int fd, int whence, off_t offset, off_t len) { struct flock lock; int ret; - lock.l_type = F_RDLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ - lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ - lock.l_start = offset; /* byte offset, relative to l_whence */ - lock.l_len = len; /* #bytes (0 means to EOF) */ - lock.l_pid = -1; + lock.l_type = F_RDLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ + lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ + lock.l_start = offset; /* byte offset, relative to l_whence */ + lock.l_len = len; /* #bytes (0 means to EOF) */ + lock.l_pid = -1; errno = 0; ret = fcntl(fd, F_GETLK, &lock); @@ -72,11 +69,11 @@ static int check_write_lock(int fd, int whence, off_t offset, off_t len) int ret; pid_t ppid = getppid(); - lock.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ - lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ - lock.l_start = offset; /* byte offset, relative to l_whence */ - lock.l_len = len; /* #bytes (0 means to EOF) */ - lock.l_pid = -1; + lock.l_type = F_WRLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ + lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ + lock.l_start = offset; /* byte offset, relative to l_whence */ + lock.l_len = len; /* #bytes (0 means to EOF) */ + lock.l_pid = -1; errno = 0; ret = fcntl(fd, F_GETLK, &lock); @@ -157,7 +154,7 @@ int main(int argc, char **argv) return -1; } - if (pid == 0) { /* child will check father's file locks */ + if (pid == 0) { /* child will check father's file locks */ test_waitsig(); if (check_file_locks()) { diff --git a/test/zdtm/static/file_locks01.c b/test/zdtm/static/file_locks01.c index a57a5b61b..6c2e54ff4 100644 --- a/test/zdtm/static/file_locks01.c +++ b/test/zdtm/static/file_locks01.c @@ -18,8 +18,8 @@ #define LOCK_READ 64 #endif -const char *test_doc = "Check that flock locks are restored"; -const char *test_author = "Qiang Huang <h.huangqiang@huawei.com>"; +const char *test_doc = "Check that flock locks are restored"; +const char *test_author = "Qiang Huang <h.huangqiang@huawei.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -78,9 +78,7 @@ static int open_all_files(int *fd_0, int *fd_1, int *fd_2) return 0; } -static int check_file_lock(int fd, char *expected_type, - char *expected_option, - unsigned int expected_dev, +static int check_file_lock(int fd, char *expected_type, char *expected_option, unsigned int expected_dev, unsigned long expected_ino) { char buf[100], fl_flag[16], fl_type[16], fl_option[16]; @@ -90,8 +88,8 @@ static int check_file_lock(int fd, char *expected_type, unsigned long i_no; int maj, min; - test_msg("check_file_lock: (fsname %s) expecting fd %d type %s option %s dev %u ino %lu\n", - m->fsname, fd, expected_type, expected_option, expected_dev, expected_ino); + test_msg("check_file_lock: (fsname %s) expecting fd %d type %s option %s dev %u ino %lu\n", m->fsname, fd, + expected_type, expected_option, expected_dev, expected_ino); snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); fp_locks = fopen(path, "r"); @@ -109,9 +107,8 @@ static int check_file_lock(int fd, char *expected_type, memset(fl_type, 0, sizeof(fl_type)); memset(fl_option, 0, sizeof(fl_option)); - num = sscanf(buf, "%*s %*d:%s %s %s %d %x:%x:%ld %*d %*s", - fl_flag, fl_type, fl_option, &fl_owner, - &maj, &min, &i_no); + num = sscanf(buf, "%*s %*d:%s %s %s %d %x:%x:%ld %*d %*s", fl_flag, fl_type, fl_option, &fl_owner, &maj, + &min, &i_no); if (num < 7) { pr_err("Invalid lock info\n"); break; diff --git a/test/zdtm/static/file_locks02.c b/test/zdtm/static/file_locks02.c index 91d13854a..d2049ebaa 100644 --- a/test/zdtm/static/file_locks02.c +++ b/test/zdtm/static/file_locks02.c @@ -9,22 +9,21 @@ #include "zdtmtst.h" -const char *test_doc = "Check that 'shared' flocks work"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check that 'shared' flocks work"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type, - char *expected_option) +static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type, char *expected_option) { char buf[100], fl_flag[16], fl_type[16], fl_option[16]; int found = 0, num, fl_owner; FILE *fp_locks = NULL; char path[PATH_MAX]; - test_msg("check_file_lock: (pid %d child %d) expecting fd %d type %s option %s\n", - pid, child, fd, expected_type, expected_option); + test_msg("check_file_lock: (pid %d child %d) expecting fd %d type %s option %s\n", pid, child, fd, + expected_type, expected_option); snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); fp_locks = fopen(path, "r"); @@ -42,8 +41,7 @@ static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type, memset(fl_type, 0, sizeof(fl_type)); memset(fl_option, 0, sizeof(fl_option)); - num = sscanf(buf, "%*s %*d:%s %s %s %d", - fl_flag, fl_type, fl_option, &fl_owner); + num = sscanf(buf, "%*s %*d:%s %s %s %d", fl_flag, fl_type, fl_option, &fl_owner); if (num < 4) { pr_perror("Invalid lock info."); break; diff --git a/test/zdtm/static/file_locks03.c b/test/zdtm/static/file_locks03.c index 19c11dbb6..35ef41a21 100644 --- a/test/zdtm/static/file_locks03.c +++ b/test/zdtm/static/file_locks03.c @@ -9,22 +9,21 @@ #include "zdtmtst.h" -const char *test_doc = "Check that 'inherited' flocks work"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check that 'inherited' flocks work"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type, - char *expected_option) +static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type, char *expected_option) { char buf[100], fl_flag[16], fl_type[16], fl_option[16]; int found = 0, num, fl_owner; FILE *fp_locks = NULL; char path[PATH_MAX]; - test_msg("check_file_lock: (pid %d child %d) expecting fd %d type %s option %s\n", - pid, child, fd, expected_type, expected_option); + test_msg("check_file_lock: (pid %d child %d) expecting fd %d type %s option %s\n", pid, child, fd, + expected_type, expected_option); snprintf(path, sizeof(path), "/proc/%d/fdinfo/%d", child, fd); fp_locks = fopen(path, "r"); @@ -42,8 +41,7 @@ static int check_file_lock(pid_t pid, pid_t child, int fd, char *expected_type, memset(fl_type, 0, sizeof(fl_type)); memset(fl_option, 0, sizeof(fl_option)); - num = sscanf(buf, "%*s %*d:%s %s %s %d", - fl_flag, fl_type, fl_option, &fl_owner); + num = sscanf(buf, "%*s %*d:%s %s %s %d", fl_flag, fl_type, fl_option, &fl_owner); if (num < 4) { pr_perror("Invalid lock info."); break; diff --git a/test/zdtm/static/file_locks04.c b/test/zdtm/static/file_locks04.c index 96170d51e..11d224fa7 100644 --- a/test/zdtm/static/file_locks04.c +++ b/test/zdtm/static/file_locks04.c @@ -9,18 +9,18 @@ #include "zdtmtst.h" -const char *test_doc = "Check that 'overlapping' flocks work"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check that 'overlapping' flocks work"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); static int check_file_locks(pid_t child_pid, int fd, int child_fd) { - char path[PATH_MAX]; - FILE *fp_locks = NULL; - char buf[100], fl_flag[16], fl_type[16], fl_option[16]; - int found = 0, num, fl_owner; + char path[PATH_MAX]; + FILE *fp_locks = NULL; + char buf[100], fl_flag[16], fl_type[16], fl_option[16]; + int found = 0, num, fl_owner; sprintf(path, "/proc/%d/fdinfo/%d", child_pid, child_fd); fp_locks = fopen(path, "r"); @@ -34,9 +34,8 @@ static int check_file_locks(pid_t child_pid, int fd, int child_fd) continue; test_msg("c: %s", buf); - num = sscanf(buf, - "%*s %*d:%s %s %s %d %*02x:%*02x:%*d %*d %*s", - fl_flag, fl_type, fl_option, &fl_owner); + num = sscanf(buf, "%*s %*d:%s %s %s %d %*02x:%*02x:%*d %*d %*s", fl_flag, fl_type, fl_option, + &fl_owner); if (num < 4) { pr_perror("Invalid lock info."); @@ -48,9 +47,7 @@ static int check_file_locks(pid_t child_pid, int fd, int child_fd) continue; } - if (!strcmp(fl_flag, "FLOCK") && - !strcmp(fl_type, "ADVISORY") && - !strcmp(fl_option, "WRITE")) + if (!strcmp(fl_flag, "FLOCK") && !strcmp(fl_type, "ADVISORY") && !strcmp(fl_option, "WRITE")) found++; memset(fl_flag, 0, sizeof(fl_flag)); diff --git a/test/zdtm/static/file_locks05.c b/test/zdtm/static/file_locks05.c index e9e56acfe..1972617d5 100644 --- a/test/zdtm/static/file_locks05.c +++ b/test/zdtm/static/file_locks05.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Sanity check for criu lock-test quirk"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Sanity check for criu lock-test quirk"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/file_locks06.c b/test/zdtm/static/file_locks06.c index 2fb0080c4..ce80113db 100644 --- a/test/zdtm/static/file_locks06.c +++ b/test/zdtm/static/file_locks06.c @@ -5,13 +5,12 @@ #include "ofd_file_locks.h" #include "zdtmtst.h" -const char *test_doc = "Check that OFD lock for the whole file is restored"; +const char *test_doc = "Check that OFD lock for the whole file is restored"; const char *test_author = "Begunkov Pavel <asml.silence@gmail.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); - int init_lock(int *fd, struct flock *lck) { *fd = open(filename, O_RDWR | O_CREAT, 0666); @@ -54,8 +53,7 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - if (check_file_lock_restored(getpid(), fd, &lck) || - check_lock_exists(filename, &lck) < 0) + if (check_file_lock_restored(getpid(), fd, &lck) || check_lock_exists(filename, &lck) < 0) fail("OFD file locks check failed"); else pass(); diff --git a/test/zdtm/static/file_locks07.c b/test/zdtm/static/file_locks07.c index 155c1a4a7..0838e35ef 100644 --- a/test/zdtm/static/file_locks07.c +++ b/test/zdtm/static/file_locks07.c @@ -5,19 +5,18 @@ #include "ofd_file_locks.h" #include "zdtmtst.h" -const char *test_doc = "Check that 'overlapping' OFD read locks work"; +const char *test_doc = "Check that 'overlapping' OFD read locks work"; const char *test_author = "Begunkov Pavel <asml.silence@gmail.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); - #define FILE_NUM 4 static int fds[FILE_NUM]; static struct flock lcks[FILE_NUM]; -static short types[] = {F_RDLCK, F_RDLCK, F_RDLCK, F_RDLCK}; -static off_t starts[] = {0, 10, 0, 70}; -static off_t lens[] = {20, 30, 100, 200}; +static short types[] = { F_RDLCK, F_RDLCK, F_RDLCK, F_RDLCK }; +static off_t starts[] = { 0, 10, 0, 70 }; +static off_t lens[] = { 20, 30, 100, 200 }; void fill_lock(struct flock *lock, off_t start, off_t len, short int type) { diff --git a/test/zdtm/static/file_locks08.c b/test/zdtm/static/file_locks08.c index a4fa1feb5..da6c096df 100644 --- a/test/zdtm/static/file_locks08.c +++ b/test/zdtm/static/file_locks08.c @@ -7,13 +7,12 @@ #include "ofd_file_locks.h" #include "zdtmtst.h" -const char *test_doc = "Check that inherited OFD locks work"; +const char *test_doc = "Check that inherited OFD locks work"; const char *test_author = "Begunkov Pavel <asml.silence@gmail.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); - int init_file_lock(int *fd, struct flock *lck) { *fd = open(filename, O_RDWR | O_CREAT, 0666); @@ -62,8 +61,7 @@ int main(int argc, char **argv) pid = fork(); if (pid == 0) { task_waiter_wait4(&tw, getppid()); - if (check_file_lock_restored(getpid(), fd, &lck) || - check_lock_exists(filename, &lck) < 0) + if (check_file_lock_restored(getpid(), fd, &lck) || check_lock_exists(filename, &lck) < 0) ret = -1; exit(ret); } @@ -73,8 +71,7 @@ int main(int argc, char **argv) task_waiter_complete_current(&tw); - if (check_file_lock_restored(getpid(), fd, &lck) || - check_lock_exists(filename, &lck) < 0) + if (check_file_lock_restored(getpid(), fd, &lck) || check_lock_exists(filename, &lck) < 0) fail("OFD file locks check failed"); kill(pid, SIGTERM); diff --git a/test/zdtm/static/file_shared.c b/test/zdtm/static/file_shared.c index 0e78b07e2..9d896c2e2 100644 --- a/test/zdtm/static/file_shared.c +++ b/test/zdtm/static/file_shared.c @@ -7,11 +7,11 @@ #include <stdio.h> #include "zdtmtst.h" -#define OFFSET 1000 +#define OFFSET 1000 #define OFFSET2 500 -const char *test_doc = "Check shared struct file-s"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Check shared struct file-s"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -46,11 +46,11 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); off = lseek(fd, OFFSET, SEEK_SET); - if (off == (off_t) -1) + if (off == (off_t)-1) return 1; off = lseek(fd3, OFFSET2, SEEK_SET); - if (off == (off_t) -1) + if (off == (off_t)-1) return 1; ret = kill(pid, SIGTERM); diff --git a/test/zdtm/static/fpu00.c b/test/zdtm/static/fpu00.c index 6cc15a2b2..7687639c4 100644 --- a/test/zdtm/static/fpu00.c +++ b/test/zdtm/static/fpu00.c @@ -3,9 +3,9 @@ #include "zdtmtst.h" -const char *test_doc = "Start a calculation, leaving FPU in a certain state,\n" -"before migration, continue after"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Start a calculation, leaving FPU in a certain state,\n" + "before migration, continue after"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; #if defined(__i386__) || defined(__x86_64__) @@ -13,25 +13,20 @@ const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; void start(float a, float b, float c, float d) { - __asm__ volatile ( - "flds %0\n" - "fadds %1\n" - "flds %2\n" - "fadds %3\n" - "fmulp %%st(1)\n" - : - : "m" (a), "m" (b), "m" (c), "m" (d) - ); + __asm__ volatile("flds %0\n" + "fadds %1\n" + "flds %2\n" + "fadds %3\n" + "fmulp %%st(1)\n" + : + : "m"(a), "m"(b), "m"(c), "m"(d)); } float finish(void) { float res; - __asm__ volatile ( - "fstps %0\n" - : "=m" (res) - ); + __asm__ volatile("fstps %0\n" : "=m"(res)); return res; } @@ -56,7 +51,6 @@ void *run_fpu_test(void *unused) c = drand48(); d = drand48(); - start(a, b, c, d); res1 = finish(); @@ -75,7 +69,7 @@ void *run_fpu_test(void *unused) return (void *)(uintptr_t)(res1 != res2); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { test_init(argc, argv); @@ -84,7 +78,6 @@ int main(int argc, char ** argv) return 1; } - #ifdef ZDTM_FPU00_RUN_IN_THREAD /* Check if thread's fpu state is preserved */ { diff --git a/test/zdtm/static/fpu01.c b/test/zdtm/static/fpu01.c index 11c480546..638a1ad8f 100644 --- a/test/zdtm/static/fpu01.c +++ b/test/zdtm/static/fpu01.c @@ -10,8 +10,8 @@ #include "cpuid.h" -const char *test_doc = "Test if FPU data in YMM registers do survive the c/r"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Test if FPU data in YMM registers do survive the c/r"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; static int verify_cpu(void) { @@ -45,36 +45,22 @@ static int fpu_test(void) { int ret = 0; - asm volatile("vmovapd %0, %%ymm0 \n" - : - : "m" (*ymm1) - : "memory"); + asm volatile("vmovapd %0, %%ymm0 \n" : : "m"(*ymm1) : "memory"); - asm volatile("vmovapd %0, %%ymm7 \n" - : - : "m" (*ymm2) - : "memory"); + asm volatile("vmovapd %0, %%ymm7 \n" : : "m"(*ymm2) : "memory"); test_daemon(); test_waitsig(); - asm volatile("vmovapd %%ymm0, %0 \n" - : "=m" (*ymm3) - : - : "memory"); + asm volatile("vmovapd %%ymm0, %0 \n" : "=m"(*ymm3) : : "memory"); - asm volatile("vmovapd %%ymm7, %0 \n" - : "=m" (*ymm4) - : - : "memory"); + asm volatile("vmovapd %%ymm7, %0 \n" : "=m"(*ymm4) : : "memory"); if (memcmp(ymm1, ymm3, 32) || memcmp(ymm2, ymm4, 32)) { - test_msg("Data mismatch ('%s' '%s' '%s' '%s')\n", - ymm1, ymm2, ymm3, ymm4); + test_msg("Data mismatch ('%s' '%s' '%s' '%s')\n", ymm1, ymm2, ymm3, ymm4); ret = -1; } else { - test_msg("Data match ('%s' '%s' '%s' '%s')\n", - ymm1, ymm2, ymm3, ymm4); + test_msg("Data match ('%s' '%s' '%s' '%s')\n", ymm1, ymm2, ymm3, ymm4); ret = 0; } diff --git a/test/zdtm/static/fpu02.c b/test/zdtm/static/fpu02.c index 660fc7d59..b201f8081 100644 --- a/test/zdtm/static/fpu02.c +++ b/test/zdtm/static/fpu02.c @@ -10,8 +10,8 @@ #include "cpuid.h" -const char *test_doc = "Test preserve of mxcsr in FPU"; -const char *test_author = "Dmitry Safonov <0x7f454c46@gmail.com>"; +const char *test_doc = "Test preserve of mxcsr in FPU"; +const char *test_author = "Dmitry Safonov <0x7f454c46@gmail.com>"; static int verify_cpu(void) { @@ -36,14 +36,12 @@ static int fpu_test(void) { uint32_t before, after; - asm volatile("stmxcsr %0\n" - : "+m"(before)); + asm volatile("stmxcsr %0\n" : "+m"(before)); test_daemon(); test_waitsig(); - asm volatile("stmxcsr %0\n" - : "+m"(after)); + asm volatile("stmxcsr %0\n" : "+m"(after)); test_msg("before: %x, after: %x\n", before, after); diff --git a/test/zdtm/static/futex-rl.c b/test/zdtm/static/futex-rl.c index a5888a340..e031bfd73 100644 --- a/test/zdtm/static/futex-rl.c +++ b/test/zdtm/static/futex-rl.c @@ -10,12 +10,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check the futex robust list c/r"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check the futex robust list c/r"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; struct args { - task_waiter_t waiter; - int result; + task_waiter_t waiter; + int result; }; static pid_t __gettid(void) diff --git a/test/zdtm/static/futex.c b/test/zdtm/static/futex.c index 5d1f2de86..30bddb3e6 100644 --- a/test/zdtm/static/futex.c +++ b/test/zdtm/static/futex.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check (via pthread/NPTL) that futeces behave through migration"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check (via pthread/NPTL) that futeces behave through migration"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; volatile int kid_passed; @@ -22,12 +22,13 @@ void *thread_fn(void *lock) return NULL; } -#define DEF_NUM_THREADS 10 -#define MAX_NUM_THREADS 50 +#define DEF_NUM_THREADS 10 +#define MAX_NUM_THREADS 50 int num_threads = DEF_NUM_THREADS; -TEST_OPTION(num_threads, int, "number of threads " - "(default " __stringify(DEF_NUM_THREADS) - " maximum " __stringify(MAX_NUM_THREADS) ")", 0); +TEST_OPTION(num_threads, int, + "number of threads " + "(default " __stringify(DEF_NUM_THREADS) " maximum " __stringify(MAX_NUM_THREADS) ")", + 0); int main(int argc, char **argv) { @@ -38,8 +39,7 @@ int main(int argc, char **argv) test_init(argc, argv); if (num_threads > MAX_NUM_THREADS) { - pr_perror("%d threads it too much. max is %d", - num_threads, MAX_NUM_THREADS); + pr_perror("%d threads it too much. max is %d", num_threads, MAX_NUM_THREADS); goto out; } diff --git a/test/zdtm/static/get_smaps_bits.c b/test/zdtm/static/get_smaps_bits.c index 3debaa752..31d0d92b2 100644 --- a/test/zdtm/static/get_smaps_bits.c +++ b/test/zdtm/static/get_smaps_bits.c @@ -3,19 +3,19 @@ #include "zdtmtst.h" #ifndef MAP_HUGETLB -# define MAP_HUGETLB 0x40000 +#define MAP_HUGETLB 0x40000 #endif #ifndef MADV_HUGEPAGE -# define MADV_HUGEPAGE 14 +#define MADV_HUGEPAGE 14 #endif #ifndef MADV_NOHUGEPAGE -# define MADV_NOHUGEPAGE 15 +#define MADV_NOHUGEPAGE 15 #endif #ifndef MADV_DONTDUMP -# define MADV_DONTDUMP 16 +#define MADV_DONTDUMP 16 #endif static void parse_vmflags(char *buf, unsigned long *flags, unsigned long *madv) @@ -66,10 +66,7 @@ static void parse_vmflags(char *buf, unsigned long *flags, unsigned long *madv) #undef _vmflag_match } -#define is_hex_digit(c) \ - (((c) >= '0' && (c) <= '9') || \ - ((c) >= 'a' && (c) <= 'f') || \ - ((c) >= 'A' && (c) <= 'F')) +#define is_hex_digit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) static int is_vma_range_fmt(char *line, unsigned long *start, unsigned long *end) { diff --git a/test/zdtm/static/ghost_holes00.c b/test/zdtm/static/ghost_holes00.c index 214a39141..a87642588 100644 --- a/test/zdtm/static/ghost_holes00.c +++ b/test/zdtm/static/ghost_holes00.c @@ -10,40 +10,40 @@ #include "zdtmtst.h" -const char *test_doc = "Test ghost with one hole in the middle"; +const char *test_doc = "Test ghost with one hole in the middle"; char *filename; TEST_OPTION(filename, string, "file name", 1); /* Buffer that is suitable for hole size */ -#define BUFSIZE 4096 +#define BUFSIZE 4096 static unsigned char buf4k[BUFSIZE]; #ifndef SEEK_DATA -#define SEEK_DATA 3 -#define SEEK_HOLE 4 +#define SEEK_DATA 3 +#define SEEK_HOLE 4 #endif #ifdef HEAD_HOLE -#define HH 1 +#define HH 1 #else -#define HH 0 +#define HH 0 #endif #ifdef TAIL_HOLE -#define TH 1 +#define TH 1 #else -#define TH 0 +#define TH 0 #endif -#define DATA1_BLK (HH) -#define DATA1_OFF (DATA1_BLK * BUFSIZE) -#define DATA2_BLK (HH + 2) -#define DATA2_OFF (DATA2_BLK * BUFSIZE) -#define FILE_BLOCKS (TH + HH + 1 /* mid hole */ + 2 /* data */) -#define FILE_SIZE (FILE_BLOCKS * BUFSIZE) +#define DATA1_BLK (HH) +#define DATA1_OFF (DATA1_BLK * BUFSIZE) +#define DATA2_BLK (HH + 2) +#define DATA2_OFF (DATA2_BLK * BUFSIZE) +#define FILE_BLOCKS (TH + HH + 1 /* mid hole */ + 2 /* data */) +#define FILE_SIZE (FILE_BLOCKS * BUFSIZE) -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; struct stat st; diff --git a/test/zdtm/static/ghost_on_rofs.c b/test/zdtm/static/ghost_on_rofs.c index 1a7922320..7fef8a366 100644 --- a/test/zdtm/static/ghost_on_rofs.c +++ b/test/zdtm/static/ghost_on_rofs.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check ghost file on readonly fs mount restores fine"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check ghost file on readonly fs mount restores fine"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; #define GHOST_DATA "Ghost Data" @@ -70,7 +70,7 @@ int main(int argc, char **argv) } ssprintf(ghost_file, "%s/ghost_file", ro_mount); - fd = open(ghost_file, O_CREAT|O_WRONLY, 0600); + fd = open(ghost_file, O_CREAT | O_WRONLY, 0600); if (fd < 0) { pr_perror("open"); return 1; @@ -82,7 +82,7 @@ int main(int argc, char **argv) } ssprintf(ghost_file_bind, "%s/ghost_file_bind", ro_bind_mount); - fd_bind = open(ghost_file_bind, O_CREAT|O_WRONLY, 0600); + fd_bind = open(ghost_file_bind, O_CREAT | O_WRONLY, 0600); if (fd_bind < 0) { pr_perror("open"); return 1; @@ -118,7 +118,7 @@ int main(int argc, char **argv) return 1; } - if (mount(NULL, ro_mount, NULL, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL)) { + if (mount(NULL, ro_mount, NULL, MS_RDONLY | MS_REMOUNT | MS_BIND, NULL)) { pr_perror("mount"); return 1; } @@ -127,7 +127,7 @@ int main(int argc, char **argv) * Need MS_NOSUID flag to check the hunk in do_bind_mount, case of * different flags for mount and it's ->bind */ - if (mount(NULL, ro_bind_mount, NULL, MS_NOSUID|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL)) { + if (mount(NULL, ro_bind_mount, NULL, MS_NOSUID | MS_RDONLY | MS_REMOUNT | MS_BIND, NULL)) { pr_perror("mount"); return 1; } diff --git a/test/zdtm/static/groups.c b/test/zdtm/static/groups.c index 01ec3a12b..1ff5c08fa 100644 --- a/test/zdtm/static/groups.c +++ b/test/zdtm/static/groups.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that supplementary groups are supported"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that supplementary groups are supported"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/grow_map.c b/test/zdtm/static/grow_map.c index 089ff7d45..6606f972a 100644 --- a/test/zdtm/static/grow_map.c +++ b/test/zdtm/static/grow_map.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that VMA-s with MAP_GROWSDOWN are restored correctly"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check that VMA-s with MAP_GROWSDOWN are restored correctly"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; int main(int argc, char **argv) { @@ -21,9 +21,8 @@ int main(int argc, char **argv) } munmap(start_addr, PAGE_SIZE * 10); - fake_grow_down = mmap(start_addr + PAGE_SIZE * 5, PAGE_SIZE, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0); + fake_grow_down = mmap(start_addr + PAGE_SIZE * 5, PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0); if (fake_grow_down == MAP_FAILED) { pr_perror("Can't mal a new region"); return 1; @@ -34,16 +33,14 @@ int main(int argc, char **argv) *p = 'b'; /* overlap the guard page of fake_grow_down */ - test_addr = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE, - PROT_READ | PROT_WRITE, + test_addr = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); if (test_addr == MAP_FAILED) { pr_perror("Can't mal a new region"); return 1; } - grow_down = mmap(start_addr + PAGE_SIZE * 2, PAGE_SIZE, - PROT_READ | PROT_WRITE, + grow_down = mmap(start_addr + PAGE_SIZE * 2, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0); if (grow_down == MAP_FAILED) { pr_perror("Can't mal a new region"); diff --git a/test/zdtm/static/grow_map02.c b/test/zdtm/static/grow_map02.c index 0b93714f4..4740947d8 100644 --- a/test/zdtm/static/grow_map02.c +++ b/test/zdtm/static/grow_map02.c @@ -7,24 +7,22 @@ #include "zdtmtst.h" -const char *test_doc = "Check that a few grow-down VMA-s are restored correctly"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check that a few grow-down VMA-s are restored correctly"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; int main(int argc, char **argv) { char *start_addr, *grow_down; test_init(argc, argv); - start_addr = mmap(NULL, PAGE_SIZE * 10, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + start_addr = mmap(NULL, PAGE_SIZE * 10, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (start_addr == MAP_FAILED) { pr_perror("Can't mal a new region"); return 1; } munmap(start_addr, PAGE_SIZE * 10); - grow_down = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE * 3, - PROT_READ | PROT_WRITE, + grow_down = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE * 3, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0); if (grow_down == MAP_FAILED) { pr_perror("Can't mal a new region"); @@ -47,8 +45,7 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - test_msg("%c %c %c\n", grow_down[0 * PAGE_SIZE], - grow_down[1 * PAGE_SIZE], grow_down[2 * PAGE_SIZE]); + test_msg("%c %c %c\n", grow_down[0 * PAGE_SIZE], grow_down[1 * PAGE_SIZE], grow_down[2 * PAGE_SIZE]); if (grow_down[0 * PAGE_SIZE] != 'x') return 1; diff --git a/test/zdtm/static/grow_map03.c b/test/zdtm/static/grow_map03.c index 6310386a4..d715223af 100644 --- a/test/zdtm/static/grow_map03.c +++ b/test/zdtm/static/grow_map03.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that VMA-s with MAP_GROWSDOWN are restored correctly"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check that VMA-s with MAP_GROWSDOWN are restored correctly"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; /* * This test case creates two consecutive grows down vmas with a hole @@ -26,8 +26,10 @@ int main(int argc, char **argv) } munmap(start_addr, PAGE_SIZE * 10); - addr1 = mmap(start_addr + PAGE_SIZE * 5, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0); - addr2 = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0); + addr1 = mmap(start_addr + PAGE_SIZE * 5, PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0); + addr2 = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0); test_msg("%p %p\n", addr1, addr2); diff --git a/test/zdtm/static/helper_zombie_child.c b/test/zdtm/static/helper_zombie_child.c index 657d56f27..f4a34e1d0 100644 --- a/test/zdtm/static/helper_zombie_child.c +++ b/test/zdtm/static/helper_zombie_child.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that a zombie with a helper parent is restored"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that a zombie with a helper parent is restored"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; void setsid_and_fork(int sk) { diff --git a/test/zdtm/static/inotify00.c b/test/zdtm/static/inotify00.c index 635c05047..9b24b55be 100644 --- a/test/zdtm/static/inotify00.c +++ b/test/zdtm/static/inotify00.c @@ -18,44 +18,29 @@ #include "zdtmtst.h" -const char *test_doc = "Check for inotify delivery"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for inotify delivery"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_FILE "inotify-removed" -#define TEST_LINK "inotify-hardlink" +#define TEST_FILE "inotify-removed" +#define TEST_LINK "inotify-hardlink" #define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX)) static void decode_event_mask(char *buf, size_t size, unsigned int mask) { static const char *names[32] = { - [ 0] = "IN_ACCESS", - [ 1] = "IN_MODIFY", - [ 2] = "IN_ATTRIB", - [ 3] = "IN_CLOSE_WRITE", - [ 4] = "IN_CLOSE_NOWRITE", - [ 5] = "IN_OPEN", - [ 6] = "IN_MOVED_FROM", - [ 7] = "IN_MOVED_TO", - [ 8] = "IN_CREATE", - [ 9] = "IN_DELETE", - [10] = "IN_DELETE_SELF", - [11] = "IN_MOVE_SELF", - - [13] = "IN_UNMOUNT", - [14] = "IN_Q_OVERFLOW", - [15] = "IN_IGNORED", - - [24] = "IN_ONLYDIR", - [25] = "IN_DONT_FOLLOW", - [26] = "IN_EXCL_UNLINK", - - [29] = "IN_MASK_ADD", - [30] = "IN_ISDIR", - [31] = "IN_ONESHOT", + [0] = "IN_ACCESS", [1] = "IN_MODIFY", [2] = "IN_ATTRIB", [3] = "IN_CLOSE_WRITE", + [4] = "IN_CLOSE_NOWRITE", [5] = "IN_OPEN", [6] = "IN_MOVED_FROM", [7] = "IN_MOVED_TO", + [8] = "IN_CREATE", [9] = "IN_DELETE", [10] = "IN_DELETE_SELF", [11] = "IN_MOVE_SELF", + + [13] = "IN_UNMOUNT", [14] = "IN_Q_OVERFLOW", [15] = "IN_IGNORED", + + [24] = "IN_ONLYDIR", [25] = "IN_DONT_FOLLOW", [26] = "IN_EXCL_UNLINK", + + [29] = "IN_MASK_ADD", [30] = "IN_ISDIR", [31] = "IN_ONESHOT", }; size_t i, j; @@ -95,8 +80,7 @@ static int inotify_read_events(char *prefix, int inotify_fd, unsigned int *expec event = (void *)(buf + off); decode_event_mask(emask, sizeof(emask), event->mask); - test_msg("\t%-16s: event %#10x -> %s\n", - prefix, event->mask, emask); + test_msg("\t%-16s: event %#10x -> %s\n", prefix, event->mask, emask); if (expected) *expected &= ~event->mask; } @@ -107,7 +91,7 @@ out: return ret; } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { unsigned int mask = IN_DELETE | IN_CLOSE_WRITE | IN_DELETE_SELF | IN_CREATE; char test_file_path[PATH_MAX]; @@ -122,51 +106,51 @@ int main (int argc, char *argv[]) } #ifdef INOTIFY01 -{ - pid_t pid; - task_waiter_t t; - static char buf[PATH_MAX]; - - task_waiter_init(&t); + { + pid_t pid; + task_waiter_t t; + static char buf[PATH_MAX]; - if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) { - pr_perror("Unable to remount /"); - return 1; - } - - pid = fork(); - if (pid < 0) { - pr_perror("Can't fork a test process"); - exit(1); - } - if (pid == 0) { - int fd; + task_waiter_init(&t); - prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); - if (unshare(CLONE_NEWNS)) { - pr_perror("Unable to unshare mount namespace"); - exit(1); + if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) { + pr_perror("Unable to remount /"); + return 1; } - if (mount("zdtm", dirname, "tmpfs", 0, NULL)) { - pr_perror("Unable to mount tmpfs"); + pid = fork(); + if (pid < 0) { + pr_perror("Can't fork a test process"); exit(1); } - fd = open(dirname, O_RDONLY); - if (fd < 0) { - pr_perror("Unable to open %s", dirname); + if (pid == 0) { + int fd; + + prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); + if (unshare(CLONE_NEWNS)) { + pr_perror("Unable to unshare mount namespace"); + exit(1); + } + + if (mount("zdtm", dirname, "tmpfs", 0, NULL)) { + pr_perror("Unable to mount tmpfs"); + exit(1); + } + fd = open(dirname, O_RDONLY); + if (fd < 0) { + pr_perror("Unable to open %s", dirname); + exit(1); + } + dup2(fd, 100); + task_waiter_complete_current(&t); + while (1) + sleep(1000); exit(1); } - dup2(fd, 100); - task_waiter_complete_current(&t); - while (1) - sleep(1000); - exit(1); + task_waiter_wait4(&t, pid); + snprintf(buf, sizeof(buf), "/proc/%d/fd/100", pid); + dirname = buf; } - task_waiter_wait4(&t, pid); - snprintf(buf, sizeof(buf), "/proc/%d/fd/100", pid); - dirname = buf; -} #endif fd = inotify_init1(IN_NONBLOCK); @@ -210,8 +194,7 @@ int main (int argc, char *argv[]) if (emask) { char emask_bits[128]; decode_event_mask(emask_bits, sizeof(emask_bits), emask); - pr_perror("Unhandled events in emask %#x -> %s", - emask, emask_bits); + pr_perror("Unhandled events in emask %#x -> %s", emask, emask_bits); exit(1); } #endif @@ -226,8 +209,7 @@ int main (int argc, char *argv[]) if (emask) { char emask_bits[128]; decode_event_mask(emask_bits, sizeof(emask_bits), emask); - fail("Unhandled events in emask %#x -> %s", - emask, emask_bits); + fail("Unhandled events in emask %#x -> %s", emask, emask_bits); return 1; } @@ -244,8 +226,7 @@ int main (int argc, char *argv[]) if (emask) { char emask_bits[128]; decode_event_mask(emask_bits, sizeof(emask_bits), emask); - fail("Unhandled events in emask %#x -> %s", - emask, emask_bits); + fail("Unhandled events in emask %#x -> %s", emask, emask_bits); return 1; } #endif diff --git a/test/zdtm/static/inotify02.c b/test/zdtm/static/inotify02.c index bedfefac9..44fcdc875 100644 --- a/test/zdtm/static/inotify02.c +++ b/test/zdtm/static/inotify02.c @@ -18,8 +18,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check for inotify file-handles storm"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for inotify file-handles storm"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -48,7 +48,7 @@ static int num_of_handles(int fd) return ret; } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { const unsigned int mask = IN_DELETE | IN_CLOSE_WRITE | IN_DELETE_SELF | IN_CREATE; const int nr_dirs = 64; diff --git a/test/zdtm/static/inotify04.c b/test/zdtm/static/inotify04.c index fb9293024..96f7b215f 100644 --- a/test/zdtm/static/inotify04.c +++ b/test/zdtm/static/inotify04.c @@ -8,13 +8,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check inotify does not have trash in queue after c/r"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check inotify does not have trash in queue after c/r"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_FILE "inotify-testfile" +#define TEST_FILE "inotify-testfile" #define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX)) @@ -49,7 +49,7 @@ static int inotify_read_events(int inotify_fd, unsigned int *n) return ret; } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { unsigned int mask = IN_ALL_EVENTS; char test_file_path[PATH_MAX]; diff --git a/test/zdtm/static/inotify_irmap.c b/test/zdtm/static/inotify_irmap.c index cf35886e2..f8e35222c 100644 --- a/test/zdtm/static/inotify_irmap.c +++ b/test/zdtm/static/inotify_irmap.c @@ -14,15 +14,15 @@ #include "zdtmtst.h" -const char *test_doc = "Check for irmap"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check for irmap"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; -#define TDIR "/etc" -char test_files[2][128] = {TDIR"/zdtm-test", TDIR"/zdtm-test1"}; +#define TDIR "/etc" +char test_files[2][128] = { TDIR "/zdtm-test", TDIR "/zdtm-test1" }; #define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX)) -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { char buf[BUFF_SIZE]; int fd, wd, i; diff --git a/test/zdtm/static/inotify_system.c b/test/zdtm/static/inotify_system.c index 3d2355436..487062cab 100644 --- a/test/zdtm/static/inotify_system.c +++ b/test/zdtm/static/inotify_system.c @@ -13,7 +13,7 @@ #include "zdtmtst.h" -const char *test_doc = "Inotify on symlink should be checked"; +const char *test_doc = "Inotify on symlink should be checked"; #ifndef NODEL char filename[] = "file"; char linkname[] = "file.lnk"; @@ -29,34 +29,35 @@ const char *inot_dir = "./inotify.nodel"; #ifndef IN_DONT_FOLLOW /* Missed in SLES 10 header */ -#define IN_DONT_FOLLOW 0x02000000 +#define IN_DONT_FOLLOW 0x02000000 #endif #define EVENT_MAX 1024 /* size of the event structure, not counting name */ -#define EVENT_SIZE (sizeof (struct inotify_event)) +#define EVENT_SIZE (sizeof(struct inotify_event)) /* reasonable guess as to size of 1024 events */ -#define EVENT_BUF_LEN (EVENT_MAX * (EVENT_SIZE + 16)) -#define BUF_SIZE 256 - -#define min_value(a,b) (a<b) ? a : b -#define handle_event(MASK) (MASK == IN_ACCESS) ? "IN_ACCESS" : \ -(MASK == IN_MODIFY) ? "IN_MODIFY" : \ -(MASK == IN_ATTRIB) ? "IN_ATTRIB" : \ -(MASK == IN_CLOSE) ? "IN_CLOSE" : \ -(MASK == IN_CLOSE_WRITE) ? "IN_CLOSE_WRITE" : \ -(MASK == IN_CLOSE_NOWRITE) ? "IN_CLOSE_NOWRITE" : \ -(MASK == IN_OPEN) ? "IN_OPEN" : \ -(MASK == IN_MOVED_FROM) ? "IN_MOVED_FROM" : \ -(MASK == IN_MOVED_TO) ? "IN_MOVED_TO" : \ -(MASK == IN_DELETE) ? "IN_DELETE" : \ -(MASK == IN_CREATE) ? "IN_CREATE" : \ -(MASK == IN_DELETE_SELF) ? "IN_DELETE_SELF" : \ -(MASK == IN_MOVE_SELF) ? "IN_MOVE_SELF" : \ -(MASK == IN_UNMOUNT) ? "IN_UNMOUNT" : \ -(MASK == IN_Q_OVERFLOW) ? "IN_Q_OVERFLOW" : \ -(MASK == IN_IGNORED) ? "IN_IGNORED" : \ -"UNKNOWN" +#define EVENT_BUF_LEN (EVENT_MAX * (EVENT_SIZE + 16)) +#define BUF_SIZE 256 + +#define min_value(a, b) (a < b) ? a : b +#define handle_event(MASK) \ + (MASK == IN_ACCESS) ? "IN_ACCESS" : \ + (MASK == IN_MODIFY) ? "IN_MODIFY" : \ + (MASK == IN_ATTRIB) ? "IN_ATTRIB" : \ + (MASK == IN_CLOSE) ? "IN_CLOSE" : \ + (MASK == IN_CLOSE_WRITE) ? "IN_CLOSE_WRITE" : \ + (MASK == IN_CLOSE_NOWRITE) ? "IN_CLOSE_NOWRITE" : \ + (MASK == IN_OPEN) ? "IN_OPEN" : \ + (MASK == IN_MOVED_FROM) ? "IN_MOVED_FROM" : \ + (MASK == IN_MOVED_TO) ? "IN_MOVED_TO" : \ + (MASK == IN_DELETE) ? "IN_DELETE" : \ + (MASK == IN_CREATE) ? "IN_CREATE" : \ + (MASK == IN_DELETE_SELF) ? "IN_DELETE_SELF" : \ + (MASK == IN_MOVE_SELF) ? "IN_MOVE_SELF" : \ + (MASK == IN_UNMOUNT) ? "IN_UNMOUNT" : \ + (MASK == IN_Q_OVERFLOW) ? "IN_Q_OVERFLOW" : \ + (MASK == IN_IGNORED) ? "IN_IGNORED" : \ + "UNKNOWN" #include <unistd.h> #include <fcntl.h> @@ -68,14 +69,16 @@ typedef struct { int dir; } desc; -void do_wait(void) { +void do_wait(void) +{ test_daemon(); test_waitsig(); } -int createFiles(char *path, char *target, char *link) { +int createFiles(char *path, char *target, char *link) +{ int fd; - fd = open(path,O_CREAT, 0644); + fd = open(path, O_CREAT, 0644); if (fd < 0) { pr_perror("can't open %s", path); return -1; @@ -88,18 +91,19 @@ int createFiles(char *path, char *target, char *link) { return 0; } -int addWatcher(int fd, const char *path) { +int addWatcher(int fd, const char *path) +{ int wd; wd = inotify_add_watch(fd, path, IN_ALL_EVENTS | IN_DONT_FOLLOW); if (wd < 0) { - pr_perror("inotify_add_watch(%d, %s, IN_ALL_EVENTS) failed", - fd, path); + pr_perror("inotify_add_watch(%d, %s, IN_ALL_EVENTS) failed", fd, path); return -1; } return wd; } -int fChmod(char *path) { +int fChmod(char *path) +{ if (chmod(path, 0755) < 0) { pr_perror("chmod(%s, 0755) failed", path); return -1; @@ -107,7 +111,8 @@ int fChmod(char *path) { return 0; } -int fWriteClose(char *path) { +int fWriteClose(char *path) +{ int fd = open(path, O_RDWR | O_CREAT, 0700); if (fd == -1) { pr_perror("open(%s, O_RDWR|O_CREAT, 0700) failed", path); @@ -124,10 +129,11 @@ int fWriteClose(char *path) { return 0; } -int fNoWriteClose(char *path) { +int fNoWriteClose(char *path) +{ char buf[BUF_SIZE]; int fd = open(path, O_RDONLY); - if ( fd < 0 ) { + if (fd < 0) { pr_perror("open(%s, O_RDONLY) failed", path); return -1; } @@ -143,7 +149,8 @@ int fNoWriteClose(char *path) { return 0; } -int fMove(char *from, char *to) { +int fMove(char *from, char *to) +{ if (rename(from, to) == -1) { pr_perror("rename error (from: %s to: %s)", from, to); return -1; @@ -151,8 +158,9 @@ int fMove(char *from, char *to) { return 0; } -desc init_env(const char *dir, char *file_path, char *link_path) { - desc in_desc = {-1, -1, -1, -1}; +desc init_env(const char *dir, char *file_path, char *link_path) +{ + desc in_desc = { -1, -1, -1, -1 }; if (mkdir(dir, 0777) < 0) { pr_perror("mkdir(%s)", dir); return in_desc; @@ -186,7 +194,8 @@ desc init_env(const char *dir, char *file_path, char *link_path) { return in_desc; } -int fDelete(char *path) { +int fDelete(char *path) +{ if (unlink(path) != 0) { pr_perror("unlink(%s)", path); return -1; @@ -194,39 +203,34 @@ int fDelete(char *path) { return 0; } -int fRemDir(const char *target) { - if(rmdir(target)) { +int fRemDir(const char *target) +{ + if (rmdir(target)) { pr_perror("rmdir(%s)", target); return -1; } return 0; } -int test_actions(const char *dir, char *file_path, char *link_path) { - - if ( - fChmod(link_path) == 0 && - fWriteClose(link_path) == 0 && - fNoWriteClose(link_path) == 0 && - fMove(file_path, filename) == 0 && - fMove(filename, file_path) == 0 +int test_actions(const char *dir, char *file_path, char *link_path) +{ + if (fChmod(link_path) == 0 && fWriteClose(link_path) == 0 && fNoWriteClose(link_path) == 0 && + fMove(file_path, filename) == 0 && fMove(filename, file_path) == 0 #ifndef NODEL - && fDelete(file_path) == 0 && - fDelete(link_path) == 0 && - fRemDir(dir) == 0 + && fDelete(file_path) == 0 && fDelete(link_path) == 0 && fRemDir(dir) == 0 #endif - ) - { + ) { return 0; } return -1; } -void dump_events(char *buf, int len) { +void dump_events(char *buf, int len) +{ int marker = 0; struct inotify_event *event; while (marker < len) { - event = (struct inotify_event *) &buf[marker]; + event = (struct inotify_event *)&buf[marker]; test_msg("\t%s (%x mask, %d len", handle_event(event->mask), event->mask, event->len); if (event->len) test_msg(", '%s' name", event->name); @@ -238,88 +242,85 @@ void dump_events(char *buf, int len) { int harmless(int mask) { switch (mask) { - case IN_CLOSE_NOWRITE: - case IN_ATTRIB: - return 1; + case IN_CLOSE_NOWRITE: + case IN_ATTRIB: + return 1; } return 0; } -int errors(int exp_len, int len, char *etalon_buf, char *buf) { - int marker=0; - int error=0; - while (marker < len){ +int errors(int exp_len, int len, char *etalon_buf, char *buf) +{ + int marker = 0; + int error = 0; + while (marker < len) { struct inotify_event *event; struct inotify_event *exp_event; - event = (struct inotify_event *) &buf[marker]; + event = (struct inotify_event *)&buf[marker]; /* It's OK if some additional events are recevived */ if (marker < exp_len) - exp_event = (struct inotify_event *) &etalon_buf[marker]; + exp_event = (struct inotify_event *)&etalon_buf[marker]; else { if (!harmless(event->mask)) { - fail("got unexpected event %s (%x mask)", - handle_event(event->mask), event->mask); + fail("got unexpected event %s (%x mask)", handle_event(event->mask), event->mask); error++; } goto next_event; } if (event->mask != exp_event->mask) { - fail("Handled %s (%x mask), expected %s (%x mask)", - handle_event(event->mask), event->mask, - handle_event(exp_event->mask), - exp_event->mask); - error++; + fail("Handled %s (%x mask), expected %s (%x mask)", handle_event(event->mask), event->mask, + handle_event(exp_event->mask), exp_event->mask); + error++; } if (event->len != exp_event->len) { fail("Incorrect length of field name."); error++; break; } else if (event->len && strncmp(event->name, exp_event->name, event->len)) { - fail("Handled file name %s, expected %s", - event->name, - exp_event->name); - error++; + fail("Handled file name %s, expected %s", event->name, exp_event->name); + error++; } -next_event: + next_event: marker += EVENT_SIZE + event->len; } return error; } -int read_set(int inot_fd, char *event_set) { +int read_set(int inot_fd, char *event_set) +{ int len; if ((len = read(inot_fd, event_set, EVENT_BUF_LEN)) < 0) { - pr_perror("read(%d, buf, %lu) failed", - inot_fd, (unsigned long)EVENT_BUF_LEN); + pr_perror("read(%d, buf, %lu) failed", inot_fd, (unsigned long)EVENT_BUF_LEN); return -1; } return len; } -void common_close(desc *descr) { +void common_close(desc *descr) +{ if (descr->inot > 0) { close(descr->inot); - descr->inot=-1; - descr->file=-1; - descr->dir=-1; - descr->link=-1; + descr->inot = -1; + descr->file = -1; + descr->dir = -1; + descr->link = -1; } } -int get_event_set(char *event_set, int wait) { +int get_event_set(char *event_set, int wait) +{ int len; char link_path[BUF_SIZE]; char file_path[BUF_SIZE]; desc common_desc; common_desc = init_env(inot_dir, file_path, link_path); - if ((common_desc.inot < 0) || (common_desc.file < 0) || \ - (common_desc.dir < 0) || (common_desc.link < 0)) { + if ((common_desc.inot < 0) || (common_desc.file < 0) || (common_desc.dir < 0) || (common_desc.link < 0)) { common_close(&common_desc); return -1; } - if(test_actions(inot_dir, file_path, link_path) < 0) { + if (test_actions(inot_dir, file_path, link_path) < 0) { common_close(&common_desc); return -1; } @@ -329,17 +330,15 @@ int get_event_set(char *event_set, int wait) { len = read_set(common_desc.inot, event_set); common_close(&common_desc); #ifdef NODEL - if (! (fDelete(file_path) == 0 && - fDelete(link_path) == 0 && - fRemDir(inot_dir) == 0)) + if (!(fDelete(file_path) == 0 && fDelete(link_path) == 0 && fRemDir(inot_dir) == 0)) return -1; #endif return len; } -int check(int len, char *event_set, int exp_len, char *etalon_event_set) { - - if ((exp_len < 0) || (len < 0)){ +int check(int len, char *event_set, int exp_len, char *etalon_event_set) +{ + if ((exp_len < 0) || (len < 0)) { fail("Error in preparing event sets."); return -1; } @@ -358,9 +357,9 @@ int check(int len, char *event_set, int exp_len, char *etalon_event_set) { return -1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { - int exp_len=-1, len=-1; + int exp_len = -1, len = -1; char etalon_event_set[EVENT_BUF_LEN]; char event_set[EVENT_BUF_LEN]; @@ -376,7 +375,7 @@ int main(int argc, char ** argv) } #else -int main(int argc, char ** argv) +int main(int argc, char **argv) { test_init(argc, argv); skip("Inotify not supported."); diff --git a/test/zdtm/static/ipc_namespace.c b/test/zdtm/static/ipc_namespace.c index da400db6c..98241d816 100644 --- a/test/zdtm/static/ipc_namespace.c +++ b/test/zdtm/static/ipc_namespace.c @@ -11,61 +11,61 @@ #include "zdtmtst.h" -#define CLONE_NEWIPC 0x08000000 +#define CLONE_NEWIPC 0x08000000 -extern int msgctl (int __msqid, int __cmd, struct msqid_ds *__buf); -extern int semctl (int __semid, int __semnum, int __cmd, ...); -extern int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf); +extern int msgctl(int __msqid, int __cmd, struct msqid_ds *__buf); +extern int semctl(int __semid, int __semnum, int __cmd, ...); +extern int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf); struct ipc_ids { - int in_use; /* TODO: Check for 0 */ -// unsigned short seq; -// unsigned short seq_max; -// struct rw_semaphore rw_mutex; -// struct idr ipcs_idr; /* TODO */ + int in_use; /* TODO: Check for 0 */ + // unsigned short seq; + // unsigned short seq_max; + // struct rw_semaphore rw_mutex; + // struct idr ipcs_idr; /* TODO */ }; struct ipc_ns { - struct ipc_ids ids[3]; + struct ipc_ids ids[3]; - int sem_ctls[4]; // + - int used_sems; // + + int sem_ctls[4]; // + + int used_sems; // + - int msg_ctlmax; // + - int msg_ctlmnb; // + - int msg_ctlmni; // + - int msg_bytes; // + - int msg_hdrs; // + - int auto_msgmni; // + - int msg_next_id; // + - int sem_next_id; // + - int shm_next_id; // + + int msg_ctlmax; // + + int msg_ctlmnb; // + + int msg_ctlmni; // + + int msg_bytes; // + + int msg_hdrs; // + + int auto_msgmni; // + + int msg_next_id; // + + int sem_next_id; // + + int shm_next_id; // + - size_t shm_ctlmax; - size_t shm_ctlall; - int shm_ctlmni; - int shm_tot; - int shm_rmid_forced; + size_t shm_ctlmax; + size_t shm_ctlall; + int shm_ctlmni; + int shm_tot; + int shm_rmid_forced; -// struct vfsmount *mq_mnt; + // struct vfsmount *mq_mnt; -// unsigned int mq_queues_count; + // unsigned int mq_queues_count; - unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */ - unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */ - unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */ - unsigned int mq_msg_default; /* initialized to DFLT_MSG */ - unsigned int mq_msgsize_default; /* initialized to DFLT_MSGSIZE */ + unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */ + unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */ + unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */ + unsigned int mq_msg_default; /* initialized to DFLT_MSG */ + unsigned int mq_msgsize_default; /* initialized to DFLT_MSGSIZE */ struct user_ns *user_ns; }; -#define IPC_SEM_IDS 0 -#define IPC_MSG_IDS 1 -#define IPC_SHM_IDS 2 +#define IPC_SEM_IDS 0 +#define IPC_MSG_IDS 1 +#define IPC_SHM_IDS 2 -const char *test_doc = "Check that ipc ns context migrated successfully"; -const char *test_author = "Stanislav Kinsbursky <skinsbursky@parallels.com>"; +const char *test_doc = "Check that ipc ns context migrated successfully"; +const char *test_author = "Stanislav Kinsbursky <skinsbursky@parallels.com>"; struct ipc_ns ipc_before, ipc_after; @@ -111,32 +111,26 @@ static int get_messages_info(struct ipc_ns *ipc) ipc->msg_hdrs = info.msgmap; ipc->ids[IPC_MSG_IDS].in_use = info.msgpool; - if (read_ipc_sysctl("/proc/sys/kernel/auto_msgmni", - &ipc->auto_msgmni, sizeof(ipc->auto_msgmni))) + if (read_ipc_sysctl("/proc/sys/kernel/auto_msgmni", &ipc->auto_msgmni, sizeof(ipc->auto_msgmni))) return -1; - if (read_ipc_sysctl("/proc/sys/kernel/msg_next_id", - &ipc->msg_next_id, sizeof(ipc->msg_next_id))) + if (read_ipc_sysctl("/proc/sys/kernel/msg_next_id", &ipc->msg_next_id, sizeof(ipc->msg_next_id))) return -1; - if (read_ipc_sysctl("/proc/sys/kernel/sem_next_id", - &ipc->sem_next_id, sizeof(ipc->sem_next_id))) + if (read_ipc_sysctl("/proc/sys/kernel/sem_next_id", &ipc->sem_next_id, sizeof(ipc->sem_next_id))) return -1; - if (read_ipc_sysctl("/proc/sys/kernel/shm_next_id", - &ipc->shm_next_id, sizeof(ipc->shm_next_id))) + if (read_ipc_sysctl("/proc/sys/kernel/shm_next_id", &ipc->shm_next_id, sizeof(ipc->shm_next_id))) return -1; - if (read_ipc_sysctl("/proc/sys/fs/mqueue/queues_max", - (int *)&ipc->mq_queues_max, sizeof(ipc->mq_queues_max))) + if (read_ipc_sysctl("/proc/sys/fs/mqueue/queues_max", (int *)&ipc->mq_queues_max, sizeof(ipc->mq_queues_max))) return -1; - if (read_ipc_sysctl("/proc/sys/fs/mqueue/msg_max", - (int *)&ipc->mq_msg_max, sizeof(ipc->mq_msg_max))) + if (read_ipc_sysctl("/proc/sys/fs/mqueue/msg_max", (int *)&ipc->mq_msg_max, sizeof(ipc->mq_msg_max))) return -1; - if (read_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_max", - (int *)&ipc->mq_msgsize_max, sizeof(ipc->mq_msgsize_max))) + if (read_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_max", (int *)&ipc->mq_msgsize_max, + sizeof(ipc->mq_msgsize_max))) return -1; - if (read_ipc_sysctl("/proc/sys/fs/mqueue/msg_default", - (int *)&ipc->mq_msg_default, sizeof(ipc->mq_msg_default))) + if (read_ipc_sysctl("/proc/sys/fs/mqueue/msg_default", (int *)&ipc->mq_msg_default, + sizeof(ipc->mq_msg_default))) return -1; - if (read_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_default", - (int *)&ipc->mq_msgsize_default, sizeof(ipc->mq_msgsize_default))) + if (read_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_default", (int *)&ipc->mq_msgsize_default, + sizeof(ipc->mq_msgsize_default))) return -1; return 0; @@ -185,14 +179,12 @@ static int get_shared_memory_info(struct ipc_ns *ipc) ipc->shm_tot = u.shminfo.shm_tot; ipc->ids[IPC_SHM_IDS].in_use = u.shminfo.used_ids; - if (read_ipc_sysctl("/proc/sys/kernel/shm_rmid_forced", - &ipc->shm_rmid_forced, sizeof(ipc->shm_rmid_forced))) + if (read_ipc_sysctl("/proc/sys/kernel/shm_rmid_forced", &ipc->shm_rmid_forced, sizeof(ipc->shm_rmid_forced))) return -1; return 0; } - int fill_ipc_ns(struct ipc_ns *ipc) { int ret; @@ -238,7 +230,7 @@ static int rand_ipc_sysctl(char *name, unsigned int val) return 0; } -#define MAX_MNI (1<<15) +#define MAX_MNI (1 << 15) static int rand_ipc_sem(void) { @@ -252,8 +244,8 @@ static int rand_ipc_sem(void) pr_perror("Can't open %s", name); return fd; } - sprintf(buf, "%d %d %d %d\n", (unsigned) lrand48(), (unsigned) lrand48(), - (unsigned) lrand48(), (unsigned) lrand48() % MAX_MNI); + sprintf(buf, "%d %d %d %d\n", (unsigned)lrand48(), (unsigned)lrand48(), (unsigned)lrand48(), + (unsigned)lrand48() % MAX_MNI); ret = write(fd, buf, 128); if (ret < 0) { pr_perror("Can't write %s", name); @@ -291,17 +283,18 @@ static int rand_ipc_ns(void) if (!ret) ret = rand_ipc_sysctl("/proc/sys/kernel/shm_rmid_forced", (unsigned)lrand48() & 1); - if (!ret) ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/queues_max", (((unsigned)lrand48()) % 1023) + 1); if (!ret) ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/msg_max", ((unsigned)lrand48() % 65536) + 1); if (!ret) - ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_max", ((unsigned)lrand48() & (8192 * 128 - 1)) | 128); + ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_max", + ((unsigned)lrand48() & (8192 * 128 - 1)) | 128); if (!ret) ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/msg_default", ((unsigned)lrand48() % 65536) + 1); if (!ret) - ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_default", ((unsigned)lrand48() & (8192 * 128 - 1)) | 128); + ret = rand_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_default", + ((unsigned)lrand48() & (8192 * 128 - 1)) | 128); if (ret < 0) pr_err("Failed to randomize ipc namespace tunables\n"); @@ -315,65 +308,45 @@ static void show_ipc_entry(struct ipc_ns *old, struct ipc_ns *new) for (i = 0; i < 3; i++) { if (old->ids[i].in_use != new->ids[i].in_use) - pr_err("ids[%d].in_use differs: %d ---> %d\n", i, - old->ids[i].in_use, new->ids[i].in_use); - + pr_err("ids[%d].in_use differs: %d ---> %d\n", i, old->ids[i].in_use, new->ids[i].in_use); } for (i = 0; i < 4; i++) { if (old->sem_ctls[i] != new->sem_ctls[i]) - pr_err("sem_ctls[%d] differs: %d ---> %d\n", i, - old->sem_ctls[i], new->sem_ctls[i]); - + pr_err("sem_ctls[%d] differs: %d ---> %d\n", i, old->sem_ctls[i], new->sem_ctls[i]); } if (old->msg_ctlmax != new->msg_ctlmax) - pr_err("msg_ctlmax differs: %d ---> %d\n", - old->msg_ctlmax, new->msg_ctlmax); + pr_err("msg_ctlmax differs: %d ---> %d\n", old->msg_ctlmax, new->msg_ctlmax); if (old->msg_ctlmnb != new->msg_ctlmnb) - pr_err("msg_ctlmnb differs: %d ---> %d\n", - old->msg_ctlmnb, new->msg_ctlmnb); + pr_err("msg_ctlmnb differs: %d ---> %d\n", old->msg_ctlmnb, new->msg_ctlmnb); if (old->msg_ctlmni != new->msg_ctlmni) - pr_err("msg_ctlmni differs: %d ---> %d\n", - old->msg_ctlmni, new->msg_ctlmni); + pr_err("msg_ctlmni differs: %d ---> %d\n", old->msg_ctlmni, new->msg_ctlmni); if (old->auto_msgmni != new->auto_msgmni) - pr_err("auto_msgmni differs: %d ---> %d\n", - old->auto_msgmni, new->auto_msgmni); + pr_err("auto_msgmni differs: %d ---> %d\n", old->auto_msgmni, new->auto_msgmni); if (old->msg_next_id != new->msg_next_id) - pr_err("msg_next_id differs: %d ---> %d\n", - old->msg_next_id, new->msg_next_id); + pr_err("msg_next_id differs: %d ---> %d\n", old->msg_next_id, new->msg_next_id); if (old->sem_next_id != new->sem_next_id) - pr_err("sem_next_id differs: %d ---> %d\n", - old->sem_next_id, new->sem_next_id); + pr_err("sem_next_id differs: %d ---> %d\n", old->sem_next_id, new->sem_next_id); if (old->shm_next_id != new->shm_next_id) - pr_err("shm_next_id differs: %d ---> %d\n", - old->shm_next_id, new->shm_next_id); + pr_err("shm_next_id differs: %d ---> %d\n", old->shm_next_id, new->shm_next_id); if (old->shm_ctlmax != new->shm_ctlmax) - pr_err("shm_ctlmax differs: %zu ---> %zu\n", - old->shm_ctlmax, new->shm_ctlmax); + pr_err("shm_ctlmax differs: %zu ---> %zu\n", old->shm_ctlmax, new->shm_ctlmax); if (old->shm_ctlall != new->shm_ctlall) - pr_err("shm_ctlall differs: %zu ---> %zu\n", - old->shm_ctlall, new->shm_ctlall); + pr_err("shm_ctlall differs: %zu ---> %zu\n", old->shm_ctlall, new->shm_ctlall); if (old->shm_ctlmni != new->shm_ctlmni) - pr_err("shm_ctlmni differs: %d ---> %d\n", - old->shm_ctlmni, new->shm_ctlmni); + pr_err("shm_ctlmni differs: %d ---> %d\n", old->shm_ctlmni, new->shm_ctlmni); if (old->shm_rmid_forced != new->shm_rmid_forced) - pr_err("shm_rmid_forced differs: %d ---> %d\n", - old->shm_rmid_forced, new->shm_rmid_forced); + pr_err("shm_rmid_forced differs: %d ---> %d\n", old->shm_rmid_forced, new->shm_rmid_forced); if (old->mq_queues_max != new->mq_queues_max) - pr_err("mq_queues_max differs: %d ---> %d\n", - old->mq_queues_max, new->mq_queues_max); + pr_err("mq_queues_max differs: %d ---> %d\n", old->mq_queues_max, new->mq_queues_max); if (old->mq_msg_max != new->mq_msg_max) - pr_err("mq_msg_max differs: %d ---> %d\n", - old->mq_msg_max, new->mq_msg_max); + pr_err("mq_msg_max differs: %d ---> %d\n", old->mq_msg_max, new->mq_msg_max); if (old->mq_msgsize_max != new->mq_msgsize_max) - pr_err("mq_msgsize_max differs: %d ---> %d\n", - old->mq_msgsize_max, new->mq_msgsize_max); + pr_err("mq_msgsize_max differs: %d ---> %d\n", old->mq_msgsize_max, new->mq_msgsize_max); if (old->mq_msg_default != new->mq_msg_default) - pr_err("mq_msg_default differs: %d ---> %d\n", - old->mq_msg_default, new->mq_msg_default); + pr_err("mq_msg_default differs: %d ---> %d\n", old->mq_msg_default, new->mq_msg_default); if (old->mq_msgsize_default != new->mq_msgsize_default) - pr_err("mq_msgsize_default differs: %d ---> %d\n", - old->mq_msgsize_default, new->mq_msgsize_default); + pr_err("mq_msgsize_default differs: %d ---> %d\n", old->mq_msgsize_default, new->mq_msgsize_default); } int main(int argc, char **argv) diff --git a/test/zdtm/static/jobctl00.c b/test/zdtm/static/jobctl00.c index a14c4a768..e842d418e 100644 --- a/test/zdtm/static/jobctl00.c +++ b/test/zdtm/static/jobctl00.c @@ -9,24 +9,27 @@ #include "zdtmtst.h" -const char *test_doc = "Check that job control migrates correctly"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that job control migrates correctly"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; -#define JOBS_DEF 8 -#define JOBS_MAX 64 +#define JOBS_DEF 8 +#define JOBS_MAX 64 unsigned int num_jobs = JOBS_DEF; -TEST_OPTION(num_jobs, uint, "# \"jobs\" in a \"shell\" " - "(default " __stringify(JOBS_DEF) - ", max " __stringify(JOBS_MAX) ")", 0); +TEST_OPTION(num_jobs, uint, + "# \"jobs\" in a \"shell\" " + "(default " __stringify(JOBS_DEF) ", max " __stringify(JOBS_MAX) ")", + 0); -#define PROCS_DEF 4 +#define PROCS_DEF 4 unsigned int num_procs = PROCS_DEF; -TEST_OPTION(num_procs, uint, "# processes in a \"job\" " - "(default " __stringify(PROCS_DEF) ")", 0); +TEST_OPTION(num_procs, uint, + "# processes in a \"job\" " + "(default " __stringify(PROCS_DEF) ")", + 0); static const char wr_string[] = "All you need is love!\n"; static const char rd_string[] = "We all live in a yellow submarine\n"; -static const char susp_char = '\032'; /* ^Z */ +static const char susp_char = '\032'; /* ^Z */ static volatile sig_atomic_t signo = 0; @@ -47,12 +50,12 @@ static int wait4sig(int sig) sigset_t mask, oldmask; sigemptyset(&mask); sigaddset(&mask, sig); - sigaddset(&mask, SIGCHLD); /* to see our children die */ + sigaddset(&mask, SIGCHLD); /* to see our children die */ sigprocmask(SIG_BLOCK, &mask, &oldmask); while (!signo) - sigsuspend (&oldmask); - sigprocmask (SIG_UNBLOCK, &mask, NULL); + sigsuspend(&oldmask); + sigprocmask(SIG_UNBLOCK, &mask, NULL); return signo != sig; } @@ -68,8 +71,7 @@ static int is_fg(void) static int reader(int sig) { char str[sizeof(rd_string) + 1]; - return read(0, str, sizeof(str)) < 0 || - strcmp(str, rd_string); + return read(0, str, sizeof(str)) < 0 || strcmp(str, rd_string); } static int post_reader(int fd) @@ -107,30 +109,30 @@ static struct job_type { int (*action)(int sig); int (*post)(int fd); } job_types[] = { - { SIGTTOU, writer, post_writer }, - { SIGTTIN, reader, post_reader }, - { SIGCONT, wait4sig, NULL }, + { SIGTTOU, writer, post_writer }, + { SIGTTIN, reader, post_reader }, + { SIGCONT, wait4sig, NULL }, }; static int process(int (*action)(int), int sig) { int ret; - if (is_fg()) /* we must be in background on entry */ + if (is_fg()) /* we must be in background on entry */ return 1; if (signal(sig, record_and_raise_sig) == SIG_ERR) return 2; - kill(getppid(), SIGUSR2); /* tell the parent we're ready */ + kill(getppid(), SIGUSR2); /* tell the parent we're ready */ - ret = action(sig); /* will be busy doing nothing for the duration of migration */ + ret = action(sig); /* will be busy doing nothing for the duration of migration */ if (ret) return 3; - if (!is_fg()) /* we must be in foreground now */ + if (!is_fg()) /* we must be in foreground now */ return 4; - ret = signo != sig; /* have we got the desired signal? */ + ret = signo != sig; /* have we got the desired signal? */ test_waitsig(); return ret; @@ -144,22 +146,22 @@ static int job(int (*action)(int), int sig) return 1; for (i = num_procs; i; i--) { - pid_t pid = fork(); + pid_t pid = fork(); if (pid < 0) - kill(0, SIGKILL); /* kill the whole job */ + kill(0, SIGKILL); /* kill the whole job */ if (pid == 0) /* the last is worker, others are sleepers */ - exit(process(i == 1 ? action : wait4sig, sig)); + exit(process(i == 1 ? action : wait4sig, sig)); /* wait for the child to grow up before going to next one * ignore return code as the child may get stopped and SIGCHILD * us */ wait4sig(SIGUSR2); - signo = 0; /* rearm sighandler */ + signo = 0; /* rearm sighandler */ } - kill(getppid(), SIGUSR2); /* tell the parent we're ready */ + kill(getppid(), SIGUSR2); /* tell the parent we're ready */ /* we (or our children) will get suspended somehow here, so the rest * will hopefully happen after migration */ @@ -195,8 +197,7 @@ int start_jobs(pid_t *jobs, int njobs, int fdmaster, int fdslave) /* the children will signal readiness via SIGUSR2 or get stopped (or * exit :) and signal that via SIGCHLD */ - if (signal(SIGUSR2, record_sig) == SIG_ERR || - signal(SIGCHLD, record_sig) == SIG_ERR) { + if (signal(SIGUSR2, record_sig) == SIG_ERR || signal(SIGCHLD, record_sig) == SIG_ERR) { pr_perror("can't install signal handler"); return -1; } @@ -205,7 +206,7 @@ int start_jobs(pid_t *jobs, int njobs, int fdmaster, int fdslave) int jtno = i % (sizeof(job_types) / sizeof(job_types[0])); jobs[i] = fork(); - if (jobs[i] < 0) { /* we're busted - bail out */ + if (jobs[i] < 0) { /* we're busted - bail out */ pr_perror("fork failed"); goto killout; } @@ -222,7 +223,7 @@ int start_jobs(pid_t *jobs, int njobs, int fdmaster, int fdslave) /* wait for the child to grow up before proceeding */ wait4sig(SIGUSR2); - signo = 0; /* rearm sighandler */ + signo = 0; /* rearm sighandler */ } return 0; @@ -236,7 +237,7 @@ int finish_jobs(pid_t *jobs, int njobs, int fdmaster, int fdslave) { int i; - for (i = num_jobs; i--; ) { + for (i = num_jobs; i--;) { int ret; int jtno = i % (sizeof(job_types) / sizeof(job_types[0])); @@ -265,7 +266,7 @@ killout: return -1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fdmaster, fdslave; pid_t jobs[JOBS_MAX] = {}; diff --git a/test/zdtm/static/link10.c b/test/zdtm/static/link10.c index 9deb4a127..a0a00d661 100644 --- a/test/zdtm/static/link10.c +++ b/test/zdtm/static/link10.c @@ -9,13 +9,13 @@ #include "zdtmtst.h" -const char *test_doc = "Migrate two hardlinked, open, and unlinked files"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Migrate two hardlinked, open, and unlinked files"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd, fd2 = 0; struct stat stat, stat2; @@ -23,8 +23,7 @@ int main(int argc, char ** argv) test_init(argc, argv); - if (snprintf(filename2, sizeof(filename2), "%s.lnk", filename) >= - sizeof(filename2)) { + if (snprintf(filename2, sizeof(filename2), "%s.lnk", filename) >= sizeof(filename2)) { pr_perror("filename %s is too long", filename); exit(1); } @@ -57,11 +56,9 @@ int main(int argc, char ** argv) goto out; } - if (stat.st_ino != stat2.st_ino || - stat.st_dev != stat2.st_dev) { - fail("files are different: st_ino %lu != %lu or st_dev %lu != %lu", - (long unsigned)stat.st_ino, (long unsigned)stat2.st_ino, - (long unsigned)stat.st_dev, (long unsigned)stat2.st_dev); + if (stat.st_ino != stat2.st_ino || stat.st_dev != stat2.st_dev) { + fail("files are different: st_ino %lu != %lu or st_dev %lu != %lu", (long unsigned)stat.st_ino, + (long unsigned)stat2.st_ino, (long unsigned)stat.st_dev, (long unsigned)stat2.st_dev); } pass(); diff --git a/test/zdtm/static/loginuid.c b/test/zdtm/static/loginuid.c index dc27eeef3..dcd6ce04b 100644 --- a/test/zdtm/static/loginuid.c +++ b/test/zdtm/static/loginuid.c @@ -66,7 +66,6 @@ int set_loginuid(const char *path, uid_t value) return ret; } - int main(int argc, char *argv[]) { int ret; @@ -89,8 +88,7 @@ int main(int argc, char *argv[]) return -1; if (new_loginuid != test_value) { - fail("loginuid value %d is different after restore: %d", - test_value, new_loginuid); + fail("loginuid value %d is different after restore: %d", test_value, new_loginuid); return -1; } diff --git a/test/zdtm/static/macvlan.c b/test/zdtm/static/macvlan.c index 0d5feb233..1c78807c8 100644 --- a/test/zdtm/static/macvlan.c +++ b/test/zdtm/static/macvlan.c @@ -13,11 +13,11 @@ #include <net/if.h> #include "zdtmtst.h" -const char *test_doc = "check that macvlan interfaces are c/r'd correctly"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "check that macvlan interfaces are c/r'd correctly"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #define BRIDGE_NAME "zdtmbr0" -#define IF_NAME "zdtmmvlan0" +#define IF_NAME "zdtmmvlan0" static bool wait_for_macvlan(void) { diff --git a/test/zdtm/static/maps00.c b/test/zdtm/static/maps00.c index 9ed248d4d..10a4cac79 100644 --- a/test/zdtm/static/maps00.c +++ b/test/zdtm/static/maps00.c @@ -10,9 +10,9 @@ #include <sys/stat.h> #include "zdtmtst.h" -const char *test_doc = "Create all sorts of maps and compare /proc/pid/maps\n" - "before and after migration\n"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Create all sorts of maps and compare /proc/pid/maps\n" + "before and after migration\n"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -23,9 +23,9 @@ const static int map_prots[] = { PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE | PROT_EXEC, }; -#define NUM_MPROTS sizeof(map_prots) / sizeof(int) -#define RW_PROT(x) ((x) & (PROT_READ | PROT_WRITE)) -#define X_PROT(x) ((x) & PROT_EXEC) +#define NUM_MPROTS sizeof(map_prots) / sizeof(int) +#define RW_PROT(x) ((x) & (PROT_READ | PROT_WRITE)) +#define X_PROT(x) ((x)&PROT_EXEC) int check_prot(int src_prot, int dst_prot) { @@ -37,21 +37,15 @@ int check_prot(int src_prot, int dst_prot) ** * A is a subset of B iff (A & B) == A */ - return (X_PROT(dst_prot) & X_PROT(src_prot)) == X_PROT(dst_prot); + return (X_PROT(dst_prot) & X_PROT(src_prot)) == X_PROT(dst_prot); } -const static int map_flags[] = { - MAP_PRIVATE, - MAP_SHARED, - MAP_PRIVATE | MAP_ANONYMOUS, - MAP_SHARED | MAP_ANONYMOUS -}; -#define NUM_MFLAGS sizeof(map_flags) / sizeof(int) -#define NUM_MAPS NUM_MPROTS * NUM_MFLAGS -#define ONE_MAP_SIZE 0x2000 +const static int map_flags[] = { MAP_PRIVATE, MAP_SHARED, MAP_PRIVATE | MAP_ANONYMOUS, MAP_SHARED | MAP_ANONYMOUS }; +#define NUM_MFLAGS sizeof(map_flags) / sizeof(int) +#define NUM_MAPS NUM_MPROTS *NUM_MFLAGS +#define ONE_MAP_SIZE 0x2000 -struct map -{ +struct map { int prot; int prot_real; int flag; @@ -75,8 +69,7 @@ static int make_map(struct map *map) if (!(map->flag & MAP_ANONYMOUS)) { /* need file */ - if (snprintf(map->filename, sizeof(map->filename), - "%s-%02d", filename, i++) >= sizeof(map->filename)) { + if (snprintf(map->filename, sizeof(map->filename), "%s-%02d", filename, i++) >= sizeof(map->filename)) { pr_perror("filename %s is too long", filename); return -1; } @@ -107,13 +100,12 @@ static int make_map(struct map *map) datagen(map->ptr, ONE_MAP_SIZE, &crc); } - test_msg("map: ptr %p flag %8x prot %8x\n", - map->ptr, map->flag, map->prot); + test_msg("map: ptr %p flag %8x prot %8x\n", map->ptr, map->flag, map->prot); return 0; } -static sigjmp_buf segv_ret; /* we need sig*jmp stuff, otherwise SIGSEGV will reset our handler */ +static sigjmp_buf segv_ret; /* we need sig*jmp stuff, otherwise SIGSEGV will reset our handler */ static void segfault(int signo) { siglongjmp(segv_ret, 1); @@ -131,19 +123,16 @@ static int check_map(struct map *map) { int prot = PROT_WRITE | PROT_READ | PROT_EXEC; - if (signal(SIGSEGV, segfault) == SIG_ERR) - { + if (signal(SIGSEGV, segfault) == SIG_ERR) { fail("setting SIGSEGV handler failed"); return -1; } - if (!sigsetjmp(segv_ret, 1)) - { + if (!sigsetjmp(segv_ret, 1)) { uint32_t crc = ~0; - if (datachk(map->ptr, ONE_MAP_SIZE, &crc)) /* perform read access */ + if (datachk(map->ptr, ONE_MAP_SIZE, &crc)) /* perform read access */ if (!(map->flag & MAP_ANONYMOUS) || - (map->prot & PROT_WRITE)) { /* anon maps could only be filled when r/w */ - fail("CRC mismatch: ptr %p flag %8x prot %8x", - map->ptr, map->flag, map->prot); + (map->prot & PROT_WRITE)) { /* anon maps could only be filled when r/w */ + fail("CRC mismatch: ptr %p flag %8x prot %8x", map->ptr, map->flag, map->prot); return -1; } /* prot |= PROT_READ// need barrier before this line, @@ -152,33 +141,29 @@ static int check_map(struct map *map) } else prot &= PROT_WRITE | !PROT_READ | PROT_EXEC; - if (signal(SIGSEGV, segfault) == SIG_ERR) - { + if (signal(SIGSEGV, segfault) == SIG_ERR) { fail("setting SIGSEGV handler failed"); return -1; } - if (!sigsetjmp(segv_ret, 1)) - { - * (int *) (map->ptr) = 1234; /* perform write access */ + if (!sigsetjmp(segv_ret, 1)) { + *(int *)(map->ptr) = 1234; /* perform write access */ } else prot &= !PROT_WRITE | PROT_READ | PROT_EXEC; - if (signal(SIGSEGV, segfault) == SIG_ERR) - { + if (signal(SIGSEGV, segfault) == SIG_ERR) { fail("restoring SIGSEGV handler failed"); return -1; } - if (!sigsetjmp(segv_ret, 1)) - { + if (!sigsetjmp(segv_ret, 1)) { if (map->prot & PROT_WRITE) { - memcpy(map->ptr,test_func, getpagesize()); + memcpy(map->ptr, test_func, getpagesize()); } else { if (!(map->flag & MAP_ANONYMOUS)) { uint8_t funlen = (uint8_t *)check_map - (uint8_t *)test_func; - lseek(map->fd,0,SEEK_SET); - if (write(map->fd,test_func,funlen)<funlen) { + lseek(map->fd, 0, SEEK_SET); + if (write(map->fd, test_func, funlen) < funlen) { pr_perror("failed to write %s", map->filename); return -1; } @@ -186,7 +171,7 @@ static int check_map(struct map *map) } if (!(map->flag & MAP_ANONYMOUS) || map->prot & PROT_WRITE) /* Function body has been copied into the mapping */ - ((int (*)(void))map->ptr)(); /* perform exec access */ + ((int (*)(void))map->ptr)(); /* perform exec access */ else /* No way to copy function body into mapping, * clear exec bit from effective protection @@ -195,8 +180,7 @@ static int check_map(struct map *map) } else prot &= PROT_WRITE | PROT_READ | !PROT_EXEC; - if (signal(SIGSEGV, SIG_DFL) == SIG_ERR) - { + if (signal(SIGSEGV, SIG_DFL) == SIG_ERR) { fail("restoring SIGSEGV handler failed"); return -1; } @@ -208,17 +192,15 @@ static void destroy_map(struct map *map) { munmap(map->ptr, ONE_MAP_SIZE); - if (map->fd >= 0) - { + if (map->fd >= 0) { close(map->fd); unlink(map->filename); } } +#define MAPS_LEN 0x10000 -#define MAPS_LEN 0x10000 - -int main(int argc, char ** argv) +int main(int argc, char **argv) { struct map maps[NUM_MAPS] = {}, maps_compare[NUM_MAPS] = {}; int i, j, k; @@ -237,22 +219,22 @@ int main(int argc, char ** argv) test_waitsig(); for (i = 0; i < NUM_MAPS; i++) - if ((maps[i].prot_real=check_map(maps + i))<0) + if ((maps[i].prot_real = check_map(maps + i)) < 0) goto err; - k=0; + k = 0; for (i = 0; i < NUM_MPROTS; i++) for (j = 0; j < NUM_MFLAGS; j++) init_map(maps_compare + k++, i, j); for (i = 0; i < NUM_MAPS; i++) - if (make_map(maps_compare+ i)) + if (make_map(maps_compare + i)) goto err; for (i = 0; i < NUM_MAPS; i++) - if ((maps_compare[i].prot_real=check_map(maps_compare + i))<0) + if ((maps_compare[i].prot_real = check_map(maps_compare + i)) < 0) goto err; - for (i = 0; i< NUM_MAPS; i++) - if (!check_prot(maps[i].prot_real, maps_compare[i].prot_real)){ - fail("protection on %i (flag=%d prot=%d) maps has changed (prot=%d(expected %d))", - i, maps[i].flag, maps[i].prot, maps[i].prot_real, maps_compare[i].prot_real); + for (i = 0; i < NUM_MAPS; i++) + if (!check_prot(maps[i].prot_real, maps_compare[i].prot_real)) { + fail("protection on %i (flag=%d prot=%d) maps has changed (prot=%d(expected %d))", i, + maps[i].flag, maps[i].prot, maps[i].prot_real, maps_compare[i].prot_real); goto err; } diff --git a/test/zdtm/static/maps01.c b/test/zdtm/static/maps01.c index 2bb465a25..9b8019ee2 100644 --- a/test/zdtm/static/maps01.c +++ b/test/zdtm/static/maps01.c @@ -11,15 +11,15 @@ #include <linux/limits.h> #include "zdtmtst.h" -#define MEM_SIZE (1LU << 30) -#define MEM_OFFSET (1LU << 29) +#define MEM_SIZE (1LU << 30) +#define MEM_OFFSET (1LU << 29) #define MEM_OFFSET2 (MEM_SIZE - PAGE_SIZE) #define MEM_OFFSET3 (20LU * PAGE_SIZE) -const char *test_doc = "Test shared memory"; -const char *test_author = "Andrew Vagin <avagin@openvz.org"; +const char *test_doc = "Test shared memory"; +const char *test_author = "Andrew Vagin <avagin@openvz.org"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { void *m, *m2, *p, *p2; char path[PATH_MAX]; @@ -32,28 +32,23 @@ int main(int argc, char ** argv) task_waiter_init(&t); - m = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, - MAP_SHARED | MAP_ANONYMOUS, -1, 0); + m = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (m == MAP_FAILED) { - pr_perror("Failed to mmap %lu Mb shared anonymous R/W memory", - MEM_SIZE >> 20); + pr_perror("Failed to mmap %lu Mb shared anonymous R/W memory", MEM_SIZE >> 20); goto err; } - p = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, - MAP_SHARED | MAP_ANONYMOUS, -1, 0); + p = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { - pr_perror("Failed to mmap %ld Mb shared anonymous R/W memory", - MEM_SIZE >> 20); + pr_perror("Failed to mmap %ld Mb shared anonymous R/W memory", MEM_SIZE >> 20); goto err; } p2 = mmap(NULL, MEM_OFFSET, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (p2 == MAP_FAILED) { - pr_perror("Failed to mmap %lu Mb anonymous memory", - MEM_OFFSET >> 20); + pr_perror("Failed to mmap %lu Mb anonymous memory", MEM_OFFSET >> 20); goto err; } @@ -64,11 +59,9 @@ int main(int argc, char ** argv) } else if (pid == 0) { void *p3; - p3 = mmap(NULL, MEM_OFFSET3, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + p3 = mmap(NULL, MEM_OFFSET3, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (p3 == MAP_FAILED) { - pr_perror("Failed to mmap %lu Mb anonymous R/W memory", - MEM_OFFSET3 >> 20); + pr_perror("Failed to mmap %lu Mb anonymous R/W memory", MEM_OFFSET3 >> 20); goto err; } @@ -122,9 +115,7 @@ int main(int argc, char ** argv) if (p2 == MAP_FAILED) goto err; - snprintf(path, PATH_MAX, "/proc/self/map_files/%lx-%lx", - (unsigned long) m, - (unsigned long) m + MEM_SIZE); + snprintf(path, PATH_MAX, "/proc/self/map_files/%lx-%lx", (unsigned long)m, (unsigned long)m + MEM_SIZE); fd = open(path, O_RDWR); if (fd == -1) { pr_perror("Can't open file %s", path); diff --git a/test/zdtm/static/maps02.c b/test/zdtm/static/maps02.c index eb7c09bdc..29f1372c9 100644 --- a/test/zdtm/static/maps02.c +++ b/test/zdtm/static/maps02.c @@ -3,26 +3,25 @@ #include "get_smaps_bits.h" #ifndef MADV_DONTDUMP -#define MADV_DONTDUMP 16 +#define MADV_DONTDUMP 16 #endif -const char *test_doc = "Test shared memory with advises"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Test shared memory with advises"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; struct mmap_data { - void *start; - unsigned long orig_flags; - unsigned long orig_madv; - unsigned long new_flags; - unsigned long new_madv; + void *start; + unsigned long orig_flags; + unsigned long orig_madv; + unsigned long new_flags; + unsigned long new_madv; }; #define MEM_SIZE (8192) static int alloc_anon_mmap(struct mmap_data *m, int flags, int adv) { - m->start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, - flags, -1, 0); + m->start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, flags, -1, 0); if (m->start == MAP_FAILED) { pr_perror("mmap failed"); return -1; @@ -32,7 +31,7 @@ static int alloc_anon_mmap(struct mmap_data *m, int flags, int adv) if (errno == EINVAL) { test_msg("madvise failed, no kernel support\n"); munmap(m->start, MEM_SIZE); - *m = (struct mmap_data){ }; + *m = (struct mmap_data){}; } else { pr_perror("madvise failed"); return -1; @@ -44,7 +43,7 @@ static int alloc_anon_mmap(struct mmap_data *m, int flags, int adv) int main(int argc, char **argv) { - struct mmap_data m[5] = { }; + struct mmap_data m[5] = {}; size_t i; test_init(argc, argv); @@ -70,10 +69,8 @@ int main(int argc, char **argv) return -1; test_msg("Fetch existing flags/adv\n"); - for (i = 0; i < sizeof(m)/sizeof(m[0]); i++) { - if (get_smaps_bits((unsigned long)m[i].start, - &m[i].orig_flags, - &m[i].orig_madv)) + for (i = 0; i < sizeof(m) / sizeof(m[0]); i++) { + if (get_smaps_bits((unsigned long)m[i].start, &m[i].orig_flags, &m[i].orig_madv)) return -1; } @@ -81,28 +78,23 @@ int main(int argc, char **argv) test_waitsig(); test_msg("Fetch restored flags/adv\n"); - for (i = 0; i < sizeof(m)/sizeof(m[0]); i++) { - if (get_smaps_bits((unsigned long)m[i].start, - &m[i].new_flags, - &m[i].new_madv)) + for (i = 0; i < sizeof(m) / sizeof(m[0]); i++) { + if (get_smaps_bits((unsigned long)m[i].start, &m[i].new_flags, &m[i].new_madv)) return -1; if (m[i].orig_flags != m[i].new_flags) { - pr_perror("Flags are changed %lx %lx -> %lx (%zu)", - (unsigned long)m[i].start, - m[i].orig_flags, m[i].new_flags, i); + pr_perror("Flags are changed %lx %lx -> %lx (%zu)", (unsigned long)m[i].start, m[i].orig_flags, + m[i].new_flags, i); fail(); return -1; } if (m[i].orig_madv != m[i].new_madv) { - pr_perror("Madvs are changed %lx %lx -> %lx (%zu)", - (unsigned long)m[i].start, - m[i].orig_madv, m[i].new_madv, i); + pr_perror("Madvs are changed %lx %lx -> %lx (%zu)", (unsigned long)m[i].start, m[i].orig_madv, + m[i].new_madv, i); fail(); return -1; } - } pass(); diff --git a/test/zdtm/static/maps03.c b/test/zdtm/static/maps03.c index 17299d551..064811c15 100644 --- a/test/zdtm/static/maps03.c +++ b/test/zdtm/static/maps03.c @@ -4,15 +4,15 @@ #include <limits.h> #include "zdtmtst.h" -#if (LONG_MAX == 2147483647L) /* 32 bit */ +#if (LONG_MAX == 2147483647L) /* 32 bit */ #define TEST_SKIP_REASON "64-bit arch required" #include "skip-me.c" #else -const char *test_doc = "Test for huge VMA area"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Test for huge VMA area"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; int main(int argc, char **argv) { @@ -21,8 +21,7 @@ int main(int argc, char **argv) test_init(argc, argv); test_msg("Alloc huge VMA\n"); - mem = (void *)mmap(NULL, (10L << 30), PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + mem = (void *)mmap(NULL, (10L << 30), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if ((void *)mem == MAP_FAILED) { pr_perror("mmap failed"); return -1; diff --git a/test/zdtm/static/maps04.c b/test/zdtm/static/maps04.c index 780c5667d..dbbb5c644 100644 --- a/test/zdtm/static/maps04.c +++ b/test/zdtm/static/maps04.c @@ -13,10 +13,10 @@ #define MEM_SIZE (1L << 29) -const char *test_doc = "Test big mappings"; -const char *test_author = "Andrew Vagin <avagin@openvz.org"; +const char *test_doc = "Test big mappings"; +const char *test_author = "Andrew Vagin <avagin@openvz.org"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { void *m; uint32_t crc; @@ -24,8 +24,7 @@ int main(int argc, char ** argv) test_init(argc, argv); - m = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + m = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (m == MAP_FAILED) { fail(); @@ -35,7 +34,7 @@ int main(int argc, char ** argv) crc = ~0; datagen(m, MEM_SIZE, &crc); - for (i = 0; i < MEM_SIZE / (1<<20); i++) + for (i = 0; i < MEM_SIZE / (1 << 20); i++) if (mprotect(m + (lrand48() * PAGE_SIZE % MEM_SIZE), PAGE_SIZE, PROT_NONE)) { pr_perror("mprotect"); return 1; diff --git a/test/zdtm/static/maps05.c b/test/zdtm/static/maps05.c index faa09ee9a..be8f2309b 100644 --- a/test/zdtm/static/maps05.c +++ b/test/zdtm/static/maps05.c @@ -10,20 +10,20 @@ #include <sys/stat.h> #include "zdtmtst.h" -const char *test_doc = "Create a bunch of small VMAs and test they survive transferring\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Create a bunch of small VMAs and test they survive transferring\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; -#define NR_MAPS 4096 +#define NR_MAPS 4096 -#define NR_MAPS_1 (NR_MAPS + 0) -#define NR_MAPS_2 (NR_MAPS + 1) +#define NR_MAPS_1 (NR_MAPS + 0) +#define NR_MAPS_2 (NR_MAPS + 1) -#define MAPS_SIZE_1 (140 << 10) -#define MAPS_SIZE_2 (8192) +#define MAPS_SIZE_1 (140 << 10) +#define MAPS_SIZE_2 (8192) int main(int argc, char *argv[]) { - void *map[NR_MAPS + 2] = { }, *addr; + void *map[NR_MAPS + 2] = {}, *addr; size_t i, summary; test_init(argc, argv); diff --git a/test/zdtm/static/maps06.c b/test/zdtm/static/maps06.c index 7480d6b24..6f7028ace 100644 --- a/test/zdtm/static/maps06.c +++ b/test/zdtm/static/maps06.c @@ -4,13 +4,13 @@ #include <sys/stat.h> #include <fcntl.h> -const char *test_doc = "Create a lot of file vma-s"; -const char *test_author = "Andrei Vagin <avagin@openvz.org>"; +const char *test_doc = "Create a lot of file vma-s"; +const char *test_author = "Andrei Vagin <avagin@openvz.org>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { void *start; int fd, i; @@ -36,15 +36,12 @@ int main(int argc, char ** argv) for (i = 0; i < test_size; i++) { int *addr; - addr = mmap(start + i * 3 * ps, ps, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, 0); + addr = mmap(start + i * 3 * ps, ps, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, 0); if (addr == MAP_FAILED) return 1; addr[0] = i * 2; - addr = mmap(start + (i * 3 + 1) * ps, ps, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + addr = mmap(start + (i * 3 + 1) * ps, ps, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); if (addr == MAP_FAILED) return 1; addr[0] = i; @@ -59,7 +56,7 @@ int main(int argc, char ** argv) addr = start + i * 3 * ps; if (addr[0] != i * 2) fail(); - addr = start + (i * 3 + 1) * ps; + addr = start + (i * 3 + 1) * ps; if (addr[0] != i) fail(); } diff --git a/test/zdtm/static/maps_file_prot.c b/test/zdtm/static/maps_file_prot.c index 3b28c1ff1..434cf075f 100644 --- a/test/zdtm/static/maps_file_prot.c +++ b/test/zdtm/static/maps_file_prot.c @@ -7,15 +7,19 @@ #include <linux/limits.h> #include "zdtmtst.h" -const char *test_doc = "Test mappings of same file with different prot"; -const char *test_author = "Jamie Liu <jamieliu@google.com>"; +const char *test_doc = "Test mappings of same file with different prot"; +const char *test_author = "Jamie Liu <jamieliu@google.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -#define die(fmt, arg...) do { pr_perror(fmt, ## arg); return 1; } while (0) +#define die(fmt, arg...) \ + do { \ + pr_perror(fmt, ##arg); \ + return 1; \ + } while (0) -int main(int argc, char ** argv) +int main(int argc, char **argv) { void *ro_map, *rw_map; int fd; diff --git a/test/zdtm/static/mem-touch.c b/test/zdtm/static/mem-touch.c index b11c97f53..fb7f13528 100644 --- a/test/zdtm/static/mem-touch.c +++ b/test/zdtm/static/mem-touch.c @@ -7,10 +7,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check changing memory"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check changing memory"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; -#define MEM_PAGES 16 +#define MEM_PAGES 16 int main(int argc, char **argv) { @@ -32,7 +32,10 @@ int main(int argc, char **argv) test_daemon(); while (test_go()) { unsigned pfn; - struct timespec req = { .tv_sec = 0, .tv_nsec = 100000, }; + struct timespec req = { + .tv_sec = 0, + .tv_nsec = 100000, + }; pfn = random() % MEM_PAGES; *(unsigned *)(mem + pfn * PAGE_SIZE) = rover; @@ -46,8 +49,7 @@ int main(int argc, char **argv) test_msg("final rover %u\n", rover); for (i = 0; i < MEM_PAGES; i++) if (backup[i] != *(unsigned *)(mem + i * PAGE_SIZE)) { - test_msg("Page %u differs want %u has %u\n", i, - backup[i], *(unsigned *)(mem + i * PAGE_SIZE)); + test_msg("Page %u differs want %u has %u\n", i, backup[i], *(unsigned *)(mem + i * PAGE_SIZE)); fail = 1; } else test_msg("Page %u matches %u\n", i, backup[i]); @@ -59,4 +61,3 @@ int main(int argc, char **argv) return 0; } - diff --git a/test/zdtm/static/memfd00.c b/test/zdtm/static/memfd00.c index 6b56eca01..d037f6969 100644 --- a/test/zdtm/static/memfd00.c +++ b/test/zdtm/static/memfd00.c @@ -12,10 +12,14 @@ #include "zdtmtst.h" -const char *test_doc = "memfd file descriptor"; -const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; - -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +const char *test_doc = "memfd file descriptor"; +const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; + +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) static int _memfd_create(const char *name, unsigned int flags) { diff --git a/test/zdtm/static/memfd01.c b/test/zdtm/static/memfd01.c index 7a7853642..90ff80fa2 100644 --- a/test/zdtm/static/memfd01.c +++ b/test/zdtm/static/memfd01.c @@ -13,10 +13,14 @@ #include "zdtmtst.h" -const char *test_doc = "memfd with different file pointer"; -const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; - -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +const char *test_doc = "memfd with different file pointer"; +const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; + +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) static int _memfd_create(const char *name, unsigned int flags) { diff --git a/test/zdtm/static/memfd02.c b/test/zdtm/static/memfd02.c index 1843e9c9a..12e294921 100644 --- a/test/zdtm/static/memfd02.c +++ b/test/zdtm/static/memfd02.c @@ -13,10 +13,14 @@ #include "zdtmtst.h" -const char *test_doc = "memfd mmap"; -const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; - -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +const char *test_doc = "memfd mmap"; +const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; + +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) static int _memfd_create(const char *name, unsigned int flags) { diff --git a/test/zdtm/static/memfd03.c b/test/zdtm/static/memfd03.c index faedf9383..c25e211dd 100644 --- a/test/zdtm/static/memfd03.c +++ b/test/zdtm/static/memfd03.c @@ -13,35 +13,37 @@ #include "zdtmtst.h" -const char *test_doc = "memfd seals"; -const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; +const char *test_doc = "memfd seals"; +const char *test_author = "Nicolas Viennot <Nicolas.Viennot@twosigma.com>"; -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) static int _memfd_create(const char *name, unsigned int flags) { return syscall(SYS_memfd_create, name, flags); } - #ifndef F_LINUX_SPECIFIC_BASE -# define F_LINUX_SPECIFIC_BASE 1024 +#define F_LINUX_SPECIFIC_BASE 1024 #endif #ifndef F_ADD_SEALS - #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) #endif #ifndef F_GET_SEALS - #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) #endif - #ifndef F_SEAL_SEAL -#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ -#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ -#define F_SEAL_GROW 0x0004 /* prevent file from growing */ -#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ #endif int main(int argc, char *argv[]) diff --git a/test/zdtm/static/mlock_setuid.c b/test/zdtm/static/mlock_setuid.c index d8aec8315..86df7fd62 100644 --- a/test/zdtm/static/mlock_setuid.c +++ b/test/zdtm/static/mlock_setuid.c @@ -15,15 +15,13 @@ int main(int argc, char **argv) test_init(argc, argv); test_msg("Alloc vma of size %d\n", MEM_SIZE); - start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (start == MAP_FAILED) { pr_perror("mmap failed"); return -1; } - test_msg("Lock vma from %p to %lx\n", - start, (unsigned long)start + MEM_SIZE); + test_msg("Lock vma from %p to %lx\n", start, (unsigned long)start + MEM_SIZE); ret = mlock(start, MEM_SIZE); if (ret < 0) { pr_perror("mlock"); diff --git a/test/zdtm/static/mmx00.c b/test/zdtm/static/mmx00.c index b736a80a1..cf9419b63 100644 --- a/test/zdtm/static/mmx00.c +++ b/test/zdtm/static/mmx00.c @@ -3,43 +3,33 @@ #include "zdtmtst.h" -const char *test_doc = "Start a calculation, leaving MMX in a certain state,\n" -"before migration, continue after"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Start a calculation, leaving MMX in a certain state,\n" + "before migration, continue after"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; #if defined(__i386__) || defined(__x86_64__) void start(uint8_t *bytes, uint16_t *words) { - __asm__ volatile ( - "movq %0, %%mm0\n" - "movq %1, %%mm1\n" - "movq %2, %%mm2\n" - "movq %3, %%mm3\n" - "paddb %%mm0, %%mm1\n" - "psubw %%mm2, %%mm3\n" - : - : "m" (bytes[0]), "m" (bytes[8]), - "m" (words[0]), "m" (words[4]) - ); + __asm__ volatile("movq %0, %%mm0\n" + "movq %1, %%mm1\n" + "movq %2, %%mm2\n" + "movq %3, %%mm3\n" + "paddb %%mm0, %%mm1\n" + "psubw %%mm2, %%mm3\n" + : + : "m"(bytes[0]), "m"(bytes[8]), "m"(words[0]), "m"(words[4])); } void finish(uint8_t *bytes, uint16_t *words) { - __asm__ volatile ( - "movq %%mm1, %0\n" - "movq %%mm3, %1\n" - : "=m" (bytes[0]), "=m" (words[0]) - ); + __asm__ volatile("movq %%mm1, %0\n" + "movq %%mm3, %1\n" + : "=m"(bytes[0]), "=m"(words[0])); } static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { - __asm__("cpuid" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (op), "c"(0)); + __asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(op), "c"(0)); } int chk_proc_mmx(void) @@ -54,12 +44,12 @@ int chk_proc_mmx(void) int main(int argc, char **argv) { #if defined(__i386__) || defined(__x86_64__) - uint8_t bytes[16]; + uint8_t bytes[16]; uint16_t words[8]; uint32_t rnd[8]; int i; - uint8_t resbytes1[8], resbytes2[8]; + uint8_t resbytes1[8], resbytes2[8]; uint16_t reswords1[4], reswords2[4]; #endif @@ -73,8 +63,8 @@ int main(int argc, char **argv) for (i = 0; i < (sizeof(bytes) + sizeof(words)) / 4; i++) rnd[i] = mrand48(); - memcpy((uint8_t *) bytes, (uint8_t *) rnd, sizeof(bytes)); - memcpy((uint8_t *) words, (uint8_t *) rnd + sizeof(bytes), sizeof(words)); + memcpy((uint8_t *)bytes, (uint8_t *)rnd, sizeof(bytes)); + memcpy((uint8_t *)words, (uint8_t *)rnd + sizeof(bytes), sizeof(words)); start(bytes, words); finish(resbytes1, reswords1); @@ -86,9 +76,9 @@ int main(int argc, char **argv) finish(resbytes2, reswords2); - if (memcmp((uint8_t *) resbytes1, (uint8_t *) resbytes2, sizeof(resbytes1))) + if (memcmp((uint8_t *)resbytes1, (uint8_t *)resbytes2, sizeof(resbytes1))) fail("byte op mismatch"); - else if (memcmp((uint8_t *) reswords1, (uint8_t *) reswords2, sizeof(reswords2))) + else if (memcmp((uint8_t *)reswords1, (uint8_t *)reswords2, sizeof(reswords2))) fail("word op mismatch"); else pass(); diff --git a/test/zdtm/static/mnt_enablefs.c b/test/zdtm/static/mnt_enablefs.c index 3de4c57eb..6f0cb9363 100644 --- a/test/zdtm/static/mnt_enablefs.c +++ b/test/zdtm/static/mnt_enablefs.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check enabled file systems (--enable-fs)"; -const char *test_author = "Andrei Vagin <avagin@virtuozzo.com>"; +const char *test_doc = "Check enabled file systems (--enable-fs)"; +const char *test_author = "Andrei Vagin <avagin@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/mnt_ext_auto.c b/test/zdtm/static/mnt_ext_auto.c index 9181b370a..977dfdbf8 100644 --- a/test/zdtm/static/mnt_ext_auto.c +++ b/test/zdtm/static/mnt_ext_auto.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check --mnt-ext-map"; -const char *test_author = "Andrew Vagin <avagin@gmail.com>"; +const char *test_doc = "Check --mnt-ext-map"; +const char *test_author = "Andrew Vagin <avagin@gmail.com>"; #ifdef ZDTM_EXTMAP_MANUAL char *dirname = "mnt_ext_manual.test"; @@ -19,25 +19,25 @@ char *dirname_private_shared_bind = "mnt_ext_manual_private_shared_bind.test"; char *dirname_bind = "mnt_ext_manual_bind.test"; char *dirname_slave_shared_bind = "mnt_ext_manual_slave_shared_bind.test"; char *dirname_slave_bind = "mnt_ext_manual_slave_bind.test"; -#define DDIR "mtest" +#define DDIR "mtest" #else char *dirname = "mnt_ext_auto.test"; char *dirname_private_shared_bind = "mnt_ext_auto_private_shared_bind.test"; char *dirname_bind = "mnt_ext_auto_bind.test"; char *dirname_slave_shared_bind = "mnt_ext_auto_slave_shared_bind.test"; char *dirname_slave_bind = "mnt_ext_auto_slave_bind.test"; -#define DDIR "atest" +#define DDIR "atest" #endif TEST_OPTION(dirname, string, "directory name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { char src[PATH_MAX], dst[PATH_MAX], *root; - char dst_bind[PATH_MAX], dst_private_shared_bind[PATH_MAX], - dst_slave_shared_bind[PATH_MAX], dst_slave_bind[PATH_MAX]; + char dst_bind[PATH_MAX], dst_private_shared_bind[PATH_MAX], dst_slave_shared_bind[PATH_MAX], + dst_slave_bind[PATH_MAX]; char *dname = "/tmp/zdtm_ext_auto.XXXXXX"; struct stat sta, stb, bsta, bstb, ssbsta, sbsta, ssbstb, sbstb, psbsta, psbstb; - char* zdtm_newns = getenv("ZDTM_NEWNS"); + char *zdtm_newns = getenv("ZDTM_NEWNS"); root = getenv("ZDTM_ROOT"); if (root == NULL) { diff --git a/test/zdtm/static/mnt_ext_dev.c b/test/zdtm/static/mnt_ext_dev.c index 1d60fc92f..2035a4cfb 100644 --- a/test/zdtm/static/mnt_ext_dev.c +++ b/test/zdtm/static/mnt_ext_dev.c @@ -11,8 +11,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check mounts of external devices"; -const char *test_author = "Andrei Vagin <avagin@virtuozzo.com"; +const char *test_doc = "Check mounts of external devices"; +const char *test_author = "Andrei Vagin <avagin@virtuozzo.com"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/mnt_ext_master.c b/test/zdtm/static/mnt_ext_master.c index 12e9ebab1..5fd8fa8b2 100644 --- a/test/zdtm/static/mnt_ext_master.c +++ b/test/zdtm/static/mnt_ext_master.c @@ -11,13 +11,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check that mounts with external master peers are c/r'd"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that mounts with external master peers are c/r'd"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname = "mnt_ext_auto.test"; TEST_OPTION(dirname, string, "directory name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { char src[PATH_MAX], dst[PATH_MAX], *root; char *dname = "/tmp/zdtm_ext_auto.XXXXXX"; @@ -64,7 +64,6 @@ test: test_daemon(); test_waitsig(); - pass(); return 0; diff --git a/test/zdtm/static/mnt_ro_bind.c b/test/zdtm/static/mnt_ro_bind.c index 1d9881408..2802c87e5 100644 --- a/test/zdtm/static/mnt_ro_bind.c +++ b/test/zdtm/static/mnt_ro_bind.c @@ -9,14 +9,14 @@ #include "zdtmtst.h" -const char *test_doc = "Check read-only bind-mounts"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check read-only bind-mounts"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_WORD "testtest" -#define TEST_WORD2 "TESTTEST" +#define TEST_WORD "testtest" +#define TEST_WORD2 "TESTTEST" int main(int argc, char **argv) { diff --git a/test/zdtm/static/mnt_tracefs.c b/test/zdtm/static/mnt_tracefs.c index 99d60870a..66a00c02f 100644 --- a/test/zdtm/static/mnt_tracefs.c +++ b/test/zdtm/static/mnt_tracefs.c @@ -10,13 +10,13 @@ #include "zdtmtst.h" -const char *test_doc = "Test c/r of tracefs"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Test c/r of tracefs"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; char *dirname = "mnt_tracefs.test"; TEST_OPTION(dirname, string, "directory name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { char dst[PATH_MAX]; @@ -69,4 +69,3 @@ test: pass(); return 0; } - diff --git a/test/zdtm/static/mntns_deleted.c b/test/zdtm/static/mntns_deleted.c index 39f9d0b47..aea2be82f 100644 --- a/test/zdtm/static/mntns_deleted.c +++ b/test/zdtm/static/mntns_deleted.c @@ -15,20 +15,20 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check the restore of deleted bindmounts"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check the restore of deleted bindmounts"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_DIR_SRC "test-src" -#define TEST_DIR_DST "test-dst" +#define TEST_DIR_SRC "test-src" +#define TEST_DIR_DST "test-dst" -#define TEST_FILE_SRC "mntns-deleted-src" -#define TEST_FILE_DST "mntns-deleted-dst" +#define TEST_FILE_SRC "mntns-deleted-src" +#define TEST_FILE_DST "mntns-deleted-dst" int main(int argc, char *argv[]) { @@ -56,8 +56,7 @@ int main(int argc, char *argv[]) unlink(TEST_FILE_SRC); unlink(TEST_FILE_DST); - if (mkdir(path_src, 0700) || - mkdir(path_dst, 0700)) { + if (mkdir(path_src, 0700) || mkdir(path_dst, 0700)) { pr_perror("mkdir"); return 1; } diff --git a/test/zdtm/static/mntns_ghost.c b/test/zdtm/static/mntns_ghost.c index e0d31572a..c8c68382b 100644 --- a/test/zdtm/static/mntns_ghost.c +++ b/test/zdtm/static/mntns_ghost.c @@ -15,13 +15,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check ghost and link-remap files in a few mntns"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check ghost and link-remap files in a few mntns"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { task_waiter_t lock; @@ -102,7 +101,6 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - kill(pid, SIGTERM); wait(&status); if (status) { diff --git a/test/zdtm/static/mntns_ghost01.c b/test/zdtm/static/mntns_ghost01.c index 665e1e162..20397d543 100644 --- a/test/zdtm/static/mntns_ghost01.c +++ b/test/zdtm/static/mntns_ghost01.c @@ -9,13 +9,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check ghost file is restored on readonly fs if it was ghost-remaped on writable bind"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check ghost file is restored on readonly fs if it was ghost-remaped on writable bind"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { char ghost_path[PATH_MAX]; @@ -71,7 +70,7 @@ int main(int argc, char **argv) return 1; } - if (mount(NULL, dirname, NULL, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL)) { + if (mount(NULL, dirname, NULL, MS_RDONLY | MS_REMOUNT | MS_BIND, NULL)) { pr_perror("remount"); return 1; } diff --git a/test/zdtm/static/mntns_link_remap.c b/test/zdtm/static/mntns_link_remap.c index 6ac08191a..7c4acc01a 100644 --- a/test/zdtm/static/mntns_link_remap.c +++ b/test/zdtm/static/mntns_link_remap.c @@ -15,17 +15,17 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check ghost and link-remap files in a few mntns"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check ghost and link-remap files in a few mntns"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; -#define MPTS_FILE "F" +#define MPTS_FILE "F" char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define NS_STACK_SIZE 4096 +#define NS_STACK_SIZE 4096 /* All arguments should be above stack, because it grows down */ struct ns_exec_args { char stack[NS_STACK_SIZE] __stack_aligned__; @@ -34,8 +34,8 @@ struct ns_exec_args { int sync; }; -#define AWK_OK 13 -#define AWK_FAIL 42 +#define AWK_OK 13 +#define AWK_FAIL 42 static int get_mntid(int fd) { @@ -102,7 +102,7 @@ int ns_child(void *_arg) id1 = get_mntid(args->fd); id2 = get_mntid(fd2); - if (id1 <0 || id2 < 0) + if (id1 < 0 || id2 < 0) exit(1); if (fstat(args->fd, &st1) || fstat(fd2, &st2)) { @@ -117,8 +117,7 @@ int ns_child(void *_arg) #else if (st1.st_nlink != 0) { #endif - pr_perror("Wrong number of links: %lu", - (long unsigned)st1.st_nlink); + pr_perror("Wrong number of links: %lu", (long unsigned)st1.st_nlink); exit(1); } @@ -228,7 +227,6 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - if (pid > 0) { int status = 1; kill(pid, SIGTERM); diff --git a/test/zdtm/static/mntns_open.c b/test/zdtm/static/mntns_open.c index c687080a7..7d8bbbaa4 100644 --- a/test/zdtm/static/mntns_open.c +++ b/test/zdtm/static/mntns_open.c @@ -14,18 +14,18 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check that mnt_id is repsected"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that mnt_id is repsected"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define MPTS_FILE "F" +#define MPTS_FILE "F" char *dirname; TEST_OPTION(dirname, string, "directory name", 1); char fpath[PATH_MAX]; -#define NS_STACK_SIZE 4096 +#define NS_STACK_SIZE 4096 /* All arguments should be above stack, because it grows down */ struct ns_exec_args { char stack[NS_STACK_SIZE] __stack_aligned__; @@ -33,8 +33,8 @@ struct ns_exec_args { int fd; }; -#define AWK_OK 13 -#define AWK_FAIL 42 +#define AWK_OK 13 +#define AWK_FAIL 42 static int get_mntid(int fd) { @@ -74,7 +74,7 @@ int ns_child(void *_arg) test_msg("%d %d", id1, id2); - if (id1 <0 || id2 < 0) + if (id1 < 0 || id2 < 0) exit(1); if (id1 > 0 && id1 != id2) exit(AWK_OK); diff --git a/test/zdtm/static/mntns_overmount.c b/test/zdtm/static/mntns_overmount.c index ba23afca8..c2a6a72cf 100644 --- a/test/zdtm/static/mntns_overmount.c +++ b/test/zdtm/static/mntns_overmount.c @@ -10,13 +10,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check two mounts in the same directory"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check two mounts in the same directory"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { char d1[PATH_MAX], d2[PATH_MAX], f1[PATH_MAX], f2[PATH_MAX]; @@ -27,17 +26,13 @@ int main(int argc, char **argv) snprintf(d1, sizeof(d1), "%s/1/", dirname); snprintf(d2, sizeof(d2), "%s/2/", dirname); - if (mkdir(dirname, 0700) || - mkdir(d1, 0777) || - mkdir(d2, 0700)) { + if (mkdir(dirname, 0700) || mkdir(d1, 0777) || mkdir(d2, 0700)) { pr_perror("mkdir"); return 1; } - if (mount("zdtm_d1", d1, "sysfs", 0, NULL) || - mount(NULL, d1, NULL, MS_SHARED, NULL) || - mount(d1, d2, NULL, MS_BIND, NULL) || - mount(NULL, d2, NULL, MS_SLAVE, NULL)) { + if (mount("zdtm_d1", d1, "sysfs", 0, NULL) || mount(NULL, d1, NULL, MS_SHARED, NULL) || + mount(d1, d2, NULL, MS_BIND, NULL) || mount(NULL, d2, NULL, MS_SLAVE, NULL)) { pr_perror("mount"); return 1; } diff --git a/test/zdtm/static/mntns_remap.c b/test/zdtm/static/mntns_remap.c index fd62cbf40..3ee3b4640 100644 --- a/test/zdtm/static/mntns_remap.c +++ b/test/zdtm/static/mntns_remap.c @@ -13,8 +13,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check a case when one mount overmount another one"; -const char *test_author = "Andrew Vagin <avagin@virtuozzo.com>"; +const char *test_doc = "Check a case when one mount overmount another one"; +const char *test_author = "Andrew Vagin <avagin@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/mntns_ro_root.c b/test/zdtm/static/mntns_ro_root.c index 8a7971018..82659709e 100644 --- a/test/zdtm/static/mntns_ro_root.c +++ b/test/zdtm/static/mntns_ro_root.c @@ -14,13 +14,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check a case when a root is read-only for a sub-mntns"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check a case when a root is read-only for a sub-mntns"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { task_waiter_t lock; diff --git a/test/zdtm/static/mntns_root_bind.c b/test/zdtm/static/mntns_root_bind.c index 86c44e197..9e1ba06e6 100644 --- a/test/zdtm/static/mntns_root_bind.c +++ b/test/zdtm/static/mntns_root_bind.c @@ -14,16 +14,15 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check bind-mouns of the root mount"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check bind-mouns of the root mount"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { char subdir1[PATH_MAX], path[PATH_MAX], bpath[PATH_MAX], spath[PATH_MAX], bspath[PATH_MAX]; @@ -47,13 +46,8 @@ int main(int argc, char **argv) ssprintf(subdir2, "%s/subdir2", dirname); ssprintf(bsubdir2, "%s/bsubdir2", dirname); - if (mkdir(dirname, 0700) || - mkdir(subdir1, 0777) || - mkdir(subdir2, 0777) || - mkdir(bsubdir2, 0777) || - mkdir(path, 0700) || - mkdir(spath, 0700) || - mkdir(bpath, 0700)) { + if (mkdir(dirname, 0700) || mkdir(subdir1, 0777) || mkdir(subdir2, 0777) || mkdir(bsubdir2, 0777) || + mkdir(path, 0700) || mkdir(spath, 0700) || mkdir(bpath, 0700)) { pr_perror("mkdir"); return 1; } @@ -81,7 +75,6 @@ int main(int argc, char **argv) return 1; } - if (umount2(bpath, MNT_DETACH)) { fail("umount"); return 1; diff --git a/test/zdtm/static/mntns_rw_ro_rw.c b/test/zdtm/static/mntns_rw_ro_rw.c index 6179c4788..b251964a2 100644 --- a/test/zdtm/static/mntns_rw_ro_rw.c +++ b/test/zdtm/static/mntns_rw_ro_rw.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test read-only bind mounts"; -const char *test_author = "Andrey Vagin <xemul@parallels.com>"; +const char *test_doc = "Test read-only bind mounts"; +const char *test_author = "Andrey Vagin <xemul@parallels.com>"; int main(int argc, char **argv) { @@ -22,7 +22,7 @@ int main(int argc, char **argv) pr_perror("Unable to bind-mount /proc/sys/net"); return 1; } - if (mount("/proc/sys/", "/proc/sys", NULL, MS_RDONLY|MS_BIND|MS_REMOUNT, NULL)) { + if (mount("/proc/sys/", "/proc/sys", NULL, MS_RDONLY | MS_BIND | MS_REMOUNT, NULL)) { pr_perror("Unable to remount /proc/sys"); return 1; } diff --git a/test/zdtm/static/mntns_shared_bind.c b/test/zdtm/static/mntns_shared_bind.c index b0d63af58..7c745606e 100644 --- a/test/zdtm/static/mntns_shared_bind.c +++ b/test/zdtm/static/mntns_shared_bind.c @@ -14,16 +14,15 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check shared non-root bind-mounts"; -const char *test_author = "Andrew Vagin <avagin@gmail.com>"; +const char *test_doc = "Check shared non-root bind-mounts"; +const char *test_author = "Andrew Vagin <avagin@gmail.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { char path[PATH_MAX], bpath[PATH_MAX], spath[PATH_MAX]; @@ -50,16 +49,13 @@ int main(int argc, char **argv) #ifdef SHARED_BIND02 /* */ - if (mount(dirname, dirname, "tmpfs", 0, NULL) || - mount(NULL, dirname, NULL, MS_SHARED, NULL)) { + if (mount(dirname, dirname, "tmpfs", 0, NULL) || mount(NULL, dirname, NULL, MS_SHARED, NULL)) { pr_perror("mount"); return 1; } #endif - if (mkdir(path, 0700) || - mkdir(spath, 0700) || - mkdir(bpath, 0700)) { + if (mkdir(path, 0700) || mkdir(spath, 0700) || mkdir(bpath, 0700)) { pr_perror("mkdir"); return 1; } @@ -99,7 +95,6 @@ int main(int argc, char **argv) return 1; } - test_daemon(); test_waitsig(); diff --git a/test/zdtm/static/mntns_shared_bind03.c b/test/zdtm/static/mntns_shared_bind03.c index e75fe6297..3c0ced831 100644 --- a/test/zdtm/static/mntns_shared_bind03.c +++ b/test/zdtm/static/mntns_shared_bind03.c @@ -14,16 +14,15 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check shared non-root bind-mounts with different shared groups"; -const char *test_author = "Andrew Vagin <avagin@gmail.com>"; +const char *test_doc = "Check shared non-root bind-mounts with different shared groups"; +const char *test_author = "Andrew Vagin <avagin@gmail.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { test_init(argc, argv); @@ -51,22 +50,19 @@ int main(int argc, char **argv) return 1; } - if (mount("1", "1", NULL, MS_BIND, NULL) || - mount(NULL, "1", NULL, MS_PRIVATE, NULL) || + if (mount("1", "1", NULL, MS_BIND, NULL) || mount(NULL, "1", NULL, MS_PRIVATE, NULL) || mount(NULL, "1", NULL, MS_SHARED, NULL)) { pr_perror("mount"); return 1; } - if (mount("1", "A", NULL, MS_BIND, NULL) || - mount(NULL, "A", NULL, MS_PRIVATE, NULL) || + if (mount("1", "A", NULL, MS_BIND, NULL) || mount(NULL, "A", NULL, MS_PRIVATE, NULL) || mount(NULL, "A", NULL, MS_SHARED, NULL)) { pr_perror("mount"); return 1; } - if (mount("1", "B", NULL, MS_BIND, NULL) || - mount(NULL, "B", NULL, MS_SLAVE, NULL)) { + if (mount("1", "B", NULL, MS_BIND, NULL) || mount(NULL, "B", NULL, MS_SLAVE, NULL)) { pr_perror("mount"); return 1; } diff --git a/test/zdtm/static/mntns_shared_vs_private.c b/test/zdtm/static/mntns_shared_vs_private.c index 5849bbbdb..c44fb0066 100644 --- a/test/zdtm/static/mntns_shared_vs_private.c +++ b/test/zdtm/static/mntns_shared_vs_private.c @@ -14,16 +14,15 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif -const char *test_doc = "Check a private mount in a shared mount"; -const char *test_author = "Andrew Vagin <avagin@gmail.com>"; +const char *test_doc = "Check a private mount in a shared mount"; +const char *test_author = "Andrew Vagin <avagin@gmail.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); - int main(int argc, char **argv) { char path[PATH_MAX]; @@ -106,7 +105,8 @@ int main(int argc, char **argv) } if (status) { - pr_err("%d/%d/%d/%d\n", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), WTERMSIG(status)); + pr_err("%d/%d/%d/%d\n", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), + WTERMSIG(status)); return 1; } } diff --git a/test/zdtm/static/mount_paths.c b/test/zdtm/static/mount_paths.c index 2377e9c94..6b9ce1c24 100644 --- a/test/zdtm/static/mount_paths.c +++ b/test/zdtm/static/mount_paths.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that special characters in paths are handled correctly"; -const char *test_author = "Andrew Vagin <avagin@virtuozzo.com>"; +const char *test_doc = "Check that special characters in paths are handled correctly"; +const char *test_author = "Andrew Vagin <avagin@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/mountpoints.c b/test/zdtm/static/mountpoints.c index cf54d1096..b5fd72aad 100644 --- a/test/zdtm/static/mountpoints.c +++ b/test/zdtm/static/mountpoints.c @@ -11,12 +11,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check that mountpoints (in mount namespace) are supported"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that mountpoints (in mount namespace) are supported"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define MPTS_ROOT "/zdtm_mpts/" +#define MPTS_ROOT "/zdtm_mpts/" -#define NS_STACK_SIZE 4096 +#define NS_STACK_SIZE 4096 /* All arguments should be above stack, because it grows down */ struct ns_exec_args { char stack[NS_STACK_SIZE] __stack_aligned__; @@ -32,22 +32,22 @@ int ns_child(void *_arg) pid_t pid; int fd, ufd; - mkdir(MPTS_ROOT"/dev/mntns2", 0600); - if (mount("none", MPTS_ROOT"/dev/mntns2", "tmpfs", 0, "") < 0) { + mkdir(MPTS_ROOT "/dev/mntns2", 0600); + if (mount("none", MPTS_ROOT "/dev/mntns2", "tmpfs", 0, "") < 0) { fail("Can't mount tmpfs"); return 1; } - mkdir(MPTS_ROOT"/dev/mntns2/test", 0600); + mkdir(MPTS_ROOT "/dev/mntns2/test", 0600); - fd = open(MPTS_ROOT"/dev/mntns2/test/test.file", O_WRONLY | O_CREAT, 0666); + fd = open(MPTS_ROOT "/dev/mntns2/test/test.file", O_WRONLY | O_CREAT, 0666); if (fd < 0) return 1; - ufd = open(MPTS_ROOT"/dev/mntns2/test/test.file.unlinked", O_WRONLY | O_CREAT, 0666); + ufd = open(MPTS_ROOT "/dev/mntns2/test/test.file.unlinked", O_WRONLY | O_CREAT, 0666); if (ufd < 0) return 1; - unlink(MPTS_ROOT"/dev/mntns2/test/test.file.unlinked"); + unlink(MPTS_ROOT "/dev/mntns2/test/test.file.unlinked"); pid = fork(); @@ -63,7 +63,7 @@ int ns_child(void *_arg) return 1; } - if (stat(MPTS_ROOT"/dev/mntns2/test", &st)) { + if (stat(MPTS_ROOT "/dev/mntns2/test", &st)) { pr_perror("Can't stat /dev/share-1/test.share/test.share"); return 1; } @@ -92,133 +92,132 @@ int main(int argc, char **argv) return 1; } - if (mount("none", MPTS_ROOT"/dev", "tmpfs", 0, "") < 0) { + if (mount("none", MPTS_ROOT "/dev", "tmpfs", 0, "") < 0) { fail("Can't mount tmpfs"); return 1; } - tmpfs_fd = open(MPTS_ROOT"/dev/test", O_WRONLY | O_CREAT); + tmpfs_fd = open(MPTS_ROOT "/dev/test", O_WRONLY | O_CREAT); if (write(tmpfs_fd, "hello", 5) <= 0) { pr_perror("write() failed"); return 1; } /* Check that over-mounted files are restored on tmpfs */ - mkdir(MPTS_ROOT"/dev/overmount", 0600); - fd = open(MPTS_ROOT"/dev/overmount/test.over", O_WRONLY | O_CREAT); + mkdir(MPTS_ROOT "/dev/overmount", 0600); + fd = open(MPTS_ROOT "/dev/overmount/test.over", O_WRONLY | O_CREAT); if (fd == -1) { - pr_perror("Unable to open "MPTS_ROOT"/dev/overmount"); + pr_perror("Unable to open " MPTS_ROOT "/dev/overmount"); return -1; } close(fd); - if (mount("none", MPTS_ROOT"/dev/overmount", "tmpfs", 0, "") < 0) { - pr_perror("Can't mount "MPTS_ROOT"/dev/overmount"); + if (mount("none", MPTS_ROOT "/dev/overmount", "tmpfs", 0, "") < 0) { + pr_perror("Can't mount " MPTS_ROOT "/dev/overmount"); return 1; } - mkdir(MPTS_ROOT"/dev/non-root", 0600); - if (mount(MPTS_ROOT"/dev/non-root", MPTS_ROOT"/module", NULL, MS_BIND, NULL) < 0) { - pr_perror("Can't bind-mount %s -> %s", MPTS_ROOT"/dev/tdir", MPTS_ROOT"/module"); + mkdir(MPTS_ROOT "/dev/non-root", 0600); + if (mount(MPTS_ROOT "/dev/non-root", MPTS_ROOT "/module", NULL, MS_BIND, NULL) < 0) { + pr_perror("Can't bind-mount %s -> %s", MPTS_ROOT "/dev/tdir", MPTS_ROOT "/module"); } - mkdir(MPTS_ROOT"/dev/non-root/test", 0600); + mkdir(MPTS_ROOT "/dev/non-root/test", 0600); - mkdir(MPTS_ROOT"/dev/share-1", 0600); - if (mount("none", MPTS_ROOT"/dev/share-1/", "tmpfs", 0, "") < 0) { + mkdir(MPTS_ROOT "/dev/share-1", 0600); + if (mount("none", MPTS_ROOT "/dev/share-1/", "tmpfs", 0, "") < 0) { fail("Can't mount tmpfs"); return 1; } - if (mount("none", MPTS_ROOT"/dev/share-1/", NULL, MS_SHARED, NULL) < 0) { + if (mount("none", MPTS_ROOT "/dev/share-1/", NULL, MS_SHARED, NULL) < 0) { fail("Can't mount tmpfs"); return 1; } //#define CR_NEXT #ifdef CR_NEXT - mkdir(MPTS_ROOT"/dev/share-1/alone", 0600); - if (mount("none", MPTS_ROOT"/dev/share-1/alone", "tmpfs", 0, "") < 0) { + mkdir(MPTS_ROOT "/dev/share-1/alone", 0600); + if (mount("none", MPTS_ROOT "/dev/share-1/alone", "tmpfs", 0, "") < 0) { fail("Can't mount tmpfs"); return 1; } #endif - mkdir(MPTS_ROOT"/dev/share-2", 0600); - if (mount(MPTS_ROOT"/dev/share-1", MPTS_ROOT"/dev/share-2", NULL, MS_BIND, NULL) < 0) { + mkdir(MPTS_ROOT "/dev/share-2", 0600); + if (mount(MPTS_ROOT "/dev/share-1", MPTS_ROOT "/dev/share-2", NULL, MS_BIND, NULL) < 0) { fail("Can't bind mount a tmpfs directory"); return 1; } - mkdir(MPTS_ROOT"/dev/share-3", 0600); - if (mount(MPTS_ROOT"/dev/share-1", MPTS_ROOT"/dev/share-3", NULL, MS_BIND, NULL) < 0) { + mkdir(MPTS_ROOT "/dev/share-3", 0600); + if (mount(MPTS_ROOT "/dev/share-1", MPTS_ROOT "/dev/share-3", NULL, MS_BIND, NULL) < 0) { fail("Can't bind mount a tmpfs directory"); return 1; } - mkdir(MPTS_ROOT"/dev/slave", 0600); - if (mount(MPTS_ROOT"/dev/share-1", MPTS_ROOT"/dev/slave", NULL, MS_BIND, NULL) < 0) { + mkdir(MPTS_ROOT "/dev/slave", 0600); + if (mount(MPTS_ROOT "/dev/share-1", MPTS_ROOT "/dev/slave", NULL, MS_BIND, NULL) < 0) { fail("Can't bind mount a tmpfs directory"); return 1; } - if (mount("none", MPTS_ROOT"/dev/slave", NULL, MS_SLAVE, NULL) < 0) { + if (mount("none", MPTS_ROOT "/dev/slave", NULL, MS_SLAVE, NULL) < 0) { fail("Can't mount tmpfs"); return 1; } - mkdir(MPTS_ROOT"/dev/slave2", 0600); - if (mount(MPTS_ROOT"/dev/share-3", MPTS_ROOT"/dev/slave2", NULL, MS_BIND, NULL) < 0) { + mkdir(MPTS_ROOT "/dev/slave2", 0600); + if (mount(MPTS_ROOT "/dev/share-3", MPTS_ROOT "/dev/slave2", NULL, MS_BIND, NULL) < 0) { fail("Can't bind mount a tmpfs directory"); return 1; } - if (mount("none", MPTS_ROOT"/dev/slave2", NULL, MS_SLAVE, NULL) < 0) { + if (mount("none", MPTS_ROOT "/dev/slave2", NULL, MS_SLAVE, NULL) < 0) { fail("Can't mount tmpfs"); return 1; } - mkdir(MPTS_ROOT"/dev/share-1/test.mnt.share", 0600); - if (mount("none", MPTS_ROOT"/dev/share-1/test.mnt.share", "tmpfs", 0, "size=1G") < 0) { + mkdir(MPTS_ROOT "/dev/share-1/test.mnt.share", 0600); + if (mount("none", MPTS_ROOT "/dev/share-1/test.mnt.share", "tmpfs", 0, "size=1G") < 0) { fail("Can't mount tmpfs"); return 1; } - mkdir(MPTS_ROOT"/dev/share-1/test.mnt.share/test.share", 0600); - if (umount(MPTS_ROOT"/dev/slave2/test.mnt.share")) { - pr_perror("Can't umount "MPTS_ROOT"/dev/slave2/test.mnt.share"); + mkdir(MPTS_ROOT "/dev/share-1/test.mnt.share/test.share", 0600); + if (umount(MPTS_ROOT "/dev/slave2/test.mnt.share")) { + pr_perror("Can't umount " MPTS_ROOT "/dev/slave2/test.mnt.share"); return 1; } - mkdir(MPTS_ROOT"/dev/slave/test.mnt.slave", 0600); - if (mount("none", MPTS_ROOT"/dev/slave/test.mnt.slave", "tmpfs", 0, "") < 0) { + mkdir(MPTS_ROOT "/dev/slave/test.mnt.slave", 0600); + if (mount("none", MPTS_ROOT "/dev/slave/test.mnt.slave", "tmpfs", 0, "") < 0) { fail("Can't mount tmpfs"); return 1; } - mkdir(MPTS_ROOT"/dev/slave/test.mnt.slave/test.slave", 0600); + mkdir(MPTS_ROOT "/dev/slave/test.mnt.slave/test.slave", 0600); - fd = open(MPTS_ROOT"/dev/bmfile", O_CREAT | O_WRONLY); + fd = open(MPTS_ROOT "/dev/bmfile", O_CREAT | O_WRONLY); if (fd < 0) { pr_perror("Can't create " MPTS_ROOT "/dev/share-1/bmfile"); return 1; } close(fd); - fd = open(MPTS_ROOT"/dev/bmfile-mount", O_CREAT | O_WRONLY); + fd = open(MPTS_ROOT "/dev/bmfile-mount", O_CREAT | O_WRONLY); if (fd < 0) { pr_perror("Can't create " MPTS_ROOT "/dev/share-1/bmfile"); return 1; } close(fd); - if (mount(MPTS_ROOT"/dev/bmfile", MPTS_ROOT"/dev/bmfile-mount", NULL, MS_BIND, NULL) < 0) { + if (mount(MPTS_ROOT "/dev/bmfile", MPTS_ROOT "/dev/bmfile-mount", NULL, MS_BIND, NULL) < 0) { fail("Can't mount tmpfs"); return 1; } - if (mount("none", MPTS_ROOT"/kernel", "proc", 0, "") < 0) { + if (mount("none", MPTS_ROOT "/kernel", "proc", 0, "") < 0) { fail("Can't mount proc"); return 1; } - if (mount("none", MPTS_ROOT"/kernel/sys/fs/binfmt_misc", - "binfmt_misc", 0, "") == 0) + if (mount("none", MPTS_ROOT "/kernel/sys/fs/binfmt_misc", "binfmt_misc", 0, "") == 0) have_bfmtm = 1; - fd = open(MPTS_ROOT"/kernel/meminfo", O_RDONLY); + fd = open(MPTS_ROOT "/kernel/meminfo", O_RDONLY); if (fd == -1) return 1; @@ -236,32 +235,32 @@ int main(int argc, char **argv) test_waitsig(); /* this checks both -- sys and proc presence */ - if (access(MPTS_ROOT"/kernel/meminfo", F_OK)) { + if (access(MPTS_ROOT "/kernel/meminfo", F_OK)) { fail("No proc after restore"); return 1; } - if (have_bfmtm && access(MPTS_ROOT"/kernel/sys/fs/binfmt_misc/register", F_OK)) { + if (have_bfmtm && access(MPTS_ROOT "/kernel/sys/fs/binfmt_misc/register", F_OK)) { fail("No binfmt_misc after restore"); return 1; } - if (umount(MPTS_ROOT"/dev/overmount") == -1) { - pr_perror("Can't umount "MPTS_ROOT"/dev/overmount"); + if (umount(MPTS_ROOT "/dev/overmount") == -1) { + pr_perror("Can't umount " MPTS_ROOT "/dev/overmount"); return -1; } - if (access(MPTS_ROOT"/dev/overmount/test.over", F_OK)) { - fail(MPTS_ROOT"/dev/overmount/test.over"); + if (access(MPTS_ROOT "/dev/overmount/test.over", F_OK)) { + fail(MPTS_ROOT "/dev/overmount/test.over"); return -1; } { struct stat st1, st2; - if (stat(MPTS_ROOT"/dev/share-1/test.mnt.share/test.share", &st1)) { + if (stat(MPTS_ROOT "/dev/share-1/test.mnt.share/test.share", &st1)) { pr_perror("Can't stat /dev/share-1/test.share/test.share"); return 1; } - if (stat(MPTS_ROOT"/dev/share-2/test.mnt.share/test.share", &st2)) { + if (stat(MPTS_ROOT "/dev/share-2/test.mnt.share/test.share", &st2)) { pr_perror("Can't stat /dev/share-2/test.mnt.share/test.share"); return 1; } @@ -269,7 +268,7 @@ int main(int argc, char **argv) fail("/dev/share-1 and /dev/share-1 is not shared"); return 1; } - if (stat(MPTS_ROOT"/dev/slave/test.mnt.share/test.share", &st2)) { + if (stat(MPTS_ROOT "/dev/slave/test.mnt.share/test.share", &st2)) { pr_perror("Can't stat /dev/slave/test.mnt.share/test.share"); return 1; } @@ -277,15 +276,15 @@ int main(int argc, char **argv) fail("/dev/slave is not slave of /dev/share-1"); return 1; } - if (stat(MPTS_ROOT"/dev/share-1/test.mnt.slave/test.slave", &st1) != -1 || errno != ENOENT) { + if (stat(MPTS_ROOT "/dev/share-1/test.mnt.slave/test.slave", &st1) != -1 || errno != ENOENT) { pr_perror("/dev/share-1/test.mnt.slave/test.slave exists"); return 1; } - if (stat(MPTS_ROOT"/dev/slave/test.mnt.slave/test.slave", &st2)) { + if (stat(MPTS_ROOT "/dev/slave/test.mnt.slave/test.slave", &st2)) { pr_perror("Can't stat /dev/slave/test.mnt.slave/test.slave"); return 1; } - if (stat(MPTS_ROOT"/dev/non-root/test", &st1)) { + if (stat(MPTS_ROOT "/dev/non-root/test", &st1)) { pr_perror("Can't stat /dev/non-root/test"); return 1; } diff --git a/test/zdtm/static/mprotect00.c b/test/zdtm/static/mprotect00.c index bf852e596..006b64772 100644 --- a/test/zdtm/static/mprotect00.c +++ b/test/zdtm/static/mprotect00.c @@ -10,19 +10,19 @@ #include "zdtmtst.h" -const char *test_doc = "Check that memory protection migrates correctly\n"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that memory protection migrates correctly\n"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; const static int prots[] = { PROT_NONE, PROT_READ, - /* PROT_WRITE, */ /* doesn't work w/o READ */ - PROT_READ | PROT_WRITE, + /* PROT_WRITE, */ /* doesn't work w/o READ */ + PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE | PROT_EXEC, }; -#define NUM_MPROTS sizeof(prots) / sizeof(int) +#define NUM_MPROTS sizeof(prots) / sizeof(int) -static sigjmp_buf segv_ret; /* we need sig*jmp stuff, otherwise SIGSEGV will reset our handler */ +static sigjmp_buf segv_ret; /* we need sig*jmp stuff, otherwise SIGSEGV will reset our handler */ static void segfault(int signo) { siglongjmp(segv_ret, 1); @@ -44,12 +44,11 @@ static int check_prot(char *ptr, int prot) fail("PROT_READ bypassed"); return -1; } - } - else /* we come here on return from SIGSEGV handler */ + } else /* we come here on return from SIGSEGV handler */ if (prot & PROT_READ) { - fail("PROT_READ rejected"); - return -1; - } + fail("PROT_READ rejected"); + return -1; + } if (!sigsetjmp(segv_ret, 1)) { ptr[20] = 67; @@ -57,13 +56,11 @@ static int check_prot(char *ptr, int prot) fail("PROT_WRITE bypassed"); return -1; } - } - else /* we come here on return from SIGSEGV handler */ + } else /* we come here on return from SIGSEGV handler */ if (prot & PROT_WRITE) { - fail("PROT_WRITE rejected"); - return -1; - } - + fail("PROT_WRITE rejected"); + return -1; + } if (signal(SIGSEGV, SIG_DFL) == SIG_ERR) { fail("restoring SIGSEGV handler failed"); @@ -73,7 +70,7 @@ static int check_prot(char *ptr, int prot) return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { char *ptr, *ptr_aligned; int pagesize; @@ -93,12 +90,10 @@ int main(int argc, char ** argv) return -1; } - ptr_aligned = (char *)(((unsigned long) ptr + pagesize - 1) & - ~(pagesize - 1)); + ptr_aligned = (char *)(((unsigned long)ptr + pagesize - 1) & ~(pagesize - 1)); for (i = 0; i < NUM_MPROTS; i++) - if (mprotect(ptr_aligned + pagesize * i, - pagesize / 2, prots[i]) < 0) { + if (mprotect(ptr_aligned + pagesize * i, pagesize / 2, prots[i]) < 0) { pr_perror("mprotect failed"); exit(1); } diff --git a/test/zdtm/static/msgque.c b/test/zdtm/static/msgque.c index f52307221..933258cf8 100644 --- a/test/zdtm/static/msgque.c +++ b/test/zdtm/static/msgque.c @@ -14,18 +14,18 @@ #include "zdtmtst.h" -const char *test_doc="Tests sysv5 msg queues supporting by checkpointing"; -const char *test_author="Stanislav Kinsbursky <skinsbursky@openvz.org>"; +const char *test_doc = "Tests sysv5 msg queues supporting by checkpointing"; +const char *test_author = "Stanislav Kinsbursky <skinsbursky@openvz.org>"; struct msg1 { long mtype; char mtext[30]; }; #define TEST_STRING "Test sysv5 msg" -#define MSG_TYPE 1 +#define MSG_TYPE 1 #define ANOTHER_TEST_STRING "Yet another test sysv5 msg" -#define ANOTHER_MSG_TYPE 26538 +#define ANOTHER_MSG_TYPE 26538 int main(int argc, char **argv) { @@ -102,8 +102,7 @@ int main(int argc, char **argv) wait(&chret); chret = WEXITSTATUS(chret); if (chret) { - fail("Parent: child exited with non-zero code %d (%s)", - chret, strerror(chret)); + fail("Parent: child exited with non-zero code %d (%s)", chret, strerror(chret)); goto out; } diff --git a/test/zdtm/static/mtime_mmap.c b/test/zdtm/static/mtime_mmap.c index 90b4d6883..f9a595864 100644 --- a/test/zdtm/static/mtime_mmap.c +++ b/test/zdtm/static/mtime_mmap.c @@ -12,12 +12,12 @@ #include "zdtmtst.h" const char *test_doc = "file mmaped for write and being written should change mtime\n" - "and be migrated with correct new data"; + "and be migrated with correct new data"; char *filename; TEST_OPTION(filename, string, "file name", 1); -#define FILE_SIZE (16 * 1024) +#define FILE_SIZE (16 * 1024) int main(int argc, char **argv) { @@ -27,8 +27,8 @@ int main(int argc, char **argv) int i; char *ptr; struct stat fst; - time_t mtime_old, mtime_new; - time_t ctime_old, ctime_new; + time_t mtime_old, mtime_new; + time_t ctime_old, ctime_new; test_init(argc, argv); @@ -51,8 +51,7 @@ int main(int argc, char **argv) goto failed; } - ptr = (char *)mmap(NULL, count, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0); + ptr = (char *)mmap(NULL, count, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { pr_perror("mmap() failed"); goto failed; @@ -75,20 +74,17 @@ int main(int argc, char **argv) goto failed; } - mtime_new = fst.st_mtime; /* time of last modification */ if (mtime_new <= mtime_old) { - fail("mtime %ld wasn't updated on mmapped %s file", - mtime_new, filename); + fail("mtime %ld wasn't updated on mmapped %s file", mtime_new, filename); goto failed; } ctime_new = fst.st_ctime; /* time of last status change */ if (ctime_new <= ctime_old) { - fail("time of last status change of %s file wasn't changed", - filename); + fail("time of last status change of %s file wasn't changed", filename); goto failed; } diff --git a/test/zdtm/static/netns-dev.c b/test/zdtm/static/netns-dev.c index 46bb90639..e220daa7f 100644 --- a/test/zdtm/static/netns-dev.c +++ b/test/zdtm/static/netns-dev.c @@ -4,14 +4,14 @@ #include "zdtmtst.h" -#define LO_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/lo" -#define DEF_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/default" -#define ALL_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/all" -#define LO_CONF6_DIR_PATH "/proc/sys/net/ipv6/conf/lo" +#define LO_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/lo" +#define DEF_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/default" +#define ALL_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/all" +#define LO_CONF6_DIR_PATH "/proc/sys/net/ipv6/conf/lo" #define DEF_CONF6_DIR_PATH "/proc/sys/net/ipv6/conf/default" #define ALL_CONF6_DIR_PATH "/proc/sys/net/ipv6/conf/all" -#define INT_MAX ((int)(~0U>>1)) +#define INT_MAX ((int)(~0U >> 1)) #define INT_MIN (-INT_MAX - 1) char *devconfs4[] = { @@ -55,37 +55,37 @@ struct range { }; struct range rand_range4[] = { - {0, 1}, /* accept_local */ - {-1, 0}, /* accept_source_route */ - {0, 1}, /* arp_accept */ - {0, 2}, /* arp_announce */ - {0, 1}, /* arp_filter */ - {0, 8}, /* arp_ignore */ - {0, 1}, /* arp_notify */ - {0, 1}, /* bootp_relay */ - {0, 1}, /* disable_policy */ - {0, 1}, /* disable_xfrm */ - {0, 1}, /* drop_gratuitous_arp */ - {0, 1}, /* drop_unicast_in_l2_multicast */ - {0, INT_MAX}, /* force_igmp_version */ - {0, 1}, /* forwarding */ - {0, 1}, /* accept_redirects */ - {0, INT_MAX}, /* igmpv2_unsolicited_report_interval */ - {0, INT_MAX}, /* igmpv3_unsolicited_report_interval */ - {0, 1}, /* ignore_routes_with_linkdown */ - {0, 1}, /* log_martians */ - {0, 1}, /* mc_forwarding */ - {-1, INT_MAX}, /* medium_id */ - {0, 1}, /* promote_secondaries */ - {0, 1}, /* proxy_arp */ - {0, 1}, /* proxy_arp_pvlan */ - {0, 1}, /* route_localnet */ - {0, 2}, /* rp_filter */ - {0, 1}, /* secure_redirects */ - {0, 1}, /* send_redirects */ - {0, 1}, /* shared_media */ - {0, 1}, /* src_valid_mark */ - {INT_MIN, INT_MAX}, /* tag */ + { 0, 1 }, /* accept_local */ + { -1, 0 }, /* accept_source_route */ + { 0, 1 }, /* arp_accept */ + { 0, 2 }, /* arp_announce */ + { 0, 1 }, /* arp_filter */ + { 0, 8 }, /* arp_ignore */ + { 0, 1 }, /* arp_notify */ + { 0, 1 }, /* bootp_relay */ + { 0, 1 }, /* disable_policy */ + { 0, 1 }, /* disable_xfrm */ + { 0, 1 }, /* drop_gratuitous_arp */ + { 0, 1 }, /* drop_unicast_in_l2_multicast */ + { 0, INT_MAX }, /* force_igmp_version */ + { 0, 1 }, /* forwarding */ + { 0, 1 }, /* accept_redirects */ + { 0, INT_MAX }, /* igmpv2_unsolicited_report_interval */ + { 0, INT_MAX }, /* igmpv3_unsolicited_report_interval */ + { 0, 1 }, /* ignore_routes_with_linkdown */ + { 0, 1 }, /* log_martians */ + { 0, 1 }, /* mc_forwarding */ + { -1, INT_MAX }, /* medium_id */ + { 0, 1 }, /* promote_secondaries */ + { 0, 1 }, /* proxy_arp */ + { 0, 1 }, /* proxy_arp_pvlan */ + { 0, 1 }, /* route_localnet */ + { 0, 2 }, /* rp_filter */ + { 0, 1 }, /* secure_redirects */ + { 0, 1 }, /* send_redirects */ + { 0, 1 }, /* shared_media */ + { 0, 1 }, /* src_valid_mark */ + { INT_MIN, INT_MAX }, /* tag */ }; char *devconfs6[] = { @@ -134,52 +134,52 @@ char *devconfs6[] = { }; #define IPV6_MIN_MTU 1280 -#define ROUTER_MAX 60 +#define ROUTER_MAX 60 /* According to kernel docs do not make max_addresses too large */ #define MAX_ADDRESSES 128 struct range rand_range6[] = { - {0, 2}, /* accept_dad */ - {0, 2}, /* accept_ra */ - {0, 1}, /* accept_ra_defrtr */ - {0, 1}, /* accept_ra_from_local */ - {0, INT_MAX}, /* accept_ra_min_hop_limit */ - {0, 1}, /* accept_ra_mtu */ - {0, 1}, /* accept_ra_pinfo */ - {0, INT_MAX}, /* accept_ra_rt_info_max_plen */ - {0, 1}, /* accept_ra_rtr_pref */ - {-1, 0}, /* accept_source_route */ - {0, 1}, /* autoconf */ - {0, INT_MAX}, /* dad_transmits */ - {0, 1}, /* disable_ipv6 */ - {0, 1}, /* drop_unicast_in_l2_multicast */ - {0, 1}, /* drop_unsolicited_na */ - {0, 2}, /* force_mld_version */ - {0, 1}, /* force_tllao */ - {0, 1}, /* forwarding */ - {0, 1}, /* accept_redirects */ - {1, 255}, /* hop_limit */ - {0, 1}, /* ignore_routes_with_linkdown */ - {-1, 1}, /* keep_addr_on_down */ - {0, MAX_ADDRESSES}, /* max_addresses */ - {0, INT_MAX}, /* max_desync_factor */ - {0, INT_MAX}, /* mldv1_unsolicited_report_interval */ - {0, INT_MAX}, /* mldv2_unsolicited_report_interval */ - {IPV6_MIN_MTU, IPV6_MIN_MTU}, /* mtu */ - {0, 1}, /* ndisc_notify */ - {0, 1}, /* optimistic_dad */ - {0, 1}, /* proxy_ndp */ - {0, INT_MAX}, /* regen_max_retry */ - {0, ROUTER_MAX}, /* router_probe_interval */ - {0, ROUTER_MAX}, /* router_solicitation_delay */ - {0, ROUTER_MAX}, /* router_solicitation_interval */ - {0, ROUTER_MAX}, /* router_solicitations */ - {0, 1}, /* suppress_frag_ndisc */ - {0, INT_MAX}, /* temp_prefered_lft */ - {0, INT_MAX}, /* temp_valid_lft */ - {0, 1}, /* use_oif_addrs_only */ - {0, 1}, /* use_optimistic */ - {0, 2}, /* use_tempaddr */ + { 0, 2 }, /* accept_dad */ + { 0, 2 }, /* accept_ra */ + { 0, 1 }, /* accept_ra_defrtr */ + { 0, 1 }, /* accept_ra_from_local */ + { 0, INT_MAX }, /* accept_ra_min_hop_limit */ + { 0, 1 }, /* accept_ra_mtu */ + { 0, 1 }, /* accept_ra_pinfo */ + { 0, INT_MAX }, /* accept_ra_rt_info_max_plen */ + { 0, 1 }, /* accept_ra_rtr_pref */ + { -1, 0 }, /* accept_source_route */ + { 0, 1 }, /* autoconf */ + { 0, INT_MAX }, /* dad_transmits */ + { 0, 1 }, /* disable_ipv6 */ + { 0, 1 }, /* drop_unicast_in_l2_multicast */ + { 0, 1 }, /* drop_unsolicited_na */ + { 0, 2 }, /* force_mld_version */ + { 0, 1 }, /* force_tllao */ + { 0, 1 }, /* forwarding */ + { 0, 1 }, /* accept_redirects */ + { 1, 255 }, /* hop_limit */ + { 0, 1 }, /* ignore_routes_with_linkdown */ + { -1, 1 }, /* keep_addr_on_down */ + { 0, MAX_ADDRESSES }, /* max_addresses */ + { 0, INT_MAX }, /* max_desync_factor */ + { 0, INT_MAX }, /* mldv1_unsolicited_report_interval */ + { 0, INT_MAX }, /* mldv2_unsolicited_report_interval */ + { IPV6_MIN_MTU, IPV6_MIN_MTU }, /* mtu */ + { 0, 1 }, /* ndisc_notify */ + { 0, 1 }, /* optimistic_dad */ + { 0, 1 }, /* proxy_ndp */ + { 0, INT_MAX }, /* regen_max_retry */ + { 0, ROUTER_MAX }, /* router_probe_interval */ + { 0, ROUTER_MAX }, /* router_solicitation_delay */ + { 0, ROUTER_MAX }, /* router_solicitation_interval */ + { 0, ROUTER_MAX }, /* router_solicitations */ + { 0, 1 }, /* suppress_frag_ndisc */ + { 0, INT_MAX }, /* temp_prefered_lft */ + { 0, INT_MAX }, /* temp_valid_lft */ + { 0, 1 }, /* use_oif_addrs_only */ + { 0, 1 }, /* use_optimistic */ + { 0, 2 }, /* use_tempaddr */ }; struct test_conf { @@ -191,8 +191,8 @@ struct test_conf { char *dir6; } lo, def, all; -static int save_conf(FILE *fp, int *conf, int *conf_rand, - struct range *range, char *path) { +static int save_conf(FILE *fp, int *conf, int *conf_rand, struct range *range, char *path) +{ int ret; /* @@ -207,11 +207,13 @@ static int save_conf(FILE *fp, int *conf, int *conf_rand, return 0; } -static int rand_in_small_range(struct range *r) { +static int rand_in_small_range(struct range *r) +{ return lrand48() % (r->max - r->min + 1) + r->min; } -static int rand_in_range(struct range *r) { +static int rand_in_range(struct range *r) +{ struct range small; int mid = r->max / 2 + r->min / 2; int half = r->max / 2 - r->min / 2; @@ -230,8 +232,8 @@ static int rand_in_range(struct range *r) { return rand_in_small_range(&small); } -static int gen_conf(FILE *fp, int *conf, int *conf_rand, - struct range *range, char *path) { +static int gen_conf(FILE *fp, int *conf, int *conf_rand, struct range *range, char *path) +{ int ret; /* * Set random value @@ -249,8 +251,8 @@ static int gen_conf(FILE *fp, int *conf, int *conf_rand, #define MAX_MSEC_GRANULARITY 10 -static int check_conf(FILE *fp, int *conf, int *conf_rand, - struct range *range, char *path) { +static int check_conf(FILE *fp, int *conf, int *conf_rand, struct range *range, char *path) +{ int ret; int val; @@ -264,11 +266,10 @@ static int check_conf(FILE *fp, int *conf, int *conf_rand, } if (val != *conf_rand) { - fail("Option \"%s\" changed from %d to %d", - path, *conf_rand, val); - if ((strstr(path, "mldv1_unsolicited_report_interval") - || strstr(path, "mldv2_unsolicited_report_interval")) - && val - *conf_rand < MAX_MSEC_GRANULARITY) + fail("Option \"%s\" changed from %d to %d", path, *conf_rand, val); + if ((strstr(path, "mldv1_unsolicited_report_interval") || + strstr(path, "mldv2_unsolicited_report_interval")) && + val - *conf_rand < MAX_MSEC_GRANULARITY) return 0; return -1; } @@ -276,8 +277,8 @@ static int check_conf(FILE *fp, int *conf, int *conf_rand, return 0; } -static int restore_conf(FILE *fp, int *conf, int *conf_rand, - struct range *range, char *path) { +static int restore_conf(FILE *fp, int *conf, int *conf_rand, struct range *range, char *path) +{ int ret; /* * Restore opt @@ -291,8 +292,9 @@ static int restore_conf(FILE *fp, int *conf, int *conf_rand, return 0; } -static int for_each_option_do(int (*f)(FILE *fp, int *conf, int *conf_rand, - struct range *range, char *path), struct test_conf *tc) { +static int for_each_option_do(int (*f)(FILE *fp, int *conf, int *conf_rand, struct range *range, char *path), + struct test_conf *tc) +{ int ret; int i; @@ -356,7 +358,8 @@ static int for_each_option_do(int (*f)(FILE *fp, int *conf, int *conf_rand, #define IPV6ADDR_EXAMPLE "2607:f0d0:1002:0051:0000:0000:0000:0004" #define MAX_STR_CONF_LEN 200 -static int set_stable_secret(struct test_conf *tc) { +static int set_stable_secret(struct test_conf *tc) +{ int ret; FILE *fp; char path[PATH_MAX]; @@ -388,11 +391,12 @@ static int set_stable_secret(struct test_conf *tc) { return 0; } -static int check_stable_secret(struct test_conf *tc) { +static int check_stable_secret(struct test_conf *tc) +{ int ret; FILE *fp; char path[PATH_MAX]; - char val[MAX_STR_CONF_LEN+1]; + char val[MAX_STR_CONF_LEN + 1]; ret = snprintf(path, sizeof(path), "%s/%s", tc->dir6, "stable_secret"); if (ret < 0) { @@ -418,8 +422,7 @@ static int check_stable_secret(struct test_conf *tc) { } if (strcmp(val, IPV6ADDR_EXAMPLE)) { - fail("Option \"%s\" changed from %s to %s", - path, IPV6ADDR_EXAMPLE, val); + fail("Option \"%s\" changed from %s to %s", path, IPV6ADDR_EXAMPLE, val); fclose(fp); return -1; } diff --git a/test/zdtm/static/netns-nf.c b/test/zdtm/static/netns-nf.c index 393f0e732..2d5968503 100644 --- a/test/zdtm/static/netns-nf.c +++ b/test/zdtm/static/netns-nf.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that netfilter rules (some) are kept"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that netfilter rules (some) are kept"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/netns-nft-ipt.c b/test/zdtm/static/netns-nft-ipt.c index 02c2a2f58..627500151 100644 --- a/test/zdtm/static/netns-nft-ipt.c +++ b/test/zdtm/static/netns-nft-ipt.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that both nftables & iptables rules (some) are C/R properly"; -const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; +const char *test_doc = "Check that both nftables & iptables rules (some) are C/R properly"; +const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/netns-nft.c b/test/zdtm/static/netns-nft.c index f4991afda..673cc007e 100644 --- a/test/zdtm/static/netns-nft.c +++ b/test/zdtm/static/netns-nft.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that nft rules (some) are kept"; -const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; +const char *test_doc = "Check that nft rules (some) are kept"; +const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/netns.c b/test/zdtm/static/netns.c index b7a75b6d9..bc7f66319 100644 --- a/test/zdtm/static/netns.c +++ b/test/zdtm/static/netns.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that network environment (links, addresses and routes) are preserved"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that network environment (links, addresses and routes) are preserved"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/netns_lock.c b/test/zdtm/static/netns_lock.c index f58ba83da..9b3a4f1c0 100644 --- a/test/zdtm/static/netns_lock.c +++ b/test/zdtm/static/netns_lock.c @@ -7,9 +7,9 @@ const char *test_author = "Zeyad Yasser <zeyady98@gmail.com>"; #include <fcntl.h> #include <sched.h> -#define NS_PATH "/var/run/netns/criu-net-lock-test" +#define NS_PATH "/var/run/netns/criu-net-lock-test" #define SYNCFILE_PATH "net_lock.sync" -#define MAX_RETRY 3 +#define MAX_RETRY 3 int main(int argc, char **argv) { @@ -42,7 +42,7 @@ int main(int argc, char **argv) */ for (i = 0; i < MAX_RETRY; i++) { - if (access(SYNCFILE_PATH, F_OK )) { + if (access(SYNCFILE_PATH, F_OK)) { /* Netns not created yet by post-start hook */ sleep(1); continue; diff --git a/test/zdtm/static/netns_sub.c b/test/zdtm/static/netns_sub.c index 9f77bf96b..501e97bd7 100644 --- a/test/zdtm/static/netns_sub.c +++ b/test/zdtm/static/netns_sub.c @@ -14,7 +14,7 @@ #include "zdtmtst.h" -const char *test_doc = "Check dump and restore a few network namespaces"; +const char *test_doc = "Check dump and restore a few network namespaces"; static int fill_name(int nsid, struct sockaddr_un *name) { @@ -41,7 +41,7 @@ static int create_socket(int nsid) return -1; } - if (bind(sk, (struct sockaddr *) &name, len) < 0) { + if (bind(sk, (struct sockaddr *)&name, len) < 0) { pr_perror("bind"); close(sk); return -1; @@ -63,7 +63,7 @@ static int check_socket(int nsid, bool success) return -1; } - if (connect(sk, (struct sockaddr *) &name, len) < 0) { + if (connect(sk, (struct sockaddr *)&name, len) < 0) { if (!success && errno == ECONNREFUSED) return 0; pr_perror("connect to %d", nsid); diff --git a/test/zdtm/static/netns_sub_sysctl.c b/test/zdtm/static/netns_sub_sysctl.c index bf828e08e..545a17308 100644 --- a/test/zdtm/static/netns_sub_sysctl.c +++ b/test/zdtm/static/netns_sub_sysctl.c @@ -3,8 +3,8 @@ #include "zdtmtst.h" #include "sysctl.h" -const char *test_doc = "Check dump and restore a net.unix.max_dgram_qlen sysctl parameter in subns"; -const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; +const char *test_doc = "Check dump and restore a net.unix.max_dgram_qlen sysctl parameter in subns"; +const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; typedef struct { const char *path; @@ -12,12 +12,9 @@ typedef struct { int new; } sysctl_opt_t; -#define CONF_UNIX_BASE "/proc/sys/net/unix" +#define CONF_UNIX_BASE "/proc/sys/net/unix" -static sysctl_opt_t net_unix_params[] = { - {CONF_UNIX_BASE"/max_dgram_qlen", 0, 0}, - {NULL, 0, 0} -}; +static sysctl_opt_t net_unix_params[] = { { CONF_UNIX_BASE "/max_dgram_qlen", 0, 0 }, { NULL, 0, 0 } }; int main(int argc, char **argv) { diff --git a/test/zdtm/static/netns_sub_veth.c b/test/zdtm/static/netns_sub_veth.c index c0a71b337..e072d7816 100644 --- a/test/zdtm/static/netns_sub_veth.c +++ b/test/zdtm/static/netns_sub_veth.c @@ -20,12 +20,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check dump and restore a few network namespaces"; +const char *test_doc = "Check dump and restore a few network namespaces"; #ifndef NSIO -#define NSIO 0xb7 -#define NS_GET_USERNS _IO(NSIO, 0x1) -#define NS_GET_PARENT _IO(NSIO, 0x2) +#define NSIO 0xb7 +#define NS_GET_USERNS _IO(NSIO, 0x1) +#define NS_GET_PARENT _IO(NSIO, 0x2) #endif int main(int argc, char **argv) @@ -33,7 +33,7 @@ int main(int argc, char **argv) task_waiter_t lock; pid_t pid[2]; int status = -1, ret, i; - struct rtnl_link *link = NULL, *new; + struct rtnl_link *link = NULL, *new; struct nl_sock *sk; int has_index = 1; @@ -77,11 +77,13 @@ int main(int argc, char **argv) for (i = 0; i < 2; i++) { char cmd[4096]; - snprintf(cmd, sizeof(cmd), "ip link add name zdtm%d index %d netns %d type veth peer name zdtm%d index %d", - i, i * 10 + 12, pid[i], i, i * 10 + 12); + snprintf(cmd, sizeof(cmd), + "ip link add name zdtm%d index %d netns %d type veth peer name zdtm%d index %d", i, + i * 10 + 12, pid[i], i, i * 10 + 12); if (system(cmd)) { has_index = 0; - snprintf(cmd, sizeof(cmd), "ip link add name zdtm%d netns %d type veth peer name zdtm%d", i, pid[i], i); + snprintf(cmd, sizeof(cmd), "ip link add name zdtm%d netns %d type veth peer name zdtm%d", i, + pid[i], i); if (system(cmd)) return 1; } diff --git a/test/zdtm/static/non_uniform_share_propagation.c b/test/zdtm/static/non_uniform_share_propagation.c index 7a18247ab..e4f7ee275 100644 --- a/test/zdtm/static/non_uniform_share_propagation.c +++ b/test/zdtm/static/non_uniform_share_propagation.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check non-uniform shares restore fine"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check non-uniform shares restore fine"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/ofd_file_locks.c b/test/zdtm/static/ofd_file_locks.c index 5b19532f8..68b6f22f5 100644 --- a/test/zdtm/static/ofd_file_locks.c +++ b/test/zdtm/static/ofd_file_locks.c @@ -16,9 +16,7 @@ static int parse_ofd_lock(char *buf, struct flock *lck) if (strncmp(buf, "lock:\t", 6) != 0) return 1; /* isn't lock, skip record */ - num = sscanf(buf, - "%*s %*d: %s %s %s %*d %*x:%*x:%*d %lld %s", - fl_flag, fl_type, fl_option, &start, fl_end); + num = sscanf(buf, "%*s %*d: %s %s %s %*d %*x:%*x:%*d %lld %s", fl_flag, fl_type, fl_option, &start, fl_end); if (num < 4) { pr_err("Invalid lock info %s\n", buf); @@ -118,9 +116,7 @@ out: static int check_file_locks_match(struct flock *orig_lck, struct flock *lck) { - return orig_lck->l_start == lck->l_start && - orig_lck->l_len == lck->l_len && - orig_lck->l_type == lck->l_type; + return orig_lck->l_start == lck->l_start && orig_lck->l_len == lck->l_len && orig_lck->l_type == lck->l_type; } int check_file_lock_restored(int pid, int fd, struct flock *lck) @@ -164,30 +160,30 @@ int zdtm_fcntl(int fd, int cmd, struct flock *f) { #if defined(__i386__) #ifndef __NR_fcntl64 -# define __NR_fcntl64 221 +#define __NR_fcntl64 221 #endif struct flock64 f64 = {}; int ret; switch (cmd) { - case F_OFD_SETLK: - case F_OFD_SETLKW: - f64.l_type = f->l_type; - f64.l_whence = f->l_whence; - f64.l_start = f->l_start; - f64.l_len = f->l_len; - f64.l_pid = f->l_pid; - return syscall(__NR_fcntl64, fd, cmd, &f64); - case F_OFD_GETLK: - ret = syscall(__NR_fcntl64, fd, cmd, &f64); - f->l_type = f64.l_type; - f->l_whence = f64.l_whence; - f->l_start = f64.l_start; - f->l_len = f64.l_len; - f->l_pid = f64.l_pid; - return ret; - default: - break; + case F_OFD_SETLK: + case F_OFD_SETLKW: + f64.l_type = f->l_type; + f64.l_whence = f->l_whence; + f64.l_start = f->l_start; + f64.l_len = f->l_len; + f64.l_pid = f->l_pid; + return syscall(__NR_fcntl64, fd, cmd, &f64); + case F_OFD_GETLK: + ret = syscall(__NR_fcntl64, fd, cmd, &f64); + f->l_type = f64.l_type; + f->l_whence = f64.l_whence; + f->l_start = f64.l_start; + f->l_len = f64.l_len; + f->l_pid = f64.l_pid; + return ret; + default: + break; } #endif return fcntl(fd, cmd, f); diff --git a/test/zdtm/static/oom_score_adj.c b/test/zdtm/static/oom_score_adj.c index 8e9c40782..cbbdfb810 100644 --- a/test/zdtm/static/oom_score_adj.c +++ b/test/zdtm/static/oom_score_adj.c @@ -65,7 +65,6 @@ int set_oom_score_adj(const char *path, int value) return ret; } - int main(int argc, char *argv[]) { int ret; @@ -84,8 +83,7 @@ int main(int argc, char *argv[]) return -1; if (new_oom_score_adj != test_value) { - fail("OOM score value %d is different after restore: %d", - test_value, new_oom_score_adj); + fail("OOM score value %d is different after restore: %d", test_value, new_oom_score_adj); return -1; } diff --git a/test/zdtm/static/opath_file.c b/test/zdtm/static/opath_file.c index 40e5987c3..779060844 100644 --- a/test/zdtm/static/opath_file.c +++ b/test/zdtm/static/opath_file.c @@ -5,13 +5,13 @@ #include "zdtmtst.h" -#define TEST_FILE "test_file" -#define BUF_SIZE 4096 -#define fdinfo_field(str, field) !strncmp(str, field":", sizeof(field)) -#define pr_debug(format, arg...) test_msg("DBG: %s:%d: " format, __FILE__, __LINE__, ## arg) +#define TEST_FILE "test_file" +#define BUF_SIZE 4096 +#define fdinfo_field(str, field) !strncmp(str, field ":", sizeof(field)) +#define pr_debug(format, arg...) test_msg("DBG: %s:%d: " format, __FILE__, __LINE__, ##arg) -const char *test_doc = "Check open file with O_PATH preserved"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check open file with O_PATH preserved"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/overmount_dev.c b/test/zdtm/static/overmount_dev.c index e126d301d..dd16c11a8 100644 --- a/test/zdtm/static/overmount_dev.c +++ b/test/zdtm/static/overmount_dev.c @@ -8,10 +8,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a device special file " - "open in a directory which has been mounted over by " - "another filesystem"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can migrate with a device special file " + "open in a directory which has been mounted over by " + "another filesystem"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/overmount_fifo.c b/test/zdtm/static/overmount_fifo.c index c73793036..f3693fef6 100644 --- a/test/zdtm/static/overmount_fifo.c +++ b/test/zdtm/static/overmount_fifo.c @@ -7,10 +7,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a named pipe " - "open in a directory which has been mounted over by " - "another filesystem"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can migrate with a named pipe " + "open in a directory which has been mounted over by " + "another filesystem"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/overmount_file.c b/test/zdtm/static/overmount_file.c index e20d98f93..178b34182 100644 --- a/test/zdtm/static/overmount_file.c +++ b/test/zdtm/static/overmount_file.c @@ -7,10 +7,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can't migrate with a file open in a " - "directory which has been mounted over by another " - "filesystem"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can't migrate with a file open in a " + "directory which has been mounted over by another " + "filesystem"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/overmount_sock.c b/test/zdtm/static/overmount_sock.c index 8d2d28bf6..6e3ab935b 100644 --- a/test/zdtm/static/overmount_sock.c +++ b/test/zdtm/static/overmount_sock.c @@ -10,10 +10,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a unix socket " - "bound in a directory which has been mounted over by" - " another filesystem"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can migrate with a unix socket " + "bound in a directory which has been mounted over by" + " another filesystem"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -44,7 +44,7 @@ static int setup_srv_sock(const char *filename) return -1; } - if (bind(sock, (struct sockaddr *) &name, SUN_LEN(&name)) < 0) { + if (bind(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) { pr_perror("can't bind to socket \"%s\"", filename); goto err; } @@ -72,7 +72,7 @@ static int setup_clnt_sock(const char *filename) if (sock < 0) return -1; - if (connect(sock, (struct sockaddr *) &name, SUN_LEN(&name)) < 0) + if (connect(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) goto err; return sock; @@ -81,7 +81,7 @@ err: return -1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int sock, acc_sock, ret; char path[256]; @@ -111,7 +111,7 @@ int main(int argc, char ** argv) goto out; } - if (pid == 0) { /* child writes to the overmounted socket and returns */ + if (pid == 0) { /* child writes to the overmounted socket and returns */ close(sock); sock = setup_clnt_sock(path); @@ -159,8 +159,7 @@ int main(int argc, char ** argv) if (WIFEXITED(ret)) { ret = WEXITSTATUS(ret); if (ret) { - fail("child exited with nonzero code %d (%s)", ret, - strerror(ret)); + fail("child exited with nonzero code %d (%s)", ret, strerror(ret)); goto out; } } diff --git a/test/zdtm/static/overmount_with_shared_parent.c b/test/zdtm/static/overmount_with_shared_parent.c index 1fcb5a5cb..95b455ec0 100644 --- a/test/zdtm/static/overmount_with_shared_parent.c +++ b/test/zdtm/static/overmount_with_shared_parent.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check overmount on shared parent works"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check overmount on shared parent works"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/overmounted_file.c b/test/zdtm/static/overmounted_file.c index ee1d1c58f..c72d27cb8 100644 --- a/test/zdtm/static/overmounted_file.c +++ b/test/zdtm/static/overmounted_file.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check open file on overmounted mounts doesn't dump"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check open file on overmounted mounts doesn't dump"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; #define DATA "Data" @@ -50,7 +50,7 @@ int main(int argc, char **argv) } ssprintf(file, "%s/file", overmounted); - fd = open(file, O_CREAT|O_WRONLY, 0600); + fd = open(file, O_CREAT | O_WRONLY, 0600); if (fd < 0) { pr_perror("open"); return 1; diff --git a/test/zdtm/static/packet_sock.c b/test/zdtm/static/packet_sock.c index 36516fa99..4a9078f81 100644 --- a/test/zdtm/static/packet_sock.c +++ b/test/zdtm/static/packet_sock.c @@ -24,30 +24,27 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; #include <linux/if_packet.h> #include <net/ethernet.h> -#define SK_RESERVE 8 -#define DEF_FANOUT 13 +#define SK_RESERVE 8 +#define DEF_FANOUT 13 #ifndef PACKET_FANOUT -#define PACKET_FANOUT 18 +#define PACKET_FANOUT 18 #endif static int test_sockaddr(int n, struct sockaddr_ll *have, struct sockaddr_ll *want) { if (have->sll_family != want->sll_family) { - fail("%d Family mismatch %d/%d", n, - (int)have->sll_family, (int)want->sll_family); + fail("%d Family mismatch %d/%d", n, (int)have->sll_family, (int)want->sll_family); return 1; } if (have->sll_protocol != want->sll_protocol) { - fail("%d Proto mismatch %d/%d", n, - (int)have->sll_protocol, (int)want->sll_protocol); + fail("%d Proto mismatch %d/%d", n, (int)have->sll_protocol, (int)want->sll_protocol); return 1; } if (have->sll_ifindex != want->sll_ifindex) { - fail("%d Index mismatch %d/%d", n, - have->sll_ifindex, want->sll_ifindex); + fail("%d Index mismatch %d/%d", n, have->sll_ifindex, want->sll_ifindex); return 1; } @@ -56,19 +53,19 @@ static int test_sockaddr(int n, struct sockaddr_ll *have, struct sockaddr_ll *wa } #ifndef MAX_ADDR_LEN -#define MAX_ADDR_LEN 32 +#define MAX_ADDR_LEN 32 #endif struct packet_mreq_max { - int mr_ifindex; - unsigned short mr_type; - unsigned short mr_alen; - unsigned char mr_address[MAX_ADDR_LEN]; + int mr_ifindex; + unsigned short mr_type; + unsigned short mr_alen; + unsigned char mr_address[MAX_ADDR_LEN]; }; -#define LO_ADDR_LEN 6 +#define LO_ADDR_LEN 6 -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0) struct tpacket_req3 { unsigned int tp_block_size; diff --git a/test/zdtm/static/packet_sock_mmap.c b/test/zdtm/static/packet_sock_mmap.c index 93d6ebbf2..2a105582b 100644 --- a/test/zdtm/static/packet_sock_mmap.c +++ b/test/zdtm/static/packet_sock_mmap.c @@ -18,7 +18,7 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; #include <net/ethernet.h> #include <sys/mman.h> -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0) struct tpacket_req3 { unsigned int tp_block_size; diff --git a/test/zdtm/static/packet_sock_spkt.c b/test/zdtm/static/packet_sock_spkt.c index 55cd16518..7aaaabd14 100644 --- a/test/zdtm/static/packet_sock_spkt.c +++ b/test/zdtm/static/packet_sock_spkt.c @@ -23,7 +23,7 @@ static int do_bind(int sk) addr.sa_family = AF_PACKET; strcpy(addr.sa_data, "lo"); - return bind(sk, (struct sockaddr *) &addr, sizeof(addr)); + return bind(sk, (struct sockaddr *)&addr, sizeof(addr)); } static int check_socket_binding(int sk, char *dev) @@ -53,7 +53,7 @@ int main(int argc, char **argv) sk1 = socket(AF_PACKET, SOCK_PACKET, htons(ETH_P_ALL)); - if (sk1 < 0) { + if (sk1 < 0) { pr_perror("Can't create socket 1"); return 1; } diff --git a/test/zdtm/static/pdeath_sig.c b/test/zdtm/static/pdeath_sig.c index 0f7436f63..d680e4842 100644 --- a/test/zdtm/static/pdeath_sig.c +++ b/test/zdtm/static/pdeath_sig.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that pdeath sig is preserved"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that pdeath sig is preserved"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; static int sigrecvd = 0; static void sigh(int s, siginfo_t *i, void *d) diff --git a/test/zdtm/static/pid00.c b/test/zdtm/static/pid00.c index 4fd3e09aa..a60f8af45 100644 --- a/test/zdtm/static/pid00.c +++ b/test/zdtm/static/pid00.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that p?pid and e?[ug]id didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that p?pid and e?[ug]id didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int setfsuid(uid_t fsuid); int setfsgid(uid_t fsgid); @@ -40,11 +40,12 @@ int main(int argc, char **argv) read(f_p[0], &res, 1); close(f_p[0]); -#define CHECK_ID(__t, __w, __e) do { \ - if (__t##id != w_##__t##__w##id) { \ - res = __e; \ - goto bad; \ - } \ +#define CHECK_ID(__t, __w, __e) \ + do { \ + if (__t##id != w_##__t##__w##id) { \ + res = __e; \ + goto bad; \ + } \ } while (0) rid = eid = sid = fsid = 0; @@ -65,7 +66,7 @@ int main(int argc, char **argv) CHECK_ID(fs, g, '8'); res = '0'; -bad: + bad: write(r_p[1], &res, 1); close(r_p[1]); _exit(0); diff --git a/test/zdtm/static/pid_file.c b/test/zdtm/static/pid_file.c index 3ee6a3942..bd4df6bfb 100644 --- a/test/zdtm/static/pid_file.c +++ b/test/zdtm/static/pid_file.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that environment didn't change"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Check that environment didn't change"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/pipe00.c b/test/zdtm/static/pipe00.c index dd487d091..492722573 100644 --- a/test/zdtm/static/pipe00.c +++ b/test/zdtm/static/pipe00.c @@ -6,12 +6,12 @@ #include "zdtmtst.h" -const char *test_doc = "Lock inversion"; -const char *test_author = "Andrey Vagin <avagin@parallels.com>"; +const char *test_doc = "Lock inversion"; +const char *test_author = "Andrey Vagin <avagin@parallels.com>"; #define TEST_STRING "Hello world" -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pipe1[2]; int pipe2[2]; @@ -42,7 +42,7 @@ int main(int argc, char ** argv) return 1; } } else { - if (dup2(pipe1[0], 12) == -1 || dup2(pipe2[1], 11) == -1) { + if (dup2(pipe1[0], 12) == -1 || dup2(pipe2[1], 11) == -1) { pr_perror("dup2 failed"); goto err; } diff --git a/test/zdtm/static/pipe01.c b/test/zdtm/static/pipe01.c index fd51988b5..587f42568 100644 --- a/test/zdtm/static/pipe01.c +++ b/test/zdtm/static/pipe01.c @@ -10,12 +10,12 @@ #include "zdtmtst.h" -const char *test_doc = "Test that all data can be restored"; -const char *test_author = "Andrey Vagin <avagin@parallels.com>"; +const char *test_doc = "Test that all data can be restored"; +const char *test_author = "Andrey Vagin <avagin@parallels.com>"; #define TEST_STRING "Hello world" -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pfd[2], pfd_dup[2], pfd_rop[2]; char path[PATH_MAX]; @@ -43,8 +43,7 @@ int main(int argc, char ** argv) snprintf(path, PATH_MAX, "/proc/self/fd/%d", pfd[1]); pfd_rop[1] = open(path, O_WRONLY); - if (pfd_rop[0] == -1 || pfd_rop[1] == -1 || - pfd_dup[0] == -1 || pfd_dup[1] == -1) { + if (pfd_rop[0] == -1 || pfd_rop[1] == -1 || pfd_dup[0] == -1 || pfd_dup[1] == -1) { pr_perror("dup() failed"); return 1; } diff --git a/test/zdtm/static/pipe02.c b/test/zdtm/static/pipe02.c index 2a8cca7da..9ee522ea8 100644 --- a/test/zdtm/static/pipe02.c +++ b/test/zdtm/static/pipe02.c @@ -10,10 +10,10 @@ #include "zdtmtst.h" -const char *test_doc = "Create two unshared descriptor for the one end of a pipe"; -const char *test_author = "Andrey Vagin <avagin@parallels.com>"; +const char *test_doc = "Create two unshared descriptor for the one end of a pipe"; +const char *test_author = "Andrey Vagin <avagin@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int p[2], fd; int ret; diff --git a/test/zdtm/static/pipe03.c b/test/zdtm/static/pipe03.c index d649007b7..d6c8f74cf 100644 --- a/test/zdtm/static/pipe03.c +++ b/test/zdtm/static/pipe03.c @@ -5,11 +5,11 @@ #include "zdtmtst.h" -const char *test_doc = "Check that pipes with a non-default size can be c/r-ed"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Check that pipes with a non-default size can be c/r-ed"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; #define DATA_SIZE (1 << 20) -#define BUF_SIZE (4096) +#define BUF_SIZE (4096) int main(int argc, char **argv) { diff --git a/test/zdtm/static/poll.c b/test/zdtm/static/poll.c index 53d801a0b..60eb54f34 100644 --- a/test/zdtm/static/poll.c +++ b/test/zdtm/static/poll.c @@ -16,8 +16,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check poll() timeouts"; -const char *test_author = "Cyrill Gorcunov <gorcunov@parallels.com>"; +const char *test_doc = "Check poll() timeouts"; +const char *test_author = "Cyrill Gorcunov <gorcunov@parallels.com>"; static void show_timestamp(char *prefix, unsigned long tv_sec, unsigned long tv_usec) { @@ -29,8 +29,7 @@ static void show_pollfd(struct pollfd *fds, size_t nfds) size_t i; for (i = 0; i < nfds; i++) { - test_msg("%2zu) fd: %2d events %2x revents %2x\n", - i, fds[i].fd, fds[i].events, fds[i].revents); + test_msg("%2zu) fd: %2d events %2x revents %2x\n", i, fds[i].fd, fds[i].events, fds[i].revents); } } @@ -100,11 +99,9 @@ int main(int argc, char *argv[]) } show_timestamp("Stop", time2.tv_sec, time2.tv_usec); - show_timestamp("Diff", time2.tv_sec - time1.tv_sec, - time2.tv_usec - time1.tv_usec); + show_timestamp("Diff", time2.tv_sec - time1.tv_sec, time2.tv_usec - time1.tv_usec); if ((time2.tv_sec - time1.tv_sec) > delta) { - fail("Delta is too big %lu", - (unsigned long)(time2.tv_sec - time1.tv_sec)); + fail("Delta is too big %lu", (unsigned long)(time2.tv_sec - time1.tv_sec)); exit(1); } } diff --git a/test/zdtm/static/posix_timers.c b/test/zdtm/static/posix_timers.c index b88114cdb..b2ed0dcf9 100644 --- a/test/zdtm/static/posix_timers.c +++ b/test/zdtm/static/posix_timers.c @@ -8,24 +8,24 @@ #include "zdtmtst.h" -const char *test_doc ="Posix timers migration check"; +const char *test_doc = "Posix timers migration check"; const char *test_author = "Kinsbursky Stanislav <skinsbursky@parallels.com>"; sigset_t mask; -#define WRONG_SIGNAL 1 -#define WRONG_SI_PTR 2 -#define FAIL_OVERRUN 4 +#define WRONG_SIGNAL 1 +#define WRONG_SI_PTR 2 +#define FAIL_OVERRUN 4 -#define MAX_TIMER_DISPLACEMENT 10 +#define MAX_TIMER_DISPLACEMENT 10 #define NO_PERIODIC #ifndef CLOCK_MONOTONIC_COARSE -# define CLOCK_MONOTONIC_COARSE 6 +#define CLOCK_MONOTONIC_COARSE 6 #endif #ifndef CLOCK_BOOTTIME -# define CLOCK_BOOTTIME 7 +#define CLOCK_BOOTTIME 7 #endif #ifndef NO_PERIODIC @@ -115,8 +115,7 @@ static struct posix_timers_info { { } }; -static int check_handler_status(struct posix_timers_info *info, - struct itimerspec *its, int ms_passed, int delta) +static int check_handler_status(struct posix_timers_info *info, struct itimerspec *its, int ms_passed, int delta) { int displacement; int timer_ms; @@ -179,7 +178,8 @@ static int check_handler_status(struct posix_timers_info *info, test_msg("%20s: Handler count : %d\n", info->name, info->handler_cnt); if (displacement > MAX_TIMER_DISPLACEMENT) { - fail("%32s: Time displacement: %d%% (max alloved: %d%%)", info->name, displacement, MAX_TIMER_DISPLACEMENT); + fail("%32s: Time displacement: %d%% (max alloved: %d%%)", info->name, displacement, + MAX_TIMER_DISPLACEMENT); return -EFAULT; } return 0; @@ -213,14 +213,14 @@ static int check_timers(int delta, struct timespec *sleep_start, struct timespec * Adjust with @total_sleep_time if needed. */ if (info->clock == CLOCK_BOOTTIME) { - info->start.tv_sec -= sleep_start->tv_sec; - info->start.tv_nsec -= sleep_start->tv_nsec; - info->end.tv_sec -= sleep_end->tv_sec; - info->end.tv_nsec -= sleep_end->tv_nsec; + info->start.tv_sec -= sleep_start->tv_sec; + info->start.tv_nsec -= sleep_start->tv_nsec; + info->end.tv_sec -= sleep_end->tv_sec; + info->end.tv_nsec -= sleep_end->tv_nsec; } ms_passed = (info->end.tv_sec - info->start.tv_sec) * 1000 + - (info->end.tv_nsec - info->start.tv_nsec) / (1000 * 1000); + (info->end.tv_nsec - info->start.tv_nsec) / (1000 * 1000); if (check_handler_status(info, &oldval, ms_passed, delta)) status--; @@ -229,8 +229,7 @@ static int check_timers(int delta, struct timespec *sleep_start, struct timespec return status; } -static void generic_handler(struct posix_timers_info *info, - struct posix_timers_info *real, int sig) +static void generic_handler(struct posix_timers_info *info, struct posix_timers_info *real, int sig) { int overrun; @@ -256,41 +255,35 @@ static void generic_handler(struct posix_timers_info *info, #ifndef NO_PERIODIC static void monotonic_periodic_handler(int sig, siginfo_t *si, void *uc) { - generic_handler(si->si_value.sival_ptr, - &posix_timers[MONOTONIC_PERIODIC_INFO], sig); + generic_handler(si->si_value.sival_ptr, &posix_timers[MONOTONIC_PERIODIC_INFO], sig); } static void boottime_periodic_handler(int sig, siginfo_t *si, void *uc) { - generic_handler(si->si_value.sival_ptr, - &posix_timers[BOOTTIME_PERIODIC_INFO], sig); + generic_handler(si->si_value.sival_ptr, &posix_timers[BOOTTIME_PERIODIC_INFO], sig); } #endif static void monotonic_oneshot_handler(int sig, siginfo_t *si, void *uc) { - generic_handler(si->si_value.sival_ptr, - &posix_timers[MONOTONIC_ONESHOT_INFO], sig); + generic_handler(si->si_value.sival_ptr, &posix_timers[MONOTONIC_ONESHOT_INFO], sig); } static void boottime_oneshot_handler(int sig, siginfo_t *si, void *uc) { - generic_handler(si->si_value.sival_ptr, - &posix_timers[BOOTTIME_ONESHOT_INFO], sig); + generic_handler(si->si_value.sival_ptr, &posix_timers[BOOTTIME_ONESHOT_INFO], sig); } #ifndef NO_PERIODIC static void realtime_periodic_handler(int sig, siginfo_t *si, void *uc) { - generic_handler(si->si_value.sival_ptr, - &posix_timers[REALTIME_PERIODIC_INFO], sig); + generic_handler(si->si_value.sival_ptr, &posix_timers[REALTIME_PERIODIC_INFO], sig); } #endif static void realtime_oneshot_handler(int sig, siginfo_t *si, void *uc) { - generic_handler(si->si_value.sival_ptr, - &posix_timers[REALTIME_ONESHOT_INFO], sig); + generic_handler(si->si_value.sival_ptr, &posix_timers[REALTIME_ONESHOT_INFO], sig); } static int setup_timers(void) @@ -302,7 +295,7 @@ static int setup_timers(void) struct itimerspec its; sigemptyset(&mask); - while(info->handler) { + while (info->handler) { sigaddset(&mask, info->sig); info++; } @@ -313,18 +306,18 @@ static int setup_timers(void) } info = posix_timers; - while(info->handler) { + while (info->handler) { /* Add and delete fake timers to test restoring 'with holes' */ timer_t timeridt; for (i = 0; i < 10; i++) { ret = timer_create(CLOCK_REALTIME, NULL, &timeridt); if (ret < 0) { - pr_perror("Can't create temporary posix timer %lx", (long) timeridt); + pr_perror("Can't create temporary posix timer %lx", (long)timeridt); return -errno; } ret = timer_delete(timeridt); if (ret < 0) { - pr_perror("Can't remove temporaty posix timer %lx", (long) timeridt); + pr_perror("Can't remove temporaty posix timer %lx", (long)timeridt); return -errno; } } @@ -398,10 +391,7 @@ static int get_total_sleep_time(struct timespec *tv, char *type) test_msg("(%6s) boottime %lu " "boottime-coarse %lu " "total_sleep_time %lu\n", - type, - (long)boottime.tv_sec, - (long)boottime_coarse.tv_sec, - (long)tv->tv_sec); + type, (long)boottime.tv_sec, (long)boottime_coarse.tv_sec, (long)tv->tv_sec); return 0; } @@ -432,9 +422,8 @@ int main(int argc, char **argv) err = get_total_sleep_time(&sleep_end, "end"); if (err) return err; - err = check_timers((end.tv_sec - start.tv_sec) * 1000 + - (end.tv_nsec - start.tv_nsec) / 1000000, - &sleep_start, &sleep_end); + err = check_timers((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000, &sleep_start, + &sleep_end); if (err) return err; diff --git a/test/zdtm/static/private_bind_propagation.c b/test/zdtm/static/private_bind_propagation.c index ee4adbd2d..2b92f7062 100644 --- a/test/zdtm/static/private_bind_propagation.c +++ b/test/zdtm/static/private_bind_propagation.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check sharing options are restored for bindmounted shared group children"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check sharing options are restored for bindmounted shared group children"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/proc-self.c b/test/zdtm/static/proc-self.c index 6f0a30e7d..10218c86b 100644 --- a/test/zdtm/static/proc-self.c +++ b/test/zdtm/static/proc-self.c @@ -12,8 +12,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check for /proc/self/ns path restore"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for /proc/self/ns path restore"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; const char nspath[] = "/proc/self/ns/net"; diff --git a/test/zdtm/static/pstree.c b/test/zdtm/static/pstree.c index ba94a275d..38cc99339 100644 --- a/test/zdtm/static/pstree.c +++ b/test/zdtm/static/pstree.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that environment didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that environment didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { diff --git a/test/zdtm/static/pthread00.c b/test/zdtm/static/pthread00.c index 4da824056..adbf74a40 100644 --- a/test/zdtm/static/pthread00.c +++ b/test/zdtm/static/pthread00.c @@ -18,35 +18,34 @@ #include "zdtmtst.h" -#define exit_group(code) \ - syscall(__NR_exit_group, code) +#define exit_group(code) syscall(__NR_exit_group, code) -const char *test_doc = "Create a few pthreads/forks and compare TLS and mmap data on restore\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Create a few pthreads/forks and compare TLS and mmap data on restore\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; static __thread char tls_data[10]; -#define TRANSITION_PASSED 4 -#define TRANSITION_FAILED 8 +#define TRANSITION_PASSED 4 +#define TRANSITION_FAILED 8 -#define MAP(map, i) (((int *)map)[i]) +#define MAP(map, i) (((int *)map)[i]) -#define SET_PASSED(map, i) MAP(map, i) = TRANSITION_PASSED -#define SET_FAILED(map, i) MAP(map, i) = TRANSITION_FAILED +#define SET_PASSED(map, i) MAP(map, i) = TRANSITION_PASSED +#define SET_FAILED(map, i) MAP(map, i) = TRANSITION_FAILED -#define IS_PASSED(map, i) (MAP(map, i) & TRANSITION_PASSED) +#define IS_PASSED(map, i) (MAP(map, i) & TRANSITION_PASSED) -#define NR_WAITERS 6 +#define NR_WAITERS 6 static task_waiter_t waiter[NR_WAITERS]; -#define passage(index) \ - do { \ - task_waiter_complete(&waiter[index], 1); \ - task_waiter_wait4(&waiter[index], 2); \ - if (memcmp(tls_data, __tls_data, sizeof(tls_data))) \ - SET_FAILED(map, index); \ - else \ - SET_PASSED(map, index); \ +#define passage(index) \ + do { \ + task_waiter_complete(&waiter[index], 1); \ + task_waiter_wait4(&waiter[index], 2); \ + if (memcmp(tls_data, __tls_data, sizeof(tls_data))) \ + SET_FAILED(map, index); \ + else \ + SET_PASSED(map, index); \ } while (0) static void *thread_subfunc_1(void *map) @@ -171,11 +170,7 @@ int main(int argc, char *argv[]) pthread_join(th1, NULL); pthread_join(th2, NULL); - if (IS_PASSED(map, 0) && - IS_PASSED(map, 1) && - IS_PASSED(map, 2) && - IS_PASSED(map, 3) && - IS_PASSED(map, 4) && + if (IS_PASSED(map, 0) && IS_PASSED(map, 1) && IS_PASSED(map, 2) && IS_PASSED(map, 3) && IS_PASSED(map, 4) && IS_PASSED(map, 5)) pass(); else diff --git a/test/zdtm/static/pthread01.c b/test/zdtm/static/pthread01.c index bdd7c59d8..6aa8d80a8 100644 --- a/test/zdtm/static/pthread01.c +++ b/test/zdtm/static/pthread01.c @@ -14,14 +14,14 @@ #include "zdtmtst.h" -#define gettid() pthread_self() +#define gettid() pthread_self() -const char *test_doc = "Create a few pthreads and test TLS + blocked signals\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Create a few pthreads and test TLS + blocked signals\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; static __thread struct tls_data_s { - char *rand_string[10]; - sigset_t blk_sigset; + char *rand_string[10]; + sigset_t blk_sigset; } tls_data; static task_waiter_t t1; @@ -36,19 +36,45 @@ static char *decode_signal(const sigset_t *s, char *buf) { buf[0] = '\0'; -#define COLLECT(sig) \ - do { \ - if (sigismember(s, sig)) \ - strcat(buf, #sig " "); \ +#define COLLECT(sig) \ + do { \ + if (sigismember(s, sig)) \ + strcat(buf, #sig " "); \ } while (0) - COLLECT(SIGHUP); COLLECT(SIGINT); COLLECT(SIGQUIT); COLLECT(SIGILL); COLLECT(SIGTRAP); - COLLECT(SIGABRT); COLLECT(SIGIOT); COLLECT(SIGBUS); COLLECT(SIGFPE); COLLECT(SIGKILL); - COLLECT(SIGUSR1); COLLECT(SIGSEGV); COLLECT(SIGUSR2); COLLECT(SIGPIPE); COLLECT(SIGALRM); - COLLECT(SIGTERM); COLLECT(SIGSTKFLT); COLLECT(SIGCHLD); COLLECT(SIGCONT); COLLECT(SIGSTOP); - COLLECT(SIGTSTP); COLLECT(SIGTTIN); COLLECT(SIGTTOU); COLLECT(SIGURG); COLLECT(SIGXCPU); - COLLECT(SIGXFSZ); COLLECT(SIGVTALRM); COLLECT(SIGPROF); COLLECT(SIGWINCH); COLLECT(SIGIO); - COLLECT(SIGPOLL); COLLECT(SIGPWR); COLLECT(SIGSYS); + COLLECT(SIGHUP); + COLLECT(SIGINT); + COLLECT(SIGQUIT); + COLLECT(SIGILL); + COLLECT(SIGTRAP); + COLLECT(SIGABRT); + COLLECT(SIGIOT); + COLLECT(SIGBUS); + COLLECT(SIGFPE); + COLLECT(SIGKILL); + COLLECT(SIGUSR1); + COLLECT(SIGSEGV); + COLLECT(SIGUSR2); + COLLECT(SIGPIPE); + COLLECT(SIGALRM); + COLLECT(SIGTERM); + COLLECT(SIGSTKFLT); + COLLECT(SIGCHLD); + COLLECT(SIGCONT); + COLLECT(SIGSTOP); + COLLECT(SIGTSTP); + COLLECT(SIGTTIN); + COLLECT(SIGTTOU); + COLLECT(SIGURG); + COLLECT(SIGXCPU); + COLLECT(SIGXFSZ); + COLLECT(SIGVTALRM); + COLLECT(SIGPROF); + COLLECT(SIGWINCH); + COLLECT(SIGIO); + COLLECT(SIGPOLL); + COLLECT(SIGPWR); + COLLECT(SIGSYS); #undef COLLECT return buf; @@ -56,20 +82,20 @@ static char *decode_signal(const sigset_t *s, char *buf) static void __show_sigset(int line, const sigset_t *s) { - char buf[sizeof(sigset_t) * 2 + 1] = { }; + char buf[sizeof(sigset_t) * 2 + 1] = {}; decode_signal(s, buf); test_msg("sigset at %4d: %s\n", line, buf); } -#define show_sigset(set) __show_sigset(__LINE__, set) +#define show_sigset(set) __show_sigset(__LINE__, set) static void *ch_thread_2(void *arg) { char __tls_data[sizeof(tls_data.rand_string)] = "XM5o:?B*[a"; int *results_map = arg; - sigset_t blk_sigset = { }; - sigset_t new = { }; + sigset_t blk_sigset = {}; + sigset_t new = {}; memcpy(tls_data.rand_string, __tls_data, sizeof(tls_data.rand_string)); @@ -114,8 +140,8 @@ static void *ch_thread_1(void *arg) { char __tls_data[sizeof(tls_data.rand_string)] = "pffYQSBo?6"; int *results_map = arg; - sigset_t blk_sigset = { }; - sigset_t new = { }; + sigset_t blk_sigset = {}; + sigset_t new = {}; memcpy(tls_data.rand_string, __tls_data, sizeof(tls_data.rand_string)); @@ -200,12 +226,8 @@ int main(int argc, char *argv[]) pthread_join(thread_1, NULL); pthread_join(thread_2, NULL); - if (results_map[1] == 1 && - results_map[2] == 1 && - results_map[3] == 1 && - results_map[4] == 1 && - results_map[5] == 1 && - results_map[6] == 1) + if (results_map[1] == 1 && results_map[2] == 1 && results_map[3] == 1 && results_map[4] == 1 && + results_map[5] == 1 && results_map[6] == 1) pass(); else fail(); diff --git a/test/zdtm/static/pthread02.c b/test/zdtm/static/pthread02.c index 186271b74..173a55e15 100644 --- a/test/zdtm/static/pthread02.c +++ b/test/zdtm/static/pthread02.c @@ -10,9 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Create a thread with a dead leader\n"; -const char *test_author = "Andrew Vagin <avagin@openvz.org"; - +const char *test_doc = "Create a thread with a dead leader\n"; +const char *test_author = "Andrew Vagin <avagin@openvz.org"; static void *thread_func(void *args) { @@ -28,7 +27,6 @@ int main(int argc, char *argv[]) test_init(argc, argv); - ret = pthread_create(&th1, NULL, &thread_func, NULL); if (ret) { diff --git a/test/zdtm/static/pthread_timers.c b/test/zdtm/static/pthread_timers.c index f4b183fc6..ddf41074d 100644 --- a/test/zdtm/static/pthread_timers.c +++ b/test/zdtm/static/pthread_timers.c @@ -8,11 +8,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check SIGEV_THREAD timers"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Check SIGEV_THREAD timers"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; int efd; -static void timer_func(union sigval sigval) { +static void timer_func(union sigval sigval) +{ long long int val = 1; if (write(efd, &val, sizeof(val)) != sizeof(val)) { diff --git a/test/zdtm/static/ptrace_sig.c b/test/zdtm/static/ptrace_sig.c index b70f8f1b0..c77cf1ea0 100644 --- a/test/zdtm/static/ptrace_sig.c +++ b/test/zdtm/static/ptrace_sig.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check ptrace, if the child process's stopped by signal"; -const char *test_author = "Andrey Vagin <avagin@parallels.com>"; +const char *test_doc = "Check ptrace, if the child process's stopped by signal"; +const char *test_author = "Andrey Vagin <avagin@parallels.com>"; typedef void (*sighandler_t)(int); @@ -55,7 +55,7 @@ int child(int fd) return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int ret, status = 0; pid_t pid, spid, cpid; @@ -82,7 +82,7 @@ int main(int argc, char ** argv) close(child_pipe[1]); test_msg("wait while child initialized"); ret = read(child_pipe[0], &status, sizeof(status)); - if (ret != sizeof(status)) { + if (ret != sizeof(status)) { pr_perror("read from child process failed"); return 1; } @@ -122,7 +122,6 @@ int main(int argc, char ** argv) } if (WIFSTOPPED(status)) { - test_msg("pid=%d stopsig=%d\n", pid, WSTOPSIG(status)); ret = ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo); @@ -137,7 +136,7 @@ int main(int argc, char ** argv) pr_perror("ptrace failed"); ret = read(child_pipe[0], &status, sizeof(status)); - if (ret != sizeof(status)) { + if (ret != sizeof(status)) { pr_perror("read"); return 1; } diff --git a/test/zdtm/static/pty00.c b/test/zdtm/static/pty00.c index 2c76d9c3e..f6db95ac0 100644 --- a/test/zdtm/static/pty00.c +++ b/test/zdtm/static/pty00.c @@ -9,8 +9,8 @@ #include <termios.h> #include <signal.h> -const char *test_doc = "Check, that pseudoterminals are restored"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Check, that pseudoterminals are restored"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; static unsigned int nr_sighups; @@ -19,7 +19,7 @@ static void signal_handler_sighup(int signum) nr_sighups++; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fdm, fds, ret, tty, i; char *slavename; @@ -77,7 +77,7 @@ int main(int argc, char ** argv) close(fds); fds = 100; - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) { /* Check connectivity */ ret = write(fdm, teststr, sizeof(teststr) - 1); if (ret != sizeof(teststr) - 1) { @@ -89,7 +89,7 @@ int main(int argc, char ** argv) test_daemon(); test_waitsig(); - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) { ret = read(fds, buf, sizeof(teststr) - 1); if (ret != sizeof(teststr) - 1) { pr_perror("read(fds) failed"); diff --git a/test/zdtm/static/pty01.c b/test/zdtm/static/pty01.c index cb7fff9af..ba0adac17 100644 --- a/test/zdtm/static/pty01.c +++ b/test/zdtm/static/pty01.c @@ -13,8 +13,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check two pts on ptmx"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check two pts on ptmx"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; static const char teststr[] = "ping\n"; @@ -81,9 +81,8 @@ int main(int argc, char *argv[]) } if (st.st_uid != new_uid || st.st_gid != new_gid) { - fail("UID/GID mismatch (got %d/%d but %d/%d expected)", - (int)st.st_uid, (int)st.st_gid, - (int)new_uid, (int)new_gid); + fail("UID/GID mismatch (got %d/%d but %d/%d expected)", (int)st.st_uid, (int)st.st_gid, (int)new_uid, + (int)new_gid); return 1; } diff --git a/test/zdtm/static/pty02.c b/test/zdtm/static/pty02.c index 041a4e4be..69bac8990 100644 --- a/test/zdtm/static/pty02.c +++ b/test/zdtm/static/pty02.c @@ -9,16 +9,18 @@ #include <termios.h> #include <signal.h> -const char *test_doc = "Check forked master ptmx"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check forked master ptmx"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; static const char teststr[] = "ping\n"; -#define exit_shot(pid, code) \ - do { kill(pid, SIGKILL); exit(code); } while (0) +#define exit_shot(pid, code) \ + do { \ + kill(pid, SIGKILL); \ + exit(code); \ + } while (0) -#define exit_shot_parent(code) \ - exit_shot(getppid(), 1) +#define exit_shot_parent(code) exit_shot(getppid(), 1) int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/pty03.c b/test/zdtm/static/pty03.c index 3c2b36369..59672d697 100644 --- a/test/zdtm/static/pty03.c +++ b/test/zdtm/static/pty03.c @@ -10,8 +10,8 @@ #include <signal.h> #include <sys/ioctl.h> -const char *test_doc = "Check a non-opened control terminal"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Check a non-opened control terminal"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; static const char teststr[] = "ping\n"; diff --git a/test/zdtm/static/pty04.c b/test/zdtm/static/pty04.c index 74d8ab466..406fbee4d 100644 --- a/test/zdtm/static/pty04.c +++ b/test/zdtm/static/pty04.c @@ -10,8 +10,8 @@ #include <signal.h> #include <sys/ioctl.h> -const char *test_doc = "Check two pts with a fake ptmx"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check two pts with a fake ptmx"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/remap_dead_pid.c b/test/zdtm/static/remap_dead_pid.c index 5d4241fc6..56294654b 100644 --- a/test/zdtm/static/remap_dead_pid.c +++ b/test/zdtm/static/remap_dead_pid.c @@ -10,7 +10,7 @@ #include "zdtmtst.h" #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif #ifdef REMAP_PID_ROOT @@ -19,8 +19,8 @@ const char *proc_path = "/proc/%d"; const char *proc_path = "/proc/%d/mountinfo"; #endif -const char *test_doc = "Check that dead pid's /proc entries are remapped correctly"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that dead pid's /proc entries are remapped correctly"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; int main(int argc, char **argv) { @@ -37,7 +37,7 @@ int main(int argc, char **argv) if (pid == 0) { /* Child process just sleeps until it is killed. All we need * here is a process to open the mountinfo of. */ - while(1) + while (1) sleep(10); } else { int fd, ret; diff --git a/test/zdtm/static/rlimits00.c b/test/zdtm/static/rlimits00.c index 17ea8daea..395d61719 100644 --- a/test/zdtm/static/rlimits00.c +++ b/test/zdtm/static/rlimits00.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that rlimits are saved"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that rlimits are saved"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { @@ -21,8 +21,7 @@ int main(int argc, char **argv) goto out; } - if (rlims[r].rlim_cur > 1 && - rlims[r].rlim_cur != RLIM_INFINITY) { + if (rlims[r].rlim_cur > 1 && rlims[r].rlim_cur != RLIM_INFINITY) { rlims[r].rlim_cur--; if (setrlimit(r, &rlims[r])) { @@ -63,4 +62,3 @@ int main(int argc, char **argv) out: return 0; } - diff --git a/test/zdtm/static/rmdir_open.c b/test/zdtm/static/rmdir_open.c index f671ac48f..93b0246bd 100644 --- a/test/zdtm/static/rmdir_open.c +++ b/test/zdtm/static/rmdir_open.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that opened removed dir works"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that opened removed dir works"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/rtc.c b/test/zdtm/static/rtc.c index 28a79b1e2..df1f3833a 100644 --- a/test/zdtm/static/rtc.c +++ b/test/zdtm/static/rtc.c @@ -10,7 +10,7 @@ #include "zdtmtst.h" -#define TEST_HZ 4 +#define TEST_HZ 4 #define NR_FAILS 10 int main(int argc, char **argv) @@ -48,7 +48,7 @@ int main(int argc, char **argv) gettimeofday(&end, NULL); end.tv_usec += end.tv_sec * 1000000; delta = end.tv_usec - start.tv_usec; - if (labs(delta - 1000000 / TEST_HZ ) > 100000) { + if (labs(delta - 1000000 / TEST_HZ) > 100000) { pr_perror("delta = %ld", delta); fail--; if (fail == 0) diff --git a/test/zdtm/static/s390x_gs_threads.c b/test/zdtm/static/s390x_gs_threads.c index 6f6e7de22..3944062e3 100644 --- a/test/zdtm/static/s390x_gs_threads.c +++ b/test/zdtm/static/s390x_gs_threads.c @@ -10,13 +10,13 @@ #include "zdtmtst.h" #include "lock.h" -#define NR_THREADS 4 -#define GS_ENABLE 0 -#define GS_SET_BC_CB 2 -#define GS_BROADCAST 4 +#define NR_THREADS 4 +#define GS_ENABLE 0 +#define GS_SET_BC_CB 2 +#define GS_BROADCAST 4 #ifndef __NR_guarded_storage -#define __NR_guarded_storage 378 +#define __NR_guarded_storage 378 #endif const char *test_doc = "Check the guarded storage broadcast"; @@ -60,12 +60,11 @@ static futex_t futex2; * Load guarded-storage */ void load_guarded(unsigned long *mem); -asm( - ".global load_guarded\n" - "load_guarded:\n" - " .insn rxy,0xe3000000004c,%r2,0(%r2)\n" - " br %r14\n" - " .size load_guarded,.-load_guarded\n"); +asm(".global load_guarded\n" + "load_guarded:\n" + " .insn rxy,0xe3000000004c,%r2,0(%r2)\n" + " br %r14\n" + " .size load_guarded,.-load_guarded\n"); /* * Inline assembly to deal with interrupted context to the call of @@ -73,23 +72,22 @@ asm( * function. */ void gs_handler_asm(void); -asm( - ".globl gs_handler_asm\n" - "gs_handler_asm:\n" - " lgr %r14,%r15\n" - " aghi %r15,-320\n" - " stmg %r0,%r14,192(%r15)\n" - " stg %r14,312(%r14)\n" - " la %r2,160(%r15)\n" - " .insn rxy,0xe30000000049,0,160(%r15)\n" - " lg %r14,24(%r2)\n" - " lg %r14,40(%r14)\n" - " la %r14,6(%r14)\n" - " stg %r14,304(%r15)\n" - " brasl %r14,gs_handler\n" - " lmg %r0,%r15,192(%r15)\n" - " br %r14\n" - " .size gs_handler_asm,.-gs_handler_asm\n"); +asm(".globl gs_handler_asm\n" + "gs_handler_asm:\n" + " lgr %r14,%r15\n" + " aghi %r15,-320\n" + " stmg %r0,%r14,192(%r15)\n" + " stg %r14,312(%r14)\n" + " la %r2,160(%r15)\n" + " .insn rxy,0xe30000000049,0,160(%r15)\n" + " lg %r14,24(%r2)\n" + " lg %r14,40(%r14)\n" + " la %r14,6(%r14)\n" + " stg %r14,304(%r15)\n" + " brasl %r14,gs_handler\n" + " lmg %r0,%r15,192(%r15)\n" + " br %r14\n" + " .size gs_handler_asm,.-gs_handler_asm\n"); /* * GS handler called when GS event occurs @@ -123,14 +121,14 @@ static void *thread_run(void *param) } gs_cb->gsd = 0x1234000000UL | 26; gs_cb->gssm = -1UL; - gs_cb->gs_epl_a = (unsigned long) gs_epl; - gs_epl[1] = (unsigned long) gs_handler_asm; + gs_cb->gs_epl_a = (unsigned long)gs_epl; + gs_epl[1] = (unsigned long)gs_handler_asm; /* Set the GS broadcast control block */ syscall(__NR_guarded_storage, GS_SET_BC_CB, gs_cb); futex_dec_and_wake(&futex); /* Wait for all threads to set the GS broadcast control block */ futex_wait_until(&futex, 0); - test_msg("Thread %016lx staring loop\n", syscall(SYS_gettid)); + test_msg("Thread %016lx staring loop\n", syscall(SYS_gettid)); /* * Designate a guarded-storage section until the main task * performs the GS_BROADCAST action and the following load_guarded diff --git a/test/zdtm/static/s390x_mmap_high.c b/test/zdtm/static/s390x_mmap_high.c index c4bd1c83d..6349113b7 100644 --- a/test/zdtm/static/s390x_mmap_high.c +++ b/test/zdtm/static/s390x_mmap_high.c @@ -5,23 +5,22 @@ #include "zdtmtst.h" -#define TASK_SIZE_LEVEL_4 0x20000000000000UL /* 8 PB */ -#define MAP_SIZE 0x1000 -#define VAL 0x77 +#define TASK_SIZE_LEVEL_4 0x20000000000000UL /* 8 PB */ +#define MAP_SIZE 0x1000 +#define VAL 0x77 -const char *test_doc = "Verify that tasks > 4TB can be checkpointed"; -const char *test_author = "Michael Holzheu <holzheu@linux.vnet.ibm.com>"; +const char *test_doc = "Verify that tasks > 4TB can be checkpointed"; +const char *test_author = "Michael Holzheu <holzheu@linux.vnet.ibm.com>"; /* * Map memory at the very end of the 8 PB address space */ int main(int argc, char **argv) { - void *addr = (void *) TASK_SIZE_LEVEL_4 - MAP_SIZE; + void *addr = (void *)TASK_SIZE_LEVEL_4 - MAP_SIZE; char *buf; int i; - test_init(argc, argv); /* @@ -39,8 +38,7 @@ int main(int argc, char **argv) } /* Map memory at the very end of the 8 PB address space */ - buf = mmap(addr, MAP_SIZE, PROT_WRITE | PROT_READ, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + buf = mmap(addr, MAP_SIZE, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); if (buf == MAP_FAILED) { pr_perror("Could not create mapping"); exit(1); diff --git a/test/zdtm/static/s390x_regs_check.c b/test/zdtm/static/s390x_regs_check.c index 9aaf41951..8d6b47997 100644 --- a/test/zdtm/static/s390x_regs_check.c +++ b/test/zdtm/static/s390x_regs_check.c @@ -48,7 +48,7 @@ const char *test_author = "Michael Holzheu <holzheu@linux.vnet.ibm.com>"; * $ zdtmp.py run --norst --pre 2 -t zdtm/static/s390x_regs_check * $ zdtmp.py run --check-only -t zdtm/static/s390x_regs_check */ -#define NR_THREADS 2 +#define NR_THREADS 2 #define NR_THREADS_ALL (NR_THREADS + 1) static pid_t thread_pids[NR_THREADS_ALL]; @@ -58,222 +58,198 @@ static int pipefd[2]; * Generic structure to define a register set and test data */ struct reg_set { - const char *name; /* Name of regset */ - int nr; /* Number of regset */ - void *data; /* Test data */ - int len; /* Number of bytes of test data */ - bool optional; /* Not all kernels/machines have this reg set */ - bool available; /* Current kernel/machine has this reg set */ + const char *name; /* Name of regset */ + int nr; /* Number of regset */ + void *data; /* Test data */ + int len; /* Number of bytes of test data */ + bool optional; /* Not all kernels/machines have this reg set */ + bool available; /* Current kernel/machine has this reg set */ }; /* * s390 floating point registers */ struct prfpreg { - uint32_t fpc; - uint64_t fprs[16]; + uint32_t fpc; + uint64_t fprs[16]; }; -struct prfpreg prfpreg_data = { - .fpc = 0, - .fprs = { - 0x0000000000000000, - 0x1111111111111110, - 0x2222222222222220, - 0x3333333333333330, - 0x4444444444444440, - 0x5555555555555550, - 0x6666666666666660, - 0x7777777777777770, - 0x8888888888888880, - 0x9999999999999990, - 0xaaaaaaaaaaaaaaa0, - 0xbbbbbbbbbbbbbbb0, - 0xccccccccccccccc0, - 0xddddddddddddddd0, - 0xeeeeeeeeeeeeeee0, - 0xfffffffffffffff0, - } -}; +struct prfpreg prfpreg_data = { .fpc = 0, + .fprs = { + 0x0000000000000000, + 0x1111111111111110, + 0x2222222222222220, + 0x3333333333333330, + 0x4444444444444440, + 0x5555555555555550, + 0x6666666666666660, + 0x7777777777777770, + 0x8888888888888880, + 0x9999999999999990, + 0xaaaaaaaaaaaaaaa0, + 0xbbbbbbbbbbbbbbb0, + 0xccccccccccccccc0, + 0xddddddddddddddd0, + 0xeeeeeeeeeeeeeee0, + 0xfffffffffffffff0, + } }; struct reg_set reg_set_prfpreg = { - .name = "PRFPREG", - .nr = NT_PRFPREG, - .data = &prfpreg_data, - .len = sizeof(prfpreg_data), - .optional = false, + .name = "PRFPREG", + .nr = NT_PRFPREG, + .data = &prfpreg_data, + .len = sizeof(prfpreg_data), + .optional = false, }; /* * s390 vector VXRS_LOW registers */ -#define NT_S390_VXRS_LOW 0x309 +#define NT_S390_VXRS_LOW 0x309 struct vxrs_low { - uint64_t regs[16]; + uint64_t regs[16]; }; -struct vxrs_low vxrs_low_data = { - .regs = { - 0x0000000000000001, - 0x1111111111111111, - 0x2222222222222221, - 0x3333333333333331, - 0x4444444444444441, - 0x5555555555555551, - 0x6666666666666661, - 0x7777777777777771, - 0x8888888888888881, - 0x9999999999999991, - 0xaaaaaaaaaaaaaaa1, - 0xbbbbbbbbbbbbbbb1, - 0xccccccccccccccc1, - 0xddddddddddddddd1, - 0xeeeeeeeeeeeeeee1, - 0xfffffffffffffff1, - } -}; +struct vxrs_low vxrs_low_data = { .regs = { + 0x0000000000000001, + 0x1111111111111111, + 0x2222222222222221, + 0x3333333333333331, + 0x4444444444444441, + 0x5555555555555551, + 0x6666666666666661, + 0x7777777777777771, + 0x8888888888888881, + 0x9999999999999991, + 0xaaaaaaaaaaaaaaa1, + 0xbbbbbbbbbbbbbbb1, + 0xccccccccccccccc1, + 0xddddddddddddddd1, + 0xeeeeeeeeeeeeeee1, + 0xfffffffffffffff1, + } }; struct reg_set reg_set_vxrs_low = { - .name = "VXRS_LOW", - .nr = NT_S390_VXRS_LOW, - .data = &vxrs_low_data, - .len = sizeof(vxrs_low_data), - .optional = true, + .name = "VXRS_LOW", + .nr = NT_S390_VXRS_LOW, + .data = &vxrs_low_data, + .len = sizeof(vxrs_low_data), + .optional = true, }; /* * s390 vector VXRS_HIGH registers */ -#define NT_S390_VXRS_HIGH 0x30a +#define NT_S390_VXRS_HIGH 0x30a struct vxrs_high { - uint64_t regs[32]; + uint64_t regs[32]; }; -struct vxrs_high vxrs_high_data = { - .regs = { - 0x0000000000000002, 0x0000000000000002, - 0x1111111111111112, 0x1111111111111112, - 0x2222222222222222, 0x2222222222222222, - 0x3333333333333332, 0x3333333333333332, - 0x4444444444444442, 0x4444444444444442, - 0x5555555555555552, 0x5555555555555552, - 0x6666666666666662, 0x6666666666666662, - 0x7777777777777772, 0x7777777777777772, - 0x8888888888888882, 0x8888888888888882, - 0x9999999999999992, 0x9999999999999992, - 0xaaaaaaaaaaaaaaa2, 0xaaaaaaaaaaaaaaa2, - 0xbbbbbbbbbbbbbbb2, 0xbbbbbbbbbbbbbbb2, - 0xccccccccccccccc2, 0xccccccccccccccc2, - 0xddddddddddddddd2, 0xddddddddddddddd2, - 0xeeeeeeeeeeeeeee2, 0xeeeeeeeeeeeeeee2, - 0xfffffffffffffff2, 0xfffffffffffffff2, - } -}; +struct vxrs_high vxrs_high_data = { .regs = { + 0x0000000000000002, 0x0000000000000002, 0x1111111111111112, + 0x1111111111111112, 0x2222222222222222, 0x2222222222222222, + 0x3333333333333332, 0x3333333333333332, 0x4444444444444442, + 0x4444444444444442, 0x5555555555555552, 0x5555555555555552, + 0x6666666666666662, 0x6666666666666662, 0x7777777777777772, + 0x7777777777777772, 0x8888888888888882, 0x8888888888888882, + 0x9999999999999992, 0x9999999999999992, 0xaaaaaaaaaaaaaaa2, + 0xaaaaaaaaaaaaaaa2, 0xbbbbbbbbbbbbbbb2, 0xbbbbbbbbbbbbbbb2, + 0xccccccccccccccc2, 0xccccccccccccccc2, 0xddddddddddddddd2, + 0xddddddddddddddd2, 0xeeeeeeeeeeeeeee2, 0xeeeeeeeeeeeeeee2, + 0xfffffffffffffff2, 0xfffffffffffffff2, + } }; struct reg_set reg_set_vxrs_high = { - .name = "VXRS_HIGH", - .nr = NT_S390_VXRS_HIGH, - .data = &vxrs_high_data, - .len = sizeof(vxrs_high_data), - .optional = true, + .name = "VXRS_HIGH", + .nr = NT_S390_VXRS_HIGH, + .data = &vxrs_high_data, + .len = sizeof(vxrs_high_data), + .optional = true, }; /* * s390 guarded-storage registers */ -#define NT_S390_GS_CB 0x30b -#define NT_S390_GS_BC 0x30c +#define NT_S390_GS_CB 0x30b +#define NT_S390_GS_BC 0x30c struct gs_cb { uint64_t regs[4]; }; -struct gs_cb gs_cb_data = { - .regs = { - 0x0000000000000000, - 0x000000123400001a, - 0x5555555555555555, - 0x000000014b58a010, - } -}; +struct gs_cb gs_cb_data = { .regs = { + 0x0000000000000000, + 0x000000123400001a, + 0x5555555555555555, + 0x000000014b58a010, + } }; struct reg_set reg_set_gs_cb = { - .name = "GS_CB", - .nr = NT_S390_GS_CB, - .data = &gs_cb_data, - .len = sizeof(gs_cb_data), - .optional = true, + .name = "GS_CB", + .nr = NT_S390_GS_CB, + .data = &gs_cb_data, + .len = sizeof(gs_cb_data), + .optional = true, }; -struct gs_cb gs_bc_data = { - .regs = { - 0x0000000000000000, - 0x000000123400001a, - 0xffffffffffffffff, - 0x0000000aaaaaaaaa, - } -}; +struct gs_cb gs_bc_data = { .regs = { + 0x0000000000000000, + 0x000000123400001a, + 0xffffffffffffffff, + 0x0000000aaaaaaaaa, + } }; struct reg_set reg_set_gs_bc = { - .name = "GS_BC_CB", - .nr = NT_S390_GS_BC, - .data = &gs_bc_data, - .len = sizeof(gs_bc_data), - .optional = true, + .name = "GS_BC_CB", + .nr = NT_S390_GS_BC, + .data = &gs_bc_data, + .len = sizeof(gs_bc_data), + .optional = true, }; /* * s390 runtime-instrumentation control block */ -#define NT_S390_RI_CB 0x30d +#define NT_S390_RI_CB 0x30d struct ri_cb { uint64_t regs[8]; }; -struct ri_cb ri_cb_data = { - .regs = { - 0x000002aa13aae000, - 0x000002aa13aad000, - 0x000002aa13aadfff, - 0xe0a1000400000000, - 0x0000000000000000, - 0x0000000000004e20, - 0x0000000000003479, - 0x0000000000000000, - } -}; +struct ri_cb ri_cb_data = { .regs = { + 0x000002aa13aae000, + 0x000002aa13aad000, + 0x000002aa13aadfff, + 0xe0a1000400000000, + 0x0000000000000000, + 0x0000000000004e20, + 0x0000000000003479, + 0x0000000000000000, + } }; struct reg_set reg_set_ri_cb = { - .name = "RI_CB", - .nr = NT_S390_RI_CB, - .data = &ri_cb_data, - .len = sizeof(ri_cb_data), - .optional = true, + .name = "RI_CB", + .nr = NT_S390_RI_CB, + .data = &ri_cb_data, + .len = sizeof(ri_cb_data), + .optional = true, }; /* * Vector with all regsets */ struct reg_set *reg_set_vec[] = { - ®_set_prfpreg, - ®_set_vxrs_low, - ®_set_vxrs_high, - ®_set_gs_cb, - ®_set_gs_bc, - ®_set_ri_cb, - NULL, + ®_set_prfpreg, ®_set_vxrs_low, ®_set_vxrs_high, ®_set_gs_cb, ®_set_gs_bc, ®_set_ri_cb, NULL, }; /* * Print hexdump for buffer with variable group parameter */ -void util_hexdump_grp(const char *tag, const void *data, int grp, - int count, int indent) +void util_hexdump_grp(const char *tag, const void *data, int grp, int count, int indent) { char str[1024], *ptr = str; const char *buf = data; @@ -325,19 +301,16 @@ static int set_regset(pid_t pid, struct reg_set *reg_set) switch (errno) { case EOPNOTSUPP: case ENODEV: - test_msg(" REGSET: %12s -> not supported by machine\n", - reg_set->name); + test_msg(" REGSET: %12s -> not supported by machine\n", reg_set->name); return 0; case EINVAL: - test_msg(" REGSET: %12s -> not supported by kernel\n", - reg_set->name); + test_msg(" REGSET: %12s -> not supported by kernel\n", reg_set->name); return 0; default: break; } } - pr_perror("PTRACE_SETREGSET for %s failed for pid %d", - reg_set->name, pid); + pr_perror("PTRACE_SETREGSET for %s failed for pid %d", reg_set->name, pid); return -1; } @@ -373,8 +346,7 @@ static int check_regset(pid_t pid, struct reg_set *reg_set) iov.iov_len = reg_set->len; if (ptrace(PTRACE_GETREGSET, pid, reg_set->nr, iov) != 0) { - pr_perror("PTRACE_SETREGSET for %s failed for pid %d", - reg_set->name, pid); + pr_perror("PTRACE_SETREGSET for %s failed for pid %d", reg_set->name, pid); free(data); return -1; } @@ -423,14 +395,15 @@ static inline void send_tid_and_loop(int fd) { int tid = syscall(__NR_gettid); - asm volatile( - "lgr 2,%0\n" /* Arg 1: fd */ + asm volatile("lgr 2,%0\n" /* Arg 1: fd */ "la 3,%1\n" /* Arg 2: &tid */ - "lghi 4,4\n" /* Arg 3: sizeof(int) */ - "svc 4\n" /* __NR_write SVC: */ + "lghi 4,4\n" /* Arg 3: sizeof(int) */ + "svc 4\n" /* __NR_write SVC: */ /* After SVC no more registers are changed */ "0: j 0b\n" /* Loop here */ - : : "d" (fd), "Q" (tid) : "2", "3", "4"); + : + : "d"(fd), "Q"(tid) + : "2", "3", "4"); } /* @@ -501,8 +474,7 @@ int main(int argc, char *argv[]) test_init(argc, argv); - test_msg("------------- START 1 PROCESS + %d THREADS ---------------\n", - NR_THREADS); + test_msg("------------- START 1 PROCESS + %d THREADS ---------------\n", NR_THREADS); if (pipe(pipefd) == -1) { perror("pipe failed"); exit(EXIT_FAILURE); diff --git a/test/zdtm/static/s390x_runtime_instr.c b/test/zdtm/static/s390x_runtime_instr.c index ff692d7c6..e6c55d3ff 100644 --- a/test/zdtm/static/s390x_runtime_instr.c +++ b/test/zdtm/static/s390x_runtime_instr.c @@ -19,61 +19,61 @@ #include "zdtmtst.h" #ifndef __NR_s390_runtime_instr -#define __NR_s390_runtime_instr 342 +#define __NR_s390_runtime_instr 342 #endif -#define NT_S390_RI_CB 0x30d +#define NT_S390_RI_CB 0x30d -#define BUF_SIZE (1024*1024) +#define BUF_SIZE (1024 * 1024) -const char *test_doc = "Check runtime-instrumentation"; +const char *test_doc = "Check runtime-instrumentation"; /* Original test provided by Martin Schwidefsky <schwidefsky@de.ibm.com> */ -const char *test_author = "Alice Frosi <alice@linux.vnet.ibm.com>"; +const char *test_author = "Alice Frosi <alice@linux.vnet.ibm.com>"; struct runtime_instr_cb { unsigned long rca; unsigned long roa; unsigned long rla; - unsigned int v : 1; - unsigned int s : 1; - unsigned int k : 1; - unsigned int h : 1; - unsigned int a : 1; - unsigned int reserved1 : 3; - unsigned int ps : 1; - unsigned int qs : 1; - unsigned int pc : 1; - unsigned int qc : 1; - unsigned int reserved2 : 1; - unsigned int g : 1; - unsigned int u : 1; - unsigned int l : 1; - unsigned int key : 4; - unsigned int reserved3 : 8; - unsigned int t : 1; - unsigned int rgs : 3; - - unsigned int m : 4; - unsigned int n : 1; - unsigned int mae : 1; - unsigned int reserved4 : 2; - unsigned int c : 1; - unsigned int r : 1; - unsigned int b : 1; - unsigned int j : 1; - unsigned int e : 1; - unsigned int x : 1; - unsigned int reserved5 : 2; - unsigned int bpxn : 1; - unsigned int bpxt : 1; - unsigned int bpti : 1; - unsigned int bpni : 1; - unsigned int reserved6 : 2; - - unsigned int d : 1; - unsigned int f : 1; - unsigned int ic : 4; - unsigned int dc : 4; + unsigned int v : 1; + unsigned int s : 1; + unsigned int k : 1; + unsigned int h : 1; + unsigned int a : 1; + unsigned int reserved1 : 3; + unsigned int ps : 1; + unsigned int qs : 1; + unsigned int pc : 1; + unsigned int qc : 1; + unsigned int reserved2 : 1; + unsigned int g : 1; + unsigned int u : 1; + unsigned int l : 1; + unsigned int key : 4; + unsigned int reserved3 : 8; + unsigned int t : 1; + unsigned int rgs : 3; + + unsigned int m : 4; + unsigned int n : 1; + unsigned int mae : 1; + unsigned int reserved4 : 2; + unsigned int c : 1; + unsigned int r : 1; + unsigned int b : 1; + unsigned int j : 1; + unsigned int e : 1; + unsigned int x : 1; + unsigned int reserved5 : 2; + unsigned int bpxn : 1; + unsigned int bpxt : 1; + unsigned int bpti : 1; + unsigned int bpni : 1; + unsigned int reserved6 : 2; + + unsigned int d : 1; + unsigned int f : 1; + unsigned int ic : 4; + unsigned int dc : 4; unsigned long reserved7; unsigned long sf; @@ -88,8 +88,8 @@ static inline unsigned long extract_psw(void) { unsigned int reg1, reg2; - asm volatile("epsw %0,%1" : "=d" (reg1), "=a" (reg2)); - return (((unsigned long) reg1) << 32) | ((unsigned long) reg2); + asm volatile("epsw %0,%1" : "=d"(reg1), "=a"(reg2)); + return (((unsigned long)reg1) << 32) | ((unsigned long)reg2); } /* @@ -97,7 +97,7 @@ static inline unsigned long extract_psw(void) */ static inline void rion(void) { - asm volatile (".word 0xaa01, 0x0000"); + asm volatile(".word 0xaa01, 0x0000"); } /* @@ -105,7 +105,7 @@ static inline void rion(void) */ static inline void rioff(void) { - asm volatile (".word 0xaa03, 0x0000"); + asm volatile(".word 0xaa03, 0x0000"); } /* @@ -113,7 +113,7 @@ static inline void rioff(void) */ static inline void mric(struct runtime_instr_cb *cb) { - asm volatile(".insn rsy,0xeb0000000062,0,0,%0" : : "Q" (*cb)); + asm volatile(".insn rsy,0xeb0000000062,0,0,%0" : : "Q"(*cb)); } /* @@ -121,7 +121,7 @@ static inline void mric(struct runtime_instr_cb *cb) */ static inline void stric(struct runtime_instr_cb *cb) { - asm volatile(".insn rsy,0xeb0000000061,0,0,%0" : "=Q" (*cb) : : "cc"); + asm volatile(".insn rsy,0xeb0000000061,0,0,%0" : "=Q"(*cb) : : "cc"); } /* @@ -130,8 +130,8 @@ static inline void stric(struct runtime_instr_cb *cb) int main(int argc, char **argv) { struct runtime_instr_cb ricb, ricb_check; - unsigned long *ricb_check_ptr = (unsigned long *) &ricb_check; - unsigned long *ricb_ptr = (unsigned long *) &ricb; + unsigned long *ricb_check_ptr = (unsigned long *)&ricb_check; + unsigned long *ricb_ptr = (unsigned long *)&ricb; unsigned long psw_mask; void *buf; int i; @@ -155,8 +155,8 @@ int main(int argc, char **argv) return -1; } /* Set buffer for RI */ - ricb.rca = ricb.roa = (unsigned long) buf; - ricb.rla = (unsigned long) buf + BUF_SIZE; + ricb.rca = ricb.roa = (unsigned long)buf; + ricb.rla = (unsigned long)buf + BUF_SIZE; mric(&ricb); /* Enable RI - afterwards the PSW will have RI bit set */ rion(); @@ -204,8 +204,7 @@ int main(int argc, char **argv) /* Skip sf field because its value may change */ if (i == 6) continue; - fail("%d:Got %016lx expected %016lx", - i, ricb_ptr[i], ricb_check_ptr[i]); + fail("%d:Got %016lx expected %016lx", i, ricb_ptr[i], ricb_check_ptr[i]); return -1; } diff --git a/test/zdtm/static/sched_policy00.c b/test/zdtm/static/sched_policy00.c index 7312abd6b..794c11af2 100644 --- a/test/zdtm/static/sched_policy00.c +++ b/test/zdtm/static/sched_policy00.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check sched policy to be preserved"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check sched policy to be preserved"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; static const int parm = 3; @@ -23,7 +23,7 @@ static int do_nothing(void) return -1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pid, ret, err = 0; struct sched_param p; @@ -82,7 +82,6 @@ int main(int argc, char ** argv) fprintf(file, "%d\n", old_rt_runtime_us); fclose(file); } - } return err; } diff --git a/test/zdtm/static/sched_prio00.c b/test/zdtm/static/sched_prio00.c index ea4a2ee13..4bc878786 100644 --- a/test/zdtm/static/sched_prio00.c +++ b/test/zdtm/static/sched_prio00.c @@ -11,10 +11,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check sched prios to be preserved"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check sched prios to be preserved"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; -#define NRTASKS 3 +#define NRTASKS 3 static int do_nothing(void) { @@ -32,7 +32,7 @@ static void kill_all(int *pid, int n) kill(pid[i], SIGKILL); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pid[NRTASKS], i, parm[NRTASKS], ret; diff --git a/test/zdtm/static/scm00.c b/test/zdtm/static/scm00.c index de626d9c9..d66975582 100644 --- a/test/zdtm/static/scm00.c +++ b/test/zdtm/static/scm00.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that SCM_RIGHTS are preserved"; -const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; +const char *test_doc = "Check that SCM_RIGHTS are preserved"; +const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; static int send_fd(int via, int fd) { diff --git a/test/zdtm/static/scm03.c b/test/zdtm/static/scm03.c index cf6049781..a40fc0101 100644 --- a/test/zdtm/static/scm03.c +++ b/test/zdtm/static/scm03.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that SCM_RIGHTS are preserved"; -const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; +const char *test_doc = "Check that SCM_RIGHTS are preserved"; +const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; static int send_fd(int via, int fd1, int fd2) { diff --git a/test/zdtm/static/scm05.c b/test/zdtm/static/scm05.c index c17bddda3..ebafc93e7 100644 --- a/test/zdtm/static/scm05.c +++ b/test/zdtm/static/scm05.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that SCM_RIGHTS are preserved"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; +const char *test_doc = "Check that SCM_RIGHTS are preserved"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; static int send_fd(int via, int fd) { @@ -82,7 +82,7 @@ int main(int argc, char **argv) { struct epoll_event event = { .events = EPOLLIN, - }; + }; int sk[2], ep, ret; test_init(argc, argv); diff --git a/test/zdtm/static/scm06.c b/test/zdtm/static/scm06.c index 6c9a78b4d..2d62f6695 100644 --- a/test/zdtm/static/scm06.c +++ b/test/zdtm/static/scm06.c @@ -11,8 +11,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check a send of looped unix sockets"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; +const char *test_doc = "Check a send of looped unix sockets"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; static int send_fd(int via, int fd) { @@ -99,8 +99,7 @@ int main(int argc, char **argv) for (i = 0; i < 2; i++) { addr.sun_path[0] = '\0'; addr.sun_path[1] = i; - if (bind(ska[i], (struct sockaddr *)&addr, - sizeof(addr.sun_family) + 2)) { + if (bind(ska[i], (struct sockaddr *)&addr, sizeof(addr.sun_family) + 2)) { fail("Can't bind"); exit(1); } diff --git a/test/zdtm/static/seccomp_filter.c b/test/zdtm/static/seccomp_filter.c index 501a4941c..757591e24 100644 --- a/test/zdtm/static/seccomp_filter.c +++ b/test/zdtm/static/seccomp_filter.c @@ -18,8 +18,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that SECCOMP_MODE_FILTER is restored"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that SECCOMP_MODE_FILTER is restored"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #ifdef __NR_seccomp @@ -52,14 +52,14 @@ int get_seccomp_mode(pid_t pid) int filter_syscall(int syscall_nr) { struct sock_filter filter[] = { - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, syscall_nr, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, nr)), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, syscall_nr, 0, 1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_KILL), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), }; struct sock_fprog bpf_prog = { - .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), + .len = (unsigned short)(sizeof(filter) / sizeof(filter[0])), .filter = filter, }; @@ -71,7 +71,7 @@ int filter_syscall(int syscall_nr) return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { pid_t pid; int mode, status; @@ -92,7 +92,6 @@ int main(int argc, char ** argv) } if (pid == 0) { - sk = sk_pair[1]; close(sk_pair[0]); diff --git a/test/zdtm/static/seccomp_filter_inheritance.c b/test/zdtm/static/seccomp_filter_inheritance.c index 3129185ea..7a86cd85e 100644 --- a/test/zdtm/static/seccomp_filter_inheritance.c +++ b/test/zdtm/static/seccomp_filter_inheritance.c @@ -11,15 +11,15 @@ #include <sys/syscall.h> #ifdef __NR_seccomp -# include <linux/seccomp.h> -# include <linux/filter.h> -# include <linux/limits.h> +#include <linux/seccomp.h> +#include <linux/filter.h> +#include <linux/limits.h> #endif #include "zdtmtst.h" -const char *test_doc = "Check that SECCOMP_MODE_FILTER is restored"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that SECCOMP_MODE_FILTER is restored"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #ifdef __NR_seccomp @@ -52,14 +52,14 @@ int get_seccomp_mode(pid_t pid) int filter_syscall(int syscall_nr) { struct sock_filter filter[] = { - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, syscall_nr, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, nr)), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, syscall_nr, 0, 1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_KILL), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), }; struct sock_fprog bpf_prog = { - .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), + .len = (unsigned short)(sizeof(filter) / sizeof(filter[0])), .filter = filter, }; @@ -71,7 +71,7 @@ int filter_syscall(int syscall_nr) return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { pid_t pid; int mode, status; @@ -92,7 +92,6 @@ int main(int argc, char ** argv) } if (pid == 0) { - pid_t pid2; sk = sk_pair[1]; @@ -112,7 +111,6 @@ int main(int argc, char ** argv) _exit(1); if (!pid2) { - if (write(sk, &c, 1) != 1) { pr_perror("write"); _exit(1); @@ -181,7 +179,6 @@ err: return 1; } - #else /* __NR_seccomp */ #define TEST_SKIP_REASON "incompatible kernel (no seccomp)" diff --git a/test/zdtm/static/seccomp_filter_threads.c b/test/zdtm/static/seccomp_filter_threads.c index 8d5b77d16..6c84ada1f 100644 --- a/test/zdtm/static/seccomp_filter_threads.c +++ b/test/zdtm/static/seccomp_filter_threads.c @@ -12,10 +12,10 @@ #include <sys/mman.h> #ifdef __NR_seccomp -# include <linux/seccomp.h> -# include <linux/filter.h> -# include <linux/limits.h> -# include <pthread.h> +#include <linux/seccomp.h> +#include <linux/filter.h> +#include <linux/limits.h> +#include <pthread.h> #endif #include "zdtmtst.h" @@ -29,12 +29,15 @@ #define SECCOMP_FILTER_FLAG_TSYNC 1 #endif -const char *test_doc = "Check threads to carry different seccomps"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check threads to carry different seccomps"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; #ifdef __NR_seccomp -static long sys_gettid(void) { return syscall(__NR_gettid); } +static long sys_gettid(void) +{ + return syscall(__NR_gettid); +} static futex_t *wait_rdy; static futex_t *wait_run; @@ -70,14 +73,14 @@ int get_seccomp_mode(pid_t pid) int filter_syscall(int syscall_nr, unsigned int flags) { struct sock_filter filter[] = { - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, syscall_nr, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO | (SECCOMP_RET_DATA & magic)), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, nr)), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, syscall_nr, 0, 1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ERRNO | (SECCOMP_RET_DATA & magic)), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), }; struct sock_fprog bpf_prog = { - .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), + .len = (unsigned short)(sizeof(filter) / sizeof(filter[0])), .filter = filter, }; @@ -89,21 +92,28 @@ int filter_syscall(int syscall_nr, unsigned int flags) return 0; } -int tigger_ptrace(void) { return ptrace(PTRACE_TRACEME); } -int trigger_prctl(void) { return prctl(PR_SET_PDEATHSIG, 9, 0, 0, 0); } -int trigger_mincore(void) { return mincore(NULL, 0, NULL); } - -#define gen_param(__syscall_nr, __trigger) \ -{ \ - .syscall_name = # __syscall_nr, \ - .syscall_nr = __syscall_nr, \ - .trigger = __trigger, \ +int tigger_ptrace(void) +{ + return ptrace(PTRACE_TRACEME); +} +int trigger_prctl(void) +{ + return prctl(PR_SET_PDEATHSIG, 9, 0, 0, 0); +} +int trigger_mincore(void) +{ + return mincore(NULL, 0, NULL); } +#define gen_param(__syscall_nr, __trigger) \ + { \ + .syscall_name = #__syscall_nr, .syscall_nr = __syscall_nr, .trigger = __trigger, \ + } + struct { - char *syscall_name; - unsigned int syscall_nr; - int (*trigger)(void); + char *syscall_name; + unsigned int syscall_nr; + int (*trigger)(void); } pthread_seccomp_params[] = { gen_param(__NR_ptrace, tigger_ptrace), gen_param(__NR_prctl, trigger_prctl), @@ -115,21 +125,17 @@ struct { void *thread_main(void *arg) { int ret; - size_t nr = (long) arg; + size_t nr = (long)arg; if (filter_syscall(pthread_seccomp_params[nr].syscall_nr, 0) < 0) pthread_exit((void *)1); - test_msg("%s filtered inside a sole thread %lu\n", - pthread_seccomp_params[nr].syscall_name, - sys_gettid()); + test_msg("%s filtered inside a sole thread %lu\n", pthread_seccomp_params[nr].syscall_name, sys_gettid()); futex_inc_and_wake(wait_rdy); futex_wait_while_lt(wait_run, 1); - test_msg("Triggering %zu %s thread %lu\n", - nr, pthread_seccomp_params[nr].syscall_name, - sys_gettid()); + test_msg("Triggering %zu %s thread %lu\n", nr, pthread_seccomp_params[nr].syscall_name, sys_gettid()); ret = pthread_seccomp_params[nr].trigger(); if (ret == -1 && errno == magic) @@ -139,7 +145,7 @@ void *thread_main(void *arg) return (void *)1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int ret, mode, status; size_t i; @@ -147,10 +153,8 @@ int main(int argc, char ** argv) test_init(argc, argv); - wait_rdy = mmap(NULL, sizeof(*wait_rdy), PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); - wait_run = mmap(NULL, sizeof(*wait_rdy), PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); + wait_rdy = mmap(NULL, sizeof(*wait_rdy), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); + wait_run = mmap(NULL, sizeof(*wait_rdy), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (wait_rdy == MAP_FAILED || wait_run == MAP_FAILED) { pr_perror("mmap failed"); @@ -169,7 +173,6 @@ int main(int argc, char ** argv) return -1; } - if (pid == 0) { pthread_t thread[ARRAY_SIZE(pthread_seccomp_params)]; void *ret; diff --git a/test/zdtm/static/seccomp_filter_tsync.c b/test/zdtm/static/seccomp_filter_tsync.c index 739ea96f7..41be83426 100644 --- a/test/zdtm/static/seccomp_filter_tsync.c +++ b/test/zdtm/static/seccomp_filter_tsync.c @@ -11,10 +11,10 @@ #include <sys/syscall.h> #ifdef __NR_seccomp -# include <linux/seccomp.h> -# include <linux/filter.h> -# include <linux/limits.h> -# include <pthread.h> +#include <linux/seccomp.h> +#include <linux/filter.h> +#include <linux/limits.h> +#include <pthread.h> #endif #include "zdtmtst.h" @@ -27,8 +27,8 @@ #define SECCOMP_FILTER_FLAG_TSYNC 1 #endif -const char *test_doc = "Check that SECCOMP_FILTER_FLAG_TSYNC works correctly after restore"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that SECCOMP_FILTER_FLAG_TSYNC works correctly after restore"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #ifdef __NR_seccomp @@ -65,14 +65,14 @@ int get_seccomp_mode(pid_t pid) int filter_syscall(int syscall_nr, unsigned int flags) { struct sock_filter filter[] = { - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, syscall_nr, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO | (SECCOMP_RET_DATA & magic)), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct seccomp_data, nr)), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, syscall_nr, 0, 1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ERRNO | (SECCOMP_RET_DATA & magic)), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), }; struct sock_fprog bpf_prog = { - .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), + .len = (unsigned short)(sizeof(filter) / sizeof(filter[0])), .filter = filter, }; @@ -101,7 +101,7 @@ void *wait_and_getpid(void *arg) return ((void *)1); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { pid_t pid; int mode, status; diff --git a/test/zdtm/static/seccomp_strict.c b/test/zdtm/static/seccomp_strict.c index 9042924b2..74bb6e9b8 100644 --- a/test/zdtm/static/seccomp_strict.c +++ b/test/zdtm/static/seccomp_strict.c @@ -9,14 +9,14 @@ #include <sys/syscall.h> #ifdef __NR_seccomp -# include <linux/seccomp.h> -# include <linux/limits.h> +#include <linux/seccomp.h> +#include <linux/limits.h> #endif #include "zdtmtst.h" -const char *test_doc = "Check that SECCOMP_MODE_STRICT is restored"; -const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; +const char *test_doc = "Check that SECCOMP_MODE_STRICT is restored"; +const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>"; #ifdef __NR_seccomp @@ -46,7 +46,7 @@ int get_seccomp_mode(pid_t pid) return -1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { pid_t pid; int mode, status; diff --git a/test/zdtm/static/selfexe00.c b/test/zdtm/static/selfexe00.c index bc6117248..4839ea18b 100644 --- a/test/zdtm/static/selfexe00.c +++ b/test/zdtm/static/selfexe00.c @@ -16,10 +16,10 @@ #include "zdtmtst.h" -#define gettid() pthread_self() +#define gettid() pthread_self() -const char *test_doc = "Check if /proc/self/exe points to same location after restore\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Check if /proc/self/exe points to same location after restore\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/selinux00.c b/test/zdtm/static/selinux00.c index be647834d..00aaeb53c 100644 --- a/test/zdtm/static/selinux00.c +++ b/test/zdtm/static/selinux00.c @@ -12,8 +12,8 @@ /* Enabling the right policy happens in selinux00.hook and selinx00.checkskip */ -const char *test_doc = "Check that a SELinux profile is restored"; -const char *test_author = "Adrian Reber <areber@redhat.com>"; +const char *test_doc = "Check that a SELinux profile is restored"; +const char *test_author = "Adrian Reber <areber@redhat.com>"; /* This is all based on Tycho's apparmor code */ @@ -60,7 +60,6 @@ int checkprofile(void) char context[1024]; int len; - fd = open("/proc/self/attr/current", O_RDONLY); if (fd < 0) { fail("Could not open /proc/self/attr/current"); @@ -70,8 +69,7 @@ int checkprofile(void) len = read(fd, context, strlen(CONTEXT)); close(fd); if (len != strlen(CONTEXT)) { - fail("SELinux context has unexpected length %d, expected %zd", - len, strlen(CONTEXT)); + fail("SELinux context has unexpected length %d, expected %zd", len, strlen(CONTEXT)); return -1; } diff --git a/test/zdtm/static/selinux01.c b/test/zdtm/static/selinux01.c index 14e99c739..b9e0a58fc 100644 --- a/test/zdtm/static/selinux01.c +++ b/test/zdtm/static/selinux01.c @@ -14,8 +14,8 @@ /* Enabling the right policy happens in selinux00.hook and selinx00.checkskip */ -const char *test_doc = "Check that a SELinux socket context is restored"; -const char *test_author = "Adrian Reber <areber@redhat.com>"; +const char *test_doc = "Check that a SELinux socket context is restored"; +const char *test_author = "Adrian Reber <areber@redhat.com>"; /* This is all based on Tycho's apparmor code */ @@ -83,7 +83,6 @@ int check_sockcreate(void) char context[1024]; int len; - fd = open("/proc/self/attr/sockcreate", O_RDONLY); if (fd < 0) { fail("Could not open /proc/self/attr/sockcreate"); @@ -93,8 +92,7 @@ int check_sockcreate(void) len = read(fd, context, strlen(CONTEXT)); close(fd); if (len != strlen(CONTEXT)) { - fail("SELinux context has unexpected length %d, expected %zd", - len, strlen(CONTEXT)); + fail("SELinux context has unexpected length %d, expected %zd", len, strlen(CONTEXT)); return -1; } diff --git a/test/zdtm/static/sem.c b/test/zdtm/static/sem.c index 257dd84ca..a3335dcfe 100644 --- a/test/zdtm/static/sem.c +++ b/test/zdtm/static/sem.c @@ -13,12 +13,10 @@ #include "zdtmtst.h" -const char *test_doc="Tests IPC semaphores migrates fine"; -const char *test_author="Stanislav Kinsbursky <skinsbursky@parallels.com>"; +const char *test_doc = "Tests IPC semaphores migrates fine"; +const char *test_author = "Stanislav Kinsbursky <skinsbursky@parallels.com>"; -static int sem_test(int id, - struct sembuf *lock, struct sembuf *unlock, - int lock_ops, int unlock_ops) +static int sem_test(int id, struct sembuf *lock, struct sembuf *unlock, int lock_ops, int unlock_ops) { if (semop(id, lock, lock_ops) == -1) { fail("Failed to lock semaphore"); @@ -38,27 +36,25 @@ static int check_sem_by_key(int key, int num) int id; struct sembuf lock[2] = { { - .sem_num = num, - .sem_op = 0, - .sem_flg = 0, + .sem_num = num, + .sem_op = 0, + .sem_flg = 0, }, { - .sem_num = num, - .sem_op = 1, - .sem_flg = 0, + .sem_num = num, + .sem_op = 1, + .sem_flg = 0, }, }; - struct sembuf unlock[1] = { - { + struct sembuf unlock[1] = { { .sem_num = num, .sem_op = -1, .sem_flg = 0, - } - }; + } }; int val; id = semget(key, NSEMS, 0777); - if (id == -1) { + if (id == -1) { fail("Can't get sem"); return -errno; } @@ -69,9 +65,7 @@ static int check_sem_by_key(int key, int num) return -errno; } - return sem_test(id, lock, unlock, - sizeof(lock)/sizeof(struct sembuf), - sizeof(unlock)/sizeof(struct sembuf)); + return sem_test(id, lock, unlock, sizeof(lock) / sizeof(struct sembuf), sizeof(unlock) / sizeof(struct sembuf)); } static int check_sem_by_id(int id, int num, int val) @@ -79,18 +73,16 @@ static int check_sem_by_id(int id, int num, int val) int curr; struct sembuf lock[] = { { - .sem_num = num, - .sem_op = val, - .sem_flg = 0, + .sem_num = num, + .sem_op = val, + .sem_flg = 0, }, }; - struct sembuf unlock[] = { - { + struct sembuf unlock[] = { { .sem_num = num, - .sem_op = - val * 2, + .sem_op = -val * 2, .sem_flg = 0, - } - }; + } }; curr = semctl(id, num, GETVAL); if (curr < 0) { @@ -101,9 +93,7 @@ static int check_sem_by_id(int id, int num, int val) fail("Sem has wrong value: %d instead of %d", curr, val); return -EFAULT; } - return sem_test(id, lock, unlock, - sizeof(lock)/sizeof(struct sembuf), - sizeof(unlock)/sizeof(struct sembuf)); + return sem_test(id, lock, unlock, sizeof(lock) / sizeof(struct sembuf), sizeof(unlock) / sizeof(struct sembuf)); } int main(int argc, char **argv) @@ -112,10 +102,10 @@ int main(int argc, char **argv) int i; /* See man semctl */ union semun { - int val; - struct semid_ds *buf; - unsigned short *array; - struct seminfo *__buf; + int val; + struct semid_ds *buf; + unsigned short *array; + struct seminfo *__buf; } val[NSEMS]; int ret, fail_count = 0; @@ -128,7 +118,7 @@ int main(int argc, char **argv) } id = semget(key, NSEMS, 0777 | IPC_CREAT | IPC_EXCL); - if (id == -1) { + if (id == -1) { fail_count++; pr_perror("Can't get sem array"); goto out; diff --git a/test/zdtm/static/session00.c b/test/zdtm/static/session00.c index f65b3cdef..147ecfb0a 100644 --- a/test/zdtm/static/session00.c +++ b/test/zdtm/static/session00.c @@ -4,13 +4,13 @@ #include "zdtmtst.h" -const char *test_doc = "Test that sid, pgid are restored"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Test that sid, pgid are restored"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; -#define DETACH 1 -#define NEWSID 2 -#define CHANGESID 4 -#define DOUBLE_CHANGESID 8 +#define DETACH 1 +#define NEWSID 2 +#define CHANGESID 4 +#define DOUBLE_CHANGESID 8 struct testcase { int flags; @@ -18,14 +18,24 @@ struct testcase { pid_t sid; }; -static struct testcase testcases[] = { - {DETACH, }, - {NEWSID, }, - {0, }, - {DETACH|NEWSID, }, - {CHANGESID, }, - {DOUBLE_CHANGESID | CHANGESID, } - }; +static struct testcase testcases[] = { { + DETACH, + }, + { + NEWSID, + }, + { + 0, + }, + { + DETACH | NEWSID, + }, + { + CHANGESID, + }, + { + DOUBLE_CHANGESID | CHANGESID, + } }; /* 2 2 session00 4 4 \_ session00 # {NEWSID, }, @@ -91,8 +101,8 @@ static int fork_child(int i) close(p[1]); wait(NULL); if (getsid(0) != sid) { - fail("The process %d (%x) has SID=%d (expected %d)", - pid, testcases[i].flags, sid, testcases[i].sid); + fail("The process %d (%x) has SID=%d (expected %d)", pid, testcases[i].flags, sid, + testcases[i].sid); exit(1); } exit(0); @@ -118,14 +128,14 @@ static int fork_child(int i) close(p[1]); wait(NULL); if (getsid(0) != sid) { - fail("The process %d (%x) has SID=%d (expected %d)", - pid, testcases[i].flags, sid, testcases[i].sid); + fail("The process %d (%x) has SID=%d (expected %d)", pid, testcases[i].flags, sid, + testcases[i].sid); exit(1); } exit(0); } -child: + child: pid = getpid(); write(p[1], &pid, sizeof(pid)); close(p[1]); @@ -171,7 +181,7 @@ child: return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int i, ret, err = 0, status; pid_t pid; @@ -198,8 +208,8 @@ int main(int argc, char ** argv) pid_t sid = getsid(pid); if (sid != testcases[i].sid) { - fail("The process %d (%x) has SID=%d (expected %d)", - pid, testcases[i].flags, sid, testcases[i].sid); + fail("The process %d (%x) has SID=%d (expected %d)", pid, testcases[i].flags, sid, + testcases[i].sid); err++; } diff --git a/test/zdtm/static/session01.c b/test/zdtm/static/session01.c index 48cfb26de..0f727a9a6 100644 --- a/test/zdtm/static/session01.c +++ b/test/zdtm/static/session01.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" #include "lock.h" -const char *test_doc = "Test that sid, pgid are restored"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Test that sid, pgid are restored"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; struct master { pid_t pid; @@ -40,27 +40,33 @@ enum { static struct testcase *testcases; static futex_t *fstate; static struct testcase __testcases[] = { - { 2, 1, 2, 1, 2, 1 }, /* session00 */ - { 4, 2, 4, 2, 4, 1 }, /* |\_session00 */ - {15, 4, 4, 4, 15, 1 }, /* | |\_session00 */ - {16, 4, 4, 4, 15, 1 }, /* | \_session00 */ - {17, 4, 4, 4, 17, 0 }, /* | |\_session00 */ - {18, 4, 4, 4, 17, 1 }, /* | \_session00 */ - { 5, 2, 2, 2, 2, 1 }, /* |\_session00 */ - { 8, 2, 8, 2, 8, 1 }, /* |\_session00 */ - { 9, 8, 2, 2, 2, 1 }, /* | \_session00 */ - {10, 2, 10, 2, 10, 1 }, /* |\_session00 */ - {11, 10, 11, 2, 11, 1 }, /* | \_session00 */ - {12, 11, 2, 2, 2, 1 }, /* | \_session00 */ - {13, 2, 2, 2, 2, 0 }, /* \_session00 */ - { 3, 13, 2, 2, 2, 1 }, /* session00 */ - { 6, 2, 6, 2, 6, 0 }, /* \_session00 */ - {14, 6, 6, 6, 6, 1 }, /* session00 */ + { 2, 1, 2, 1, 2, 1 }, /* session00 */ + { 4, 2, 4, 2, 4, 1 }, /* |\_session00 */ + { 15, 4, 4, 4, 15, 1 }, /* | |\_session00 */ + { 16, 4, 4, 4, 15, 1 }, /* | \_session00 */ + { 17, 4, 4, 4, 17, 0 }, /* | |\_session00 */ + { 18, 4, 4, 4, 17, 1 }, /* | \_session00 */ + { 5, 2, 2, 2, 2, 1 }, /* |\_session00 */ + { 8, 2, 8, 2, 8, 1 }, /* |\_session00 */ + { 9, 8, 2, 2, 2, 1 }, /* | \_session00 */ + { 10, 2, 10, 2, 10, 1 }, /* |\_session00 */ + { 11, 10, 11, 2, 11, 1 }, /* | \_session00 */ + { 12, 11, 2, 2, 2, 1 }, /* | \_session00 */ + { 13, 2, 2, 2, 2, 0 }, /* \_session00 */ + { 3, 13, 2, 2, 2, 1 }, /* session00 */ + { 6, 2, 6, 2, 6, 0 }, /* \_session00 */ + { 14, 6, 6, 6, 6, 1 }, /* session00 */ }; #define TESTS (sizeof(__testcases) / sizeof(struct testcase)) -#define check(n, a, b) do { if ((a) != (b)) { pr_perror("%s mismatch %d != %d", n, a, b); goto err; } } while (0) +#define check(n, a, b) \ + do { \ + if ((a) != (b)) { \ + pr_perror("%s mismatch %d != %d", n, a, b); \ + goto err; \ + } \ + } while (0) static int child(const int c); static int fork_children(struct testcase *t, int leader) @@ -73,7 +79,7 @@ static int fork_children(struct testcase *t, int leader) continue; if (leader ^ (t->pid == testcases[i].born_sid)) - continue; + continue; cid = test_fork_id(i); if (cid < 0) @@ -135,7 +141,7 @@ static int child(const int c) goto err; } - t->master.pgid = testcases[i].master.pid; + t->master.pgid = testcases[i].master.pid; break; } @@ -160,17 +166,17 @@ static int child(const int c) futex_wait_until(fstate, TEST_MASTER); /* Save the master copy */ - t->master.ppid = getppid(); - t->master.sid = getsid(0); + t->master.ppid = getppid(); + t->master.sid = getsid(0); futex_set_and_wake(&t->futex, c); futex_wait_until(fstate, TEST_CHECK); - check("pid", t->master.pid, getpid()); - check("ppid", t->master.ppid, getppid()); - check("sid", t->master.sid, getsid(0)); - check("pgid", t->master.pgid, getpgid(0)); + check("pid", t->master.pid, getpid()); + check("ppid", t->master.ppid, getppid()); + check("sid", t->master.sid, getsid(0)); + check("pgid", t->master.pgid, getpgid(0)); futex_set_and_wake(&t->futex, c); @@ -183,7 +189,7 @@ err: return 1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int i, err, ret; void *ptr; @@ -238,8 +244,7 @@ int main(int argc, char ** argv) continue; if (testcases[i].alive) continue; - test_msg("Wait porcess %d (pid %d)\n", - i, testcases[i].master.pid); + test_msg("Wait porcess %d (pid %d)\n", i, testcases[i].master.pid); waitpid(testcases[i].master.pid, NULL, 0); } @@ -272,28 +277,24 @@ int main(int argc, char ** argv) struct testcase *p = testcases + j; /* sanity check */ if (p->pid == t->sid && t->master.sid != p->master.pid) { - pr_perror("session mismatch (%d) %d != (%d) %d", - i, t->master.sid, j, p->master.pid); + pr_perror("session mismatch (%d) %d != (%d) %d", i, t->master.sid, j, p->master.pid); err++; } if (p->pid == t->pgid && t->master.pgid != p->master.pid) { - pr_perror("pgid mismatch (%d) %d != (%d) %d", - i, t->master.pgid, j, p->master.pid); + pr_perror("pgid mismatch (%d) %d != (%d) %d", i, t->master.pgid, j, p->master.pid); err++; } } sid = getsid(t->master.pid); if (t->master.sid != sid) { - pr_perror("%d: session mismatch %d (expected %d)", - i, sid, t->master.sid); + pr_perror("%d: session mismatch %d (expected %d)", i, sid, t->master.sid); err++; } pgid = getpgid(t->master.pid); if (t->master.pgid != pgid) { - pr_perror("%d: pgid mismatch %d (expected %d)", - i, t->master.pgid, pgid); + pr_perror("%d: pgid mismatch %d (expected %d)", i, t->master.pgid, pgid); err++; } } diff --git a/test/zdtm/static/session02.c b/test/zdtm/static/session02.c index f5c81df16..0967e04b2 100644 --- a/test/zdtm/static/session02.c +++ b/test/zdtm/static/session02.c @@ -10,11 +10,10 @@ #include "zdtmtst.h" -const char *test_doc = "Create a crazy process tree"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Create a crazy process tree"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; -struct process -{ +struct process { pid_t pid; pid_t sid; int sks[2]; @@ -39,20 +38,12 @@ static void cleanup(void) } } -enum commands -{ - TEST_FORK, - TEST_WAIT, - TEST_SUBREAPER, - TEST_SETSID, - TEST_DIE -}; +enum commands { TEST_FORK, TEST_WAIT, TEST_SUBREAPER, TEST_SETSID, TEST_DIE }; -struct command -{ - enum commands cmd; - int arg1; - int arg2; +struct command { + enum commands cmd; + int arg1; + int arg2; }; static void handle_command(void); @@ -63,7 +54,7 @@ static void mainloop(void) handle_command(); } -#define CLONE_STACK_SIZE 4096 +#define CLONE_STACK_SIZE 4096 /* All arguments should be above stack, because it grows down */ struct clone_args { char stack[CLONE_STACK_SIZE] __stack_aligned__; @@ -73,7 +64,7 @@ struct clone_args { static int clone_func(void *_arg) { - struct clone_args *args = (struct clone_args *) _arg; + struct clone_args *args = (struct clone_args *)_arg; current = args->id; @@ -89,8 +80,7 @@ static int make_child(int id, int flags) args.id = id; - cid = clone(clone_func, args.stack_ptr, - flags | SIGCHLD, &args); + cid = clone(clone_func, args.stack_ptr, flags | SIGCHLD, &args); if (cid < 0) pr_perror("clone(%d, %d)", id, flags); @@ -112,24 +102,20 @@ static void handle_command(void) } switch (cmd.cmd) { - case TEST_FORK: - { - pid_t pid; - - pid = make_child(cmd.arg1, cmd.arg2); - if (pid == -1) { - status = -1; - goto err; - } - - test_msg("%3d: fork(%d, %x) = %d\n", - current, cmd.arg1, cmd.arg2, pid); - processes[cmd.arg1].pid = pid; + case TEST_FORK: { + pid_t pid; + + pid = make_child(cmd.arg1, cmd.arg2); + if (pid == -1) { + status = -1; + goto err; } - break; + + test_msg("%3d: fork(%d, %x) = %d\n", current, cmd.arg1, cmd.arg2, pid); + processes[cmd.arg1].pid = pid; + } break; case TEST_WAIT: - test_msg("%3d: wait(%d) = %d\n", current, - cmd.arg1, processes[cmd.arg1].pid); + test_msg("%3d: wait(%d) = %d\n", current, cmd.arg1, processes[cmd.arg1].pid); if (waitpid(processes[cmd.arg1].pid, NULL, 0) == -1) { pr_perror("waitpid(%d)", processes[cmd.arg1].pid); @@ -145,7 +131,7 @@ static void handle_command(void) break; case TEST_SETSID: test_msg("%3d: setsid()\n", current); - if(setsid() == -1) { + if (setsid() == -1) { pr_perror("setsid"); status = -1; } @@ -175,7 +161,7 @@ err: static int send_command(int id, enum commands op, int arg1, int arg2) { int sk = processes[id].sks[1], ret, status; - struct command cmd = {op, arg1, arg2}; + struct command cmd = { op, arg1, arg2 }; if (op == TEST_FORK) { if (processes[arg1].pid) { @@ -208,15 +194,14 @@ err: exit(1); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pid, i; int fail_cnt = 0; test_init(argc, argv); - processes = mmap(NULL, PAGE_SIZE, PROT_WRITE | PROT_READ, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + processes = mmap(NULL, PAGE_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (processes == NULL) { pr_perror("Unable to map share memory"); return 1; @@ -243,39 +228,39 @@ int main(int argc, char ** argv) * 13 12 \_ session02 ( 8) */ - send_command(0, TEST_SUBREAPER, 1, 0); - send_command(0, TEST_SETSID, 0, 0); + send_command(0, TEST_SUBREAPER, 1, 0); + send_command(0, TEST_SETSID, 0, 0); - send_command(0, TEST_FORK, 1, 0); - send_command(1, TEST_FORK, 2, 0); + send_command(0, TEST_FORK, 1, 0); + send_command(1, TEST_FORK, 2, 0); - send_command(2, TEST_SETSID, 0, 0); - send_command(2, TEST_FORK, 3, CLONE_PARENT); - send_command(2, TEST_DIE, 0, 0); - send_command(1, TEST_WAIT, 2, 0); + send_command(2, TEST_SETSID, 0, 0); + send_command(2, TEST_FORK, 3, CLONE_PARENT); + send_command(2, TEST_DIE, 0, 0); + send_command(1, TEST_WAIT, 2, 0); - send_command(3, TEST_FORK, 4, 0); - send_command(4, TEST_FORK, 5, 0); - send_command(5, TEST_FORK, 6, 0); + send_command(3, TEST_FORK, 4, 0); + send_command(4, TEST_FORK, 5, 0); + send_command(5, TEST_FORK, 6, 0); - send_command(5, TEST_FORK, 7, 0); - send_command(7, TEST_SETSID, 0, 0); - send_command(7, TEST_FORK, 8, CLONE_PARENT); - send_command(7, TEST_FORK, 9, CLONE_PARENT); - send_command(7, TEST_DIE, 0, 0); - send_command(5, TEST_WAIT, 7, 0); + send_command(5, TEST_FORK, 7, 0); + send_command(7, TEST_SETSID, 0, 0); + send_command(7, TEST_FORK, 8, CLONE_PARENT); + send_command(7, TEST_FORK, 9, CLONE_PARENT); + send_command(7, TEST_DIE, 0, 0); + send_command(5, TEST_WAIT, 7, 0); - send_command(9, TEST_FORK, 10, 0); - send_command(1, TEST_SUBREAPER, 1, 0); - send_command(9, TEST_DIE, 0, 0); - send_command(5, TEST_WAIT, 9, 0); - send_command(1, TEST_SUBREAPER, 0, 0); + send_command(9, TEST_FORK, 10, 0); + send_command(1, TEST_SUBREAPER, 1, 0); + send_command(9, TEST_DIE, 0, 0); + send_command(5, TEST_WAIT, 9, 0); + send_command(1, TEST_SUBREAPER, 0, 0); - send_command(4, TEST_DIE, 0, 0); - send_command(3, TEST_WAIT, 4, 0); + send_command(4, TEST_DIE, 0, 0); + send_command(3, TEST_WAIT, 4, 0); - send_command(1, TEST_SETSID, 0, 0); - send_command(5, TEST_SETSID, 0, 0); + send_command(1, TEST_SETSID, 0, 0); + send_command(5, TEST_SETSID, 0, 0); for (i = 0; i < nr_processes; i++) { if (processes[i].dead) @@ -309,8 +294,7 @@ int main(int argc, char ** argv) } if (sid != processes[i].sid) { - fail("%d, %d: wrong sid %d (expected %d)", - i, processes[i].pid, sid, processes[i].sid); + fail("%d, %d: wrong sid %d (expected %d)", i, processes[i].pid, sid, processes[i].sid); fail_cnt++; } } diff --git a/test/zdtm/static/session03.c b/test/zdtm/static/session03.c index 8ca16e410..6e6f948ab 100644 --- a/test/zdtm/static/session03.c +++ b/test/zdtm/static/session03.c @@ -10,11 +10,10 @@ #include "zdtmtst.h" -const char *test_doc = "Create a crazy process tree"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Create a crazy process tree"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; -struct process -{ +struct process { pid_t pid; pid_t sid; int sks[2]; @@ -23,7 +22,7 @@ struct process }; #define MEM_SIZE (2 * PAGE_SIZE) -#define PR_MAX (MEM_SIZE / sizeof(struct process)) +#define PR_MAX (MEM_SIZE / sizeof(struct process)) struct process *processes; int nr_processes = 0; @@ -60,17 +59,9 @@ static void cleanup(void) } } -enum commands -{ - TEST_FORK, - TEST_DIE_WAIT, - TEST_DIE, - TEST_SUBREAPER, - TEST_SETSID, - TEST_MAX -}; +enum commands { TEST_FORK, TEST_DIE_WAIT, TEST_DIE, TEST_SUBREAPER, TEST_SETSID, TEST_MAX }; -int cmd_weght[TEST_MAX] = {10, 3, 1, 10, 7}; +int cmd_weght[TEST_MAX] = { 10, 3, 1, 10, 7 }; int sum_weight = 0; static int get_rnd_op(void) { @@ -90,11 +81,10 @@ static int get_rnd_op(void) return -1; } -struct command -{ - enum commands cmd; - int arg1; - int arg2; +struct command { + enum commands cmd; + int arg1; + int arg2; }; static void handle_command(void); @@ -105,7 +95,7 @@ static void mainloop(void) handle_command(); } -#define CLONE_STACK_SIZE 4096 +#define CLONE_STACK_SIZE 4096 /* All arguments should be above stack, because it grows down */ struct clone_args { char stack[CLONE_STACK_SIZE] __stack_aligned__; @@ -115,7 +105,7 @@ struct clone_args { static int clone_func(void *_arg) { - struct clone_args *args = (struct clone_args *) _arg; + struct clone_args *args = (struct clone_args *)_arg; current = args->id; @@ -131,8 +121,7 @@ static int make_child(int id, int flags) args.id = id; - cid = clone(clone_func, args.stack_ptr, - flags | SIGCHLD, &args); + cid = clone(clone_func, args.stack_ptr, flags | SIGCHLD, &args); if (cid < 0) pr_perror("clone(%d, %d)", id, flags); @@ -154,21 +143,18 @@ static void handle_command(void) } switch (cmd.cmd) { - case TEST_FORK: - { - pid_t pid; - - pid = make_child(cmd.arg1, cmd.arg2 ? CLONE_PARENT : 0); - if (pid < 0) { - status = -1; - goto err; - } - - test_msg("%3d: fork(%d, %x) = %d\n", - current, cmd.arg1, cmd.arg2, pid); - processes[cmd.arg1].pid = pid; + case TEST_FORK: { + pid_t pid; + + pid = make_child(cmd.arg1, cmd.arg2 ? CLONE_PARENT : 0); + if (pid < 0) { + status = -1; + goto err; } - break; + + test_msg("%3d: fork(%d, %x) = %d\n", current, cmd.arg1, cmd.arg2, pid); + processes[cmd.arg1].pid = pid; + } break; case TEST_SUBREAPER: test_msg("%3d: subreaper(%d)\n", current, cmd.arg1); if (prctl(PR_SET_CHILD_SUBREAPER, cmd.arg1, 0, 0, 0) == -1) { @@ -180,7 +166,7 @@ static void handle_command(void) if (getsid(0) == getpid()) break; test_msg("%3d: setsid()\n", current); - if(setsid() == -1) { + if (setsid() == -1) { pr_perror("setsid"); status = -1; } @@ -218,7 +204,7 @@ err: static int send_command(int id, enum commands op, int arg) { int sk = processes[id].sks[1], ret, status; - struct command cmd = {op, arg}; + struct command cmd = { op, arg }; if (op == TEST_FORK) { cmd.arg1 = nr_processes; @@ -236,8 +222,7 @@ static int send_command(int id, enum commands op, int arg) status = 0; ret = read(sk, &status, sizeof(status)); - if (ret != sizeof(status) && - !(status == 0 && (op == TEST_DIE || op == TEST_DIE_WAIT))) { + if (ret != sizeof(status) && !(status == 0 && (op == TEST_DIE || op == TEST_DIE_WAIT))) { pr_perror("Unable to get answer"); goto err; } @@ -253,7 +238,7 @@ err: exit(1); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { struct sigaction act; int pid, i, ret; @@ -283,8 +268,7 @@ int main(int argc, char ** argv) return -1; } - processes = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + processes = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (processes == NULL) { pr_perror("Unable to map share memory"); return 1; @@ -302,7 +286,7 @@ int main(int argc, char ** argv) if (pid < 0) return -1; - while(nr_processes < PR_MAX) { + while (nr_processes < PR_MAX) { int op, id; int flags = lrand48() % 2; @@ -357,8 +341,7 @@ int main(int argc, char ** argv) } if (sid != processes[i].sid) { - fail("%d, %d: wrong sid %d (expected %d)", - i, processes[i].pid, sid, processes[i].sid); + fail("%d, %d: wrong sid %d (expected %d)", i, processes[i].pid, sid, processes[i].sid); fail_cnt++; } } diff --git a/test/zdtm/static/shared_mount_propagation.c b/test/zdtm/static/shared_mount_propagation.c index 4e81b9ec6..47ffa8263 100644 --- a/test/zdtm/static/shared_mount_propagation.c +++ b/test/zdtm/static/shared_mount_propagation.c @@ -5,8 +5,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check mounts are propagated to shared mounts"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check mounts are propagated to shared mounts"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/shared_slave_mount_children.c b/test/zdtm/static/shared_slave_mount_children.c index 75c2513c6..172a61a60 100644 --- a/test/zdtm/static/shared_slave_mount_children.c +++ b/test/zdtm/static/shared_slave_mount_children.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check non-uniform shares restore fine"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check non-uniform shares restore fine"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/shm-mp.c b/test/zdtm/static/shm-mp.c index a7c87962d..1929dac19 100644 --- a/test/zdtm/static/shm-mp.c +++ b/test/zdtm/static/shm-mp.c @@ -8,10 +8,10 @@ #include "zdtmtst.h" -const char *test_doc="Tests mprotected SYSVIPC shmems"; -const char *test_author="Pavel Emelyanov <xemul@openvz.org>"; +const char *test_doc = "Tests mprotected SYSVIPC shmems"; +const char *test_author = "Pavel Emelyanov <xemul@openvz.org>"; -static sigjmp_buf segv_ret; /* we need sig*jmp stuff, otherwise SIGSEGV will reset our handler */ +static sigjmp_buf segv_ret; /* we need sig*jmp stuff, otherwise SIGSEGV will reset our handler */ static void segfault(int signo) { siglongjmp(segv_ret, 1); @@ -33,11 +33,11 @@ static int check_prot(char *ptr, char val, int prot) fail("PROT_READ bypassed"); return -1; } - } else /* we come here on return from SIGSEGV handler */ + } else /* we come here on return from SIGSEGV handler */ if (prot & PROT_READ) { - fail("PROT_READ rejected"); - return -1; - } + fail("PROT_READ rejected"); + return -1; + } if (!sigsetjmp(segv_ret, 1)) { *ptr = val; @@ -45,11 +45,11 @@ static int check_prot(char *ptr, char val, int prot) fail("PROT_WRITE bypassed"); return -1; } - } else /* we come here on return from SIGSEGV handler */ + } else /* we come here on return from SIGSEGV handler */ if (prot & PROT_WRITE) { - fail("PROT_WRITE rejected"); - return -1; - } + fail("PROT_WRITE rejected"); + return -1; + } if (signal(SIGSEGV, SIG_DFL) == SIG_ERR) { fail("restoring SIGSEGV handler failed"); @@ -100,7 +100,6 @@ int main(int argc, char **argv) if (check_prot(mem + PAGE_SIZE, 'W', PROT_READ | PROT_WRITE)) f++; - if (!f) pass(); else diff --git a/test/zdtm/static/shm.c b/test/zdtm/static/shm.c index 320211bfc..3da29daeb 100644 --- a/test/zdtm/static/shm.c +++ b/test/zdtm/static/shm.c @@ -13,14 +13,14 @@ #include "zdtmtst.h" -const char *test_doc="Tests detached shmems migrate fine"; -const char *test_author="Stanislav Kinsbursky <skinsbursky@parallels.com>"; +const char *test_doc = "Tests detached shmems migrate fine"; +const char *test_author = "Stanislav Kinsbursky <skinsbursky@parallels.com>"; -#define DEF_MEM_SIZE (40960) +#define DEF_MEM_SIZE (40960) unsigned int shmem_size = DEF_MEM_SIZE; TEST_OPTION(shmem_size, uint, "Size of shared memory segment", 0); -#define INIT_CRC (~0) +#define INIT_CRC (~0) static int fill_shm_seg(int id, size_t size) { diff --git a/test/zdtm/static/shmemfd-priv.c b/test/zdtm/static/shmemfd-priv.c index bbdb46905..0f6e817cc 100644 --- a/test/zdtm/static/shmemfd-priv.c +++ b/test/zdtm/static/shmemfd-priv.c @@ -9,10 +9,14 @@ #include "zdtmtst.h" -const char *test_doc = "Test C/R of shared memory file descriptors"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Test C/R of shared memory file descriptors"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) int main(int argc, char *argv[]) { @@ -28,12 +32,11 @@ int main(int argc, char *argv[]) return 1; } - *(int *) addr = 1; - *(int *) (addr + PAGE_SIZE) = 11; - *(int *) (addr + 2 * PAGE_SIZE) = 111; + *(int *)addr = 1; + *(int *)(addr + PAGE_SIZE) = 11; + *(int *)(addr + 2 * PAGE_SIZE) = 111; - snprintf(path, sizeof(path), "/proc/self/map_files/%lx-%lx", - (long)addr, (long)addr + 5 * PAGE_SIZE); + snprintf(path, sizeof(path), "/proc/self/map_files/%lx-%lx", (long)addr, (long)addr + 5 * PAGE_SIZE); fd = open(path, O_RDWR | O_LARGEFILE); if (fd < 0) err(1, "Can't open %s", path); @@ -50,30 +53,30 @@ int main(int argc, char *argv[]) return 1; } - *(int *) (priv_addr + PAGE_SIZE) = 22; + *(int *)(priv_addr + PAGE_SIZE) = 22; test_daemon(); test_waitsig(); - if (*(int *) (priv_addr + PAGE_SIZE) != 22) { + if (*(int *)(priv_addr + PAGE_SIZE) != 22) { fail("the second page of the private mapping is corrupted"); return 1; } - if (*(int *) (priv_addr) != 11) { + if (*(int *)(priv_addr) != 11) { fail("the first page of the private mapping is corrupted"); return 1; } - if (*(int *) (addr2) != 111) { + if (*(int *)(addr2) != 111) { fail("the first page of the second shared mapping is corrupted"); return 1; } - *(int *) (addr2) = 333; - if (*(int *) (addr + 2 * PAGE_SIZE) != 333) { + *(int *)(addr2) = 333; + if (*(int *)(addr + 2 * PAGE_SIZE) != 333) { fail("the first page of the second shared mapping isn't shared"); return 1; } - *(int *) (addr + 3 * PAGE_SIZE) = 444; - if (*(int *) (priv_addr + 2 * PAGE_SIZE) != 444) { + *(int *)(addr + 3 * PAGE_SIZE) = 444; + if (*(int *)(priv_addr + 2 * PAGE_SIZE) != 444) { fail("the third page of the private mapping is corrupted"); return 1; } diff --git a/test/zdtm/static/shmemfd.c b/test/zdtm/static/shmemfd.c index b65faa2e1..8a5232bbd 100644 --- a/test/zdtm/static/shmemfd.c +++ b/test/zdtm/static/shmemfd.c @@ -9,10 +9,14 @@ #include "zdtmtst.h" -const char *test_doc = "Test C/R of shared memory file descriptors"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Test C/R of shared memory file descriptors"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; -#define err(exitcode, msg, ...) ({ pr_perror(msg, ##__VA_ARGS__); exit(exitcode); }) +#define err(exitcode, msg, ...) \ + ({ \ + pr_perror(msg, ##__VA_ARGS__); \ + exit(exitcode); \ + }) int main(int argc, char *argv[]) { @@ -31,8 +35,7 @@ int main(int argc, char *argv[]) return 1; } - snprintf(path, sizeof(path), "/proc/self/map_files/%lx-%lx", - (long)addr, (long)addr + PAGE_SIZE); + snprintf(path, sizeof(path), "/proc/self/map_files/%lx-%lx", (long)addr, (long)addr + PAGE_SIZE); fd = open(path, O_RDWR | O_LARGEFILE); if (fd < 0) err(1, "Can't open %s", path); diff --git a/test/zdtm/static/sigaltstack.c b/test/zdtm/static/sigaltstack.c index 13602d3a1..dd7c82d39 100644 --- a/test/zdtm/static/sigaltstack.c +++ b/test/zdtm/static/sigaltstack.c @@ -11,8 +11,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check for alternate signal stack"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check for alternate signal stack"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; #define TESTSIGSTKSZ 16384 @@ -31,20 +31,17 @@ static stack_t sas_state[SAS_MAX]; static task_waiter_t t; -#define exit_group(code) syscall(__NR_exit_group, code) -#define gettid() syscall(__NR_gettid) +#define exit_group(code) syscall(__NR_exit_group, code) +#define gettid() syscall(__NR_gettid) static int sascmp(stack_t *old, stack_t *new) { - return old->ss_size != new->ss_size || - old->ss_sp != new->ss_sp || - old->ss_flags != new->ss_flags; + return old->ss_size != new->ss_size || old->ss_sp != new->ss_sp || old->ss_flags != new->ss_flags; } static void show_ss(char *prefix, stack_t *s) { - test_msg("%20s: at %p (size %8zu flags %#2x)\n", - prefix, s->ss_sp, s->ss_size, s->ss_flags); + test_msg("%20s: at %p (size %8zu flags %#2x)\n", prefix, s->ss_sp, s->ss_size, s->ss_flags); } void thread_sigaction(int signo, siginfo_t *info, void *context) @@ -64,14 +61,14 @@ void thread_sigaction(int signo, siginfo_t *info, void *context) static void *thread_func(void *arg) { struct sigaction sa = { - .sa_sigaction = thread_sigaction, - .sa_flags = SA_RESTART | SA_ONSTACK, + .sa_sigaction = thread_sigaction, + .sa_flags = SA_RESTART | SA_ONSTACK, }; - sas_state[SAS_THRD_OLD] = (stack_t) { - .ss_size = sizeof(stack_thread) - 8, - .ss_sp = stack_thread, - .ss_flags = 0, + sas_state[SAS_THRD_OLD] = (stack_t){ + .ss_size = sizeof(stack_thread) - 8, + .ss_sp = stack_thread, + .ss_flags = 0, }; sigemptyset(&sa.sa_mask); @@ -106,14 +103,14 @@ int main(int argc, char *argv[]) pthread_t thread; struct sigaction sa = { - .sa_sigaction = leader_sigaction, - .sa_flags = SA_RESTART | SA_ONSTACK, + .sa_sigaction = leader_sigaction, + .sa_flags = SA_RESTART | SA_ONSTACK, }; - sas_state[SAS_MAIN_OLD] = (stack_t) { - .ss_size = sizeof(stack_main) - 8, - .ss_sp = stack_main, - .ss_flags = 0, + sas_state[SAS_MAIN_OLD] = (stack_t){ + .ss_size = sizeof(stack_main) - 8, + .ss_sp = stack_main, + .ss_flags = 0, }; sigemptyset(&sa.sa_mask); diff --git a/test/zdtm/static/signalfd00.c b/test/zdtm/static/signalfd00.c index 61b1f0398..b98372885 100644 --- a/test/zdtm/static/signalfd00.c +++ b/test/zdtm/static/signalfd00.c @@ -18,8 +18,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check for signalfd without signals"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check for signalfd without signals"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/sigpending.c b/test/zdtm/static/sigpending.c index 4d174588c..1641fdd86 100644 --- a/test/zdtm/static/sigpending.c +++ b/test/zdtm/static/sigpending.c @@ -9,13 +9,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check pending signals"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check pending signals"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; static pid_t child; static int numsig; -#define TESTSIG (SIGRTMAX) +#define TESTSIG (SIGRTMAX) #define THREADSIG (SIGRTMIN) static siginfo_t share_infos[2]; static siginfo_t self_infos[64]; /* self */ @@ -25,7 +25,7 @@ static int self_nr; static int thread_nr; #ifndef offsetof -# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER) #endif /* cr_siginfo is declared to get an offset of _sifields */ @@ -59,7 +59,7 @@ typedef union cr_siginfo cr_siginfo_t; * } _rt; * Look at __copy_siginfo_to_user32() for more information. */ -# define _si_fields_sz 12 +#define _si_fields_sz 12 #define siginfo_filled (offsetof(cr_siginfo_t, _info._sifields) + _si_fields_sz) static pthread_mutex_t exit_lock; @@ -78,9 +78,7 @@ static void sig_handler(int signal, siginfo_t *info, void *data) switch (signal) { case SIGCHLD: - if ((info->si_code & CLD_EXITED) && - (info->si_pid == child) && - (info->si_status == 5)) + if ((info->si_code & CLD_EXITED) && (info->si_pid == child) && (info->si_status == 5)) numsig++; else { fail("Wrong siginfo"); @@ -104,12 +102,12 @@ static void sig_handler(int signal, siginfo_t *info, void *data) } crc = ~0; - if (datachk((uint8_t *) siginf_body(info), _si_fields_sz, &crc)) { + if (datachk((uint8_t *)siginf_body(info), _si_fields_sz, &crc)) { fail("CRC mismatch"); return; } - if (memcmp(info, src, siginfo_filled)) { + if (memcmp(info, src, siginfo_filled)) { fail("Source and received info are differ"); return; } @@ -186,7 +184,7 @@ int send_siginfo(int signo, pid_t pid, pid_t tid, int group, siginfo_t *info) info->si_code = si_code; si_code--; info->si_signo = signo; - datagen((uint8_t *) siginf_body(info), _si_fields_sz, &crc); + datagen((uint8_t *)siginf_body(info), _si_fields_sz, &crc); sent_sigs++; @@ -196,7 +194,7 @@ int send_siginfo(int signo, pid_t pid, pid_t tid, int group, siginfo_t *info) return syscall(SYS_rt_tgsigqueueinfo, pid, tid, signo, info); } -int main(int argc, char ** argv) +int main(int argc, char **argv) { sigset_t blockmask, oldset, newset; struct sigaction act; @@ -239,7 +237,7 @@ int main(int argc, char ** argv) return -1; } - if(child == 0) + if (child == 0) return 5; /* SIGCHLD */ if (waitid(P_PID, child, &infop, WNOWAIT | WEXITED)) { pr_perror("waitid"); diff --git a/test/zdtm/static/sigtrap.c b/test/zdtm/static/sigtrap.c index 659213cf5..6bd30aad4 100644 --- a/test/zdtm/static/sigtrap.c +++ b/test/zdtm/static/sigtrap.c @@ -18,10 +18,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check that a pending SIGTRAP handled correctly"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Check that a pending SIGTRAP handled correctly"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; -static void sigh(int signo) {} +static void sigh(int signo) +{ +} int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/sigtrap01.c b/test/zdtm/static/sigtrap01.c index a63e55d6a..a61f4368e 100644 --- a/test/zdtm/static/sigtrap01.c +++ b/test/zdtm/static/sigtrap01.c @@ -5,15 +5,15 @@ #include "zdtmtst.h" -const char *test_doc = "Check that a signal handler for SIGTRAP is restored"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Check that a signal handler for SIGTRAP is restored"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; static int sigtrap = 0; -static void sigh(int signo) { +static void sigh(int signo) +{ sigtrap = 1; } - int main(int argc, char **argv) { test_init(argc, argv); diff --git a/test/zdtm/static/sit.c b/test/zdtm/static/sit.c index 07c36ab5d..8deb2901d 100644 --- a/test/zdtm/static/sit.c +++ b/test/zdtm/static/sit.c @@ -13,12 +13,12 @@ #include <net/if.h> #include "zdtmtst.h" -const char *test_doc = "check sit devices"; -const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; +const char *test_doc = "check sit devices"; +const char *test_author = "Pavel Emelyanov <xemul@virtuozzo.com>"; -#define IF_NAME "zdtmsit0" -#define LOCAL_ADDR "1.1.1.2" -#define REMOT_ADDR "2.2.2.1" +#define IF_NAME "zdtmsit0" +#define LOCAL_ADDR "1.1.1.2" +#define REMOT_ADDR "2.2.2.1" int main(int argc, char **argv) { @@ -55,4 +55,3 @@ int main(int argc, char **argv) out: return ret; } - diff --git a/test/zdtm/static/sk-freebind.c b/test/zdtm/static/sk-freebind.c index de30329c9..0fc719f6c 100644 --- a/test/zdtm/static/sk-freebind.c +++ b/test/zdtm/static/sk-freebind.c @@ -2,12 +2,12 @@ #include <stdlib.h> #include <string.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include "zdtmtst.h" -const char *test_doc = "Check that IP_FREEBIND is restored"; -const char *test_author = "Andrew Vagin <avagin@virtuozzo.com>"; +const char *test_doc = "Check that IP_FREEBIND is restored"; +const char *test_author = "Andrew Vagin <avagin@virtuozzo.com>"; union sockaddr_inet { struct sockaddr_in v4; @@ -40,18 +40,18 @@ int main(int argc, char **argv) return -1; } val = 1; - if (setsockopt(sock, SOL_IP, IP_FREEBIND, &val, sizeof(int)) == -1 ) { + if (setsockopt(sock, SOL_IP, IP_FREEBIND, &val, sizeof(int)) == -1) { pr_perror("setsockopt() error"); return -1; } - if (bind(sock, (struct sockaddr *) &addr, sizeof(addr))) { + if (bind(sock, (struct sockaddr *)&addr, sizeof(addr))) { pr_perror("bind()"); return -1; } if (!fb_keep) { val = 0; - if (setsockopt(sock, SOL_IP, IP_FREEBIND, &val, sizeof(int)) == -1 ) { + if (setsockopt(sock, SOL_IP, IP_FREEBIND, &val, sizeof(int)) == -1) { pr_perror("setsockopt() error"); return -1; } @@ -61,7 +61,7 @@ int main(int argc, char **argv) test_waitsig(); len = sizeof(int); - if (getsockopt(sock, SOL_IP, IP_FREEBIND, &val, &len) == -1 ) { + if (getsockopt(sock, SOL_IP, IP_FREEBIND, &val, &len) == -1) { pr_perror("setsockopt() error"); return -1; } diff --git a/test/zdtm/static/sk-netlink.c b/test/zdtm/static/sk-netlink.c index 7f06f0259..b79ac0cf7 100644 --- a/test/zdtm/static/sk-netlink.c +++ b/test/zdtm/static/sk-netlink.c @@ -7,15 +7,15 @@ #include "zdtmtst.h" #ifndef SOL_NETLINK -#define SOL_NETLINK 270 +#define SOL_NETLINK 270 #endif -#define UDEV_MONITOR_TEST 32 +#define UDEV_MONITOR_TEST 32 -const char *test_doc = "Support of netlink sockets"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Support of netlink sockets"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int ssk, bsk, csk, dsk; struct sockaddr_nl addr; @@ -64,21 +64,21 @@ int main(int argc, char ** argv) addr.nl_family = AF_NETLINK; addr.nl_groups = 0; addr.nl_pid = getpid(); - if (bind(ssk, (struct sockaddr *) &addr, sizeof(struct sockaddr_nl))) { + if (bind(ssk, (struct sockaddr *)&addr, sizeof(struct sockaddr_nl))) { pr_perror("bind"); return 1; } addr.nl_groups = 1 << (UDEV_MONITOR_TEST - 1); addr.nl_pid = 0; - if (bind(bsk, (struct sockaddr *) &addr, sizeof(struct sockaddr_nl))) { + if (bind(bsk, (struct sockaddr *)&addr, sizeof(struct sockaddr_nl))) { pr_perror("bind"); return 1; } addr.nl_pid = getpid(); addr.nl_groups = 1 << (UDEV_MONITOR_TEST - 1); - if (connect(csk, (struct sockaddr *) &addr, sizeof(struct sockaddr_nl))) { + if (connect(csk, (struct sockaddr *)&addr, sizeof(struct sockaddr_nl))) { pr_perror("connect"); return 1; } @@ -87,18 +87,18 @@ int main(int argc, char ** argv) test_waitsig(); - req.hdr.nlmsg_len = sizeof(req); - req.hdr.nlmsg_type = 0x1234; - req.hdr.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; - req.hdr.nlmsg_seq = 0xabcd; + req.hdr.nlmsg_len = sizeof(req); + req.hdr.nlmsg_type = 0x1234; + req.hdr.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; + req.hdr.nlmsg_seq = 0xabcd; memset(&msg, 0, sizeof(msg)); msg.msg_namelen = 0; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; - iov.iov_base = (void *) &req; - iov.iov_len = sizeof(req); + iov.iov_base = (void *)&req; + iov.iov_len = sizeof(req); if (sendmsg(csk, &msg, 0) < 0) { pr_perror("Can't send request message"); @@ -107,11 +107,11 @@ int main(int argc, char ** argv) memset(&msg, 0, sizeof(msg)); msg.msg_namelen = 0; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; - iov.iov_base = buf; - iov.iov_len = sizeof(buf); + iov.iov_base = buf; + iov.iov_len = sizeof(buf); if (recvmsg(ssk, &msg, 0) < 0) { pr_perror("Can't recv request message"); @@ -129,12 +129,12 @@ int main(int argc, char ** argv) memset(&msg, 0, sizeof(msg)); msg.msg_namelen = sizeof(addr); - msg.msg_name = &addr; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + msg.msg_name = &addr; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; - iov.iov_base = (void *) &req; - iov.iov_len = sizeof(req); + iov.iov_base = (void *)&req; + iov.iov_len = sizeof(req); if (sendmsg(dsk, &msg, 0) < 0) { pr_perror("Can't send request message"); @@ -143,11 +143,11 @@ int main(int argc, char ** argv) memset(&msg, 0, sizeof(msg)); msg.msg_namelen = 0; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; - iov.iov_base = buf; - iov.iov_len = sizeof(buf); + iov.iov_base = buf; + iov.iov_len = sizeof(buf); if (recvmsg(ssk, &msg, 0) < 0) { pr_perror("Can't recv request message"); diff --git a/test/zdtm/static/sk-unix-dgram-ghost.c b/test/zdtm/static/sk-unix-dgram-ghost.c index a726d6a64..fdf8fb18b 100644 --- a/test/zdtm/static/sk-unix-dgram-ghost.c +++ b/test/zdtm/static/sk-unix-dgram-ghost.c @@ -1,5 +1,5 @@ #ifndef _GNU_SOURCE -# define _GNU_SOURCE +#define _GNU_SOURCE #endif #include <stdlib.h> @@ -18,8 +18,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check data of bound ghost DGRAM unix socket and possibility to connect"; -const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; +const char *test_doc = "Check data of bound ghost DGRAM unix socket and possibility to connect"; +const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>"; /* * PROCESS_NUM | FREEZE_FREQ @@ -41,8 +41,7 @@ static int fill_sock_name(struct sockaddr_un *name, const char *filename) cwd = get_current_dir_name(); if (strlen(filename) + strlen(cwd) + 1 >= sizeof(name->sun_path)) { - pr_err("Name %s/%s is too long for socket\n", - cwd, filename); + pr_err("Name %s/%s is too long for socket\n", cwd, filename); return -1; } @@ -67,7 +66,7 @@ static int client(int i, task_waiter_t t) return 1; } - if (connect(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) < 0) { + if (connect(sk, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) { pr_perror("connect failed %d", i); return 1; } @@ -163,7 +162,7 @@ int main(int argc, char **argv) goto clean; } - if (bind(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_un))) { + if (bind(srv, (struct sockaddr *)&addr, sizeof(struct sockaddr_un))) { pr_perror("bind srv"); ret = 1; goto clean; diff --git a/test/zdtm/static/sk-unix-mntns.c b/test/zdtm/static/sk-unix-mntns.c index 46376ff50..cd37b8d02 100644 --- a/test/zdtm/static/sk-unix-mntns.c +++ b/test/zdtm/static/sk-unix-mntns.c @@ -15,8 +15,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test that unix sockets are restored in proper mount namespaces\n"; -const char *test_author = "Andrei Vagin <avagin@openvz.org>"; +const char *test_doc = "Test that unix sockets are restored in proper mount namespaces\n"; +const char *test_author = "Andrei Vagin <avagin@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "socket file name", 1); @@ -87,13 +87,13 @@ int main(int argc, char *argv[]) exit(1); } - ret = bind(sk, (struct sockaddr *) &addr, addrlen); + ret = bind(sk, (struct sockaddr *)&addr, addrlen); if (ret) { fail("bind"); exit(1); } - if (connect(csk, (struct sockaddr *) &addr, addrlen)) { + if (connect(csk, (struct sockaddr *)&addr, addrlen)) { fail("connect"); exit(1); } @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) pr_perror("socket"); exit(1); } - if (connect(csk, (struct sockaddr *) &addr, addrlen)) { + if (connect(csk, (struct sockaddr *)&addr, addrlen)) { pr_perror("connect"); exit(1); } diff --git a/test/zdtm/static/sk-unix-rel.c b/test/zdtm/static/sk-unix-rel.c index a62a5c92d..10c19080a 100644 --- a/test/zdtm/static/sk-unix-rel.c +++ b/test/zdtm/static/sk-unix-rel.c @@ -15,8 +15,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test unix stream sockets with relative name\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Test unix stream sockets with relative name\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; #define SK_DATA "packet" @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = bind(sock[0], (struct sockaddr *) &addr, addrlen); + ret = bind(sock[0], (struct sockaddr *)&addr, addrlen); if (ret) { fail("bind"); exit(1); @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) test_daemon(); test_waitsig(); - if (connect(sock[1], (struct sockaddr *) &addr, addrlen)) { + if (connect(sock[1], (struct sockaddr *)&addr, addrlen)) { fail("connect"); exit(1); } diff --git a/test/zdtm/static/sk-unix-unconn.c b/test/zdtm/static/sk-unix-unconn.c index 91e3d433b..caad3d315 100644 --- a/test/zdtm/static/sk-unix-unconn.c +++ b/test/zdtm/static/sk-unix-unconn.c @@ -6,10 +6,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check unconnected unix sockets"; -const char *test_author = "Vagin Andrew <avagin@parallels.com>"; +const char *test_doc = "Check unconnected unix sockets"; +const char *test_author = "Vagin Andrew <avagin@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int sk, skc; int ret, len; @@ -43,7 +43,7 @@ int main(int argc, char ** argv) addr.sun_path[0] = 0; addr.sun_path[len - 1] = 0; - ret = bind(sk, (struct sockaddr *) &addr, addrlen); + ret = bind(sk, (struct sockaddr *)&addr, addrlen); if (ret) { fail("bind"); return 1; @@ -58,7 +58,7 @@ int main(int argc, char ** argv) return 1; } - if (connect(skc, (struct sockaddr *) &addr, addrlen) == -1) { + if (connect(skc, (struct sockaddr *)&addr, addrlen) == -1) { fail("Unable to connect"); return 1; } diff --git a/test/zdtm/static/sk-unix01.c b/test/zdtm/static/sk-unix01.c index 0e9006a15..c2bb8b9ed 100644 --- a/test/zdtm/static/sk-unix01.c +++ b/test/zdtm/static/sk-unix01.c @@ -1,5 +1,5 @@ #ifndef _GNU_SOURCE -# define _GNU_SOURCE +#define _GNU_SOURCE #endif #include <stdlib.h> @@ -18,8 +18,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that deleted unix sockets with dirs are restored correctly"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Check that deleted unix sockets with dirs are restored correctly"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -62,16 +62,16 @@ static int sk_alloc_connect(int type, struct sockaddr_un *addr) return sk; } -#define write_int(__f, __p) \ - ({ \ - ssize_t __r = write(__f, __p, sizeof(*(__p))); \ - (__r == sizeof(*(__p))) ? 0 : -1; \ +#define write_int(__f, __p) \ + ({ \ + ssize_t __r = write(__f, __p, sizeof(*(__p))); \ + (__r == sizeof(*(__p))) ? 0 : -1; \ }) -#define read_int(__f, __p) \ - ({ \ - ssize_t __r = read(__f, __p, sizeof(*(__p))); \ - (__r == sizeof(*(__p))) ? 0 : -1; \ +#define read_int(__f, __p) \ + ({ \ + ssize_t __r = read(__f, __p, sizeof(*(__p))); \ + (__r == sizeof(*(__p))) ? 0 : -1; \ }) int main(int argc, char **argv) @@ -215,8 +215,7 @@ int main(int argc, char **argv) pr_perror("Can't create dgram pair"); return 1; } - test_msg("sk-dgp: sockpair %d %d\n", - sk_dgram_pair[0], sk_dgram_pair[1]); + test_msg("sk-dgp: sockpair %d %d\n", sk_dgram_pair[0], sk_dgram_pair[1]); ssprintf(filename, "%s/%s", subdir_dg, "sk-dtp"); if (unix_fill_sock_name(&addr, filename)) { @@ -303,39 +302,35 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - if (write_int(sk_dgram[1], &c1) || read_int(sk_dgram[0], &c2) || - write_int(sk_dgram[3], &c3) || read_int(sk_dgram[2], &c4)) { + if (write_int(sk_dgram[1], &c1) || read_int(sk_dgram[0], &c2) || write_int(sk_dgram[3], &c3) || + read_int(sk_dgram[2], &c4)) { fail("Unable to send/receive a message on dgram"); return 1; } if (c1 != c2 || c3 != c4) { - fail("Vals mismatch on dgram: c1 %d c2 %d c3 %d c4 %d", - c1, c2, c3, c4); + fail("Vals mismatch on dgram: c1 %d c2 %d c3 %d c4 %d", c1, c2, c3, c4); return 1; } - if (write_int(sk_dgram_pair[1], &c9) || - read_int(sk_dgram_pair[0], &c10)) { + if (write_int(sk_dgram_pair[1], &c9) || read_int(sk_dgram_pair[0], &c10)) { fail("Unable to send/receive a message on paired dgram"); return 1; } if (c9 != c10) { - fail("Vals mismatch on dgram: c9 %d c10 %d", - c9, c10); + fail("Vals mismatch on dgram: c9 %d c10 %d", c9, c10); return 1; } - if (write_int(sk_st[2], &c5) || read_int(sk_st[1], &c6) || - write_int(sk_st[4], &c7) || read_int(sk_st[3], &c8)) { + if (write_int(sk_st[2], &c5) || read_int(sk_st[1], &c6) || write_int(sk_st[4], &c7) || + read_int(sk_st[3], &c8)) { fail("Unable to send/receive a message on stream"); return 1; } if (c5 != c6 || c7 != c8) { - fail("Vals mismatch on stream: c5 %d c6 %d c7 %d c8 %d", - c5, c6, c7, c8); + fail("Vals mismatch on stream: c5 %d c6 %d c7 %d c8 %d", c5, c6, c7, c8); return 1; } diff --git a/test/zdtm/static/skip-me.c b/test/zdtm/static/skip-me.c index 9a552761e..a7f3e8d33 100644 --- a/test/zdtm/static/skip-me.c +++ b/test/zdtm/static/skip-me.c @@ -1,4 +1,4 @@ -int main(int argc, char ** argv) +int main(int argc, char **argv) { test_init(argc, argv); diff --git a/test/zdtm/static/sleeping00.c b/test/zdtm/static/sleeping00.c index f59ffaf1f..fb45ebc46 100644 --- a/test/zdtm/static/sleeping00.c +++ b/test/zdtm/static/sleeping00.c @@ -2,10 +2,10 @@ #include "zdtmtst.h" -const char *test_doc = "Suspend while migrating"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Suspend while migrating"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { test_init(argc, argv); diff --git a/test/zdtm/static/sock_filter00.c b/test/zdtm/static/sock_filter00.c index 7c408220c..abaabc4ee 100644 --- a/test/zdtm/static/sock_filter00.c +++ b/test/zdtm/static/sock_filter00.c @@ -8,17 +8,17 @@ #include "zdtmtst.h" -const char *test_doc = "Check socket filter"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check socket filter"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; #ifndef SO_GET_FILTER -#define SO_GET_FILTER SO_ATTACH_FILTER +#define SO_GET_FILTER SO_ATTACH_FILTER #endif #ifdef SOCK_FILTER01 -#define SFLEN 4 +#define SFLEN 4 #else -#define SFLEN 14 +#define SFLEN 14 #endif int main(int argc, char **argv) @@ -27,27 +27,18 @@ int main(int argc, char **argv) struct sock_fprog p; #ifdef SOCK_FILTER01 struct sock_filter f[SFLEN] = { - { 0x6, 0, 0, 0x0000ffff }, - { 0x6, 0, 0, 0x0000ffff }, - { 0x6, 0, 0, 0x0000ffff }, - { 0x6, 0, 0, 0x0000ffff }, + { 0x6, 0, 0, 0x0000ffff }, + { 0x6, 0, 0, 0x0000ffff }, + { 0x6, 0, 0, 0x0000ffff }, + { 0x6, 0, 0, 0x0000ffff }, }; #else struct sock_filter f[SFLEN] = { - { 0x28, 0, 0, 0x0000000c }, - { 0x15, 0, 4, 0x00000800 }, - { 0x20, 0, 0, 0x0000001a }, - { 0x15, 8, 0, 0x7f000001 }, - { 0x20, 0, 0, 0x0000001e }, - { 0x15, 6, 7, 0x7f000001 }, - { 0x15, 1, 0, 0x00000806 }, - { 0x15, 0, 5, 0x00008035 }, - { 0x20, 0, 0, 0x0000001c }, - { 0x15, 2, 0, 0x7f000001 }, - { 0x20, 0, 0, 0x00000026 }, - { 0x15, 0, 1, 0x7f000001 }, - { 0x6, 0, 0, 0x0000ffff }, - { 0x6, 0, 0, 0x00000000 }, + { 0x28, 0, 0, 0x0000000c }, { 0x15, 0, 4, 0x00000800 }, { 0x20, 0, 0, 0x0000001a }, + { 0x15, 8, 0, 0x7f000001 }, { 0x20, 0, 0, 0x0000001e }, { 0x15, 6, 7, 0x7f000001 }, + { 0x15, 1, 0, 0x00000806 }, { 0x15, 0, 5, 0x00008035 }, { 0x20, 0, 0, 0x0000001c }, + { 0x15, 2, 0, 0x7f000001 }, { 0x20, 0, 0, 0x00000026 }, { 0x15, 0, 1, 0x7f000001 }, + { 0x6, 0, 0, 0x0000ffff }, { 0x6, 0, 0, 0x00000000 }, }; #endif struct sock_filter f2[SFLEN], f3[SFLEN]; @@ -125,4 +116,3 @@ int main(int argc, char **argv) return 0; } - diff --git a/test/zdtm/static/sock_opts00.c b/test/zdtm/static/sock_opts00.c index e02a2e7ba..5b4624f6d 100644 --- a/test/zdtm/static/sock_opts00.c +++ b/test/zdtm/static/sock_opts00.c @@ -6,15 +6,15 @@ #include "zdtmtst.h" -const char *test_doc = "Check various socket options to work"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check various socket options to work"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; #define TEST_PORT 59687 #define TEST_ADDR INADDR_ANY -#define NOPTS 8 +#define NOPTS 8 -int main(int argc, char ** argv) +int main(int argc, char **argv) { int sock, ret = 0, vname[NOPTS], val[NOPTS], rval, i; socklen_t len = sizeof(int); @@ -59,8 +59,7 @@ int main(int argc, char ** argv) if (rval != val[i]) { if (rval + 1 == val[i]) { - pr_perror("can't reset option %d want %d have %d", i, - val[i], rval); + pr_perror("can't reset option %d want %d have %d", i, val[i], rval); return 1; } diff --git a/test/zdtm/static/sock_opts01.c b/test/zdtm/static/sock_opts01.c index 7dfce2257..2709d8586 100644 --- a/test/zdtm/static/sock_opts01.c +++ b/test/zdtm/static/sock_opts01.c @@ -8,10 +8,10 @@ #include "zdtmtst.h" -const char *test_doc = "Check that SO_BINDTODEVICE option works"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; +const char *test_doc = "Check that SO_BINDTODEVICE option works"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int sock, ret; char dev[IFNAMSIZ], dev2[IFNAMSIZ]; diff --git a/test/zdtm/static/sock_peercred.c b/test/zdtm/static/sock_peercred.c index 23c709bb5..5ebfe757a 100644 --- a/test/zdtm/static/sock_peercred.c +++ b/test/zdtm/static/sock_peercred.c @@ -12,10 +12,10 @@ #include "zdtmtst.h" #define STACK_SIZE (1024 * 1024) -#define GID_INC 1 -#define UID_INC 1 +#define GID_INC 1 +#define UID_INC 1 -const char *test_doc = "Check peercred of a unix socket remains the same"; +const char *test_doc = "Check peercred of a unix socket remains the same"; const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; static int child_func(void *fd_p) @@ -93,7 +93,7 @@ int main(int argc, char **argv) goto out; } - pid = clone(child_func, stack + STACK_SIZE, CLONE_FILES|SIGCHLD, (void *)(unsigned long)fd); + pid = clone(child_func, stack + STACK_SIZE, CLONE_FILES | SIGCHLD, (void *)(unsigned long)fd); if (pid == -1) { pr_perror("clone"); goto out; @@ -113,15 +113,14 @@ int main(int argc, char **argv) goto out; } - if (ucred.pid != pid || ucred.gid != getuid() + UID_INC || - ucred.gid != getgid() + GID_INC) { + if (ucred.pid != pid || ucred.gid != getuid() + UID_INC || ucred.gid != getgid() + GID_INC) { fail("Wrong pid, uid or gid"); goto out; } pass(); exit_code = 0; - out: +out: free(stack); return exit_code; } diff --git a/test/zdtm/static/socket-ext.c b/test/zdtm/static/socket-ext.c index 88e70559f..6ebe02b1d 100644 --- a/test/zdtm/static/socket-ext.c +++ b/test/zdtm/static/socket-ext.c @@ -14,8 +14,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test external sockets\n"; -const char *test_author = "Andrey Vagin <avagin@openvz.org"; +const char *test_doc = "Test external sockets\n"; +const char *test_author = "Andrey Vagin <avagin@openvz.org"; #define SK_DATA "packet" @@ -50,8 +50,7 @@ int main(int argc, char *argv[]) } chmod(dir, 0777); addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), - "%s/%s", dir, "sock"); + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", dir, "sock"); path = addr.sun_path; addrlen = sizeof(addr.sun_family) + strlen(path); @@ -70,7 +69,7 @@ int main(int argc, char *argv[]) pr_perror("Can't create socket"); return 1; } - ret = bind(sk, (struct sockaddr *) &addr, addrlen); + ret = bind(sk, (struct sockaddr *)&addr, addrlen); if (ret < 0) { pr_perror("Can't bind socket to %s", path); return 1; @@ -97,13 +96,12 @@ int main(int argc, char *argv[]) return 1; } - ret = connect(sk, (struct sockaddr *) &addr, addrlen); + ret = connect(sk, (struct sockaddr *)&addr, addrlen); if (ret < 0) { pr_perror("Can't connect socket"); return 1; } - test_daemon(); test_waitsig(); diff --git a/test/zdtm/static/socket-linger.c b/test/zdtm/static/socket-linger.c index b512745ca..ffa01f91f 100644 --- a/test/zdtm/static/socket-linger.c +++ b/test/zdtm/static/socket-linger.c @@ -5,13 +5,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check SO_LINGER socket option"; -const char *test_author = "Radostin Stoyanov <rstoyanov1@gmail.com>"; +const char *test_doc = "Check SO_LINGER socket option"; +const char *test_author = "Radostin Stoyanov <rstoyanov1@gmail.com>"; int main(int argc, char **argv) { int sk; - struct linger dump = {true, 30}, restore = {0, 0}; + struct linger dump = { true, 30 }, restore = { 0, 0 }; socklen_t optlen = sizeof(restore); test_init(argc, argv); @@ -36,14 +36,12 @@ int main(int argc, char **argv) } if (restore.l_onoff != dump.l_onoff) { - fail("linger.l_onoff has incorrect value (%d != %d)", - restore.l_onoff, dump.l_onoff); + fail("linger.l_onoff has incorrect value (%d != %d)", restore.l_onoff, dump.l_onoff); return 1; } if (restore.l_linger != dump.l_linger) { - fail("linger.l_linger has incorrect value (%d != %d)", - restore.l_linger, dump.l_linger); + fail("linger.l_linger has incorrect value (%d != %d)", restore.l_linger, dump.l_linger); return 1; } diff --git a/test/zdtm/static/socket-raw.c b/test/zdtm/static/socket-raw.c index 7382bf7c4..3bcfc3db6 100644 --- a/test/zdtm/static/socket-raw.c +++ b/test/zdtm/static/socket-raw.c @@ -29,36 +29,36 @@ * http://www.binarytides.com/raw-udp-sockets-c-linux/ */ -const char *test_doc = "Test RAW sockets (IPv4,6)\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; +const char *test_doc = "Test RAW sockets (IPv4,6)\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; #ifndef SO_IP_SET -# define SO_IP_SET 83 +#define SO_IP_SET 83 #endif #ifndef IP_SET_OP_VERSION -# define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */ +#define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */ #endif -#define pr_debug(format, arg...) test_msg("DBG: %s:%d: " format, __FILE__, __LINE__, ## arg) +#define pr_debug(format, arg...) test_msg("DBG: %s:%d: " format, __FILE__, __LINE__, ##arg) struct ip_set_req_version { - unsigned int op; - unsigned int version; + unsigned int op; + unsigned int version; }; struct pseudo_header { - uint32_t source_address; - uint32_t dest_address; - uint8_t placeholder; - uint8_t protocol; - uint16_t udp_length; + uint32_t source_address; + uint32_t dest_address; + uint8_t placeholder; + uint8_t protocol; + uint16_t udp_length; }; static int stop_icmp(int sk_icmp, int sk_icmpv6) { - struct icmp6_filter filter6 = { }; - struct icmp_filter filter = { }; + struct icmp6_filter filter6 = {}; + struct icmp_filter filter = {}; socklen_t aux; int ret = 0; @@ -70,8 +70,7 @@ static int stop_icmp(int sk_icmp, int sk_icmpv6) } if (filter.data != (1 << ICMP_TIMESTAMP)) { - pr_err("data mismatch on icmp filter %d != %d\n", - filter.data, (1 << ICMP_TIMESTAMP)); + pr_err("data mismatch on icmp filter %d != %d\n", filter.data, (1 << ICMP_TIMESTAMP)); return -1; } @@ -83,27 +82,25 @@ static int stop_icmp(int sk_icmp, int sk_icmpv6) } if (filter6.data[0] != (1 << ICMP_TIMESTAMP)) { - pr_err("data mismatch on icmp filter %d != %d\n", - filter6.data[0], (1 << ICMP_TIMESTAMP)); + pr_err("data mismatch on icmp filter %d != %d\n", filter6.data[0], (1 << ICMP_TIMESTAMP)); return -1; } return ret; } -static int start_icmp(int sk_icmp, int sk_icmpv6, - const char *a4, const char *a6, int port) +static int start_icmp(int sk_icmp, int sk_icmpv6, const char *a4, const char *a6, int port) { struct sockaddr_in addr_client; - struct icmp6_filter filter6 = { }; - struct icmp_filter filter = { }; + struct icmp6_filter filter6 = {}; + struct icmp_filter filter = {}; int ret = 0; memset(&addr_client, 0, sizeof(addr_client)); - addr_client.sin_family = AF_INET; - addr_client.sin_port = htons(port); - addr_client.sin_addr.s_addr = inet_addr(a4); + addr_client.sin_family = AF_INET; + addr_client.sin_port = htons(port); + addr_client.sin_addr.s_addr = inet_addr(a4); ret = bind(sk_icmp, (struct sockaddr *)&addr_client, sizeof(addr_client)); if (ret < 0) { @@ -164,7 +161,6 @@ static void raw_socks_storm(void) int sk6[IPPROTO_MAX]; size_t i; - for (i = 1; i < ARRAY_SIZE(sk4); i++) { sk4[i] = socket(PF_INET, SOCK_RAW | SOCK_NONBLOCK, i); if (sk4[i] >= 0) @@ -265,13 +261,13 @@ int main(int argc, char *argv[]) memset(&addr_serv, 0, sizeof(addr_serv)); memset(&addr_client, 0, sizeof(addr_client)); - addr_client.sin_family = AF_INET; - addr_client.sin_port = htons(port_client); - addr_client.sin_addr.s_addr = inet_addr(string_client_ip); + addr_client.sin_family = AF_INET; + addr_client.sin_port = htons(port_client); + addr_client.sin_addr.s_addr = inet_addr(string_client_ip); - addr_serv.sin_family = AF_INET; - addr_serv.sin_port = htons(port_serv); - addr_serv.sin_addr.s_addr = inet_addr(string_serv_ip); + addr_serv.sin_family = AF_INET; + addr_serv.sin_port = htons(port_serv); + addr_serv.sin_addr.s_addr = inet_addr(string_serv_ip); ret = bind(sk_udp_serv, (struct sockaddr *)&addr_serv, sizeof(addr_serv)); if (ret < 0) { @@ -287,36 +283,35 @@ int main(int argc, char *argv[]) } pr_debug("Bound sk_udp\n"); - if (start_icmp(sk_icmp, sk_icmpv6, string_client_icmp_ip, - string_client_icmpv6_ip, port_client)) + if (start_icmp(sk_icmp, sk_icmpv6, string_client_icmp_ip, string_client_icmpv6_ip, port_client)) return 1; data = datagram + sizeof(struct iphdr) + sizeof(struct udphdr); strcpy(data, string_data); - iph->ihl = 5; - iph->version = 4; - iph->tos = 0; - iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + strlen(string_data); - iph->id = htonl(54321); - iph->frag_off = 0; - iph->ttl = 255; - iph->protocol = IPPROTO_UDP; - iph->check = 0; - iph->saddr = inet_addr(string_client_ip); - iph->daddr = addr_serv.sin_addr.s_addr; - iph->check = csum((unsigned short *)datagram, sizeof(struct iphdr)); - - udph->source = htons(port_client); - udph->dest = htons(port_serv); - udph->len = htons(8 + strlen(data)); - udph->check = 0; - - psh.source_address = inet_addr(string_client_ip); - psh.dest_address = addr_serv.sin_addr.s_addr; - psh.placeholder = 0; - psh.protocol = IPPROTO_UDP; - psh.udp_length = htons(sizeof(struct udphdr) + strlen(string_data)); + iph->ihl = 5; + iph->version = 4; + iph->tos = 0; + iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + strlen(string_data); + iph->id = htonl(54321); + iph->frag_off = 0; + iph->ttl = 255; + iph->protocol = IPPROTO_UDP; + iph->check = 0; + iph->saddr = inet_addr(string_client_ip); + iph->daddr = addr_serv.sin_addr.s_addr; + iph->check = csum((unsigned short *)datagram, sizeof(struct iphdr)); + + udph->source = htons(port_client); + udph->dest = htons(port_serv); + udph->len = htons(8 + strlen(data)); + udph->check = 0; + + psh.source_address = inet_addr(string_client_ip); + psh.dest_address = addr_serv.sin_addr.s_addr; + psh.placeholder = 0; + psh.protocol = IPPROTO_UDP; + psh.udp_length = htons(sizeof(struct udphdr) + strlen(string_data)); psize = sizeof(psh) + sizeof(struct udphdr) + strlen(string_data); pseudogram = malloc(psize); @@ -325,7 +320,7 @@ int main(int argc, char *argv[]) exit(1); } - memcpy(pseudogram, (char *)&psh , sizeof(psh)); + memcpy(pseudogram, (char *)&psh, sizeof(psh)); memcpy(pseudogram + sizeof(psh), udph, sizeof(*udph) + strlen(string_data)); udph->check = csum((unsigned short *)pseudogram, psize); @@ -340,8 +335,7 @@ int main(int argc, char *argv[]) if (pid == 0) { task_waiter_wait4(&waiter, 2); pr_debug("Gonna read data\n"); - ret = recvfrom(sk_udp_serv, receiver, sizeof(receiver), 0, - (struct sockaddr *)&addr_client, &len); + ret = recvfrom(sk_udp_serv, receiver, sizeof(receiver), 0, (struct sockaddr *)&addr_client, &len); if (ret < 0) { task_waiter_complete(&waiter, 2); fail("Can't read data"); @@ -353,8 +347,7 @@ int main(int argc, char *argv[]) task_waiter_complete(&waiter, 3); if (strcmp(receiver, string_data)) { - pr_err("Data mismatch (got %s but expected %s)\n", - receiver, string_data); + pr_err("Data mismatch (got %s but expected %s)\n", receiver, string_data); exit(1); } else pr_debug("Data match\n"); @@ -369,8 +362,7 @@ int main(int argc, char *argv[]) test_daemon(); test_waitsig(); - if (sendto(sk_udp, datagram, iph->tot_len, 0, - (struct sockaddr *)&addr_serv, sizeof(addr_serv)) < 0) { + if (sendto(sk_udp, datagram, iph->tot_len, 0, (struct sockaddr *)&addr_serv, sizeof(addr_serv)) < 0) { kill(pid, SIGKILL); fail("Can't send RAW data"); exit(1); diff --git a/test/zdtm/static/socket-tcp-close-wait.c b/test/zdtm/static/socket-tcp-close-wait.c index 152dcf31f..6e5ccdbeb 100644 --- a/test/zdtm/static/socket-tcp-close-wait.c +++ b/test/zdtm/static/socket-tcp-close-wait.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -169,8 +169,7 @@ int main(int argc, char **argv) if (size < 0) return 1; #else - if (read(fd, buf, sizeof(buf)) != sizeof(TEST_MSG) || - strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) { + if (read(fd, buf, sizeof(buf)) != sizeof(TEST_MSG) || strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) { pr_perror("read"); return 1; } diff --git a/test/zdtm/static/socket-tcp-close0.c b/test/zdtm/static/socket-tcp-close0.c index 270965cbd..96ac2b38a 100644 --- a/test/zdtm/static/socket-tcp-close0.c +++ b/test/zdtm/static/socket-tcp-close0.c @@ -18,7 +18,7 @@ static int check_socket_closed(int sk) { int err, buffer = 0; struct { - __u8 tcpi_state; + __u8 tcpi_state; } info; socklen_t len = sizeof(info); struct pollfd pollfd = {}; diff --git a/test/zdtm/static/socket-tcp-close1.c b/test/zdtm/static/socket-tcp-close1.c index 49a34a6ef..d5e473bee 100644 --- a/test/zdtm/static/socket-tcp-close1.c +++ b/test/zdtm/static/socket-tcp-close1.c @@ -15,7 +15,7 @@ static int check_socket_state(int sk, int state) { int err; struct { - __u8 tcpi_state; + __u8 tcpi_state; } info; socklen_t len = sizeof(info); diff --git a/test/zdtm/static/socket-tcp-closed.c b/test/zdtm/static/socket-tcp-closed.c index e8fc25c56..f9516357c 100644 --- a/test/zdtm/static/socket-tcp-closed.c +++ b/test/zdtm/static/socket-tcp-closed.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif diff --git a/test/zdtm/static/socket-tcp-closing.c b/test/zdtm/static/socket-tcp-closing.c index 84ff6be9d..87e1d7533 100644 --- a/test/zdtm/static/socket-tcp-closing.c +++ b/test/zdtm/static/socket-tcp-closing.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif diff --git a/test/zdtm/static/socket-tcp-fin-wait1.c b/test/zdtm/static/socket-tcp-fin-wait1.c index 4bc7b3238..9b8488904 100644 --- a/test/zdtm/static/socket-tcp-fin-wait1.c +++ b/test/zdtm/static/socket-tcp-fin-wait1.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -202,7 +202,6 @@ int main(int argc, char **argv) return 1; } - test_daemon(); test_waitsig(); @@ -211,8 +210,7 @@ int main(int argc, char **argv) return 1; } - if (recv(fd, buf, sizeof(buf), MSG_WAITALL) != sizeof(TEST_MSG) || - strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) { + if (recv(fd, buf, sizeof(buf), MSG_WAITALL) != sizeof(TEST_MSG) || strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) { pr_perror("recv: expected %s, got %s", TEST_MSG, buf); return 1; } diff --git a/test/zdtm/static/socket-tcp-listen.c b/test/zdtm/static/socket-tcp-listen.c index 52d21d894..da3dcb8cf 100644 --- a/test/zdtm/static/socket-tcp-listen.c +++ b/test/zdtm/static/socket-tcp-listen.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -65,7 +65,6 @@ int main(int argc, char **argv) int val; socklen_t optlen; - test_init(argc, argv); if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) { @@ -87,7 +86,7 @@ int main(int argc, char **argv) test_waitsig(); clt = tcp_init_client_with_fd(clt, ZDTM_FAMILY, "localhost", port); - if (clt < 0) + if (clt < 0) return 1; /* diff --git a/test/zdtm/static/socket-tcp-reseted.c b/test/zdtm/static/socket-tcp-reseted.c index 07ad36009..ad382e38e 100644 --- a/test/zdtm/static/socket-tcp-reseted.c +++ b/test/zdtm/static/socket-tcp-reseted.c @@ -2,19 +2,19 @@ #include "zdtmtst.h" #include <string.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <stdlib.h> #include <sys/wait.h> #include <signal.h> #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -46,11 +46,10 @@ int main(int argc, char **argv) return 1; } - clt = tcp_init_client(ZDTM_FAMILY, "localhost", port); if (clt < 0) { pr_perror("Unable to create a client socket"); - return 1; + return 1; } /* @@ -65,7 +64,8 @@ int main(int argc, char **argv) pr_perror("Unable to write into a socket"); return 1; } - snprintf(cmd, sizeof(cmd), "iptables -w -t filter --protocol tcp -A INPUT --dport %d -j REJECT --reject-with tcp-reset", port); + snprintf(cmd, sizeof(cmd), + "iptables -w -t filter --protocol tcp -A INPUT --dport %d -j REJECT --reject-with tcp-reset", port); if (system(cmd)) return 1; @@ -74,7 +74,8 @@ int main(int argc, char **argv) return 1; } - snprintf(cmd, sizeof(cmd), "iptables -w -t filter --protocol tcp -D INPUT --dport %d -j REJECT --reject-with tcp-reset", port); + snprintf(cmd, sizeof(cmd), + "iptables -w -t filter --protocol tcp -D INPUT --dport %d -j REJECT --reject-with tcp-reset", port); if (system(cmd)) return 1; diff --git a/test/zdtm/static/socket-tcp-reuseport.c b/test/zdtm/static/socket-tcp-reuseport.c index a085ab503..25e0493d4 100644 --- a/test/zdtm/static/socket-tcp-reuseport.c +++ b/test/zdtm/static/socket-tcp-reuseport.c @@ -19,7 +19,7 @@ const char *test_author = "Andrey Vagin <avagin@parallels.com"; #include <sched.h> #include <netinet/tcp.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #define BUF_SIZE 4096 @@ -54,9 +54,7 @@ int write_data(int fd, const unsigned char *buf, int size) int main(int argc, char **argv) { - struct zdtm_tcp_opts opts = { .reuseaddr = false, - .reuseport = true, - .flags = SOCK_NONBLOCK}; + struct zdtm_tcp_opts opts = { .reuseaddr = false, .reuseport = true, .flags = SOCK_NONBLOCK }; unsigned char buf[BUF_SIZE]; int port = 8880, port2; int fd, fd_s, fd_s2, clt, i; @@ -79,12 +77,11 @@ int main(int argc, char **argv) if (port != port2) return 1; - if (setsockopt(fd_s, SOL_SOCKET, SO_REUSEPORT, &no, sizeof(int)) == -1 ) { + if (setsockopt(fd_s, SOL_SOCKET, SO_REUSEPORT, &no, sizeof(int)) == -1) { pr_perror("Unable to set SO_REUSEPORT"); return -1; } - clt = tcp_init_client(ZDTM_FAMILY, "localhost", port); if (clt < 0) return 1; @@ -103,7 +100,6 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - optlen = sizeof(val); if (getsockopt(fd_s, SOL_SOCKET, SO_REUSEPORT, &val, &optlen)) { pr_perror("getsockopt"); @@ -123,7 +119,7 @@ int main(int argc, char **argv) return 1; } - for (i = 0; ; i++) { + for (i = 0;; i++) { crc = 0; datagen(buf, BUF_SIZE, &crc); if (write_data(fd, buf, BUF_SIZE)) { diff --git a/test/zdtm/static/socket-tcp-skip-in-flight.c b/test/zdtm/static/socket-tcp-skip-in-flight.c index 99ca03ac5..51d74d2ce 100644 --- a/test/zdtm/static/socket-tcp-skip-in-flight.c +++ b/test/zdtm/static/socket-tcp-skip-in-flight.c @@ -24,7 +24,6 @@ const char *test_author = "Radostin Stoyanov <rstoyanov1@gmail.com>"; #include <unistd.h> #include <fcntl.h> - int main(int argc, char **argv) { struct pollfd poll_set[1]; diff --git a/test/zdtm/static/socket-tcp-syn-sent.c b/test/zdtm/static/socket-tcp-syn-sent.c index 755532a8a..8265d5fb7 100644 --- a/test/zdtm/static/socket-tcp-syn-sent.c +++ b/test/zdtm/static/socket-tcp-syn-sent.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -52,7 +52,6 @@ int main(int argc, char **argv) return 1; } - if ((sock = socket(ZDTM_FAMILY, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP)) < 0) { pr_perror("can't create socket"); return -1; @@ -61,13 +60,13 @@ int main(int argc, char **argv) /* Construct the server address structure */ memset(&addr, 0, sizeof(addr)); if (ZDTM_FAMILY == AF_INET) { - addr.v4.sin_family = AF_INET; + addr.v4.sin_family = AF_INET; inet_pton(AF_INET, "localhost", &addr.v4.sin_addr); } else { - addr.v6.sin6_family = AF_INET6; + addr.v6.sin6_family = AF_INET6; inet_pton(AF_INET6, "localhost", &addr.v6.sin6_addr); } - if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { pr_perror("can't connect to server"); return -1; } @@ -79,17 +78,17 @@ int main(int argc, char **argv) /* Construct the server address structure */ memset(&addr, 0, sizeof(addr)); if (ZDTM_FAMILY == AF_INET) { - addr.v4.sin_family = AF_INET; - addr.v4.sin_port = htons(port); + addr.v4.sin_family = AF_INET; + addr.v4.sin_port = htons(port); inet_pton(AF_INET, "localhost", &addr.v4.sin_addr); } else { - addr.v6.sin6_family = AF_INET6; - addr.v6.sin6_port = htons(port); + addr.v6.sin6_family = AF_INET6; + addr.v6.sin6_port = htons(port); inet_pton(AF_INET6, "localhost", &addr.v6.sin6_addr); } errno = 0; - if (connect(sock, (struct sockaddr *) &addr, sizeof(addr)) == 0 || errno != EINPROGRESS) { + if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0 || errno != EINPROGRESS) { pr_perror("can't connect to server"); return -1; } @@ -137,7 +136,6 @@ int main(int argc, char **argv) return 1; } - pass(); return 0; } diff --git a/test/zdtm/static/socket-tcp-unconn.c b/test/zdtm/static/socket-tcp-unconn.c index 1b3e1a660..bfb0cdb8e 100644 --- a/test/zdtm/static/socket-tcp-unconn.c +++ b/test/zdtm/static/socket-tcp-unconn.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -51,7 +51,6 @@ int main(int argc, char **argv) return 1; } - if ((sock = socket(ZDTM_FAMILY, SOCK_STREAM, IPPROTO_TCP)) < 0) { pr_perror("can't create socket"); return -1; @@ -60,13 +59,13 @@ int main(int argc, char **argv) /* Construct the server address structure */ memset(&addr, 0, sizeof(addr)); if (ZDTM_FAMILY == AF_INET) { - addr.v4.sin_family = AF_INET; + addr.v4.sin_family = AF_INET; inet_pton(AF_INET, "localhost", &addr.v4.sin_addr); } else { - addr.v6.sin6_family = AF_INET6; + addr.v6.sin6_family = AF_INET6; inet_pton(AF_INET6, "localhost", &addr.v6.sin6_addr); } - if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { pr_perror("can't connect to server"); return -1; } @@ -93,15 +92,15 @@ int main(int argc, char **argv) /* Construct the server address structure */ memset(&addr, 0, sizeof(addr)); if (ZDTM_FAMILY == AF_INET) { - addr.v4.sin_family = AF_INET; - addr.v4.sin_port = htons(port); + addr.v4.sin_family = AF_INET; + addr.v4.sin_port = htons(port); inet_pton(AF_INET, "localhost", &addr.v4.sin_addr); } else { - addr.v6.sin6_family = AF_INET6; - addr.v6.sin6_port = htons(port); + addr.v6.sin6_family = AF_INET6; + addr.v6.sin6_port = htons(port); inet_pton(AF_INET6, "localhost", &addr.v6.sin6_addr); } - if (connect(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { pr_perror("can't connect to server"); return -1; } @@ -116,7 +115,6 @@ int main(int argc, char **argv) } close(fd_s); - pass(); return 0; } diff --git a/test/zdtm/static/socket-tcp.c b/test/zdtm/static/socket-tcp.c index 80c2e7b3b..f6ef47385 100644 --- a/test/zdtm/static/socket-tcp.c +++ b/test/zdtm/static/socket-tcp.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif diff --git a/test/zdtm/static/socket-tcpbuf.c b/test/zdtm/static/socket-tcpbuf.c index fbb4043f1..0ed69c09a 100644 --- a/test/zdtm/static/socket-tcpbuf.c +++ b/test/zdtm/static/socket-tcpbuf.c @@ -22,7 +22,7 @@ const char *test_author = "Andrey Vagin <avagin@parallels.com"; static int port = 8880; -#define BUF_SIZE 4096 +#define BUF_SIZE 4096 #define TCP_MAX_BUF (100 << 20) static void read_safe(int fd, void *buf, size_t size) @@ -236,15 +236,13 @@ int main(int argc, char **argv) } sk_bsize = TCP_MAX_BUF; - if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, - &sk_bsize, sizeof(sk_bsize)) == -1) { + if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sk_bsize, sizeof(sk_bsize)) == -1) { pr_perror("Can't set snd buf"); return 1; } sk_bsize = TCP_MAX_BUF; - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, - &sk_bsize, sizeof(sk_bsize)) == -1) { + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sk_bsize, sizeof(sk_bsize)) == -1) { pr_perror("Can't set snd buf"); return 1; } diff --git a/test/zdtm/static/socket6_udp.c b/test/zdtm/static/socket6_udp.c index b81a6afee..15f1239c0 100644 --- a/test/zdtm/static/socket6_udp.c +++ b/test/zdtm/static/socket6_udp.c @@ -12,7 +12,7 @@ const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>\n"; #include <errno.h> #include <stdlib.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <sys/wait.h> static int port = 8880; @@ -54,7 +54,7 @@ int main(int argc, char **argv) memset(&addr2, 0, sizeof(addr2)); addr2.sin6_family = AF_INET6; - addr2.sin6_port = htons(port+1); + addr2.sin6_port = htons(port + 1); inet_pton(AF_INET6, "::1", &addr2.sin6_addr); ret = bind(sk2, (struct sockaddr *)&addr2, len); @@ -72,8 +72,7 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - ret = sendto(sk1, MSG1, sizeof(MSG1), 0, - (struct sockaddr *)&addr2, len); + ret = sendto(sk1, MSG1, sizeof(MSG1), 0, (struct sockaddr *)&addr2, len); if (ret < 0) { fail("Can't send"); return 1; @@ -85,8 +84,7 @@ int main(int argc, char **argv) return 1; } - ret = recvfrom(sk1, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk1, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { fail("Can't recv C"); return 1; @@ -102,8 +100,7 @@ int main(int argc, char **argv) return 1; } - ret = recvfrom(sk2, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk2, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { fail("Can't recv"); return 1; diff --git a/test/zdtm/static/socket_aio.c b/test/zdtm/static/socket_aio.c index 1dcdfec42..a545483e1 100644 --- a/test/zdtm/static/socket_aio.c +++ b/test/zdtm/static/socket_aio.c @@ -31,7 +31,7 @@ int main(int argc, char **argv) int status; pid_t pid; int ret, res; - const struct aiocb *aioary[1]; + const struct aiocb *aioary[1]; task_waiter_t child_waiter; test_init(argc, argv); @@ -77,7 +77,7 @@ int main(int argc, char **argv) test_msg("."); #endif res = 0; -again: + again: if (aio_suspend(aioary, 1, NULL) < 0 && errno != EINTR) { pr_perror("aio_suspend failed"); res = 1; @@ -125,7 +125,6 @@ again: } close(fd); - if (wait(&status) < 0) { pr_perror("wait failed"); goto error; diff --git a/test/zdtm/static/socket_close_data.c b/test/zdtm/static/socket_close_data.c index de552ada9..301896443 100644 --- a/test/zdtm/static/socket_close_data.c +++ b/test/zdtm/static/socket_close_data.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check one end of socketpair with data"; -const char *test_author = "Andrew Vagin <avagin@openvz.org"; +const char *test_doc = "Check one end of socketpair with data"; +const char *test_author = "Andrew Vagin <avagin@openvz.org"; #define MSG "hello" int main(int argc, char **argv) diff --git a/test/zdtm/static/socket_close_data01.c b/test/zdtm/static/socket_close_data01.c index df4b894b2..7ffbd7f21 100644 --- a/test/zdtm/static/socket_close_data01.c +++ b/test/zdtm/static/socket_close_data01.c @@ -9,8 +9,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check data of bound socket and possibility to connect"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo"; +const char *test_doc = "Check data of bound socket and possibility to connect"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo"; #define MSG "hello" char *filename; @@ -30,7 +30,7 @@ static int client(const char *iter) addr.sun_family = AF_UNIX; strcpy(addr.sun_path, filename); - if (connect(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) < 0) { + if (connect(sk, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) { pr_perror("connect failed %s", iter); return 1; } @@ -60,7 +60,7 @@ int main(int argc, char **argv) addr.sun_family = AF_UNIX; strcpy(addr.sun_path, filename); - if (bind(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_un))) { + if (bind(srv, (struct sockaddr *)&addr, sizeof(struct sockaddr_un))) { pr_perror("bind srv"); exit(1); } diff --git a/test/zdtm/static/socket_dgram_data.c b/test/zdtm/static/socket_dgram_data.c index 0f29af0ad..d555050a4 100644 --- a/test/zdtm/static/socket_dgram_data.c +++ b/test/zdtm/static/socket_dgram_data.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that data in dgram socket are restored correctly"; -const char *test_author = "Andrew Vagin <avagin@openvz.org"; +const char *test_doc = "Check that data in dgram socket are restored correctly"; +const char *test_author = "Andrew Vagin <avagin@openvz.org"; #define SK_SRV "\0socket_dgram_srv" @@ -42,15 +42,15 @@ int main(int argc, char **argv) memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV)); addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV); - if (bind(srv, (struct sockaddr *) &addr, addrlen)) { + if (bind(srv, (struct sockaddr *)&addr, addrlen)) { fail("bind"); exit(1); } - if (connect(clnt1, (struct sockaddr *) &addr, addrlen)) { + if (connect(clnt1, (struct sockaddr *)&addr, addrlen)) { fail("connect"); exit(1); } - if (connect(clnt2, (struct sockaddr *) &addr, addrlen)) { + if (connect(clnt2, (struct sockaddr *)&addr, addrlen)) { fail("connect"); exit(1); } diff --git a/test/zdtm/static/socket_listen.c b/test/zdtm/static/socket_listen.c index a4d3e66bd..519107d01 100644 --- a/test/zdtm/static/socket_listen.c +++ b/test/zdtm/static/socket_listen.c @@ -1,13 +1,13 @@ #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET6 #elif defined(ZDTM_IPV6) -#define ZDTM_FAMILY AF_INET6 +#define ZDTM_FAMILY AF_INET6 #define ZDTM_SRV_FAMILY AF_INET6 #else -#define ZDTM_FAMILY AF_INET +#define ZDTM_FAMILY AF_INET #define ZDTM_SRV_FAMILY AF_INET #endif @@ -31,7 +31,9 @@ static int port = 8880; #define BUF_SIZE 1024 -static void sig_hand(int signo) {} +static void sig_hand(int signo) +{ +} int main(int argc, char **argv) { @@ -42,7 +44,7 @@ int main(int argc, char **argv) int res; uint32_t crc; struct sigaction sa = { - .sa_handler = sig_hand, + .sa_handler = sig_hand, /* don't set SA_RESTART */ }; @@ -103,7 +105,6 @@ int main(int argc, char **argv) } close(fd); - if (wait(&status) < 0) { pr_perror("wait failed"); goto error; diff --git a/test/zdtm/static/socket_queues.c b/test/zdtm/static/socket_queues.c index 86e052db7..e30bca0e1 100644 --- a/test/zdtm/static/socket_queues.c +++ b/test/zdtm/static/socket_queues.c @@ -16,8 +16,8 @@ /* FIXME Need gram sockets tests */ -const char *test_doc = "Test unix sockets queues (2 messages in queue)\n"; -const char *test_author = "Stanislav Kinsbursky <skinsbursky@parallels.com>\n"; +const char *test_doc = "Test unix sockets queues (2 messages in queue)\n"; +const char *test_author = "Stanislav Kinsbursky <skinsbursky@parallels.com>\n"; #define SK_DATA_S1 "packet stream left" #define SK_DATA_S2 "packet stream right" @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) fail("data corrupted"); exit(1); } - read(ssk_pair_d[0], buf_right,strlen(SK_DATA_D1) + 1); + read(ssk_pair_d[0], buf_right, strlen(SK_DATA_D1) + 1); if (strcmp(buf_right, SK_DATA_D1)) { fail("data corrupted"); exit(1); diff --git a/test/zdtm/static/socket_snd_addr.c b/test/zdtm/static/socket_snd_addr.c index 89a0a1762..a78af3a70 100644 --- a/test/zdtm/static/socket_snd_addr.c +++ b/test/zdtm/static/socket_snd_addr.c @@ -7,16 +7,16 @@ #include "zdtmtst.h" -const char *test_doc = "Check that sender addresses are restored"; -const char *test_author = "Andrew Vagin <avagin@openvz.org"; +const char *test_doc = "Check that sender addresses are restored"; +const char *test_author = "Andrew Vagin <avagin@openvz.org"; -#define SK_SRV "\0socket_snd_srv" +#define SK_SRV "\0socket_snd_srv" #define SK_NAME "\0A-socket_snd_clnt" char sk_names[2][128] = { - SK_NAME, - SK_NAME, - }; + SK_NAME, + SK_NAME, +}; #define MSG "hello" int main(int argc, char **argv) @@ -26,15 +26,15 @@ int main(int argc, char **argv) int srv, clnt = -1, ret, i; char buf[1024]; struct iovec iov = { - .iov_base = &buf, - .iov_len = sizeof(buf), - }; + .iov_base = &buf, + .iov_len = sizeof(buf), + }; struct msghdr hdr = { - .msg_name = &addr, - .msg_namelen = sizeof(addr), - .msg_iov = &iov, - .msg_iovlen = 1, - }; + .msg_name = &addr, + .msg_namelen = sizeof(addr), + .msg_iov = &iov, + .msg_iovlen = 1, + }; test_init(argc, argv); @@ -44,7 +44,7 @@ int main(int argc, char **argv) memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV)); addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV); - if (bind(srv, (struct sockaddr *) &addr, addrlen)) { + if (bind(srv, (struct sockaddr *)&addr, addrlen)) { fail("bind"); exit(1); } @@ -58,14 +58,14 @@ int main(int argc, char **argv) memcpy(addr.sun_path, sk_names[i], sizeof(SK_NAME)); addrlen = sizeof(addr.sun_family) + sizeof(SK_NAME); - if (bind(clnt, (struct sockaddr *) &addr, addrlen)) { + if (bind(clnt, (struct sockaddr *)&addr, addrlen)) { fail("bind"); exit(1); } memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV)); addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV); - if (connect(clnt, (struct sockaddr *) &addr, addrlen)) { + if (connect(clnt, (struct sockaddr *)&addr, addrlen)) { fail("connect"); exit(1); } diff --git a/test/zdtm/static/socket_udp-corked.c b/test/zdtm/static/socket_udp-corked.c index 540b9456a..f502ec7ea 100644 --- a/test/zdtm/static/socket_udp-corked.c +++ b/test/zdtm/static/socket_udp-corked.c @@ -17,7 +17,7 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com<>\n"; #include <errno.h> #include <stdlib.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <sys/wait.h> #include <netinet/udp.h> @@ -70,7 +70,6 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - pass(); return 0; } diff --git a/test/zdtm/static/socket_udp.c b/test/zdtm/static/socket_udp.c index cce29fc96..c38bcb6fd 100644 --- a/test/zdtm/static/socket_udp.c +++ b/test/zdtm/static/socket_udp.c @@ -17,7 +17,7 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com<>\n"; #include <errno.h> #include <stdlib.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <sys/wait.h> static int port = 8880; @@ -77,8 +77,7 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - ret = sendto(sk1, MSG1, sizeof(MSG1), 0, - (struct sockaddr *)&addr2, len); + ret = sendto(sk1, MSG1, sizeof(MSG1), 0, (struct sockaddr *)&addr2, len); if (ret < 0) { fail("Can't send"); return 1; @@ -90,8 +89,7 @@ int main(int argc, char **argv) return 1; } - ret = recvfrom(sk1, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk1, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { fail("Can't recv C"); return 1; @@ -107,8 +105,7 @@ int main(int argc, char **argv) return 1; } - ret = recvfrom(sk2, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk2, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { fail("Can't recv"); return 1; diff --git a/test/zdtm/static/socket_udp_shutdown.c b/test/zdtm/static/socket_udp_shutdown.c index 5d65348ea..91dc8f30a 100644 --- a/test/zdtm/static/socket_udp_shutdown.c +++ b/test/zdtm/static/socket_udp_shutdown.c @@ -7,13 +7,13 @@ #include <errno.h> #include <stdlib.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <sys/wait.h> #include "zdtmtst.h" -const char *test_doc = "static test for UDP shutdown'ed socket"; -const char *test_author = "Cyrill Gorcunov <gorcunov@virtuozzo.com>"; +const char *test_doc = "static test for UDP shutdown'ed socket"; +const char *test_author = "Cyrill Gorcunov <gorcunov@virtuozzo.com>"; static int port = 8881; @@ -39,41 +39,36 @@ int main(int argc, char **argv) memset(&addr1, 0, sizeof(addr1)); memset(&addr2, 0, sizeof(addr1)); - addr1.sin_family = AF_INET; - addr1.sin_addr.s_addr = inet_addr("127.0.0.10"); - addr1.sin_port = htons(port); + addr1.sin_family = AF_INET; + addr1.sin_addr.s_addr = inet_addr("127.0.0.10"); + addr1.sin_port = htons(port); - addr2.sin_family = AF_INET; - addr2.sin_addr.s_addr = inet_addr("127.0.0.10"); - addr2.sin_port = htons(port + 1); + addr2.sin_family = AF_INET; + addr2.sin_addr.s_addr = inet_addr("127.0.0.10"); + addr2.sin_port = htons(port + 1); - if (bind(sk1, (struct sockaddr *)&addr1, len) < 0 || - bind(sk2, (struct sockaddr *)&addr2, len) < 0) { + if (bind(sk1, (struct sockaddr *)&addr1, len) < 0 || bind(sk2, (struct sockaddr *)&addr2, len) < 0) { pr_perror("Can't bind socket"); return 1; } - if (connect(sk1, (struct sockaddr *)&addr2, len) || - connect(sk2, (struct sockaddr *)&addr1, len)) { + if (connect(sk1, (struct sockaddr *)&addr2, len) || connect(sk2, (struct sockaddr *)&addr1, len)) { pr_perror("Can't connect"); return 1; } - if (shutdown(sk1, SHUT_WR) || - shutdown(sk2, SHUT_RD)) { + if (shutdown(sk1, SHUT_WR) || shutdown(sk2, SHUT_RD)) { pr_perror("Can't shutdown"); return 1; } - ret = sendto(sk2, MSG1, sizeof(MSG1), 0, - (struct sockaddr *)&addr1, len); + ret = sendto(sk2, MSG1, sizeof(MSG1), 0, (struct sockaddr *)&addr1, len); if (ret < 0) { pr_perror("Can't send"); return 1; } - ret = recvfrom(sk1, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk1, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { pr_perror("Can't receive data"); return 1; @@ -92,15 +87,13 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - ret = sendto(sk2, MSG1, sizeof(MSG1), 0, - (struct sockaddr *)&addr1, len); + ret = sendto(sk2, MSG1, sizeof(MSG1), 0, (struct sockaddr *)&addr1, len); if (ret < 0) { pr_perror("Can't send"); return 1; } - ret = recvfrom(sk1, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk1, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { pr_perror("Can't receive data"); return 1; @@ -116,8 +109,7 @@ int main(int argc, char **argv) return 1; } - ret = sendto(sk1, MSG1, sizeof(MSG1), 0, - (struct sockaddr *)&addr2, len); + ret = sendto(sk1, MSG1, sizeof(MSG1), 0, (struct sockaddr *)&addr2, len); if (ret >= 0) { fail("Sent to write-shutdown'ed socket"); return 1; diff --git a/test/zdtm/static/socket_udplite.c b/test/zdtm/static/socket_udplite.c index 763df319b..886317455 100644 --- a/test/zdtm/static/socket_udplite.c +++ b/test/zdtm/static/socket_udplite.c @@ -17,7 +17,7 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com<>\n"; #include <errno.h> #include <stdlib.h> #include <sys/socket.h> -#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <sys/wait.h> static int port = 8890; @@ -133,8 +133,7 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - ret = sendto(sk1, MSG1, sizeof(MSG1), 0, - (struct sockaddr *)&addr2, len); + ret = sendto(sk1, MSG1, sizeof(MSG1), 0, (struct sockaddr *)&addr2, len); if (ret < 0) { fail("Can't send"); return 1; @@ -146,8 +145,7 @@ int main(int argc, char **argv) return 1; } - ret = recvfrom(sk1, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk1, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { fail("Can't recv C"); return 1; @@ -163,8 +161,7 @@ int main(int argc, char **argv) return 1; } - ret = recvfrom(sk2, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &len); + ret = recvfrom(sk2, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &len); if (ret <= 0) { fail("Can't recv"); return 1; diff --git a/test/zdtm/static/sockets00.c b/test/zdtm/static/sockets00.c index 4aa8ae098..53890077b 100644 --- a/test/zdtm/static/sockets00.c +++ b/test/zdtm/static/sockets00.c @@ -15,8 +15,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test unix stream sockets\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Test unix stream sockets\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; #define SK_DATA "packet" @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = bind(ssk_icon[0], (struct sockaddr *) &addr, addrlen); + ret = bind(ssk_icon[0], (struct sockaddr *)&addr, addrlen); if (ret) { fail("bind"); exit(1); @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = connect(ssk_icon[2], (struct sockaddr *) &addr, addrlen); + ret = connect(ssk_icon[2], (struct sockaddr *)&addr, addrlen); if (ret) { fail("connect"); exit(1); @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = connect(ssk_icon[1], (struct sockaddr *) &addr, addrlen); + ret = connect(ssk_icon[1], (struct sockaddr *)&addr, addrlen); if (ret) { fail("connect"); exit(1); @@ -124,14 +124,12 @@ int main(int argc, char *argv[]) } if (st_b.st_mode != st_a.st_mode) { - fail("The file permissions for %s were changed %o %o", - path, st_b.st_mode, st_a.st_mode); + fail("The file permissions for %s were changed %o %o", path, st_b.st_mode, st_a.st_mode); exit(1); } if (st_b.st_uid != uid || st_b.st_gid != gid) { - fail("Owner user or group for %s corrupted, uid=%d, gid=%d", - path, st_b.st_uid, st_b.st_gid); + fail("Owner user or group for %s corrupted, uid=%d, gid=%d", path, st_b.st_uid, st_b.st_gid); exit(1); } diff --git a/test/zdtm/static/sockets01.c b/test/zdtm/static/sockets01.c index 12650536f..e35a31fec 100644 --- a/test/zdtm/static/sockets01.c +++ b/test/zdtm/static/sockets01.c @@ -13,13 +13,21 @@ #include "zdtmtst.h" -const char *test_doc = "Test unix sockets shutdown"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; - -#define fin(msg) do { pr_perror(msg); exit(1); } while (0) -#define ffin(msg) do { fail(msg); exit(1); } while (0) - -#define TEST_MSG "test-message" +const char *test_doc = "Test unix sockets shutdown"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>"; + +#define fin(msg) \ + do { \ + pr_perror(msg); \ + exit(1); \ + } while (0) +#define ffin(msg) \ + do { \ + fail(msg); \ + exit(1); \ + } while (0) + +#define TEST_MSG "test-message" static char buf[sizeof(TEST_MSG)]; int main(int argc, char *argv[]) diff --git a/test/zdtm/static/sockets02.c b/test/zdtm/static/sockets02.c index a227c88ae..2729ade2c 100644 --- a/test/zdtm/static/sockets02.c +++ b/test/zdtm/static/sockets02.c @@ -13,8 +13,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test semi-closed unix stream connection\n"; -const char *test_author = "Pavel Emelyanov <xemul@parallels.com>\n"; +const char *test_doc = "Test semi-closed unix stream connection\n"; +const char *test_author = "Pavel Emelyanov <xemul@parallels.com>\n"; int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/sockets03.c b/test/zdtm/static/sockets03.c index cbc46ca27..cd6f60831 100644 --- a/test/zdtm/static/sockets03.c +++ b/test/zdtm/static/sockets03.c @@ -14,8 +14,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test unix stream sockets with mismatch in shutdown state\n"; -const char *test_author = "Andrey Ryabinin <aryabinin@virtuozzo.com>"; +const char *test_doc = "Test unix stream sockets with mismatch in shutdown state\n"; +const char *test_author = "Andrey Ryabinin <aryabinin@virtuozzo.com>"; #define SK_DATA "packet" @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = bind(sk[0], (struct sockaddr *) &addr, addrlen); + ret = bind(sk[0], (struct sockaddr *)&addr, addrlen); if (ret) { fail("bind"); exit(1); @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = connect(sk[1], (struct sockaddr *) &addr, addrlen); + ret = connect(sk[1], (struct sockaddr *)&addr, addrlen); if (ret) { fail("connect"); exit(1); diff --git a/test/zdtm/static/sockets_dgram.c b/test/zdtm/static/sockets_dgram.c index 35ee88244..e88b43f89 100644 --- a/test/zdtm/static/sockets_dgram.c +++ b/test/zdtm/static/sockets_dgram.c @@ -13,12 +13,12 @@ #include "zdtmtst.h" -const char *test_doc = "Test unix dgram sockets\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Test unix dgram sockets\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; -#define SK_DATA_BOUND "data-packet-bound" -#define SK_DATA_CONN "data-packet-conn" -#define SK_DATA_BOUND_CONN "data-packet-bound-conn" +#define SK_DATA_BOUND "data-packet-bound" +#define SK_DATA_CONN "data-packet-conn" +#define SK_DATA_BOUND_CONN "data-packet-bound-conn" char *filename; TEST_OPTION(filename, string, "socket file name", 1); @@ -55,19 +55,15 @@ int main(int argc, char *argv[]) snprintf(path, sizeof(path), "%s/%s", dirname, filename); unlink(path); - sk_dgram_bound_client = socket(AF_UNIX, SOCK_DGRAM, 0); - sk_dgram_bound_server = socket(AF_UNIX, SOCK_DGRAM, 0); - sk_dgram_conn_client = socket(AF_UNIX, SOCK_DGRAM, 0); - sk_dgram_conn_client2 = socket(AF_UNIX, SOCK_DGRAM, 0); - sk_dgram_conn_server = socket(AF_UNIX, SOCK_DGRAM, 0); - sk_dgram_bound_conn = socket(AF_UNIX, SOCK_DGRAM, 0); - - if (sk_dgram_conn_server < 0 || - sk_dgram_bound_server < 0 || - sk_dgram_conn_client < 0 || - sk_dgram_conn_client2 < 0 || - sk_dgram_conn_server < 0 || - sk_dgram_bound_conn < 0) { + sk_dgram_bound_client = socket(AF_UNIX, SOCK_DGRAM, 0); + sk_dgram_bound_server = socket(AF_UNIX, SOCK_DGRAM, 0); + sk_dgram_conn_client = socket(AF_UNIX, SOCK_DGRAM, 0); + sk_dgram_conn_client2 = socket(AF_UNIX, SOCK_DGRAM, 0); + sk_dgram_conn_server = socket(AF_UNIX, SOCK_DGRAM, 0); + sk_dgram_bound_conn = socket(AF_UNIX, SOCK_DGRAM, 0); + + if (sk_dgram_conn_server < 0 || sk_dgram_bound_server < 0 || sk_dgram_conn_client < 0 || + sk_dgram_conn_client2 < 0 || sk_dgram_conn_server < 0 || sk_dgram_bound_conn < 0) { fail("socket"); exit(1); } @@ -94,54 +90,54 @@ int main(int argc, char *argv[]) snprintf(path, sizeof(path), "%s/%s.bound-conn", dirname, filename); unlink(path); - if (strlen(path) >= sizeof(name_bound_conn.sun_path)) { - fail("too long path"); - exit(1); - } + if (strlen(path) >= sizeof(name_bound_conn.sun_path)) { + fail("too long path"); + exit(1); + } name_bound_conn.sun_family = AF_UNIX; strncpy(name_bound_conn.sun_path, path, sizeof(name_bound_conn.sun_path)); - ret = bind(sk_dgram_bound_server, (struct sockaddr *) &name_bound, sizeof(name_bound)); + ret = bind(sk_dgram_bound_server, (struct sockaddr *)&name_bound, sizeof(name_bound)); if (ret) { fail("bind"); exit(1); } - ret = bind(sk_dgram_conn_server, (struct sockaddr *) &name_conn, sizeof(name_conn)); + ret = bind(sk_dgram_conn_server, (struct sockaddr *)&name_conn, sizeof(name_conn)); if (ret) { fail("bind"); exit(1); } - ret = connect(sk_dgram_conn_client, (struct sockaddr *) &name_conn, sizeof(name_conn)); + ret = connect(sk_dgram_conn_client, (struct sockaddr *)&name_conn, sizeof(name_conn)); if (ret) { fail("connect"); exit(1); } - ret = connect(sk_dgram_conn_client2, (struct sockaddr *) &name_conn, sizeof(name_conn)); + ret = connect(sk_dgram_conn_client2, (struct sockaddr *)&name_conn, sizeof(name_conn)); if (ret) { fail("connect"); exit(1); } - ret = bind(sk_dgram_bound_conn, (struct sockaddr *) &name_bound_conn, sizeof(name_bound_conn)); + ret = bind(sk_dgram_bound_conn, (struct sockaddr *)&name_bound_conn, sizeof(name_bound_conn)); if (ret) { fail("bind"); exit(1); } /* Note, it's already bound, so make it more idiotic! */ - ret = connect(sk_dgram_bound_conn, (struct sockaddr *) &name_bound_conn, sizeof(name_bound_conn)); + ret = connect(sk_dgram_bound_conn, (struct sockaddr *)&name_bound_conn, sizeof(name_bound_conn)); if (ret) { fail("connect"); exit(1); } memset(buf, 0, sizeof(buf)); - sendto(sk_dgram_bound_client, SK_DATA_BOUND, sizeof(SK_DATA_BOUND), 0, - (struct sockaddr *) &name_bound, sizeof(name_bound)); + sendto(sk_dgram_bound_client, SK_DATA_BOUND, sizeof(SK_DATA_BOUND), 0, (struct sockaddr *)&name_bound, + sizeof(name_bound)); read(sk_dgram_bound_server, &buf, sizeof(buf)); if (strcmp(buf, SK_DATA_BOUND)) { fail("data corrupted"); @@ -171,8 +167,8 @@ int main(int argc, char *argv[]) test_waitsig(); memset(buf, 0, sizeof(buf)); - sendto(sk_dgram_bound_client, SK_DATA_BOUND, sizeof(SK_DATA_BOUND), 0, - (struct sockaddr *) &name_bound, sizeof(name_bound)); + sendto(sk_dgram_bound_client, SK_DATA_BOUND, sizeof(SK_DATA_BOUND), 0, (struct sockaddr *)&name_bound, + sizeof(name_bound)); read(sk_dgram_bound_server, &buf, sizeof(buf)); if (strcmp(buf, SK_DATA_BOUND)) { fail("data corrupted"); diff --git a/test/zdtm/static/sockets_spair.c b/test/zdtm/static/sockets_spair.c index a67cdb312..2dbb132aa 100644 --- a/test/zdtm/static/sockets_spair.c +++ b/test/zdtm/static/sockets_spair.c @@ -13,8 +13,8 @@ #include "zdtmtst.h" -const char *test_doc = "Test unix stream socketpair\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Test unix stream socketpair\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; #define SK_DATA "packet" diff --git a/test/zdtm/static/sse00.c b/test/zdtm/static/sse00.c index c2d601948..737f40f21 100644 --- a/test/zdtm/static/sse00.c +++ b/test/zdtm/static/sse00.c @@ -3,40 +3,31 @@ #include "zdtmtst.h" -const char *test_doc = "Start a calculation, leaving SSE in a certain state,\n" - "before migration, continue after"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Start a calculation, leaving SSE in a certain state,\n" + "before migration, continue after"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; #if defined(__i386__) || defined(__x86_64__) void start(float *in) { - __asm__ volatile ( - "movaps %0, %%xmm0\n" - "movaps %1, %%xmm1\n" - "addps %%xmm0, %%xmm1\n" - "sqrtps %%xmm1, %%xmm2\n" - : - : "m" (in[0]), "m" (in[4]) - ); + __asm__ volatile("movaps %0, %%xmm0\n" + "movaps %1, %%xmm1\n" + "addps %%xmm0, %%xmm1\n" + "sqrtps %%xmm1, %%xmm2\n" + : + : "m"(in[0]), "m"(in[4])); } void finish(float *out) { - __asm__ volatile ( - "movaps %%xmm1, %0\n" - "movaps %%xmm2, %1\n" - : "=m" (out[0]), "=m" (out[4]) - ); + __asm__ volatile("movaps %%xmm1, %0\n" + "movaps %%xmm2, %1\n" + : "=m"(out[0]), "=m"(out[4])); } static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { - __asm__("cpuid" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (op), "c"(0)); + __asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(op), "c"(0)); } int chk_proc_sse(void) @@ -77,7 +68,7 @@ int main(int argc, char **argv) finish(res2); - if (memcmp((uint8_t *) res1, (uint8_t *) res2, sizeof(res1))) + if (memcmp((uint8_t *)res1, (uint8_t *)res2, sizeof(res1))) fail("results differ"); else pass(); diff --git a/test/zdtm/static/sse20.c b/test/zdtm/static/sse20.c index 1958eedfa..bfe3a37b2 100644 --- a/test/zdtm/static/sse20.c +++ b/test/zdtm/static/sse20.c @@ -3,40 +3,31 @@ #include "zdtmtst.h" -const char *test_doc = "Start a calculation, leaving SSE2 in a certain state,\n" - "before migration, continue after"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Start a calculation, leaving SSE2 in a certain state,\n" + "before migration, continue after"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; #if defined(__i386__) || defined(__x86_64__) void start(double *in) { - __asm__ volatile ( - "movapd %0, %%xmm0\n" - "movapd %1, %%xmm1\n" - "addpd %%xmm0, %%xmm1\n" - "sqrtpd %%xmm1, %%xmm2\n" - : - : "m" (in[0]), "m" (in[2]) - ); + __asm__ volatile("movapd %0, %%xmm0\n" + "movapd %1, %%xmm1\n" + "addpd %%xmm0, %%xmm1\n" + "sqrtpd %%xmm1, %%xmm2\n" + : + : "m"(in[0]), "m"(in[2])); } void finish(double *out) { - __asm__ volatile ( - "movapd %%xmm1, %0\n" - "movapd %%xmm2, %1\n" - : "=m" (out[0]), "=m" (out[2]) - ); + __asm__ volatile("movapd %%xmm1, %0\n" + "movapd %%xmm2, %1\n" + : "=m"(out[0]), "=m"(out[2])); } static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { - __asm__("cpuid" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (op), "c"(0)); + __asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(op), "c"(0)); } int chk_proc_sse2(void) @@ -77,7 +68,7 @@ int main(int argc, char **argv) finish(res2); - if (memcmp((uint8_t *) res1, (uint8_t *) res2, sizeof(res1))) + if (memcmp((uint8_t *)res1, (uint8_t *)res2, sizeof(res1))) fail("results differ"); else pass(); diff --git a/test/zdtm/static/stopped.c b/test/zdtm/static/stopped.c index 9bb849363..059a2a92a 100644 --- a/test/zdtm/static/stopped.c +++ b/test/zdtm/static/stopped.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check, that stopped tasts are restored correctly"; -const char *test_author = "Andrew Vagin <avagin@parallels.com>"; +const char *test_doc = "Check, that stopped tasts are restored correctly"; +const char *test_author = "Andrew Vagin <avagin@parallels.com>"; int main(int argc, char **argv) { @@ -66,7 +66,7 @@ int main(int argc, char **argv) if (WIFSTOPPED(status)) test_msg("The procces stopped\n"); - else{ + else { fail("The process doesn't stopped"); goto out; } diff --git a/test/zdtm/static/symlink.c b/test/zdtm/static/symlink.c index 074c80052..fb34db3a7 100644 --- a/test/zdtm/static/symlink.c +++ b/test/zdtm/static/symlink.c @@ -7,11 +7,11 @@ #include "zdtmtst.h" -#define TEST_FILE "test_file" +#define TEST_FILE "test_file" #define TEST_SYMLINK "test_symlink" -const char *test_doc = "Check open symlink preserved"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check open symlink preserved"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/tempfs.c b/test/zdtm/static/tempfs.c index 8a103be6d..e03576e2b 100644 --- a/test/zdtm/static/tempfs.c +++ b/test/zdtm/static/tempfs.c @@ -8,14 +8,14 @@ #include "zdtmtst.h" -const char *test_doc = "Check tmpfs mount"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check tmpfs mount"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_WORD "testtest" -#define TEST_WORD2 "TESTTEST" +#define TEST_WORD "testtest" +#define TEST_WORD2 "TESTTEST" int main(int argc, char **argv) { diff --git a/test/zdtm/static/tempfs_overmounted.c b/test/zdtm/static/tempfs_overmounted.c index ed329bf99..41577e19d 100644 --- a/test/zdtm/static/tempfs_overmounted.c +++ b/test/zdtm/static/tempfs_overmounted.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check tmpfs mount"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check tmpfs mount"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/tempfs_overmounted01.c b/test/zdtm/static/tempfs_overmounted01.c index 5a7250903..c0ecba5d5 100644 --- a/test/zdtm/static/tempfs_overmounted01.c +++ b/test/zdtm/static/tempfs_overmounted01.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check how file systems are dumped if some mount points are overmounted"; -const char *test_author = "Andrei Vagin <avagin@gmail.com>"; +const char *test_doc = "Check how file systems are dumped if some mount points are overmounted"; +const char *test_author = "Andrei Vagin <avagin@gmail.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); @@ -50,8 +50,7 @@ int main(int argc, char **argv) /* Create a chain when a parent mount is overmounted */ mkdir("a", 0700); mkdir("b", 0700); - if (mount("zdtm1", "a", "tmpfs", 0, "") || - mount("a", "b", NULL, MS_BIND, "")) { + if (mount("zdtm1", "a", "tmpfs", 0, "") || mount("a", "b", NULL, MS_BIND, "")) { pr_perror("Can't mount tmpfs"); return 1; } @@ -75,8 +74,7 @@ int main(int argc, char **argv) } mkdir("b/b", 0700); mkdir("b/b/z", 0700); - if (mount("b", "b/b", NULL, MS_BIND, NULL) || - mount("b/b/b", "b/b", NULL, MS_BIND, NULL)) { + if (mount("b", "b/b", NULL, MS_BIND, NULL) || mount("b/b/b", "b/b", NULL, MS_BIND, NULL)) { pr_perror("can't mount tmpfs"); return 1; } @@ -88,8 +86,7 @@ int main(int argc, char **argv) pr_perror("umount"); return 1; } - if (umount2("b/b", MNT_DETACH) || - umount2("b/b", MNT_DETACH)) { + if (umount2("b/b", MNT_DETACH) || umount2("b/b", MNT_DETACH)) { pr_perror("umount"); return 1; } diff --git a/test/zdtm/static/tempfs_ro.c b/test/zdtm/static/tempfs_ro.c index f30ae8dc5..4c823d8fd 100644 --- a/test/zdtm/static/tempfs_ro.c +++ b/test/zdtm/static/tempfs_ro.c @@ -8,13 +8,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check read-only tmpfs mount"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check read-only tmpfs mount"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_WORD "testtest" +#define TEST_WORD "testtest" int main(int argc, char **argv) { @@ -50,7 +50,6 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - fd = open(fname, O_RDONLY); if (fd < 0) { pr_perror("open failed"); diff --git a/test/zdtm/static/tempfs_ro02.c b/test/zdtm/static/tempfs_ro02.c index 7b70b866e..d313aff86 100644 --- a/test/zdtm/static/tempfs_ro02.c +++ b/test/zdtm/static/tempfs_ro02.c @@ -8,13 +8,13 @@ #include "zdtmtst.h" -const char *test_doc = "Check read-only tmpfs mount"; -const char *test_author = "Andrew Vagin <avagin@openvz.org>"; +const char *test_doc = "Check read-only tmpfs mount"; +const char *test_author = "Andrew Vagin <avagin@openvz.org>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); -#define TEST_WORD "testtest" +#define TEST_WORD "testtest" int main(int argc, char **argv) { @@ -34,7 +34,6 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - fd = open(fname, O_RDWR | O_CREAT, 0777); if (fd >= 0 || errno != EROFS) { pr_perror("open failed -> %d", fd); diff --git a/test/zdtm/static/tempfs_subns.c b/test/zdtm/static/tempfs_subns.c index 610f427d7..ed3ef9a3a 100644 --- a/test/zdtm/static/tempfs_subns.c +++ b/test/zdtm/static/tempfs_subns.c @@ -10,8 +10,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check tmpfs in a non-root mntns"; -const char *test_author = "Andrew Vagin <avagin@virtuozzo.com"; +const char *test_doc = "Check tmpfs in a non-root mntns"; +const char *test_author = "Andrew Vagin <avagin@virtuozzo.com"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/thp_disable.c b/test/zdtm/static/thp_disable.c index a809caaff..ab88120c2 100644 --- a/test/zdtm/static/thp_disable.c +++ b/test/zdtm/static/thp_disable.c @@ -4,11 +4,11 @@ #include "get_smaps_bits.h" #ifndef MADV_DONTDUMP -#define MADV_DONTDUMP 16 +#define MADV_DONTDUMP 16 #endif -const char *test_doc = "Test prctl(THP_DISABLE) behaviour"; -const char *test_author = "Mike Rapoport <rppt@linux.ibm.com>"; +const char *test_doc = "Test prctl(THP_DISABLE) behaviour"; +const char *test_author = "Mike Rapoport <rppt@linux.ibm.com>"; #define MEM_SIZE (2 << 20) @@ -20,8 +20,7 @@ int main(int argc, char **argv) test_init(argc, argv); - area = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + area = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (area == MAP_FAILED) { pr_perror("mmap failed"); return -1; diff --git a/test/zdtm/static/thread_different_uid_gid.c b/test/zdtm/static/thread_different_uid_gid.c index 4344654e7..3a0b6291b 100644 --- a/test/zdtm/static/thread_different_uid_gid.c +++ b/test/zdtm/static/thread_different_uid_gid.c @@ -15,16 +15,15 @@ #include "zdtmtst.h" -#define exit_group(code) \ - syscall(__NR_exit_group, code) +#define exit_group(code) syscall(__NR_exit_group, code) -const char *test_doc = "Acquire UID/GID setting caps, create thread and drop thread to non-root by changing UID/GID\n"; -const char *test_author = "Vitaly Ostrosablin <vostrosablin@virtuozzo.com>"; +const char *test_doc = "Acquire UID/GID setting caps, create thread and drop thread to non-root by changing UID/GID\n"; +const char *test_author = "Vitaly Ostrosablin <vostrosablin@virtuozzo.com>"; unsigned int gid; unsigned int uid; -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; task_waiter_t t; int done = 0; diff --git a/test/zdtm/static/time.c b/test/zdtm/static/time.c index d37e2a8f8..3f9c4c99b 100644 --- a/test/zdtm/static/time.c +++ b/test/zdtm/static/time.c @@ -5,16 +5,15 @@ #include "zdtmtst.h" -const char *test_doc = "Check monotonic and boot clocks"; -const char *test_author = "Andrei Vagin <avagin@gmail.com"; - +const char *test_doc = "Check monotonic and boot clocks"; +const char *test_author = "Andrei Vagin <avagin@gmail.com"; #define NSEC_PER_SEC 1000000000ULL int main(int argc, char **argv) { struct timespec tss[2], ts; - int clocks[] = {CLOCK_MONOTONIC, CLOCK_BOOTTIME}; + int clocks[] = { CLOCK_MONOTONIC, CLOCK_BOOTTIME }; unsigned long long a, b; int i; diff --git a/test/zdtm/static/timens_for_kids.c b/test/zdtm/static/timens_for_kids.c index 72543486b..7712147f7 100644 --- a/test/zdtm/static/timens_for_kids.c +++ b/test/zdtm/static/timens_for_kids.c @@ -9,12 +9,11 @@ #include "zdtmtst.h" -const char *test_doc = "Check nested time namespaces"; -const char *test_author = "Andrei Vagin <avagin@gmail.com"; - +const char *test_doc = "Check nested time namespaces"; +const char *test_author = "Andrei Vagin <avagin@gmail.com"; #ifndef CLONE_NEWTIME -#define CLONE_NEWTIME 0x00000080 +#define CLONE_NEWTIME 0x00000080 #endif int main(int argc, char **argv) @@ -26,7 +25,6 @@ int main(int argc, char **argv) return 1; } - test_daemon(); test_waitsig(); diff --git a/test/zdtm/static/timens_nested.c b/test/zdtm/static/timens_nested.c index 3f4b0e821..05214f6be 100644 --- a/test/zdtm/static/timens_nested.c +++ b/test/zdtm/static/timens_nested.c @@ -10,12 +10,11 @@ #include "zdtmtst.h" -const char *test_doc = "Check nested time namespaces"; -const char *test_author = "Andrei Vagin <avagin@gmail.com"; - +const char *test_doc = "Check nested time namespaces"; +const char *test_author = "Andrei Vagin <avagin@gmail.com"; #ifndef CLONE_NEWTIME -#define CLONE_NEWTIME 0x00000080 +#define CLONE_NEWTIME 0x00000080 #endif int main(int argc, char **argv) diff --git a/test/zdtm/static/timerfd.c b/test/zdtm/static/timerfd.c index 132c3acd8..a4ff9c73c 100644 --- a/test/zdtm/static/timerfd.c +++ b/test/zdtm/static/timerfd.c @@ -11,26 +11,21 @@ const char *test_doc = "Checks timerfd survives checkpoint/restore\n"; const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>"; -#define TIMERFD_VNSEC 50000 -#define TIMERFD_ISEC 4 +#define TIMERFD_VNSEC 50000 +#define TIMERFD_ISEC 4 struct timerfd_status { - int clockid; - uint64_t ticks; - int settime_flags; - struct itimerspec v; + int clockid; + uint64_t ticks; + int settime_flags; + struct itimerspec v; }; static void show_timerfd(char *prefix, struct timerfd_status *s) { - test_msg("\t%s clockid %d ticks %llu settime_flags %d it_value(%llu, %llu) it_interval(%llu, %llu)\n", - prefix, - s->clockid, - (unsigned long long)s->ticks, - s->settime_flags, - (unsigned long long)s->v.it_value.tv_sec, - (unsigned long long)s->v.it_value.tv_nsec, - (unsigned long long)s->v.it_interval.tv_sec, + test_msg("\t%s clockid %d ticks %llu settime_flags %d it_value(%llu, %llu) it_interval(%llu, %llu)\n", prefix, + s->clockid, (unsigned long long)s->ticks, s->settime_flags, (unsigned long long)s->v.it_value.tv_sec, + (unsigned long long)s->v.it_value.tv_nsec, (unsigned long long)s->v.it_interval.tv_sec, (unsigned long long)s->v.it_interval.tv_nsec); } @@ -58,7 +53,7 @@ static int parse_self_fdinfo(int fd, struct timerfd_status *s) */ while (fgets(buf, sizeof(buf), f)) { if (strncmp(buf, "clockid:", 8)) - continue; + continue; if (sscanf(buf, "clockid: %d", &s->clockid) != 1) goto parse_err; @@ -75,15 +70,13 @@ static int parse_self_fdinfo(int fd, struct timerfd_status *s) if (!fgets(buf, sizeof(buf), f)) goto parse_err; - if (sscanf(buf, "it_value: (%llu, %llu)", - (unsigned long long *)&s->v.it_value.tv_sec, + if (sscanf(buf, "it_value: (%llu, %llu)", (unsigned long long *)&s->v.it_value.tv_sec, (unsigned long long *)&s->v.it_value.tv_nsec) != 2) goto parse_err; if (!fgets(buf, sizeof(buf), f)) goto parse_err; - if (sscanf(buf, "it_interval: (%llu, %llu)", - (unsigned long long *)&s->v.it_interval.tv_sec, + if (sscanf(buf, "it_interval: (%llu, %llu)", (unsigned long long *)&s->v.it_interval.tv_sec, (unsigned long long *)&s->v.it_interval.tv_nsec) != 2) goto parse_err; @@ -110,11 +103,8 @@ static int check_timerfd(int fd, struct timerfd_status *old) return -1; show_timerfd("restored", &new); - if (old->clockid != new.clockid || - old->settime_flags != new.settime_flags || - old->ticks > new.ticks || - old->v.it_value.tv_sec > new.v.it_value.tv_sec || - old->v.it_interval.tv_sec != new.v.it_interval.tv_sec) + if (old->clockid != new.clockid || old->settime_flags != new.settime_flags || old->ticks > new.ticks || + old->v.it_value.tv_sec > new.v.it_value.tv_sec || old->v.it_interval.tv_sec != new.v.it_interval.tv_sec) return -1; return 0; diff --git a/test/zdtm/static/timers.c b/test/zdtm/static/timers.c index 256a5c1be..e5f7f2a02 100644 --- a/test/zdtm/static/timers.c +++ b/test/zdtm/static/timers.c @@ -11,14 +11,15 @@ static struct { const int timer_type; const int signal; volatile sig_atomic_t count; -} timer_tests[] = { /* from slowest to fastest */ - { ITIMER_VIRTUAL, SIGVTALRM }, - { ITIMER_PROF, SIGPROF }, - { ITIMER_REAL, SIGALRM }, +} timer_tests[] = { + /* from slowest to fastest */ + { ITIMER_VIRTUAL, SIGVTALRM }, + { ITIMER_PROF, SIGPROF }, + { ITIMER_REAL, SIGALRM }, }; #define NUM_TIMERS (sizeof(timer_tests) / sizeof(timer_tests[0])) -#define MAX_TIMER_COUNT 10 +#define MAX_TIMER_COUNT 10 static void timer_tick(int sig) { @@ -36,14 +37,8 @@ static void setup_timers(void) { int i; struct itimerval tv = { - .it_interval = { - .tv_sec = 0, - .tv_usec = 100000 - }, - .it_value = { - .tv_sec = 0, - .tv_usec = 100 - }, + .it_interval = { .tv_sec = 0, .tv_usec = 100000 }, + .it_value = { .tv_sec = 0, .tv_usec = 100 }, }; for (i = 0; i < NUM_TIMERS; i++) { @@ -62,14 +57,15 @@ static void setup_timers(void) static void check_timers(void) { int i; - volatile unsigned int j; /* avoid optimizing the loop away */ + volatile unsigned int j; /* avoid optimizing the loop away */ - for (i = 0; i < NUM_TIMERS; i++) /* reset counters first */ + for (i = 0; i < NUM_TIMERS; i++) /* reset counters first */ timer_tests[i].count = 0; /* waste some real and CPU time: run for MAX_TIMER_COUNT ticks or until * j overflows */ - for (j = 1; j && timer_tests[0].count < MAX_TIMER_COUNT; j++); + for (j = 1; j && timer_tests[0].count < MAX_TIMER_COUNT; j++) + ; for (i = 0; i < NUM_TIMERS; i++) if (!timer_tests[i].count) { diff --git a/test/zdtm/static/tty00.c b/test/zdtm/static/tty00.c index 473650cdd..080f8d4b0 100644 --- a/test/zdtm/static/tty00.c +++ b/test/zdtm/static/tty00.c @@ -10,8 +10,8 @@ #include <termios.h> #include <sys/ioctl.h> -const char *test_doc = "Check that a control terminal is restored"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Check that a control terminal is restored"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; static int sighup = 0; static void sighup_handler(int signo) @@ -20,7 +20,7 @@ static void sighup_handler(int signo) sighup = 1; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fdm, fds, status; task_waiter_t t; diff --git a/test/zdtm/static/tty02.c b/test/zdtm/static/tty02.c index bac0d82be..e0ff11203 100644 --- a/test/zdtm/static/tty02.c +++ b/test/zdtm/static/tty02.c @@ -9,10 +9,10 @@ #include <termios.h> #include <sys/ioctl.h> -const char *test_doc = "Check a non-controling terminal"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Check a non-controling terminal"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fdm, fds; char *slavename; diff --git a/test/zdtm/static/tty03.c b/test/zdtm/static/tty03.c index a582f1031..6abd1e61a 100644 --- a/test/zdtm/static/tty03.c +++ b/test/zdtm/static/tty03.c @@ -9,10 +9,10 @@ #include <termios.h> #include <sys/ioctl.h> -const char *test_doc = "Check a controlling terminal, if a proper fd belongs to another session leader"; -const char *test_author = "Andrey Vagin <avagin@openvz.org>"; +const char *test_doc = "Check a controlling terminal, if a proper fd belongs to another session leader"; +const char *test_author = "Andrey Vagin <avagin@openvz.org>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fdm, fds, exit_code = 1, status; task_waiter_t t; diff --git a/test/zdtm/static/tun.c b/test/zdtm/static/tun.c index f6bfeb91b..85c504c5d 100644 --- a/test/zdtm/static/tun.c +++ b/test/zdtm/static/tun.c @@ -9,19 +9,19 @@ #include "zdtmtst.h" -const char *test_doc = "Test TUN/TAP devices\n"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Test TUN/TAP devices\n"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define TUN_DEVICE "/dev/net/tun" +#define TUN_DEVICE "/dev/net/tun" #ifndef IFF_MULTI_QUEUE -#define IFF_MULTI_QUEUE 0x0100 +#define IFF_MULTI_QUEUE 0x0100 #define IFF_ATTACH_QUEUE 0x0200 #define IFF_DETACH_QUEUE 0x0400 -#define IFF_PERSIST 0x0800 +#define IFF_PERSIST 0x0800 #endif #ifndef TUNSETQUEUE -#define TUNSETQUEUE _IOW('T', 217, int) +#define TUNSETQUEUE _IOW('T', 217, int) #endif static int any_fail = 0; @@ -39,7 +39,9 @@ static int __open_tun(void) static int set_tun_queue(int fd, const char *name, unsigned flags) { - struct ifreq ifr = { .ifr_flags = flags, }; + struct ifreq ifr = { + .ifr_flags = flags, + }; if (ioctl(fd, TUNSETQUEUE, &ifr) < 0) { pr_perror("Can't set queue on %s", name); @@ -51,9 +53,11 @@ static int set_tun_queue(int fd, const char *name, unsigned flags) static int __attach_tun(int fd, const char *name, unsigned flags) { - struct ifreq ifr = { .ifr_flags = flags, }; + struct ifreq ifr = { + .ifr_flags = flags, + }; - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)-1); + strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name) - 1); if (ioctl(fd, TUNSETIFF, &ifr) < 0) { if (!(flags & IFF_TUN_EXCL)) @@ -77,7 +81,7 @@ static int open_tun(const char *name, unsigned flags) static void check_tun(int fd, const char *name, unsigned flags) { - struct ifreq ifr = { }; + struct ifreq ifr = {}; if (ioctl(fd, TUNGETIFF, &ifr) > 0) { any_fail = 1; @@ -97,7 +101,7 @@ static void check_tun(int fd, const char *name, unsigned flags) static int dev_get_hwaddr(int fd, const char *name, char *a) { - struct ifreq ifr = { }; + struct ifreq ifr = {}; if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { pr_perror("Can't get hwaddr on %s", name); @@ -225,9 +229,7 @@ int main(int argc, char **argv) pr_perror("No hwaddr for tap? (2)"); any_fail = 1; } else if (memcmp(addr, a2, sizeof(addr))) { - fail("Address mismatch on tap %x:%x -> %x:%x", - (int)addr[0], (int)addr[1], - (int)a2[0], (int)a2[1]); + fail("Address mismatch on tap %x:%x -> %x:%x", (int)addr[0], (int)addr[1], (int)a2[0], (int)a2[1]); any_fail = 1; } diff --git a/test/zdtm/static/uffd-events.c b/test/zdtm/static/uffd-events.c index 5a46d7e6d..c811bcf4c 100644 --- a/test/zdtm/static/uffd-events.c +++ b/test/zdtm/static/uffd-events.c @@ -11,11 +11,11 @@ #include <linux/limits.h> #include "zdtmtst.h" -const char *test_doc = "Test uffd events"; -const char *test_author = "Mike Rapoport <rppt@linux.vnet.ibm.com>"; +const char *test_doc = "Test uffd events"; +const char *test_author = "Mike Rapoport <rppt@linux.vnet.ibm.com>"; -#define NR_MAPS 5 -#define MAP_SIZE (1 << 20) +#define NR_MAPS 5 +#define MAP_SIZE (1 << 20) static void *map[NR_MAPS]; @@ -25,8 +25,7 @@ static int create_mappings(void) int i; for (i = 0; i < NR_MAPS; i++) { - map[i] = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + map[i] = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (map[i] == MAP_FAILED) { fail("mmap failed"); return 1; @@ -134,7 +133,7 @@ static int check_swapped_mappings(int idx) return 0; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { uint32_t crc; int pid; diff --git a/test/zdtm/static/umask00.c b/test/zdtm/static/umask00.c index 5acf5a39b..9d50b98de 100644 --- a/test/zdtm/static/umask00.c +++ b/test/zdtm/static/umask00.c @@ -2,8 +2,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that umask didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that umask didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; unsigned int mask; TEST_OPTION(mask, uint, "umask", 1); diff --git a/test/zdtm/static/unbindable.c b/test/zdtm/static/unbindable.c index 2f7b38164..6966d4181 100644 --- a/test/zdtm/static/unbindable.c +++ b/test/zdtm/static/unbindable.c @@ -6,8 +6,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check unbindable flag does not break mount restore"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check unbindable flag does not break mount restore"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/unbound_sock.c b/test/zdtm/static/unbound_sock.c index f1d610d20..98f9a710a 100644 --- a/test/zdtm/static/unbound_sock.c +++ b/test/zdtm/static/unbound_sock.c @@ -6,19 +6,19 @@ #include "zdtmtst.h" -const char *test_doc = "Create a socket before migration, and bind to it after\n"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Create a socket before migration, and bind to it after\n"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; #define TEST_PORT 59687 #define TEST_ADDR INADDR_ANY -int main(int argc, char ** argv) +int main(int argc, char **argv) { int sock; struct sockaddr_in name = { - .sin_family = AF_INET, - .sin_port = htons(TEST_PORT), - .sin_addr.s_addr = htonl(TEST_ADDR), + .sin_family = AF_INET, + .sin_port = htons(TEST_PORT), + .sin_addr.s_addr = htonl(TEST_ADDR), }; test_init(argc, argv); @@ -32,7 +32,7 @@ int main(int argc, char ** argv) test_daemon(); test_waitsig(); - if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) + if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) fail("can't bind to a socket"); else pass(); diff --git a/test/zdtm/static/unhashed_proc.c b/test/zdtm/static/unhashed_proc.c index 75fe881ce..c6c94803c 100644 --- a/test/zdtm/static/unhashed_proc.c +++ b/test/zdtm/static/unhashed_proc.c @@ -9,10 +9,10 @@ #include "zdtmtst.h" -const char *test_doc = "Chdir into unhashed proc entry"; -const char *test_author = "Konstantin Khlebnikov <khlebnikov@openvz.org>"; +const char *test_doc = "Chdir into unhashed proc entry"; +const char *test_author = "Konstantin Khlebnikov <khlebnikov@openvz.org>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int pid, len; char cwd1[PATH_MAX], cwd2[PATH_MAX]; @@ -65,7 +65,7 @@ int main(int argc, char ** argv) exit(1); } - len = readlink("/proc/self/cwd", cwd2, sizeof(cwd2)-1); + len = readlink("/proc/self/cwd", cwd2, sizeof(cwd2) - 1); if (len < 0) { fail("can't read cwd symlink"); exit(1); diff --git a/test/zdtm/static/unlink_fifo.c b/test/zdtm/static/unlink_fifo.c index ff36edacf..9cddc0f53 100644 --- a/test/zdtm/static/unlink_fifo.c +++ b/test/zdtm/static/unlink_fifo.c @@ -7,9 +7,9 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a named pipe " - "open and then unlinked"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Check that we can migrate with a named pipe " + "open and then unlinked"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); diff --git a/test/zdtm/static/unlink_fifo_wronly.c b/test/zdtm/static/unlink_fifo_wronly.c index c5c4b206e..fe4d05847 100644 --- a/test/zdtm/static/unlink_fifo_wronly.c +++ b/test/zdtm/static/unlink_fifo_wronly.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that we can migrate with a named pipe, " - "opened in WRONLY mode and then unlinked"; +const char *test_doc = "Check that we can migrate with a named pipe, " + "opened in WRONLY mode and then unlinked"; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -26,8 +26,7 @@ int main(int argc, char **argv) fd = open(filename, O_RDONLY | O_NONBLOCK); if (fd < 0) { - pr_perror("open(%s, O_RDONLY | O_NONBLOCK) Failed", - filename); + pr_perror("open(%s, O_RDONLY | O_NONBLOCK) Failed", filename); return 1; } diff --git a/test/zdtm/static/unlink_fstat00.c b/test/zdtm/static/unlink_fstat00.c index 9f8e30188..8a9841bfa 100644 --- a/test/zdtm/static/unlink_fstat00.c +++ b/test/zdtm/static/unlink_fstat00.c @@ -17,7 +17,7 @@ #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) #endif -const char *test_doc = "Open, unlink, change size, seek, migrate, check size"; +const char *test_doc = "Open, unlink, change size, seek, migrate, check size"; #ifdef UNLINK_FSTAT04 char *dirname; @@ -27,10 +27,10 @@ char *filename; TEST_OPTION(filename, string, "file name", 1); #endif -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; - size_t fsize=1000; + size_t fsize = 1000; mode_t mode; uid_t uid; gid_t gid; @@ -125,14 +125,12 @@ int main(int argc, char ** argv) /* Check file size */ if (fst.st_size != fsize) { - fail("(via fstat): file size changed to %ld", - (long)fst.st_size); + fail("(via fstat): file size changed to %ld", (long)fst.st_size); goto failed; } fst.st_size = lseek(fd, 0, SEEK_END); if (fst.st_size != fsize) { - fail("(via lseek): file size changed to %ld", - (long)fst.st_size); + fail("(via lseek): file size changed to %ld", (long)fst.st_size); goto failed; } /* Check mode */ @@ -142,8 +140,7 @@ int main(int argc, char ** argv) } /* Check uid, gid */ if (fst.st_uid != uid || fst.st_gid != gid) { - fail("u(g)id changed: uid=%d(%d), gid=%d(%d)", - fst.st_uid, uid, fst.st_gid, gid); + fail("u(g)id changed: uid=%d(%d), gid=%d(%d)", fst.st_uid, uid, fst.st_gid, gid); goto failed; } diff --git a/test/zdtm/static/unlink_fstat01.c b/test/zdtm/static/unlink_fstat01.c index 43ea6b9f6..bf2341482 100644 --- a/test/zdtm/static/unlink_fstat01.c +++ b/test/zdtm/static/unlink_fstat01.c @@ -8,15 +8,15 @@ #include "zdtmtst.h" -const char *test_doc = "Open, unlink, change size, migrate, check size"; +const char *test_doc = "Open, unlink, change size, migrate, check size"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; - size_t fsize=1000; + size_t fsize = 1000; uint8_t buf[fsize]; struct stat fst; @@ -44,15 +44,15 @@ int main(int argc, char ** argv) } #ifdef UNLINK_OVER -{ - int fdo; - - fdo = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fdo < 0) { - pr_perror("can't open %s", filename); - exit(1); + { + int fdo; + + fdo = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fdo < 0) { + pr_perror("can't open %s", filename); + exit(1); + } } -} #endif memset(buf, '0', sizeof(buf)); @@ -70,15 +70,13 @@ int main(int argc, char ** argv) } if (fst.st_size != fsize) { - fail("(via fstat): file size changed to %lld", - (long long)fst.st_size); + fail("(via fstat): file size changed to %lld", (long long)fst.st_size); goto failed; } fst.st_size = lseek(fd, 0, SEEK_END); if (fst.st_size != fsize) { - fail("(via lseek): file size changed to %lld", - (long long)fst.st_size); + fail("(via lseek): file size changed to %lld", (long long)fst.st_size); goto failed; } diff --git a/test/zdtm/static/unlink_fstat02.c b/test/zdtm/static/unlink_fstat02.c index 3d75db3e0..613e52bc8 100644 --- a/test/zdtm/static/unlink_fstat02.c +++ b/test/zdtm/static/unlink_fstat02.c @@ -8,16 +8,16 @@ #include "zdtmtst.h" -const char *test_doc = "Open, link, unlink x2, change size, migrate, check size"; +const char *test_doc = "Open, link, unlink x2, change size, migrate, check size"; char *filename; TEST_OPTION(filename, string, "file name", 1); static char link_name[1024]; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd[2]; - size_t fsize=1000; + size_t fsize = 1000; uint8_t buf[fsize]; struct stat fst, fst2; @@ -47,8 +47,7 @@ int main(int argc, char ** argv) } if (fst.st_size != 0) { - pr_perror("%s file size eq %lld", - filename, (long long)fst.st_size); + pr_perror("%s file size eq %lld", filename, (long long)fst.st_size); goto failed; } @@ -87,15 +86,13 @@ int main(int argc, char ** argv) } if (fst.st_size != fsize) { - fail("(via fstat): file size changed to %lld", - (long long)fst.st_size); + fail("(via fstat): file size changed to %lld", (long long)fst.st_size); goto failed; } fst.st_size = lseek(fd[0], 0, SEEK_END); if (fst.st_size != fsize) { - fail("(via lseek): file size changed to %lld", - (long long)fst.st_size); + fail("(via lseek): file size changed to %lld", (long long)fst.st_size); goto failed; } diff --git a/test/zdtm/static/unlink_fstat03.c b/test/zdtm/static/unlink_fstat03.c index 64d069970..b46bfc33a 100644 --- a/test/zdtm/static/unlink_fstat03.c +++ b/test/zdtm/static/unlink_fstat03.c @@ -10,16 +10,16 @@ #include "zdtmtst.h" -const char *test_doc = "Open, link, unlink former, change size, migrate, check size"; +const char *test_doc = "Open, link, unlink former, change size, migrate, check size"; char *filename; TEST_OPTION(filename, string, "file name", 1); static char link_name[1024]; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; - size_t fsize=1000; + size_t fsize = 1000; uint8_t buf[fsize]; struct stat fst, fst2; struct statfs fsst; @@ -44,8 +44,7 @@ int main(int argc, char ** argv) } if (fst.st_size != 0) { - pr_perror("%s file size eq %lld", filename, - (long long)fst.st_size); + pr_perror("%s file size eq %lld", filename, (long long)fst.st_size); goto failed; } @@ -85,15 +84,13 @@ int main(int argc, char ** argv) } if (fst2.st_size != fsize) { - fail("(via fstat): file size changed to %lld", - (long long)fst.st_size); + fail("(via fstat): file size changed to %lld", (long long)fst.st_size); goto failed; } fst2.st_size = lseek(fd, 0, SEEK_END); if (fst2.st_size != fsize) { - fail("(via lseek): file size changed to %lld", - (long long)fst.st_size); + fail("(via lseek): file size changed to %lld", (long long)fst.st_size); goto failed; } diff --git a/test/zdtm/static/unlink_largefile.c b/test/zdtm/static/unlink_largefile.c index f47391238..4baacafff 100644 --- a/test/zdtm/static/unlink_largefile.c +++ b/test/zdtm/static/unlink_largefile.c @@ -12,11 +12,11 @@ const char *test_doc = "Checkpointing/restore of big (2Gb) unlinked files"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; char buf[1000000]; - off64_t offset= 0x80002000ULL; + off64_t offset = 0x80002000ULL; size_t count; test_init(argc, argv); @@ -28,8 +28,7 @@ int main(int argc, char ** argv) } if (lseek64(fd, offset, SEEK_SET) < 0) { - pr_perror("can't lseek %s, offset= %llx", filename, - (long long unsigned)offset); + pr_perror("can't lseek %s, offset= %llx", filename, (long long unsigned)offset); goto failed; } diff --git a/test/zdtm/static/unlink_mmap00.c b/test/zdtm/static/unlink_mmap00.c index 03509aabc..405157dac 100644 --- a/test/zdtm/static/unlink_mmap00.c +++ b/test/zdtm/static/unlink_mmap00.c @@ -9,13 +9,13 @@ #include "zdtmtst.h" -const char *test_doc = "Test mmaped and unlinked files"; +const char *test_doc = "Test mmaped and unlinked files"; char *filename; TEST_OPTION(filename, string, "file name", 1); #ifndef PAGE_SIZE -#define PAGE_SIZE 4096 +#define PAGE_SIZE 4096 #endif static void touch_file_page(int fd, unsigned long off, char c) @@ -31,7 +31,7 @@ static void touch_file_page(int fd, unsigned long off, char c) } } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; char *mem_a, *mem_b; @@ -44,7 +44,6 @@ int main(int argc, char ** argv) exit(1); } - touch_file_page(fd, 0, 'a'); touch_file_page(fd, PAGE_SIZE, 'b'); touch_file_page(fd, 2 * PAGE_SIZE - 1, 'c'); /* for aligned file */ diff --git a/test/zdtm/static/unlink_mmap01.c b/test/zdtm/static/unlink_mmap01.c index 66c1bc353..d43246b79 100644 --- a/test/zdtm/static/unlink_mmap01.c +++ b/test/zdtm/static/unlink_mmap01.c @@ -11,14 +11,14 @@ #include "zdtmtst.h" -const char *test_doc = "Test mmaped and unlinked files (2, with hard links)"; +const char *test_doc = "Test mmaped and unlinked files (2, with hard links)"; char *filename; TEST_OPTION(filename, string, "file name", 1); static char linkname[4096]; #ifndef PAGE_SIZE -#define PAGE_SIZE 4096 +#define PAGE_SIZE 4096 #endif static void touch_file_page(int fd, unsigned long off, char c) @@ -34,7 +34,7 @@ static void touch_file_page(int fd, unsigned long off, char c) } } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; char *mem_a, *mem_b; @@ -48,7 +48,7 @@ int main(int argc, char ** argv) } touch_file_page(fd, 0, 'a'); - touch_file_page(fd, PAGE_SIZE - 1, 'b');/* for aligned file */ + touch_file_page(fd, PAGE_SIZE - 1, 'b'); /* for aligned file */ mem_a = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_FILE, fd, 0); if (mem_a == MAP_FAILED) { diff --git a/test/zdtm/static/unlink_mmap02.c b/test/zdtm/static/unlink_mmap02.c index 85d6b3887..a6b1841b3 100644 --- a/test/zdtm/static/unlink_mmap02.c +++ b/test/zdtm/static/unlink_mmap02.c @@ -9,13 +9,13 @@ #include "zdtmtst.h" -const char *test_doc = "Test mmaped, opened and unlinked files"; +const char *test_doc = "Test mmaped, opened and unlinked files"; char *filename; TEST_OPTION(filename, string, "file name", 1); #ifndef PAGE_SIZE -#define PAGE_SIZE 4096 +#define PAGE_SIZE 4096 #endif static void touch_file_page(int fd, unsigned long off, char c) @@ -31,7 +31,7 @@ static void touch_file_page(int fd, unsigned long off, char c) } } -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; char *mem_a, *mem_b; @@ -44,7 +44,6 @@ int main(int argc, char ** argv) exit(1); } - touch_file_page(fd, 2 * PAGE_SIZE - 1, 'c'); /* for aligned file */ /* map with different prots to create 2 regions */ diff --git a/test/zdtm/static/unlink_multiple_largefiles.c b/test/zdtm/static/unlink_multiple_largefiles.c index 2f9248c2f..e475e739f 100644 --- a/test/zdtm/static/unlink_multiple_largefiles.c +++ b/test/zdtm/static/unlink_multiple_largefiles.c @@ -12,10 +12,9 @@ #include <linux/fiemap.h> #include "zdtmtst.h" - -#define FSIZE 0x3B600000ULL -#define NFILES 10 -#define BUFSIZE (1<<20) +#define FSIZE 0x3B600000ULL +#define NFILES 10 +#define BUFSIZE (1 << 20) const char *test_doc = "C/R of ten big (951MiB) unlinked files in root dir"; const char *test_author = "Vitaly Ostrosablin <vostrosablin@virtuozzo.com>"; @@ -86,23 +85,19 @@ void check_extent_map(struct fiemap *map) test_msg("Verifying extent map...\n"); for (i = 0; i < map->fm_mapped_extents; i++) { - test_msg("Extent %d, start %llx, length %llx\n", - i, - (long long) map->fm_extents[i].fe_logical, - (long long) map->fm_extents[i].fe_length); + test_msg("Extent %d, start %llx, length %llx\n", i, (long long)map->fm_extents[i].fe_logical, + (long long)map->fm_extents[i].fe_length); if (i == 0) holesize = map->fm_extents[i].fe_logical; datasize += map->fm_extents[i].fe_length; } if (holesize != FSIZE) { - pr_err("Unexpected hole size %llx != %llx\n", - (long long) holesize, (unsigned long long) FSIZE); + pr_err("Unexpected hole size %llx != %llx\n", (long long)holesize, (unsigned long long)FSIZE); exit(1); } if (datasize != BUFSIZE) { - pr_err("Unexpected data size %llx != %llx\n", - (long long) datasize, (unsigned long long) BUFSIZE); + pr_err("Unexpected data size %llx != %llx\n", (long long)datasize, (unsigned long long)BUFSIZE); exit(1); } } @@ -207,7 +202,7 @@ failed: int main(int argc, char **argv) { - int fd[NFILES] = {0}; + int fd[NFILES] = { 0 }; char links[NFILES][PATH_MAX]; char link[PATH_MAX]; int count = 0; @@ -217,13 +212,11 @@ int main(int argc, char **argv) /* We need to create 10 unlinked files, each is around 1GB in size */ for (count = 0; count < NFILES; count++) { - test_msg("Creating unlinked file %d/%d\n", count + 1, NFILES); tempfd = create_unlinked_file(count); if (tempfd < 0) { - pr_err("Cannot create unlinked file %d/%d\n", - count + 1, NFILES); + pr_err("Cannot create unlinked file %d/%d\n", count + 1, NFILES); return 1; } @@ -248,8 +241,7 @@ int main(int argc, char **argv) read_proc_fd_link(fd[count], &link[0]); if (strcmp(&links[count][0], &link[0])) { - pr_err("Symlink target %s has changed to %s\n", - links[count], link); + pr_err("Symlink target %s has changed to %s\n", links[count], link); return 1; } diff --git a/test/zdtm/static/unlink_regular00.c b/test/zdtm/static/unlink_regular00.c index 383fabbf0..2c93c8986 100644 --- a/test/zdtm/static/unlink_regular00.c +++ b/test/zdtm/static/unlink_regular00.c @@ -11,16 +11,16 @@ #include "zdtmtst.h" const char *test_doc = "Checkpointing/restore of unlinked file inside unlinked directory"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); #define SUBDIR "subdir" -#define FNAME "testfile" -#define MSG "Hello!!!111" +#define FNAME "testfile" +#define MSG "Hello!!!111" -int main(int argc, char ** argv) +int main(int argc, char **argv) { char subdir[PATH_MAX], fname[PATH_MAX], lname[PATH_MAX]; char buf[sizeof(MSG) + 1]; @@ -88,8 +88,7 @@ int main(int argc, char ** argv) } if (strcmp(buf, MSG)) { - fail("content differs: %s, %s, sizeof=%zu", - buf, MSG, sizeof(MSG)); + fail("content differs: %s, %s, sizeof=%zu", buf, MSG, sizeof(MSG)); goto close_file; } diff --git a/test/zdtm/static/unsupported_children_collision.c b/test/zdtm/static/unsupported_children_collision.c index 15e8f3ba0..176f7080c 100644 --- a/test/zdtm/static/unsupported_children_collision.c +++ b/test/zdtm/static/unsupported_children_collision.c @@ -4,8 +4,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check unsupported children collision for mounts"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check unsupported children collision for mounts"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; char *dirname; TEST_OPTION(dirname, string, "directory name", 1); diff --git a/test/zdtm/static/uptime_grow.c b/test/zdtm/static/uptime_grow.c index ce262c4fc..5cb4b8671 100644 --- a/test/zdtm/static/uptime_grow.c +++ b/test/zdtm/static/uptime_grow.c @@ -1,15 +1,12 @@ #include "zdtmtst.h" -const char *test_doc = "test to ensure that monotonic clock doesn't decrease"; +const char *test_doc = "test to ensure that monotonic clock doesn't decrease"; const char *test_author = "Evgeny Antysev <eantyshev@parallels.com>"; #include <time.h> #include <stdlib.h> -# define tv_ge(a, b) \ - (((a)->tv_sec == (b)->tv_sec) ? \ - ((a)->tv_nsec >= (b)->tv_nsec) : \ - ((a)->tv_sec > (b)->tv_sec)) +#define tv_ge(a, b) (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec >= (b)->tv_nsec) : ((a)->tv_sec > (b)->tv_sec)) int main(int argc, char **argv) { @@ -33,8 +30,7 @@ int main(int argc, char **argv) exit(1); } if (!tv_ge(&tm, &tm_old)) { - diff_nsec = (tm_old.tv_sec - tm.tv_sec) * 1.0E9 +\ - (tm_old.tv_nsec - tm.tv_nsec); + diff_nsec = (tm_old.tv_sec - tm.tv_sec) * 1.0E9 + (tm_old.tv_nsec - tm.tv_nsec); fail("clock step backward for %e nsec", diff_nsec); exit(1); } diff --git a/test/zdtm/static/utsname.c b/test/zdtm/static/utsname.c index 964548a8f..4c96942f2 100644 --- a/test/zdtm/static/utsname.c +++ b/test/zdtm/static/utsname.c @@ -5,12 +5,12 @@ #include "zdtmtst.h" -const char *test_doc = "Check that utsname hasn't changed"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that utsname hasn't changed"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; static struct utsname after; -#define ZDTM_NODE "zdtm.nodename.ru" +#define ZDTM_NODE "zdtm.nodename.ru" #define ZDTM_DOMAIN "zdtm.nodename.ru" int main(int argc, char **argv) diff --git a/test/zdtm/static/vdso-proxy.c b/test/zdtm/static/vdso-proxy.c index f5ff21bd9..43334974f 100644 --- a/test/zdtm/static/vdso-proxy.c +++ b/test/zdtm/static/vdso-proxy.c @@ -4,17 +4,18 @@ #include "zdtmtst.h" -const char *test_doc = "Compare mappings before/after C/R for vdso/vvar presence. Should run iterative under vdso proxy fault-injection.\n"; -const char *test_author = "Dmitry Safonov <dsafonov@virtuozzo.com>"; +const char *test_doc = + "Compare mappings before/after C/R for vdso/vvar presence. Should run iterative under vdso proxy fault-injection.\n"; +const char *test_author = "Dmitry Safonov <dsafonov@virtuozzo.com>"; -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) -#define VSYSCALL_START 0xffffffffff600000ULL +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) +#define VSYSCALL_START 0xffffffffff600000ULL /* * Use constant MAX_VMAS - to minimize the risk of allocating a new * mapping or changing the size of existent VMA with realloc() */ -#define MAX_VMAS 80 -#define BUF_SIZE 1024 +#define MAX_VMAS 80 +#define BUF_SIZE 1024 /* * After C/R with vdso trampolines insertion, there should @@ -69,8 +70,7 @@ static int parse_maps(struct vm_area *vmas) #endif v->is_vvar_or_vdso |= strstr(buf, "[vdso]") != NULL; v->is_vvar_or_vdso |= strstr(buf, "[vvar]") != NULL; - test_msg("[NOTE]\tVMA: [%#" PRIx64 ", %#" PRIx64 "]\n", - v->start, v->end); + test_msg("[NOTE]\tVMA: [%#" PRIx64 ", %#" PRIx64 "]\n", v->start, v->end); } if (fclose(maps)) { @@ -110,9 +110,8 @@ static int check_vvar_vdso(struct vm_area *before, struct vm_area *after) if (cmp == 0) continue; - if (cmp < 0) {/* Lost mapping */ - test_msg("[NOTE]\tLost mapping: %#" PRIx64 "-%#" PRIx64 "\n", - before[i].start, before[i].end); + if (cmp < 0) { /* Lost mapping */ + test_msg("[NOTE]\tLost mapping: %#" PRIx64 "-%#" PRIx64 "\n", before[i].start, before[i].end); j--; if (before[i].is_vvar_or_vdso) { fail("Lost vvar/vdso mapping"); @@ -121,8 +120,7 @@ static int check_vvar_vdso(struct vm_area *before, struct vm_area *after) continue; } - test_msg("[NOTE]\tNew mapping appeared: %#" PRIx64 "-%#" PRIx64 "\n", - after[j].start, after[j].end); + test_msg("[NOTE]\tNew mapping appeared: %#" PRIx64 "-%#" PRIx64 "\n", after[j].start, after[j].end); i--; } diff --git a/test/zdtm/static/vdso00.c b/test/zdtm/static/vdso00.c index 8ac4ccad9..a9bef4dbd 100644 --- a/test/zdtm/static/vdso00.c +++ b/test/zdtm/static/vdso00.c @@ -7,8 +7,8 @@ #include <sys/types.h> #include "zdtmtst.h" -const char *test_doc = "Check if we can use vDSO after restore\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Check if we can use vDSO after restore\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; int main(int argc, char *argv[]) { diff --git a/test/zdtm/static/vdso01.c b/test/zdtm/static/vdso01.c index 269688c5e..d8d64155a 100644 --- a/test/zdtm/static/vdso01.c +++ b/test/zdtm/static/vdso01.c @@ -15,67 +15,68 @@ #include "zdtmtst.h" -const char *test_doc = "Check if we can use vDSO using direct vDSO calls\n"; -const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; +const char *test_doc = "Check if we can use vDSO using direct vDSO calls\n"; +const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org"; #ifdef __i386__ -# define Ehdr_t Elf32_Ehdr -# define Sym_t Elf32_Sym -# define Phdr_t Elf32_Phdr -# define Word_t Elf32_Word -# define Dyn_t Elf32_Dyn +#define Ehdr_t Elf32_Ehdr +#define Sym_t Elf32_Sym +#define Phdr_t Elf32_Phdr +#define Word_t Elf32_Word +#define Dyn_t Elf32_Dyn -# define ELF_ST_TYPE ELF32_ST_TYPE -# define ELF_ST_BIND ELF32_ST_BIND +#define ELF_ST_TYPE ELF32_ST_TYPE +#define ELF_ST_BIND ELF32_ST_BIND const char elf_ident[] = { - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #else /* non-i386 */ -# define Ehdr_t Elf64_Ehdr -# define Sym_t Elf64_Sym -# define Phdr_t Elf64_Phdr -# define Word_t Elf64_Word -# define Dyn_t Elf64_Dyn +#define Ehdr_t Elf64_Ehdr +#define Sym_t Elf64_Sym +#define Phdr_t Elf64_Phdr +#define Word_t Elf64_Word +#define Dyn_t Elf64_Dyn -# ifndef ELF_ST_TYPE -# define ELF_ST_TYPE ELF64_ST_TYPE -# endif -# ifndef ELF_ST_BIND -# define ELF_ST_BIND ELF64_ST_BIND -# endif +#ifndef ELF_ST_TYPE +#define ELF_ST_TYPE ELF64_ST_TYPE +#endif +#ifndef ELF_ST_BIND +#define ELF_ST_BIND ELF64_ST_BIND +#endif /* * See Elf specification for this magic values. */ const char elf_ident[] = { - 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #endif -typedef int (__vdso_clock_gettime_t)(clockid_t clock, struct timespec *ts); -typedef long (__vdso_getcpu_t)(unsigned *cpu, unsigned *node, void *unused); -typedef int (__vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz); -typedef time_t (__vdso_time_t)(time_t *t); +typedef int(__vdso_clock_gettime_t)(clockid_t clock, struct timespec *ts); +typedef long(__vdso_getcpu_t)(unsigned *cpu, unsigned *node, void *unused); +typedef int(__vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz); +typedef time_t(__vdso_time_t)(time_t *t); -#define TIME_DELTA_SEC (3) +#define TIME_DELTA_SEC (3) -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) -#define VDSO_BAD_ADDR (-1ul) +#define VDSO_BAD_ADDR (-1ul) struct vdso_symbol { - char name[32]; - unsigned long offset; + char name[32]; + unsigned long offset; }; -#define VDSO_SYMBOL_INIT { .offset = VDSO_BAD_ADDR, } +#define VDSO_SYMBOL_INIT \ + { \ + .offset = VDSO_BAD_ADDR, \ + } /* Check if symbol present in symtable */ static inline bool vdso_symbol_empty(struct vdso_symbol *s) @@ -93,26 +94,24 @@ enum { }; const char *vdso_symbols[VDSO_SYMBOL_MAX] = { - [VDSO_SYMBOL_CLOCK_GETTIME] = "__vdso_clock_gettime", - [VDSO_SYMBOL_GETCPU] = "__vdso_getcpu", - [VDSO_SYMBOL_GETTIMEOFDAY] = "__vdso_gettimeofday", - [VDSO_SYMBOL_TIME] = "__vdso_time", + [VDSO_SYMBOL_CLOCK_GETTIME] = "__vdso_clock_gettime", + [VDSO_SYMBOL_GETCPU] = "__vdso_getcpu", + [VDSO_SYMBOL_GETTIMEOFDAY] = "__vdso_gettimeofday", + [VDSO_SYMBOL_TIME] = "__vdso_time", }; struct vdso_symtable { - unsigned long vma_start; - unsigned long vma_end; - struct vdso_symbol symbols[VDSO_SYMBOL_MAX]; + unsigned long vma_start; + unsigned long vma_end; + struct vdso_symbol symbols[VDSO_SYMBOL_MAX]; }; -#define VDSO_SYMTABLE_INIT \ - { \ - .vma_start = VDSO_BAD_ADDR, \ - .vma_end = VDSO_BAD_ADDR, \ - .symbols = { \ - [0 ... VDSO_SYMBOL_MAX - 1] = \ - (struct vdso_symbol)VDSO_SYMBOL_INIT, \ - }, \ +#define VDSO_SYMTABLE_INIT \ + { \ + .vma_start = VDSO_BAD_ADDR, .vma_end = VDSO_BAD_ADDR, \ + .symbols = { \ + [0 ... VDSO_SYMBOL_MAX - 1] = (struct vdso_symbol)VDSO_SYMBOL_INIT, \ + }, \ } static bool __ptr_oob(void *ptr, void *start, size_t size) @@ -240,8 +239,7 @@ static int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t) bucket = &hash[2]; chain = &hash[nbucket + 2]; - test_msg("nbucket %lu nchain %lu bucket %p chain %p\n", - (long)nbucket, (long)nchain, bucket, chain); + test_msg("nbucket %lu nchain %lu bucket %p chain %p\n", (long)nbucket, (long)nchain, bucket, chain); for (i = 0; i < ARRAY_SIZE(vdso_symbols); i++) { k = elf_hash((const unsigned char *)vdso_symbols[i]); @@ -254,8 +252,7 @@ static int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t) if (__ptr_oob(sym, mem, size)) continue; - if (ELF_ST_TYPE(sym->st_info) != STT_FUNC && - ELF_ST_BIND(sym->st_info) != STB_GLOBAL) + if (ELF_ST_TYPE(sym->st_info) != STT_FUNC && ELF_ST_BIND(sym->st_info) != STB_GLOBAL) continue; name = &dynsymbol_names[sym->st_name]; @@ -327,8 +324,7 @@ static int vdso_clock_gettime_handler(void *func) clock_gettime(CLOCK_REALTIME, &ts1); vdso_clock_gettime(CLOCK_REALTIME, &ts2); - test_msg("clock_gettime: tv_sec %li vdso_clock_gettime: tv_sec %li\n", - ts1.tv_sec, ts2.tv_sec); + test_msg("clock_gettime: tv_sec %li vdso_clock_gettime: tv_sec %li\n", ts1.tv_sec, ts2.tv_sec); if (labs(ts1.tv_sec - ts2.tv_sec) > TIME_DELTA_SEC) { pr_perror("Delta is too big"); @@ -358,8 +354,7 @@ static int vdso_gettimeofday_handler(void *func) gettimeofday(&tv1, &tz); vdso_gettimeofday(&tv2, &tz); - test_msg("gettimeofday: tv_sec %li vdso_gettimeofday: tv_sec %li\n", - tv1.tv_sec, tv2.tv_sec); + test_msg("gettimeofday: tv_sec %li vdso_gettimeofday: tv_sec %li\n", tv1.tv_sec, tv2.tv_sec); if (labs(tv1.tv_sec - tv2.tv_sec) > TIME_DELTA_SEC) { pr_perror("Delta is too big"); @@ -389,12 +384,12 @@ static int vdso_time_handler(void *func) static int call_handlers(struct vdso_symtable *symtable) { - typedef int (handler_t)(void *func); + typedef int(handler_t)(void *func); handler_t *handlers[VDSO_SYMBOL_MAX] = { - [VDSO_SYMBOL_CLOCK_GETTIME] = vdso_clock_gettime_handler, - [VDSO_SYMBOL_GETCPU] = vdso_getcpu_handler, - [VDSO_SYMBOL_GETTIMEOFDAY] = vdso_gettimeofday_handler, - [VDSO_SYMBOL_TIME] = vdso_time_handler, + [VDSO_SYMBOL_CLOCK_GETTIME] = vdso_clock_gettime_handler, + [VDSO_SYMBOL_GETCPU] = vdso_getcpu_handler, + [VDSO_SYMBOL_GETTIMEOFDAY] = vdso_gettimeofday_handler, + [VDSO_SYMBOL_TIME] = vdso_time_handler, }; size_t i; diff --git a/test/zdtm/static/vdso02.c b/test/zdtm/static/vdso02.c index f0047bc2c..ea28c4453 100644 --- a/test/zdtm/static/vdso02.c +++ b/test/zdtm/static/vdso02.c @@ -6,10 +6,11 @@ #include "zdtmtst.h" -const char *test_doc = "Restoring task with unmapped vDSO blob. Poor man's test for C/R on vdso64_enabled=0 booted kernel.\n"; -const char *test_author = "Dmitry Safonov <dsafonov@virtuozzo.com>"; +const char *test_doc = + "Restoring task with unmapped vDSO blob. Poor man's test for C/R on vdso64_enabled=0 booted kernel.\n"; +const char *test_author = "Dmitry Safonov <dsafonov@virtuozzo.com>"; -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) #define VDSO_BAD_ADDR (-1ul) #define VVAR_BAD_ADDR (-1ul) #define BUF_SZ 1024 @@ -34,10 +35,10 @@ static int find_blobs(pid_t pid, struct vm_area *vdso, struct vm_area *vvar) int ret = -1; FILE *maps; - vdso->start = VDSO_BAD_ADDR; - vdso->end = VDSO_BAD_ADDR; - vvar->start = VVAR_BAD_ADDR; - vvar->end = VVAR_BAD_ADDR; + vdso->start = VDSO_BAD_ADDR; + vdso->end = VDSO_BAD_ADDR; + vvar->start = VVAR_BAD_ADDR; + vvar->end = VVAR_BAD_ADDR; if (snprintf(buf, BUF_SZ, "/proc/%d/maps", pid) < 0) { pr_perror("snprintf() failure for path"); @@ -73,28 +74,25 @@ err: * On i386 syscalls for speed are optimized trough vdso, * call raw int80 as vdso is unmapped. */ -#define __NR32_munmap 91 -#define __NR32_kill 37 -#define __NR32_exit 1 +#define __NR32_munmap 91 +#define __NR32_kill 37 +#define __NR32_exit 1 struct syscall_args32 { uint32_t nr, arg0, arg1; }; static inline void do_full_int80(struct syscall_args32 *args) { - asm volatile ( - "int $0x80\n\t" - : "+a" (args->nr), - "+b" (args->arg0), "+c" (args->arg1)); + asm volatile("int $0x80\n\t" : "+a"(args->nr), "+b"(args->arg0), "+c"(args->arg1)); } int sys_munmap(void *addr, size_t len) { - struct syscall_args32 s = {0}; + struct syscall_args32 s = { 0 }; - s.nr = __NR32_munmap; - s.arg0 = (uint32_t)(uintptr_t)addr; - s.arg1 = (uint32_t)len; + s.nr = __NR32_munmap; + s.arg0 = (uint32_t)(uintptr_t)addr; + s.arg1 = (uint32_t)len; do_full_int80(&s); @@ -103,11 +101,11 @@ int sys_munmap(void *addr, size_t len) int sys_kill(pid_t pid, int sig) { - struct syscall_args32 s = {0}; + struct syscall_args32 s = { 0 }; - s.nr = __NR32_kill; - s.arg0 = (uint32_t)pid; - s.arg1 = (uint32_t)sig; + s.nr = __NR32_kill; + s.arg0 = (uint32_t)pid; + s.arg1 = (uint32_t)sig; do_full_int80(&s); @@ -116,10 +114,10 @@ int sys_kill(pid_t pid, int sig) void sys_exit(int status) { - struct syscall_args32 s = {0}; + struct syscall_args32 s = { 0 }; - s.nr = __NR32_exit; - s.arg0 = (uint32_t)status; + s.nr = __NR32_exit; + s.arg0 = (uint32_t)status; do_full_int80(&s); } @@ -152,12 +150,12 @@ static int unmap_blobs(void) return -1; if (vdso.start != VDSO_BAD_ADDR) { - ret = sys_munmap((void*)vdso.start, vdso.end - vdso.start); + ret = sys_munmap((void *)vdso.start, vdso.end - vdso.start); if (ret) return ret; } if (vvar.start != VVAR_BAD_ADDR) { - ret = sys_munmap((void*)vvar.start, vvar.end - vvar.start); + ret = sys_munmap((void *)vvar.start, vvar.end - vvar.start); if (ret) return ret; } @@ -196,8 +194,7 @@ int main(int argc, char *argv[]) } else if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - pr_err("Child unexpectedly signaled with %d: %s\n", - sig, strsignal(sig)); + pr_err("Child unexpectedly signaled with %d: %s\n", sig, strsignal(sig)); goto out_kill; } else if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) { pr_err("Child is unstoppable or was stopped by other means\n"); diff --git a/test/zdtm/static/vfork00.c b/test/zdtm/static/vfork00.c index 6abc5c6ac..12dd890bc 100644 --- a/test/zdtm/static/vfork00.c +++ b/test/zdtm/static/vfork00.c @@ -9,10 +9,10 @@ #include "zdtmtst.h" -const char *test_doc = "Block migration by a pending (non-exec()-ed) vfork()"; -const char *test_author = "Pavel Emelianov <xemul@sw.ru>"; +const char *test_doc = "Block migration by a pending (non-exec()-ed) vfork()"; +const char *test_author = "Pavel Emelianov <xemul@sw.ru>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int ret = 0; pid_t pid; diff --git a/test/zdtm/static/vsx.c b/test/zdtm/static/vsx.c index e7d81b12c..3c1d669a0 100644 --- a/test/zdtm/static/vsx.c +++ b/test/zdtm/static/vsx.c @@ -30,20 +30,21 @@ int main(int argc, char *argv[]) * their content. */ -const char *test_doc = "Test if data in vector registers do survive the c/r"; -const char *test_author = "Laurent Dufour <ldufour@linux.vnet.ibm.com>"; +const char *test_doc = "Test if data in vector registers do survive the c/r"; +const char *test_author = "Laurent Dufour <ldufour@linux.vnet.ibm.com>"; int is_test_doable(void) { unsigned long val; val = getauxval(AT_HWCAP); -#define CHECK_FEATURE(f) do { \ - if (!(val & f)) { \ - test_msg("CPU feature " #f " is missing\n"); \ - return 0; \ - } \ - } while(0) +#define CHECK_FEATURE(f) \ + do { \ + if (!(val & f)) { \ + test_msg("CPU feature " #f " is missing\n"); \ + return 0; \ + } \ + } while (0) CHECK_FEATURE(PPC_FEATURE_64); CHECK_FEATURE(PPC_FEATURE_HAS_ALTIVEC); @@ -53,318 +54,315 @@ int is_test_doable(void) void fill_vsx(uint64_t *pt) { - asm volatile( - "lis 3, 0 \n" - - "lxvd2x 0, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 1, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 2, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 3, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 4, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 5, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 6, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 7, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 8, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 9, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "lxvd2x 10, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 11, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 12, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 13, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 14, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 15, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 16, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 17, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 18, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 19, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "lxvd2x 20, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 21, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 22, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 23, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 24, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 25, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 26, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 27, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 28, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 29, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "lxvd2x 30, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 31, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 32, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 33, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 34, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 35, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 36, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 37, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 38, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 39, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "lxvd2x 40, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 41, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 42, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 43, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 44, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 45, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 46, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 47, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 48, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 49, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "lxvd2x 50, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 51, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 52, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 53, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 54, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 55, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 56, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 57, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 58, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 59, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "lxvd2x 60, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 61, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 62, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "lxvd2x 63, 3, %0 \n" - : /* no output */ - : "r" (pt) - : "3"); + asm volatile("lis 3, 0 \n" + + "lxvd2x 0, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 1, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 2, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 3, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 4, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 5, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 6, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 7, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 8, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 9, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "lxvd2x 10, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 11, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 12, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 13, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 14, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 15, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 16, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 17, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 18, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 19, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "lxvd2x 20, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 21, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 22, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 23, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 24, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 25, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 26, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 27, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 28, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 29, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "lxvd2x 30, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 31, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 32, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 33, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 34, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 35, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 36, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 37, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 38, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 39, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "lxvd2x 40, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 41, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 42, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 43, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 44, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 45, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 46, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 47, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 48, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 49, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "lxvd2x 50, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 51, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 52, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 53, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 54, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 55, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 56, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 57, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 58, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 59, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "lxvd2x 60, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 61, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 62, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "lxvd2x 63, 3, %0 \n" + : /* no output */ + : "r"(pt) + : "3"); } void read_vsx(uint64_t *pt) { - asm volatile( - "lis 3, 0 \n" - - "stxvd2x 0, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 1, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 2, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 3, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 4, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 5, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 6, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 7, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 8, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 9, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "stxvd2x 10, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 11, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 12, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 13, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 14, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 15, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 16, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 17, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 18, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 19, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "stxvd2x 20, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 21, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 22, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 23, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 24, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 25, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 26, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 27, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 28, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 29, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "stxvd2x 30, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 31, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 32, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 33, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 34, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 35, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 36, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 37, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 38, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 39, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "stxvd2x 40, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 41, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 42, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 43, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 44, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 45, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 46, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 47, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 48, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 49, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "stxvd2x 50, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 51, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 52, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 53, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 54, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 55, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 56, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 57, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 58, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 59, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - - "stxvd2x 60, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 61, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 62, 3, %0 \n" - "addi 3, 3, 16 \n" /* move to the next qword */ - "stxvd2x 63, 3, %0 \n" - - : /* no output */ - : "r" (pt) - : "3"); + asm volatile("lis 3, 0 \n" + + "stxvd2x 0, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 1, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 2, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 3, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 4, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 5, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 6, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 7, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 8, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 9, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "stxvd2x 10, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 11, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 12, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 13, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 14, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 15, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 16, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 17, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 18, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 19, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "stxvd2x 20, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 21, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 22, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 23, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 24, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 25, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 26, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 27, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 28, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 29, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "stxvd2x 30, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 31, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 32, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 33, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 34, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 35, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 36, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 37, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 38, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 39, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "stxvd2x 40, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 41, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 42, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 43, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 44, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 45, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 46, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 47, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 48, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 49, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "stxvd2x 50, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 51, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 52, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 53, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 54, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 55, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 56, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 57, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 58, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 59, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + + "stxvd2x 60, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 61, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 62, 3, %0 \n" + "addi 3, 3, 16 \n" /* move to the next qword */ + "stxvd2x 63, 3, %0 \n" + + : /* no output */ + : "r"(pt) + : "3"); } int main(int argc, char *argv[]) { /* A random buffer of 1024 bytes (64 * 128bit registers to fill) */ - static const char ibuffer[128/8*64]= - "sahwoleiGun9loosliz0Aech9aiph5eiIengei7Ogh8zu7ye" - "Aeshie6vai0thaehool1ooK6ayaj3Neitahn8yeeh5ahfuiT" - "uCeir1bife4ieceema8choo2Wengaec1seDaidohteipa4ai" - "aequee7AiriejaeJar1giak8Gei2uathloh5uemaeG6EiSoo" - "PhaenaethoPhej8nEecheegeihosho8Zohroo8ea6Juuheif" - "nu2Hahvai1tuf0Zeeeveephu2EitaexiVaekieboac7Nushu" - "aeTh6Quoo3iozeisaudaGheed0aPah2Schoog0eiChaeN5su" - "xoo1phoic1mahXohSai1thoogo0oesooeaxai7eBahHahMue" - "quiloh2ooPahpiujeithae0Dau0shuwicobinaaYooj0ajiw" - "iiheeS4awoh3haevlaiGe8phaev3eiluaChaF6ieng4aith4" - "aif3TooYo1aigoomZiuhai8eesoo4maiLahr3PoM8Eir5ooz" - "Iequ9ahre4Op4bahaiso6ohnah8Shokimooch1Oafahf5aih" - "xohphee1pi5Iecaiaigh7Eisah2uew5acie7wi6Zo0Eelah9" - "woi8QueerohfeiThaBoh5jaic3peiPohAhng0bu5shoop7ca" - "Qui5kodaika8quioahmohreeVe8loquaeeLi5ze3oceiHa0l" - "roh8Ooxae7uish9ioog7ieS3aibeo2thOosiuvaiS5lohp4U" - "emieG0eit6Bien8EzaiwiTh3geighaexshee8eHiec1TooH2" - "Eeceacai0inaejieboo8NeishieweiraHooj9apeecooy0th" - "daThei6aexeisahdsei3keik0diPheejchais6ezo0iep5Ae" - "Wiqu6aepeing4ba8diek3aev9waYooveAebai9eef6Iex6vo" - "Quee9MeitahMighoHuo3seveeMoh3ohtoxaib6ootaiF5EeT" - "Ohb9eijoonoh6ich"; - char obuffer[128/8*64]; + static const char ibuffer[128 / 8 * 64] = "sahwoleiGun9loosliz0Aech9aiph5eiIengei7Ogh8zu7ye" + "Aeshie6vai0thaehool1ooK6ayaj3Neitahn8yeeh5ahfuiT" + "uCeir1bife4ieceema8choo2Wengaec1seDaidohteipa4ai" + "aequee7AiriejaeJar1giak8Gei2uathloh5uemaeG6EiSoo" + "PhaenaethoPhej8nEecheegeihosho8Zohroo8ea6Juuheif" + "nu2Hahvai1tuf0Zeeeveephu2EitaexiVaekieboac7Nushu" + "aeTh6Quoo3iozeisaudaGheed0aPah2Schoog0eiChaeN5su" + "xoo1phoic1mahXohSai1thoogo0oesooeaxai7eBahHahMue" + "quiloh2ooPahpiujeithae0Dau0shuwicobinaaYooj0ajiw" + "iiheeS4awoh3haevlaiGe8phaev3eiluaChaF6ieng4aith4" + "aif3TooYo1aigoomZiuhai8eesoo4maiLahr3PoM8Eir5ooz" + "Iequ9ahre4Op4bahaiso6ohnah8Shokimooch1Oafahf5aih" + "xohphee1pi5Iecaiaigh7Eisah2uew5acie7wi6Zo0Eelah9" + "woi8QueerohfeiThaBoh5jaic3peiPohAhng0bu5shoop7ca" + "Qui5kodaika8quioahmohreeVe8loquaeeLi5ze3oceiHa0l" + "roh8Ooxae7uish9ioog7ieS3aibeo2thOosiuvaiS5lohp4U" + "emieG0eit6Bien8EzaiwiTh3geighaexshee8eHiec1TooH2" + "Eeceacai0inaejieboo8NeishieweiraHooj9apeecooy0th" + "daThei6aexeisahdsei3keik0diPheejchais6ezo0iep5Ae" + "Wiqu6aepeing4ba8diek3aev9waYooveAebai9eef6Iex6vo" + "Quee9MeitahMighoHuo3seveeMoh3ohtoxaib6ootaiF5EeT" + "Ohb9eijoonoh6ich"; + char obuffer[128 / 8 * 64]; int do_test; test_init(argc, argv); diff --git a/test/zdtm/static/vt.c b/test/zdtm/static/vt.c index 6c96fceba..08490584a 100644 --- a/test/zdtm/static/vt.c +++ b/test/zdtm/static/vt.c @@ -9,16 +9,16 @@ #include "zdtmtst.h" -const char *test_doc = "Check c/r of a virtual terminal"; -const char *test_author = "Ruslan Kuprieiev <kupruser@gmail.com>"; +const char *test_doc = "Check c/r of a virtual terminal"; +const char *test_author = "Ruslan Kuprieiev <kupruser@gmail.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); #ifdef __s390x__ -#define MINOR 65 /* ttysclp0 */ +#define MINOR 65 /* ttysclp0 */ #else -#define MINOR 5 +#define MINOR 5 #endif int main(int argc, char **argv) @@ -53,9 +53,7 @@ int main(int argc, char **argv) } if (st1.st_rdev != st2.st_rdev) { - fail("Virtual terminal rdev mismatch %x != %x on %s", - (int)st1.st_rdev, (int)st2.st_rdev, - filename); + fail("Virtual terminal rdev mismatch %x != %x on %s", (int)st1.st_rdev, (int)st2.st_rdev, filename); return 1; } diff --git a/test/zdtm/static/wait00.c b/test/zdtm/static/wait00.c index e16cd5bd7..f2e561742 100644 --- a/test/zdtm/static/wait00.c +++ b/test/zdtm/static/wait00.c @@ -8,10 +8,10 @@ #include "zdtmtst.h" -const char *test_doc = "See if we can wait() for a child after migration"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "See if we can wait() for a child after migration"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { int ret; pid_t pid; diff --git a/test/zdtm/static/write_read00.c b/test/zdtm/static/write_read00.c index 2b7bdd4ad..86ec99c74 100644 --- a/test/zdtm/static/write_read00.c +++ b/test/zdtm/static/write_read00.c @@ -5,13 +5,13 @@ #include "zdtmtst.h" -const char *test_doc = "Write file before migration, read after"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Write file before migration, read after"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; uint32_t crc; diff --git a/test/zdtm/static/write_read01.c b/test/zdtm/static/write_read01.c index abb481117..866067c4b 100644 --- a/test/zdtm/static/write_read01.c +++ b/test/zdtm/static/write_read01.c @@ -5,13 +5,13 @@ #include "zdtmtst.h" -const char *test_doc = "Write and half way read file before migration, complete after"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Write and half way read file before migration, complete after"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd; int len; diff --git a/test/zdtm/static/write_read02.c b/test/zdtm/static/write_read02.c index 59ff4ce2f..09b9e5e6d 100644 --- a/test/zdtm/static/write_read02.c +++ b/test/zdtm/static/write_read02.c @@ -5,13 +5,13 @@ #include "zdtmtst.h" -const char *test_doc = "Write file half way before migration, complete and read after"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Write file half way before migration, complete and read after"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd, fd1; int len, full_len; diff --git a/test/zdtm/static/write_read10.c b/test/zdtm/static/write_read10.c index f4ef9bb16..fff4b8f95 100644 --- a/test/zdtm/static/write_read10.c +++ b/test/zdtm/static/write_read10.c @@ -8,15 +8,15 @@ #include "zdtmtst.h" -const char *test_doc = "Open r/w and unlink file, and fork before migration;\n" - "check that the child can write to it and the parent\n" - "can read from it after migration"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Open r/w and unlink file, and fork before migration;\n" + "check that the child can write to it and the parent\n" + "can read from it after migration"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; char *filename; TEST_OPTION(filename, string, "file name", 1); -int main(int argc, char ** argv) +int main(int argc, char **argv) { int fd, child_fd, ret; pid_t pid; @@ -51,7 +51,7 @@ int main(int argc, char ** argv) exit(1); } - if (pid == 0) { /* child writes to the unlinked file and returns */ + if (pid == 0) { /* child writes to the unlinked file and returns */ close(fd); task_waiter_complete_current(&t); test_waitsig(); @@ -109,15 +109,13 @@ int main(int argc, char ** argv) goto out; } - if (close(fd)) { fail("close failed"); goto out_noclose; } if (unlink(filename) != -1 || errno != ENOENT) { - fail("file %s should have been deleted before migration: unlink", - filename); + fail("file %s should have been deleted before migration: unlink", filename); goto out_noclose; } diff --git a/test/zdtm/static/xids00.c b/test/zdtm/static/xids00.c index 0e8f324f6..4831d9a37 100644 --- a/test/zdtm/static/xids00.c +++ b/test/zdtm/static/xids00.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that environment didn't change"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Check that environment didn't change"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; int main(int argc, char **argv) { @@ -86,8 +86,8 @@ int main(int argc, char **argv) pr_perror("Unable to wait P2 %d", pid); exit(3); } else if (!WIFEXITED(stat) || WEXITSTATUS(stat)) { - pr_perror("P2 stat %d/%d/%d/%d", WIFEXITED(stat), WEXITSTATUS(stat), - WIFSIGNALED(stat), WTERMSIG(stat)); + pr_perror("P2 stat %d/%d/%d/%d", WIFEXITED(stat), WEXITSTATUS(stat), WIFSIGNALED(stat), + WTERMSIG(stat)); exit(3); } @@ -112,8 +112,8 @@ int main(int argc, char **argv) pr_perror("Unable to wait %d", pids[i]); fail = 1; } else if (!WIFEXITED(stat) || WEXITSTATUS(stat)) { - pr_perror("P%d stat %d/%d/%d/%d", i, WIFEXITED(stat), WEXITSTATUS(stat), - WIFSIGNALED(stat), WTERMSIG(stat)); + pr_perror("P%d stat %d/%d/%d/%d", i, WIFEXITED(stat), WEXITSTATUS(stat), WIFSIGNALED(stat), + WTERMSIG(stat)); fail = 1; } } diff --git a/test/zdtm/static/zombie00.c b/test/zdtm/static/zombie00.c index def2c8892..c40efcadc 100644 --- a/test/zdtm/static/zombie00.c +++ b/test/zdtm/static/zombie00.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "See if we can wait() for a zombified child after migration"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "See if we can wait() for a zombified child after migration"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; struct zombie { int pid; @@ -17,9 +17,9 @@ struct zombie { int exitcode; }; -#define NR_ZOMBIES 4 +#define NR_ZOMBIES 4 -int main(int argc, char ** argv) +int main(int argc, char **argv) { int i, status; struct zombie zombie[NR_ZOMBIES]; @@ -56,8 +56,7 @@ int main(int argc, char ** argv) _exit(13); /* just in case */ } - test_msg("kid %d will %d/%d\n", zombie[i].pid, - zombie[i].exited, zombie[i].exitcode); + test_msg("kid %d will %d/%d\n", zombie[i].pid, zombie[i].exited, zombie[i].exitcode); } /* diff --git a/test/zdtm/static/zombie01.c b/test/zdtm/static/zombie01.c index 6e904c047..8cdb5bf4e 100644 --- a/test/zdtm/static/zombie01.c +++ b/test/zdtm/static/zombie01.c @@ -8,8 +8,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check that zombie pgid is restored"; -const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; +const char *test_doc = "Check that zombie pgid is restored"; +const char *test_author = "Kirill Tkhai <ktkhai@virtuozzo.com>"; int main(int argc, char **argv) { @@ -31,7 +31,7 @@ int main(int argc, char **argv) fail("setpgid"); exit(1); } - pid = sys_clone_unified(CLONE_PARENT|SIGCHLD, NULL, NULL, NULL, 0); + pid = sys_clone_unified(CLONE_PARENT | SIGCHLD, NULL, NULL, NULL, 0); if (pid < 0) { fail("fork"); exit(1); @@ -50,7 +50,7 @@ int main(int argc, char **argv) exit(1); } - if (waitid(P_ALL, 0, &info, WEXITED|WNOWAIT) < 0) { + if (waitid(P_ALL, 0, &info, WEXITED | WNOWAIT) < 0) { fail("waitpid"); exit(1); } @@ -58,7 +58,7 @@ int main(int argc, char **argv) test_daemon(); test_waitsig(); - if (waitid(P_ALL, 0, &info, WEXITED|WNOWAIT) < 0) { + if (waitid(P_ALL, 0, &info, WEXITED | WNOWAIT) < 0) { fail("waitpid"); exit(1); } diff --git a/test/zdtm/static/zombie_leader.c b/test/zdtm/static/zombie_leader.c index 1928687cd..e835ba689 100644 --- a/test/zdtm/static/zombie_leader.c +++ b/test/zdtm/static/zombie_leader.c @@ -7,8 +7,8 @@ #include "zdtmtst.h" -const char *test_doc = "Check non-empty session with zombie leader"; -const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; +const char *test_doc = "Check non-empty session with zombie leader"; +const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>"; int child(void) { @@ -44,8 +44,7 @@ int main(int argc, char **argv) test_init(argc, argv); - cpid = (int *)mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); + cpid = (int *)mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); *cpid = 0; pid = fork(); diff --git a/test/zdtm/transition/epoll.c b/test/zdtm/transition/epoll.c index 098eeb1fd..fdd492ab2 100644 --- a/test/zdtm/transition/epoll.c +++ b/test/zdtm/transition/epoll.c @@ -13,9 +13,9 @@ #include "zdtmtst.h" -const char *test_doc = "migrate application using epoll"; +const char *test_doc = "migrate application using epoll"; -#define MAX_SCALE 128 +#define MAX_SCALE 128 enum child_exit_codes { SUCCESS = 0, @@ -25,11 +25,7 @@ enum child_exit_codes { MAX_EXIT_CODE }; -static char *child_fail_reason[] = { - "Success", - "Can't get time", - "Can't write" -}; +static char *child_fail_reason[] = { "Success", "Can't get time", "Can't write" }; int scale = 13; TEST_OPTION(scale, int, "How many children should perform testing", 0); @@ -58,7 +54,7 @@ static void run_child(int num) { int fd = fds[num][1]; uint32_t crc = ~0; - size_t buf_size=512; + size_t buf_size = 512; uint8_t buf[buf_size]; struct timeval tv; struct timespec ts; @@ -80,15 +76,15 @@ static void run_child(int num) ts.tv_nsec = rand() % 999999999; nanosleep(&ts, &ts); if (write(fd, buf, buf_size) < 0 && - (!stop /* signal SIGUSR2 NOT received */ || - (errno != EINTR && errno != EPIPE))) { + (!stop /* signal SIGUSR2 NOT received */ || (errno != EINTR && errno != EPIPE))) { fail("child write"); rv = WRITEERROR; goto out; } } rv = SUCCESS; -out: close(fds[num][1]); +out: + close(fds[num][1]); exit(rv); } @@ -97,11 +93,9 @@ int main(int argc, char **argv) int rv, i; int counter = 0; int efd; - size_t buf_size=512; + size_t buf_size = 512; char buf[buf_size]; - struct epoll_event event = { - .events = EPOLLIN - }, *events; + struct epoll_event event = { .events = EPOLLIN }, *events; test_init(argc, argv); @@ -149,7 +143,7 @@ int main(int argc, char **argv) pids[i] = rv; } - if ((events = (struct epoll_event*) malloc (sizeof(struct epoll_event)*scale)) == NULL) { + if ((events = (struct epoll_event *)malloc(sizeof(struct epoll_event) * scale)) == NULL) { pr_perror("Can't allocate memory"); killall(); exit(1); @@ -164,7 +158,8 @@ int main(int argc, char **argv) exit(1); } for (i = 0; i < rv; i++) { - while (read(events[i].data.fd, buf, buf_size) > 0); + while (read(events[i].data.fd, buf, buf_size) > 0) + ; if (errno != EAGAIN && errno != 0 && errno) { pr_perror("read error"); killall(); @@ -184,8 +179,7 @@ int main(int argc, char **argv) } else { rv = WEXITSTATUS(rv); if (rv < MAX_EXIT_CODE && rv > SUCCESS) { - fail("Child failed: %s (%d)", - child_fail_reason[rv], rv); + fail("Child failed: %s (%d)", child_fail_reason[rv], rv); counter++; } else if (rv != SUCCESS) { fail("Unknown exitcode from child: %d", rv); diff --git a/test/zdtm/transition/fifo_dyn.c b/test/zdtm/transition/fifo_dyn.c index d72e1e6cd..09f337536 100644 --- a/test/zdtm/transition/fifo_dyn.c +++ b/test/zdtm/transition/fifo_dyn.c @@ -12,10 +12,10 @@ #include "zdtmtst.h" -const char *test_doc = "dynamic FIFO test"; +const char *test_doc = "dynamic FIFO test"; -#define PROCS_DEF 2 /* 0 - parent, 1 - child */ -#define BUF_SIZE 256 +#define PROCS_DEF 2 /* 0 - parent, 1 - child */ +#define BUF_SIZE 256 unsigned int num_procs = PROCS_DEF; char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -70,8 +70,7 @@ int main(int argc, char **argv) if (pipe_in2out(readfd, writefd, buf, sizeof(buf)) < 0) /* pass errno as exit code to the parent */ - if (test_go() /* signal NOT delivered */ || - (errno != EINTR && errno != EPIPE)) + if (test_go() /* signal NOT delivered */ || (errno != EINTR && errno != EPIPE)) ret = errno; close(readfd); close(writefd); @@ -138,8 +137,7 @@ int main(int argc, char **argv) wait(&chret); chret = WEXITSTATUS(chret); if (chret) { - fail("child exited with non-zero code %d (%s)", - chret, strerror(chret)); + fail("child exited with non-zero code %d (%s)", chret, strerror(chret)); return 1; } if (!ret) diff --git a/test/zdtm/transition/fifo_loop.c b/test/zdtm/transition/fifo_loop.c index 51f93f645..a8f5e79be 100644 --- a/test/zdtm/transition/fifo_loop.c +++ b/test/zdtm/transition/fifo_loop.c @@ -12,12 +12,14 @@ #include "zdtmtst.h" -const char *test_doc = "Multi-process fifo loop"; -#define BUF_SIZE 256 -#define PROCS_DEF 4 +const char *test_doc = "Multi-process fifo loop"; +#define BUF_SIZE 256 +#define PROCS_DEF 4 unsigned int num_procs = PROCS_DEF; -TEST_OPTION(num_procs, uint, "# processes to create " - "(default " __stringify(PROCS_DEF) ")", 0); +TEST_OPTION(num_procs, uint, + "# processes to create " + "(default " __stringify(PROCS_DEF) ")", + 0); char *filename; TEST_OPTION(filename, string, "file name", 1); @@ -60,7 +62,7 @@ int main(int argc, char **argv) exit(1); } - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ pid = test_fork(); if (pid < 0) { pr_perror("Can't fork"); @@ -71,16 +73,14 @@ int main(int argc, char **argv) file_path = path[i - 1]; readfd = open(file_path, O_RDONLY); if (readfd < 0) { - pr_perror("open(%s, O_RDONLY) failed", - file_path); + pr_perror("open(%s, O_RDONLY) failed", file_path); ret = errno; return ret; } file_path = path[i]; writefd = open(file_path, O_WRONLY); if (writefd < 0) { - pr_perror("open(%s, O_WRONLY) failed", - file_path); + pr_perror("open(%s, O_WRONLY) failed", file_path); ret = errno; return ret; } @@ -95,8 +95,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); if (pipe_in2out(readfd, writefd, buf, sizeof(buf)) < 0) /* pass errno as exit code to the parent */ - if (test_go() /* signal NOT delivered */ || - (errno != EINTR && errno != EPIPE)) + if (test_go() /* signal NOT delivered */ || (errno != EINTR && errno != EPIPE)) ret = errno; close(readfd); close(writefd); @@ -181,11 +180,11 @@ int main(int argc, char **argv) if (kill(0, SIGTERM)) { fail("failed to send SIGTERM to my process group"); - return 1; /* shouldn't wait() in this case */ + return 1; /* shouldn't wait() in this case */ } close(readfd); - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ int chret; if (waitpid(pids[i], &chret, 0) < 0) { fail("waitpid error"); @@ -195,8 +194,7 @@ int main(int argc, char **argv) chret = WEXITSTATUS(chret); if (chret) { - fail("child %d exited with non-zero code %d (%s)", - i, chret, strerror(chret)); + fail("child %d exited with non-zero code %d (%s)", i, chret, strerror(chret)); ret = 1; continue; } diff --git a/test/zdtm/transition/file_aio.c b/test/zdtm/transition/file_aio.c index 4a76c9390..74146c918 100644 --- a/test/zdtm/transition/file_aio.c +++ b/test/zdtm/transition/file_aio.c @@ -1,6 +1,6 @@ #include "zdtmtst.h" -const char *test_doc = "test for AIO"; +const char *test_doc = "test for AIO"; const char *test_author = "Andrew Vagin <avagin@parallels.com>"; #include <stdio.h> @@ -20,8 +20,8 @@ int main(int argc, char **argv) char buf[BUF_SIZE]; int fd; struct aiocb aiocb; - const struct aiocb *aioary[1]; - char tmpfname[256]="/tmp/file_aio.XXXXXX"; + const struct aiocb *aioary[1]; + char tmpfname[256] = "/tmp/file_aio.XXXXXX"; int ret; test_init(argc, argv); @@ -62,10 +62,10 @@ int main(int argc, char **argv) } /* Wait for request completion */ aioary[0] = &aiocb; -again: + again: ret = aio_suspend(aioary, 1, NULL); if (ret < 0) { - if ((errno == EINTR) && (! test_go())) + if ((errno == EINTR) && (!test_go())) break; if (errno != EINTR) { pr_perror("aio_suspend failed"); diff --git a/test/zdtm/transition/file_read.c b/test/zdtm/transition/file_read.c index 9b5670c65..7729e9f61 100644 --- a/test/zdtm/transition/file_read.c +++ b/test/zdtm/transition/file_read.c @@ -11,12 +11,12 @@ #include "zdtmtst.h" -const char *test_doc = "Fill/read file continuously to check" - "it's migrated at the right moment"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Fill/read file continuously to check" + "it's migrated at the right moment"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define MAX_SCALE 128 -#define FILE_SIZE (16 * 1024) +#define MAX_SCALE 128 +#define FILE_SIZE (16 * 1024) enum kids_exit_codes { SUCCESS = 0, @@ -31,16 +31,14 @@ enum kids_exit_codes { MAX_EXIT_CODE_VAL }; -static char *kids_fail_reasons[] = { - "Success", - /* 1 */ "File corrupted", - /* 2 */ "Map failed", - /* 3 */ "Open (create) failed", - /* 4 */ "Write failed", - /* 5 */ "Read failed", - /* 6 */ "Fsync failed", - /* 7 */ "Lseek failed" -}; +static char *kids_fail_reasons[] = { "Success", + /* 1 */ "File corrupted", + /* 2 */ "Map failed", + /* 3 */ "Open (create) failed", + /* 4 */ "Write failed", + /* 5 */ "Read failed", + /* 6 */ "Fsync failed", + /* 7 */ "Lseek failed" }; int scale = 13; TEST_OPTION(scale, int, "How many children should perform testing", 0); @@ -120,8 +118,7 @@ static void chew_some_file(int num) int fd, rv; char chew_file[PATH_MAX]; - buf = mmap(NULL, FILE_SIZE, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + buf = mmap(NULL, FILE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); rv = MMAP_FAILED; if (buf == MAP_FAILED) goto out_exit; @@ -157,8 +154,7 @@ static void chew_some_file(int num) case -2: rv = SEEK_FAILED; goto out_exit; - case 1: - { + case 1: { int fd1; char str[PATH_MAX]; @@ -170,7 +166,7 @@ static void chew_some_file(int num) pr_perror("can't write %s", str); close(fd1); goto out_exit; - } + } } } rv = SUCCESS; @@ -227,8 +223,7 @@ int main(int argc, char **argv) } else { rv = WEXITSTATUS(rv); if (rv < MAX_EXIT_CODE_VAL && rv > SUCCESS) { - fail("Kid failed: %s (%d)", - kids_fail_reasons[rv], rv); + fail("Kid failed: %s (%d)", kids_fail_reasons[rv], rv); counter++; } else if (rv != SUCCESS) { fail("Unknown exitcode from kid: %d", rv); diff --git a/test/zdtm/transition/fork.c b/test/zdtm/transition/fork.c index 9ab160599..4f0049a29 100644 --- a/test/zdtm/transition/fork.c +++ b/test/zdtm/transition/fork.c @@ -86,7 +86,6 @@ int main(int argc, char **argv) goto out; } } - } pass(); out: diff --git a/test/zdtm/transition/ipc.c b/test/zdtm/transition/ipc.c index be52d7396..0f16dbc68 100644 --- a/test/zdtm/transition/ipc.c +++ b/test/zdtm/transition/ipc.c @@ -14,8 +14,8 @@ #include "zdtmtst.h" -const char *test_doc="Tests ipc sems and shmems migrate fine"; -const char *test_author="Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Tests ipc sems and shmems migrate fine"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; static struct sembuf unlock = { .sem_op = 1, @@ -29,13 +29,13 @@ static struct sembuf lock = { .sem_flg = 0, }; -#define DEF_MEM_SIZE (40960) +#define DEF_MEM_SIZE (40960) unsigned int shmem_size = DEF_MEM_SIZE; TEST_OPTION(shmem_size, uint, "Size of shared memory segment", 0); -#define INIT_CRC (~0) +#define INIT_CRC (~0) -#define POISON 0xac +#define POISON 0xac static inline void poison_area(int *mem) { memset(mem, POISON, shmem_size); @@ -68,7 +68,8 @@ static int child(key_t key) } crc = INIT_CRC; datagen(mem, shmem_size, &crc); - while ((ret = semop(sem, &unlock, 1)) && (errno == EINTR)); + while ((ret = semop(sem, &unlock, 1)) && (errno == EINTR)) + ; if (ret) { fail("Error in semop unlock"); res = errno; @@ -97,7 +98,7 @@ int main(int argc, char **argv) } sem = semget(key, 1, 0777 | IPC_CREAT | IPC_EXCL); - if (sem == -1) { + if (sem == -1) { pr_perror("Can't get sem"); goto out; } @@ -154,13 +155,14 @@ int main(int argc, char **argv) if (datachk(mem, shmem_size, &crc)) { fail_count++; fail("Semaphore protection is broken or " - "shmem pages are messed"); + "shmem pages are messed"); semop(sem, &unlock, 1); break; } poison_area((int *)mem); } - while ((ret = semop(sem, &unlock, 1)) && (errno == EINTR)); + while ((ret = semop(sem, &unlock, 1)) && (errno == EINTR)) + ; if (ret) { fail_count++; fail("Error in semop unlock"); diff --git a/test/zdtm/transition/lazy-thp.c b/test/zdtm/transition/lazy-thp.c index 01075d773..2bf99dc4c 100644 --- a/test/zdtm/transition/lazy-thp.c +++ b/test/zdtm/transition/lazy-thp.c @@ -13,12 +13,12 @@ #define N_PAGES 1024 -const char *test_doc = "Test interaction between THP and lazy-pages"; +const char *test_doc = "Test interaction between THP and lazy-pages"; /* The test is based on example by Adrian Reber <areber@redhat.com> */ -const char *test_author = "Mike Rapoport <rppt@linux.vnet.ibm.com>"; +const char *test_author = "Mike Rapoport <rppt@linux.vnet.ibm.com>"; -int main(int argc, char ** argv) +int main(int argc, char **argv) { char *mem, *org, *m; int count; @@ -44,7 +44,7 @@ int main(int argc, char ** argv) } for (count = 0; count < N_PAGES; count++) { - m = mem+(count*PAGE_SIZE); + m = mem + (count * PAGE_SIZE); org[128] = (count % 2 == 0) ? count : 0x42; if (memcmp(org, m, PAGE_SIZE)) { diff --git a/test/zdtm/transition/maps007.c b/test/zdtm/transition/maps007.c index ee5e7c7f7..8a605cfe0 100644 --- a/test/zdtm/transition/maps007.c +++ b/test/zdtm/transition/maps007.c @@ -15,12 +15,12 @@ #define MAP_SIZE (1UL << 20) #define MEM_SIZE (1UL << 29) -const char *test_doc = "create random mappings and touch memory"; +const char *test_doc = "create random mappings and touch memory"; int sys_process_vm_readv(pid_t pid, void *addr, void *buf, int size) { - struct iovec lvec = {.iov_base = buf, .iov_len = size }; - struct iovec rvec = {.iov_base = addr, .iov_len = size }; + struct iovec lvec = { .iov_base = buf, .iov_len = size }; + struct iovec rvec = { .iov_base = addr, .iov_len = size }; /* workaround bug in glibc with sixth argument of syscall */ char nop[PAGE_SIZE]; @@ -38,7 +38,7 @@ int main(int argc, char **argv) struct { futex_t delta; futex_t stop; - } *shm; + } * shm; uint32_t v; unsigned long long count = 0; int i; @@ -84,8 +84,7 @@ int main(int argc, char **argv) /* shm->delta must be always bigger than MAX_DELTA */ futex_wait_while_lt(&shm->delta, MAX_DELTA + 2); else if (count % 100 == 0) - test_msg("count %llu delta %d\n", - count, futex_get(&shm->delta)); /* heartbeat */ + test_msg("count %llu delta %d\n", count, futex_get(&shm->delta)); /* heartbeat */ if (futex_get(&shm->stop) && atomic_get(&shm->delta.raw) == MAX_DELTA) break; @@ -173,6 +172,6 @@ int main(int argc, char **argv) return 0; err: kill(child, SIGSEGV); - *((volatile int *) 0) = 0; + *((volatile int *)0) = 0; return 1; } diff --git a/test/zdtm/transition/maps008.c b/test/zdtm/transition/maps008.c index 851814c11..e5aa236ef 100644 --- a/test/zdtm/transition/maps008.c +++ b/test/zdtm/transition/maps008.c @@ -62,8 +62,7 @@ static void cont_and_wait_child(pid_t pid) static void *mmap_ashmem(size_t size) { - void *mem = mmap(NULL, size, PROT_WRITE | PROT_READ, - MAP_SHARED | MAP_ANONYMOUS, -1, 0); + void *mem = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (mem == MAP_FAILED) { pr_perror("Can't map shmem %zx", size); exit(1); @@ -71,15 +70,13 @@ static void *mmap_ashmem(size_t size) return mem; } -static void *mmap_proc_mem(pid_t pid, unsigned long addr, - unsigned long size) +static void *mmap_proc_mem(pid_t pid, unsigned long addr, unsigned long size) { int fd; void *mem; char path[PATH_MAX]; - snprintf(path, PATH_MAX, "/proc/%d/map_files/%lx-%lx", - (int)pid, addr, addr + size); + snprintf(path, PATH_MAX, "/proc/%d/map_files/%lx-%lx", (int)pid, addr, addr + size); fd = open(path, O_RDWR); if (fd == -1) { pr_perror("Can't open file %s", path); @@ -100,8 +97,7 @@ static void check_mem_eq(void *addr1, size_t size1, void *addr2, size_t size2) unsigned long min_size = size1 < size2 ? size1 : size2; if (memcmp(addr1, addr2, min_size)) { - pr_err("Mem differs %lx %lx %lx", (unsigned long)addr1, - (unsigned long)addr2, min_size); + pr_err("Mem differs %lx %lx %lx\n", (unsigned long)addr1, (unsigned long)addr2, min_size); exit(1); } } @@ -114,8 +110,7 @@ static void xmunmap(void *map, size_t size) } } -static void chk_proc_mem_eq(pid_t pid1, void *addr1, unsigned long size1, - pid_t pid2, void *addr2, unsigned long size2) +static void chk_proc_mem_eq(pid_t pid1, void *addr1, unsigned long size1, pid_t pid2, void *addr2, unsigned long size2) { void *map1, *map2; @@ -136,14 +131,14 @@ static void chk_proc_mem_eq(pid_t pid1, void *addr1, unsigned long size1, */ #define PROC_CNT 7 -#define PROC1_PGIX 0 -#define PROC11_PGIX 1 -#define PROC12_PGIX 2 -#define PROC13_PGIX 3 +#define PROC1_PGIX 0 +#define PROC11_PGIX 1 +#define PROC12_PGIX 2 +#define PROC13_PGIX 3 #define PROC111_PGIX 4 #define PROC112_PGIX 5 #define PROC131_PGIX 6 -#define ZERO_PGIX 7 +#define ZERO_PGIX 7 /* unused pgix: 8 */ #define MEM_PERIOD (9 * PAGE_SIZE) @@ -278,12 +273,9 @@ static int proc13_func(task_waiter_t *setup_waiter) mems_datachck_each_pgix(PROC13_PGIX); - chk_proc_mem_eq(pstree->proc13, mem1, mem1_size, - pstree->proc131, mem1, mem1_size); - chk_proc_mem_eq(pstree->proc13, mem2, mem2_size, - pstree->proc131, mem2, mem2_size); - chk_proc_mem_eq(pstree->proc13, mem3, mem3_size, - pstree->proc131, mem3, mem3_size); + chk_proc_mem_eq(pstree->proc13, mem1, mem1_size, pstree->proc131, mem1, mem1_size); + chk_proc_mem_eq(pstree->proc13, mem2, mem2_size, pstree->proc131, mem2, mem2_size); + chk_proc_mem_eq(pstree->proc13, mem3, mem3_size, pstree->proc131, mem3, mem3_size); cont_and_wait_child(pstree->proc131); return 0; @@ -368,23 +360,16 @@ static int proc11_func(task_waiter_t *setup_waiter) mems_datachck_each_pgix(PROC11_PGIX); - chk_proc_mem_eq(pstree->proc11, mem1, mem1_size, - pstree->proc111, mem1, mem1_size); - chk_proc_mem_eq(pstree->proc11, mem1, mem1_size, - pstree->proc112, mem1, mem1_size); + chk_proc_mem_eq(pstree->proc11, mem1, mem1_size, pstree->proc111, mem1, mem1_size); + chk_proc_mem_eq(pstree->proc11, mem1, mem1_size, pstree->proc112, mem1, mem1_size); - chk_proc_mem_eq(pstree->proc11, mem2, mem2_size, - pstree->proc111, mem2, mem2_size); - chk_proc_mem_eq(pstree->proc11, mem2, mem2_size, - pstree->proc112, mem2, mem2_size); + chk_proc_mem_eq(pstree->proc11, mem2, mem2_size, pstree->proc111, mem2, mem2_size); + chk_proc_mem_eq(pstree->proc11, mem2, mem2_size, pstree->proc112, mem2, mem2_size); - chk_proc_mem_eq(pstree->proc11, mem3, mem3_size, - pstree->proc111, mem3, mem3_size + MEM3_END_CUT); - chk_proc_mem_eq(pstree->proc11, mem3, mem3_size, - pstree->proc112, mem3, mem3_size + MEM3_END_CUT); + chk_proc_mem_eq(pstree->proc11, mem3, mem3_size, pstree->proc111, mem3, mem3_size + MEM3_END_CUT); + chk_proc_mem_eq(pstree->proc11, mem3, mem3_size, pstree->proc112, mem3, mem3_size + MEM3_END_CUT); - proc1_mem3 = mmap_proc_mem(pstree->proc1, - (unsigned long)mem3_old, mem3_size_old); + proc1_mem3 = mmap_proc_mem(pstree->proc1, (unsigned long)mem3_old, mem3_size_old); check_mem_eq(mem3, mem3_size, proc1_mem3 + MEM3_START_CUT, mem3_size); xmunmap(proc1_mem3, mem3_size_old); @@ -394,7 +379,7 @@ static int proc11_func(task_waiter_t *setup_waiter) } #define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MB(n) ((n) * (1UL << 20)) +#define MB(n) ((n) * (1UL << 20)) static int proc1_func(void) { @@ -423,8 +408,7 @@ static int proc1_func(void) fork_and_setup(proc13_func); xmunmap(mem1, mem1_size); - if (mremap(mem2, mem2_size, mem1_size, MREMAP_MAYMOVE | MREMAP_FIXED, - mem1) != mem1) { + if (mremap(mem2, mem2_size, mem1_size, MREMAP_MAYMOVE | MREMAP_FIXED, mem1) != mem1) { pr_perror("proc1 mem2 remap"); exit(1); } @@ -441,13 +425,10 @@ static int proc1_func(void) mems_datachck_each_pgix(PROC1_PGIX); - chk_proc_mem_eq(pstree->proc1, mem1, mem1_size, - pstree->proc11, mem2_old, mem2_size); - chk_proc_mem_eq(pstree->proc1, mem1, mem1_size, - pstree->proc12, mem2_old, mem2_size); + chk_proc_mem_eq(pstree->proc1, mem1, mem1_size, pstree->proc11, mem2_old, mem2_size); + chk_proc_mem_eq(pstree->proc1, mem1, mem1_size, pstree->proc12, mem2_old, mem2_size); - chk_proc_mem_eq(pstree->proc1, mem3, mem3_size, - pstree->proc12, mem3, mem3_size); + chk_proc_mem_eq(pstree->proc1, mem3, mem3_size, pstree->proc12, mem3, mem3_size); cont_and_wait_child(pstree->proc11); cont_and_wait_child(pstree->proc12); @@ -490,10 +471,7 @@ static void sigchld_hand(int signo, siginfo_t *info, void *ucontext) int main(int argc, char **argv) { - struct sigaction sa = { - .sa_sigaction = sigchld_hand, - .sa_flags = SA_RESTART | SA_SIGINFO | SA_NOCLDSTOP - }; + struct sigaction sa = { .sa_sigaction = sigchld_hand, .sa_flags = SA_RESTART | SA_SIGINFO | SA_NOCLDSTOP }; sigemptyset(&sa.sa_mask); test_init(argc, argv); diff --git a/test/zdtm/transition/netlink00.c b/test/zdtm/transition/netlink00.c index 8e7d33c95..2bc4aebd3 100644 --- a/test/zdtm/transition/netlink00.c +++ b/test/zdtm/transition/netlink00.c @@ -25,14 +25,14 @@ #undef DEBUG //#define DEBUG -const char *test_doc = "Netlink socket loop"; +const char *test_doc = "Netlink socket loop"; const char *test_author = "Andrew Vagin (avagin@parallels.com)"; //buffer to hold the RTNETLINK request struct { - struct nlmsghdr nl; - struct rtmsg rt; - char buf[8192]; + struct nlmsghdr nl; + struct rtmsg rt; + char buf[8192]; } req; // variables used for @@ -46,7 +46,7 @@ int rtn; // buffer to hold the RTNETLINK reply(ies) char buf[8192]; char dsts[24] = "192.168.0.255"; -int pn = 32;//network prefix +int pn = 32; //network prefix // RTNETLINK message pointers & lengths // used when processing messages @@ -63,8 +63,7 @@ int form_request_del(void); int read_reply(void); typedef int (*cmd_t)(void); #define CMD_NUM 2 -cmd_t cmd[CMD_NUM]={form_request_add, form_request_del}; - +cmd_t cmd[CMD_NUM] = { form_request_add, form_request_del }; int main(int argc, char *argv[]) { @@ -73,7 +72,7 @@ int main(int argc, char *argv[]) test_init(argc, argv); fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - if (fd<0){ + if (fd < 0) { pr_perror("socket"); goto out; } @@ -82,7 +81,7 @@ int main(int argc, char *argv[]) bzero(&la, sizeof(la)); la.nl_family = AF_NETLINK; la.nl_pid = getpid(); - if (bind(fd, (struct sockaddr*) &la, sizeof(la))){ + if (bind(fd, (struct sockaddr *)&la, sizeof(la))) { pr_perror("bind failed"); goto out; } @@ -93,20 +92,20 @@ int main(int argc, char *argv[]) test_daemon(); - while (test_go()){ - for (i=0; i < CMD_NUM; i++){ + while (test_go()) { + for (i = 0; i < CMD_NUM; i++) { cmd[i](); - if (send_request() < 0){ + if (send_request() < 0) { fail("send_request failed"); goto out; }; - if (recv_reply() < 0){ + if (recv_reply() < 0) { fail("RTNETLINK answers"); goto out; }; #ifdef DEBUG - if (read_reply() < 0){ + if (read_reply() < 0) { fail("read_reply failed"); goto out; } @@ -129,17 +128,17 @@ int send_request(void) // initialize & create the struct msghdr supplied // to the sendmsg() function bzero(&msg, sizeof(msg)); - msg.msg_name = (void *) &pa; + msg.msg_name = (void *)&pa; msg.msg_namelen = sizeof(pa); // place the pointer & size of the RTNETLINK // message in the struct msghdr - iov.iov_base = (void *) &req.nl; + iov.iov_base = (void *)&req.nl; iov.iov_len = req.nl.nlmsg_len; msg.msg_iov = &iov; msg.msg_iovlen = 1; // send the RTNETLINK message to kernel rtn = sendmsg(fd, &msg, 0); - if (rtn<0){ + if (rtn < 0) { pr_perror("sendmsg failed"); return -1; } @@ -155,7 +154,7 @@ int recv_reply(void) // read from the socket until the NLMSG_DONE is // returned in the type of the RTNETLINK message // or if it was a monitoring socket - while(1) { + while (1) { rtn = recv(fd, p, sizeof(buf) - nll, 0); if (rtn < 0) { pr_perror("recv failed"); @@ -167,12 +166,12 @@ int recv_reply(void) return -1; } - nlp = (struct nlmsghdr *) p; - if(nlp->nlmsg_type == NLMSG_DONE) + nlp = (struct nlmsghdr *)p; + if (nlp->nlmsg_type == NLMSG_DONE) return 0; if (nlp->nlmsg_type == NLMSG_ERROR) { - struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(nlp); - errno=-err->error; + struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nlp); + errno = -err->error; if (errno) { return -1; } @@ -184,8 +183,7 @@ int recv_reply(void) // increment the total size by the size of // the last received message nll += rtn; - if((la.nl_groups & RTMGRP_IPV4_ROUTE) - == RTMGRP_IPV4_ROUTE) + if ((la.nl_groups & RTMGRP_IPV4_ROUTE) == RTMGRP_IPV4_ROUTE) break; } return 0; @@ -199,14 +197,13 @@ int read_reply(void) // outer loop: loops thru all the NETLINK // headers that also include the route entry // header - nlp = (struct nlmsghdr *) buf; - for(; NLMSG_OK(nlp, nll); nlp = NLMSG_NEXT(nlp, nll)) - { + nlp = (struct nlmsghdr *)buf; + for (; NLMSG_OK(nlp, nll); nlp = NLMSG_NEXT(nlp, nll)) { // get route entry header - rtp = (struct rtmsg *) NLMSG_DATA(nlp); + rtp = (struct rtmsg *)NLMSG_DATA(nlp); // we are only concerned about the // main route table - if(rtp->rtm_table != RT_TABLE_MAIN) + if (rtp->rtm_table != RT_TABLE_MAIN) continue; // init all the strings bzero(dsts, sizeof(dsts)); @@ -215,40 +212,33 @@ int read_reply(void) bzero(ms, sizeof(ms)); // inner loop: loop thru all the attributes of // one route entry - rtap = (struct rtattr *) RTM_RTA(rtp); + rtap = (struct rtattr *)RTM_RTA(rtp); rtl = RTM_PAYLOAD(nlp); - for( ; RTA_OK(rtap, rtl); rtap = RTA_NEXT(rtap,rtl)) - { - switch(rtap->rta_type) - { - // destination IPv4 address - case RTA_DST: - inet_ntop(AF_INET, RTA_DATA(rtap), - dsts, 24); - break; - // next hop IPv4 address - case RTA_GATEWAY: - inet_ntop(AF_INET, RTA_DATA(rtap), - gws, 24); - break; - // unique ID associated with the network - // interface - case RTA_OIF: - sprintf(ifs, "%d", - *((int *) RTA_DATA(rtap))); - default: - break; + for (; RTA_OK(rtap, rtl); rtap = RTA_NEXT(rtap, rtl)) { + switch (rtap->rta_type) { + // destination IPv4 address + case RTA_DST: + inet_ntop(AF_INET, RTA_DATA(rtap), dsts, 24); + break; + // next hop IPv4 address + case RTA_GATEWAY: + inet_ntop(AF_INET, RTA_DATA(rtap), gws, 24); + break; + // unique ID associated with the network + // interface + case RTA_OIF: + sprintf(ifs, "%d", *((int *)RTA_DATA(rtap))); + default: + break; } } sprintf(ms, "%d", rtp->rtm_dst_len); - test_msg("dst %s/%s gw %s if %s\n", - dsts, ms, gws, ifs); + test_msg("dst %s/%s gw %s if %s\n", dsts, ms, gws, ifs); } return 0; } -#define NLMSG_TAIL(nmsg) \ - ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) +#define NLMSG_TAIL(nmsg) ((struct rtattr *)(((void *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) int form_request_del(void) { @@ -258,8 +248,7 @@ int form_request_del(void) rtap = NLMSG_TAIL(&req.nl); rtap->rta_type = RTA_DST; rtap->rta_len = RTA_LENGTH(4); - inet_pton(AF_INET, dsts, - ((char *)rtap) + sizeof(struct rtattr)); + inet_pton(AF_INET, dsts, ((char *)rtap) + sizeof(struct rtattr)); req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len); req.nl.nlmsg_flags = NLM_F_CREATE | NLM_F_ACK | NLM_F_REQUEST; req.nl.nlmsg_type = RTM_DELROUTE; @@ -281,15 +270,13 @@ int form_request_add(void) rtap = NLMSG_TAIL(&req.nl); rtap->rta_type = RTA_DST; rtap->rta_len = RTA_LENGTH(4); - inet_pton(AF_INET, dsts, - ((char *)rtap) + sizeof(struct rtattr)); + inet_pton(AF_INET, dsts, ((char *)rtap) + sizeof(struct rtattr)); req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len); rtap = NLMSG_TAIL(&req.nl); - rtap->rta_type = RTA_OIF;//Output interface index + rtap->rta_type = RTA_OIF; //Output interface index rtap->rta_len = RTA_LENGTH(sizeof(int)); - memcpy(((char *)rtap) + sizeof(struct rtattr), - &ifcn, sizeof(int)); + memcpy(((char *)rtap) + sizeof(struct rtattr), &ifcn, sizeof(int)); req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len); req.nl.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; diff --git a/test/zdtm/transition/pipe_loop00.c b/test/zdtm/transition/pipe_loop00.c index 73e05e217..fa1f0eee4 100644 --- a/test/zdtm/transition/pipe_loop00.c +++ b/test/zdtm/transition/pipe_loop00.c @@ -10,15 +10,16 @@ #include "zdtmtst.h" -const char *test_doc = "Multi-process pipe loop"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Multi-process pipe loop"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define PROCS_DEF 4 -#define PROCS_MAX 64 +#define PROCS_DEF 4 +#define PROCS_MAX 64 unsigned int num_procs = PROCS_DEF; -TEST_OPTION(num_procs, uint, "# processes to create " - "(default " __stringify(PROCS_DEF) - ", max " __stringify(PROCS_MAX) ")", 0); +TEST_OPTION(num_procs, uint, + "# processes to create " + "(default " __stringify(PROCS_DEF) ", max " __stringify(PROCS_MAX) ")", + 0); volatile sig_atomic_t num_exited = 0; void inc_num_exited(int signo) @@ -53,7 +54,7 @@ int main(int argc, char **argv) exit(1); } - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ pid = test_fork(); if (pid < 0) { pr_perror("Can't fork"); @@ -72,11 +73,10 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); if (pipe_in2out(pipes[in], pipes[out], buf, sizeof(buf)) < 0) /* pass errno as exit code to the parent */ - if (test_go() /* signal NOT delivered */ || - (errno != EINTR && errno != EPIPE)) + if (test_go() /* signal NOT delivered */ || (errno != EINTR && errno != EPIPE)) ret = errno; - test_waitsig(); /* even if failed, wait for migration to complete */ + test_waitsig(); /* even if failed, wait for migration to complete */ close(pipes[in]); close(pipes[out]); @@ -90,7 +90,7 @@ int main(int argc, char **argv) out = pipes[num_procs * 2 - 1]; /* don't block on writing, _do_ block on reading */ - if (set_nonblock(out,1) < 0) { + if (set_nonblock(out, 1) < 0) { pr_perror("setting O_NONBLOCK failed"); exit(1); } @@ -143,14 +143,14 @@ int main(int argc, char **argv) close(out); - test_waitsig(); /* even if failed, wait for migration to complete */ + test_waitsig(); /* even if failed, wait for migration to complete */ if (kill(0, SIGTERM)) { fail("failed to send SIGTERM to my process group"); - goto out; /* shouldn't wait() in this case */ + goto out; /* shouldn't wait() in this case */ } - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ int chret; if (wait(&chret) < 0) { fail("can't wait for a child"); @@ -160,8 +160,7 @@ int main(int argc, char **argv) chret = WEXITSTATUS(chret); if (chret) { - fail("child %d exited with non-zero code %d (%s)", - i, chret, strerror(chret)); + fail("child %d exited with non-zero code %d (%s)", i, chret, strerror(chret)); ret = 1; continue; } diff --git a/test/zdtm/transition/pipe_shared00.c b/test/zdtm/transition/pipe_shared00.c index d1dcd665d..421a8d0bf 100644 --- a/test/zdtm/transition/pipe_shared00.c +++ b/test/zdtm/transition/pipe_shared00.c @@ -10,15 +10,16 @@ #include "zdtmtst.h" -const char *test_doc = "Multi-process pipe split"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Multi-process pipe split"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define PROCS_DEF 4 -#define PROCS_MAX 64 +#define PROCS_DEF 4 +#define PROCS_MAX 64 unsigned int num_procs = PROCS_DEF; -TEST_OPTION(num_procs, uint, "# processes to create " - "(default " __stringify(PROCS_DEF) - ", max " __stringify(PROCS_MAX) ")", 0); +TEST_OPTION(num_procs, uint, + "# processes to create " + "(default " __stringify(PROCS_DEF) ", max " __stringify(PROCS_MAX) ")", + 0); volatile sig_atomic_t num_exited = 0; void inc_num_exited(int signo) @@ -53,7 +54,7 @@ int main(int argc, char **argv) exit(1); } - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ pid = test_fork(); if (pid < 0) { pr_perror("can't fork"); @@ -69,7 +70,7 @@ int main(int argc, char **argv) if (rlen == 0) break; else if (rlen < 0) { - ret = errno; /* pass errno as exit code to the parent */ + ret = errno; /* pass errno as exit code to the parent */ break; } @@ -81,7 +82,7 @@ int main(int argc, char **argv) } } - test_waitsig(); /* even if failed, wait for migration to complete */ + test_waitsig(); /* even if failed, wait for migration to complete */ close(pipes[0]); exit(ret); @@ -99,23 +100,23 @@ int main(int argc, char **argv) test_daemon(); memset(buf, SND_CHR, sizeof(buf)); - while(test_go()) + while (test_go()) if (write(pipes[1], buf, sizeof(buf)) < 0 && - (errno != EINTR || test_go())) { /* only SIGTERM may stop us */ + (errno != EINTR || test_go())) { /* only SIGTERM may stop us */ fail("write failed"); ret = 1; break; } close(pipes[1]); - test_waitsig(); /* even if failed, wait for migration to complete */ + test_waitsig(); /* even if failed, wait for migration to complete */ if (kill(0, SIGTERM)) { fail("failed to send SIGTERM to my process group"); - goto out; /* shouldn't wait() in this case */ + goto out; /* shouldn't wait() in this case */ } - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ int chret; if (wait(&chret) < 0) { fail("can't wait for a child"); @@ -125,8 +126,7 @@ int main(int argc, char **argv) chret = WEXITSTATUS(chret); if (chret) { - fail("child exited with non-zero code %d (%s)", - chret, strerror(chret)); + fail("child exited with non-zero code %d (%s)", chret, strerror(chret)); ret = 1; continue; } diff --git a/test/zdtm/transition/ptrace.c b/test/zdtm/transition/ptrace.c index 29e2e01d9..bf6344f1c 100644 --- a/test/zdtm/transition/ptrace.c +++ b/test/zdtm/transition/ptrace.c @@ -15,7 +15,7 @@ const char *test_doc = "Tests that ptraced thread do not escape from tracing"; const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define NR_THREADS 2 +#define NR_THREADS 2 unsigned int nr_threads = NR_THREADS; TEST_OPTION(nr_threads, uint, "Number of threads", 0); @@ -30,17 +30,15 @@ static void *thread(void *arg) int main(int argc, char **argv) { int pid, status, i, stopped; -#define PT_REGS_SIZE 4096 /* big enough for any arch */ -#define PT_REGS_ALIGN 16 /* big enough for any arch */ +#define PT_REGS_SIZE 4096 /* big enough for any arch */ +#define PT_REGS_ALIGN 16 /* big enough for any arch */ char regs[PT_REGS_SIZE] __attribute__((aligned(PT_REGS_ALIGN))); int *pids; test_init(argc, argv); - pids = (int *)mmap(NULL, sizeof(int) * nr_threads, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0); + pids = (int *)mmap(NULL, sizeof(int) * nr_threads, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); if (pids == MAP_FAILED) { pr_perror("Can't map"); exit(1); @@ -62,8 +60,8 @@ int main(int argc, char **argv) } } thread(pids + i); -out_th: - for (i--; i >=0; i--) { + out_th: + for (i--; i >= 0; i--) { pthread_kill(pt[i], SIGKILL); pthread_join(pt[i], NULL); } diff --git a/test/zdtm/transition/shmem.c b/test/zdtm/transition/shmem.c index 39ccfbe9b..bca0f06c8 100644 --- a/test/zdtm/transition/shmem.c +++ b/test/zdtm/transition/shmem.c @@ -7,9 +7,9 @@ #include "zdtmtst.h" -const char *test_author = "Andrei Vagin <avagin@virtuozzo.com>"; +const char *test_author = "Andrei Vagin <avagin@virtuozzo.com>"; -#define MEM_SIZE (1<<25) +#define MEM_SIZE (1 << 25) int main(int argc, char **argv) { diff --git a/test/zdtm/transition/socket_loop00.c b/test/zdtm/transition/socket_loop00.c index 85dba1155..5a13ecb34 100644 --- a/test/zdtm/transition/socket_loop00.c +++ b/test/zdtm/transition/socket_loop00.c @@ -11,15 +11,16 @@ #include "zdtmtst.h" -const char *test_doc = "Multi-process socket loop"; -const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; +const char *test_doc = "Multi-process socket loop"; +const char *test_author = "Pavel Emelianov <xemul@parallels.com>"; -#define PROCS_DEF 4 -#define PROCS_MAX 64 +#define PROCS_DEF 4 +#define PROCS_MAX 64 unsigned int num_procs = PROCS_DEF; -TEST_OPTION(num_procs, uint, "# processes to create " - "(default " __stringify(PROCS_DEF) - ", max " __stringify(PROCS_MAX) ")", 0); +TEST_OPTION(num_procs, uint, + "# processes to create " + "(default " __stringify(PROCS_DEF) ", max " __stringify(PROCS_MAX) ")", + 0); volatile sig_atomic_t num_exited = 0; void inc_num_exited(int signo) @@ -54,7 +55,7 @@ int main(int argc, char **argv) exit(1); } - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ pid = test_fork(); if (pid < 0) { pr_perror("Can't fork"); @@ -74,11 +75,10 @@ int main(int argc, char **argv) if (pipe_in2out(socks[in], socks[out], buf, sizeof(buf)) < 0) /* pass errno as exit code to the parent */ if (test_go() /* signal NOT delivered */ || - (errno != EINTR && errno != EPIPE - && errno != ECONNRESET)) + (errno != EINTR && errno != EPIPE && errno != ECONNRESET)) ret = errno; - test_waitsig(); /* even if failed, wait for migration to complete */ + test_waitsig(); /* even if failed, wait for migration to complete */ close(socks[in]); close(socks[out]); @@ -92,7 +92,7 @@ int main(int argc, char **argv) out = socks[num_procs * 2 - 1]; /* don't block on writing, _do_ block on reading */ - if (set_nonblock(out,1) < 0) { + if (set_nonblock(out, 1) < 0) { pr_perror("setting O_NONBLOCK failed"); exit(1); } @@ -143,15 +143,14 @@ int main(int argc, char **argv) } } - - test_waitsig(); /* even if failed, wait for migration to complete */ + test_waitsig(); /* even if failed, wait for migration to complete */ /* We expect that write(2) in child may return error only after signal * has been received. Thus, send signal before closing parent fds. */ if (kill(0, SIGTERM)) { fail("failed to send SIGTERM to my process group"); - goto out; /* shouldn't wait() in this case */ + goto out; /* shouldn't wait() in this case */ } if (close(out)) fail("Failed to close parent fd 'out'"); @@ -162,7 +161,7 @@ int main(int argc, char **argv) if (close(in)) fail("failed to close parent fd 'in'"); - for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ + for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ int chret; if (wait(&chret) < 0) { fail("can't wait for a child"); @@ -172,8 +171,7 @@ int main(int argc, char **argv) chret = WEXITSTATUS(chret); if (chret) { - fail("child %d exited with non-zero code %d (%s)", - i, chret, strerror(chret)); + fail("child %d exited with non-zero code %d (%s)", i, chret, strerror(chret)); ret = 1; continue; } diff --git a/test/zdtm/transition/thread-bomb.c b/test/zdtm/transition/thread-bomb.c index c1b825be7..c101f85d4 100644 --- a/test/zdtm/transition/thread-bomb.c +++ b/test/zdtm/transition/thread-bomb.c @@ -8,8 +8,7 @@ #include "zdtmtst.h" -#define exit_group(code) \ - syscall(__NR_exit_group, code) +#define exit_group(code) syscall(__NR_exit_group, code) static pthread_attr_t attr; /* Having in mind setup with 64 Kb large pages */ diff --git a/test/zdtm/transition/unix_sock.c b/test/zdtm/transition/unix_sock.c index 1fb61139d..caa5a4a57 100644 --- a/test/zdtm/transition/unix_sock.c +++ b/test/zdtm/transition/unix_sock.c @@ -13,20 +13,21 @@ #include "zdtmtst.h" -const char *test_doc = "Multi-client - server app"; -const char *test_author = "Roman Kagan <rkagan@parallels.com>"; +const char *test_doc = "Multi-client - server app"; +const char *test_author = "Roman Kagan <rkagan@parallels.com>"; -#define PROCS_DEF 4 -#define PROCS_MAX 64 +#define PROCS_DEF 4 +#define PROCS_MAX 64 unsigned int num_procs = PROCS_DEF; -TEST_OPTION(num_procs, uint, "# processes to create " - "(default " __stringify(PROCS_DEF) - ", max " __stringify(PROCS_MAX) ")", 0); +TEST_OPTION(num_procs, uint, + "# processes to create " + "(default " __stringify(PROCS_DEF) ", max " __stringify(PROCS_MAX) ")", + 0); char *filename; TEST_OPTION(filename, string, "file name", 1); -#define ACCEPT_TIMEOUT 100 /* max delay for the child to connect */ +#define ACCEPT_TIMEOUT 100 /* max delay for the child to connect */ static int fill_sock_name(struct sockaddr_un *name, const char *filename) { @@ -54,7 +55,7 @@ static int setup_srv_sock(void) return -1; } - if (bind(sock, (struct sockaddr *) &name, SUN_LEN(&name)) < 0) { + if (bind(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) { pr_perror("can't bind to socket \"%s\"", filename); goto err; } @@ -121,7 +122,7 @@ static int setup_clnt_sock(void) return ret; } - if (connect(sock, (struct sockaddr *) &name, SUN_LEN(&name)) < 0) { + if (connect(sock, (struct sockaddr *)&name, SUN_LEN(&name)) < 0) { ret = -errno; pr_perror("can't connect"); goto err; @@ -150,10 +151,8 @@ static int child(void) signal(SIGPIPE, SIG_IGN); while (test_go()) { datagen(buf, sizeof(buf), &crc); - if (write(sock, buf, sizeof(buf)) < 0 && - (test_go() /* signal NOT received */ || - (errno != EINTR && errno != EPIPE && \ - errno != ECONNRESET))) { + if (write(sock, buf, sizeof(buf)) < 0 && (test_go() /* signal NOT received */ || + (errno != EINTR && errno != EPIPE && errno != ECONNRESET))) { ret = errno; fail("child write"); goto out; @@ -212,13 +211,12 @@ int main(int argc, char **argv) FD_SET(child_desc[nproc].sock, &active_fds); } - close(sock); /* no more connections */ + close(sock); /* no more connections */ test_daemon(); while (test_go()) { read_fds = active_fds; - if (select(FD_SETSIZE, &read_fds, NULL, NULL, NULL) < 0 && - errno != EINTR) { + if (select(FD_SETSIZE, &read_fds, NULL, NULL, NULL) < 0 && errno != EINTR) { fail("error waiting for data"); goto out; } @@ -226,7 +224,7 @@ int main(int argc, char **argv) for (i = 0; i < num_procs; i++) if (FD_ISSET(child_desc[i].sock, &read_fds)) { if (read(child_desc[i].sock, buf, sizeof(buf)) < 0) { - if(errno == EINTR) /* we're asked to stop */ + if (errno == EINTR) /* we're asked to stop */ break; else { fail("error reading data from socket"); @@ -241,13 +239,12 @@ int main(int argc, char **argv) } } - out: test_waitsig(); if (kill(0, SIGTERM)) { fail("failed to send SIGTERM to my process group"); - goto cleanup; /* shouldn't wait() in this case */ + goto cleanup; /* shouldn't wait() in this case */ } while (nproc-- > 0) { @@ -258,7 +255,7 @@ out: * signal to child, child has checked for signal & found none * (not yet delivered), then called write(), blocking forever. */ - if(close(child_desc[nproc].sock)) + if (close(child_desc[nproc].sock)) fail("Can't close server socket"); if (wait(&chret) < 0) { @@ -268,8 +265,7 @@ out: chret = WEXITSTATUS(chret); if (chret) { - fail("child exited with non-zero code %d (%s)", - chret, strerror(chret)); + fail("child exited with non-zero code %d (%s)", chret, strerror(chret)); goto cleanup; } } diff --git a/test/zdtm_ct.c b/test/zdtm_ct.c index 60aa40334..e8d45a9e7 100644 --- a/test/zdtm_ct.c +++ b/test/zdtm_ct.c @@ -12,33 +12,33 @@ #include <sys/utsname.h> #ifndef CLONE_NEWTIME -#define CLONE_NEWTIME 0x00000080 /* New time namespace */ +#define CLONE_NEWTIME 0x00000080 /* New time namespace */ #endif static inline int _settime(clockid_t clk_id, time_t offset) { - int fd, len; - char buf[4096]; + int fd, len; + char buf[4096]; - if (clk_id == CLOCK_MONOTONIC_COARSE || clk_id == CLOCK_MONOTONIC_RAW) - clk_id = CLOCK_MONOTONIC; + if (clk_id == CLOCK_MONOTONIC_COARSE || clk_id == CLOCK_MONOTONIC_RAW) + clk_id = CLOCK_MONOTONIC; - len = snprintf(buf, sizeof(buf), "%d %ld 0", clk_id, offset); + len = snprintf(buf, sizeof(buf), "%d %ld 0", clk_id, offset); - fd = open("/proc/self/timens_offsets", O_WRONLY); - if (fd < 0) { - fprintf(stderr, "/proc/self/timens_offsets: %m"); + fd = open("/proc/self/timens_offsets", O_WRONLY); + if (fd < 0) { + fprintf(stderr, "/proc/self/timens_offsets: %m"); return -1; } - if (write(fd, buf, len) != len) { - fprintf(stderr, "/proc/self/timens_offsets: %m"); + if (write(fd, buf, len) != len) { + fprintf(stderr, "/proc/self/timens_offsets: %m"); return -1; } - close(fd); + close(fd); - return 0; + return 0; } static int create_timens() @@ -117,13 +117,11 @@ int main(int argc, char **argv) fprintf(stderr, "mount(/proc): %m"); return 1; } - if (mount("zdtm_devpts", "/dev/pts", "devpts", 0, - "newinstance,ptmxmode=0666")) { + if (mount("zdtm_devpts", "/dev/pts", "devpts", 0, "newinstance,ptmxmode=0666")) { fprintf(stderr, "mount(pts): %m"); return 1; } - if (mount("zdtm_binfmt", "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, - NULL)) { + if (mount("zdtm_binfmt", "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, NULL)) { fprintf(stderr, "mount(binfmt_misc): %m"); return 1; } |