case MDEVCTL_CMD_LAST:
default:
/* SHOULD NEVER HAPPEN */
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown Command '%i'"), cmd_type);
return NULL;
}
static int
-virMdevctlCreate(virNodeDeviceDef *def, char **uuid, char **errmsg)
+virMdevctlCreate(virNodeDeviceDef *def, char **uuid)
{
int status;
+ g_autofree char *errmsg = NULL;
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCommand(def,
MDEVCTL_CMD_CREATE,
uuid,
- errmsg);
+ &errmsg);
if (!cmd)
return -1;
/* an auto-generated uuid is returned via stdout if no uuid is specified in
* the mdevctl args */
- if (virCommandRun(cmd, &status) < 0 || status != 0)
+ if (virCommandRun(cmd, &status) < 0)
+ return -1;
+
+ if (status != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to start mediated device: %s"),
+ MDEVCTL_ERROR(errmsg));
return -1;
+ }
/* remove newline */
*uuid = g_strstrip(*uuid);
-
return 0;
}
static int
-virMdevctlDefine(virNodeDeviceDef *def, char **uuid, char **errmsg)
+virMdevctlDefine(virNodeDeviceDef *def, char **uuid)
{
int status;
+ g_autofree char *errmsg = NULL;
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCommand(def,
MDEVCTL_CMD_DEFINE,
- uuid, errmsg);
+ uuid, &errmsg);
if (!cmd)
return -1;
/* an auto-generated uuid is returned via stdout if no uuid is specified in
* the mdevctl args */
- if (virCommandRun(cmd, &status) < 0 || status != 0)
+ if (virCommandRun(cmd, &status) < 0)
return -1;
+ if (status != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to define mediated device: %s"),
+ MDEVCTL_ERROR(errmsg));
+ return -1;
+ }
+
/* remove newline */
*uuid = g_strstrip(*uuid);
-
return 0;
}
virNodeDeviceDef *def)
{
g_autofree char *uuid = NULL;
- g_autofree char *errmsg = NULL;
if (!def->parent) {
virReportError(VIR_ERR_XML_ERROR, "%s",
return NULL;
}
- if (virMdevctlCreate(def, &uuid, &errmsg) < 0) {
- if (errmsg)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to start mediated device: %s"),
- errmsg);
+ if (virMdevctlCreate(def, &uuid) < 0) {
return NULL;
}
static int
-virMdevctlStop(virNodeDeviceDef *def, char **errmsg)
+virMdevctlStop(virNodeDeviceDef *def)
{
int status;
g_autoptr(virCommand) cmd = NULL;
+ g_autofree char *errmsg = NULL;
- cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errmsg);
+ cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, &errmsg);
if (!cmd)
return -1;
- if (virCommandRun(cmd, &status) < 0 || status != 0)
+ if (virCommandRun(cmd, &status) < 0)
return -1;
+ if (status != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to destroy '%s': %s"), def->name,
+ MDEVCTL_ERROR(errmsg));
+ return -1;
+ }
+
return 0;
}
static int
-virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg)
+virMdevctlUndefine(virNodeDeviceDef *def)
{
int status;
g_autoptr(virCommand) cmd = NULL;
+ g_autofree char *errmsg = NULL;
- cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, errmsg);
+ cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, &errmsg);
if (!cmd)
return -1;
- if (virCommandRun(cmd, &status) < 0 || status != 0)
+ if (virCommandRun(cmd, &status) < 0)
return -1;
+ if (status != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to undefine mediated device: %s"),
+ MDEVCTL_ERROR(errmsg));
+ return -1;
+ }
+
return 0;
}
static int
-virMdevctlStart(virNodeDeviceDef *def, char **errmsg)
+virMdevctlStart(virNodeDeviceDef *def)
{
int status;
g_autoptr(virCommand) cmd = NULL;
+ g_autofree char *errmsg = NULL;
- cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errmsg);
+ cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, &errmsg);
if (!cmd)
return -1;
- if (virCommandRun(cmd, &status) < 0 || status != 0)
+ if (virCommandRun(cmd, &status) < 0)
return -1;
+ if (status != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to create mediated device: %s"),
+ MDEVCTL_ERROR(errmsg));
+ return -1;
+ }
+
return 0;
}
g_autofree char *vfiogroup =
virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid);
VIR_AUTOCLOSE fd = -1;
- g_autofree char *errmsg = NULL;
if (!vfiogroup)
goto cleanup;
goto cleanup;
}
- if (virMdevctlStop(def, &errmsg) < 0) {
- if (errmsg)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to destroy '%s': %s"), def->name,
- errmsg);
+ if (virMdevctlStop(def) < 0)
goto cleanup;
- }
+
ret = 0;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
g_autoptr(virNodeDeviceDef) def = NULL;
const char *virt_type = NULL;
g_autofree char *uuid = NULL;
- g_autofree char *errmsg = NULL;
g_autofree char *name = NULL;
virCheckFlags(0, NULL);
return NULL;
}
- if (virMdevctlDefine(def, &uuid, &errmsg) < 0) {
- if (errmsg)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to define mediated device: %s"), errmsg);
+ if (virMdevctlDefine(def, &uuid) < 0) {
return NULL;
}
}
if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
- g_autofree char *errmsg = NULL;
-
- if (virMdevctlUndefine(def, &errmsg) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to undefine mediated device: %s"),
- MDEVCTL_ERROR(errmsg));
+ if (virMdevctlUndefine(def) < 0)
goto cleanup;
- }
+
ret = 0;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
goto cleanup;
if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
- g_autofree char *errmsg = NULL;
-
- if (virMdevctlStart(def, &errmsg) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to create mediated device: %s"),
- MDEVCTL_ERROR(errmsg));
+ if (virMdevctlStart(def) < 0)
goto cleanup;
- }
+
ret = 0;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",