summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_debug.c
diff options
context:
space:
mode:
authorJohn Pittman <jpittman@redhat.com>2020-09-02 17:14:33 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2020-09-02 22:49:53 -0400
commit979e0dc3457cc95e48920ff5ca901a5821ef57d8 (patch)
tree4d28460464549158b055f1277f77132720ff8b5b /drivers/scsi/scsi_debug.c
parent5d929371b71b05a85d07dbc3333be7d129be6338 (diff)
downloadlinux-979e0dc3457cc95e48920ff5ca901a5821ef57d8.tar.bz2
scsi: scsi_debug: Adjust num_parts to create equally sized partitions
Currently when using the num_parts parameter, partitions are aligned and the end sector is one prior to the next start. This creates different sized partitions. Create instead equally sized partitions by trimming the end of each partition to the size of the smallest partition. This aligns better with what one would expect from automatically created partitions and can be helpful with testing things such as raid which often expect legs of the same size. Minimal space is lost as the initial partition starting size is calculated by dividing num_sectors by sdebug_num_parts. Link: https://lore.kernel.org/r/20200902211434.9979-2-jpittman@redhat.com Acked-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: John Pittman <jpittman@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r--drivers/scsi/scsi_debug.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index c5829493dd35..87bbd0967bd8 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -5265,7 +5265,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt)
static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size)
{
struct msdos_partition *pp;
- int starts[SDEBUG_MAX_PARTS + 2];
+ int starts[SDEBUG_MAX_PARTS + 2], max_part_secs;
int sectors_per_part, num_sectors, k;
int heads_by_sects, start_sec, end_sec;
@@ -5281,9 +5281,13 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size)
/ sdebug_num_parts;
heads_by_sects = sdebug_heads * sdebug_sectors_per;
starts[0] = sdebug_sectors_per;
- for (k = 1; k < sdebug_num_parts; ++k)
+ max_part_secs = sectors_per_part;
+ for (k = 1; k < sdebug_num_parts; ++k) {
starts[k] = ((k * sectors_per_part) / heads_by_sects)
* heads_by_sects;
+ if (starts[k] - starts[k - 1] < max_part_secs)
+ max_part_secs = starts[k] - starts[k - 1];
+ }
starts[sdebug_num_parts] = num_sectors;
starts[sdebug_num_parts + 1] = 0;
@@ -5292,7 +5296,7 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size)
pp = (struct msdos_partition *)(ramp + 0x1be);
for (k = 0; starts[k + 1]; ++k, ++pp) {
start_sec = starts[k];
- end_sec = starts[k + 1] - 1;
+ end_sec = starts[k] + max_part_secs - 1;
pp->boot_ind = 0;
pp->cyl = start_sec / heads_by_sects;