From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Nitin Gupta <ngupta@vflare.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] zram: call zram_init_device() only from disksize_store()
Date: Tue, 30 Oct 2012 16:58:31 +0300 [thread overview]
Message-ID: <20121030135831.GD5052@swordfish.minsk.epam.com> (raw)
zram: call zram_init_device() only from disksize_store()
Call device init only when user set desksize (thus makes it possible to init device)
and before any RW requests can happen. In that case there is no need to call zram_init_device()
concurrently from zram_make_request().
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/staging/zram/zram_drv.c | 18 ++++--------------
drivers/staging/zram/zram_sysfs.c | 4 ++++
2 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 47f2e3a..a40ecc1 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -470,12 +470,11 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
{
struct zram *zram = queue->queuedata;
- if (unlikely(!zram->init_done) && zram_init_device(zram))
- goto error;
-
down_read(&zram->init_lock);
- if (unlikely(!zram->init_done))
+ if (unlikely(!zram->init_done)) {
+ WARN_ON_ONCE(1);
goto error_unlock;
+ }
if (!valid_io_request(zram, bio)) {
zram_stat64_inc(zram, &zram->stats.invalid_io);
@@ -486,10 +485,8 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
up_read(&zram->init_lock);
return;
-
error_unlock:
up_read(&zram->init_lock);
-error:
bio_io_error(bio);
}
@@ -539,12 +536,8 @@ int zram_init_device(struct zram *zram)
int ret;
size_t num_pages;
- down_write(&zram->init_lock);
-
- if (zram->init_done) {
- up_write(&zram->init_lock);
+ if (zram->init_done)
return 0;
- }
zram_set_disksize(zram, totalram_pages << PAGE_SHIFT);
@@ -584,8 +577,6 @@ int zram_init_device(struct zram *zram)
}
zram->init_done = 1;
- up_write(&zram->init_lock);
-
pr_debug("Initialization done!\n");
return 0;
@@ -594,7 +585,6 @@ fail_no_table:
zram->disksize = 0;
fail:
__zram_reset_device(zram);
- up_write(&zram->init_lock);
pr_err("Initialization failed: err=%d\n", ret);
return ret;
}
diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c
index de1eacf..ae95a14 100644
--- a/drivers/staging/zram/zram_sysfs.c
+++ b/drivers/staging/zram/zram_sysfs.c
@@ -71,6 +71,10 @@ static ssize_t disksize_store(struct device *dev,
zram->disksize = PAGE_ALIGN(disksize);
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
+ if (zram_init_device(zram) != 0) {
+ pr_err("Zram device initialization failed\n");
+ len = -EINVAL;
+ }
up_write(&zram->init_lock);
return len;
reply other threads:[~2012-10-30 14:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121030135831.GD5052@swordfish.minsk.epam.com \
--to=sergey.senozhatsky@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ngupta@vflare.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome