Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
cbb1dd0a
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,发现更多精彩内容 >>
提交
cbb1dd0a
编写于
11月 04, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove use of virStringList in favour of strongly typed APIs
上级
b5bb5d95
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
134 addition
and
132 deletion
+134
-132
ChangeLog
ChangeLog
+14
-0
src/internal.h
src/internal.h
+0
-12
src/libvirt.c
src/libvirt.c
+0
-40
src/storage_backend_fs.c
src/storage_backend_fs.c
+25
-21
src/storage_backend_logical.c
src/storage_backend_logical.c
+3
-0
src/storage_conf.c
src/storage_conf.c
+91
-59
src/storage_conf.h
src/storage_conf.h
+1
-0
未找到文件。
ChangeLog
浏览文件 @
cbb1dd0a
Tue Nov 4 21:50:31 UTC 2008 Daniel P. Berrange <berrange@redhat.com>
Remove use of virStringList
* src/internal.h, src/libvirt.c: Remove virStringList code
* src/storage_backend_fs.c: Replace use of virStringList
with virStoragePoolSourceList
* src/storage_backend_logical.c: Set format to LVM2 and
source type to LOGICAL
* src/storage_conf.c: Refactor pool source XML formating
into virStoragePoolSourceFormat and make both users call
the common code
* src/storage_conf.h: Include pool source type in
virStoragePoolSourceList struct
Tue Nov 4 14:58:31 CET 2008 Jim Meyering <meyering@redhat.com>
don't print an uninitialized integer in a diagnostic
...
...
src/internal.h
浏览文件 @
cbb1dd0a
...
...
@@ -371,18 +371,6 @@ int __virDomainMigratePrepare (virConnectPtr dconn, char **cookie, int *cookiele
int
__virDomainMigratePerform
(
virDomainPtr
domain
,
const
char
*
cookie
,
int
cookielen
,
const
char
*
uri
,
unsigned
long
flags
,
const
char
*
dname
,
unsigned
long
bandwidth
);
virDomainPtr
__virDomainMigrateFinish
(
virConnectPtr
dconn
,
const
char
*
dname
,
const
char
*
cookie
,
int
cookielen
,
const
char
*
uri
,
unsigned
long
flags
);
typedef
struct
_virStringList
virStringList
;
struct
_virStringList
{
char
*
val
;
int
len
;
struct
_virStringList
*
next
;
};
char
*
__virStringListJoin
(
const
virStringList
*
list
,
const
char
*
pre
,
const
char
*
post
,
const
char
*
sep
);
void
__virStringListFree
(
virStringList
*
list
);
/**
* Domain Event Notification
*/
...
...
src/libvirt.c
浏览文件 @
cbb1dd0a
...
...
@@ -5305,46 +5305,6 @@ virStorageVolGetPath(virStorageVolPtr vol)
/* Not for public use. Combines the elements of a virStringList
* into a single string.
*/
char
*
__virStringListJoin
(
const
virStringList
*
list
,
const
char
*
pre
,
const
char
*
post
,
const
char
*
sep
)
{
size_t
pre_len
=
strlen
(
pre
);
size_t
sep_len
=
strlen
(
sep
);
size_t
len
=
pre_len
+
strlen
(
post
);
const
virStringList
*
p
;
char
*
retval
;
for
(
p
=
list
;
p
;
p
=
p
->
next
)
len
+=
p
->
len
+
sep_len
;
if
(
VIR_ALLOC_N
(
retval
,
len
+
1
)
<
0
)
return
NULL
;
strcpy
(
retval
,
pre
);
len
=
pre_len
;
for
(
p
=
list
;
p
;
p
=
p
->
next
)
{
strcpy
(
retval
+
len
,
p
->
val
);
len
+=
p
->
len
;
strcpy
(
retval
+
len
,
sep
);
len
+=
sep_len
;
}
strcpy
(
retval
+
len
,
post
);
return
retval
;
}
void
__virStringListFree
(
virStringList
*
list
)
{
while
(
list
)
{
virStringList
*
p
=
list
->
next
;
VIR_FREE
(
list
);
list
=
p
;
}
}
/*
* Domain Event Notification
*/
...
...
src/storage_backend_fs.c
浏览文件 @
cbb1dd0a
...
...
@@ -295,7 +295,7 @@ static int virStorageBackendProbeFile(virConnectPtr conn,
#if WITH_STORAGE_FS
struct
_virNetfsDiscoverState
{
const
char
*
host
;
virSt
ringList
*
list
;
virSt
oragePoolSourceList
list
;
};
typedef
struct
_virNetfsDiscoverState
virNetfsDiscoverState
;
...
...
@@ -307,8 +307,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_U
void
*
data
)
{
virNetfsDiscoverState
*
state
=
data
;
virStringList
*
newItem
;
const
char
*
name
,
*
path
;
virStoragePoolSource
*
src
;
path
=
groups
[
0
];
...
...
@@ -325,24 +325,17 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_U
return
-
1
;
}
/* Append new XML desc to list */
if
(
VIR_ALLOC
(
newItem
)
!=
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
"%s"
,
_
(
"new xml desc"
));
if
(
VIR_REALLOC_N
(
state
->
list
.
sources
,
state
->
list
.
nsources
+
1
)
<
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
NULL
);
return
-
1
;
}
memset
(
state
->
list
.
sources
+
state
->
list
.
nsources
,
0
,
sizeof
(
*
state
->
list
.
sources
));
if
(
asprintf
(
&
newItem
->
val
,
"<source><host name='%s'/><dir path='%s'/></source>"
,
state
->
host
,
path
)
<=
0
)
{
virStorageReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"asprintf failed"
));
VIR_FREE
(
newItem
);
src
=
state
->
list
.
sources
+
state
->
list
.
nsources
++
;
if
(
!
(
src
->
host
.
name
=
strdup
(
state
->
host
))
||
!
(
src
->
dir
=
strdup
(
path
)))
return
-
1
;
}
newItem
->
len
=
strlen
(
newItem
->
val
);
newItem
->
next
=
state
->
list
;
state
->
list
=
newItem
;
src
->
format
=
VIR_STORAGE_POOL_NETFS_NFS
;
return
0
;
}
...
...
@@ -368,10 +361,18 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn,
};
xmlDocPtr
doc
=
NULL
;
xmlXPathContextPtr
xpath_ctxt
=
NULL
;
virNetfsDiscoverState
state
=
{
.
host
=
NULL
,
.
list
=
NULL
};
virNetfsDiscoverState
state
=
{
.
host
=
NULL
,
.
list
=
{
.
type
=
VIR_STORAGE_POOL_NETFS
,
.
nsources
=
0
,
.
sources
=
NULL
}
};
const
char
*
prog
[]
=
{
SHOWMOUNT
,
"--no-headers"
,
"--exports"
,
NULL
,
NULL
};
int
exitstatus
;
char
*
retval
=
NULL
;
unsigned
int
i
;
doc
=
xmlReadDoc
((
const
xmlChar
*
)
srcSpec
,
"srcSpec.xml"
,
NULL
,
XML_PARSE_NOENT
|
XML_PARSE_NONET
|
...
...
@@ -400,18 +401,21 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn,
&
state
,
&
exitstatus
)
<
0
)
goto
cleanup
;
retval
=
__virStringListJoin
(
state
.
list
,
SOURCES_START_TAG
,
SOURCES_END_TAG
,
"
\n
"
);
retval
=
virStoragePoolSourceListFormat
(
conn
,
&
state
.
list
);
if
(
retval
==
NULL
)
{
virStorageReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
"%s"
,
_
(
"retval"
));
goto
cleanup
;
}
cleanup:
for
(
i
=
0
;
i
<
state
.
list
.
nsources
;
i
++
)
virStoragePoolSourceFree
(
&
state
.
list
.
sources
[
i
]);
VIR_FREE
(
state
.
list
.
sources
);
VIR_FREE
(
state
.
host
);
xmlFreeDoc
(
doc
);
xmlXPathFreeContext
(
xpath_ctxt
);
VIR_FREE
(
state
.
host
);
__virStringListFree
(
state
.
list
);
return
retval
;
}
...
...
src/storage_backend_logical.c
浏览文件 @
cbb1dd0a
...
...
@@ -295,6 +295,7 @@ virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn,
dev
=
&
thisSource
->
devices
[
thisSource
->
ndevice
];
thisSource
->
ndevice
++
;
thisSource
->
format
=
VIR_STORAGE_POOL_LOGICAL_LVM2
;
memset
(
dev
,
0
,
sizeof
(
*
dev
));
dev
->
path
=
pvname
;
...
...
@@ -331,6 +332,8 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn,
int
i
;
memset
(
&
sourceList
,
0
,
sizeof
(
sourceList
));
sourceList
.
type
=
VIR_STORAGE_POOL_LOGICAL
;
if
(
virStorageBackendRunProgRegex
(
conn
,
NULL
,
prog
,
1
,
regexes
,
vars
,
virStorageBackendLogicalFindPoolSourcesFunc
,
&
sourceList
,
&
exitstatus
)
<
0
)
...
...
src/storage_conf.c
浏览文件 @
cbb1dd0a
...
...
@@ -472,6 +472,68 @@ virStoragePoolDefParse(virConnectPtr conn,
return
NULL
;
}
static
int
virStoragePoolSourceFormat
(
virConnectPtr
conn
,
virBufferPtr
buf
,
virStorageBackendPoolOptionsPtr
options
,
virStoragePoolSourcePtr
src
)
{
int
i
,
j
;
virBufferAddLit
(
buf
,
" <source>
\n
"
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_HOST
)
&&
src
->
host
.
name
)
virBufferVSprintf
(
buf
,
" <host name='%s'/>
\n
"
,
src
->
host
.
name
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE
)
&&
src
->
ndevice
)
{
for
(
i
=
0
;
i
<
src
->
ndevice
;
i
++
)
{
if
(
src
->
devices
[
i
].
nfreeExtent
)
{
virBufferVSprintf
(
buf
,
" <device path='%s'>
\n
"
,
src
->
devices
[
i
].
path
);
for
(
j
=
0
;
j
<
src
->
devices
[
i
].
nfreeExtent
;
j
++
)
{
virBufferVSprintf
(
buf
,
" <freeExtent start='%llu' end='%llu'/>
\n
"
,
src
->
devices
[
i
].
freeExtents
[
j
].
start
,
src
->
devices
[
i
].
freeExtents
[
j
].
end
);
}
virBufferAddLit
(
buf
,
" </device>
\n
"
);
}
else
virBufferVSprintf
(
buf
,
" <device path='%s'/>
\n
"
,
src
->
devices
[
i
].
path
);
}
}
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_DIR
)
&&
src
->
dir
)
virBufferVSprintf
(
buf
,
" <dir path='%s'/>
\n
"
,
src
->
dir
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER
)
&&
src
->
adapter
)
virBufferVSprintf
(
buf
,
" <adapter name='%s'/>
\n
"
,
src
->
adapter
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_NAME
)
&&
src
->
name
)
virBufferVSprintf
(
buf
,
" <name>%s</name>
\n
"
,
src
->
name
);
if
(
options
->
formatToString
)
{
const
char
*
format
=
(
options
->
formatToString
)(
src
->
format
);
if
(
!
format
)
{
virStorageReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"unknown pool format number %d"
),
src
->
format
);
return
-
1
;
}
virBufferVSprintf
(
buf
,
" <format type='%s'/>
\n
"
,
format
);
}
if
(
src
->
authType
==
VIR_STORAGE_POOL_AUTH_CHAP
)
virBufferVSprintf
(
buf
,
" <auth type='chap' login='%s' passwd='%s'>
\n
"
,
src
->
auth
.
chap
.
login
,
src
->
auth
.
chap
.
passwd
);
virBufferAddLit
(
buf
,
" </source>
\n
"
);
return
0
;
}
char
*
virStoragePoolDefFormat
(
virConnectPtr
conn
,
...
...
@@ -480,7 +542,6 @@ virStoragePoolDefFormat(virConnectPtr conn,
virBuffer
buf
=
VIR_BUFFER_INITIALIZER
;
const
char
*
type
;
char
uuid
[
VIR_UUID_STRING_BUFLEN
];
int
i
,
j
;
options
=
virStorageBackendPoolOptionsForType
(
def
->
type
);
if
(
options
==
NULL
)
...
...
@@ -505,56 +566,8 @@ virStoragePoolDefFormat(virConnectPtr conn,
virBufferVSprintf
(
&
buf
,
" <available>%llu</available>
\n
"
,
def
->
available
);
virBufferAddLit
(
&
buf
,
" <source>
\n
"
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_HOST
)
&&
def
->
source
.
host
.
name
)
virBufferVSprintf
(
&
buf
,
" <host name='%s'/>
\n
"
,
def
->
source
.
host
.
name
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE
)
&&
def
->
source
.
ndevice
)
{
for
(
i
=
0
;
i
<
def
->
source
.
ndevice
;
i
++
)
{
if
(
def
->
source
.
devices
[
i
].
nfreeExtent
)
{
virBufferVSprintf
(
&
buf
,
" <device path='%s'>
\n
"
,
def
->
source
.
devices
[
i
].
path
);
for
(
j
=
0
;
j
<
def
->
source
.
devices
[
i
].
nfreeExtent
;
j
++
)
{
virBufferVSprintf
(
&
buf
,
" <freeExtent start='%llu' end='%llu'/>
\n
"
,
def
->
source
.
devices
[
i
].
freeExtents
[
j
].
start
,
def
->
source
.
devices
[
i
].
freeExtents
[
j
].
end
);
}
virBufferAddLit
(
&
buf
,
" </device>
\n
"
);
}
else
virBufferVSprintf
(
&
buf
,
" <device path='%s'/>
\n
"
,
def
->
source
.
devices
[
i
].
path
);
}
}
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_DIR
)
&&
def
->
source
.
dir
)
virBufferVSprintf
(
&
buf
,
" <dir path='%s'/>
\n
"
,
def
->
source
.
dir
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER
)
&&
def
->
source
.
adapter
)
virBufferVSprintf
(
&
buf
,
" <adapter name='%s'/>
\n
"
,
def
->
source
.
adapter
);
if
((
options
->
flags
&
VIR_STORAGE_BACKEND_POOL_SOURCE_NAME
)
&&
def
->
source
.
name
)
virBufferVSprintf
(
&
buf
,
" <name>%s</name>
\n
"
,
def
->
source
.
name
);
if
(
options
->
formatToString
)
{
const
char
*
format
=
(
options
->
formatToString
)(
def
->
source
.
format
);
if
(
!
format
)
{
virStorageReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"unknown pool format number %d"
),
def
->
source
.
format
);
if
(
virStoragePoolSourceFormat
(
conn
,
&
buf
,
options
,
&
def
->
source
)
<
0
)
goto
cleanup
;
}
virBufferVSprintf
(
&
buf
,
" <format type='%s'/>
\n
"
,
format
);
}
if
(
def
->
source
.
authType
==
VIR_STORAGE_POOL_AUTH_CHAP
)
virBufferVSprintf
(
&
buf
,
" <auth type='chap' login='%s' passwd='%s'>
\n
"
,
def
->
source
.
auth
.
chap
.
login
,
def
->
source
.
auth
.
chap
.
passwd
);
virBufferAddLit
(
&
buf
,
" </source>
\n
"
);
virBufferAddLit
(
&
buf
,
" <target>
\n
"
);
...
...
@@ -1271,22 +1284,41 @@ virStoragePoolObjDeleteDef(virConnectPtr conn,
return
0
;
}
char
*
virStoragePoolSourceListFormat
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
char
*
virStoragePoolSourceListFormat
(
virConnectPtr
conn
,
virStoragePoolSourceListPtr
def
)
{
int
i
,
j
;
virStorageBackendPoolOptionsPtr
options
;
virBuffer
buf
=
VIR_BUFFER_INITIALIZER
;
const
char
*
type
;
int
i
;
options
=
virStorageBackendPoolOptionsForType
(
def
->
type
);
if
(
options
==
NULL
)
return
NULL
;
type
=
virStorageBackendToString
(
def
->
type
);
if
(
!
type
)
{
virStorageReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"unexpected pool type"
));
goto
cleanup
;
}
virBufferAddLit
(
&
buf
,
"<sources>"
);
virBufferAddLit
(
&
buf
,
"<sources>
\n
"
);
for
(
i
=
0
;
i
<
def
->
nsources
;
i
++
)
{
virBufferVSprintf
(
&
buf
,
"<source><name>%s</name>"
,
def
->
sources
[
i
].
name
);
for
(
j
=
0
;
j
<
def
->
sources
[
i
].
ndevice
;
j
++
)
virBufferVSprintf
(
&
buf
,
"<device path='%s'/>"
,
def
->
sources
[
i
].
devices
[
j
].
path
);
virBufferAddLit
(
&
buf
,
"</source>"
);
virStoragePoolSourceFormat
(
conn
,
&
buf
,
options
,
&
def
->
sources
[
i
]);
}
virBufferAddLit
(
&
buf
,
"</sources>"
);
virBufferAddLit
(
&
buf
,
"</sources>
\n
"
);
if
(
virBufferError
(
&
buf
))
goto
no_memory
;
return
virBufferContentAndReset
(
&
buf
);
no_memory:
virStorageReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
NULL
);
cleanup:
free
(
virBufferContentAndReset
(
&
buf
));
return
NULL
;
}
src/storage_conf.h
浏览文件 @
cbb1dd0a
...
...
@@ -252,6 +252,7 @@ struct _virStorageDriverState {
typedef
struct
_virStoragePoolSourceList
virStoragePoolSourceList
;
typedef
virStoragePoolSourceList
*
virStoragePoolSourceListPtr
;
struct
_virStoragePoolSourceList
{
int
type
;
unsigned
int
nsources
;
virStoragePoolSourcePtr
sources
;
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录