Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm-snap: simplify the origin_dev == cow_dev check in snapshot_ctr

Use the block_device acquired in dm_get_device for the check instead
of doing an extra lookup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Mike Snitzer <snitzer@kernel.org>
Link: https://lore.kernel.org/r/20230531125535.676098-18-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
26110d5a 7cadcaf1

+5 -9
+5 -9
drivers/md/dm-snap.c
··· 1241 1241 int i; 1242 1242 int r = -EINVAL; 1243 1243 char *origin_path, *cow_path; 1244 - dev_t origin_dev, cow_dev; 1245 1244 unsigned int args_used, num_flush_bios = 1; 1246 1245 fmode_t origin_mode = FMODE_READ; 1247 1246 ··· 1278 1279 ti->error = "Cannot get origin device"; 1279 1280 goto bad_origin; 1280 1281 } 1281 - origin_dev = s->origin->bdev->bd_dev; 1282 1282 1283 1283 cow_path = argv[0]; 1284 1284 argv++; 1285 1285 argc--; 1286 1286 1287 - cow_dev = dm_get_dev_t(cow_path); 1288 - if (cow_dev && cow_dev == origin_dev) { 1289 - ti->error = "COW device cannot be the same as origin device"; 1290 - r = -EINVAL; 1291 - goto bad_cow; 1292 - } 1293 - 1294 1287 r = dm_get_device(ti, cow_path, dm_table_get_mode(ti->table), &s->cow); 1295 1288 if (r) { 1296 1289 ti->error = "Cannot get COW device"; 1297 1290 goto bad_cow; 1291 + } 1292 + if (s->cow->bdev && s->cow->bdev == s->origin->bdev) { 1293 + ti->error = "COW device cannot be the same as origin device"; 1294 + r = -EINVAL; 1295 + goto bad_store; 1298 1296 } 1299 1297 1300 1298 r = dm_exception_store_create(ti, argc, argv, s, &args_used, &s->store);