[CRIU] [PATCH] cr-dump: call stat for /proc/pid/fd/X directly
Pavel Emelyanov
xemul at parallels.com
Mon Jan 21 08:34:24 EST 2013
Applied, but one comment inline
On 01/19/2013 06:55 PM, Andrey Vagin wrote:
> This patch can be committed instead of:
> [PATCH 1/6] cr-dump: move parasite_drain_fds_seized out of dump_task_files
> [PATCH 2/6] cr-dump: fix dumping file locks in a mount namespace
>
> readlink is not required here and a file can be unavailable,
> if a process is in another mnt namespace
>
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
> cr-dump.c | 23 +++++------------------
> 1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/cr-dump.c b/cr-dump.c
> index e94aa51..6a274f3 100644
> --- a/cr-dump.c
> +++ b/cr-dump.c
> @@ -694,36 +694,23 @@ err:
> static int get_fd_by_ino(unsigned long i_no, struct parasite_drain_fd *dfds,
> pid_t pid)
> {
> - int i, ret = -1;
> - char path[PATH_MAX];
> - char buf[40];
> + int i;
> + char buf[PATH_MAX];
> struct stat fd_stat;
>
> - i = 0;
> - while (i < dfds->nr_fds) {
> + for (i = 0; i < dfds->nr_fds; i++) {
> snprintf(buf, sizeof(buf), "/proc/%d/fd/%d", pid,
> dfds->fds[i]);
> - buf[39] = '\0';
> -
> - memset(path, 0, sizeof(path));
> - ret = readlink(buf, path, sizeof(path));
> - if (ret < 0) {
> - pr_err("Read link %s failed!\n", buf);
> - goto err;
> - }
>
> - if (stat(path, &fd_stat) == -1) {
> - i++;
> - pr_msg("Could not get %s stat!\n", path);
> + if (stat(buf, &fd_stat) == -1) {
> + pr_msg("Could not get %s stat!\n", buf);
> continue;
> }
>
> if (fd_stat.st_ino == i_no)
Is it correct to check inode only? Files from different disks
may have equal inodes.
> return dfds->fds[i];
> - i++;
> }
>
> -err:
> return -1;
> }
>
>
More information about the CRIU
mailing list