Skip to contentSkip to conversation

(no subject)

libvirt In review Osier Yang 4 participants 26 messages Nov 11, 2011 – Dec 10, 2011 KVM

lore
Share & tools
lore

Osier Yang

author
#0 lore raw

Hi, all

This is a basic implementation of libvirt Native Linux KVM Tool driver. Note that this is just made with my own interest and spare time, it's not an endorsement/effort by Red Hat, and it isn't supported by Red Hat officially.

Basically, the driver is designed as *stateful*, as KVM tool doesn't maintain any info about the guest except a socket which for its own IPC. And it's implemented by using KVM tool binary, which is name "kvm" currently, along with cgroup controllers "cpuacct", and "memory" support. And as one of KVM tool's pricinple is to allow both the non-root and root user to play with. The driver is designed to support root and non-root too, just like QEMU does. Example of the connection URI:

virsh -c kvmtool:///system
virsh -c kvmtool:///session
virsh -c kvmtool+unix:///system
virsh -c kvmtool+unix:///session

The implementation can support more or less than 15 virsh commands currently, including basic domain cycle operations (define/undefine, start/destroy, suspend/resume, console, setmem, schedinfo, dumpxml, ,autostart, dominfo, etc.)

About the domain configuration:
* "kernel": must be specified as KVM tool only support boots from the kernel currently (no integration with BIOS app yet).

* "disk": only virtio bus is supported, and device type must be 'disk'.

* "serial/console": only one console is supported, of type serial or virtio (can extend to support multiple console as long as kvm tool supports, libvirt already supported mutiple console, see upstream commit 0873b688c).

* "p9fs": only support specifying the source dir, and mount tag, only type of 'mount' is supported.

* "memballoon": only virtio is supported, and there is no way to config the addr.

* Multiple "disk" and "p9fs" is supported.

* Graphics and network are not supported, will explain below.

Please see "[PATCH 7/8]" for an example of the domain config. (which contains all the XMLs supported by current implementation).

The problems of Native Linux KVM Tool from libvirt p.o.v:

* Some destros package "qemu-kvm" as "kvm", also "kvm" is a long established name for "KVM" itself, so naming the project as "kvm" might be not a good idea. I assume it will be named as "kvmtool" in this implementation, never mind this if you don't like that, it can be updated easily. :-)

* It still doesn't have an official package yet, even no "make install". means we have no way to check the dependancy and do the checking when 'configure'. I assume it will be installed as "/usr/bin/kvmtool" in this implementation. This is the main reason which can prevents upstream libvirt accepting the patches I guess.

* Lacks of options for user's configuration, such as "-vnc", there is no option for user to configure the properties for the "vnc", such as the port. It hides things, doesn't provide ways to query the properties too, this causes problems for libvirt to add the vnc support, as vnc clients such as virt-manager, virt-viewer, have no way to connect the guest. Even vncviewer can't.

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

* There is a gap about the domain status between KVM tool and libvirt, it's caused by KVM tool unlink()s the guest socket when user exits from console (both text and graphic), but libvirt still think the guest is running.

* KVM tool uses $HOME/.kvm_tool as the state dir, and no way to configure, I made a small patch to allow KVM tool accept a ENV variable, which is "KVM_STATE_DIR", it's used across the driver. I made a simple patch against kvm tool to let the whole patches work. See "[PATCH] kvm tools.....". As generally we want the state dir of a driver can be "/var/run/libvirt/kvmtool/..." for root user or "$HOME/.libvirt/kvmtool/run" for non-root user.

* kvmtoolGetVersion is just broken now, as what "./kvm version" returns is something like "3.0.rc5.873.gb73216", however, libvirt wants things like "2.6.40.6-0". This might be not a problem as long as KVM tool has a official package.

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

* It will be quite desireable if kvm tool could report the capabilities, of which is lacked by QEMU forever (seems so), it causes much pain for upper layer mgmt apps. See the RFC by Daniel Berrange in QEMU list for more details:

http://lists.nongnu.org/archive/html/qemu-devel/2010-06/msg00921.html

As a conclusion, it seems to me that KVM tool dosesn't consider too much about the interface for upper layer management tools, (generally, upper layer apps will want good interface to set/get), which might be no good for KVM tool future development.

Thoughts, and opinions? Thanks.

[PATCH 1/7] kvmtool: Add configure support
[PATCH] kvm tools: Introduce an ENV variable for the state dir [PATCH 2/7] kvmtool: Add documents
[PATCH 3/7] kvmtool: Add new enums and error codes for the driver [PATCH 4/7] kvmtool: Add hook support for kvmtool domain [PATCH 5/7] kvmtool: Add new domain type
[PATCH 6/7] conf: Set source type of the stub console [PATCH 7/7] kvmtool: Implementation for kvm tool driver

Regards,
Osier

author
#1 lore raw

Re: [libvirt] Add driver support for Native Linux KVM Tool

Sorry, I missed the title. :(

Osier

Quoted 135 lines · Osier Yang

Hi, all

This is a basic implementation of libvirt Native Linux KVM Tool driver. Note that this is just made with my own interest and spare time, it's not an endorsement/effort by Red Hat, and it isn't supported by Red Hat officially.

Basically, the driver is designed as *stateful*, as KVM tool doesn't maintain any info about the guest except a socket which for its own IPC. And it's implemented by using KVM tool binary, which is name "kvm" currently, along with cgroup controllers "cpuacct", and "memory" support. And as one of KVM tool's pricinple is to allow both the non-root and root user to play with. The driver is designed to support root and non-root too, just like QEMU does. Example of the connection URI:

virsh -c kvmtool:///system
virsh -c kvmtool:///session
virsh -c kvmtool+unix:///system
virsh -c kvmtool+unix:///session

The implementation can support more or less than 15 virsh commands currently, including basic domain cycle operations (define/undefine, start/destroy, suspend/resume, console, setmem, schedinfo, dumpxml, ,autostart, dominfo, etc.)

About the domain configuration:
* "kernel": must be specified as KVM tool only support boots from the kernel currently (no integration with BIOS app yet).

* "disk": only virtio bus is supported, and device type must be 'disk'.

* "serial/console": only one console is supported, of type serial or virtio (can extend to support multiple console as long as kvm tool supports, libvirt already supported mutiple console, see upstream commit 0873b688c).

* "p9fs": only support specifying the source dir, and mount tag, only type of 'mount' is supported.

* "memballoon": only virtio is supported, and there is no way to config the addr.

* Multiple "disk" and "p9fs" is supported.

* Graphics and network are not supported, will explain below.

Please see "[PATCH 7/8]" for an example of the domain config. (which contains all the XMLs supported by current implementation).

The problems of Native Linux KVM Tool from libvirt p.o.v:

* Some destros package "qemu-kvm" as "kvm", also "kvm" is a long established name for "KVM" itself, so naming the project as "kvm" might be not a good idea. I assume it will be named as "kvmtool" in this implementation, never mind this if you don't like that, it can be updated easily. :-)

* It still doesn't have an official package yet, even no "make install". means we have no way to check the dependancy and do the checking when 'configure'. I assume it will be installed as "/usr/bin/kvmtool" in this implementation. This is the main reason which can prevents upstream libvirt accepting the patches I guess.

* Lacks of options for user's configuration, such as "-vnc", there is no option for user to configure the properties for the "vnc", such as the port. It hides things, doesn't provide ways to query the properties too, this causes problems for libvirt to add the vnc support, as vnc clients such as virt-manager, virt-viewer, have no way to connect the guest. Even vncviewer can't.

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

* There is a gap about the domain status between KVM tool and libvirt, it's caused by KVM tool unlink()s the guest socket when user exits from console (both text and graphic), but libvirt still think the guest is running.

* KVM tool uses $HOME/.kvm_tool as the state dir, and no way to configure, I made a small patch to allow KVM tool accept a ENV variable, which is "KVM_STATE_DIR", it's used across the driver. I made a simple patch against kvm tool to let the whole patches work. See "[PATCH] kvm tools.....". As generally we want the state dir of a driver can be "/var/run/libvirt/kvmtool/..." for root user or "$HOME/.libvirt/kvmtool/run" for non-root user.

* kvmtoolGetVersion is just broken now, as what "./kvm version" returns is something like "3.0.rc5.873.gb73216", however, libvirt wants things like "2.6.40.6-0". This might be not a problem as long as KVM tool has a official package.

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

* It will be quite desireable if kvm tool could report the capabilities, of which is lacked by QEMU forever (seems so), it causes much pain for upper layer mgmt apps. See the RFC by Daniel Berrange in QEMU list for more details:

http://lists.nongnu.org/archive/html/qemu-devel/2010-06/msg00921.html

As a conclusion, it seems to me that KVM tool dosesn't consider too much about the interface for upper layer management tools, (generally, upper layer apps will want good interface to set/get), which might be no good for KVM tool future development.

Thoughts, and opinions? Thanks.

[PATCH 1/7] kvmtool: Add configure support
[PATCH] kvm tools: Introduce an ENV variable for the state dir [PATCH 2/7] kvmtool: Add documents
[PATCH 3/7] kvmtool: Add new enums and error codes for the driver [PATCH 4/7] kvmtool: Add hook support for kvmtool domain [PATCH 5/7] kvmtool: Add new domain type
[PATCH 6/7] conf: Set source type of the stub console [PATCH 7/7] kvmtool: Implementation for kvm tool driver

Regards,
Osier

--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list

author
#2 lore raw

PATCH 1/7 kvmtool: Add configure support

In reply to Osier Yang

Assumes the binary of "Native Linux KVM Tool" will be named as "kvmtool", and installed to "/usr/bin".

---
 configure.ac |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
configure.ac +24 -0
index 3b7535e..bcb2a40 100644
@@ -299,6 +299,8 @@ AC_ARG_WITH([esx],
   AC_HELP_STRING([--with-esx], [add ESX support @<:@default=check@:>@]),[],[with_esx=check])
 AC_ARG_WITH([hyperv],
   AC_HELP_STRING([--with-hyperv], [add Hyper-V support @<:@default=check@:>@]),[],[with_hyperv=check])
+AC_ARG_WITH([kvmtool],
+  AC_HELP_STRING([--with-kvmtool], [add kvm tool driver support @<:@default=yes@:>@]),[],[with_kvmtool=check])
 AC_ARG_WITH([test],
   AC_HELP_STRING([--with-test], [add test driver support @<:@default=yes@:>@]),[],[with_test=yes])
 AC_ARG_WITH([remote],
@@ -485,6 +487,27 @@ if test "$with_qemu" = "yes" ; then
 fi
 AM_CONDITIONAL([WITH_QEMU], [test "$with_qemu" = "yes"])
 
+dnl
+dnl Check if kvm tool binary available (Native Linux KVM Tool driver)
+dnl
+if test "$with_kvmtool" = "yes" || test "$with_kvmtool" = "check"; then
+  AC_PATH_PROG([KVMTOOL], [kvmtool], [], [$PATH:/sbin:/usr/sbin])
+
+  if test "$with_kvmtool" = "yes"; then
+    if test -z "$KVMTOOL"; then AC_MSG_ERROR([kvm tool binary is required for kvm tool driver]); fi
+  else
+    if test -z "$KVMTOOL"; then with_kvmtool=no; fi
+
+    if test "$with_kvmtool" = "check"; then with_kvmtool=yes; fi
+  fi
+
+  if test "$with_kvmtool" = "yes"; then
+    AC_DEFINE_UNQUOTED([WITH_KVMTOOL], 1, [whether kvm tool driver is enabled])
+    AC_DEFINE_UNQUOTED([KVMTOOL],["$KVMTOOL"],[Location of kvm tool binary])
+  fi
+fi
+AM_CONDITIONAL([WITH_KVMTOOL], [test "$with_kvmtool" = "yes"])
+
 if test "$with_test" = "yes" ; then
     AC_DEFINE_UNQUOTED([WITH_TEST], 1, [whether Test driver is enabled])
 fi
@@ -2509,6 +2532,7 @@ AC_MSG_NOTICE([     LXC: $with_lxc])
 AC_MSG_NOTICE([    PHYP: $with_phyp])
 AC_MSG_NOTICE([     ESX: $with_esx])
 AC_MSG_NOTICE([ Hyper-V: $with_hyperv])
+AC_MSG_NOTICE([ KVMTOOL: $with_kvmtool])
 AC_MSG_NOTICE([    Test: $with_test])
 AC_MSG_NOTICE([  Remote: $with_remote])
 AC_MSG_NOTICE([ Network: $with_network])
Signature · 1 line
1.7.6
author
#3 lore raw

PATCH 1/1 kvm tools: Introduce an ENV variable for the state dir

In reply to Osier Yang

Which is named as "KVMTOOL_STATE_DIR", so that the user can configure the path of state directly as he wants.

---
 tools/kvm/main.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tools/kvm/main.c +6 -1
index 05bc82c..37b2b1d 100644
@@ -13,7 +13,12 @@ static int handle_kvm_command(int argc, char **argv)
 
 int main(int argc, char *argv[])
 {
-	kvm__set_dir("%s/%s", HOME_DIR, KVM_PID_FILE_PATH);
+	char *state_dir = getenv("KVMTOOL_STATE_DIR");
+
+	if (state_dir)
+		kvm__set_dir("%s", state_dir);
+	else
+		kvm__set_dir("%s/%s", HOME_DIR, KVM_PID_FILE_PATH);
 
 	return handle_kvm_command(argc - 1, &argv[1]);
 }
Signature · 1 line
1.7.6
#4 lore raw

Re: [libvirt] [PATCH] kvm tools: Introduce an ENV variable for the state dir

Quoted 14 lines · Osier Yang

Which is named as "KVMTOOL_STATE_DIR", so that the user can configure the path of state directly as he wants.

---
 tools/kvm/main.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tools/kvm/main.c +0 -0
index 05bc82c..37b2b1d 100644
@@ -13,7 +13,12 @@ static int handle_kvm_command(int argc, char **argv)
 
 int main(int argc, char *argv[])
 {

tools/kvm/main.c static int handle_kvm_command(int argc, char **argv) · line 24

Quoted 10 lines
tools/kvm/main.c +6 -1
-	kvm__set_dir("%s/%s", HOME_DIR, KVM_PID_FILE_PATH);
+	char *state_dir = getenv("KVMTOOL_STATE_DIR");
+
+	if (state_dir)
+		kvm__set_dir("%s", state_dir);
+	else
+		kvm__set_dir("%s/%s", HOME_DIR, KVM_PID_FILE_PATH);
 
 	return handle_kvm_command(argc - 1, &argv[1]);
 }

As per my comments in the first patch, I don't think this is critical for libvirt's needs. We should just honour the default location that the KVM tool uses, rather than forcing a libvirt specific location.

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#5 lore raw

Re: [libvirt] [PATCH] kvm tools: Introduce an ENV variable for the state dir

Quoted 23 lines · Daniel P. Berrange
Quoted 22 lines · Osier Yang

Which is named as "KVMTOOL_STATE_DIR", so that the user can configure the path of state directly as he wants.

---
  tools/kvm/main.c |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
tools/kvm/main.c +6 -1
index 05bc82c..37b2b1d 100644
@@ -13,7 +13,12 @@ static int handle_kvm_command(int argc, char **argv)
 
  int main(int argc, char *argv[])
  {
-	kvm__set_dir("%s/%s", HOME_DIR, KVM_PID_FILE_PATH);
+	char *state_dir = getenv("KVMTOOL_STATE_DIR");
+
+	if (state_dir)
+		kvm__set_dir("%s", state_dir);
+	else
+		kvm__set_dir("%s/%s", HOME_DIR, KVM_PID_FILE_PATH);
 
Quoted 7 lines

tools/kvm/main.c static int handle_kvm_command(int argc, char **argv) · line 24

Quoted 2 lines
tools/kvm/main.c +0 -0
  	return handle_kvm_command(argc - 1,&argv[1]);
  }

As per my comments in the first patch, I don't think this is critical for libvirt's needs. We should just honour the default location that the KVM tool uses, rather than forcing a libvirt specific location.

Thanks for the guy who pushed the patch, it's already in kvmtool's
source. It will be useful when we run the kvmtool process as non-priviledge user and group.

Regards,
Osier

author
#6 lore raw

PATCH 2/7 kvmtool: Add documents

In reply to Osier Yang

The document is rather rough now, but at least contains an domain config example of all the current supported XMLs, and tells how to play with the driver.

---
 docs/drivers.html.in    |    1 +
 docs/drvkvmtool.html.in |   87 +++++++++++++++++++++++++++++++++++++++++++++++
 docs/index.html.in      |    3 ++
 docs/sitemap.html.in    |    4 ++
 src/README              |    3 +-
 5 files changed, 97 insertions(+), 1 deletions(-)
 create mode 100644 docs/drvkvmtool.html.in
docs/drivers.html.in +1 -0
index 75038fc..249c137 100644
@@ -29,6 +29,7 @@
       <li><strong><a href="drvvmware.html">VMware Workstation/Player</a></strong></li>
       <li><strong><a href="drvxen.html">Xen</a></strong></li>
       <li><strong><a href="drvhyperv.html">Microsoft Hyper-V</a></strong></li>
+      <li><strong><a href="drvkvmtool.html">Native Linux KVM Tool</a></strong></li>
     </ul>
 
     <h2><a name="stroage">Storage drivers</a></h2>
docs/drvkvmtool.html.in new file +87 -0

87 lines not on this page · raw message

docs/index.html.in +3 -0
index c84eb1f..fcb7b1d 100644
@@ -63,6 +63,9 @@
         The <a href="http://libvirt.org/drvhyperv.html">Microsoft Hyper-V</a> hypervisor
       </li>
       <li>
+        The <a href="http://libvirt.org/drvkvmtool.html">Native Linux KVM Tool</a> hypervisor
+      </li>
+      <li>
         Virtual networks using bridging, NAT, VEPA and VN-LINK.
       </li>
       <li>
docs/sitemap.html.in +4 -0
index 1de2b20..0816190 100644
@@ -210,6 +210,10 @@
                 <a href="drvhyperv.html">Microsoft Hyper-V</a>
                 <span>Driver for Microsoft Hyper-V</span>
               </li>
+              <li>
+                <a href="drvkvmtool.html">Native Linux KVM Tool</a>
+                <span>Driver for Native Linux KVM Tool</span>
+              </li>
             </ul>
           </li>
           <li>
src/README +2 -1
index 00d11d1..de1720b 100644
@@ -27,6 +27,7 @@ Then there are the hypervisor implementations:
 
  * esx/          - VMware ESX and GSX support using vSphere API over SOAP
  * hyperv/       - Microsoft Hyper-V support using WinRM
+ * kvm/          - Native Linux KVM Tool support using CLI
  * lxc/          - Linux Native Containers
  * openvz/       - OpenVZ containers using cli tools
  * phyp/         - IBM Power Hypervisor using CLI tools over SSH
@@ -41,7 +42,7 @@ Then there are the hypervisor implementations:
 
 
 Finally some secondary drivers that are shared for several HVs.
-Currently these are used by LXC, OpenVZ, QEMU, UML and Xen drivers.
+Currently these are used by LXC, OpenVZ, QEMU, UML, KVMTOOL, and Xen drivers.
 The ESX, Hyper-V, Power Hypervisor, Remote, Test & VirtualBox drivers all
 implement the secondary drivers directly
 
Signature · 1 line
1.7.6
#7 lore raw

Re: [libvirt] [PATCH 2/7] kvmtool: Add documents

Quoted 63 lines · Osier Yang

The document is rather rough now, but at least contains an domain config example of all the current supported XMLs, and tells how to play with the driver.

---
 docs/drivers.html.in    |    1 +
 docs/drvkvmtool.html.in |   87 +++++++++++++++++++++++++++++++++++++++++++++++
 docs/index.html.in      |    3 ++
 docs/sitemap.html.in    |    4 ++
 src/README              |    3 +-
 5 files changed, 97 insertions(+), 1 deletions(-)
 create mode 100644 docs/drvkvmtool.html.in
docs/drivers.html.in +1 -0
index 75038fc..249c137 100644
@@ -29,6 +29,7 @@
       <li><strong><a href="drvvmware.html">VMware Workstation/Player</a></strong></li>
       <li><strong><a href="drvxen.html">Xen</a></strong></li>
       <li><strong><a href="drvhyperv.html">Microsoft Hyper-V</a></strong></li>
+      <li><strong><a href="drvkvmtool.html">Native Linux KVM Tool</a></strong></li>
     </ul>
 
     <h2><a name="stroage">Storage drivers</a></h2>
docs/drvkvmtool.html.in new file +33 -0
new file mode 100644
index 0000000..1b6acdf
@@ -0,0 +1,87 @@
+<html>
+  <body>
+    <h1>KVM tool driver</h1>
+
+    <ul id="toc"></ul>
+
+    <p>
+      The libvirt KVMTOOL driver manages hypervisor Native Linux KVM Tool,
+      it's implemented by using command line of kvm tool binary.
+    </p>
+
+    <h2><a name="project">Project Links</a></h2>
+
+    <ul>
+      <li>
+        The <a href="git://github.com/penberg/linux-kvm.git">Native Linux KVM Tool</a> Native
+        Linux KVM Tool
+      </li>
+    </ul>
+
+    <h2><a name="uris">Connections to the KVMTOOL driver</a></h2>
+    <p>
+      The libvirt KVMTOOL driver is a multi-instance driver, providing a single
+      system wide privileged driver (the "system" instance), and per-user
+      unprivileged drivers (the "session" instance). The URI driver protocol
+      is "kvmtool". Some example conection URIs for the libvirt driver are:
+    </p>
+
+    <pre>
+      kvmtool:///session                      (local access to per-user instance)
+      kvmtool+unix:///session                 (local access to per-user instance)
+
+      kvmtool:///system                       (local access to system instance)

docs/drvkvmtool.html.in line 43

Quoted 10 lines
docs/drvkvmtool.html.in new file +10 -0
+      kvmtool+unix:///system                  (local access to system instance)
+    </pre>
+    <p>
+      cgroups controllers "cpuacct", and "memory" are supported currently.
+    </p>
+
+  <h3>Example config</h3>
+
+  <pre>
+&lt;domain type='kvmtool' id='1'&gt;

As mentioned in a later patch, we should just use type='kvm' here still

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#8 lore raw

PATCH 3/7 kvmtool: Add new enums and error codes for the driver

In reply to Osier Yang
---
 include/libvirt/virterror.h |    1 +
 src/driver.h                |    1 +
 src/util/virterror.c        |    3 +++
 3 files changed, 5 insertions(+), 0 deletions(-)
include/libvirt/virterror.h +1 -0
index a8549b7..deda42d 100644
@@ -84,6 +84,7 @@ typedef enum {
     VIR_FROM_LIBXL = 41,	/* Error from libxenlight driver */
     VIR_FROM_LOCKING = 42,	/* Error from lock manager */
     VIR_FROM_HYPERV = 43,	/* Error from Hyper-V driver */
+    VIR_FROM_KVMTOOL = 44,	/* Error from kvm tool driver */
 } virErrorDomain;
 
 
src/driver.h +1 -0
index 4c14aaa..158a13c 100644
@@ -30,6 +30,7 @@ typedef enum {
     VIR_DRV_VMWARE = 13,
     VIR_DRV_LIBXL = 14,
     VIR_DRV_HYPERV = 15,
+    VIR_DRV_KVMTOOL = 16,
 } virDrvNo;
 
 
src/util/virterror.c +3 -0
index 5006fa2..abb5b5a 100644
@@ -175,6 +175,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
         case VIR_FROM_HYPERV:
             dom = "Hyper-V ";
             break;
+        case VIR_FROM_KVMTOOL:
+            dom = "KVMTOOL ";
+            break;
     }
     return(dom);
 }
Signature · 1 line
1.7.6
#9 lore raw

Re: [libvirt] [PATCH 3/7] kvmtool: Add new enums and error codes for the driver

Quoted 35 lines · Osier Yang
---
 include/libvirt/virterror.h |    1 +
 src/driver.h                |    1 +
 src/util/virterror.c        |    3 +++
 3 files changed, 5 insertions(+), 0 deletions(-)
include/libvirt/virterror.h +1 -0
index a8549b7..deda42d 100644
@@ -84,6 +84,7 @@ typedef enum {
     VIR_FROM_LIBXL = 41,	/* Error from libxenlight driver */
     VIR_FROM_LOCKING = 42,	/* Error from lock manager */
     VIR_FROM_HYPERV = 43,	/* Error from Hyper-V driver */
+    VIR_FROM_KVMTOOL = 44,	/* Error from kvm tool driver */
 } virErrorDomain;
 
 
src/driver.h +1 -0
index 4c14aaa..158a13c 100644
@@ -30,6 +30,7 @@ typedef enum {
     VIR_DRV_VMWARE = 13,
     VIR_DRV_LIBXL = 14,
     VIR_DRV_HYPERV = 15,
+    VIR_DRV_KVMTOOL = 16,
 } virDrvNo;
 
 
src/util/virterror.c +0 -0
index 5006fa2..abb5b5a 100644

src/util/virterror.c static const char *virErrorDomainName(virErrorDomain domain) { · line 183

Quoted 9 lines
src/util/virterror.c +3 -0
@@ -175,6 +175,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
         case VIR_FROM_HYPERV:
             dom = "Hyper-V ";
             break;
+        case VIR_FROM_KVMTOOL:
+            dom = "KVMTOOL ";
+            break;
     }
     return(dom);
 }

Trivial, ACK

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#10 lore raw

PATCH 4/7 kvmtool: Add hook support for kvmtool domain

In reply to Osier Yang

Just like QEMU and LXC, kvm driver intends to support running hook script before domain starting and after domain shutdown too.

---
 src/util/hooks.c |   11 ++++++++++-
 src/util/hooks.h |    8 ++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
src/util/hooks.c +10 -1
index 110a94b..765cb68 100644
@@ -52,12 +52,14 @@ VIR_ENUM_DECL(virHookDaemonOp)
 VIR_ENUM_DECL(virHookSubop)
 VIR_ENUM_DECL(virHookQemuOp)
 VIR_ENUM_DECL(virHookLxcOp)
+VIR_ENUM_DECL(virHookKvmToolOp)
 
 VIR_ENUM_IMPL(virHookDriver,
               VIR_HOOK_DRIVER_LAST,
               "daemon",
               "qemu",
-              "lxc")
+              "lxc",
+              "kvmtool")
 
 VIR_ENUM_IMPL(virHookDaemonOp, VIR_HOOK_DAEMON_OP_LAST,
               "start",
@@ -79,6 +81,10 @@ VIR_ENUM_IMPL(virHookLxcOp, VIR_HOOK_LXC_OP_LAST,
               "start",
               "stopped")
 
+VIR_ENUM_IMPL(virHookKvmToolOp, VIR_HOOK_KVMTOOL_OP_LAST,
+              "start",
+              "stopped")
+
 static int virHooksFound = -1;
 
 /**
@@ -230,6 +236,9 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
         case VIR_HOOK_DRIVER_LXC:
             opstr = virHookLxcOpTypeToString(op);
             break;
+        case VIR_HOOK_DRIVER_KVMTOOL:
+            opstr = virHookKvmToolOpTypeToString(op);
+            break;
     }
     if (opstr == NULL) {
         virHookReportError(VIR_ERR_INTERNAL_ERROR,
src/util/hooks.h +8 -0
index fd7411c..69081c4 100644
@@ -31,6 +31,7 @@ enum virHookDriverType {
     VIR_HOOK_DRIVER_DAEMON = 0,        /* Daemon related events */
     VIR_HOOK_DRIVER_QEMU,              /* QEmu domains related events */
     VIR_HOOK_DRIVER_LXC,               /* LXC domains related events */
+    VIR_HOOK_DRIVER_KVMTOOL,           /* KVMTOOL domains related events */
 
     VIR_HOOK_DRIVER_LAST,
 };
@@ -67,6 +68,13 @@ enum virHookLxcOpType {
     VIR_HOOK_LXC_OP_LAST,
 };
 
+enum virHookKvmToolOpType {
+    VIR_HOOK_KVMTOOL_OP_START,            /* domain is about to start */
+    VIR_HOOK_KVMTOOL_OP_STOPPED,          /* domain has stopped */
+
+    VIR_HOOK_KVMTOOL_OP_LAST,
+};
+
 int virHookInitialize(void);
 
 int virHookPresent(int driver);
Signature · 1 line
1.7.6
#11 lore raw

Re: [libvirt] [PATCH 4/7] kvmtool: Add hook support for kvmtool domain

Quoted 64 lines · Osier Yang

Just like QEMU and LXC, kvm driver intends to support running hook script before domain starting and after domain shutdown too.

---
 src/util/hooks.c |   11 ++++++++++-
 src/util/hooks.h |    8 ++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
src/util/hooks.c +10 -1
index 110a94b..765cb68 100644
@@ -52,12 +52,14 @@ VIR_ENUM_DECL(virHookDaemonOp)
 VIR_ENUM_DECL(virHookSubop)
 VIR_ENUM_DECL(virHookQemuOp)
 VIR_ENUM_DECL(virHookLxcOp)
+VIR_ENUM_DECL(virHookKvmToolOp)
 
 VIR_ENUM_IMPL(virHookDriver,
               VIR_HOOK_DRIVER_LAST,
               "daemon",
               "qemu",
-              "lxc")
+              "lxc",
+              "kvmtool")
 
 VIR_ENUM_IMPL(virHookDaemonOp, VIR_HOOK_DAEMON_OP_LAST,
               "start",
@@ -79,6 +81,10 @@ VIR_ENUM_IMPL(virHookLxcOp, VIR_HOOK_LXC_OP_LAST,
               "start",
               "stopped")
 
+VIR_ENUM_IMPL(virHookKvmToolOp, VIR_HOOK_KVMTOOL_OP_LAST,
+              "start",
+              "stopped")
+
 static int virHooksFound = -1;
 
 /**
@@ -230,6 +236,9 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
         case VIR_HOOK_DRIVER_LXC:
             opstr = virHookLxcOpTypeToString(op);
             break;
+        case VIR_HOOK_DRIVER_KVMTOOL:
+            opstr = virHookKvmToolOpTypeToString(op);
+            break;
     }
     if (opstr == NULL) {
         virHookReportError(VIR_ERR_INTERNAL_ERROR,
src/util/hooks.h +1 -0
index fd7411c..69081c4 100644
@@ -31,6 +31,7 @@ enum virHookDriverType {
     VIR_HOOK_DRIVER_DAEMON = 0,        /* Daemon related events */
     VIR_HOOK_DRIVER_QEMU,              /* QEmu domains related events */
     VIR_HOOK_DRIVER_LXC,               /* LXC domains related events */
+    VIR_HOOK_DRIVER_KVMTOOL,           /* KVMTOOL domains related events */
 
     VIR_HOOK_DRIVER_LAST,
 };
@@ -67,6 +68,13 @@ enum virHookLxcOpType {
     VIR_HOOK_LXC_OP_LAST,
 };
 

src/util/hooks.h enum virHookLxcOpType { · line 80

Quoted 10 lines
src/util/hooks.h +7 -0
+enum virHookKvmToolOpType {
+    VIR_HOOK_KVMTOOL_OP_START,            /* domain is about to start */
+    VIR_HOOK_KVMTOOL_OP_STOPPED,          /* domain has stopped */
+
+    VIR_HOOK_KVMTOOL_OP_LAST,
+};
+
 int virHookInitialize(void);
 
 int virHookPresent(int driver);

Trivial, ACK

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#12 lore raw

PATCH 5/7 kvmtool: Add new domain type

In reply to Osier Yang

It's named as "kvmtool".

---
 src/conf/domain_conf.c |    4 +++-
 src/conf/domain_conf.h |    1 +
 2 files changed, 4 insertions(+), 1 deletions(-)
src/conf/domain_conf.c +3 -1
index 58f4d0f..55121d8 100644
@@ -91,7 +91,8 @@ VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
               "hyperv",
               "vbox",
               "one",
-              "phyp")
+              "phyp",
+              "kvmtool")
 
 VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
               "fd",
@@ -4018,6 +4019,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
     if (type == NULL) {
         def->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
     } else if ((def->source.type = virDomainChrTypeFromString(type)) < 0) {
+        VIR_WARN("type = %s", type);
         virDomainReportError(VIR_ERR_XML_ERROR,
                              _("unknown type presented to host for character device: %s"),
                              type);
src/conf/domain_conf.h +1 -0
index a3cb834..001bc46 100644
@@ -59,6 +59,7 @@ enum virDomainVirtType {
     VIR_DOMAIN_VIRT_VBOX,
     VIR_DOMAIN_VIRT_ONE,
     VIR_DOMAIN_VIRT_PHYP,
+    VIR_DOMAIN_VIRT_KVMTOOL,
 
     VIR_DOMAIN_VIRT_LAST,
 };
Signature · 1 line
1.7.6
#13 lore raw

Re: [libvirt] [PATCH 5/7] kvmtool: Add new domain type

Quoted 33 lines · Osier Yang

It's named as "kvmtool".

---
 src/conf/domain_conf.c |    4 +++-
 src/conf/domain_conf.h |    1 +
 2 files changed, 4 insertions(+), 1 deletions(-)
src/conf/domain_conf.c +3 -1
index 58f4d0f..55121d8 100644
@@ -91,7 +91,8 @@ VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
               "hyperv",
               "vbox",
               "one",
-              "phyp")
+              "phyp",
+              "kvmtool")
 
 VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
               "fd",
@@ -4018,6 +4019,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
     if (type == NULL) {
         def->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
     } else if ((def->source.type = virDomainChrTypeFromString(type)) < 0) {
+        VIR_WARN("type = %s", type);
         virDomainReportError(VIR_ERR_XML_ERROR,
                              _("unknown type presented to host for character device: %s"),
                              type);
src/conf/domain_conf.h +0 -0
index a3cb834..001bc46 100644

src/conf/domain_conf.h enum virDomainVirtType { · line 65

Quoted 7 lines
src/conf/domain_conf.h +1 -0
@@ -59,6 +59,7 @@ enum virDomainVirtType {
     VIR_DOMAIN_VIRT_VBOX,
     VIR_DOMAIN_VIRT_ONE,
     VIR_DOMAIN_VIRT_PHYP,
+    VIR_DOMAIN_VIRT_KVMTOOL,
 
     VIR_DOMAIN_VIRT_LAST,
 };

IMHO this patch is not required. The domain type is refering to the hypervisor used for the domain, which is still 'kvm'. What is different here is just the userspace device model. If you look at the 3 different Xen user spaces we support, all of them use <domain type='xen'> still. So just use <domain type='kvm'> here for kvmtool.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#14 lore raw

Re: [libvirt] [PATCH 5/7] kvmtool: Add new domain type

Quoted 39 lines · Daniel P. Berrange
Quoted 38 lines · Osier Yang

It's named as "kvmtool".

---
  src/conf/domain_conf.c |    4 +++-
  src/conf/domain_conf.h |    1 +
  2 files changed, 4 insertions(+), 1 deletions(-)
src/conf/domain_conf.c +3 -1
index 58f4d0f..55121d8 100644
@@ -91,7 +91,8 @@ VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
                "hyperv",
                "vbox",
                "one",
-              "phyp")
+              "phyp",
+              "kvmtool")
 
  VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
                "fd",
@@ -4018,6 +4019,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
      if (type == NULL) {
          def->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
      } else if ((def->source.type = virDomainChrTypeFromString(type))<  0) {
+        VIR_WARN("type = %s", type);
          virDomainReportError(VIR_ERR_XML_ERROR,
                               _("unknown type presented to host for character device: %s"),
                               type);
src/conf/domain_conf.h +1 -0
index a3cb834..001bc46 100644
@@ -59,6 +59,7 @@ enum virDomainVirtType {
      VIR_DOMAIN_VIRT_VBOX,
      VIR_DOMAIN_VIRT_ONE,
      VIR_DOMAIN_VIRT_PHYP,
+    VIR_DOMAIN_VIRT_KVMTOOL,
 
Quoted 9 lines

src/conf/domain_conf.h enum virDomainVirtType { · line 65

Quoted 2 lines
src/conf/domain_conf.h +0 -0
      VIR_DOMAIN_VIRT_LAST,
  };

IMHO this patch is not required. The domain type is refering to the hypervisor used for the domain, which is still 'kvm'. What is different here is just the userspace device model. If you look at the 3 different Xen user spaces we support, all of them use<domain type='xen'> still. So just use<domain type='kvm'> here for kvmtool.

Make sense, agreed.

Osier

author
#15 lore raw

PATCH 6/7 conf: Set source type of the stub console

In reply to Osier Yang

As "serials[0]->source.type". This is for kvm tool driver only supports one console currently, and it setup ptys (redirect the stdout/stderr of kvm tool process to the master pty, and the slave pty path will be set to source path of the console) for connect to the guest via console. If the console config is like:

      <console type='pty'>
        <target type='serial' port='0'/>
      </console>

Things don't work, as kvm tool driver only tries to find consoles and set the slave pty path to "consoles[0]->source.path". Though another solution is to set the slave pty path to "serials[0]->source.path" if no console of type "pty" can be found.

---
 src/conf/domain_conf.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
src/conf/domain_conf.c +1 -0
index 55121d8..138105e 100644
@@ -7287,6 +7287,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
                 goto no_memory;
             chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
             chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
+            chr->source.type = def->serials[0]->source.type;
         }
 
         chr->target.port = i;
Signature · 1 line
1.7.6
author
#16 lore raw

PATCH 7/7 kvmtool: Implementation for kvm tool driver

In reply to Osier Yang

Basically, the drivers is implemented by using kvm tool binary currently, (see ./kvm help for more info).

Current implementation supports define/undefine, start/destroy/, suspend/resume, connect to guest console via "virsh console", and balloon memory with with "virsh setmem" (using ./kvm balloon command). Also as it supports cgroup controllers "cpuacct", and "memory", so some other commands like "schedinfo", "memtune" can also work. Some other commands such as "domid", "domname", "dumpxml" ,"autostart", etc. are supported, as the driver is designed as a "stateful" driver, those APIs just need to talk with libvirtd simply.

As Native Linux KVM Tool is designed for both non-root and root users, the driver is designed just like QEMU, supports two modes of the connection:

kvmtool:///system
kvmtool+unix:///system

kvmtool:///session
kvmtool+unix:///session

An example of the domain XML (all the XMLs supported currently are listed):

% virsh -c kvm:///system dumpxml kvm_test <domain type='kvmtool'>
<name>kvm_test</name> <uuid>88bf38f1-b6ab-cfa6-ab53-4b4c0993d894</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu>
<os>

    <type arch='x86_64'>hvm</type>
    <kernel>/boot/bzImage</kernel>
    <boot dev='hd'/>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/kvmtool</emulator>
    <disk type='file' device='disk'>
      <source file='/var/lib/libvirt/images/linux-0.2.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/tmp'/>
      <target dir='/mnt'/>
    </filesystem>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <memballoon model='virtio'/>
  </devices>
</domain>
---
 cfg.mk                       |    1 +
 daemon/Makefile.am           |    4 +
 daemon/libvirtd.c            |    7 +
 po/POTFILES.in               |    2 +
 src/Makefile.am              |   36 +-
 src/kvmtool/kvmtool_conf.c   |  130 ++
 src/kvmtool/kvmtool_conf.h   |   66 +
 src/kvmtool/kvmtool_driver.c | 3079 ++++++++++++++++++++++++++++++++++++++++++
 src/kvmtool/kvmtool_driver.h |   29 +
 9 files changed, 3353 insertions(+), 1 deletions(-)
 create mode 100644 src/kvmtool/kvmtool_conf.c
 create mode 100644 src/kvmtool/kvmtool_conf.h
 create mode 100644 src/kvmtool/kvmtool_driver.c
 create mode 100644 src/kvmtool/kvmtool_driver.h
cfg.mk +1 -0
index 574c7a4..d8e8fac 100644
@@ -472,6 +472,7 @@ msg_gen_function += eventReportError
 msg_gen_function += ifaceError
 msg_gen_function += interfaceReportError
 msg_gen_function += iptablesError
+msg_gen_function += kvmtoolError
 msg_gen_function += lxcError
 msg_gen_function += libxlError
 msg_gen_function += macvtapError
daemon/Makefile.am +4 -0
index e8c47ae..5941c21 100644
@@ -133,6 +133,10 @@ if WITH_UML
     libvirtd_LDADD += ../src/libvirt_driver_uml.la
 endif
 
+if WITH_KVMTOOL
+    libvirtd_LDADD += ../src/libvirt_driver_kvmtool.la
+endif
+
 if WITH_STORAGE_DIR
     libvirtd_LDADD += ../src/libvirt_driver_storage.la
 endif
daemon/libvirtd.c +7 -0
index 5e1fc96..f01fecb 100644
@@ -70,6 +70,9 @@
 # ifdef WITH_UML
 #  include "uml/uml_driver.h"
 # endif
+# ifdef WITH_KVMTOOL
+#  include "kvmtool/kvmtool_driver.h"
+# endif
 # ifdef WITH_NETWORK
 #  include "network/bridge_driver.h"
 # endif
@@ -382,6 +385,7 @@ static void daemonInitialize(void)
     virDriverLoadModule("qemu");
     virDriverLoadModule("lxc");
     virDriverLoadModule("uml");
+    virDriverLoadModule("kvmtool");
     virDriverLoadModule("nwfilter");
 #else
 # ifdef WITH_NETWORK
@@ -414,6 +418,9 @@ static void daemonInitialize(void)
 # ifdef WITH_UML
     umlRegister();
 # endif
+# ifdef WITH_KVMTOOL
+    kvmtoolRegister();
+# endif
 #endif
 }
 
po/POTFILES.in +2 -0
index a3685e8..1f80e98 100644
@@ -153,3 +153,5 @@ src/xenxs/xen_xm.c
 tools/console.c
 tools/libvirt-guests.init.sh
 tools/virsh.c
+src/kvmtool/kvmtool_driver.c
+src/kvmtool/kvmtool_conf.c
src/Makefile.am +35 -1
index e931d41..d0115ac 100644
@@ -442,6 +442,10 @@ HYPERV_DRIVER_EXTRA_DIST =							\
 		hyperv/hyperv_wmi_generator.py					\
 		$(HYPERV_DRIVER_GENERATED)
 
+KVMTOOL_DRIVER_SOURCES = \
+		kvmtool/kvmtool_conf.c kvmtool/kvmtool_conf.h \
+		kvmtool/kvmtool_driver.h kvmtool/kvmtool_driver.c
+
 NETWORK_DRIVER_SOURCES =					\
 		network/bridge_driver.h network/bridge_driver.c
 
@@ -906,6 +910,25 @@ endif
 libvirt_driver_hyperv_la_SOURCES = $(HYPERV_DRIVER_SOURCES)
 endif
 
+if WITH_KVMTOOL
+if WITH_DRIVER_MODULES
+mod_LTLIBRARIES += libvirt_driver_kvmtool.la
+else
+noinst_LTLIBRARIES += libvirt_driver_kvmtool.la
+# Stateful, so linked to daemon instead
+#libvirt_la_BUILT_LIBADD += libvirt_driver_kvmtool.la
+endif
+libvirt_driver_kvmtool_la_CFLAGS = \
+                               -I@top_srcdir@/src/conf $(AM_CFLAGS)
+libvirt_driver_kvmtool_la_LDFLAGS = $(AM_LDFLAGS)
+if WITH_DRIVER_MODULES
+libvirt_driver_kvmtool_la_LIBADD = ../gnulib/lib/libgnu.la
+libvirt_driver_kvmtool_la_LDFLAGS += -module -avoid-version
+endif
+libvirt_driver_kvmtool_la_SOURCES = $(KVMTOOL_DRIVER_SOURCES)
+endif
+
+
 if WITH_NETWORK
 if WITH_DRIVER_MODULES
 mod_LTLIBRARIES += libvirt_driver_network.la
@@ -1101,11 +1124,12 @@ EXTRA_DIST +=							\
 		$(PHYP_DRIVER_SOURCES)				\
 		$(VBOX_DRIVER_SOURCES)				\
 		$(XENAPI_DRIVER_SOURCES)			\
-		$(LIBXL_DRIVER_SOURCES)			\
+		$(LIBXL_DRIVER_SOURCES)				\
 		$(ESX_DRIVER_SOURCES)				\
 		$(ESX_DRIVER_EXTRA_DIST)			\
 		$(HYPERV_DRIVER_SOURCES)			\
 		$(HYPERV_DRIVER_EXTRA_DIST)			\
+		$(KVMTOOL_DRIVER_SOURCES)			\
 		$(NETWORK_DRIVER_SOURCES)			\
 		$(INTERFACE_DRIVER_SOURCES)			\
 		$(STORAGE_DRIVER_SOURCES)			\
@@ -1554,6 +1578,11 @@ if WITH_UML
 	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/uml"
 	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/uml"
 endif
+if WITH_KVMTOOL
+	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/kvmtool"
+	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/kvmtool"
+	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/libvirt/kvmtool"
+endif
 if WITH_NETWORK
 	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/network"
 	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/dnsmasq"
@@ -1600,6 +1629,11 @@ if WITH_UML
 	rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/uml" ||:
 	rmdir "$(DESTDIR)$(localstatedir)/run/libvirt/uml" ||:
 endif
+if WITH_KVMTOOL
+       rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/kvmtool" ||:
+       rmdir "$(DESTDIR)$(localstatedir)/run/libvirt/kvmtool" ||:
+       rmdir "$(DESTDIR)$(localstatedir)/log/libvirt/kvmtool" ||:
+endif
 if WITH_NETWORK
 	rm -f $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/autostart/default.xml
 	rm -f $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/default.xml
src/kvmtool/kvmtool_conf.c new file +130 -0

130 lines not on this page · raw message

src/kvmtool/kvmtool_conf.h new file +66 -0

66 lines not on this page · raw message

src/kvmtool/kvmtool_driver.c new file +3079 -0

2,687 lines not on this page · raw message

src/kvmtool/kvmtool_driver.h new file +29 -0
new file mode 100644
index 0000000..84cc3db

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.6

Part of the diff is not shown here. View the raw message.

#17 lore raw

Re: [libvirt] [PATCH 7/7] kvmtool: Implementation for kvm tool driver

Quoted 60 lines · Osier Yang

Basically, the drivers is implemented by using kvm tool binary currently, (see ./kvm help for more info).

Current implementation supports define/undefine, start/destroy/, suspend/resume, connect to guest console via "virsh console", and balloon memory with with "virsh setmem" (using ./kvm balloon command). Also as it supports cgroup controllers "cpuacct", and "memory", so some other commands like "schedinfo", "memtune" can also work. Some other commands such as "domid", "domname", "dumpxml" ,"autostart", etc. are supported, as the driver is designed as a "stateful" driver, those APIs just need to talk with libvirtd simply.

As Native Linux KVM Tool is designed for both non-root and root users, the driver is designed just like QEMU, supports two modes of the connection:

kvmtool:///system
kvmtool+unix:///system

kvmtool:///session
kvmtool+unix:///session

An example of the domain XML (all the XMLs supported currently are listed):

% virsh -c kvm:///system dumpxml kvm_test <domain type='kvmtool'>
<name>kvm_test</name> <uuid>88bf38f1-b6ab-cfa6-ab53-4b4c0993d894</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu>
<os>

    <type arch='x86_64'>hvm</type>
    <kernel>/boot/bzImage</kernel>
    <boot dev='hd'/>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/kvmtool</emulator>
    <disk type='file' device='disk'>
      <source file='/var/lib/libvirt/images/linux-0.2.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/tmp'/>
      <target dir='/mnt'/>
    </filesystem>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <memballoon model='virtio'/>
  </devices>
</domain>
---
 cfg.mk                       |    1 +
Quoted 8 lines
 daemon/Makefile.am           |    4 +
 daemon/libvirtd.c            |    7 +
 po/POTFILES.in               |    2 +
 src/Makefile.am              |   36 +-
 src/kvmtool/kvmtool_conf.c   |  130 ++
 src/kvmtool/kvmtool_conf.h   |   66 +
 src/kvmtool/kvmtool_driver.c | 3079 ++++++++++++++++++++++++++++++++++++++++++
 src/kvmtool/kvmtool_driver.h |   29 +

My main suggestion here would be to split up the kvmtool_driver.c file into 3 parts as we did with the QEMU driver.

  kvmtool_driver.c   -> Basic libvirt API glue
  kvmtool_command.c  -> ARGV generation
  kvmtool_process.c  -> KVMtool process start/stop/autostart/autodestroy

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#18 lore raw

Re: [libvirt] [PATCH 7/7] kvmtool: Implementation for kvm tool driver

Quoted 70 lines · Daniel P. Berrange
Quoted 60 lines · Osier Yang

Basically, the drivers is implemented by using kvm tool binary currently, (see ./kvm help for more info).

Current implementation supports define/undefine, start/destroy/, suspend/resume, connect to guest console via "virsh console", and balloon memory with with "virsh setmem" (using ./kvm balloon command). Also as it supports cgroup controllers "cpuacct", and "memory", so some other commands like "schedinfo", "memtune" can also work. Some other commands such as "domid", "domname", "dumpxml" ,"autostart", etc. are supported, as the driver is designed as a "stateful" driver, those APIs just need to talk with libvirtd simply.

As Native Linux KVM Tool is designed for both non-root and root users, the driver is designed just like QEMU, supports two modes of the connection:

kvmtool:///system
kvmtool+unix:///system

kvmtool:///session
kvmtool+unix:///session

An example of the domain XML (all the XMLs supported currently are listed):

% virsh -c kvm:///system dumpxml kvm_test <domain type='kvmtool'>
<name>kvm_test</name> <uuid>88bf38f1-b6ab-cfa6-ab53-4b4c0993d894</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu>
<os>

     <type arch='x86_64'>hvm</type>
     <kernel>/boot/bzImage</kernel>
     <boot dev='hd'/>
   </os>
   <clock offset='utc'/>
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>restart</on_reboot>
   <on_crash>restart</on_crash>
   <devices>
     <emulator>/usr/bin/kvmtool</emulator>
     <disk type='file' device='disk'>
       <source file='/var/lib/libvirt/images/linux-0.2.img'/>
       <target dev='vda' bus='virtio'/>
     </disk>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/tmp'/>
       <target dir='/mnt'/>
     </filesystem>
     <console type='pty'>
       <target type='serial' port='0'/>
     </console>
     <memballoon model='virtio'/>
   </devices>
</domain>
---
  cfg.mk                       |    1 +
Quoted 8 lines
  daemon/Makefile.am           |    4 +
  daemon/libvirtd.c            |    7 +
  po/POTFILES.in               |    2 +
  src/Makefile.am              |   36 +-
  src/kvmtool/kvmtool_conf.c   |  130 ++
  src/kvmtool/kvmtool_conf.h   |   66 +
  src/kvmtool/kvmtool_driver.c | 3079 ++++++++++++++++++++++++++++++++++++++++++
  src/kvmtool/kvmtool_driver.h |   29 +
Quoted 7 lines

My main suggestion here would be to split up the kvmtool_driver.c file into 3 parts as we did with the QEMU driver.

   kvmtool_driver.c   ->  Basic libvirt API glue
   kvmtool_command.c  ->  ARGV generation
   kvmtool_process.c  ->  KVMtool process start/stop/autostart/autodestroy

Agreed. As a early thinking, kvmtool might has APIs exposed in future, how should we plan for it? A new driver just like libxl for XEN? or new backend driver like what we do for xm, xend for XEN driver? Should we consider the expansibility currently if we tend to use backend drivers?

Regards,
Osier

#19 lore raw
In reply to Osier Yang
Quoted 50 lines · Osier Yang

Hi, all

This is a basic implementation of libvirt Native Linux KVM Tool driver. Note that this is just made with my own interest and spare time, it's not an endorsement/effort by Red Hat, and it isn't supported by Red Hat officially.

Basically, the driver is designed as *stateful*, as KVM tool doesn't maintain any info about the guest except a socket which for its own IPC. And it's implemented by using KVM tool binary, which is name "kvm" currently, along with cgroup controllers "cpuacct", and "memory" support. And as one of KVM tool's pricinple is to allow both the non-root and root user to play with. The driver is designed to support root and non-root too, just like QEMU does. Example of the connection URI:

virsh -c kvmtool:///system
virsh -c kvmtool:///session
virsh -c kvmtool+unix:///system
virsh -c kvmtool+unix:///session

The implementation can support more or less than 15 virsh commands currently, including basic domain cycle operations (define/undefine, start/destroy, suspend/resume, console, setmem, schedinfo, dumpxml, ,autostart, dominfo, etc.)

About the domain configuration:
* "kernel": must be specified as KVM tool only support boots from the kernel currently (no integration with BIOS app yet).

* "disk": only virtio bus is supported, and device type must be 'disk'.

* "serial/console": only one console is supported, of type serial or virtio (can extend to support multiple console as long as kvm tool supports, libvirt already supported mutiple console, see upstream commit 0873b688c).

* "p9fs": only support specifying the source dir, and mount tag, only type of 'mount' is supported.

* "memballoon": only virtio is supported, and there is no way to config the addr.

* Multiple "disk" and "p9fs" is supported.

* Graphics and network are not supported, will explain below.

Please see "[PATCH 7/8]" for an example of the domain config. (which contains all the XMLs supported by current implementation).

Quoted 7 lines

The problems of Native Linux KVM Tool from libvirt p.o.v:

* Some destros package "qemu-kvm" as "kvm", also "kvm" is a long established name for "KVM" itself, so naming the project as "kvm" might be not a good idea. I assume it will be named as "kvmtool" in this implementation, never mind this if you don't like that, it can be updated easily. :-)

Yeah, naming the binary 'kvm' is just madness. I'd strongly recommend using 'kvmtool' as the binary name to avoid confusion with existing 'kvm' binaries based on QEMU.

Quoted 5 lines

* It still doesn't have an official package yet, even no "make install". means we have no way to check the dependancy and do the checking when 'configure'. I assume it will be installed as "/usr/bin/kvmtool" in this implementation. This is the main reason which can prevents upstream libvirt accepting the patches I guess.

Ok, not really a problem - we do similar for the regular QEMU driver.

Quoted 6 lines

* Lacks of options for user's configuration, such as "-vnc", there is no option for user to configure the properties for the "vnc", such as the port. It hides things, doesn't provide ways to query the properties too, this causes problems for libvirt to add the vnc support, as vnc clients such as virt-manager, virt-viewer, have no way to connect the guest. Even vncviewer can't.

Being able to specify a VNC port of libvirt's choosing is pretty much mandatory to be able to support that.In addition being able to specify the bind address is important to be able to control security. eg to only bind to 127.0.0.1, or only to certain NICs in a multi-NIC host.

Quoted 5 lines

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

If KVM tool support TAP devices, can't be do whatever we like with that just by passing in a configured TAP device from libvir ?

Quoted 4 lines

* There is a gap about the domain status between KVM tool and libvirt, it's caused by KVM tool unlink()s the guest socket when user exits from console (both text and graphic), but libvirt still think the guest is running.

Being able to reliably detect shutdown/exit of the KVM too is a very important tasks, and we can't rely on waitpid/SIG_CHLD because we want to daemonize all instances wrt libvirtd.

In the QEMU driver we keep open a socket to the monitor, and when we see an I/O error / POLLHUP on the socket we know that QEMU has quit.

What is this guest socket used for ? Could libvirt keep open a connection to it ?

One other option would be to use inotify to watch for deletion of the guest socket in the filesystem. This is sortof what we do with the UML driver.

Quoted 7 lines

* KVM tool uses $HOME/.kvm_tool as the state dir, and no way to configure, I made a small patch to allow KVM tool accept a ENV variable, which is "KVM_STATE_DIR", it's used across the driver. I made a simple patch against kvm tool to let the whole patches work. See "[PATCH] kvm tools.....". As generally we want the state dir of a driver can be "/var/run/libvirt/kvmtool/..." for root user or "$HOME/.libvirt/kvmtool/run" for non-root user.

What does it do with the state dir ? Is that just for storing the guest socket ?

With QEMU we chose $HOME/.libvirt/qemu or /var/run/libvirt because there was no policy set by QEMU itself. If KVM tool has a policy for where it stores its state, we should just use that, and not try to force it into a libvirt specific location.

In a privileged libvirtd instace, we should aim to still have kvmtool itself run as an unprivilegd user / group , eg 'kvmtool:kvmtool' And we could set the home dir of that user to /var/lib/kvmtool

Quoted 4 lines

* kvmtoolGetVersion is just broken now, as what "./kvm version" returns is something like "3.0.rc5.873.gb73216", however, libvirt wants things like "2.6.40.6-0". This might be not a problem as long as KVM tool has a official package.

The version numbers libvirt reports for hypervisors are pretty meaningless really. In that example you give I'd just report '3.0' as the version from libvirt. Anything that relies on these versions from libvirt is doomed to be broken anyway.

Quoted 5 lines

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

This sounds good enough for now.

Quoted 3 lines

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

What sort of guest info are you thinking about ? The most immediate pieces of info I can imagine we need are

- Mapping between PIDs and vCPU threads
- Current balloon driver value

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#20 lore raw
Quoted 8 lines · Daniel P. Berrange
Quoted 6 lines · Osier Yang

* Lacks of options for user's configuration, such as "-vnc", there is no option for user to configure the properties for the "vnc", such as the port. It hides things, doesn't provide ways to query the properties too, this causes problems for libvirt to add the vnc support, as vnc clients such as virt-manager, virt-viewer, have no way to connect the guest. Even vncviewer can't.

Quoted 5 lines

Being able to specify a VNC port of libvirt's choosing is pretty much mandatory to be able to support that.In addition being able to specify the bind address is important to be able to control security. eg to only bind to 127.0.0.1, or only to certain NICs in a multi-NIC host.

I'll add that feature in the next couple of days.

Quoted 9 lines
Quoted 6 lines

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

If KVM tool support TAP devices, can't be do whatever we like with that just by passing in a configured TAP device from libvir ?

KVM tool currently creates and configures the TAP devices it uses, it shouldn't be an issue to have it use a TAP fd passed to it either.

How does libvirt do it? Create a /dev/tapX on it's own and pass the fd to the hypervisor?

Quoted 10 lines
Quoted 5 lines

* There is a gap about the domain status between KVM tool and libvirt, it's caused by KVM tool unlink()s the guest socket when user exits from console (both text and graphic), but libvirt still think the guest is running.

Being able to reliably detect shutdown/exit of the KVM too is a very important tasks, and we can't rely on waitpid/SIG_CHLD because we want to daemonize all instances wrt libvirtd.

Quoted 6 lines

In the QEMU driver we keep open a socket to the monitor, and when we see an I/O error / POLLHUP on the socket we know that QEMU has quit.

What is this guest socket used for ? Could libvirt keep open a connection to it ?

It's being used for communication with the IPC sub-commands (like 'kvm list', 'kvm debug', etc). It's basically the server in a server-client setup used to signal the hypervisor to do things.

Theres also no problem with keeping an open connection to it.

Quoted 12 lines

One other option would be to use inotify to watch for deletion of the guest socket in the filesystem. This is sortof what we do with the UML driver.

Quoted 7 lines

* KVM tool uses $HOME/.kvm_tool as the state dir, and no way to configure, I made a small patch to allow KVM tool accept a ENV variable, which is "KVM_STATE_DIR", it's used across the driver. I made a simple patch against kvm tool to let the whole patches work. See "[PATCH] kvm tools.....". As generally we want the state dir of a driver can be "/var/run/libvirt/kvmtool/..." for root user or "$HOME/.libvirt/kvmtool/run" for non-root user.

Quoted 2 lines

What does it do with the state dir ? Is that just for storing the guest socket ?

afaik that patch should be already in as well.

It does two things in the state dir:

- Store sockets.
- KVM tools has a feature which lets a user boot a guest based on
virtio-9p which lets him see a system which is an exact copy of the host. This makes testing of programs and sandboxing very easy. The state files required for that are stored in that dir as well.

Quoted 15 lines

With QEMU we chose $HOME/.libvirt/qemu or /var/run/libvirt because there was no policy set by QEMU itself. If KVM tool has a policy for where it stores its state, we should just use that, and not try to force it into a libvirt specific location.

In a privileged libvirtd instace, we should aim to still have kvmtool itself run as an unprivilegd user / group , eg 'kvmtool:kvmtool' And we could set the home dir of that user to /var/lib/kvmtool

Quoted 4 lines

* kvmtoolGetVersion is just broken now, as what "./kvm version" returns is something like "3.0.rc5.873.gb73216", however, libvirt wants things like "2.6.40.6-0". This might be not a problem as long as KVM tool has a official package.

Quoted 4 lines

The version numbers libvirt reports for hypervisors are pretty meaningless really. In that example you give I'd just report '3.0' as the version from libvirt. Anything that relies on these versions from libvirt is doomed to be broken anyway.

The version is just a 'git describe' of the kernel tree in which it was built, so if you build KVM tools from an "official" kernel tree* you'll also get pretty versions :)

* After KVM tools is merged...

Quoted 8 lines
Quoted 6 lines

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

This sounds good enough for now.

KVM tools does a redirection to a PTY, which at that point could be redirected to anywhere the user wants.

What features might be interesting to do on top of that?

Quoted 9 lines
Quoted 3 lines

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

What sort of guest info are you thinking about ? The most immediate pieces of info I can imagine we need are

- Mapping between PIDs and vCPU threads
- Current balloon driver value

Those are pretty easily added using the IPC interface I've mentioned above. For example, 'kvm balloon' and 'kvm stat' will return a lot of info out of the balloon driver (including the memory stats VQ - which afaik we're probably the only ones who actually do that (but I might be wrong) :)

Any other commands are added on-demand. Just let us know what you want to see there.

Signature · 1 line
Sasha.
#21 lore raw
Quoted 8 lines · Sasha Levin
Quoted 7 lines · Daniel P. Berrange
Quoted 5 lines · Osier Yang

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

Quoted 8 lines
Quoted 2 lines

If KVM tool support TAP devices, can't be do whatever we like with that just by passing in a configured TAP device from libvir ?

KVM tool currently creates and configures the TAP devices it uses, it shouldn't be an issue to have it use a TAP fd passed to it either.

How does libvirt do it? Create a /dev/tapX on it's own and pass the fd to the hypervisor?

Yes, libvirt opens a /dev/tap device (or a macvtap device for VEPA mode), adds it to the neccessary bridge, and/or configures VEPA, etc and then passes the FD to the hypervisor, with a ARGV parameter to tell the HV which FD is being passed.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

Quoted 6 lines
Quoted 1 line

This sounds good enough for now.

KVM tools does a redirection to a PTY, which at that point could be redirected to anywhere the user wants.

What features might be interesting to do on top of that?

I presume that Osier is just comparing with the features QEMU has available for chardevs config, which include

- PTYs
- UNIX sockets
- TCP sockets
- UDP sockets
- FIFO pipe
- Plain file (output only obviously, but useful for logging)

libvirt doesn't specifically need any of them, but it can support those options if they exist.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

What sort of guest info are you thinking about ? The most immediate pieces of info I can imagine we need are

Quoted 8 lines
Quoted 2 lines

- Mapping between PIDs and vCPU threads
- Current balloon driver value

Those are pretty easily added using the IPC interface I've mentioned above. For example, 'kvm balloon' and 'kvm stat' will return a lot of info out of the balloon driver (including the memory stats VQ - which afaik we're probably the only ones who actually do that (but I might be wrong) :)

Ok, that sounds sufficient for the balloon info.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#22 lore raw
Quoted 39 lines · Daniel P. Berrange
Quoted 8 lines · Sasha Levin
Quoted 7 lines · Daniel P. Berrange
Quoted 5 lines · Osier Yang

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

Quoted 8 lines
Quoted 2 lines

If KVM tool support TAP devices, can't be do whatever we like with that just by passing in a configured TAP device from libvir ?

KVM tool currently creates and configures the TAP devices it uses, it shouldn't be an issue to have it use a TAP fd passed to it either.

How does libvirt do it? Create a /dev/tapX on it's own and pass the fd to the hypervisor?

Yes, libvirt opens a /dev/tap device (or a macvtap device for VEPA mode), adds it to the neccessary bridge, and/or configures VEPA, etc and then passes the FD to the hypervisor, with a ARGV parameter to tell the HV which FD is being passed.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

Quoted 6 lines
Quoted 1 line

This sounds good enough for now.

KVM tools does a redirection to a PTY, which at that point could be redirected to anywhere the user wants.

What features might be interesting to do on top of that?

I presume that Osier is just comparing with the features QEMU has available for chardevs config, which include

Quoted 6 lines

- PTYs
- UNIX sockets
- TCP sockets
- UDP sockets
- FIFO pipe
- Plain file (output only obviously, but useful for logging)

Yes, that's what I meant. :-)

Quoted 3 lines

libvirt doesn't specifically need any of them, but it can support those options if they exist.

Yes, these won't prevent us, I just meant it will be great if they are supported.

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

What sort of guest info are you thinking about ? The most immediate pieces of info I can imagine we need are

Quoted 8 lines
Quoted 2 lines

- Mapping between PIDs and vCPU threads
- Current balloon driver value

Those are pretty easily added using the IPC interface I've mentioned above. For example, 'kvm balloon' and 'kvm stat' will return a lot of info out of the balloon driver (including the memory stats VQ - which afaik we're probably the only ones who actually do that (but I might be wrong) :)

Ok, that sounds sufficient for the balloon info.

Regards,
Daniel

author
#23 lore raw
In reply to Sasha Levin
Quoted 46 lines · Sasha Levin
Quoted 8 lines · Daniel P. Berrange
Quoted 6 lines · Osier Yang

* Lacks of options for user's configuration, such as "-vnc", there is no option for user to configure the properties for the "vnc", such as the port. It hides things, doesn't provide ways to query the properties too, this causes problems for libvirt to add the vnc support, as vnc clients such as virt-manager, virt-viewer, have no way to connect the guest. Even vncviewer can't.

Quoted 5 lines

Being able to specify a VNC port of libvirt's choosing is pretty much mandatory to be able to support that.In addition being able to specify the bind address is important to be able to control security. eg to only bind to 127.0.0.1, or only to certain NICs in a multi-NIC host.

I'll add that feature in the next couple of days.

Quoted 9 lines
Quoted 6 lines

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

If KVM tool support TAP devices, can't be do whatever we like with that just by passing in a configured TAP device from libvir ?

KVM tool currently creates and configures the TAP devices it uses, it shouldn't be an issue to have it use a TAP fd passed to it either.

How does libvirt do it? Create a /dev/tapX on it's own and pass the fd to the hypervisor?

Quoted 14 lines
Quoted 5 lines

* There is a gap about the domain status between KVM tool and libvirt, it's caused by KVM tool unlink()s the guest socket when user exits from console (both text and graphic), but libvirt still think the guest is running.

Being able to reliably detect shutdown/exit of the KVM too is a very important tasks, and we can't rely on waitpid/SIG_CHLD because we want to daemonize all instances wrt libvirtd.

In the QEMU driver we keep open a socket to the monitor, and when we see an I/O error / POLLHUP on the socket we know that QEMU has quit.

Quoted 8 lines
Quoted 2 lines

What is this guest socket used for ? Could libvirt keep open a connection to it ?

It's being used for communication with the IPC sub-commands (like 'kvm list', 'kvm debug', etc). It's basically the server in a server-client setup used to signal the hypervisor to do things.

Theres also no problem with keeping an open connection to it.

I'll update the codes to use it.

Quoted 61 lines
Quoted 13 lines

One other option would be to use inotify to watch for deletion of the guest socket in the filesystem. This is sortof what we do with the UML driver.

Quoted 7 lines

* KVM tool uses $HOME/.kvm_tool as the state dir, and no way to configure, I made a small patch to allow KVM tool accept a ENV variable, which is "KVM_STATE_DIR", it's used across the driver. I made a simple patch against kvm tool to let the whole patches work. See "[PATCH] kvm tools.....". As generally we want the state dir of a driver can be "/var/run/libvirt/kvmtool/..." for root user or "$HOME/.libvirt/kvmtool/run" for non-root user.

Quoted 2 lines

What does it do with the state dir ? Is that just for storing the guest socket ?

afaik that patch should be already in as well.

It does two things in the state dir:

- Store sockets.
- KVM tools has a feature which lets a user boot a guest based on
virtio-9p which lets him see a system which is an exact copy of the host. This makes testing of programs and sandboxing very easy. The state files required for that are stored in that dir as well.

Quoted 15 lines

With QEMU we chose $HOME/.libvirt/qemu or /var/run/libvirt because there was no policy set by QEMU itself. If KVM tool has a policy for where it stores its state, we should just use that, and not try to force it into a libvirt specific location.

In a privileged libvirtd instace, we should aim to still have kvmtool itself run as an unprivilegd user / group , eg 'kvmtool:kvmtool' And we could set the home dir of that user to /var/lib/kvmtool

Quoted 4 lines

* kvmtoolGetVersion is just broken now, as what "./kvm version" returns is something like "3.0.rc5.873.gb73216", however, libvirt wants things like "2.6.40.6-0". This might be not a problem as long as KVM tool has a official package.

Quoted 4 lines

The version numbers libvirt reports for hypervisors are pretty meaningless really. In that example you give I'd just report '3.0' as the version from libvirt. Anything that relies on these versions from libvirt is doomed to be broken anyway.

The version is just a 'git describe' of the kernel tree in which it was built, so if you build KVM tools from an "official" kernel tree* you'll also get pretty versions :)

* After KVM tools is merged...

Quoted 7 lines
Quoted 6 lines

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

Quoted 6 lines
Quoted 1 line

This sounds good enough for now.

KVM tools does a redirection to a PTY, which at that point could be redirected to anywhere the user wants.

What features might be interesting to do on top of that?

No others except the console. But as we have already implemented the console support using pty in libvirt self. So temporarily wont's use it.

Quoted 20 lines
Quoted 10 lines
Quoted 4 lines

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

What sort of guest info are you thinking about ? The most immediate pieces of info I can imagine we need are

- Mapping between PIDs and vCPU threads
- Current balloon driver value

Those are pretty easily added using the IPC interface I've mentioned above. For example, 'kvm balloon' and 'kvm stat' will return a lot of info out of the balloon driver (including the memory stats VQ - which afaik we're probably the only ones who actually do that (but I might be wrong) :)

Any other commands are added on-demand. Just let us know what you want to see there.

author
#24 lore raw
In reply to Daniel P. Berrange
Quoted 124 lines · Daniel P. Berrange
Quoted 50 lines · Osier Yang

Hi, all

This is a basic implementation of libvirt Native Linux KVM Tool driver. Note that this is just made with my own interest and spare time, it's not an endorsement/effort by Red Hat, and it isn't supported by Red Hat officially.

Basically, the driver is designed as *stateful*, as KVM tool doesn't maintain any info about the guest except a socket which for its own IPC. And it's implemented by using KVM tool binary, which is name "kvm" currently, along with cgroup controllers "cpuacct", and "memory" support. And as one of KVM tool's pricinple is to allow both the non-root and root user to play with. The driver is designed to support root and non-root too, just like QEMU does. Example of the connection URI:

virsh -c kvmtool:///system
virsh -c kvmtool:///session
virsh -c kvmtool+unix:///system
virsh -c kvmtool+unix:///session

The implementation can support more or less than 15 virsh commands currently, including basic domain cycle operations (define/undefine, start/destroy, suspend/resume, console, setmem, schedinfo, dumpxml, ,autostart, dominfo, etc.)

About the domain configuration:
* "kernel": must be specified as KVM tool only support boots from the kernel currently (no integration with BIOS app yet).

* "disk": only virtio bus is supported, and device type must be 'disk'.

* "serial/console": only one console is supported, of type serial or virtio (can extend to support multiple console as long as kvm tool supports, libvirt already supported mutiple console, see upstream commit 0873b688c).

* "p9fs": only support specifying the source dir, and mount tag, only type of 'mount' is supported.

* "memballoon": only virtio is supported, and there is no way to config the addr.

* Multiple "disk" and "p9fs" is supported.

* Graphics and network are not supported, will explain below.

Please see "[PATCH 7/8]" for an example of the domain config. (which contains all the XMLs supported by current implementation).

Quoted 7 lines

The problems of Native Linux KVM Tool from libvirt p.o.v:

* Some destros package "qemu-kvm" as "kvm", also "kvm" is a long established name for "KVM" itself, so naming the project as "kvm" might be not a good idea. I assume it will be named as "kvmtool" in this implementation, never mind this if you don't like that, it can be updated easily. :-)

Yeah, naming the binary 'kvm' is just madness. I'd strongly recommend using 'kvmtool' as the binary name to avoid confusion with existing 'kvm' binaries based on QEMU.

Quoted 5 lines

* It still doesn't have an official package yet, even no "make install". means we have no way to check the dependancy and do the checking when 'configure'. I assume it will be installed as "/usr/bin/kvmtool" in this implementation. This is the main reason which can prevents upstream libvirt accepting the patches I guess.

Ok, not really a problem - we do similar for the regular QEMU driver.

Quoted 6 lines

* Lacks of options for user's configuration, such as "-vnc", there is no option for user to configure the properties for the "vnc", such as the port. It hides things, doesn't provide ways to query the properties too, this causes problems for libvirt to add the vnc support, as vnc clients such as virt-manager, virt-viewer, have no way to connect the guest. Even vncviewer can't.

Being able to specify a VNC port of libvirt's choosing is pretty much mandatory to be able to support that.In addition being able to specify the bind address is important to be able to control security. eg to only bind to 127.0.0.1, or only to certain NICs in a multi-NIC host.

Quoted 5 lines

* KVM tool manages the network completely itself (with DHCP support?), no way to configure, except specify the modes (user|tap|none). I have not test it yet, but it should need explicit script to setup the network rules(e.g. NAT) for the guest access outside world. Anyway, there is no way for libvirt to control the guest network.

If KVM tool support TAP devices, can't be do whatever we like with that just by passing in a configured TAP device from libvir ?

Quoted 4 lines

* There is a gap about the domain status between KVM tool and libvirt, it's caused by KVM tool unlink()s the guest socket when user exits from console (both text and graphic), but libvirt still think the guest is running.

Being able to reliably detect shutdown/exit of the KVM too is a very important tasks, and we can't rely on waitpid/SIG_CHLD because we want to daemonize all instances wrt libvirtd.

In the QEMU driver we keep open a socket to the monitor, and when we see an I/O error / POLLHUP on the socket we know that QEMU has quit.

What is this guest socket used for ? Could libvirt keep open a connection to it ?

One other option would be to use inotify to watch for deletion of the guest socket in the filesystem. This is sortof what we do with the UML driver.

Quoted 7 lines

* KVM tool uses $HOME/.kvm_tool as the state dir, and no way to configure, I made a small patch to allow KVM tool accept a ENV variable, which is "KVM_STATE_DIR", it's used across the driver. I made a simple patch against kvm tool to let the whole patches work. See "[PATCH] kvm tools.....". As generally we want the state dir of a driver can be "/var/run/libvirt/kvmtool/..." for root user or "$HOME/.libvirt/kvmtool/run" for non-root user.

What does it do with the state dir ? Is that just for storing the guest socket ?

Quoted 8 lines

With QEMU we chose $HOME/.libvirt/qemu or /var/run/libvirt because there was no policy set by QEMU itself. If KVM tool has a policy for where it stores its state, we should just use that, and not try to force it into a libvirt specific location.

In a privileged libvirtd instace, we should aim to still have kvmtool itself run as an unprivilegd user / group , eg 'kvmtool:kvmtool' And we could set the home dir of that user to /var/lib/kvmtool

Is there any harm if we force it into /var/run/libvirt/kvmtool? The only harm I can think of the user who uses kvmtool directly might be confused after turning into using libvirt.

Quoted 10 lines
Quoted 5 lines

* kvmtoolGetVersion is just broken now, as what "./kvm version" returns is something like "3.0.rc5.873.gb73216", however, libvirt wants things like "2.6.40.6-0". This might be not a problem as long as KVM tool has a official package.

The version numbers libvirt reports for hypervisors are pretty meaningless really. In that example you give I'd just report '3.0' as the version from libvirt. Anything that relies on these versions from libvirt is doomed to be broken anyway.

Okay, I thought the API wants the complete version. :-)

Quoted 13 lines
Quoted 6 lines

* console connection is implemented by setup ptys in libvirt, stdout/stderr of kvm tool process is redirected to the master pty, and libvirt connects to the slave pty. This works fine now, but it might be better if kvm tool could provide more advanced console mechanisms. Just like QEMU does?

This sounds good enough for now.

Quoted 3 lines

* Not much ways existed yet for external apps or user to query the guest informations. But this might be changed soon per KVM tool grows up quickly.

Quoted 5 lines

What sort of guest info are you thinking about ? The most immediate pieces of info I can imagine we need are

- Mapping between PIDs and vCPU threads
- Current balloon driver value

My mainly concern was the balloon driver value, we want to display the value in domain's XML. Didn't think of the mapping between PIDs and vCPU threads, we might also want to see the disk info / stats. But that's not what can prevent us going forward.

By the way, nobody is interested in kvmtool privodes a way to for external apps to get the capabilities? Do we still want to suffer from parsing the capabilities ourselves in future just like what
we do for qemu? :-)

Regards,
Osier

#25 lore raw
Quoted 4 lines · Osier Yang

By the way, nobody is interested in kvmtool privodes a way to for external apps to get the capabilities? Do we still want to suffer from parsing the capabilities ourselves in future just like what we do for qemu? :-)

I think the feature makes sense especially if it simplifies libvirt.

Pekka