aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Pittman <jpittman@redhat.com>2018-06-21 17:35:33 -0400
committerMike Snitzer <snitzer@redhat.com>2018-07-27 15:24:18 -0400
commitaf9313c32c0fa2a0ac3b113669273833d60cc9de (patch)
tree4adfc242b5c53974fe4b6a07fa50eaab1a89da03
parent6c7413c0f5ab61d2339cf516d25bb44d71f4bad4 (diff)
dm cache: only allow a single io_mode cache feature to be requested
More than one io_mode feature can be requested when creating a dm cache device (as is: last one wins). The io_mode selections are incompatible with one another, we should force them to be selected exclusively. Add a counter to check for more than one io_mode selection. Fixes: 629d0a8a1a10 ("dm cache metadata: add "metadata2" feature") Signed-off-by: John Pittman <jpittman@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r--drivers/md/dm-cache-target.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index ce14a3d1f609..44df244807e5 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -2250,7 +2250,7 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
2250 {0, 2, "Invalid number of cache feature arguments"}, 2250 {0, 2, "Invalid number of cache feature arguments"},
2251 }; 2251 };
2252 2252
2253 int r; 2253 int r, mode_ctr = 0;
2254 unsigned argc; 2254 unsigned argc;
2255 const char *arg; 2255 const char *arg;
2256 struct cache_features *cf = &ca->features; 2256 struct cache_features *cf = &ca->features;
@@ -2264,14 +2264,20 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
2264 while (argc--) { 2264 while (argc--) {
2265 arg = dm_shift_arg(as); 2265 arg = dm_shift_arg(as);
2266 2266
2267 if (!strcasecmp(arg, "writeback")) 2267 if (!strcasecmp(arg, "writeback")) {
2268 cf->io_mode = CM_IO_WRITEBACK; 2268 cf->io_mode = CM_IO_WRITEBACK;
2269 mode_ctr++;
2270 }
2269 2271
2270 else if (!strcasecmp(arg, "writethrough")) 2272 else if (!strcasecmp(arg, "writethrough")) {
2271 cf->io_mode = CM_IO_WRITETHROUGH; 2273 cf->io_mode = CM_IO_WRITETHROUGH;
2274 mode_ctr++;
2275 }
2272 2276
2273 else if (!strcasecmp(arg, "passthrough")) 2277 else if (!strcasecmp(arg, "passthrough")) {
2274 cf->io_mode = CM_IO_PASSTHROUGH; 2278 cf->io_mode = CM_IO_PASSTHROUGH;
2279 mode_ctr++;
2280 }
2275 2281
2276 else if (!strcasecmp(arg, "metadata2")) 2282 else if (!strcasecmp(arg, "metadata2"))
2277 cf->metadata_version = 2; 2283 cf->metadata_version = 2;
@@ -2282,6 +2288,11 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
2282 } 2288 }
2283 } 2289 }
2284 2290
2291 if (mode_ctr > 1) {
2292 *error = "Duplicate cache io_mode features requested";
2293 return -EINVAL;
2294 }
2295
2285 return 0; 2296 return 0;
2286} 2297}
2287 2298