Commit 531d56ec authored by Jeff Garzik's avatar Jeff Garzik

After Al Viro's recent swapfile cleanup, the swap_device member of

swap_info_struct became pretty much superfluous.  As we are minimizing
kdev_t usage anyway, I took the opportunity to remove swap_device
member, and replace the remaining usages with SWP_BLOCKDEV bit flag.

Adding SWP_BLOCKDEV in turn motivated a small cleanup of the
SWP_xxx bit flags and their usage.

Patch has been in light testing for a couple weeks, and
has been glanced at by Al.  "looks sane"
parent 0a67f33c
...@@ -50,8 +50,12 @@ union swap_header { ...@@ -50,8 +50,12 @@ union swap_header {
#include <asm/atomic.h> #include <asm/atomic.h>
#define SWP_USED 1 enum {
#define SWP_WRITEOK 3 SWP_USED = (1 << 0), /* is slot in swap_info[] used? */
SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */
SWP_BLOCKDEV = (1 << 2), /* is this swap a block device? */
SWP_ACTIVE = (SWP_USED | SWP_WRITEOK),
};
#define SWAP_CLUSTER_MAX 32 #define SWAP_CLUSTER_MAX 32
...@@ -63,7 +67,6 @@ union swap_header { ...@@ -63,7 +67,6 @@ union swap_header {
*/ */
struct swap_info_struct { struct swap_info_struct {
unsigned int flags; unsigned int flags;
kdev_t swap_device;
spinlock_t sdev_lock; spinlock_t sdev_lock;
struct file *swap_file; struct file *swap_file;
unsigned short * swap_map; unsigned short * swap_map;
......
...@@ -114,7 +114,7 @@ swp_entry_t get_swap_page(void) ...@@ -114,7 +114,7 @@ swp_entry_t get_swap_page(void)
while (1) { while (1) {
p = &swap_info[type]; p = &swap_info[type];
if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) { if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
swap_device_lock(p); swap_device_lock(p);
offset = scan_swap_map(p); offset = scan_swap_map(p);
swap_device_unlock(p); swap_device_unlock(p);
...@@ -729,7 +729,7 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -729,7 +729,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
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_WRITEOK) == SWP_WRITEOK) { if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
if (p->swap_file->f_dentry == nd.dentry) if (p->swap_file->f_dentry == nd.dentry)
break; break;
} }
...@@ -752,7 +752,7 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -752,7 +752,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
} }
nr_swap_pages -= p->pages; nr_swap_pages -= p->pages;
total_swap_pages -= p->pages; total_swap_pages -= p->pages;
p->flags = SWP_USED; p->flags &= ~SWP_WRITEOK;
swap_list_unlock(); swap_list_unlock();
unlock_kernel(); unlock_kernel();
err = try_to_unuse(type); err = try_to_unuse(type);
...@@ -770,7 +770,7 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -770,7 +770,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
swap_info[prev].next = p - swap_info; swap_info[prev].next = p - swap_info;
nr_swap_pages += p->pages; nr_swap_pages += p->pages;
total_swap_pages += p->pages; total_swap_pages += p->pages;
p->flags = SWP_WRITEOK; p->flags |= SWP_WRITEOK;
swap_list_unlock(); swap_list_unlock();
goto out_dput; goto out_dput;
} }
...@@ -778,7 +778,6 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -778,7 +778,6 @@ asmlinkage long sys_swapoff(const char * specialfile)
swap_device_lock(p); swap_device_lock(p);
swap_file = p->swap_file; swap_file = p->swap_file;
p->swap_file = NULL; p->swap_file = NULL;
p->swap_device = NODEV;
p->max = 0; p->max = 0;
swap_map = p->swap_map; swap_map = p->swap_map;
p->swap_map = NULL; p->swap_map = NULL;
...@@ -822,7 +821,8 @@ int get_swaparea_info(char *buf) ...@@ -822,7 +821,8 @@ int get_swaparea_info(char *buf)
} }
len += sprintf(buf + len, "%-39s %s\t%d\t%d\t%d\n", len += sprintf(buf + len, "%-39s %s\t%d\t%d\t%d\n",
path, path,
!kdev_none(ptr->swap_device) ? "partition" : "file\t", (ptr->flags & SWP_BLOCKDEV) ?
"partition" : "file\t",
ptr->pages << (PAGE_SHIFT - 10), ptr->pages << (PAGE_SHIFT - 10),
usedswap << (PAGE_SHIFT - 10), usedswap << (PAGE_SHIFT - 10),
ptr->prio); ptr->prio);
...@@ -837,8 +837,9 @@ int is_swap_partition(kdev_t dev) { ...@@ -837,8 +837,9 @@ int is_swap_partition(kdev_t dev) {
int i; int i;
for (i = 0 ; i < nr_swapfiles ; i++, ptr++) { for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
if (ptr->flags & SWP_USED) if ((ptr->flags & SWP_USED) &&
if (kdev_same(ptr->swap_device, dev)) (ptr->flags & SWP_BLOCKDEV) &&
(kdev_same(ptr->swap_file->f_dentry->d_inode->i_rdev, dev)))
return 1; return 1;
} }
return 0; return 0;
...@@ -883,7 +884,6 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -883,7 +884,6 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
nr_swapfiles = type+1; nr_swapfiles = type+1;
p->flags = SWP_USED; p->flags = SWP_USED;
p->swap_file = NULL; p->swap_file = NULL;
p->swap_device = NODEV;
p->swap_map = NULL; p->swap_map = NULL;
p->lowest_bit = 0; p->lowest_bit = 0;
p->highest_bit = 0; p->highest_bit = 0;
...@@ -911,8 +911,10 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -911,8 +911,10 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
error = -EINVAL; error = -EINVAL;
if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) { if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) {
p->swap_device = swap_file->f_dentry->d_inode->i_rdev; error = set_blocksize(swap_file->f_dentry->d_inode->i_rdev,
set_blocksize(p->swap_device, PAGE_SIZE); PAGE_SIZE);
if (error < 0)
goto bad_swap;
} else if (!S_ISREG(swap_file->f_dentry->d_inode->i_mode)) } else if (!S_ISREG(swap_file->f_dentry->d_inode->i_mode))
goto bad_swap; goto bad_swap;
...@@ -1035,7 +1037,9 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -1035,7 +1037,9 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
swap_list_lock(); swap_list_lock();
swap_device_lock(p); swap_device_lock(p);
p->max = maxpages; p->max = maxpages;
p->flags = SWP_WRITEOK; p->flags = SWP_ACTIVE;
if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode))
p->flags |= SWP_BLOCKDEV;
p->pages = nr_good_pages; p->pages = nr_good_pages;
nr_swap_pages += nr_good_pages; nr_swap_pages += nr_good_pages;
total_swap_pages += nr_good_pages; total_swap_pages += nr_good_pages;
...@@ -1064,7 +1068,6 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -1064,7 +1068,6 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
bad_swap_2: bad_swap_2:
swap_list_lock(); swap_list_lock();
swap_map = p->swap_map; swap_map = p->swap_map;
p->swap_device = NODEV;
p->swap_file = NULL; p->swap_file = NULL;
p->swap_map = NULL; p->swap_map = NULL;
p->flags = 0; p->flags = 0;
...@@ -1090,7 +1093,7 @@ void si_swapinfo(struct sysinfo *val) ...@@ -1090,7 +1093,7 @@ void si_swapinfo(struct sysinfo *val)
swap_list_lock(); swap_list_lock();
for (i = 0; i < nr_swapfiles; i++) { for (i = 0; i < nr_swapfiles; i++) {
unsigned int j; unsigned int j;
if (swap_info[i].flags != SWP_USED) if (!(swap_info[i].flags & SWP_USED))
continue; continue;
for (j = 0; j < swap_info[i].max; ++j) { for (j = 0; j < swap_info[i].max; ++j) {
switch (swap_info[i].swap_map[j]) { switch (swap_info[i].swap_map[j]) {
......
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