network: move driver state struct into bridge_driver_conf.h

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Laine Stump 2022-03-13 14:21:02 -04:00
parent 15bd9179be
commit 3fcae3c6d4
5 changed files with 129 additions and 63 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -1,5 +1,6 @@
network_driver_sources = [
'bridge_driver.c',
'bridge_driver_conf.c',
'bridge_driver_platform.c',
]