提交 2ea3ce33 编写于 作者: M Michal Privoznik

bridge_driver: s/virNetworkObjList/virNetworkObjListPtr/

In order to hide the object internals (and use just accessors
everywhere), lets store a pointer to the object, instead of object
itself.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 c3dfec15
...@@ -130,7 +130,7 @@ networkObjFromNetwork(virNetworkPtr net) ...@@ -130,7 +130,7 @@ networkObjFromNetwork(virNetworkPtr net)
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(driver->networks, net->uuid);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
...@@ -303,7 +303,7 @@ networkRemoveInactive(virNetworkObjPtr net) ...@@ -303,7 +303,7 @@ networkRemoveInactive(virNetworkObjPtr net)
unlink(statusfile); unlink(statusfile);
/* remove the network definition */ /* remove the network definition */
virNetworkRemoveInactive(&driver->networks, net); virNetworkRemoveInactive(driver->networks, net);
ret = 0; ret = 0;
...@@ -350,8 +350,8 @@ networkUpdateAllState(void) ...@@ -350,8 +350,8 @@ networkUpdateAllState(void)
{ {
size_t i; size_t i;
for (i = 0; i < driver->networks.count; i++) { for (i = 0; i < driver->networks->count; i++) {
virNetworkObjPtr obj = driver->networks.objs[i]; virNetworkObjPtr obj = driver->networks->objs[i];
virNetworkObjLock(obj); virNetworkObjLock(obj);
if (!virNetworkObjIsActive(obj)) { if (!virNetworkObjIsActive(obj)) {
...@@ -411,8 +411,8 @@ networkUpdateAllState(void) ...@@ -411,8 +411,8 @@ networkUpdateAllState(void)
/* remove inactive transient networks */ /* remove inactive transient networks */
i = 0; i = 0;
while (i < driver->networks.count) { while (i < driver->networks->count) {
virNetworkObjPtr obj = driver->networks.objs[i]; virNetworkObjPtr obj = driver->networks->objs[i];
virNetworkObjLock(obj); virNetworkObjLock(obj);
if (!obj->persistent && !obj->active) { if (!obj->persistent && !obj->active) {
...@@ -431,15 +431,15 @@ networkAutostartConfigs(void) ...@@ -431,15 +431,15 @@ networkAutostartConfigs(void)
{ {
size_t i; size_t i;
for (i = 0; i < driver->networks.count; i++) { for (i = 0; i < driver->networks->count; i++) {
virNetworkObjLock(driver->networks.objs[i]); virNetworkObjLock(driver->networks->objs[i]);
if (driver->networks.objs[i]->autostart && if (driver->networks->objs[i]->autostart &&
!virNetworkObjIsActive(driver->networks.objs[i])) { !virNetworkObjIsActive(driver->networks->objs[i])) {
if (networkStartNetwork(driver->networks.objs[i]) < 0) { if (networkStartNetwork(driver->networks->objs[i]) < 0) {
/* failed to start but already logged */ /* failed to start but already logged */
} }
} }
virNetworkObjUnlock(driver->networks.objs[i]); virNetworkObjUnlock(driver->networks->objs[i]);
} }
} }
...@@ -638,11 +638,14 @@ networkStateInitialize(bool privileged, ...@@ -638,11 +638,14 @@ networkStateInitialize(bool privileged,
/* if this fails now, it will be retried later with dnsmasqCapsRefresh() */ /* if this fails now, it will be retried later with dnsmasqCapsRefresh() */
driver->dnsmasqCaps = dnsmasqCapsNewFromBinary(DNSMASQ); driver->dnsmasqCaps = dnsmasqCapsNewFromBinary(DNSMASQ);
if (virNetworkLoadAllState(&driver->networks, if (VIR_ALLOC(driver->networks) < 0)
goto error;
if (virNetworkLoadAllState(driver->networks,
driver->stateDir) < 0) driver->stateDir) < 0)
goto error; goto error;
if (virNetworkLoadAllConfigs(&driver->networks, if (virNetworkLoadAllConfigs(driver->networks,
driver->networkConfigDir, driver->networkConfigDir,
driver->networkAutostartDir) < 0) driver->networkAutostartDir) < 0)
goto error; goto error;
...@@ -723,9 +726,9 @@ networkStateReload(void) ...@@ -723,9 +726,9 @@ networkStateReload(void)
return 0; return 0;
networkDriverLock(); networkDriverLock();
virNetworkLoadAllState(&driver->networks, virNetworkLoadAllState(driver->networks,
driver->stateDir); driver->stateDir);
virNetworkLoadAllConfigs(&driver->networks, virNetworkLoadAllConfigs(driver->networks,
driver->networkConfigDir, driver->networkConfigDir,
driver->networkAutostartDir); driver->networkAutostartDir);
networkReloadFirewallRules(); networkReloadFirewallRules();
...@@ -752,7 +755,8 @@ networkStateCleanup(void) ...@@ -752,7 +755,8 @@ networkStateCleanup(void)
virObjectEventStateFree(driver->networkEventState); virObjectEventStateFree(driver->networkEventState);
/* free inactive networks */ /* free inactive networks */
virNetworkObjListFree(&driver->networks); virNetworkObjListFree(driver->networks);
VIR_FREE(driver->networks);
VIR_FREE(driver->networkConfigDir); VIR_FREE(driver->networkConfigDir);
VIR_FREE(driver->networkAutostartDir); VIR_FREE(driver->networkAutostartDir);
...@@ -1751,8 +1755,8 @@ networkRefreshDaemons(void) ...@@ -1751,8 +1755,8 @@ networkRefreshDaemons(void)
VIR_INFO("Refreshing network daemons"); VIR_INFO("Refreshing network daemons");
for (i = 0; i < driver->networks.count; i++) { for (i = 0; i < driver->networks->count; i++) {
virNetworkObjPtr network = driver->networks.objs[i]; virNetworkObjPtr network = driver->networks->objs[i];
virNetworkObjLock(network); virNetworkObjLock(network);
if (virNetworkObjIsActive(network) && if (virNetworkObjIsActive(network) &&
...@@ -1779,8 +1783,8 @@ networkReloadFirewallRules(void) ...@@ -1779,8 +1783,8 @@ networkReloadFirewallRules(void)
VIR_INFO("Reloading iptables rules"); VIR_INFO("Reloading iptables rules");
for (i = 0; i < driver->networks.count; i++) { for (i = 0; i < driver->networks->count; i++) {
virNetworkObjPtr network = driver->networks.objs[i]; virNetworkObjPtr network = driver->networks->objs[i];
virNetworkObjLock(network); virNetworkObjLock(network);
if (virNetworkObjIsActive(network) && if (virNetworkObjIsActive(network) &&
...@@ -2472,7 +2476,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn, ...@@ -2472,7 +2476,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
virNetworkPtr ret = NULL; virNetworkPtr ret = NULL;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, uuid); network = virNetworkFindByUUID(driver->networks, uuid);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
...@@ -2501,7 +2505,7 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn, ...@@ -2501,7 +2505,7 @@ static virNetworkPtr networkLookupByName(virConnectPtr conn,
virNetworkPtr ret = NULL; virNetworkPtr ret = NULL;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByName(&driver->networks, name); network = virNetworkFindByName(driver->networks, name);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -2529,8 +2533,8 @@ static int networkConnectNumOfNetworks(virConnectPtr conn) ...@@ -2529,8 +2533,8 @@ static int networkConnectNumOfNetworks(virConnectPtr conn)
return -1; return -1;
networkDriverLock(); networkDriverLock();
for (i = 0; i < driver->networks.count; i++) { for (i = 0; i < driver->networks->count; i++) {
virNetworkObjPtr obj = driver->networks.objs[i]; virNetworkObjPtr obj = driver->networks->objs[i];
virNetworkObjLock(obj); virNetworkObjLock(obj);
if (virConnectNumOfNetworksCheckACL(conn, obj->def) && if (virConnectNumOfNetworksCheckACL(conn, obj->def) &&
virNetworkObjIsActive(obj)) virNetworkObjIsActive(obj))
...@@ -2550,8 +2554,8 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in ...@@ -2550,8 +2554,8 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in
return -1; return -1;
networkDriverLock(); networkDriverLock();
for (i = 0; i < driver->networks.count && got < nnames; i++) { for (i = 0; i < driver->networks->count && got < nnames; i++) {
virNetworkObjPtr obj = driver->networks.objs[i]; virNetworkObjPtr obj = driver->networks->objs[i];
virNetworkObjLock(obj); virNetworkObjLock(obj);
if (virConnectListNetworksCheckACL(conn, obj->def) && if (virConnectListNetworksCheckACL(conn, obj->def) &&
virNetworkObjIsActive(obj)) { virNetworkObjIsActive(obj)) {
...@@ -2583,8 +2587,8 @@ static int networkConnectNumOfDefinedNetworks(virConnectPtr conn) ...@@ -2583,8 +2587,8 @@ static int networkConnectNumOfDefinedNetworks(virConnectPtr conn)
return -1; return -1;
networkDriverLock(); networkDriverLock();
for (i = 0; i < driver->networks.count; i++) { for (i = 0; i < driver->networks->count; i++) {
virNetworkObjPtr obj = driver->networks.objs[i]; virNetworkObjPtr obj = driver->networks->objs[i];
virNetworkObjLock(obj); virNetworkObjLock(obj);
if (virConnectNumOfDefinedNetworksCheckACL(conn, obj->def) && if (virConnectNumOfDefinedNetworksCheckACL(conn, obj->def) &&
!virNetworkObjIsActive(obj)) !virNetworkObjIsActive(obj))
...@@ -2604,8 +2608,8 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na ...@@ -2604,8 +2608,8 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na
return -1; return -1;
networkDriverLock(); networkDriverLock();
for (i = 0; i < driver->networks.count && got < nnames; i++) { for (i = 0; i < driver->networks->count && got < nnames; i++) {
virNetworkObjPtr obj = driver->networks.objs[i]; virNetworkObjPtr obj = driver->networks->objs[i];
virNetworkObjLock(obj); virNetworkObjLock(obj);
if (virConnectListDefinedNetworksCheckACL(conn, obj->def) && if (virConnectListDefinedNetworksCheckACL(conn, obj->def) &&
!virNetworkObjIsActive(obj)) { !virNetworkObjIsActive(obj)) {
...@@ -2640,7 +2644,7 @@ networkConnectListAllNetworks(virConnectPtr conn, ...@@ -2640,7 +2644,7 @@ networkConnectListAllNetworks(virConnectPtr conn,
goto cleanup; goto cleanup;
networkDriverLock(); networkDriverLock();
ret = virNetworkObjListExport(conn, &driver->networks, nets, ret = virNetworkObjListExport(conn, driver->networks, nets,
virConnectListAllNetworksCheckACL, virConnectListAllNetworksCheckACL,
flags); flags);
networkDriverUnlock(); networkDriverUnlock();
...@@ -2743,7 +2747,7 @@ networkValidate(virNetworkDefPtr def, ...@@ -2743,7 +2747,7 @@ networkValidate(virNetworkDefPtr def,
bool usesInterface = false, usesAddress = false; bool usesInterface = false, usesAddress = false;
/* check for duplicate networks */ /* check for duplicate networks */
if (virNetworkObjIsDuplicate(&driver->networks, def, check_active) < 0) if (virNetworkObjIsDuplicate(driver->networks, def, check_active) < 0)
return -1; return -1;
/* Only the three L3 network types that are configured by libvirt /* Only the three L3 network types that are configured by libvirt
...@@ -2753,7 +2757,7 @@ networkValidate(virNetworkDefPtr def, ...@@ -2753,7 +2757,7 @@ networkValidate(virNetworkDefPtr def,
def->forward.type == VIR_NETWORK_FORWARD_NAT || def->forward.type == VIR_NETWORK_FORWARD_NAT ||
def->forward.type == VIR_NETWORK_FORWARD_ROUTE) { def->forward.type == VIR_NETWORK_FORWARD_ROUTE) {
if (virNetworkSetBridgeName(&driver->networks, def, 1)) if (virNetworkSetBridgeName(driver->networks, def, 1))
return -1; return -1;
virNetworkSetBridgeMacAddr(def); virNetworkSetBridgeMacAddr(def);
...@@ -2971,12 +2975,12 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml) ...@@ -2971,12 +2975,12 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char *xml)
* we assign the def with live = true in anticipation that it will * we assign the def with live = true in anticipation that it will
* be started momentarily. * be started momentarily.
*/ */
if (!(network = virNetworkAssignDef(&driver->networks, def, true))) if (!(network = virNetworkAssignDef(driver->networks, def, true)))
goto cleanup; goto cleanup;
def = NULL; def = NULL;
if (networkStartNetwork(network) < 0) { if (networkStartNetwork(network) < 0) {
virNetworkRemoveInactive(&driver->networks, virNetworkRemoveInactive(driver->networks,
network); network);
network = NULL; network = NULL;
goto cleanup; goto cleanup;
...@@ -3019,7 +3023,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml) ...@@ -3019,7 +3023,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
if (networkValidate(def, false) < 0) if (networkValidate(def, false) < 0)
goto cleanup; goto cleanup;
if (!(network = virNetworkAssignDef(&driver->networks, def, false))) if (!(network = virNetworkAssignDef(driver->networks, def, false)))
goto cleanup; goto cleanup;
/* def was assigned to network object */ /* def was assigned to network object */
...@@ -3027,7 +3031,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml) ...@@ -3027,7 +3031,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char *xml)
if (virNetworkSaveConfig(driver->networkConfigDir, def) < 0) { if (virNetworkSaveConfig(driver->networkConfigDir, def) < 0) {
if (!virNetworkObjIsActive(network)) { if (!virNetworkObjIsActive(network)) {
virNetworkRemoveInactive(&driver->networks, network); virNetworkRemoveInactive(driver->networks, network);
network = NULL; network = NULL;
goto cleanup; goto cleanup;
} }
...@@ -3067,7 +3071,7 @@ networkUndefine(virNetworkPtr net) ...@@ -3067,7 +3071,7 @@ networkUndefine(virNetworkPtr net)
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(driver->networks, net->uuid);
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
...@@ -3140,7 +3144,7 @@ networkUpdate(virNetworkPtr net, ...@@ -3140,7 +3144,7 @@ networkUpdate(virNetworkPtr net,
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(driver->networks, net->uuid);
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
"%s", _("no network with matching uuid")); "%s", _("no network with matching uuid"));
...@@ -3297,7 +3301,7 @@ static int networkCreate(virNetworkPtr net) ...@@ -3297,7 +3301,7 @@ static int networkCreate(virNetworkPtr net)
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(driver->networks, net->uuid);
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -3332,7 +3336,7 @@ static int networkDestroy(virNetworkPtr net) ...@@ -3332,7 +3336,7 @@ static int networkDestroy(virNetworkPtr net)
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(driver->networks, net->uuid);
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -3458,7 +3462,7 @@ static int networkSetAutostart(virNetworkPtr net, ...@@ -3458,7 +3462,7 @@ static int networkSetAutostart(virNetworkPtr net,
int ret = -1; int ret = -1;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByUUID(&driver->networks, net->uuid); network = virNetworkFindByUUID(driver->networks, net->uuid);
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -3788,7 +3792,7 @@ networkAllocateActualDevice(virDomainDefPtr dom, ...@@ -3788,7 +3792,7 @@ networkAllocateActualDevice(virDomainDefPtr dom,
iface->data.network.actual = NULL; iface->data.network.actual = NULL;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByName(&driver->networks, iface->data.network.name); network = virNetworkFindByName(driver->networks, iface->data.network.name);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -4197,7 +4201,7 @@ networkNotifyActualDevice(virDomainDefPtr dom, ...@@ -4197,7 +4201,7 @@ networkNotifyActualDevice(virDomainDefPtr dom,
return 0; return 0;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByName(&driver->networks, iface->data.network.name); network = virNetworkFindByName(driver->networks, iface->data.network.name);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -4397,7 +4401,7 @@ networkReleaseActualDevice(virDomainDefPtr dom, ...@@ -4397,7 +4401,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
return 0; return 0;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByName(&driver->networks, iface->data.network.name); network = virNetworkFindByName(driver->networks, iface->data.network.name);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
...@@ -4556,7 +4560,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr) ...@@ -4556,7 +4560,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
*netaddr = NULL; *netaddr = NULL;
networkDriverLock(); networkDriverLock();
network = virNetworkFindByName(&driver->networks, netname); network = virNetworkFindByName(driver->networks, netname);
networkDriverUnlock(); networkDriverUnlock();
if (!network) { if (!network) {
virReportError(VIR_ERR_NO_NETWORK, virReportError(VIR_ERR_NO_NETWORK,
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
struct _virNetworkDriverState { struct _virNetworkDriverState {
virMutex lock; virMutex lock;
virNetworkObjList networks; virNetworkObjListPtr networks;
char *networkConfigDir; char *networkConfigDir;
char *networkAutostartDir; char *networkAutostartDir;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册