cciss: remove redundant code

This patch removes redundant code where ever logical volumes are added or
removed. It adds 3 new functions that are called instead of having the same
code spread throughout the driver. It also removes the cciss_getgeometry
function.
The patch is fairly complex but we haven't figured out how to make it any
simpler and still do everything that needs to be done. Some of the
complexity comes from having to special case booting from cciss. Otherwise
the gendisk doesn't get added in time and the switchroot will fail.

Signed-off-by: Stephen M. Cameron <scameron@beardog.cca.cpqcorp.net>
Signed-off-by: Mike Miller <mike.miller@hp.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

authored by Mike Miller and committed by Jens Axboe 6ae5ce8e a72da29b

+169 -304
+169 -304
drivers/block/cciss.c
··· 159 159 static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); 160 160 161 161 static int cciss_revalidate(struct gendisk *disk); 162 - static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk); 162 + static int rebuild_lun_table(ctlr_info_t *h, int first_time); 163 163 static int deregister_disk(struct gendisk *disk, drive_info_struct *drv, 164 164 int clear_all); 165 165 ··· 171 171 int withirq, sector_t total_size, 172 172 unsigned int block_size, InquiryData_struct *inq_buff, 173 173 drive_info_struct *drv); 174 - static void cciss_getgeometry(int cntl_num); 175 174 static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *, 176 175 __u32); 177 176 static void start_io(ctlr_info_t *h); ··· 928 929 return 0; 929 930 } 930 931 932 + case CCISS_DEREGDISK: 933 + case CCISS_REGNEWD: 931 934 case CCISS_REVALIDVOLS: 932 - return rebuild_lun_table(host, NULL); 935 + return rebuild_lun_table(host, 0); 933 936 934 937 case CCISS_GETLUNINFO:{ 935 938 LogvolInfo_struct luninfo; ··· 944 943 return -EFAULT; 945 944 return 0; 946 945 } 947 - case CCISS_DEREGDISK: 948 - return rebuild_lun_table(host, disk); 949 - 950 - case CCISS_REGNEWD: 951 - return rebuild_lun_table(host, NULL); 952 - 953 946 case CCISS_PASSTHRU: 954 947 { 955 948 IOCTL_Command_struct iocommand; ··· 1356 1361 return; 1357 1362 } 1358 1363 1364 + static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk, 1365 + int drv_index) 1366 + { 1367 + disk->queue = blk_init_queue(do_cciss_request, &h->lock); 1368 + sprintf(disk->disk_name, "cciss/c%dd%d", h->ctlr, drv_index); 1369 + disk->major = h->major; 1370 + disk->first_minor = drv_index << NWD_SHIFT; 1371 + disk->fops = &cciss_fops; 1372 + disk->private_data = &h->drv[drv_index]; 1373 + 1374 + /* Set up queue information */ 1375 + blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); 1376 + 1377 + /* This is a hardware imposed limit. */ 1378 + blk_queue_max_hw_segments(disk->queue, MAXSGENTRIES); 1379 + 1380 + /* This is a limit in the driver and could be eliminated. */ 1381 + blk_queue_max_phys_segments(disk->queue, MAXSGENTRIES); 1382 + 1383 + blk_queue_max_sectors(disk->queue, h->cciss_max_sectors); 1384 + 1385 + blk_queue_softirq_done(disk->queue, cciss_softirq_done); 1386 + 1387 + disk->queue->queuedata = h; 1388 + 1389 + blk_queue_hardsect_size(disk->queue, 1390 + h->drv[drv_index].block_size); 1391 + 1392 + /* Make sure all queue data is written out before */ 1393 + /* setting h->drv[drv_index].queue, as setting this */ 1394 + /* allows the interrupt handler to start the queue */ 1395 + wmb(); 1396 + h->drv[drv_index].queue = disk->queue; 1397 + add_disk(disk); 1398 + } 1399 + 1359 1400 /* This function will check the usage_count of the drive to be updated/added. 1360 1401 * If the usage_count is zero and it is a heretofore unknown drive, or, 1361 1402 * the drive's capacity, geometry, or serial number has changed, ··· 1402 1371 * is also the controller node. Any changes to disk 0 will show up on 1403 1372 * the next reboot. 1404 1373 */ 1405 - static void cciss_update_drive_info(int ctlr, int drv_index) 1374 + static void cciss_update_drive_info(int ctlr, int drv_index, int first_time) 1406 1375 { 1407 1376 ctlr_info_t *h = hba[ctlr]; 1408 1377 struct gendisk *disk; ··· 1412 1381 unsigned long flags = 0; 1413 1382 int ret = 0; 1414 1383 drive_info_struct *drvinfo; 1384 + int was_only_controller_node; 1415 1385 1416 1386 /* Get information about the disk and modify the driver structure */ 1417 1387 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 1418 1388 drvinfo = kmalloc(sizeof(*drvinfo), GFP_KERNEL); 1419 1389 if (inq_buff == NULL || drvinfo == NULL) 1420 1390 goto mem_msg; 1391 + 1392 + /* See if we're trying to update the "controller node" 1393 + * this will happen the when the first logical drive gets 1394 + * created by ACU. 1395 + */ 1396 + was_only_controller_node = (drv_index == 0 && 1397 + h->drv[0].raid_level == -1); 1421 1398 1422 1399 /* testing to see if 16-byte CDBs are already being used */ 1423 1400 if (h->cciss_read == CCISS_READ_16) { ··· 1466 1427 drvinfo->nr_blocks == h->drv[drv_index].nr_blocks && 1467 1428 drvinfo->heads == h->drv[drv_index].heads && 1468 1429 drvinfo->sectors == h->drv[drv_index].sectors && 1469 - drvinfo->cylinders == h->drv[drv_index].cylinders)) { 1430 + drvinfo->cylinders == h->drv[drv_index].cylinders)) 1470 1431 /* The disk is unchanged, nothing to update */ 1471 1432 goto freeret; 1472 - } 1473 1433 1474 - /* Not the same disk, or something's changed, so we need to */ 1475 - /* deregister it, and re-register it, if it's not in use. */ 1476 - 1477 - /* if the disk already exists then deregister it before proceeding */ 1478 - /* (unless it's the first disk (for the controller node). */ 1434 + /* If we get here it's not the same disk, or something's changed, 1435 + * so we need to * deregister it, and re-register it, if it's not 1436 + * in use. 1437 + * If the disk already exists then deregister it before proceeding 1438 + * (unless it's the first disk (for the controller node). 1439 + */ 1479 1440 if (h->drv[drv_index].raid_level != -1 && drv_index != 0) { 1480 1441 printk(KERN_WARNING "disk %d has changed.\n", drv_index); 1481 1442 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 1482 1443 h->drv[drv_index].busy_configuring = 1; 1483 1444 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 1484 1445 1485 - /* deregister_disk sets h->drv[drv_index].queue = NULL */ 1486 - /* which keeps the interrupt handler from starting */ 1487 - /* the queue. */ 1446 + /* deregister_disk sets h->drv[drv_index].queue = NULL 1447 + * which keeps the interrupt handler from starting 1448 + * the queue. 1449 + */ 1488 1450 ret = deregister_disk(h->gendisk[drv_index], 1489 1451 &h->drv[drv_index], 0); 1490 1452 h->drv[drv_index].busy_configuring = 0; ··· 1495 1455 if (ret) 1496 1456 goto freeret; 1497 1457 1498 - /* Save the new information from cciss_geometry_inquiry */ 1499 - /* and serial number inquiry. */ 1458 + /* Save the new information from cciss_geometry_inquiry 1459 + * and serial number inquiry. 1460 + */ 1500 1461 h->drv[drv_index].block_size = drvinfo->block_size; 1501 1462 h->drv[drv_index].nr_blocks = drvinfo->nr_blocks; 1502 1463 h->drv[drv_index].heads = drvinfo->heads; ··· 1510 1469 disk = h->gendisk[drv_index]; 1511 1470 set_capacity(disk, h->drv[drv_index].nr_blocks); 1512 1471 1513 - /* if it's the controller (if drv_index == 0) it's already added */ 1514 - if (drv_index) { 1515 - disk->queue = blk_init_queue(do_cciss_request, &h->lock); 1516 - sprintf(disk->disk_name, "cciss/c%dd%d", ctlr, drv_index); 1517 - disk->major = h->major; 1518 - disk->first_minor = drv_index << NWD_SHIFT; 1519 - disk->fops = &cciss_fops; 1520 - disk->private_data = &h->drv[drv_index]; 1472 + /* If it's not disk 0 (drv_index != 0) 1473 + * or if it was disk 0, but there was previously 1474 + * no actual corresponding configured logical drive 1475 + * (raid_leve == -1) then we want to update the 1476 + * logical drive's information. 1477 + */ 1478 + if (drv_index || first_time) 1479 + cciss_add_disk(h, disk, drv_index); 1521 1480 1522 - /* Set up queue information */ 1523 - blk_queue_bounce_limit(disk->queue, hba[ctlr]->pdev->dma_mask); 1524 - 1525 - /* This is a hardware imposed limit. */ 1526 - blk_queue_max_hw_segments(disk->queue, MAXSGENTRIES); 1527 - 1528 - /* This is a limit in the driver and could be eliminated. */ 1529 - blk_queue_max_phys_segments(disk->queue, MAXSGENTRIES); 1530 - 1531 - blk_queue_max_sectors(disk->queue, h->cciss_max_sectors); 1532 - 1533 - blk_queue_softirq_done(disk->queue, cciss_softirq_done); 1534 - 1535 - disk->queue->queuedata = hba[ctlr]; 1536 - 1537 - blk_queue_hardsect_size(disk->queue, 1538 - hba[ctlr]->drv[drv_index].block_size); 1539 - 1540 - /* Make sure all queue data is written out before */ 1541 - /* setting h->drv[drv_index].queue, as setting this */ 1542 - /* allows the interrupt handler to start the queue */ 1543 - wmb(); 1544 - h->drv[drv_index].queue = disk->queue; 1545 - add_disk(disk); 1546 - } 1547 - 1548 - freeret: 1481 + freeret: 1549 1482 kfree(inq_buff); 1550 1483 kfree(drvinfo); 1551 1484 return; 1552 - mem_msg: 1485 + mem_msg: 1553 1486 printk(KERN_ERR "cciss: out of memory\n"); 1554 1487 goto freeret; 1555 1488 } ··· 1548 1533 return -1; 1549 1534 } 1550 1535 1536 + /* cciss_add_gendisk finds a free hba[]->drv structure 1537 + * and allocates a gendisk if needed, and sets the lunid 1538 + * in the drvinfo structure. It returns the index into 1539 + * the ->drv[] array, or -1 if none are free. 1540 + * is_controller_node indicates whether highest_lun should 1541 + * count this disk, or if it's only being added to provide 1542 + * a means to talk to the controller in case no logical 1543 + * drives have yet been configured. 1544 + */ 1545 + static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid) 1546 + { 1547 + int drv_index; 1548 + 1549 + drv_index = cciss_find_free_drive_index(h->ctlr); 1550 + if (drv_index == -1) 1551 + return -1; 1552 + /*Check if the gendisk needs to be allocated */ 1553 + if (!h->gendisk[drv_index]) { 1554 + h->gendisk[drv_index] = 1555 + alloc_disk(1 << NWD_SHIFT); 1556 + if (!h->gendisk[drv_index]) { 1557 + printk(KERN_ERR "cciss%d: could not " 1558 + "allocate a new disk %d\n", 1559 + h->ctlr, drv_index); 1560 + return -1; 1561 + } 1562 + } 1563 + h->drv[drv_index].LunID = lunid; 1564 + 1565 + /* Don't need to mark this busy because nobody */ 1566 + /* else knows about this disk yet to contend */ 1567 + /* for access to it. */ 1568 + h->drv[drv_index].busy_configuring = 0; 1569 + wmb(); 1570 + return drv_index; 1571 + } 1572 + 1573 + /* This is for the special case of a controller which 1574 + * has no logical drives. In this case, we still need 1575 + * to register a disk so the controller can be accessed 1576 + * by the Array Config Utility. 1577 + */ 1578 + static void cciss_add_controller_node(ctlr_info_t *h) 1579 + { 1580 + struct gendisk *disk; 1581 + int drv_index; 1582 + 1583 + if (h->gendisk[0] != NULL) /* already did this? Then bail. */ 1584 + return; 1585 + 1586 + drv_index = cciss_add_gendisk(h, 0); 1587 + if (drv_index == -1) { 1588 + printk(KERN_WARNING "cciss%d: could not " 1589 + "add disk 0.\n", h->ctlr); 1590 + return; 1591 + } 1592 + h->drv[drv_index].block_size = 512; 1593 + h->drv[drv_index].nr_blocks = 0; 1594 + h->drv[drv_index].heads = 0; 1595 + h->drv[drv_index].sectors = 0; 1596 + h->drv[drv_index].cylinders = 0; 1597 + h->drv[drv_index].raid_level = -1; 1598 + memset(h->drv[drv_index].serial_no, 0, 16); 1599 + disk = h->gendisk[drv_index]; 1600 + cciss_add_disk(h, disk, drv_index); 1601 + } 1602 + 1551 1603 /* This function will add and remove logical drives from the Logical 1552 1604 * drive array of the controller and maintain persistency of ordering 1553 1605 * so that mount points are preserved until the next reboot. This allows ··· 1622 1540 * without a re-ordering of those drives. 1623 1541 * INPUT 1624 1542 * h = The controller to perform the operations on 1625 - * del_disk = The disk to remove if specified. If the value given 1626 - * is NULL then no disk is removed. 1627 1543 */ 1628 - static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk) 1544 + static int rebuild_lun_table(ctlr_info_t *h, int first_time) 1629 1545 { 1630 1546 int ctlr = h->ctlr; 1631 1547 int num_luns; ··· 1636 1556 __u32 lunid = 0; 1637 1557 unsigned long flags; 1638 1558 1559 + if (!capable(CAP_SYS_RAWIO)) 1560 + return -EPERM; 1561 + 1639 1562 /* Set busy_configuring flag for this operation */ 1640 1563 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 1641 1564 if (h->busy_configuring) { ··· 1647 1564 } 1648 1565 h->busy_configuring = 1; 1649 1566 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 1650 - 1651 - if (!capable(CAP_SYS_RAWIO)) 1652 - return -EPERM; 1653 1567 1654 1568 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); 1655 1569 if (ld_buff == NULL) ··· 1673 1593 " this driver.\n"); 1674 1594 } 1675 1595 1676 - /* Compare controller drive array to driver's drive array */ 1677 - /* to see if any drives are missing on the controller due */ 1678 - /* to action of Array Config Utility (user deletes drive) */ 1679 - /* and deregister logical drives which have disappeared. */ 1596 + if (num_luns == 0) 1597 + cciss_add_controller_node(h); 1598 + 1599 + /* Compare controller drive array to driver's drive array 1600 + * to see if any drives are missing on the controller due 1601 + * to action of Array Config Utility (user deletes drive) 1602 + * and deregister logical drives which have disappeared. 1603 + */ 1680 1604 for (i = 0; i <= h->highest_lun; i++) { 1681 1605 int j; 1682 1606 drv_found = 0; ··· 1732 1648 1733 1649 /* check if the drive was found already in the array */ 1734 1650 if (!drv_found) { 1735 - drv_index = cciss_find_free_drive_index(ctlr); 1651 + drv_index = cciss_add_gendisk(h, lunid); 1736 1652 if (drv_index == -1) 1737 1653 goto freeret; 1738 - /*Check if the gendisk needs to be allocated */ 1739 - if (!h->gendisk[drv_index]) { 1740 - h->gendisk[drv_index] = 1741 - alloc_disk(1 << NWD_SHIFT); 1742 - if (!h->gendisk[drv_index]){ 1743 - printk(KERN_ERR "cciss: could not " 1744 - "allocate new disk %d\n", 1745 - drv_index); 1746 - goto mem_msg; 1747 - } 1748 - } 1749 - h->drv[drv_index].LunID = lunid; 1750 - 1751 - /* Don't need to mark this busy because nobody 1752 - * else knows about this disk yet to contend 1753 - * for access to it. 1754 - */ 1755 - h->drv[drv_index].busy_configuring = 0; 1756 - wmb(); 1757 - 1758 1654 } 1759 - cciss_update_drive_info(ctlr, drv_index); 1655 + cciss_update_drive_info(ctlr, drv_index, first_time); 1760 1656 } /* end for */ 1761 1657 1762 - freeret: 1658 + freeret: 1763 1659 kfree(ld_buff); 1764 1660 h->busy_configuring = 0; 1765 1661 /* We return -1 here to tell the ACU that we have registered/updated ··· 1747 1683 * additional times. 1748 1684 */ 1749 1685 return -1; 1750 - mem_msg: 1686 + mem_msg: 1751 1687 printk(KERN_ERR "cciss: out of memory\n"); 1752 1688 h->busy_configuring = 0; 1753 1689 goto freeret; ··· 3352 3288 return err; 3353 3289 } 3354 3290 3355 - /* 3356 - * Gets information about the local volumes attached to the controller. 3291 + /* Function to find the first free pointer into our hba[] array 3292 + * Returns -1 if no free entries are left. 3357 3293 */ 3358 - static void cciss_getgeometry(int cntl_num) 3359 - { 3360 - ReportLunData_struct *ld_buff; 3361 - InquiryData_struct *inq_buff; 3362 - int return_code; 3363 - int i; 3364 - int listlength = 0; 3365 - __u32 lunid = 0; 3366 - unsigned block_size; 3367 - sector_t total_size; 3368 - 3369 - ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); 3370 - if (ld_buff == NULL) { 3371 - printk(KERN_ERR "cciss: out of memory\n"); 3372 - return; 3373 - } 3374 - inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 3375 - if (inq_buff == NULL) { 3376 - printk(KERN_ERR "cciss: out of memory\n"); 3377 - kfree(ld_buff); 3378 - return; 3379 - } 3380 - /* Get the firmware version */ 3381 - return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff, 3382 - sizeof(InquiryData_struct), 0, 0, 0, NULL, 3383 - TYPE_CMD); 3384 - if (return_code == IO_OK) { 3385 - hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32]; 3386 - hba[cntl_num]->firm_ver[1] = inq_buff->data_byte[33]; 3387 - hba[cntl_num]->firm_ver[2] = inq_buff->data_byte[34]; 3388 - hba[cntl_num]->firm_ver[3] = inq_buff->data_byte[35]; 3389 - } else { /* send command failed */ 3390 - 3391 - printk(KERN_WARNING "cciss: unable to determine firmware" 3392 - " version of controller\n"); 3393 - } 3394 - /* Get the number of logical volumes */ 3395 - return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff, 3396 - sizeof(ReportLunData_struct), 0, 0, 0, NULL, 3397 - TYPE_CMD); 3398 - 3399 - if (return_code == IO_OK) { 3400 - #ifdef CCISS_DEBUG 3401 - printk("LUN Data\n--------------------------\n"); 3402 - #endif /* CCISS_DEBUG */ 3403 - 3404 - listlength |= 3405 - (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24; 3406 - listlength |= 3407 - (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16; 3408 - listlength |= 3409 - (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8; 3410 - listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]); 3411 - } else { /* reading number of logical volumes failed */ 3412 - 3413 - printk(KERN_WARNING "cciss: report logical volume" 3414 - " command failed\n"); 3415 - listlength = 0; 3416 - } 3417 - hba[cntl_num]->num_luns = listlength / 8; // 8 bytes pre entry 3418 - if (hba[cntl_num]->num_luns > CISS_MAX_LUN) { 3419 - printk(KERN_ERR 3420 - "ciss: only %d number of logical volumes supported\n", 3421 - CISS_MAX_LUN); 3422 - hba[cntl_num]->num_luns = CISS_MAX_LUN; 3423 - } 3424 - #ifdef CCISS_DEBUG 3425 - printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", 3426 - ld_buff->LUNListLength[0], ld_buff->LUNListLength[1], 3427 - ld_buff->LUNListLength[2], ld_buff->LUNListLength[3], 3428 - hba[cntl_num]->num_luns); 3429 - #endif /* CCISS_DEBUG */ 3430 - 3431 - hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns - 1; 3432 - for (i = 0; i < CISS_MAX_LUN; i++) { 3433 - if (i < hba[cntl_num]->num_luns) { 3434 - lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3])) 3435 - << 24; 3436 - lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2])) 3437 - << 16; 3438 - lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1])) 3439 - << 8; 3440 - lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]); 3441 - 3442 - hba[cntl_num]->drv[i].LunID = lunid; 3443 - 3444 - #ifdef CCISS_DEBUG 3445 - printk(KERN_DEBUG "LUN[%d]: %x %x %x %x = %x\n", i, 3446 - ld_buff->LUN[i][0], ld_buff->LUN[i][1], 3447 - ld_buff->LUN[i][2], ld_buff->LUN[i][3], 3448 - hba[cntl_num]->drv[i].LunID); 3449 - #endif /* CCISS_DEBUG */ 3450 - 3451 - /* testing to see if 16-byte CDBs are already being used */ 3452 - if(hba[cntl_num]->cciss_read == CCISS_READ_16) { 3453 - cciss_read_capacity_16(cntl_num, i, 0, 3454 - &total_size, &block_size); 3455 - goto geo_inq; 3456 - } 3457 - cciss_read_capacity(cntl_num, i, 0, &total_size, &block_size); 3458 - 3459 - /* If read_capacity returns all F's the logical is >2TB */ 3460 - /* so we switch to 16-byte CDBs for all read/write ops */ 3461 - if(total_size == 0xFFFFFFFFULL) { 3462 - cciss_read_capacity_16(cntl_num, i, 0, 3463 - &total_size, &block_size); 3464 - hba[cntl_num]->cciss_read = CCISS_READ_16; 3465 - hba[cntl_num]->cciss_write = CCISS_WRITE_16; 3466 - } else { 3467 - hba[cntl_num]->cciss_read = CCISS_READ_10; 3468 - hba[cntl_num]->cciss_write = CCISS_WRITE_10; 3469 - } 3470 - geo_inq: 3471 - cciss_geometry_inquiry(cntl_num, i, 0, total_size, 3472 - block_size, inq_buff, 3473 - &hba[cntl_num]->drv[i]); 3474 - cciss_get_serial_no(cntl_num, i, 0, 3475 - hba[cntl_num]->drv[i].serial_no, 3476 - sizeof(hba[cntl_num]->drv[i].serial_no)); 3477 - } else { 3478 - /* initialize raid_level to indicate a free space */ 3479 - hba[cntl_num]->drv[i].raid_level = -1; 3480 - } 3481 - } 3482 - kfree(ld_buff); 3483 - kfree(inq_buff); 3484 - } 3485 - 3486 - /* Function to find the first free pointer into our hba[] array */ 3487 - /* Returns -1 if no free entries are left. */ 3488 3294 static int alloc_cciss_hba(void) 3489 3295 { 3490 3296 int i; ··· 3366 3432 p = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL); 3367 3433 if (!p) 3368 3434 goto Enomem; 3369 - p->gendisk[0] = alloc_disk(1 << NWD_SHIFT); 3370 - if (!p->gendisk[0]) { 3371 - kfree(p); 3372 - goto Enomem; 3373 - } 3374 3435 hba[i] = p; 3375 3436 return i; 3376 3437 } ··· 3493 3564 ((hba[i]->nr_cmds + BITS_PER_LONG - 3494 3565 1) / BITS_PER_LONG) * sizeof(unsigned long)); 3495 3566 3496 - #ifdef CCISS_DEBUG 3497 - printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n", i); 3498 - #endif /* CCISS_DEBUG */ 3499 - 3500 - cciss_getgeometry(i); 3567 + hba[i]->num_luns = 0; 3568 + hba[i]->highest_lun = -1; 3569 + for (j = 0; j < CISS_MAX_LUN; j++) { 3570 + hba[i]->drv[j].raid_level = -1; 3571 + hba[i]->drv[j].queue = NULL; 3572 + hba[i]->gendisk[j] = NULL; 3573 + } 3501 3574 3502 3575 cciss_scsi_setup(i); 3503 3576 ··· 3512 3581 3513 3582 hba[i]->busy_initializing = 0; 3514 3583 3515 - do { 3516 - drive_info_struct *drv = &(hba[i]->drv[j]); 3517 - struct gendisk *disk = hba[i]->gendisk[j]; 3518 - struct request_queue *q; 3519 - 3520 - /* Check if the disk was allocated already */ 3521 - if (!disk){ 3522 - hba[i]->gendisk[j] = alloc_disk(1 << NWD_SHIFT); 3523 - disk = hba[i]->gendisk[j]; 3524 - } 3525 - 3526 - /* Check that the disk was able to be allocated */ 3527 - if (!disk) { 3528 - printk(KERN_ERR "cciss: unable to allocate memory for disk %d\n", j); 3529 - goto clean4; 3530 - } 3531 - 3532 - q = blk_init_queue(do_cciss_request, &hba[i]->lock); 3533 - if (!q) { 3534 - printk(KERN_ERR 3535 - "cciss: unable to allocate queue for disk %d\n", 3536 - j); 3537 - goto clean4; 3538 - } 3539 - drv->queue = q; 3540 - 3541 - blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask); 3542 - 3543 - /* This is a hardware imposed limit. */ 3544 - blk_queue_max_hw_segments(q, MAXSGENTRIES); 3545 - 3546 - /* This is a limit in the driver and could be eliminated. */ 3547 - blk_queue_max_phys_segments(q, MAXSGENTRIES); 3548 - 3549 - blk_queue_max_sectors(q, hba[i]->cciss_max_sectors); 3550 - 3551 - blk_queue_softirq_done(q, cciss_softirq_done); 3552 - 3553 - q->queuedata = hba[i]; 3554 - sprintf(disk->disk_name, "cciss/c%dd%d", i, j); 3555 - disk->major = hba[i]->major; 3556 - disk->first_minor = j << NWD_SHIFT; 3557 - disk->fops = &cciss_fops; 3558 - disk->queue = q; 3559 - disk->private_data = drv; 3560 - disk->driverfs_dev = &pdev->dev; 3561 - /* we must register the controller even if no disks exist */ 3562 - /* this is for the online array utilities */ 3563 - if (!drv->heads && j) 3564 - continue; 3565 - blk_queue_hardsect_size(q, drv->block_size); 3566 - set_capacity(disk, drv->nr_blocks); 3567 - j++; 3568 - } while (j <= hba[i]->highest_lun); 3569 - 3570 - /* Make sure all queue data is written out before */ 3571 - /* interrupt handler, triggered by add_disk, */ 3572 - /* is allowed to start them. */ 3573 - wmb(); 3574 - 3575 - for (j = 0; j <= hba[i]->highest_lun; j++) 3576 - add_disk(hba[i]->gendisk[j]); 3577 - 3578 - /* we must register the controller even if no disks exist */ 3579 - if (hba[i]->highest_lun == -1) 3580 - add_disk(hba[i]->gendisk[0]); 3581 - 3584 + rebuild_lun_table(hba[i], 1); 3582 3585 return 1; 3583 3586 3584 - clean4: 3587 + clean4: 3585 3588 #ifdef CONFIG_CISS_SCSI_TAPE 3586 3589 kfree(hba[i]->scsi_rejects.complete); 3587 3590 #endif ··· 3530 3665 hba[i]->errinfo_pool, 3531 3666 hba[i]->errinfo_pool_dhandle); 3532 3667 free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]); 3533 - clean2: 3668 + clean2: 3534 3669 unregister_blkdev(hba[i]->major, hba[i]->devname); 3535 - clean1: 3670 + clean1: 3536 3671 hba[i]->busy_initializing = 0; 3537 3672 /* cleanup any queues that may have been initialized */ 3538 3673 for (j=0; j <= hba[i]->highest_lun; j++){