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