From 08b9144b413059dfd2edb95647e08d2120d60b85 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Mar 27 2008 19:18:59 +0000 Subject: Add a couple of iscsi patches to the storage backend; without these two patches, iscsi storage support is incomplete (and won't work properly). --- diff --git a/libvirt-iscsi-sysfs4.patch b/libvirt-iscsi-sysfs4.patch new file mode 100644 index 0000000..4ebb0e5 --- /dev/null +++ b/libvirt-iscsi-sysfs4.patch @@ -0,0 +1,146 @@ +--- a/src/storage_backend_iscsi.c 4 Mar 2008 20:02:34 -0000 1.3 ++++ b/src/storage_backend_iscsi.c 26 Mar 2008 22:07:05 -0000 +@@ -170,20 +170,91 @@ + virStorageBackendISCSIMakeLUN(virConnectPtr conn, + virStoragePoolObjPtr pool, + char **const groups, +- void *data ATTRIBUTE_UNUSED) ++ void *data) + { + virStorageVolDefPtr vol; + int fd = -1; ++ unsigned int target, channel, id, lun; + char lunid[100]; +- char *dev = groups[4]; + int opentries = 0; + char *devpath = NULL; ++ char *session = data; ++ char sysfs_path[PATH_MAX]; ++ char *dev = NULL; ++ DIR *sysdir; ++ struct dirent *block_dirent; ++ struct stat sbuf; ++ int len; ++ ++ if ((virStrToLong_ui(groups[0], NULL, 10, &target) < 0) || ++ (virStrToLong_ui(groups[1], NULL, 10, &channel) < 0) || ++ (virStrToLong_ui(groups[2], NULL, 10, &id) < 0) || ++ (virStrToLong_ui(groups[3], NULL, 10, &lun) < 0)) { ++ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", ++ _("Failed parsing iscsiadm commands")); ++ return -1; ++ } ++ ++ if (lun == 0) { ++ /* the 0'th LUN isn't a real LUN, it's just a control LUN; skip it */ ++ return 0; ++ } ++ ++ snprintf(sysfs_path, PATH_MAX, ++ "/sys/class/iscsi_session/session%s/device/" ++ "target%d:%d:%d/%d:%d:%d:%d/block", ++ session, target, channel, id, target, channel, id, lun); ++ ++ if (stat(sysfs_path, &sbuf) < 0) { ++ /* block path in subdir didn't exist; this is unexpected, so fail */ ++ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, ++ _("Failed to find the sysfs path for %d:%d:%d:%d: %s"), ++ target, channel, id, lun, strerror(errno)); ++ return -1; ++ } ++ ++ sysdir = opendir(sysfs_path); ++ if (sysdir == NULL) { ++ /* we failed for some reason; return an error */ ++ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, ++ _("Failed to opendir sysfs path %s: %s"), ++ sysfs_path, strerror(errno)); ++ return -1; ++ } ++ ++ while ((block_dirent = readdir(sysdir)) != NULL) { ++ len = strlen(block_dirent->d_name); ++ if ((len == 1 && block_dirent->d_name[0] == '.') || ++ (len == 2 && block_dirent->d_name[0] == '.' && block_dirent->d_name[1] == '.')) { ++ /* the . and .. directories; just skip them */ ++ continue; ++ } ++ ++ /* OK, not . or ..; let's see if it is a SCSI device */ ++ if (len > 2 && ++ block_dirent->d_name[0] == 's' && ++ block_dirent->d_name[1] == 'd') { ++ /* looks like a scsi device, smells like scsi device; it must be ++ a scsi device */ ++ dev = strdup(block_dirent->d_name); ++ break; ++ } ++ } ++ closedir(sysdir); ++ ++ if (dev == NULL) { ++ /* we didn't find the sd? device we were looking for; fail */ ++ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, ++ _("Failed to find SCSI device for %d:%d:%d:%d: %s"), ++ target, channel, id, lun, strerror(errno)); ++ return -1; ++ } + + snprintf(lunid, sizeof(lunid)-1, "lun-%s", groups[3]); + + if ((vol = calloc(1, sizeof(virStorageVolDef))) == NULL) { + virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume")); +- return -1; ++ goto cleanup; + } + + if ((vol->name = strdup(lunid)) == NULL) { +@@ -197,6 +268,8 @@ + } + strcpy(devpath, "/dev/"); + strcat(devpath, dev); ++ free(dev); ++ dev = NULL; + /* It can take a little while between logging into the ISCSI + * server and udev creating the /dev nodes, so if we get ENOENT + * we must retry a few times - they should eventually appear. +@@ -258,6 +331,7 @@ + if (fd != -1) close(fd); + free(devpath); + virStorageVolDefFree(vol); ++ free(dev); + return -1; + } + +@@ -281,14 +355,13 @@ + * scsi1 Channel 00 Id 0 Lun: 5 + * Attached scsi disk sdg State: running + * +- * Need 2 regex to match alternating lines ++ * Need a regex to match the Channel:Id:Lun lines + */ + const char *regexes[] = { +- "^\\s*scsi(\\S+)\\s+Channel\\s+(\\S+)\\s+Id\\s+(\\S+)\\s+Lun:\\s+(\\S+)\\s*$", +- "^\\s*Attached\\s+scsi\\s+disk\\s+(\\S+)\\s+State:\\s+running\\s*$" ++ "^\\s*scsi(\\S+)\\s+Channel\\s+(\\S+)\\s+Id\\s+(\\S+)\\s+Lun:\\s+(\\S+)\\s*$" + }; + int vars[] = { +- 4, 1 ++ 4 + }; + const char *prog[] = { + ISCSIADM, "--mode", "session", "-r", session, "-P", "3", NULL, +@@ -296,11 +369,11 @@ + + return virStorageBackendRunProgRegex(conn, pool, + prog, +- 2, ++ 1, + regexes, + vars, + virStorageBackendISCSIMakeLUN, +- NULL); ++ (void *)session); + } + + diff --git a/libvirt-storage-api-iscsi-sendtarget.patch b/libvirt-storage-api-iscsi-sendtarget.patch new file mode 100644 index 0000000..31e6a9d --- /dev/null +++ b/libvirt-storage-api-iscsi-sendtarget.patch @@ -0,0 +1,17 @@ +--- /home/boston/clalance/devel/libvirt--devel/src/storage_backend_iscsi.c 2008-02-13 13:48:32.497466000 -0500 ++++ libvirt-0.4.0/src/storage_backend_iscsi.c 2008-02-11 17:19:35.000000000 -0500 +@@ -143,6 +143,14 @@ static int virStorageBackendISCSIConnect + "--targetname", pool->def->source.devices[0].path, action, NULL + }; + ++ const char *cmdsendtarget[] = { ++ ISCSIADM, "--mode", "discovery", "--type", "sendtargets", ++ "--portal", portal, NULL ++ }; ++ ++ if (virRun(conn, (char **)cmdsendtarget, NULL) < 0) ++ return -1; ++ + if (virRun(conn, (char **)cmdargv, NULL) < 0) + return -1; + diff --git a/libvirt.spec b/libvirt.spec index ecd4345..86f8127 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -21,7 +21,7 @@ Summary: Library providing a simple API virtualization Name: libvirt Version: 0.4.1 -Release: 4%{?dist}%{?extra_release} +Release: 5%{?dist}%{?extra_release} License: LGPL Group: Development/Libraries Source: libvirt-%{version}.tar.gz @@ -31,6 +31,8 @@ Patch2: %{name}-%{version}-daemon-startup.patch Patch3: %{name}-%{version}-qemu-media-change.patch Patch4: %{name}-%{version}-xen-boot-device.patch Patch5: %{name}-%{version}-tap-ifname.patch +Patch6: libvirt-storage-api-iscsi-sendtarget.patch +Patch7: libvirt-iscsi-sysfs4.patch BuildRoot: %{_tmppath}/%{name}-%{version}-root URL: http://libvirt.org/ BuildRequires: python python-devel @@ -148,6 +150,8 @@ of recent versions of Linux (and other OSes). %patch3 -p1 %patch4 -p1 %patch5 -p1 +%patch6 -p1 +%patch7 -p1 %build # Xen is available only on i386 x86_64 ia64 @@ -291,6 +295,11 @@ fi %doc docs/examples/python %changelog +* Thu Mar 27 2008 Chris Lalancette - 0.4.1-5.fc9 +- Do iscsiadm sendtarget before trying to do login +- Do sysfs scanning for iSCSI LUNs instead of trying to parse them from + iscsiadm session output + * Thu Mar 13 2008 Daniel P. Berrange - 0.4.1-4.fc9 - Fix QEMU tap device setup - Fix Xen boot device XML processing