Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi_dh: move device matching to the core code

Add a single list of devices that need non-ALUA device handlers to the core
scsi_dh code so that we can autoload the modules for them at probe time.

While this is a little ugly in terms of architecture it actually
significantly simplifies the code in addition to the new autoloading
functionality.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>

authored by

Christoph Hellwig and committed by
James Bottomley
d95dbff2 086b91d0

+66 -134
-6
drivers/scsi/device_handler/scsi_dh_alua.c
··· 819 819 820 820 } 821 821 822 - static bool alua_match(struct scsi_device *sdev) 823 - { 824 - return (scsi_device_tpgs(sdev) != 0); 825 - } 826 - 827 822 /* 828 823 * alua_bus_attach - Attach device handler 829 824 * @sdev: device to be attached to ··· 872 877 .check_sense = alua_check_sense, 873 878 .activate = alua_activate, 874 879 .set_params = alua_set_params, 875 - .match = alua_match, 876 880 }; 877 881 878 882 static int __init alua_init(void)
-29
drivers/scsi/device_handler/scsi_dh_emc.c
··· 622 622 return result; 623 623 } 624 624 625 - static const struct { 626 - char *vendor; 627 - char *model; 628 - } clariion_dev_list[] = { 629 - {"DGC", "RAID"}, 630 - {"DGC", "DISK"}, 631 - {"DGC", "VRAID"}, 632 - {NULL, NULL}, 633 - }; 634 - 635 - static bool clariion_match(struct scsi_device *sdev) 636 - { 637 - int i; 638 - 639 - if (scsi_device_tpgs(sdev)) 640 - return false; 641 - 642 - for (i = 0; clariion_dev_list[i].vendor; i++) { 643 - if (!strncmp(sdev->vendor, clariion_dev_list[i].vendor, 644 - strlen(clariion_dev_list[i].vendor)) && 645 - !strncmp(sdev->model, clariion_dev_list[i].model, 646 - strlen(clariion_dev_list[i].model))) { 647 - return true; 648 - } 649 - } 650 - return false; 651 - } 652 - 653 625 static struct scsi_dh_data *clariion_bus_attach(struct scsi_device *sdev) 654 626 { 655 627 struct clariion_dh_data *h; ··· 670 698 .activate = clariion_activate, 671 699 .prep_fn = clariion_prep_fn, 672 700 .set_params = clariion_set_params, 673 - .match = clariion_match, 674 701 }; 675 702 676 703 static int __init clariion_init(void)
-30
drivers/scsi/device_handler/scsi_dh_hp_sw.c
··· 311 311 return 0; 312 312 } 313 313 314 - static const struct { 315 - char *vendor; 316 - char *model; 317 - } hp_sw_dh_data_list[] = { 318 - {"COMPAQ", "MSA1000 VOLUME"}, 319 - {"COMPAQ", "HSV110"}, 320 - {"HP", "HSV100"}, 321 - {"DEC", "HSG80"}, 322 - {NULL, NULL}, 323 - }; 324 - 325 - static bool hp_sw_match(struct scsi_device *sdev) 326 - { 327 - int i; 328 - 329 - if (scsi_device_tpgs(sdev)) 330 - return false; 331 - 332 - for (i = 0; hp_sw_dh_data_list[i].vendor; i++) { 333 - if (!strncmp(sdev->vendor, hp_sw_dh_data_list[i].vendor, 334 - strlen(hp_sw_dh_data_list[i].vendor)) && 335 - !strncmp(sdev->model, hp_sw_dh_data_list[i].model, 336 - strlen(hp_sw_dh_data_list[i].model))) { 337 - return true; 338 - } 339 - } 340 - return false; 341 - } 342 - 343 314 static struct scsi_dh_data *hp_sw_bus_attach(struct scsi_device *sdev) 344 315 { 345 316 struct hp_sw_dh_data *h; ··· 350 379 .detach = hp_sw_bus_detach, 351 380 .activate = hp_sw_activate, 352 381 .prep_fn = hp_sw_prep_fn, 353 - .match = hp_sw_match, 354 382 }; 355 383 356 384 static int __init hp_sw_init(void)
-50
drivers/scsi/device_handler/scsi_dh_rdac.c
··· 778 778 return SCSI_RETURN_NOT_HANDLED; 779 779 } 780 780 781 - static const struct { 782 - char *vendor; 783 - char *model; 784 - } rdac_dev_list[] = { 785 - {"IBM", "1722"}, 786 - {"IBM", "1724"}, 787 - {"IBM", "1726"}, 788 - {"IBM", "1742"}, 789 - {"IBM", "1745"}, 790 - {"IBM", "1746"}, 791 - {"IBM", "1813"}, 792 - {"IBM", "1814"}, 793 - {"IBM", "1815"}, 794 - {"IBM", "1818"}, 795 - {"IBM", "3526"}, 796 - {"SGI", "TP9"}, 797 - {"SGI", "IS"}, 798 - {"STK", "OPENstorage D280"}, 799 - {"STK", "FLEXLINE 380"}, 800 - {"SUN", "CSM"}, 801 - {"SUN", "LCSM100"}, 802 - {"SUN", "STK6580_6780"}, 803 - {"SUN", "SUN_6180"}, 804 - {"SUN", "ArrayStorage"}, 805 - {"DELL", "MD3"}, 806 - {"NETAPP", "INF-01-00"}, 807 - {"LSI", "INF-01-00"}, 808 - {"ENGENIO", "INF-01-00"}, 809 - {NULL, NULL}, 810 - }; 811 - 812 - static bool rdac_match(struct scsi_device *sdev) 813 - { 814 - int i; 815 - 816 - if (scsi_device_tpgs(sdev)) 817 - return false; 818 - 819 - for (i = 0; rdac_dev_list[i].vendor; i++) { 820 - if (!strncmp(sdev->vendor, rdac_dev_list[i].vendor, 821 - strlen(rdac_dev_list[i].vendor)) && 822 - !strncmp(sdev->model, rdac_dev_list[i].model, 823 - strlen(rdac_dev_list[i].model))) { 824 - return true; 825 - } 826 - } 827 - return false; 828 - } 829 - 830 781 static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev) 831 782 { 832 783 struct rdac_dh_data *h; ··· 846 895 .attach = rdac_bus_attach, 847 896 .detach = rdac_bus_detach, 848 897 .activate = rdac_activate, 849 - .match = rdac_match, 850 898 }; 851 899 852 900 static int __init rdac_init(void)
+66 -18
drivers/scsi/scsi_dh.c
··· 29 29 static DEFINE_SPINLOCK(list_lock); 30 30 static LIST_HEAD(scsi_dh_list); 31 31 32 + struct scsi_dh_blist { 33 + const char *vendor; 34 + const char *model; 35 + const char *driver; 36 + }; 37 + 38 + static const struct scsi_dh_blist scsi_dh_blist[] = { 39 + {"DGC", "RAID", "clariion" }, 40 + {"DGC", "DISK", "clariion" }, 41 + {"DGC", "VRAID", "clariion" }, 42 + 43 + {"COMPAQ", "MSA1000 VOLUME", "hp_sw" }, 44 + {"COMPAQ", "HSV110", "hp_sw" }, 45 + {"HP", "HSV100", "hp_sw"}, 46 + {"DEC", "HSG80", "hp_sw"}, 47 + 48 + {"IBM", "1722", "rdac", }, 49 + {"IBM", "1724", "rdac", }, 50 + {"IBM", "1726", "rdac", }, 51 + {"IBM", "1742", "rdac", }, 52 + {"IBM", "1745", "rdac", }, 53 + {"IBM", "1746", "rdac", }, 54 + {"IBM", "1813", "rdac", }, 55 + {"IBM", "1814", "rdac", }, 56 + {"IBM", "1815", "rdac", }, 57 + {"IBM", "1818", "rdac", }, 58 + {"IBM", "3526", "rdac", }, 59 + {"SGI", "TP9", "rdac", }, 60 + {"SGI", "IS", "rdac", }, 61 + {"STK", "OPENstorage D280", "rdac", }, 62 + {"STK", "FLEXLINE 380", "rdac", }, 63 + {"SUN", "CSM", "rdac", }, 64 + {"SUN", "LCSM100", "rdac", }, 65 + {"SUN", "STK6580_6780", "rdac", }, 66 + {"SUN", "SUN_6180", "rdac", }, 67 + {"SUN", "ArrayStorage", "rdac", }, 68 + {"DELL", "MD3", "rdac", }, 69 + {"NETAPP", "INF-01-00", "rdac", }, 70 + {"LSI", "INF-01-00", "rdac", }, 71 + {"ENGENIO", "INF-01-00", "rdac", }, 72 + {NULL, NULL, NULL }, 73 + }; 74 + 75 + static const char * 76 + scsi_dh_find_driver(struct scsi_device *sdev) 77 + { 78 + const struct scsi_dh_blist *b; 79 + 80 + if (scsi_device_tpgs(sdev)) 81 + return "alua"; 82 + 83 + for (b = scsi_dh_blist; b->vendor; b++) { 84 + if (!strncmp(sdev->vendor, b->vendor, strlen(b->vendor)) && 85 + !strncmp(sdev->model, b->model, strlen(b->model))) { 86 + return b->driver; 87 + } 88 + } 89 + return NULL; 90 + } 91 + 92 + 32 93 static struct scsi_device_handler *__scsi_dh_lookup(const char *name) 33 94 { 34 95 struct scsi_device_handler *tmp, *found = NULL; ··· 116 55 } 117 56 118 57 return dh; 119 - } 120 - 121 - static struct scsi_device_handler * 122 - device_handler_match(struct scsi_device *sdev) 123 - { 124 - struct scsi_device_handler *tmp_dh, *found_dh = NULL; 125 - 126 - spin_lock(&list_lock); 127 - list_for_each_entry(tmp_dh, &scsi_dh_list, list) { 128 - if (tmp_dh->match && tmp_dh->match(sdev)) { 129 - found_dh = tmp_dh; 130 - break; 131 - } 132 - } 133 - spin_unlock(&list_lock); 134 - return found_dh; 135 58 } 136 59 137 60 /* ··· 229 184 230 185 int scsi_dh_add_device(struct scsi_device *sdev) 231 186 { 232 - struct scsi_device_handler *devinfo; 187 + struct scsi_device_handler *devinfo = NULL; 188 + const char *drv; 233 189 int err; 234 190 235 191 err = device_create_file(&sdev->sdev_gendev, &scsi_dh_state_attr); 236 192 if (err) 237 193 return err; 238 194 239 - devinfo = device_handler_match(sdev); 195 + drv = scsi_dh_find_driver(sdev); 196 + if (drv) 197 + devinfo = scsi_dh_lookup(drv); 240 198 if (devinfo) 241 199 err = scsi_dh_handler_attach(sdev, devinfo); 242 200 return err;
-1
include/scsi/scsi_device.h
··· 215 215 int (*activate)(struct scsi_device *, activate_complete, void *); 216 216 int (*prep_fn)(struct scsi_device *, struct request *); 217 217 int (*set_params)(struct scsi_device *, const char *); 218 - bool (*match)(struct scsi_device *); 219 218 }; 220 219 221 220 struct scsi_dh_data {