linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: neilb@suse.de
Cc: linux-raid@vger.kernel.org, marcin.labun@intel.com,
	ed.ciechanowski@intel.com
Subject: [PATCH 4/9] sysfs: fix sysfs_disk_to_scsi_id
Date: Thu, 25 Aug 2011 19:14:19 -0700	[thread overview]
Message-ID: <20110826021419.28015.64805.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20110826020908.28015.52384.stgit@localhost6.localdomain6>

Not sure how this ever worked, but now we just try to parse a directory
name that looks like <host>:<bus>:<target>:<lun>.

Array creation segfaults on Fedora 14 without this.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 sysfs.c |   30 ++++++++++--------------------
 1 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/sysfs.c b/sysfs.c
index 56813b7..2146264 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -709,9 +709,9 @@ int sysfs_disk_to_scsi_id(int fd, __u32 *id)
 	/* from an open block device, try to retrieve it scsi_id */
 	struct stat st;
 	char path[256];
-	char *c1, *c2;
 	DIR *dir;
 	struct dirent *de;
+	int host, bus, target, lun;
 
 	if (fstat(fd, &st))
 		return 1;
@@ -723,32 +723,22 @@ int sysfs_disk_to_scsi_id(int fd, __u32 *id)
 	if (!dir)
 		return 1;
 
-	de = readdir(dir);
-	while (de) {
-		if (strchr(de->d_name, ':'))
+	for (de = readdir(dir); de; de = readdir(dir)) {
+		int count;
+
+		if (de->d_type != DT_DIR)
+			continue;
+
+		count = sscanf(de->d_name, "%d:%d:%d:%d", &host, &bus, &target, &lun);
+		if (count == 4)
 			break;
-		de = readdir(dir);
 	}
 	closedir(dir);
 
 	if (!de)
 		return 1;
 
-	c1 = de->d_name;
-	c2 = strchr(c1, ':');
-	*c2 = '\0';
-	*id = strtol(c1, NULL, 10) << 24; /* host */
-	c1 = c2 + 1;
-	c2 = strchr(c1, ':');
-	*c2 = '\0';
-	*id |= strtol(c1, NULL, 10) << 16; /* bus */
-	c1 = c2 + 1;
-	c2 = strchr(c1, ':');
-	*c2 = '\0';
-	*id |= strtol(c1, NULL, 10) << 8; /* target */
-	c1 = c2 + 1;
-	*id |= strtol(c1, NULL, 10); /* lun */
-
+	*id = (host << 24) | (bus << 16) | (target << 8) | (lun << 0);
 	return 0;
 }
 


  parent reply	other threads:[~2011-08-26  2:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26  2:13 [PATCH 0/9] recovering an imsm raid5 array Dan Williams
2011-08-26  2:14 ` [PATCH 1/9] imsm: fix max disks per array Dan Williams
2011-08-26  2:14 ` [PATCH 2/9] imsm: fix, stop metadata updates to newly failed devices Dan Williams
2011-08-26  2:14 ` [PATCH 3/9] imsm: fix display spares Dan Williams
2011-08-26  2:14 ` Dan Williams [this message]
2011-08-26  2:14 ` [PATCH 5/9] imsm: fix reserved sectors for spares Dan Williams
2011-08-26 19:51   ` Williams, Dan J
2011-08-30  2:20     ` NeilBrown
2011-09-06 20:42       ` Williams, Dan J
2011-09-19 12:57         ` Czarnowska, Anna
2011-09-21  4:45           ` NeilBrown
2011-08-26  2:14 ` [PATCH 6/9] mdmon: fix, close spare activation race Dan Williams
2011-08-26  2:14 ` [PATCH 7/9] imsm: support 'missing' devices at Create Dan Williams
2011-08-30  2:26   ` NeilBrown
2011-08-26  2:14 ` [PATCH 8/9] util: allow regular files through test_partition() Dan Williams
2011-08-26  2:14 ` [PATCH 9/9] mdadm: 'dump' support Dan Williams
2011-08-30  2:58   ` NeilBrown
2011-08-30 10:12     ` Alexander Kühn
2013-05-16  5:11       ` NeilBrown
2011-08-26 11:06 ` [PATCH 0/9] recovering an imsm raid5 array linbloke
2011-08-30  3:13 ` NeilBrown

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=20110826021419.28015.64805.stgit@localhost6.localdomain6 \
    --to=dan.j.williams@intel.com \
    --cc=ed.ciechanowski@intel.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=marcin.labun@intel.com \
    --cc=neilb@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).