Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
ab1649d3
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ab1649d3
编写于
3月 06, 2007
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virGetDomain/Network require non-NULL name & UUID
上级
d6db609d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
163 addition
and
4 deletion
+163
-4
ChangeLog
ChangeLog
+5
-0
src/hash.c
src/hash.c
+158
-4
未找到文件。
ChangeLog
浏览文件 @
ab1649d3
Tue Mar 06 17:02:12 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/hash.c: virGetDomain and virGetNetwork require that both
name and UUID are non-NULL. (Patch from Rich Jones)
Tue Mar 06 16:52:12 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* include/libvirt/libvirt.h.in, python/libvir.c, src/driver.h
...
...
src/hash.c
浏览文件 @
ab1649d3
...
...
@@ -617,7 +617,7 @@ virHashError(virConnectPtr conn, virErrorNumber error, const char *info)
return
;
errmsg
=
__virErrorMsg
(
error
,
info
);
__virRaiseError
(
conn
,
NULL
,
VIR_FROM_NONE
,
error
,
VIR_ERR_ERROR
,
__virRaiseError
(
conn
,
NULL
,
NULL
,
VIR_FROM_NONE
,
error
,
VIR_ERR_ERROR
,
errmsg
,
info
,
NULL
,
0
,
0
,
errmsg
,
info
);
}
...
...
@@ -636,6 +636,20 @@ virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED)
return
(
virDomainFree
(
domain
));
}
/**
* virNetworkFreeName:
* @network: a network object
*
* Destroy the network object, this is just used by the network hash callback.
*
* Returns 0 in case of success and -1 in case of failure.
*/
static
int
virNetworkFreeName
(
virNetworkPtr
network
,
const
char
*
name
ATTRIBUTE_UNUSED
)
{
return
(
virNetworkFree
(
network
));
}
/**
* virGetConnect:
*
...
...
@@ -660,6 +674,9 @@ virGetConnect(void) {
ret
->
domains
=
virHashCreate
(
20
);
if
(
ret
->
domains
==
NULL
)
goto
failed
;
ret
->
networks
=
virHashCreate
(
20
);
if
(
ret
->
networks
==
NULL
)
goto
failed
;
ret
->
hashes_mux
=
xmlNewMutex
();
if
(
ret
->
hashes_mux
==
NULL
)
goto
failed
;
...
...
@@ -671,6 +688,8 @@ failed:
if
(
ret
!=
NULL
)
{
if
(
ret
->
domains
!=
NULL
)
virHashFree
(
ret
->
domains
,
(
virHashDeallocator
)
virDomainFreeName
);
if
(
ret
->
networks
!=
NULL
)
virHashFree
(
ret
->
networks
,
(
virHashDeallocator
)
virNetworkFreeName
);
if
(
ret
->
hashes_mux
!=
NULL
)
xmlFreeMutex
(
ret
->
hashes_mux
);
free
(
ret
);
...
...
@@ -705,6 +724,8 @@ virFreeConnect(virConnectPtr conn) {
if
(
conn
->
domains
!=
NULL
)
virHashFree
(
conn
->
domains
,
(
virHashDeallocator
)
virDomainFreeName
);
if
(
conn
->
networks
!=
NULL
)
virHashFree
(
conn
->
networks
,
(
virHashDeallocator
)
virNetworkFreeName
);
if
(
conn
->
hashes_mux
!=
NULL
)
xmlFreeMutex
(
conn
->
hashes_mux
);
free
(
conn
);
...
...
@@ -714,8 +735,8 @@ virFreeConnect(virConnectPtr conn) {
/**
* virGetDomain:
* @conn: the hypervisor connection
* @name: pointer to the domain name
or NULL
* @uuid: pointer to the uuid
or NULL
* @name: pointer to the domain name
* @uuid: pointer to the uuid
*
* Lookup if the domain is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
...
...
@@ -728,7 +749,7 @@ virDomainPtr
virGetDomain
(
virConnectPtr
conn
,
const
char
*
name
,
const
unsigned
char
*
uuid
)
{
virDomainPtr
ret
=
NULL
;
if
((
!
VIR_IS_CONNECT
(
conn
))
||
(
(
name
==
NULL
)
&&
(
uuid
==
NULL
)
)
||
if
((
!
VIR_IS_CONNECT
(
conn
))
||
(
name
==
NULL
)
||
(
uuid
==
NULL
)
||
(
conn
->
hashes_mux
==
NULL
))
{
virHashError
(
conn
,
VIR_ERR_INVALID_ARG
,
__FUNCTION__
);
return
(
NULL
);
...
...
@@ -893,6 +914,139 @@ done:
xmlMutexUnlock
(
conn
->
hashes_mux
);
return
(
ret
);
}
/**
* virGetNetwork:
* @conn: the hypervisor connection
* @name: pointer to the network name
* @uuid: pointer to the uuid
*
* Lookup if the network is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
* virFreeNetwork() is needed to not leak data.
*
* Returns a pointer to the network, or NULL in case of failure
*/
virNetworkPtr
virGetNetwork
(
virConnectPtr
conn
,
const
char
*
name
,
const
unsigned
char
*
uuid
)
{
virNetworkPtr
ret
=
NULL
;
if
((
!
VIR_IS_CONNECT
(
conn
))
||
(
name
==
NULL
)
||
(
uuid
==
NULL
)
||
(
conn
->
hashes_mux
==
NULL
))
{
virHashError
(
conn
,
VIR_ERR_INVALID_ARG
,
__FUNCTION__
);
return
(
NULL
);
}
xmlMutexLock
(
conn
->
hashes_mux
);
/* TODO search by UUID first as they are better differenciators */
ret
=
(
virNetworkPtr
)
virHashLookup
(
conn
->
networks
,
name
);
if
(
ret
!=
NULL
)
{
/* TODO check the UUID */
goto
done
;
}
/*
* not found, allocate a new one
*/
ret
=
(
virNetworkPtr
)
malloc
(
sizeof
(
virNetwork
));
if
(
ret
==
NULL
)
{
virHashError
(
conn
,
VIR_ERR_NO_MEMORY
,
_
(
"allocating network"
));
goto
error
;
}
memset
(
ret
,
0
,
sizeof
(
virNetwork
));
ret
->
name
=
strdup
(
name
);
if
(
ret
->
name
==
NULL
)
{
virHashError
(
conn
,
VIR_ERR_NO_MEMORY
,
_
(
"allocating network"
));
goto
error
;
}
ret
->
magic
=
VIR_NETWORK_MAGIC
;
ret
->
conn
=
conn
;
if
(
uuid
!=
NULL
)
memcpy
(
&
(
ret
->
uuid
[
0
]),
uuid
,
VIR_UUID_BUFLEN
);
if
(
virHashAddEntry
(
conn
->
networks
,
name
,
ret
)
<
0
)
{
virHashError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"failed to add network to connection hash table"
));
goto
error
;
}
conn
->
uses
++
;
done:
ret
->
uses
++
;
xmlMutexUnlock
(
conn
->
hashes_mux
);
return
(
ret
);
error:
xmlMutexUnlock
(
conn
->
hashes_mux
);
if
(
ret
!=
NULL
)
{
if
(
ret
->
name
!=
NULL
)
free
(
ret
->
name
);
free
(
ret
);
}
return
(
NULL
);
}
/**
* virFreeNetwork:
* @conn: the hypervisor connection
* @network: the network to release
*
* Release the given network, if the reference count drops to zero, then
* the network is really freed.
*
* Returns the reference count or -1 in case of failure.
*/
int
virFreeNetwork
(
virConnectPtr
conn
,
virNetworkPtr
network
)
{
int
ret
=
0
;
if
((
!
VIR_IS_CONNECT
(
conn
))
||
(
!
VIR_IS_CONNECTED_NETWORK
(
network
))
||
(
network
->
conn
!=
conn
)
||
(
conn
->
hashes_mux
==
NULL
))
{
virHashError
(
conn
,
VIR_ERR_INVALID_ARG
,
__FUNCTION__
);
return
(
-
1
);
}
xmlMutexLock
(
conn
->
hashes_mux
);
/*
* decrement the count for the network
*/
network
->
uses
--
;
ret
=
network
->
uses
;
if
(
ret
>
0
)
goto
done
;
/* TODO search by UUID first as they are better differenciators */
if
(
virHashRemoveEntry
(
conn
->
networks
,
network
->
name
,
NULL
)
<
0
)
{
virHashError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"network missing from connection hash table"
));
goto
done
;
}
network
->
magic
=
-
1
;
if
(
network
->
name
)
free
(
network
->
name
);
free
(
network
);
/*
* decrement the count for the connection
*/
conn
->
uses
--
;
if
(
conn
->
uses
>
0
)
goto
done
;
if
(
conn
->
networks
!=
NULL
)
virHashFree
(
conn
->
networks
,
(
virHashDeallocator
)
virNetworkFreeName
);
if
(
conn
->
hashes_mux
!=
NULL
)
xmlFreeMutex
(
conn
->
hashes_mux
);
free
(
conn
);
return
(
0
);
done:
xmlMutexUnlock
(
conn
->
hashes_mux
);
return
(
ret
);
}
/*
* Local variables:
* indent-tabs-mode: nil
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录