This is more similar to lxc and qemu drivers, where the driver state struct is defined along with a config struct in ${driver}_conf.h Signed-off-by: Laine Stump <laine@xxxxxxxxxx> --- src/network/bridge_driver.c | 25 ----------- src/network/bridge_driver_conf.c | 56 +++++++++++++++++++++++ src/network/bridge_driver_conf.h | 67 ++++++++++++++++++++++++++++ src/network/bridge_driver_platform.h | 43 +++--------------- src/network/meson.build | 1 + 5 files changed, 129 insertions(+), 63 deletions(-) create mode 100644 src/network/bridge_driver_conf.c create mode 100644 src/network/bridge_driver_conf.h diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 733abaa719..3c36a66ec7 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -95,31 +95,6 @@ networkGetDriver(void) } -static dnsmasqCaps * -networkGetDnsmasqCaps(virNetworkDriverState *driver) -{ - VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock); - return virObjectRef(driver->dnsmasqCaps); -} - - -static int -networkDnsmasqCapsRefresh(virNetworkDriverState *driver) -{ - dnsmasqCaps *caps; - - if (!(caps = dnsmasqCapsNewFromBinary())) - return -1; - - VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { - virObjectUnref(driver->dnsmasqCaps); - driver->dnsmasqCaps = caps; - } - - return 0; -} - - extern virXMLNamespace networkDnsmasqXMLNamespace; typedef struct _networkDnsmasqXmlNsDef networkDnsmasqXmlNsDef; diff --git a/src/network/bridge_driver_conf.c b/src/network/bridge_driver_conf.c new file mode 100644 index 0000000000..b6c059e1e9 --- /dev/null +++ b/src/network/bridge_driver_conf.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 Red Hat, Inc. + * + * bridge_driver__conf.c: network.conf config file inspection + * + * 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 + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +/* includes */ +#include <config.h> +#include "virerror.h" +#include "datatypes.h" +#include "virlog.h" +#include "bridge_driver_conf.h" + +#define VIR_FROM_THIS VIR_FROM_NETWORK + +VIR_LOG_INIT("network.bridge_driver"); + + +dnsmasqCaps * +networkGetDnsmasqCaps(virNetworkDriverState *driver) +{ + VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock); + return virObjectRef(driver->dnsmasqCaps); +} + + +int +networkDnsmasqCapsRefresh(virNetworkDriverState *driver) +{ + dnsmasqCaps *caps; + + if (!(caps = dnsmasqCapsNewFromBinary())) + return -1; + + VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) { + virObjectUnref(driver->dnsmasqCaps); + driver->dnsmasqCaps = caps; + } + + return 0; +} diff --git a/src/network/bridge_driver_conf.h b/src/network/bridge_driver_conf.h new file mode 100644 index 0000000000..f4307bbdba --- /dev/null +++ b/src/network/bridge_driver_conf.h @@ -0,0 +1,67 @@ +/* + * bridge_driver_conf.h: network bridge driver state and config objects + * + * Copyright (C) 2006-2013 Red Hat, Inc. + * Copyright (C) 2006 Daniel P. Berrange + * + * 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 + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "internal.h" +#include "virthread.h" +#include "virdnsmasq.h" +#include "virnetworkobj.h" +#include "object_event.h" + +/* Main driver state */ +struct _virNetworkDriverState { + virMutex lock; + + /* Read-only */ + bool privileged; + + /* pid file FD, ensures two copies of the driver can't use the same root */ + int lockFD; + + /* Immutable pointer, self-locking APIs */ + virNetworkObjList *networks; + + /* Immutable pointers, Immutable objects */ + char *networkConfigDir; + char *networkAutostartDir; + char *stateDir; + char *pidDir; + char *dnsmasqStateDir; + + /* Require lock to get a reference on the object, + * lockless access thereafter + */ + dnsmasqCaps *dnsmasqCaps; + + /* Immutable pointer, self-locking APIs */ + virObjectEventState *networkEventState; + + virNetworkXMLOption *xmlopt; +}; + +typedef struct _virNetworkDriverState virNetworkDriverState; + +dnsmasqCaps * +networkGetDnsmasqCaps(virNetworkDriverState *driver); + +int +networkDnsmasqCapsRefresh(virNetworkDriverState *driver); diff --git a/src/network/bridge_driver_platform.h b/src/network/bridge_driver_platform.h index de7cbc1195..b720d343be 100644 --- a/src/network/bridge_driver_platform.h +++ b/src/network/bridge_driver_platform.h @@ -21,46 +21,13 @@ #pragma once -#include "internal.h" -#include "virthread.h" -#include "virdnsmasq.h" -#include "virnetworkobj.h" -#include "object_event.h" +#include "network_conf.h" +#include "bridge_driver_conf.h" -/* Main driver state */ -struct _virNetworkDriverState { - virMutex lock; +void networkPreReloadFirewallRules(virNetworkDriverState *driver, + bool startup, + bool force); - /* Read-only */ - bool privileged; - - /* pid file FD, ensures two copies of the driver can't use the same root */ - int lockFD; - - /* Immutable pointer, self-locking APIs */ - virNetworkObjList *networks; - - /* Immutable pointers, Immutable objects */ - char *networkConfigDir; - char *networkAutostartDir; - char *stateDir; - char *pidDir; - char *dnsmasqStateDir; - - /* Require lock to get a reference on the object, - * lockless access thereafter - */ - dnsmasqCaps *dnsmasqCaps; - - /* Immutable pointer, self-locking APIs */ - virObjectEventState *networkEventState; - - virNetworkXMLOption *xmlopt; -}; - -typedef struct _virNetworkDriverState virNetworkDriverState; - -void networkPreReloadFirewallRules(virNetworkDriverState *driver, bool startup, bool force); void networkPostReloadFirewallRules(bool startup); int networkCheckRouteCollision(virNetworkDef *def); diff --git a/src/network/meson.build b/src/network/meson.build index b5eff0c3ab..395074a0a0 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -1,5 +1,6 @@ network_driver_sources = [ 'bridge_driver.c', + 'bridge_driver_conf.c', 'bridge_driver_platform.c', ] -- 2.37.1