Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
e545dd4f
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看板
提交
e545dd4f
编写于
1月 30, 2012
作者:
Z
Zeeshan Ali (Khattak)
提交者:
Laine Stump
1月 31, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement virStorageVolResize() for FS backend
Currently only VIR_STORAGE_VOL_RESIZE_DELTA flag is supported.
上级
055bbf45
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
166 addition
and
1 deletion
+166
-1
src/storage/storage_backend.h
src/storage/storage_backend.h
+6
-0
src/storage/storage_backend_fs.c
src/storage/storage_backend_fs.c
+53
-0
src/storage/storage_driver.c
src/storage/storage_driver.c
+89
-1
src/util/storage_file.c
src/util/storage_file.c
+16
-0
src/util/storage_file.h
src/util/storage_file.h
+2
-0
未找到文件。
src/storage/storage_backend.h
浏览文件 @
e545dd4f
...
...
@@ -44,6 +44,11 @@ typedef int (*virStorageBackendDeleteVol)(virConnectPtr conn, virStoragePoolObjP
typedef
int
(
*
virStorageBackendBuildVolFrom
)(
virConnectPtr
conn
,
virStoragePoolObjPtr
pool
,
virStorageVolDefPtr
origvol
,
virStorageVolDefPtr
newvol
,
unsigned
int
flags
);
typedef
int
(
*
virStorageBackendVolumeResize
)(
virConnectPtr
conn
,
virStoragePoolObjPtr
pool
,
virStorageVolDefPtr
vol
,
unsigned
long
long
capacity
,
unsigned
int
flags
);
/* File creation/cloning functions used for cloning between backends */
int
virStorageBackendCreateRaw
(
virConnectPtr
conn
,
...
...
@@ -78,6 +83,7 @@ struct _virStorageBackend {
virStorageBackendCreateVol
createVol
;
virStorageBackendRefreshVol
refreshVol
;
virStorageBackendDeleteVol
deleteVol
;
virStorageBackendVolumeResize
resizeVol
;
};
virStorageBackendPtr
virStorageBackendForType
(
int
type
);
...
...
src/storage/storage_backend_fs.c
浏览文件 @
e545dd4f
...
...
@@ -1187,6 +1187,56 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
return
0
;
}
static
int
virStorageBackendFilesystemResizeQemuImg
(
const
char
*
path
,
unsigned
long
long
capacity
)
{
int
ret
=
-
1
;
char
*
img_tool
;
virCommandPtr
cmd
=
NULL
;
/* KVM is usually ahead of qemu on features, so try that first */
img_tool
=
virFindFileInPath
(
"kvm-img"
);
if
(
!
img_tool
)
img_tool
=
virFindFileInPath
(
"qemu-img"
);
if
(
!
img_tool
)
{
virStorageReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"unable to find kvm-img or qemu-img"
));
return
-
1
;
}
cmd
=
virCommandNew
(
img_tool
);
virCommandAddArgList
(
cmd
,
"resize"
,
path
,
NULL
);
virCommandAddArgFormat
(
cmd
,
"%llu"
,
capacity
);
ret
=
virCommandRun
(
cmd
,
NULL
);
VIR_FREE
(
img_tool
);
virCommandFree
(
cmd
);
return
ret
;
}
/**
* Resize a volume
*/
static
int
virStorageBackendFileSystemVolResize
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
virStoragePoolObjPtr
pool
ATTRIBUTE_UNUSED
,
virStorageVolDefPtr
vol
,
unsigned
long
long
capacity
,
unsigned
int
flags
)
{
virCheckFlags
(
0
,
-
1
);
if
(
vol
->
target
.
format
==
VIR_STORAGE_FILE_RAW
)
return
virStorageFileResize
(
vol
->
target
.
path
,
capacity
);
else
return
virStorageBackendFilesystemResizeQemuImg
(
vol
->
target
.
path
,
capacity
);
}
virStorageBackend
virStorageBackendDirectory
=
{
.
type
=
VIR_STORAGE_POOL_DIR
,
...
...
@@ -1199,6 +1249,7 @@ virStorageBackend virStorageBackendDirectory = {
.
createVol
=
virStorageBackendFileSystemVolCreate
,
.
refreshVol
=
virStorageBackendFileSystemVolRefresh
,
.
deleteVol
=
virStorageBackendFileSystemVolDelete
,
.
resizeVol
=
virStorageBackendFileSystemVolResize
,
};
#if WITH_STORAGE_FS
...
...
@@ -1216,6 +1267,7 @@ virStorageBackend virStorageBackendFileSystem = {
.
createVol
=
virStorageBackendFileSystemVolCreate
,
.
refreshVol
=
virStorageBackendFileSystemVolRefresh
,
.
deleteVol
=
virStorageBackendFileSystemVolDelete
,
.
resizeVol
=
virStorageBackendFileSystemVolResize
,
};
virStorageBackend
virStorageBackendNetFileSystem
=
{
.
type
=
VIR_STORAGE_POOL_NETFS
,
...
...
@@ -1232,5 +1284,6 @@ virStorageBackend virStorageBackendNetFileSystem = {
.
createVol
=
virStorageBackendFileSystemVolCreate
,
.
refreshVol
=
virStorageBackendFileSystemVolRefresh
,
.
deleteVol
=
virStorageBackendFileSystemVolDelete
,
.
resizeVol
=
virStorageBackendFileSystemVolResize
,
};
#endif
/* WITH_STORAGE_FS */
src/storage/storage_driver.c
浏览文件 @
e545dd4f
/*
* storage_driver.c: core driver for storage APIs
*
* Copyright (C) 2006-201
1
Red Hat, Inc.
* Copyright (C) 2006-201
2
Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
...
...
@@ -1695,7 +1695,94 @@ out:
return
ret
;
}
static
int
storageVolumeResize
(
virStorageVolPtr
obj
,
unsigned
long
long
capacity
,
unsigned
int
flags
)
{
virStorageDriverStatePtr
driver
=
obj
->
conn
->
storagePrivateData
;
virStorageBackendPtr
backend
;
virStoragePoolObjPtr
pool
=
NULL
;
virStorageVolDefPtr
vol
=
NULL
;
unsigned
long
long
abs_capacity
;
int
ret
=
-
1
;
virCheckFlags
(
VIR_STORAGE_VOL_RESIZE_DELTA
,
-
1
);
storageDriverLock
(
driver
);
pool
=
virStoragePoolObjFindByName
(
&
driver
->
pools
,
obj
->
pool
);
storageDriverUnlock
(
driver
);
if
(
!
pool
)
{
virStorageReportError
(
VIR_ERR_NO_STORAGE_POOL
,
_
(
"no storage pool with matching uuid"
));
goto
out
;
}
if
(
!
virStoragePoolObjIsActive
(
pool
))
{
virStorageReportError
(
VIR_ERR_OPERATION_INVALID
,
_
(
"storage pool is not active"
));
goto
out
;
}
if
((
backend
=
virStorageBackendForType
(
pool
->
def
->
type
))
==
NULL
)
goto
out
;
vol
=
virStorageVolDefFindByName
(
pool
,
obj
->
name
);
if
(
vol
==
NULL
)
{
virStorageReportError
(
VIR_ERR_NO_STORAGE_VOL
,
_
(
"no storage vol with matching name '%s'"
),
obj
->
name
);
goto
out
;
}
if
(
vol
->
building
)
{
virStorageReportError
(
VIR_ERR_OPERATION_INVALID
,
_
(
"volume '%s' is still being allocated."
),
vol
->
name
);
goto
out
;
}
if
(
flags
&
VIR_STORAGE_VOL_RESIZE_DELTA
)
{
abs_capacity
=
vol
->
capacity
+
capacity
;
flags
&=
~
VIR_STORAGE_VOL_RESIZE_DELTA
;
}
else
{
abs_capacity
=
capacity
;
}
if
(
abs_capacity
<
vol
->
allocation
)
{
virStorageReportError
(
VIR_ERR_INVALID_ARG
,
_
(
"can't shrink capacity below "
"existing allocation"
));
goto
out
;
}
if
(
abs_capacity
>
vol
->
allocation
+
pool
->
def
->
available
)
{
virStorageReportError
(
VIR_ERR_INVALID_ARG
,
_
(
"Not enough space left on storage pool"
));
goto
out
;
}
if
(
!
backend
->
resizeVol
)
{
virStorageReportError
(
VIR_ERR_NO_SUPPORT
,
_
(
"storage pool does not support changing of "
"volume capacity"
));
goto
out
;
}
if
(
backend
->
resizeVol
(
obj
->
conn
,
pool
,
vol
,
abs_capacity
,
flags
)
<
0
)
goto
out
;
vol
->
capacity
=
abs_capacity
;
ret
=
0
;
out:
if
(
pool
)
virStoragePoolObjUnlock
(
pool
);
return
ret
;
}
/* If the volume we're wiping is already a sparse file, we simply
* truncate and extend it to its original size, filling it with
...
...
@@ -2243,6 +2330,7 @@ static virStorageDriver storageDriver = {
.
volGetInfo
=
storageVolumeGetInfo
,
/* 0.4.0 */
.
volGetXMLDesc
=
storageVolumeGetXMLDesc
,
/* 0.4.0 */
.
volGetPath
=
storageVolumeGetPath
,
/* 0.4.0 */
.
volResize
=
storageVolumeResize
,
/* 0.9.10 */
.
poolIsActive
=
storagePoolIsActive
,
/* 0.7.3 */
.
poolIsPersistent
=
storagePoolIsPersistent
,
/* 0.7.3 */
...
...
src/util/storage_file.c
浏览文件 @
e545dd4f
...
...
@@ -931,6 +931,22 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta)
VIR_FREE
(
meta
);
}
/**
* virStorageFileResize:
*
* Change the capacity of the raw storage file at 'path'.
*/
int
virStorageFileResize
(
const
char
*
path
,
unsigned
long
long
capacity
)
{
if
(
truncate
(
path
,
capacity
)
<
0
)
{
virReportSystemError
(
errno
,
_
(
"Failed to truncate file '%s'"
),
path
);
return
-
1
;
}
return
0
;
}
#ifdef __linux__
# ifndef NFS_SUPER_MAGIC
...
...
src/util/storage_file.h
浏览文件 @
e545dd4f
...
...
@@ -72,6 +72,8 @@ int virStorageFileGetMetadataFromFD(const char *path,
void
virStorageFileFreeMetadata
(
virStorageFileMetadata
*
meta
);
int
virStorageFileResize
(
const
char
*
path
,
unsigned
long
long
capacity
);
enum
{
VIR_STORAGE_FILE_SHFS_NFS
=
(
1
<<
0
),
VIR_STORAGE_FILE_SHFS_GFS2
=
(
1
<<
1
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录