- /*
- * Search for an existing target for this sdev.
- */
- list_for_each_entry(device, &shost->__devices, siblings) {
- if (device->id == sdev->id &&
- device->channel == sdev->channel) {
- list_add_tail(&sdev->same_target_siblings,
- &device->same_target_siblings);
- sdev->scsi_level = device->scsi_level;
- starget = device->sdev_target;
- break;
- }
- }
-
- if (!starget) {
- const int size = sizeof(*starget) +
- shost->transportt->target_size;
- starget = kmalloc(size, GFP_ATOMIC);
- if (!starget) {
- printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
- spin_unlock_irqrestore(shost->host_lock,
- flags);
- return -ENOMEM;
- }
- memset(starget, 0, size);
- dev = &starget->dev;
- device_initialize(dev);
- dev->parent = get_device(&shost->shost_gendev);
- dev->release = scsi_target_dev_release;
- sprintf(dev->bus_id, "target%d:%d:%d",
- shost->host_no, sdev->channel, sdev->id);
- starget->id = sdev->id;
- starget->channel = sdev->channel;
- create = starget->create = 1;
- /*
- * If there wasn't another lun already configured at
- * this target, then default this device to SCSI_2
- * until we know better
- */
- sdev->scsi_level = SCSI_2;
- }
- get_device(&starget->dev);
- sdev->sdev_gendev.parent = &starget->dev;
- sdev->sdev_target = starget;