diff options
author | Joe Thornber <ejt@redhat.com> | 2013-05-10 14:37:19 +0100 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2013-05-10 14:37:19 +0100 |
commit | 5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90 (patch) | |
tree | 699c91ea6a15e759ae856f306f2f6ae47f44e7a6 | |
parent | b17446df2ebcaf32889376d90f4b9b2baebb2db6 (diff) | |
download | op-kernel-dev-5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90.zip op-kernel-dev-5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90.tar.gz |
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>
-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 111c148..ef021b0 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; |