[PATCH] fix host number sysfs parsing

16 views
Skip to first unread message

Pete Wyckoff

unread,
May 4, 2008, 1:52:48 PM5/4/08
to Mike Christie, open-...@googlegroups.com
I need this on top of git head to be able to get status
from iscsi using 2.6.25-rc1. You'll probably want
to go looking for host in both sysfs paths, to handle
old and new kernels. Here's an example of how it works
in a recent one.

Others testing recent kernels may want to hack this
in temporarily.

Here are the error message from old iscsi utils,
iscsi-initiator-utils-6.2.0.868-0.3.fc9.x86_64.

aib01# iscsiadm -m session
iscsiadm: Could not get host for sid 1.
iscsiadm: could not get host_no for session 6.
iscsiadm: could not find session info for session1
iscsiadm: Can not get list of active sessions (6)

aib01# iscsiadm -m node -p 10.100.2.32,3260 -T aib02 -u
iscsiadm: Could not get host for sid 1.
iscsiadm: could not get host_no for session 6.
iscsiadm: could not find session info for session1

-- Pete


Sysfs layout changed yet again. Accommodate new kernels (2.6.25-rc1
at least), but probably break the parsing on older ones.

Signed-off-by: Pete Wyckoff <p...@osc.edu>
---
usr/iscsi_sysfs.c | 19 +++++++------------
1 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
index 7b65d6d..361eff0 100644
--- a/usr/iscsi_sysfs.c
+++ b/usr/iscsi_sysfs.c
@@ -279,7 +279,7 @@ void get_negotiated_session_conf(int sid,
uint32_t get_host_no_from_sid(uint32_t sid, int *err)
{
char *buf, *path, *tmp;
- uint32_t host_no;
+ uint32_t host_no = 0;

*err = 0;

@@ -290,28 +290,23 @@ uint32_t get_host_no_from_sid(uint32_t sid, int *err)
}
path = buf + PATH_MAX;

- sprintf(path, ISCSI_SESSION_DIR"/session%d/device", sid);
+ sprintf(path, ISCSI_SESSION_DIR"/session%d", sid);
if (readlink(path, buf, PATH_MAX) < 0) {
log_error("Could not get link for %s.", path);
*err = errno;
goto free_buf;
}

- /* buf will be .....bus_info/hostX/sessionY */
+ /* buf will be ../../devices/platform/hostX/sessionY/iscsi_session/sessionY */

/* find hostX */
- tmp = strrchr(buf, '/');
- *tmp = '\0';
-
- /* find bus and increment past it */
- tmp = strrchr(buf, '/');
- tmp++;
-
- if (sscanf(tmp, "host%u", &host_no) != 1) {
- log_error("Could not get host for sid %u.", sid);
+ tmp = strstr(buf, "host");
+ if (tmp == NULL) {
+ log_error("could not find host in session link %s", buf);
*err = ENXIO;
goto free_buf;
}
+ host_no = atoi(tmp + 4);

free_buf:
free(buf);
--
1.5.4.1

Mike Christie

unread,
May 5, 2008, 1:36:22 PM5/5/08
to open-...@googlegroups.com
Pete Wyckoff wrote:
> I need this on top of git head to be able to get status
> from iscsi using 2.6.25-rc1. You'll probably want
> to go looking for host in both sysfs paths, to handle
> old and new kernels. Here's an example of how it works
> in a recent one.
>
> Others testing recent kernels may want to hack this
> in temporarily.
>
> Here are the error message from old iscsi utils,
> iscsi-initiator-utils-6.2.0.868-0.3.fc9.x86_64.
>
> aib01# iscsiadm -m session
> iscsiadm: Could not get host for sid 1.
> iscsiadm: could not get host_no for session 6.
> iscsiadm: could not find session info for session1
> iscsiadm: Can not get list of active sessions (6)
>
> aib01# iscsiadm -m node -p 10.100.2.32,3260 -T aib02 -u
> iscsiadm: Could not get host for sid 1.
> iscsiadm: could not get host_no for session 6.
> iscsiadm: could not find session info for session1
>
> -- Pete
>
>
> Sysfs layout changed yet again. Accommodate new kernels (2.6.25-rc1
> at least), but probably break the parsing on older ones.
>

Damn you sysfs! :) I am in the middle of trying to use udev's sysfs code
instead of our crap. I will send out a test patch later this week.

Thanks for the patch and the bug report.

Reply all
Reply to author
Forward
0 new messages