Skip to content

Commit

Permalink
Merge pull request #178 from giuseppe/not-override-ino
Browse files Browse the repository at this point in the history
main: lookup skip ino if there is no origin
  • Loading branch information
rhatdan authored Jan 31, 2020
2 parents 9076145 + 47cc3c2 commit 9266fca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
- docker
env:
- GOPATH=$HOME/go GOROOT=/usr/local/go GO=/usr/local/go/bin/go
- GOPATH=$HOME/go GOROOT=/usr/local/go GO=/usr/local/go/bin/go PATH=/usr/local/go/bin:$PATH
language: c
sudo: required
dist: xenial
Expand All @@ -26,13 +26,13 @@ addons:
before_install:
- docker pull fedora &
- docker build -t alpine-build -f Dockerfile.alpine .
- (wget https://dl.google.com/go/go1.10.8.linux-amd64.tar.gz && tar xf go1.10.8.linux-amd64.tar.gz && sudo mv go /usr/local)
- (wget https://dl.google.com/go/go1.13.7.linux-amd64.tar.gz && tar xf go1.13.7.linux-amd64.tar.gz && sudo mv go /usr/local)
- sudo mkdir -p /lower /upper /mnt
- (cd /; sudo git clone https://github.com/amir73il/unionmount-testsuite.git)
- (git clone --depth 1 git://github.com/ninja-build/ninja.git && cd ninja && python3.5 ./bootstrap.py && sudo cp ninja /usr/bin)
- (git clone --depth 1 -b 0.51.1 https://github.com/mesonbuild/meson.git; cd meson; sudo python3.5 ./setup.py install)
- (git clone --depth 1 https://github.com/sstephenson/bats.git; cd bats; sudo ./install.sh /usr/local)
- (go get github.com/containers/storage; cd $GOPATH/src/github.com/containers/storage; sed -i -e 's|^AUTOTAGS.*$|AUTOTAGS := exclude_graphdriver_devicemapper exclude_graphdriver_btrfs|' Makefile; make GO=$GO containers-storage)
- ($GO get github.com/containers/storage; cd $GOPATH/src/github.com/containers/storage; sed -i -e 's|^AUTOTAGS.*$|AUTOTAGS := exclude_graphdriver_devicemapper exclude_graphdriver_btrfs|' Makefile; make GO=$GO containers-storage)
- (wget https://github.com/libfuse/libfuse/releases/download/fuse-3.6.2/fuse-3.6.2.tar.xz; tar xf fuse-3.6.2.tar.xz; cd fuse-3.6.2; mkdir build; cd build; meson .. --prefix /usr && ninja && sudo ninja install)
script:
- ./autogen.sh || travis_terminate 1;
Expand Down
48 changes: 38 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* fuse-overlayfs: Overlay Filesystem in Userspace
Copyright (C) 2018 Giuseppe Scrivano <giuseppe@scrivano.org>
Copyright (C) 2018-2019 Red Hat Inc.
Copyright (C) 2018-2020 Red Hat Inc.
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -463,6 +463,22 @@ can_access_xattr (const char *name)
&& !has_prefix (name, PRIVILEGED_XATTR_PREFIX);
}

static int
set_fd_origin (int fd, const char *origin)
{
cleanup_close int opq_whiteout_fd = -1;
size_t len = strlen (origin) + 1;
int ret;

ret = fsetxattr (fd, ORIGIN_XATTR, origin, len, 0);
if (ret < 0)
{
if (errno == ENOTSUP)
return 0;
}
return ret;
}

static int
set_fd_opaque (int fd)
{
Expand Down Expand Up @@ -1153,6 +1169,7 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c
mode_t mode = 0;
char *new_name;
struct ovl_node *ret_xchg;
bool has_origin = true;
cleanup_node_init struct ovl_node *ret = NULL;

ret = calloc (1, sizeof (*ret));
Expand Down Expand Up @@ -1233,10 +1250,13 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c
{
if (it->ds->statat (it, npath, &st, AT_SYMLINK_NOFOLLOW, STATX_TYPE|STATX_MODE|STATX_INO) == 0)
{
ret->tmp_ino = st.st_ino;
ret->tmp_dev = st.st_dev;
if (mode == 0)
mode = st.st_mode;
if (has_origin)
{
ret->tmp_ino = st.st_ino;
ret->tmp_dev = st.st_dev;
if (mode == 0)
mode = st.st_mode;
}
ret->last_layer = it;
}
goto no_fd;
Expand All @@ -1245,10 +1265,13 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c
/* It is an open FD, stat the file and read the origin xattrs. */
if (it->ds->fstat (it, fd, npath, STATX_TYPE|STATX_MODE|STATX_INO, &st) == 0)
{
ret->tmp_ino = st.st_ino;
ret->tmp_dev = st.st_dev;
if (mode == 0)
mode = st.st_mode;
if (has_origin)
{
ret->tmp_ino = st.st_ino;
ret->tmp_dev = st.st_dev;
if (mode == 0)
mode = st.st_mode;
}
ret->last_layer = it;
}

Expand Down Expand Up @@ -1292,7 +1315,9 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c

/* If an origin is specified, use it for the next layer lookup. */
s = safe_read_xattr (&origin, fd, ORIGIN_XATTR, PATH_MAX);
if (s > 0)
if (s <= 0)
has_origin = false;
else
{
free (npath);
npath = origin;
Expand Down Expand Up @@ -2692,6 +2717,9 @@ copyup (struct ovl_data *lo, struct ovl_node *node)
if (ret < 0)
goto exit;

if (set_fd_origin (dfd, node->path) < 0)
goto exit;

/* Finally, move the file to its destination. */
ret = renameat (lo->workdir_fd, wd_tmp_file_name, get_upper_layer (lo)->fd, node->path);
if (ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ open_fd_or_get_path (struct ovl_layer *l, const char *path, char *out, int *fd,
out[0] = '\0';

*fd = l->ds->openat (l, path, O_NONBLOCK|O_NOFOLLOW|flags, 0755);
if (*fd < 0 && (errno == ELOOP || errno == EISDIR))
if (*fd < 0 && (errno == ELOOP || errno == EISDIR || errno == ENXIO))
{
strconcat3 (out, PATH_MAX, l->path, "/", path);
return 0;
Expand Down

0 comments on commit 9266fca

Please sign in to comment.