[libvirt] [go-xml PATCH] Add support for network port XML schema
by Daniel P. Berrangé
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
domain.go | 1 +
network.go | 1 +
network_port.go | 200 ++++++++++++++++++++++++++++++++++++++++++++++++
xml_test.go | 3 +
4 files changed, 205 insertions(+)
create mode 100644 network_port.go
diff --git a/domain.go b/domain.go
index 0757048..a7cbdcf 100644
--- a/domain.go
+++ b/domain.go
@@ -440,6 +440,7 @@ type DomainInterfaceSourceNetwork struct {
Network string `xml:"network,attr,omitempty"`
PortGroup string `xml:"portgroup,attr,omitempty"`
Bridge string `xml:"bridge,attr,omitempty"`
+ PortID string `xml:"portid,attr,omitempty"`
}
type DomainInterfaceSourceBridge struct {
diff --git a/network.go b/network.go
index d4faf46..61c1af0 100644
--- a/network.go
+++ b/network.go
@@ -282,6 +282,7 @@ type NetworkBandwidthParams struct {
}
type NetworkBandwidth struct {
+ ClassID uint `xml:"classID,attr,omitempty"`
Inbound *NetworkBandwidthParams `xml:"inbound"`
Outbound *NetworkBandwidthParams `xml:"outbound"`
}
diff --git a/network_port.go b/network_port.go
new file mode 100644
index 0000000..3cbc7fb
--- /dev/null
+++ b/network_port.go
@@ -0,0 +1,200 @@
+/*
+ * This file is part of the libvirt-go-xml project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import (
+ "encoding/xml"
+ "fmt"
+)
+
+type NetworkPort struct {
+ XMLName xml.Name `xml:"networkport"`
+ UUID string `xml:"uuid,omitempty"`
+ Owner *NetworkPortOwner `xml:"owner",`
+ MAC *NetworkPortMAC `xml:"mac"`
+ Group string `xml:"group,omitempty"`
+ Bandwidth *NetworkBandwidth `xml:"bandwidth"`
+ VirtualPort *NetworkVirtualPort `xml:"virtualport"`
+ RXFilters *NetworkPortRXFilters `xml:"rxfilters"`
+ Plug *NetworkPortPlug `xml:"plug"`
+}
+
+type NetworkPortOwner struct {
+ UUID string `xml:"uuid,omitempty"`
+ Name string `xml:"name,omitempty"`
+}
+
+type NetworkPortMAC struct {
+ Address string `xml:"address,attr"`
+}
+
+type NetworkPortRXFilters struct {
+ TrustGuest string `xml:"trustGuest,attr"`
+}
+
+type NetworkPortPlug struct {
+ Bridge *NetworkPortPlugBridge `xml:"-"`
+ Network *NetworkPortPlugNetwork `xml:"-"`
+ Direct *NetworkPortPlugDirect `xml:"-"`
+ HostDevPCI *NetworkPortPlugHostDevPCI `xml:"-"`
+}
+
+type NetworkPortPlugBridge struct {
+ Bridge string `xml:"bridge,attr"`
+ MacTableManager string `xml:"macTableManager,attr,omitempty"`
+}
+
+type NetworkPortPlugNetwork struct {
+ Bridge string `xml:"bridge,attr"`
+ MacTableManager string `xml:"macTableManager,attr,omitempty"`
+}
+
+type NetworkPortPlugDirect struct {
+ Dev string `xml:"dev,attr"`
+ Mode string `xml:"mode,attr"`
+}
+
+type NetworkPortPlugHostDevPCI struct {
+ Managed string `xml:"managed,attr,omitempty"`
+ Driver *NetworkPortPlugHostDevPCIDriver `xml:"driver"`
+ Address *NetworkPortPlugHostDevPCIAddress `xml:"address"`
+}
+
+type NetworkPortPlugHostDevPCIDriver struct {
+ Name string `xml:"name,attr"`
+}
+
+type NetworkPortPlugHostDevPCIAddress struct {
+ Domain *uint `xml:"domain,attr"`
+ Bus *uint `xml:"bus,attr"`
+ Slot *uint `xml:"slot,attr"`
+ Function *uint `xml:"function,attr"`
+}
+
+func (a *NetworkPortPlugHostDevPCIAddress) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ marshalUintAttr(&start, "domain", a.Domain, "0x%04x")
+ marshalUintAttr(&start, "bus", a.Bus, "0x%02x")
+ marshalUintAttr(&start, "slot", a.Slot, "0x%02x")
+ marshalUintAttr(&start, "function", a.Function, "0x%x")
+ e.EncodeToken(start)
+ e.EncodeToken(start.End())
+ return nil
+}
+
+func (a *NetworkPortPlugHostDevPCIAddress) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+ for _, attr := range start.Attr {
+ if attr.Name.Local == "domain" {
+ if err := unmarshalUintAttr(attr.Value, &a.Domain, 0); err != nil {
+ return err
+ }
+ } else if attr.Name.Local == "bus" {
+ if err := unmarshalUintAttr(attr.Value, &a.Bus, 0); err != nil {
+ return err
+ }
+ } else if attr.Name.Local == "slot" {
+ if err := unmarshalUintAttr(attr.Value, &a.Slot, 0); err != nil {
+ return err
+ }
+ } else if attr.Name.Local == "function" {
+ if err := unmarshalUintAttr(attr.Value, &a.Function, 0); err != nil {
+ return err
+ }
+ }
+ }
+ d.Skip()
+ return nil
+}
+
+func (p *NetworkPortPlug) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ start.Name.Local = "plug"
+ if p.Bridge != nil {
+ start.Attr = append(start.Attr, xml.Attr{
+ xml.Name{Local: "type"}, "bridge",
+ })
+ return e.EncodeElement(p.Bridge, start)
+ } else if p.Network != nil {
+ start.Attr = append(start.Attr, xml.Attr{
+ xml.Name{Local: "type"}, "network",
+ })
+ return e.EncodeElement(p.Network, start)
+ } else if p.Direct != nil {
+ start.Attr = append(start.Attr, xml.Attr{
+ xml.Name{Local: "type"}, "direct",
+ })
+ return e.EncodeElement(p.Direct, start)
+ } else if p.HostDevPCI != nil {
+ start.Attr = append(start.Attr, xml.Attr{
+ xml.Name{Local: "type"}, "hostdev-pci",
+ })
+ return e.EncodeElement(p.HostDevPCI, start)
+ }
+ return nil
+}
+
+func (p *NetworkPortPlug) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+ typ, ok := getAttr(start.Attr, "type")
+ if !ok {
+ return fmt.Errorf("Missing type attribute on plug")
+ } else if typ == "bridge" {
+ var pb NetworkPortPlugBridge
+ if err := d.DecodeElement(&pb, &start); err != nil {
+ return err
+ }
+ p.Bridge = &pb
+ } else if typ == "network" {
+ var pn NetworkPortPlugNetwork
+ if err := d.DecodeElement(&pn, &start); err != nil {
+ return err
+ }
+ p.Network = &pn
+ } else if typ == "direct" {
+ var pd NetworkPortPlugDirect
+ if err := d.DecodeElement(&pd, &start); err != nil {
+ return err
+ }
+ p.Direct = &pd
+ } else if typ == "hostdev-pci" {
+ var ph NetworkPortPlugHostDevPCI
+ if err := d.DecodeElement(&ph, &start); err != nil {
+ return err
+ }
+ p.HostDevPCI = &ph
+ }
+ d.Skip()
+ return nil
+}
+
+func (s *NetworkPort) Unmarshal(doc string) error {
+ return xml.Unmarshal([]byte(doc), s)
+}
+
+func (s *NetworkPort) Marshal() (string, error) {
+ doc, err := xml.MarshalIndent(s, "", " ")
+ if err != nil {
+ return "", err
+ }
+ return string(doc), nil
+}
diff --git a/xml_test.go b/xml_test.go
index 320c248..7e3876a 100644
--- a/xml_test.go
+++ b/xml_test.go
@@ -83,6 +83,7 @@ var xmldirs = []string{
"testdata/libvirt/tests/storagevolxml2xmlin",
"testdata/libvirt/tests/storagevolxml2xmlout",
"testdata/libvirt/tests/vircaps2xmldata",
+ "testdata/libvirt/tests/virnetworkportxml2xmldata",
"testdata/libvirt/tests/virstorageutildata",
"testdata/libvirt/tests/vmx2xmldata",
"testdata/libvirt/tests/xlconfigdata",
@@ -306,6 +307,8 @@ func testRoundTrip(t *testing.T, xml string, filename string) {
doc = &Domain{}
} else if strings.HasPrefix(xml, "<capabilities") {
doc = &Caps{}
+ } else if strings.HasPrefix(xml, "<networkport") {
+ doc = &NetworkPort{}
} else if strings.HasPrefix(xml, "<network") {
doc = &Network{}
} else if strings.HasPrefix(xml, "<secret") {
--
2.21.0
5 years, 5 months
[libvirt] ANNOUNCE: virt-manager 2.2.0 released
by Cole Robinson
I'm happy to announce the release of virt-manager 2.2.0!
virt-manager is a desktop application for managing KVM, Xen, and LXC
virtualization via libvirt.
The release can be downloaded from:
http://virt-manager.org/download/
This release includes:
- libvirt XML viewing and editing UI for new and existing domain,
pools, volumes, networks
- virt-install: libosinfo --unattended support (Fabiano Fidêncio, Cole
Robinson)
- Improve CPU model security defaults (Pavel Hrdina)
- virt-install: new --install option. Ex: virt-install --install
fedora29
- virt-install: new --install kernel=,initrd=
- virt-install: --disk, --memory, --name defaults from libosinfo
(Fabiano Fidêncio, Cole Robinson)
- virt-install: add device suboption aliases which consistently match
libvirt XML naming
- virt-xml: new --start, --no-define options (Marc Hartmayer)
- virt-install: Add driver_queues argument to --controller (Vasudeva
Kamath)
- RISC-V support (Andrea Bolognani)
- Device default improvements for non-x86 KVM (Andrea Bolognani)
- Redesigned 'New Network' wizard
- libguestfs inspection improvements (Pino Toscano)
- virt-install: Add support for xenbus controller (Jim Fehlig)
- cli: Add --disk wwn=,rawio= (Athina Plaskasoviti)
- cli: Add --memballoon autodeflate=,stats.period= (Athina
Plaskasoviti)
- cli: Add --iothreads (Athina Plaskasoviti)
- cli: Add --numatune memory.placement (Athina Plaskasoviti)
- cli: Add --launchSecurity option (Erik Skultety)
- cli: Fill in --memorybacking options
- cli: --smartcard: support database= and certificate[0-9]*=
- cli: --sysinfo: Add chasis suboptions
- cli: --metadata: add genid= and genid_enable=
- cli: --vcpus: add vcpus.vcpu[0-9]* config
- cli: fill in all common char source options for --serial, --parellel,
--console, --channel, --smartcard, --rng, --redirdev
Thanks to everyone who has contributed to this release through testing,
bug reporting, submitting patches, and otherwise sending in feedback!
Thanks,
Cole
5 years, 5 months
[libvirt] [PATCH v6 00/23] network: refactor to decouple virt drivers from network driver
by Daniel P. Berrangé
An update to
v1: https://www.redhat.com/archives/libvir-list/2018-December/msg00681.html
v2: https://www.redhat.com/archives/libvir-list/2019-February/msg01581.html
v3: https://www.redhat.com/archives/libvir-list/2019-March/msg01259.html
v4: https://www.redhat.com/archives/libvir-list/2019-April/msg01186.html
v5: https://www.redhat.com/archives/libvir-list/2019-May/msg00358.html
Currently the network driver registers a set of callbacks with the virt
driver in order to handle allocating/releasing network ports associated
with guest NICs.
This series introduces a virNetworkPortPtr object and associated XML
that describes a network port. The virt drivers now call public APIs
associated with this new object to create/delete ports for guest NICs.
Changed in v6:
- Fixed mistakes in RNG schema & example XML
- Fix docs typos
Changed in v5:
- Separately track ports with type=network vs type=bridge to deal with
fallout after reverting patches which merged them
- Add RNG schema and XML format docs
- Change to use classID attr on <bandwidth> isntead of
of separate <class id="xx"/> element
- Drop obsolete driver deps from RPM spec
- Other misc bug fixes found during testing
Changed in v4:
- Merged the ACKd patches which didn't depend on other un-acked
parts
- Improve bandwidth error messages
- Ensure we set floor sum to zero when starting network
- Misc fixes for previous review comments
NB, I have not added missing docs for the new XML doc format
yet. This is work in progress.
Changed in v3:
- Remove unused API symbol
- Fix dist of test data files
Changed in v2:
- Fix many bugs related to upgrades with running VMs
- Convert over bandwidth controls to the new APIs
- Handle reconnecting VIFs to bridges during startup
- Much much more that I can't remember
Daniel P. Berrangé (23):
conf: allow bandwidth parsing / formatting to include class ID
conf: introduce virNetworkPortDefPtr struct and XML support
network: make networkLogAllocation independent of domain conf
conf: add APIs to convert virDomainNetDef to virNetworkPortDef
network: convert networkAllocateActualDevice to virNetworkPortDef
network: convert networkNotifyActualDevice to virNetworkPortDef
network: convert networkReleaseActualDevice to virNetworkPortDef
network: convert hook script to take a network port XML
network: remove the virDomainNetBandwidthChangeAllowed callback
network: introduce networkAllocatePort
network: introduce networkNotifyPort
network: introduce networkReleasePort
network: introduce networkUpdatePortBandwidth
network: add public APIs for network port object
access: add permissions for network port objects
remote: add support for new network port APIs
virsh: add support for network port APIs
conf: support recording ports against virNetworkObjPtr
network: add implementation of network port APIs
lxc, libxl: notify network driver of NICs during reconnect
lxc, libxl: save domain status after reconnect
conf: record a portid against the domain conf
conf: switch over to use network port APIs for virt drivers
docs/docs.html.in | 1 +
docs/formatdomain.html.in | 8 +
docs/formatnetworkport.html.in | 212 +++
docs/hooks.html.in | 24 +-
docs/schemas/domaincommon.rng | 5 +
docs/schemas/networkcommon.rng | 5 +
docs/schemas/networkport.rng | 154 +++
include/libvirt/libvirt-network.h | 122 ++
include/libvirt/virterror.h | 3 +
libvirt.spec.in | 1 +
src/access/genpolkit.pl | 2 +-
src/access/viraccessdriver.h | 6 +
src/access/viraccessdrivernop.c | 11 +
src/access/viraccessdriverpolkit.c | 26 +
src/access/viraccessdriverstack.c | 25 +
src/access/viraccessmanager.c | 16 +
src/access/viraccessmanager.h | 6 +
src/access/viraccessperm.c | 6 +
src/access/viraccessperm.h | 44 +
src/conf/Makefile.inc.am | 2 +
src/conf/domain_conf.c | 531 +++++++-
src/conf/domain_conf.h | 49 +-
src/conf/netdev_bandwidth_conf.c | 30 +-
src/conf/netdev_bandwidth_conf.h | 2 +
src/conf/network_conf.c | 8 +-
src/conf/virnetworkobj.c | 303 +++++
src/conf/virnetworkobj.h | 34 +
src/conf/virnetworkportdef.c | 508 +++++++
src/conf/virnetworkportdef.h | 113 ++
src/datatypes.c | 60 +
src/datatypes.h | 41 +
src/driver-network.h | 41 +
src/libvirt-network.c | 444 +++++++
src/libvirt_private.syms | 23 +-
src/libvirt_public.syms | 15 +
src/libxl/libxl_driver.c | 33 +
src/lxc/lxc_process.c | 35 +
src/network/bridge_driver.c | 1182 ++++++++++-------
src/qemu/qemu_driver.c | 8 +-
src/remote/remote_daemon_dispatch.c | 73 +
src/remote/remote_driver.c | 69 +
src/remote/remote_protocol.x | 124 +-
src/remote_protocol-structs | 69 +
src/rpc/gendispatch.pl | 18 +-
src/util/virerror.c | 9 +
src/util/virhook.c | 4 +-
src/util/virhook.h | 4 +-
tests/Makefile.am | 7 +
.../net-virtio-network-portgroup.xml | 6 +-
tests/virnetdevbandwidthtest.c | 1 +
.../plug-bridge-mactbl.xml | 9 +
.../virnetworkportxml2xmldata/plug-bridge.xml | 15 +
.../virnetworkportxml2xmldata/plug-direct.xml | 12 +
.../plug-hostdev-pci.xml | 12 +
.../plug-network.xml | 15 +
tests/virnetworkportxml2xmldata/plug-none.xml | 8 +
tests/virnetworkportxml2xmltest.c | 104 ++
tests/virschematest.c | 1 +
tools/virsh-completer.c | 50 +
tools/virsh-completer.h | 4 +
tools/virsh-network.c | 399 +++++-
tools/virsh-network.h | 5 +
62 files changed, 4499 insertions(+), 658 deletions(-)
create mode 100644 docs/formatnetworkport.html.in
create mode 100644 docs/schemas/networkport.rng
create mode 100644 src/conf/virnetworkportdef.c
create mode 100644 src/conf/virnetworkportdef.h
create mode 100644 tests/virnetworkportxml2xmldata/plug-bridge-mactbl.xml
create mode 100644 tests/virnetworkportxml2xmldata/plug-bridge.xml
create mode 100644 tests/virnetworkportxml2xmldata/plug-direct.xml
create mode 100644 tests/virnetworkportxml2xmldata/plug-hostdev-pci.xml
create mode 100644 tests/virnetworkportxml2xmldata/plug-network.xml
create mode 100644 tests/virnetworkportxml2xmldata/plug-none.xml
create mode 100644 tests/virnetworkportxml2xmltest.c
--
2.21.0
5 years, 5 months
Re: [libvirt] [PATCH] storage: escape ipv6 for ceph mon hosts to librados
by Yi Li
> >Hosts for rbd are ceph monitor daemons. These have fixed IP addresses,
> >so they are often referenced by IP rather than hostname for
> >convenience, or to avoid relying on DNS. Using IPv4 addresses as the
> >host name works already, but IPv6 addresses require rbd-specific
>
> If you include the escaping in the XML, does it currently work?
> <host name='[2205::192:168:205:141]' port='6789'/>
Yes, It works.
>
>
> >escaping because the colon is used as an option separator in the
> >string passed to librados.
> >
> >Escape these colons, and enclose the IPv6 address in square brackets
> >so it is distinguished from the port, which is currently mandatory.
> >
> >Signed-off-by: Yi Li <yili(a)winhong.com>
> >---
> > docs/schemas/storagepool.rng | 5 ++++-
> > src/storage/storage_backend_rbd.c | 13 ++++++++++---
> > tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml | 13 +++++++++++++
> > tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml | 16 ++++++++++++++++
> > tests/storagepoolxml2xmltest.c | 1 +
> > 5 files changed, 44 insertions(+), 4 deletions(-)
> > create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml
> > create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml
> >
> >diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
> >index f8c968e..3056563 100644
> >--- a/src/storage/storage_backend_rbd.c
> >+++ b/src/storage/storage_backend_rbd.c
> >@@ -268,9 +268,16 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
> > source->hosts[i].name);
> > } else if (source->hosts[i].name != NULL &&
> > source->hosts[i].port) {
> >- virBufferAsprintf(&mon_host, "%s:%d,",
> >- source->hosts[i].name,
> >- source->hosts[i].port);
> >+ /* assume host containing : is ipv6 */
> >+ if (strchr(source->hosts[i].name, ':')) {
>
> if (virSocketAddrNumericFamily(listenAddress) == AF_INET6)
>
> By using this helper function, we won't try to escape an address that is
> already escaped.
>
> Also, instead of copying the whole virBuffer call twice, it would be
> nicer to assign the format to a temporary variable like we do in qemuMigrationDstPrepare
>
> Jano
Good point. I'd sending a v2.
>
>
> >+ virBufferAsprintf(&mon_host, "[%s]:%d,",
> >+ source->hosts[i].name,
> >+ source->hosts[i].port);
> >+ } else {
> >+ virBufferAsprintf(&mon_host, "%s:%d,",
> >+ source->hosts[i].name,
> >+ source->hosts[i].port);
> >+ }
> > } else {
> > virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> > _("received malformed monitor, check the XML definition"));
On Sun, Apr 28, 2019 at 1:10 PM winhong-yili <yili(a)winhong.com> wrote:
>
> >Hosts for rbd are ceph monitor daemons. These have fixed IP addresses,
> >so they are often referenced by IP rather than hostname for
> >convenience, or to avoid relying on DNS. Using IPv4 addresses as the
> >host name works already, but IPv6 addresses require rbd-specific
>
> If you include the escaping in the XML, does it currently work?
> <host name='[2205::192:168:205:141]' port='6789'/>
>
> >escaping because the colon is used as an option separator in the
> >string passed to librados.
> >
> >Escape these colons, and enclose the IPv6 address in square brackets
> >so it is distinguished from the port, which is currently mandatory.
> >
> >Signed-off-by: Yi Li <yili(a)winhong.com>
> >---
> > docs/schemas/storagepool.rng | 5 ++++-
> > src/storage/storage_backend_rbd.c | 13 ++++++++++---
> > tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml | 13 +++++++++++++
> > tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml | 16 ++++++++++++++++
> > tests/storagepoolxml2xmltest.c | 1 +
> > 5 files changed, 44 insertions(+), 4 deletions(-)
> > create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-ipv6.xml
> > create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-ipv6.xml
> >
> >diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
> >index f8c968e..3056563 100644
> >--- a/src/storage/storage_backend_rbd.c
> >+++ b/src/storage/storage_backend_rbd.c
> >@@ -268,9 +268,16 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
> > source->hosts[i].name);
> > } else if (source->hosts[i].name != NULL &&
> > source->hosts[i].port) {
> >- virBufferAsprintf(&mon_host, "%s:%d,",
> >- source->hosts[i].name,
> >- source->hosts[i].port);
> >+ /* assume host containing : is ipv6 */
> >+ if (strchr(source->hosts[i].name, ':')) {
>
> if (virSocketAddrNumericFamily(listenAddress) == AF_INET6)
>
> By using this helper function, we won't try to escape an address that is
> already escaped.
>
> Also, instead of copying the whole virBuffer call twice, it would be
> nicer to assign the format to a temporary variable like we do in qemuMigrationDstPrepare
>
> Jano
>
> >+ virBufferAsprintf(&mon_host, "[%s]:%d,",
> >+ source->hosts[i].name,
> >+ source->hosts[i].port);
> >+ } else {
> >+ virBufferAsprintf(&mon_host, "%s:%d,",
> >+ source->hosts[i].name,
> >+ source->hosts[i].port);
> >+ }
> > } else {
> > virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> > _("received malformed monitor, check the XML definition"));
5 years, 5 months
[libvirt] [PATCH v3 00/15] implement cgroups v2 support
by Pavel Hrdina
In cgroups v2 there is no devices controller, eBPF should be used
instead.
Changes in v3:
- removed workaround for kernel bug [1]
- added documentation how to get the eBPF program
Changes in v2:
- fixed build on bsd and older kernels without cgroup BPF
- cgroup bpf devices code moved to separate file
Documentation for eBPF:
<http://man7.org/linux/man-pages/man2/bpf.2.html>
<https://www.kernel.org/doc/Documentation/networking/filter.txt>
<https://docs.cilium.io/en/v1.3/bpf/>
[1] <https://bugzilla.redhat.com/show_bug.cgi?id=1656432>
Pavel Hrdina (15):
util: introduce virbpf helpers
vircgroup: introduce virCgroupV2DevicesAvailable
vircgroup: introduce virCgroupV2DevicesAttachProg
vircgroup: introduce virCgroupV2DevicesDetectProg
vircgroup: introduce virCgroupV2DevicesCreateProg
vircgroup: introduce virCgroupV2DevicesPrepareProg
vircgroup: introduce virCgroupV2DevicesRemoveProg
vircgroup: introduce virCgroupV2DeviceGetPerms
vircgroup: introduce virCgroupV2DevicesGetKey
vircgroup: introduce virCgroupV2AllowDevice
vircgroup: introduce virCgroupV2DenyDevice
vircgroup: introduce virCgroupV2AllowAllDevices
vircgroup: introduce virCgroupV2DenyAllDevices
vircgroup: workaround devices in hybrid mode
vircgroupmock: mock virCgroupV2DevicesAvailable
configure.ac | 6 +
include/libvirt/virterror.h | 2 +
src/Makefile.am | 2 +
src/libvirt_private.syms | 26 ++
src/util/Makefile.inc.am | 4 +
src/util/virbpf.c | 438 +++++++++++++++++++
src/util/virbpf.h | 259 ++++++++++++
src/util/vircgroup.c | 3 +-
src/util/vircgroupbackend.h | 3 +-
src/util/vircgrouppriv.h | 10 +
src/util/vircgroupv1.c | 9 +-
src/util/vircgroupv2.c | 117 +++++-
src/util/vircgroupv2devices.c | 670 ++++++++++++++++++++++++++++++
src/util/vircgroupv2devices.h | 57 +++
src/util/virerror.c | 2 +
tests/vircgroupdata/hybrid.parsed | 2 +-
tests/vircgroupmock.c | 7 +
tests/vircgrouptest.c | 4 +-
18 files changed, 1613 insertions(+), 8 deletions(-)
create mode 100644 src/util/virbpf.c
create mode 100644 src/util/virbpf.h
create mode 100644 src/util/vircgroupv2devices.c
create mode 100644 src/util/vircgroupv2devices.h
--
2.20.1
5 years, 5 months
[libvirt] [PATCH RFC 0/1] mdevctl: further config for vfio-ap
by Cornelia Huck
This patch adds a very rough implementation of additional config data
for mdev devices. The idea is to make it possible to specify some
type-specific key=value pairs in the config file for an mdev device.
If a device is started automatically, the device is stopped and restarted
after applying the config.
The code has still some problems, like not doing a lot of error handling
and being ugly in general; but most importantly, I can't really test it,
as I don't have the needed hardware. Feedback welcome; would be good to
know if the direction is sensible in general.
Also available at
https://github.com/cohuck/mdevctl conf-data
Cornelia Huck (1):
allow to specify additional config data
mdevctl.libexec | 25 ++++++++++++++++++++++
mdevctl.sbin | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 80 insertions(+), 1 deletion(-)
--
2.20.1
5 years, 5 months
[libvirt] [perl PATCH] Add support for virNetworkPortPtr and its APIs
by Daniel P. Berrangé
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
Changes | 2 +-
lib/Sys/Virt.pm | 1 +
lib/Sys/Virt.xs | 179 ++++++++++++++++++++++++++++++++++++
lib/Sys/Virt/Error.pm | 12 +++
lib/Sys/Virt/Network.pm | 39 ++++++++
lib/Sys/Virt/NetworkPort.pm | 177 +++++++++++++++++++++++++++++++++++
t/030-api-coverage.t | 2 +-
typemap | 14 +++
8 files changed, 424 insertions(+), 2 deletions(-)
create mode 100644 lib/Sys/Virt/NetworkPort.pm
diff --git a/Changes b/Changes
index 0fb13d5..e13c3b3 100644
--- a/Changes
+++ b/Changes
@@ -2,7 +2,7 @@ Revision history for perl module Sys::Virt
5.5.0 2019-07-00
- - XXX
+ - Add support for virNetworkPortPtr object and its APIs
5.4.0 2019-06-12
diff --git a/lib/Sys/Virt.pm b/lib/Sys/Virt.pm
index b6553aa..2e01fd6 100644
--- a/lib/Sys/Virt.pm
+++ b/lib/Sys/Virt.pm
@@ -69,6 +69,7 @@ use warnings;
use Sys::Virt::Error;
use Sys::Virt::Domain;
use Sys::Virt::Network;
+use Sys::Virt::NetworkPort;
use Sys::Virt::StoragePool;
use Sys::Virt::StorageVol;
use Sys::Virt::NodeDevice;
diff --git a/lib/Sys/Virt.xs b/lib/Sys/Virt.xs
index 9586be8..ccd5ba0 100644
--- a/lib/Sys/Virt.xs
+++ b/lib/Sys/Virt.xs
@@ -6828,6 +6828,27 @@ PREINIT:
free(leases);
+void
+list_all_ports(net, flags=0)
+ virNetworkPtr net;
+ unsigned int flags;
+ PREINIT:
+ virNetworkPortPtr *ports;
+ int i, nport;
+ SV *portrv;
+ PPCODE:
+ if ((nport = virNetworkListAllPorts(net, &ports, flags)) < 0)
+ _croak_error();
+
+ EXTEND(SP, nport);
+ for (i = 0 ; i < nport ; i++) {
+ portrv = sv_newmortal();
+ sv_setref_pv(portrv, "Sys::Virt::NetworkPort", ports[i]);
+ PUSHs(portrv);
+ }
+ free(ports);
+
+
void
destroy(net_rv)
SV *net_rv;
@@ -6852,6 +6873,150 @@ DESTROY(net_rv)
}
+MODULE = Sys::Virt::NetworkPort PACKAGE = Sys::Virt::NetworkPort
+
+
+virNetworkPortPtr
+_create_xml(net, xml, flags=0)
+ virNetworkPtr net;
+ const char *xml;
+ unsigned int flags;
+ CODE:
+ if (!(RETVAL = virNetworkPortCreateXML(net, xml, flags)))
+ _croak_error();
+ OUTPUT:
+ RETVAL
+
+
+virNetworkPortPtr
+_lookup_by_uuid(net, uuid)
+ virNetworkPtr net;
+ const unsigned char *uuid;
+ CODE:
+ if (!(RETVAL = virNetworkPortLookupByUUID(net, uuid)))
+ _croak_error();
+ OUTPUT:
+ RETVAL
+
+
+virNetworkPortPtr
+_lookup_by_uuid_string(net, uuid)
+ virNetworkPtr net;
+ const char *uuid;
+ CODE:
+ if (!(RETVAL = virNetworkPortLookupByUUIDString(net, uuid)))
+ _croak_error();
+
+ OUTPUT:
+ RETVAL
+
+
+SV *
+get_uuid(port)
+ virNetworkPortPtr port;
+ PREINIT:
+ unsigned char rawuuid[VIR_UUID_BUFLEN];
+ CODE:
+ if ((virNetworkPortGetUUID(port, rawuuid)) < 0)
+ _croak_error();
+
+ RETVAL = newSVpv((char*)rawuuid, sizeof(rawuuid));
+ OUTPUT:
+ RETVAL
+
+
+SV *
+get_uuid_string(port)
+ virNetworkPortPtr port;
+ PREINIT:
+ char uuid[VIR_UUID_STRING_BUFLEN];
+ CODE:
+ if ((virNetworkPortGetUUIDString(port, uuid)) < 0)
+ _croak_error();
+
+ RETVAL = newSVpv(uuid, 0);
+ OUTPUT:
+ RETVAL
+
+
+SV *
+get_xml_description(port, flags=0)
+ virNetworkPortPtr port;
+ unsigned int flags;
+ PREINIT:
+ char *xml;
+ CODE:
+ if (!(xml = virNetworkPortGetXMLDesc(port, flags)))
+ _croak_error();
+
+ RETVAL = newSVpv(xml, 0);
+ free(xml);
+ OUTPUT:
+ RETVAL
+
+
+HV *
+get_parameters(port, flags=0)
+ virNetworkPortPtr port;
+ unsigned int flags;
+ PREINIT:
+ virTypedParameterPtr params = NULL;
+ int nparams = 0;
+ CODE:
+ if (virNetworkPortGetParameters(port, ¶ms, &nparams, flags) < 0) {
+ vir_typed_param_safe_free(params, nparams);
+ _croak_error();
+ }
+
+ RETVAL = vir_typed_param_to_hv(params, nparams);
+ vir_typed_param_safe_free(params, nparams);
+ OUTPUT:
+ RETVAL
+
+
+void
+set_parameters(port, newparams, flags=0)
+ virNetworkPortPtr port;
+ HV *newparams;
+ unsigned int flags;
+ PREINIT:
+ virTypedParameterPtr params = NULL;
+ int nparams = 0;
+ PPCODE:
+ if (virNetworkPortGetParameters(port, ¶ms, &nparams, 0) < 0) {
+ vir_typed_param_safe_free(params, nparams);
+ _croak_error();
+ }
+
+ nparams = vir_typed_param_from_hv(newparams, params, nparams);
+
+ if (virNetworkPortSetParameters(port, params, nparams, flags) < 0)
+ _croak_error();
+ vir_typed_param_safe_free(params, nparams);
+
+
+void
+delete(port, flags=0)
+ virNetworkPortPtr port;
+ unsigned int flags;
+ PPCODE:
+ if (virNetworkPortDelete(port, flags) < 0)
+ _croak_error();
+
+
+void
+DESTROY(port_rv)
+ SV *port_rv;
+ PREINIT:
+ virNetworkPortPtr port;
+ PPCODE:
+ port = (virNetworkPortPtr)SvIV((SV*)SvRV(port_rv));
+ if (port) {
+ virNetworkPortFree(port);
+ sv_setiv((SV*)SvRV(port_rv), 0);
+ }
+
+
MODULE = Sys::Virt::StoragePool PACKAGE = Sys::Virt::StoragePool
@@ -9577,6 +9742,17 @@ BOOT:
REGISTER_CONSTANT(VIR_NETWORK_EVENT_STOPPED, EVENT_STOPPED);
+ stash = gv_stashpv( "Sys::Virt::NetworkPort", TRUE );
+ REGISTER_CONSTANT(VIR_NETWORK_PORT_CREATE_RECLAIM, CREATE_RECLAIM);
+
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE, BANDWIDTH_IN_AVERAGE);
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_IN_BURST, BANDWIDTH_IN_BURST);
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR, BANDWIDTH_IN_FLOOR);
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK, BANDWIDTH_IN_PEAK);
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE, BANDWIDTH_OUT_AVERAGE);
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST, BANDWIDTH_OUT_BURST);
+ REGISTER_CONSTANT_STR(VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK, BANDWIDTH_OUT_PEAK);
+
stash = gv_stashpv( "Sys::Virt::Interface", TRUE );
REGISTER_CONSTANT(VIR_INTERFACE_XML_INACTIVE, XML_INACTIVE);
@@ -9863,4 +10039,7 @@ BOOT:
REGISTER_CONSTANT(VIR_ERR_INVALID_DOMAIN_CHECKPOINT, ERR_INVALID_DOMAIN_CHECKPOINT);
REGISTER_CONSTANT(VIR_ERR_NO_DOMAIN_BACKUP, ERR_NO_DOMAIN_BACKUP);
REGISTER_CONSTANT(VIR_ERR_NO_DOMAIN_CHECKPOINT, ERR_NO_DOMAIN_CHECKPOINT);
+ REGISTER_CONSTANT(VIR_ERR_NO_NETWORK_PORT, ERR_NO_NETWORK_PORT);
+ REGISTER_CONSTANT(VIR_ERR_INVALID_NETWORK_PORT, ERR_INVALID_NETWORK_PORT);
+ REGISTER_CONSTANT(VIR_ERR_NETWORK_PORT_EXIST, ERR_NETWORK_PORT_EXIST);
}
diff --git a/lib/Sys/Virt/Error.pm b/lib/Sys/Virt/Error.pm
index d65ceb5..3f48769 100644
--- a/lib/Sys/Virt/Error.pm
+++ b/lib/Sys/Virt/Error.pm
@@ -844,6 +844,18 @@ Domain checkpoint not found
Domain backup job id not found
+=item Sys::Virt::Error::ERR_NO_NETWORK_PORT
+
+No matching network port
+
+=item Sys::Virt::Error::ERR_INVALID_NETWORK_PORT
+
+Invalid network port object
+
+=item Sys::Virt::Error::ERR_NETWORK_PORT_EXIST
+
+Network port already exists
+
=back
=head1 AUTHORS
diff --git a/lib/Sys/Virt/Network.pm b/lib/Sys/Virt/Network.pm
index 415e629..e4b54da 100644
--- a/lib/Sys/Virt/Network.pm
+++ b/lib/Sys/Virt/Network.pm
@@ -193,6 +193,45 @@ The client ID or DUID
=back
+=item @port = $net->list_all_ports($flags=0)
+
+List all ports associated with the network. The return array elements
+are instances of the C<Sys::Virt::NetworkPort> class.
+
+=item $port = $net->create_port($xml, $flags=0)
+
+Create a new network port from the given C<$xml> description. The C<$flags>
+parameter can optionally taken one or more of the network port creation
+constants. The returned C<$port> object is an instance of the
+C<Sys::Virt::NetworkPort> class.
+
+=cut
+
+sub create_port {
+ my $self = shift;
+ my $xml = shift;
+ my $flags = shift || 0;
+
+ return Sys::Virt::NetworkPort->_new(net => $self, xml => $xml, flags => $flags);
+}
+
+
+=item $port = $net->get_port_by_uuid($uuid);
+
+Lookup a network port from a raw or printable UUID.
+The returned C<$port> object is an instance of the C<Sys::Virt::NetworkPort>
+class.
+
+=cut
+
+sub get_port_by_uuid {
+ my $self = shift;
+ my $uuid = shift;
+
+ return Sys::Virt::NetworkPort->_new(net => $self, uuid => $uuid);
+}
+
+
=back
=head1 CONSTANTS
diff --git a/lib/Sys/Virt/NetworkPort.pm b/lib/Sys/Virt/NetworkPort.pm
new file mode 100644
index 0000000..9e9bf37
--- /dev/null
+++ b/lib/Sys/Virt/NetworkPort.pm
@@ -0,0 +1,177 @@
+# -*- perl -*-
+#
+# Copyright (C) 2019 Red Hat
+#
+# This program is free software; You can redistribute it and/or modify
+# it under either:
+#
+# a) the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any
+# later version,
+#
+# or
+#
+# b) the "Artistic License"
+#
+# The file "LICENSE" distributed along with this file provides full
+# details of the terms and conditions of the two licenses.
+
+=pod
+
+=head1 NAME
+
+Sys::Virt::NetworkPort - Represent & manage a libvirt virtual network port
+
+=head1 DESCRIPTION
+
+The C<Sys::Virt::NetworkPort> module represents a port in a virtual network.
+
+=head1 METHODS
+
+=over 4
+
+=cut
+
+package Sys::Virt::NetworkPort;
+
+use strict;
+use warnings;
+
+
+sub _new {
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+ my %params = @_;
+
+ my $net = exists $params{network} ? $params{network} : die "network parameter is required";
+ my $self;
+ if (exists $params{uuid}) {
+ if (length($params{uuid}) == 16) {
+ $self = Sys::Virt::NetworkPort::_lookup_by_uuid($net, $params{uuid});
+ } elsif (length($params{uuid}) == 32 ||
+ length($params{uuid}) == 36) {
+ $self = Sys::Virt::NetworkPort::_lookup_by_uuid_string($net, $params{uuid});
+ } else {
+ die "UUID must be either 16 unsigned bytes, or 32/36 hex characters long";
+ }
+ } elsif (exists $params{xml}) {
+ my $flags = $params{flags} || 0;
+ $self = Sys::Virt::NetworkPort::_create_xml($net, $params{xml}, $flags);
+ } else {
+ die "uuid or xml parameters are required";
+ }
+
+ bless $self, $class;
+
+ return $self;
+}
+
+
+=item my $uuid = $net->get_uuid()
+
+Returns a 16 byte long string containing the raw globally unique identifier
+(UUID) for the network port.
+
+=item my $uuid = $net->get_uuid_string()
+
+Returns a printable string representation of the raw UUID, in the format
+'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.
+
+=item my $xml = $net->get_xml_description()
+
+Returns an XML document containing a complete description of
+the network port's configuration
+
+=item $net->delete()
+
+Delete the network port from the managed network.
+
+=item my $params = $net->get_parameters($flags=0);
+
+Get tunable parameters associated with the network port. The C<$flags>
+parameter is currently unused and defaults to zero. The returned
+C<$params> is a hash reference whose keys are one or more of the
+following constants:
+
+=over 4
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_IN_AVERAGE
+
+The average inbound bandwidth
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_IN_BURST
+
+The burstable inbound bandwidth
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_IN_FLOOR
+
+The minimum inbound bandwidth
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_IN_PEAK
+
+The peak inbound bandwidth
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_OUT_AVERAGE
+
+The average outbound bandwidth
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_OUT_BURST
+
+The burstable outbound bandwidth
+
+=item Sys::Virt::NetworkPort::BANDWIDTH_OUT_PEAK
+
+The peak outbound bandwidth
+
+=back
+
+=item $net->set_parameters($params, $flags=0);
+
+Set tunable parameters associated with the network port. The C<$flags>
+parameter is currently unused and defaults to zero. The C<$params>
+parameter is a hash reference whose keys are one or more of the
+constants listed for C<get_parameters>.
+
+=back
+
+=head2 NETWORK PORT CREATION CONSTANTS
+
+When creating network ports zero or more of the following
+constants may be used
+
+=over 4
+
+=item Sys::Virt::NetworkPort::CREATE_RECLAIM
+
+Providing configuration reclaiming a pre-existing network port.
+
+=back
+
+
+=cut
+
+
+1;
+
+
+=head1 AUTHORS
+
+Daniel P. Berrange <berrange(a)redhat.com>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2019 Red Hat
+
+=head1 LICENSE
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of either the GNU General Public License as published
+by the Free Software Foundation (either version 2 of the License, or at
+your option any later version), or, the Artistic License, as specified
+in the Perl README file.
+
+=head1 SEE ALSO
+
+L<Sys::Virt>, L<Sys::Virt::Network>, L<Sys::Virt::Error>, C<http://libvirt.org>
+
+=cut
diff --git a/t/030-api-coverage.t b/t/030-api-coverage.t
index 15d4a77..0b6592a 100644
--- a/t/030-api-coverage.t
+++ b/t/030-api-coverage.t
@@ -152,7 +152,7 @@ virNetworkDHCPLeaseFree
);
foreach my $func (sort { $a cmp $b } @functions) {
- if ($func =~ /(GetConnect|Ref|GetDomain)$/ ||
+ if ($func =~ /(GetConnect|Ref|GetDomain|GetNetwork)$/ ||
grep {/$func/ } @blacklist) {
ok(1, $func);
next;
diff --git a/typemap b/typemap
index 9784094..b316aa2 100644
--- a/typemap
+++ b/typemap
@@ -4,6 +4,7 @@ const unsigned char * T_PV
virConnectPtr O_OBJECT_connect
virDomainPtr O_OBJECT_domain
virNetworkPtr O_OBJECT_network
+virNetworkPortPtr O_OBJECT_network_port
virNWFilterPtr O_OBJECT_nwfilter
virNWFilterBindingPtr O_OBJECT_nwfilter_binding
virInterfacePtr O_OBJECT_interface
@@ -55,6 +56,19 @@ OUTPUT
O_OBJECT_network
sv_setref_pv( $arg, "Sys::Virt::Network", (void*)$var );
+INPUT
+O_OBJECT_network_port
+ if (sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG))
+ $var = INT2PTR($type, SvIV((SV*)SvRV( $arg )));
+ else {
+ warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" );
+ XSRETURN_UNDEF;
+ }
+
+OUTPUT
+O_OBJECT_network_port
+ sv_setref_pv( $arg, "Sys::Virt::NetworkPort", (void*)$var );
+
INPUT
O_OBJECT_storagepool
--
2.21.0
5 years, 5 months
[libvirt] [PATCH 0/4] docs: Use CDNJS, update JavaScript libraries
by Andrea Bolognani
We're carrying around embedded copies of a few JavaScript libraries
for use in our homepage, and we've been unforgivably bad at keeping
them up to date.
Instead of serving JavaScript from libvirt.org, use CDNJS so that
users will get better performance and the load on our Web server
will decrease (win-win!); at the same time, move from the positively
ancient versions we're currently using to the freshest ones
available.
Andrea Bolognani (4):
docs: Use CDNJS for Moment.js
docs: Use CDNJS for jquery.rss
docs: Use CDNJS for jQuery
docs: Update JavaScript libraries
docs/Makefile.am | 4 +---
docs/index.html.in | 6 +++---
docs/js/jquery-3.1.1.min.js | 4 ----
docs/js/jquery.rss.min.js | 11 -----------
docs/js/moment.min.js | 7 -------
5 files changed, 4 insertions(+), 28 deletions(-)
delete mode 100644 docs/js/jquery-3.1.1.min.js
delete mode 100644 docs/js/jquery.rss.min.js
delete mode 100644 docs/js/moment.min.js
--
2.21.0
5 years, 5 months
[libvirt] [PATCH 0/5] docs: drvqemu: Clean up documentation regarding XML<->native conversion
by Peter Krempa
This is a follow up to the series for dropping qemu command line
parsing.
This fixes the qemu driver documentation.
Note that the patches removing the outdated examples can be skipped if
we wish to keep them around. I did not see a point in doing so though.
Peter Krempa (5):
docs: drvqemu: Clarify caveats of domxml-to-native
docs: drvqemu: Remove outdated example of virsh domxml-from-native
docs: css: Add style for <span class='deprecated'> ...
docs: drvqemu: Add note about deprecation of domxml-from-native
docs: drvqemu: Drop old example for domxml-to-native
docs/drvqemu.html.in | 77 +++++---------------------------------------
docs/libvirt.css | 6 ++++
2 files changed, 14 insertions(+), 69 deletions(-)
--
2.21.0
5 years, 5 months
[libvirt] [PATCH] test_driver: implement virNetworkGetDHCPLeases
by Ilias Stamatis
Return infinite time DHCP leases for fixed IPV4 addresses.
Signed-off-by: Ilias Stamatis <stamatis.iliass(a)gmail.com>
---
src/test/test_driver.c | 118 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 118 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 1aa79ce898..b7f8f6ecf2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3831,6 +3831,123 @@ testNetworkSetAutostart(virNetworkPtr net,
}
+static int
+testNetworkGetDHCPLeases(virNetworkPtr net,
+ const char *mac,
+ virNetworkDHCPLeasePtr **leases,
+ unsigned int flags)
+{
+ int ret = -1;
+ int ndomains = 0;
+ size_t i, j;
+ size_t nleases = 0;
+ bool need_results = !!leases;
+ char *hostname = NULL;
+ char mac_str[VIR_MAC_STRING_BUFLEN];
+ virMacAddr mac_addr;
+ virDomainObjPtr vm = NULL;
+ virDomainPtr *domains = NULL;
+ virDomainNetDefPtr inf = NULL;
+ virNetworkObjPtr obj = NULL;
+ virNetworkDefPtr obj_def = NULL;
+ virNetworkDHCPLeasePtr lease = NULL;
+ virNetworkDHCPLeasePtr *leases_ret = NULL;
+ testDriverPtr privconn = net->conn->privateData;
+
+ virCheckFlags(0, -1);
+
+ if (mac && virMacAddrParse(mac, &mac_addr) < 0) {
+ virReportError(VIR_ERR_INVALID_MAC, "%s", mac);
+ return -1;
+ }
+
+ if (!(obj = testNetworkObjFindByName(privconn, net->name)))
+ goto cleanup;
+ obj_def = virNetworkObjGetDef(obj);
+
+ ndomains = virDomainObjListExport(privconn->domains, net->conn, &domains,
+ NULL, VIR_CONNECT_LIST_DOMAINS_ACTIVE);
+ if (ndomains < 0)
+ goto cleanup;
+
+ for (i = 0; i < ndomains; i++) {
+ /* the following must be called before testDomObjFromDomain */
+ hostname = testDomainGetHostname(domains[i], 0);
+
+ if (!(vm = testDomObjFromDomain(domains[i])))
+ continue;
+
+ for (j = 0; j < vm->def->nnets; j++) {
+ inf = vm->def->nets[j];
+ if (STRNEQ(inf->data.network.name, obj_def->name))
+ continue;
+
+ virMacAddrFormat(&inf->mac, mac_str);
+ if (mac && virMacAddrCompare(mac, mac_str))
+ continue;
+
+ if (!need_results) {
+ nleases++;
+ continue;
+ }
+
+ if (VIR_ALLOC(lease) < 0)
+ goto error;
+
+ /* the lease is for infinite time */
+ lease->expirytime = 0;
+
+ if ((VIR_STRDUP(lease->mac, mac_str) < 0) ||
+ (VIR_STRDUP(lease->iface, obj_def->bridge) < 0) ||
+ (VIR_STRDUP(lease->hostname, hostname) < 0))
+ goto error;
+
+ lease->prefix = 24;
+ lease->type = VIR_IP_ADDR_TYPE_IPV4;
+ if (virAsprintf(&lease->ipaddr, "192.168.0.%zu", 1 + j) < 0)
+ goto error;
+
+ lease->iaid = lease->clientid = NULL;
+
+ if (VIR_INSERT_ELEMENT(leases_ret, nleases, nleases, lease) < 0)
+ goto error;
+ }
+
+ VIR_FREE(hostname);
+ virDomainObjEndAPI(&vm);
+ }
+
+ if (leases_ret) {
+ /* NULL terminated array */
+ ignore_value(VIR_REALLOC_N(leases_ret, nleases + 1));
+ VIR_STEAL_PTR(*leases, leases_ret);
+ }
+
+ ret = nleases;
+
+ cleanup:
+ for (i = 0; i < ndomains; i++)
+ virDomainFree(domains[i]);
+ VIR_FREE(domains);
+
+ VIR_FREE(hostname);
+ virNetworkObjEndAPI(&obj);
+ return ret;
+
+ error:
+ VIR_FREE(lease);
+
+ if (leases_ret) {
+ for (i = 0; i < nleases; i++)
+ virNetworkDHCPLeaseFree(leases_ret[i]);
+ VIR_FREE(leases_ret);
+ }
+
+ virDomainObjEndAPI(&vm);
+ goto cleanup;
+}
+
+
/*
* Physical host interface routines
*/
@@ -7114,6 +7231,7 @@ static virNetworkDriver testNetworkDriver = {
.networkGetBridgeName = testNetworkGetBridgeName, /* 0.3.2 */
.networkGetAutostart = testNetworkGetAutostart, /* 0.3.2 */
.networkSetAutostart = testNetworkSetAutostart, /* 0.3.2 */
+ .networkGetDHCPLeases = testNetworkGetDHCPLeases, /* 5.5.0 */
.networkIsActive = testNetworkIsActive, /* 0.7.3 */
.networkIsPersistent = testNetworkIsPersistent, /* 0.7.3 */
};
--
2.21.0
5 years, 5 months