scsi_debug: improve num_parts usage
cover scsi_debug: improve num_parts usage
Hello,
The 1st patch sets all partitions to the same size when using the num_parts parameter.
The 2nd patch allows virtual_gb to be respected when it is passed at the same time as num_parts.
John Pittman (2):
scsi: scsi_debug: adjust num_parts to create equally sized partitions
scsi: scsi_debug: sdebug_build_parts() respect virtual_gb
scsi_debug.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
PATCH 1/2 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.
--- drivers/scsi/scsi_debug.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/scsi/scsi_debug.c +7 -4
@@ -5259,7 +5259,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;
@@ -5271,13 +5271,16 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size)pr_warn ("reducing partitions to %d\n" ,SDEBUG_MAX_PARTS ); } num_sectors = (int )sdebug_store_sectors; - sectors_per_part = (num_sectors - sdebug_sectors_per) + max_part_secs = sectors_per_part = (num_sectors - sdebug_sectors_per) / sdebug_num_parts; heads_by_sects = sdebug_heads * sdebug_sectors_per; starts[0 ] = sdebug_sectors_per; -for (k =1 ; k < sdebug_num_parts; ++k) +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 ;
@@ -5286,7 +5289,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;
Signature · 1 line
2.17.2
Re: [PATCH 1/2] scsi: scsi_debug: adjust num_parts to create equally sized partitions
Quoted 49 lines · John Pittman
Currently when using the
num_partsparameter, 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 dividingnum_sectorsbysdebug_num_parts.Signed-off-by John Pittman <[email protected]>--- drivers/scsi/scsi_debug.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/scsi/scsi_debug.c +6
-3@@ -5259,7 +5259,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;@@ -5271,13 +5271,16 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size)pr_warn ("reducing partitions to %d\n" ,SDEBUG_MAX_PARTS ); } num_sectors = (int )sdebug_store_sectors; - sectors_per_part = (num_sectors - sdebug_sectors_per) + max_part_secs = sectors_per_part = (num_sectors - sdebug_sectors_per) / sdebug_num_parts; heads_by_sects = sdebug_heads * sdebug_sectors_per; starts[0 ] = sdebug_sectors_per; -for (k =1 ; k < sdebug_num_parts; ++k) +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 ;
drivers/scsi/scsi_debug.c static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size) · line 5295
Quoted 8 lines
drivers/scsi/scsi_debug.c +1
-1@@ -5286,7 +5289,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;
Apart from the multiple assignments on one line (ref: lk coding style) the patch looks fine to me.
PATCH 2/2 scsi: scsi_debug: sdebug_build_parts() respect virtual_gb
In reply to John PittmanIf virtual_gb is passed while using num_parts, when creating the partitions, virtual_gb is not respected. Set num_sectors using get_sdebug_capacity() to pull virtual_gb if set.
--- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +1 -1
@@ -5270,7 +5270,7 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size) sdebug_num_parts =SDEBUG_MAX_PARTS ;pr_warn ("reducing partitions to %d\n" ,SDEBUG_MAX_PARTS ); } - num_sectors = (int )sdebug_store_sectors; + num_sectors = (int )get_sdebug_capacity (); max_part_secs = sectors_per_part = (num_sectors - sdebug_sectors_per) / sdebug_num_parts; heads_by_sects = sdebug_heads * sdebug_sectors_per;
Signature · 1 line
2.17.2
Re: [PATCH 2/2] scsi: scsi_debug: sdebug_build_parts() respect virtual_gb
Quoted 15 lines · John Pittman
If
virtual_gbis passed while usingnum_parts, when creating the partitions,virtual_gbis not respected. Setnum_sectorsusingget_sdebug_capacity()to pullvirtual_gbif set.Signed-off-by John Pittman <[email protected]>--- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/scsi_debug.c +0
-0
drivers/scsi/scsi_debug.c static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size) · line 5276
Quoted 8 lines
drivers/scsi/scsi_debug.c +1
-1@@ -5270,7 +5270,7 @@ static void sdebug_build_parts(unsigned char *ramp, unsigned long store_size) sdebug_num_parts =SDEBUG_MAX_PARTS ;pr_warn ("reducing partitions to %d\n" ,SDEBUG_MAX_PARTS ); } - num_sectors = (int )sdebug_store_sectors; + num_sectors = (int )get_sdebug_capacity (); max_part_secs = sectors_per_part = (num_sectors - sdebug_sectors_per) / sdebug_num_parts; heads_by_sects = sdebug_heads * sdebug_sectors_per;