Commit 76a79709 authored by Alexander Viro's avatar Alexander Viro Committed by Andy Grover

[PATCH] sys_swapoff() cleanup

Instead of user_path_walk() and comparing dentries, sys_swapoff()
opens its argument and compares ->i_mapping.  Result: slightly
simpler code and swapoff(2) becomes tolerant to e.g.

	swapon /dev/sda2
	switch root from initrd to sda1
	....
	swapoff /dev/sda2  # where /dev is from sda1, not from initrd

current tree fails in the case above (different dentries -> no love).
parent efcea164
......@@ -959,24 +959,26 @@ asmlinkage long sys_swapoff(const char * specialfile)
{
struct swap_info_struct * p = NULL;
unsigned short *swap_map;
struct file *swap_file;
struct nameidata nd;
struct file *swap_file, *victim;
struct address_space *mapping;
int i, type, prev;
int err;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
err = user_path_walk(specialfile, &nd);
if (err)
victim = filp_open(specialfile, O_RDWR, 0);
err = PTR_ERR(victim);
if (IS_ERR(victim))
goto out;
mapping = victim->f_dentry->d_inode->i_mapping;
prev = -1;
swap_list_lock();
for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
p = swap_info + type;
if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
if (p->swap_file->f_dentry == nd.dentry)
if (p->swap_file->f_dentry->d_inode->i_mapping==mapping)
break;
}
prev = type;
......@@ -1040,7 +1042,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
err = 0;
out_dput:
path_release(&nd);
filp_close(victim, NULL);
out:
return err;
}
......
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