Commit 21a22878 authored by Amir Goldstein's avatar Amir Goldstein Committed by Miklos Szeredi

ovl: handle rename when upper doesn't support xattr

On failure to set opaque/redirect xattr on rename, skip setting xattr and
return -EXDEV.

On failure to set opaque xattr when creating a new directory, -EIO is
returned instead of -EOPNOTSUPP.

Any failure to set those xattr will be recorded in super block and
then setting any xattr on upper won't be attempted again.
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 6266d465
...@@ -127,17 +127,28 @@ int ovl_create_real(struct inode *dir, struct dentry *newdentry, ...@@ -127,17 +127,28 @@ int ovl_create_real(struct inode *dir, struct dentry *newdentry,
return err; return err;
} }
static int ovl_set_opaque(struct dentry *dentry, struct dentry *upperdentry) static int ovl_set_opaque_xerr(struct dentry *dentry, struct dentry *upper,
int xerr)
{ {
int err; int err;
err = ovl_do_setxattr(upperdentry, OVL_XATTR_OPAQUE, "y", 1, 0); err = ovl_check_setxattr(dentry, upper, OVL_XATTR_OPAQUE, "y", 1, xerr);
if (!err) if (!err)
ovl_dentry_set_opaque(dentry); ovl_dentry_set_opaque(dentry);
return err; return err;
} }
static int ovl_set_opaque(struct dentry *dentry, struct dentry *upperdentry)
{
/*
* Fail with -EIO when trying to create opaque dir and upper doesn't
* support xattrs. ovl_rename() calls ovl_set_opaque_xerr(-EXDEV) to
* return a specific error for noxattr case.
*/
return ovl_set_opaque_xerr(dentry, upperdentry, -EIO);
}
/* Common operations required to be done after creation of file on upper */ /* Common operations required to be done after creation of file on upper */
static void ovl_instantiate(struct dentry *dentry, struct inode *inode, static void ovl_instantiate(struct dentry *dentry, struct inode *inode,
struct dentry *newdentry, bool hardlink) struct dentry *newdentry, bool hardlink)
...@@ -846,18 +857,16 @@ static int ovl_set_redirect(struct dentry *dentry, bool samedir) ...@@ -846,18 +857,16 @@ static int ovl_set_redirect(struct dentry *dentry, bool samedir)
if (IS_ERR(redirect)) if (IS_ERR(redirect))
return PTR_ERR(redirect); return PTR_ERR(redirect);
err = ovl_do_setxattr(ovl_dentry_upper(dentry), OVL_XATTR_REDIRECT, err = ovl_check_setxattr(dentry, ovl_dentry_upper(dentry),
redirect, strlen(redirect), 0); OVL_XATTR_REDIRECT,
redirect, strlen(redirect), -EXDEV);
if (!err) { if (!err) {
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
ovl_dentry_set_redirect(dentry, redirect); ovl_dentry_set_redirect(dentry, redirect);
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
} else { } else {
kfree(redirect); kfree(redirect);
if (err == -EOPNOTSUPP) pr_warn_ratelimited("overlay: failed to set redirect (%i)\n", err);
ovl_clear_redirect_dir(dentry->d_sb);
else
pr_warn_ratelimited("overlay: failed to set redirect (%i)\n", err);
/* Fall back to userspace copy-up */ /* Fall back to userspace copy-up */
err = -EXDEV; err = -EXDEV;
} }
...@@ -992,7 +1001,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old, ...@@ -992,7 +1001,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
if (ovl_type_merge_or_lower(old)) if (ovl_type_merge_or_lower(old))
err = ovl_set_redirect(old, samedir); err = ovl_set_redirect(old, samedir);
else if (!old_opaque && ovl_type_merge(new->d_parent)) else if (!old_opaque && ovl_type_merge(new->d_parent))
err = ovl_set_opaque(old, olddentry); err = ovl_set_opaque_xerr(old, olddentry, -EXDEV);
if (err) if (err)
goto out_dput; goto out_dput;
} }
...@@ -1000,7 +1009,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old, ...@@ -1000,7 +1009,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
if (ovl_type_merge_or_lower(new)) if (ovl_type_merge_or_lower(new))
err = ovl_set_redirect(new, samedir); err = ovl_set_redirect(new, samedir);
else if (!new_opaque && ovl_type_merge(old->d_parent)) else if (!new_opaque && ovl_type_merge(old->d_parent))
err = ovl_set_opaque(new, newdentry); err = ovl_set_opaque_xerr(new, newdentry, -EXDEV);
if (err) if (err)
goto out_dput; goto out_dput;
} }
......
...@@ -206,7 +206,6 @@ bool ovl_dentry_is_opaque(struct dentry *dentry); ...@@ -206,7 +206,6 @@ bool ovl_dentry_is_opaque(struct dentry *dentry);
bool ovl_dentry_is_whiteout(struct dentry *dentry); bool ovl_dentry_is_whiteout(struct dentry *dentry);
void ovl_dentry_set_opaque(struct dentry *dentry); void ovl_dentry_set_opaque(struct dentry *dentry);
bool ovl_redirect_dir(struct super_block *sb); bool ovl_redirect_dir(struct super_block *sb);
void ovl_clear_redirect_dir(struct super_block *sb);
const char *ovl_dentry_get_redirect(struct dentry *dentry); const char *ovl_dentry_get_redirect(struct dentry *dentry);
void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry); void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
......
...@@ -191,14 +191,7 @@ bool ovl_redirect_dir(struct super_block *sb) ...@@ -191,14 +191,7 @@ bool ovl_redirect_dir(struct super_block *sb)
{ {
struct ovl_fs *ofs = sb->s_fs_info; struct ovl_fs *ofs = sb->s_fs_info;
return ofs->config.redirect_dir; return ofs->config.redirect_dir && !ofs->noxattr;
}
void ovl_clear_redirect_dir(struct super_block *sb)
{
struct ovl_fs *ofs = sb->s_fs_info;
ofs->config.redirect_dir = false;
} }
const char *ovl_dentry_get_redirect(struct dentry *dentry) const char *ovl_dentry_get_redirect(struct dentry *dentry)
......
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