Skip to content

Commit

Permalink
afs: Fix unlink
Browse files Browse the repository at this point in the history
Repeating creation and deletion of a file on an afs mount will run the box
out of memory, e.g.:

	dd if=/dev/zero of=/afs/scratch/m0 bs=$((1024*1024)) count=512
	rm /afs/scratch/m0

The problem seems to be that it's not properly decrementing the nlink count
so that the inode can be scrapped.

Note that this doesn't fix local creation followed by remote deletion.
That's harder to handle and will require a separate patch as we're not told
that the file has been deleted - only that the directory has changed.

Reported-by: Marc Dionne <[email protected]>
Signed-off-by: David Howells <[email protected]>
  • Loading branch information
dhowells committed Jan 2, 2018
1 parent 7888da9 commit 440fbc3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
37 changes: 29 additions & 8 deletions fs/afs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,20 +895,38 @@ static int afs_rmdir(struct inode *dir, struct dentry *dentry)
* However, if we didn't have a callback promise outstanding, or it was
* outstanding on a different server, then it won't break it either...
*/
static int afs_dir_remove_link(struct dentry *dentry, struct key *key)
static int afs_dir_remove_link(struct dentry *dentry, struct key *key,
unsigned long d_version_before,
unsigned long d_version_after)
{
bool dir_valid;
int ret = 0;

/* There were no intervening changes on the server if the version
* number we got back was incremented by exactly 1.
*/
dir_valid = (d_version_after == d_version_before + 1);

if (d_really_is_positive(dentry)) {
struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));

if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
kdebug("AFS_VNODE_DELETED");
clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);

ret = afs_validate(vnode, key);
if (ret == -ESTALE)
if (dir_valid) {
drop_nlink(&vnode->vfs_inode);
if (vnode->vfs_inode.i_nlink == 0) {
set_bit(AFS_VNODE_DELETED, &vnode->flags);
clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
}
ret = 0;
} else {
clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);

if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
kdebug("AFS_VNODE_DELETED");

ret = afs_validate(vnode, key);
if (ret == -ESTALE)
ret = 0;
}
_debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
}

Expand All @@ -923,6 +941,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
struct afs_fs_cursor fc;
struct afs_vnode *dvnode = AFS_FS_I(dir), *vnode;
struct key *key;
unsigned long d_version = (unsigned long)dentry->d_fsdata;
int ret;

_enter("{%x:%u},{%pd}",
Expand Down Expand Up @@ -955,7 +974,9 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
afs_vnode_commit_status(&fc, dvnode, fc.cb_break);
ret = afs_end_vnode_operation(&fc);
if (ret == 0)
ret = afs_dir_remove_link(dentry, key);
ret = afs_dir_remove_link(
dentry, key, d_version,
(unsigned long)dvnode->status.data_version);
}

error_key:
Expand Down
4 changes: 4 additions & 0 deletions fs/afs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ int afs_validate(struct afs_vnode *vnode, struct key *key)
}

read_sequnlock_excl(&vnode->cb_lock);

if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
clear_nlink(&vnode->vfs_inode);

if (valid)
goto valid;

Expand Down

0 comments on commit 440fbc3

Please sign in to comment.