diff --git a/crtools.c b/crtools.c index d2a79a009..5e3dee2e6 100644 --- a/crtools.c +++ b/crtools.c @@ -98,6 +98,7 @@ int main(int argc, char *argv[]) { "pidfile", required_argument, 0, 46}, { "veth-pair", required_argument, 0, 47}, { "action-script", required_argument, 0, 49}, + { LREMAP_PARAM, no_argument, 0, 41}, { }, }; @@ -160,6 +161,10 @@ int main(int argc, char *argv[]) log_level++; } break; + case 41: + pr_info("Will allow link remaps on FS\n"); + opts.link_remap_ok = true; + break; case 42: pr_info("Will dump TCP connections\n"); opts.tcp_established_ok = true; @@ -302,6 +307,7 @@ usage: pr_msg(" -r|--root [PATH] change the root filesystem (when run in mount namespace)\n"); pr_msg(" --evasive-devices use any path to a device file if the original one is inaccessible\n"); pr_msg(" --veth-pair [IN=OUT] correspondence between outside and inside names of veth devices\n"); + pr_msg(" --link-remap allow to link unlinked files back when possible (modifies FS till restore)\n"); pr_msg(" --action-script [SCR] add an external action script\n"); pr_msg(" The environment variable CRTOOL_SCRIPT_ACTION contains one of the actions:\n"); pr_msg(" * network-lock - lock network in a target network namespace"); diff --git a/files-reg.c b/files-reg.c index 72b4ddd64..c103154e2 100644 --- a/files-reg.c +++ b/files-reg.c @@ -285,6 +285,12 @@ static int create_link_remap(char *path, int len, int lfd, u32 *idp) RegFileEntry rfe = REG_FILE_ENTRY__INIT; FownEntry fwn = FOWN_ENTRY__INIT; + if (!opts.link_remap_ok) { + pr_err("Can't create link remap for %s. " + "Use " LREMAP_PARAM " option.\n", path); + return -1; + } + /* * Linked remapping -- we create a hard link on a removed file * in the directory original file used to sit. diff --git a/include/crtools.h b/include/crtools.h index 2fb5abd9b..dd678545c 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -95,6 +95,7 @@ struct cr_options { bool ext_unix_sk; bool tcp_established_ok; bool evasive_devices; + bool link_remap_ok; unsigned int namespaces_flags; bool log_file_per_pid; char *output; diff --git a/include/files.h b/include/files.h index e91194cdb..cc0e46faf 100644 --- a/include/files.h +++ b/include/files.h @@ -95,4 +95,6 @@ extern int set_fd_flags(int fd, int flags); #define AT_EMPTY_PATH 0x1000 #endif +#define LREMAP_PARAM "link-remap" + #endif /* FILES_H_ */ diff --git a/test/zdtm.sh b/test/zdtm.sh index d8009e117..042957517 100644 --- a/test/zdtm.sh +++ b/test/zdtm.sh @@ -232,7 +232,7 @@ EOF echo Dump $PID mkdir -p $ddump save_fds $PID $ddump/dump.fd - setsid $CRTOOLS dump --tcp-established -x --evasive-devices -D $ddump -o dump.log -v 4 -t $PID $args $ARGS || { + setsid $CRTOOLS dump --tcp-established --link-remap -x --evasive-devices -D $ddump -o dump.log -v 4 -t $PID $args $ARGS || { echo WARNING: process $tname is left running for your debugging needs return 1 }