Re: [PATCHv3 9/9] zram: add dynamic device add/remove functionality
From: Sergey Senozhatsky
Date: Mon May 04 2015 - 07:35:49 EST
> 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)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/