Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
e428a69e
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,发现更多精彩内容 >>
提交
e428a69e
编写于
1月 20, 2009
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove use of static data in Xen inotify driver
上级
437ac354
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
88 addition
and
69 deletion
+88
-69
ChangeLog
ChangeLog
+6
-0
src/xen_inotify.c
src/xen_inotify.c
+59
-50
src/xen_unified.h
src/xen_unified.h
+7
-0
src/xs_internal.c
src/xs_internal.c
+16
-19
未找到文件。
ChangeLog
浏览文件 @
e428a69e
Tue Jan 20 17:15:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
* src/xen_inotify.c, src/xen_unified.h, src/xs_internal.c:
Move statically declared data into xenUnifiedPrivatePtr
struct
Tue Jan 20 16:59:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
Make error reporting threadsafe by avoiding strerror()
...
...
src/xen_inotify.c
浏览文件 @
e428a69e
...
...
@@ -48,9 +48,6 @@
__FUNCTION__, __LINE__, fmt)
#define LIBVIRTD_DOMAINS_DIR "/var/lib/xend/domains"
static
const
char
*
configDir
=
NULL
;
static
int
useXenConfigCache
=
0
;
static
xenUnifiedDomainInfoListPtr
configInfoList
=
NULL
;
struct
xenUnifiedDriver
xenInotifyDriver
=
{
xenInotifyOpen
,
/* open */
...
...
@@ -121,6 +118,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, const char *filename,
virDomainPtr
dom
;
const
char
*
uuid_str
;
unsigned
char
rawuuid
[
VIR_UUID_BUFLEN
];
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
/* xend is managing domains. we will get
* a filename in the manner:
...
...
@@ -142,15 +140,15 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, const char *filename,
/* If we are here, the domain has gone away.
search for, and create a domain from the stored
list info */
for
(
i
=
0
;
i
<
configInfoList
->
count
;
i
++
)
{
if
(
!
memcmp
(
uuid
,
configInfoList
->
doms
[
i
]
->
uuid
,
VIR_UUID_BUFLEN
))
{
*
name
=
strdup
(
configInfoList
->
doms
[
i
]
->
name
);
for
(
i
=
0
;
i
<
priv
->
configInfoList
->
count
;
i
++
)
{
if
(
!
memcmp
(
uuid
,
priv
->
configInfoList
->
doms
[
i
]
->
uuid
,
VIR_UUID_BUFLEN
))
{
*
name
=
strdup
(
priv
->
configInfoList
->
doms
[
i
]
->
name
);
if
(
!*
name
)
{
virXenInotifyError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"finding dom for %s"
),
uuid_str
);
return
-
1
;
}
memcpy
(
uuid
,
configInfoList
->
doms
[
i
]
->
uuid
,
VIR_UUID_BUFLEN
);
memcpy
(
uuid
,
priv
->
configInfoList
->
doms
[
i
]
->
uuid
,
VIR_UUID_BUFLEN
);
DEBUG0
(
"Found dom on list"
);
return
0
;
}
...
...
@@ -172,7 +170,8 @@ static int
xenInotifyDomainLookup
(
virConnectPtr
conn
,
const
char
*
filename
,
char
**
name
,
unsigned
char
*
uuid
)
{
if
(
useXenConfigCache
)
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
if
(
priv
->
useXenConfigCache
)
return
xenInotifyXenCacheLookup
(
filename
,
name
,
uuid
);
else
return
xenInotifyXendDomainsDirLookup
(
conn
,
filename
,
name
,
uuid
);
...
...
@@ -195,8 +194,9 @@ xenInotifyDomainEventFromFile(virConnectPtr conn,
}
static
int
xenInotifyXendDomainsDirRemoveEntry
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
xenInotifyXendDomainsDirRemoveEntry
(
virConnectPtr
conn
,
const
char
*
fname
)
{
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
const
char
*
uuidstr
=
fname
+
strlen
(
LIBVIRTD_DOMAINS_DIR
)
+
1
;
unsigned
char
uuid
[
VIR_UUID_BUFLEN
];
int
i
;
...
...
@@ -208,22 +208,22 @@ xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn ATTRIBUTE_UNUSED,
}
/* match and remove on uuid */
for
(
i
=
0
;
i
<
configInfoList
->
count
;
i
++
)
{
if
(
!
memcmp
(
uuid
,
configInfoList
->
doms
[
i
]
->
uuid
,
VIR_UUID_BUFLEN
))
{
VIR_FREE
(
configInfoList
->
doms
[
i
]
->
name
);
VIR_FREE
(
configInfoList
->
doms
[
i
]);
if
(
i
<
(
configInfoList
->
count
-
1
))
memmove
(
configInfoList
->
doms
+
i
,
configInfoList
->
doms
+
i
+
1
,
sizeof
(
*
(
configInfoList
->
doms
))
*
(
configInfoList
->
count
-
(
i
+
1
)));
if
(
VIR_REALLOC_N
(
configInfoList
->
doms
,
configInfoList
->
count
-
1
)
<
0
)
{
for
(
i
=
0
;
i
<
priv
->
configInfoList
->
count
;
i
++
)
{
if
(
!
memcmp
(
uuid
,
priv
->
configInfoList
->
doms
[
i
]
->
uuid
,
VIR_UUID_BUFLEN
))
{
VIR_FREE
(
priv
->
configInfoList
->
doms
[
i
]
->
name
);
VIR_FREE
(
priv
->
configInfoList
->
doms
[
i
]);
if
(
i
<
(
priv
->
configInfoList
->
count
-
1
))
memmove
(
priv
->
configInfoList
->
doms
+
i
,
priv
->
configInfoList
->
doms
+
i
+
1
,
sizeof
(
*
(
priv
->
configInfoList
->
doms
))
*
(
priv
->
configInfoList
->
count
-
(
i
+
1
)));
if
(
VIR_REALLOC_N
(
priv
->
configInfoList
->
doms
,
priv
->
configInfoList
->
count
-
1
)
<
0
)
{
;
/* Failure to reduce memory allocation isn't fatal */
}
configInfoList
->
count
--
;
priv
->
configInfoList
->
count
--
;
return
0
;
}
}
...
...
@@ -235,13 +235,15 @@ xenInotifyXendDomainsDirAddEntry(virConnectPtr conn,
const
char
*
fname
)
{
char
*
name
=
NULL
;
unsigned
char
uuid
[
VIR_UUID_BUFLEN
];
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
if
(
xenInotifyDomainLookup
(
conn
,
fname
,
&
name
,
uuid
)
<
0
)
{
virXenInotifyError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Error looking up domain"
));
return
-
1
;
}
if
(
xenUnifiedAddDomainInfo
(
configInfoList
,
if
(
xenUnifiedAddDomainInfo
(
priv
->
configInfoList
,
-
1
,
name
,
uuid
)
<
0
)
{
virXenInotifyError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Error adding file to config cache"
));
...
...
@@ -255,14 +257,18 @@ xenInotifyXendDomainsDirAddEntry(virConnectPtr conn,
static
int
xenInotifyRemoveDomainConfigInfo
(
virConnectPtr
conn
,
const
char
*
fname
)
{
return
useXenConfigCache
?
xenXMConfigCacheRemoveFile
(
conn
,
fname
)
:
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
return
priv
->
useXenConfigCache
?
xenXMConfigCacheRemoveFile
(
conn
,
fname
)
:
xenInotifyXendDomainsDirRemoveEntry
(
conn
,
fname
);
}
static
int
xenInotifyAddDomainConfigInfo
(
virConnectPtr
conn
,
const
char
*
fname
)
{
return
useXenConfigCache
?
xenXMConfigCacheAddFile
(
conn
,
fname
)
:
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
return
priv
->
useXenConfigCache
?
xenXMConfigCacheAddFile
(
conn
,
fname
)
:
xenInotifyXendDomainsDirAddEntry
(
conn
,
fname
);
}
...
...
@@ -277,7 +283,7 @@ xenInotifyEvent(int watch ATTRIBUTE_UNUSED,
struct
inotify_event
*
e
;
int
got
;
char
*
tmp
,
*
name
;
virConnectPtr
conn
=
(
virConnectPtr
)
data
;
virConnectPtr
conn
=
data
;
xenUnifiedPrivatePtr
priv
=
NULL
;
DEBUG0
(
"got inotify event"
);
...
...
@@ -315,7 +321,8 @@ reread:
name
=
(
char
*
)
&
(
e
->
name
);
snprintf
(
fname
,
1024
,
"%s/%s"
,
configDir
,
name
);
snprintf
(
fname
,
1024
,
"%s/%s"
,
priv
->
configDir
,
name
);
if
(
e
->
mask
&
(
IN_DELETE
|
IN_MOVED_FROM
))
{
virDomainEventPtr
event
=
...
...
@@ -378,24 +385,24 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
if
(
priv
->
xendConfigVersion
<=
2
)
{
/* /etc/xen */
configDir
=
xenXMGetConfigDir
();
useXenConfigCache
=
1
;
priv
->
configDir
=
xenXMGetConfigDir
();
priv
->
useXenConfigCache
=
1
;
}
else
{
/* /var/lib/xend/domains/<uuid>/config.sxp */
configDir
=
LIBVIRTD_DOMAINS_DIR
;
useXenConfigCache
=
0
;
priv
->
configDir
=
LIBVIRTD_DOMAINS_DIR
;
priv
->
useXenConfigCache
=
0
;
if
(
VIR_ALLOC
(
configInfoList
)
<
0
)
{
if
(
VIR_ALLOC
(
priv
->
configInfoList
)
<
0
)
{
virXenInotifyError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"failed to allocate configInfoList"
));
return
-
1
;
}
/* populate initial list */
if
(
!
(
dh
=
opendir
(
configDir
)))
{
if
(
!
(
dh
=
opendir
(
priv
->
configDir
)))
{
virReportSystemError
(
NULL
,
errno
,
_
(
"cannot open directory: %s"
),
configDir
);
priv
->
configDir
);
return
-
1
;
}
while
((
ent
=
readdir
(
dh
)))
{
...
...
@@ -403,9 +410,10 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
continue
;
/* Build the full file path */
if
((
strlen
(
configDir
)
+
1
+
strlen
(
ent
->
d_name
)
+
1
)
>
PATH_MAX
)
if
((
strlen
(
priv
->
configDir
)
+
1
+
strlen
(
ent
->
d_name
)
+
1
)
>
PATH_MAX
)
continue
;
strcpy
(
path
,
configDir
);
strcpy
(
path
,
priv
->
configDir
);
strcat
(
path
,
"/"
);
strcat
(
path
,
ent
->
d_name
);
...
...
@@ -419,24 +427,25 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
}
if
((
priv
->
inotifyFD
=
inotify_init
())
<
0
)
{
vir
XenInotifyError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
vir
ReportSystemError
(
NULL
,
errno
,
"%s"
,
_
(
"initializing inotify"
));
return
-
1
;
}
DEBUG
(
"Adding a watch on %s"
,
configDir
);
DEBUG
(
"Adding a watch on %s"
,
priv
->
configDir
);
if
(
inotify_add_watch
(
priv
->
inotifyFD
,
configDir
,
priv
->
configDir
,
IN_CREATE
|
IN_CLOSE_WRITE
|
IN_DELETE
|
IN_MOVED_TO
|
IN_MOVED_FROM
)
<
0
)
{
virXenInotifyError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"adding watch on %s"
),
_
(
configDir
));
virReportSystemError
(
NULL
,
errno
,
_
(
"adding watch on %s"
),
priv
->
configDir
);
return
-
1
;
}
DEBUG0
(
"Building initial config cache"
);
if
(
useXenConfigCache
&&
if
(
priv
->
useXenConfigCache
&&
xenXMConfigCacheRefresh
(
conn
)
<
0
)
{
DEBUG
(
"Failed to enable XM config cache %s"
,
conn
->
err
.
message
);
return
-
1
;
...
...
@@ -464,10 +473,10 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
int
xenInotifyClose
(
virConnectPtr
conn
)
{
xenUnifiedPrivatePtr
priv
=
(
xenUnifiedPrivatePtr
)
conn
->
privateData
;
xenUnifiedPrivatePtr
priv
=
conn
->
privateData
;
if
(
configInfoList
)
xenUnifiedDomainInfoListFree
(
configInfoList
);
if
(
priv
->
configInfoList
)
xenUnifiedDomainInfoListFree
(
priv
->
configInfoList
);
if
(
priv
->
inotifyWatch
!=
-
1
)
virEventRemoveHandle
(
priv
->
inotifyWatch
);
...
...
src/xen_unified.h
浏览文件 @
e428a69e
...
...
@@ -156,6 +156,9 @@ struct _xenUnifiedPrivate {
/* A list of xenstore watches */
xenStoreWatchListPtr
xsWatchList
;
int
xsWatch
;
/* A list of active domain name/uuids */
xenUnifiedDomainInfoListPtr
activeDomainList
;
/* An list of callbacks */
virDomainEventCallbackListPtr
domainEventCallbacks
;
...
...
@@ -164,6 +167,10 @@ struct _xenUnifiedPrivate {
/* The inotify fd */
int
inotifyFD
;
int
inotifyWatch
;
const
char
*
configDir
;
int
useXenConfigCache
;
xenUnifiedDomainInfoListPtr
configInfoList
;
#endif
};
...
...
src/xs_internal.c
浏览文件 @
e428a69e
...
...
@@ -46,9 +46,6 @@
#endif
#ifndef PROXY
/* A list of active domain name/uuids */
static
xenUnifiedDomainInfoListPtr
activeDomainList
=
NULL
;
static
char
*
xenStoreDomainGetOSType
(
virDomainPtr
domain
);
struct
xenUnifiedDriver
xenStoreDriver
=
{
...
...
@@ -312,7 +309,7 @@ xenStoreOpen(virConnectPtr conn,
#ifndef PROXY
/* Init activeDomainList */
if
(
VIR_ALLOC
(
activeDomainList
)
<
0
)
{
if
(
VIR_ALLOC
(
priv
->
activeDomainList
)
<
0
)
{
virXenStoreError
(
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"failed to allocate activeDomainList"
));
return
-
1
;
...
...
@@ -390,8 +387,8 @@ xenStoreClose(virConnectPtr conn)
xenStoreWatchListFree
(
priv
->
xsWatchList
);
priv
->
xsWatchList
=
NULL
;
#ifndef PROXY
xenUnifiedDomainInfoListFree
(
activeDomainList
);
activeDomainList
=
NULL
;
xenUnifiedDomainInfoListFree
(
priv
->
activeDomainList
);
priv
->
activeDomainList
=
NULL
;
#endif
if
(
priv
->
xshandle
==
NULL
)
return
(
-
1
);
...
...
@@ -1190,7 +1187,7 @@ int xenStoreDomainIntroduced(virConnectPtr conn,
int
*
new_domids
;
int
nread
;
xenUnifiedPrivatePtr
priv
=
(
xenUnifiedPrivatePtr
)
opaque
;
xenUnifiedPrivatePtr
priv
=
opaque
;
retry:
new_domain_cnt
=
xenStoreNumOfDomains
(
conn
);
...
...
@@ -1209,8 +1206,8 @@ retry:
missing
=
0
;
for
(
i
=
0
;
i
<
new_domain_cnt
;
i
++
)
{
found
=
0
;
for
(
j
=
0
;
j
<
activeDomainList
->
count
;
j
++
)
{
if
(
activeDomainList
->
doms
[
j
]
->
id
==
new_domids
[
i
])
{
for
(
j
=
0
;
j
<
priv
->
activeDomainList
->
count
;
j
++
)
{
if
(
priv
->
activeDomainList
->
doms
[
j
]
->
id
==
new_domids
[
i
])
{
found
=
1
;
break
;
}
...
...
@@ -1238,7 +1235,7 @@ retry:
xenUnifiedDomainEventDispatch
(
priv
,
event
);
/* Add to the list */
xenUnifiedAddDomainInfo
(
activeDomainList
,
xenUnifiedAddDomainInfo
(
priv
->
activeDomainList
,
new_domids
[
i
],
name
,
uuid
);
VIR_FREE
(
name
);
...
...
@@ -1267,7 +1264,7 @@ int xenStoreDomainReleased(virConnectPtr conn,
xenUnifiedPrivatePtr
priv
=
(
xenUnifiedPrivatePtr
)
opaque
;
if
(
!
activeDomainList
->
count
)
return
0
;
if
(
!
priv
->
activeDomainList
->
count
)
return
0
;
retry:
new_domain_cnt
=
xenStoreNumOfDomains
(
conn
);
...
...
@@ -1285,10 +1282,10 @@ retry:
}
removed
=
0
;
for
(
j
=
0
;
j
<
activeDomainList
->
count
;
j
++
)
{
for
(
j
=
0
;
j
<
priv
->
activeDomainList
->
count
;
j
++
)
{
found
=
0
;
for
(
i
=
0
;
i
<
new_domain_cnt
;
i
++
)
{
if
(
activeDomainList
->
doms
[
j
]
->
id
==
new_domids
[
i
])
{
if
(
priv
->
activeDomainList
->
doms
[
j
]
->
id
==
new_domids
[
i
])
{
found
=
1
;
break
;
}
...
...
@@ -1297,18 +1294,18 @@ retry:
if
(
!
found
)
{
virDomainEventPtr
event
=
virDomainEventNew
(
-
1
,
activeDomainList
->
doms
[
j
]
->
name
,
activeDomainList
->
doms
[
j
]
->
uuid
,
priv
->
activeDomainList
->
doms
[
j
]
->
name
,
priv
->
activeDomainList
->
doms
[
j
]
->
uuid
,
VIR_DOMAIN_EVENT_STOPPED
,
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN
);
if
(
event
)
xenUnifiedDomainEventDispatch
(
priv
,
event
);
/* Remove from the list */
xenUnifiedRemoveDomainInfo
(
activeDomainList
,
activeDomainList
->
doms
[
j
]
->
id
,
activeDomainList
->
doms
[
j
]
->
name
,
activeDomainList
->
doms
[
j
]
->
uuid
);
xenUnifiedRemoveDomainInfo
(
priv
->
activeDomainList
,
priv
->
activeDomainList
->
doms
[
j
]
->
id
,
priv
->
activeDomainList
->
doms
[
j
]
->
name
,
priv
->
activeDomainList
->
doms
[
j
]
->
uuid
);
removed
=
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录