On 02/19/2016 08:10 PM, Bart Van Assche wrote:
On 02/19/2016 12:17 AM, Hannes Reinecke wrote:
+static ssize_t
+sdev_show_access_state(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct scsi_device *sdev = to_scsi_device(dev);
+ unsigned char access_state;
+ const char *access_state_name;
+ bool pref = false;
+
+ if (!sdev->handler)
+ return -EINVAL;
+
+ if (sdev->access_state & SCSI_ACCESS_STATE_PREFERRED)
+ pref = true;
+
+ access_state = (sdev->access_state & SCSI_ACCESS_STATE_MASK);
+ access_state_name = scsi_access_state_name(access_state);
+
+ return snprintf(buf, 32, "%s%s\n",
+ access_state_name ? access_state_name : "unknown",
+ pref ? " preferred" : "");
+}
Hello Hannes,
What is inelegant about the above approach is that the access_state attribute
is added to all SCSI devices, whether or not a device handler has been attached,
and that reading that attribute doesn't fail for devices to which another handler
than the ALUA handler has been attached. How about the patch below, which moves
the access_state show handler to the scsi_dh_alua.c source file, where it belongs?
Actually, this was my first approach, but hch suggested moving it to
the generic code :-(
Also when using your suggestion the 'access_state' attribute will only
be created _after_ the 'ADD' uevent, making it impossible to use it from
udev events.
However, I'm currently working on using the 'is_visible' callback for
SCSI sysfs attributes for this; in theory it should be possible to
use 'sysfs_update_groups()' during scsi_add_lun() to blank out the
unsupported attributes.
Which I think might be the best approach here.
But probably not for this patch series; I'd rather have the alua update
in first as it took long enough.
If you're absolutely against it we can drop the 'access_state' patches
(ie patch 20-22) and have them folded into a separate patchset.
Cheers,
Hannes
--
Dr. Hannes Reinecke zSeries & Storage
hare@xxxxxxx +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html