Skip to contentSkip to conversation

scsi_dh_alua: suppress errors from unsupported devices

PATCH In review Hannes Reinecke 2 participants 3 messages Aug 8, 2017 – Aug 10, 2017 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi_dh_alua: suppress errors from unsupported devices

ALUA is only relevant for disk-like devices, so we shouldn't be printing out warning messages for other device types.

---
 drivers/scsi/device_handler/scsi_dh_alua.c |  2 ++
 drivers/scsi/scsi_dh.c                     | 15 +++++++++------
 drivers/scsi/scsi_priv.h                   |  2 +-
 drivers/scsi/scsi_sysfs.c                  |  8 +-------
 4 files changed, 13 insertions(+), 14 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +2 -0
index 0962fd5..c3aea06 100644
@@ -1100,6 +1100,8 @@ static int alua_bus_attach(struct scsi_device *sdev)
 	err = alua_initialize(sdev, h);
 	if (err == SCSI_DH_NOMEM)
 		ret = -ENOMEM;
+	if (err == SCSI_DH_DEV_UNSUPP)
+		ret = -ENODEV;
 	if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
 		goto failed;
 
drivers/scsi/scsi_dh.c +9 -6
index 84addee..df521aba 100644
@@ -133,8 +133,9 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
 
 	error = scsi_dh->attach(sdev);
 	if (error) {
-		sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
-			    scsi_dh->name, error);
+		if (error != -ENODEV)
+			sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
+				    scsi_dh->name, error);
 		module_put(scsi_dh->module);
 	} else
 		sdev->handler = scsi_dh;
@@ -153,18 +154,20 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev)
 	module_put(sdev->handler->module);
 }
 
-int scsi_dh_add_device(struct scsi_device *sdev)
+void scsi_dh_add_device(struct scsi_device *sdev)
 {
 	struct scsi_device_handler *devinfo = NULL;
 	const char *drv;
-	int err = 0;
 
 	drv = scsi_dh_find_driver(sdev);
 	if (drv)
 		devinfo = __scsi_dh_lookup(drv);
+	/*
+	 * device_handler is optional, so ignore errors
+	 * from scsi_dh_handler_attach()
+	 */
 	if (devinfo)
-		err = scsi_dh_handler_attach(sdev, devinfo);
-	return err;
+		scsi_dh_handler_attach(sdev, devinfo);
 }
 
 void scsi_dh_release_device(struct scsi_device *sdev)
drivers/scsi/scsi_priv.h +1 -1
index c11c1f9c..f2925a2 100644
@@ -176,7 +176,7 @@ static inline void scsi_autopm_put_host(struct Scsi_Host *h) {}
 
 /* scsi_dh.c */
 #ifdef CONFIG_SCSI_DH
-int scsi_dh_add_device(struct scsi_device *sdev);
+void scsi_dh_add_device(struct scsi_device *sdev);
 void scsi_dh_release_device(struct scsi_device *sdev);
 #else
 static inline int scsi_dh_add_device(struct scsi_device *sdev) { return 0; }
drivers/scsi/scsi_sysfs.c +1 -7
index d6984df..a8d3f8b 100644
@@ -1221,13 +1221,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
 
 	scsi_autopm_get_device(sdev);
 
-	error = scsi_dh_add_device(sdev);
-	if (error)
-		/*
-		 * device_handler is optional, so any error can be ignored
-		 */
-		sdev_printk(KERN_INFO, sdev,
-				"failed to add device handler: %d\n", error);
+	scsi_dh_add_device(sdev);
 
 	error = device_add(&sdev->sdev_gendev);
 	if (error) {
Signature · 1 line
1.8.5.6
#1 lore raw

drivers/scsi/device_handler/scsi_dh_alua.c static int alua_bus_attach(struct scsi_device *sdev) · line 1106

Quoted 11 lines

index 0962fd5..c3aea06 100644

drivers/scsi/device_handler/scsi_dh_alua.c +2 -0
@@ -1100,6 +1100,8 @@ static int alua_bus_attach(struct scsi_device *sdev)
 	err = alua_initialize(sdev, h);
 	if (err == SCSI_DH_NOMEM)
 		ret = -ENOMEM;
+	if (err == SCSI_DH_DEV_UNSUPP)
+		ret = -ENODEV;
 	if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
 		goto failed;

This screams for a switch statement..

drivers/scsi/scsi_dh.c static int scsi_dh_handler_attach(struct scsi_device *sdev, · line 139

Quoted 12 lines
drivers/scsi/scsi_dh.c +3 -2
@@ -133,8 +133,9 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
 
 	error = scsi_dh->attach(sdev);
 	if (error) {
-		sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
-			    scsi_dh->name, error);
+		if (error != -ENODEV)
+			sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
+				    scsi_dh->name, error);
 		module_put(scsi_dh->module);

OTOH why don't we just return the SCSI_DH_ values from ->attach?

#2 lore raw
Quoted 18 lines · Christoph Hellwig

drivers/scsi/device_handler/scsi_dh_alua.c static int alua_bus_attach(struct scsi_device *sdev) · line 1106

Quoted 11 lines

index 0962fd5..c3aea06 100644

drivers/scsi/device_handler/scsi_dh_alua.c +2 -0
@@ -1100,6 +1100,8 @@ static int alua_bus_attach(struct scsi_device *sdev)
 	err = alua_initialize(sdev, h);
 	if (err == SCSI_DH_NOMEM)
 		ret = -ENOMEM;
+	if (err == SCSI_DH_DEV_UNSUPP)
+		ret = -ENODEV;
 	if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
 		goto failed;

This screams for a switch statement..

Quoted 4 lines
drivers/scsi/scsi_dh.c +0 -0
@@ -133,8 +133,9 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
 
Quoted 11 lines

drivers/scsi/scsi_dh.c static int scsi_dh_handler_attach(struct scsi_device *sdev, · line 139

Quoted 8 lines
drivers/scsi/scsi_dh.c +3 -2
 	error = scsi_dh->attach(sdev);
 	if (error) {
-		sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
-			    scsi_dh->name, error);
+		if (error != -ENODEV)
+			sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
+				    scsi_dh->name, error);
 		module_put(scsi_dh->module);

OTOH why don't we just return the SCSI_DH_ values from ->attach?

Hmm. Not a bad idea. Let's see how it turns out.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)