323 Commits

Author SHA1 Message Date
Sascha Grunert
0aa0537459
Fix possible segmentation fault in direct_fsync()
If the call to `get_upper_layer(lo)` returns `NULL` then the
`node->layer` will be `NULL`, too. If this is the case we pass `NULL` to
`direct_fsync()` which will cause a segmentation fault in:

```c
cfd = openat(l->fd, path, O_NOFOLLOW|O_DIRECTORY);
```

To fix this we now apply an additional check and error in the case of
`get_upper_layer(lo) == NULL`.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-08 09:33:48 +01:00
Sascha Grunert
07627d4ddb
Fix dead assignment in main.c
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-08 09:23:42 +01:00
Sascha Grunert
8f3a1dde24
Fix dead increment in main.c
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-08 09:22:22 +01:00
Giuseppe Scrivano
884052db48
build: fix compiler warnings found by gcc
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-12-09 14:49:34 +01:00
Giuseppe Scrivano
1d7b99d95a
fuse-overlayfs: fix some warnings reported by clang
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-12-09 11:05:47 +01:00
Giuseppe Scrivano
5d053201d1
main: drop special handling for security.capability
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-29 11:53:49 +01:00
Giuseppe Scrivano
dfd9f18773
main: prevent parent whiteout to hide file
use the full relative path when looking up the whiteout file,
otherwise a whiteout in the upper layer will hide files in
subdirectories.

Closes: https://github.com/containers/fuse-overlayfs/issues/151

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-27 21:03:21 +01:00
Daniel J Walsh
b57e5c8d00
Merge pull request #147 from giuseppe/fix-build-musl
build: fix build on musl
2019-11-26 05:46:12 -05:00
Giuseppe Scrivano
d1f318ef73
build: fix build on musl
Closes: https://github.com/containers/fuse-overlayfs/issues/145

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-18 13:47:37 +01:00
Giuseppe Scrivano
d077ea28e3
configure: check for FUSE copy_file_range
check if the version of FUSE supports copy_file_range.

It fixes the build on RHEL 8.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-18 13:41:51 +01:00
Giuseppe Scrivano
2403cd9537
main: honor opaque whiteout
Closes: https://github.com/containers/fuse-overlayfs/issues/138

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-04 08:36:37 +01:00
Giuseppe Scrivano
35ef75d9b0
main, mkdir: set directory opaque
when creating a directory, set it opaque.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-02 19:46:51 +01:00
Giuseppe Scrivano
042846de50
main: correctly mark the last_layer with a deleted directory
Closes: https://github.com/containers/fuse-overlayfs/issues/136

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-31 14:26:15 +01:00
Giuseppe Scrivano
715a95c39d
plugins: load from default location
if no -o plugins is specified, load them from $PKGLIBEXECDIR (usually
has the value /usr/libexec/fuse-overlayfs).

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-25 11:02:17 +02:00
Giuseppe Scrivano
3fa10346c3
main: drop magic numbers
use EXIT_FAILURE and EXIT_SUCCESS instead.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-24 13:52:35 +02:00
Giuseppe Scrivano
1c490d91d8
plugins: allow to manage multiple layers with a ds
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-24 13:52:34 +02:00
Giuseppe Scrivano
7095cc29ef
main: fix fast_ino
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-21 18:41:53 +02:00
Giuseppe Scrivano
62abdcf00f
readdir: use mode from uppermost layer
differently than dev/ino number, use the uppermost mode found.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-20 22:06:41 +02:00
Giuseppe Scrivano
9f6f90a6da
direct: use statx when available
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-20 22:06:40 +02:00
Giuseppe Scrivano
b28a23a39d
fuse-overlayfs: add plugin system
Add a simple plugin mechanism that will help to expand fuse-overlayfs
functionalities, in particular it allows to load data from a layer on
demand.

A plugin is loaded into fuse-overlayfs using the option:

-o plugins=path/to/plugin.so:path/to/another/plugin.so

A layer can use a plugin with the syntax:

-o lowerdir=//plugin-name/DATA-FOR-THE-PLUGIN/path

Each time a file/directory is looked up, if a plugin is registered for
a layer, the plugin is first notified about the request.

After the callback is invoked, fuse-overlayfs still expects the data
to be accessible at the specified directory.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-20 22:06:39 +02:00
Giuseppe Scrivano
c2c2ac5b82
main: split the code in multiple files
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-20 19:44:20 +02:00
Giuseppe Scrivano
53c165e6bd
main: refactor to use a data store
this is the first step towards supporting data from lower layers
coming from other sources.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-20 19:44:20 +02:00
Giuseppe Scrivano
e72f92bcf6
main: fix debug format string
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-20 19:43:23 +02:00
Giuseppe Scrivano
c9bbc94ab6
fuse-overlayfs: support running without upper layer
when there is no upper layer specified, fail every read operation with
EROFS.

Closes: https://github.com/containers/fuse-overlayfs/issues/100

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-19 21:33:35 +02:00
Giuseppe Scrivano
45c902ea87
main.c: reload the directory on stat
make sure the directory is reloaded so the correct number of links can
be retrieved.

Closes: https://github.com/containers/fuse-overlayfs/issues/131

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-15 12:55:55 +02:00
Daniel J Walsh
504862881f
Merge pull request #129 from giuseppe/skip-whiteout-creation-if-not-needed
main: skip whiteout creation if not needed
2019-10-03 14:17:38 -04:00
Daniel J Walsh
a9f6140602
Merge pull request #128 from giuseppe/restore-suid-on-cacheback-write
writeback: restore suid mode after write
2019-10-03 14:17:18 -04:00
Giuseppe Scrivano
3a31451fe3
main: skip whiteout creation if not needed
if the file is present only on the upper layer, do not create a
whiteout when it is created.  Previously it was looking only at the
parent directory.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-03 16:11:45 +02:00
Giuseppe Scrivano
86b9cf5a83
writeback: restore suid mode after write
restore the inode mode if there is a writepage request that could
reset the setuid bit.

Closes: https://github.com/containers/fuse-overlayfs/issues/127

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-03 16:07:02 +02:00
Giuseppe Scrivano
163510e592
main: store the new mode after chmod
after a successful chmod, store the new mode for the ino.

Closes: https://github.com/containers/fuse-overlayfs/issues/124

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-02 14:22:13 +02:00
Giuseppe Scrivano
614f57d8f6
main: fix skip whiteout deletion optimization
fix the lookup function to report also a whiteout node, instead of
NULL.  This is required to correctly delete the whiteout file when it
exists.

Closes: https://github.com/containers/fuse-overlayfs/issues/122

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-09-23 22:35:02 +02:00
Giuseppe Scrivano
20e8529c4e
ioctl: do not reuse fi->fh for directories
for directories, it points to a structure, not an open file
descriptor.

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-09-23 22:34:20 +02:00
Giuseppe Scrivano
b0a9bdaa64
Merge pull request #120 from giuseppe/setattr-no-require-wronly
set_attrs: don't require write to S_IFREG
2019-09-18 13:27:51 +02:00
Nathaniel Wesley Filardo
69dcdb3af2
set_attrs: don't require write to S_IFREG
It's perfectly possible to set attributes by being the file's owner; one
does not need write access to the contents.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-09-13 15:06:14 +02:00
Tyler Ramer
4a9906739a Fix typo in set_limits
- Setting and getting nofile not process limits

Authored-by: Tyler Ramer <tramer@pivotal.io>
2019-09-11 09:17:37 -04:00
Giuseppe Scrivano
ed99282f27
main: check whether writeback is supported
disable writeback if it is not supported by FUSE.

Closes: https://github.com/containers/fuse-overlayfs/issues/116

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-09-09 17:58:26 +02:00
Giuseppe Scrivano
35499daa30
main: use st_dev for the ino key
when creating the key for the ino, also use the source st_dev.

Closes: https://github.com/containers/fuse-overlayfs/issues/112

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-08-29 23:21:44 +02:00
Giuseppe Scrivano
fc4115f5c4
main: avoid hash map lookup when possible
skip reading from the inodes hash table if the inode is already
known.

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-08-29 23:02:54 +02:00
Giuseppe Scrivano
7251f20c4b
main: correctly read inode for unix sockets
correctly read the inode when processing a UNIX socket.

regression introduced by b25bbde64dc5d06373e087d7fae6367acf1fd09e.

Closes: https://github.com/containers/fuse-overlayfs/issues/110

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-08-25 23:06:32 +02:00
Giuseppe Scrivano
b25bbde64d
main: introduce inodes cache
introduce a hash map to refer from an inode to the file paths.
A recent change where we enable FUSE writeback by default uncovered an
underlying issue in fuse-overlayfs where changes to a file with
multiple links would not be visible from the other link.

For each inode, maintain a list of nodes that refer to it, so that we
can still access it when a link is removed and more importantly we can
use the inode value with FUSE.

Closes: https://github.com/containers/fuse-overlayfs/issues/108
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1744109

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-08-23 15:27:12 +02:00
Giuseppe Scrivano
9e110ad55c
main, listxattr: open the file in read only mode
Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-08-15 23:14:25 +02:00
Giuseppe Scrivano
08136d8826
main: if the path is a dir, work on the proc path
when reading xattr, if the path cannot be open as it is a directory,
operate on the /proc/fd/FD path.

Closes: https://github.com/containers/fuse-overlayfs/issues/104

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2019-08-15 21:55:25 +02:00
Giuseppe Scrivano
3b27676c88
main: use cached st_mode
node already keeps st_mode in cache so there is no need of the
additional stat to find out the file type.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-08-11 23:44:57 +02:00
Giuseppe Scrivano
1faf62ce32
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>
2019-08-07 23:58:06 +02:00
Giuseppe Scrivano
5e325f7d9c
main: fix type for flistxattr return
the return type is ssize_t, not size_t.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-31 16:26:01 +02:00
Giuseppe Scrivano
56cc4d3d61
main: fix warnings reported by lgtm.com
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-29 13:36:07 +02:00
Giuseppe Scrivano
cf86b89adc
main: open the fd correctly for reading xattrs
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-29 13:35:23 +02:00
Giuseppe Scrivano
cecbcbb7ad
main: make sure the work directory is empty
make sure the work directory is empty when fuse-overlayfs starts.

Closes: https://github.com/containers/fuse-overlayfs/issues/93

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-29 13:35:22 +02:00
Giuseppe Scrivano
4e32e8907d
main: fix fd validity check
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-25 17:56:30 +02:00
Giuseppe Scrivano
45b8bb85d4
main, rename: use cleanup_close
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-25 17:50:58 +02:00