Skip to contentSkip to conversation

dm cache: drop redundant origin size check

PATCH In review Li Chen 2 participants 3 messages Dec 10, 2025 Device mapper

lore
Share & tools
lore

Li Chen

author
#0 lore raw

PATCH 1/2 dm cache: drop redundant origin size check

The cache target already exposes the origin device through cache_iterate_devices(), which allows dm-table to call device_area_is_invalid() and verify that the mapping fits inside the underlying block device.

The explicit ti->len > origin_sectors test in parse_origin_dev() is therefore redundant. Drop this check and rely on the core device validation instead. This changes the user-visible error string when the origin is too small, but preserves the failure behaviour.

---
 drivers/md/dm-cache-target.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/md/dm-cache-target.c +0 -7
index a10d75a562db..350a0aa53365 100644
@@ -2099,7 +2099,6 @@ static int parse_cache_dev(struct cache_args *ca, struct dm_arg_set *as,
 static int parse_origin_dev(struct cache_args *ca, struct dm_arg_set *as,
 			    char **error)
 {
-	sector_t origin_sectors;
 	int r;
 
 	if (!at_least_one_arg(as, error))
@@ -2112,12 +2111,6 @@ static int parse_origin_dev(struct cache_args *ca, struct dm_arg_set *as,
 		return r;
 	}
 
-	origin_sectors = get_dev_size(ca->origin_dev);
-	if (ca->ti->len > origin_sectors) {
-		*error = "Device size larger than cached device";
-		return -EINVAL;
-	}
-
 	return 0;
 }
 
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 2/2 dm clone: drop redundant size checks

The clone target already exposes both source and destination devices via clone_iterate_devices(), so dm-table's device_area_is_invalid() helper ensures that the mapping does not extend past either underlying block device.

The manual comparisons between ti->len and the source/destination device sizes in parse_source_dev() and parse_dest_dev() are therefore redundant. Remove these checks and rely on the core validation instead. This changes the error strings reported when the devices are too small, but preserves the failure behaviour.

---
 drivers/md/dm-clone-target.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/md/dm-clone-target.c +0 -16
index e956d980672c..ac94e3466560 100644
@@ -1697,7 +1697,6 @@ static int parse_metadata_dev(struct clone *clone, struct dm_arg_set *as, char *
 static int parse_dest_dev(struct clone *clone, struct dm_arg_set *as, char **error)
 {
 	int r;
-	sector_t dest_dev_size;
 
 	r = dm_get_device(clone->ti, dm_shift_arg(as),
 			  BLK_OPEN_READ | BLK_OPEN_WRITE, &clone->dest_dev);
@@ -1706,20 +1705,12 @@ static int parse_dest_dev(struct clone *clone, struct dm_arg_set *as, char **err
 		return r;
 	}
 
-	dest_dev_size = get_dev_size(clone->dest_dev);
-	if (dest_dev_size < clone->ti->len) {
-		dm_put_device(clone->ti, clone->dest_dev);
-		*error = "Device size larger than destination device";
-		return -EINVAL;
-	}
-
 	return 0;
 }
 
 static int parse_source_dev(struct clone *clone, struct dm_arg_set *as, char **error)
 {
 	int r;
-	sector_t source_dev_size;
 
 	r = dm_get_device(clone->ti, dm_shift_arg(as), BLK_OPEN_READ,
 			  &clone->source_dev);
@@ -1728,13 +1719,6 @@ static int parse_source_dev(struct clone *clone, struct dm_arg_set *as, char **e
 		return r;
 	}
 
-	source_dev_size = get_dev_size(clone->source_dev);
-	if (source_dev_size < clone->ti->len) {
-		dm_put_device(clone->ti, clone->source_dev);
-		*error = "Device size larger than source device";
-		return -EINVAL;
-	}
-
 	return 0;
 }
 
Signature · 1 line
2.51.0
#2 lore raw
In reply to Li Chen
Quoted 42 lines · Li Chen

The cache target already exposes the origin device through cache_iterate_devices(), which allows dm-table to call device_area_is_invalid() and verify that the mapping fits inside the underlying block device.

The explicit ti->len > origin_sectors test in parse_origin_dev() is therefore redundant. Drop this check and rely on the core device validation instead. This changes the user-visible error string when the origin is too small, but preserves the failure behaviour.

---
 drivers/md/dm-cache-target.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/md/dm-cache-target.c +0 -8
index a10d75a562db..350a0aa53365 100644
@@ -2099,7 +2099,6 @@ static int parse_cache_dev(struct cache_args *ca, struct dm_arg_set *as,
 static int parse_origin_dev(struct cache_args *ca, struct dm_arg_set *as,
                            char **error)
 {
-       sector_t origin_sectors;
        int r;
 
        if (!at_least_one_arg(as, error))
@@ -2112,12 +2111,6 @@ static int parse_origin_dev(struct cache_args *ca, struct dm_arg_set *as,
                return r;
        }
 
-       origin_sectors = get_dev_size(ca->origin_dev);
-       if (ca->ti->len > origin_sectors) {
-               *error = "Device size larger than cached device";
-               return -EINVAL;
-       }
-
        return 0;
 }
 
--
Quoted 3 lines

2.51.0

The size check in parse_origin_dev() provides early validation during table creation. Removing it delays the size check until the resume phase when reloading an existing device, which leaves the device suspended if the new table size is invalid. This changes user expectations and could affect volume managers like LVM and Stratis.

Ming-Hung Tsai