Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
040a4fe7
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,发现更多精彩内容 >>
提交
040a4fe7
编写于
2月 11, 2016
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
conf: snapshot: Extract code to generate default external file names
上级
d5c7655c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
77 addition
and
54 deletion
+77
-54
src/conf/snapshot_conf.c
src/conf/snapshot_conf.c
+77
-54
未找到文件。
src/conf/snapshot_conf.c
浏览文件 @
040a4fe7
...
...
@@ -429,6 +429,80 @@ virDomainSnapshotDefParseString(const char *xmlStr,
return
ret
;
}
/**
* virDomainSnapshotDefAssignExternalNames:
* @def: snapshot def object
*
* Generate default external file names for snapshot targets. Returns 0 on
* success, -1 on error.
*/
static
int
virDomainSnapshotDefAssignExternalNames
(
virDomainSnapshotDefPtr
def
)
{
size_t
i
;
int
ret
=
-
1
;
for
(
i
=
0
;
i
<
def
->
ndisks
;
i
++
)
{
virDomainSnapshotDiskDefPtr
disk
=
&
def
->
disks
[
i
];
if
(
disk
->
snapshot
==
VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL
&&
!
disk
->
src
->
path
)
{
const
char
*
original
=
virDomainDiskGetSource
(
def
->
dom
->
disks
[
i
]);
const
char
*
tmp
;
struct
stat
sb
;
if
(
disk
->
src
->
type
!=
VIR_STORAGE_TYPE_FILE
)
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"cannot generate external snapshot name "
"for disk '%s' on a '%s' device"
),
disk
->
name
,
virStorageTypeToString
(
disk
->
src
->
type
));
goto
cleanup
;
}
if
(
!
original
)
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"cannot generate external snapshot name "
"for disk '%s' without source"
),
disk
->
name
);
goto
cleanup
;
}
if
(
stat
(
original
,
&
sb
)
<
0
||
!
S_ISREG
(
sb
.
st_mode
))
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"source for disk '%s' is not a regular "
"file; refusing to generate external "
"snapshot name"
),
disk
->
name
);
goto
cleanup
;
}
tmp
=
strrchr
(
original
,
'.'
);
if
(
!
tmp
||
strchr
(
tmp
,
'/'
))
{
if
(
virAsprintf
(
&
disk
->
src
->
path
,
"%s.%s"
,
original
,
def
->
name
)
<
0
)
goto
cleanup
;
}
else
{
if
((
tmp
-
original
)
>
INT_MAX
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"integer overflow"
));
goto
cleanup
;
}
if
(
virAsprintf
(
&
disk
->
src
->
path
,
"%.*s.%s"
,
(
int
)
(
tmp
-
original
),
original
,
def
->
name
)
<
0
)
goto
cleanup
;
}
}
}
ret
=
0
;
cleanup:
return
ret
;
}
static
int
virDomainSnapshotCompareDiskIndex
(
const
void
*
a
,
const
void
*
b
)
{
...
...
@@ -565,60 +639,9 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
qsort
(
&
def
->
disks
[
0
],
def
->
ndisks
,
sizeof
(
def
->
disks
[
0
]),
virDomainSnapshotCompareDiskIndex
);
/* Generate any default external file names, but only if the
* backing file is a regular file. */
for
(
i
=
0
;
i
<
def
->
ndisks
;
i
++
)
{
virDomainSnapshotDiskDefPtr
disk
=
&
def
->
disks
[
i
];
if
(
disk
->
snapshot
==
VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL
&&
!
disk
->
src
->
path
)
{
const
char
*
original
=
virDomainDiskGetSource
(
def
->
dom
->
disks
[
i
]);
const
char
*
tmp
;
struct
stat
sb
;
if
(
disk
->
src
->
type
!=
VIR_STORAGE_TYPE_FILE
)
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"cannot generate external snapshot name "
"for disk '%s' on a '%s' device"
),
disk
->
name
,
virStorageTypeToString
(
disk
->
src
->
type
));
/* Generate default external file names for external snapshot locations */
if
(
virDomainSnapshotDefAssignExternalNames
(
def
)
<
0
)
goto
cleanup
;
}
if
(
!
original
)
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"cannot generate external snapshot name "
"for disk '%s' without source"
),
disk
->
name
);
goto
cleanup
;
}
if
(
stat
(
original
,
&
sb
)
<
0
||
!
S_ISREG
(
sb
.
st_mode
))
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"source for disk '%s' is not a regular "
"file; refusing to generate external "
"snapshot name"
),
disk
->
name
);
goto
cleanup
;
}
tmp
=
strrchr
(
original
,
'.'
);
if
(
!
tmp
||
strchr
(
tmp
,
'/'
))
{
if
(
virAsprintf
(
&
disk
->
src
->
path
,
"%s.%s"
,
original
,
def
->
name
)
<
0
)
goto
cleanup
;
}
else
{
if
((
tmp
-
original
)
>
INT_MAX
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"integer overflow"
));
goto
cleanup
;
}
if
(
virAsprintf
(
&
disk
->
src
->
path
,
"%.*s.%s"
,
(
int
)
(
tmp
-
original
),
original
,
def
->
name
)
<
0
)
goto
cleanup
;
}
}
}
ret
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录