Skip to content

Commit af9313c

Browse files
jtpittman195snitm
authored andcommitted
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: 629d0a8 ("dm cache metadata: add "metadata2" feature") Signed-off-by: John Pittman <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 6c7413c commit af9313c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/md/dm-cache-target.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
22502250
{0, 2, "Invalid number of cache feature arguments"},
22512251
};
22522252

2253-
int r;
2253+
int r, mode_ctr = 0;
22542254
unsigned argc;
22552255
const char *arg;
22562256
struct cache_features *cf = &ca->features;
@@ -2264,14 +2264,20 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
22642264
while (argc--) {
22652265
arg = dm_shift_arg(as);
22662266

2267-
if (!strcasecmp(arg, "writeback"))
2267+
if (!strcasecmp(arg, "writeback")) {
22682268
cf->io_mode = CM_IO_WRITEBACK;
2269+
mode_ctr++;
2270+
}
22692271

2270-
else if (!strcasecmp(arg, "writethrough"))
2272+
else if (!strcasecmp(arg, "writethrough")) {
22712273
cf->io_mode = CM_IO_WRITETHROUGH;
2274+
mode_ctr++;
2275+
}
22722276

2273-
else if (!strcasecmp(arg, "passthrough"))
2277+
else if (!strcasecmp(arg, "passthrough")) {
22742278
cf->io_mode = CM_IO_PASSTHROUGH;
2279+
mode_ctr++;
2280+
}
22752281

22762282
else if (!strcasecmp(arg, "metadata2"))
22772283
cf->metadata_version = 2;
@@ -2282,6 +2288,11 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
22822288
}
22832289
}
22842290

2291+
if (mode_ctr > 1) {
2292+
*error = "Duplicate cache io_mode features requested";
2293+
return -EINVAL;
2294+
}
2295+
22852296
return 0;
22862297
}
22872298

0 commit comments

Comments
 (0)