Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
8e85f628
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,发现更多精彩内容 >>
提交
8e85f628
编写于
7月 14, 2015
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virsh: Refactor argument handling in cmdBlockCopy
Put all argument parsing together and refactor the argument checking code.
上级
bd687cf9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
33 deletion
+44
-33
tools/virsh-domain.c
tools/virsh-domain.c
+44
-33
未找到文件。
tools/virsh-domain.c
浏览文件 @
8e85f628
...
@@ -2088,11 +2088,12 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
...
@@ -2088,11 +2088,12 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
unsigned
long
long
buf_size
=
0
;
unsigned
long
long
buf_size
=
0
;
unsigned
int
flags
=
0
;
unsigned
int
flags
=
0
;
bool
ret
=
false
;
bool
ret
=
false
;
bool
blocking
=
vshCommandOptBool
(
cmd
,
"wait"
);
bool
verbose
=
vshCommandOptBool
(
cmd
,
"verbose"
);
bool
verbose
=
vshCommandOptBool
(
cmd
,
"verbose"
);
bool
pivot
=
vshCommandOptBool
(
cmd
,
"pivot"
);
bool
pivot
=
vshCommandOptBool
(
cmd
,
"pivot"
);
bool
finish
=
vshCommandOptBool
(
cmd
,
"finish"
);
bool
finish
=
vshCommandOptBool
(
cmd
,
"finish"
);
bool
blockdev
=
vshCommandOptBool
(
cmd
,
"blockdev"
);
bool
blockdev
=
vshCommandOptBool
(
cmd
,
"blockdev"
);
bool
blocking
=
vshCommandOptBool
(
cmd
,
"wait"
)
||
finish
||
pivot
;
bool
async
=
vshCommandOptBool
(
cmd
,
"async"
);
int
timeout
=
0
;
int
timeout
=
0
;
struct
sigaction
sig_action
;
struct
sigaction
sig_action
;
struct
sigaction
old_sig_action
;
struct
sigaction
old_sig_action
;
...
@@ -2117,22 +2118,56 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
...
@@ -2117,22 +2118,56 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
return
false
;
return
false
;
if
(
vshCommandOptString
(
ctl
,
cmd
,
"format"
,
&
format
)
<
0
)
if
(
vshCommandOptString
(
ctl
,
cmd
,
"format"
,
&
format
)
<
0
)
return
false
;
return
false
;
/* XXX: Parse bandwidth as scaled input, rather than forcing
* MiB/s, and either reject negative input or treat it as 0 rather
* than trying to guess which value will work well across both
* APIs with their different sizes and scales. */
if
(
vshCommandOptULWrap
(
ctl
,
cmd
,
"bandwidth"
,
&
bandwidth
)
<
0
)
return
false
;
if
(
vshCommandOptUInt
(
ctl
,
cmd
,
"granularity"
,
&
granularity
)
<
0
)
return
false
;
if
(
vshCommandOptULongLong
(
ctl
,
cmd
,
"buf-size"
,
&
buf_size
)
<
0
)
return
false
;
/* Exploit that some VIR_DOMAIN_BLOCK_REBASE_* and
* VIR_DOMAIN_BLOCK_COPY_* flags have the same values. */
if
(
vshCommandOptBool
(
cmd
,
"shallow"
))
flags
|=
VIR_DOMAIN_BLOCK_REBASE_SHALLOW
;
if
(
vshCommandOptBool
(
cmd
,
"reuse-external"
))
flags
|=
VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT
;
if
(
vshCommandOptTimeoutToMs
(
ctl
,
cmd
,
&
timeout
)
<
0
)
return
false
;
if
(
timeout
)
blocking
=
true
;
if
(
async
)
abort_flags
|=
VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC
;
VSH_EXCLUSIVE_OPTIONS_VAR
(
dest
,
xml
);
VSH_EXCLUSIVE_OPTIONS_VAR
(
dest
,
xml
);
VSH_EXCLUSIVE_OPTIONS_VAR
(
format
,
xml
);
VSH_EXCLUSIVE_OPTIONS_VAR
(
format
,
xml
);
VSH_EXCLUSIVE_OPTIONS_VAR
(
blockdev
,
xml
);
VSH_EXCLUSIVE_OPTIONS_VAR
(
blockdev
,
xml
);
VSH_EXCLUSIVE_OPTIONS_VAR
(
pivot
,
finish
);
blocking
|=
vshCommandOptBool
(
cmd
,
"timeout"
)
||
pivot
||
finish
;
if
(
!
dest
&&
!
xml
)
{
if
(
blocking
)
{
vshError
(
ctl
,
"%s"
,
_
(
"need either --dest or --xml"
));
if
(
pivot
&&
finish
)
{
return
false
;
vshError
(
ctl
,
"%s"
,
_
(
"cannot mix --pivot and --finish"
));
}
if
(
!
blocking
)
{
if
(
verbose
)
{
vshError
(
ctl
,
"%s"
,
_
(
"--verbose requires at least one of --timeout, "
"--wait, --pivot, or --finish"
));
return
false
;
return
false
;
}
}
if
(
vshCommandOptTimeoutToMs
(
ctl
,
cmd
,
&
timeout
)
<
0
)
if
(
async
)
{
vshError
(
ctl
,
"%s"
,
_
(
"--async requires at least one of --timeout, "
"--wait, --pivot, or --finish"
));
return
false
;
return
false
;
if
(
vshCommandOptBool
(
cmd
,
"async"
))
}
abort_flags
|=
VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC
;
}
if
(
blocking
)
{
sigemptyset
(
&
sigmask
);
sigemptyset
(
&
sigmask
);
sigaddset
(
&
sigmask
,
SIGINT
);
sigaddset
(
&
sigmask
,
SIGINT
);
...
@@ -2143,9 +2178,6 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
...
@@ -2143,9 +2178,6 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
sigaction
(
SIGINT
,
&
sig_action
,
&
old_sig_action
);
sigaction
(
SIGINT
,
&
sig_action
,
&
old_sig_action
);
GETTIMEOFDAY
(
&
start
);
GETTIMEOFDAY
(
&
start
);
}
else
if
(
verbose
||
vshCommandOptBool
(
cmd
,
"async"
))
{
vshError
(
ctl
,
"%s"
,
_
(
"missing --wait option"
));
return
false
;
}
}
virConnectDomainEventGenericCallback
cb
=
virConnectDomainEventGenericCallback
cb
=
...
@@ -2162,34 +2194,13 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
...
@@ -2162,34 +2194,13 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
if
(
!
(
dom
=
vshCommandOptDomain
(
ctl
,
cmd
,
NULL
)))
if
(
!
(
dom
=
vshCommandOptDomain
(
ctl
,
cmd
,
NULL
)))
goto
cleanup
;
goto
cleanup
;
/* XXX: Parse bandwidth as scaled input, rather than forcing
* MiB/s, and either reject negative input or treat it as 0 rather
* than trying to guess which value will work well across both
* APIs with their different sizes and scales. */
if
(
vshCommandOptULWrap
(
ctl
,
cmd
,
"bandwidth"
,
&
bandwidth
)
<
0
)
goto
cleanup
;
if
(
vshCommandOptUInt
(
ctl
,
cmd
,
"granularity"
,
&
granularity
)
<
0
)
goto
cleanup
;
if
(
vshCommandOptULongLong
(
ctl
,
cmd
,
"buf-size"
,
&
buf_size
)
<
0
)
goto
cleanup
;
if
(
xml
)
{
if
(
xml
)
{
if
(
virFileReadAll
(
xml
,
VSH_MAX_XML_FILE
,
&
xmlstr
)
<
0
)
{
if
(
virFileReadAll
(
xml
,
VSH_MAX_XML_FILE
,
&
xmlstr
)
<
0
)
{
vshReportError
(
ctl
);
vshReportError
(
ctl
);
goto
cleanup
;
goto
cleanup
;
}
}
}
else
if
(
!
dest
)
{
vshError
(
ctl
,
"%s"
,
_
(
"need either --dest or --xml"
));
goto
cleanup
;
}
}
/* Exploit that some VIR_DOMAIN_BLOCK_REBASE_* and
* VIR_DOMAIN_BLOCK_COPY_* flags have the same values. */
if
(
vshCommandOptBool
(
cmd
,
"shallow"
))
flags
|=
VIR_DOMAIN_BLOCK_REBASE_SHALLOW
;
if
(
vshCommandOptBool
(
cmd
,
"reuse-external"
))
flags
|=
VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT
;
if
(
granularity
||
buf_size
||
(
format
&&
STRNEQ
(
format
,
"raw"
))
||
xml
)
{
if
(
granularity
||
buf_size
||
(
format
&&
STRNEQ
(
format
,
"raw"
))
||
xml
)
{
/* New API */
/* New API */
if
(
bandwidth
||
granularity
||
buf_size
)
{
if
(
bandwidth
||
granularity
||
buf_size
)
{
...
@@ -2242,7 +2253,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
...
@@ -2242,7 +2253,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
}
else
{
}
else
{
/* Old API */
/* Old API */
flags
|=
VIR_DOMAIN_BLOCK_REBASE_COPY
;
flags
|=
VIR_DOMAIN_BLOCK_REBASE_COPY
;
if
(
vshCommandOptBool
(
cmd
,
"blockdev"
)
)
if
(
blockdev
)
flags
|=
VIR_DOMAIN_BLOCK_REBASE_COPY_DEV
;
flags
|=
VIR_DOMAIN_BLOCK_REBASE_COPY_DEV
;
if
(
STREQ_NULLABLE
(
format
,
"raw"
))
if
(
STREQ_NULLABLE
(
format
,
"raw"
))
flags
|=
VIR_DOMAIN_BLOCK_REBASE_COPY_RAW
;
flags
|=
VIR_DOMAIN_BLOCK_REBASE_COPY_RAW
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录