Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
f5da0d18
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看板
提交
f5da0d18
编写于
7月 08, 2016
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libvirt: convert to typesafe virConf accessors
Signed-off-by:
N
Daniel P. Berrange
<
berrange@redhat.com
>
上级
a9331394
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
61 deletion
+77
-61
src/libvirt-admin.c
src/libvirt-admin.c
+38
-30
src/libvirt.c
src/libvirt.c
+39
-31
未找到文件。
src/libvirt-admin.c
浏览文件 @
f5da0d18
...
...
@@ -158,35 +158,32 @@ getSocketPath(virURIPtr uri)
goto
cleanup
;
}
static
const
char
*
virAdmGetDefaultURI
(
virConfPtr
conf
)
static
int
virAdmGetDefaultURI
(
virConfPtr
conf
,
char
**
uristr
)
{
virConfValuePtr
value
=
NULL
;
const
char
*
uristr
=
NULL
;
uristr
=
virGetEnvAllowSUID
(
"LIBVIRT_ADMIN_DEFAULT_URI"
);
if
(
uristr
&&
*
uristr
)
{
VIR_DEBUG
(
"Using LIBVIRT_ADMIN_DEFAULT_URI '%s'"
,
uristr
);
}
else
if
((
value
=
virConfGetValue
(
conf
,
"admin_uri_default"
)))
{
if
(
value
->
type
!=
VIR_CONF_STRING
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Expected a string for 'admin_uri_default' config "
"parameter"
));
return
NULL
;
}
VIR_DEBUG
(
"Using config file uri '%s'"
,
value
->
str
);
uristr
=
value
->
str
;
const
char
*
defname
=
virGetEnvAllowSUID
(
"LIBVIRT_ADMIN_DEFAULT_URI"
);
if
(
defname
&&
*
defname
)
{
if
(
VIR_STRDUP
(
*
uristr
,
defname
)
<
0
)
return
-
1
;
VIR_DEBUG
(
"Using LIBVIRT_ADMIN_DEFAULT_URI '%s'"
,
*
uristr
);
}
else
{
/* Since we can't probe connecting via any hypervisor driver as libvirt
* does, if no explicit URI was given and neither the environment
* variable, nor the configuration parameter had previously been set,
* we set the default admin server URI to 'libvirtd://system'.
*/
uristr
=
"libvirtd:///system"
;
if
(
virConfGetValueString
(
conf
,
"admin_uri_default"
,
uristr
)
<
0
)
return
-
1
;
if
(
*
uristr
)
{
VIR_DEBUG
(
"Using config file uri '%s'"
,
*
uristr
);
}
else
{
/* Since we can't probe connecting via any hypervisor driver as libvirt
* does, if no explicit URI was given and neither the environment
* variable, nor the configuration parameter had previously been set,
* we set the default admin server URI to 'libvirtd://system'.
*/
if
(
VIR_STRDUP
(
*
uristr
,
"libvirtd:///system"
)
<
0
)
return
-
1
;
}
}
return
uristr
;
return
0
;
}
/**
...
...
@@ -206,6 +203,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
char
*
alias
=
NULL
;
virAdmConnectPtr
conn
=
NULL
;
virConfPtr
conf
=
NULL
;
char
*
uristr
=
NULL
;
if
(
virAdmInitialize
()
<
0
)
goto
error
;
...
...
@@ -219,14 +217,24 @@ virAdmConnectOpen(const char *name, unsigned int flags)
if
(
virConfLoadConfig
(
&
conf
,
"libvirt-admin.conf"
)
<
0
)
goto
error
;
if
(
!
name
&&
!
(
name
=
virAdmGetDefaultURI
(
conf
)))
goto
error
;
if
(
name
)
{
if
(
VIR_STRDUP
(
uristr
,
name
)
<
0
)
goto
error
;
}
else
{
if
(
virAdmGetDefaultURI
(
conf
,
&
uristr
)
<
0
)
goto
error
;
}
if
((
!
(
flags
&
VIR_CONNECT_NO_ALIASES
)
&&
virURIResolveAlias
(
conf
,
name
,
&
alias
)
<
0
))
virURIResolveAlias
(
conf
,
uristr
,
&
alias
)
<
0
))
goto
error
;
if
(
!
(
conn
->
uri
=
virURIParse
(
alias
?
alias
:
name
)))
if
(
alias
)
{
VIR_FREE
(
uristr
);
uristr
=
alias
;
}
if
(
!
(
conn
->
uri
=
virURIParse
(
uristr
)))
goto
error
;
if
(
!
(
sock_path
=
getSocketPath
(
conn
->
uri
)))
...
...
@@ -242,7 +250,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
cleanup:
VIR_FREE
(
sock_path
);
VIR_FREE
(
alias
);
VIR_FREE
(
uristr
);
virConfFree
(
conf
);
return
conn
;
...
...
src/libvirt.c
浏览文件 @
f5da0d18
...
...
@@ -903,22 +903,20 @@ virGetVersion(unsigned long *libVer, const char *type ATTRIBUTE_UNUSED,
static
int
virConnectGetDefaultURI
(
virConfPtr
conf
,
c
onst
c
har
**
name
)
char
**
name
)
{
int
ret
=
-
1
;
virConfValuePtr
value
=
NULL
;
const
char
*
defname
=
virGetEnvBlockSUID
(
"LIBVIRT_DEFAULT_URI"
);
if
(
defname
&&
*
defname
)
{
VIR_DEBUG
(
"Using LIBVIRT_DEFAULT_URI '%s'"
,
defname
);
*
name
=
defname
;
}
else
if
((
value
=
virConfGetValue
(
conf
,
"uri_default"
)))
{
if
(
value
->
type
!=
VIR_CONF_STRING
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Expected a string for 'uri_default' config parameter"
));
if
(
VIR_STRDUP
(
*
name
,
defname
)
<
0
)
goto
cleanup
;
}
VIR_DEBUG
(
"Using config file uri '%s'"
,
value
->
str
);
*
name
=
value
->
str
;
}
else
{
if
(
virConfGetValueString
(
conf
,
"uri_default"
,
name
)
<
0
)
goto
cleanup
;
if
(
*
name
)
VIR_DEBUG
(
"Using config file uri '%s'"
,
*
name
);
}
ret
=
0
;
...
...
@@ -965,6 +963,7 @@ virConnectOpenInternal(const char *name,
int
res
;
virConnectPtr
ret
;
virConfPtr
conf
=
NULL
;
char
*
uristr
=
NULL
;
ret
=
virGetConnect
();
if
(
ret
==
NULL
)
...
...
@@ -982,54 +981,61 @@ virConnectOpenInternal(const char *name,
goto
failed
;
}
/* Convert xen -> xen:/// for back compat */
if
(
name
&&
STRCASEEQ
(
name
,
"xen"
))
name
=
"xen:///"
;
/* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
* former. This allows URIs such as xen://localhost to work.
*/
if
(
name
&&
STREQ
(
name
,
"xen://"
))
name
=
"xen:///"
;
/*
* If no URI is passed, then check for an environment string if not
* available probe the compiled in drivers to find a default hypervisor
* if detectable.
*/
if
(
!
name
&&
virConnectGetDefaultURI
(
conf
,
&
name
)
<
0
)
goto
failed
;
if
(
name
)
{
char
*
alias
=
NULL
;
/* Convert xen -> xen:/// for back compat */
if
(
STRCASEEQ
(
name
,
"xen"
))
name
=
"xen:///"
;
if
(
VIR_STRDUP
(
uristr
,
name
)
<
0
)
goto
failed
;
}
else
{
if
(
virConnectGetDefaultURI
(
conf
,
&
uristr
)
<
0
)
goto
failed
;
}
/* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
* former. This allows URIs such as xen://localhost to work.
*/
if
(
STREQ
(
name
,
"xen://"
))
name
=
"xen:///"
;
if
(
uristr
)
{
char
*
alias
=
NULL
;
if
(
!
(
flags
&
VIR_CONNECT_NO_ALIASES
)
&&
virURIResolveAlias
(
conf
,
name
,
&
alias
)
<
0
)
virURIResolveAlias
(
conf
,
uristr
,
&
alias
)
<
0
)
goto
failed
;
if
(
!
(
ret
->
uri
=
virURIParse
(
alias
?
alias
:
name
)))
{
if
(
alias
)
{
VIR_FREE
(
uristr
);
uristr
=
alias
;
}
if
(
!
(
ret
->
uri
=
virURIParse
(
uristr
)))
{
VIR_FREE
(
alias
);
goto
failed
;
}
VIR_DEBUG
(
"
name
\"
%s
\"
to URI components:
\n
"
VIR_DEBUG
(
"
Split
\"
%s
\"
to URI components:
\n
"
" scheme %s
\n
"
" server %s
\n
"
" user %s
\n
"
" port %d
\n
"
" path %s"
,
alias
?
alias
:
name
,
uristr
,
NULLSTR
(
ret
->
uri
->
scheme
),
NULLSTR
(
ret
->
uri
->
server
),
NULLSTR
(
ret
->
uri
->
user
),
ret
->
uri
->
port
,
NULLSTR
(
ret
->
uri
->
path
));
if
(
virConnectCheckURIMissingSlash
(
alias
?
alias
:
name
,
if
(
virConnectCheckURIMissingSlash
(
uristr
,
ret
->
uri
)
<
0
)
{
VIR_FREE
(
alias
);
goto
failed
;
}
VIR_FREE
(
alias
);
}
else
{
VIR_DEBUG
(
"no name, allowing driver auto-select"
);
}
...
...
@@ -1114,10 +1120,12 @@ virConnectOpenInternal(const char *name,
}
virConfFree
(
conf
);
VIR_FREE
(
uristr
);
return
ret
;
failed:
VIR_FREE
(
uristr
);
virConfFree
(
conf
);
virObjectUnref
(
ret
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录