aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2008-03-19 22:09:16 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-04-07 13:18:58 -0400
commit5cb2fc06107fe343a9488b32ddf3d9b4596b7090 (patch)
tree21545a47e33634903b1294e50b8b54260e87846d /drivers/scsi
parentf3df41cff40992499d3c693251622299e4ce18c3 (diff)
[SCSI] scsi_debug: create new scsi_debug devices at a single place
Two functions, sdebug_add_adapter and devInfoReg, creates new scsi_debug devices. To simplify the code, this patch adds a new helper function to create new scsi_debug devices (sdebug_device_create) and converts both functions to use it. I plan to add more to scsi_debug devices (e.g. using a thread for a scsi_debug device for scalability testings). This patch enable me to add such to just the new helper function instead of touching two functions, sdebug_add_adapter and devInfoReg. 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.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 2a388d06094a..161af1ded888 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2014,6 +2014,19 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp)
2014 } 2014 }
2015} 2015}
2016 2016
2017struct sdebug_dev_info *sdebug_device_create(struct sdebug_host_info *sdbg_host,
2018 gfp_t flags)
2019{
2020 struct sdebug_dev_info *devip;
2021
2022 devip = kzalloc(sizeof(*devip), flags);
2023 if (devip) {
2024 devip->sdbg_host = sdbg_host;
2025 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list);
2026 }
2027 return devip;
2028}
2029
2017static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev) 2030static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
2018{ 2031{
2019 struct sdebug_host_info * sdbg_host; 2032 struct sdebug_host_info * sdbg_host;
@@ -2038,16 +2051,13 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
2038 open_devip = devip; 2051 open_devip = devip;
2039 } 2052 }
2040 } 2053 }
2041 if (NULL == open_devip) { /* try and make a new one */ 2054 if (!open_devip) { /* try and make a new one */
2042 open_devip = kzalloc(sizeof(*open_devip),GFP_ATOMIC); 2055 open_devip = sdebug_device_create(sdbg_host, GFP_ATOMIC);
2043 if (NULL == open_devip) { 2056 if (!open_devip) {
2044 printk(KERN_ERR "%s: out of memory at line %d\n", 2057 printk(KERN_ERR "%s: out of memory at line %d\n",
2045 __FUNCTION__, __LINE__); 2058 __FUNCTION__, __LINE__);
2046 return NULL; 2059 return NULL;
2047 } 2060 }
2048 open_devip->sdbg_host = sdbg_host;
2049 list_add_tail(&open_devip->dev_list,
2050 &sdbg_host->dev_info_list);
2051 } 2061 }
2052 if (open_devip) { 2062 if (open_devip) {
2053 open_devip->channel = sdev->channel; 2063 open_devip->channel = sdev->channel;
@@ -2935,16 +2945,13 @@ static int sdebug_add_adapter(void)
2935 2945
2936 devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; 2946 devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns;
2937 for (k = 0; k < devs_per_host; k++) { 2947 for (k = 0; k < devs_per_host; k++) {
2938 sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo),GFP_KERNEL); 2948 sdbg_devinfo = sdebug_device_create(sdbg_host, GFP_KERNEL);
2939 if (NULL == sdbg_devinfo) { 2949 if (!sdbg_devinfo) {
2940 printk(KERN_ERR "%s: out of memory at line %d\n", 2950 printk(KERN_ERR "%s: out of memory at line %d\n",
2941 __FUNCTION__, __LINE__); 2951 __FUNCTION__, __LINE__);
2942 error = -ENOMEM; 2952 error = -ENOMEM;
2943 goto clean; 2953 goto clean;
2944 } 2954 }
2945 sdbg_devinfo->sdbg_host = sdbg_host;
2946 list_add_tail(&sdbg_devinfo->dev_list,
2947 &sdbg_host->dev_info_list);
2948 } 2955 }
2949 2956
2950 spin_lock(&sdebug_host_list_lock); 2957 spin_lock(&sdebug_host_list_lock);