[libvirt PATCH] schema: Add support for high TSC frequency
by Jiri Denemark
The unsignedInt XML schema type allows for values up to 2^32 - 1, i.e.,
using 4294967296 or greater TSC frequency would fail schema validation.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
docs/schemas/domaincommon.rng | 2 +-
.../cpu-tsc-high-frequency.x86_64-latest.args | 38 +++++++++++++++++++
.../cpu-tsc-high-frequency.xml | 35 +++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
4 files changed, 75 insertions(+), 1 deletion(-)
create mode 100644 tests/qemuxml2argvdata/cpu-tsc-high-frequency.x86_64-latest.args
create mode 100644 tests/qemuxml2argvdata/cpu-tsc-high-frequency.xml
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 97fa873977..e0d09f9c03 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1235,7 +1235,7 @@
</optional>
<optional>
<attribute name="frequency">
- <ref name="unsignedInt"/>
+ <ref name="unsignedLong"/>
</attribute>
</optional>
<optional>
diff --git a/tests/qemuxml2argvdata/cpu-tsc-high-frequency.x86_64-latest.args b/tests/qemuxml2argvdata/cpu-tsc-high-frequency.x86_64-latest.args
new file mode 100644
index 0000000000..16a4282ab1
--- /dev/null
+++ b/tests/qemuxml2argvdata/cpu-tsc-high-frequency.x86_64-latest.args
@@ -0,0 +1,38 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine pc,accel=kvm,usb=off,dump-guest-core=off,memory-backend=pc.ram \
+-cpu EPYC-Rome,x2apic=on,tsc-deadline=on,hypervisor=on,tsc-adjust=on,stibp=on,\
+arch-capabilities=on,ssbd=on,xsaves=on,cmp-legacy=on,amd-ssbd=on,virt-ssbd=on,\
+rdctl-no=on,skip-l1dfl-vmentry=on,mds-no=on,pschange-mc-no=on,invtsc=on,\
+tsc-frequency=4567890000 \
+-m 214 \
+-object memory-backend-ram,id=pc.ram,size=224395264 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/cpu-tsc-high-frequency.xml b/tests/qemuxml2argvdata/cpu-tsc-high-frequency.xml
new file mode 100644
index 0000000000..afaef6e8e5
--- /dev/null
+++ b/tests/qemuxml2argvdata/cpu-tsc-high-frequency.xml
@@ -0,0 +1,35 @@
+<domain type='kvm'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <title>A description of the test machine.</title>
+ <description>
+ A test of qemu's minimal configuration.
+ This test also tests the description and title elements.
+ </description>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <cpu mode='host-model'>
+ <model fallback='allow'/>
+ <feature policy='require' name='invtsc'/>
+ </cpu>
+ <clock offset='utc'>
+ <timer name='tsc' frequency='4567890000'/>
+ </clock>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ec33134a97..174294c0f1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1953,6 +1953,7 @@ mymain(void)
DO_TEST_CAPS_VER("cpu-host-model-cmt", "4.0.0");
DO_TEST("cpu-tsc-frequency", QEMU_CAPS_KVM);
DO_TEST_CAPS_VER("cpu-tsc-frequency", "4.0.0");
+ DO_TEST_CAPS_LATEST("cpu-tsc-high-frequency");
DO_TEST_CAPS_VER("cpu-translation", "4.0.0");
DO_TEST_CAPS_LATEST("cpu-translation");
qemuTestSetHostCPU(&driver, driver.hostarch, NULL);
--
2.29.2
4 years, 6 months
[PATCH v2] qemu: Move qemuExtDevicesStop() before removing the pidfiles
by Masayoshi Mizuma
From: Masayoshi Mizuma <m.mizuma(a)jp.fujitsu.com>
A qemu guest which has virtiofs config fails to start if the previous
starting failed because of invalid option or something.
That's because the virtiofsd isn't killed by virPidFileForceCleanupPath()
on the former failure because the pidfile was already removed by
virFileDeleteTree(priv->libDir) in qemuProcessStop(), so
virPidFileForceCleanupPath() just returned.
Move qemuExtDevicesStop() before virFileDeleteTree(priv->libDir) so that
virPidFileForceCleanupPath() can kill virtiofsd correctly.
For example of the reproduction:
# virsh start guest
error: Failed to start domain guest
error: internal error: process exited while connecting to monitor: qemu-system-x86_64: -foo: invalid option
... fix the option ...
# virsh start guest
error: Failed to start domain guest
error: Cannot open log file: '/var/log/libvirt/qemu/guest-fs0-virtiofsd.log': Device or resource busy
#
Signed-off-by: Masayoshi Mizuma <m.mizuma(a)jp.fujitsu.com>
---
src/qemu/qemu_process.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0a36b49c85..1963de9fb8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7638,6 +7638,8 @@ void qemuProcessStop(virQEMUDriverPtr driver,
/* Do this before we delete the tree and remove pidfile. */
qemuProcessKillManagedPRDaemon(vm);
+ qemuExtDevicesStop(driver, vm);
+
virFileDeleteTree(priv->libDir);
virFileDeleteTree(priv->channelTargetDir);
@@ -7654,8 +7656,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
qemuDomainCleanupRun(driver, vm);
- qemuExtDevicesStop(driver, vm);
-
qemuDBusStop(driver, vm);
vm->def->id = -1;
--
2.27.0
4 years, 6 months
[PATCH v7 0/4] qemu: Support rbd namespace in rbd source name
by Han Han
Diff from v6: rebase to 6.9.0
v6: https://www.redhat.com/archives/libvir-list/2020-October/msg00707.html
gitlab repo: https://gitlab.com/hhan2/libvirt/-/commits/rbd-namespace-v7
Han Han (4):
qemu_capabilities: Add QEMU_CAPS_RBD_NAMESPACE
util: Add member ns to the storage source struct
conf: Support to parse rbd namespace from source name
qemu: Implement rbd namespace to the source name attribute
docs/formatdomain.rst | 16 ++++++
src/conf/domain_conf.c | 47 ++++++++++++++++--
src/qemu/qemu_block.c | 1 +
src/qemu/qemu_capabilities.c | 4 ++
src/qemu/qemu_capabilities.h | 3 ++
src/qemu/qemu_domain.c | 8 +++
src/util/virstoragefile.c | 2 +
src/util/virstoragefile.h | 1 +
.../caps_5.0.0.aarch64.xml | 1 +
.../qemucapabilitiesdata/caps_5.0.0.ppc64.xml | 1 +
.../caps_5.0.0.riscv64.xml | 1 +
.../caps_5.0.0.x86_64.xml | 1 +
.../caps_5.1.0.x86_64.xml | 1 +
.../caps_5.2.0.x86_64.xml | 1 +
...k-network-rbd-namespace.x86_64-latest.args | 49 +++++++++++++++++++
.../disk-network-rbd-namespace.xml | 40 +++++++++++++++
tests/qemuxml2argvtest.c | 1 +
...sk-network-rbd-namespace.x86_64-latest.xml | 49 +++++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
19 files changed, 224 insertions(+), 4 deletions(-)
create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args
create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.xml
create mode 100644 tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml
--
2.28.0
4 years, 6 months
[PATCH v2 0/2] Support mdev_types on CSS devices
by Boris Fiuczynski
All refactoring patches of this series in v1 were accepted except for
actual patch enabling the mdev_types support on CSS devices.
v2 adds one more refactoring patch in docs before the already
sent enablement patch follows again.
Boris Fiuczynski (2):
docs: refactor mdev_types into new paragraph
node_device: detecting mdev_types capability on CSS devices
docs/drvnodedev.html.in | 5 +-
docs/formatnode.html.in | 85 +++++++++++------
docs/schemas/nodedev.rng | 4 +
src/conf/node_device_conf.c | 92 ++++++++++++++++++-
src/conf/node_device_conf.h | 11 +++
src/conf/virnodedeviceobj.c | 7 +-
src/libvirt_private.syms | 1 +
src/node_device/node_device_udev.c | 3 +
.../css_0_0_fffe_mdev_types.xml | 17 ++++
tests/nodedevxml2xmltest.c | 1 +
10 files changed, 192 insertions(+), 34 deletions(-)
create mode 100644 tests/nodedevschemadata/css_0_0_fffe_mdev_types.xml
--
2.26.2
4 years, 6 months
[PATCH 1/8] Added a few attach-disk parameters
by Ryan Gahagan
Signed-off-by: Ryan Gahagan <rgahagan(a)cs.utexas.edu>
---
tools/virsh-domain.c | 76 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 68 insertions(+), 8 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 12b35c037d..16227085cc 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -224,6 +224,26 @@ static const vshCmdOptDef opts_attach_disk[] = {
.flags = VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK,
.help = N_("source of disk device")
},
+ {.name = "source-protocol",
+ .type = VSH_OT_STRING,
+ .help = N_("protocol used by disk device source")
+ }
+ {.name = "source-name",
+ .type = VSH_OT_STRING,
+ .help = N_("name of disk device source")
+ },
+ {.name = "source-host-name",
+ .type = VSH_OT_STRING,
+ .help = N_("host name for source of disk device")
+ },
+ {.name = "source-host-transport",
+ .type = VSH_OT_STRING,
+ .help = N_("host transport for source of disk device")
+ },
+ {.name = "source-host-socket",
+ .type = VSH_OT_STRING,
+ .help = N_("host socket for source of disk device")
+ },
{.name = "target",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
@@ -562,11 +582,13 @@ static bool
cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
- const char *source = NULL, *target = NULL, *driver = NULL,
- *subdriver = NULL, *type = NULL, *mode = NULL,
- *iothread = NULL, *cache = NULL, *io = NULL,
- *serial = NULL, *straddr = NULL, *wwn = NULL,
- *targetbus = NULL, *alias = NULL;
+ const char *source = NULL, *source_name = NULL, *source_protocol = NULL,
+ *target = NULL, *driver = NULL, *subdriver = NULL, *type = NULL,
+ *mode = NULL, *iothread = NULL, *cache = NULL,
+ *io = NULL, *serial = NULL, *straddr = NULL,
+ *wwn = NULL, *targetbus = NULL, *alias = NULL,
+ *host_name = NULL, *host_transport = NULL,
+ *host_port = NULL, *host_socket = NULL;
struct DiskAddress diskAddr;
bool isFile = false, functionReturn = false;
int ret;
@@ -591,6 +613,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
flags |= VIR_DOMAIN_AFFECT_LIVE;
if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 ||
+ vshCommandOptStringReq(ctl, cmd, "source-name", &source_name) < 0 ||
+ vshCommandOptStringReq(ctl, cmd, "source-protocol", &source_protocol) < 0 ||
vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 ||
vshCommandOptStringReq(ctl, cmd, "subdriver", &subdriver) < 0 ||
@@ -604,7 +628,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
vshCommandOptStringReq(ctl, cmd, "address", &straddr) < 0 ||
vshCommandOptStringReq(ctl, cmd, "targetbus", &targetbus) < 0 ||
vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 ||
- vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0)
+ vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0 ||
+ vshCommandOptStringReq(ctl, cmd, "source-host-name", &host_name) < 0 ||
+ vshCommandOptStringReq(ctl, cmd, "source-host-transport", &host_transport) < 0 ||
+ vshCommandOptStringReq(ctl, cmd, "source-host-socket", &host_socket) < 0)
goto cleanup;
if (!stype) {
@@ -659,9 +686,42 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
virBufferAddLit(&buf, "/>\n");
}
- if (source)
- virBufferAsprintf(&buf, "<source %s='%s'/>\n",
+ if (source || source_protocol || source_name ||
+ host_name || host_transport || host_socket) {
+ virBufferAsprintf(&buf, "<source");
+
+ if (source)
+ virBufferAsprintf(&buf, " %s='%s'",
isFile ? "file" : "dev", source);
+ if (source_protocol)
+ virBufferAsprintf(&buf, " protocol='%s'", source_protocol);
+ if (source_name)
+ virBufferAsprintf(&buf, " name='%s'", source_name);
+
+ if (host_name || host_transport || host_socket) {
+ virBufferAsprintf(">\n<host");
+
+ if (host_name) {
+ host_port = strchr(host_name, ':');
+
+ if (!host_port)
+ virBufferAsprintf(" name='%s'", host_name);
+ else {
+ host_name[host_port - host_name] = '\0';
+ virBufferAsprintf(" name='%s' port='%s'", host_name, host_port + 1);
+ }
+ }
+ if (host_transport)
+ virBufferAsprintf(" transport='%s'", host_transport);
+ if (host_socket)
+ virBufferAsprintf(" socket='%s'", host_socket);
+
+ virBufferAsprintf(" />\n</source>\n");
+ } else {
+ virBufferAsprintf(" />\n");
+ }
+ }
+
virBufferAsprintf(&buf, "<target dev='%s'", target);
if (targetbus)
virBufferAsprintf(&buf, " bus='%s'", targetbus);
--
2.29.0
4 years, 6 months
[libvirt] [PATCH v2 00/13] virsh completion improvement
by Lin Ma
Add more bash completions for some of virsh subcommands/subparameters.
v1->v2
* Follow Michal's suggestions:
- guestvcpus command: complete offlined vCPUs if --enable, complete onlined vCPUs if --disable
- Added a static helper function for interface string provider,
- Adjusted some needlessly complicated loops.
* Refered to Peter and Michal's comments, I droped the vnc completion patches.
* Concentrate on completion itself, Drop all of patches which related to macros to make review easier.
Lin Ma (13):
virsh: Add vcpu list completion to guestvcpus command
virsh: Add logical CPU IDs completion for nodecpustats command
virsh: Add serial/parallel device name completion to console command
virsh-interface: Add a static helper virshInterfaceStringHelper
virsh: Add interface mac completion to iface-name command
virsh: Add interface name completion to iface-bridge command
virsh: Add interface name completion to iface-mac command
vsh: Fix completion error in case of multiple mac addresses
virsh: Add mac completion to net-dhcp-leases command
virsh: Move/add some of function declarations to virsh-domain.h
virsh: Add signal name completion to send-process-signal command
virsh: Add lifecycle type completion to set-lifecycle-action command
Add lifecycle action completion to set-lifecycle-action command
tools/bash-completion/vsh | 1 +
tools/virsh-completer-domain.c | 190 ++++++++++++++++++++++++++++++
tools/virsh-completer-domain.h | 20 ++++
tools/virsh-completer-host.c | 31 +++++
tools/virsh-completer-host.h | 4 +
tools/virsh-completer-interface.c | 34 ++++--
tools/virsh-completer-interface.h | 7 ++
tools/virsh-completer-network.c | 44 +++++++
tools/virsh-completer-network.h | 4 +
tools/virsh-domain.c | 6 +-
tools/virsh-domain.h | 4 +
tools/virsh-host.c | 1 +
tools/virsh-interface.c | 3 +
tools/virsh-network.c | 15 ++-
14 files changed, 349 insertions(+), 15 deletions(-)
--
2.26.0
4 years, 6 months
[libvirt PATCH] qemu: add qemuAgentSSH{Add,Remove,Get}AuthorizedKeys
by marcandre.lureau@redhat.com
From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
In QEMU 5.2, the guest agent learned to manipulate a user
~/.ssh/authorized_keys. Bind the JSON API to libvirt.
https://wiki.qemu.org/ChangeLog/5.2#Guest_agent
Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1888537
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
---
src/qemu/qemu_agent.c | 158 ++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_agent.h | 26 +++++++
tests/qemuagenttest.c | 80 +++++++++++++++++++++
3 files changed, 264 insertions(+)
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 7fbb4a9431..75e7fea9e4 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -2496,3 +2496,161 @@ qemuAgentSetResponseTimeout(qemuAgentPtr agent,
{
agent->timeout = timeout;
}
+
+void qemuAgentSSHAuthorizedKeyFree(qemuAgentSSHAuthorizedKeyPtr key)
+{
+ if (!key)
+ return;
+
+ g_free(key->key);
+ g_free(key);
+}
+
+/* Returns: 0 on success
+ * -2 when agent command is not supported by the agent and
+ * 'report_unsupported' is false (libvirt error is not reported)
+ * -1 otherwise (libvirt error is reported)
+ */
+int qemuAgentSSHGetAuthorizedKeys(qemuAgentPtr agent,
+ const char *user,
+ qemuAgentSSHAuthorizedKeyPtr **keys,
+ bool report_unsupported)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ virJSONValuePtr data = NULL;
+ size_t ndata;
+ size_t i;
+ int rc;
+ qemuAgentSSHAuthorizedKeyPtr *keys_ret = NULL;
+
+ if (!(cmd = qemuAgentMakeCommand("guest-ssh-get-authorized-keys",
+ "s:username", user,
+ NULL)))
+ return -1;
+
+ if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
+ report_unsupported)) < 0)
+ return rc;
+
+ if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("qemu agent didn't return an array of keys"));
+ return -1;
+ }
+ ndata = virJSONValueArraySize(data);
+
+ keys_ret = g_new0(qemuAgentSSHAuthorizedKeyPtr, ndata);
+
+ for (i = 0; i < ndata; i++) {
+ virJSONValuePtr entry = virJSONValueArrayGet(data, i);
+
+ if (!entry) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("array element missing in guest-ssh-get-authorized-keys return "
+ "value"));
+ goto cleanup;
+ }
+
+ keys_ret[i] = g_new0(qemuAgentSSHAuthorizedKey, 1);
+ keys_ret[i]->key = g_strdup(virJSONValueGetString(entry));
+ }
+
+ *keys = g_steal_pointer(&keys_ret);
+ return ndata;
+
+ cleanup:
+ if (keys_ret) {
+ for (i = 0; i < ndata; i++)
+ qemuAgentSSHAuthorizedKeyFree(keys_ret[i]);
+ g_free(keys_ret);
+ }
+ return -1;
+}
+
+static virJSONValuePtr
+makeJSONArrayFromKeys(qemuAgentSSHAuthorizedKeyPtr *keys,
+ size_t nkeys)
+{
+ g_autoptr(virJSONValue) jkeys = NULL;
+ size_t i;
+
+ jkeys = virJSONValueNewArray();
+
+ for (i = 0; i < nkeys; i++) {
+ qemuAgentSSHAuthorizedKeyPtr k = keys[i];
+
+ if (virJSONValueArrayAppendString(jkeys, k->key) < 0)
+ return NULL;
+ }
+
+ return g_steal_pointer(&jkeys);
+}
+
+/* Returns: 0 on success
+ * -2 when agent command is not supported by the agent and
+ * 'report_unsupported' is false (libvirt error is not reported)
+ * -1 otherwise (libvirt error is reported)
+ */
+int qemuAgentSSHAddAuthorizedKeys(qemuAgentPtr agent,
+ const char *user,
+ qemuAgentSSHAuthorizedKeyPtr *keys,
+ size_t nkeys,
+ bool reset,
+ bool report_unsupported)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ g_autoptr(virJSONValue) jkeys = NULL;
+ int rc;
+
+ jkeys = makeJSONArrayFromKeys(keys, nkeys);
+ if (jkeys == NULL)
+ return -1;
+
+ if (!(cmd = qemuAgentMakeCommand("guest-ssh-add-authorized-keys",
+ "s:username", user,
+ "a:keys", &jkeys,
+ "b:reset", reset,
+ NULL)))
+ return -1;
+
+ if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
+ report_unsupported)) < 0)
+ return rc;
+
+ return 0;
+}
+
+/* Returns: 0 on success
+ * -2 when agent command is not supported by the agent and
+ * 'report_unsupported' is false (libvirt error is not reported)
+ * -1 otherwise (libvirt error is reported)
+ */
+int qemuAgentSSHRemoveAuthorizedKeys(qemuAgentPtr agent,
+ const char *user,
+ qemuAgentSSHAuthorizedKeyPtr *keys,
+ size_t nkeys,
+ bool report_unsupported)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ g_autoptr(virJSONValue) jkeys = NULL;
+ int rc;
+
+ jkeys = makeJSONArrayFromKeys(keys, nkeys);
+ if (jkeys == NULL)
+ return -1;
+
+ if (!(cmd = qemuAgentMakeCommand("guest-ssh-remove-authorized-keys",
+ "s:username", user,
+ "a:keys", &jkeys,
+ NULL)))
+ return -1;
+
+ if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
+ report_unsupported)) < 0)
+ return rc;
+
+ return 0;
+}
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 2eeb376a68..3e70a55c19 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -67,6 +67,12 @@ typedef enum {
QEMU_AGENT_SHUTDOWN_LAST,
} qemuAgentShutdownMode;
+typedef struct _qemuAgentSSHAuthorizedKey qemuAgentSSHAuthorizedKey;
+typedef qemuAgentSSHAuthorizedKey *qemuAgentSSHAuthorizedKeyPtr;
+struct _qemuAgentSSHAuthorizedKey {
+ char *key;
+};
+
typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo;
typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr;
struct _qemuAgentDiskInfo {
@@ -170,3 +176,23 @@ int qemuAgentGetTimezone(qemuAgentPtr mon,
void qemuAgentSetResponseTimeout(qemuAgentPtr mon,
int timeout);
+
+void qemuAgentSSHAuthorizedKeyFree(qemuAgentSSHAuthorizedKeyPtr key);
+
+int qemuAgentSSHGetAuthorizedKeys(qemuAgentPtr agent,
+ const char *user,
+ qemuAgentSSHAuthorizedKeyPtr **keys,
+ bool report_unsupported);
+
+int qemuAgentSSHAddAuthorizedKeys(qemuAgentPtr agent,
+ const char *user,
+ qemuAgentSSHAuthorizedKeyPtr *keys,
+ size_t nkeys,
+ bool reset,
+ bool report_unsupported);
+
+int qemuAgentSSHRemoveAuthorizedKeys(qemuAgentPtr agent,
+ const char *user,
+ qemuAgentSSHAuthorizedKeyPtr *keys,
+ size_t nkeys,
+ bool report_unsupported);
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index 607bd97b5c..eda688850f 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -35,6 +35,85 @@
virQEMUDriver driver;
+static int
+testQemuAgentSSHKeys(const void *data)
+{
+ virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+ qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
+ qemuAgentSSHAuthorizedKeyPtr *keys = NULL;
+ int nkeys = 0, i;
+ int ret = -1;
+
+ if (!test)
+ return -1;
+
+ if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+ goto cleanup;
+
+ if (qemuMonitorTestAddItem(test, "guest-ssh-get-authorized-keys",
+ "{ \"return\" : [\"algo1 key1 comments1\","
+ " \"algo2 key2 comments2\"] }") < 0)
+ goto cleanup;
+
+ if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+ goto cleanup;
+
+ if (qemuMonitorTestAddItem(test, "guest-ssh-add-authorized-keys",
+ "{ \"return\" : {} }") < 0)
+ goto cleanup;
+
+ if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+ goto cleanup;
+
+ if (qemuMonitorTestAddItem(test, "guest-ssh-remove-authorized-keys",
+ "{ \"return\" : {} }") < 0)
+ goto cleanup;
+
+ if ((nkeys = qemuAgentSSHGetAuthorizedKeys(qemuMonitorTestGetAgent(test),
+ "user",
+ &keys,
+ true)) < 0)
+ goto cleanup;
+
+ if (nkeys != 2) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "expected 2 keys, got %d", nkeys);
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (STRNEQ(keys[1]->key, "algo2 key2 comments2")) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected key returned: %s", keys[1]->key);
+ ret = -1;
+ goto cleanup;
+ }
+
+ if ((ret = qemuAgentSSHAddAuthorizedKeys(qemuMonitorTestGetAgent(test),
+ "user",
+ keys,
+ nkeys,
+ true,
+ true)) < 0)
+ goto cleanup;
+
+ if ((ret = qemuAgentSSHRemoveAuthorizedKeys(qemuMonitorTestGetAgent(test),
+ "user",
+ keys,
+ nkeys,
+ true)) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ for (i = 0; i < nkeys; i++)
+ qemuAgentSSHAuthorizedKeyFree(keys[i]);
+ VIR_FREE(keys);
+ qemuMonitorTestFree(test);
+ return ret;
+}
+
+
static int
testQemuAgentFSFreeze(const void *data)
{
@@ -1315,6 +1394,7 @@ mymain(void)
DO_TEST(Users);
DO_TEST(OSInfo);
DO_TEST(Timezone);
+ DO_TEST(SSHKeys);
DO_TEST(Timeout); /* Timeout should always be called last */
--
2.29.0
4 years, 6 months
[libvirt] [PATCH 00/19] virsh completion improvement
by Lin Ma
Lin Ma (19):
virsh: Add current vcpu list completion to guestvcpus command
virsh: Add logical CPU IDs completion for nodecpustats command
virsh: Add serial/parallel device name completion to console command
virsh: Rename virshInterfaceNameCompleter to virshInterfaceCompleter
virsh: create a macro with a _FULL suffix for common --interface
option
virsh: Add interface name completion to iface-bridge command
virsh: Add interface name completion to iface-mac command
virsh: Add interface mac completion to iface-name command
virdomainobjlist: Add vnc into filter group to check the vnc existence
of guest
virsh: Only return domains that have VNC display to vncdisplay command
vsh: Fix completion error in case of multiple mac addresses
virsh: Add mac completion to net-dhcp-leases command
virsh-domain: Introduce 2 macros for domain options 'interface' and
'mac'
virsh-domain: Apply macro VIRSH_DOMAIN_OPT_INTERFACE for interface
option
virsh-domain: Apply macro VIRSH_DOMAIN_OPT_MAC for mac option
virsh: Move/add some of function declarations to virsh-domain.h
virsh: Add signal name completion to send-process-signal command
virsh: Add lifecycle type completion to set-lifecycle-action command
virsh: Add lifecycle action completion to set-lifecycle-action command
include/libvirt/libvirt-domain.h | 3 +
src/conf/virdomainobjlist.c | 15 +++
src/conf/virdomainobjlist.h | 7 +-
tools/bash-completion/vsh | 1 +
tools/virsh-completer-domain.c | 153 +++++++++++++++++++++++++++++-
tools/virsh-completer-domain.h | 20 ++++
tools/virsh-completer-host.c | 35 +++++++
tools/virsh-completer-host.h | 4 +
tools/virsh-completer-interface.c | 19 ++--
tools/virsh-completer-interface.h | 10 +-
tools/virsh-completer-network.c | 45 +++++++++
tools/virsh-completer-network.h | 4 +
tools/virsh-domain-monitor.c | 20 +---
tools/virsh-domain-monitor.h | 1 +
tools/virsh-domain.c | 30 ++----
tools/virsh-domain.h | 22 +++++
tools/virsh-host.c | 1 +
tools/virsh-interface.c | 39 ++++----
tools/virsh-network.c | 15 ++-
19 files changed, 367 insertions(+), 77 deletions(-)
--
2.26.0
4 years, 6 months
[PATCH] util: convert char pointers to use g_autofree
by Ryan Gahagan
From: Barrett Schonefeld <bschoney(a)utexas.edu>
additional conversions to the GLib API in src/util per issue #11.
files updated are:
- src/util/vircgroupv1.c
- src/util/virhostcpu.c
- src/util/virlockspace.c
- src/util/virmacmap.c
- src/util/virresctrl.c
- src/util/virsysinfo.c
Related issue: https://gitlab.com/libvirt/libvirt/-/issues/11
Signed-off-by: bschoney <bschoney(a)utexas.edu>
Signed-off-by: Barrett Schonefeld <bschoney(a)utexas.edu>
---
src/util/vircgroupv1.c | 3 +--
src/util/virhostcpu.c | 4 +---
src/util/virlockspace.c | 6 ++----
src/util/virmacmap.c | 3 +--
src/util/virresctrl.c | 25 ++++++++-----------------
src/util/virsysinfo.c | 9 +++------
6 files changed, 16 insertions(+), 34 deletions(-)
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 731e9d61d4..984cd50409 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1549,7 +1549,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
unsigned long long *unevictable)
{
int ret = -1;
- char *stat = NULL;
+ g_autofree char *stat = NULL;
char *line = NULL;
unsigned long long cacheVal = 0;
unsigned long long activeAnonVal = 0;
@@ -1614,7 +1614,6 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
ret = 0;
cleanup:
- VIR_FREE(stat);
return ret;
}
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c531d65f86..4f6c3390ce 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -87,7 +87,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
int *nparams)
{
const char *sysctl_name;
- long *cpu_times;
+ g_autofree long *cpu_times = NULL;
struct clockinfo clkinfo;
size_t i, j, cpu_times_size, clkinfo_size;
int cpu_times_num, offset, hz, stathz, ret = -1;
@@ -172,8 +172,6 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
ret = 0;
cleanup:
- VIR_FREE(cpu_times);
-
return ret;
}
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index b90e13f506..71d5dfb83e 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -515,7 +515,7 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace,
const char *resname)
{
int ret = -1;
- char *respath = NULL;
+ g_autofree char *respath = NULL;
VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname);
@@ -538,7 +538,6 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace,
cleanup:
virMutexUnlock(&lockspace->lock);
- VIR_FREE(respath);
return ret;
}
@@ -547,7 +546,7 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace,
const char *resname)
{
int ret = -1;
- char *respath = NULL;
+ g_autofree char *respath = NULL;
VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname);
@@ -575,7 +574,6 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace,
cleanup:
virMutexUnlock(&lockspace->lock);
- VIR_FREE(respath);
return ret;
}
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index f9047d0fb1..e68742de10 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -129,7 +129,7 @@ static int
virMacMapLoadFile(virMacMapPtr mgr,
const char *file)
{
- char *map_str = NULL;
+ g_autofree char *map_str = NULL;
virJSONValuePtr map = NULL;
int map_str_len = 0;
size_t i;
@@ -189,7 +189,6 @@ virMacMapLoadFile(virMacMapPtr mgr,
ret = 0;
cleanup:
- VIR_FREE(map_str);
virJSONValueFree(map);
return ret;
}
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index d3087b98c1..1c2d175295 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -709,7 +709,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
{
int ret = -1;
int rv = -1;
- char *featurestr = NULL;
+ g_autofree char *featurestr = NULL;
char **features = NULL;
size_t nfeatures = 0;
virResctrlInfoMongrpPtr info_monitor = NULL;
@@ -771,7 +771,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
ret = 0;
cleanup:
- VIR_FREE(featurestr);
g_strfreev(features);
VIR_FREE(info_monitor);
return ret;
@@ -1736,7 +1735,7 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
const char *groupname,
virResctrlAllocPtr *alloc)
{
- char *schemata = NULL;
+ g_autofree char *schemata = NULL;
int rv = virFileReadValueString(&schemata,
SYSFS_RESCTRL_PATH "/%s/schemata",
groupname);
@@ -1753,11 +1752,9 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
if (virResctrlAllocParse(resctrl, *alloc, schemata) < 0)
goto error;
- VIR_FREE(schemata);
return 0;
error:
- VIR_FREE(schemata);
virObjectUnref(*alloc);
*alloc = NULL;
return -1;
@@ -2354,8 +2351,8 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
virResctrlAllocPtr alloc,
const char *machinename)
{
- char *schemata_path = NULL;
- char *alloc_str = NULL;
+ g_autofree char *schemata_path = NULL;
+ g_autofree char *alloc_str = NULL;
int ret = -1;
int lockfd = -1;
@@ -2403,8 +2400,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
ret = 0;
cleanup:
virResctrlUnlock(lockfd);
- VIR_FREE(alloc_str);
- VIR_FREE(schemata_path);
return ret;
}
@@ -2413,8 +2408,8 @@ static int
virResctrlAddPID(const char *path,
pid_t pid)
{
- char *tasks = NULL;
- char *pidstr = NULL;
+ g_autofree char *tasks = NULL;
+ g_autofree char *pidstr = NULL;
int ret = 0;
if (!path) {
@@ -2436,8 +2431,6 @@ virResctrlAddPID(const char *path,
ret = 0;
cleanup:
- VIR_FREE(tasks);
- VIR_FREE(pidstr);
return ret;
}
@@ -2657,8 +2650,8 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
size_t i = 0;
unsigned long long val = 0;
g_autoptr(DIR) dirp = NULL;
- char *datapath = NULL;
- char *filepath = NULL;
+ g_autofree char *datapath = NULL;
+ g_autofree char *filepath = NULL;
struct dirent *ent = NULL;
virResctrlMonitorStatsPtr stat = NULL;
@@ -2737,8 +2730,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
ret = 0;
cleanup:
- VIR_FREE(datapath);
- VIR_FREE(filepath);
virResctrlMonitorStatsFree(stat);
return ret;
}
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 217f842a37..e1336bf566 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -532,9 +532,9 @@ static int
virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
{
const char *tmp_base;
- char *manufacturer = NULL;
- char *procline = NULL;
- char *ncpu = NULL;
+ g_autofree char *manufacturer = NULL;
+ g_autofree char *procline = NULL;
+ g_autofree char *ncpu = NULL;
int result = -1;
virSysinfoProcessorDefPtr processor;
@@ -593,9 +593,6 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
result = 0;
error:
- VIR_FREE(manufacturer);
- VIR_FREE(procline);
- VIR_FREE(ncpu);
return result;
}
--
2.29.0
4 years, 6 months
[libvirt PATCH] virgdbus: fix getting non-shared DBus connection
by Pavel Hrdina
We need to pass some flags in order to properly initialize the
connection otherwise it will not work. This copies what GLib does
for g_bus_get_sync() internally.
This fixes an issue with LXC driver where libvirt was not able to
register any VM with machined.
Reported-by: Matthias Maier <tamiko(a)gentoo.org>
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/util/virgdbus.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/util/virgdbus.c b/src/util/virgdbus.c
index 19fd7e2fe4..4ad1a5c842 100644
--- a/src/util/virgdbus.c
+++ b/src/util/virgdbus.c
@@ -54,11 +54,15 @@ virGDBusBusInit(GBusType type, GError **error)
if (sharedBus) {
return g_bus_get_sync(type, NULL, error);
} else {
+ GDBusConnectionFlags dbusFlags =
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION;
+
address = g_dbus_address_get_for_bus_sync(type, NULL, error);
if (*error)
return NULL;
return g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_NONE,
+ dbusFlags,
NULL,
NULL,
error);
--
2.26.2
4 years, 6 months