aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-thin.c
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2013-05-10 09:37:19 -0400
committerAlasdair G Kergon <agk@redhat.com>2013-05-10 09:37:19 -0400
commit5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90 (patch)
tree699c91ea6a15e759ae856f306f2f6ae47f44e7a6 /drivers/md/dm-thin.c
parentb17446df2ebcaf32889376d90f4b9b2baebb2db6 (diff)
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/dm-thin.c')
-rw-r--r--drivers/md/dm-thin.c25
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)
1945 unsigned long block_size; 1945 unsigned long block_size;
1946 dm_block_t low_water_blocks; 1946 dm_block_t low_water_blocks;
1947 struct dm_dev *metadata_dev; 1947 struct dm_dev *metadata_dev;
1948 fmode_t metadata_mode;
1948 1949
1949 /* 1950 /*
1950 * FIXME Remove validation from scope of lock. 1951 * FIXME Remove validation from scope of lock.
@@ -1956,10 +1957,22 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
1956 r = -EINVAL; 1957 r = -EINVAL;
1957 goto out_unlock; 1958 goto out_unlock;
1958 } 1959 }
1960
1959 as.argc = argc; 1961 as.argc = argc;
1960 as.argv = argv; 1962 as.argv = argv;
1961 1963
1962 r = dm_get_device(ti, argv[0], FMODE_READ | FMODE_WRITE, &metadata_dev); 1964 /*
1965 * Set default pool features.
1966 */
1967 pool_features_init(&pf);
1968
1969 dm_consume_args(&as, 4);
1970 r = parse_pool_features(&as, &pf, ti);
1971 if (r)
1972 goto out_unlock;
1973
1974 metadata_mode = FMODE_READ | ((pf.mode == PM_READ_ONLY) ? 0 : FMODE_WRITE);
1975 r = dm_get_device(ti, argv[0], metadata_mode, &metadata_dev);
1963 if (r) { 1976 if (r) {
1964 ti->error = "Error opening metadata block device"; 1977 ti->error = "Error opening metadata block device";
1965 goto out_unlock; 1978 goto out_unlock;
@@ -1992,16 +2005,6 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
1992 goto out; 2005 goto out;
1993 } 2006 }
1994 2007
1995 /*
1996 * Set default pool features.
1997 */
1998 pool_features_init(&pf);
1999
2000 dm_consume_args(&as, 4);
2001 r = parse_pool_features(&as, &pf, ti);
2002 if (r)
2003 goto out;
2004
2005 pt = kzalloc(sizeof(*pt), GFP_KERNEL); 2008 pt = kzalloc(sizeof(*pt), GFP_KERNEL);
2006 if (!pt) { 2009 if (!pt) {
2007 r = -ENOMEM; 2010 r = -ENOMEM;