diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 671b88ede3..f632edd55a 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -233,7 +233,7 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int fd = -1; int ret = -1; @@ -242,6 +242,8 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, gid_t gid; uid_t uid; + virCheckFlags(0, -1); + if ((fd = open(vol->target.path, O_RDWR)) < 0) { virReportSystemError(errno, _("cannot create path '%s'"), @@ -643,7 +645,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret = -1; char *create_tool; @@ -652,6 +654,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, bool do_encryption = (vol->target.encryption != NULL); unsigned long long int size_arg; + virCheckFlags(0, -1); + const char *type = virStorageFileFormatTypeToString(vol->target.format); const char *backingType = vol->backingStore.path ? virStorageFileFormatTypeToString(vol->backingStore.format) : NULL; @@ -847,12 +851,14 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int ret; char *size; virCommandPtr cmd; + virCheckFlags(0, -1); + if (inputvol) { virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot copy from volume with qcow-create")); diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 0b10d3694c..82b41efcda 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -1,7 +1,7 @@ /* * storage_backend_disk.c: storage backend for disk handling * - * Copyright (C) 2007-2008, 2010 Red Hat, Inc. + * Copyright (C) 2007-2008, 2010-2011 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -334,7 +334,7 @@ virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { /* eg parted /dev/sda mklabel msdos */ const char *prog[] = { @@ -347,6 +347,8 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, NULL, }; + virCheckFlags(0, -1); + if (virRun(prog, NULL) < 0) return -1; @@ -643,7 +645,7 @@ static int virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { char *part_num = NULL; char *devpath = NULL; @@ -652,6 +654,8 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, bool isDevMapperDevice; int rc = -1; + virCheckFlags(0, -1); + if (virFileResolveLink(vol->target.path, &devpath) < 0) { virReportSystemError(errno, _("Couldn't read volume target path '%s'"), diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index d87401fd36..b30e01edfd 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -212,7 +212,7 @@ cleanup: static char * virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { /* * # showmount --no-headers -e HOSTNAME @@ -241,6 +241,8 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE char *retval = NULL; unsigned int i; + virCheckFlags(0, NULL); + source = virStoragePoolDefParseSourceString(srcSpec, VIR_STORAGE_POOL_NETFS); if (!source) @@ -538,12 +540,14 @@ virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { int err, ret = -1; char *parent; char *p; + virCheckFlags(0, -1); + if ((parent = strdup(pool->def->target.path)) == NULL) { virReportOOMError(); goto error; @@ -755,8 +759,10 @@ virStorageBackendFileSystemStop(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendFileSystemDelete(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + /* XXX delete all vols first ? */ if (rmdir(pool->def->target.path) < 0) { @@ -806,9 +812,12 @@ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ int err; + virCheckFlags(0, -1); + if (inputvol) { virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -896,7 +905,10 @@ virStorageBackendFileSystemVolBuildFrom(virConnectPtr conn, virStoragePoolObjPtr pool, virStorageVolDefPtr vol, virStorageVolDefPtr inputvol, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(0, -1); + return _virStorageBackendFileSystemVolBuild(conn, pool, vol, inputvol); } @@ -907,8 +919,10 @@ static int virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { + virCheckFlags(0, -1); + if (unlink(vol->target.path) < 0) { /* Silently ignore failures where the vol has already gone away */ if (errno != ENOENT) { diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index 72887e3c71..7b8dc9746c 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -550,7 +550,7 @@ virStorageBackendISCSIScanTargets(const char *portal, static char * virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { virStoragePoolSourcePtr source = NULL; size_t ntargets = 0; @@ -564,6 +564,8 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, }; char *portal = NULL; + virCheckFlags(0, NULL); + if (!(source = virStoragePoolDefParseSourceString(srcSpec, list.type))) return NULL; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 4de5442ab9..5fe9a1f315 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -1,7 +1,7 @@ /* * storage_backend_logical.c: storage backend for logical volume handling * - * Copyright (C) 2007-2009 Red Hat, Inc. + * Copyright (C) 2007-2009, 2011 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -294,7 +294,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_ static char * virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, const char *srcSpec ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { /* * # pvs --noheadings -o pv_name,vg_name @@ -313,6 +313,8 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolSourceList sourceList; int i; + virCheckFlags(0, NULL); + /* * NOTE: ignoring errors here; this is just to "touch" any logical volumes * that might be hanging around, so if this fails for some reason, the @@ -382,13 +384,15 @@ virStorageBackendLogicalStartPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { const char **vgargv; const char *pvargv[3]; int n = 0, i, fd; char zeros[PV_BLANK_SECTOR_SIZE]; + virCheckFlags(0, -1); + memset(zeros, 0, sizeof(zeros)); if (VIR_ALLOC_N(vgargv, 3 + pool->def->source.ndevice) < 0) { @@ -518,7 +522,7 @@ virStorageBackendLogicalStopPool(virConnectPtr conn ATTRIBUTE_UNUSED, static int virStorageBackendLogicalDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { const char *cmdargv[] = { VGREMOVE, "-f", pool->def->source.name, NULL @@ -526,6 +530,8 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED, const char *pvargv[3]; int i, error; + virCheckFlags(0, -1); + /* first remove the volume group */ if (virRun(cmdargv, NULL) < 0) return -1; @@ -665,12 +671,14 @@ static int virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStorageVolDefPtr vol, - unsigned int flags ATTRIBUTE_UNUSED) + unsigned int flags) { const char *cmdargv[] = { LVREMOVE, "-f", vol->target.path, NULL }; + virCheckFlags(0, -1); + if (virRun(cmdargv, NULL) < 0) return -1; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index d1fef92ccd..4f35be0cb8 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -322,7 +322,10 @@ storagePoolLookupByVolume(virStorageVolPtr vol) { static virDrvOpenStatus storageOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + if (!driverState) return VIR_DRV_OPEN_DECLINED; @@ -516,13 +519,16 @@ cleanup: static virStoragePoolPtr storagePoolCreate(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = conn->storagePrivateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; virStorageBackendPtr backend; + virCheckFlags(0, NULL); + storageDriverLock(driver); if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; @@ -567,12 +573,15 @@ cleanup: static virStoragePoolPtr storagePoolDefine(virConnectPtr conn, const char *xml, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = conn->storagePrivateData; virStoragePoolDefPtr def; virStoragePoolObjPtr pool = NULL; virStoragePoolPtr ret = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); if (!(def = virStoragePoolDefParseString(xml))) goto cleanup; @@ -657,12 +666,15 @@ cleanup: static int storagePoolStart(virStoragePoolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; int ret = -1; + virCheckFlags(0, -1); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); storageDriverUnlock(driver); @@ -848,12 +860,15 @@ cleanup: static int storagePoolRefresh(virStoragePoolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; int ret = -1; + virCheckFlags(0, -1); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); @@ -940,11 +955,14 @@ cleanup: static char * storagePoolGetXMLDesc(virStoragePoolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; char *ret = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); storageDriverUnlock(driver); @@ -1261,13 +1279,16 @@ static int storageVolumeDelete(virStorageVolPtr obj, unsigned int flags); static virStorageVolPtr storageVolumeCreateXML(virStoragePoolPtr obj, const char *xmldesc, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; virStorageVolPtr ret = NULL, volobj = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); storageDriverUnlock(driver); @@ -1383,7 +1404,8 @@ static virStorageVolPtr storageVolumeCreateXMLFrom(virStoragePoolPtr obj, const char *xmldesc, virStorageVolPtr vobj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool, origpool = NULL; virStorageBackendPtr backend; @@ -1391,6 +1413,8 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj, virStorageVolPtr ret = NULL, volobj = NULL; int buildret; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid); if (pool && STRNEQ(obj->name, vobj->pool)) { @@ -2010,13 +2034,16 @@ cleanup: static char * storageVolumeGetXMLDesc(virStorageVolPtr obj, - unsigned int flags ATTRIBUTE_UNUSED) { + unsigned int flags) +{ virStorageDriverStatePtr driver = obj->conn->storagePrivateData; virStoragePoolObjPtr pool; virStorageBackendPtr backend; virStorageVolDefPtr vol; char *ret = NULL; + virCheckFlags(0, NULL); + storageDriverLock(driver); pool = virStoragePoolObjFindByName(&driver->pools, obj->pool); storageDriverUnlock(driver);