Commit 70f2ae1f authored by Linus Torvalds's avatar Linus Torvalds

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

Pull overlayfs fixes from Miklos Szeredi:
 "This contains a fix for the vfs_mkdir() issue discovered by Al, as
  well as other fixes and cleanups"

* tag 'ovl-fixes-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs:
  ovl: use inode_insert5() to hash a newly created inode
  ovl: Pass argument to ovl_get_inode() in a structure
  vfs: factor out inode_insert5()
  ovl: clean up copy-up error paths
  ovl: return EIO on internal error
  ovl: make ovl_create_real() cope with vfs_mkdir() safely
  ovl: create helper ovl_create_temp()
  ovl: return dentry from ovl_create_real()
  ovl: struct cattr cleanups
  ovl: strip debug argument from ovl_do_ helpers
  ovl: remove WARN_ON() real inode attributes mismatch
  ovl: Kconfig documentation fixes
  ovl: update documentation for unionmount-testsuite
parents da315f6e 01b39dcc
...@@ -429,11 +429,12 @@ This verification may cause significant overhead in some cases. ...@@ -429,11 +429,12 @@ This verification may cause significant overhead in some cases.
Testsuite Testsuite
--------- ---------
There's testsuite developed by David Howells at: There's a testsuite originally developed by David Howells and currently
maintained by Amir Goldstein at:
git://git.infradead.org/users/dhowells/unionmount-testsuite.git https://github.com/amir73il/unionmount-testsuite.git
Run as root: Run as root:
# cd unionmount-testsuite # cd unionmount-testsuite
# ./run --ov # ./run --ov --verify
...@@ -1003,6 +1003,70 @@ void unlock_two_nondirectories(struct inode *inode1, struct inode *inode2) ...@@ -1003,6 +1003,70 @@ void unlock_two_nondirectories(struct inode *inode1, struct inode *inode2)
} }
EXPORT_SYMBOL(unlock_two_nondirectories); EXPORT_SYMBOL(unlock_two_nondirectories);
/**
* inode_insert5 - obtain an inode from a mounted file system
* @inode: pre-allocated inode to use for insert to cache
* @hashval: hash value (usually inode number) to get
* @test: callback used for comparisons between inodes
* @set: callback used to initialize a new struct inode
* @data: opaque data pointer to pass to @test and @set
*
* Search for the inode specified by @hashval and @data in the inode cache,
* and if present it is return it with an increased reference count. This is
* a variant of iget5_locked() for callers that don't want to fail on memory
* allocation of inode.
*
* If the inode is not in cache, insert the pre-allocated inode to cache and
* return it locked, hashed, and with the I_NEW flag set. The file system gets
* to fill it in before unlocking it via unlock_new_inode().
*
* Note both @test and @set are called with the inode_hash_lock held, so can't
* sleep.
*/
struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
int (*test)(struct inode *, void *),
int (*set)(struct inode *, void *), void *data)
{
struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
struct inode *old;
again:
spin_lock(&inode_hash_lock);
old = find_inode(inode->i_sb, head, test, data);
if (unlikely(old)) {
/*
* Uhhuh, somebody else created the same inode under us.
* Use the old inode instead of the preallocated one.
*/
spin_unlock(&inode_hash_lock);
wait_on_inode(old);
if (unlikely(inode_unhashed(old))) {
iput(old);
goto again;
}
return old;
}
if (set && unlikely(set(inode, data))) {
inode = NULL;
goto unlock;
}
/*
* Return the locked inode with I_NEW set, the
* caller is responsible for filling in the contents
*/
spin_lock(&inode->i_lock);
inode->i_state |= I_NEW;
hlist_add_head(&inode->i_hash, head);
spin_unlock(&inode->i_lock);
unlock:
spin_unlock(&inode_hash_lock);
return inode;
}
EXPORT_SYMBOL(inode_insert5);
/** /**
* iget5_locked - obtain an inode from a mounted file system * iget5_locked - obtain an inode from a mounted file system
* @sb: super block of file system * @sb: super block of file system
...@@ -1027,66 +1091,18 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, ...@@ -1027,66 +1091,18 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
int (*test)(struct inode *, void *), int (*test)(struct inode *, void *),
int (*set)(struct inode *, void *), void *data) int (*set)(struct inode *, void *), void *data)
{ {
struct hlist_head *head = inode_hashtable + hash(sb, hashval); struct inode *inode = ilookup5(sb, hashval, test, data);
struct inode *inode;
again:
spin_lock(&inode_hash_lock);
inode = find_inode(sb, head, test, data);
spin_unlock(&inode_hash_lock);
if (inode) { if (!inode) {
wait_on_inode(inode); struct inode *new = new_inode(sb);
if (unlikely(inode_unhashed(inode))) {
iput(inode);
goto again;
}
return inode;
}
inode = alloc_inode(sb); if (new) {
if (inode) { inode = inode_insert5(new, hashval, test, set, data);
struct inode *old; if (unlikely(inode != new))
iput(new);
spin_lock(&inode_hash_lock);
/* We released the lock, so.. */
old = find_inode(sb, head, test, data);
if (!old) {
if (set(inode, data))
goto set_failed;
spin_lock(&inode->i_lock);
inode->i_state = I_NEW;
hlist_add_head(&inode->i_hash, head);
spin_unlock(&inode->i_lock);
inode_sb_list_add(inode);
spin_unlock(&inode_hash_lock);
/* Return the locked inode with I_NEW set, the
* caller is responsible for filling in the contents
*/
return inode;
}
/*
* Uhhuh, somebody else created the same inode under
* us. Use the old inode instead of the one we just
* allocated.
*/
spin_unlock(&inode_hash_lock);
destroy_inode(inode);
inode = old;
wait_on_inode(inode);
if (unlikely(inode_unhashed(inode))) {
iput(inode);
goto again;
} }
} }
return inode; return inode;
set_failed:
spin_unlock(&inode_hash_lock);
destroy_inode(inode);
return NULL;
} }
EXPORT_SYMBOL(iget5_locked); EXPORT_SYMBOL(iget5_locked);
...@@ -1427,43 +1443,13 @@ EXPORT_SYMBOL(insert_inode_locked); ...@@ -1427,43 +1443,13 @@ EXPORT_SYMBOL(insert_inode_locked);
int insert_inode_locked4(struct inode *inode, unsigned long hashval, int insert_inode_locked4(struct inode *inode, unsigned long hashval,
int (*test)(struct inode *, void *), void *data) int (*test)(struct inode *, void *), void *data)
{ {
struct super_block *sb = inode->i_sb; struct inode *old = inode_insert5(inode, hashval, test, NULL, data);
struct hlist_head *head = inode_hashtable + hash(sb, hashval);
while (1) { if (old != inode) {
struct inode *old = NULL;
spin_lock(&inode_hash_lock);
hlist_for_each_entry(old, head, i_hash) {
if (old->i_sb != sb)
continue;
if (!test(old, data))
continue;
spin_lock(&old->i_lock);
if (old->i_state & (I_FREEING|I_WILL_FREE)) {
spin_unlock(&old->i_lock);
continue;
}
break;
}
if (likely(!old)) {
spin_lock(&inode->i_lock);
inode->i_state |= I_NEW;
hlist_add_head(&inode->i_hash, head);
spin_unlock(&inode->i_lock);
spin_unlock(&inode_hash_lock);
return 0;
}
__iget(old);
spin_unlock(&old->i_lock);
spin_unlock(&inode_hash_lock);
wait_on_inode(old);
if (unlikely(!inode_unhashed(old))) {
iput(old);
return -EBUSY;
}
iput(old); iput(old);
return -EBUSY;
} }
return 0;
} }
EXPORT_SYMBOL(insert_inode_locked4); EXPORT_SYMBOL(insert_inode_locked4);
......
...@@ -11,7 +11,7 @@ config OVERLAY_FS ...@@ -11,7 +11,7 @@ config OVERLAY_FS
For more information see Documentation/filesystems/overlayfs.txt For more information see Documentation/filesystems/overlayfs.txt
config OVERLAY_FS_REDIRECT_DIR config OVERLAY_FS_REDIRECT_DIR
bool "Overlayfs: turn on redirect dir feature by default" bool "Overlayfs: turn on redirect directory feature by default"
depends on OVERLAY_FS depends on OVERLAY_FS
help help
If this config option is enabled then overlay filesystems will use If this config option is enabled then overlay filesystems will use
...@@ -46,7 +46,7 @@ config OVERLAY_FS_INDEX ...@@ -46,7 +46,7 @@ config OVERLAY_FS_INDEX
depends on OVERLAY_FS depends on OVERLAY_FS
help help
If this config option is enabled then overlay filesystems will use If this config option is enabled then overlay filesystems will use
the inodes index dir to map lower inodes to upper inodes by default. the index directory to map lower inodes to upper inodes by default.
In this case it is still possible to turn off index globally with the In this case it is still possible to turn off index globally with the
"index=off" module option or on a filesystem instance basis with the "index=off" module option or on a filesystem instance basis with the
"index=off" mount option. "index=off" mount option.
...@@ -66,7 +66,7 @@ config OVERLAY_FS_NFS_EXPORT ...@@ -66,7 +66,7 @@ config OVERLAY_FS_NFS_EXPORT
depends on OVERLAY_FS_INDEX depends on OVERLAY_FS_INDEX
help help
If this config option is enabled then overlay filesystems will use If this config option is enabled then overlay filesystems will use
the inodes index dir to decode overlay NFS file handles by default. the index directory to decode overlay NFS file handles by default.
In this case, it is still possible to turn off NFS export support In this case, it is still possible to turn off NFS export support
globally with the "nfs_export=off" module option or on a filesystem globally with the "nfs_export=off" module option or on a filesystem
instance basis with the "nfs_export=off" mount option. instance basis with the "nfs_export=off" mount option.
......
...@@ -365,17 +365,14 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin, ...@@ -365,17 +365,14 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
if (err) if (err)
return err; return err;
temp = ovl_lookup_temp(indexdir); temp = ovl_create_temp(indexdir, OVL_CATTR(S_IFDIR | 0));
err = PTR_ERR(temp);
if (IS_ERR(temp)) if (IS_ERR(temp))
goto temp_err; goto free_name;
err = ovl_do_mkdir(dir, temp, S_IFDIR, true);
if (err)
goto out;
err = ovl_set_upper_fh(upper, temp); err = ovl_set_upper_fh(upper, temp);
if (err) if (err)
goto out_cleanup; goto out;
index = lookup_one_len(name.name, indexdir, name.len); index = lookup_one_len(name.name, indexdir, name.len);
if (IS_ERR(index)) { if (IS_ERR(index)) {
...@@ -384,23 +381,13 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin, ...@@ -384,23 +381,13 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
err = ovl_do_rename(dir, temp, dir, index, 0); err = ovl_do_rename(dir, temp, dir, index, 0);
dput(index); dput(index);
} }
if (err)
goto out_cleanup;
out: out:
if (err)
ovl_cleanup(dir, temp);
dput(temp); dput(temp);
free_name:
kfree(name.name); kfree(name.name);
return err; return err;
temp_err:
err = PTR_ERR(temp);
temp = NULL;
goto out;
out_cleanup:
ovl_cleanup(dir, temp);
goto out;
} }
struct ovl_copy_up_ctx { struct ovl_copy_up_ctx {
...@@ -439,8 +426,7 @@ static int ovl_link_up(struct ovl_copy_up_ctx *c) ...@@ -439,8 +426,7 @@ static int ovl_link_up(struct ovl_copy_up_ctx *c)
c->dentry->d_name.len); c->dentry->d_name.len);
err = PTR_ERR(upper); err = PTR_ERR(upper);
if (!IS_ERR(upper)) { if (!IS_ERR(upper)) {
err = ovl_do_link(ovl_dentry_upper(c->dentry), udir, upper, err = ovl_do_link(ovl_dentry_upper(c->dentry), udir, upper);
true);
dput(upper); dput(upper);
if (!err) { if (!err) {
...@@ -470,7 +456,7 @@ static int ovl_install_temp(struct ovl_copy_up_ctx *c, struct dentry *temp, ...@@ -470,7 +456,7 @@ static int ovl_install_temp(struct ovl_copy_up_ctx *c, struct dentry *temp,
return PTR_ERR(upper); return PTR_ERR(upper);
if (c->tmpfile) if (c->tmpfile)
err = ovl_do_link(temp, udir, upper, true); err = ovl_do_link(temp, udir, upper);
else else
err = ovl_do_rename(d_inode(c->workdir), temp, udir, upper, 0); err = ovl_do_rename(d_inode(c->workdir), temp, udir, upper, 0);
...@@ -481,13 +467,13 @@ static int ovl_install_temp(struct ovl_copy_up_ctx *c, struct dentry *temp, ...@@ -481,13 +467,13 @@ static int ovl_install_temp(struct ovl_copy_up_ctx *c, struct dentry *temp,
return err; return err;
} }
static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp) static struct dentry *ovl_get_tmpfile(struct ovl_copy_up_ctx *c)
{ {
int err; int err;
struct dentry *temp; struct dentry *temp;
const struct cred *old_creds = NULL; const struct cred *old_creds = NULL;
struct cred *new_creds = NULL; struct cred *new_creds = NULL;
struct cattr cattr = { struct ovl_cattr cattr = {
/* Can't properly set mode on creation because of the umask */ /* Can't properly set mode on creation because of the umask */
.mode = c->stat.mode & S_IFMT, .mode = c->stat.mode & S_IFMT,
.rdev = c->stat.rdev, .rdev = c->stat.rdev,
...@@ -495,41 +481,24 @@ static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp) ...@@ -495,41 +481,24 @@ static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp)
}; };
err = security_inode_copy_up(c->dentry, &new_creds); err = security_inode_copy_up(c->dentry, &new_creds);
temp = ERR_PTR(err);
if (err < 0) if (err < 0)
goto out; goto out;
if (new_creds) if (new_creds)
old_creds = override_creds(new_creds); old_creds = override_creds(new_creds);
if (c->tmpfile) { if (c->tmpfile)
temp = ovl_do_tmpfile(c->workdir, c->stat.mode); temp = ovl_do_tmpfile(c->workdir, c->stat.mode);
if (IS_ERR(temp)) else
goto temp_err; temp = ovl_create_temp(c->workdir, &cattr);
} else {
temp = ovl_lookup_temp(c->workdir);
if (IS_ERR(temp))
goto temp_err;
err = ovl_create_real(d_inode(c->workdir), temp, &cattr,
NULL, true);
if (err) {
dput(temp);
goto out;
}
}
err = 0;
*tempp = temp;
out: out:
if (new_creds) { if (new_creds) {
revert_creds(old_creds); revert_creds(old_creds);
put_cred(new_creds); put_cred(new_creds);
} }
return err; return temp;
temp_err:
err = PTR_ERR(temp);
goto out;
} }
static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp) static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)
...@@ -579,21 +548,21 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c) ...@@ -579,21 +548,21 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c)
struct inode *udir = c->destdir->d_inode; struct inode *udir = c->destdir->d_inode;
struct inode *inode; struct inode *inode;
struct dentry *newdentry = NULL; struct dentry *newdentry = NULL;
struct dentry *temp = NULL; struct dentry *temp;
int err; int err;
err = ovl_get_tmpfile(c, &temp); temp = ovl_get_tmpfile(c);
if (err) if (IS_ERR(temp))
goto out; return PTR_ERR(temp);
err = ovl_copy_up_inode(c, temp); err = ovl_copy_up_inode(c, temp);
if (err) if (err)
goto out_cleanup; goto out;
if (S_ISDIR(c->stat.mode) && c->indexed) { if (S_ISDIR(c->stat.mode) && c->indexed) {
err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp); err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp);
if (err) if (err)
goto out_cleanup; goto out;
} }
if (c->tmpfile) { if (c->tmpfile) {
...@@ -604,7 +573,7 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c) ...@@ -604,7 +573,7 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c)
err = ovl_install_temp(c, temp, &newdentry); err = ovl_install_temp(c, temp, &newdentry);
} }
if (err) if (err)
goto out_cleanup; goto out;
inode = d_inode(c->dentry); inode = d_inode(c->dentry);
ovl_inode_update(inode, newdentry); ovl_inode_update(inode, newdentry);
...@@ -612,13 +581,11 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c) ...@@ -612,13 +581,11 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c)
ovl_set_flag(OVL_WHITEOUTS, inode); ovl_set_flag(OVL_WHITEOUTS, inode);
out: out:
if (err && !c->tmpfile)
ovl_cleanup(d_inode(c->workdir), temp);
dput(temp); dput(temp);
return err; return err;
out_cleanup:
if (!c->tmpfile)
ovl_cleanup(d_inode(c->workdir), temp);
goto out;
} }
/* /*
......
This diff is collapsed.
...@@ -300,12 +300,18 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb, ...@@ -300,12 +300,18 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
struct ovl_entry *oe; struct ovl_entry *oe;
struct ovl_inode_params oip = {
.lowerpath = lowerpath,
.index = index,
.numlower = !!lower
};
/* We get overlay directory dentries with ovl_lookup_real() */ /* We get overlay directory dentries with ovl_lookup_real() */
if (d_is_dir(upper ?: lower)) if (d_is_dir(upper ?: lower))
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
inode = ovl_get_inode(sb, dget(upper), lowerpath, index, !!lower); oip.upperdentry = dget(upper);
inode = ovl_get_inode(sb, &oip);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
dput(upper); dput(upper);
return ERR_CAST(inode); return ERR_CAST(inode);
......
...@@ -749,15 +749,26 @@ static bool ovl_hash_bylower(struct super_block *sb, struct dentry *upper, ...@@ -749,15 +749,26 @@ static bool ovl_hash_bylower(struct super_block *sb, struct dentry *upper,
return true; return true;
} }
struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry, static struct inode *ovl_iget5(struct super_block *sb, struct inode *newinode,
struct ovl_path *lowerpath, struct dentry *index, struct inode *key)
unsigned int numlower)
{ {
return newinode ? inode_insert5(newinode, (unsigned long) key,
ovl_inode_test, ovl_inode_set, key) :
iget5_locked(sb, (unsigned long) key,
ovl_inode_test, ovl_inode_set, key);
}
struct inode *ovl_get_inode(struct super_block *sb,
struct ovl_inode_params *oip)
{
struct dentry *upperdentry = oip->upperdentry;
struct ovl_path *lowerpath = oip->lowerpath;
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;
bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry, index); bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry,
int fsid = bylower ? lowerpath->layer->fsid : 0; oip->index);
int fsid = bylower ? oip->lowerpath->layer->fsid : 0;
bool is_dir; bool is_dir;
unsigned long ino = 0; unsigned long ino = 0;
...@@ -774,8 +785,7 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry, ...@@ -774,8 +785,7 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
upperdentry); upperdentry);
unsigned int nlink = is_dir ? 1 : realinode->i_nlink; unsigned int nlink = is_dir ? 1 : realinode->i_nlink;
inode = iget5_locked(sb, (unsigned long) key, inode = ovl_iget5(sb, oip->newinode, key);
ovl_inode_test, ovl_inode_set, key);
if (!inode) if (!inode)
goto out_nomem; goto out_nomem;
if (!(inode->i_state & I_NEW)) { if (!(inode->i_state & I_NEW)) {
...@@ -811,12 +821,12 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry, ...@@ -811,12 +821,12 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
if (upperdentry && ovl_is_impuredir(upperdentry)) if (upperdentry && ovl_is_impuredir(upperdentry))
ovl_set_flag(OVL_IMPURE, inode); ovl_set_flag(OVL_IMPURE, inode);
if (index) if (oip->index)
ovl_set_flag(OVL_INDEX, inode); ovl_set_flag(OVL_INDEX, inode);
/* 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) || numlower > 1) || if (((upperdentry && lowerdentry) || oip->numlower > 1) ||
ovl_check_origin_xattr(upperdentry ?: lowerdentry)) { ovl_check_origin_xattr(upperdentry ?: lowerdentry)) {
ovl_set_flag(OVL_WHITEOUTS, inode); ovl_set_flag(OVL_WHITEOUTS, inode);
} }
......
...@@ -1004,8 +1004,14 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, ...@@ -1004,8 +1004,14 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
upperdentry = dget(index); upperdentry = dget(index);
if (upperdentry || ctr) { if (upperdentry || ctr) {
inode = ovl_get_inode(dentry->d_sb, upperdentry, stack, index, struct ovl_inode_params oip = {
ctr); .upperdentry = upperdentry,
.lowerpath = stack,
.index = index,
.numlower = ctr,
};
inode = ovl_get_inode(dentry->d_sb, &oip);
err = PTR_ERR(inode); err = PTR_ERR(inode);
if (IS_ERR(inode)) if (IS_ERR(inode))
goto out_free_oe; goto out_free_oe;
......
...@@ -86,6 +86,7 @@ struct ovl_fh { ...@@ -86,6 +86,7 @@ struct ovl_fh {
static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry) static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
{ {
int err = vfs_rmdir(dir, dentry); int err = vfs_rmdir(dir, dentry);
pr_debug("rmdir(%pd2) = %i\n", dentry, err); pr_debug("rmdir(%pd2) = %i\n", dentry, err);
return err; return err;
} }
...@@ -93,56 +94,52 @@ static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -93,56 +94,52 @@ static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry) static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)
{ {
int err = vfs_unlink(dir, dentry, NULL); int err = vfs_unlink(dir, dentry, NULL);
pr_debug("unlink(%pd2) = %i\n", dentry, err); pr_debug("unlink(%pd2) = %i\n", dentry, err);
return err; return err;
} }
static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir, static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,
struct dentry *new_dentry, bool debug) struct dentry *new_dentry)
{ {
int err = vfs_link(old_dentry, dir, new_dentry, NULL); int err = vfs_link(old_dentry, dir, new_dentry, NULL);
if (debug) {
pr_debug("link(%pd2, %pd2) = %i\n", pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err);
old_dentry, new_dentry, err);
}
return err; return err;
} }
static inline int ovl_do_create(struct inode *dir, struct dentry *dentry, static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,
umode_t mode, bool debug) umode_t mode)
{ {
int err = vfs_create(dir, dentry, mode, true); int err = vfs_create(dir, dentry, mode, true);
if (debug)
pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
return err; return err;
} }
static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry, static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,
umode_t mode, bool debug) umode_t mode)
{ {
int err = vfs_mkdir(dir, dentry, mode); int err = vfs_mkdir(dir, dentry, mode);
if (debug) pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
return err; return err;
} }
static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry, static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,
umode_t mode, dev_t dev, bool debug) umode_t mode, dev_t dev)
{ {
int err = vfs_mknod(dir, dentry, mode, dev); int err = vfs_mknod(dir, dentry, mode, dev);
if (debug) {
pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err);
dentry, mode, dev, err);
}
return err; return err;
} }
static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry, static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
const char *oldname, bool debug) const char *oldname)
{ {
int err = vfs_symlink(dir, dentry, oldname); int err = vfs_symlink(dir, dentry, oldname);
if (debug)
pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err); pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
return err; return err;
} }
...@@ -168,11 +165,8 @@ static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry, ...@@ -168,11 +165,8 @@ static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,
{ {
int err; int err;
pr_debug("rename(%pd2, %pd2, 0x%x)\n", pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags);
olddentry, newdentry, flags);
err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags); err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags);
if (err) { if (err) {
pr_debug("...rename(%pd2, %pd2, ...) = %i\n", pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
olddentry, newdentry, err); olddentry, newdentry, err);
...@@ -334,12 +328,18 @@ int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags); ...@@ -334,12 +328,18 @@ int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags);
int ovl_update_time(struct inode *inode, struct timespec *ts, int flags); int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);
bool ovl_is_private_xattr(const char *name); bool ovl_is_private_xattr(const char *name);
struct ovl_inode_params {
struct inode *newinode;
struct dentry *upperdentry;
struct ovl_path *lowerpath;
struct dentry *index;
unsigned int numlower;
};
struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
bool is_upper); bool is_upper);
struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry, struct inode *ovl_get_inode(struct super_block *sb,
struct ovl_path *lowerpath, struct dentry *index, struct ovl_inode_params *oip);
unsigned int numlower);
static inline void ovl_copyattr(struct inode *from, struct inode *to) static inline void ovl_copyattr(struct inode *from, struct inode *to)
{ {
to->i_uid = from->i_uid; to->i_uid = from->i_uid;
...@@ -352,18 +352,21 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to) ...@@ -352,18 +352,21 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to)
/* dir.c */ /* dir.c */
extern const struct inode_operations ovl_dir_inode_operations; extern const struct inode_operations ovl_dir_inode_operations;
struct dentry *ovl_lookup_temp(struct dentry *workdir);
int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir,
struct dentry *dentry); struct dentry *dentry);
struct cattr { struct ovl_cattr {
dev_t rdev; dev_t rdev;
umode_t mode; umode_t mode;
const char *link; const char *link;
struct dentry *hardlink;
}; };
int ovl_create_real(struct inode *dir, struct dentry *newdentry,
struct cattr *attr, #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
struct dentry *hardlink, bool debug);
struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry,
struct ovl_cattr *attr);
int ovl_cleanup(struct inode *dir, struct dentry *dentry); int ovl_cleanup(struct inode *dir, struct dentry *dentry);
struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr);
/* copy_up.c */ /* copy_up.c */
int ovl_copy_up(struct dentry *dentry); int ovl_copy_up(struct dentry *dentry);
......
...@@ -611,11 +611,10 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs, ...@@ -611,11 +611,10 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
goto retry; goto retry;
} }
err = ovl_create_real(dir, work, work = ovl_create_real(dir, work, OVL_CATTR(attr.ia_mode));
&(struct cattr){.mode = S_IFDIR | 0}, err = PTR_ERR(work);
NULL, true); if (IS_ERR(work))
if (err) goto out_err;
goto out_dput;
/* /*
* Try to remove POSIX ACL xattrs from workdir. We are good if: * Try to remove POSIX ACL xattrs from workdir. We are good if:
......
...@@ -2886,6 +2886,10 @@ extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, ...@@ -2886,6 +2886,10 @@ extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
int (*test)(struct inode *, void *), void *data); int (*test)(struct inode *, void *), void *data);
extern struct inode *ilookup(struct super_block *sb, unsigned long ino); extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
extern struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
int (*test)(struct inode *, void *),
int (*set)(struct inode *, void *),
void *data);
extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
extern struct inode * iget_locked(struct super_block *, unsigned long); extern struct inode * iget_locked(struct super_block *, unsigned long);
extern struct inode *find_inode_nowait(struct super_block *, extern struct inode *find_inode_nowait(struct super_block *,
......
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