From: Chris Lalancette Date: Mon, 3 Nov 2008 11:37:11 +0000 (+0000) Subject: Give iSCSI and disk storage backend drivers the X-Git-Tag: LIBVIRT_0_5_0~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17a9e03cd17813e93f78a3b6071dd6ee739a10e0;p=thirdparty%2Flibvirt.git Give iSCSI and disk storage backend drivers the ability to resolve any kind of volume path to the pool target volume path. For instance, if the pool was defined with a /dev/disk/by-id section, and one of the volumes is /dev/disk/by-id/scsi-S_beaf11, then you would be able to call virStorageVolLookupByPath("/dev/sdc"), and get the correct volume back. Signed-off-by: Chris Lalancette --- diff --git a/ChangeLog b/ChangeLog index 63f27651c1..2f16de29b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Mon Nov 03 12:37:00 CET 2008 Chris Lalancette + * src/storage_backend.c src/storage_backend.h + src/storage_backend_disk.c src/storage_backend_iscsi.c + src/storage_driver.c: Give iSCSI and disk storage backend drivers the + ability to resolve any kind of volume path to the pool target volume + path. For instance, if the pool was defined with a + /dev/disk/by-id section, and one of the + volumes is /dev/disk/by-id/scsi-S_beaf11, then you would be able to + call virStorageVolLookupByPath("/dev/sdc"), and get the correct volume + back. + Fri Oct 31 14:55:46 CET 2008 Daniel Veillard * python/virConnect.py: needed for events from the python bindings diff --git a/src/storage_backend.c b/src/storage_backend.c index 1f4ed10a72..b8772ff006 100644 --- a/src/storage_backend.c +++ b/src/storage_backend.c @@ -357,16 +357,17 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn, char * virStorageBackendStablePath(virConnectPtr conn, virStoragePoolObjPtr pool, - char *devpath) + const char *devpath) { DIR *dh; struct dirent *dent; + char *stablepath; /* Short circuit if pool has no target, or if its /dev */ if (pool->def->target.path == NULL || STREQ(pool->def->target.path, "/dev") || STREQ(pool->def->target.path, "/dev/")) - return devpath; + goto ret_strdup; /* The pool is pointing somewhere like /dev/disk/by-path * or /dev/disk/by-id, so we need to check all symlinks in @@ -382,7 +383,6 @@ virStorageBackendStablePath(virConnectPtr conn, } while ((dent = readdir(dh)) != NULL) { - char *stablepath; if (dent->d_name[0] == '.') continue; @@ -407,10 +407,17 @@ virStorageBackendStablePath(virConnectPtr conn, closedir(dh); + ret_strdup: /* Couldn't find any matching stable link so give back * the original non-stable dev path */ - return devpath; + + stablepath = strdup(devpath); + + if (stablepath == NULL) + virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("dup path")); + + return stablepath; } diff --git a/src/storage_backend.h b/src/storage_backend.h index ff7614cf30..46311c60e5 100644 --- a/src/storage_backend.h +++ b/src/storage_backend.h @@ -50,6 +50,7 @@ enum { VIR_STORAGE_BACKEND_POOL_SOURCE_DIR = (1<<2), VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER = (1<<3), VIR_STORAGE_BACKEND_POOL_SOURCE_NAME = (1<<4), + VIR_STORAGE_BACKEND_POOL_STABLE_PATH = (1<<5), }; enum partTableType { @@ -138,7 +139,7 @@ int virStorageBackendUpdateVolInfoFD(virConnectPtr conn, char *virStorageBackendStablePath(virConnectPtr conn, virStoragePoolObjPtr pool, - char *devpath); + const char *devpath); typedef int (*virStorageBackendListVolRegexFunc)(virConnectPtr conn, virStoragePoolObjPtr pool, diff --git a/src/storage_backend_disk.c b/src/storage_backend_disk.c index b835cf011d..b2768ca31b 100644 --- a/src/storage_backend_disk.c +++ b/src/storage_backend_disk.c @@ -109,8 +109,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn, devpath)) == NULL) return -1; - if (devpath != vol->target.path) - VIR_FREE(devpath); + VIR_FREE(devpath); } if (vol->key == NULL) { @@ -447,7 +446,8 @@ virStorageBackend virStorageBackendDisk = { .deleteVol = virStorageBackendDiskDeleteVol, .poolOptions = { - .flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE), + .flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE| + VIR_STORAGE_BACKEND_POOL_STABLE_PATH), .defaultFormat = VIR_STORAGE_POOL_DISK_UNKNOWN, .formatFromString = virStorageBackendPartTableTypeFromString, .formatToString = virStorageBackendPartTableTypeToString, diff --git a/src/storage_backend_iscsi.c b/src/storage_backend_iscsi.c index decb736890..bc71eb605f 100644 --- a/src/storage_backend_iscsi.c +++ b/src/storage_backend_iscsi.c @@ -219,8 +219,7 @@ virStorageBackendISCSINewLun(virConnectPtr conn, virStoragePoolObjPtr pool, devpath)) == NULL) goto cleanup; - if (devpath != vol->target.path) - VIR_FREE(devpath); + VIR_FREE(devpath); if (virStorageBackendUpdateVolInfoFD(conn, vol, fd, 1) < 0) goto cleanup; @@ -645,7 +644,8 @@ virStorageBackend virStorageBackendISCSI = { .poolOptions = { .flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_HOST | - VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE) + VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE | + VIR_STORAGE_BACKEND_POOL_STABLE_PATH) }, .volType = VIR_STORAGE_VOL_BLOCK, diff --git a/src/storage_driver.c b/src/storage_driver.c index 0773821070..bced52e385 100644 --- a/src/storage_driver.c +++ b/src/storage_driver.c @@ -966,8 +966,34 @@ storageVolumeLookupByPath(virConnectPtr conn, for (i = 0 ; i < driver->pools.count ; i++) { if (virStoragePoolObjIsActive(driver->pools.objs[i])) { - virStorageVolDefPtr vol = - virStorageVolDefFindByPath(driver->pools.objs[i], path); + virStorageVolDefPtr vol; + virStorageBackendPoolOptionsPtr options; + + options = virStorageBackendPoolOptionsForType(driver->pools.objs[i]->def->type); + if (options == NULL) + continue; + + if (options->flags & VIR_STORAGE_BACKEND_POOL_STABLE_PATH) { + const char *stable_path; + + stable_path = virStorageBackendStablePath(conn, + driver->pools.objs[i], + path); + /* + * virStorageBackendStablePath already does + * virStorageReportError if it fails; we just need to keep + * propagating the return code + */ + if (stable_path == NULL) + return NULL; + + vol = virStorageVolDefFindByPath(driver->pools.objs[i], + stable_path); + VIR_FREE(stable_path); + } + else + vol = virStorageVolDefFindByPath(driver->pools.objs[i], path); + if (vol) return virGetStorageVol(conn,