Commit ccdcb3d3 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fsnotify: Simplify get_mark_path code

Handle the simplest (remap) case early. This makes code
simpler and reduces one level of indent.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 32adef6f
...@@ -184,48 +184,45 @@ static char *get_mark_path(const char *who, struct file_remap *remap, ...@@ -184,48 +184,45 @@ static char *get_mark_path(const char *who, struct file_remap *remap,
int mntfd = -1; int mntfd = -1;
fh_t handle; fh_t handle;
if (!remap) { if (remap) {
memzero(&handle, sizeof(handle)); pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s)\n",
who, s_dev, i_ino, path);
return remap->path;
}
handle.type = f_handle->type; memzero(&handle, sizeof(handle));
handle.bytes = f_handle->bytes;
memcpy(handle.__handle, f_handle->handle, handle.type = f_handle->type;
min(pb_repeated_size(f_handle, handle), handle.bytes = f_handle->bytes;
sizeof(handle.__handle)));
mntfd = open_mount(s_dev); memcpy(handle.__handle, f_handle->handle,
if (mntfd < 0) { min(pb_repeated_size(f_handle, handle),
pr_err("Mount root for 0x%08x not found\n", s_dev); sizeof(handle.__handle)));
goto err;
}
*target = sys_open_by_handle_at(mntfd, (void *)&handle, 0); mntfd = open_mount(s_dev);
if (*target < 0) { if (mntfd < 0) {
pr_perror("Can't open file handle for 0x%08x:0x%016lx", pr_err("Mount root for 0x%08x not found\n", s_dev);
s_dev, i_ino); goto err;
goto err; }
}
snprintf(buf, size, "/proc/self/fd/%d", *target);
path = buf;
if (log_get_loglevel() >= LOG_DEBUG) { *target = sys_open_by_handle_at(mntfd, (void *)&handle, 0);
char link[PATH_MAX]; if (*target < 0) {
pr_perror("Can't open file handle for 0x%08x:0x%016lx",
s_dev, i_ino);
goto err;
}
snprintf(buf, size, "/proc/self/fd/%d", *target);
path = buf;
if (read_fd_link(*target, link, sizeof(link)) < 0) if (log_get_loglevel() >= LOG_DEBUG) {
link[0] = '\0'; char link[PATH_MAX];
pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s -> %s)\n", if (read_fd_link(*target, link, sizeof(link)) < 0)
who, s_dev, i_ino, path, link); link[0] = '\0';
}
} else {
*target = -1;
path = remap->path;
pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s)\n", pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s -> %s)\n",
who, s_dev, i_ino, path); who, s_dev, i_ino, path, link);
} }
err: err:
close_safe(&mntfd); close_safe(&mntfd);
return path; return path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment