[PATCH 2/3] scsi: create an all-one filter for scanners
From: Paolo Bonzini
Date: Sat Nov 10 2018 - 11:35:46 EST
Any command is allowed for scanners when /dev/sg is used.
Reimplement this using customizable command filters, so that the
sysfs knobs will work in this case, too.
Cc: linux-scsi@xxxxxxxxxxxxxxx
Cc: Hannes Reinecke <hare@xxxxxxxx>
Cc: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
Cc: James Bottomley <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
drivers/scsi/scsi_scan.c | 13 +++++++++++++
drivers/scsi/sg.c | 3 ---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 78ca63dfba4a..ceb7f5535f44 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -844,6 +844,19 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
*bflags |= BLIST_NOREPORTLUN;
}
+ if (sdev->type == TYPE_SCANNER) {
+ sdev->request_queue->cmd_filter =
+ kzalloc(sizeof(struct blk_cmd_filter), GFP_KERNEL);
+
+ if (!sdev->request_queue->cmd_filter)
+ return SCSI_SCAN_NO_RESPONSE;
+
+ memset(sdev->request_queue->cmd_filter->read_ok, 0xFF,
+ sizeof(sdev->request_queue->cmd_filter->read_ok));
+ memset(sdev->request_queue->cmd_filter->write_ok, 0xFF,
+ sizeof(sdev->request_queue->cmd_filter->write_ok));
+ }
+
/*
* For a peripheral qualifier (PQ) value of 1 (001b), the SCSI
* spec says: The device server is capable of supporting the
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 1b04016d3bb8..e04acf41f283 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -242,9 +242,6 @@ static int sg_allow_access(struct file *filp, unsigned char *cmd)
struct sg_fd *sfp = filp->private_data;
struct scsi_device *device = sfp->parentdp->device;
- if (device->type == TYPE_SCANNER)
- return 0;
-
return blk_verify_command(device->request_queue, cmd, filp->f_mode);
}
--
1.8.3.1