All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ankit Jain <jankit@suse.de>
To: linux-scsi <linux-scsi@vger.kernel.org>
Cc: James Bottomley <James.Bottomley@parallels.com>,
	Hannes Reinecke <hare@suse.de>
Subject: [PATCH] ses: Handle non-unique element descriptors
Date: Mon, 04 Jul 2011 20:46:22 +0530	[thread overview]
Message-ID: <4E11D946.4050307@suse.de> (raw)

Some SES devices give non-unique Element Descriptors as part of the
Element Descriptor diag page. Since we use these for creating sysfs
entries, they need to be unique.

Eg:
$ sg_ses -p 7 /dev/sg0
  FTS CORP  TXS6_SAS20BPX12   0500
    enclosure services device
Element descriptor In diagnostic page:
  generation code: 0x0
  element descriptor by type list
    Element type: Array device, subenclosure id: 0
      Overall descriptor: ArrayDevicesInSubEnclsr0
      Element 1 descriptor: ArrayDevice00
      Element 2 descriptor: ArrayDevice01
      Element 3 descriptor: ArrayDevice02
      Element 4 descriptor: ArrayDevice03
      Element 5 descriptor: ArrayDevice03
      Element 6 descriptor: ArrayDevice03
      Element 7 descriptor: ArrayDevice03
      Element 8 descriptor: ArrayDevice03
      Element 9 descriptor: ArrayDevice03
      Element 10 descriptor: ArrayDevice03
      Element 11 descriptor: ArrayDevice03
      Element 12 descriptor: ArrayDevice03

Based on scsi-misc

Signed-off-by: Ankit Jain <jankit@suse.de>

---
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 00e5fca..8087055 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -239,6 +239,24 @@ static void enclosure_component_release(struct device *dev)
 	put_device(dev->parent);
 }
 
+struct enclosure_component *
+enclosure_component_find_by_name(struct enclosure_device *edev,
+				const char *name)
+{
+	int i;
+	if (!edev || !name || !name[0])
+		return NULL;
+
+	for (i=0; i<edev->components; i++) {
+		struct enclosure_component *ecomp = &edev->component[i];
+		if (ecomp->number != -1 && !strcmp(dev_name(&ecomp->cdev), name))
+			return ecomp;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(enclosure_component_find_by_name);
+
 static const struct attribute_group *enclosure_groups[];
 
 /**
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index eba183c..abfd962 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -421,12 +421,17 @@ static void ses_enclosure_data_process(struct enclosure_device *edev,
 			if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
 			    type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE) {
 
-				if (create)
+				if (create) {
+					if (enclosure_component_find_by_name(edev, name))
+						/* name is not unique, already used
+						 * set to NULL, so that enclosure_component_register
+						 * will assign us a new one */
+						name = NULL;
 					ecomp =	enclosure_component_register(edev,
 									     components++,
 									     type_ptr[0],
 									     name);
-				else
+				} else
 					ecomp = &edev->component[components++];
 
 				if (!IS_ERR(ecomp) && addl_desc_ptr)
diff --git a/include/linux/enclosure.h b/include/linux/enclosure.h
index 9a33c5f..7e48ba9 100644
--- a/include/linux/enclosure.h
+++ b/include/linux/enclosure.h
@@ -122,6 +122,8 @@ void enclosure_unregister(struct enclosure_device *);
 struct enclosure_component *
 enclosure_component_register(struct enclosure_device *, unsigned int,
 				 enum enclosure_component_type, const char *);
+struct enclosure_component *
+enclosure_component_find_by_name(struct enclosure_device *, const char *);
 int enclosure_add_device(struct enclosure_device *enclosure, int component,
 			 struct device *dev);
 int enclosure_remove_device(struct enclosure_device *, struct device *);
-- 
Ankit Jain
SUSE Labs

             reply	other threads:[~2011-07-04 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-04 15:16 Ankit Jain [this message]
2011-07-04 15:35 ` [PATCH] ses: Handle non-unique element descriptors James Bottomley
2011-07-04 22:59   ` Ankit Jain
2011-07-04 23:00     ` James Bottomley
2011-07-11 10:24       ` Ankit Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E11D946.4050307@suse.de \
    --to=jankit@suse.de \
    --cc=James.Bottomley@parallels.com \
    --cc=hare@suse.de \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.