2009-07-21 14:02:16 +00:00
|
|
|
/*
|
|
|
|
* interface_driver.c: backend driver methods to handle physical
|
|
|
|
* interface configuration using the netcf library.
|
|
|
|
*
|
2011-07-06 20:40:19 +00:00
|
|
|
* Copyright (C) 2006-2011 Red Hat, Inc.
|
2009-07-21 14:02:16 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-07-21 10:06:23 +00:00
|
|
|
* License along with this library; If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-07-21 14:02:16 +00:00
|
|
|
*
|
|
|
|
* Author: Laine Stump <laine@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <netcf.h>
|
|
|
|
|
|
|
|
#include "virterror_internal.h"
|
|
|
|
#include "datatypes.h"
|
2009-09-15 17:55:16 +00:00
|
|
|
#include "netcf_driver.h"
|
2009-07-21 14:02:16 +00:00
|
|
|
#include "interface_conf.h"
|
|
|
|
#include "memory.h"
|
2012-09-04 16:10:17 +00:00
|
|
|
#include "logging.h"
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_INTERFACE
|
|
|
|
|
|
|
|
/* Main driver state */
|
|
|
|
struct interface_driver
|
|
|
|
{
|
|
|
|
virMutex lock;
|
|
|
|
struct netcf *netcf;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void interfaceDriverLock(struct interface_driver *driver)
|
|
|
|
{
|
|
|
|
virMutexLock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void interfaceDriverUnlock(struct interface_driver *driver)
|
|
|
|
{
|
|
|
|
virMutexUnlock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcf_to_vir_err(int netcf_errcode)
|
|
|
|
{
|
|
|
|
switch (netcf_errcode)
|
|
|
|
{
|
|
|
|
case NETCF_NOERROR:
|
|
|
|
/* no error, everything ok */
|
|
|
|
return VIR_ERR_OK;
|
|
|
|
case NETCF_EINTERNAL:
|
|
|
|
/* internal error, aka bug */
|
|
|
|
return VIR_ERR_INTERNAL_ERROR;
|
|
|
|
case NETCF_EOTHER:
|
|
|
|
/* other error, copout for being more specific */
|
|
|
|
return VIR_ERR_INTERNAL_ERROR;
|
|
|
|
case NETCF_ENOMEM:
|
2009-07-21 14:15:39 +00:00
|
|
|
/*
|
|
|
|
* allocation failed return VIR ERR NO MEMORY
|
|
|
|
* though it should not be used now.
|
|
|
|
*/
|
2012-03-22 11:33:35 +00:00
|
|
|
return 2;
|
2009-07-21 14:02:16 +00:00
|
|
|
case NETCF_EXMLPARSER:
|
|
|
|
/* XML parser choked */
|
|
|
|
return VIR_ERR_XML_ERROR;
|
|
|
|
case NETCF_EXMLINVALID:
|
|
|
|
/* XML invalid in some form */
|
|
|
|
return VIR_ERR_XML_ERROR;
|
|
|
|
case NETCF_ENOENT:
|
|
|
|
/* Required entry in a tree is missing */
|
|
|
|
return VIR_ERR_INTERNAL_ERROR;
|
|
|
|
case NETCF_EEXEC:
|
|
|
|
/* external program execution failed or returned non-0 */
|
|
|
|
return VIR_ERR_INTERNAL_ERROR;
|
2011-05-06 12:54:53 +00:00
|
|
|
#ifdef NETCF_EINVALIDOP
|
|
|
|
case NETCF_EINVALIDOP:
|
|
|
|
/* attempted operation is invalid while the system is in the current state. */
|
|
|
|
return VIR_ERR_OPERATION_INVALID;
|
|
|
|
#endif
|
2009-07-21 14:02:16 +00:00
|
|
|
default:
|
|
|
|
return VIR_ERR_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct netcf_if *interfaceDriverGetNetcfIF(struct netcf *ncf, virInterfacePtr ifinfo)
|
|
|
|
{
|
|
|
|
/* 1) caller already has lock,
|
|
|
|
* 2) caller cleans up iface on return
|
|
|
|
*/
|
|
|
|
struct netcf_if *iface = ncf_lookup_by_name(ncf, ifinfo->name);
|
|
|
|
if (!iface) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(ncf, &errmsg, &details);
|
|
|
|
if (errcode != NETCF_NOERROR) {
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("couldn't find interface named '%s': %s%s%s"),
|
|
|
|
ifinfo->name, errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
} else {
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("couldn't find interface named '%s'"),
|
|
|
|
ifinfo->name);
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDrvOpenStatus interfaceOpenInterface(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct interface_driver *driverState;
|
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
if (VIR_ALLOC(driverState) < 0)
|
|
|
|
{
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-21 14:02:16 +00:00
|
|
|
goto alloc_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize non-0 stuff in driverState */
|
|
|
|
if (virMutexInit(&driverState->lock) < 0)
|
|
|
|
{
|
|
|
|
/* what error to report? */
|
|
|
|
goto mutex_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open netcf */
|
|
|
|
if (ncf_init(&driverState->netcf, NULL) != 0)
|
|
|
|
{
|
|
|
|
/* what error to report? */
|
|
|
|
goto netcf_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->interfacePrivateData = driverState;
|
2010-02-14 22:15:56 +00:00
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
netcf_error:
|
|
|
|
if (driverState->netcf)
|
|
|
|
{
|
|
|
|
ncf_close(driverState->netcf);
|
|
|
|
}
|
|
|
|
virMutexDestroy (&driverState->lock);
|
|
|
|
mutex_error:
|
|
|
|
VIR_FREE(driverState);
|
|
|
|
alloc_error:
|
2010-02-14 22:15:56 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceCloseInterface(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (conn->interfacePrivateData != NULL)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
|
|
|
|
/* close netcf instance */
|
|
|
|
ncf_close(driver->netcf);
|
|
|
|
/* destroy lock */
|
|
|
|
virMutexDestroy(&driver->lock);
|
|
|
|
/* free driver state */
|
|
|
|
VIR_FREE(driver);
|
|
|
|
}
|
|
|
|
conn->interfacePrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceNumOfInterfaces(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
count = ncf_num_of_interfaces(driver->netcf, NETCF_IFACE_ACTIVE);
|
|
|
|
if (count < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get number of interfaces on host: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "", details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceListInterfaces(virConnectPtr conn, char **const names, int nnames)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
count = ncf_list_interfaces(driver->netcf, nnames, names, NETCF_IFACE_ACTIVE);
|
|
|
|
if (count < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to list host interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceNumOfDefinedInterfaces(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
count = ncf_num_of_interfaces(driver->netcf, NETCF_IFACE_INACTIVE);
|
|
|
|
if (count < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get number of defined interfaces on host: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceListDefinedInterfaces(virConnectPtr conn, char **const names, int nnames)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
count = ncf_list_interfaces(driver->netcf, nnames, names, NETCF_IFACE_INACTIVE);
|
|
|
|
if (count < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to list host defined interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-04 16:10:17 +00:00
|
|
|
static int
|
|
|
|
interfaceListAllInterfaces(virConnectPtr conn,
|
|
|
|
virInterfacePtr **ifaces,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
virInterfacePtr *tmp_iface_objs = NULL;
|
|
|
|
virInterfacePtr iface_obj = NULL;
|
|
|
|
unsigned int status;
|
|
|
|
int niface_objs = 0;
|
|
|
|
int ret = -1;
|
|
|
|
char **names = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
|
|
|
|
VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
/* List all interfaces, in case of we might support new filter flags
|
|
|
|
* except active|inactive in future.
|
|
|
|
*/
|
|
|
|
count = ncf_num_of_interfaces(driver->netcf, NETCF_IFACE_ACTIVE |
|
|
|
|
NETCF_IFACE_INACTIVE);
|
|
|
|
if (count < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get number of host interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(names, count) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((count = ncf_list_interfaces(driver->netcf, count, names,
|
|
|
|
NETCF_IFACE_ACTIVE |
|
|
|
|
NETCF_IFACE_INACTIVE)) < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to list host interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifaces) {
|
|
|
|
if (VIR_ALLOC_N(tmp_iface_objs, count + 1) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
iface = ncf_lookup_by_name(driver->netcf, names[i]);
|
|
|
|
if (!iface) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
|
|
|
if (errcode != NETCF_NOERROR) {
|
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("couldn't find interface named '%s': %s%s%s"),
|
|
|
|
names[i], errmsg,
|
|
|
|
details ? " - " : "", details ? details : "");
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
/* Ignore the NETCF_NOERROR, as the interface is very likely
|
|
|
|
* deleted by other management apps (e.g. virt-manager).
|
|
|
|
*/
|
|
|
|
VIR_WARN("couldn't find interface named '%s', might be "
|
|
|
|
"deleted by other process", names[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ncf_if_status(iface, &status) < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get status of interface %s: %s%s%s"),
|
|
|
|
names[i], errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: Filter the result, need to be splitted once new filter flags
|
|
|
|
* except active|inactive are supported.
|
|
|
|
*/
|
|
|
|
if (((status & NETCF_IFACE_ACTIVE) &&
|
|
|
|
(flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
|
|
|
|
((status & NETCF_IFACE_INACTIVE) &&
|
|
|
|
(flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
|
|
|
|
if (ifaces) {
|
|
|
|
iface_obj = virGetInterface(conn, ncf_if_name(iface),
|
|
|
|
ncf_if_mac_string(iface));
|
|
|
|
tmp_iface_objs[niface_objs] = iface_obj;
|
|
|
|
}
|
|
|
|
niface_objs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ncf_if_free(iface);
|
|
|
|
iface = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp_iface_objs) {
|
|
|
|
/* trim the array to the final size */
|
|
|
|
ignore_value(VIR_REALLOC_N(tmp_iface_objs, niface_objs + 1));
|
|
|
|
*ifaces = tmp_iface_objs;
|
|
|
|
tmp_iface_objs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = niface_objs;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
|
|
|
|
if (names)
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
VIR_FREE(names);
|
|
|
|
|
|
|
|
if (tmp_iface_objs) {
|
|
|
|
for (i = 0; i < niface_objs; i++) {
|
|
|
|
if (tmp_iface_objs[i])
|
|
|
|
virInterfaceFree(tmp_iface_objs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
static virInterfacePtr interfaceLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface;
|
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
iface = ncf_lookup_by_name(driver->netcf, name);
|
|
|
|
if (!iface) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
|
|
|
if (errcode != NETCF_NOERROR) {
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("couldn't find interface named '%s': %s%s%s"),
|
|
|
|
name, errmsg,
|
|
|
|
details ? " - " : "", details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
} else {
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("couldn't find interface named '%s'"), name);
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetInterface(conn, ncf_if_name(iface), ncf_if_mac_string(iface));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virInterfacePtr interfaceLookupByMACString(virConnectPtr conn,
|
|
|
|
const char *macstr)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface;
|
|
|
|
int niface;
|
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
niface = ncf_lookup_by_mac_string(driver->netcf, macstr, 1, &iface);
|
|
|
|
|
|
|
|
if (niface < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("couldn't find interface with MAC address '%s': %s%s%s"),
|
|
|
|
macstr, errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (niface == 0) {
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("couldn't find interface with MAC address '%s'"),
|
|
|
|
macstr);
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (niface > 1) {
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(VIR_ERR_MULTIPLE_INTERFACES,
|
|
|
|
"%s", _("multiple interfaces with matching MAC address"));
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetInterface(conn, ncf_if_name(iface), ncf_if_mac_string(iface));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *interfaceGetXMLDesc(virInterfacePtr ifinfo,
|
2009-10-28 09:40:54 +00:00
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
char *xmlstr = NULL;
|
|
|
|
virInterfaceDefPtr ifacedef = NULL;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
libvirt: do not mix internal flags into public API
There were two API in driver.c that were silently masking flags
bits prior to calling out to the drivers, and several others
that were explicitly masking flags bits. This is not
forward-compatible - if we ever have that many flags in the
future, then talking to an old server that masks out the
flags would be indistinguishable from talking to a new server
that can honor the flag. In general, libvirt.c should forward
_all_ flags on to drivers, and only the drivers should reject
unknown flags.
In the case of virDrvSecretGetValue, the solution is to separate
the internal driver callback function to have two parameters
instead of one, with only one parameter affected by the public
API. In the case of virDomainGetXMLDesc, it turns out that
no one was ever mixing VIR_DOMAIN_XML_INTERNAL_STATUS with
the dumpxml path in the first place; that internal flag was
only used in saving and restoring state files, which happened
to be in functions internal to a single file, so there is no
mixing of the internal flag with a public flags argument.
Additionally, virDomainMemoryStats passed a flags argument
over RPC, but not to the driver.
* src/driver.h (VIR_DOMAIN_XML_FLAGS_MASK)
(VIR_SECRET_GET_VALUE_FLAGS_MASK): Delete.
(virDrvSecretGetValue): Separate out internal flags.
(virDrvDomainMemoryStats): Provide missing flags argument.
* src/driver.c (verify): Drop unused check.
* src/conf/domain_conf.h (virDomainObjParseFile): Delete
declaration.
(virDomainXMLInternalFlags): Move...
* src/conf/domain_conf.c: ...here. Delete redundant include.
(virDomainObjParseFile): Make static.
* src/libvirt.c (virDomainGetXMLDesc, virSecretGetValue): Update
clients.
(virDomainMemoryPeek, virInterfaceGetXMLDesc)
(virDomainMemoryStats, virDomainBlockPeek, virNetworkGetXMLDesc)
(virStoragePoolGetXMLDesc, virStorageVolGetXMLDesc)
(virNodeNumOfDevices, virNodeListDevices, virNWFilterGetXMLDesc):
Don't mask unknown flags.
* src/interface/netcf_driver.c (interfaceGetXMLDesc): Reject
unknown flags.
* src/secret/secret_driver.c (secretGetValue): Update clients.
* src/remote/remote_driver.c (remoteSecretGetValue)
(remoteDomainMemoryStats): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainMemoryStats): Likewise.
* daemon/remote.c (remoteDispatchDomainMemoryStats): Likewise.
2011-07-13 21:31:56 +00:00
|
|
|
virCheckFlags(VIR_INTERFACE_XML_INACTIVE, NULL);
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-10-28 09:40:54 +00:00
|
|
|
if ((flags & VIR_INTERFACE_XML_INACTIVE)) {
|
|
|
|
xmlstr = ncf_if_xml_desc(iface);
|
|
|
|
} else {
|
|
|
|
xmlstr = ncf_if_xml_state(iface);
|
|
|
|
}
|
2009-07-21 14:02:16 +00:00
|
|
|
if (!xmlstr) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("could not get interface XML description: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
ifacedef = virInterfaceDefParseString(xmlstr);
|
2009-07-21 14:02:16 +00:00
|
|
|
if (!ifacedef) {
|
|
|
|
/* error was already reported */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
ret = virInterfaceDefFormat(ifacedef);
|
2009-07-21 14:02:16 +00:00
|
|
|
if (!ret) {
|
|
|
|
/* error was already reported */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
VIR_FREE(xmlstr);
|
|
|
|
virInterfaceDefFree(ifacedef);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virInterfacePtr interfaceDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
char *xmlstr = NULL;
|
|
|
|
virInterfaceDefPtr ifacedef = NULL;
|
|
|
|
virInterfacePtr ret = NULL;
|
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
ifacedef = virInterfaceDefParseString(xml);
|
2009-07-21 14:02:16 +00:00
|
|
|
if (!ifacedef) {
|
|
|
|
/* error was already reported */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
xmlstr = virInterfaceDefFormat(ifacedef);
|
2009-07-21 14:02:16 +00:00
|
|
|
if (!xmlstr) {
|
|
|
|
/* error was already reported */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = ncf_define(driver->netcf, xmlstr);
|
|
|
|
if (!iface) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("could not get interface XML description: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetInterface(conn, ncf_if_name(iface), ncf_if_mac_string(iface));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
VIR_FREE(xmlstr);
|
|
|
|
virInterfaceDefFree(ifacedef);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceUndefine(virInterfacePtr ifinfo) {
|
|
|
|
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ncf_if_undefine(iface);
|
|
|
|
if (ret < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to undefine interface %s: %s%s%s"),
|
|
|
|
ifinfo->name, errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceCreate(virInterfacePtr ifinfo,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ncf_if_up(iface);
|
|
|
|
if (ret < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to create (start) interface %s: %s%s%s"),
|
|
|
|
ifinfo->name, errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceDestroy(virInterfacePtr ifinfo,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ncf_if_down(iface);
|
|
|
|
if (ret < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to destroy (stop) interface %s: %s%s%s"),
|
|
|
|
ifinfo->name, errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2009-07-21 14:02:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-13 17:22:56 +00:00
|
|
|
static int interfaceIsActive(virInterfacePtr ifinfo)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ncf_if_status(iface, &flags) < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get status of interface %s: %s%s%s"),
|
|
|
|
ifinfo->name, errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2010-04-13 17:22:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = flags & NETCF_IFACE_ACTIVE ? 1 : 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ncf_if_free(iface);
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-06 12:54:53 +00:00
|
|
|
#ifdef HAVE_NETCF_TRANSACTIONS
|
|
|
|
static int interfaceChangeBegin(virConnectPtr conn, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1); /* currently flags must be 0 */
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
ret = ncf_change_begin(driver->netcf, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to begin transaction: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2011-05-06 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceChangeCommit(virConnectPtr conn, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1); /* currently flags must be 0 */
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
ret = ncf_change_commit(driver->netcf, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to commit transaction: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2011-05-06 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int interfaceChangeRollback(virConnectPtr conn, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct interface_driver *driver = conn->interfacePrivateData;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1); /* currently flags must be 0 */
|
|
|
|
|
|
|
|
interfaceDriverLock(driver);
|
|
|
|
|
|
|
|
ret = ncf_change_rollback(driver->netcf, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2012-07-18 11:46:55 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to rollback transaction: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
2011-05-06 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interfaceDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_NETCF_TRANSACTIONS */
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
static virInterfaceDriver interfaceDriver = {
|
|
|
|
"Interface",
|
2011-05-13 13:35:01 +00:00
|
|
|
.open = interfaceOpenInterface, /* 0.7.0 */
|
|
|
|
.close = interfaceCloseInterface, /* 0.7.0 */
|
|
|
|
.numOfInterfaces = interfaceNumOfInterfaces, /* 0.7.0 */
|
|
|
|
.listInterfaces = interfaceListInterfaces, /* 0.7.0 */
|
|
|
|
.numOfDefinedInterfaces = interfaceNumOfDefinedInterfaces, /* 0.7.0 */
|
|
|
|
.listDefinedInterfaces = interfaceListDefinedInterfaces, /* 0.7.0 */
|
2012-09-04 16:10:17 +00:00
|
|
|
.listAllInterfaces = interfaceListAllInterfaces, /* 0.10.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.interfaceLookupByName = interfaceLookupByName, /* 0.7.0 */
|
|
|
|
.interfaceLookupByMACString = interfaceLookupByMACString, /* 0.7.0 */
|
|
|
|
.interfaceGetXMLDesc = interfaceGetXMLDesc, /* 0.7.0 */
|
|
|
|
.interfaceDefineXML = interfaceDefineXML, /* 0.7.0 */
|
|
|
|
.interfaceUndefine = interfaceUndefine, /* 0.7.0 */
|
|
|
|
.interfaceCreate = interfaceCreate, /* 0.7.0 */
|
|
|
|
.interfaceDestroy = interfaceDestroy, /* 0.7.0 */
|
|
|
|
.interfaceIsActive = interfaceIsActive, /* 0.7.3 */
|
2011-05-06 12:54:53 +00:00
|
|
|
#ifdef HAVE_NETCF_TRANSACTIONS
|
|
|
|
.interfaceChangeBegin = interfaceChangeBegin, /* 0.9.2 */
|
|
|
|
.interfaceChangeCommit = interfaceChangeCommit, /* 0.9.2 */
|
|
|
|
.interfaceChangeRollback = interfaceChangeRollback, /* 0.9.2 */
|
|
|
|
#endif /* HAVE_NETCF_TRANSACTIONS */
|
2009-07-21 14:02:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int interfaceRegister(void) {
|
|
|
|
virRegisterInterfaceDriver(&interfaceDriver);
|
|
|
|
return 0;
|
|
|
|
}
|