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

Configure Feed

Select the types of activity you want to include in your feed.

loop: Consolidate size calculation logic into lo_calculate_size()

Renamed get_size to lo_calculate_size and merged the logic from get_size
and get_loop_size into a single function. Update all callers to use
lo_calculate_size. This is done in preparation for improving the size
detection logic.

Signed-off-by: Rajeev Mishra <rajeevm@hpe.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250818184821.115033-2-rajeevm@hpe.com
[axboe: massage commit message]
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Rajeev Mishra and committed by
Jens Axboe
8aa5a3b6 72421690

+9 -17
+9 -17
drivers/block/loop.c
··· 137 137 static int max_part; 138 138 static int part_shift; 139 139 140 - static loff_t get_size(loff_t offset, loff_t sizelimit, struct file *file) 140 + static loff_t lo_calculate_size(struct loop_device *lo, struct file *file) 141 141 { 142 142 loff_t loopsize; 143 - 144 143 /* Compute loopsize in bytes */ 145 144 loopsize = i_size_read(file->f_mapping->host); 146 - if (offset > 0) 147 - loopsize -= offset; 145 + if (lo->lo_offset > 0) 146 + loopsize -= lo->lo_offset; 148 147 /* offset is beyond i_size, weird but possible */ 149 148 if (loopsize < 0) 150 149 return 0; 151 - 152 - if (sizelimit > 0 && sizelimit < loopsize) 153 - loopsize = sizelimit; 150 + if (lo->lo_sizelimit > 0 && lo->lo_sizelimit < loopsize) 151 + loopsize = lo->lo_sizelimit; 154 152 /* 155 153 * Unfortunately, if we want to do I/O on the device, 156 154 * the number of 512-byte sectors has to fit into a sector_t. 157 155 */ 158 156 return loopsize >> 9; 159 - } 160 - 161 - static loff_t get_loop_size(struct loop_device *lo, struct file *file) 162 - { 163 - return get_size(lo->lo_offset, lo->lo_sizelimit, file); 164 157 } 165 158 166 159 /* ··· 562 569 error = -EINVAL; 563 570 564 571 /* size of the new backing store needs to be the same */ 565 - if (get_loop_size(lo, file) != get_loop_size(lo, old_file)) 572 + if (lo_calculate_size(lo, file) != lo_calculate_size(lo, old_file)) 566 573 goto out_err; 567 574 568 575 /* ··· 1056 1063 loop_update_dio(lo); 1057 1064 loop_sysfs_init(lo); 1058 1065 1059 - size = get_loop_size(lo, file); 1066 + size = lo_calculate_size(lo, file); 1060 1067 loop_set_size(lo, size); 1061 1068 1062 1069 /* Order wrt reading lo_state in loop_validate_file(). */ ··· 1248 1255 if (partscan) 1249 1256 clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state); 1250 1257 if (!err && size_changed) { 1251 - loff_t new_size = get_size(lo->lo_offset, lo->lo_sizelimit, 1252 - lo->lo_backing_file); 1258 + loff_t new_size = lo_calculate_size(lo, lo->lo_backing_file); 1253 1259 loop_set_size(lo, new_size); 1254 1260 } 1255 1261 out_unlock: ··· 1391 1399 if (unlikely(lo->lo_state != Lo_bound)) 1392 1400 return -ENXIO; 1393 1401 1394 - size = get_loop_size(lo, lo->lo_backing_file); 1402 + size = lo_calculate_size(lo, lo->lo_backing_file); 1395 1403 loop_set_size(lo, size); 1396 1404 1397 1405 return 0;