Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
dd48e929
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
dd48e929
编写于
10月 10, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch network objects to array instead of linked list
上级
47891540
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
150 addition
and
157 deletion
+150
-157
ChangeLog
ChangeLog
+6
-0
src/network_conf.c
src/network_conf.c
+51
-35
src/network_conf.h
src/network_conf.h
+13
-7
src/network_driver.c
src/network_driver.c
+53
-67
src/test.c
src/test.c
+27
-48
未找到文件。
ChangeLog
浏览文件 @
dd48e929
Fri Oct 10 15:39:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/network_conf.c, src/network_conf.h, src/network_driver.c,
src/test.c: Switch to using array instead of linked list for
network objects
Fri Oct 10 15:19:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/domain_conf.c, src/domain_conf.h: Switch to using
...
...
src/network_conf.c
浏览文件 @
dd48e929
...
...
@@ -52,28 +52,26 @@ VIR_ENUM_IMPL(virNetworkForward,
__virReportErrorHelper(conn, VIR_FROM_NETWORK, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
virNetworkObjPtr
virNetworkFindByUUID
(
const
virNetworkObjPtr
nets
,
virNetworkObjPtr
virNetworkFindByUUID
(
const
virNetworkObj
List
Ptr
nets
,
const
unsigned
char
*
uuid
)
{
virNetworkObjPtr
net
=
nets
;
while
(
net
)
{
if
(
!
memcmp
(
net
->
def
->
uuid
,
uuid
,
VIR_UUID_BUFLEN
))
return
net
;
net
=
net
->
next
;
}
unsigned
int
i
;
for
(
i
=
0
;
i
<
nets
->
count
;
i
++
)
if
(
!
memcmp
(
nets
->
objs
[
i
]
->
def
->
uuid
,
uuid
,
VIR_UUID_BUFLEN
))
return
nets
->
objs
[
i
];
return
NULL
;
}
virNetworkObjPtr
virNetworkFindByName
(
const
virNetworkObjPtr
nets
,
virNetworkObjPtr
virNetworkFindByName
(
const
virNetworkObj
List
Ptr
nets
,
const
char
*
name
)
{
virNetworkObjPtr
net
=
nets
;
while
(
net
)
{
if
(
STREQ
(
net
->
def
->
name
,
name
))
return
net
;
net
=
net
->
next
;
}
unsigned
int
i
;
for
(
i
=
0
;
i
<
nets
->
count
;
i
++
)
if
(
STREQ
(
nets
->
objs
[
i
]
->
def
->
name
,
name
))
return
nets
->
objs
[
i
];
return
NULL
;
}
...
...
@@ -124,13 +122,24 @@ void virNetworkObjFree(virNetworkObjPtr net)
VIR_FREE
(
net
);
}
void
virNetworkObjListFree
(
virNetworkObjListPtr
nets
)
{
unsigned
int
i
;
for
(
i
=
0
;
i
<
nets
->
count
;
i
++
)
virNetworkObjFree
(
nets
->
objs
[
i
]);
VIR_FREE
(
nets
->
objs
);
nets
->
count
=
0
;
}
virNetworkObjPtr
virNetworkAssignDef
(
virConnectPtr
conn
,
virNetworkObj
Ptr
*
nets
,
virNetworkObj
ListPtr
nets
,
const
virNetworkDefPtr
def
)
{
virNetworkObjPtr
network
;
if
((
network
=
virNetworkFindByName
(
*
nets
,
def
->
name
)))
{
if
((
network
=
virNetworkFindByName
(
nets
,
def
->
name
)))
{
if
(
!
virNetworkIsActive
(
network
))
{
virNetworkDefFree
(
network
->
def
);
network
->
def
=
def
;
...
...
@@ -149,34 +158,41 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn,
}
network
->
def
=
def
;
network
->
next
=
*
nets
;
*
nets
=
network
;
if
(
VIR_REALLOC_N
(
nets
->
objs
,
nets
->
count
+
1
)
<
0
)
{
virNetworkReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
NULL
);
VIR_FREE
(
network
);
return
NULL
;
}
nets
->
objs
[
nets
->
count
]
=
network
;
nets
->
count
++
;
return
network
;
}
void
virNetworkRemoveInactive
(
virNetworkObj
Ptr
*
nets
,
void
virNetworkRemoveInactive
(
virNetworkObj
ListPtr
nets
,
const
virNetworkObjPtr
net
)
{
virNetworkObjPtr
prev
=
NULL
;
virNetworkObjPtr
curr
=
*
nets
;
unsigned
int
i
;
while
(
curr
&&
curr
!=
net
)
{
prev
=
curr
;
curr
=
curr
->
next
;
}
for
(
i
=
0
;
i
<
nets
->
count
;
i
++
)
{
if
(
nets
->
objs
[
i
]
==
net
)
{
virNetworkObjFree
(
nets
->
objs
[
i
]);
if
(
curr
)
{
if
(
prev
)
prev
->
next
=
curr
->
next
;
else
*
nets
=
curr
->
next
;
}
if
(
i
<
(
nets
->
count
-
1
))
memmove
(
nets
->
objs
+
i
,
nets
->
objs
+
i
+
1
,
sizeof
(
*
(
nets
->
objs
))
*
(
nets
->
count
-
(
i
+
1
)));
virNetworkObjFree
(
net
);
if
(
VIR_REALLOC_N
(
nets
->
objs
,
nets
->
count
-
1
)
<
0
)
{
;
/* Failure to reduce memory allocation isn't fatal */
}
nets
->
count
--
;
break
;
}
}
}
...
...
@@ -682,7 +698,7 @@ int virNetworkSaveConfig(virConnectPtr conn,
}
virNetworkObjPtr
virNetworkLoadConfig
(
virConnectPtr
conn
,
virNetworkObj
Ptr
*
nets
,
virNetworkObj
ListPtr
nets
,
const
char
*
configDir
,
const
char
*
autostartDir
,
const
char
*
file
)
...
...
@@ -736,7 +752,7 @@ error:
}
int
virNetworkLoadAllConfigs
(
virConnectPtr
conn
,
virNetworkObj
Ptr
*
nets
,
virNetworkObj
ListPtr
nets
,
const
char
*
configDir
,
const
char
*
autostartDir
)
{
...
...
src/network_conf.h
浏览文件 @
dd48e929
...
...
@@ -88,8 +88,13 @@ struct _virNetworkObj {
virNetworkDefPtr
def
;
/* The current definition */
virNetworkDefPtr
newDef
;
/* New definition to activate at shutdown */
};
virNetworkObjPtr
next
;
typedef
struct
_virNetworkObjList
virNetworkObjList
;
typedef
virNetworkObjList
*
virNetworkObjListPtr
;
struct
_virNetworkObjList
{
unsigned
int
count
;
virNetworkObjPtr
*
objs
;
};
static
inline
int
...
...
@@ -99,19 +104,20 @@ virNetworkIsActive(const virNetworkObjPtr net)
}
virNetworkObjPtr
virNetworkFindByUUID
(
const
virNetworkObjPtr
nets
,
virNetworkObjPtr
virNetworkFindByUUID
(
const
virNetworkObj
List
Ptr
nets
,
const
unsigned
char
*
uuid
);
virNetworkObjPtr
virNetworkFindByName
(
const
virNetworkObjPtr
nets
,
virNetworkObjPtr
virNetworkFindByName
(
const
virNetworkObj
List
Ptr
nets
,
const
char
*
name
);
void
virNetworkDefFree
(
virNetworkDefPtr
def
);
void
virNetworkObjFree
(
virNetworkObjPtr
net
);
void
virNetworkObjListFree
(
virNetworkObjListPtr
vms
);
virNetworkObjPtr
virNetworkAssignDef
(
virConnectPtr
conn
,
virNetworkObj
Ptr
*
nets
,
virNetworkObj
ListPtr
nets
,
const
virNetworkDefPtr
def
);
void
virNetworkRemoveInactive
(
virNetworkObj
Ptr
*
nets
,
void
virNetworkRemoveInactive
(
virNetworkObj
ListPtr
nets
,
const
virNetworkObjPtr
net
);
virNetworkDefPtr
virNetworkDefParseString
(
virConnectPtr
conn
,
...
...
@@ -132,13 +138,13 @@ int virNetworkSaveConfig(virConnectPtr conn,
virNetworkObjPtr
net
);
virNetworkObjPtr
virNetworkLoadConfig
(
virConnectPtr
conn
,
virNetworkObj
Ptr
*
nets
,
virNetworkObj
ListPtr
nets
,
const
char
*
configDir
,
const
char
*
autostartDir
,
const
char
*
file
);
int
virNetworkLoadAllConfigs
(
virConnectPtr
conn
,
virNetworkObj
Ptr
*
nets
,
virNetworkObj
ListPtr
nets
,
const
char
*
configDir
,
const
char
*
autostartDir
);
...
...
src/network_driver.c
浏览文件 @
dd48e929
...
...
@@ -58,7 +58,7 @@
/* Main driver state */
struct
network_driver
{
virNetworkObj
Ptr
networks
;
virNetworkObj
List
networks
;
iptablesContext
*
iptables
;
brControl
*
brctl
;
...
...
@@ -89,23 +89,18 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
static
struct
network_driver
*
driverState
=
NULL
;
static
void
networkAutostartConfigs
(
struct
network_driver
*
driver
)
{
virNetworkObjPtr
network
;
network
=
driver
->
networks
;
while
(
network
!=
NULL
)
{
virNetworkObjPtr
next
=
network
->
next
;
static
void
networkAutostartConfigs
(
struct
network_driver
*
driver
)
{
unsigned
int
i
;
if
(
network
->
autostart
&&
!
virNetworkIsActive
(
network
)
&&
networkStartNetworkDaemon
(
NULL
,
driver
,
network
)
<
0
)
{
for
(
i
=
0
;
i
<
driver
->
networks
.
count
;
i
++
)
{
if
(
driver
->
networks
.
objs
[
i
]
->
autostart
&&
!
virNetworkIsActive
(
driver
->
networks
.
objs
[
i
])
&&
networkStartNetworkDaemon
(
NULL
,
driver
,
driver
->
networks
.
objs
[
i
])
<
0
)
{
virErrorPtr
err
=
virGetLastError
();
networkLog
(
NETWORK_ERR
,
_
(
"Failed to autostart network '%s': %s
\n
"
),
network
->
def
->
name
,
err
->
message
);
driver
->
networks
.
objs
[
i
]
->
def
->
name
,
err
->
message
);
}
network
=
next
;
}
}
...
...
@@ -187,6 +182,9 @@ networkStartup(void) {
*/
static
int
networkReload
(
void
)
{
if
(
!
driverState
)
return
0
;
virNetworkLoadAllConfigs
(
NULL
,
&
driverState
->
networks
,
driverState
->
networkConfigDir
,
...
...
@@ -213,13 +211,14 @@ networkReload(void) {
*/
static
int
networkActive
(
void
)
{
virNetworkObjPtr
net
=
driverState
->
networks
;
unsigned
int
i
;
while
(
net
)
{
if
(
virNetworkIsActive
(
net
))
if
(
!
driverState
)
return
0
;
for
(
i
=
0
;
i
<
driverState
->
networks
.
count
;
i
++
)
if
(
virNetworkIsActive
(
driverState
->
networks
.
objs
[
i
]))
return
1
;
net
=
net
->
next
;
}
/* Otherwise we're happy to deal with a shutdown */
return
0
;
...
...
@@ -232,28 +231,19 @@ networkActive(void) {
*/
static
int
networkShutdown
(
void
)
{
virNetworkObjPtr
network
;
unsigned
int
i
;
if
(
!
driverState
)
return
-
1
;
/* shutdown active networks */
network
=
driverState
->
networks
;
while
(
network
)
{
virNetworkObjPtr
next
=
network
->
next
;
if
(
virNetworkIsActive
(
network
))
networkShutdownNetworkDaemon
(
NULL
,
driverState
,
network
);
network
=
next
;
}
for
(
i
=
0
;
i
<
driverState
->
networks
.
count
;
i
++
)
if
(
virNetworkIsActive
(
driverState
->
networks
.
objs
[
i
]))
networkShutdownNetworkDaemon
(
NULL
,
driverState
,
driverState
->
networks
.
objs
[
i
]);
/* free inactive networks */
network
=
driverState
->
networks
;
while
(
network
)
{
virNetworkObjPtr
next
=
network
->
next
;
virNetworkObjFree
(
network
);
network
=
next
;
}
driverState
->
networks
=
NULL
;
virNetworkObjListFree
(
&
driverState
->
networks
);
VIR_FREE
(
driverState
->
logDir
);
VIR_FREE
(
driverState
->
networkConfigDir
);
...
...
@@ -815,7 +805,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
static
virNetworkPtr
networkLookupByUUID
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
const
unsigned
char
*
uuid
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
uuid
);
virNetworkPtr
net
;
if
(
!
network
)
{
...
...
@@ -830,7 +820,7 @@ static virNetworkPtr networkLookupByUUID(virConnectPtr conn ATTRIBUTE_UNUSED,
static
virNetworkPtr
networkLookupByName
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
const
char
*
name
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByName
(
driver
->
networks
,
name
);
virNetworkObjPtr
network
=
virNetworkFindByName
(
&
driver
->
networks
,
name
);
virNetworkPtr
net
;
if
(
!
network
)
{
...
...
@@ -860,31 +850,29 @@ static int networkCloseNetwork(virConnectPtr conn) {
}
static
int
networkNumNetworks
(
virConnectPtr
conn
)
{
int
nactive
=
0
;
int
nactive
=
0
,
i
;
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
conn
->
networkPrivateData
;
virNetworkObjPtr
net
=
driver
->
networks
;
while
(
net
)
{
if
(
virNetworkIsActive
(
net
))
for
(
i
=
0
;
i
<
driver
->
networks
.
count
;
i
++
)
if
(
virNetworkIsActive
(
driver
->
networks
.
objs
[
i
]
))
nactive
++
;
net
=
net
->
next
;
}
return
nactive
;
}
static
int
networkListNetworks
(
virConnectPtr
conn
,
char
**
const
names
,
int
nnames
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
driver
->
networks
;
int
got
=
0
,
i
;
while
(
network
&&
got
<
nnames
)
{
if
(
virNetworkIsActive
(
network
))
{
if
(
!
(
names
[
got
]
=
strdup
(
network
->
def
->
name
)))
{
for
(
i
=
0
;
i
<
driver
->
networks
.
count
&&
got
<
nnames
;
i
++
)
{
if
(
virNetworkIsActive
(
driver
->
networks
.
objs
[
i
]))
{
if
(
!
(
names
[
got
]
=
strdup
(
driver
->
networks
.
objs
[
i
]
->
def
->
name
)))
{
networkReportError
(
conn
,
NULL
,
NULL
,
VIR_ERR_NO_MEMORY
,
"%s"
,
_
(
"failed to allocate space for VM name string"
));
"%s"
,
_
(
"failed to allocate space for VM name string"
));
goto
cleanup
;
}
got
++
;
}
network
=
network
->
next
;
}
return
got
;
...
...
@@ -895,31 +883,29 @@ static int networkListNetworks(virConnectPtr conn, char **const names, int nname
}
static
int
networkNumDefinedNetworks
(
virConnectPtr
conn
)
{
int
ninactive
=
0
;
int
ninactive
=
0
,
i
;
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
conn
->
networkPrivateData
;
virNetworkObjPtr
net
=
driver
->
networks
;
while
(
net
)
{
if
(
!
virNetworkIsActive
(
net
))
for
(
i
=
0
;
i
<
driver
->
networks
.
count
;
i
++
)
if
(
!
virNetworkIsActive
(
driver
->
networks
.
objs
[
i
]
))
ninactive
++
;
net
=
net
->
next
;
}
return
ninactive
;
}
static
int
networkListDefinedNetworks
(
virConnectPtr
conn
,
char
**
const
names
,
int
nnames
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
driver
->
networks
;
int
got
=
0
,
i
;
while
(
network
&&
got
<
nnames
)
{
if
(
!
virNetworkIsActive
(
network
))
{
if
(
!
(
names
[
got
]
=
strdup
(
network
->
def
->
name
)))
{
for
(
i
=
0
;
i
<
driver
->
networks
.
count
&&
got
<
nnames
;
i
++
)
{
if
(
!
virNetworkIsActive
(
driver
->
networks
.
objs
[
i
]))
{
if
(
!
(
names
[
got
]
=
strdup
(
driver
->
networks
.
objs
[
i
]
->
def
->
name
)))
{
networkReportError
(
conn
,
NULL
,
NULL
,
VIR_ERR_NO_MEMORY
,
"%s"
,
_
(
"failed to allocate space for VM name string"
));
"%s"
,
_
(
"failed to allocate space for VM name string"
));
goto
cleanup
;
}
got
++
;
}
network
=
network
->
next
;
}
return
got
;
...
...
@@ -984,7 +970,7 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
static
int
networkUndefine
(
virNetworkPtr
net
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
if
(
!
network
)
{
networkReportError
(
net
->
conn
,
NULL
,
net
,
VIR_ERR_INVALID_DOMAIN
,
...
...
@@ -1009,7 +995,7 @@ static int networkUndefine(virNetworkPtr net) {
static
int
networkStart
(
virNetworkPtr
net
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
if
(
!
network
)
{
networkReportError
(
net
->
conn
,
NULL
,
net
,
VIR_ERR_INVALID_NETWORK
,
...
...
@@ -1022,7 +1008,7 @@ static int networkStart(virNetworkPtr net) {
static
int
networkDestroy
(
virNetworkPtr
net
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
int
ret
;
if
(
!
network
)
{
...
...
@@ -1038,7 +1024,7 @@ static int networkDestroy(virNetworkPtr net) {
static
char
*
networkDumpXML
(
virNetworkPtr
net
,
int
flags
ATTRIBUTE_UNUSED
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
if
(
!
network
)
{
networkReportError
(
net
->
conn
,
NULL
,
net
,
VIR_ERR_INVALID_NETWORK
,
...
...
@@ -1051,7 +1037,7 @@ static char *networkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED) {
static
char
*
networkGetBridgeName
(
virNetworkPtr
net
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
char
*
bridge
;
if
(
!
network
)
{
networkReportError
(
net
->
conn
,
NULL
,
net
,
VIR_ERR_INVALID_NETWORK
,
...
...
@@ -1071,7 +1057,7 @@ static char *networkGetBridgeName(virNetworkPtr net) {
static
int
networkGetAutostart
(
virNetworkPtr
net
,
int
*
autostart
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
if
(
!
network
)
{
networkReportError
(
net
->
conn
,
NULL
,
net
,
VIR_ERR_INVALID_NETWORK
,
...
...
@@ -1087,7 +1073,7 @@ static int networkGetAutostart(virNetworkPtr net,
static
int
networkSetAutostart
(
virNetworkPtr
net
,
int
autostart
)
{
struct
network_driver
*
driver
=
(
struct
network_driver
*
)
net
->
conn
->
networkPrivateData
;
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
driver
->
networks
,
net
->
uuid
);
virNetworkObjPtr
network
=
virNetworkFindByUUID
(
&
driver
->
networks
,
net
->
uuid
);
if
(
!
network
)
{
networkReportError
(
net
->
conn
,
NULL
,
net
,
VIR_ERR_INVALID_NETWORK
,
...
...
src/test.c
浏览文件 @
dd48e929
...
...
@@ -58,7 +58,7 @@ struct _testConn {
virCapsPtr
caps
;
virNodeInfo
nodeInfo
;
virDomainObjList
domains
;
virNetworkObj
Ptr
networks
;
virNetworkObj
List
networks
;
int
numCells
;
testCell
cells
[
MAX_CELLS
];
};
...
...
@@ -100,7 +100,7 @@ static const virNodeInfo defaultNodeInfo = {
\
privconn = (testConnPtr)net->conn->privateData; \
do { \
if ((privnet = virNetworkFindByName(
privconn->networks,
\
if ((privnet = virNetworkFindByName(
&privconn->networks,
\
(net)->name)) == NULL) { \
testError((net)->conn, NULL, (net), VIR_ERR_INVALID_ARG, \
__FUNCTION__); \
...
...
@@ -260,7 +260,7 @@ static int testOpenDefault(virConnectPtr conn) {
error:
virDomainObjListFree
(
&
privconn
->
domains
);
virNetworkObj
Free
(
privconn
->
networks
);
virNetworkObj
ListFree
(
&
privconn
->
networks
);
virCapabilitiesFree
(
privconn
->
caps
);
VIR_FREE
(
privconn
);
return
VIR_DRV_OPEN_ERROR
;
...
...
@@ -495,12 +495,7 @@ static int testOpenFromFile(virConnectPtr conn,
if
(
fd
!=
-
1
)
close
(
fd
);
virDomainObjListFree
(
&
privconn
->
domains
);
net
=
privconn
->
networks
;
while
(
net
)
{
virNetworkObjPtr
tmp
=
net
->
next
;
virNetworkObjFree
(
net
);
net
=
tmp
;
}
virNetworkObjListFree
(
&
privconn
->
networks
);
VIR_FREE
(
privconn
);
conn
->
privateData
=
NULL
;
return
VIR_DRV_OPEN_ERROR
;
...
...
@@ -547,16 +542,12 @@ static int testOpen(virConnectPtr conn,
static
int
testClose
(
virConnectPtr
conn
)
{
virNetworkObjPtr
net
;
GET_CONNECTION
(
conn
);
virCapabilitiesFree
(
privconn
->
caps
);
virDomainObjListFree
(
&
privconn
->
domains
);
net
=
privconn
->
networks
;
while
(
net
)
{
virNetworkObjPtr
tmp
=
net
->
next
;
virNetworkObjFree
(
net
);
net
=
tmp
;
}
virNetworkObjListFree
(
&
privconn
->
networks
);
VIR_FREE
(
privconn
);
conn
->
privateData
=
conn
;
return
0
;
...
...
@@ -1283,7 +1274,7 @@ static virNetworkPtr testLookupNetworkByUUID(virConnectPtr conn,
virNetworkObjPtr
net
=
NULL
;
GET_CONNECTION
(
conn
);
if
((
net
=
virNetworkFindByUUID
(
privconn
->
networks
,
uuid
))
==
NULL
)
{
if
((
net
=
virNetworkFindByUUID
(
&
privconn
->
networks
,
uuid
))
==
NULL
)
{
testError
(
conn
,
NULL
,
NULL
,
VIR_ERR_NO_NETWORK
,
NULL
);
return
NULL
;
}
...
...
@@ -1297,7 +1288,7 @@ static virNetworkPtr testLookupNetworkByName(virConnectPtr conn,
virNetworkObjPtr
net
=
NULL
;
GET_CONNECTION
(
conn
);
if
((
net
=
virNetworkFindByName
(
privconn
->
networks
,
name
))
==
NULL
)
{
if
((
net
=
virNetworkFindByName
(
&
privconn
->
networks
,
name
))
==
NULL
)
{
testError
(
conn
,
NULL
,
NULL
,
VIR_ERR_NO_NETWORK
,
NULL
);
return
NULL
;
}
...
...
@@ -1307,32 +1298,26 @@ static virNetworkPtr testLookupNetworkByName(virConnectPtr conn,
static
int
testNumNetworks
(
virConnectPtr
conn
)
{
int
numActive
=
0
;
virNetworkObjPtr
net
;
int
numActive
=
0
,
i
;
GET_CONNECTION
(
conn
);
net
=
privconn
->
networks
;
while
(
net
)
{
if
(
virNetworkIsActive
(
net
))
for
(
i
=
0
;
i
<
privconn
->
networks
.
count
;
i
++
)
if
(
virNetworkIsActive
(
privconn
->
networks
.
objs
[
i
]))
numActive
++
;
net
=
net
->
next
;
}
return
numActive
;
}
static
int
testListNetworks
(
virConnectPtr
conn
,
char
**
const
names
,
int
nnames
)
{
int
n
=
0
;
virNetworkObjPtr
net
;
int
n
=
0
,
i
;
GET_CONNECTION
(
conn
);
net
=
privconn
->
networks
;
memset
(
names
,
0
,
sizeof
(
*
names
)
*
nnames
);
while
(
net
&&
n
<
nnames
)
{
if
(
virNetworkIsActive
(
net
)
&&
!
(
names
[
n
++
]
=
strdup
(
net
->
def
->
name
)))
for
(
i
=
0
;
i
<
privconn
->
networks
.
count
&&
n
<
nnames
;
i
++
)
if
(
virNetworkIsActive
(
privconn
->
networks
.
objs
[
i
]
)
&&
!
(
names
[
n
++
]
=
strdup
(
privconn
->
networks
.
objs
[
i
]
->
def
->
name
)))
goto
no_memory
;
net
=
net
->
next
;
}
return
n
;
no_memory:
...
...
@@ -1343,32 +1328,26 @@ no_memory:
}
static
int
testNumDefinedNetworks
(
virConnectPtr
conn
)
{
int
numInactive
=
0
;
virNetworkObjPtr
net
;
int
numInactive
=
0
,
i
;
GET_CONNECTION
(
conn
);
net
=
privconn
->
networks
;
while
(
net
)
{
if
(
!
virNetworkIsActive
(
net
))
for
(
i
=
0
;
i
<
privconn
->
networks
.
count
;
i
++
)
if
(
!
virNetworkIsActive
(
privconn
->
networks
.
objs
[
i
]))
numInactive
++
;
net
=
net
->
next
;
}
return
numInactive
;
}
static
int
testListDefinedNetworks
(
virConnectPtr
conn
,
char
**
const
names
,
int
nnames
)
{
int
n
=
0
;
virNetworkObjPtr
net
;
int
n
=
0
,
i
;
GET_CONNECTION
(
conn
);
net
=
privconn
->
networks
;
memset
(
names
,
0
,
sizeof
(
*
names
)
*
nnames
);
while
(
net
&&
n
<
nnames
)
{
if
(
!
virNetworkIsActive
(
net
)
&&
!
(
names
[
n
++
]
=
strdup
(
net
->
def
->
name
)))
for
(
i
=
0
;
i
<
privconn
->
networks
.
count
&&
n
<
nnames
;
i
++
)
if
(
!
virNetworkIsActive
(
privconn
->
networks
.
objs
[
i
]
)
&&
!
(
names
[
n
++
]
=
strdup
(
privconn
->
networks
.
objs
[
i
]
->
def
->
name
)))
goto
no_memory
;
net
=
net
->
next
;
}
return
n
;
no_memory:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录