Commit 2c5ca23f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'ovl-update-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs

Pull overlayfs updates from Miklos Szeredi:

 - Support idmapped layers in overlayfs (Christian Brauner)

 - Add a fix to exportfs that is relevant to open_by_handle_at(2) as
   well

 - Introduce new lookup helpers that allow passing mnt_userns into
   inode_permission()

* tag 'ovl-update-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs:
  ovl: support idmapped layers
  ovl: handle idmappings in ovl_xattr_{g,s}et()
  ovl: handle idmappings in layer open helpers
  ovl: handle idmappings in ovl_permission()
  ovl: use ovl_copy_{real,upper}attr() wrappers
  ovl: store lower path in ovl_inode
  ovl: handle idmappings for layer lookup
  ovl: handle idmappings for layer fileattrs
  ovl: use ovl_path_getxattr() wrapper
  ovl: use ovl_lookup_upper() wrapper
  ovl: use ovl_do_notify_change() wrapper
  ovl: pass layer mnt to ovl_open_realfile()
  ovl: pass ofs to setattr operations
  ovl: handle idmappings in creation operations
  ovl: add ovl_upper_mnt_userns() wrapper
  ovl: pass ofs to creation operations
  ovl: use wrappers to all vfs_*xattr() calls
  exportfs: support idmapped mounts
  fs: add two trivial lookup helpers
parents 73d15ba6 bc70682a
...@@ -145,7 +145,7 @@ static struct dentry *reconnect_one(struct vfsmount *mnt, ...@@ -145,7 +145,7 @@ static struct dentry *reconnect_one(struct vfsmount *mnt,
if (err) if (err)
goto out_err; goto out_err;
dprintk("%s: found name: %s\n", __func__, nbuf); dprintk("%s: found name: %s\n", __func__, nbuf);
tmp = lookup_one_len_unlocked(nbuf, parent, strlen(nbuf)); tmp = lookup_one_unlocked(mnt_user_ns(mnt), nbuf, parent, strlen(nbuf));
if (IS_ERR(tmp)) { if (IS_ERR(tmp)) {
dprintk("%s: lookup failed: %d\n", __func__, PTR_ERR(tmp)); dprintk("%s: lookup failed: %d\n", __func__, PTR_ERR(tmp));
err = PTR_ERR(tmp); err = PTR_ERR(tmp);
...@@ -525,7 +525,8 @@ exportfs_decode_fh_raw(struct vfsmount *mnt, struct fid *fid, int fh_len, ...@@ -525,7 +525,8 @@ exportfs_decode_fh_raw(struct vfsmount *mnt, struct fid *fid, int fh_len,
} }
inode_lock(target_dir->d_inode); inode_lock(target_dir->d_inode);
nresult = lookup_one_len(nbuf, target_dir, strlen(nbuf)); nresult = lookup_one(mnt_user_ns(mnt), nbuf,
target_dir, strlen(nbuf));
if (!IS_ERR(nresult)) { if (!IS_ERR(nresult)) {
if (unlikely(nresult->d_inode != result->d_inode)) { if (unlikely(nresult->d_inode != result->d_inode)) {
dput(nresult); dput(nresult);
......
...@@ -2769,7 +2769,8 @@ struct dentry *lookup_one(struct user_namespace *mnt_userns, const char *name, ...@@ -2769,7 +2769,8 @@ struct dentry *lookup_one(struct user_namespace *mnt_userns, const char *name,
EXPORT_SYMBOL(lookup_one); EXPORT_SYMBOL(lookup_one);
/** /**
* lookup_one_len_unlocked - filesystem helper to lookup single pathname component * lookup_one_unlocked - filesystem helper to lookup single pathname component
* @mnt_userns: idmapping of the mount the lookup is performed from
* @name: pathname component to lookup * @name: pathname component to lookup
* @base: base directory to lookup from * @base: base directory to lookup from
* @len: maximum length @len should be interpreted to * @len: maximum length @len should be interpreted to
...@@ -2780,14 +2781,15 @@ EXPORT_SYMBOL(lookup_one); ...@@ -2780,14 +2781,15 @@ EXPORT_SYMBOL(lookup_one);
* Unlike lookup_one_len, it should be called without the parent * Unlike lookup_one_len, it should be called without the parent
* i_mutex held, and will take the i_mutex itself if necessary. * i_mutex held, and will take the i_mutex itself if necessary.
*/ */
struct dentry *lookup_one_len_unlocked(const char *name, struct dentry *lookup_one_unlocked(struct user_namespace *mnt_userns,
struct dentry *base, int len) const char *name, struct dentry *base,
int len)
{ {
struct qstr this; struct qstr this;
int err; int err;
struct dentry *ret; struct dentry *ret;
err = lookup_one_common(&init_user_ns, name, base, len, &this); err = lookup_one_common(mnt_userns, name, base, len, &this);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
...@@ -2796,6 +2798,59 @@ struct dentry *lookup_one_len_unlocked(const char *name, ...@@ -2796,6 +2798,59 @@ struct dentry *lookup_one_len_unlocked(const char *name,
ret = lookup_slow(&this, base, 0); ret = lookup_slow(&this, base, 0);
return ret; return ret;
} }
EXPORT_SYMBOL(lookup_one_unlocked);
/**
* lookup_one_positive_unlocked - filesystem helper to lookup single
* pathname component
* @mnt_userns: idmapping of the mount the lookup is performed from
* @name: pathname component to lookup
* @base: base directory to lookup from
* @len: maximum length @len should be interpreted to
*
* This helper will yield ERR_PTR(-ENOENT) on negatives. The helper returns
* known positive or ERR_PTR(). This is what most of the users want.
*
* Note that pinned negative with unlocked parent _can_ become positive at any
* time, so callers of lookup_one_unlocked() need to be very careful; pinned
* positives have >d_inode stable, so this one avoids such problems.
*
* Note that this routine is purely a helper for filesystem usage and should
* not be called by generic code.
*
* The helper should be called without i_mutex held.
*/
struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
const char *name,
struct dentry *base, int len)
{
struct dentry *ret = lookup_one_unlocked(mnt_userns, name, base, len);
if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) {
dput(ret);
ret = ERR_PTR(-ENOENT);
}
return ret;
}
EXPORT_SYMBOL(lookup_one_positive_unlocked);
/**
* lookup_one_len_unlocked - filesystem helper to lookup single pathname component
* @name: pathname component to lookup
* @base: base directory to lookup from
* @len: maximum length @len should be interpreted to
*
* Note that this routine is purely a helper for filesystem usage and should
* not be called by generic code.
*
* Unlike lookup_one_len, it should be called without the parent
* i_mutex held, and will take the i_mutex itself if necessary.
*/
struct dentry *lookup_one_len_unlocked(const char *name,
struct dentry *base, int len)
{
return lookup_one_unlocked(&init_user_ns, name, base, len);
}
EXPORT_SYMBOL(lookup_one_len_unlocked); EXPORT_SYMBOL(lookup_one_len_unlocked);
/* /*
...@@ -2809,12 +2864,7 @@ EXPORT_SYMBOL(lookup_one_len_unlocked); ...@@ -2809,12 +2864,7 @@ EXPORT_SYMBOL(lookup_one_len_unlocked);
struct dentry *lookup_positive_unlocked(const char *name, struct dentry *lookup_positive_unlocked(const char *name,
struct dentry *base, int len) struct dentry *base, int len)
{ {
struct dentry *ret = lookup_one_len_unlocked(name, base, len); return lookup_one_positive_unlocked(&init_user_ns, name, base, len);
if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) {
dput(ret);
ret = ERR_PTR(-ENOENT);
}
return ret;
} }
EXPORT_SYMBOL(lookup_positive_unlocked); EXPORT_SYMBOL(lookup_positive_unlocked);
......
This diff is collapsed.
This diff is collapsed.
...@@ -391,6 +391,11 @@ static struct dentry *ovl_lookup_real_one(struct dentry *connected, ...@@ -391,6 +391,11 @@ static struct dentry *ovl_lookup_real_one(struct dentry *connected,
* pointer because we hold no lock on the real dentry. * pointer because we hold no lock on the real dentry.
*/ */
take_dentry_name_snapshot(&name, real); take_dentry_name_snapshot(&name, real);
/*
* No mnt_userns handling here: it's an internal lookup. Could skip
* permission checking altogether, but for now just use non-mnt_userns
* transformed ids.
*/
this = lookup_one_len(name.name.name, connected, name.name.len); this = lookup_one_len(name.name.name, connected, name.name.len);
release_dentry_name_snapshot(&name); release_dentry_name_snapshot(&name);
err = PTR_ERR(this); err = PTR_ERR(this);
......
...@@ -38,9 +38,11 @@ static char ovl_whatisit(struct inode *inode, struct inode *realinode) ...@@ -38,9 +38,11 @@ static char ovl_whatisit(struct inode *inode, struct inode *realinode)
#define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY) #define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY)
static struct file *ovl_open_realfile(const struct file *file, static struct file *ovl_open_realfile(const struct file *file,
struct inode *realinode) struct path *realpath)
{ {
struct inode *realinode = d_inode(realpath->dentry);
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct user_namespace *real_mnt_userns;
struct file *realfile; struct file *realfile;
const struct cred *old_cred; const struct cred *old_cred;
int flags = file->f_flags | OVL_OPEN_FLAGS; int flags = file->f_flags | OVL_OPEN_FLAGS;
...@@ -51,11 +53,12 @@ static struct file *ovl_open_realfile(const struct file *file, ...@@ -51,11 +53,12 @@ static struct file *ovl_open_realfile(const struct file *file,
acc_mode |= MAY_APPEND; acc_mode |= MAY_APPEND;
old_cred = ovl_override_creds(inode->i_sb); old_cred = ovl_override_creds(inode->i_sb);
err = inode_permission(&init_user_ns, realinode, MAY_OPEN | acc_mode); real_mnt_userns = mnt_user_ns(realpath->mnt);
err = inode_permission(real_mnt_userns, realinode, MAY_OPEN | acc_mode);
if (err) { if (err) {
realfile = ERR_PTR(err); realfile = ERR_PTR(err);
} else { } else {
if (!inode_owner_or_capable(&init_user_ns, realinode)) if (!inode_owner_or_capable(real_mnt_userns, realinode))
flags &= ~O_NOATIME; flags &= ~O_NOATIME;
realfile = open_with_fake_path(&file->f_path, flags, realinode, realfile = open_with_fake_path(&file->f_path, flags, realinode,
...@@ -101,21 +104,21 @@ static int ovl_change_flags(struct file *file, unsigned int flags) ...@@ -101,21 +104,21 @@ static int ovl_change_flags(struct file *file, unsigned int flags)
static int ovl_real_fdget_meta(const struct file *file, struct fd *real, static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
bool allow_meta) bool allow_meta)
{ {
struct inode *inode = file_inode(file); struct dentry *dentry = file_dentry(file);
struct inode *realinode; struct path realpath;
real->flags = 0; real->flags = 0;
real->file = file->private_data; real->file = file->private_data;
if (allow_meta) if (allow_meta)
realinode = ovl_inode_real(inode); ovl_path_real(dentry, &realpath);
else else
realinode = ovl_inode_realdata(inode); ovl_path_realdata(dentry, &realpath);
/* Has it been copied up since we'd opened it? */ /* Has it been copied up since we'd opened it? */
if (unlikely(file_inode(real->file) != realinode)) { if (unlikely(file_inode(real->file) != d_inode(realpath.dentry))) {
real->flags = FDPUT_FPUT; real->flags = FDPUT_FPUT;
real->file = ovl_open_realfile(file, realinode); real->file = ovl_open_realfile(file, &realpath);
return PTR_ERR_OR_ZERO(real->file); return PTR_ERR_OR_ZERO(real->file);
} }
...@@ -141,17 +144,20 @@ static int ovl_real_fdget(const struct file *file, struct fd *real) ...@@ -141,17 +144,20 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)
static int ovl_open(struct inode *inode, struct file *file) static int ovl_open(struct inode *inode, struct file *file)
{ {
struct dentry *dentry = file_dentry(file);
struct file *realfile; struct file *realfile;
struct path realpath;
int err; int err;
err = ovl_maybe_copy_up(file_dentry(file), file->f_flags); err = ovl_maybe_copy_up(dentry, file->f_flags);
if (err) if (err)
return err; return err;
/* No longer need these flags, so don't pass them on to underlying fs */ /* No longer need these flags, so don't pass them on to underlying fs */
file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
realfile = ovl_open_realfile(file, ovl_inode_realdata(inode)); ovl_path_realdata(dentry, &realpath);
realfile = ovl_open_realfile(file, &realpath);
if (IS_ERR(realfile)) if (IS_ERR(realfile))
return PTR_ERR(realfile); return PTR_ERR(realfile);
...@@ -270,7 +276,7 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req) ...@@ -270,7 +276,7 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)
__sb_writers_acquired(file_inode(iocb->ki_filp)->i_sb, __sb_writers_acquired(file_inode(iocb->ki_filp)->i_sb,
SB_FREEZE_WRITE); SB_FREEZE_WRITE);
file_end_write(iocb->ki_filp); file_end_write(iocb->ki_filp);
ovl_copyattr(ovl_inode_real(inode), inode); ovl_copyattr(inode);
} }
orig_iocb->ki_pos = iocb->ki_pos; orig_iocb->ki_pos = iocb->ki_pos;
...@@ -352,7 +358,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) ...@@ -352,7 +358,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
inode_lock(inode); inode_lock(inode);
/* Update mode */ /* Update mode */
ovl_copyattr(ovl_inode_real(inode), inode); ovl_copyattr(inode);
ret = file_remove_privs(file); ret = file_remove_privs(file);
if (ret) if (ret)
goto out_unlock; goto out_unlock;
...@@ -376,7 +382,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) ...@@ -376,7 +382,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
ovl_iocb_to_rwf(ifl)); ovl_iocb_to_rwf(ifl));
file_end_write(real.file); file_end_write(real.file);
/* Update size */ /* Update size */
ovl_copyattr(ovl_inode_real(inode), inode); ovl_copyattr(inode);
} else { } else {
struct ovl_aio_req *aio_req; struct ovl_aio_req *aio_req;
...@@ -426,12 +432,11 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, ...@@ -426,12 +432,11 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
struct fd real; struct fd real;
const struct cred *old_cred; const struct cred *old_cred;
struct inode *inode = file_inode(out); struct inode *inode = file_inode(out);
struct inode *realinode = ovl_inode_real(inode);
ssize_t ret; ssize_t ret;
inode_lock(inode); inode_lock(inode);
/* Update mode */ /* Update mode */
ovl_copyattr(realinode, inode); ovl_copyattr(inode);
ret = file_remove_privs(out); ret = file_remove_privs(out);
if (ret) if (ret)
goto out_unlock; goto out_unlock;
...@@ -447,7 +452,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, ...@@ -447,7 +452,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
file_end_write(real.file); file_end_write(real.file);
/* Update size */ /* Update size */
ovl_copyattr(realinode, inode); ovl_copyattr(inode);
revert_creds(old_cred); revert_creds(old_cred);
fdput(real); fdput(real);
...@@ -521,7 +526,7 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len ...@@ -521,7 +526,7 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
revert_creds(old_cred); revert_creds(old_cred);
/* Update size */ /* Update size */
ovl_copyattr(ovl_inode_real(inode), inode); ovl_copyattr(inode);
fdput(real); fdput(real);
...@@ -593,7 +598,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, ...@@ -593,7 +598,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
revert_creds(old_cred); revert_creds(old_cred);
/* Update size */ /* Update size */
ovl_copyattr(ovl_inode_real(inode_out), inode_out); ovl_copyattr(inode_out);
fdput(real_in); fdput(real_in);
fdput(real_out); fdput(real_out);
......
...@@ -21,6 +21,7 @@ int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, ...@@ -21,6 +21,7 @@ int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
struct iattr *attr) struct iattr *attr)
{ {
int err; int err;
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
bool full_copy_up = false; bool full_copy_up = false;
struct dentry *upperdentry; struct dentry *upperdentry;
const struct cred *old_cred; const struct cred *old_cred;
...@@ -77,10 +78,10 @@ int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, ...@@ -77,10 +78,10 @@ int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
inode_lock(upperdentry->d_inode); inode_lock(upperdentry->d_inode);
old_cred = ovl_override_creds(dentry->d_sb); old_cred = ovl_override_creds(dentry->d_sb);
err = notify_change(&init_user_ns, upperdentry, attr, NULL); err = ovl_do_notify_change(ofs, upperdentry, attr);
revert_creds(old_cred); revert_creds(old_cred);
if (!err) if (!err)
ovl_copyattr(upperdentry->d_inode, dentry->d_inode); ovl_copyattr(dentry->d_inode);
inode_unlock(upperdentry->d_inode); inode_unlock(upperdentry->d_inode);
if (winode) if (winode)
...@@ -279,12 +280,14 @@ int ovl_permission(struct user_namespace *mnt_userns, ...@@ -279,12 +280,14 @@ int ovl_permission(struct user_namespace *mnt_userns,
struct inode *inode, int mask) struct inode *inode, int mask)
{ {
struct inode *upperinode = ovl_inode_upper(inode); struct inode *upperinode = ovl_inode_upper(inode);
struct inode *realinode = upperinode ?: ovl_inode_lower(inode); struct inode *realinode;
struct path realpath;
const struct cred *old_cred; const struct cred *old_cred;
int err; int err;
/* Careful in RCU walk mode */ /* Careful in RCU walk mode */
if (!realinode) { ovl_i_path_real(inode, &realpath);
if (!realpath.dentry) {
WARN_ON(!(mask & MAY_NOT_BLOCK)); WARN_ON(!(mask & MAY_NOT_BLOCK));
return -ECHILD; return -ECHILD;
} }
...@@ -297,6 +300,7 @@ int ovl_permission(struct user_namespace *mnt_userns, ...@@ -297,6 +300,7 @@ int ovl_permission(struct user_namespace *mnt_userns,
if (err) if (err)
return err; return err;
realinode = d_inode(realpath.dentry);
old_cred = ovl_override_creds(inode->i_sb); old_cred = ovl_override_creds(inode->i_sb);
if (!upperinode && if (!upperinode &&
!special_file(realinode->i_mode) && mask & MAY_WRITE) { !special_file(realinode->i_mode) && mask & MAY_WRITE) {
...@@ -304,7 +308,7 @@ int ovl_permission(struct user_namespace *mnt_userns, ...@@ -304,7 +308,7 @@ int ovl_permission(struct user_namespace *mnt_userns,
/* Make sure mounter can read file for copy up later */ /* Make sure mounter can read file for copy up later */
mask |= MAY_READ; mask |= MAY_READ;
} }
err = inode_permission(&init_user_ns, realinode, mask); err = inode_permission(mnt_user_ns(realpath.mnt), realinode, mask);
revert_creds(old_cred); revert_creds(old_cred);
return err; return err;
...@@ -342,8 +346,10 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, ...@@ -342,8 +346,10 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
int err; int err;
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
struct dentry *upperdentry = ovl_i_dentry_upper(inode); struct dentry *upperdentry = ovl_i_dentry_upper(inode);
struct dentry *realdentry = upperdentry ?: ovl_dentry_lower(dentry); struct dentry *realdentry = upperdentry ?: ovl_dentry_lower(dentry);
struct path realpath;
const struct cred *old_cred; const struct cred *old_cred;
err = ovl_want_write(dentry); err = ovl_want_write(dentry);
...@@ -351,8 +357,9 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, ...@@ -351,8 +357,9 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
goto out; goto out;
if (!value && !upperdentry) { if (!value && !upperdentry) {
ovl_path_lower(dentry, &realpath);
old_cred = ovl_override_creds(dentry->d_sb); old_cred = ovl_override_creds(dentry->d_sb);
err = vfs_getxattr(&init_user_ns, realdentry, name, NULL, 0); err = vfs_getxattr(mnt_user_ns(realpath.mnt), realdentry, name, NULL, 0);
revert_creds(old_cred); revert_creds(old_cred);
if (err < 0) if (err < 0)
goto out_drop_write; goto out_drop_write;
...@@ -367,17 +374,17 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, ...@@ -367,17 +374,17 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
} }
old_cred = ovl_override_creds(dentry->d_sb); old_cred = ovl_override_creds(dentry->d_sb);
if (value) if (value) {
err = vfs_setxattr(&init_user_ns, realdentry, name, value, size, err = ovl_do_setxattr(ofs, realdentry, name, value, size,
flags); flags);
else { } else {
WARN_ON(flags != XATTR_REPLACE); WARN_ON(flags != XATTR_REPLACE);
err = vfs_removexattr(&init_user_ns, realdentry, name); err = ovl_do_removexattr(ofs, realdentry, name);
} }
revert_creds(old_cred); revert_creds(old_cred);
/* copy c/mtime */ /* copy c/mtime */
ovl_copyattr(d_inode(realdentry), inode); ovl_copyattr(inode);
out_drop_write: out_drop_write:
ovl_drop_write(dentry); ovl_drop_write(dentry);
...@@ -390,11 +397,11 @@ int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, ...@@ -390,11 +397,11 @@ int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
{ {
ssize_t res; ssize_t res;
const struct cred *old_cred; const struct cred *old_cred;
struct dentry *realdentry = struct path realpath;
ovl_i_dentry_upper(inode) ?: ovl_dentry_lower(dentry);
ovl_i_path_real(inode, &realpath);
old_cred = ovl_override_creds(dentry->d_sb); old_cred = ovl_override_creds(dentry->d_sb);
res = vfs_getxattr(&init_user_ns, realdentry, name, value, size); res = vfs_getxattr(mnt_user_ns(realpath.mnt), realpath.dentry, name, value, size);
revert_creds(old_cred); revert_creds(old_cred);
return res; return res;
} }
...@@ -535,7 +542,7 @@ int ovl_real_fileattr_set(struct path *realpath, struct fileattr *fa) ...@@ -535,7 +542,7 @@ int ovl_real_fileattr_set(struct path *realpath, struct fileattr *fa)
if (err) if (err)
return err; return err;
return vfs_fileattr_set(&init_user_ns, realpath->dentry, fa); return vfs_fileattr_set(mnt_user_ns(realpath->mnt), realpath->dentry, fa);
} }
int ovl_fileattr_set(struct user_namespace *mnt_userns, int ovl_fileattr_set(struct user_namespace *mnt_userns,
...@@ -579,7 +586,7 @@ int ovl_fileattr_set(struct user_namespace *mnt_userns, ...@@ -579,7 +586,7 @@ int ovl_fileattr_set(struct user_namespace *mnt_userns,
inode_set_flags(inode, flags, OVL_COPY_I_FLAGS_MASK); inode_set_flags(inode, flags, OVL_COPY_I_FLAGS_MASK);
/* Update ctime */ /* Update ctime */
ovl_copyattr(ovl_inode_real(inode), inode); ovl_copyattr(inode);
} }
ovl_drop_write(dentry); ovl_drop_write(dentry);
out: out:
...@@ -777,16 +784,19 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, ...@@ -777,16 +784,19 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
unsigned long ino, int fsid) unsigned long ino, int fsid)
{ {
struct inode *realinode; struct inode *realinode;
struct ovl_inode *oi = OVL_I(inode);
if (oip->upperdentry) if (oip->upperdentry)
OVL_I(inode)->__upperdentry = oip->upperdentry; oi->__upperdentry = oip->upperdentry;
if (oip->lowerpath && oip->lowerpath->dentry) if (oip->lowerpath && oip->lowerpath->dentry) {
OVL_I(inode)->lower = igrab(d_inode(oip->lowerpath->dentry)); oi->lowerpath.dentry = dget(oip->lowerpath->dentry);
oi->lowerpath.layer = oip->lowerpath->layer;
}
if (oip->lowerdata) if (oip->lowerdata)
OVL_I(inode)->lowerdata = igrab(d_inode(oip->lowerdata)); oi->lowerdata = igrab(d_inode(oip->lowerdata));
realinode = ovl_inode_real(inode); realinode = ovl_inode_real(inode);
ovl_copyattr(realinode, inode); ovl_copyattr(inode);
ovl_copyflags(realinode, inode); ovl_copyflags(realinode, inode);
ovl_map_ino(inode, ino, fsid); ovl_map_ino(inode, ino, fsid);
} }
...@@ -871,8 +881,8 @@ static int ovl_set_nlink_common(struct dentry *dentry, ...@@ -871,8 +881,8 @@ static int ovl_set_nlink_common(struct dentry *dentry,
if (WARN_ON(len >= sizeof(buf))) if (WARN_ON(len >= sizeof(buf)))
return -EIO; return -EIO;
return ovl_do_setxattr(OVL_FS(inode->i_sb), ovl_dentry_upper(dentry), return ovl_setxattr(OVL_FS(inode->i_sb), ovl_dentry_upper(dentry),
OVL_XATTR_NLINK, buf, len); OVL_XATTR_NLINK, buf, len);
} }
int ovl_set_nlink_upper(struct dentry *dentry) int ovl_set_nlink_upper(struct dentry *dentry)
...@@ -897,8 +907,8 @@ unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry, ...@@ -897,8 +907,8 @@ unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,
if (!lowerdentry || !upperdentry || d_inode(lowerdentry)->i_nlink == 1) if (!lowerdentry || !upperdentry || d_inode(lowerdentry)->i_nlink == 1)
return fallback; return fallback;
err = ovl_do_getxattr(ofs, upperdentry, OVL_XATTR_NLINK, err = ovl_getxattr_upper(ofs, upperdentry, OVL_XATTR_NLINK,
&buf, sizeof(buf) - 1); &buf, sizeof(buf) - 1);
if (err < 0) if (err < 0)
goto fail; goto fail;
...@@ -1102,6 +1112,10 @@ struct inode *ovl_get_inode(struct super_block *sb, ...@@ -1102,6 +1112,10 @@ struct inode *ovl_get_inode(struct super_block *sb,
struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL; struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL;
struct inode *inode; struct inode *inode;
struct dentry *lowerdentry = lowerpath ? lowerpath->dentry : NULL; struct dentry *lowerdentry = lowerpath ? lowerpath->dentry : NULL;
struct path realpath = {
.dentry = upperdentry ?: lowerdentry,
.mnt = upperdentry ? ovl_upper_mnt(ofs) : lowerpath->layer->mnt,
};
bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry, bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry,
oip->index); oip->index);
int fsid = bylower ? lowerpath->layer->fsid : 0; int fsid = bylower ? lowerpath->layer->fsid : 0;
...@@ -1175,7 +1189,7 @@ struct inode *ovl_get_inode(struct super_block *sb, ...@@ -1175,7 +1189,7 @@ struct inode *ovl_get_inode(struct super_block *sb,
/* Check for non-merge dir that may have whiteouts */ /* Check for non-merge dir that may have whiteouts */
if (is_dir) { if (is_dir) {
if (((upperdentry && lowerdentry) || oip->numlower > 1) || if (((upperdentry && lowerdentry) || oip->numlower > 1) ||
ovl_check_origin_xattr(ofs, upperdentry ?: lowerdentry)) { ovl_path_check_origin_xattr(ofs, &realpath)) {
ovl_set_flag(OVL_WHITEOUTS, inode); ovl_set_flag(OVL_WHITEOUTS, inode);
} }
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
struct ovl_lookup_data { struct ovl_lookup_data {
struct super_block *sb; struct super_block *sb;
struct vfsmount *mnt;
struct qstr name; struct qstr name;
bool is_dir; bool is_dir;
bool opaque; bool opaque;
...@@ -25,14 +26,14 @@ struct ovl_lookup_data { ...@@ -25,14 +26,14 @@ struct ovl_lookup_data {
bool metacopy; bool metacopy;
}; };
static int ovl_check_redirect(struct dentry *dentry, struct ovl_lookup_data *d, static int ovl_check_redirect(struct path *path, struct ovl_lookup_data *d,
size_t prelen, const char *post) size_t prelen, const char *post)
{ {
int res; int res;
char *buf; char *buf;
struct ovl_fs *ofs = OVL_FS(d->sb); struct ovl_fs *ofs = OVL_FS(d->sb);
buf = ovl_get_redirect_xattr(ofs, dentry, prelen + strlen(post)); buf = ovl_get_redirect_xattr(ofs, path, prelen + strlen(post));
if (IS_ERR_OR_NULL(buf)) if (IS_ERR_OR_NULL(buf))
return PTR_ERR(buf); return PTR_ERR(buf);
...@@ -105,13 +106,13 @@ int ovl_check_fb_len(struct ovl_fb *fb, int fb_len) ...@@ -105,13 +106,13 @@ int ovl_check_fb_len(struct ovl_fb *fb, int fb_len)
return 0; return 0;
} }
static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *dentry, static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *upperdentry,
enum ovl_xattr ox) enum ovl_xattr ox)
{ {
int res, err; int res, err;
struct ovl_fh *fh = NULL; struct ovl_fh *fh = NULL;
res = ovl_do_getxattr(ofs, dentry, ox, NULL, 0); res = ovl_getxattr_upper(ofs, upperdentry, ox, NULL, 0);
if (res < 0) { if (res < 0) {
if (res == -ENODATA || res == -EOPNOTSUPP) if (res == -ENODATA || res == -EOPNOTSUPP)
return NULL; return NULL;
...@@ -125,7 +126,7 @@ static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *dentry, ...@@ -125,7 +126,7 @@ static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *dentry,
if (!fh) if (!fh)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
res = ovl_do_getxattr(ofs, dentry, ox, fh->buf, res); res = ovl_getxattr_upper(ofs, upperdentry, ox, fh->buf, res);
if (res < 0) if (res < 0)
goto fail; goto fail;
...@@ -193,16 +194,17 @@ struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh, ...@@ -193,16 +194,17 @@ struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
return real; return real;
} }
static bool ovl_is_opaquedir(struct super_block *sb, struct dentry *dentry) static bool ovl_is_opaquedir(struct ovl_fs *ofs, struct path *path)
{ {
return ovl_check_dir_xattr(sb, dentry, OVL_XATTR_OPAQUE); return ovl_path_check_dir_xattr(ofs, path, OVL_XATTR_OPAQUE);
} }
static struct dentry *ovl_lookup_positive_unlocked(const char *name, static struct dentry *ovl_lookup_positive_unlocked(struct ovl_lookup_data *d,
const char *name,
struct dentry *base, int len, struct dentry *base, int len,
bool drop_negative) bool drop_negative)
{ {
struct dentry *ret = lookup_one_len_unlocked(name, base, len); struct dentry *ret = lookup_one_unlocked(mnt_user_ns(d->mnt), name, base, len);
if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) {
if (drop_negative && ret->d_lockref.count == 1) { if (drop_negative && ret->d_lockref.count == 1) {
...@@ -224,10 +226,11 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d, ...@@ -224,10 +226,11 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
struct dentry **ret, bool drop_negative) struct dentry **ret, bool drop_negative)
{ {
struct dentry *this; struct dentry *this;
struct path path;
int err; int err;
bool last_element = !post[0]; bool last_element = !post[0];
this = ovl_lookup_positive_unlocked(name, base, namelen, drop_negative); this = ovl_lookup_positive_unlocked(d, name, base, namelen, drop_negative);
if (IS_ERR(this)) { if (IS_ERR(this)) {
err = PTR_ERR(this); err = PTR_ERR(this);
this = NULL; this = NULL;
...@@ -253,12 +256,15 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d, ...@@ -253,12 +256,15 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
d->stop = true; d->stop = true;
goto put_and_out; goto put_and_out;
} }
path.dentry = this;
path.mnt = d->mnt;
if (!d_can_lookup(this)) { if (!d_can_lookup(this)) {
if (d->is_dir || !last_element) { if (d->is_dir || !last_element) {
d->stop = true; d->stop = true;
goto put_and_out; goto put_and_out;
} }
err = ovl_check_metacopy_xattr(OVL_FS(d->sb), this); err = ovl_check_metacopy_xattr(OVL_FS(d->sb), &path);
if (err < 0) if (err < 0)
goto out_err; goto out_err;
...@@ -278,14 +284,14 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d, ...@@ -278,14 +284,14 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
if (d->last) if (d->last)
goto out; goto out;
if (ovl_is_opaquedir(d->sb, this)) { if (ovl_is_opaquedir(OVL_FS(d->sb), &path)) {
d->stop = true; d->stop = true;
if (last_element) if (last_element)
d->opaque = true; d->opaque = true;
goto out; goto out;
} }
} }
err = ovl_check_redirect(this, d, prelen, post); err = ovl_check_redirect(&path, d, prelen, post);
if (err) if (err)
goto out_err; goto out_err;
out: out:
...@@ -464,7 +470,7 @@ int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry, ...@@ -464,7 +470,7 @@ int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
err = ovl_verify_fh(ofs, dentry, ox, fh); err = ovl_verify_fh(ofs, dentry, ox, fh);
if (set && err == -ENODATA) if (set && err == -ENODATA)
err = ovl_do_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len); err = ovl_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len);
if (err) if (err)
goto fail; goto fail;
...@@ -704,7 +710,8 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, ...@@ -704,7 +710,8 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); index = lookup_one_positive_unlocked(ovl_upper_mnt_userns(ofs), name.name,
ofs->indexdir, name.len);
if (IS_ERR(index)) { if (IS_ERR(index)) {
err = PTR_ERR(index); err = PTR_ERR(index);
if (err == -ENOENT) { if (err == -ENOENT) {
...@@ -856,6 +863,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, ...@@ -856,6 +863,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
old_cred = ovl_override_creds(dentry->d_sb); old_cred = ovl_override_creds(dentry->d_sb);
upperdir = ovl_dentry_upper(dentry->d_parent); upperdir = ovl_dentry_upper(dentry->d_parent);
if (upperdir) { if (upperdir) {
d.mnt = ovl_upper_mnt(ofs);
err = ovl_lookup_layer(upperdir, &d, &upperdentry, true); err = ovl_lookup_layer(upperdir, &d, &upperdentry, true);
if (err) if (err)
goto out; goto out;
...@@ -911,6 +919,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, ...@@ -911,6 +919,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
else else
d.last = lower.layer->idx == roe->numlower; d.last = lower.layer->idx == roe->numlower;
d.mnt = lower.layer->mnt;
err = ovl_lookup_layer(lower.dentry, &d, &this, false); err = ovl_lookup_layer(lower.dentry, &d, &this, false);
if (err) if (err)
goto out_put; goto out_put;
...@@ -1071,14 +1080,18 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, ...@@ -1071,14 +1080,18 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
if (upperdentry) if (upperdentry)
ovl_dentry_set_upper_alias(dentry); ovl_dentry_set_upper_alias(dentry);
else if (index) { else if (index) {
upperdentry = dget(index); struct path upperpath = {
upperredirect = ovl_get_redirect_xattr(ofs, upperdentry, 0); .dentry = upperdentry = dget(index),
.mnt = ovl_upper_mnt(ofs),
};
upperredirect = ovl_get_redirect_xattr(ofs, &upperpath, 0);
if (IS_ERR(upperredirect)) { if (IS_ERR(upperredirect)) {
err = PTR_ERR(upperredirect); err = PTR_ERR(upperredirect);
upperredirect = NULL; upperredirect = NULL;
goto out_free_oe; goto out_free_oe;
} }
err = ovl_check_metacopy_xattr(ofs, upperdentry); err = ovl_check_metacopy_xattr(ofs, &upperpath);
if (err < 0) if (err < 0)
goto out_free_oe; goto out_free_oe;
uppermetacopy = err; uppermetacopy = err;
...@@ -1163,8 +1176,8 @@ bool ovl_lower_positive(struct dentry *dentry) ...@@ -1163,8 +1176,8 @@ bool ovl_lower_positive(struct dentry *dentry)
struct dentry *this; struct dentry *this;
struct dentry *lowerdir = poe->lowerstack[i].dentry; struct dentry *lowerdir = poe->lowerstack[i].dentry;
this = lookup_positive_unlocked(name->name, lowerdir, this = lookup_one_positive_unlocked(mnt_user_ns(poe->lowerstack[i].layer->mnt),
name->len); name->name, lowerdir, name->len);
if (IS_ERR(this)) { if (IS_ERR(this)) {
switch (PTR_ERR(this)) { switch (PTR_ERR(this)) {
case -ENOENT: case -ENOENT:
......
This diff is collapsed.
...@@ -90,6 +90,11 @@ static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) ...@@ -90,6 +90,11 @@ static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
return ofs->layers[0].mnt; return ofs->layers[0].mnt;
} }
static inline struct user_namespace *ovl_upper_mnt_userns(struct ovl_fs *ofs)
{
return mnt_user_ns(ovl_upper_mnt(ofs));
}
static inline struct ovl_fs *OVL_FS(struct super_block *sb) static inline struct ovl_fs *OVL_FS(struct super_block *sb)
{ {
return (struct ovl_fs *)sb->s_fs_info; return (struct ovl_fs *)sb->s_fs_info;
...@@ -129,7 +134,7 @@ struct ovl_inode { ...@@ -129,7 +134,7 @@ struct ovl_inode {
unsigned long flags; unsigned long flags;
struct inode vfs_inode; struct inode vfs_inode;
struct dentry *__upperdentry; struct dentry *__upperdentry;
struct inode *lower; struct ovl_path lowerpath;
/* synchronize copy up and more */ /* synchronize copy up and more */
struct mutex lock; struct mutex lock;
......
...@@ -264,11 +264,11 @@ static int ovl_fill_merge(struct dir_context *ctx, const char *name, ...@@ -264,11 +264,11 @@ static int ovl_fill_merge(struct dir_context *ctx, const char *name,
return ovl_fill_lowest(rdd, name, namelen, offset, ino, d_type); return ovl_fill_lowest(rdd, name, namelen, offset, ino, d_type);
} }
static int ovl_check_whiteouts(struct dentry *dir, struct ovl_readdir_data *rdd) static int ovl_check_whiteouts(struct path *path, struct ovl_readdir_data *rdd)
{ {
int err; int err;
struct ovl_cache_entry *p; struct ovl_cache_entry *p;
struct dentry *dentry; struct dentry *dentry, *dir = path->dentry;
const struct cred *old_cred; const struct cred *old_cred;
old_cred = ovl_override_creds(rdd->dentry->d_sb); old_cred = ovl_override_creds(rdd->dentry->d_sb);
...@@ -278,7 +278,7 @@ static int ovl_check_whiteouts(struct dentry *dir, struct ovl_readdir_data *rdd) ...@@ -278,7 +278,7 @@ static int ovl_check_whiteouts(struct dentry *dir, struct ovl_readdir_data *rdd)
while (rdd->first_maybe_whiteout) { while (rdd->first_maybe_whiteout) {
p = rdd->first_maybe_whiteout; p = rdd->first_maybe_whiteout;
rdd->first_maybe_whiteout = p->next_maybe_whiteout; rdd->first_maybe_whiteout = p->next_maybe_whiteout;
dentry = lookup_one_len(p->name, dir, p->len); dentry = lookup_one(mnt_user_ns(path->mnt), p->name, dir, p->len);
if (!IS_ERR(dentry)) { if (!IS_ERR(dentry)) {
p->is_whiteout = ovl_is_whiteout(dentry); p->is_whiteout = ovl_is_whiteout(dentry);
dput(dentry); dput(dentry);
...@@ -312,7 +312,7 @@ static inline int ovl_dir_read(struct path *realpath, ...@@ -312,7 +312,7 @@ static inline int ovl_dir_read(struct path *realpath,
} while (!err && rdd->count); } while (!err && rdd->count);
if (!err && rdd->first_maybe_whiteout && rdd->dentry) if (!err && rdd->first_maybe_whiteout && rdd->dentry)
err = ovl_check_whiteouts(realpath->dentry, rdd); err = ovl_check_whiteouts(realpath, rdd);
fput(realfile); fput(realfile);
...@@ -479,7 +479,7 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p) ...@@ -479,7 +479,7 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p)
goto get; goto get;
} }
} }
this = lookup_one_len(p->name, dir, p->len); this = lookup_one(mnt_user_ns(path->mnt), p->name, dir, p->len);
if (IS_ERR_OR_NULL(this) || !this->d_inode) { if (IS_ERR_OR_NULL(this) || !this->d_inode) {
/* Mark a stale entry */ /* Mark a stale entry */
p->is_whiteout = true; p->is_whiteout = true;
...@@ -623,8 +623,8 @@ static struct ovl_dir_cache *ovl_cache_get_impure(struct path *path) ...@@ -623,8 +623,8 @@ static struct ovl_dir_cache *ovl_cache_get_impure(struct path *path)
* Removing the "impure" xattr is best effort. * Removing the "impure" xattr is best effort.
*/ */
if (!ovl_want_write(dentry)) { if (!ovl_want_write(dentry)) {
ovl_do_removexattr(ofs, ovl_dentry_upper(dentry), ovl_removexattr(ofs, ovl_dentry_upper(dentry),
OVL_XATTR_IMPURE); OVL_XATTR_IMPURE);
ovl_drop_write(dentry); ovl_drop_write(dentry);
} }
ovl_clear_flag(OVL_IMPURE, d_inode(dentry)); ovl_clear_flag(OVL_IMPURE, d_inode(dentry));
...@@ -1001,7 +1001,8 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) ...@@ -1001,7 +1001,8 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
return err; return err;
} }
void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list) void ovl_cleanup_whiteouts(struct ovl_fs *ofs, struct dentry *upper,
struct list_head *list)
{ {
struct ovl_cache_entry *p; struct ovl_cache_entry *p;
...@@ -1012,7 +1013,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list) ...@@ -1012,7 +1013,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list)
if (WARN_ON(!p->is_whiteout || !p->is_upper)) if (WARN_ON(!p->is_whiteout || !p->is_upper))
continue; continue;
dentry = lookup_one_len(p->name, upper, p->len); dentry = ovl_lookup_upper(ofs, p->name, upper, p->len);
if (IS_ERR(dentry)) { if (IS_ERR(dentry)) {
pr_err("lookup '%s/%.*s' failed (%i)\n", pr_err("lookup '%s/%.*s' failed (%i)\n",
upper->d_name.name, p->len, p->name, upper->d_name.name, p->len, p->name,
...@@ -1020,7 +1021,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list) ...@@ -1020,7 +1021,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list)
continue; continue;
} }
if (dentry->d_inode) if (dentry->d_inode)
ovl_cleanup(upper->d_inode, dentry); ovl_cleanup(ofs, upper->d_inode, dentry);
dput(dentry); dput(dentry);
} }
inode_unlock(upper->d_inode); inode_unlock(upper->d_inode);
...@@ -1064,7 +1065,8 @@ int ovl_check_d_type_supported(struct path *realpath) ...@@ -1064,7 +1065,8 @@ int ovl_check_d_type_supported(struct path *realpath)
#define OVL_INCOMPATDIR_NAME "incompat" #define OVL_INCOMPATDIR_NAME "incompat"
static int ovl_workdir_cleanup_recurse(struct path *path, int level) static int ovl_workdir_cleanup_recurse(struct ovl_fs *ofs, struct path *path,
int level)
{ {
int err; int err;
struct inode *dir = path->dentry->d_inode; struct inode *dir = path->dentry->d_inode;
...@@ -1111,11 +1113,11 @@ static int ovl_workdir_cleanup_recurse(struct path *path, int level) ...@@ -1111,11 +1113,11 @@ static int ovl_workdir_cleanup_recurse(struct path *path, int level)
err = -EINVAL; err = -EINVAL;
break; break;
} }
dentry = lookup_one_len(p->name, path->dentry, p->len); dentry = ovl_lookup_upper(ofs, p->name, path->dentry, p->len);
if (IS_ERR(dentry)) if (IS_ERR(dentry))
continue; continue;
if (dentry->d_inode) if (dentry->d_inode)
err = ovl_workdir_cleanup(dir, path->mnt, dentry, level); err = ovl_workdir_cleanup(ofs, dir, path->mnt, dentry, level);
dput(dentry); dput(dentry);
if (err) if (err)
break; break;
...@@ -1126,24 +1128,24 @@ static int ovl_workdir_cleanup_recurse(struct path *path, int level) ...@@ -1126,24 +1128,24 @@ static int ovl_workdir_cleanup_recurse(struct path *path, int level)
return err; return err;
} }
int ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt, int ovl_workdir_cleanup(struct ovl_fs *ofs, struct inode *dir,
struct dentry *dentry, int level) struct vfsmount *mnt, struct dentry *dentry, int level)
{ {
int err; int err;
if (!d_is_dir(dentry) || level > 1) { if (!d_is_dir(dentry) || level > 1) {
return ovl_cleanup(dir, dentry); return ovl_cleanup(ofs, dir, dentry);
} }
err = ovl_do_rmdir(dir, dentry); err = ovl_do_rmdir(ofs, dir, dentry);
if (err) { if (err) {
struct path path = { .mnt = mnt, .dentry = dentry }; struct path path = { .mnt = mnt, .dentry = dentry };
inode_unlock(dir); inode_unlock(dir);
err = ovl_workdir_cleanup_recurse(&path, level + 1); err = ovl_workdir_cleanup_recurse(ofs, &path, level + 1);
inode_lock_nested(dir, I_MUTEX_PARENT); inode_lock_nested(dir, I_MUTEX_PARENT);
if (!err) if (!err)
err = ovl_cleanup(dir, dentry); err = ovl_cleanup(ofs, dir, dentry);
} }
return err; return err;
...@@ -1179,7 +1181,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs) ...@@ -1179,7 +1181,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
if (p->len == 2 && p->name[1] == '.') if (p->len == 2 && p->name[1] == '.')
continue; continue;
} }
index = lookup_one_len(p->name, indexdir, p->len); index = ovl_lookup_upper(ofs, p->name, indexdir, p->len);
if (IS_ERR(index)) { if (IS_ERR(index)) {
err = PTR_ERR(index); err = PTR_ERR(index);
index = NULL; index = NULL;
...@@ -1187,7 +1189,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs) ...@@ -1187,7 +1189,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
} }
/* Cleanup leftover from index create/cleanup attempt */ /* Cleanup leftover from index create/cleanup attempt */
if (index->d_name.name[0] == '#') { if (index->d_name.name[0] == '#') {
err = ovl_workdir_cleanup(dir, path.mnt, index, 1); err = ovl_workdir_cleanup(ofs, dir, path.mnt, index, 1);
if (err) if (err)
break; break;
goto next; goto next;
...@@ -1197,7 +1199,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs) ...@@ -1197,7 +1199,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
goto next; goto next;
} else if (err == -ESTALE) { } else if (err == -ESTALE) {
/* Cleanup stale index entries */ /* Cleanup stale index entries */
err = ovl_cleanup(dir, index); err = ovl_cleanup(ofs, dir, index);
} else if (err != -ENOENT) { } else if (err != -ENOENT) {
/* /*
* Abort mount to avoid corrupting the index if * Abort mount to avoid corrupting the index if
...@@ -1213,7 +1215,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs) ...@@ -1213,7 +1215,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
err = ovl_cleanup_and_whiteout(ofs, dir, index); err = ovl_cleanup_and_whiteout(ofs, dir, index);
} else { } else {
/* Cleanup orphan index entries */ /* Cleanup orphan index entries */
err = ovl_cleanup(dir, index); err = ovl_cleanup(ofs, dir, index);
} }
if (err) if (err)
......
...@@ -184,7 +184,8 @@ static struct inode *ovl_alloc_inode(struct super_block *sb) ...@@ -184,7 +184,8 @@ static struct inode *ovl_alloc_inode(struct super_block *sb)
oi->version = 0; oi->version = 0;
oi->flags = 0; oi->flags = 0;
oi->__upperdentry = NULL; oi->__upperdentry = NULL;
oi->lower = NULL; oi->lowerpath.dentry = NULL;
oi->lowerpath.layer = NULL;
oi->lowerdata = NULL; oi->lowerdata = NULL;
mutex_init(&oi->lock); mutex_init(&oi->lock);
...@@ -205,7 +206,7 @@ static void ovl_destroy_inode(struct inode *inode) ...@@ -205,7 +206,7 @@ static void ovl_destroy_inode(struct inode *inode)
struct ovl_inode *oi = OVL_I(inode); struct ovl_inode *oi = OVL_I(inode);
dput(oi->__upperdentry); dput(oi->__upperdentry);
iput(oi->lower); dput(oi->lowerpath.dentry);
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
ovl_dir_cache_free(inode); ovl_dir_cache_free(inode);
else else
...@@ -761,7 +762,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs, ...@@ -761,7 +762,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
inode_lock_nested(dir, I_MUTEX_PARENT); inode_lock_nested(dir, I_MUTEX_PARENT);
retry: retry:
work = lookup_one_len(name, ofs->workbasedir, strlen(name)); work = ovl_lookup_upper(ofs, name, ofs->workbasedir, strlen(name));
if (!IS_ERR(work)) { if (!IS_ERR(work)) {
struct iattr attr = { struct iattr attr = {
...@@ -778,7 +779,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs, ...@@ -778,7 +779,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
goto out_unlock; goto out_unlock;
retried = true; retried = true;
err = ovl_workdir_cleanup(dir, mnt, work, 0); err = ovl_workdir_cleanup(ofs, dir, mnt, work, 0);
dput(work); dput(work);
if (err == -EINVAL) { if (err == -EINVAL) {
work = ERR_PTR(err); work = ERR_PTR(err);
...@@ -787,7 +788,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs, ...@@ -787,7 +788,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
goto retry; goto retry;
} }
err = ovl_mkdir_real(dir, &work, attr.ia_mode); err = ovl_mkdir_real(ofs, dir, &work, attr.ia_mode);
if (err) if (err)
goto out_dput; goto out_dput;
...@@ -809,19 +810,19 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs, ...@@ -809,19 +810,19 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
* allowed as upper are limited to "normal" ones, where checking * allowed as upper are limited to "normal" ones, where checking
* for the above two errors is sufficient. * for the above two errors is sufficient.
*/ */
err = vfs_removexattr(&init_user_ns, work, err = ovl_do_removexattr(ofs, work,
XATTR_NAME_POSIX_ACL_DEFAULT); XATTR_NAME_POSIX_ACL_DEFAULT);
if (err && err != -ENODATA && err != -EOPNOTSUPP) if (err && err != -ENODATA && err != -EOPNOTSUPP)
goto out_dput; goto out_dput;
err = vfs_removexattr(&init_user_ns, work, err = ovl_do_removexattr(ofs, work,
XATTR_NAME_POSIX_ACL_ACCESS); XATTR_NAME_POSIX_ACL_ACCESS);
if (err && err != -ENODATA && err != -EOPNOTSUPP) if (err && err != -ENODATA && err != -EOPNOTSUPP)
goto out_dput; goto out_dput;
/* Clear any inherited mode bits */ /* Clear any inherited mode bits */
inode_lock(work->d_inode); inode_lock(work->d_inode);
err = notify_change(&init_user_ns, work, &attr, NULL); err = ovl_do_notify_change(ofs, work, &attr);
inode_unlock(work->d_inode); inode_unlock(work->d_inode);
if (err) if (err)
goto out_dput; goto out_dput;
...@@ -873,10 +874,6 @@ static int ovl_mount_dir_noesc(const char *name, struct path *path) ...@@ -873,10 +874,6 @@ static int ovl_mount_dir_noesc(const char *name, struct path *path)
pr_err("filesystem on '%s' not supported\n", name); pr_err("filesystem on '%s' not supported\n", name);
goto out_put; goto out_put;
} }
if (is_idmapped_mnt(path->mnt)) {
pr_err("idmapped layers are currently not supported\n");
goto out_put;
}
if (!d_is_dir(path->dentry)) { if (!d_is_dir(path->dentry)) {
pr_err("'%s' not a directory\n", name); pr_err("'%s' not a directory\n", name);
goto out_put; goto out_put;
...@@ -1256,8 +1253,9 @@ static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs, ...@@ -1256,8 +1253,9 @@ static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs,
* Returns 1 if RENAME_WHITEOUT is supported, 0 if not supported and * Returns 1 if RENAME_WHITEOUT is supported, 0 if not supported and
* negative values if error is encountered. * negative values if error is encountered.
*/ */
static int ovl_check_rename_whiteout(struct dentry *workdir) static int ovl_check_rename_whiteout(struct ovl_fs *ofs)
{ {
struct dentry *workdir = ofs->workdir;
struct inode *dir = d_inode(workdir); struct inode *dir = d_inode(workdir);
struct dentry *temp; struct dentry *temp;
struct dentry *dest; struct dentry *dest;
...@@ -1267,12 +1265,12 @@ static int ovl_check_rename_whiteout(struct dentry *workdir) ...@@ -1267,12 +1265,12 @@ static int ovl_check_rename_whiteout(struct dentry *workdir)
inode_lock_nested(dir, I_MUTEX_PARENT); inode_lock_nested(dir, I_MUTEX_PARENT);
temp = ovl_create_temp(workdir, OVL_CATTR(S_IFREG | 0)); temp = ovl_create_temp(ofs, workdir, OVL_CATTR(S_IFREG | 0));
err = PTR_ERR(temp); err = PTR_ERR(temp);
if (IS_ERR(temp)) if (IS_ERR(temp))
goto out_unlock; goto out_unlock;
dest = ovl_lookup_temp(workdir); dest = ovl_lookup_temp(ofs, workdir);
err = PTR_ERR(dest); err = PTR_ERR(dest);
if (IS_ERR(dest)) { if (IS_ERR(dest)) {
dput(temp); dput(temp);
...@@ -1281,14 +1279,14 @@ static int ovl_check_rename_whiteout(struct dentry *workdir) ...@@ -1281,14 +1279,14 @@ static int ovl_check_rename_whiteout(struct dentry *workdir)
/* Name is inline and stable - using snapshot as a copy helper */ /* Name is inline and stable - using snapshot as a copy helper */
take_dentry_name_snapshot(&name, temp); take_dentry_name_snapshot(&name, temp);
err = ovl_do_rename(dir, temp, dir, dest, RENAME_WHITEOUT); err = ovl_do_rename(ofs, dir, temp, dir, dest, RENAME_WHITEOUT);
if (err) { if (err) {
if (err == -EINVAL) if (err == -EINVAL)
err = 0; err = 0;
goto cleanup_temp; goto cleanup_temp;
} }
whiteout = lookup_one_len(name.name.name, workdir, name.name.len); whiteout = ovl_lookup_upper(ofs, name.name.name, workdir, name.name.len);
err = PTR_ERR(whiteout); err = PTR_ERR(whiteout);
if (IS_ERR(whiteout)) if (IS_ERR(whiteout))
goto cleanup_temp; goto cleanup_temp;
...@@ -1297,11 +1295,11 @@ static int ovl_check_rename_whiteout(struct dentry *workdir) ...@@ -1297,11 +1295,11 @@ static int ovl_check_rename_whiteout(struct dentry *workdir)
/* Best effort cleanup of whiteout and temp file */ /* Best effort cleanup of whiteout and temp file */
if (err) if (err)
ovl_cleanup(dir, whiteout); ovl_cleanup(ofs, dir, whiteout);
dput(whiteout); dput(whiteout);
cleanup_temp: cleanup_temp:
ovl_cleanup(dir, temp); ovl_cleanup(ofs, dir, temp);
release_dentry_name_snapshot(&name); release_dentry_name_snapshot(&name);
dput(temp); dput(temp);
dput(dest); dput(dest);
...@@ -1312,16 +1310,17 @@ static int ovl_check_rename_whiteout(struct dentry *workdir) ...@@ -1312,16 +1310,17 @@ static int ovl_check_rename_whiteout(struct dentry *workdir)
return err; return err;
} }
static struct dentry *ovl_lookup_or_create(struct dentry *parent, static struct dentry *ovl_lookup_or_create(struct ovl_fs *ofs,
struct dentry *parent,
const char *name, umode_t mode) const char *name, umode_t mode)
{ {
size_t len = strlen(name); size_t len = strlen(name);
struct dentry *child; struct dentry *child;
inode_lock_nested(parent->d_inode, I_MUTEX_PARENT); inode_lock_nested(parent->d_inode, I_MUTEX_PARENT);
child = lookup_one_len(name, parent, len); child = ovl_lookup_upper(ofs, name, parent, len);
if (!IS_ERR(child) && !child->d_inode) if (!IS_ERR(child) && !child->d_inode)
child = ovl_create_real(parent->d_inode, child, child = ovl_create_real(ofs, parent->d_inode, child,
OVL_CATTR(mode)); OVL_CATTR(mode));
inode_unlock(parent->d_inode); inode_unlock(parent->d_inode);
dput(parent); dput(parent);
...@@ -1343,7 +1342,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs) ...@@ -1343,7 +1342,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs)
const char *const *name = volatile_path; const char *const *name = volatile_path;
for (ctr = ARRAY_SIZE(volatile_path); ctr; ctr--, name++) { for (ctr = ARRAY_SIZE(volatile_path); ctr; ctr--, name++) {
d = ovl_lookup_or_create(d, *name, ctr > 1 ? S_IFDIR : S_IFREG); d = ovl_lookup_or_create(ofs, d, *name, ctr > 1 ? S_IFDIR : S_IFREG);
if (IS_ERR(d)) if (IS_ERR(d))
return PTR_ERR(d); return PTR_ERR(d);
} }
...@@ -1391,7 +1390,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, ...@@ -1391,7 +1390,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
pr_warn("upper fs needs to support d_type.\n"); pr_warn("upper fs needs to support d_type.\n");
/* Check if upper/work fs supports O_TMPFILE */ /* Check if upper/work fs supports O_TMPFILE */
temp = ovl_do_tmpfile(ofs->workdir, S_IFREG | 0); temp = ovl_do_tmpfile(ofs, ofs->workdir, S_IFREG | 0);
ofs->tmpfile = !IS_ERR(temp); ofs->tmpfile = !IS_ERR(temp);
if (ofs->tmpfile) if (ofs->tmpfile)
dput(temp); dput(temp);
...@@ -1400,7 +1399,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, ...@@ -1400,7 +1399,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
/* Check if upper/work fs supports RENAME_WHITEOUT */ /* Check if upper/work fs supports RENAME_WHITEOUT */
err = ovl_check_rename_whiteout(ofs->workdir); err = ovl_check_rename_whiteout(ofs);
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -1411,7 +1410,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, ...@@ -1411,7 +1410,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
/* /*
* Check if upper/work fs supports (trusted|user).overlay.* xattr * Check if upper/work fs supports (trusted|user).overlay.* xattr
*/ */
err = ovl_do_setxattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE, "0", 1); err = ovl_setxattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE, "0", 1);
if (err) { if (err) {
ofs->noxattr = true; ofs->noxattr = true;
if (ofs->config.index || ofs->config.metacopy) { if (ofs->config.index || ofs->config.metacopy) {
...@@ -1429,7 +1428,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, ...@@ -1429,7 +1428,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
} }
err = 0; err = 0;
} else { } else {
ovl_do_removexattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE); ovl_removexattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE);
} }
/* /*
......
...@@ -194,6 +194,20 @@ enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path) ...@@ -194,6 +194,20 @@ enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path)
return type; return type;
} }
enum ovl_path_type ovl_path_realdata(struct dentry *dentry, struct path *path)
{
enum ovl_path_type type = ovl_path_type(dentry);
WARN_ON_ONCE(d_is_dir(dentry));
if (!OVL_TYPE_UPPER(type) || OVL_TYPE_MERGE(type))
ovl_path_lowerdata(dentry, path);
else
ovl_path_upper(dentry, path);
return type;
}
struct dentry *ovl_dentry_upper(struct dentry *dentry) struct dentry *ovl_dentry_upper(struct dentry *dentry)
{ {
return ovl_upperdentry_dereference(OVL_I(d_inode(dentry))); return ovl_upperdentry_dereference(OVL_I(d_inode(dentry)));
...@@ -236,6 +250,17 @@ struct dentry *ovl_i_dentry_upper(struct inode *inode) ...@@ -236,6 +250,17 @@ struct dentry *ovl_i_dentry_upper(struct inode *inode)
return ovl_upperdentry_dereference(OVL_I(inode)); return ovl_upperdentry_dereference(OVL_I(inode));
} }
void ovl_i_path_real(struct inode *inode, struct path *path)
{
path->dentry = ovl_i_dentry_upper(inode);
if (!path->dentry) {
path->dentry = OVL_I(inode)->lowerpath.dentry;
path->mnt = OVL_I(inode)->lowerpath.layer->mnt;
} else {
path->mnt = ovl_upper_mnt(OVL_FS(inode->i_sb));
}
}
struct inode *ovl_inode_upper(struct inode *inode) struct inode *ovl_inode_upper(struct inode *inode)
{ {
struct dentry *upperdentry = ovl_i_dentry_upper(inode); struct dentry *upperdentry = ovl_i_dentry_upper(inode);
...@@ -245,7 +270,9 @@ struct inode *ovl_inode_upper(struct inode *inode) ...@@ -245,7 +270,9 @@ struct inode *ovl_inode_upper(struct inode *inode)
struct inode *ovl_inode_lower(struct inode *inode) struct inode *ovl_inode_lower(struct inode *inode)
{ {
return OVL_I(inode)->lower; struct dentry *lowerdentry = OVL_I(inode)->lowerpath.dentry;
return lowerdentry ? d_inode(lowerdentry) : NULL;
} }
struct inode *ovl_inode_real(struct inode *inode) struct inode *ovl_inode_real(struct inode *inode)
...@@ -443,7 +470,7 @@ static void ovl_dir_version_inc(struct dentry *dentry, bool impurity) ...@@ -443,7 +470,7 @@ static void ovl_dir_version_inc(struct dentry *dentry, bool impurity)
void ovl_dir_modified(struct dentry *dentry, bool impurity) void ovl_dir_modified(struct dentry *dentry, bool impurity)
{ {
/* Copy mtime/ctime */ /* Copy mtime/ctime */
ovl_copyattr(d_inode(ovl_dentry_upper(dentry)), d_inode(dentry)); ovl_copyattr(d_inode(dentry));
ovl_dir_version_inc(dentry, impurity); ovl_dir_version_inc(dentry, impurity);
} }
...@@ -466,6 +493,7 @@ bool ovl_is_whiteout(struct dentry *dentry) ...@@ -466,6 +493,7 @@ bool ovl_is_whiteout(struct dentry *dentry)
struct file *ovl_path_open(struct path *path, int flags) struct file *ovl_path_open(struct path *path, int flags)
{ {
struct inode *inode = d_inode(path->dentry); struct inode *inode = d_inode(path->dentry);
struct user_namespace *real_mnt_userns = mnt_user_ns(path->mnt);
int err, acc_mode; int err, acc_mode;
if (flags & ~(O_ACCMODE | O_LARGEFILE)) if (flags & ~(O_ACCMODE | O_LARGEFILE))
...@@ -482,12 +510,12 @@ struct file *ovl_path_open(struct path *path, int flags) ...@@ -482,12 +510,12 @@ struct file *ovl_path_open(struct path *path, int flags)
BUG(); BUG();
} }
err = inode_permission(&init_user_ns, inode, acc_mode | MAY_OPEN); err = inode_permission(real_mnt_userns, inode, acc_mode | MAY_OPEN);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
/* O_NOATIME is an optimization, don't fail if not permitted */ /* O_NOATIME is an optimization, don't fail if not permitted */
if (inode_owner_or_capable(&init_user_ns, inode)) if (inode_owner_or_capable(real_mnt_userns, inode))
flags |= O_NOATIME; flags |= O_NOATIME;
return dentry_open(path, flags, current_cred()); return dentry_open(path, flags, current_cred());
...@@ -550,11 +578,11 @@ void ovl_copy_up_end(struct dentry *dentry) ...@@ -550,11 +578,11 @@ void ovl_copy_up_end(struct dentry *dentry)
ovl_inode_unlock(d_inode(dentry)); ovl_inode_unlock(d_inode(dentry));
} }
bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry) bool ovl_path_check_origin_xattr(struct ovl_fs *ofs, struct path *path)
{ {
int res; int res;
res = ovl_do_getxattr(ofs, dentry, OVL_XATTR_ORIGIN, NULL, 0); res = ovl_path_getxattr(ofs, path, OVL_XATTR_ORIGIN, NULL, 0);
/* Zero size value means "copied up but origin unknown" */ /* Zero size value means "copied up but origin unknown" */
if (res >= 0) if (res >= 0)
...@@ -563,16 +591,16 @@ bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry) ...@@ -563,16 +591,16 @@ bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry)
return false; return false;
} }
bool ovl_check_dir_xattr(struct super_block *sb, struct dentry *dentry, bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, struct path *path,
enum ovl_xattr ox) enum ovl_xattr ox)
{ {
int res; int res;
char val; char val;
if (!d_is_dir(dentry)) if (!d_is_dir(path->dentry))
return false; return false;
res = ovl_do_getxattr(OVL_FS(sb), dentry, ox, &val, 1); res = ovl_path_getxattr(ofs, path, ox, &val, 1);
if (res == 1 && val == 'y') if (res == 1 && val == 'y')
return true; return true;
...@@ -612,7 +640,7 @@ int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry, ...@@ -612,7 +640,7 @@ int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry,
if (ofs->noxattr) if (ofs->noxattr)
return xerr; return xerr;
err = ovl_do_setxattr(ofs, upperdentry, ox, value, size); err = ovl_setxattr(ofs, upperdentry, ox, value, size);
if (err == -EOPNOTSUPP) { if (err == -EOPNOTSUPP) {
pr_warn("cannot set %s xattr on upper\n", ovl_xattr(ofs, ox)); pr_warn("cannot set %s xattr on upper\n", ovl_xattr(ofs, ox));
...@@ -652,8 +680,8 @@ void ovl_check_protattr(struct inode *inode, struct dentry *upper) ...@@ -652,8 +680,8 @@ void ovl_check_protattr(struct inode *inode, struct dentry *upper)
char buf[OVL_PROTATTR_MAX+1]; char buf[OVL_PROTATTR_MAX+1];
int res, n; int res, n;
res = ovl_do_getxattr(ofs, upper, OVL_XATTR_PROTATTR, buf, res = ovl_getxattr_upper(ofs, upper, OVL_XATTR_PROTATTR, buf,
OVL_PROTATTR_MAX); OVL_PROTATTR_MAX);
if (res < 0) if (res < 0)
return; return;
...@@ -708,7 +736,7 @@ int ovl_set_protattr(struct inode *inode, struct dentry *upper, ...@@ -708,7 +736,7 @@ int ovl_set_protattr(struct inode *inode, struct dentry *upper,
err = ovl_check_setxattr(ofs, upper, OVL_XATTR_PROTATTR, err = ovl_check_setxattr(ofs, upper, OVL_XATTR_PROTATTR,
buf, len, -EPERM); buf, len, -EPERM);
} else if (inode->i_flags & OVL_PROT_I_FLAGS_MASK) { } else if (inode->i_flags & OVL_PROT_I_FLAGS_MASK) {
err = ovl_do_removexattr(ofs, upper, OVL_XATTR_PROTATTR); err = ovl_removexattr(ofs, upper, OVL_XATTR_PROTATTR);
if (err == -EOPNOTSUPP || err == -ENODATA) if (err == -EOPNOTSUPP || err == -ENODATA)
err = 0; err = 0;
} }
...@@ -824,7 +852,7 @@ static void ovl_cleanup_index(struct dentry *dentry) ...@@ -824,7 +852,7 @@ static void ovl_cleanup_index(struct dentry *dentry)
} }
inode_lock_nested(dir, I_MUTEX_PARENT); inode_lock_nested(dir, I_MUTEX_PARENT);
index = lookup_one_len(name.name, indexdir, name.len); index = ovl_lookup_upper(ofs, name.name, indexdir, name.len);
err = PTR_ERR(index); err = PTR_ERR(index);
if (IS_ERR(index)) { if (IS_ERR(index)) {
index = NULL; index = NULL;
...@@ -834,7 +862,7 @@ static void ovl_cleanup_index(struct dentry *dentry) ...@@ -834,7 +862,7 @@ static void ovl_cleanup_index(struct dentry *dentry)
dir, index); dir, index);
} else { } else {
/* Cleanup orphan index entries */ /* Cleanup orphan index entries */
err = ovl_cleanup(dir, index); err = ovl_cleanup(ofs, dir, index);
} }
inode_unlock(dir); inode_unlock(dir);
...@@ -943,15 +971,15 @@ int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir) ...@@ -943,15 +971,15 @@ int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir)
} }
/* err < 0, 0 if no metacopy xattr, 1 if metacopy xattr found */ /* err < 0, 0 if no metacopy xattr, 1 if metacopy xattr found */
int ovl_check_metacopy_xattr(struct ovl_fs *ofs, struct dentry *dentry) int ovl_check_metacopy_xattr(struct ovl_fs *ofs, struct path *path)
{ {
int res; int res;
/* Only regular files can have metacopy xattr */ /* Only regular files can have metacopy xattr */
if (!S_ISREG(d_inode(dentry)->i_mode)) if (!S_ISREG(d_inode(path->dentry)->i_mode))
return 0; return 0;
res = ovl_do_getxattr(ofs, dentry, OVL_XATTR_METACOPY, NULL, 0); res = ovl_path_getxattr(ofs, path, OVL_XATTR_METACOPY, NULL, 0);
if (res < 0) { if (res < 0) {
if (res == -ENODATA || res == -EOPNOTSUPP) if (res == -ENODATA || res == -EOPNOTSUPP)
return 0; return 0;
...@@ -987,13 +1015,12 @@ bool ovl_is_metacopy_dentry(struct dentry *dentry) ...@@ -987,13 +1015,12 @@ bool ovl_is_metacopy_dentry(struct dentry *dentry)
return (oe->numlower > 1); return (oe->numlower > 1);
} }
char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct dentry *dentry, char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct path *path, int padding)
int padding)
{ {
int res; int res;
char *s, *next, *buf = NULL; char *s, *next, *buf = NULL;
res = ovl_do_getxattr(ofs, dentry, OVL_XATTR_REDIRECT, NULL, 0); res = ovl_path_getxattr(ofs, path, OVL_XATTR_REDIRECT, NULL, 0);
if (res == -ENODATA || res == -EOPNOTSUPP) if (res == -ENODATA || res == -EOPNOTSUPP)
return NULL; return NULL;
if (res < 0) if (res < 0)
...@@ -1005,7 +1032,7 @@ char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct dentry *dentry, ...@@ -1005,7 +1032,7 @@ char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct dentry *dentry,
if (!buf) if (!buf)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
res = ovl_do_getxattr(ofs, dentry, OVL_XATTR_REDIRECT, buf, res); res = ovl_path_getxattr(ofs, path, OVL_XATTR_REDIRECT, buf, res);
if (res < 0) if (res < 0)
goto fail; goto fail;
if (res == 0) if (res == 0)
...@@ -1060,3 +1087,33 @@ int ovl_sync_status(struct ovl_fs *ofs) ...@@ -1060,3 +1087,33 @@ int ovl_sync_status(struct ovl_fs *ofs)
return errseq_check(&mnt->mnt_sb->s_wb_err, ofs->errseq); return errseq_check(&mnt->mnt_sb->s_wb_err, ofs->errseq);
} }
/*
* ovl_copyattr() - copy inode attributes from layer to ovl inode
*
* When overlay copies inode information from an upper or lower layer to the
* relevant overlay inode it will apply the idmapping of the upper or lower
* layer when doing so ensuring that the ovl inode ownership will correctly
* reflect the ownership of the idmapped upper or lower layer. For example, an
* idmapped upper or lower layer mapping id 1001 to id 1000 will take care to
* map any lower or upper inode owned by id 1001 to id 1000. These mapping
* helpers are nops when the relevant layer isn't idmapped.
*/
void ovl_copyattr(struct inode *inode)
{
struct path realpath;
struct inode *realinode;
struct user_namespace *real_mnt_userns;
ovl_i_path_real(inode, &realpath);
realinode = d_inode(realpath.dentry);
real_mnt_userns = mnt_user_ns(realpath.mnt);
inode->i_uid = i_uid_into_mnt(real_mnt_userns, realinode);
inode->i_gid = i_gid_into_mnt(real_mnt_userns, realinode);
inode->i_mode = realinode->i_mode;
inode->i_atime = realinode->i_atime;
inode->i_mtime = realinode->i_mtime;
inode->i_ctime = realinode->i_ctime;
i_size_write(inode, i_size_read(realinode));
}
...@@ -69,6 +69,12 @@ extern struct dentry *lookup_one_len(const char *, struct dentry *, int); ...@@ -69,6 +69,12 @@ extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int); extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int);
extern struct dentry *lookup_positive_unlocked(const char *, struct dentry *, int); extern struct dentry *lookup_positive_unlocked(const char *, struct dentry *, int);
struct dentry *lookup_one(struct user_namespace *, const char *, struct dentry *, int); struct dentry *lookup_one(struct user_namespace *, const char *, struct dentry *, int);
struct dentry *lookup_one_unlocked(struct user_namespace *mnt_userns,
const char *name, struct dentry *base,
int len);
struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
const char *name,
struct dentry *base, int len);
extern int follow_down_one(struct path *); extern int follow_down_one(struct path *);
extern int follow_down(struct path *); extern int follow_down(struct 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