storage: Use VIR_AUTOFREE for storage backends

Let's make use of the auto __cleanup capabilities. This also allows
for the cleanup of some goto paths.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
John Ferlan 2019-01-31 12:09:38 -05:00
parent 1ee7294bed
commit 821dd6d80a
14 changed files with 150 additions and 308 deletions

View File

@ -87,8 +87,7 @@ virStorageDriverLoadBackendModule(const char *name,
const char *regfunc, const char *regfunc,
bool forceload) bool forceload)
{ {
char *modfile = NULL; VIR_AUTOFREE(char *) modfile = NULL;
int ret;
if (!(modfile = virFileFindResourceFull(name, if (!(modfile = virFileFindResourceFull(name,
"libvirt_storage_backend_", "libvirt_storage_backend_",
@ -98,11 +97,7 @@ virStorageDriverLoadBackendModule(const char *name,
"LIBVIRT_STORAGE_BACKEND_DIR"))) "LIBVIRT_STORAGE_BACKEND_DIR")))
return -1; return -1;
ret = virModuleLoad(modfile, regfunc, forceload); return virModuleLoad(modfile, regfunc, forceload);
VIR_FREE(modfile);
return ret;
} }

View File

@ -56,8 +56,9 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *tmp, *devpath, *partname; char *tmp, *partname;
bool addVol = false; bool addVol = false;
VIR_AUTOFREE(char *) devpath = NULL;
/* Prepended path will be same for all partitions, so we can /* Prepended path will be same for all partitions, so we can
* strip the path to form a reasonable pool-unique name * strip the path to form a reasonable pool-unique name
@ -89,7 +90,6 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
* way of doing this... * way of doing this...
*/ */
vol->target.path = virStorageBackendStablePath(pool, devpath, true); vol->target.path = virStorageBackendStablePath(pool, devpath, true);
VIR_FREE(devpath);
if (vol->target.path == NULL) if (vol->target.path == NULL)
goto error; goto error;
} }
@ -355,12 +355,11 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
*/ */
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *parthelper_path;
struct virStorageBackendDiskPoolVolData cbdata = { struct virStorageBackendDiskPoolVolData cbdata = {
.pool = pool, .pool = pool,
.vol = vol, .vol = vol,
}; };
int ret; VIR_AUTOFREE(char *) parthelper_path = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
if (!(parthelper_path = virFileFindResource("libvirt_parthelper", if (!(parthelper_path = virFileFindResource("libvirt_parthelper",
@ -388,12 +387,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
def->allocation = 0; def->allocation = 0;
def->capacity = def->available = 0; def->capacity = def->available = 0;
ret = virCommandRunNul(cmd, return virCommandRunNul(cmd, 6, virStorageBackendDiskMakeVol, &cbdata);
6,
virStorageBackendDiskMakeVol,
&cbdata);
VIR_FREE(parthelper_path);
return ret;
} }
static int static int
@ -419,8 +413,7 @@ static int
virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *parthelper_path; VIR_AUTOFREE(char *) parthelper_path = NULL;
int ret;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
if (!(parthelper_path = virFileFindResource("libvirt_parthelper", if (!(parthelper_path = virFileFindResource("libvirt_parthelper",
@ -433,12 +426,8 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
"-g", "-g",
NULL); NULL);
ret = virCommandRunNul(cmd, return virCommandRunNul(cmd, 3, virStorageBackendDiskMakePoolGeometry,
3, pool);
virStorageBackendDiskMakePoolGeometry,
pool);
VIR_FREE(parthelper_path);
return ret;
} }
static int static int
@ -770,13 +759,12 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr pool,
unsigned int flags) unsigned int flags)
{ {
char *part_num = NULL; char *part_num = NULL;
char *devpath = NULL;
char *dev_name; char *dev_name;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *src_path = def->source.devices[0].path; char *src_path = def->source.devices[0].path;
char *srcname = last_component(src_path); char *srcname = last_component(src_path);
bool isDevMapperDevice; bool isDevMapperDevice;
int rc = -1; VIR_AUTOFREE(char *) devpath = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
virCheckFlags(0, -1); virCheckFlags(0, -1);
@ -800,7 +788,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr pool,
virReportSystemError(errno, virReportSystemError(errno,
_("Couldn't read volume target path '%s'"), _("Couldn't read volume target path '%s'"),
vol->target.path); vol->target.path);
goto cleanup; return -1;
} }
dev_name = last_component(devpath); dev_name = last_component(devpath);
} }
@ -811,7 +799,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr pool,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Volume path '%s' did not start with parent " _("Volume path '%s' did not start with parent "
"pool source device name."), dev_name); "pool source device name."), dev_name);
goto cleanup; return -1;
} }
part_num = dev_name + strlen(srcname); part_num = dev_name + strlen(srcname);
@ -825,7 +813,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr pool,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse partition number from target " _("cannot parse partition number from target "
"'%s'"), dev_name); "'%s'"), dev_name);
goto cleanup; return -1;
} }
/* eg parted /dev/sda rm 2 or /dev/mapper/mpathc rm 2 */ /* eg parted /dev/sda rm 2 or /dev/mapper/mpathc rm 2 */
@ -836,7 +824,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr pool,
part_num, part_num,
NULL); NULL);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; return -1;
/* Refreshing the pool is the easiest option as LOGICAL and EXTENDED /* Refreshing the pool is the easiest option as LOGICAL and EXTENDED
* partition allocation/capacity management is handled within * partition allocation/capacity management is handled within
@ -845,12 +833,9 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr pool,
*/ */
virStoragePoolObjClearVols(pool); virStoragePoolObjClearVols(pool);
if (virStorageBackendDiskRefreshPool(pool) < 0) if (virStorageBackendDiskRefreshPool(pool) < 0)
goto cleanup; return -1;
rc = 0; return 0;
cleanup:
VIR_FREE(devpath);
return rc;
} }
@ -858,11 +843,10 @@ static int
virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
int res = -1;
char *partFormat = NULL;
unsigned long long startOffset = 0, endOffset = 0; unsigned long long startOffset = 0, endOffset = 0;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virErrorPtr save_err; virErrorPtr save_err;
VIR_AUTOFREE(char *)partFormat = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
cmd = virCommandNewArgList(PARTED, cmd = virCommandNewArgList(PARTED,
@ -875,11 +859,11 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
vol->target.encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { vol->target.encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("storage pool only supports LUKS encrypted volumes")); _("storage pool only supports LUKS encrypted volumes"));
goto cleanup; return -1;
} }
if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0)
goto cleanup; return -1;
virCommandAddArg(cmd, partFormat); virCommandAddArg(cmd, partFormat);
/* If we're going to encrypt using LUKS, then we could need up to /* If we're going to encrypt using LUKS, then we could need up to
@ -889,13 +873,13 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
if (virStorageBackendDiskPartBoundaries(pool, &startOffset, &endOffset, if (virStorageBackendDiskPartBoundaries(pool, &startOffset, &endOffset,
vol->target.capacity) < 0) vol->target.capacity) < 0)
goto cleanup; return -1;
virCommandAddArgFormat(cmd, "%lluB", startOffset); virCommandAddArgFormat(cmd, "%lluB", startOffset);
virCommandAddArgFormat(cmd, "%lluB", endOffset); virCommandAddArgFormat(cmd, "%lluB", endOffset);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; return -1;
/* wait for device node to show up */ /* wait for device node to show up */
virWaitForDevices(); virWaitForDevices();
@ -919,11 +903,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
goto error; goto error;
} }
res = 0; return 0;
cleanup:
VIR_FREE(partFormat);
return res;
error: error:
/* Best effort to remove the partition. Ignore any errors /* Best effort to remove the partition. Ignore any errors
@ -933,7 +913,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool,
ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0)); ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0));
virSetError(save_err); virSetError(save_err);
virFreeError(save_err); virFreeError(save_err);
goto cleanup; return -1;
} }

View File

@ -246,11 +246,11 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
{ {
int ret = -1; int ret = -1;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *src = NULL;
FILE *mtab; FILE *mtab;
struct mntent ent; struct mntent ent;
char buf[1024]; char buf[1024];
int rc1, rc2; int rc1, rc2;
VIR_AUTOFREE(char *) src = NULL;
if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) { if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
virReportSystemError(errno, virReportSystemError(errno,
@ -282,7 +282,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
cleanup: cleanup:
VIR_FORCE_FCLOSE(mtab); VIR_FORCE_FCLOSE(mtab);
VIR_FREE(src);
return ret; return ret;
} }
@ -299,9 +298,8 @@ static int
virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *src = NULL;
int ret = -1;
int rc; int rc;
VIR_AUTOFREE(char *) src = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
if (virStorageBackendFileSystemIsValid(pool) < 0) if (virStorageBackendFileSystemIsValid(pool) < 0)
@ -320,13 +318,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
return -1; return -1;
cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src); cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
if (virCommandRun(cmd, NULL) < 0) return virCommandRun(cmd, NULL);
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(src);
return ret;
} }
@ -579,10 +571,10 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr ctxt,
void **data) void **data)
{ {
virStoragePoolFSMountOptionsDefPtr cmdopts = NULL; virStoragePoolFSMountOptionsDefPtr cmdopts = NULL;
xmlNodePtr *nodes = NULL;
int nnodes; int nnodes;
size_t i; size_t i;
int ret = -1; int ret = -1;
VIR_AUTOFREE(xmlNodePtr *)nodes = NULL;
if (xmlXPathRegisterNs(ctxt, BAD_CAST "fs", if (xmlXPathRegisterNs(ctxt, BAD_CAST "fs",
BAD_CAST STORAGE_POOL_FS_NAMESPACE_HREF) < 0) { BAD_CAST STORAGE_POOL_FS_NAMESPACE_HREF) < 0) {
@ -617,7 +609,6 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(nodes);
virStoragePoolDefFSNamespaceFree(cmdopts); virStoragePoolDefFSNamespaceFree(cmdopts);
return ret; return ret;
} }

View File

@ -127,11 +127,9 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool)
if (glfs_set_volfile_server(ret->vol, "tcp", if (glfs_set_volfile_server(ret->vol, "tcp",
ret->uri->server, ret->uri->port) < 0 || ret->uri->server, ret->uri->port) < 0 ||
glfs_init(ret->vol) < 0) { glfs_init(ret->vol) < 0) {
char *uri = virURIFormat(ret->uri); VIR_AUTOFREE(char *) uri = NULL;
uri = virURIFormat(ret->uri);
virReportSystemError(errno, _("failed to connect to %s"), virReportSystemError(errno, _("failed to connect to %s"), NULLSTR(uri));
NULLSTR(uri));
VIR_FREE(uri);
goto error; goto error;
} }
@ -187,9 +185,8 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
virStorageVolDefPtr vol, virStorageVolDefPtr vol,
const char *name) const char *name)
{ {
int ret = -1;
char *path = NULL;
char *tmp; char *tmp;
VIR_AUTOFREE(char *) path = NULL;
VIR_FREE(vol->key); VIR_FREE(vol->key);
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
@ -200,35 +197,31 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterStatePtr state,
if (name) { if (name) {
VIR_FREE(vol->name); VIR_FREE(vol->name);
if (VIR_STRDUP(vol->name, name) < 0) if (VIR_STRDUP(vol->name, name) < 0)
goto cleanup; return -1;
} }
if (virAsprintf(&path, "%s%s%s", state->volname, state->dir, if (virAsprintf(&path, "%s%s%s", state->volname, state->dir,
vol->name) < 0) vol->name) < 0)
goto cleanup; return -1;
tmp = state->uri->path; tmp = state->uri->path;
if (virAsprintf(&state->uri->path, "/%s", path) < 0) { if (virAsprintf(&state->uri->path, "/%s", path) < 0) {
state->uri->path = tmp; state->uri->path = tmp;
goto cleanup; return -1;
} }
if (!(vol->target.path = virURIFormat(state->uri))) { if (!(vol->target.path = virURIFormat(state->uri))) {
VIR_FREE(state->uri->path); VIR_FREE(state->uri->path);
state->uri->path = tmp; state->uri->path = tmp;
goto cleanup; return -1;
} }
VIR_FREE(state->uri->path); VIR_FREE(state->uri->path);
state->uri->path = tmp; state->uri->path = tmp;
/* the path is unique enough to serve as a volume key */ /* the path is unique enough to serve as a volume key */
if (VIR_STRDUP(vol->key, vol->target.path) < 0) if (VIR_STRDUP(vol->key, vol->target.path) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
VIR_FREE(path);
return ret;
} }
@ -244,10 +237,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
int ret = -1; int ret = -1;
glfs_fd_t *fd = NULL; glfs_fd_t *fd = NULL;
virStorageSourcePtr meta = NULL; virStorageSourcePtr meta = NULL;
char *header = NULL;
ssize_t len; ssize_t len;
int backingFormat; int backingFormat;
VIR_AUTOPTR(virStorageVolDef) vol = NULL; VIR_AUTOPTR(virStorageVolDef) vol = NULL;
VIR_AUTOFREE(char *) header = NULL;
*volptr = NULL; *volptr = NULL;
@ -333,7 +326,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
virStorageSourceFree(meta); virStorageSourceFree(meta);
if (fd) if (fd)
glfs_close(fd); glfs_close(fd);
VIR_FREE(header);
return ret; return ret;
} }

View File

@ -130,27 +130,20 @@ static int
virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool, virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool,
const char *session) const char *session)
{ {
char *sysfs_path;
int retval = -1;
uint32_t host; uint32_t host;
VIR_AUTOFREE(char *) sysfs_path = NULL;
if (virAsprintf(&sysfs_path, if (virAsprintf(&sysfs_path,
"/sys/class/iscsi_session/session%s/device", session) < 0) "/sys/class/iscsi_session/session%s/device", session) < 0)
goto cleanup; return -1;
if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0)
goto cleanup; return -1;
if (virStorageBackendSCSIFindLUs(pool, host) < 0) if (virStorageBackendSCSIFindLUs(pool, host) < 0)
goto cleanup; return -1;
retval = 0; return 0;
cleanup:
VIR_FREE(sysfs_path);
return retval;
} }
@ -167,7 +160,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
.nsources = 0, .nsources = 0,
.sources = NULL .sources = NULL
}; };
char *portal = NULL; VIR_AUTOFREE(char *) portal = NULL;
VIR_AUTOPTR(virStoragePoolSource) source = NULL; VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
@ -226,7 +219,6 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
for (i = 0; i < ntargets; i++) for (i = 0; i < ntargets; i++)
VIR_FREE(targets[i]); VIR_FREE(targets[i]);
VIR_FREE(targets); VIR_FREE(targets);
VIR_FREE(portal);
return ret; return ret;
} }
@ -235,8 +227,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr pool,
bool *isActive) bool *isActive)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *session = NULL;
int ret = -1; int ret = -1;
VIR_AUTOFREE(char *) session = NULL;
*isActive = false; *isActive = false;
@ -259,10 +251,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr pool,
return -1; return -1;
} }
if ((session = virStorageBackendISCSISession(pool, true)) != NULL) { if ((session = virStorageBackendISCSISession(pool, true)))
*isActive = true; *isActive = true;
VIR_FREE(session);
}
ret = 0; ret = 0;
return ret; return ret;
@ -330,9 +320,8 @@ static int
virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool) virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *portal = NULL; VIR_AUTOFREE(char *) portal = NULL;
char *session = NULL; VIR_AUTOFREE(char *) session = NULL;
int ret = -1;
if (def->source.nhost != 1) { if (def->source.nhost != 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -355,50 +344,40 @@ virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool)
if ((session = virStorageBackendISCSISession(pool, true)) == NULL) { if ((session = virStorageBackendISCSISession(pool, true)) == NULL) {
if ((portal = virStorageBackendISCSIPortal(&def->source)) == NULL) if ((portal = virStorageBackendISCSIPortal(&def->source)) == NULL)
goto cleanup; return -1;
/* Create a static node record for the IQN target. Must be done /* Create a static node record for the IQN target. Must be done
* in order for login to the target */ * in order for login to the target */
if (virISCSINodeNew(portal, def->source.devices[0].path) < 0) if (virISCSINodeNew(portal, def->source.devices[0].path) < 0)
goto cleanup; return -1;
if (virStorageBackendISCSISetAuth(portal, &def->source) < 0) if (virStorageBackendISCSISetAuth(portal, &def->source) < 0)
goto cleanup; return -1;
if (virISCSIConnectionLogin(portal, if (virISCSIConnectionLogin(portal,
def->source.initiator.iqn, def->source.initiator.iqn,
def->source.devices[0].path) < 0) def->source.devices[0].path) < 0)
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
VIR_FREE(portal);
VIR_FREE(session);
return ret;
} }
static int static int
virStorageBackendISCSIRefreshPool(virStoragePoolObjPtr pool) virStorageBackendISCSIRefreshPool(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *session = NULL; VIR_AUTOFREE(char *) session = NULL;
def->allocation = def->capacity = def->available = 0; def->allocation = def->capacity = def->available = 0;
if ((session = virStorageBackendISCSISession(pool, false)) == NULL) if ((session = virStorageBackendISCSISession(pool, false)) == NULL)
goto cleanup; return -1;
if (virISCSIRescanLUNs(session) < 0) if (virISCSIRescanLUNs(session) < 0)
goto cleanup; return -1;
if (virStorageBackendISCSIFindLUs(pool, session) < 0) if (virStorageBackendISCSIFindLUs(pool, session) < 0)
goto cleanup; return -1;
VIR_FREE(session);
return 0; return 0;
cleanup:
VIR_FREE(session);
return -1;
} }
@ -406,13 +385,11 @@ static int
virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool) virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *portal; VIR_AUTOFREE(char *) portal = NULL;
char *session; VIR_AUTOFREE(char *) session = NULL;
int ret = -1;
if ((session = virStorageBackendISCSISession(pool, true)) == NULL) if ((session = virStorageBackendISCSISession(pool, true)) == NULL)
return 0; return 0;
VIR_FREE(session);
if ((portal = virStorageBackendISCSIPortal(&def->source)) == NULL) if ((portal = virStorageBackendISCSIPortal(&def->source)) == NULL)
return -1; return -1;
@ -420,12 +397,9 @@ virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool)
if (virISCSIConnectionLogout(portal, if (virISCSIConnectionLogout(portal,
def->source.initiator.iqn, def->source.initiator.iqn,
def->source.devices[0].path) < 0) def->source.devices[0].path) < 0)
goto cleanup; return -1;
ret = 0;
cleanup: return 0;
VIR_FREE(portal);
return ret;
} }
virStorageBackend virStorageBackendISCSI = { virStorageBackend virStorageBackendISCSI = {

View File

@ -421,15 +421,13 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi,
} }
for (tmp_addr = addr; tmp_addr; tmp_addr = tmp_addr->next) { for (tmp_addr = addr; tmp_addr; tmp_addr = tmp_addr->next) {
char *target = NULL; VIR_AUTOFREE(char *) target = NULL;
if (VIR_STRDUP(target, tmp_addr->target_name) < 0) if (VIR_STRDUP(target, tmp_addr->target_name) < 0)
goto cleanup; goto cleanup;
if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) { if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0)
VIR_FREE(target);
goto cleanup; goto cleanup;
}
} }
VIR_STEAL_PTR(*targets, tmp_targets); VIR_STEAL_PTR(*targets, tmp_targets);
@ -490,7 +488,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
.nsources = 0, .nsources = 0,
.sources = NULL .sources = NULL
}; };
char *portal = NULL; VIR_AUTOFREE(char *) portal = NULL;
VIR_AUTOPTR(virStoragePoolSource) source = NULL; VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
@ -551,7 +549,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
for (i = 0; i < ntargets; i++) for (i = 0; i < ntargets; i++)
VIR_FREE(targets[i]); VIR_FREE(targets[i]);
VIR_FREE(targets); VIR_FREE(targets);
VIR_FREE(portal);
return ret; return ret;
} }
@ -561,7 +558,7 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoolObjPtr pool,
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
struct iscsi_context *iscsi = NULL; struct iscsi_context *iscsi = NULL;
char *portal = NULL; VIR_AUTOFREE(char *) portal = NULL;
if (!(iscsi = virISCSIDirectCreateContext(def->source.initiator.iqn))) if (!(iscsi = virISCSIDirectCreateContext(def->source.initiator.iqn)))
goto error; goto error;
@ -578,7 +575,6 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoolObjPtr pool,
VIR_STEAL_PTR(*portalRet, portal); VIR_STEAL_PTR(*portalRet, portal);
cleanup: cleanup:
VIR_FREE(portal);
return iscsi; return iscsi;
error: error:
@ -591,19 +587,14 @@ static int
virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool) virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool)
{ {
struct iscsi_context *iscsi = NULL; struct iscsi_context *iscsi = NULL;
char *portal = NULL;
int ret = -1; int ret = -1;
if (!(iscsi = virStorageBackendISCSIDirectSetConnection(pool, &portal))) VIR_AUTOFREE(char *) portal = NULL;
goto cleanup;
if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0)
goto disconect;
ret = 0; if (!(iscsi = virStorageBackendISCSIDirectSetConnection(pool, &portal)))
disconect: return -1;
ret = virISCSIDirectReportLuns(pool, iscsi, portal);
virISCSIDirectDisconnect(iscsi); virISCSIDirectDisconnect(iscsi);
iscsi_destroy_context(iscsi); iscsi_destroy_context(iscsi);
cleanup:
VIR_FREE(portal);
return ret; return ret;
} }
@ -639,7 +630,7 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol,
struct scsi_task *task = NULL; struct scsi_task *task = NULL;
int lun = 0; int lun = 0;
int ret = -1; int ret = -1;
unsigned char *data; VIR_AUTOFREE(unsigned char *) data = NULL;
if (virStorageBackendISCSIDirectGetLun(vol, &lun) < 0) if (virStorageBackendISCSIDirectGetLun(vol, &lun) < 0)
return ret; return ret;
@ -656,22 +647,19 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol,
if (!(task = iscsi_write10_sync(iscsi, lun, lba, data, if (!(task = iscsi_write10_sync(iscsi, lun, lba, data,
block_size * BLOCK_PER_PACKET, block_size * BLOCK_PER_PACKET,
block_size, 0, 0, 0, 0, 0))) block_size, 0, 0, 0, 0, 0)))
goto cleanup; return -1;
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
lba += BLOCK_PER_PACKET; lba += BLOCK_PER_PACKET;
} else { } else {
if (!(task = iscsi_write10_sync(iscsi, lun, lba, data, block_size, if (!(task = iscsi_write10_sync(iscsi, lun, lba, data, block_size,
block_size, 0, 0, 0, 0, 0))) block_size, 0, 0, 0, 0, 0)))
goto cleanup; return -1;
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
lba++; lba++;
} }
} }
ret = 0; return 0;
cleanup:
VIR_FREE(data);
return ret;
} }
static int static int

View File

@ -117,14 +117,14 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
{ {
int nextents, ret = -1; int nextents, ret = -1;
const char *regex_unit = "(\\S+)\\((\\S+)\\)"; const char *regex_unit = "(\\S+)\\((\\S+)\\)";
char *regex = NULL;
regex_t *reg = NULL;
regmatch_t *vars = NULL;
char *p = NULL; char *p = NULL;
size_t i; size_t i;
int err, nvars; int err, nvars;
unsigned long long offset, size, length; unsigned long long offset, size, length;
virStorageVolSourceExtent extent; virStorageVolSourceExtent extent;
VIR_AUTOFREE(char *) regex = NULL;
VIR_AUTOFREE(regex_t *) reg = NULL;
VIR_AUTOFREE(regmatch_t *) vars = NULL;
memset(&extent, 0, sizeof(extent)); memset(&extent, 0, sizeof(extent));
@ -202,7 +202,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
for (i = 0; i < nextents; i++) { for (i = 0; i < nextents; i++) {
size_t j; size_t j;
int len; int len;
char *offset_str = NULL; VIR_AUTOFREE(char *) offset_str = NULL;
j = (i * 2) + 1; j = (i * 2) + 1;
len = vars[j].rm_eo - vars[j].rm_so; len = vars[j].rm_eo - vars[j].rm_so;
@ -219,10 +219,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed volume extent offset value")); _("malformed volume extent offset value"));
VIR_FREE(offset_str);
goto cleanup; goto cleanup;
} }
VIR_FREE(offset_str);
extent.start = offset * size; extent.start = offset * size;
extent.end = (offset * size) + length; extent.end = (offset * size) + length;
@ -234,9 +232,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(regex);
VIR_FREE(reg);
VIR_FREE(vars);
VIR_FREE(extent.path); VIR_FREE(extent.path);
return ret; return ret;
} }
@ -459,16 +454,15 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **const groups,
void *data) void *data)
{ {
virStoragePoolSourceListPtr sourceList = data; virStoragePoolSourceListPtr sourceList = data;
char *pvname = NULL;
char *vgname = NULL;
int retval = -1;
size_t i; size_t i;
virStoragePoolSourceDevicePtr dev; virStoragePoolSourceDevicePtr dev;
virStoragePoolSource *thisSource; virStoragePoolSource *thisSource;
VIR_AUTOFREE(char *) pvname = NULL;
VIR_AUTOFREE(char *) vgname = NULL;
if (VIR_STRDUP(pvname, groups[0]) < 0 || if (VIR_STRDUP(pvname, groups[0]) < 0 ||
VIR_STRDUP(vgname, groups[1]) < 0) VIR_STRDUP(vgname, groups[1]) < 0)
goto error; return -1;
thisSource = NULL; thisSource = NULL;
for (i = 0; i < sourceList->nsources; i++) { for (i = 0; i < sourceList->nsources; i++) {
@ -480,13 +474,13 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **const groups,
if (thisSource == NULL) { if (thisSource == NULL) {
if (!(thisSource = virStoragePoolSourceListNewSource(sourceList))) if (!(thisSource = virStoragePoolSourceListNewSource(sourceList)))
goto error; return -1;
VIR_STEAL_PTR(thisSource->name, vgname); VIR_STEAL_PTR(thisSource->name, vgname);
} }
if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0) if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0)
goto error; return -1;
dev = &thisSource->devices[thisSource->ndevice]; dev = &thisSource->devices[thisSource->ndevice];
thisSource->ndevice++; thisSource->ndevice++;
@ -495,13 +489,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **const groups,
memset(dev, 0, sizeof(*dev)); memset(dev, 0, sizeof(*dev));
VIR_STEAL_PTR(dev->path, pvname); VIR_STEAL_PTR(dev->path, pvname);
retval = 0; return 0;
error:
VIR_FREE(pvname);
VIR_FREE(vgname);
return retval;
} }
/* /*

View File

@ -153,31 +153,31 @@ static int
virStorageBackendCreateVols(virStoragePoolObjPtr pool, virStorageBackendCreateVols(virStoragePoolObjPtr pool,
struct dm_names *names) struct dm_names *names)
{ {
int retval = -1, is_mpath = 0; int is_mpath = 0;
char *map_device = NULL;
uint32_t minor = -1; uint32_t minor = -1;
uint32_t next; uint32_t next;
VIR_AUTOFREE(char *) map_device = NULL;
do { do {
is_mpath = virStorageBackendIsMultipath(names->name); is_mpath = virStorageBackendIsMultipath(names->name);
if (is_mpath < 0) if (is_mpath < 0)
goto out; return -1;
if (is_mpath == 1) { if (is_mpath == 1) {
if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) if (virAsprintf(&map_device, "mapper/%s", names->name) < 0)
goto out; return -1;
if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) { if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to get %s minor number"), _("Failed to get %s minor number"),
names->name); names->name);
goto out; return -1;
} }
if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0) if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0)
goto out; return -1;
VIR_FREE(map_device); VIR_FREE(map_device);
} }
@ -191,10 +191,7 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool,
} while (next); } while (next);
retval = 0; return 0;
out:
VIR_FREE(map_device);
return retval;
} }

View File

@ -86,10 +86,10 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr ctxt,
void **data) void **data)
{ {
virStoragePoolRBDConfigOptionsDefPtr cmdopts = NULL; virStoragePoolRBDConfigOptionsDefPtr cmdopts = NULL;
xmlNodePtr *nodes = NULL;
int nnodes; int nnodes;
size_t i; size_t i;
int ret = -1; int ret = -1;
VIR_AUTOFREE(xmlNodePtr *)nodes = NULL;
if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd", if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd",
BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) { BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) {
@ -145,7 +145,6 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(nodes);
virStoragePoolDefRBDNamespaceFree(cmdopts); virStoragePoolDefRBDNamespaceFree(cmdopts);
return ret; return ret;
} }
@ -213,12 +212,12 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
char *rados_key = NULL; char *rados_key = NULL;
virBuffer mon_host = VIR_BUFFER_INITIALIZER; virBuffer mon_host = VIR_BUFFER_INITIALIZER;
size_t i; size_t i;
char *mon_buff = NULL;
const char *client_mount_timeout = "30"; const char *client_mount_timeout = "30";
const char *mon_op_timeout = "30"; const char *mon_op_timeout = "30";
const char *osd_op_timeout = "30"; const char *osd_op_timeout = "30";
const char *rbd_default_format = "2"; const char *rbd_default_format = "2";
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
VIR_AUTOFREE(char *) mon_buff = NULL;
if (authdef) { if (authdef) {
VIR_DEBUG("Using cephx authorization, username: %s", authdef->username); VIR_DEBUG("Using cephx authorization, username: %s", authdef->username);
@ -348,7 +347,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
virObjectUnref(conn); virObjectUnref(conn);
virBufferFreeAndReset(&mon_host); virBufferFreeAndReset(&mon_host);
VIR_FREE(mon_buff);
return ret; return ret;
} }
@ -574,11 +572,12 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
int ret = -1; int ret = -1;
int len = -1; int len = -1;
int r = 0; int r = 0;
char *name, *names = NULL; char *name;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStorageBackendRBDStatePtr ptr = NULL; virStorageBackendRBDStatePtr ptr = NULL;
struct rados_cluster_stat_t clusterstat; struct rados_cluster_stat_t clusterstat;
struct rados_pool_stat_t poolstat; struct rados_pool_stat_t poolstat;
VIR_AUTOFREE(char *) names = NULL;
if (!(ptr = virStorageBackendRBDNewState(pool))) if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup; goto cleanup;
@ -662,7 +661,6 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(names);
virStorageBackendRBDFreeState(&ptr); virStorageBackendRBDFreeState(&ptr);
return ret; return ret;
} }
@ -677,8 +675,8 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioctx,
int max_snaps = 128; int max_snaps = 128;
int snap_count, protected; int snap_count, protected;
size_t i; size_t i;
rbd_snap_info_t *snaps = NULL;
rbd_image_t image = NULL; rbd_image_t image = NULL;
VIR_AUTOFREE(rbd_snap_info_t *) snaps = NULL;
if ((r = rbd_open(ioctx, vol->name, &image, NULL)) < 0) { if ((r = rbd_open(ioctx, vol->name, &image, NULL)) < 0) {
virReportSystemError(-r, _("failed to open the RBD image '%s'"), virReportSystemError(-r, _("failed to open the RBD image '%s'"),
@ -737,8 +735,6 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioctx,
if (snaps) if (snaps)
rbd_snap_list_end(snaps); rbd_snap_list_end(snaps);
VIR_FREE(snaps);
if (image) if (image)
rbd_close(image); rbd_close(image);
@ -949,8 +945,8 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t image,
int max_snaps = 128; int max_snaps = 128;
size_t i; size_t i;
int diff; int diff;
rbd_snap_info_t *snaps = NULL;
rbd_image_info_t info; rbd_image_info_t info;
VIR_AUTOFREE(rbd_snap_info_t *) snaps = NULL;
if ((r = rbd_stat(image, &info, sizeof(info))) < 0) { if ((r = rbd_stat(image, &info, sizeof(info))) < 0) {
virReportSystemError(-r, _("failed to stat the RBD image %s"), virReportSystemError(-r, _("failed to stat the RBD image %s"),
@ -1023,8 +1019,6 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t image,
if (snaps) if (snaps)
rbd_snap_list_end(snaps); rbd_snap_list_end(snaps);
VIR_FREE(snaps);
return ret; return ret;
} }
@ -1098,8 +1092,8 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io,
uint64_t stripe_count; uint64_t stripe_count;
uint64_t stripe_unit; uint64_t stripe_unit;
virBuffer snapname = VIR_BUFFER_INITIALIZER; virBuffer snapname = VIR_BUFFER_INITIALIZER;
char *snapname_buff = NULL;
rbd_image_t image = NULL; rbd_image_t image = NULL;
VIR_AUTOFREE(char *) snapname_buff = NULL;
if ((r = rbd_open(io, origvol, &image, NULL)) < 0) { if ((r = rbd_open(io, origvol, &image, NULL)) < 0) {
virReportSystemError(-r, _("failed to open the RBD image %s"), virReportSystemError(-r, _("failed to open the RBD image %s"),
@ -1170,7 +1164,6 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io,
cleanup: cleanup:
virBufferFreeAndReset(&snapname); virBufferFreeAndReset(&snapname);
VIR_FREE(snapname_buff);
if (image) if (image)
rbd_close(image); rbd_close(image);
@ -1271,13 +1264,12 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image,
uint64_t stripe_count) uint64_t stripe_count)
{ {
int r = -1; int r = -1;
int ret = -1;
unsigned long long offset = 0; unsigned long long offset = 0;
unsigned long long length; unsigned long long length;
char *writebuf; VIR_AUTOFREE(char *) writebuf = NULL;
if (VIR_ALLOC_N(writebuf, info->obj_size * stripe_count) < 0) if (VIR_ALLOC_N(writebuf, info->obj_size * stripe_count) < 0)
goto cleanup; return -1;
while (offset < info->size) { while (offset < info->size) {
length = MIN((info->size - offset), (info->obj_size * stripe_count)); length = MIN((info->size - offset), (info->obj_size * stripe_count));
@ -1286,7 +1278,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image,
virReportSystemError(-r, _("writing %llu bytes failed on " virReportSystemError(-r, _("writing %llu bytes failed on "
"RBD image %s at offset %llu"), "RBD image %s at offset %llu"),
length, imgname, offset); length, imgname, offset);
goto cleanup; return -1;
} }
VIR_DEBUG("Wrote %llu bytes to RBD image %s at offset %llu", VIR_DEBUG("Wrote %llu bytes to RBD image %s at offset %llu",
@ -1295,12 +1287,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image,
offset += length; offset += length;
} }
ret = 0; return 0;
cleanup:
VIR_FREE(writebuf);
return ret;
} }
static int static int

View File

@ -57,13 +57,13 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
{ {
int fd = -1; int fd = -1;
int retval = -1; int retval = -1;
char *path = NULL; VIR_AUTOFREE(char *) path = NULL;
VIR_DEBUG("Triggering rescan of host %d", host); VIR_DEBUG("Triggering rescan of host %d", host);
if (virAsprintf(&path, "%s/host%u/scan", if (virAsprintf(&path, "%s/host%u/scan",
LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0)
goto cleanup; return -1;
VIR_DEBUG("Scan trigger path is '%s'", path); VIR_DEBUG("Scan trigger path is '%s'", path);
@ -89,7 +89,6 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
cleanup: cleanup:
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
VIR_FREE(path);
VIR_DEBUG("Rescan of host %d complete", host); VIR_DEBUG("Rescan of host %d complete", host);
return retval; return retval;
} }
@ -175,7 +174,6 @@ static char *
getAdapterName(virStorageAdapterPtr adapter) getAdapterName(virStorageAdapterPtr adapter)
{ {
char *name = NULL; char *name = NULL;
char *parentaddr = NULL;
if (adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) { if (adapter->type == VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) {
virStorageAdapterSCSIHostPtr scsi_host = &adapter->data.scsi_host; virStorageAdapterSCSIHostPtr scsi_host = &adapter->data.scsi_host;
@ -189,7 +187,7 @@ getAdapterName(virStorageAdapterPtr adapter)
addr->slot, addr->slot,
addr->function, addr->function,
unique_id))) unique_id)))
goto cleanup; return NULL;
} else { } else {
ignore_value(VIR_STRDUP(name, scsi_host->name)); ignore_value(VIR_STRDUP(name, scsi_host->name));
} }
@ -203,8 +201,6 @@ getAdapterName(virStorageAdapterPtr adapter)
} }
} }
cleanup:
VIR_FREE(parentaddr);
return name; return name;
} }
@ -245,10 +241,10 @@ checkParent(const char *name,
const char *parent_name) const char *parent_name)
{ {
unsigned int host_num; unsigned int host_num;
char *scsi_host_name = NULL;
char *vhba_parent = NULL;
bool retval = false; bool retval = false;
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
VIR_AUTOFREE(char *) scsi_host_name = NULL;
VIR_AUTOFREE(char *) vhba_parent = NULL;
VIR_DEBUG("name=%s, parent_name=%s", name, parent_name); VIR_DEBUG("name=%s, parent_name=%s", name, parent_name);
@ -288,8 +284,6 @@ checkParent(const char *name,
cleanup: cleanup:
virObjectUnref(conn); virObjectUnref(conn);
VIR_FREE(vhba_parent);
VIR_FREE(scsi_host_name);
return retval; return retval;
} }
@ -299,10 +293,9 @@ createVport(virStoragePoolDefPtr def,
const char *configFile, const char *configFile,
virStorageAdapterFCHostPtr fchost) virStorageAdapterFCHostPtr fchost)
{ {
char *name = NULL;
virStoragePoolFCRefreshInfoPtr cbdata = NULL; virStoragePoolFCRefreshInfoPtr cbdata = NULL;
virThread thread; virThread thread;
int ret = -1; VIR_AUTOFREE(char *) name = NULL;
VIR_DEBUG("configFile='%s' parent='%s', wwnn='%s' wwpn='%s'", VIR_DEBUG("configFile='%s' parent='%s', wwnn='%s' wwpn='%s'",
NULLSTR(configFile), NULLSTR(fchost->parent), NULLSTR(configFile), NULLSTR(fchost->parent),
@ -314,14 +307,14 @@ createVport(virStoragePoolDefPtr def,
*/ */
if ((name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) { if ((name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) {
if (!(checkName(name))) if (!(checkName(name)))
goto cleanup; return -1;
/* If a parent was provided, let's make sure the 'name' we've /* If a parent was provided, let's make sure the 'name' we've
* retrieved has the same parent. If not this will cause failure. */ * retrieved has the same parent. If not this will cause failure. */
if (!fchost->parent || checkParent(name, fchost->parent)) if (!fchost->parent || checkParent(name, fchost->parent))
ret = 0; return 0;
goto cleanup; return -1;
} }
/* Since we're creating the vHBA, then we need to manage removing it /* Since we're creating the vHBA, then we need to manage removing it
@ -333,12 +326,12 @@ createVport(virStoragePoolDefPtr def,
fchost->managed = VIR_TRISTATE_BOOL_YES; fchost->managed = VIR_TRISTATE_BOOL_YES;
if (configFile) { if (configFile) {
if (virStoragePoolSaveConfig(configFile, def) < 0) if (virStoragePoolSaveConfig(configFile, def) < 0)
goto cleanup; return -1;
} }
} }
if (!(name = virNodeDeviceCreateVport(fchost))) if (!(name = virNodeDeviceCreateVport(fchost)))
goto cleanup; return -1;
/* Creating our own VPORT didn't leave enough time to find any LUN's, /* Creating our own VPORT didn't leave enough time to find any LUN's,
* so, let's create a thread whose job it is to call the FindLU's with * so, let's create a thread whose job it is to call the FindLU's with
@ -357,11 +350,7 @@ createVport(virStoragePoolDefPtr def,
} }
} }
ret = 0; return 0;
cleanup:
VIR_FREE(name);
return ret;
} }
@ -370,10 +359,9 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr pool,
bool *isActive) bool *isActive)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *path = NULL;
char *name = NULL;
unsigned int host; unsigned int host;
int ret = -1; VIR_AUTOFREE(char *) path = NULL;
VIR_AUTOFREE(char *) name = NULL;
*isActive = false; *isActive = false;
@ -391,28 +379,23 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr pool,
} }
if (virSCSIHostGetNumber(name, &host) < 0) if (virSCSIHostGetNumber(name, &host) < 0)
goto cleanup; return -1;
if (virAsprintf(&path, "%s/host%d", if (virAsprintf(&path, "%s/host%d",
LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0)
goto cleanup; return -1;
*isActive = virFileExists(path); *isActive = virFileExists(path);
ret = 0; return 0;
cleanup:
VIR_FREE(path);
VIR_FREE(name);
return ret;
} }
static int static int
virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr pool) virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *name = NULL;
unsigned int host; unsigned int host;
int ret = -1; VIR_AUTOFREE(char *) name = NULL;
def->allocation = def->capacity = def->available = 0; def->allocation = def->capacity = def->available = 0;
@ -420,20 +403,17 @@ virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr pool)
return -1; return -1;
if (virSCSIHostGetNumber(name, &host) < 0) if (virSCSIHostGetNumber(name, &host) < 0)
goto out; return -1;
VIR_DEBUG("Scanning host%u", host); VIR_DEBUG("Scanning host%u", host);
if (virStorageBackendSCSITriggerRescan(host) < 0) if (virStorageBackendSCSITriggerRescan(host) < 0)
goto out; return -1;
if (virStorageBackendSCSIFindLUs(pool, host) < 0) if (virStorageBackendSCSIFindLUs(pool, host) < 0)
goto out; return -1;
ret = 0; return 0;
out:
VIR_FREE(name);
return ret;
} }

View File

@ -136,9 +136,8 @@ virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr pool, const char *diskIn
static int static int
virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool) virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
{ {
int ret = -1;
char *output = NULL;
size_t i; size_t i;
VIR_AUTOFREE(char *) output = NULL;
VIR_AUTOPTR(virString) lines = NULL; VIR_AUTOPTR(virString) lines = NULL;
VIR_AUTOPTR(virString) cells = NULL; VIR_AUTOPTR(virString) cells = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
@ -147,11 +146,11 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
virStorageBackendSheepdogAddHostArg(cmd, pool); virStorageBackendSheepdogAddHostArg(cmd, pool);
virCommandSetOutputBuffer(cmd, &output); virCommandSetOutputBuffer(cmd, &output);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; return -1;
lines = virStringSplit(output, "\n", 0); lines = virStringSplit(output, "\n", 0);
if (lines == NULL) if (lines == NULL)
goto cleanup; return -1;
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
const char *line = lines[i]; const char *line = lines[i];
@ -163,42 +162,34 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
if (cells != NULL && if (cells != NULL &&
virStringListLength((const char * const *)cells) > 2) { virStringListLength((const char * const *)cells) > 2) {
if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0)
goto cleanup; return -1;
} }
virStringListFree(cells); virStringListFree(cells);
cells = NULL; cells = NULL;
} }
ret = 0; return 0;
cleanup:
VIR_FREE(output);
return ret;
} }
static int static int
virStorageBackendSheepdogRefreshPool(virStoragePoolObjPtr pool) virStorageBackendSheepdogRefreshPool(virStoragePoolObjPtr pool)
{ {
int ret = -1; VIR_AUTOFREE(char *) output = NULL;
char *output = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
cmd = virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL); cmd = virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL);
virStorageBackendSheepdogAddHostArg(cmd, pool); virStorageBackendSheepdogAddHostArg(cmd, pool);
virCommandSetOutputBuffer(cmd, &output); virCommandSetOutputBuffer(cmd, &output);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; return -1;
if (virStorageBackendSheepdogParseNodeInfo(virStoragePoolObjGetDef(pool), if (virStorageBackendSheepdogParseNodeInfo(virStoragePoolObjGetDef(pool),
output) < 0) output) < 0)
goto cleanup; return -1;
ret = virStorageBackendSheepdogRefreshAllVol(pool); return virStorageBackendSheepdogRefreshAllVol(pool);
cleanup:
VIR_FREE(output);
return ret;
} }

View File

@ -39,9 +39,9 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool)
{ {
int ret = -1; int ret = -1;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *grp_name = NULL; VIR_AUTOFREE(char *) grp_name = NULL;
char *usr_name = NULL; VIR_AUTOFREE(char *) usr_name = NULL;
char *mode = NULL; VIR_AUTOFREE(char *) mode = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
/* Check the permissions */ /* Check the permissions */
@ -55,13 +55,13 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool)
/* Convert ids to names because vstorage uses names */ /* Convert ids to names because vstorage uses names */
if (!(grp_name = virGetGroupName(def->target.perms.gid))) if (!(grp_name = virGetGroupName(def->target.perms.gid)))
goto cleanup; return -1;
if (!(usr_name = virGetUserName(def->target.perms.uid))) if (!(usr_name = virGetUserName(def->target.perms.uid)))
goto cleanup; return -1;
if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0) if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0)
goto cleanup; return -1;
cmd = virCommandNewArgList(VSTORAGE_MOUNT, cmd = virCommandNewArgList(VSTORAGE_MOUNT,
"-c", def->source.name, "-c", def->source.name,
@ -70,15 +70,7 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool)
"-g", grp_name, "-u", usr_name, "-g", grp_name, "-u", usr_name,
NULL); NULL);
if (virCommandRun(cmd, NULL) < 0) return virCommandRun(cmd, NULL);
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(mode);
VIR_FREE(grp_name);
VIR_FREE(usr_name);
return ret;
} }
@ -90,7 +82,7 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool)
FILE *mtab; FILE *mtab;
struct mntent ent; struct mntent ent;
char buf[1024]; char buf[1024];
char *cluster = NULL; VIR_AUTOFREE(char *) cluster = NULL;
if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0) if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0)
return -1; return -1;
@ -115,7 +107,6 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool)
cleanup: cleanup:
VIR_FORCE_FCLOSE(mtab); VIR_FORCE_FCLOSE(mtab);
VIR_FREE(cluster);
return ret; return ret;
} }

View File

@ -52,7 +52,7 @@ static int
virStorageBackendZFSVolModeNeeded(void) virStorageBackendZFSVolModeNeeded(void)
{ {
int ret = -1, exit_code = -1; int ret = -1, exit_code = -1;
char *error = NULL; VIR_AUTOFREE(char *) error = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
/* 'zfs get' without arguments prints out /* 'zfs get' without arguments prints out
@ -77,7 +77,6 @@ virStorageBackendZFSVolModeNeeded(void)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(error);
return ret; return ret;
} }
@ -86,13 +85,12 @@ virStorageBackendZFSCheckPool(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
bool *isActive) bool *isActive)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *devpath; VIR_AUTOFREE(char *) devpath = NULL;
if (virAsprintf(&devpath, "/dev/zvol/%s", if (virAsprintf(&devpath, "/dev/zvol/%s",
def->source.name) < 0) def->source.name) < 0)
return -1; return -1;
*isActive = virFileIsDir(devpath); *isActive = virFileIsDir(devpath);
VIR_FREE(devpath);
return 0; return 0;
} }
@ -178,10 +176,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
char *volumes_list = NULL;
size_t i; size_t i;
VIR_AUTOPTR(virString) lines = NULL; VIR_AUTOPTR(virString) lines = NULL;
VIR_AUTOPTR(virCommand) cmd = NULL; VIR_AUTOPTR(virCommand) cmd = NULL;
VIR_AUTOFREE(char *) volumes_list = NULL;
/** /**
* $ zfs list -Hp -t volume -o name,volsize -r test * $ zfs list -Hp -t volume -o name,volsize -r test
@ -203,10 +201,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
NULL); NULL);
virCommandSetOutputBuffer(cmd, &volumes_list); virCommandSetOutputBuffer(cmd, &volumes_list);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; return -1;
if (!(lines = virStringSplit(volumes_list, "\n", 0))) if (!(lines = virStringSplit(volumes_list, "\n", 0)))
goto cleanup; return -1;
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
if (STREQ(lines[i], "")) if (STREQ(lines[i], ""))
@ -216,9 +214,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
continue; continue;
} }
cleanup:
VIR_FREE(volumes_list);
return 0; return 0;
} }

View File

@ -258,11 +258,10 @@ virStorageFileBackendGlusterReadlinkCallback(const char *path,
void *data) void *data)
{ {
virStorageFileBackendGlusterPrivPtr priv = data; virStorageFileBackendGlusterPrivPtr priv = data;
char *buf = NULL;
size_t bufsiz = 0; size_t bufsiz = 0;
ssize_t ret; ssize_t ret;
struct stat st; struct stat st;
int retval = -1; VIR_AUTOFREE(char *) buf = NULL;
*linkpath = NULL; *linkpath = NULL;
@ -278,13 +277,13 @@ virStorageFileBackendGlusterReadlinkCallback(const char *path,
realloc: realloc:
if (VIR_EXPAND_N(buf, bufsiz, 256) < 0) if (VIR_EXPAND_N(buf, bufsiz, 256) < 0)
goto error; return -1;
if ((ret = glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) { if ((ret = glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("failed to read link of gluster file '%s'"), _("failed to read link of gluster file '%s'"),
path); path);
goto error; return -1;
} }
if (ret == bufsiz) if (ret == bufsiz)
@ -294,11 +293,7 @@ virStorageFileBackendGlusterReadlinkCallback(const char *path,
VIR_STEAL_PTR(*linkpath, buf); VIR_STEAL_PTR(*linkpath, buf);
retval = 0; return 0;
error:
VIR_FREE(buf);
return retval;
} }
@ -306,7 +301,7 @@ static const char *
virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src) virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
char *filePath = NULL; VIR_AUTOFREE(char *) filePath = NULL;
if (priv->canonpath) if (priv->canonpath)
return priv->canonpath; return priv->canonpath;
@ -322,8 +317,6 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
src->volume, src->volume,
filePath)); filePath));
VIR_FREE(filePath);
return priv->canonpath; return priv->canonpath;
} }