Currently, whenever virNetworkObjSetMacMap() is called the same
pattern is used:
1) call virMacMapFileName() to generate a filename,
2) pass this filename to virMacMapNew(), and finally
3) pass retval from previous step to virNetworkObjSetMacMap().
Move this code into a helper (networkSetMacMap()) and replace
both pattern occurrences with its call.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/network/bridge_driver.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 024487b359..7098054f77 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -443,6 +443,24 @@ networkUpdatePort(virNetworkPortDef *port,
return false;
}
+static int
+networkSetMacMap(virNetworkDriverState *driver,
+ virNetworkObj *obj)
+{
+ virNetworkDef *def = virNetworkObjGetDef(obj);
+ g_autoptr(virMacMap) macmap = NULL;
+ g_autofree char *macMapFile = NULL;
+
+ if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
+ def->bridge)))
+ return -1;
+ if (!(macmap = virMacMapNew(macMapFile)))
+ return -1;
+
+ virNetworkObjSetMacMap(obj, &macmap);
+ return 0;
+}
+
static int
networkUpdateState(virNetworkObj *obj,
void *opaque)
@@ -450,8 +468,6 @@ networkUpdateState(virNetworkObj *obj,
virNetworkDef *def;
virNetworkDriverState *driver = opaque;
g_autoptr(dnsmasqCaps) dnsmasq_caps = networkGetDnsmasqCaps(driver);
- g_autoptr(virMacMap) macmap = NULL;
- g_autofree char *macMapFile = NULL;
VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
if (!virNetworkObjIsActive(obj))
@@ -468,15 +484,9 @@ networkUpdateState(virNetworkObj *obj,
if (!(def->bridge && virNetDevExists(def->bridge) == 1))
virNetworkObjSetActive(obj, false);
- if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
- def->bridge)))
+ if (networkSetMacMap(driver, obj) < 0)
return -1;
- if (!(macmap = virMacMapNew(macMapFile)))
- return -1;
-
- virNetworkObjSetMacMap(obj, &macmap);
-
break;
case VIR_NETWORK_FORWARD_BRIDGE:
@@ -1938,8 +1948,6 @@ networkStartNetworkVirtual(virNetworkDriverState *driver,
virErrorPtr save_err = NULL;
virNetworkIPDef *ipdef;
virNetDevIPRoute *routedef;
- g_autoptr(virMacMap) macmap = NULL;
- g_autofree char *macMapFile = NULL;
bool dnsmasqStarted = false;
bool devOnline = false;
bool firewalRulesAdded = false;
@@ -1966,13 +1974,9 @@ networkStartNetworkVirtual(virNetworkDriverState *driver,
if (virNetDevBridgeCreate(def->bridge, &def->mac) < 0)
return -1;
- if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
- def->bridge)) ||
- !(macmap = virMacMapNew(macMapFile)))
+ if (networkSetMacMap(driver, obj) < 0)
goto error;
- virNetworkObjSetMacMap(obj, &macmap);
-
/* Set bridge options */
if (def->mtu && virNetDevSetMTU(def->bridge, def->mtu) < 0)
--
2.35.1