a couple of shmem rename fixes - recent regression from tree-in-dcache
series and older breakage from stable directory offsets stuff. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQqUNBr3gm4hGXdBJlZ7Krx/gZQ6wUCaUD1egAKCRBZ7Krx/gZQ 693YAQDWMzqUs8bJx95frxidF4fJ658K/bZWHuG9eLDvhF2CxAEAoIWt5EbJ1dE0 NEIg/+kdVpKpk1DH7SZTzc+Mgbe4aAE= =/LtU -----END PGP SIGNATURE----- Merge tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs Pull shmem rename fixes from Al Viro: "A couple of shmem rename fixes - recent regression from tree-in-dcache series and older breakage from stable directory offsets stuff" * tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: shmem: fix recovery on rename failures shmem_whiteout(): fix regression from tree-in-dcache seriesmaster
commit
40fbbd64bb
50
fs/libfs.c
50
fs/libfs.c
|
|
@ -346,22 +346,22 @@ void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry)
|
|||
* User space expects the directory offset value of the replaced
|
||||
* (new) directory entry to be unchanged after a rename.
|
||||
*
|
||||
* Returns zero on success, a negative errno value on failure.
|
||||
* Caller must have grabbed a slot for new_dentry in the maple_tree
|
||||
* associated with new_dir, even if dentry is negative.
|
||||
*/
|
||||
int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry)
|
||||
void simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry)
|
||||
{
|
||||
struct offset_ctx *old_ctx = old_dir->i_op->get_offset_ctx(old_dir);
|
||||
struct offset_ctx *new_ctx = new_dir->i_op->get_offset_ctx(new_dir);
|
||||
long new_offset = dentry2offset(new_dentry);
|
||||
|
||||
simple_offset_remove(old_ctx, old_dentry);
|
||||
if (WARN_ON(!new_offset))
|
||||
return;
|
||||
|
||||
if (new_offset) {
|
||||
offset_set(new_dentry, 0);
|
||||
return simple_offset_replace(new_ctx, old_dentry, new_offset);
|
||||
}
|
||||
return simple_offset_add(new_ctx, old_dentry);
|
||||
simple_offset_remove(old_ctx, old_dentry);
|
||||
offset_set(new_dentry, 0);
|
||||
WARN_ON(simple_offset_replace(new_ctx, old_dentry, new_offset));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -388,31 +388,23 @@ int simple_offset_rename_exchange(struct inode *old_dir,
|
|||
long new_index = dentry2offset(new_dentry);
|
||||
int ret;
|
||||
|
||||
simple_offset_remove(old_ctx, old_dentry);
|
||||
simple_offset_remove(new_ctx, new_dentry);
|
||||
if (WARN_ON(!old_index || !new_index))
|
||||
return -EINVAL;
|
||||
|
||||
ret = simple_offset_replace(new_ctx, old_dentry, new_index);
|
||||
if (ret)
|
||||
goto out_restore;
|
||||
ret = mtree_store(&new_ctx->mt, new_index, old_dentry, GFP_KERNEL);
|
||||
if (WARN_ON(ret))
|
||||
return ret;
|
||||
|
||||
ret = simple_offset_replace(old_ctx, new_dentry, old_index);
|
||||
if (ret) {
|
||||
simple_offset_remove(new_ctx, old_dentry);
|
||||
goto out_restore;
|
||||
ret = mtree_store(&old_ctx->mt, old_index, new_dentry, GFP_KERNEL);
|
||||
if (WARN_ON(ret)) {
|
||||
mtree_store(&new_ctx->mt, new_index, new_dentry, GFP_KERNEL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
|
||||
if (ret) {
|
||||
simple_offset_remove(new_ctx, old_dentry);
|
||||
simple_offset_remove(old_ctx, new_dentry);
|
||||
goto out_restore;
|
||||
}
|
||||
offset_set(old_dentry, new_index);
|
||||
offset_set(new_dentry, old_index);
|
||||
simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
|
||||
return 0;
|
||||
|
||||
out_restore:
|
||||
(void)simple_offset_replace(old_ctx, old_dentry, old_index);
|
||||
(void)simple_offset_replace(new_ctx, new_dentry, new_index);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3247,7 +3247,7 @@ struct offset_ctx {
|
|||
void simple_offset_init(struct offset_ctx *octx);
|
||||
int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry);
|
||||
void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry);
|
||||
int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
void simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry);
|
||||
int simple_offset_rename_exchange(struct inode *old_dir,
|
||||
struct dentry *old_dentry,
|
||||
|
|
|
|||
38
mm/shmem.c
38
mm/shmem.c
|
|
@ -4019,22 +4019,10 @@ static int shmem_whiteout(struct mnt_idmap *idmap,
|
|||
whiteout = d_alloc(old_dentry->d_parent, &old_dentry->d_name);
|
||||
if (!whiteout)
|
||||
return -ENOMEM;
|
||||
|
||||
error = shmem_mknod(idmap, old_dir, whiteout,
|
||||
S_IFCHR | WHITEOUT_MODE, WHITEOUT_DEV);
|
||||
dput(whiteout);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
/*
|
||||
* Cheat and hash the whiteout while the old dentry is still in
|
||||
* place, instead of playing games with FS_RENAME_DOES_D_MOVE.
|
||||
*
|
||||
* d_lookup() will consistently find one of them at this point,
|
||||
* not sure which one, but that isn't even important.
|
||||
*/
|
||||
d_rehash(whiteout);
|
||||
return 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -4050,6 +4038,7 @@ static int shmem_rename2(struct mnt_idmap *idmap,
|
|||
{
|
||||
struct inode *inode = d_inode(old_dentry);
|
||||
int they_are_dirs = S_ISDIR(inode->i_mode);
|
||||
bool had_offset = false;
|
||||
int error;
|
||||
|
||||
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
|
||||
|
|
@ -4062,16 +4051,23 @@ static int shmem_rename2(struct mnt_idmap *idmap,
|
|||
if (!simple_empty(new_dentry))
|
||||
return -ENOTEMPTY;
|
||||
|
||||
if (flags & RENAME_WHITEOUT) {
|
||||
error = shmem_whiteout(idmap, old_dir, old_dentry);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
|
||||
error = simple_offset_rename(old_dir, old_dentry, new_dir, new_dentry);
|
||||
if (error)
|
||||
error = simple_offset_add(shmem_get_offset_ctx(new_dir), new_dentry);
|
||||
if (error == -EBUSY)
|
||||
had_offset = true;
|
||||
else if (unlikely(error))
|
||||
return error;
|
||||
|
||||
if (flags & RENAME_WHITEOUT) {
|
||||
error = shmem_whiteout(idmap, old_dir, old_dentry);
|
||||
if (error) {
|
||||
if (!had_offset)
|
||||
simple_offset_remove(shmem_get_offset_ctx(new_dir),
|
||||
new_dentry);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
simple_offset_rename(old_dir, old_dentry, new_dir, new_dentry);
|
||||
if (d_really_is_positive(new_dentry)) {
|
||||
(void) shmem_unlink(new_dir, new_dentry);
|
||||
if (they_are_dirs) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue