]> git.hungrycats.org Git - linux/commitdiff
After Al Viro's recent swapfile cleanup, the swap_device member of
authorJeff Garzik <jgarzik@rum.normnet.org>
Fri, 8 Feb 2002 13:11:31 +0000 (08:11 -0500)
committerJeff Garzik <jgarzik@rum.normnet.org>
Fri, 8 Feb 2002 13:11:31 +0000 (08:11 -0500)
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"

include/linux/swap.h
mm/swapfile.c

index b0ac23988cf4c7177472a9b118c98bab915125a1..3535d0dbafe5d899b0a144b2cc8586c4eaff0c4d 100644 (file)
@@ -50,8 +50,12 @@ union swap_header {
 
 #include <asm/atomic.h>
 
-#define SWP_USED       1
-#define SWP_WRITEOK    3
+enum {
+       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
 
@@ -63,7 +67,6 @@ union swap_header {
  */
 struct swap_info_struct {
        unsigned int flags;
-       kdev_t swap_device;
        spinlock_t sdev_lock;
        struct file *swap_file;
        unsigned short * swap_map;
index 925286b4f23e81e0418e5e057bff927a239d97db..fbe389829142dc628c4266c2aa6ffe00cff9bca6 100644 (file)
@@ -114,7 +114,7 @@ swp_entry_t get_swap_page(void)
 
        while (1) {
                p = &swap_info[type];
-               if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
+               if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
                        swap_device_lock(p);
                        offset = scan_swap_map(p);
                        swap_device_unlock(p);
@@ -729,7 +729,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
        swap_list_lock();
        for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
                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)
                                break;
                }
@@ -752,7 +752,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
        }
        nr_swap_pages -= p->pages;
        total_swap_pages -= p->pages;
-       p->flags = SWP_USED;
+       p->flags &= ~SWP_WRITEOK;
        swap_list_unlock();
        unlock_kernel();
        err = try_to_unuse(type);
@@ -770,7 +770,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
                        swap_info[prev].next = p - swap_info;
                nr_swap_pages += p->pages;
                total_swap_pages += p->pages;
-               p->flags = SWP_WRITEOK;
+               p->flags |= SWP_WRITEOK;
                swap_list_unlock();
                goto out_dput;
        }
@@ -778,7 +778,6 @@ asmlinkage long sys_swapoff(const char * specialfile)
        swap_device_lock(p);
        swap_file = p->swap_file;
        p->swap_file = NULL;
-       p->swap_device = NODEV;
        p->max = 0;
        swap_map = p->swap_map;
        p->swap_map = NULL;
@@ -822,7 +821,8 @@ int get_swaparea_info(char *buf)
                                }
                        len += sprintf(buf + len, "%-39s %s\t%d\t%d\t%d\n",
                                       path,
-                                      !kdev_none(ptr->swap_device) ? "partition" : "file\t",
+                                      (ptr->flags & SWP_BLOCKDEV) ?
+                                               "partition" : "file\t",
                                       ptr->pages << (PAGE_SHIFT - 10),
                                       usedswap << (PAGE_SHIFT - 10),
                                       ptr->prio);
@@ -837,9 +837,10 @@ int is_swap_partition(kdev_t dev) {
        int i;
 
        for (i = 0 ; i < nr_swapfiles ; i++, ptr++) {
-               if (ptr->flags & SWP_USED)
-                       if (kdev_same(ptr->swap_device, dev))
-                               return 1;
+               if ((ptr->flags & SWP_USED) &&
+                   (ptr->flags & SWP_BLOCKDEV) &&
+                   (kdev_same(ptr->swap_file->f_dentry->d_inode->i_rdev, dev)))
+                       return 1;
        }
        return 0;
 }
@@ -883,7 +884,6 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
                nr_swapfiles = type+1;
        p->flags = SWP_USED;
        p->swap_file = NULL;
-       p->swap_device = NODEV;
        p->swap_map = NULL;
        p->lowest_bit = 0;
        p->highest_bit = 0;
@@ -911,8 +911,10 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
 
        error = -EINVAL;
        if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) {
-               p->swap_device = swap_file->f_dentry->d_inode->i_rdev;
-               set_blocksize(p->swap_device, PAGE_SIZE);
+               error = set_blocksize(swap_file->f_dentry->d_inode->i_rdev,
+                                     PAGE_SIZE);
+               if (error < 0)
+                       goto bad_swap;
        } else if (!S_ISREG(swap_file->f_dentry->d_inode->i_mode))
                goto bad_swap;
 
@@ -1035,7 +1037,9 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
        swap_list_lock();
        swap_device_lock(p);
        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;
        nr_swap_pages += nr_good_pages;
        total_swap_pages += nr_good_pages;
@@ -1064,7 +1068,6 @@ bad_swap:
 bad_swap_2:
        swap_list_lock();
        swap_map = p->swap_map;
-       p->swap_device = NODEV;
        p->swap_file = NULL;
        p->swap_map = NULL;
        p->flags = 0;
@@ -1090,7 +1093,7 @@ void si_swapinfo(struct sysinfo *val)
        swap_list_lock();
        for (i = 0; i < nr_swapfiles; i++) {
                unsigned int j;
-               if (swap_info[i].flags != SWP_USED)
+               if (!(swap_info[i].flags & SWP_USED))
                        continue;
                for (j = 0; j < swap_info[i].max; ++j) {
                        switch (swap_info[i].swap_map[j]) {