mirror of
https://github.com/containers/fuse-overlayfs.git
synced 2025-09-13 17:28:27 -04:00
main: simplify setattr
always use the /proc/self/fd/FD path when the path doesn't refer to a directory or regular file. commit 0b0c7a3a01dae4de65ba79016a111d794c1d1719 introduced the regression. Closes: https://github.com/containers/fuse-overlayfs/issues/99 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
80eb59d71d
commit
1faf62ce32
49
main.c
49
main.c
@ -1605,7 +1605,6 @@ do_lookup_file (struct ovl_data *lo, fuse_ino_t parent, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
strconcat3 (whpath, PATH_MAX, pnode->path, "/.wh.", name);
|
strconcat3 (whpath, PATH_MAX, pnode->path, "/.wh.", name);
|
||||||
|
|
||||||
ret = file_exists_at (it->fd, whpath);
|
ret = file_exists_at (it->fd, whpath);
|
||||||
if (ret < 0 && errno != ENOENT)
|
if (ret < 0 && errno != ENOENT)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -3245,8 +3244,8 @@ ovl_setattr (fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, stru
|
|||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
int ret;
|
int ret;
|
||||||
int fd;
|
int fd = -1;
|
||||||
char proc_path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if (UNLIKELY (ovl_debug (req)))
|
if (UNLIKELY (ovl_debug (req)))
|
||||||
fprintf (stderr, "ovl_setattr(ino=%" PRIu64 "s, to_set=%d)\n", ino, to_set);
|
fprintf (stderr, "ovl_setattr(ino=%" PRIu64 "s, to_set=%d)\n", ino, to_set);
|
||||||
@ -3274,20 +3273,28 @@ ovl_setattr (fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, stru
|
|||||||
fd = fi->fh; // use existing fd if fuse_file_info is available
|
fd = fi->fh; // use existing fd if fuse_file_info is available
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
struct stat st;
|
||||||
int dirfd = node_dirfd (node);
|
int dirfd = node_dirfd (node);
|
||||||
|
|
||||||
|
ret = fstatat (dirfd, node->path, &st, AT_SYMLINK_NOFOLLOW);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fuse_reply_err (req, errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (st.st_mode & S_IFMT)
|
||||||
|
{
|
||||||
|
case S_IFREG:
|
||||||
cleaned_up_fd = fd = TEMP_FAILURE_RETRY (openat (dirfd, node->path, O_NOFOLLOW|O_NONBLOCK|O_WRONLY));
|
cleaned_up_fd = fd = TEMP_FAILURE_RETRY (openat (dirfd, node->path, O_NOFOLLOW|O_NONBLOCK|O_WRONLY));
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
if (errno == EISDIR)
|
|
||||||
goto handle_eisdir;
|
|
||||||
if (errno == ELOOP)
|
|
||||||
goto handle_eloop;
|
|
||||||
|
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
handle_eisdir:
|
case S_IFDIR:
|
||||||
cleaned_up_fd = fd = TEMP_FAILURE_RETRY (openat (dirfd, node->path, O_NOFOLLOW|O_NONBLOCK));
|
cleaned_up_fd = fd = TEMP_FAILURE_RETRY (openat (dirfd, node->path, O_NOFOLLOW|O_NONBLOCK));
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
@ -3296,16 +3303,22 @@ handle_eisdir:
|
|||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handle_eloop:
|
}
|
||||||
/* It is a symlink and it cannot be used directly. Fallback to the /proc/fd/$FD path. */
|
break;
|
||||||
|
|
||||||
|
case S_IFLNK:
|
||||||
cleaned_up_fd = TEMP_FAILURE_RETRY (openat (dirfd, node->path, O_PATH|O_NOFOLLOW|O_NONBLOCK));
|
cleaned_up_fd = TEMP_FAILURE_RETRY (openat (dirfd, node->path, O_PATH|O_NOFOLLOW|O_NONBLOCK));
|
||||||
if (cleaned_up_fd < 0)
|
if (cleaned_up_fd < 0)
|
||||||
{
|
{
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sprintf (proc_path, "/proc/self/fd/%d", cleaned_up_fd);
|
sprintf (path, "/proc/self/fd/%d", cleaned_up_fd);
|
||||||
}
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
strconcat3 (path, PATH_MAX, get_upper_layer (lo)->path, "/", node->path);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3329,7 +3342,7 @@ handle_eloop:
|
|||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
ret = futimens (fd, times);
|
ret = futimens (fd, times);
|
||||||
else
|
else
|
||||||
ret = utimensat (AT_FDCWD, proc_path, times, AT_SYMLINK_NOFOLLOW);
|
ret = utimensat (AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
@ -3342,7 +3355,7 @@ handle_eloop:
|
|||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
ret = fchmod (fd, attr->st_mode);
|
ret = fchmod (fd, attr->st_mode);
|
||||||
else
|
else
|
||||||
ret = chmod (proc_path, attr->st_mode);
|
ret = chmod (path, attr->st_mode);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
@ -3355,7 +3368,7 @@ handle_eloop:
|
|||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
ret = ftruncate (fd, attr->st_size);
|
ret = ftruncate (fd, attr->st_size);
|
||||||
else
|
else
|
||||||
ret = truncate (proc_path, attr->st_size);
|
ret = truncate (path, attr->st_size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
@ -3375,7 +3388,7 @@ handle_eloop:
|
|||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
ret = fchown (fd, uid, gid);
|
ret = fchown (fd, uid, gid);
|
||||||
else
|
else
|
||||||
ret = chown (proc_path, uid, gid);
|
ret = chown (path, uid, gid);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
@ -3383,7 +3396,7 @@ handle_eloop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_getattr (req, &e, node, fd, proc_path) < 0)
|
if (do_getattr (req, &e, node, fd, path) < 0)
|
||||||
{
|
{
|
||||||
fuse_reply_err (req, errno);
|
fuse_reply_err (req, errno);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user