mm/zswap: make sure each swapfile always have zswap rb-tree
[linux-2.6-microblaze.git] / mm / swapfile.c
index 746aa9d..b3a83c5 100644 (file)
@@ -2348,8 +2348,6 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,
                                unsigned char *swap_map,
                                struct swap_cluster_info *cluster_info)
 {
-       zswap_swapon(p->type);
-
        spin_lock(&swap_lock);
        spin_lock(&p->lock);
        setup_swap_info(p, prio, swap_map, cluster_info);
@@ -3167,6 +3165,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
        if (error)
                goto bad_swap_unlock_inode;
 
+       error = zswap_swapon(p->type);
+       if (error)
+               goto free_swap_address_space;
+
        /*
         * Flush any pending IO and dirty mappings before we start using this
         * swap device.
@@ -3175,7 +3177,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
        error = inode_drain_writes(inode);
        if (error) {
                inode->i_flags &= ~S_SWAPFILE;
-               goto free_swap_address_space;
+               goto free_swap_zswap;
        }
 
        mutex_lock(&swapon_mutex);
@@ -3199,6 +3201,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 
        error = 0;
        goto out;
+free_swap_zswap:
+       zswap_swapoff(p->type);
 free_swap_address_space:
        exit_swap_address_space(p->type);
 bad_swap_unlock_inode: