Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
45707d56
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,发现更多精彩内容 >>
提交
45707d56
编写于
4月 01, 2009
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add treeview to node device listing in virsh
上级
4d3d0039
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
3 deletion
+123
-3
ChangeLog
ChangeLog
+6
-0
src/remote_internal.c
src/remote_internal.c
+1
-0
src/virsh.c
src/virsh.c
+116
-3
未找到文件。
ChangeLog
浏览文件 @
45707d56
Wed Apr 1 10:50:22 BST 2009 Daniel P. Berrange <berrange@redhat.com>
Add a tree view of node devices
* src/remote_internal.c: Fix memory leak in virNodeDeviceGetParent() impl
* src/virsh.c: Add --tree flag to nodedev-list command
Tue Mar 31 17:40:00 CEST 2009 Chris Lalancette <clalance@redhat.com>
* src/lxc_driver.c, src/openvz_driver.c, src/qemu_driver.c,
src/remote_internal.c, src/test.c, src/uml_driver.c, src/xen_unified.c,
...
...
src/remote_internal.c
浏览文件 @
45707d56
...
...
@@ -4821,6 +4821,7 @@ static char *remoteNodeDeviceGetParent(virNodeDevicePtr dev)
/* Caller frees. */
rv
=
ret
.
parent
?
*
ret
.
parent
:
NULL
;
VIR_FREE
(
ret
.
parent
);
done:
remoteDriverUnlock
(
priv
);
...
...
src/virsh.c
浏览文件 @
45707d56
...
...
@@ -4391,16 +4391,96 @@ static const vshCmdInfo info_node_list_devices[] = {
};
static
const
vshCmdOptDef
opts_node_list_devices
[]
=
{
{
"tree"
,
VSH_OT_BOOL
,
0
,
gettext_noop
(
"list devices in a tree"
)},
{
"cap"
,
VSH_OT_STRING
,
VSH_OFLAG_NONE
,
gettext_noop
(
"capability name"
)},
{
NULL
,
0
,
0
,
NULL
}
};
#define MAX_DEPTH 100
#define INDENT_SIZE 4
#define INDENT_BUFLEN ((MAX_DEPTH * INDENT_SIZE) + 1)
static
void
cmdNodeListDevicesPrint
(
vshControl
*
ctl
,
char
**
devices
,
char
**
parents
,
int
num_devices
,
int
devid
,
int
lastdev
,
unsigned
int
depth
,
unsigned
int
indentIdx
,
char
*
indentBuf
)
{
int
i
;
int
nextlastdev
=
-
1
;
/* Prepare indent for this device, but not if at root */
if
(
depth
&&
depth
<
MAX_DEPTH
)
{
indentBuf
[
indentIdx
]
=
'+'
;
indentBuf
[
indentIdx
+
1
]
=
'-'
;
}
/* Print this device */
vshPrint
(
ctl
,
indentBuf
);
vshPrint
(
ctl
,
"%s
\n
"
,
devices
[
devid
]);
/* Update indent to show '|' or ' ' for child devices */
if
(
depth
&&
depth
<
MAX_DEPTH
)
{
if
(
devid
==
lastdev
)
indentBuf
[
indentIdx
]
=
' '
;
else
indentBuf
[
indentIdx
]
=
'|'
;
indentBuf
[
indentIdx
+
1
]
=
' '
;
indentIdx
+=
2
;
}
/* Determine the index of the last child device */
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
if
(
parents
[
i
]
&&
STREQ
(
parents
[
i
],
devices
[
devid
]))
{
nextlastdev
=
i
;
}
}
/* If there is a child device, then print another blank line */
if
(
nextlastdev
!=
-
1
)
{
vshPrint
(
ctl
,
indentBuf
);
vshPrint
(
ctl
,
" |
\n
"
);
}
/* Finally print all children */
if
(
depth
<
MAX_DEPTH
)
indentBuf
[
indentIdx
]
=
' '
;
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
if
(
depth
<
MAX_DEPTH
)
{
indentBuf
[
indentIdx
]
=
' '
;
indentBuf
[
indentIdx
+
1
]
=
' '
;
}
if
(
parents
[
i
]
&&
STREQ
(
parents
[
i
],
devices
[
devid
]))
cmdNodeListDevicesPrint
(
ctl
,
devices
,
parents
,
num_devices
,
i
,
nextlastdev
,
depth
+
1
,
indentIdx
+
2
,
indentBuf
);
if
(
depth
<
MAX_DEPTH
)
indentBuf
[
indentIdx
]
=
'\0'
;
}
/* If there was no child device, and we're the last in
* a list of devices, then print another blank line */
if
(
nextlastdev
==
-
1
&&
devid
==
lastdev
)
{
vshPrint
(
ctl
,
indentBuf
);
vshPrint
(
ctl
,
"
\n
"
);
}
}
static
int
cmdNodeListDevices
(
vshControl
*
ctl
,
const
vshCmd
*
cmd
ATTRIBUTE_UNUSED
)
{
char
*
cap
;
char
**
devices
;
int
found
,
num_devices
,
i
;
int
tree
=
vshCommandOptBool
(
cmd
,
"tree"
);
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
,
TRUE
))
return
FALSE
;
...
...
@@ -4426,9 +4506,42 @@ cmdNodeListDevices (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return
FALSE
;
}
qsort
(
&
devices
[
0
],
num_devices
,
sizeof
(
char
*
),
namesorter
);
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
vshPrint
(
ctl
,
"%s
\n
"
,
devices
[
i
]);
free
(
devices
[
i
]);
if
(
tree
)
{
char
indentBuf
[
INDENT_BUFLEN
];
char
**
parents
=
vshMalloc
(
ctl
,
sizeof
(
char
*
)
*
num_devices
);
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
virNodeDevicePtr
dev
=
virNodeDeviceLookupByName
(
ctl
->
conn
,
devices
[
i
]);
if
(
dev
&&
STRNEQ
(
devices
[
i
],
"computer"
))
{
const
char
*
parent
=
virNodeDeviceGetParent
(
dev
);
parents
[
i
]
=
parent
?
strdup
(
parent
)
:
NULL
;
}
else
{
parents
[
i
]
=
NULL
;
}
virNodeDeviceFree
(
dev
);
}
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
memset
(
indentBuf
,
'\0'
,
sizeof
indentBuf
);
if
(
parents
[
i
]
==
NULL
)
cmdNodeListDevicesPrint
(
ctl
,
devices
,
parents
,
num_devices
,
i
,
i
,
0
,
0
,
indentBuf
);
}
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
free
(
devices
[
i
]);
free
(
parents
[
i
]);
}
free
(
parents
);
}
else
{
for
(
i
=
0
;
i
<
num_devices
;
i
++
)
{
vshPrint
(
ctl
,
"%s
\n
"
,
devices
[
i
]);
free
(
devices
[
i
]);
}
}
free
(
devices
);
return
TRUE
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录