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,
int mntfd = -1;
fh_t handle;
if (!remap) {
memzero(&handle, sizeof(handle));
if (remap) {
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;
handle.bytes = f_handle->bytes;
memzero(&handle, sizeof(handle));
memcpy(handle.__handle, f_handle->handle,
min(pb_repeated_size(f_handle, handle),
sizeof(handle.__handle)));
handle.type = f_handle->type;
handle.bytes = f_handle->bytes;
mntfd = open_mount(s_dev);
if (mntfd < 0) {
pr_err("Mount root for 0x%08x not found\n", s_dev);
goto err;
}
memcpy(handle.__handle, f_handle->handle,
min(pb_repeated_size(f_handle, handle),
sizeof(handle.__handle)));
*target = sys_open_by_handle_at(mntfd, (void *)&handle, 0);
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;
mntfd = open_mount(s_dev);
if (mntfd < 0) {
pr_err("Mount root for 0x%08x not found\n", s_dev);
goto err;
}
if (log_get_loglevel() >= LOG_DEBUG) {
char link[PATH_MAX];
*target = sys_open_by_handle_at(mntfd, (void *)&handle, 0);
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)
link[0] = '\0';
if (log_get_loglevel() >= LOG_DEBUG) {
char link[PATH_MAX];
pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s -> %s)\n",
who, s_dev, i_ino, path, link);
}
} else {
*target = -1;
path = remap->path;
if (read_fd_link(*target, link, sizeof(link)) < 0)
link[0] = '\0';
pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s)\n",
who, s_dev, i_ino, path);
pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s -> %s)\n",
who, s_dev, i_ino, path, link);
}
err:
close_safe(&mntfd);
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