提交 baa72449 编写于 作者: E Eric Blake

maint: improve VIR_ERR_NO_SUPPORT usage

We weren't very consistent in our use of VIR_ERR_NO_SUPPORT; many
users just passed __FUNCTION__ on, while others passed "%s" to
silence over-eager compilers that warn about __FUNCTION__ not
containing any %.  It's nicer to route all these uses through
a single macro, so that if we ever need to change the reporting,
we can do it in one place.

I verified that 'virsh -c test:///default qemu-monitor-command test foo'
gives the same error message before and after this patch:
error: this function is not supported by the connection driver: virDomainQemuMonitorCommand

Note that in libvirt.c, we were inconsistent on whether virDomain*
API used virLibConnError() (with VIR_FROM_NONE) or virLibDomainError()
(with VIR_FROM_DOMAIN); this patch unifies these errors to all use
VIR_FROM_NONE, on the grounds that it is unlikely that a caller
learning that a call is unimplemented can do anything in particular
with extra knowledge of which error domain it belongs to.

One particular change to note is virDomainOpenGraphics which was
trying to fail with VIR_ERR_NO_SUPPORT after a failed
VIR_DRV_SUPPORTS_FEATURE check; all other places that fail a
feature check report VIR_ERR_ARGUMENT_UNSUPPORTED.

* src/util/virerror.h (virReportUnsupportedError): New macro.
* src/libvirt-qemu.c: Use new macro.
* src/libvirt-lxc.c: Likewise.
* src/lxc/lxc_driver.c: Likewise.
* src/security/security_manager.c: Likewise.
* src/util/virinitctl.c: Likewise.
* src/libvirt.c: Likewise.
(virDomainOpenGraphics): Use correct error for unsupported feature.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 8f6c845f
...@@ -99,7 +99,7 @@ virDomainLxcOpenNamespace(virDomainPtr domain, ...@@ -99,7 +99,7 @@ virDomainLxcOpenNamespace(virDomainPtr domain,
return ret; return ret;
} }
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
error: error:
virDispatchError(conn); virDispatchError(conn);
......
...@@ -105,7 +105,7 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, ...@@ -105,7 +105,7 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
return ret; return ret;
} }
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
error: error:
virDispatchError(conn); virDispatchError(conn);
...@@ -180,7 +180,7 @@ virDomainQemuAttach(virConnectPtr conn, ...@@ -180,7 +180,7 @@ virDomainQemuAttach(virConnectPtr conn,
return ret; return ret;
} }
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
error: error:
virDispatchError(conn); virDispatchError(conn);
...@@ -242,9 +242,8 @@ virDomainQemuAgentCommand(virDomainPtr domain, ...@@ -242,9 +242,8 @@ virDomainQemuAgentCommand(virDomainPtr domain,
return ret; return ret;
} }
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
/* Copy to connection error object for back compatibility */
error: error:
virDispatchError(conn); virDispatchError(conn);
return NULL; return NULL;
......
此差异已折叠。
/* /*
* Copyright (C) 2010-2013 Red Hat, Inc. * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright IBM Corp. 2008 * Copyright IBM Corp. 2008
* *
* lxc_driver.c: linux container driver functions * lxc_driver.c: linux container driver functions
...@@ -2257,7 +2257,7 @@ lxcDomainInterfaceStats(virDomainPtr dom, ...@@ -2257,7 +2257,7 @@ lxcDomainInterfaceStats(virDomainPtr dom,
const char *path ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED,
struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED) struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED)
{ {
virReportError(VIR_ERR_NO_SUPPORT, "%s", __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
#endif #endif
......
/* /*
* security_manager.c: Internal security manager API * security_manager.c: Internal security manager API
* *
* Copyright (C) 2010-2013 Red Hat, Inc. * Copyright (C) 2010-2014 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -256,7 +256,7 @@ virSecurityManagerGetDOI(virSecurityManagerPtr mgr) ...@@ -256,7 +256,7 @@ virSecurityManagerGetDOI(virSecurityManagerPtr mgr)
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return NULL; return NULL;
} }
...@@ -271,7 +271,7 @@ virSecurityManagerGetModel(virSecurityManagerPtr mgr) ...@@ -271,7 +271,7 @@ virSecurityManagerGetModel(virSecurityManagerPtr mgr)
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return NULL; return NULL;
} }
...@@ -317,7 +317,7 @@ int virSecurityManagerRestoreImageLabel(virSecurityManagerPtr mgr, ...@@ -317,7 +317,7 @@ int virSecurityManagerRestoreImageLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -332,7 +332,7 @@ int virSecurityManagerSetDaemonSocketLabel(virSecurityManagerPtr mgr, ...@@ -332,7 +332,7 @@ int virSecurityManagerSetDaemonSocketLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -347,7 +347,7 @@ int virSecurityManagerSetSocketLabel(virSecurityManagerPtr mgr, ...@@ -347,7 +347,7 @@ int virSecurityManagerSetSocketLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -362,7 +362,7 @@ int virSecurityManagerClearSocketLabel(virSecurityManagerPtr mgr, ...@@ -362,7 +362,7 @@ int virSecurityManagerClearSocketLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -378,7 +378,7 @@ int virSecurityManagerSetImageLabel(virSecurityManagerPtr mgr, ...@@ -378,7 +378,7 @@ int virSecurityManagerSetImageLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -395,7 +395,7 @@ int virSecurityManagerRestoreHostdevLabel(virSecurityManagerPtr mgr, ...@@ -395,7 +395,7 @@ int virSecurityManagerRestoreHostdevLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -412,7 +412,7 @@ int virSecurityManagerSetHostdevLabel(virSecurityManagerPtr mgr, ...@@ -412,7 +412,7 @@ int virSecurityManagerSetHostdevLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -428,7 +428,7 @@ int virSecurityManagerSetSavedStateLabel(virSecurityManagerPtr mgr, ...@@ -428,7 +428,7 @@ int virSecurityManagerSetSavedStateLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -444,7 +444,7 @@ int virSecurityManagerRestoreSavedStateLabel(virSecurityManagerPtr mgr, ...@@ -444,7 +444,7 @@ int virSecurityManagerRestoreSavedStateLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -512,7 +512,7 @@ int virSecurityManagerGenLabel(virSecurityManagerPtr mgr, ...@@ -512,7 +512,7 @@ int virSecurityManagerGenLabel(virSecurityManagerPtr mgr,
} }
if (!sec_managers[i]->drv->domainGenSecurityLabel) { if (!sec_managers[i]->drv->domainGenSecurityLabel) {
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
} else { } else {
/* The seclabel must be added to @vm prior calling domainGenSecurityLabel /* The seclabel must be added to @vm prior calling domainGenSecurityLabel
* which may require seclabel to be presented already */ * which may require seclabel to be presented already */
...@@ -553,7 +553,7 @@ int virSecurityManagerReserveLabel(virSecurityManagerPtr mgr, ...@@ -553,7 +553,7 @@ int virSecurityManagerReserveLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -568,7 +568,7 @@ int virSecurityManagerReleaseLabel(virSecurityManagerPtr mgr, ...@@ -568,7 +568,7 @@ int virSecurityManagerReleaseLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -584,7 +584,7 @@ int virSecurityManagerSetAllLabel(virSecurityManagerPtr mgr, ...@@ -584,7 +584,7 @@ int virSecurityManagerSetAllLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -600,7 +600,7 @@ int virSecurityManagerRestoreAllLabel(virSecurityManagerPtr mgr, ...@@ -600,7 +600,7 @@ int virSecurityManagerRestoreAllLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -617,7 +617,7 @@ int virSecurityManagerGetProcessLabel(virSecurityManagerPtr mgr, ...@@ -617,7 +617,7 @@ int virSecurityManagerGetProcessLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -632,7 +632,7 @@ int virSecurityManagerSetProcessLabel(virSecurityManagerPtr mgr, ...@@ -632,7 +632,7 @@ int virSecurityManagerSetProcessLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -643,7 +643,7 @@ int virSecurityManagerSetChildProcessLabel(virSecurityManagerPtr mgr, ...@@ -643,7 +643,7 @@ int virSecurityManagerSetChildProcessLabel(virSecurityManagerPtr mgr,
if (mgr->drv->domainSetSecurityChildProcessLabel) if (mgr->drv->domainSetSecurityChildProcessLabel)
return mgr->drv->domainSetSecurityChildProcessLabel(mgr, vm, cmd); return mgr->drv->domainSetSecurityChildProcessLabel(mgr, vm, cmd);
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -671,7 +671,7 @@ int virSecurityManagerVerify(virSecurityManagerPtr mgr, ...@@ -671,7 +671,7 @@ int virSecurityManagerVerify(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -687,7 +687,7 @@ int virSecurityManagerSetImageFDLabel(virSecurityManagerPtr mgr, ...@@ -687,7 +687,7 @@ int virSecurityManagerSetImageFDLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -703,7 +703,7 @@ int virSecurityManagerSetTapFDLabel(virSecurityManagerPtr mgr, ...@@ -703,7 +703,7 @@ int virSecurityManagerSetTapFDLabel(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
...@@ -718,7 +718,7 @@ char *virSecurityManagerGetMountOptions(virSecurityManagerPtr mgr, ...@@ -718,7 +718,7 @@ char *virSecurityManagerGetMountOptions(virSecurityManagerPtr mgr,
return ret; return ret;
} }
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
return NULL; return NULL;
} }
......
/* /*
* virerror.c: error handling and reporting code for libvirt * virerror.c: error handling and reporting code for libvirt
* *
* Copyright (C) 2006-2013 Red Hat, Inc. * Copyright (C) 2006-2014 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -156,6 +156,11 @@ void virReportSystemErrorFull(int domcode, ...@@ -156,6 +156,11 @@ void virReportSystemErrorFull(int domcode,
0, 0, \ 0, 0, \
"%s", message); "%s", message);
# define virReportUnsupportedError() \
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_NO_SUPPORT, \
__FILE__, __FUNCTION__, __LINE__, __FUNCTION__)
void virReportOOMErrorFull(int domcode, void virReportOOMErrorFull(int domcode,
const char *filename, const char *filename,
const char *funcname, const char *funcname,
......
/* /*
* virinitctl.c: API for talking to init systems via initctl * virinitctl.c: API for talking to init systems via initctl
* *
* Copyright (C) 2012 Red Hat, Inc. * Copyright (C) 2012-2014 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -168,7 +168,7 @@ cleanup: ...@@ -168,7 +168,7 @@ cleanup:
int virInitctlSetRunLevel(virInitctlRunLevel level ATTRIBUTE_UNUSED, int virInitctlSetRunLevel(virInitctlRunLevel level ATTRIBUTE_UNUSED,
const char *vroot ATTRIBUTE_UNUSED) const char *vroot ATTRIBUTE_UNUSED)
{ {
virReportError(VIR_ERR_NO_SUPPORT, "%s", __FUNCTION__); virReportUnsupportedError();
return -1; return -1;
} }
#endif #endif
/* /*
* xen_driver.c: Unified Xen driver. * xen_driver.c: Unified Xen driver.
* *
* Copyright (C) 2007-2013 Red Hat, Inc. * Copyright (C) 2007-2014 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -2320,7 +2320,7 @@ xenUnifiedConnectDomainEventRegister(virConnectPtr conn, ...@@ -2320,7 +2320,7 @@ xenUnifiedConnectDomainEventRegister(virConnectPtr conn,
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (priv->xsWatch == -1) { if (priv->xsWatch == -1) {
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
return -1; return -1;
} }
...@@ -2346,7 +2346,7 @@ xenUnifiedConnectDomainEventDeregister(virConnectPtr conn, ...@@ -2346,7 +2346,7 @@ xenUnifiedConnectDomainEventDeregister(virConnectPtr conn,
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (priv->xsWatch == -1) { if (priv->xsWatch == -1) {
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
return -1; return -1;
} }
...@@ -2377,7 +2377,7 @@ xenUnifiedConnectDomainEventRegisterAny(virConnectPtr conn, ...@@ -2377,7 +2377,7 @@ xenUnifiedConnectDomainEventRegisterAny(virConnectPtr conn,
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (priv->xsWatch == -1) { if (priv->xsWatch == -1) {
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
return -1; return -1;
} }
...@@ -2404,7 +2404,7 @@ xenUnifiedConnectDomainEventDeregisterAny(virConnectPtr conn, ...@@ -2404,7 +2404,7 @@ xenUnifiedConnectDomainEventDeregisterAny(virConnectPtr conn,
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (priv->xsWatch == -1) { if (priv->xsWatch == -1) {
virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__); virReportUnsupportedError();
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册