Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
42accf1b
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,发现更多精彩内容 >>
提交
42accf1b
编写于
2月 14, 2012
作者:
O
Osier Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virsh: Use vshFindDisk and vshPrepareDiskXML in cmdDetachDisk
The first use of the two new helper functions.
上级
025998eb
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
10 addition
and
55 deletion
+10
-55
tools/virsh.c
tools/virsh.c
+10
-55
未找到文件。
tools/virsh.c
浏览文件 @
42accf1b
...
...
@@ -14391,7 +14391,6 @@ typedef enum {
* @path: Fully-qualified path or target of disk device.
* @type: Either VSH_FIND_DISK_NORMAL or VSH_FIND_DISK_CHANGEABLE.
*/
ATTRIBUTE_UNUSED
static xmlNodePtr
vshFindDisk(const char *doc,
const char *path,
...
...
@@ -14489,7 +14488,6 @@ typedef enum {
* for changeable disk. Returns the processed XML as string on
* success, or NULL on failure. Caller must free the result.
*/
ATTRIBUTE_UNUSED
static char *
vshPrepareDiskXML(xmlNodePtr disk_node,
const char *source,
...
...
@@ -14615,18 +14613,14 @@ static const vshCmdOptDef opts_detach_disk[] = {
static bool
cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj=NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr cur = NULL;
xmlBufferPtr xml_buf = NULL;
char *disk_xml = NULL;
virDomainPtr dom = NULL;
const char *target = NULL;
char *doc;
int i = 0, diff_tgt;
int ret;
bool functionReturn = false;
unsigned int flags;
xmlNodePtr disk_node = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
...
...
@@ -14641,60 +14635,22 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get disk information"));
goto cleanup;
}
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) {
vshError(ctl, "%s", _("Failed to get disk information"));
goto cleanup;
}
/* search target */
for (; i < obj->nodesetval->nodeNr; i++) {
cur = obj->nodesetval->nodeTab[i]->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "target")) {
char *tmp_tgt = virXMLPropString(cur, "dev");
diff_tgt = STREQ(tmp_tgt, target);
VIR_FREE(tmp_tgt);
if (diff_tgt) {
goto hit;
}
}
cur = cur->next;
}
}
vshError(ctl, _("No found disk whose target is %s"), target);
goto cleanup;
hit:
xml_buf = xmlBufferCreate();
if (!xml_buf) {
vshError(ctl, "%s", _("Failed to allocate memory"));
if (!(disk_node = vshFindDisk(doc, target, VSH_FIND_DISK_NORMAL)))
goto cleanup;
}
if (
xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0) {
vshError(ctl, "%s", _("Failed to create XML"));
if (
!(disk_xml = vshPrepareDiskXML(disk_node, NULL, NULL,
VSH_PREPARE_DISK_XML_NONE)))
goto cleanup;
}
if (vshCommandOptBool(cmd, "persistent")) {
flags = VIR_DOMAIN_AFFECT_CONFIG;
if (virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
ret = virDomainDetachDeviceFlags(dom,
(char *)xmlBufferContent(xml_buf)
,
disk_xml
,
flags);
} else {
ret = virDomainDetachDevice(dom,
(char *)xmlBufferContent(xml_buf)
);
ret = virDomainDetachDevice(dom,
disk_xml
);
}
if (ret != 0) {
...
...
@@ -14705,10 +14661,9 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
}
cleanup:
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml);
xmlBufferFree(xml_buf);
xmlFreeNode(disk_node);
VIR_FREE(disk_xml);
VIR_FREE(doc);
if (dom)
virDomainFree(dom);
return functionReturn;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录