aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-10-04 15:39:14 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-10-04 15:39:14 -0400
commit58e57fbd1c7e8833314459555e337364fe5521f3 (patch)
tree242a3859387588889c9dcc45915b0dec951f84c3 /drivers/block
parent8a0382f6fceaf0c6479e582e1054f36333ea3d24 (diff)
parent0f78ab9899e9d6acb09d5465def618704255963b (diff)
Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
* 'for-linus' of git://git.kernel.dk/linux-2.6-block: (41 commits) Revert "Seperate read and write statistics of in_flight requests" cfq-iosched: don't delay async queue if it hasn't dispatched at all block: Topology ioctls cfq-iosched: use assigned slice sync value, not default cfq-iosched: rename 'desktop' sysfs entry to 'low_latency' cfq-iosched: implement slower async initiate and queue ramp up cfq-iosched: delay async IO dispatch, if sync IO was just done cfq-iosched: add a knob for desktop interactiveness Add a tracepoint for block request remapping block: allow large discard requests block: use normal I/O path for discard requests swapfile: avoid NULL pointer dereference in swapon when s_bdev is NULL fs/bio.c: move EXPORT* macros to line after function Add missing blk_trace_remove_sysfs to be in pair with blk_trace_init_sysfs cciss: fix build when !PROC_FS block: Do not clamp max_hw_sectors for stacking devices block: Set max_sectors correctly for stacking devices cciss: cciss_host_attr_groups should be const cciss: Dynamically allocate the drive_info_struct for each logical drive. cciss: Add usage_count attribute to each logical drive in /sys ...
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/DAC960.c156
-rw-r--r--drivers/block/cciss.c753
-rw-r--r--drivers/block/cciss.h12
-rw-r--r--drivers/block/cpqarray.c63
4 files changed, 655 insertions, 329 deletions
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 6fa7b0fdbdfd..eb4fa1943944 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -38,6 +38,7 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/smp_lock.h> 39#include <linux/smp_lock.h>
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/seq_file.h>
41#include <linux/reboot.h> 42#include <linux/reboot.h>
42#include <linux/spinlock.h> 43#include <linux/spinlock.h>
43#include <linux/timer.h> 44#include <linux/timer.h>
@@ -6422,16 +6423,10 @@ static bool DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller,
6422 return true; 6423 return true;
6423} 6424}
6424 6425
6425 6426static int dac960_proc_show(struct seq_file *m, void *v)
6426/*
6427 DAC960_ProcReadStatus implements reading /proc/rd/status.
6428*/
6429
6430static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset,
6431 int Count, int *EOF, void *Data)
6432{ 6427{
6433 unsigned char *StatusMessage = "OK\n"; 6428 unsigned char *StatusMessage = "OK\n";
6434 int ControllerNumber, BytesAvailable; 6429 int ControllerNumber;
6435 for (ControllerNumber = 0; 6430 for (ControllerNumber = 0;
6436 ControllerNumber < DAC960_ControllerCount; 6431 ControllerNumber < DAC960_ControllerCount;
6437 ControllerNumber++) 6432 ControllerNumber++)
@@ -6444,52 +6439,49 @@ static int DAC960_ProcReadStatus(char *Page, char **Start, off_t Offset,
6444 break; 6439 break;
6445 } 6440 }
6446 } 6441 }
6447 BytesAvailable = strlen(StatusMessage) - Offset; 6442 seq_puts(m, StatusMessage);
6448 if (Count >= BytesAvailable) 6443 return 0;
6449 {
6450 Count = BytesAvailable;
6451 *EOF = true;
6452 }
6453 if (Count <= 0) return 0;
6454 *Start = Page;
6455 memcpy(Page, &StatusMessage[Offset], Count);
6456 return Count;
6457} 6444}
6458 6445
6446static int dac960_proc_open(struct inode *inode, struct file *file)
6447{
6448 return single_open(file, dac960_proc_show, NULL);
6449}
6459 6450
6460/* 6451static const struct file_operations dac960_proc_fops = {
6461 DAC960_ProcReadInitialStatus implements reading /proc/rd/cN/initial_status. 6452 .owner = THIS_MODULE,
6462*/ 6453 .open = dac960_proc_open,
6454 .read = seq_read,
6455 .llseek = seq_lseek,
6456 .release = single_release,
6457};
6463 6458
6464static int DAC960_ProcReadInitialStatus(char *Page, char **Start, off_t Offset, 6459static int dac960_initial_status_proc_show(struct seq_file *m, void *v)
6465 int Count, int *EOF, void *Data)
6466{ 6460{
6467 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; 6461 DAC960_Controller_T *Controller = (DAC960_Controller_T *)m->private;
6468 int BytesAvailable = Controller->InitialStatusLength - Offset; 6462 seq_printf(m, "%.*s", Controller->InitialStatusLength, Controller->CombinedStatusBuffer);
6469 if (Count >= BytesAvailable) 6463 return 0;
6470 {
6471 Count = BytesAvailable;
6472 *EOF = true;
6473 }
6474 if (Count <= 0) return 0;
6475 *Start = Page;
6476 memcpy(Page, &Controller->CombinedStatusBuffer[Offset], Count);
6477 return Count;
6478} 6464}
6479 6465
6466static int dac960_initial_status_proc_open(struct inode *inode, struct file *file)
6467{
6468 return single_open(file, dac960_initial_status_proc_show, PDE(inode)->data);
6469}
6480 6470
6481/* 6471static const struct file_operations dac960_initial_status_proc_fops = {
6482 DAC960_ProcReadCurrentStatus implements reading /proc/rd/cN/current_status. 6472 .owner = THIS_MODULE,
6483*/ 6473 .open = dac960_initial_status_proc_open,
6474 .read = seq_read,
6475 .llseek = seq_lseek,
6476 .release = single_release,
6477};
6484 6478
6485static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset, 6479static int dac960_current_status_proc_show(struct seq_file *m, void *v)
6486 int Count, int *EOF, void *Data)
6487{ 6480{
6488 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; 6481 DAC960_Controller_T *Controller = (DAC960_Controller_T *) m->private;
6489 unsigned char *StatusMessage = 6482 unsigned char *StatusMessage =
6490 "No Rebuild or Consistency Check in Progress\n"; 6483 "No Rebuild or Consistency Check in Progress\n";
6491 int ProgressMessageLength = strlen(StatusMessage); 6484 int ProgressMessageLength = strlen(StatusMessage);
6492 int BytesAvailable;
6493 if (jiffies != Controller->LastCurrentStatusTime) 6485 if (jiffies != Controller->LastCurrentStatusTime)
6494 { 6486 {
6495 Controller->CurrentStatusLength = 0; 6487 Controller->CurrentStatusLength = 0;
@@ -6513,49 +6505,41 @@ static int DAC960_ProcReadCurrentStatus(char *Page, char **Start, off_t Offset,
6513 } 6505 }
6514 Controller->LastCurrentStatusTime = jiffies; 6506 Controller->LastCurrentStatusTime = jiffies;
6515 } 6507 }
6516 BytesAvailable = Controller->CurrentStatusLength - Offset; 6508 seq_printf(m, "%.*s", Controller->CurrentStatusLength, Controller->CurrentStatusBuffer);
6517 if (Count >= BytesAvailable) 6509 return 0;
6518 {
6519 Count = BytesAvailable;
6520 *EOF = true;
6521 }
6522 if (Count <= 0) return 0;
6523 *Start = Page;
6524 memcpy(Page, &Controller->CurrentStatusBuffer[Offset], Count);
6525 return Count;
6526} 6510}
6527 6511
6512static int dac960_current_status_proc_open(struct inode *inode, struct file *file)
6513{
6514 return single_open(file, dac960_current_status_proc_show, PDE(inode)->data);
6515}
6528 6516
6529/* 6517static const struct file_operations dac960_current_status_proc_fops = {
6530 DAC960_ProcReadUserCommand implements reading /proc/rd/cN/user_command. 6518 .owner = THIS_MODULE,
6531*/ 6519 .open = dac960_current_status_proc_open,
6520 .read = seq_read,
6521 .llseek = seq_lseek,
6522 .release = single_release,
6523};
6532 6524
6533static int DAC960_ProcReadUserCommand(char *Page, char **Start, off_t Offset, 6525static int dac960_user_command_proc_show(struct seq_file *m, void *v)
6534 int Count, int *EOF, void *Data)
6535{ 6526{
6536 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; 6527 DAC960_Controller_T *Controller = (DAC960_Controller_T *)m->private;
6537 int BytesAvailable = Controller->UserStatusLength - Offset;
6538 if (Count >= BytesAvailable)
6539 {
6540 Count = BytesAvailable;
6541 *EOF = true;
6542 }
6543 if (Count <= 0) return 0;
6544 *Start = Page;
6545 memcpy(Page, &Controller->UserStatusBuffer[Offset], Count);
6546 return Count;
6547}
6548 6528
6529 seq_printf(m, "%.*s", Controller->UserStatusLength, Controller->UserStatusBuffer);
6530 return 0;
6531}
6549 6532
6550/* 6533static int dac960_user_command_proc_open(struct inode *inode, struct file *file)
6551 DAC960_ProcWriteUserCommand implements writing /proc/rd/cN/user_command. 6534{
6552*/ 6535 return single_open(file, dac960_user_command_proc_show, PDE(inode)->data);
6536}
6553 6537
6554static int DAC960_ProcWriteUserCommand(struct file *file, 6538static ssize_t dac960_user_command_proc_write(struct file *file,
6555 const char __user *Buffer, 6539 const char __user *Buffer,
6556 unsigned long Count, void *Data) 6540 size_t Count, loff_t *pos)
6557{ 6541{
6558 DAC960_Controller_T *Controller = (DAC960_Controller_T *) Data; 6542 DAC960_Controller_T *Controller = (DAC960_Controller_T *) PDE(file->f_path.dentry->d_inode)->data;
6559 unsigned char CommandBuffer[80]; 6543 unsigned char CommandBuffer[80];
6560 int Length; 6544 int Length;
6561 if (Count > sizeof(CommandBuffer)-1) return -EINVAL; 6545 if (Count > sizeof(CommandBuffer)-1) return -EINVAL;
@@ -6572,6 +6556,14 @@ static int DAC960_ProcWriteUserCommand(struct file *file,
6572 ? Count : -EBUSY); 6556 ? Count : -EBUSY);
6573} 6557}
6574 6558
6559static const struct file_operations dac960_user_command_proc_fops = {
6560 .owner = THIS_MODULE,
6561 .open = dac960_user_command_proc_open,
6562 .read = seq_read,
6563 .llseek = seq_lseek,
6564 .release = single_release,
6565 .write = dac960_user_command_proc_write,
6566};
6575 6567
6576/* 6568/*
6577 DAC960_CreateProcEntries creates the /proc/rd/... entries for the 6569 DAC960_CreateProcEntries creates the /proc/rd/... entries for the
@@ -6586,23 +6578,17 @@ static void DAC960_CreateProcEntries(DAC960_Controller_T *Controller)
6586 6578
6587 if (DAC960_ProcDirectoryEntry == NULL) { 6579 if (DAC960_ProcDirectoryEntry == NULL) {
6588 DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL); 6580 DAC960_ProcDirectoryEntry = proc_mkdir("rd", NULL);
6589 StatusProcEntry = create_proc_read_entry("status", 0, 6581 StatusProcEntry = proc_create("status", 0,
6590 DAC960_ProcDirectoryEntry, 6582 DAC960_ProcDirectoryEntry,
6591 DAC960_ProcReadStatus, NULL); 6583 &dac960_proc_fops);
6592 } 6584 }
6593 6585
6594 sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber); 6586 sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber);
6595 ControllerProcEntry = proc_mkdir(Controller->ControllerName, 6587 ControllerProcEntry = proc_mkdir(Controller->ControllerName,
6596 DAC960_ProcDirectoryEntry); 6588 DAC960_ProcDirectoryEntry);
6597 create_proc_read_entry("initial_status", 0, ControllerProcEntry, 6589 proc_create_data("initial_status", 0, ControllerProcEntry, &dac960_initial_status_proc_fops, Controller);
6598 DAC960_ProcReadInitialStatus, Controller); 6590 proc_create_data("current_status", 0, ControllerProcEntry, &dac960_current_status_proc_fops, Controller);
6599 create_proc_read_entry("current_status", 0, ControllerProcEntry, 6591 UserCommandProcEntry = proc_create_data("user_command", S_IWUSR | S_IRUSR, ControllerProcEntry, &dac960_user_command_proc_fops, Controller);
6600 DAC960_ProcReadCurrentStatus, Controller);
6601 UserCommandProcEntry =
6602 create_proc_read_entry("user_command", S_IWUSR | S_IRUSR,
6603 ControllerProcEntry, DAC960_ProcReadUserCommand,
6604 Controller);
6605 UserCommandProcEntry->write_proc = DAC960_ProcWriteUserCommand;
6606 Controller->ControllerProcEntry = ControllerProcEntry; 6592 Controller->ControllerProcEntry = ControllerProcEntry;
6607} 6593}
6608 6594
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 1ece0b47b581..fb5be2d95d52 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -36,9 +36,11 @@
36#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
37#include <linux/seq_file.h> 37#include <linux/seq_file.h>
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/jiffies.h>
39#include <linux/hdreg.h> 40#include <linux/hdreg.h>
40#include <linux/spinlock.h> 41#include <linux/spinlock.h>
41#include <linux/compat.h> 42#include <linux/compat.h>
43#include <linux/mutex.h>
42#include <asm/uaccess.h> 44#include <asm/uaccess.h>
43#include <asm/io.h> 45#include <asm/io.h>
44 46
@@ -155,6 +157,10 @@ static struct board_type products[] = {
155 157
156static ctlr_info_t *hba[MAX_CTLR]; 158static ctlr_info_t *hba[MAX_CTLR];
157 159
160static struct task_struct *cciss_scan_thread;
161static DEFINE_MUTEX(scan_mutex);
162static LIST_HEAD(scan_q);
163
158static void do_cciss_request(struct request_queue *q); 164static void do_cciss_request(struct request_queue *q);
159static irqreturn_t do_cciss_intr(int irq, void *dev_id); 165static irqreturn_t do_cciss_intr(int irq, void *dev_id);
160static int cciss_open(struct block_device *bdev, fmode_t mode); 166static int cciss_open(struct block_device *bdev, fmode_t mode);
@@ -164,9 +170,9 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
164static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); 170static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
165 171
166static int cciss_revalidate(struct gendisk *disk); 172static int cciss_revalidate(struct gendisk *disk);
167static int rebuild_lun_table(ctlr_info_t *h, int first_time); 173static int rebuild_lun_table(ctlr_info_t *h, int first_time, int via_ioctl);
168static int deregister_disk(ctlr_info_t *h, int drv_index, 174static int deregister_disk(ctlr_info_t *h, int drv_index,
169 int clear_all); 175 int clear_all, int via_ioctl);
170 176
171static void cciss_read_capacity(int ctlr, int logvol, int withirq, 177static void cciss_read_capacity(int ctlr, int logvol, int withirq,
172 sector_t *total_size, unsigned int *block_size); 178 sector_t *total_size, unsigned int *block_size);
@@ -189,8 +195,13 @@ static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
189static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c); 195static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
190 196
191static void fail_all_cmds(unsigned long ctlr); 197static void fail_all_cmds(unsigned long ctlr);
198static int add_to_scan_list(struct ctlr_info *h);
192static int scan_thread(void *data); 199static int scan_thread(void *data);
193static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c); 200static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c);
201static void cciss_hba_release(struct device *dev);
202static void cciss_device_release(struct device *dev);
203static void cciss_free_gendisk(ctlr_info_t *h, int drv_index);
204static void cciss_free_drive_info(ctlr_info_t *h, int drv_index);
194 205
195#ifdef CONFIG_PROC_FS 206#ifdef CONFIG_PROC_FS
196static void cciss_procinit(int i); 207static void cciss_procinit(int i);
@@ -245,7 +256,10 @@ static inline void removeQ(CommandList_struct *c)
245 256
246#include "cciss_scsi.c" /* For SCSI tape support */ 257#include "cciss_scsi.c" /* For SCSI tape support */
247 258
248#define RAID_UNKNOWN 6 259static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
260 "UNKNOWN"
261};
262#define RAID_UNKNOWN (sizeof(raid_label) / sizeof(raid_label[0])-1)
249 263
250#ifdef CONFIG_PROC_FS 264#ifdef CONFIG_PROC_FS
251 265
@@ -255,9 +269,6 @@ static inline void removeQ(CommandList_struct *c)
255#define ENG_GIG 1000000000 269#define ENG_GIG 1000000000
256#define ENG_GIG_FACTOR (ENG_GIG/512) 270#define ENG_GIG_FACTOR (ENG_GIG/512)
257#define ENGAGE_SCSI "engage scsi" 271#define ENGAGE_SCSI "engage scsi"
258static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
259 "UNKNOWN"
260};
261 272
262static struct proc_dir_entry *proc_cciss; 273static struct proc_dir_entry *proc_cciss;
263 274
@@ -318,7 +329,7 @@ static int cciss_seq_show(struct seq_file *seq, void *v)
318 ctlr_info_t *h = seq->private; 329 ctlr_info_t *h = seq->private;
319 unsigned ctlr = h->ctlr; 330 unsigned ctlr = h->ctlr;
320 loff_t *pos = v; 331 loff_t *pos = v;
321 drive_info_struct *drv = &h->drv[*pos]; 332 drive_info_struct *drv = h->drv[*pos];
322 333
323 if (*pos > h->highest_lun) 334 if (*pos > h->highest_lun)
324 return 0; 335 return 0;
@@ -331,7 +342,7 @@ static int cciss_seq_show(struct seq_file *seq, void *v)
331 vol_sz_frac *= 100; 342 vol_sz_frac *= 100;
332 sector_div(vol_sz_frac, ENG_GIG_FACTOR); 343 sector_div(vol_sz_frac, ENG_GIG_FACTOR);
333 344
334 if (drv->raid_level > 5) 345 if (drv->raid_level < 0 || drv->raid_level > RAID_UNKNOWN)
335 drv->raid_level = RAID_UNKNOWN; 346 drv->raid_level = RAID_UNKNOWN;
336 seq_printf(seq, "cciss/c%dd%d:" 347 seq_printf(seq, "cciss/c%dd%d:"
337 "\t%4u.%02uGB\tRAID %s\n", 348 "\t%4u.%02uGB\tRAID %s\n",
@@ -454,9 +465,19 @@ static void __devinit cciss_procinit(int i)
454#define to_hba(n) container_of(n, struct ctlr_info, dev) 465#define to_hba(n) container_of(n, struct ctlr_info, dev)
455#define to_drv(n) container_of(n, drive_info_struct, dev) 466#define to_drv(n) container_of(n, drive_info_struct, dev)
456 467
457static struct device_type cciss_host_type = { 468static ssize_t host_store_rescan(struct device *dev,
458 .name = "cciss_host", 469 struct device_attribute *attr,
459}; 470 const char *buf, size_t count)
471{
472 struct ctlr_info *h = to_hba(dev);
473
474 add_to_scan_list(h);
475 wake_up_process(cciss_scan_thread);
476 wait_for_completion_interruptible(&h->scan_wait);
477
478 return count;
479}
480DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
460 481
461static ssize_t dev_show_unique_id(struct device *dev, 482static ssize_t dev_show_unique_id(struct device *dev,
462 struct device_attribute *attr, 483 struct device_attribute *attr,
@@ -560,11 +581,101 @@ static ssize_t dev_show_rev(struct device *dev,
560} 581}
561DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL); 582DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL);
562 583
584static ssize_t cciss_show_lunid(struct device *dev,
585 struct device_attribute *attr, char *buf)
586{
587 drive_info_struct *drv = to_drv(dev);
588 struct ctlr_info *h = to_hba(drv->dev.parent);
589 unsigned long flags;
590 unsigned char lunid[8];
591
592 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
593 if (h->busy_configuring) {
594 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
595 return -EBUSY;
596 }
597 if (!drv->heads) {
598 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
599 return -ENOTTY;
600 }
601 memcpy(lunid, drv->LunID, sizeof(lunid));
602 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
603 return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
604 lunid[0], lunid[1], lunid[2], lunid[3],
605 lunid[4], lunid[5], lunid[6], lunid[7]);
606}
607DEVICE_ATTR(lunid, S_IRUGO, cciss_show_lunid, NULL);
608
609static ssize_t cciss_show_raid_level(struct device *dev,
610 struct device_attribute *attr, char *buf)
611{
612 drive_info_struct *drv = to_drv(dev);
613 struct ctlr_info *h = to_hba(drv->dev.parent);
614 int raid;
615 unsigned long flags;
616
617 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
618 if (h->busy_configuring) {
619 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
620 return -EBUSY;
621 }
622 raid = drv->raid_level;
623 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
624 if (raid < 0 || raid > RAID_UNKNOWN)
625 raid = RAID_UNKNOWN;
626
627 return snprintf(buf, strlen(raid_label[raid]) + 7, "RAID %s\n",
628 raid_label[raid]);
629}
630DEVICE_ATTR(raid_level, S_IRUGO, cciss_show_raid_level, NULL);
631
632static ssize_t cciss_show_usage_count(struct device *dev,
633 struct device_attribute *attr, char *buf)
634{
635 drive_info_struct *drv = to_drv(dev);
636 struct ctlr_info *h = to_hba(drv->dev.parent);
637 unsigned long flags;
638 int count;
639
640 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
641 if (h->busy_configuring) {
642 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
643 return -EBUSY;
644 }
645 count = drv->usage_count;
646 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
647 return snprintf(buf, 20, "%d\n", count);
648}
649DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL);
650
651static struct attribute *cciss_host_attrs[] = {
652 &dev_attr_rescan.attr,
653 NULL
654};
655
656static struct attribute_group cciss_host_attr_group = {
657 .attrs = cciss_host_attrs,
658};
659
660static const struct attribute_group *cciss_host_attr_groups[] = {
661 &cciss_host_attr_group,
662 NULL
663};
664
665static struct device_type cciss_host_type = {
666 .name = "cciss_host",
667 .groups = cciss_host_attr_groups,
668 .release = cciss_hba_release,
669};
670
563static struct attribute *cciss_dev_attrs[] = { 671static struct attribute *cciss_dev_attrs[] = {
564 &dev_attr_unique_id.attr, 672 &dev_attr_unique_id.attr,
565 &dev_attr_model.attr, 673 &dev_attr_model.attr,
566 &dev_attr_vendor.attr, 674 &dev_attr_vendor.attr,
567 &dev_attr_rev.attr, 675 &dev_attr_rev.attr,
676 &dev_attr_lunid.attr,
677 &dev_attr_raid_level.attr,
678 &dev_attr_usage_count.attr,
568 NULL 679 NULL
569}; 680};
570 681
@@ -580,12 +691,24 @@ static const struct attribute_group *cciss_dev_attr_groups[] = {
580static struct device_type cciss_dev_type = { 691static struct device_type cciss_dev_type = {
581 .name = "cciss_device", 692 .name = "cciss_device",
582 .groups = cciss_dev_attr_groups, 693 .groups = cciss_dev_attr_groups,
694 .release = cciss_device_release,
583}; 695};
584 696
585static struct bus_type cciss_bus_type = { 697static struct bus_type cciss_bus_type = {
586 .name = "cciss", 698 .name = "cciss",
587}; 699};
588 700
701/*
702 * cciss_hba_release is called when the reference count
703 * of h->dev goes to zero.
704 */
705static void cciss_hba_release(struct device *dev)
706{
707 /*
708 * nothing to do, but need this to avoid a warning
709 * about not having a release handler from lib/kref.c.
710 */
711}
589 712
590/* 713/*
591 * Initialize sysfs entry for each controller. This sets up and registers 714 * Initialize sysfs entry for each controller. This sets up and registers
@@ -609,6 +732,16 @@ static int cciss_create_hba_sysfs_entry(struct ctlr_info *h)
609static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h) 732static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h)
610{ 733{
611 device_del(&h->dev); 734 device_del(&h->dev);
735 put_device(&h->dev); /* final put. */
736}
737
738/* cciss_device_release is called when the reference count
739 * of h->drv[x]dev goes to zero.
740 */
741static void cciss_device_release(struct device *dev)
742{
743 drive_info_struct *drv = to_drv(dev);
744 kfree(drv);
612} 745}
613 746
614/* 747/*
@@ -617,24 +750,39 @@ static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h)
617 * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from 750 * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from
618 * /sys/block/cciss!c#d# to this entry. 751 * /sys/block/cciss!c#d# to this entry.
619 */ 752 */
620static int cciss_create_ld_sysfs_entry(struct ctlr_info *h, 753static long cciss_create_ld_sysfs_entry(struct ctlr_info *h,
621 drive_info_struct *drv,
622 int drv_index) 754 int drv_index)
623{ 755{
624 device_initialize(&drv->dev); 756 struct device *dev;
625 drv->dev.type = &cciss_dev_type; 757
626 drv->dev.bus = &cciss_bus_type; 758 if (h->drv[drv_index]->device_initialized)
627 dev_set_name(&drv->dev, "c%dd%d", h->ctlr, drv_index); 759 return 0;
628 drv->dev.parent = &h->dev; 760
629 return device_add(&drv->dev); 761 dev = &h->drv[drv_index]->dev;
762 device_initialize(dev);
763 dev->type = &cciss_dev_type;
764 dev->bus = &cciss_bus_type;
765 dev_set_name(dev, "c%dd%d", h->ctlr, drv_index);
766 dev->parent = &h->dev;
767 h->drv[drv_index]->device_initialized = 1;
768 return device_add(dev);
630} 769}
631 770
632/* 771/*
633 * Remove sysfs entries for a logical drive. 772 * Remove sysfs entries for a logical drive.
634 */ 773 */
635static void cciss_destroy_ld_sysfs_entry(drive_info_struct *drv) 774static void cciss_destroy_ld_sysfs_entry(struct ctlr_info *h, int drv_index,
775 int ctlr_exiting)
636{ 776{
637 device_del(&drv->dev); 777 struct device *dev = &h->drv[drv_index]->dev;
778
779 /* special case for c*d0, we only destroy it on controller exit */
780 if (drv_index == 0 && !ctlr_exiting)
781 return;
782
783 device_del(dev);
784 put_device(dev); /* the "final" put. */
785 h->drv[drv_index] = NULL;
638} 786}
639 787
640/* 788/*
@@ -751,7 +899,7 @@ static int cciss_open(struct block_device *bdev, fmode_t mode)
751 printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name); 899 printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name);
752#endif /* CCISS_DEBUG */ 900#endif /* CCISS_DEBUG */
753 901
754 if (host->busy_initializing || drv->busy_configuring) 902 if (drv->busy_configuring)
755 return -EBUSY; 903 return -EBUSY;
756 /* 904 /*
757 * Root is allowed to open raw volume zero even if it's not configured 905 * Root is allowed to open raw volume zero even if it's not configured
@@ -767,7 +915,8 @@ static int cciss_open(struct block_device *bdev, fmode_t mode)
767 if (MINOR(bdev->bd_dev) & 0x0f) { 915 if (MINOR(bdev->bd_dev) & 0x0f) {
768 return -ENXIO; 916 return -ENXIO;
769 /* if it is, make sure we have a LUN ID */ 917 /* if it is, make sure we have a LUN ID */
770 } else if (drv->LunID == 0) { 918 } else if (memcmp(drv->LunID, CTLR_LUNID,
919 sizeof(drv->LunID))) {
771 return -ENXIO; 920 return -ENXIO;
772 } 921 }
773 } 922 }
@@ -1132,12 +1281,13 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1132 case CCISS_DEREGDISK: 1281 case CCISS_DEREGDISK:
1133 case CCISS_REGNEWD: 1282 case CCISS_REGNEWD:
1134 case CCISS_REVALIDVOLS: 1283 case CCISS_REVALIDVOLS:
1135 return rebuild_lun_table(host, 0); 1284 return rebuild_lun_table(host, 0, 1);
1136 1285
1137 case CCISS_GETLUNINFO:{ 1286 case CCISS_GETLUNINFO:{
1138 LogvolInfo_struct luninfo; 1287 LogvolInfo_struct luninfo;
1139 1288
1140 luninfo.LunID = drv->LunID; 1289 memcpy(&luninfo.LunID, drv->LunID,
1290 sizeof(luninfo.LunID));
1141 luninfo.num_opens = drv->usage_count; 1291 luninfo.num_opens = drv->usage_count;
1142 luninfo.num_parts = 0; 1292 luninfo.num_parts = 0;
1143 if (copy_to_user(argp, &luninfo, 1293 if (copy_to_user(argp, &luninfo,
@@ -1475,7 +1625,10 @@ static void cciss_check_queues(ctlr_info_t *h)
1475 /* make sure the disk has been added and the drive is real 1625 /* make sure the disk has been added and the drive is real
1476 * because this can be called from the middle of init_one. 1626 * because this can be called from the middle of init_one.
1477 */ 1627 */
1478 if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads)) 1628 if (!h->drv[curr_queue])
1629 continue;
1630 if (!(h->drv[curr_queue]->queue) ||
1631 !(h->drv[curr_queue]->heads))
1479 continue; 1632 continue;
1480 blk_start_queue(h->gendisk[curr_queue]->queue); 1633 blk_start_queue(h->gendisk[curr_queue]->queue);
1481 1634
@@ -1532,13 +1685,11 @@ static void cciss_softirq_done(struct request *rq)
1532 spin_unlock_irqrestore(&h->lock, flags); 1685 spin_unlock_irqrestore(&h->lock, flags);
1533} 1686}
1534 1687
1535static void log_unit_to_scsi3addr(ctlr_info_t *h, unsigned char scsi3addr[], 1688static inline void log_unit_to_scsi3addr(ctlr_info_t *h,
1536 uint32_t log_unit) 1689 unsigned char scsi3addr[], uint32_t log_unit)
1537{ 1690{
1538 log_unit = h->drv[log_unit].LunID & 0x03fff; 1691 memcpy(scsi3addr, h->drv[log_unit]->LunID,
1539 memset(&scsi3addr[4], 0, 4); 1692 sizeof(h->drv[log_unit]->LunID));
1540 memcpy(&scsi3addr[0], &log_unit, 4);
1541 scsi3addr[3] |= 0x40;
1542} 1693}
1543 1694
1544/* This function gets the SCSI vendor, model, and revision of a logical drive 1695/* This function gets the SCSI vendor, model, and revision of a logical drive
@@ -1615,16 +1766,23 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1615 return; 1766 return;
1616} 1767}
1617 1768
1618static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk, 1769/*
1770 * cciss_add_disk sets up the block device queue for a logical drive
1771 */
1772static int cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1619 int drv_index) 1773 int drv_index)
1620{ 1774{
1621 disk->queue = blk_init_queue(do_cciss_request, &h->lock); 1775 disk->queue = blk_init_queue(do_cciss_request, &h->lock);
1776 if (!disk->queue)
1777 goto init_queue_failure;
1622 sprintf(disk->disk_name, "cciss/c%dd%d", h->ctlr, drv_index); 1778 sprintf(disk->disk_name, "cciss/c%dd%d", h->ctlr, drv_index);
1623 disk->major = h->major; 1779 disk->major = h->major;
1624 disk->first_minor = drv_index << NWD_SHIFT; 1780 disk->first_minor = drv_index << NWD_SHIFT;
1625 disk->fops = &cciss_fops; 1781 disk->fops = &cciss_fops;
1626 disk->private_data = &h->drv[drv_index]; 1782 if (cciss_create_ld_sysfs_entry(h, drv_index))
1627 disk->driverfs_dev = &h->drv[drv_index].dev; 1783 goto cleanup_queue;
1784 disk->private_data = h->drv[drv_index];
1785 disk->driverfs_dev = &h->drv[drv_index]->dev;
1628 1786
1629 /* Set up queue information */ 1787 /* Set up queue information */
1630 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); 1788 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask);
@@ -1642,14 +1800,21 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1642 disk->queue->queuedata = h; 1800 disk->queue->queuedata = h;
1643 1801
1644 blk_queue_logical_block_size(disk->queue, 1802 blk_queue_logical_block_size(disk->queue,
1645 h->drv[drv_index].block_size); 1803 h->drv[drv_index]->block_size);
1646 1804
1647 /* Make sure all queue data is written out before */ 1805 /* Make sure all queue data is written out before */
1648 /* setting h->drv[drv_index].queue, as setting this */ 1806 /* setting h->drv[drv_index]->queue, as setting this */
1649 /* allows the interrupt handler to start the queue */ 1807 /* allows the interrupt handler to start the queue */
1650 wmb(); 1808 wmb();
1651 h->drv[drv_index].queue = disk->queue; 1809 h->drv[drv_index]->queue = disk->queue;
1652 add_disk(disk); 1810 add_disk(disk);
1811 return 0;
1812
1813cleanup_queue:
1814 blk_cleanup_queue(disk->queue);
1815 disk->queue = NULL;
1816init_queue_failure:
1817 return -1;
1653} 1818}
1654 1819
1655/* This function will check the usage_count of the drive to be updated/added. 1820/* This function will check the usage_count of the drive to be updated/added.
@@ -1662,7 +1827,8 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1662 * is also the controller node. Any changes to disk 0 will show up on 1827 * is also the controller node. Any changes to disk 0 will show up on
1663 * the next reboot. 1828 * the next reboot.
1664 */ 1829 */
1665static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) 1830static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1831 int via_ioctl)
1666{ 1832{
1667 ctlr_info_t *h = hba[ctlr]; 1833 ctlr_info_t *h = hba[ctlr];
1668 struct gendisk *disk; 1834 struct gendisk *disk;
@@ -1672,21 +1838,13 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1672 unsigned long flags = 0; 1838 unsigned long flags = 0;
1673 int ret = 0; 1839 int ret = 0;
1674 drive_info_struct *drvinfo; 1840 drive_info_struct *drvinfo;
1675 int was_only_controller_node;
1676 1841
1677 /* Get information about the disk and modify the driver structure */ 1842 /* Get information about the disk and modify the driver structure */
1678 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 1843 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
1679 drvinfo = kmalloc(sizeof(*drvinfo), GFP_KERNEL); 1844 drvinfo = kzalloc(sizeof(*drvinfo), GFP_KERNEL);
1680 if (inq_buff == NULL || drvinfo == NULL) 1845 if (inq_buff == NULL || drvinfo == NULL)
1681 goto mem_msg; 1846 goto mem_msg;
1682 1847
1683 /* See if we're trying to update the "controller node"
1684 * this will happen the when the first logical drive gets
1685 * created by ACU.
1686 */
1687 was_only_controller_node = (drv_index == 0 &&
1688 h->drv[0].raid_level == -1);
1689
1690 /* testing to see if 16-byte CDBs are already being used */ 1848 /* testing to see if 16-byte CDBs are already being used */
1691 if (h->cciss_read == CCISS_READ_16) { 1849 if (h->cciss_read == CCISS_READ_16) {
1692 cciss_read_capacity_16(h->ctlr, drv_index, 1, 1850 cciss_read_capacity_16(h->ctlr, drv_index, 1,
@@ -1719,16 +1877,19 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1719 drvinfo->model, drvinfo->rev); 1877 drvinfo->model, drvinfo->rev);
1720 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no, 1878 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no,
1721 sizeof(drvinfo->serial_no)); 1879 sizeof(drvinfo->serial_no));
1880 /* Save the lunid in case we deregister the disk, below. */
1881 memcpy(drvinfo->LunID, h->drv[drv_index]->LunID,
1882 sizeof(drvinfo->LunID));
1722 1883
1723 /* Is it the same disk we already know, and nothing's changed? */ 1884 /* Is it the same disk we already know, and nothing's changed? */
1724 if (h->drv[drv_index].raid_level != -1 && 1885 if (h->drv[drv_index]->raid_level != -1 &&
1725 ((memcmp(drvinfo->serial_no, 1886 ((memcmp(drvinfo->serial_no,
1726 h->drv[drv_index].serial_no, 16) == 0) && 1887 h->drv[drv_index]->serial_no, 16) == 0) &&
1727 drvinfo->block_size == h->drv[drv_index].block_size && 1888 drvinfo->block_size == h->drv[drv_index]->block_size &&
1728 drvinfo->nr_blocks == h->drv[drv_index].nr_blocks && 1889 drvinfo->nr_blocks == h->drv[drv_index]->nr_blocks &&
1729 drvinfo->heads == h->drv[drv_index].heads && 1890 drvinfo->heads == h->drv[drv_index]->heads &&
1730 drvinfo->sectors == h->drv[drv_index].sectors && 1891 drvinfo->sectors == h->drv[drv_index]->sectors &&
1731 drvinfo->cylinders == h->drv[drv_index].cylinders)) 1892 drvinfo->cylinders == h->drv[drv_index]->cylinders))
1732 /* The disk is unchanged, nothing to update */ 1893 /* The disk is unchanged, nothing to update */
1733 goto freeret; 1894 goto freeret;
1734 1895
@@ -1738,18 +1899,17 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1738 * If the disk already exists then deregister it before proceeding 1899 * If the disk already exists then deregister it before proceeding
1739 * (unless it's the first disk (for the controller node). 1900 * (unless it's the first disk (for the controller node).
1740 */ 1901 */
1741 if (h->drv[drv_index].raid_level != -1 && drv_index != 0) { 1902 if (h->drv[drv_index]->raid_level != -1 && drv_index != 0) {
1742 printk(KERN_WARNING "disk %d has changed.\n", drv_index); 1903 printk(KERN_WARNING "disk %d has changed.\n", drv_index);
1743 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 1904 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
1744 h->drv[drv_index].busy_configuring = 1; 1905 h->drv[drv_index]->busy_configuring = 1;
1745 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 1906 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
1746 1907
1747 /* deregister_disk sets h->drv[drv_index].queue = NULL 1908 /* deregister_disk sets h->drv[drv_index]->queue = NULL
1748 * which keeps the interrupt handler from starting 1909 * which keeps the interrupt handler from starting
1749 * the queue. 1910 * the queue.
1750 */ 1911 */
1751 ret = deregister_disk(h, drv_index, 0); 1912 ret = deregister_disk(h, drv_index, 0, via_ioctl);
1752 h->drv[drv_index].busy_configuring = 0;
1753 } 1913 }
1754 1914
1755 /* If the disk is in use return */ 1915 /* If the disk is in use return */
@@ -1757,22 +1917,31 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1757 goto freeret; 1917 goto freeret;
1758 1918
1759 /* Save the new information from cciss_geometry_inquiry 1919 /* Save the new information from cciss_geometry_inquiry
1760 * and serial number inquiry. 1920 * and serial number inquiry. If the disk was deregistered
1921 * above, then h->drv[drv_index] will be NULL.
1761 */ 1922 */
1762 h->drv[drv_index].block_size = drvinfo->block_size; 1923 if (h->drv[drv_index] == NULL) {
1763 h->drv[drv_index].nr_blocks = drvinfo->nr_blocks; 1924 drvinfo->device_initialized = 0;
1764 h->drv[drv_index].heads = drvinfo->heads; 1925 h->drv[drv_index] = drvinfo;
1765 h->drv[drv_index].sectors = drvinfo->sectors; 1926 drvinfo = NULL; /* so it won't be freed below. */
1766 h->drv[drv_index].cylinders = drvinfo->cylinders; 1927 } else {
1767 h->drv[drv_index].raid_level = drvinfo->raid_level; 1928 /* special case for cxd0 */
1768 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16); 1929 h->drv[drv_index]->block_size = drvinfo->block_size;
1769 memcpy(h->drv[drv_index].vendor, drvinfo->vendor, VENDOR_LEN + 1); 1930 h->drv[drv_index]->nr_blocks = drvinfo->nr_blocks;
1770 memcpy(h->drv[drv_index].model, drvinfo->model, MODEL_LEN + 1); 1931 h->drv[drv_index]->heads = drvinfo->heads;
1771 memcpy(h->drv[drv_index].rev, drvinfo->rev, REV_LEN + 1); 1932 h->drv[drv_index]->sectors = drvinfo->sectors;
1933 h->drv[drv_index]->cylinders = drvinfo->cylinders;
1934 h->drv[drv_index]->raid_level = drvinfo->raid_level;
1935 memcpy(h->drv[drv_index]->serial_no, drvinfo->serial_no, 16);
1936 memcpy(h->drv[drv_index]->vendor, drvinfo->vendor,
1937 VENDOR_LEN + 1);
1938 memcpy(h->drv[drv_index]->model, drvinfo->model, MODEL_LEN + 1);
1939 memcpy(h->drv[drv_index]->rev, drvinfo->rev, REV_LEN + 1);
1940 }
1772 1941
1773 ++h->num_luns; 1942 ++h->num_luns;
1774 disk = h->gendisk[drv_index]; 1943 disk = h->gendisk[drv_index];
1775 set_capacity(disk, h->drv[drv_index].nr_blocks); 1944 set_capacity(disk, h->drv[drv_index]->nr_blocks);
1776 1945
1777 /* If it's not disk 0 (drv_index != 0) 1946 /* If it's not disk 0 (drv_index != 0)
1778 * or if it was disk 0, but there was previously 1947 * or if it was disk 0, but there was previously
@@ -1780,8 +1949,15 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1780 * (raid_leve == -1) then we want to update the 1949 * (raid_leve == -1) then we want to update the
1781 * logical drive's information. 1950 * logical drive's information.
1782 */ 1951 */
1783 if (drv_index || first_time) 1952 if (drv_index || first_time) {
1784 cciss_add_disk(h, disk, drv_index); 1953 if (cciss_add_disk(h, disk, drv_index) != 0) {
1954 cciss_free_gendisk(h, drv_index);
1955 cciss_free_drive_info(h, drv_index);
1956 printk(KERN_WARNING "cciss:%d could not update "
1957 "disk %d\n", h->ctlr, drv_index);
1958 --h->num_luns;
1959 }
1960 }
1785 1961
1786freeret: 1962freeret:
1787 kfree(inq_buff); 1963 kfree(inq_buff);
@@ -1793,28 +1969,70 @@ mem_msg:
1793} 1969}
1794 1970
1795/* This function will find the first index of the controllers drive array 1971/* This function will find the first index of the controllers drive array
1796 * that has a -1 for the raid_level and will return that index. This is 1972 * that has a null drv pointer and allocate the drive info struct and
1797 * where new drives will be added. If the index to be returned is greater 1973 * will return that index This is where new drives will be added.
1798 * than the highest_lun index for the controller then highest_lun is set 1974 * If the index to be returned is greater than the highest_lun index for
1799 * to this new index. If there are no available indexes then -1 is returned. 1975 * the controller then highest_lun is set * to this new index.
1800 * "controller_node" is used to know if this is a real logical drive, or just 1976 * If there are no available indexes or if tha allocation fails, then -1
1801 * the controller node, which determines if this counts towards highest_lun. 1977 * is returned. * "controller_node" is used to know if this is a real
1978 * logical drive, or just the controller node, which determines if this
1979 * counts towards highest_lun.
1802 */ 1980 */
1803static int cciss_find_free_drive_index(int ctlr, int controller_node) 1981static int cciss_alloc_drive_info(ctlr_info_t *h, int controller_node)
1804{ 1982{
1805 int i; 1983 int i;
1984 drive_info_struct *drv;
1806 1985
1986 /* Search for an empty slot for our drive info */
1807 for (i = 0; i < CISS_MAX_LUN; i++) { 1987 for (i = 0; i < CISS_MAX_LUN; i++) {
1808 if (hba[ctlr]->drv[i].raid_level == -1) { 1988
1809 if (i > hba[ctlr]->highest_lun) 1989 /* if not cxd0 case, and it's occupied, skip it. */
1810 if (!controller_node) 1990 if (h->drv[i] && i != 0)
1811 hba[ctlr]->highest_lun = i; 1991 continue;
1992 /*
1993 * If it's cxd0 case, and drv is alloc'ed already, and a
1994 * disk is configured there, skip it.
1995 */
1996 if (i == 0 && h->drv[i] && h->drv[i]->raid_level != -1)
1997 continue;
1998
1999 /*
2000 * We've found an empty slot. Update highest_lun
2001 * provided this isn't just the fake cxd0 controller node.
2002 */
2003 if (i > h->highest_lun && !controller_node)
2004 h->highest_lun = i;
2005
2006 /* If adding a real disk at cxd0, and it's already alloc'ed */
2007 if (i == 0 && h->drv[i] != NULL)
1812 return i; 2008 return i;
1813 } 2009
2010 /*
2011 * Found an empty slot, not already alloc'ed. Allocate it.
2012 * Mark it with raid_level == -1, so we know it's new later on.
2013 */
2014 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
2015 if (!drv)
2016 return -1;
2017 drv->raid_level = -1; /* so we know it's new */
2018 h->drv[i] = drv;
2019 return i;
1814 } 2020 }
1815 return -1; 2021 return -1;
1816} 2022}
1817 2023
2024static void cciss_free_drive_info(ctlr_info_t *h, int drv_index)
2025{
2026 kfree(h->drv[drv_index]);
2027 h->drv[drv_index] = NULL;
2028}
2029
2030static void cciss_free_gendisk(ctlr_info_t *h, int drv_index)
2031{
2032 put_disk(h->gendisk[drv_index]);
2033 h->gendisk[drv_index] = NULL;
2034}
2035
1818/* cciss_add_gendisk finds a free hba[]->drv structure 2036/* cciss_add_gendisk finds a free hba[]->drv structure
1819 * and allocates a gendisk if needed, and sets the lunid 2037 * and allocates a gendisk if needed, and sets the lunid
1820 * in the drvinfo structure. It returns the index into 2038 * in the drvinfo structure. It returns the index into
@@ -1824,13 +2042,15 @@ static int cciss_find_free_drive_index(int ctlr, int controller_node)
1824 * a means to talk to the controller in case no logical 2042 * a means to talk to the controller in case no logical
1825 * drives have yet been configured. 2043 * drives have yet been configured.
1826 */ 2044 */
1827static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node) 2045static int cciss_add_gendisk(ctlr_info_t *h, unsigned char lunid[],
2046 int controller_node)
1828{ 2047{
1829 int drv_index; 2048 int drv_index;
1830 2049
1831 drv_index = cciss_find_free_drive_index(h->ctlr, controller_node); 2050 drv_index = cciss_alloc_drive_info(h, controller_node);
1832 if (drv_index == -1) 2051 if (drv_index == -1)
1833 return -1; 2052 return -1;
2053
1834 /*Check if the gendisk needs to be allocated */ 2054 /*Check if the gendisk needs to be allocated */
1835 if (!h->gendisk[drv_index]) { 2055 if (!h->gendisk[drv_index]) {
1836 h->gendisk[drv_index] = 2056 h->gendisk[drv_index] =
@@ -1839,23 +2059,24 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1839 printk(KERN_ERR "cciss%d: could not " 2059 printk(KERN_ERR "cciss%d: could not "
1840 "allocate a new disk %d\n", 2060 "allocate a new disk %d\n",
1841 h->ctlr, drv_index); 2061 h->ctlr, drv_index);
1842 return -1; 2062 goto err_free_drive_info;
1843 } 2063 }
1844 } 2064 }
1845 h->drv[drv_index].LunID = lunid; 2065 memcpy(h->drv[drv_index]->LunID, lunid,
1846 if (cciss_create_ld_sysfs_entry(h, &h->drv[drv_index], drv_index)) 2066 sizeof(h->drv[drv_index]->LunID));
2067 if (cciss_create_ld_sysfs_entry(h, drv_index))
1847 goto err_free_disk; 2068 goto err_free_disk;
1848
1849 /* Don't need to mark this busy because nobody */ 2069 /* Don't need to mark this busy because nobody */
1850 /* else knows about this disk yet to contend */ 2070 /* else knows about this disk yet to contend */
1851 /* for access to it. */ 2071 /* for access to it. */
1852 h->drv[drv_index].busy_configuring = 0; 2072 h->drv[drv_index]->busy_configuring = 0;
1853 wmb(); 2073 wmb();
1854 return drv_index; 2074 return drv_index;
1855 2075
1856err_free_disk: 2076err_free_disk:
1857 put_disk(h->gendisk[drv_index]); 2077 cciss_free_gendisk(h, drv_index);
1858 h->gendisk[drv_index] = NULL; 2078err_free_drive_info:
2079 cciss_free_drive_info(h, drv_index);
1859 return -1; 2080 return -1;
1860} 2081}
1861 2082
@@ -1872,21 +2093,25 @@ static void cciss_add_controller_node(ctlr_info_t *h)
1872 if (h->gendisk[0] != NULL) /* already did this? Then bail. */ 2093 if (h->gendisk[0] != NULL) /* already did this? Then bail. */
1873 return; 2094 return;
1874 2095
1875 drv_index = cciss_add_gendisk(h, 0, 1); 2096 drv_index = cciss_add_gendisk(h, CTLR_LUNID, 1);
1876 if (drv_index == -1) { 2097 if (drv_index == -1)
1877 printk(KERN_WARNING "cciss%d: could not " 2098 goto error;
1878 "add disk 0.\n", h->ctlr); 2099 h->drv[drv_index]->block_size = 512;
1879 return; 2100 h->drv[drv_index]->nr_blocks = 0;
1880 } 2101 h->drv[drv_index]->heads = 0;
1881 h->drv[drv_index].block_size = 512; 2102 h->drv[drv_index]->sectors = 0;
1882 h->drv[drv_index].nr_blocks = 0; 2103 h->drv[drv_index]->cylinders = 0;
1883 h->drv[drv_index].heads = 0; 2104 h->drv[drv_index]->raid_level = -1;
1884 h->drv[drv_index].sectors = 0; 2105 memset(h->drv[drv_index]->serial_no, 0, 16);
1885 h->drv[drv_index].cylinders = 0;
1886 h->drv[drv_index].raid_level = -1;
1887 memset(h->drv[drv_index].serial_no, 0, 16);
1888 disk = h->gendisk[drv_index]; 2106 disk = h->gendisk[drv_index];
1889 cciss_add_disk(h, disk, drv_index); 2107 if (cciss_add_disk(h, disk, drv_index) == 0)
2108 return;
2109 cciss_free_gendisk(h, drv_index);
2110 cciss_free_drive_info(h, drv_index);
2111error:
2112 printk(KERN_WARNING "cciss%d: could not "
2113 "add disk 0.\n", h->ctlr);
2114 return;
1890} 2115}
1891 2116
1892/* This function will add and remove logical drives from the Logical 2117/* This function will add and remove logical drives from the Logical
@@ -1897,7 +2122,8 @@ static void cciss_add_controller_node(ctlr_info_t *h)
1897 * INPUT 2122 * INPUT
1898 * h = The controller to perform the operations on 2123 * h = The controller to perform the operations on
1899 */ 2124 */
1900static int rebuild_lun_table(ctlr_info_t *h, int first_time) 2125static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2126 int via_ioctl)
1901{ 2127{
1902 int ctlr = h->ctlr; 2128 int ctlr = h->ctlr;
1903 int num_luns; 2129 int num_luns;
@@ -1907,7 +2133,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1907 int i; 2133 int i;
1908 int drv_found; 2134 int drv_found;
1909 int drv_index = 0; 2135 int drv_index = 0;
1910 __u32 lunid = 0; 2136 unsigned char lunid[8] = CTLR_LUNID;
1911 unsigned long flags; 2137 unsigned long flags;
1912 2138
1913 if (!capable(CAP_SYS_RAWIO)) 2139 if (!capable(CAP_SYS_RAWIO))
@@ -1960,13 +2186,13 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1960 drv_found = 0; 2186 drv_found = 0;
1961 2187
1962 /* skip holes in the array from already deleted drives */ 2188 /* skip holes in the array from already deleted drives */
1963 if (h->drv[i].raid_level == -1) 2189 if (h->drv[i] == NULL)
1964 continue; 2190 continue;
1965 2191
1966 for (j = 0; j < num_luns; j++) { 2192 for (j = 0; j < num_luns; j++) {
1967 memcpy(&lunid, &ld_buff->LUN[j][0], 4); 2193 memcpy(lunid, &ld_buff->LUN[j][0], sizeof(lunid));
1968 lunid = le32_to_cpu(lunid); 2194 if (memcmp(h->drv[i]->LunID, lunid,
1969 if (h->drv[i].LunID == lunid) { 2195 sizeof(lunid)) == 0) {
1970 drv_found = 1; 2196 drv_found = 1;
1971 break; 2197 break;
1972 } 2198 }
@@ -1974,11 +2200,11 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1974 if (!drv_found) { 2200 if (!drv_found) {
1975 /* Deregister it from the OS, it's gone. */ 2201 /* Deregister it from the OS, it's gone. */
1976 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2202 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
1977 h->drv[i].busy_configuring = 1; 2203 h->drv[i]->busy_configuring = 1;
1978 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2204 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
1979 return_code = deregister_disk(h, i, 1); 2205 return_code = deregister_disk(h, i, 1, via_ioctl);
1980 cciss_destroy_ld_sysfs_entry(&h->drv[i]); 2206 if (h->drv[i] != NULL)
1981 h->drv[i].busy_configuring = 0; 2207 h->drv[i]->busy_configuring = 0;
1982 } 2208 }
1983 } 2209 }
1984 2210
@@ -1992,17 +2218,16 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1992 2218
1993 drv_found = 0; 2219 drv_found = 0;
1994 2220
1995 memcpy(&lunid, &ld_buff->LUN[i][0], 4); 2221 memcpy(lunid, &ld_buff->LUN[i][0], sizeof(lunid));
1996 lunid = le32_to_cpu(lunid);
1997
1998 /* Find if the LUN is already in the drive array 2222 /* Find if the LUN is already in the drive array
1999 * of the driver. If so then update its info 2223 * of the driver. If so then update its info
2000 * if not in use. If it does not exist then find 2224 * if not in use. If it does not exist then find
2001 * the first free index and add it. 2225 * the first free index and add it.
2002 */ 2226 */
2003 for (j = 0; j <= h->highest_lun; j++) { 2227 for (j = 0; j <= h->highest_lun; j++) {
2004 if (h->drv[j].raid_level != -1 && 2228 if (h->drv[j] != NULL &&
2005 h->drv[j].LunID == lunid) { 2229 memcmp(h->drv[j]->LunID, lunid,
2230 sizeof(h->drv[j]->LunID)) == 0) {
2006 drv_index = j; 2231 drv_index = j;
2007 drv_found = 1; 2232 drv_found = 1;
2008 break; 2233 break;
@@ -2015,7 +2240,8 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
2015 if (drv_index == -1) 2240 if (drv_index == -1)
2016 goto freeret; 2241 goto freeret;
2017 } 2242 }
2018 cciss_update_drive_info(ctlr, drv_index, first_time); 2243 cciss_update_drive_info(ctlr, drv_index, first_time,
2244 via_ioctl);
2019 } /* end for */ 2245 } /* end for */
2020 2246
2021freeret: 2247freeret:
@@ -2032,6 +2258,25 @@ mem_msg:
2032 goto freeret; 2258 goto freeret;
2033} 2259}
2034 2260
2261static void cciss_clear_drive_info(drive_info_struct *drive_info)
2262{
2263 /* zero out the disk size info */
2264 drive_info->nr_blocks = 0;
2265 drive_info->block_size = 0;
2266 drive_info->heads = 0;
2267 drive_info->sectors = 0;
2268 drive_info->cylinders = 0;
2269 drive_info->raid_level = -1;
2270 memset(drive_info->serial_no, 0, sizeof(drive_info->serial_no));
2271 memset(drive_info->model, 0, sizeof(drive_info->model));
2272 memset(drive_info->rev, 0, sizeof(drive_info->rev));
2273 memset(drive_info->vendor, 0, sizeof(drive_info->vendor));
2274 /*
2275 * don't clear the LUNID though, we need to remember which
2276 * one this one is.
2277 */
2278}
2279
2035/* This function will deregister the disk and it's queue from the 2280/* This function will deregister the disk and it's queue from the
2036 * kernel. It must be called with the controller lock held and the 2281 * kernel. It must be called with the controller lock held and the
2037 * drv structures busy_configuring flag set. It's parameters are: 2282 * drv structures busy_configuring flag set. It's parameters are:
@@ -2046,43 +2291,48 @@ mem_msg:
2046 * the disk in preparation for re-adding it. In this case 2291 * the disk in preparation for re-adding it. In this case
2047 * the highest_lun should be left unchanged and the LunID 2292 * the highest_lun should be left unchanged and the LunID
2048 * should not be cleared. 2293 * should not be cleared.
2294 * via_ioctl
2295 * This indicates whether we've reached this path via ioctl.
2296 * This affects the maximum usage count allowed for c0d0 to be messed with.
2297 * If this path is reached via ioctl(), then the max_usage_count will
2298 * be 1, as the process calling ioctl() has got to have the device open.
2299 * If we get here via sysfs, then the max usage count will be zero.
2049*/ 2300*/
2050static int deregister_disk(ctlr_info_t *h, int drv_index, 2301static int deregister_disk(ctlr_info_t *h, int drv_index,
2051 int clear_all) 2302 int clear_all, int via_ioctl)
2052{ 2303{
2053 int i; 2304 int i;
2054 struct gendisk *disk; 2305 struct gendisk *disk;
2055 drive_info_struct *drv; 2306 drive_info_struct *drv;
2307 int recalculate_highest_lun;
2056 2308
2057 if (!capable(CAP_SYS_RAWIO)) 2309 if (!capable(CAP_SYS_RAWIO))
2058 return -EPERM; 2310 return -EPERM;
2059 2311
2060 drv = &h->drv[drv_index]; 2312 drv = h->drv[drv_index];
2061 disk = h->gendisk[drv_index]; 2313 disk = h->gendisk[drv_index];
2062 2314
2063 /* make sure logical volume is NOT is use */ 2315 /* make sure logical volume is NOT is use */
2064 if (clear_all || (h->gendisk[0] == disk)) { 2316 if (clear_all || (h->gendisk[0] == disk)) {
2065 if (drv->usage_count > 1) 2317 if (drv->usage_count > via_ioctl)
2066 return -EBUSY; 2318 return -EBUSY;
2067 } else if (drv->usage_count > 0) 2319 } else if (drv->usage_count > 0)
2068 return -EBUSY; 2320 return -EBUSY;
2069 2321
2322 recalculate_highest_lun = (drv == h->drv[h->highest_lun]);
2323
2070 /* invalidate the devices and deregister the disk. If it is disk 2324 /* invalidate the devices and deregister the disk. If it is disk
2071 * zero do not deregister it but just zero out it's values. This 2325 * zero do not deregister it but just zero out it's values. This
2072 * allows us to delete disk zero but keep the controller registered. 2326 * allows us to delete disk zero but keep the controller registered.
2073 */ 2327 */
2074 if (h->gendisk[0] != disk) { 2328 if (h->gendisk[0] != disk) {
2075 struct request_queue *q = disk->queue; 2329 struct request_queue *q = disk->queue;
2076 if (disk->flags & GENHD_FL_UP) 2330 if (disk->flags & GENHD_FL_UP) {
2331 cciss_destroy_ld_sysfs_entry(h, drv_index, 0);
2077 del_gendisk(disk); 2332 del_gendisk(disk);
2078 if (q) {
2079 blk_cleanup_queue(q);
2080 /* Set drv->queue to NULL so that we do not try
2081 * to call blk_start_queue on this queue in the
2082 * interrupt handler
2083 */
2084 drv->queue = NULL;
2085 } 2333 }
2334 if (q)
2335 blk_cleanup_queue(q);
2086 /* If clear_all is set then we are deleting the logical 2336 /* If clear_all is set then we are deleting the logical
2087 * drive, not just refreshing its info. For drives 2337 * drive, not just refreshing its info. For drives
2088 * other than disk 0 we will call put_disk. We do not 2338 * other than disk 0 we will call put_disk. We do not
@@ -2105,34 +2355,20 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
2105 } 2355 }
2106 } else { 2356 } else {
2107 set_capacity(disk, 0); 2357 set_capacity(disk, 0);
2358 cciss_clear_drive_info(drv);
2108 } 2359 }
2109 2360
2110 --h->num_luns; 2361 --h->num_luns;
2111 /* zero out the disk size info */
2112 drv->nr_blocks = 0;
2113 drv->block_size = 0;
2114 drv->heads = 0;
2115 drv->sectors = 0;
2116 drv->cylinders = 0;
2117 drv->raid_level = -1; /* This can be used as a flag variable to
2118 * indicate that this element of the drive
2119 * array is free.
2120 */
2121
2122 if (clear_all) {
2123 /* check to see if it was the last disk */
2124 if (drv == h->drv + h->highest_lun) {
2125 /* if so, find the new hightest lun */
2126 int i, newhighest = -1;
2127 for (i = 0; i <= h->highest_lun; i++) {
2128 /* if the disk has size > 0, it is available */
2129 if (h->drv[i].heads)
2130 newhighest = i;
2131 }
2132 h->highest_lun = newhighest;
2133 }
2134 2362
2135 drv->LunID = 0; 2363 /* if it was the last disk, find the new hightest lun */
2364 if (clear_all && recalculate_highest_lun) {
2365 int i, newhighest = -1;
2366 for (i = 0; i <= h->highest_lun; i++) {
2367 /* if the disk has size > 0, it is available */
2368 if (h->drv[i] && h->drv[i]->heads)
2369 newhighest = i;
2370 }
2371 h->highest_lun = newhighest;
2136 } 2372 }
2137 return 0; 2373 return 0;
2138} 2374}
@@ -2479,8 +2715,6 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2479 } else { /* Get geometry failed */ 2715 } else { /* Get geometry failed */
2480 printk(KERN_WARNING "cciss: reading geometry failed\n"); 2716 printk(KERN_WARNING "cciss: reading geometry failed\n");
2481 } 2717 }
2482 printk(KERN_INFO " heads=%d, sectors=%d, cylinders=%d\n\n",
2483 drv->heads, drv->sectors, drv->cylinders);
2484} 2718}
2485 2719
2486static void 2720static void
@@ -2514,9 +2748,6 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2514 *total_size = 0; 2748 *total_size = 0;
2515 *block_size = BLOCK_SIZE; 2749 *block_size = BLOCK_SIZE;
2516 } 2750 }
2517 if (*total_size != 0)
2518 printk(KERN_INFO " blocks= %llu block_size= %d\n",
2519 (unsigned long long)*total_size+1, *block_size);
2520 kfree(buf); 2751 kfree(buf);
2521} 2752}
2522 2753
@@ -2568,7 +2799,8 @@ static int cciss_revalidate(struct gendisk *disk)
2568 InquiryData_struct *inq_buff = NULL; 2799 InquiryData_struct *inq_buff = NULL;
2569 2800
2570 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) { 2801 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) {
2571 if (h->drv[logvol].LunID == drv->LunID) { 2802 if (memcmp(h->drv[logvol]->LunID, drv->LunID,
2803 sizeof(drv->LunID)) == 0) {
2572 FOUND = 1; 2804 FOUND = 1;
2573 break; 2805 break;
2574 } 2806 }
@@ -3053,8 +3285,7 @@ static void do_cciss_request(struct request_queue *q)
3053 /* The first 2 bits are reserved for controller error reporting. */ 3285 /* The first 2 bits are reserved for controller error reporting. */
3054 c->Header.Tag.lower = (c->cmdindex << 3); 3286 c->Header.Tag.lower = (c->cmdindex << 3);
3055 c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */ 3287 c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */
3056 c->Header.LUN.LogDev.VolId = drv->LunID; 3288 memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID));
3057 c->Header.LUN.LogDev.Mode = 1;
3058 c->Request.CDBLen = 10; // 12 byte commands not in FW yet; 3289 c->Request.CDBLen = 10; // 12 byte commands not in FW yet;
3059 c->Request.Type.Type = TYPE_CMD; // It is a command. 3290 c->Request.Type.Type = TYPE_CMD; // It is a command.
3060 c->Request.Type.Attribute = ATTR_SIMPLE; 3291 c->Request.Type.Attribute = ATTR_SIMPLE;
@@ -3232,20 +3463,121 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id)
3232 return IRQ_HANDLED; 3463 return IRQ_HANDLED;
3233} 3464}
3234 3465
3466/**
3467 * add_to_scan_list() - add controller to rescan queue
3468 * @h: Pointer to the controller.
3469 *
3470 * Adds the controller to the rescan queue if not already on the queue.
3471 *
3472 * returns 1 if added to the queue, 0 if skipped (could be on the
3473 * queue already, or the controller could be initializing or shutting
3474 * down).
3475 **/
3476static int add_to_scan_list(struct ctlr_info *h)
3477{
3478 struct ctlr_info *test_h;
3479 int found = 0;
3480 int ret = 0;
3481
3482 if (h->busy_initializing)
3483 return 0;
3484
3485 if (!mutex_trylock(&h->busy_shutting_down))
3486 return 0;
3487
3488 mutex_lock(&scan_mutex);
3489 list_for_each_entry(test_h, &scan_q, scan_list) {
3490 if (test_h == h) {
3491 found = 1;
3492 break;
3493 }
3494 }
3495 if (!found && !h->busy_scanning) {
3496 INIT_COMPLETION(h->scan_wait);
3497 list_add_tail(&h->scan_list, &scan_q);
3498 ret = 1;
3499 }
3500 mutex_unlock(&scan_mutex);
3501 mutex_unlock(&h->busy_shutting_down);
3502
3503 return ret;
3504}
3505
3506/**
3507 * remove_from_scan_list() - remove controller from rescan queue
3508 * @h: Pointer to the controller.
3509 *
3510 * Removes the controller from the rescan queue if present. Blocks if
3511 * the controller is currently conducting a rescan.
3512 **/
3513static void remove_from_scan_list(struct ctlr_info *h)
3514{
3515 struct ctlr_info *test_h, *tmp_h;
3516 int scanning = 0;
3517
3518 mutex_lock(&scan_mutex);
3519 list_for_each_entry_safe(test_h, tmp_h, &scan_q, scan_list) {
3520 if (test_h == h) {
3521 list_del(&h->scan_list);
3522 complete_all(&h->scan_wait);
3523 mutex_unlock(&scan_mutex);
3524 return;
3525 }
3526 }
3527 if (&h->busy_scanning)
3528 scanning = 0;
3529 mutex_unlock(&scan_mutex);
3530
3531 if (scanning)
3532 wait_for_completion(&h->scan_wait);
3533}
3534
3535/**
3536 * scan_thread() - kernel thread used to rescan controllers
3537 * @data: Ignored.
3538 *
3539 * A kernel thread used scan for drive topology changes on
3540 * controllers. The thread processes only one controller at a time
3541 * using a queue. Controllers are added to the queue using
3542 * add_to_scan_list() and removed from the queue either after done
3543 * processing or using remove_from_scan_list().
3544 *
3545 * returns 0.
3546 **/
3235static int scan_thread(void *data) 3547static int scan_thread(void *data)
3236{ 3548{
3237 ctlr_info_t *h = data; 3549 struct ctlr_info *h;
3238 int rc;
3239 DECLARE_COMPLETION_ONSTACK(wait);
3240 h->rescan_wait = &wait;
3241 3550
3242 for (;;) { 3551 while (1) {
3243 rc = wait_for_completion_interruptible(&wait); 3552 set_current_state(TASK_INTERRUPTIBLE);
3553 schedule();
3244 if (kthread_should_stop()) 3554 if (kthread_should_stop())
3245 break; 3555 break;
3246 if (!rc) 3556
3247 rebuild_lun_table(h, 0); 3557 while (1) {
3558 mutex_lock(&scan_mutex);
3559 if (list_empty(&scan_q)) {
3560 mutex_unlock(&scan_mutex);
3561 break;
3562 }
3563
3564 h = list_entry(scan_q.next,
3565 struct ctlr_info,
3566 scan_list);
3567 list_del(&h->scan_list);
3568 h->busy_scanning = 1;
3569 mutex_unlock(&scan_mutex);
3570
3571 if (h) {
3572 rebuild_lun_table(h, 0, 0);
3573 complete_all(&h->scan_wait);
3574 mutex_lock(&scan_mutex);
3575 h->busy_scanning = 0;
3576 mutex_unlock(&scan_mutex);
3577 }
3578 }
3248 } 3579 }
3580
3249 return 0; 3581 return 0;
3250} 3582}
3251 3583
@@ -3268,8 +3600,8 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3268 case REPORT_LUNS_CHANGED: 3600 case REPORT_LUNS_CHANGED:
3269 printk(KERN_WARNING "cciss%d: report LUN data " 3601 printk(KERN_WARNING "cciss%d: report LUN data "
3270 "changed\n", h->ctlr); 3602 "changed\n", h->ctlr);
3271 if (h->rescan_wait) 3603 add_to_scan_list(h);
3272 complete(h->rescan_wait); 3604 wake_up_process(cciss_scan_thread);
3273 return 1; 3605 return 1;
3274 break; 3606 break;
3275 case POWER_OR_RESET: 3607 case POWER_OR_RESET:
@@ -3489,7 +3821,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
3489 if (scratchpad == CCISS_FIRMWARE_READY) 3821 if (scratchpad == CCISS_FIRMWARE_READY)
3490 break; 3822 break;
3491 set_current_state(TASK_INTERRUPTIBLE); 3823 set_current_state(TASK_INTERRUPTIBLE);
3492 schedule_timeout(HZ / 10); /* wait 100ms */ 3824 schedule_timeout(msecs_to_jiffies(100)); /* wait 100ms */
3493 } 3825 }
3494 if (scratchpad != CCISS_FIRMWARE_READY) { 3826 if (scratchpad != CCISS_FIRMWARE_READY) {
3495 printk(KERN_WARNING "cciss: Board not ready. Timed out.\n"); 3827 printk(KERN_WARNING "cciss: Board not ready. Timed out.\n");
@@ -3615,7 +3947,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
3615 break; 3947 break;
3616 /* delay and try again */ 3948 /* delay and try again */
3617 set_current_state(TASK_INTERRUPTIBLE); 3949 set_current_state(TASK_INTERRUPTIBLE);
3618 schedule_timeout(10); 3950 schedule_timeout(msecs_to_jiffies(1));
3619 } 3951 }
3620 3952
3621#ifdef CCISS_DEBUG 3953#ifdef CCISS_DEBUG
@@ -3669,15 +4001,16 @@ Enomem:
3669 return -1; 4001 return -1;
3670} 4002}
3671 4003
3672static void free_hba(int i) 4004static void free_hba(int n)
3673{ 4005{
3674 ctlr_info_t *p = hba[i]; 4006 ctlr_info_t *h = hba[n];
3675 int n; 4007 int i;
3676 4008
3677 hba[i] = NULL; 4009 hba[n] = NULL;
3678 for (n = 0; n < CISS_MAX_LUN; n++) 4010 for (i = 0; i < h->highest_lun + 1; i++)
3679 put_disk(p->gendisk[n]); 4011 if (h->gendisk[i] != NULL)
3680 kfree(p); 4012 put_disk(h->gendisk[i]);
4013 kfree(h);
3681} 4014}
3682 4015
3683/* Send a message CDB to the firmware. */ 4016/* Send a message CDB to the firmware. */
@@ -3918,6 +4251,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3918 hba[i]->busy_initializing = 1; 4251 hba[i]->busy_initializing = 1;
3919 INIT_HLIST_HEAD(&hba[i]->cmpQ); 4252 INIT_HLIST_HEAD(&hba[i]->cmpQ);
3920 INIT_HLIST_HEAD(&hba[i]->reqQ); 4253 INIT_HLIST_HEAD(&hba[i]->reqQ);
4254 mutex_init(&hba[i]->busy_shutting_down);
3921 4255
3922 if (cciss_pci_init(hba[i], pdev) != 0) 4256 if (cciss_pci_init(hba[i], pdev) != 0)
3923 goto clean0; 4257 goto clean0;
@@ -3926,6 +4260,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3926 hba[i]->ctlr = i; 4260 hba[i]->ctlr = i;
3927 hba[i]->pdev = pdev; 4261 hba[i]->pdev = pdev;
3928 4262
4263 init_completion(&hba[i]->scan_wait);
4264
3929 if (cciss_create_hba_sysfs_entry(hba[i])) 4265 if (cciss_create_hba_sysfs_entry(hba[i]))
3930 goto clean0; 4266 goto clean0;
3931 4267
@@ -4001,8 +4337,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4001 hba[i]->num_luns = 0; 4337 hba[i]->num_luns = 0;
4002 hba[i]->highest_lun = -1; 4338 hba[i]->highest_lun = -1;
4003 for (j = 0; j < CISS_MAX_LUN; j++) { 4339 for (j = 0; j < CISS_MAX_LUN; j++) {
4004 hba[i]->drv[j].raid_level = -1; 4340 hba[i]->drv[j] = NULL;
4005 hba[i]->drv[j].queue = NULL;
4006 hba[i]->gendisk[j] = NULL; 4341 hba[i]->gendisk[j] = NULL;
4007 } 4342 }
4008 4343
@@ -4035,14 +4370,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4035 4370
4036 hba[i]->cciss_max_sectors = 2048; 4371 hba[i]->cciss_max_sectors = 2048;
4037 4372
4373 rebuild_lun_table(hba[i], 1, 0);
4038 hba[i]->busy_initializing = 0; 4374 hba[i]->busy_initializing = 0;
4039
4040 rebuild_lun_table(hba[i], 1);
4041 hba[i]->cciss_scan_thread = kthread_run(scan_thread, hba[i],
4042 "cciss_scan%02d", i);
4043 if (IS_ERR(hba[i]->cciss_scan_thread))
4044 return PTR_ERR(hba[i]->cciss_scan_thread);
4045
4046 return 1; 4375 return 1;
4047 4376
4048clean4: 4377clean4:
@@ -4063,12 +4392,7 @@ clean1:
4063 cciss_destroy_hba_sysfs_entry(hba[i]); 4392 cciss_destroy_hba_sysfs_entry(hba[i]);
4064clean0: 4393clean0:
4065 hba[i]->busy_initializing = 0; 4394 hba[i]->busy_initializing = 0;
4066 /* cleanup any queues that may have been initialized */ 4395
4067 for (j=0; j <= hba[i]->highest_lun; j++){
4068 drive_info_struct *drv = &(hba[i]->drv[j]);
4069 if (drv->queue)
4070 blk_cleanup_queue(drv->queue);
4071 }
4072 /* 4396 /*
4073 * Deliberately omit pci_disable_device(): it does something nasty to 4397 * Deliberately omit pci_disable_device(): it does something nasty to
4074 * Smart Array controllers that pci_enable_device does not undo 4398 * Smart Array controllers that pci_enable_device does not undo
@@ -4125,8 +4449,9 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
4125 return; 4449 return;
4126 } 4450 }
4127 4451
4128 kthread_stop(hba[i]->cciss_scan_thread); 4452 mutex_lock(&hba[i]->busy_shutting_down);
4129 4453
4454 remove_from_scan_list(hba[i]);
4130 remove_proc_entry(hba[i]->devname, proc_cciss); 4455 remove_proc_entry(hba[i]->devname, proc_cciss);
4131 unregister_blkdev(hba[i]->major, hba[i]->devname); 4456 unregister_blkdev(hba[i]->major, hba[i]->devname);
4132 4457
@@ -4136,8 +4461,10 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
4136 if (disk) { 4461 if (disk) {
4137 struct request_queue *q = disk->queue; 4462 struct request_queue *q = disk->queue;
4138 4463
4139 if (disk->flags & GENHD_FL_UP) 4464 if (disk->flags & GENHD_FL_UP) {
4465 cciss_destroy_ld_sysfs_entry(hba[i], j, 1);
4140 del_gendisk(disk); 4466 del_gendisk(disk);
4467 }
4141 if (q) 4468 if (q)
4142 blk_cleanup_queue(q); 4469 blk_cleanup_queue(q);
4143 } 4470 }
@@ -4170,6 +4497,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
4170 pci_release_regions(pdev); 4497 pci_release_regions(pdev);
4171 pci_set_drvdata(pdev, NULL); 4498 pci_set_drvdata(pdev, NULL);
4172 cciss_destroy_hba_sysfs_entry(hba[i]); 4499 cciss_destroy_hba_sysfs_entry(hba[i]);
4500 mutex_unlock(&hba[i]->busy_shutting_down);
4173 free_hba(i); 4501 free_hba(i);
4174} 4502}
4175 4503
@@ -4202,15 +4530,25 @@ static int __init cciss_init(void)
4202 if (err) 4530 if (err)
4203 return err; 4531 return err;
4204 4532
4533 /* Start the scan thread */
4534 cciss_scan_thread = kthread_run(scan_thread, NULL, "cciss_scan");
4535 if (IS_ERR(cciss_scan_thread)) {
4536 err = PTR_ERR(cciss_scan_thread);
4537 goto err_bus_unregister;
4538 }
4539
4205 /* Register for our PCI devices */ 4540 /* Register for our PCI devices */
4206 err = pci_register_driver(&cciss_pci_driver); 4541 err = pci_register_driver(&cciss_pci_driver);
4207 if (err) 4542 if (err)
4208 goto err_bus_register; 4543 goto err_thread_stop;
4209 4544
4210 return 0; 4545 return err;
4211 4546
4212err_bus_register: 4547err_thread_stop:
4548 kthread_stop(cciss_scan_thread);
4549err_bus_unregister:
4213 bus_unregister(&cciss_bus_type); 4550 bus_unregister(&cciss_bus_type);
4551
4214 return err; 4552 return err;
4215} 4553}
4216 4554
@@ -4227,6 +4565,7 @@ static void __exit cciss_cleanup(void)
4227 cciss_remove_one(hba[i]->pdev); 4565 cciss_remove_one(hba[i]->pdev);
4228 } 4566 }
4229 } 4567 }
4568 kthread_stop(cciss_scan_thread);
4230 remove_proc_entry("driver/cciss", NULL); 4569 remove_proc_entry("driver/cciss", NULL);
4231 bus_unregister(&cciss_bus_type); 4570 bus_unregister(&cciss_bus_type);
4232} 4571}
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index 06a5db25b298..31524cf42c77 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -2,6 +2,7 @@
2#define CCISS_H 2#define CCISS_H
3 3
4#include <linux/genhd.h> 4#include <linux/genhd.h>
5#include <linux/mutex.h>
5 6
6#include "cciss_cmd.h" 7#include "cciss_cmd.h"
7 8
@@ -29,7 +30,7 @@ struct access_method {
29}; 30};
30typedef struct _drive_info_struct 31typedef struct _drive_info_struct
31{ 32{
32 __u32 LunID; 33 unsigned char LunID[8];
33 int usage_count; 34 int usage_count;
34 struct request_queue *queue; 35 struct request_queue *queue;
35 sector_t nr_blocks; 36 sector_t nr_blocks;
@@ -51,6 +52,7 @@ typedef struct _drive_info_struct
51 char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */ 52 char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
52 char model[MODEL_LEN + 1]; /* SCSI model string */ 53 char model[MODEL_LEN + 1]; /* SCSI model string */
53 char rev[REV_LEN + 1]; /* SCSI revision string */ 54 char rev[REV_LEN + 1]; /* SCSI revision string */
55 char device_initialized; /* indicates whether dev is initialized */
54} drive_info_struct; 56} drive_info_struct;
55 57
56struct ctlr_info 58struct ctlr_info
@@ -86,7 +88,7 @@ struct ctlr_info
86 BYTE cciss_read_capacity; 88 BYTE cciss_read_capacity;
87 89
88 // information about each logical volume 90 // information about each logical volume
89 drive_info_struct drv[CISS_MAX_LUN]; 91 drive_info_struct *drv[CISS_MAX_LUN];
90 92
91 struct access_method access; 93 struct access_method access;
92 94
@@ -108,6 +110,8 @@ struct ctlr_info
108 int nr_frees; 110 int nr_frees;
109 int busy_configuring; 111 int busy_configuring;
110 int busy_initializing; 112 int busy_initializing;
113 int busy_scanning;
114 struct mutex busy_shutting_down;
111 115
112 /* This element holds the zero based queue number of the last 116 /* This element holds the zero based queue number of the last
113 * queue to be started. It is used for fairness. 117 * queue to be started. It is used for fairness.
@@ -122,8 +126,8 @@ struct ctlr_info
122 /* and saved for later processing */ 126 /* and saved for later processing */
123#endif 127#endif
124 unsigned char alive; 128 unsigned char alive;
125 struct completion *rescan_wait; 129 struct list_head scan_list;
126 struct task_struct *cciss_scan_thread; 130 struct completion scan_wait;
127 struct device dev; 131 struct device dev;
128}; 132};
129 133
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index b82d438e2607..6422651ec364 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -32,6 +32,7 @@
32#include <linux/blkpg.h> 32#include <linux/blkpg.h>
33#include <linux/timer.h> 33#include <linux/timer.h>
34#include <linux/proc_fs.h> 34#include <linux/proc_fs.h>
35#include <linux/seq_file.h>
35#include <linux/init.h> 36#include <linux/init.h>
36#include <linux/hdreg.h> 37#include <linux/hdreg.h>
37#include <linux/spinlock.h> 38#include <linux/spinlock.h>
@@ -177,7 +178,6 @@ static int cpqarray_register_ctlr(int ctlr, struct pci_dev *pdev);
177 178
178#ifdef CONFIG_PROC_FS 179#ifdef CONFIG_PROC_FS
179static void ida_procinit(int i); 180static void ida_procinit(int i);
180static int ida_proc_get_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data);
181#else 181#else
182static void ida_procinit(int i) {} 182static void ida_procinit(int i) {}
183#endif 183#endif
@@ -206,6 +206,7 @@ static const struct block_device_operations ida_fops = {
206#ifdef CONFIG_PROC_FS 206#ifdef CONFIG_PROC_FS
207 207
208static struct proc_dir_entry *proc_array; 208static struct proc_dir_entry *proc_array;
209static const struct file_operations ida_proc_fops;
209 210
210/* 211/*
211 * Get us a file in /proc/array that says something about each controller. 212 * Get us a file in /proc/array that says something about each controller.
@@ -218,19 +219,16 @@ static void __init ida_procinit(int i)
218 if (!proc_array) return; 219 if (!proc_array) return;
219 } 220 }
220 221
221 create_proc_read_entry(hba[i]->devname, 0, proc_array, 222 proc_create_data(hba[i]->devname, 0, proc_array, &ida_proc_fops, hba[i]);
222 ida_proc_get_info, hba[i]);
223} 223}
224 224
225/* 225/*
226 * Report information about this controller. 226 * Report information about this controller.
227 */ 227 */
228static int ida_proc_get_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data) 228static int ida_proc_show(struct seq_file *m, void *v)
229{ 229{
230 off_t pos = 0; 230 int i, ctlr;
231 off_t len = 0; 231 ctlr_info_t *h = (ctlr_info_t*)m->private;
232 int size, i, ctlr;
233 ctlr_info_t *h = (ctlr_info_t*)data;
234 drv_info_t *drv; 232 drv_info_t *drv;
235#ifdef CPQ_PROC_PRINT_QUEUES 233#ifdef CPQ_PROC_PRINT_QUEUES
236 cmdlist_t *c; 234 cmdlist_t *c;
@@ -238,7 +236,7 @@ static int ida_proc_get_info(char *buffer, char **start, off_t offset, int lengt
238#endif 236#endif
239 237
240 ctlr = h->ctlr; 238 ctlr = h->ctlr;
241 size = sprintf(buffer, "%s: Compaq %s Controller\n" 239 seq_printf(m, "%s: Compaq %s Controller\n"
242 " Board ID: 0x%08lx\n" 240 " Board ID: 0x%08lx\n"
243 " Firmware Revision: %c%c%c%c\n" 241 " Firmware Revision: %c%c%c%c\n"
244 " Controller Sig: 0x%08lx\n" 242 " Controller Sig: 0x%08lx\n"
@@ -258,55 +256,54 @@ static int ida_proc_get_info(char *buffer, char **start, off_t offset, int lengt
258 h->log_drives, h->phys_drives, 256 h->log_drives, h->phys_drives,
259 h->Qdepth, h->maxQsinceinit); 257 h->Qdepth, h->maxQsinceinit);
260 258
261 pos += size; len += size; 259 seq_puts(m, "Logical Drive Info:\n");
262
263 size = sprintf(buffer+len, "Logical Drive Info:\n");
264 pos += size; len += size;
265 260
266 for(i=0; i<h->log_drives; i++) { 261 for(i=0; i<h->log_drives; i++) {
267 drv = &h->drv[i]; 262 drv = &h->drv[i];
268 size = sprintf(buffer+len, "ida/c%dd%d: blksz=%d nr_blks=%d\n", 263 seq_printf(m, "ida/c%dd%d: blksz=%d nr_blks=%d\n",
269 ctlr, i, drv->blk_size, drv->nr_blks); 264 ctlr, i, drv->blk_size, drv->nr_blks);
270 pos += size; len += size;
271 } 265 }
272 266
273#ifdef CPQ_PROC_PRINT_QUEUES 267#ifdef CPQ_PROC_PRINT_QUEUES
274 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags); 268 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
275 size = sprintf(buffer+len, "\nCurrent Queues:\n"); 269 seq_puts(m, "\nCurrent Queues:\n");
276 pos += size; len += size;
277 270
278 c = h->reqQ; 271 c = h->reqQ;
279 size = sprintf(buffer+len, "reqQ = %p", c); pos += size; len += size; 272 seq_printf(m, "reqQ = %p", c);
280 if (c) c=c->next; 273 if (c) c=c->next;
281 while(c && c != h->reqQ) { 274 while(c && c != h->reqQ) {
282 size = sprintf(buffer+len, "->%p", c); 275 seq_printf(m, "->%p", c);
283 pos += size; len += size;
284 c=c->next; 276 c=c->next;
285 } 277 }
286 278
287 c = h->cmpQ; 279 c = h->cmpQ;
288 size = sprintf(buffer+len, "\ncmpQ = %p", c); pos += size; len += size; 280 seq_printf(m, "\ncmpQ = %p", c);
289 if (c) c=c->next; 281 if (c) c=c->next;
290 while(c && c != h->cmpQ) { 282 while(c && c != h->cmpQ) {
291 size = sprintf(buffer+len, "->%p", c); 283 seq_printf(m, "->%p", c);
292 pos += size; len += size;
293 c=c->next; 284 c=c->next;
294 } 285 }
295 286
296 size = sprintf(buffer+len, "\n"); pos += size; len += size; 287 seq_putc(m, '\n');
297 spin_unlock_irqrestore(IDA_LOCK(h->ctlr), flags); 288 spin_unlock_irqrestore(IDA_LOCK(h->ctlr), flags);
298#endif 289#endif
299 size = sprintf(buffer+len, "nr_allocs = %d\nnr_frees = %d\n", 290 seq_printf(m, "nr_allocs = %d\nnr_frees = %d\n",
300 h->nr_allocs, h->nr_frees); 291 h->nr_allocs, h->nr_frees);
301 pos += size; len += size; 292 return 0;
302 293}
303 *eof = 1; 294
304 *start = buffer+offset; 295static int ida_proc_open(struct inode *inode, struct file *file)
305 len -= offset; 296{
306 if (len>length) 297 return single_open(file, ida_proc_show, PDE(inode)->data);
307 len = length;
308 return len;
309} 298}
299
300static const struct file_operations ida_proc_fops = {
301 .owner = THIS_MODULE,
302 .open = ida_proc_open,
303 .read = seq_read,
304 .llseek = seq_lseek,
305 .release = single_release,
306};
310#endif /* CONFIG_PROC_FS */ 307#endif /* CONFIG_PROC_FS */
311 308
312module_param_array(eisa, int, NULL, 0); 309module_param_array(eisa, int, NULL, 0);