zram: drop `init_done' struct zram member
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Mon, 7 Apr 2014 22:38:00 +0000 (15:38 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 7 Apr 2014 23:35:59 +0000 (16:35 -0700)
Introduce init_done() helper function which allows us to drop `init_done'
struct zram member.  init_done() uses the fact that ->init_done == 1
equals to ->meta != NULL.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/block/zram/zram_drv.c
drivers/block/zram/zram_drv.h

index 51c557cfd92b37cf6b7aecdfa50d212fdacc05ee..b3e6f072c19b6bf348dbe45f201fe07a2fab1368 100644 (file)
@@ -42,6 +42,11 @@ static struct zram *zram_devices;
 /* Module params (documentation at end) */
 static unsigned int num_devices = 1;
 
+static inline int init_done(struct zram *zram)
+{
+       return zram->meta != NULL;
+}
+
 static inline struct zram *dev_to_zram(struct device *dev)
 {
        return (struct zram *)dev_to_disk(dev)->private_data;
@@ -60,7 +65,7 @@ static ssize_t initstate_show(struct device *dev,
 {
        struct zram *zram = dev_to_zram(dev);
 
-       return sprintf(buf, "%u\n", zram->init_done);
+       return sprintf(buf, "%u\n", init_done(zram));
 }
 
 static ssize_t num_reads_show(struct device *dev,
@@ -133,7 +138,7 @@ static ssize_t mem_used_total_show(struct device *dev,
        struct zram_meta *meta = zram->meta;
 
        down_read(&zram->init_lock);
-       if (zram->init_done)
+       if (init_done(zram))
                val = zs_get_total_size_bytes(meta->mem_pool);
        up_read(&zram->init_lock);
 
@@ -546,14 +551,12 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
        struct zram_meta *meta;
 
        down_write(&zram->init_lock);
-       if (!zram->init_done) {
+       if (!init_done(zram)) {
                up_write(&zram->init_lock);
                return;
        }
 
        meta = zram->meta;
-       zram->init_done = 0;
-
        /* Free all pages that are still in this zram device */
        for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
                unsigned long handle = meta->table[index].handle;
@@ -594,8 +597,6 @@ static void zram_init_device(struct zram *zram, struct zram_meta *meta)
        queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
 
        zram->meta = meta;
-       zram->init_done = 1;
-
        pr_debug("Initialization done!\n");
 }
 
@@ -615,7 +616,7 @@ static ssize_t disksize_store(struct device *dev,
        if (!meta)
                return -ENOMEM;
        down_write(&zram->init_lock);
-       if (zram->init_done) {
+       if (init_done(zram)) {
                up_write(&zram->init_lock);
                zram_meta_free(meta);
                pr_info("Cannot change disksize for initialized device\n");
@@ -736,7 +737,7 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
        struct zram *zram = queue->queuedata;
 
        down_read(&zram->init_lock);
-       if (unlikely(!zram->init_done))
+       if (unlikely(!init_done(zram)))
                goto error;
 
        if (!valid_io_request(zram, bio)) {
@@ -859,7 +860,7 @@ static int create_device(struct zram *zram, int device_id)
                goto out_free_disk;
        }
 
-       zram->init_done = 0;
+       zram->meta = NULL;
        return 0;
 
 out_free_disk:
index ad8aa35bae00e9836bcb96f0efbd3f8b781b2705..e81e9cdf414722679c20f9284b95b6b14794c82d 100644 (file)
@@ -95,7 +95,6 @@ struct zram {
        struct zram_meta *meta;
        struct request_queue *queue;
        struct gendisk *disk;
-       int init_done;
        /* Prevent concurrent execution of device init, reset and R/W request */
        struct rw_semaphore init_lock;
        /*