2009-07-21 14:02:16 +00:00
|
|
|
/*
|
2014-03-07 13:38:51 +00:00
|
|
|
* interface_backend_netcf.c: backend driver methods to handle physical
|
|
|
|
* interface configuration using the netcf library.
|
2009-07-21 14:02:16 +00:00
|
|
|
*
|
2015-09-18 17:22:46 +00:00
|
|
|
* Copyright (C) 2006-2015 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-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <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>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2009-07-21 14:02:16 +00:00
|
|
|
#include "datatypes.h"
|
2012-09-18 01:27:06 +00:00
|
|
|
#include "interface_driver.h"
|
2009-07-21 14:02:16 +00:00
|
|
|
#include "interface_conf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2013-04-23 10:56:22 +00:00
|
|
|
#include "virstring.h"
|
|
|
|
#include "viraccessapicheck.h"
|
2017-02-28 21:20:44 +00:00
|
|
|
#include "virinterfaceobj.h"
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_INTERFACE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("interface.interface_backend_netcf");
|
|
|
|
|
2013-08-27 16:26:48 +00:00
|
|
|
#define INTERFACE_DRIVER_NAME "netcf"
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
/* Main driver state */
|
2013-08-27 16:26:48 +00:00
|
|
|
typedef struct
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLockable parent;
|
2009-07-21 14:02:16 +00:00
|
|
|
struct netcf *netcf;
|
2018-01-26 11:16:00 +00:00
|
|
|
bool privileged;
|
2013-08-27 16:26:48 +00:00
|
|
|
} virNetcfDriverState, *virNetcfDriverStatePtr;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
static virClassPtr virNetcfDriverStateClass;
|
|
|
|
static void virNetcfDriverStateDispose(void *obj);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
static int
|
|
|
|
virNetcfDriverStateOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!(virNetcfDriverStateClass = virClassNew(virClassForObjectLockable(),
|
|
|
|
"virNetcfDriverState",
|
|
|
|
sizeof(virNetcfDriverState),
|
|
|
|
virNetcfDriverStateDispose)))
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(virNetcfDriverState)
|
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
static virNetcfDriverStatePtr driver;
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virNetcfDriverStateDispose(void *obj)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
2014-10-23 14:17:18 +00:00
|
|
|
virNetcfDriverStatePtr _driver = obj;
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
if (_driver->netcf)
|
|
|
|
ncf_close(_driver->netcf);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-01-26 11:16:00 +00:00
|
|
|
netcfStateInitialize(bool privileged,
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
if (virNetcfDriverStateInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
if (!(driver = virObjectLockableNew(virNetcfDriverStateClass)))
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
return -1;
|
|
|
|
|
2018-01-26 11:16:00 +00:00
|
|
|
driver->privileged = privileged;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
/* open netcf */
|
2014-10-23 14:17:18 +00:00
|
|
|
if (ncf_init(&driver->netcf, NULL) != 0) {
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to initialize netcf"));
|
2014-10-23 14:17:18 +00:00
|
|
|
virObjectUnref(driver);
|
|
|
|
driver = NULL;
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
netcfStateCleanup(void)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
2014-10-23 14:17:18 +00:00
|
|
|
if (!driver)
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
if (virObjectUnref(driver)) {
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Attempt to close netcf state driver "
|
|
|
|
"with open connections"));
|
|
|
|
return -1;
|
|
|
|
}
|
2014-10-23 14:17:18 +00:00
|
|
|
driver = NULL;
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
return 0;
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
netcfStateReload(void)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
if (!driver)
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
virObjectLock(driver);
|
|
|
|
ncf_close(driver->netcf);
|
|
|
|
if (ncf_init(&driver->netcf, NULL) != 0) {
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
/* this isn't a good situation, because we can't shut down the
|
|
|
|
* driver as there may still be connections to it. If we set
|
|
|
|
* the netcf handle to NULL, any subsequent calls to netcf
|
|
|
|
* will just fail rather than causing a crash. Not ideal, but
|
|
|
|
* livable (since this should never happen).
|
|
|
|
*/
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to re-init netcf"));
|
2014-10-23 14:17:18 +00:00
|
|
|
driver->netcf = NULL;
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2014-10-23 14:17:18 +00:00
|
|
|
virObjectUnlock(driver);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-26 11:16:00 +00:00
|
|
|
static virDrvOpenStatus
|
|
|
|
netcfConnectOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
virConfPtr conf ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
|
|
|
/* Verify uri was specified */
|
|
|
|
if (conn->uri == NULL) {
|
|
|
|
/* Only hypervisor drivers are permitted to auto-open on NULL uri */
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
} else {
|
|
|
|
if (STRNEQ_NULLABLE(conn->uri->scheme, "interface"))
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* Leave for remote driver */
|
|
|
|
if (conn->uri->server != NULL)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("interface state driver is not active"));
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driver->privileged) {
|
|
|
|
if (STRNEQ(conn->uri->path, "/system")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected interface URI path '%s', try interface:///system"),
|
|
|
|
conn->uri->path);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (STRNEQ(conn->uri->path, "/session")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected interface URI path '%s', try interface:///session"),
|
|
|
|
conn->uri->path);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virConnectOpenEnsureACL(conn) < 0)
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcfConnectClose(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int netcfConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* Trivially secure, since always inside the daemon */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int netcfConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* Not encrypted, but remote driver takes care of that */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int netcfConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
/*
|
|
|
|
* Get a minimal virInterfaceDef containing enough metadata
|
|
|
|
* for access control checks to be performed. Currently
|
2014-04-20 20:07:46 +00:00
|
|
|
* this implies existence of name and mac address attributes
|
2013-04-23 10:56:22 +00:00
|
|
|
*/
|
|
|
|
static virInterfaceDef * ATTRIBUTE_NONNULL(1)
|
|
|
|
netcfGetMinimalDefForDevice(struct netcf_if *iface)
|
|
|
|
{
|
|
|
|
virInterfaceDef *def;
|
|
|
|
|
|
|
|
/* Allocate our interface definition structure */
|
2013-07-04 10:10:05 +00:00
|
|
|
if (VIR_ALLOC(def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(def->name, ncf_if_name(iface)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(def->mac, ncf_if_mac_string(iface)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
return def;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
static int netcf_to_vir_err(int netcf_errcode)
|
|
|
|
{
|
2014-09-03 22:24:43 +00:00
|
|
|
switch (netcf_errcode) {
|
2009-07-21 14:02:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-10 17:56:57 +00:00
|
|
|
static int
|
|
|
|
netcfInterfaceObjIsActive(struct netcf_if *iface,
|
|
|
|
bool *active)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
2014-10-23 14:17:18 +00:00
|
|
|
virObjectRef(driver);
|
2013-12-10 17:56:57 +00:00
|
|
|
if (ncf_if_status(iface, &flags) < 0) {
|
|
|
|
const char *errmsg, *details;
|
2014-10-23 14:17:18 +00:00
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2013-12-10 17:56:57 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get status of interface %s: %s%s%s"),
|
|
|
|
ncf_if_name(iface), errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
*active = flags & NETCF_IFACE_ACTIVE;
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2014-10-23 14:17:18 +00:00
|
|
|
virObjectUnref(driver);
|
2013-12-10 17:56:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
static int netcfConnectNumOfInterfacesImpl(virConnectPtr conn,
|
|
|
|
int status,
|
|
|
|
virInterfaceObjListFilter filter)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
2013-06-27 16:07:22 +00:00
|
|
|
int count;
|
|
|
|
int want = 0;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/interface/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-06-27 16:07:22 +00:00
|
|
|
char **names = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
/* List all interfaces, in case we might support new filter flags
|
|
|
|
* beyond active|inactive in future.
|
|
|
|
*/
|
|
|
|
count = ncf_num_of_interfaces(driver->netcf, status);
|
2009-07-21 14:02:16 +00:00
|
|
|
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),
|
2013-06-27 16:07:22 +00:00
|
|
|
_("failed to get number of host interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
goto cleanup;
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
if (count == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:10:05 +00:00
|
|
|
if (VIR_ALLOC_N(names, count) < 0)
|
2013-06-27 16:07:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((count = ncf_list_interfaces(driver->netcf, count, names, status)) < 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
virInterfaceDefPtr def;
|
|
|
|
struct netcf_if *iface;
|
|
|
|
|
|
|
|
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 (!(def = netcfGetMinimalDefForDevice(iface))) {
|
|
|
|
ncf_if_free(iface);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ncf_if_free(iface);
|
|
|
|
|
|
|
|
if (!filter(conn, def)) {
|
|
|
|
virInterfaceDefFree(def);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
virInterfaceDefFree(def);
|
|
|
|
|
|
|
|
want++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = want;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
Convert 'int i' to 'size_t i' in src/interface/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (names && count > 0)
|
2013-06-27 16:07:22 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
VIR_FREE(names);
|
|
|
|
return ret;
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
|
|
|
|
static int netcfConnectListInterfacesImpl(virConnectPtr conn,
|
|
|
|
int status,
|
|
|
|
char **const names, int nnames,
|
|
|
|
virInterfaceObjListFilter filter)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
2013-06-27 16:07:22 +00:00
|
|
|
int count = 0;
|
|
|
|
int want = 0;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/interface/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-06-27 16:07:22 +00:00
|
|
|
char **allnames = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
count = ncf_num_of_interfaces(driver->netcf, status);
|
|
|
|
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 : "");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-04-23 10:56:22 +00:00
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
if (count == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2013-07-04 10:10:05 +00:00
|
|
|
if (VIR_ALLOC_N(allnames, count) < 0)
|
2013-06-27 16:07:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((count = ncf_list_interfaces(driver->netcf, count, allnames, status)) < 0) {
|
2009-07-21 14:02:16 +00:00
|
|
|
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 : "");
|
2013-06-27 16:07:22 +00:00
|
|
|
goto cleanup;
|
2009-07-21 14:02:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
if (count == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count && want < nnames; i++) {
|
|
|
|
virInterfaceDefPtr def;
|
|
|
|
struct netcf_if *iface;
|
|
|
|
|
|
|
|
iface = ncf_lookup_by_name(driver->netcf, allnames[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"),
|
|
|
|
allnames[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", allnames[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface))) {
|
|
|
|
ncf_if_free(iface);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ncf_if_free(iface);
|
|
|
|
|
|
|
|
if (!filter(conn, def)) {
|
|
|
|
virInterfaceDefFree(def);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
virInterfaceDefFree(def);
|
|
|
|
|
|
|
|
names[want++] = allnames[i];
|
|
|
|
allnames[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = want;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
Convert 'int i' to 'size_t i' in src/interface/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (allnames && count > 0)
|
2013-06-27 16:07:22 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
VIR_FREE(allnames[i]);
|
|
|
|
VIR_FREE(allnames);
|
|
|
|
if (ret < 0) {
|
|
|
|
for (i = 0; i < nnames; i++)
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int netcfConnectNumOfInterfaces(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (virConnectNumOfInterfacesEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2013-06-27 16:07:22 +00:00
|
|
|
count = netcfConnectNumOfInterfacesImpl(conn,
|
|
|
|
NETCF_IFACE_ACTIVE,
|
|
|
|
virConnectNumOfInterfacesCheckACL);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2013-06-27 16:07:22 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcfConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (virConnectListInterfacesEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2013-06-27 16:07:22 +00:00
|
|
|
count = netcfConnectListInterfacesImpl(conn,
|
|
|
|
NETCF_IFACE_ACTIVE,
|
|
|
|
names, nnames,
|
|
|
|
virConnectListInterfacesCheckACL);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfConnectNumOfDefinedInterfaces(virConnectPtr conn)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectNumOfDefinedInterfacesEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2013-06-27 16:07:22 +00:00
|
|
|
count = netcfConnectNumOfInterfacesImpl(conn,
|
|
|
|
NETCF_IFACE_INACTIVE,
|
|
|
|
virConnectNumOfDefinedInterfacesCheckACL);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int nnames)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListDefinedInterfacesEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2013-06-27 16:07:22 +00:00
|
|
|
count = netcfConnectListInterfacesImpl(conn,
|
|
|
|
NETCF_IFACE_INACTIVE,
|
|
|
|
names, nnames,
|
|
|
|
virConnectListDefinedInterfacesCheckACL);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-21 13:29:38 +00:00
|
|
|
#define MATCH(FLAG) (flags & (FLAG))
|
2012-09-04 16:10:17 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
netcfConnectListAllInterfaces(virConnectPtr conn,
|
|
|
|
virInterfacePtr **ifaces,
|
|
|
|
unsigned int flags)
|
2012-09-04 16:10:17 +00:00
|
|
|
{
|
|
|
|
int count;
|
Convert 'int i' to 'size_t i' in src/interface/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2015-09-18 17:51:33 +00:00
|
|
|
unsigned int ncf_flags = 0;
|
2012-09-04 16:10:17 +00:00
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
virInterfacePtr *tmp_iface_objs = NULL;
|
|
|
|
virInterfacePtr iface_obj = NULL;
|
|
|
|
int niface_objs = 0;
|
|
|
|
int ret = -1;
|
|
|
|
char **names = NULL;
|
|
|
|
|
2013-05-21 13:29:38 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
|
2012-09-04 16:10:17 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListAllInterfacesEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2012-09-04 16:10:17 +00:00
|
|
|
|
2015-09-18 17:51:33 +00:00
|
|
|
/* let netcf pre-filter for this flag to save time */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE)) {
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE))
|
|
|
|
ncf_flags |= NETCF_IFACE_ACTIVE;
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE))
|
|
|
|
ncf_flags |= NETCF_IFACE_INACTIVE;
|
|
|
|
} else {
|
|
|
|
ncf_flags = NETCF_IFACE_ACTIVE | NETCF_IFACE_INACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((count = ncf_num_of_interfaces(driver->netcf, ncf_flags)) < 0) {
|
2012-09-04 16:10:17 +00:00
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2015-09-18 17:51:33 +00:00
|
|
|
|
2012-09-04 16:10:17 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to get number of host interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:10:05 +00:00
|
|
|
if (VIR_ALLOC_N(names, count) < 0)
|
2012-09-04 16:10:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-09-18 17:51:33 +00:00
|
|
|
if ((count = ncf_list_interfaces(driver->netcf, count,
|
|
|
|
names, ncf_flags)) < 0) {
|
2012-09-04 16:10:17 +00:00
|
|
|
const char *errmsg, *details;
|
|
|
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
2015-09-18 17:51:33 +00:00
|
|
|
|
2012-09-04 16:10:17 +00:00
|
|
|
virReportError(netcf_to_vir_err(errcode),
|
|
|
|
_("failed to list host interfaces: %s%s%s"),
|
|
|
|
errmsg, details ? " - " : "",
|
|
|
|
details ? details : "");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:10:05 +00:00
|
|
|
if (ifaces && VIR_ALLOC_N(tmp_iface_objs, count + 1) < 0)
|
|
|
|
goto cleanup;
|
2012-09-04 16:10:17 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2013-06-27 16:07:22 +00:00
|
|
|
virInterfaceDefPtr def;
|
2015-09-18 17:19:27 +00:00
|
|
|
|
2012-09-04 16:10:17 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 16:07:22 +00:00
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!virConnectListAllInterfacesCheckACL(conn, def)) {
|
|
|
|
ncf_if_free(iface);
|
|
|
|
iface = NULL;
|
|
|
|
virInterfaceDefFree(def);
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-21 13:29:38 +00:00
|
|
|
|
|
|
|
if (ifaces) {
|
2017-04-12 07:58:23 +00:00
|
|
|
if (!(iface_obj = virGetInterface(conn, def->name, def->mac))) {
|
|
|
|
virInterfaceDefFree(def);
|
2015-09-18 17:22:46 +00:00
|
|
|
goto cleanup;
|
2017-04-12 07:58:23 +00:00
|
|
|
}
|
2015-09-18 17:24:47 +00:00
|
|
|
tmp_iface_objs[niface_objs] = iface_obj;
|
2012-09-04 16:10:17 +00:00
|
|
|
}
|
2015-09-18 17:24:47 +00:00
|
|
|
niface_objs++;
|
2012-09-04 16:10:17 +00:00
|
|
|
|
2015-09-18 17:19:27 +00:00
|
|
|
virInterfaceDefFree(def);
|
2012-09-04 16:10:17 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-09-04 16:10:17 +00:00
|
|
|
ncf_if_free(iface);
|
|
|
|
|
Convert 'int i' to 'size_t i' in src/interface/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (names && count > 0)
|
2012-09-04 16:10:17 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
VIR_FREE(names);
|
|
|
|
|
|
|
|
if (tmp_iface_objs) {
|
2014-11-30 17:07:19 +00:00
|
|
|
for (i = 0; i < niface_objs; i++)
|
|
|
|
virObjectUnref(tmp_iface_objs[i]);
|
2013-01-09 14:54:16 +00:00
|
|
|
VIR_FREE(tmp_iface_objs);
|
2012-09-04 16:10:17 +00:00
|
|
|
}
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2012-09-04 16:10:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virInterfacePtr netcfInterfaceLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct netcf_if *iface;
|
|
|
|
virInterfacePtr ret = NULL;
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virInterfaceLookupByNameEnsureACL(conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-09-18 17:19:27 +00:00
|
|
|
ret = virGetInterface(conn, def->name, def->mac);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virInterfacePtr netcfInterfaceLookupByMACString(virConnectPtr conn,
|
|
|
|
const char *macstr)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct netcf_if *iface;
|
|
|
|
int niface;
|
|
|
|
virInterfacePtr ret = NULL;
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
|
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virInterfaceLookupByMACStringEnsureACL(conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-09-18 17:19:27 +00:00
|
|
|
ret = virGetInterface(conn, def->name, def->mac);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static char *netcfInterfaceGetXMLDesc(virInterfacePtr ifinfo,
|
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct netcf_if *iface = NULL;
|
|
|
|
char *xmlstr = NULL;
|
|
|
|
virInterfaceDefPtr ifacedef = NULL;
|
|
|
|
char *ret = NULL;
|
2014-04-07 12:32:00 +00:00
|
|
|
bool active;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
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);
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-04-07 12:32:00 +00:00
|
|
|
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((flags & VIR_INTERFACE_XML_INACTIVE) || !active) {
|
2009-10-28 09:40:54 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virInterfaceGetXMLDescEnsureACL(ifinfo->conn, ifacedef) < 0)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
|
|
|
VIR_FREE(xmlstr);
|
|
|
|
virInterfaceDefFree(ifacedef);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static virInterfacePtr netcfInterfaceDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virInterfaceDefineXMLEnsureACL(conn, ifacedef) < 0)
|
|
|
|
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));
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
|
|
|
VIR_FREE(xmlstr);
|
|
|
|
virInterfaceDefFree(ifacedef);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-18 08:19:33 +00:00
|
|
|
static int netcfInterfaceUndefine(virInterfacePtr ifinfo)
|
|
|
|
{
|
2009-07-21 14:02:16 +00:00
|
|
|
struct netcf_if *iface = NULL;
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
|
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virInterfaceUndefineEnsureACL(ifinfo->conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfInterfaceCreate(virInterfacePtr ifinfo,
|
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct netcf_if *iface = NULL;
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
int ret = -1;
|
2013-12-10 18:29:54 +00:00
|
|
|
bool active;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
|
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virInterfaceCreateEnsureACL(ifinfo->conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-12-10 18:29:54 +00:00
|
|
|
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("interface is already running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfInterfaceDestroy(virInterfacePtr ifinfo,
|
|
|
|
unsigned int flags)
|
2009-07-21 14:02:16 +00:00
|
|
|
{
|
|
|
|
struct netcf_if *iface = NULL;
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
2009-07-21 14:02:16 +00:00
|
|
|
int ret = -1;
|
2013-12-10 18:29:54 +00:00
|
|
|
bool active;
|
2009-07-21 14:02:16 +00:00
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
|
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virInterfaceDestroyEnsureACL(ifinfo->conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-12-10 18:29:54 +00:00
|
|
|
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("interface is not running"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-07-21 14:02:16 +00:00
|
|
|
ncf_if_free(iface);
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2009-07-21 14:02:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfInterfaceIsActive(virInterfacePtr ifinfo)
|
2010-04-13 17:22:56 +00:00
|
|
|
{
|
|
|
|
struct netcf_if *iface = NULL;
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
2010-04-13 17:22:56 +00:00
|
|
|
int ret = -1;
|
2013-12-10 17:56:57 +00:00
|
|
|
bool active;
|
2010-04-13 17:22:56 +00:00
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2010-04-13 17:22:56 +00:00
|
|
|
|
|
|
|
iface = interfaceDriverGetNetcfIF(driver->netcf, ifinfo);
|
|
|
|
if (!iface) {
|
|
|
|
/* helper already reported error */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virInterfaceIsActiveEnsureACL(ifinfo->conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-12-10 17:56:57 +00:00
|
|
|
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
2010-04-13 17:22:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-12-10 17:56:57 +00:00
|
|
|
ret = active ? 1 : 0;
|
2010-04-13 17:22:56 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-04-13 17:22:56 +00:00
|
|
|
ncf_if_free(iface);
|
2013-04-23 10:56:22 +00:00
|
|
|
virInterfaceDefFree(def);
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2010-04-13 17:22:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-06 12:54:53 +00:00
|
|
|
#ifdef HAVE_NETCF_TRANSACTIONS
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfInterfaceChangeBegin(virConnectPtr conn, unsigned int flags)
|
2011-05-06 12:54:53 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1); /* currently flags must be 0 */
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virInterfaceChangeBeginEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2011-05-06 12:54:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2011-05-06 12:54:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfInterfaceChangeCommit(virConnectPtr conn, unsigned int flags)
|
2011-05-06 12:54:53 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1); /* currently flags must be 0 */
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virInterfaceChangeCommitEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2011-05-06 12:54:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2011-05-06 12:54:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int netcfInterfaceChangeRollback(virConnectPtr conn, unsigned int flags)
|
2011-05-06 12:54:53 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1); /* currently flags must be 0 */
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virInterfaceChangeRollbackEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectLock(driver);
|
2011-05-06 12:54:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
virObjectUnlock(driver);
|
2011-05-06 12:54:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_NETCF_TRANSACTIONS */
|
|
|
|
|
2009-07-21 14:02:16 +00:00
|
|
|
static virInterfaceDriver interfaceDriver = {
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
.name = INTERFACE_DRIVER_NAME,
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfInterfaces = netcfConnectNumOfInterfaces, /* 0.7.0 */
|
|
|
|
.connectListInterfaces = netcfConnectListInterfaces, /* 0.7.0 */
|
|
|
|
.connectNumOfDefinedInterfaces = netcfConnectNumOfDefinedInterfaces, /* 0.7.0 */
|
|
|
|
.connectListDefinedInterfaces = netcfConnectListDefinedInterfaces, /* 0.7.0 */
|
|
|
|
.connectListAllInterfaces = netcfConnectListAllInterfaces, /* 0.10.2 */
|
|
|
|
.interfaceLookupByName = netcfInterfaceLookupByName, /* 0.7.0 */
|
|
|
|
.interfaceLookupByMACString = netcfInterfaceLookupByMACString, /* 0.7.0 */
|
|
|
|
.interfaceGetXMLDesc = netcfInterfaceGetXMLDesc, /* 0.7.0 */
|
|
|
|
.interfaceDefineXML = netcfInterfaceDefineXML, /* 0.7.0 */
|
|
|
|
.interfaceUndefine = netcfInterfaceUndefine, /* 0.7.0 */
|
|
|
|
.interfaceCreate = netcfInterfaceCreate, /* 0.7.0 */
|
|
|
|
.interfaceDestroy = netcfInterfaceDestroy, /* 0.7.0 */
|
|
|
|
.interfaceIsActive = netcfInterfaceIsActive, /* 0.7.3 */
|
2011-05-06 12:54:53 +00:00
|
|
|
#ifdef HAVE_NETCF_TRANSACTIONS
|
2013-04-23 12:50:18 +00:00
|
|
|
.interfaceChangeBegin = netcfInterfaceChangeBegin, /* 0.9.2 */
|
|
|
|
.interfaceChangeCommit = netcfInterfaceChangeCommit, /* 0.9.2 */
|
|
|
|
.interfaceChangeRollback = netcfInterfaceChangeRollback, /* 0.9.2 */
|
2011-05-06 12:54:53 +00:00
|
|
|
#endif /* HAVE_NETCF_TRANSACTIONS */
|
2009-07-21 14:02:16 +00:00
|
|
|
};
|
|
|
|
|
2018-01-26 11:16:00 +00:00
|
|
|
|
|
|
|
static virHypervisorDriver interfaceHypervisorDriver = {
|
|
|
|
.name = "interface",
|
|
|
|
.connectOpen = netcfConnectOpen, /* 4.1.0 */
|
|
|
|
.connectClose = netcfConnectClose, /* 4.1.0 */
|
|
|
|
.connectIsEncrypted = netcfConnectIsEncrypted, /* 4.1.0 */
|
|
|
|
.connectIsSecure = netcfConnectIsSecure, /* 4.1.0 */
|
|
|
|
.connectIsAlive = netcfConnectIsAlive, /* 4.1.0 */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static virConnectDriver interfaceConnectDriver = {
|
|
|
|
.hypervisorDriver = &interfaceHypervisorDriver,
|
|
|
|
.interfaceDriver = &interfaceDriver,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
netcf driver: use a single netcf handle for all connections
This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=983026
The netcf interface driver previously had no state driver associated
with it - as a connection was opened, it would create a new netcf
instance just for that connection, and close it when it was
finished. the problem with this is that each connection to libvirt
used up a netlink socket, and there is a per process maximum of ~1000
netlink sockets.
The solution is to create a state driver to go along with the netcf
driver. The state driver will opens a netcf instance, then all
connections share that same netcf instance, thus only a single
netlink socket will be used no matter how many connections are mde to
libvirtd.
This was rather simple to do - a new virObjectLockable class is
created for the single driverState object, which is created in
netcfStateInitialize and contains the single netcf handle; instead of
creating a new object for each client connection, netcfInterfaceOpen
now just increments the driverState object's reference count and puts
a pointer to it into the connection's privateData. Similarly,
netcfInterfaceClose() just un-refs the driverState object (as does
netcfStateCleanup()), and virNetcfInterfaceDriverStateDispose()
handles closing the netcf instance. Since all the functions already
have locking around them, the static lock functions used by all
functions just needed to be changed to call virObjectLock() and
virObjectUnlock() instead of directly calling the virMutex* functions.
2013-08-28 16:56:21 +00:00
|
|
|
static virStateDriver interfaceStateDriver = {
|
|
|
|
.name = INTERFACE_DRIVER_NAME,
|
|
|
|
.stateInitialize = netcfStateInitialize,
|
|
|
|
.stateCleanup = netcfStateCleanup,
|
|
|
|
.stateReload = netcfStateReload,
|
|
|
|
};
|
|
|
|
|
2014-03-18 08:19:33 +00:00
|
|
|
int netcfIfaceRegister(void)
|
|
|
|
{
|
2018-01-26 11:16:00 +00:00
|
|
|
if (virRegisterConnectDriver(&interfaceConnectDriver, false) < 0)
|
|
|
|
return -1;
|
2015-01-20 16:16:26 +00:00
|
|
|
if (virSetSharedInterfaceDriver(&interfaceDriver) < 0)
|
2012-10-06 19:20:26 +00:00
|
|
|
return -1;
|
2014-03-17 13:35:42 +00:00
|
|
|
if (virRegisterStateDriver(&interfaceStateDriver) < 0)
|
|
|
|
return -1;
|
2009-07-21 14:02:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|