Skip to content

Commit 19da6b2

Browse files
bmarzinsMikulas Patocka
authored andcommitted
dm-flakey: Clean up parsing messages
There were a number of cases where the error message for an invalid table line did not match the actual problem. Fix these. Additionally, error out when duplicate corrupt_bio_byte, random_read_corrupt, or random_write_corrupt features are present. Also, error_reads is incompatible with random_read_corrupt and corrupt_bio_byte with the READ flag set, so disallow that. Reported-by: Kent Overstreet <kent.overstreet@linux.dev> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent d90e7a5 commit 19da6b2

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

drivers/md/dm-flakey.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
128128
* corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags>
129129
*/
130130
if (!strcasecmp(arg_name, "corrupt_bio_byte")) {
131-
if (!argc) {
132-
ti->error = "Feature corrupt_bio_byte requires parameters";
131+
if (fc->corrupt_bio_byte) {
132+
ti->error = "Feature corrupt_bio_byte duplicated";
133+
return -EINVAL;
134+
} else if (argc < 4) {
135+
ti->error = "Feature corrupt_bio_byte requires 4 parameters";
133136
return -EINVAL;
134137
}
135138

@@ -176,7 +179,10 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
176179
}
177180

178181
if (!strcasecmp(arg_name, "random_read_corrupt")) {
179-
if (!argc) {
182+
if (fc->random_read_corrupt) {
183+
ti->error = "Feature random_read_corrupt duplicated";
184+
return -EINVAL;
185+
} else if (!argc) {
180186
ti->error = "Feature random_read_corrupt requires a parameter";
181187
return -EINVAL;
182188
}
@@ -189,7 +195,10 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
189195
}
190196

191197
if (!strcasecmp(arg_name, "random_write_corrupt")) {
192-
if (!argc) {
198+
if (fc->random_write_corrupt) {
199+
ti->error = "Feature random_write_corrupt duplicated";
200+
return -EINVAL;
201+
} else if (!argc) {
193202
ti->error = "Feature random_write_corrupt requires a parameter";
194203
return -EINVAL;
195204
}
@@ -205,12 +214,18 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
205214
return -EINVAL;
206215
}
207216

208-
if (test_bit(DROP_WRITES, &fc->flags) && (fc->corrupt_bio_rw == WRITE)) {
209-
ti->error = "drop_writes is incompatible with corrupt_bio_byte with the WRITE flag set";
217+
if (test_bit(DROP_WRITES, &fc->flags) &&
218+
(fc->corrupt_bio_rw == WRITE || fc->random_write_corrupt)) {
219+
ti->error = "drop_writes is incompatible with random_write_corrupt or corrupt_bio_byte with the WRITE flag set";
210220
return -EINVAL;
211221

212-
} else if (test_bit(ERROR_WRITES, &fc->flags) && (fc->corrupt_bio_rw == WRITE)) {
213-
ti->error = "error_writes is incompatible with corrupt_bio_byte with the WRITE flag set";
222+
} else if (test_bit(ERROR_WRITES, &fc->flags) &&
223+
(fc->corrupt_bio_rw == WRITE || fc->random_write_corrupt)) {
224+
ti->error = "error_writes is incompatible with random_write_corrupt or corrupt_bio_byte with the WRITE flag set";
225+
return -EINVAL;
226+
} else if (test_bit(ERROR_READS, &fc->flags) &&
227+
(fc->corrupt_bio_rw == READ || fc->random_read_corrupt)) {
228+
ti->error = "error_reads is incompatible with random_read_corrupt or corrupt_bio_byte with the READ flag set";
214229
return -EINVAL;
215230
}
216231

@@ -278,7 +293,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
278293
if (r)
279294
goto bad;
280295

281-
r = dm_read_arg(_args, &as, &fc->down_interval, &ti->error);
296+
r = dm_read_arg(_args + 1, &as, &fc->down_interval, &ti->error);
282297
if (r)
283298
goto bad;
284299

0 commit comments

Comments
 (0)