提交 c2c47b58 编写于 作者: M Michal Privoznik

src: Use virDomainNetFindByName

Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 784742c7
......@@ -4961,7 +4961,7 @@ libxlDomainInterfaceStats(virDomainPtr dom,
{
libxlDriverPrivatePtr driver = dom->conn->privateData;
virDomainObjPtr vm;
size_t i;
virDomainNetDefPtr net = NULL;
int ret = -1;
if (!(vm = libxlDomObjFromDomain(dom)))
......@@ -4979,20 +4979,16 @@ libxlDomainInterfaceStats(virDomainPtr dom,
goto endjob;
}
/* Check the path is one of the domain's network interfaces. */
for (i = 0; i < vm->def->nnets; i++) {
if (vm->def->nets[i]->ifname &&
STREQ(vm->def->nets[i]->ifname, path)) {
ret = 0;
break;
}
}
if (ret == 0)
ret = virNetDevTapInterfaceStats(path, stats);
else
if (!(net = virDomainNetFindByName(vm->def, path))) {
virReportError(VIR_ERR_INVALID_ARG,
_("'%s' is not a known interface"), path);
goto endjob;
}
if (virNetDevTapInterfaceStats(path, stats) < 0)
goto endjob;
ret = 0;
endjob:
libxlDomainObjEndJob(driver, vm);
......
......@@ -2853,9 +2853,9 @@ lxcDomainInterfaceStats(virDomainPtr dom,
virDomainInterfaceStatsPtr stats)
{
virDomainObjPtr vm;
size_t i;
int ret = -1;
virLXCDriverPtr driver = dom->conn->privateData;
virDomainNetDefPtr net = NULL;
if (!(vm = lxcDomObjFromDomain(dom)))
goto cleanup;
......@@ -2872,20 +2872,16 @@ lxcDomainInterfaceStats(virDomainPtr dom,
goto endjob;
}
/* Check the path is one of the domain's network interfaces. */
for (i = 0; i < vm->def->nnets; i++) {
if (vm->def->nets[i]->ifname &&
STREQ(vm->def->nets[i]->ifname, path)) {
ret = 0;
break;
}
}
if (ret == 0)
ret = virNetDevTapInterfaceStats(path, stats);
else
if (!(net = virDomainNetFindByName(vm->def, path))) {
virReportError(VIR_ERR_INVALID_ARG,
_("Invalid path, '%s' is not a known interface"), path);
goto endjob;
}
if (virNetDevTapInterfaceStats(path, stats) < 0)
goto endjob;
ret = 0;
endjob:
virLXCDomainObjEndJob(driver, vm);
......
......@@ -1985,7 +1985,7 @@ openvzDomainInterfaceStats(virDomainPtr dom,
{
struct openvz_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
size_t i;
virDomainNetDefPtr net = NULL;
int ret = -1;
openvzDriverLock(driver);
......@@ -2006,20 +2006,16 @@ openvzDomainInterfaceStats(virDomainPtr dom,
goto cleanup;
}
/* Check the path is one of the domain's network interfaces. */
for (i = 0; i < vm->def->nnets; i++) {
if (vm->def->nets[i]->ifname &&
STREQ(vm->def->nets[i]->ifname, path)) {
ret = 0;
break;
}
}
if (ret == 0)
ret = virNetDevTapInterfaceStats(path, stats);
else
if (!(net = virDomainNetFindByName(vm->def, path))) {
virReportError(VIR_ERR_INVALID_ARG,
_("invalid path, '%s' is not a known interface"), path);
goto cleanup;
}
if (virNetDevTapInterfaceStats(path, stats) < 0)
goto cleanup;
ret = 0;
cleanup:
if (vm)
......
......@@ -11016,7 +11016,6 @@ qemuDomainInterfaceStats(virDomainPtr dom,
{
virDomainObjPtr vm;
virDomainNetDefPtr net = NULL;
size_t i;
int ret = -1;
if (!(vm = qemuDomObjFromDomain(dom)))
......@@ -11031,15 +11030,7 @@ qemuDomainInterfaceStats(virDomainPtr dom,
goto cleanup;
}
/* Check the path is one of the domain's network interfaces. */
for (i = 0; i < vm->def->nnets; i++) {
if (STREQ_NULLABLE(vm->def->nets[i]->ifname, path)) {
net = vm->def->nets[i];
break;
}
}
if (!net) {
if (!(net = virDomainNetFindByName(vm->def, path))) {
virReportError(VIR_ERR_INVALID_ARG,
_("invalid path, '%s' is not a known interface"), path);
goto cleanup;
......
......@@ -593,25 +593,16 @@ testDomainGenerateIfname(virDomainDefPtr domdef)
{
int maxif = 1024;
int ifctr;
size_t i;
for (ifctr = 0; ifctr < maxif; ++ifctr) {
virDomainNetDefPtr net = NULL;
char *ifname;
int found = 0;
if (virAsprintf(&ifname, "testnet%d", ifctr) < 0)
return NULL;
/* Generate network interface names */
for (i = 0; i < domdef->nnets; i++) {
if (domdef->nets[i]->ifname &&
STREQ(domdef->nets[i]->ifname, ifname)) {
found = 1;
break;
}
}
if (!found)
if (!(net = virDomainNetFindByName(domdef, ifname)))
return ifname;
VIR_FREE(ifname);
}
......@@ -3176,8 +3167,9 @@ static int testDomainInterfaceStats(virDomainPtr domain,
virDomainObjPtr privdom;
struct timeval tv;
unsigned long long statbase;
size_t i;
int found = 0, ret = -1;
virDomainNetDefPtr net = NULL;
int ret = -1;
if (!(privdom = testDomObjFromDomain(domain)))
return -1;
......@@ -3188,15 +3180,7 @@ static int testDomainInterfaceStats(virDomainPtr domain,
goto error;
}
for (i = 0; i < privdom->def->nnets; i++) {
if (privdom->def->nets[i]->ifname &&
STREQ(privdom->def->nets[i]->ifname, path)) {
found = 1;
break;
}
}
if (!found) {
if (!(net = virDomainNetFindByName(privdom->def, path))) {
virReportError(VIR_ERR_INVALID_ARG,
_("invalid path, '%s' is not a known interface"), path);
goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册