All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] path_id: add handle_scsi_sas
@ 2010-06-25 12:28 harald
  2010-06-25 13:27 ` harald
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: harald @ 2010-06-25 12:28 UTC (permalink / raw)
  To: linux-hotplug

From: Harald Hoyer <harald@redhat.com>

based on code by Jim Garlick.
---
 extras/path_id/path_id.c |   64 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/extras/path_id/path_id.c b/extras/path_id/path_id.c
index dcee378..8dbdd30 100644
--- a/extras/path_id/path_id.c
+++ b/extras/path_id/path_id.c
@@ -121,7 +121,69 @@ out:
 
 static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
 {
-	return NULL;
+	struct udev *udev  = udev_device_get_udev(parent);
+	struct udev_device *end_dev;
+	struct udev_device *sasdev;
+	struct udev_device *phydev;
+	struct udev_device *parent_dev;
+	struct udev_device *child_dev;
+	char syspath[UTIL_PATH_SIZE], *base;
+	char phy_path[UTIL_PATH_SIZE];
+	const char *end_name, *name, *enc, *bay;
+	const char *port_path;
+	int scsi_host;
+	int num_phys = 8;
+	int i;
+
+	parent_dev = parent;
+	while (1) {
+		child_dev = parent_dev;
+		parent_dev = udev_device_get_parent(child_dev);
+		if (parent_dev = NULL)
+			return NULL;
+		name = udev_device_get_sysname(parent_dev);
+		if (strstr(name, "end_device-")) {
+			end_dev = parent_dev;
+			end_name = name;
+		} else if (sscanf(name, "host%d", &scsi_host)) {
+			port_path = udev_device_get_syspath(child_dev);
+			break;
+		}
+	}
+
+	base = strdup(udev_device_get_syspath(end_dev));
+	if (!base)
+		return NULL;
+	snprintf(syspath, sizeof(syspath), "%s/sas_device/%s", base, end_name);
+	free(base);
+
+	for (i = 0 ; i < num_phys ; i++) {
+		snprintf(phy_path, sizeof(phy_path), "%s/phy-%d:%d",
+				port_path, scsi_host, i);
+		if (phydev = udev_device_new_from_syspath(udev, phy_path)) {
+			udev_device_unref(phydev);
+			break;
+		}
+	}
+	if (i = num_phys)
+		return NULL;
+
+	sasdev = udev_device_new_from_syspath(udev, syspath);
+	if (sasdev = NULL) {
+		fprintf(stderr, "unable to access '%s'\n", syspath);
+		return NULL;
+	}
+	enc = udev_device_get_sysattr_value(sasdev, "enclosure_identifier");
+	bay = udev_device_get_sysattr_value(sasdev, "bay_identifier");
+	if (bay = NULL) {
+		parent = NULL;
+		goto out;
+	}
+
+	path_prepend(path, "sas-%s-%s-%s", strrchr(phy_path, '/') + 1, enc : "unknown", bay);
+out:
+	udev_device_unref(sasdev);
+	return parent;
 }
 
 static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path)
-- 
1.7.0.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] path_id: add handle_scsi_sas
  2010-06-25 12:28 [PATCH] path_id: add handle_scsi_sas harald
@ 2010-06-25 13:27 ` harald
  2010-06-25 13:29 ` Harald Hoyer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: harald @ 2010-06-25 13:27 UTC (permalink / raw)
  To: linux-hotplug

From: Harald Hoyer <harald@redhat.com>

based on code by Jim Garlick.
---
 extras/path_id/path_id.c |   64 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/extras/path_id/path_id.c b/extras/path_id/path_id.c
index dcee378..c3d241b 100644
--- a/extras/path_id/path_id.c
+++ b/extras/path_id/path_id.c
@@ -121,7 +121,69 @@ out:
 
 static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
 {
-	return NULL;
+	struct udev *udev  = udev_device_get_udev(parent);
+	struct udev_device *end_dev;
+	struct udev_device *sasdev;
+	struct udev_device *phydev;
+	struct udev_device *parent_dev;
+	struct udev_device *child_dev;
+	char syspath[UTIL_PATH_SIZE], *base;
+	char phy_path[UTIL_PATH_SIZE];
+	const char *end_name, *name, *enc, *bay;
+	const char *port_path;
+	int scsi_host;
+	int num_phys = 8;
+	int i;
+
+	parent_dev = parent;
+	while (1) {
+		child_dev = parent_dev;
+		parent_dev = udev_device_get_parent(child_dev);
+		if (parent_dev = NULL)
+			return NULL;
+		name = udev_device_get_sysname(parent_dev);
+		if (strstr(name, "end_device-")) {
+			end_dev = parent_dev;
+			end_name = name;
+		} else if (sscanf(name, "host%d", &scsi_host)) {
+			port_path = udev_device_get_syspath(child_dev);
+			break;
+		}
+	}
+
+	base = strdup(udev_device_get_syspath(end_dev));
+	if (!base)
+		return NULL;
+	snprintf(syspath, sizeof(syspath), "%s/sas_device/%s", base, end_name);
+	free(base);
+
+	for (i = 0 ; i < num_phys ; i++) {
+		snprintf(phy_path, sizeof(phy_path), "%s/phy-%d:%d",
+				port_path, scsi_host, i);
+		if (phydev = udev_device_new_from_syspath(udev, phy_path)) {
+			udev_device_unref(phydev);
+			break;
+		}
+	}
+	if (i = num_phys)
+		return NULL;
+
+	sasdev = udev_device_new_from_syspath(udev, syspath);
+	if (sasdev = NULL) {
+		fprintf(stderr, "unable to access '%s'\n", syspath);
+		return NULL;
+	}
+	enc = udev_device_get_sysattr_value(sasdev, "enclosure_identifier");
+	bay = udev_device_get_sysattr_value(sasdev, "bay_identifier");
+	if (bay = NULL) {
+		parent = NULL;
+		goto out;
+	}
+
+	path_prepend(path, "sas-%s-%s-%s", strrchr(phy_path, '/') + 1, enc ? enc : "unknown", bay);
+out:
+	udev_device_unref(sasdev);
+	return parent;
 }
 
 static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path)
-- 
1.7.0.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] path_id: add handle_scsi_sas
  2010-06-25 12:28 [PATCH] path_id: add handle_scsi_sas harald
  2010-06-25 13:27 ` harald
@ 2010-06-25 13:29 ` Harald Hoyer
  2010-07-07 10:20 ` Hannes Reinecke
  2010-07-07 12:05 ` Kay Sievers
  3 siblings, 0 replies; 5+ messages in thread
From: Harald Hoyer @ 2010-06-25 13:29 UTC (permalink / raw)
  To: linux-hotplug

On 06/25/2010 02:28 PM, harald@redhat.com wrote:
> +	path_prepend(path, "sas-%s-%s-%s", strrchr(phy_path, '/') + 1, enc : "unknown", bay);

copy & paste error here... revised patch follows

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] path_id: add handle_scsi_sas
  2010-06-25 12:28 [PATCH] path_id: add handle_scsi_sas harald
  2010-06-25 13:27 ` harald
  2010-06-25 13:29 ` Harald Hoyer
@ 2010-07-07 10:20 ` Hannes Reinecke
  2010-07-07 12:05 ` Kay Sievers
  3 siblings, 0 replies; 5+ messages in thread
From: Hannes Reinecke @ 2010-07-07 10:20 UTC (permalink / raw)
  To: linux-hotplug

harald@redhat.com wrote:
> From: Harald Hoyer <harald@redhat.com>
> 
> based on code by Jim Garlick.
> ---
>  extras/path_id/path_id.c |   64 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 63 insertions(+), 1 deletions(-)
> 
> diff --git a/extras/path_id/path_id.c b/extras/path_id/path_id.c
> index dcee378..c3d241b 100644
> --- a/extras/path_id/path_id.c
> +++ b/extras/path_id/path_id.c
> @@ -121,7 +121,69 @@ out:
>  
>  static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
>  {
> -	return NULL;
> +	struct udev *udev  = udev_device_get_udev(parent);
> +	struct udev_device *end_dev;
> +	struct udev_device *sasdev;
> +	struct udev_device *phydev;
> +	struct udev_device *parent_dev;
> +	struct udev_device *child_dev;
> +	char syspath[UTIL_PATH_SIZE], *base;
> +	char phy_path[UTIL_PATH_SIZE];
> +	const char *end_name, *name, *enc, *bay;
> +	const char *port_path;
> +	int scsi_host;
> +	int num_phys = 8;
> +	int i;
> +
> +	parent_dev = parent;
> +	while (1) {
> +		child_dev = parent_dev;
> +		parent_dev = udev_device_get_parent(child_dev);
> +		if (parent_dev = NULL)
> +			return NULL;
> +		name = udev_device_get_sysname(parent_dev);
> +		if (strstr(name, "end_device-")) {
> +			end_dev = parent_dev;
> +			end_name = name;
> +		} else if (sscanf(name, "host%d", &scsi_host)) {
> +			port_path = udev_device_get_syspath(child_dev);
> +			break;
> +		}
> +	}
> +
This is wrong. The whole idea of path_id is that the path traversal is done
in one common loop, from which there are callouts to the individual device
handlers.

So we should be having one sas_end_device_handler and one sas_host handler.

I'll see to come up with an updated version.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] path_id: add handle_scsi_sas
  2010-06-25 12:28 [PATCH] path_id: add handle_scsi_sas harald
                   ` (2 preceding siblings ...)
  2010-07-07 10:20 ` Hannes Reinecke
@ 2010-07-07 12:05 ` Kay Sievers
  3 siblings, 0 replies; 5+ messages in thread
From: Kay Sievers @ 2010-07-07 12:05 UTC (permalink / raw)
  To: linux-hotplug

On Wed, Jul 7, 2010 at 12:20, Hannes Reinecke <hare@suse.de> wrote:
> This is wrong. The whole idea of path_id is that the path traversal is done
> in one common loop, from which there are callouts to the individual device
> handlers.

If you get a working update, please also remove the "unknown" stuff
from the returned string.

We must not return anything we are not entirely sure about, and the
strings must never change when something becomes "known" in the future
with some kernel/driver/sysfs update or anything similar.

In all such cases we better return nothing, than some random stuff we
can not keep reasonable stable.

Thanks,
Kay

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-07-07 12:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-25 12:28 [PATCH] path_id: add handle_scsi_sas harald
2010-06-25 13:27 ` harald
2010-06-25 13:29 ` Harald Hoyer
2010-07-07 10:20 ` Hannes Reinecke
2010-07-07 12:05 ` Kay Sievers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.