Skip to content

Commit

Permalink
afs: Don't over-increment the cell usage count when pinning it
Browse files Browse the repository at this point in the history
AFS cells that are added or set as the workstation cell through /proc are
pinned against removal by setting the AFS_CELL_FL_NO_GC flag on them and
taking a ref.  The ref should be only taken if the flag wasn't already set.

Fix this by making it conditional.

Without this an assertion failure will occur during module removal
indicating that the refcount is too elevated.

Signed-off-by: David Howells <[email protected]>
  • Loading branch information
dhowells committed Apr 9, 2018
1 parent fe342cf commit 17814ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fs/afs/cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ int afs_cell_init(struct afs_net *net, const char *rootcell)
return PTR_ERR(new_root);
}

set_bit(AFS_CELL_FL_NO_GC, &new_root->flags);
afs_get_cell(new_root);
if (!test_and_set_bit(AFS_CELL_FL_NO_GC, &new_root->flags))
afs_get_cell(new_root);

/* install the new cell */
write_seqlock(&net->cells_lock);
Expand Down
3 changes: 2 additions & 1 deletion fs/afs/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
goto done;
}

set_bit(AFS_CELL_FL_NO_GC, &cell->flags);
if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags))
afs_put_cell(net, cell);
printk("kAFS: Added new cell '%s'\n", name);
} else {
goto inval;
Expand Down

0 comments on commit 17814ae

Please sign in to comment.