[libvirt] [PATCH] rpc: libssh: don't crash when known_hosts file path is not provided
by Peter Krempa
When connecting as root, the "hostsfile" variable would be NULL due to
the code leading to this point. This would result into a crash when
attempting to set the known hosts file path.
To avoid deviating from the approach taken in the libssh2 driver set the
file to /dev/null so that all entries are discarded unless explicitly
specified.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1406457
---
Note that it would be much simpler just to skip ssh_options_set if 'hostsfile'
is NULL. This would result in using /root/.ssh/known_hosts (according to the
config) which would be different to the approach taken in libssh2. With libssh2
this can't be done (at least the last time I checked) as it happened to corrupt
the file in some cases.
src/rpc/virnetlibsshsession.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 5de6629d7..5fc16ba8a 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -1172,6 +1172,9 @@ virNetLibsshSessionSetHostKeyVerification(virNetLibsshSessionPtr sess,
goto error;
}
+ if (!hostsfile)
+ hostsfile = "/dev/null";
+
/* set the known hosts file */
if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, hostsfile) < 0)
goto error;
--
2.11.0
7 years, 11 months
[libvirt] [PATCH 0/6] qemu: blockjob: make automatic disk locking less useless
by Peter Krempa
If automatic disk locking would be enabled with either lock manager the
operations would most probably fail. This was mostly as libvirt did not bother
to release images that were no longer written to by qemu, or tried re-lock
the same image.
This fixes the locking code for creation of external snapshots (both disk-only
and with memory), block copy and active block commit.
This series also kills the horrible "rollback" code in the external disk
snapshot code.
Regular block commit work will be tracked by:
https://bugzilla.redhat.com/show_bug.cgi?id=1405537
Peter Krempa (6):
qemu: blockcopy: Save monitor error prior to calling into lock manager
locking: Fix documentation on how automatic sanlock leases are stored
qemu: snapshot: Don't redetect backing chain after snapshot
qemu: snapshot: Refactor snapshot rollback on failure
qemu: snapshot: Properly handle image locking
qemu: blockjob: Fix locking of block copy/active block commit
src/locking/sanlock.conf | 2 +-
src/qemu/qemu_blockjob.c | 26 ++--
src/qemu/qemu_driver.c | 389 +++++++++++++++++++++++++++--------------------
3 files changed, 242 insertions(+), 175 deletions(-)
--
2.11.0
7 years, 11 months
[libvirt] [PATCH go-xml] Added Storage Pool and Storage Volume XML schemes.
by Alexey Slaykovsky
Signed-off-by: Alexey Slaykovsky <aslaikov(a)redhat.com>
---
storage_encryption.go | 50 ++++++++++
storage_pool.go | 121 +++++++++++++++++++++++++
storage_pool_test.go | 240 ++++++++++++++++++++++++++++++++++++++++++++++++
storage_vol.go | 83 +++++++++++++++++
storage_vol_test.go | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 740 insertions(+)
create mode 100644 storage_encryption.go
create mode 100644 storage_pool.go
create mode 100644 storage_pool_test.go
create mode 100644 storage_vol.go
create mode 100644 storage_vol_test.go
diff --git a/storage_encryption.go b/storage_encryption.go
new file mode 100644
index 0000000..f66314c
--- /dev/null
+++ b/storage_encryption.go
@@ -0,0 +1,50 @@
+/*
+ * 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) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+type StorageEncryptionSecret struct {
+ Type string `xml:"type,attr"`
+ UUID string `xml:"uuid,attr"`
+}
+
+type StorageEncryptionCipher struct {
+ Name string `xml:"name,attr"`
+ Size uint64 `xml:"size,attr"`
+ Mode string `xml:"mode,attr"`
+ Hash string `xml:"hash,attr"`
+}
+
+type StorageEncryptionIvgen struct {
+ Name string `xml:"name,attr"`
+ Hash string `xml:"hash,attr"`
+}
+
+type StorageEncryption struct {
+ Format string `xml:"format,attr"`
+ Secret *StorageEncryptionSecret `xml:"secret"`
+ Cipher *StorageEncryptionCipher `xml:"cipher"`
+ Ivgen *StorageEncryptionIvgen `xml:"ivgen"`
+}
diff --git a/storage_pool.go b/storage_pool.go
new file mode 100644
index 0000000..3481361
--- /dev/null
+++ b/storage_pool.go
@@ -0,0 +1,121 @@
+/*
+ * 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) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import "encoding/xml"
+
+type StoragePoolTargetPermissions struct {
+ Owner string `xml:"owner,omitempty"`
+ Group string `xml:"group,omitempty"`
+ Mode string `xml:"mode,omitempty"`
+ Label string `xml:"label,omitempty"`
+}
+
+type StoragePoolTargetTimestamps struct {
+ Atime string `xml:"atime"`
+ Mtime string `xml:"mtime"`
+ Ctime string `xml:"ctime"`
+}
+
+type StoragePoolTarget struct {
+ Path string `xml:"path,omitempty"`
+ Permissions *StoragePoolTargetPermissions `xml:"permissions"`
+ Timestamps *StoragePoolTargetTimestamps `xml:"timestamps"`
+ Encryption *StorageEncryption `xml:"encryption"`
+}
+
+type StoragePoolSourceFormat struct {
+ Type string `xml:"type,attr"`
+}
+type StoragePoolSourceHost struct {
+ Name string `xml:"name,attr"`
+}
+
+type StoragePoolSourceDevice struct {
+ Path string `xml:"path,attr"`
+ PartSeparator string `xml:"part_separator,attr,omitempty"`
+}
+
+type StoragePoolSourceAuthSecret struct {
+ Usage string `xml:"usage,attr"`
+}
+
+type StoragePoolSourceAuth struct {
+ Type string `xml:"type,attr"`
+ Username string `xml:"username,attr"`
+ Secret *StoragePoolSourceAuthSecret `xml:"secret"`
+}
+
+type StoragePoolSourceVendor struct {
+ Name string `xml:"name,attr"`
+}
+
+type StoragePoolSourceProduct struct {
+ Name string `xml:"name,attr"`
+}
+
+type StoragePoolSourceAdapterParentAddrAddress struct {
+ Domain string `xml:"domain,attr"`
+ Bus string `xml:"bus,attr"`
+ Slot string `xml:"slot,attr"`
+ Addr string `xml:"addr,attr"`
+}
+
+type StoragePoolSourceAdapterParentAddr struct {
+ UniqueID uint64 `xml:"unique_id,attr"`
+ Address *StoragePoolSourceAdapterParentAddrAddress `xml:"address"`
+}
+
+type StoragePoolSourceAdapter struct {
+ Type string `xml:"type,attr"`
+ Name string `xml:"name,attr,omitempty"`
+ Parent string `xml:"parent,attr,omitempty"`
+ WWNN string `xml:"wwnn,attr,omitempty"`
+ WWPN string `xml:"wwpn,attr,omitempty"`
+ ParentAddr *StoragePoolSourceAdapterParentAddr `xml:"parentaddr"`
+}
+
+type StoragePoolSource struct {
+ Host *StoragePoolSourceHost `xml:"host"`
+ Device *StoragePoolSourceDevice `xml:"device"`
+ Auth *StoragePoolSourceAuth `xml:"auth"`
+ Vendor *StoragePoolSourceVendor `xml:"vendor"`
+ Product *StoragePoolSourceProduct `xml:"product"`
+ Format *StoragePoolSourceFormat `xml:"format"`
+ Adapter *StoragePoolSourceAdapter `xml:"adapter"`
+}
+
+type StoragePool struct {
+ XMLName xml.Name `xml:"pool"`
+ Type string `xml:"type,attr"`
+ Name string `xml:"name"`
+ UUID string `xml:"uuid,omitempty"`
+ Allocation uint64 `xml:"allocation,omitempty"`
+ Capacity uint64 `xml:"capacity,omitempty"`
+ Available uint64 `xml:"available,omitempty"`
+ Target *StoragePoolTarget `xml:"target"`
+ Source *StoragePoolSource `xml:"source"`
+}
diff --git a/storage_pool_test.go b/storage_pool_test.go
new file mode 100644
index 0000000..8c1b606
--- /dev/null
+++ b/storage_pool_test.go
@@ -0,0 +1,240 @@
+/*
+ * 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) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import (
+ "encoding/xml"
+ "strings"
+ "testing"
+)
+
+var storagePoolTestData = []struct {
+ Object *StoragePool
+ Expected []string
+}{
+ {
+ Object: &StoragePool{
+ Type: "dir",
+ Name: "pool",
+ UUID: "3e3fce45-4f53-4fa7-bb32-11f34168b82b",
+ Allocation: 1000000,
+ Capacity: 5000000,
+ Available: 3000000,
+ },
+ Expected: []string{
+ `<pool type="dir">`,
+ ` <name>pool</name>`,
+ ` <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid>`,
+ ` <allocation>1000000</allocation>`,
+ ` <capacity>5000000</capacity>`,
+ ` <available>3000000</available>`,
+ `</pool>`,
+ },
+ },
+ {
+ Object: &StoragePool{
+ Type: "iscsi",
+ Name: "pool",
+ Source: &StoragePoolSource{
+ Host: &StoragePoolSourceHost{
+ Name: "host.example.com",
+ },
+ Device: &StoragePoolSourceDevice{
+ Path: "pool.example.com:iscsi-pool",
+ },
+ Auth: &StoragePoolSourceAuth{
+ Type: "chap",
+ Username: "username",
+ Secret: &StoragePoolSourceAuthSecret{
+ Usage: "cluster",
+ },
+ },
+ Vendor: &StoragePoolSourceVendor{
+ Name: "vendor",
+ },
+ Product: &StoragePoolSourceProduct{
+ Name: "product",
+ },
+ },
+ },
+ Expected: []string{
+ `<pool type="iscsi">`,
+ ` <name>pool</name>`,
+ ` <source>`,
+ ` <host name="host.example.com"></host>`,
+ ` <device path="pool.example.com:iscsi-pool"></device>`,
+ ` <auth type="chap" username="username">`,
+ ` <secret usage="cluster"></secret>`,
+ ` </auth>`,
+ ` <vendor name="vendor"></vendor>`,
+ ` <product name="product"></product>`,
+ ` </source>`,
+ `</pool>`,
+ },
+ },
+ {
+ Object: &StoragePool{
+ Type: "disk",
+ Name: "pool",
+ Source: &StoragePoolSource{
+ Device: &StoragePoolSourceDevice{
+ Path: "/dev/mapper/pool",
+ PartSeparator: "no",
+ },
+ Format: &StoragePoolSourceFormat{
+ Type: "gpt",
+ },
+ },
+ },
+ Expected: []string{
+ `<pool type="disk">`,
+ ` <name>pool</name>`,
+ ` <source>`,
+ ` <device path="/dev/mapper/pool" part_separator="no"></device>`,
+ ` <format type="gpt"></format>`,
+ ` </source>`,
+ `</pool>`,
+ },
+ },
+ {
+ Object: &StoragePool{
+ Type: "scsi",
+ Name: "pool",
+ Source: &StoragePoolSource{
+ Adapter: &StoragePoolSourceAdapter{
+ Type: "scsi_host",
+ Name: "scsi_host",
+ },
+ },
+ },
+ Expected: []string{
+ `<pool type="scsi">`,
+ ` <name>pool</name>`,
+ ` <source>`,
+ ` <adapter type="scsi_host" name="scsi_host"></adapter>`,
+ ` </source>`,
+ `</pool>`,
+ },
+ },
+ {
+ Object: &StoragePool{
+ Type: "scsi",
+ Name: "pool",
+ Source: &StoragePoolSource{
+ Adapter: &StoragePoolSourceAdapter{
+ Type: "scsi_host",
+ ParentAddr: &StoragePoolSourceAdapterParentAddr{
+ UniqueID: 1,
+ Address: &StoragePoolSourceAdapterParentAddrAddress{
+ Domain: "0x0000",
+ Bus: "0x00",
+ Slot: "0x1f",
+ Addr: "0x2",
+ },
+ },
+ },
+ },
+ },
+ Expected: []string{
+ `<pool type="scsi">`,
+ ` <name>pool</name>`,
+ ` <source>`,
+ ` <adapter type="scsi_host">`,
+ ` <parentaddr unique_id="1">`,
+ ` <address domain="0x0000" bus="0x00" slot="0x1f" addr="0x2"></address>`,
+ ` </parentaddr>`,
+ ` </adapter>`,
+ ` </source>`,
+ `</pool>`,
+ },
+ },
+ {
+ Object: &StoragePool{
+ Type: "fs",
+ Name: "pool",
+ Source: &StoragePoolSource{
+ Adapter: &StoragePoolSourceAdapter{
+ Type: "fc_host",
+ Parent: "scsi_parent",
+ WWNN: "20000000c9831b4b",
+ WWPN: "10000000c9831b4b",
+ },
+ },
+ },
+ Expected: []string{
+ `<pool type="fs">`,
+ ` <name>pool</name>`,
+ ` <source>`,
+ ` <adapter type="fc_host" parent="scsi_parent" wwnn="20000000c9831b4b" wwpn="10000000c9831b4b"></adapter>`,
+ ` </source>`,
+ `</pool>`,
+ },
+ },
+ {
+ Object: &StoragePool{
+ Type: "dir",
+ Name: "pool",
+ Target: &StoragePoolTarget{
+ Path: "/pool",
+ Permissions: &StoragePoolTargetPermissions{
+ Owner: "1",
+ Group: "1",
+ Mode: "0744",
+ Label: "pool",
+ },
+ },
+ },
+ Expected: []string{
+ `<pool type="dir">`,
+ ` <name>pool</name>`,
+ ` <target>`,
+ ` <path>/pool</path>`,
+ ` <permissions>`,
+ ` <owner>1</owner>`,
+ ` <group>1</group>`,
+ ` <mode>0744</mode>`,
+ ` <label>pool</label>`,
+ ` </permissions>`,
+ ` </target>`,
+ `</pool>`,
+ },
+ },
+}
+
+func TestStoragePool(t *testing.T) {
+ for _, test := range storagePoolTestData {
+ doc, err := xml.MarshalIndent(test.Object, "", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ expect := strings.Join(test.Expected, "\n")
+
+ if string(doc) != expect {
+ t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n")
+ }
+ }
+}
diff --git a/storage_vol.go b/storage_vol.go
new file mode 100644
index 0000000..7d42b53
--- /dev/null
+++ b/storage_vol.go
@@ -0,0 +1,83 @@
+/*
+ * 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) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import "encoding/xml"
+
+type StorageVolumeMemory struct {
+ Unit string `xml:"unit,attr,omitempty"`
+ Value uint64 `xml:",chardata"`
+}
+
+type StorageVolumeTargetPermissions struct {
+ Owner string `xml:"owner,omitempty"`
+ Group string `xml:"group,omitempty"`
+ Mode string `xml:"mode,omitempty"`
+ Label string `xml:"label,omitempty"`
+}
+
+type StorageVolumeTargetFeature struct {
+ LazyRefcounts *struct{} `xml:"lazy_refcounts"`
+}
+
+type StorageVolumeTargetFormat struct {
+ Type string `xml:"type,attr"`
+}
+
+type StorageVolumeTargetTimestamps struct {
+ Atime string `xml:"atime"`
+ Mtime string `xml:"mtime"`
+ Ctime string `xml:"ctime"`
+}
+
+type StorageVolumeTarget struct {
+ Path string `xml:"path,omitempty"`
+ Format *StorageVolumeTargetFormat `xml:"format"`
+ Permissions *StorageVolumeTargetPermissions `xml:"permissions"`
+ Timestamps *StorageVolumeTargetTimestamps `xml:"timestamps"`
+ Compat string `xml:"compat,omitempty"`
+ NoCOW *struct{} `xml:"nocow"`
+ Features []StorageVolumeTargetFeature `xml:"features"`
+ Encryption *StorageEncryption `xml:"encryption"`
+}
+
+type StorageVolumeBackingStore struct {
+ Path string `xml:"path"`
+ Format *StorageVolumeTargetFormat `xml:"format"`
+ Permissions *StorageVolumeTargetPermissions `xml:"permissions"`
+}
+
+type StorageVolume struct {
+ XMLName xml.Name `xml:"volume"`
+ Type string `xml:"type,attr,omitempty"`
+ Name string `xml:"name"`
+ Key string `xml:"key,omitempty"`
+ Allocation *StorageVolumeMemory `xml:"allocation"`
+ Capacity *StorageVolumeMemory `xml:"capacity"`
+ Physical *StorageVolumeMemory `xml:"physical"`
+ Target *StorageVolumeTarget `xml:"target"`
+ BackingStore *StorageVolumeBackingStore `xml:"backingStore"`
+}
diff --git a/storage_vol_test.go b/storage_vol_test.go
new file mode 100644
index 0000000..e57e94d
--- /dev/null
+++ b/storage_vol_test.go
@@ -0,0 +1,246 @@
+/*
+ * 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) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import (
+ "encoding/xml"
+ "strings"
+ "testing"
+)
+
+var storageVolumeTestData = []struct {
+ Object *StorageVolume
+ Expected []string
+}{
+ {
+ Object: &StorageVolume{
+ Type: "file",
+ Name: "file.img",
+ Key: "/file.img",
+ Allocation: &StorageVolumeMemory{
+ Value: 0,
+ },
+
+ Capacity: &StorageVolumeMemory{
+ Unit: "T",
+ Value: 1,
+ },
+ },
+ Expected: []string{
+ `<volume type="file">`,
+ ` <name>file.img</name>`,
+ ` <key>/file.img</key>`,
+ ` <allocation>0</allocation>`,
+ ` <capacity unit="T">1</capacity>`,
+ `</volume>`,
+ },
+ },
+ {
+ Object: &StorageVolume{
+ Type: "file",
+ Name: "file.img",
+ Target: &StorageVolumeTarget{
+ Path: "/file.img",
+ Format: &StorageVolumeTargetFormat{
+ Type: "qcow2",
+ },
+ Permissions: &StorageVolumeTargetPermissions{
+ Owner: "107",
+ Group: "107",
+ Mode: "0744",
+ Label: "image",
+ },
+ Timestamps: &StorageVolumeTargetTimestamps{
+ Atime: "1341933637.273190990",
+ Mtime: "1341930622.047245868",
+ Ctime: "1341930622.047245868",
+ },
+ Compat: "1.1",
+ NoCOW: &struct{}{},
+ Features: []StorageVolumeTargetFeature{
+ StorageVolumeTargetFeature{
+ LazyRefcounts: &struct{}{},
+ },
+ },
+ },
+ },
+ Expected: []string{
+ `<volume type="file">`,
+ ` <name>file.img</name>`,
+ ` <target>`,
+ ` <path>/file.img</path>`,
+ ` <format type="qcow2"></format>`,
+ ` <permissions>`,
+ ` <owner>107</owner>`,
+ ` <group>107</group>`,
+ ` <mode>0744</mode>`,
+ ` <label>image</label>`,
+ ` </permissions>`,
+ ` <timestamps>`,
+ ` <atime>1341933637.273190990</atime>`,
+ ` <mtime>1341930622.047245868</mtime>`,
+ ` <ctime>1341930622.047245868</ctime>`,
+ ` </timestamps>`,
+ ` <compat>1.1</compat>`,
+ ` <nocow></nocow>`,
+ ` <features>`,
+ ` <lazy_refcounts></lazy_refcounts>`,
+ ` </features>`,
+ ` </target>`,
+ `</volume>`,
+ },
+ },
+ {
+ Object: &StorageVolume{
+ Type: "file",
+ Name: "file.img",
+ BackingStore: &StorageVolumeBackingStore{
+ Path: "/master.img",
+ Format: &StorageVolumeTargetFormat{
+ Type: "raw",
+ },
+ Permissions: &StorageVolumeTargetPermissions{
+ Owner: "107",
+ Group: "107",
+ Mode: "0744",
+ Label: "label",
+ },
+ },
+ },
+ Expected: []string{
+ `<volume type="file">`,
+ ` <name>file.img</name>`,
+ ` <backingStore>`,
+ ` <path>/master.img</path>`,
+ ` <format type="raw"></format>`,
+ ` <permissions>`,
+ ` <owner>107</owner>`,
+ ` <group>107</group>`,
+ ` <mode>0744</mode>`,
+ ` <label>label</label>`,
+ ` </permissions>`,
+ ` </backingStore>`,
+ `</volume>`,
+ },
+ },
+ {
+ Object: &StorageVolume{
+ Name: "luks.img",
+ Capacity: &StorageVolumeMemory{
+ Unit: "G",
+ Value: 5,
+ },
+ Target: &StorageVolumeTarget{
+ Path: "/luks.img",
+ Format: &StorageVolumeTargetFormat{
+ Type: "raw",
+ },
+ Encryption: &StorageEncryption{
+ Format: "luks",
+ Secret: &StorageEncryptionSecret{
+ Type: "passphrase",
+ UUID: "f52a81b2-424e-490c-823d-6bd4235bc572",
+ },
+ },
+ },
+ },
+ Expected: []string{
+ `<volume>`,
+ ` <name>luks.img</name>`,
+ ` <capacity unit="G">5</capacity>`,
+ ` <target>`,
+ ` <path>/luks.img</path>`,
+ ` <format type="raw"></format>`,
+ ` <encryption format="luks">`,
+ ` <secret type="passphrase" uuid="f52a81b2-424e-490c-823d-6bd4235bc572"></secret>`,
+ ` </encryption>`,
+ ` </target>`,
+ `</volume>`,
+ },
+ },
+ {
+ Object: &StorageVolume{
+ Name: "twofish",
+ Capacity: &StorageVolumeMemory{
+ Unit: "G",
+ Value: 5,
+ },
+ Target: &StorageVolumeTarget{
+ Path: "/twofish.luks",
+ Format: &StorageVolumeTargetFormat{
+ Type: "raw",
+ },
+ Encryption: &StorageEncryption{
+ Format: "luks",
+ Secret: &StorageEncryptionSecret{
+ Type: "passphrase",
+ UUID: "f52a81b2-424e-490c-823d-6bd4235bc572",
+ },
+ Cipher: &StorageEncryptionCipher{
+ Name: "twofish",
+ Size: 256,
+ Mode: "cbc",
+ Hash: "sha256",
+ },
+ Ivgen: &StorageEncryptionIvgen{
+ Name: "plain64",
+ Hash: "sha256",
+ },
+ },
+ },
+ },
+ Expected: []string{
+ `<volume>`,
+ ` <name>twofish</name>`,
+ ` <capacity unit="G">5</capacity>`,
+ ` <target>`,
+ ` <path>/twofish.luks</path>`,
+ ` <format type="raw"></format>`,
+ ` <encryption format="luks">`,
+ ` <secret type="passphrase" uuid="f52a81b2-424e-490c-823d-6bd4235bc572"></secret>`,
+ ` <cipher name="twofish" size="256" mode="cbc" hash="sha256"></cipher>`,
+ ` <ivgen name="plain64" hash="sha256"></ivgen>`,
+ ` </encryption>`,
+ ` </target>`,
+ `</volume>`,
+ },
+ },
+}
+
+func TestStorageVolume(t *testing.T) {
+ for _, test := range storageVolumeTestData {
+ doc, err := xml.MarshalIndent(test.Object, "", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ expect := strings.Join(test.Expected, "\n")
+
+ if string(doc) != expect {
+ t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n")
+ }
+ }
+}
--
2.11.0
7 years, 11 months
[libvirt] [PATCH 0/2] Attempt, and fail, to fix build with Clang 3.9 / Linux
by Andrea Bolognani
Martin asked for this a while ago. I was surprised, at first,
because according to my experience the only issue with Clang
builds were a couple of test cases failing to run, but trying
again on Clang 3.9 / Fedora rawhide caused me to run into at
least three separate compilation issues.
Two of them I take care with this series, even though I'm
fairly unconvinced the bugs are actually in libvirt rather
than Clang or glibc; more details in the relevant commit
messages.
The last one I was unable to work around in any sensible
manner: when linking, clang fails with
../gnulib/lib/.libs/libgnu.a(mgetgroups.o):
In function `realloc_groupbuf':
.../libvirt/gnulib/lib/mgetgroups.c:45:
undefined reference to `__muloti4'
This seems to be a well-known issue[1] with no solution in
sight; passing CFLAGS='-rtlib=compiler-rt' to configure
allows the compilation to succeed but, yeah, way gross.
So basically I've spent way too much time trying to get this
to work and I'm stuck now, so I'm posting whatever I have so
far in hope others will pitch in and help me out :)
[1] https://llvm.org/bugs/show_bug.cgi?id=16404
Andrea Bolognani (2):
util: Turn virFirewallAddRule() into a macro
util: Cast to 'long double' when calling isnan()
src/libvirt_private.syms | 1 -
src/util/virfirewall.c | 23 -----------------------
src/util/virfirewall.h | 16 ++++++++++++----
src/util/virxml.c | 10 +++++-----
4 files changed, 17 insertions(+), 33 deletions(-)
--
2.11.0
7 years, 11 months
[libvirt] [PATCH v2 0/5] Don't run whole sec driver in namespace
by Michal Privoznik
v2 of:
https://www.redhat.com/archives/libvir-list/2016-December/msg00907.html
diff to v1:
- Pushed 1/6 from the original series as it was ACKed
- Added more comments
- Fixed return value of virSecurityDACTransactionAppend and virSecuritySELinuxTransactionAppend
- Dropped ignore_value() around virThreadLocalSet()
- Unset thread local just in transactionCommit APIs
I have not implemented any rollback yet, but I've added comments
where the implementation should go ;-)
Michal Privoznik (5):
security_dac: Resolve virSecurityDACSetOwnershipInternal const
correctness
security driver: Introduce transaction APIs
security_dac: Implement transaction APIs
security_selinux: Implement transaction APIs
qemu: Use transactions from security driver
src/libvirt_private.syms | 3 +
src/qemu/qemu_driver.c | 25 ++--
src/qemu/qemu_security.c | 100 ++++---------
src/security/security_dac.c | 261 +++++++++++++++++++++++++++++++++-
src/security/security_driver.h | 9 ++
src/security/security_manager.c | 68 +++++++++
src/security/security_manager.h | 7 +-
src/security/security_selinux.c | 256 ++++++++++++++++++++++++++++++++-
src/security/security_stack.c | 49 +++++++
src/storage/storage_backend.h | 2 +-
src/storage/storage_backend_fs.c | 2 +-
src/storage/storage_backend_gluster.c | 2 +-
src/storage/storage_driver.c | 6 +-
src/storage/storage_driver.h | 4 +-
src/util/virstoragefile.c | 2 +-
src/util/virstoragefile.h | 2 +-
16 files changed, 703 insertions(+), 95 deletions(-)
--
2.11.0
7 years, 11 months
[libvirt] [PATCH v3 0/3] qemu: Use virtio-pci by default for mach-virt guests
by Andrea Bolognani
Changes from [v2]:
* rename qemuDomainCountVirtioMMIODevices() to
qemuDomainHasVirtioMMIODevices() and make it exit as soon
as the first virtio-mmio device is encountered, as
suggested by Laine
* tweak test suite and note no new test cases are needed
* add comments and user documentation
* add release notes entry
* can actually be merged now that all patches it builds on
have been merged :)
Changes from [v1]:
* use virDomainDeviceInfoIterate(), as suggested by Martin
and Laine, which results in cleaner and more robust code
[v1] https://www.redhat.com/archives/libvir-list/2016-October/msg00988.html
[v2] https://www.redhat.com/archives/libvir-list/2016-October/msg01042.html
Andrea Bolognani (3):
qemu: Use virtio-pci by default for mach-virt guests
docs: Document virtio-mmio by default for mach-virt guests
NEWS: Update for virtio-pci by default for mach-virt guests
docs/formatdomain.html.in | 8 +++-
docs/news.html.in | 6 +++
src/qemu/qemu_domain_address.c | 51 ++++++++++++++++++++--
...l2argv-aarch64-virt-2.6-virtio-pci-default.args | 14 +++---
.../qemuxml2argv-aarch64-virtio-pci-default.args | 17 +++++---
.../qemuxml2argv-aarch64-virtio-pci-default.xml | 3 --
tests/qemuxml2argvtest.c | 1 +
.../qemuxml2xmlout-aarch64-virtio-pci-default.xml | 40 ++++++++++++++---
tests/qemuxml2xmltest.c | 1 +
9 files changed, 119 insertions(+), 22 deletions(-)
--
2.7.4
7 years, 11 months
[libvirt] [PATCH go] Add support for perf cache_l1d event
by Daniel P. Berrange
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
Pushed as a build fix
connect.go | 6 ++++++
domain.go | 6 ++++++
domain_compat.h | 4 ++++
3 files changed, 16 insertions(+)
diff --git a/connect.go b/connect.go
index 35eb7fd..41c54b1 100644
--- a/connect.go
+++ b/connect.go
@@ -2253,6 +2253,8 @@ type DomainStatsPerf struct {
StalledCyclesBackend uint64
RefCpuCyclesSet bool
RefCpuCycles uint64
+ CacheL1DSet bool
+ CacheL1D uint64
}
func getDomainStatsPerfFieldInfo(params *DomainStatsPerf) map[string]typedParamsFieldInfo {
@@ -2309,6 +2311,10 @@ func getDomainStatsPerfFieldInfo(params *DomainStatsPerf) map[string]typedParams
set: ¶ms.RefCpuCyclesSet,
ul: ¶ms.RefCpuCycles,
},
+ "perf.cache_l1d": typedParamsFieldInfo{
+ set: ¶ms.CacheL1DSet,
+ ul: ¶ms.CacheL1D,
+ },
}
}
diff --git a/domain.go b/domain.go
index 515138a..3e66dab 100644
--- a/domain.go
+++ b/domain.go
@@ -3183,6 +3183,8 @@ type DomainPerfEvents struct {
StalledCyclesBackend bool
RefCpuCyclesSet bool
RefCpuCycles bool
+ CacheL1DSet bool
+ CacheL1D bool
}
/* Remember to also update DomainStatsPerf in connect.go when adding to the stuct above */
@@ -3241,6 +3243,10 @@ func getDomainPerfEventsFieldInfo(params *DomainPerfEvents) map[string]typedPara
set: ¶ms.RefCpuCyclesSet,
b: ¶ms.RefCpuCycles,
},
+ C.VIR_PERF_PARAM_CACHE_L1D: typedParamsFieldInfo{
+ set: ¶ms.CacheL1DSet,
+ b: ¶ms.CacheL1D,
+ },
}
}
diff --git a/domain_compat.h b/domain_compat.h
index 14072d0..4da562b 100644
--- a/domain_compat.h
+++ b/domain_compat.h
@@ -45,6 +45,10 @@
#define VIR_PERF_PARAM_REF_CPU_CYCLES "ref_cpu_cycles"
#endif
+#ifndef VIR_PERF_PARAM_CACHE_L1D
+#define VIR_PERF_PARAM_CACHE_L1D "cache_l1d"
+#endif
+
#ifndef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
#define VIR_DOMAIN_EVENT_ID_METADATA_CHANGE 23
#endif
--
2.9.3
7 years, 11 months
[libvirt] [libvirt-python][PATCH] examples: Update event-test.py
by Michal Privoznik
With recent changes there are new events known to libvirt.
Reflect those changes in our event-test.py example script.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
examples/event-test.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/examples/event-test.py b/examples/event-test.py
index e43a2f8..d5af33c 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -538,6 +538,9 @@ def myDomainEventJobCompletedCallback(conn, dom, params, opaque):
def myDomainEventDeviceRemovalFailedCallback(conn, dom, dev, opaque):
print("myDomainEventDeviceRemovalFailedCallback: Domain %s(%s) failed to remove device: %s" % (
dom.name(), dom.ID(), dev))
+def myDomainEventMetadataChangeCallback(conn, dom, mtype, nsuri, opaque):
+ print("myDomainEventMetadataChangeCallback: Domain %s(%s) changed metadata mtype=%d nsuri=%s" % (
+ dom.name(), dom.ID(), mtype, nsuri))
##########################################################################
# Network events
@@ -600,6 +603,23 @@ def myNodeDeviceEventLifecycleCallback(conn, dev, event, detail, opaque):
def myNodeDeviceEventUpdateCallback(conn, dev, opaque):
print("myNodeDeviceEventUpdateCallback: Node device %s" % dev.name())
+##########################################################################
+# Secret events
+##########################################################################
+def secretEventToString(event):
+ secretEventStrings = ( "Defined",
+ "Undefined",
+ )
+ return secretEventStrings[event]
+
+def mySecretEventLifecycleCallback(conn, secret, event, detail, opaque):
+ print("mySecretEventLifecycleCallback: Secret %s %s %d" % (secret.UUIDString(),
+ secretEventToString(event),
+ detail))
+
+def mySecretEventValueChanged(conn, secret, opaque):
+ print("mySecretEventValueChanged: Secret %s" % secret.UUIDString())
+
##########################################################################
# Set up and run the program
##########################################################################
@@ -689,6 +709,7 @@ def main():
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION, myDomainEventMigrationIteration, None)
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_JOB_COMPLETED, myDomainEventJobCompletedCallback, None)
vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventDeviceRemovalFailedCallback, None)
+ vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, myDomainEventMetadataChangeCallback, None)
vc.networkEventRegisterAny(None, libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None)
@@ -698,6 +719,9 @@ def main():
vc.nodeDeviceEventRegisterAny(None, libvirt.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE, myNodeDeviceEventLifecycleCallback, None)
vc.nodeDeviceEventRegisterAny(None, libvirt.VIR_NODE_DEVICE_EVENT_ID_UPDATE, myNodeDeviceEventUpdateCallback, None)
+ vc.secretEventRegisterAny(None, libvirt.VIR_SECRET_EVENT_ID_LIFECYCLE, mySecretEventLifecycleCallback, None)
+ vc.secretEventRegisterAny(None, libvirt.VIR_SECRET_EVENT_ID_VALUE_CHANGED, mySecretEventValueChanged, None)
+
vc.setKeepAlive(5, 3)
# The rest of your app would go here normally, but for sake
--
2.11.0
7 years, 11 months
[libvirt] [PATCH python 0/2] Add support for new events
by Daniel P. Berrange
Daniel P. Berrange (2):
Add support for secret event APIs
Add support for domain metadata change event
generator.py | 2 +
libvirt-override-virConnect.py | 52 +++++++++
libvirt-override.c | 260 +++++++++++++++++++++++++++++++++++++++++
sanitytest.py | 3 +
4 files changed, 317 insertions(+)
--
2.9.3
7 years, 11 months