From: Joe Thornber Date: Fri, 10 May 2013 13:37:19 +0000 (+0100) Subject: dm thin: open dev read only when possible X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git dm thin: open dev read only when possible If a thin pool is created in read-only-metadata mode then only open the metadata device read-only. Previously it was always opened with FMODE_READ | FMODE_WRITE. (Note that dm_get_device() still allows read-only dm devices to be used read-write at the moment: If I create a read-only linear device for the metadata, via dmsetup load --readonly, then I can still create a rw pool out of it.) Signed-off-by: Joe Thornber Signed-off-by: Alasdair G Kergon --- diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index 111c148fb1d0..ef021b0c8106 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -1945,6 +1945,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) unsigned long block_size; dm_block_t low_water_blocks; struct dm_dev *metadata_dev; + fmode_t metadata_mode; /* * FIXME Remove validation from scope of lock. @@ -1956,10 +1957,22 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) r = -EINVAL; goto out_unlock; } + as.argc = argc; as.argv = argv; - r = dm_get_device(ti, argv[0], FMODE_READ | FMODE_WRITE, &metadata_dev); + /* + * Set default pool features. + */ + pool_features_init(&pf); + + dm_consume_args(&as, 4); + r = parse_pool_features(&as, &pf, ti); + if (r) + goto out_unlock; + + metadata_mode = FMODE_READ | ((pf.mode == PM_READ_ONLY) ? 0 : FMODE_WRITE); + r = dm_get_device(ti, argv[0], metadata_mode, &metadata_dev); if (r) { ti->error = "Error opening metadata block device"; goto out_unlock; @@ -1992,16 +2005,6 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) goto out; } - /* - * Set default pool features. - */ - pool_features_init(&pf); - - dm_consume_args(&as, 4); - r = parse_pool_features(&as, &pf, ti); - if (r) - goto out; - pt = kzalloc(sizeof(*pt), GFP_KERNEL); if (!pt) { r = -ENOMEM;