From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nitin Gupta <ngupta@vflare.org>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [PATCHv3 9/9] zram: add dynamic device add/remove functionality
Date: Mon, 4 May 2015 20:34:40 +0900 [thread overview]
Message-ID: <20150504113406.GA505@swordfish> (raw)
In-Reply-To: <20150504022008.GA14452@blaptop>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 3df4394..7fb72dc 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1074,13 +1074,6 @@ static ssize_t reset_store(struct device *dev,
> if (!bdev)
> return -ENOMEM;
>
> - mutex_lock(&bdev->bd_mutex);
> - /* Do not reset an active device! */
> - if (bdev->bd_openers) {
> - ret = -EBUSY;
> - goto out;
> - }
> -
> ret = kstrtou16(buf, 10, &do_reset);
> if (ret)
> goto out;
> @@ -1090,23 +1083,52 @@ static ssize_t reset_store(struct device *dev,
> goto out;
> }
>
> + mutex_lock(&bdev->bd_mutex);
> + /* Do not reset an active device or claimed device */
> + if (bdev->bd_openers || zram->claim) {
> + ret = -EBUSY;
> + mutex_unlock(&bdev->bd_mutex);
> + goto out;
> + }
> +
> + /* From now on, anyone can't open /dev/zram[0-9] */
> + zram->claim = true;
> + mutex_unlock(&bdev->bd_mutex);
> +
> /* Make sure all pending I/O is finished */
> fsync_bdev(bdev);
> zram_reset_device(zram);
>
> - mutex_unlock(&bdev->bd_mutex);
> revalidate_disk(zram->disk);
> bdput(bdev);
>
> - return len;
> + mutex_lock(&bdev->bd_mutex);
> + zram->claim = false;
> + mutex_unlock(&bdev->bd_mutex);
>
> + return len;
> out:
> - mutex_unlock(&bdev->bd_mutex);
> bdput(bdev);
> return ret;
just backported reset_store() simplification from my another patch.
make validation outisde of ->bd_mutex and before we inc ndev ref
counter in bdget_disk(). this also makes it possible to get rid of
goto label.
the rest looks ok to me. will fold into your patch and submit.
---
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 7fb72dc..f50bd66 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1068,27 +1068,24 @@ static ssize_t reset_store(struct device *dev,
struct zram *zram;
struct block_device *bdev;
+ ret = kstrtou16(buf, 10, &do_reset);
+ if (ret)
+ return ret;
+
+ if (!do_reset)
+ return -EINVAL;
+
zram = dev_to_zram(dev);
bdev = bdget_disk(zram->disk, 0);
-
if (!bdev)
return -ENOMEM;
- ret = kstrtou16(buf, 10, &do_reset);
- if (ret)
- goto out;
-
- if (!do_reset) {
- ret = -EINVAL;
- goto out;
- }
-
mutex_lock(&bdev->bd_mutex);
/* Do not reset an active device or claimed device */
if (bdev->bd_openers || zram->claim) {
- ret = -EBUSY;
mutex_unlock(&bdev->bd_mutex);
- goto out;
+ bdput(bdev);
+ return -EBUSY;
}
/* From now on, anyone can't open /dev/zram[0-9] */
@@ -1107,9 +1104,6 @@ static ssize_t reset_store(struct device *dev,
mutex_unlock(&bdev->bd_mutex);
return len;
-out:
- bdput(bdev);
- return ret;
}
static int zram_open(struct block_device *bdev, fmode_t mode)
next prev parent reply other threads:[~2015-05-04 11:35 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 13:21 [PATCHv3 0/9] introduce on-demand device creation Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 1/9] zram: add `compact` sysfs entry to documentation Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 2/9] zram: cosmetic ZRAM_ATTR_RO code formatting tweak Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 3/9] zram: use idr instead of `zram_devices' array Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 4/9] zram: reorganize code layout Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 5/9] zram: remove max_num_devices limitation Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 6/9] zram: report every added and removed device Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 7/9] zram: trivial: correct flag operations comment Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 8/9] zram: return zram device_id from zram_add() Sergey Senozhatsky
2015-04-27 13:21 ` [PATCHv3 9/9] zram: add dynamic device add/remove functionality Sergey Senozhatsky
2015-04-29 0:16 ` Sergey Senozhatsky
2015-04-29 6:48 ` Minchan Kim
2015-04-29 7:02 ` Sergey Senozhatsky
2015-04-29 7:23 ` Sergey Senozhatsky
2015-04-30 5:47 ` Minchan Kim
2015-04-30 6:34 ` Sergey Senozhatsky
2015-04-30 6:44 ` Minchan Kim
2015-04-30 6:51 ` Sergey Senozhatsky
2015-05-04 2:20 ` Minchan Kim
2015-05-04 2:28 ` Minchan Kim
2015-05-04 6:32 ` Sergey Senozhatsky
2015-05-04 6:29 ` Sergey Senozhatsky
2015-05-04 11:34 ` Sergey Senozhatsky [this message]
2015-04-30 6:44 ` Sergey Senozhatsky
2015-04-27 13:41 ` [PATCHv3 0/9] introduce on-demand device creation Sergey Senozhatsky
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=20150504113406.GA505@swordfish \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=sergey.senozhatsky.work@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.