2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

util: dump fsfd log messages

It should help to investigate errors of fsconfig, fsmount and etc.

Signed-off-by: Andrei Vagin <avagin@google.com>
This commit is contained in:
Andrei Vagin 2024-09-12 11:19:35 -07:00 committed by Andrei Vagin
parent 096c1f7a4d
commit a8cbe76d4f
5 changed files with 84 additions and 39 deletions

View File

@ -28,7 +28,6 @@
#include "images/cgroup.pb-c.h"
#include "kerndat.h"
#include "linux/mount.h"
#include "syscall.h"
/*
* This structure describes set of controller groups
@ -581,14 +580,15 @@ static int __new_open_cgroupfs(struct cg_ctl *cc)
int fsfd, fd;
char *name;
fsfd = sys_fsopen(fstype, 0);
fsfd = cr_fsopen(fstype, 0);
if (fsfd < 0) {
pr_perror("Unable to open the cgroup file system");
return -1;
}
if (strstartswith(cc->name, namestr)) {
if (sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "name", cc->name + strlen(namestr), 0)) {
if (cr_fsconfig(fsfd, FSCONFIG_SET_STRING, "name", cc->name + strlen(namestr), 0)) {
fsfd_dump_messages(fsfd);
pr_perror("Unable to configure the cgroup (%s) file system", cc->name);
goto err;
}
@ -596,7 +596,8 @@ static int __new_open_cgroupfs(struct cg_ctl *cc)
char *saveptr = NULL, *buf = strdupa(cc->name);
name = strtok_r(buf, ",", &saveptr);
while (name) {
if (sys_fsconfig(fsfd, FSCONFIG_SET_FLAG, name, NULL, 0)) {
if (cr_fsconfig(fsfd, FSCONFIG_SET_FLAG, name, NULL, 0)) {
fsfd_dump_messages(fsfd);
pr_perror("Unable to configure the cgroup (%s) file system", name);
goto err;
}
@ -604,14 +605,17 @@ static int __new_open_cgroupfs(struct cg_ctl *cc)
}
}
if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0)) {
if (cr_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0)) {
fsfd_dump_messages(fsfd);
pr_perror("Unable to create the cgroup (%s) file system", cc->name);
goto err;
}
fd = sys_fsmount(fsfd, 0, 0);
if (fd < 0)
fd = cr_fsmount(fsfd, 0, 0);
if (fd < 0) {
fsfd_dump_messages(fsfd);
pr_perror("Unable to mount the cgroup (%s) file system", cc->name);
}
close(fsfd);
return fd;

View File

@ -54,7 +54,6 @@
#include "restorer.h"
#include "uffd.h"
#include "linux/aio_abi.h"
#include "syscall.h"
#include "mount-v2.h"
#include "images/inventory.pb-c.h"
@ -1437,18 +1436,18 @@ static int ovl_mount(void)
{
int tmpfs, fsfd, ovl;
fsfd = sys_fsopen("tmpfs", 0);
fsfd = cr_fsopen("tmpfs", 0);
if (fsfd == -1) {
pr_perror("Unable to fsopen tmpfs");
return -1;
}
if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) == -1) {
if (cr_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) == -1) {
pr_perror("Unable to create tmpfs mount");
return -1;
}
tmpfs = sys_fsmount(fsfd, 0, 0);
tmpfs = cr_fsmount(fsfd, 0, 0);
if (tmpfs == -1) {
pr_perror("Unable to mount tmpfs");
return -1;
@ -1475,23 +1474,23 @@ static int ovl_mount(void)
return -1;
}
fsfd = sys_fsopen("overlay", 0);
fsfd = cr_fsopen("overlay", 0);
if (fsfd == -1) {
pr_perror("Unable to fsopen overlayfs");
return -1;
}
if (sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "source", "test", 0) == -1 ||
sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "lowerdir", "/tmp/l", 0) == -1 ||
sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "upperdir", "/tmp/u", 0) == -1 ||
sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "workdir", "/tmp/w", 0) == -1) {
if (cr_fsconfig(fsfd, FSCONFIG_SET_STRING, "source", "test", 0) == -1 ||
cr_fsconfig(fsfd, FSCONFIG_SET_STRING, "lowerdir", "/tmp/l", 0) == -1 ||
cr_fsconfig(fsfd, FSCONFIG_SET_STRING, "upperdir", "/tmp/u", 0) == -1 ||
cr_fsconfig(fsfd, FSCONFIG_SET_STRING, "workdir", "/tmp/w", 0) == -1) {
pr_perror("Unable to configure overlayfs");
return -1;
}
if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) == -1) {
if (cr_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) == -1) {
pr_perror("Unable to create overlayfs");
return -1;
}
ovl = sys_fsmount(fsfd, 0, 0);
ovl = cr_fsmount(fsfd, 0, 0);
if (ovl == -1) {
pr_perror("Unable to mount overlayfs");
return -1;

View File

@ -1,17 +0,0 @@
#ifndef __CR_SYSCALL_H__
#define __CR_SYSCALL_H__
static inline int sys_fsopen(const char *fsname, unsigned int flags)
{
return syscall(__NR_fsopen, fsname, flags);
}
static inline int sys_fsconfig(int fd, unsigned int cmd, const char *key, const char *value, int aux)
{
return syscall(__NR_fsconfig, fd, cmd, key, value, aux);
}
static inline int sys_fsmount(int fd, unsigned int flags, unsigned int attr_flags)
{
return syscall(__NR_fsmount, fd, flags, attr_flags);
}
#endif /* __CR_SYSCALL_H__ */

View File

@ -387,6 +387,11 @@ static inline void print_stack_trace(pid_t pid)
extern int mount_detached_fs(const char *fsname);
extern int cr_fsopen(const char *fsname, unsigned int flags);
extern int cr_fsconfig(int fd, unsigned int cmd, const char *key, const char *value, int aux);
extern int cr_fsmount(int fd, unsigned int flags, unsigned int attr_flags);
extern void fsfd_dump_messages(int fd);
extern char *get_legacy_iptables_bin(bool ipv6, bool restore);
extern int set_opts_cap_eff(void);

View File

@ -39,7 +39,6 @@
#include "mem.h"
#include "namespaces.h"
#include "criu-log.h"
#include "syscall.h"
#include "util-caps.h"
#include "clone-noasan.h"
@ -1556,23 +1555,78 @@ void print_stack_trace(pid_t pid)
}
#endif
int cr_fsopen(const char *fsname, unsigned int flags)
{
return syscall(__NR_fsopen, fsname, flags);
}
int cr_fsconfig(int fd, unsigned int cmd, const char *key, const char *value, int aux)
{
int ret = syscall(__NR_fsconfig, fd, cmd, key, value, aux);
if (ret)
fsfd_dump_messages(fd);
return ret;
}
int cr_fsmount(int fd, unsigned int flags, unsigned int attr_flags)
{
int ret = syscall(__NR_fsmount, fd, flags, attr_flags);
if (ret)
fsfd_dump_messages(fd);
return ret;
}
void fsfd_dump_messages(int fd)
{
char buf[4096];
int err, n;
err = errno;
for (;;) {
n = read(fd, buf, sizeof(buf) - 1);
if (n < 0) {
if (errno != ENODATA)
pr_perror("Unable to read from fs descriptor");
break;
}
buf[n] = 0;
switch (buf[0]) {
case 'w':
pr_warn("%s\n", buf);
break;
case 'i':
pr_info("%s\n", buf);
break;
case 'e':
/* fallthrough */
default:
pr_err("%s\n", buf);
break;
}
}
errno = err;
}
int mount_detached_fs(const char *fsname)
{
int fsfd, fd;
fsfd = sys_fsopen(fsname, 0);
fsfd = cr_fsopen(fsname, 0);
if (fsfd < 0) {
pr_perror("Unable to open the %s file system", fsname);
return -1;
}
if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) {
if (cr_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) {
pr_perror("Unable to create the %s file system", fsname);
close(fsfd);
return -1;
}
fd = sys_fsmount(fsfd, 0, 0);
fd = cr_fsmount(fsfd, 0, 0);
if (fd < 0)
pr_perror("Unable to mount the %s file system", fsname);
close(fsfd);