Re: [libvirt] About cgroup mechanism using in libvirt
by Alex Jia
Thanks for Daniel and Balbir.
In fact, libvirt just have implemented CPU scheduler controller for QEMU driver now,
the following controller is still not available for QEMU driver at present:
1. Memory controller
2. CPU set controller
3. CPU accounting controller
4. Devices controller
5. Freezer controller
6. Network class controller
and CPU scheduler and memory controller are available for LXC driver now, the above
2-6 haven't been implemented in LXC driver by libvirt.
Best Regards,
Alex
----- Original Message -----
From: "Daniel P. Berrange" <berrange(a)redhat.com>
To: "Balbir Singh" <balbir(a)linux.vnet.ibm.com>
Cc: "Alex Jia" <ajia(a)redhat.com>, libvir-list(a)redhat.com
Sent: Monday, June 14, 2010 6:20:33 AM GMT -05:00 US/Canada Eastern
Subject: Re: [libvirt] About cgroup mechanism using in libvirt
On Mon, Jun 14, 2010 at 03:28:42PM +0530, Balbir Singh wrote:
> On Mon, Jun 14, 2010 at 3:10 PM, Daniel P. Berrange <berrange(a)redhat.com> wrote:
> > On Sat, Jun 12, 2010 at 07:23:33AM -0400, Alex Jia wrote:
> >> Hey Daniel,
> >> The cgroup mechanism have been integrated into libvirt for LXC and QEMU driver,
> >> and the LXC driver uses all of cgroup controllers except for net_cls and cpuset,
> >> while the QEMU driver only uses the cpu and devices controllers at present.
> >>
> >> From the user point of view, user can use some virsh commands to control some
> >> guest resources:
> >> 1. Using 'virsh schedinfo' command to get/set CPU scheduler priority for a guest
> >
> > QEMU + LXC use the cpu controller 'cpu_shares' tunable
> >
> >> 2. Using 'virsh vcpuin' command to control guest vcpu affinity
> >
> > QEMU pins the process directly, doesn't use cgroups. LXC has't
> > implemented this yet
> >
> >> 3. Using 'virsh setmem' command to change memory allocation
> >> 4. Using 'virsh setmaxmem' command to change maximum memory limit
> >
> > QEMU uses balloon driver. LXC uses cgroups memory controller
> >
>
> Not sure if I understand this, but the balloon driver and memory
> cgroups are not mutually exclusive. One could use both together and I
> would certainly like to see additional commands to support cgroups.
> What happens if a guest (like freebsd) does not support ballooning?
> Are you suggesting we'll not need cgroups at all with QEMU?
No, I was merely describing the current usage. Making use of cgroups to
enforce the limit is certainly a desirable RFE for the future.
> >> 5. Using 'virsh setvcpus' command to change number of virtual CPUs
> >
> > QEMU uses cpu hotplug. LXC hasn't implemented this.
> >
> >> I just make sure the above 1 using CPU scheduler controller, maybe 4 using Memory
> >> controller? and maybe 5 using CPU set controller? I am not sure.
> >>
>
> I think we'll some notion of soft limits as well, not sure if they can
> be encapsulated using the current set. We need memory shares for
> example to encapsulate them.
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
14 years, 5 months
[libvirt] [PATCH] virsh: change printf() calls to vshPrint()
by Justin Clift
Trivial fix changing printf() calls to vshPrint() where the ctl
variable is available.
---
Haven't created a BZ for this yet, as I'm not sure it's important enough
to warrant pushing into anything other than git head.
Should a BZ be created anyway?
tools/virsh.c | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 07f2a1e..d8d2220 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1620,25 +1620,25 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nparams; i++){
switch (params[i].type) {
case VIR_DOMAIN_SCHED_FIELD_INT:
- printf("%-15s: %d\n", params[i].field, params[i].value.i);
+ vshPrint(ctl, "%-15s: %d\n", params[i].field, params[i].value.i);
break;
case VIR_DOMAIN_SCHED_FIELD_UINT:
- printf("%-15s: %u\n", params[i].field, params[i].value.ui);
+ vshPrint(ctl, "%-15s: %u\n", params[i].field, params[i].value.ui);
break;
case VIR_DOMAIN_SCHED_FIELD_LLONG:
- printf("%-15s: %lld\n", params[i].field, params[i].value.l);
+ vshPrint(ctl, "%-15s: %lld\n", params[i].field, params[i].value.l);
break;
case VIR_DOMAIN_SCHED_FIELD_ULLONG:
- printf("%-15s: %llu\n", params[i].field, params[i].value.ul);
+ vshPrint(ctl, "%-15s: %llu\n", params[i].field, params[i].value.ul);
break;
case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
- printf("%-15s: %f\n", params[i].field, params[i].value.d);
+ vshPrint(ctl, "%-15s: %f\n", params[i].field, params[i].value.d);
break;
case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
- printf("%-15s: %d\n", params[i].field, params[i].value.b);
+ vshPrint(ctl, "%-15s: %d\n", params[i].field, params[i].value.b);
break;
default:
- printf("not implemented scheduler parameter type\n");
+ vshPrint(ctl, "not implemented scheduler parameter type\n");
}
}
}
@@ -2654,7 +2654,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virDomainGetXMLDesc(dom, flags);
if (dump != NULL) {
- printf("%s", dump);
+ vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else {
ret = FALSE;
@@ -2700,7 +2700,7 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
xmlData = virConnectDomainXMLFromNative(ctl->conn, format, configData, flags);
if (xmlData != NULL) {
- printf("%s", xmlData);
+ vshPrint(ctl, "%s", xmlData);
VIR_FREE(xmlData);
} else {
ret = FALSE;
@@ -2745,7 +2745,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
configData = virConnectDomainXMLToNative(ctl->conn, format, xmlData, flags);
if (configData != NULL) {
- printf("%s", configData);
+ vshPrint(ctl, "%s", configData);
VIR_FREE(configData);
} else {
ret = FALSE;
@@ -3217,7 +3217,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virNetworkGetXMLDesc(network, 0);
if (dump != NULL) {
- printf("%s", dump);
+ vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else {
ret = FALSE;
@@ -3806,7 +3806,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virInterfaceGetXMLDesc(iface, flags);
if (dump != NULL) {
- printf("%s", dump);
+ vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else {
ret = FALSE;
@@ -4094,7 +4094,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virNWFilterGetXMLDesc(nwfilter, 0);
if (dump != NULL) {
- printf("%s", dump);
+ vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else {
ret = FALSE;
@@ -4566,7 +4566,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
return FALSE;
if (printXML) {
- printf("%s", xml);
+ vshPrint(ctl, "%s", xml);
VIR_FREE(xml);
} else {
pool = virStoragePoolCreateXML(ctl->conn, xml, 0);
@@ -4655,7 +4655,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
return FALSE;
if (printXML) {
- printf("%s", xml);
+ vshPrint(ctl, "%s", xml);
VIR_FREE(xml);
} else {
pool = virStoragePoolDefineXML(ctl->conn, xml, 0);
@@ -4859,7 +4859,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virStoragePoolGetXMLDesc(pool, 0);
if (dump != NULL) {
- printf("%s", dump);
+ vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else {
ret = FALSE;
@@ -5925,7 +5925,7 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virStorageVolGetXMLDesc(vol, 0);
if (dump != NULL) {
- printf("%s", dump);
+ vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else {
ret = FALSE;
@@ -6240,7 +6240,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
xml = virSecretGetXMLDesc(secret, 0);
if (xml == NULL)
goto cleanup;
- printf("%s", xml);
+ vshPrint(ctl, "%s", xml);
VIR_FREE(xml);
ret = TRUE;
@@ -6350,7 +6350,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, "%s", _("Failed to allocate memory"));
goto cleanup;
}
- printf("%s", base64);
+ vshPrint(ctl, "%s", base64);
memset(base64, 0, strlen(base64));
VIR_FREE(base64);
ret = TRUE;
@@ -8681,7 +8681,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!xml)
goto cleanup;
- printf("%s", xml);
+ vshPrint(ctl, "%s", xml);
ret = TRUE;
--
1.7.0.1
14 years, 5 months
[libvirt] [PATCH] nwfilter: use match target on incoming traffic
by Stefan Berger
The following patch enables the iptables match target to be used by
default for incoming traffic. So far it has only be used for outgoing
traffic.
Signed-off-by: Stefan Berger
---
src/nwfilter/nwfilter_ebiptables_driver.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -1488,18 +1488,25 @@ iptablesCreateRuleInstance(virNWFilterDe
char chainPrefix[2];
int needState = 1;
bool maySkipICMP, inout = false;
+ const char *matchState;
if ((rule->tt == VIR_NWFILTER_RULE_DIRECTION_IN) ||
(rule->tt == VIR_NWFILTER_RULE_DIRECTION_INOUT)) {
directionIn = 1;
- needState = 0;
inout = (rule->tt == VIR_NWFILTER_RULE_DIRECTION_INOUT);
+ if (inout)
+ needState = 0;
}
chainPrefix[0] = 'F';
maySkipICMP = directionIn || inout;
+ if (needState)
+ matchState = directionIn ? MATCH_STATE_IN : MATCH_STATE_OUT;
+ else
+ matchState = NULL;
+
chainPrefix[1] = CHAINPREFIX_HOST_IN_TEMP;
rc = _iptablesCreateRuleInstance(directionIn,
chainPrefix,
@@ -1508,8 +1515,7 @@ iptablesCreateRuleInstance(virNWFilterDe
ifname,
vars,
res,
- needState ? MATCH_STATE_OUT
- : NULL,
+ matchState,
"RETURN",
isIPv6,
maySkipICMP);
@@ -1518,6 +1524,10 @@ iptablesCreateRuleInstance(virNWFilterDe
maySkipICMP = !directionIn || inout;
+ if (needState)
+ matchState = directionIn ? MATCH_STATE_OUT : MATCH_STATE_IN;
+ else
+ matchState = NULL;
chainPrefix[1] = CHAINPREFIX_HOST_OUT_TEMP;
rc = _iptablesCreateRuleInstance(!directionIn,
@@ -1527,8 +1537,7 @@ iptablesCreateRuleInstance(virNWFilterDe
ifname,
vars,
res,
- needState ? MATCH_STATE_IN
- : NULL,
+ matchState,
"ACCEPT",
isIPv6,
maySkipICMP);
14 years, 5 months
[libvirt] [PATCHv3 2/2] virsh: improve help text for vol query commands
by Justin Clift
Improves the help text for vol-path, vol-name, and vol-key, which
previously referred to volume UUIDs.
Addresses BZ # 598365.
---
tools/virsh.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 7d8ae0e..8c9ae83 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -6011,13 +6011,13 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
* "vol-name" command
*/
static const vshCmdInfo info_vol_name[] = {
- {"help", N_("convert a vol UUID to vol name")},
+ {"help", N_("returns the volume name for a given volume key or path")},
{"desc", ""},
{NULL, NULL}
};
static const vshCmdOptDef opts_vol_name[] = {
- {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("vol key or path")},
+ {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("volume key or path")},
{NULL, 0, 0, NULL}
};
@@ -6098,7 +6098,7 @@ static const vshCmdInfo info_vol_key[] = {
static const vshCmdOptDef opts_vol_key[] = {
{"pool", VSH_OT_STRING, 0, N_("pool name or uuid")},
- {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("vol uuid")},
+ {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("volume name or path")},
{NULL, 0, 0, NULL}
};
@@ -6124,14 +6124,14 @@ cmdVolKey(vshControl *ctl, const vshCmd *cmd)
* "vol-path" command
*/
static const vshCmdInfo info_vol_path[] = {
- {"help", N_("convert a vol UUID to vol path")},
+ {"help", N_("returns the volume path for a given volume name or key")},
{"desc", ""},
{NULL, NULL}
};
static const vshCmdOptDef opts_vol_path[] = {
{"pool", VSH_OT_STRING, 0, N_("pool name or uuid")},
- {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("vol name or key")},
+ {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("volume name or key")},
{NULL, 0, 0, NULL}
};
--
1.7.0.1
14 years, 5 months
[libvirt] [PATCH] esx: Update case insensitive .vmx tests
by Matthias Bolte
Commit b9efc7dc3b97ef667ab99cee884b8485ebcb2f91 made virFileHasSuffix
case insensitive. Honor this in the tests by switching vmdk to VMDK.
---
tests/vmx2xmldata/vmx2xml-case-insensitive-1.vmx | 2 +-
tests/vmx2xmldata/vmx2xml-case-insensitive-1.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/vmx2xmldata/vmx2xml-case-insensitive-1.vmx b/tests/vmx2xmldata/vmx2xml-case-insensitive-1.vmx
index 3626c5e..bd36cf8 100644
--- a/tests/vmx2xmldata/vmx2xml-case-insensitive-1.vmx
+++ b/tests/vmx2xmldata/vmx2xml-case-insensitive-1.vmx
@@ -18,7 +18,7 @@ SCSI0.SHAREDBUS = "NONE"
SCSI0.VIRTUALDEV = "LSILOGIC"
MEMSIZE = "1024"
SCSI0:0.PRESENT = "TRUE"
-SCSI0:0.FILENAME = "FEDORA11.vmdk"
+SCSI0:0.FILENAME = "FEDORA11.VMDK"
SCSI0:0.DEVICETYPE = "SCSI-HARDDISK"
IDE0:0.PRESENT = "TRUE"
IDE0:0.CLIENTDEVICE = "TRUE"
diff --git a/tests/vmx2xmldata/vmx2xml-case-insensitive-1.xml b/tests/vmx2xmldata/vmx2xml-case-insensitive-1.xml
index 0be570f..3131bb2 100644
--- a/tests/vmx2xmldata/vmx2xml-case-insensitive-1.xml
+++ b/tests/vmx2xmldata/vmx2xml-case-insensitive-1.xml
@@ -14,7 +14,7 @@
<devices>
<disk type='file' device='disk'>
<driver name='LSILOGIC'/>
- <source file='[datastore] directory/FEDORA11.vmdk'/>
+ <source file='[datastore] directory/FEDORA11.VMDK'/>
<target dev='sda' bus='scsi'/>
</disk>
<interface type='bridge'>
--
1.7.0.4
14 years, 5 months
[libvirt] [PATCH] esx: Accept 'disk' as harddisk device type in .vmx files
by Matthias Bolte
---
src/esx/esx_vmx.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index 5cadb5a..675318f 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -1542,16 +1542,20 @@ esxVMX_ParseDisk(esxVI_Context *ctx, virConfPtr conf, int device, int bus,
if (virFileHasSuffix(fileName, ".vmdk")) {
if (deviceType != NULL) {
if (bus == VIR_DOMAIN_DISK_BUS_SCSI &&
- STRCASENEQ(deviceType, "scsi-hardDisk")) {
+ STRCASENEQ(deviceType, "scsi-hardDisk") &&
+ STRCASENEQ(deviceType, "disk")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'scsi-hardDisk' "
- "but found '%s'"), deviceType_name, deviceType);
+ "or 'disk' but found '%s'"), deviceType_name,
+ deviceType);
goto cleanup;
} else if (bus == VIR_DOMAIN_DISK_BUS_IDE &&
- STRCASENEQ(deviceType, "ata-hardDisk")) {
+ STRCASENEQ(deviceType, "ata-hardDisk") &&
+ STRCASENEQ(deviceType, "disk")) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'ata-hardDisk' "
- "but found '%s'"), deviceType_name, deviceType);
+ "or 'disk' but found '%s'"), deviceType_name,
+ deviceType);
goto cleanup;
}
}
--
1.7.0.4
14 years, 5 months
[libvirt] [PATCH v2] nwfilter: fix loadable module support
by Stefan Berger
Following Daniel Berrange's suggestion of introducing another driver
interface, I now wrote the below patch where the nwfilter driver
registers the functions to instantiate and teardown the nwfilters with a
function in conf/domain_nwfilter.c called virDomainConfNWFilterRegister.
Previous helper functions that were called from qemu_driver.c and
qemu_conf.c were move into conf/domain_nwfilter.h with slight renaming
done for consistency. Those functions now call the function expored by
domain_nwfilter.c, which in turn call the functions of the new driver
interface, if available.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/Makefile.am | 3 -
src/conf/domain_nwfilter.c | 51 ++++++++++++++++++++++++
src/conf/domain_nwfilter.h | 68
+++++++++++++++++++++++++++++++++
src/libvirt_private.syms | 5 ++
src/nwfilter/nwfilter_driver.c | 22 ++++++++++
src/nwfilter/nwfilter_gentech_driver.h | 17 --------
src/qemu/qemu_conf.c | 11 ++---
src/qemu/qemu_driver.c | 2
8 files changed, 155 insertions(+), 24 deletions(-)
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.h
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
@@ -67,21 +67,4 @@ void virNWFilterDomainFWUpdateCB(void *p
const char *name ATTRIBUTE_UNUSED,
void *data);
-
-/* tear down an interface's filter before tearing down the interface */
-static inline void
-virNWFilterTearNWFilter(virDomainNetDefPtr net) {
- if ((net->filter) && (net->ifname))
- virNWFilterTeardownFilter(net);
-}
-
-
-static inline void
-virNWFilterTearVMNWFilters(virDomainObjPtr vm) {
- int i;
-
- for (i = 0; i < vm->def->nnets; i++)
- virNWFilterTearNWFilter(vm->def->nets[i]);
-}
-
#endif
Index: libvirt-acl/src/qemu/qemu_conf.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_conf.c
+++ libvirt-acl/src/qemu/qemu_conf.c
@@ -54,7 +54,7 @@
#include "network.h"
#include "macvtap.h"
#include "cpu/cpu.h"
-#include "nwfilter/nwfilter_gentech_driver.h"
+#include "domain_nwfilter.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -1514,9 +1514,10 @@ int qemudExtractVersion(struct qemud_dri
/**
* qemudPhysIfaceConnect:
* @conn: pointer to virConnect object
+ * @driver: pointer to the qemud_driver
* @net: pointer to he VM's interface description with direct device type
- * @linkdev: The name of the physical interface to link the macvtap to
- * @brmode: The mode to put the macvtap device into
+ * @qemuCmdFlags: flags for qemu
+ * @vmuuid: The UUID of the VM (needed by 802.1Qbh)
*
* Returns a filedescriptor on success or -1 in case of error.
*/
@@ -1555,7 +1556,7 @@ qemudPhysIfaceConnect(virConnectPtr conn
if (rc >= 0) {
if ((net->filter) && (net->ifname)) {
- err = virNWFilterInstantiateFilter(conn, net);
+ err = virNWFilterInstantiateNWFilter(conn, net);
if (err) {
close(rc);
rc = -1;
@@ -1688,7 +1689,7 @@ qemudNetworkIfaceConnect(virConnectPtr c
if (tapfd >= 0) {
if ((net->filter) && (net->ifname)) {
- err = virNWFilterInstantiateFilter(conn, net);
+ err = virNWFilterInstantiateNWFilter(conn, net);
if (err) {
close(tapfd);
tapfd = -1;
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -81,7 +81,7 @@
#include "xml.h"
#include "cpu/cpu.h"
#include "macvtap.h"
-#include "nwfilter/nwfilter_gentech_driver.h"
+#include "domain_nwfilter.h"
#include "hooks.h"
#include "storage_file.h"
Index: libvirt-acl/src/Makefile.am
===================================================================
--- libvirt-acl.orig/src/Makefile.am
+++ libvirt-acl/src/Makefile.am
@@ -97,7 +97,8 @@ DRIVER_SOURCES = \
# Domain driver generic impl APIs
DOMAIN_CONF_SOURCES = \
conf/capabilities.c conf/capabilities.h \
- conf/domain_conf.c conf/domain_conf.h
+ conf/domain_conf.c conf/domain_conf.h \
+ conf/domain_nwfilter.c conf/domain_nwfilter.h
DOMAIN_EVENT_SOURCES = \
conf/domain_event.c conf/domain_event.h
Index: libvirt-acl/src/conf/domain_nwfilter.h
===================================================================
--- /dev/null
+++ libvirt-acl/src/conf/domain_nwfilter.h
@@ -0,0 +1,68 @@
+/*
+ * domain_nwfilter.h:
+ *
+ * Copyright (C) 2010 IBM Corporation
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Stefan Berger <stefanb(a)us.ibm.com>
+ */
+#ifndef DOMAIN_NWFILTER_H
+# define DOMAIN_NWFILTER_H
+
+typedef int (*virDomainConfInstantiateNWFilter)(virConnectPtr conn,
+ virDomainNetDefPtr net);
+typedef void (*virDomainConfTeardownNWFilter)(virDomainNetDefPtr net);
+
+typedef struct {
+ virDomainConfInstantiateNWFilter instantiateFilter;
+ virDomainConfTeardownNWFilter teardownFilter;
+} virDomainConfNWFilterDriver;
+typedef virDomainConfNWFilterDriver *virDomainConfNWFilterDriverPtr;
+
+void virDomainConfNWFilterRegister(virDomainConfNWFilterDriverPtr driver);
+
+int virDomainConfNWFilterInstantiate(virConnectPtr conn,
+ virDomainNetDefPtr net);
+void virDomainConfNWFilterTeardown(virDomainNetDefPtr net);
+
+
+/* helper functions */
+
+static inline
+int virNWFilterInstantiateNWFilter(virConnectPtr conn,
+ const virDomainNetDefPtr net)
+{
+ return virDomainConfNWFilterInstantiate(conn, net);
+}
+
+/* tear down an interface's filter before tearing down the interface */
+static inline void
+virNWFilterTearNWFilter(virDomainNetDefPtr net) {
+ if ((net->filter) && (net->ifname))
+ virDomainConfNWFilterTeardown(net);
+}
+
+
+static inline void
+virNWFilterTearVMNWFilters(virDomainObjPtr vm) {
+ int i;
+
+ for (i = 0; i < vm->def->nnets; i++)
+ virNWFilterTearNWFilter(vm->def->nets[i]);
+}
+
+#endif /* DOMAIN_NWFILTER_H */
Index: libvirt-acl/src/conf/domain_nwfilter.c
===================================================================
--- /dev/null
+++ libvirt-acl/src/conf/domain_nwfilter.c
@@ -0,0 +1,51 @@
+/*
+ * domain_nwfilter.c:
+ *
+ * Copyright (C) 2010 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Stefan Berger <stefanb(a)us.ibm.com>
+ */
+
+#include <config.h>
+
+#include "internal.h"
+
+#include "datatypes.h"
+#include "domain_conf.h"
+#include "domain_nwfilter.h"
+
+static virDomainConfNWFilterDriverPtr nwfilterDriver;
+
+void
+virDomainConfNWFilterRegister(virDomainConfNWFilterDriverPtr driver) {
+ nwfilterDriver = driver;
+}
+
+int
+virDomainConfNWFilterInstantiate(virConnectPtr conn,
+ virDomainNetDefPtr net) {
+ if (nwfilterDriver)
+ return nwfilterDriver->instantiateFilter(conn, net);
+ /* driver module not available -- don't indicate failure */
+ return 0;
+}
+
+void
+virDomainConfNWFilterTeardown(virDomainNetDefPtr net) {
+ if (nwfilterDriver)
+ nwfilterDriver->teardownFilter(net);
+}
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -264,6 +264,11 @@ virDomainEventDispatchDefaultFunc;
virDomainEventDispatch;
virDomainEventQueueDispatch;
+# domain_nwfilter.h
+virDomainConfNWFilterRegister;
+virDomainConfNWFilterInstantiate;
+virDomainConfNWFilterTeardown;
+
# ebtables.h
ebtablesAddForwardAllowIn;
Index: libvirt-acl/src/nwfilter/nwfilter_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_driver.c
@@ -33,6 +33,7 @@
#include "datatypes.h"
#include "memory.h"
#include "domain_conf.h"
+#include "domain_nwfilter.h"
#include "nwfilter_driver.h"
#include "nwfilter_gentech_driver.h"
@@ -410,6 +411,19 @@ cleanup:
}
+static int
+nwfilterInstantiateFilter(virConnectPtr conn,
+ virDomainNetDefPtr net) {
+ return virNWFilterInstantiateFilter(conn, net);
+}
+
+
+static void
+nwfilterTeardownFilter(virDomainNetDefPtr net) {
+ virNWFilterTeardownFilter(net);
+}
+
+
static virNWFilterDriver nwfilterDriver = {
.name = "nwfilter",
.open = nwfilterOpen,
@@ -432,8 +446,16 @@ static virStateDriver stateDriver = {
.active = nwfilterDriverActive,
};
+
+static virDomainConfNWFilterDriver domainNWFilterDriver = {
+ .instantiateFilter = nwfilterInstantiateFilter,
+ .teardownFilter = nwfilterTeardownFilter,
+};
+
+
int nwfilterRegister(void) {
virRegisterNWFilterDriver(&nwfilterDriver);
virRegisterStateDriver(&stateDriver);
+ virDomainConfNWFilterRegister(&domainNWFilterDriver);
return 0;
}
14 years, 5 months
[libvirt] [PATCH 1/2] virsh: add new --details option to pool-list
by Justin Clift
This patch adds a new --details option to the virsh pool-list
command, making its output more useful to people who use virsh
for significant lengths of time.
---
Output from the new option (hopefully this doesn't wrap):
virsh # pool-list
Name State Autostart
-----------------------------------------
default active yes
image_dir active yes
virsh # pool-list --all
Name State Autostart
-----------------------------------------
default active yes
image_dir active yes
tmp inactive no
virsh # pool-list --details
Name State Autostart Persistent Capacity Allocation Available
--------------------------------------------------------------------------------------
default running yes yes 1.79 TB 1.47 TB 326.02 GB
image_dir running yes yes 1.79 TB 1.47 TB 326.02 GB
virsh # pool-list --all --details
Name State Autostart Persistent Capacity Allocation Available
--------------------------------------------------------------------------------------
default running yes yes 1.79 TB 1.47 TB 326.02 GB
image_dir running yes yes 1.79 TB 1.47 TB 326.02 GB
tmp inactive no yes - - -
virsh #
Much more practical than running pool-info individually on each pool.
tools/virsh.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++------
tools/virsh.pod | 6 ++-
2 files changed, 119 insertions(+), 17 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index d8d2220..afa84e6 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -4882,14 +4882,17 @@ static const vshCmdInfo info_pool_list[] = {
static const vshCmdOptDef opts_pool_list[] = {
{"inactive", VSH_OT_BOOL, 0, N_("list inactive pools")},
{"all", VSH_OT_BOOL, 0, N_("list inactive & active pools")},
+ {"details", VSH_OT_BOOL, 0, N_("display extended details for pools")},
{NULL, 0, 0, NULL}
};
static int
cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
+ virStoragePoolInfo info;
int inactive = vshCommandOptBool(cmd, "inactive");
int all = vshCommandOptBool(cmd, "all");
+ int details = vshCommandOptBool(cmd, "details");
int active = !inactive || all ? 1 : 0;
int maxactive = 0, maxinactive = 0, i;
char **activeNames = NULL, **inactiveNames = NULL;
@@ -4937,36 +4940,114 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
qsort(&inactiveNames[0], maxinactive, sizeof(char*), namesorter);
}
}
- vshPrintExtra(ctl, "%-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart"));
- vshPrintExtra(ctl, "-----------------------------------------\n");
+
+ /* Display the appropriate heading */
+ if (details) {
+ vshPrintExtra(ctl, "%-20s %-10s %-10s %-11s %-9s %-11s %-10s\n",
+ _("Name"), _("State"), _("Autostart"), _("Persistent"),
+ _("Capacity"), _("Allocation"), _("Available"));
+ vshPrintExtra(ctl,
+ "--------------------------------------------------------------------------------------\n");
+ } else {
+ vshPrintExtra(ctl, "%-20s %-10s %-10s\n", _("Name"), _("State"),
+ _("Autostart"));
+ vshPrintExtra(ctl, "-----------------------------------------\n");
+ }
for (i = 0; i < maxactive; i++) {
- virStoragePoolPtr pool = virStoragePoolLookupByName(ctl->conn, activeNames[i]);
- const char *autostartStr;
- int autostart = 0;
+ const char *autostartStr, *persistentStr, *stateStr = NULL;
+ int autostart = 0, persistent = 0;
/* this kind of work with pools is not atomic operation */
+ virStoragePoolPtr pool = virStoragePoolLookupByName(ctl->conn, activeNames[i]);
if (!pool) {
VIR_FREE(activeNames[i]);
continue;
}
+ /* Retrieve the pool autostart status */
if (virStoragePoolGetAutostart(pool, &autostart) < 0)
autostartStr = _("no autostart");
else
autostartStr = autostart ? _("yes") : _("no");
- vshPrint(ctl, "%-20s %-10s %-10s\n",
- virStoragePoolGetName(pool),
- _("active"),
- autostartStr);
+ /* If requested, collect the extended information for this pool */
+ if (details) {
+ if (virStoragePoolGetInfo(pool, &info) != 0) {
+ vshError(ctl, "%s", _("Could not retrieve pool information"));
+ VIR_FREE(activeNames[i]);
+ continue;
+ }
+
+ /* Decide which state string to display */
+ switch (info.state) {
+ case VIR_STORAGE_POOL_INACTIVE:
+ stateStr = _("inactive");
+ break;
+ case VIR_STORAGE_POOL_BUILDING:
+ stateStr = _("building");
+ break;
+ case VIR_STORAGE_POOL_RUNNING:
+ stateStr = _("running");
+ break;
+ case VIR_STORAGE_POOL_DEGRADED:
+ stateStr = _("degraded");
+ break;
+ case VIR_STORAGE_POOL_INACCESSIBLE:
+ stateStr = _("inaccessible");
+ break;
+ }
+
+ /* Check if the pool is persistent or not */
+ persistent = virStoragePoolIsPersistent(pool);
+ vshDebug(ctl, 5, "Persistent flag value: %d\n", persistent);
+ if (persistent < 0)
+ persistentStr = _("unknown");
+ else
+ persistentStr = persistent ? _("yes") : _("no");
+
+ /* Display all information for this pool */
+ vshPrint(ctl, "%-20s %-10s %-10s %-11s",
+ virStoragePoolGetName(pool),
+ stateStr,
+ autostartStr,
+ persistentStr);
+
+ /* Display the capacity related quantities */
+ if (info.state == VIR_STORAGE_POOL_RUNNING ||
+ info.state == VIR_STORAGE_POOL_DEGRADED) {
+ double val;
+ const char *unit;
+ virBuffer infoBufStr = VIR_BUFFER_INITIALIZER;
+
+ val = prettyCapacity(info.capacity, &unit);
+ virBufferVSprintf(&infoBufStr, "%.2lf %s", val, unit);
+ vshPrint(ctl, " %-9s", virBufferContentAndReset(&infoBufStr));
+
+ val = prettyCapacity(info.allocation, &unit);
+ virBufferVSprintf(&infoBufStr, "%.2lf %s", val, unit);
+ vshPrint(ctl, " %-11s", virBufferContentAndReset(&infoBufStr));
+
+ val = prettyCapacity(info.available, &unit);
+ virBufferVSprintf(&infoBufStr, "%.2lf %s", val, unit);
+ vshPrint(ctl, " %-10s\n", virBufferContentAndReset(&infoBufStr));
+ } else
+ vshPrint(ctl, " %-9s %-11s %-10s\n", "-", "-", "-");
+ } else {
+ /* Display basic information pool information */
+ vshPrint(ctl, "%-20s %-10s %-10s\n",
+ virStoragePoolGetName(pool),
+ _("active"),
+ autostartStr);
+ }
+
virStoragePoolFree(pool);
VIR_FREE(activeNames[i]);
}
for (i = 0; i < maxinactive; i++) {
virStoragePoolPtr pool = virStoragePoolLookupByName(ctl->conn, inactiveNames[i]);
- const char *autostartStr;
- int autostart = 0;
+ const char *autostartStr, *persistentStr;
+ int autostart = 0, persistent = 0;
/* this kind of work with pools is not atomic operation */
if (!pool) {
@@ -4979,10 +5060,29 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
else
autostartStr = autostart ? _("yes") : _("no");
- vshPrint(ctl, "%-20s %-10s %-10s\n",
- inactiveNames[i],
- _("inactive"),
- autostartStr);
+ if (details) {
+ /* Check if the pool is persistent or not */
+ persistent = virStoragePoolIsPersistent(pool);
+ vshDebug(ctl, 5, "Persistent flag value: %d\n", persistent);
+ if (persistent < 0)
+ persistentStr = _("unknown");
+ else
+ persistentStr = persistent ? _("yes") : _("no");
+
+ /* Display detailed pool information */
+ vshPrint(ctl, "%-20s %-10s %-10s %-11s %-9s %-11s %-10s\n",
+ inactiveNames[i],
+ _("inactive"),
+ autostartStr,
+ persistentStr,
+ "-", "-", "-");
+ } else {
+ /* Display basic pool information */
+ vshPrint(ctl, "%-20s %-10s %-10s\n",
+ inactiveNames[i],
+ _("inactive"),
+ autostartStr);
+ }
virStoragePoolFree(pool);
VIR_FREE(inactiveNames[i]);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index b1917ee..cec07e3 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -732,11 +732,13 @@ variables, and defaults to C<vi>.
Returns basic information about the I<pool> object.
-=item B<pool-list> optional I<--inactive> I<--all>
+=item B<pool-list> optional I<--inactive> I<--all> I<--details>
List pool objects known to libvirt. By default, only pools in use by
active domains are listed; I<--inactive> lists just the inactive
-pools, and I<--all> lists all pools.
+pools, and I<--all> lists all pools. The I<--details> option instructs
+virsh to additionally display pool persistence and capacity related
+information where available.
=item B<pool-name> I<uuid>
--
1.7.0.1
14 years, 5 months
[libvirt] [PATCH 0/2] virsh: add new --details option flag to pool-list and vol-list
by Justin Clift
Hi all,
The following two patches add a new "--details" option flag to the virsh
pool-list and vol-list commands. (with virsh.pod entries too)
The reason for adding them, is that when using virsh for any length of
time it's gets painful having to use pool-info and vol-info on (70+)
individual volumes, just to get basic info. :/
This shows the required info much more easily. :)
+ The first patch is for the pool-list command, and was pretty
straightforward.
+ The second patch is for the vol-list command, and was a pain due to
adding support for multi-line output when long path and name strings
were involved. (if there be dragons, they'd be here ;> )
Decent example of the output from each command are in their email comments.
Open for suggestions and better ideas of course. :)
Regards and best wishes,
Justin Clift
--
Salasaga - Open Source eLearning IDE
http://www.salasaga.org
14 years, 5 months
[libvirt] IP Address of a domain
by IKI-サガル バルウェ
Hello,
I would like to obtain the IP Address of a domain using the libvirt API.
I see that the XMLDesc gives the MAC address, but not the IP Address.
I found out that the "vncdisplay" command option from "virsh" command line
tool provides the IP Address and port number. How would I obtain this info
using libvirt API.
Please help.
I am using libvirt version libvirtd (libvirt) 0.6.3.
Thanks and Regards
Sagar Barve
14 years, 5 months