diff options
author | Joe Thornber <ejt@redhat.com> | 2013-05-10 15:37:19 +0200 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2013-05-10 15:37:19 +0200 |
commit | 5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90 (patch) | |
tree | 699c91ea6a15e759ae856f306f2f6ae47f44e7a6 /drivers/md | |
parent | dm thin: refactor data dev resize (diff) | |
download | linux-5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90.tar.xz linux-5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90.zip |
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 <ejt@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-thin.c | 25 |
1 files changed, 14 insertions, 11 deletions
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; |