virVHBAPathExists(const char *sysfs_prefix,
int host)
{
- char *sysfs_path = NULL;
+ g_autofree char *sysfs_path = NULL;
bool ret = false;
sysfs_path = g_strdup_printf("%s/host%d",
if (virFileExists(sysfs_path))
ret = true;
- VIR_FREE(sysfs_path);
return ret;
}
virVHBAIsVportCapable(const char *sysfs_prefix,
int host)
{
- char *scsi_host_path = NULL;
- char *fc_host_path = NULL;
+ g_autofree char *scsi_host_path = NULL;
+ g_autofree char *fc_host_path = NULL;
bool ret = false;
fc_host_path = g_strdup_printf("%s/host%d/%s",
if (virFileExists(fc_host_path) || virFileExists(scsi_host_path))
ret = true;
- VIR_FREE(fc_host_path);
- VIR_FREE(scsi_host_path);
return ret;
}
int host,
const char *entry)
{
- char *sysfs_path = NULL;
+ g_autofree char *sysfs_path = NULL;
char *p = NULL;
- char *buf = NULL;
+ g_autofree char *buf = NULL;
char *result = NULL;
sysfs_path = g_strdup_printf("%s/host%d/%s",
result = g_strdup(p);
cleanup:
- VIR_FREE(sysfs_path);
- VIR_FREE(buf);
return result;
}
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
g_autoptr(DIR) dir = NULL;
struct dirent *entry = NULL;
- char *max_vports = NULL;
- char *vports = NULL;
- char *state = NULL;
- char *ret = NULL;
if (virDirOpen(&dir, prefix) < 0)
return NULL;
while (virDirRead(dir, &entry, prefix) > 0) {
+ g_autofree char *state = NULL;
+ g_autofree char *max_vports = NULL;
+ g_autofree char *vports = NULL;
unsigned int host;
char *p = NULL;
/* Skip the not online FC host */
if (STRNEQ(state, PORT_STATE_ONLINE)) {
- VIR_FREE(state);
continue;
}
- VIR_FREE(state);
if (!(max_vports = virVHBAGetConfig(prefix, host, "max_npiv_vports"))) {
VIR_DEBUG("Failed to read max_npiv_vports for host%d", host);
if (!(vports = virVHBAGetConfig(prefix, host, "npiv_vports_inuse"))) {
VIR_DEBUG("Failed to read npiv_vports_inuse for host%d", host);
- VIR_FREE(max_vports);
continue;
}
if ((strlen(max_vports) >= strlen(vports)) ||
((strlen(max_vports) == strlen(vports)) &&
strcmp(max_vports, vports) > 0)) {
- ret = g_strdup(entry->d_name);
- goto cleanup;
+ return g_strdup(entry->d_name);
}
-
- VIR_FREE(max_vports);
- VIR_FREE(vports);
}
- cleanup:
- VIR_FREE(max_vports);
- VIR_FREE(vports);
- return ret;
+ return NULL;
}
/* virVHBAManageVport:
const char *wwnn,
int operation)
{
- int ret = -1;
- char *operation_path = NULL, *vport_name = NULL;
+ g_autofree char *operation_path = NULL;
+ g_autofree char *vport_name = NULL;
const char *operation_file = NULL;
switch (operation) {
default:
virReportError(VIR_ERR_OPERATION_INVALID,
_("Invalid vport operation (%d)"), operation);
- goto cleanup;
+ return -1;
}
operation_path = g_strdup_printf("%s/host%d/%s", SYSFS_FC_HOST_PATH,
_("vport operation '%s' is not supported "
"for host%d"),
operation_file, parent_host);
- goto cleanup;
+ return -1;
}
}
* lifecycle event for applications to consume. */
vport_name = g_strdup_printf("%s:%s", wwpn, wwnn);
- if (virFileWriteStr(operation_path, vport_name, 0) == 0)
- ret = 0;
- else
+ if (virFileWriteStr(operation_path, vport_name, 0) < 0) {
virReportSystemError(errno,
- _("Write of '%s' to '%s' during "
- "vport create/delete failed"),
+ _("Write of '%s' to '%s' during vport create/delete failed"),
vport_name, operation_path);
+ return -1;
+ }
- cleanup:
- VIR_FREE(vport_name);
- VIR_FREE(operation_path);
- return ret;
+ return 0;
}
const char *f_name,
const char *wwn)
{
- char *path;
- char *buf = NULL;
+ g_autofree char *path = NULL;
+ g_autofree char *buf = NULL;
char *p;
int ret = -1;
ret = 1;
cleanup:
- VIR_FREE(path);
- VIR_FREE(buf);
return ret;
}
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
struct dirent *entry = NULL;
g_autoptr(DIR) dir = NULL;
- char *vport_create_path = NULL;
- char *ret = NULL;
if (virDirOpen(&dir, prefix) < 0)
return NULL;
while (virDirRead(dir, &entry, prefix) > 0) {
+ g_autofree char *vport_create_path = NULL;
int rc;
- VIR_FREE(vport_create_path);
-
/* Existing vHBA's will have the same fabric_name, but won't
* have the vport_create file - so we check for both */
vport_create_path = g_strdup_printf("%s/%s/vport_create", prefix,
if ((rc = vhbaReadCompareWWN(prefix, entry->d_name,
"fabric_name", fabric_wwn)) < 0)
- goto cleanup;
+ return NULL;
if (rc == 0)
continue;
- ret = g_strdup(entry->d_name);
- break;
+ return g_strdup(entry->d_name);
}
- cleanup:
- VIR_FREE(vport_create_path);
- return ret;
+ return NULL;
}
#else