diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2008-03-29 11:59:55 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-04-07 13:19:06 -0400 |
commit | 28898873b0049d4271c0ff3eb57eb329bbc4d9df (patch) | |
tree | d828cc30a26b9a9712aa493959ccd1cb2437e9bc /drivers/scsi | |
parent | f58b0efbf49ec54c82b8904c64a6498f829e7544 (diff) |
[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>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/scsi_debug.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 4e93b69207c4..70bcee6516c2 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c | |||
@@ -823,6 +823,14 @@ static int resp_start_stop(struct scsi_cmnd * scp, | |||
823 | return 0; | 823 | return 0; |
824 | } | 824 | } |
825 | 825 | ||
826 | static sector_t get_sdebug_capacity(void) | ||
827 | { | ||
828 | if (scsi_debug_virtual_gb > 0) | ||
829 | return 2048 * 1024 * scsi_debug_virtual_gb; | ||
830 | else | ||
831 | return sdebug_store_sectors; | ||
832 | } | ||
833 | |||
826 | #define SDEBUG_READCAP_ARR_SZ 8 | 834 | #define SDEBUG_READCAP_ARR_SZ 8 |
827 | static int resp_readcap(struct scsi_cmnd * scp, | 835 | static int resp_readcap(struct scsi_cmnd * scp, |
828 | struct sdebug_dev_info * devip) | 836 | struct sdebug_dev_info * devip) |
@@ -834,11 +842,7 @@ static int resp_readcap(struct scsi_cmnd * scp, | |||
834 | if ((errsts = check_readiness(scp, 1, devip))) | 842 | if ((errsts = check_readiness(scp, 1, devip))) |
835 | return errsts; | 843 | return errsts; |
836 | /* following just in case virtual_gb changed */ | 844 | /* following just in case virtual_gb changed */ |
837 | if (scsi_debug_virtual_gb > 0) { | 845 | sdebug_capacity = get_sdebug_capacity(); |
838 | sdebug_capacity = 2048 * 1024; | ||
839 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
840 | } else | ||
841 | sdebug_capacity = sdebug_store_sectors; | ||
842 | memset(arr, 0, SDEBUG_READCAP_ARR_SZ); | 846 | memset(arr, 0, SDEBUG_READCAP_ARR_SZ); |
843 | if (sdebug_capacity < 0xffffffff) { | 847 | if (sdebug_capacity < 0xffffffff) { |
844 | capac = (unsigned int)sdebug_capacity - 1; | 848 | capac = (unsigned int)sdebug_capacity - 1; |
@@ -871,11 +875,7 @@ static int resp_readcap16(struct scsi_cmnd * scp, | |||
871 | alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8) | 875 | alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8) |
872 | + cmd[13]); | 876 | + cmd[13]); |
873 | /* following just in case virtual_gb changed */ | 877 | /* following just in case virtual_gb changed */ |
874 | if (scsi_debug_virtual_gb > 0) { | 878 | sdebug_capacity = get_sdebug_capacity(); |
875 | sdebug_capacity = 2048 * 1024; | ||
876 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
877 | } else | ||
878 | sdebug_capacity = sdebug_store_sectors; | ||
879 | memset(arr, 0, SDEBUG_READCAP16_ARR_SZ); | 879 | memset(arr, 0, SDEBUG_READCAP16_ARR_SZ); |
880 | capac = sdebug_capacity - 1; | 880 | capac = sdebug_capacity - 1; |
881 | for (k = 0; k < 8; ++k, capac >>= 8) | 881 | for (k = 0; k < 8; ++k, capac >>= 8) |
@@ -1169,13 +1169,9 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target, | |||
1169 | offset = 8; | 1169 | offset = 8; |
1170 | } | 1170 | } |
1171 | ap = arr + offset; | 1171 | ap = arr + offset; |
1172 | if ((bd_len > 0) && (0 == sdebug_capacity)) { | 1172 | if ((bd_len > 0) && (!sdebug_capacity)) |
1173 | if (scsi_debug_virtual_gb > 0) { | 1173 | sdebug_capacity = get_sdebug_capacity(); |
1174 | sdebug_capacity = 2048 * 1024; | 1174 | |
1175 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
1176 | } else | ||
1177 | sdebug_capacity = sdebug_store_sectors; | ||
1178 | } | ||
1179 | if (8 == bd_len) { | 1175 | if (8 == bd_len) { |
1180 | if (sdebug_capacity > 0xfffffffe) { | 1176 | if (sdebug_capacity > 0xfffffffe) { |
1181 | ap[0] = 0xff; | 1177 | ap[0] = 0xff; |
@@ -2392,11 +2388,9 @@ static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp, | |||
2392 | 2388 | ||
2393 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { | 2389 | if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { |
2394 | scsi_debug_virtual_gb = n; | 2390 | scsi_debug_virtual_gb = n; |
2395 | if (scsi_debug_virtual_gb > 0) { | 2391 | |
2396 | sdebug_capacity = 2048 * 1024; | 2392 | sdebug_capacity = get_sdebug_capacity(); |
2397 | sdebug_capacity *= scsi_debug_virtual_gb; | 2393 | |
2398 | } else | ||
2399 | sdebug_capacity = sdebug_store_sectors; | ||
2400 | return count; | 2394 | return count; |
2401 | } | 2395 | } |
2402 | return -EINVAL; | 2396 | return -EINVAL; |
@@ -2507,11 +2501,7 @@ static int __init scsi_debug_init(void) | |||
2507 | scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ | 2501 | scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ |
2508 | sz = (unsigned int)scsi_debug_dev_size_mb * 1048576; | 2502 | sz = (unsigned int)scsi_debug_dev_size_mb * 1048576; |
2509 | sdebug_store_sectors = sz / SECT_SIZE; | 2503 | sdebug_store_sectors = sz / SECT_SIZE; |
2510 | if (scsi_debug_virtual_gb > 0) { | 2504 | sdebug_capacity = get_sdebug_capacity(); |
2511 | sdebug_capacity = 2048 * 1024; | ||
2512 | sdebug_capacity *= scsi_debug_virtual_gb; | ||
2513 | } else | ||
2514 | sdebug_capacity = sdebug_store_sectors; | ||
2515 | 2505 | ||
2516 | /* play around with geometry, don't waste too much on track 0 */ | 2506 | /* play around with geometry, don't waste too much on track 0 */ |
2517 | sdebug_heads = 8; | 2507 | sdebug_heads = 8; |