* [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate
@ 2008-03-29 15:59 FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 1/5] scsi_debug: remove unnecessary sdebug_store_size FUJITA Tomonori
2008-03-30 17:11 ` [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate Douglas Gilbert
0 siblings, 2 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-29 15:59 UTC (permalink / raw)
To: linux-scsi; +Cc: tomof, James.Bottomley, dougg, fujita.tomonori
Currently, the maximum amount of RAM that scsi_debug can actually
allocate is 4GB. This patchset increase it to 2TB.
Here's an example, scsi_debug allocates 6GB ram and exports it as if
it were 6GB disk.
fujita@rose:/sys/bus/pseudo/drivers/scsi_debug$ cat virtual_gb
0
fujita@rose:/sys/bus/pseudo/drivers/scsi_debug$ cat dev_size_mb
6144
scsi3 : scsi_debug, version 1.81 [20070104], dev_size_mb=6144, opts=0x0
scsi 3:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5
sd 3:0:0:0: [sdc] 12582912 512-byte hardware sectors (6442 MB)
This patchset also include minor cleanup.
This is against scsi-misc with the scsi_build_sense_buffer helper
patchset and the scsi_debug lba fix:
http://marc.info/?l=linux-scsi&m=120640632301595&w=2
http://marc.info/?l=linux-scsi&m=120643343003171&w=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/5] scsi_debug: remove unnecessary sdebug_store_size
2008-03-29 15:59 [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate FUJITA Tomonori
@ 2008-03-29 15:59 ` FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 2/5] scsi_debug: sweep up sdebug_capacity calculation FUJITA Tomonori
2008-03-30 17:11 ` [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate Douglas Gilbert
1 sibling, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-29 15:59 UTC (permalink / raw)
To: linux-scsi; +Cc: tomof, FUJITA Tomonori, Douglas Gilbert, James Bottomley
sdebug_store_size doesn't need to be static global. It's used at
startup only.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
drivers/scsi/scsi_debug.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 65c88dd..4e93b69 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -148,7 +148,6 @@ static int scsi_debug_cmnd_count = 0;
#define DEV_READONLY(TGT) (0)
#define DEV_REMOVEABLE(TGT) (0)
-static unsigned int sdebug_store_size; /* in bytes */
static unsigned int sdebug_store_sectors;
static sector_t sdebug_capacity; /* in sectors */
@@ -1969,7 +1968,8 @@ static void __init init_all_queued(void)
spin_unlock_irqrestore(&queued_arr_lock, iflags);
}
-static void __init sdebug_build_parts(unsigned char * ramp)
+static void __init sdebug_build_parts(unsigned char *ramp,
+ unsigned int store_size)
{
struct partition * pp;
int starts[SDEBUG_MAX_PARTS + 2];
@@ -1977,7 +1977,7 @@ static void __init sdebug_build_parts(unsigned char * ramp)
int heads_by_sects, start_sec, end_sec;
/* assume partition table already zeroed */
- if ((scsi_debug_num_parts < 1) || (sdebug_store_size < 1048576))
+ if ((scsi_debug_num_parts < 1) || (store_size < 1048576))
return;
if (scsi_debug_num_parts > SDEBUG_MAX_PARTS) {
scsi_debug_num_parts = SDEBUG_MAX_PARTS;
@@ -2505,8 +2505,8 @@ static int __init scsi_debug_init(void)
if (scsi_debug_dev_size_mb < 1)
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
- sdebug_store_size = (unsigned int)scsi_debug_dev_size_mb * 1048576;
- sdebug_store_sectors = sdebug_store_size / SECT_SIZE;
+ sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
+ sdebug_store_sectors = sz / SECT_SIZE;
if (scsi_debug_virtual_gb > 0) {
sdebug_capacity = 2048 * 1024;
sdebug_capacity *= scsi_debug_virtual_gb;
@@ -2530,7 +2530,6 @@ static int __init scsi_debug_init(void)
(sdebug_sectors_per * sdebug_heads);
}
- sz = sdebug_store_size;
fake_storep = vmalloc(sz);
if (NULL == fake_storep) {
printk(KERN_ERR "scsi_debug_init: out of memory, 1\n");
@@ -2538,7 +2537,7 @@ static int __init scsi_debug_init(void)
}
memset(fake_storep, 0, sz);
if (scsi_debug_num_parts > 0)
- sdebug_build_parts(fake_storep);
+ sdebug_build_parts(fake_storep, sz);
ret = device_register(&pseudo_primary);
if (ret < 0) {
--
1.5.3.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/5] scsi_debug: sweep up sdebug_capacity calculation
2008-03-29 15:59 ` [PATCH 1/5] scsi_debug: remove unnecessary sdebug_store_size FUJITA Tomonori
@ 2008-03-29 15:59 ` FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 3/5] scsi_debug: remove the duplicated code in resp_read and resp_write FUJITA Tomonori
0 siblings, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-29 15:59 UTC (permalink / raw)
To: linux-scsi; +Cc: tomof, FUJITA Tomonori, Douglas Gilbert, James Bottomley
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>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
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 4e93b69..70bcee6 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,
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
static int resp_readcap(struct scsi_cmnd * scp,
struct sdebug_dev_info * devip)
@@ -834,11 +842,7 @@ static int resp_readcap(struct scsi_cmnd * scp,
if ((errsts = check_readiness(scp, 1, devip)))
return errsts;
/* following just in case virtual_gb changed */
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+ sdebug_capacity = get_sdebug_capacity();
memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
if (sdebug_capacity < 0xffffffff) {
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)
+ cmd[13]);
/* following just in case virtual_gb changed */
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+ sdebug_capacity = get_sdebug_capacity();
memset(arr, 0, SDEBUG_READCAP16_ARR_SZ);
capac = sdebug_capacity - 1;
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;
}
ap = arr + offset;
- if ((bd_len > 0) && (0 == sdebug_capacity)) {
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
- }
+ if ((bd_len > 0) && (!sdebug_capacity))
+ sdebug_capacity = get_sdebug_capacity();
+
if (8 == bd_len) {
if (sdebug_capacity > 0xfffffffe) {
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)) {
scsi_debug_virtual_gb = n;
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+
+ sdebug_capacity = get_sdebug_capacity();
+
return count;
}
return -EINVAL;
@@ -2507,11 +2501,7 @@ static int __init scsi_debug_init(void)
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
sdebug_store_sectors = sz / SECT_SIZE;
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+ sdebug_capacity = get_sdebug_capacity();
/* play around with geometry, don't waste too much on track 0 */
sdebug_heads = 8;
--
1.5.3.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/5] scsi_debug: remove the duplicated code in resp_read and resp_write
2008-03-29 15:59 ` [PATCH 2/5] scsi_debug: sweep up sdebug_capacity calculation FUJITA Tomonori
@ 2008-03-29 15:59 ` FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk FUJITA Tomonori
0 siblings, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-29 15:59 UTC (permalink / raw)
To: linux-scsi; +Cc: tomof, FUJITA Tomonori, Douglas Gilbert, James Bottomley
resp_read and resp_write performs READ_* and WRITE_* commands
respectively. This sweeps up the similar code in them.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
drivers/scsi/scsi_debug.c | 116 +++++++++++++++++++-------------------------
1 files changed, 50 insertions(+), 66 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 70bcee6..c98559e 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1468,25 +1468,53 @@ static int resp_log_sense(struct scsi_cmnd * scp,
min(len, SDEBUG_MAX_INQ_ARR_SZ));
}
-static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba,
- unsigned int num, struct sdebug_dev_info * devip)
+static int check_device_access_params(struct sdebug_dev_info *devi,
+ unsigned long long lba, unsigned int num)
{
- unsigned long iflags;
- unsigned int block, from_bottom;
- unsigned long long u;
- int ret;
-
if (lba + num > sdebug_capacity) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE,
- 0);
+ mk_sense_buffer(devi, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, 0);
return check_condition_result;
}
/* transfer length excessive (tie in to block limits VPD page) */
if (num > sdebug_store_sectors) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
- 0);
+ mk_sense_buffer(devi, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
return check_condition_result;
}
+ return 0;
+}
+
+static int do_device_access(struct scsi_cmnd *scmd,
+ struct sdebug_dev_info *devi,
+ unsigned long long lba, unsigned int num, int write)
+{
+ int ret;
+ unsigned int block, rest = 0;
+ int (*func)(struct scsi_cmnd *, unsigned char *, int);
+
+ func = write ? fetch_to_dev_buffer : fill_from_dev_buffer;
+
+ block = do_div(lba, sdebug_store_sectors);
+ if (block + num > sdebug_store_sectors)
+ rest = block + num - sdebug_store_sectors;
+
+ ret = func(scmd, fake_storep + (block * SECT_SIZE),
+ (num - rest) * SECT_SIZE);
+ if (!ret && rest)
+ ret = func(scmd, fake_storep, rest * SECT_SIZE);
+
+ return ret;
+}
+
+static int resp_read(struct scsi_cmnd *SCpnt, unsigned long long lba,
+ unsigned int num, struct sdebug_dev_info *devip)
+{
+ unsigned long iflags;
+ int ret;
+
+ ret = check_device_access_params(devip, lba, num);
+ if (ret)
+ return ret;
+
if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) &&
(lba <= OPT_MEDIUM_ERR_ADDR) &&
((lba + num) > OPT_MEDIUM_ERR_ADDR)) {
@@ -1505,74 +1533,30 @@ static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba,
return check_condition_result;
}
read_lock_irqsave(&atomic_rw, iflags);
- if ((lba + num) <= sdebug_store_sectors)
- ret = fill_from_dev_buffer(SCpnt,
- fake_storep + (lba * SECT_SIZE),
- num * SECT_SIZE);
- else {
- /* modulo when one arg is 64 bits needs do_div() */
- u = lba;
- block = do_div(u, sdebug_store_sectors);
- from_bottom = 0;
- if ((block + num) > sdebug_store_sectors)
- from_bottom = (block + num) - sdebug_store_sectors;
- ret = fill_from_dev_buffer(SCpnt,
- fake_storep + (block * SECT_SIZE),
- (num - from_bottom) * SECT_SIZE);
- if ((0 == ret) && (from_bottom > 0))
- ret = fill_from_dev_buffer(SCpnt, fake_storep,
- from_bottom * SECT_SIZE);
- }
+ ret = do_device_access(SCpnt, devip, lba, num, 0);
read_unlock_irqrestore(&atomic_rw, iflags);
return ret;
}
-static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba,
- unsigned int num, struct sdebug_dev_info * devip)
+static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba,
+ unsigned int num, struct sdebug_dev_info *devip)
{
unsigned long iflags;
- unsigned int block, to_bottom;
- unsigned long long u;
- int res;
+ int ret;
- if (lba + num > sdebug_capacity) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE,
- 0);
- return check_condition_result;
- }
- /* transfer length excessive (tie in to block limits VPD page) */
- if (num > sdebug_store_sectors) {
- mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
- 0);
- return check_condition_result;
- }
+ ret = check_device_access_params(devip, lba, num);
+ if (ret)
+ return ret;
write_lock_irqsave(&atomic_rw, iflags);
- if ((lba + num) <= sdebug_store_sectors)
- res = fetch_to_dev_buffer(SCpnt,
- fake_storep + (lba * SECT_SIZE),
- num * SECT_SIZE);
- else {
- /* modulo when one arg is 64 bits needs do_div() */
- u = lba;
- block = do_div(u, sdebug_store_sectors);
- to_bottom = 0;
- if ((block + num) > sdebug_store_sectors)
- to_bottom = (block + num) - sdebug_store_sectors;
- res = fetch_to_dev_buffer(SCpnt,
- fake_storep + (block * SECT_SIZE),
- (num - to_bottom) * SECT_SIZE);
- if ((0 == res) && (to_bottom > 0))
- res = fetch_to_dev_buffer(SCpnt, fake_storep,
- to_bottom * SECT_SIZE);
- }
+ ret = do_device_access(SCpnt, devip, lba, num, 1);
write_unlock_irqrestore(&atomic_rw, iflags);
- if (-1 == res)
+ if (-1 == ret)
return (DID_ERROR << 16);
- else if ((res < (num * SECT_SIZE)) &&
+ else if ((ret < (num * SECT_SIZE)) &&
(SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
printk(KERN_INFO "scsi_debug: write: cdb indicated=%u, "
- " IO sent=%d bytes\n", num * SECT_SIZE, res);
+ " IO sent=%d bytes\n", num * SECT_SIZE, ret);
return 0;
}
--
1.5.3.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/5] scsi_debug: support large non-fake virtual disk
2008-03-29 15:59 ` [PATCH 3/5] scsi_debug: remove the duplicated code in resp_read and resp_write FUJITA Tomonori
@ 2008-03-29 15:59 ` FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 5/5] scsi_debug: remove unnecessary function declarations FUJITA Tomonori
2008-03-29 18:09 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk Douglas Gilbert
0 siblings, 2 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-29 15:59 UTC (permalink / raw)
To: linux-scsi; +Cc: tomof, FUJITA Tomonori, Douglas Gilbert, James Bottomley
Currently, the maximum amount of RAM that scsi_debug can allocate is
4GB. This patch increases it to 2TB; scsi_debug can allocates 2TB
memory and export it as if it were 2TB scsi disk.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
drivers/scsi/scsi_debug.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index c98559e..1b6a6d8 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1949,7 +1949,7 @@ static void __init init_all_queued(void)
}
static void __init sdebug_build_parts(unsigned char *ramp,
- unsigned int store_size)
+ unsigned long store_size)
{
struct partition * pp;
int starts[SDEBUG_MAX_PARTS + 2];
@@ -2476,14 +2476,14 @@ static void do_remove_driverfs_files(void)
static int __init scsi_debug_init(void)
{
- unsigned int sz;
+ unsigned long sz;
int host_to_add;
int k;
int ret;
if (scsi_debug_dev_size_mb < 1)
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
- sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
+ sz = (unsigned long)scsi_debug_dev_size_mb * 1048576;
sdebug_store_sectors = sz / SECT_SIZE;
sdebug_capacity = get_sdebug_capacity();
--
1.5.3.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/5] scsi_debug: remove unnecessary function declarations
2008-03-29 15:59 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk FUJITA Tomonori
@ 2008-03-29 15:59 ` FUJITA Tomonori
2008-03-29 18:09 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk Douglas Gilbert
1 sibling, 0 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-29 15:59 UTC (permalink / raw)
To: linux-scsi; +Cc: tomof, FUJITA Tomonori, Douglas Gilbert, James Bottomley
This patch removes function declarations with moving some
functions. This cleans up them a bit to silence checkpatch.pl. There
is no functional change.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
drivers/scsi/scsi_debug.c | 277 ++++++++++++++++++++++-----------------------
1 files changed, 133 insertions(+), 144 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1b6a6d8..07103c3 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -218,8 +218,6 @@ static DEFINE_RWLOCK(atomic_rw);
static char sdebug_proc_name[] = "scsi_debug";
-static int sdebug_driver_probe(struct device *);
-static int sdebug_driver_remove(struct device *);
static struct bus_type pseudo_lld_bus;
static struct device_driver sdebug_driverfs_driver = {
@@ -235,18 +233,42 @@ static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
0, 0, 0x0, 0x0};
-static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev);
-static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
- int asc, int asq);
-static void stop_all_queued(void);
-static int stop_queued_cmnd(struct scsi_cmnd * cmnd);
-
static int sdebug_add_adapter(void);
static void sdebug_remove_adapter(void);
-static void sdebug_max_tgts_luns(void);
-static struct device pseudo_primary;
-static struct bus_type pseudo_lld_bus;
+static void sdebug_max_tgts_luns(void)
+{
+ struct sdebug_host_info *sdbg_host;
+ struct Scsi_Host *hpnt;
+
+ spin_lock(&sdebug_host_list_lock);
+ list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
+ hpnt = sdbg_host->shost;
+ if ((hpnt->this_id >= 0) &&
+ (scsi_debug_num_tgts > hpnt->this_id))
+ hpnt->max_id = scsi_debug_num_tgts + 1;
+ else
+ hpnt->max_id = scsi_debug_num_tgts;
+ /* scsi_debug_max_luns; */
+ hpnt->max_lun = SAM2_WLUN_REPORT_LUNS;
+ }
+ spin_unlock(&sdebug_host_list_lock);
+}
+
+static void mk_sense_buffer(struct sdebug_dev_info *devip, int key,
+ int asc, int asq)
+{
+ unsigned char *sbuff;
+
+ sbuff = devip->sense_buff;
+ memset(sbuff, 0, SDEBUG_SENSE_LEN);
+
+ scsi_build_sense_buffer(scsi_debug_dsense, sbuff, key, asc, asq);
+
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: [sense_key,asc,ascq]: "
+ "[0x%x,0x%x,0x%x]\n", key, asc, asq);
+}
static void get_data_transfer_info(unsigned char *cmd,
unsigned long long *lba, unsigned int *num)
@@ -1680,52 +1702,9 @@ static void timer_intr_handler(unsigned long indx)
spin_unlock_irqrestore(&queued_arr_lock, iflags);
}
-static int scsi_debug_slave_alloc(struct scsi_device * sdp)
-{
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: slave_alloc <%u %u %u %u>\n",
- sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
- set_bit(QUEUE_FLAG_BIDI, &sdp->request_queue->queue_flags);
- return 0;
-}
-
-static int scsi_debug_slave_configure(struct scsi_device * sdp)
-{
- struct sdebug_dev_info * devip;
-
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n",
- sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
- if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
- sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN;
- devip = devInfoReg(sdp);
- if (NULL == devip)
- return 1; /* no resources, will be marked offline */
- sdp->hostdata = devip;
- if (sdp->host->cmd_per_lun)
- scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING,
- sdp->host->cmd_per_lun);
- blk_queue_max_segment_size(sdp->request_queue, 256 * 1024);
- return 0;
-}
-
-static void scsi_debug_slave_destroy(struct scsi_device * sdp)
-{
- struct sdebug_dev_info * devip =
- (struct sdebug_dev_info *)sdp->hostdata;
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: slave_destroy <%u %u %u %u>\n",
- sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
- if (devip) {
- /* make this slot avaliable for re-use */
- devip->used = 0;
- sdp->hostdata = NULL;
- }
-}
-
-struct sdebug_dev_info *sdebug_device_create(struct sdebug_host_info *sdbg_host,
- gfp_t flags)
+static struct sdebug_dev_info *
+sdebug_device_create(struct sdebug_host_info *sdbg_host, gfp_t flags)
{
struct sdebug_dev_info *devip;
@@ -1789,19 +1768,88 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
return open_devip;
}
-static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
- int asc, int asq)
+static int scsi_debug_slave_alloc(struct scsi_device *sdp)
{
- unsigned char *sbuff;
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: slave_alloc <%u %u %u %u>\n",
+ sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
+ set_bit(QUEUE_FLAG_BIDI, &sdp->request_queue->queue_flags);
+ return 0;
+}
- sbuff = devip->sense_buff;
- memset(sbuff, 0, SDEBUG_SENSE_LEN);
+static int scsi_debug_slave_configure(struct scsi_device *sdp)
+{
+ struct sdebug_dev_info *devip;
- scsi_build_sense_buffer(scsi_debug_dsense, sbuff, key, asc, asq);
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n",
+ sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
+ if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
+ sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN;
+ devip = devInfoReg(sdp);
+ if (NULL == devip)
+ return 1; /* no resources, will be marked offline */
+ sdp->hostdata = devip;
+ if (sdp->host->cmd_per_lun)
+ scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING,
+ sdp->host->cmd_per_lun);
+ blk_queue_max_segment_size(sdp->request_queue, 256 * 1024);
+ return 0;
+}
+
+static void scsi_debug_slave_destroy(struct scsi_device *sdp)
+{
+ struct sdebug_dev_info *devip =
+ (struct sdebug_dev_info *)sdp->hostdata;
if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: [sense_key,asc,ascq]: "
- "[0x%x,0x%x,0x%x]\n", key, asc, asq);
+ printk(KERN_INFO "scsi_debug: slave_destroy <%u %u %u %u>\n",
+ sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
+ if (devip) {
+ /* make this slot avaliable for re-use */
+ devip->used = 0;
+ sdp->hostdata = NULL;
+ }
+}
+
+/* Returns 1 if found 'cmnd' and deleted its timer. else returns 0 */
+static int stop_queued_cmnd(struct scsi_cmnd *cmnd)
+{
+ unsigned long iflags;
+ int k;
+ struct sdebug_queued_cmd *sqcp;
+
+ spin_lock_irqsave(&queued_arr_lock, iflags);
+ for (k = 0; k < SCSI_DEBUG_CANQUEUE; ++k) {
+ sqcp = &queued_arr[k];
+ if (sqcp->in_use && (cmnd == sqcp->a_cmnd)) {
+ del_timer_sync(&sqcp->cmnd_timer);
+ sqcp->in_use = 0;
+ sqcp->a_cmnd = NULL;
+ break;
+ }
+ }
+ spin_unlock_irqrestore(&queued_arr_lock, iflags);
+ return (k < SCSI_DEBUG_CANQUEUE) ? 1 : 0;
+}
+
+/* Deletes (stops) timers of all queued commands */
+static void stop_all_queued(void)
+{
+ unsigned long iflags;
+ int k;
+ struct sdebug_queued_cmd *sqcp;
+
+ spin_lock_irqsave(&queued_arr_lock, iflags);
+ for (k = 0; k < SCSI_DEBUG_CANQUEUE; ++k) {
+ sqcp = &queued_arr[k];
+ if (sqcp->in_use && sqcp->a_cmnd) {
+ del_timer_sync(&sqcp->cmnd_timer);
+ sqcp->in_use = 0;
+ sqcp->a_cmnd = NULL;
+ }
+ }
+ spin_unlock_irqrestore(&queued_arr_lock, iflags);
}
static int scsi_debug_abort(struct scsi_cmnd * SCpnt)
@@ -1891,46 +1939,6 @@ static int scsi_debug_host_reset(struct scsi_cmnd * SCpnt)
return SUCCESS;
}
-/* Returns 1 if found 'cmnd' and deleted its timer. else returns 0 */
-static int stop_queued_cmnd(struct scsi_cmnd * cmnd)
-{
- unsigned long iflags;
- int k;
- struct sdebug_queued_cmd * sqcp;
-
- spin_lock_irqsave(&queued_arr_lock, iflags);
- for (k = 0; k < SCSI_DEBUG_CANQUEUE; ++k) {
- sqcp = &queued_arr[k];
- if (sqcp->in_use && (cmnd == sqcp->a_cmnd)) {
- del_timer_sync(&sqcp->cmnd_timer);
- sqcp->in_use = 0;
- sqcp->a_cmnd = NULL;
- break;
- }
- }
- spin_unlock_irqrestore(&queued_arr_lock, iflags);
- return (k < SCSI_DEBUG_CANQUEUE) ? 1 : 0;
-}
-
-/* Deletes (stops) timers of all queued commands */
-static void stop_all_queued(void)
-{
- unsigned long iflags;
- int k;
- struct sdebug_queued_cmd * sqcp;
-
- spin_lock_irqsave(&queued_arr_lock, iflags);
- for (k = 0; k < SCSI_DEBUG_CANQUEUE; ++k) {
- sqcp = &queued_arr[k];
- if (sqcp->in_use && sqcp->a_cmnd) {
- del_timer_sync(&sqcp->cmnd_timer);
- sqcp->in_use = 0;
- sqcp->a_cmnd = NULL;
- }
- }
- spin_unlock_irqrestore(&queued_arr_lock, iflags);
-}
-
/* Initializes timers in queued array */
static void __init init_all_queued(void)
{
@@ -2055,7 +2063,6 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
return 0;
}
}
-
/* Note: The following macros create attribute files in the
/sys/module/scsi_debug/parameters directory. Unfortunately this
driver is unaware of a change and cannot trigger auxiliary actions
@@ -2474,6 +2481,17 @@ static void do_remove_driverfs_files(void)
driver_remove_file(&sdebug_driverfs_driver, &driver_attr_add_host);
}
+static void pseudo_0_release(struct device *dev)
+{
+ if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
+ printk(KERN_INFO "scsi_debug: pseudo_0_release() called\n");
+}
+
+static struct device pseudo_primary = {
+ .bus_id = "pseudo_0",
+ .release = pseudo_0_release,
+};
+
static int __init scsi_debug_init(void)
{
unsigned long sz;
@@ -2588,30 +2606,6 @@ static void __exit scsi_debug_exit(void)
device_initcall(scsi_debug_init);
module_exit(scsi_debug_exit);
-static void pseudo_0_release(struct device * dev)
-{
- if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
- printk(KERN_INFO "scsi_debug: pseudo_0_release() called\n");
-}
-
-static struct device pseudo_primary = {
- .bus_id = "pseudo_0",
- .release = pseudo_0_release,
-};
-
-static int pseudo_lld_bus_match(struct device *dev,
- struct device_driver *dev_driver)
-{
- return 1;
-}
-
-static struct bus_type pseudo_lld_bus = {
- .name = "pseudo",
- .match = pseudo_lld_bus_match,
- .probe = sdebug_driver_probe,
- .remove = sdebug_driver_remove,
-};
-
static void sdebug_release_adapter(struct device * dev)
{
struct sdebug_host_info *sdbg_host;
@@ -3011,20 +3005,15 @@ static int sdebug_driver_remove(struct device * dev)
return 0;
}
-static void sdebug_max_tgts_luns(void)
+static int pseudo_lld_bus_match(struct device *dev,
+ struct device_driver *dev_driver)
{
- struct sdebug_host_info * sdbg_host;
- struct Scsi_Host *hpnt;
-
- spin_lock(&sdebug_host_list_lock);
- list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
- hpnt = sdbg_host->shost;
- if ((hpnt->this_id >= 0) &&
- (scsi_debug_num_tgts > hpnt->this_id))
- hpnt->max_id = scsi_debug_num_tgts + 1;
- else
- hpnt->max_id = scsi_debug_num_tgts;
- hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* scsi_debug_max_luns; */
- }
- spin_unlock(&sdebug_host_list_lock);
+ return 1;
}
+
+static struct bus_type pseudo_lld_bus = {
+ .name = "pseudo",
+ .match = pseudo_lld_bus_match,
+ .probe = sdebug_driver_probe,
+ .remove = sdebug_driver_remove,
+};
--
1.5.3.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 4/5] scsi_debug: support large non-fake virtual disk
2008-03-29 15:59 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 5/5] scsi_debug: remove unnecessary function declarations FUJITA Tomonori
@ 2008-03-29 18:09 ` Douglas Gilbert
2008-03-30 2:58 ` FUJITA Tomonori
1 sibling, 1 reply; 9+ messages in thread
From: Douglas Gilbert @ 2008-03-29 18:09 UTC (permalink / raw)
To: FUJITA Tomonori; +Cc: linux-scsi, tomof, James Bottomley
FUJITA Tomonori wrote:
> Currently, the maximum amount of RAM that scsi_debug can allocate is
> 4GB. This patch increases it to 2TB; scsi_debug can allocates 2TB
> memory and export it as if it were 2TB scsi disk.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> Cc: Douglas Gilbert <dougg@torque.net>
> Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> ---
> drivers/scsi/scsi_debug.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index c98559e..1b6a6d8 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -1949,7 +1949,7 @@ static void __init init_all_queued(void)
> }
>
> static void __init sdebug_build_parts(unsigned char *ramp,
> - unsigned int store_size)
> + unsigned long store_size)
> {
> struct partition * pp;
> int starts[SDEBUG_MAX_PARTS + 2];
> @@ -2476,14 +2476,14 @@ static void do_remove_driverfs_files(void)
>
> static int __init scsi_debug_init(void)
> {
> - unsigned int sz;
> + unsigned long sz;
> int host_to_add;
> int k;
> int ret;
>
> if (scsi_debug_dev_size_mb < 1)
> scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
> - sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
> + sz = (unsigned long)scsi_debug_dev_size_mb * 1048576;
> sdebug_store_sectors = sz / SECT_SIZE;
> sdebug_capacity = get_sdebug_capacity();
>
Tomo,
Unsigned long is 32 bits on i386 (and 64 bits in the LP64
data model). Don't you want 64 bits in all cases? Either
unsigned long long, uint64_t or one of those crappy
kernel typedefs for 64 bits.
BTW I recently removed just about all the "unsigned long"
declarations out of sg3_utils due the uncertainty about the
size of "long".
Doug Gilbert
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/5] scsi_debug: support large non-fake virtual disk
2008-03-29 18:09 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk Douglas Gilbert
@ 2008-03-30 2:58 ` FUJITA Tomonori
0 siblings, 0 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2008-03-30 2:58 UTC (permalink / raw)
To: dougg; +Cc: fujita.tomonori, linux-scsi, tomof, James.Bottomley
On Sat, 29 Mar 2008 14:09:29 -0400
Douglas Gilbert <dougg@torque.net> wrote:
> FUJITA Tomonori wrote:
> > Currently, the maximum amount of RAM that scsi_debug can allocate is
> > 4GB. This patch increases it to 2TB; scsi_debug can allocates 2TB
> > memory and export it as if it were 2TB scsi disk.
> >
> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> > Cc: Douglas Gilbert <dougg@torque.net>
> > Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
> > ---
> > drivers/scsi/scsi_debug.c | 6 +++---
> > 1 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> > index c98559e..1b6a6d8 100644
> > --- a/drivers/scsi/scsi_debug.c
> > +++ b/drivers/scsi/scsi_debug.c
> > @@ -1949,7 +1949,7 @@ static void __init init_all_queued(void)
> > }
> >
> > static void __init sdebug_build_parts(unsigned char *ramp,
> > - unsigned int store_size)
> > + unsigned long store_size)
> > {
> > struct partition * pp;
> > int starts[SDEBUG_MAX_PARTS + 2];
> > @@ -2476,14 +2476,14 @@ static void do_remove_driverfs_files(void)
> >
> > static int __init scsi_debug_init(void)
> > {
> > - unsigned int sz;
> > + unsigned long sz;
> > int host_to_add;
> > int k;
> > int ret;
> >
> > if (scsi_debug_dev_size_mb < 1)
> > scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
> > - sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
> > + sz = (unsigned long)scsi_debug_dev_size_mb * 1048576;
> > sdebug_store_sectors = sz / SECT_SIZE;
> > sdebug_capacity = get_sdebug_capacity();
> >
>
> Tomo,
> Unsigned long is 32 bits on i386 (and 64 bits in the LP64
> data model). Don't you want 64 bits in all cases? Either
> unsigned long long, uint64_t or one of those crappy
> kernel typedefs for 64 bits.
I don't think that u64 is useful.
scsi_debug uses vmalloc for logical unit's contents. so u32 is large
enough for 32-bit systems.
Even if we change scsi_debug use alloc_pages to allocate multiple
pages, 32-bit systems can have only several GB memory at most. So u32
is large enough for them in most cases. The advantage of vmalloc, a
continuous memory area, making the driver simpler a bit, is nice.
vmalloc takes unsigned long so I changed 'unsigned int' to 'unsigned
long' here.
In the end, you need a 64-bit system if you want scsi_debug use huge
amount memory.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate
2008-03-29 15:59 [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 1/5] scsi_debug: remove unnecessary sdebug_store_size FUJITA Tomonori
@ 2008-03-30 17:11 ` Douglas Gilbert
1 sibling, 0 replies; 9+ messages in thread
From: Douglas Gilbert @ 2008-03-30 17:11 UTC (permalink / raw)
To: FUJITA Tomonori; +Cc: linux-scsi, tomof, James.Bottomley
FUJITA Tomonori wrote:
> Currently, the maximum amount of RAM that scsi_debug can actually
> allocate is 4GB. This patchset increase it to 2TB.
>
> Here's an example, scsi_debug allocates 6GB ram and exports it as if
> it were 6GB disk.
>
> fujita@rose:/sys/bus/pseudo/drivers/scsi_debug$ cat virtual_gb
> 0
> fujita@rose:/sys/bus/pseudo/drivers/scsi_debug$ cat dev_size_mb
> 6144
>
> scsi3 : scsi_debug, version 1.81 [20070104], dev_size_mb=6144, opts=0x0
> scsi 3:0:0:0: Direct-Access Linux scsi_debug 0004 PQ: 0 ANSI: 5
> sd 3:0:0:0: [sdc] 12582912 512-byte hardware sectors (6442 MB)
>
>
> This patchset also include minor cleanup.
>
> This is against scsi-misc with the scsi_build_sense_buffer helper
> patchset and the scsi_debug lba fix:
>
> http://marc.info/?l=linux-scsi&m=120640632301595&w=2
>
> http://marc.info/?l=linux-scsi&m=120643343003171&w=2
For patches 1/5, 2/5, 3/5, 4/5 and 5/5 associated with this post:
Signed-off-by: Douglas Gilbert <dougg@torque.net>
Doug Gilbert
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-03-30 17:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-29 15:59 [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 1/5] scsi_debug: remove unnecessary sdebug_store_size FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 2/5] scsi_debug: sweep up sdebug_capacity calculation FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 3/5] scsi_debug: remove the duplicated code in resp_read and resp_write FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk FUJITA Tomonori
2008-03-29 15:59 ` [PATCH 5/5] scsi_debug: remove unnecessary function declarations FUJITA Tomonori
2008-03-29 18:09 ` [PATCH 4/5] scsi_debug: support large non-fake virtual disk Douglas Gilbert
2008-03-30 2:58 ` FUJITA Tomonori
2008-03-30 17:11 ` [PATCH 0/5] scsi_debug: increase the amount of ram that scsi_ram can allocate Douglas Gilbert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).