Commit 5d0db96d13a4e2cd22b52494fb19ce5a9c8b8d90

Authored by Joe Thornber
Committed by Alasdair G Kergon
1 parent b17446df2e

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>

Showing 1 changed file with 14 additions and 11 deletions Side-by-side Diff

drivers/md/dm-thin.c
... ... @@ -1945,6 +1945,7 @@
1945 1945 unsigned long block_size;
1946 1946 dm_block_t low_water_blocks;
1947 1947 struct dm_dev *metadata_dev;
  1948 + fmode_t metadata_mode;
1948 1949  
1949 1950 /*
1950 1951 * FIXME Remove validation from scope of lock.
1951 1952  
... ... @@ -1956,10 +1957,22 @@
1956 1957 r = -EINVAL;
1957 1958 goto out_unlock;
1958 1959 }
  1960 +
1959 1961 as.argc = argc;
1960 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 1976 if (r) {
1964 1977 ti->error = "Error opening metadata block device";
1965 1978 goto out_unlock;
... ... @@ -1991,16 +2004,6 @@
1991 2004 r = -EINVAL;
1992 2005 goto out;
1993 2006 }
1994   -
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 2007  
2005 2008 pt = kzalloc(sizeof(*pt), GFP_KERNEL);
2006 2009 if (!pt) {