On 12/14/2017 11:11 AM, Hannes Reinecke wrote:
Implement the 'rescan' virtio-scsi feature. Rescanning works by sending a 'rescan' virtio-scsi command with the next requested target id to the backend. The backend will respond with the next used target id or '-1' if no more targets are found. This avoids scanning all possible targets. Signed-off-by: Hannes Reinecke <hare@xxxxxxxx> --- drivers/scsi/virtio_scsi.c | 239 ++++++++++++++++++++++++++++++++++++++- include/uapi/linux/virtio_scsi.h | 15 +++ 2 files changed, 250 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 7c28e8d..a561e90 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c
+static void virtscsi_rescan_work(struct work_struct *work) +{
+ if (target_id == -1) { + shost_printk(KERN_INFO, sh, "rescan: terminated\n"); + spin_unlock_irq(&vscsi->rescan_lock); + return; + } + spin_unlock_irq(&vscsi->rescan_lock); + + cmd = mempool_alloc(virtscsi_cmd_pool, GFP_NOIO); + if (!cmd) { + shost_printk(KERN_INFO, sh, "rescan: no memory\n"); + goto scan_host; + } + shost_printk(KERN_INFO, sh, "rescan: next target %d\n", target_id);
+ shost_printk(KERN_INFO, sh, + "rescan: no more targets\n");
+ shost_printk(KERN_INFO, sh, "rescan: scan host\n"); + scsi_scan_host(sh); +} + +static void virtscsi_scan_host(struct virtio_scsi *vscsi) +{ + struct Scsi_Host *sh = virtio_scsi_host(vscsi->vdev); + int ret; + struct virtio_scsi_cmd *cmd; + DECLARE_COMPLETION_ONSTACK(comp); + + cmd = mempool_alloc(virtscsi_cmd_pool, GFP_NOIO); + if (!cmd) { + shost_printk(KERN_INFO, sh, "rescan: no memory\n");
If shost_printk does not add any info about calling function, this cannot be distinguished from a message with the same format string above in virtscsi_rescan_work()?
+ return; + } + shost_printk(KERN_INFO, sh, "rescan: scan host\n");
dito
+static void virtscsi_scan_start(struct Scsi_Host *sh) +{ + struct virtio_scsi *vscsi = shost_priv(sh); + + virtscsi_scan_host(vscsi); + spin_lock_irq(&vscsi->rescan_lock); + if (vscsi->next_target_id != -1) { + shost_printk(KERN_INFO, sh, "rescan: already running\n"); + spin_unlock_irq(&vscsi->rescan_lock); + return; + } + vscsi->next_target_id = 0; + shost_printk(KERN_INFO, sh, "rescan: start\n"); + spin_unlock_irq(&vscsi->rescan_lock); + queue_work(system_freezable_wq, &vscsi->rescan_work); +} + +int virtscsi_scan_finished(struct Scsi_Host *sh, unsigned long time)
+ shost_printk(KERN_INFO, sh, "rescan: %s finished\n", + ret ? "" : "not"); + return ret; +}
-- Mit freundlichen Grüßen / Kind regards Steffen Maier Linux on z Systems Development IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294