[SCSI] scsi_debug: sweep up sdebug_capacity calculation
sdebug_capacity is calculated at five different places. This add a helper function to calculate sdebug_capacity to sweep up the duplicatated code. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Acked-by: Douglas Gilbert <dougg@torque.net> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
This commit is contained in:
parent
f58b0efbf4
commit
28898873b0
|
@ -823,6 +823,14 @@ static int resp_start_stop(struct scsi_cmnd * scp,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sector_t get_sdebug_capacity(void)
|
||||||
|
{
|
||||||
|
if (scsi_debug_virtual_gb > 0)
|
||||||
|
return 2048 * 1024 * scsi_debug_virtual_gb;
|
||||||
|
else
|
||||||
|
return sdebug_store_sectors;
|
||||||
|
}
|
||||||
|
|
||||||
#define SDEBUG_READCAP_ARR_SZ 8
|
#define SDEBUG_READCAP_ARR_SZ 8
|
||||||
static int resp_readcap(struct scsi_cmnd * scp,
|
static int resp_readcap(struct scsi_cmnd * scp,
|
||||||
struct sdebug_dev_info * devip)
|
struct sdebug_dev_info * devip)
|
||||||
|
@ -834,11 +842,7 @@ static int resp_readcap(struct scsi_cmnd * scp,
|
||||||
if ((errsts = check_readiness(scp, 1, devip)))
|
if ((errsts = check_readiness(scp, 1, devip)))
|
||||||
return errsts;
|
return errsts;
|
||||||
/* following just in case virtual_gb changed */
|
/* following just in case virtual_gb changed */
|
||||||
if (scsi_debug_virtual_gb > 0) {
|
sdebug_capacity = get_sdebug_capacity();
|
||||||
sdebug_capacity = 2048 * 1024;
|
|
||||||
sdebug_capacity *= scsi_debug_virtual_gb;
|
|
||||||
} else
|
|
||||||
sdebug_capacity = sdebug_store_sectors;
|
|
||||||
memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
|
memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
|
||||||
if (sdebug_capacity < 0xffffffff) {
|
if (sdebug_capacity < 0xffffffff) {
|
||||||
capac = (unsigned int)sdebug_capacity - 1;
|
capac = (unsigned int)sdebug_capacity - 1;
|
||||||
|
@ -871,11 +875,7 @@ static int resp_readcap16(struct scsi_cmnd * scp,
|
||||||
alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8)
|
alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8)
|
||||||
+ cmd[13]);
|
+ cmd[13]);
|
||||||
/* following just in case virtual_gb changed */
|
/* following just in case virtual_gb changed */
|
||||||
if (scsi_debug_virtual_gb > 0) {
|
sdebug_capacity = get_sdebug_capacity();
|
||||||
sdebug_capacity = 2048 * 1024;
|
|
||||||
sdebug_capacity *= scsi_debug_virtual_gb;
|
|
||||||
} else
|
|
||||||
sdebug_capacity = sdebug_store_sectors;
|
|
||||||
memset(arr, 0, SDEBUG_READCAP16_ARR_SZ);
|
memset(arr, 0, SDEBUG_READCAP16_ARR_SZ);
|
||||||
capac = sdebug_capacity - 1;
|
capac = sdebug_capacity - 1;
|
||||||
for (k = 0; k < 8; ++k, capac >>= 8)
|
for (k = 0; k < 8; ++k, capac >>= 8)
|
||||||
|
@ -1169,13 +1169,9 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
|
||||||
offset = 8;
|
offset = 8;
|
||||||
}
|
}
|
||||||
ap = arr + offset;
|
ap = arr + offset;
|
||||||
if ((bd_len > 0) && (0 == sdebug_capacity)) {
|
if ((bd_len > 0) && (!sdebug_capacity))
|
||||||
if (scsi_debug_virtual_gb > 0) {
|
sdebug_capacity = get_sdebug_capacity();
|
||||||
sdebug_capacity = 2048 * 1024;
|
|
||||||
sdebug_capacity *= scsi_debug_virtual_gb;
|
|
||||||
} else
|
|
||||||
sdebug_capacity = sdebug_store_sectors;
|
|
||||||
}
|
|
||||||
if (8 == bd_len) {
|
if (8 == bd_len) {
|
||||||
if (sdebug_capacity > 0xfffffffe) {
|
if (sdebug_capacity > 0xfffffffe) {
|
||||||
ap[0] = 0xff;
|
ap[0] = 0xff;
|
||||||
|
@ -2392,11 +2388,9 @@ static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp,
|
||||||
|
|
||||||
if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
|
if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
|
||||||
scsi_debug_virtual_gb = n;
|
scsi_debug_virtual_gb = n;
|
||||||
if (scsi_debug_virtual_gb > 0) {
|
|
||||||
sdebug_capacity = 2048 * 1024;
|
sdebug_capacity = get_sdebug_capacity();
|
||||||
sdebug_capacity *= scsi_debug_virtual_gb;
|
|
||||||
} else
|
|
||||||
sdebug_capacity = sdebug_store_sectors;
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -2507,11 +2501,7 @@ static int __init scsi_debug_init(void)
|
||||||
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
|
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
|
||||||
sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
|
sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
|
||||||
sdebug_store_sectors = sz / SECT_SIZE;
|
sdebug_store_sectors = sz / SECT_SIZE;
|
||||||
if (scsi_debug_virtual_gb > 0) {
|
sdebug_capacity = get_sdebug_capacity();
|
||||||
sdebug_capacity = 2048 * 1024;
|
|
||||||
sdebug_capacity *= scsi_debug_virtual_gb;
|
|
||||||
} else
|
|
||||||
sdebug_capacity = sdebug_store_sectors;
|
|
||||||
|
|
||||||
/* play around with geometry, don't waste too much on track 0 */
|
/* play around with geometry, don't waste too much on track 0 */
|
||||||
sdebug_heads = 8;
|
sdebug_heads = 8;
|
||||||
|
|
Loading…
Reference in a new issue