1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Replace use of HYPERV_ERROR with virReportError

Update the Hyper-V driver to use virReportError instead
of the HYPERV_ERROR custom macro

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-18 15:29:12 +01:00
parent cf8cff035c
commit d9de122052
5 changed files with 133 additions and 138 deletions

1
cfg.mk
View File

@ -506,7 +506,6 @@ sc_avoid_attribute_unused_in_header:
# |grep -vE '^(qsort|if|close|assert|fputc|free|N_|vir.*GetName|.*Unlock|virNodeListDevices|virHashRemoveEntry|freeaddrinfo|.*[fF]ree|xdrmem_create|xmlXPathFreeObject|virUUIDFormat|openvzSetProgramSentinal|polkit_action_unref)$'
msg_gen_function =
msg_gen_function += HYPERV_ERROR
msg_gen_function += PHYP_ERROR
msg_gen_function += VIR_ERROR
msg_gen_function += VMX_ERROR

View File

@ -96,7 +96,7 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
return VIR_DRV_OPEN_DECLINED;
}
HYPERV_ERROR(VIR_ERR_INVALID_ARG,
virReportError(VIR_ERR_INVALID_ARG,
_("Transport '%s' in URI scheme is not supported, try again "
"without the transport part"), plus + 1);
return VIR_DRV_OPEN_ERROR;
@ -104,14 +104,14 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
/* Require server part */
if (conn->uri->server == NULL) {
HYPERV_ERROR(VIR_ERR_INVALID_ARG, "%s",
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("URI is missing the server part"));
return VIR_DRV_OPEN_ERROR;
}
/* Require auth */
if (auth == NULL || auth->cb == NULL) {
HYPERV_ERROR(VIR_ERR_INVALID_ARG, "%s",
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Missing or invalid auth pointer"));
return VIR_DRV_OPEN_ERROR;
}
@ -150,7 +150,7 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
username = virAuthGetUsername(conn, auth, "hyperv", "administrator", conn->uri->server);
if (username == NULL) {
HYPERV_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
goto cleanup;
}
}
@ -158,7 +158,7 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
password = virAuthGetPassword(conn, auth, "hyperv", username, conn->uri->server);
if (password == NULL) {
HYPERV_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
goto cleanup;
}
@ -167,13 +167,13 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
priv->parsedUri->transport, username, password);
if (priv->client == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create openwsman client"));
goto cleanup;
}
if (wsmc_transport_init(priv->client, NULL) != 0) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize openwsman transport"));
goto cleanup;
}
@ -194,7 +194,7 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
}
if (computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s is not a Hyper-V server"), conn->uri->server);
goto cleanup;
}
@ -254,7 +254,7 @@ hypervGetHostname(virConnectPtr conn)
}
if (computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s"),
"Win32_ComputerSystem");
goto cleanup;
@ -296,7 +296,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
}
if (computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s"),
"Win32_ComputerSystem");
goto cleanup;
@ -315,7 +315,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
}
if (processorList == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s"),
"Win32_Processor");
goto cleanup;
@ -342,7 +342,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
/* Fill struct */
if (virStrncpy(info->model, processorList->data->Name,
sizeof(info->model) - 1, sizeof(info->model)) == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("CPU model %s too long for destination"),
processorList->data->Name);
goto cleanup;
@ -471,7 +471,7 @@ hypervDomainLookupByID(virConnectPtr conn, int id)
}
if (computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id);
virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id);
goto cleanup;
}
@ -506,7 +506,7 @@ hypervDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
}
if (computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_NO_DOMAIN,
virReportError(VIR_ERR_NO_DOMAIN,
_("No domain with UUID %s"), uuid_string);
goto cleanup;
}
@ -539,7 +539,7 @@ hypervDomainLookupByName(virConnectPtr conn, const char *name)
}
if (computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_NO_DOMAIN,
virReportError(VIR_ERR_NO_DOMAIN,
_("No domain with name %s"), name);
goto cleanup;
}
@ -567,7 +567,7 @@ hypervDomainSuspend(virDomainPtr domain)
if (computerSystem->data->EnabledState !=
MSVM_COMPUTERSYSTEM_ENABLEDSTATE_ENABLED) {
HYPERV_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not active"));
goto cleanup;
}
@ -596,7 +596,7 @@ hypervDomainResume(virDomainPtr domain)
if (computerSystem->data->EnabledState !=
MSVM_COMPUTERSYSTEM_ENABLEDSTATE_PAUSED) {
HYPERV_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not paused"));
goto cleanup;
}
@ -628,7 +628,7 @@ hypervDomainDestroyFlags(virDomainPtr domain, unsigned int flags)
if (!hypervIsMsvmComputerSystemActive(computerSystem, &in_transition) ||
in_transition) {
HYPERV_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not active or is in state transition"));
goto cleanup;
}
@ -703,7 +703,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
}
if (virtualSystemSettingData == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for domain %s"),
"Msvm_VirtualSystemSettingData",
computerSystem->data->ElementName);
@ -724,7 +724,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
}
if (processorSettingData == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for domain %s"),
"Msvm_ProcessorSettingData",
computerSystem->data->ElementName);
@ -746,7 +746,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
if (memorySettingData == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for domain %s"),
"Msvm_MemorySettingData",
computerSystem->data->ElementName);
@ -845,7 +845,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
}
if (virtualSystemSettingData == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for domain %s"),
"Msvm_VirtualSystemSettingData",
computerSystem->data->ElementName);
@ -866,7 +866,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
}
if (processorSettingData == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for domain %s"),
"Msvm_ProcessorSettingData",
computerSystem->data->ElementName);
@ -888,7 +888,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
if (memorySettingData == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for domain %s"),
"Msvm_MemorySettingData",
computerSystem->data->ElementName);
@ -905,7 +905,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
}
if (virUUIDParse(computerSystem->data->Name, def->uuid) < 0) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse UUID from string '%s'"),
computerSystem->data->Name);
return NULL;
@ -1066,7 +1066,7 @@ hypervDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
}
if (hypervIsMsvmComputerSystemActive(computerSystem, NULL)) {
HYPERV_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is already active or is in state transition"));
goto cleanup;
}
@ -1189,7 +1189,7 @@ hypervDomainManagedSave(virDomainPtr domain, unsigned int flags)
if (!hypervIsMsvmComputerSystemActive(computerSystem, &in_transition) ||
in_transition) {
HYPERV_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain is not active or is in state transition"));
goto cleanup;
}
@ -1244,7 +1244,7 @@ hypervDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags)
if (computerSystem->data->EnabledState !=
MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED) {
HYPERV_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Domain has no managed save image"));
goto cleanup;
}

View File

@ -29,10 +29,6 @@
# include "hyperv_util.h"
# include "openwsman.h"
# define HYPERV_ERROR(code, ...) \
virReportErrorHelper(VIR_FROM_HYPERV, code, __FILE__, __FUNCTION__, \
__LINE__, __VA_ARGS__)
typedef struct _hypervPrivate hypervPrivate;
struct _hypervPrivate {

View File

@ -42,7 +42,7 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
int i;
if (parsedUri == NULL || *parsedUri != NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
@ -66,7 +66,7 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
if (STRNEQ((*parsedUri)->transport, "http") &&
STRNEQ((*parsedUri)->transport, "https")) {
HYPERV_ERROR(VIR_ERR_INVALID_ARG,
virReportError(VIR_ERR_INVALID_ARG,
_("Query parameter 'transport' has unexpected value "
"'%s' (should be http|https)"),
(*parsedUri)->transport);

View File

@ -56,7 +56,7 @@ hyperyVerifyResponse(WsManClient *client, WsXmlDocH response,
WsManFault *fault;
if (lastError != WS_LASTERR_OK) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Transport error during %s: %s (%d)"),
detail, wsman_transport_get_last_error_string(lastError),
lastError);
@ -66,14 +66,14 @@ hyperyVerifyResponse(WsManClient *client, WsXmlDocH response,
/* Check the HTTP response code and report an error if it's not 200 (OK),
* 400 (Bad Request) or 500 (Internal Server Error) */
if (responseCode != 200 && responseCode != 400 && responseCode != 500) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected HTTP response during %s: %d"),
detail, responseCode);
return -1;
}
if (response == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Empty response during %s"), detail);
return -1;
}
@ -88,7 +88,7 @@ hyperyVerifyResponse(WsManClient *client, WsXmlDocH response,
wsmc_get_fault_data(response, fault);
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("SOAP fault during %s: code '%s', subcode '%s', "
"reason '%s', detail '%s'"),
detail, NULLSTR(fault->code), NULLSTR(fault->subcode),
@ -126,7 +126,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
hypervObject *object;
if (list == NULL || *list != NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
@ -140,7 +140,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
options = wsmc_options_init();
if (options == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize options"));
goto cleanup;
}
@ -149,7 +149,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string);
if (filter == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create filter"));
goto cleanup;
}
@ -176,7 +176,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
node = ws_xml_get_soap_body(response);
if (node == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not lookup SOAP body"));
goto cleanup;
}
@ -184,7 +184,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_PULL_RESP);
if (node == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not lookup pull response"));
goto cleanup;
}
@ -192,7 +192,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ITEMS);
if (node == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not lookup pull response items"));
goto cleanup;
}
@ -205,7 +205,7 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
className, resourceUri, NULL, 0, 0);
if (data == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not deserialize pull response item"));
goto cleanup;
}
@ -422,7 +422,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
options = wsmc_options_init();
if (options == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not initialize options"));
goto cleanup;
}
@ -442,14 +442,14 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
returnValue = ws_xml_get_xpath_value(response, (char *)"/s:Envelope/s:Body/p:RequestStateChange_OUTPUT/p:ReturnValue");
if (returnValue == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for %s invocation"),
"ReturnValue", "RequestStateChange");
goto cleanup;
}
if (virStrToLong_i(returnValue, NULL, 10, &returnCode) < 0) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse return code from '%s'"), returnValue);
goto cleanup;
}
@ -459,7 +459,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
instanceID = ws_xml_get_xpath_value(response, (char *)"/s:Envelope/s:Body/p:RequestStateChange_OUTPUT/p:Job/a:ReferenceParameters/w:SelectorSet/w:Selector[@Name='InstanceID']");
if (instanceID == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for %s invocation"),
"InstanceID", "RequestStateChange");
goto cleanup;
@ -476,7 +476,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
}
if (concreteJob == NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not lookup %s for %s invocation"),
"Msvm_ConcreteJob", "RequestStateChange");
goto cleanup;
@ -501,20 +501,20 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
case MSVM_CONCRETEJOB_JOBSTATE_KILLED:
case MSVM_CONCRETEJOB_JOBSTATE_EXCEPTION:
case MSVM_CONCRETEJOB_JOBSTATE_SERVICE:
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Concrete job for %s invocation is in error state"),
"RequestStateChange");
goto cleanup;
default:
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Concrete job for %s invocation is in unknown state"),
"RequestStateChange");
goto cleanup;
}
}
} else if (returnCode != CIM_RETURNCODE_COMPLETED_WITH_NO_ERROR) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invocation of %s returned an error: %s (%d)"),
"RequestStateChange", hypervReturnCodeToString(returnCode),
returnCode);
@ -624,12 +624,12 @@ hypervMsvmComputerSystemToDomain(virConnectPtr conn,
unsigned char uuid[VIR_UUID_BUFLEN];
if (domain == NULL || *domain != NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
if (virUUIDParse(computerSystem->data->Name, uuid) < 0) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse UUID from string '%s'"),
computerSystem->data->Name);
return -1;
@ -659,7 +659,7 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
virBuffer query = VIR_BUFFER_INITIALIZER;
if (computerSystem == NULL || *computerSystem != NULL) {
HYPERV_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
@ -675,7 +675,7 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
}
if (*computerSystem == NULL) {
HYPERV_ERROR(VIR_ERR_NO_DOMAIN,
virReportError(VIR_ERR_NO_DOMAIN,
_("No domain with UUID %s"), uuid_string);
return -1;
}