Re: Patch Re: save and restore guest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Farkas Levente wrote:
> Daniel P. Berrange wrote:
>> On Mon, Oct 08, 2007 at 04:27:00PM +0200, Farkas Levente wrote:
>>> Daniel P. Berrange wrote:
>>>> On Sat, Oct 06, 2007 at 02:29:39PM +0200, Farkas Levente wrote:
>>>>> hi,
>>>>> if i use xen with xendomain it's possible to save and restore guest
>>>>> state. if i use libvirt it's not working (at least by default with kvm).
>>>>> i mean if i stop or restart libvirtd all guests a stopped and even if i
>>>>> restart libvirtd i've to start all guests manually. imho this's a very
>>>>> essential feature. what is the reason this not working with libvirtd?:
>>>>> - this feature is missing from libvirtd? or
>>>> You can set KVM/QEMU guests to autostart with
>>>>
>>>>   virsh autostart {NAME|ID|UUID}
>>> thanks, but go back to my first question. afais /etc/init.d/libvirtd
>>> simple kill libvirtd, but virsh has a command save/restore. wouldn't be
>>> it's much better to save guest's state on stop, restore on start in
>>> stead of start if there is a saved state. i can send a patch to the
>>> /etc/init.d/libvirtd, just would like to know is there any reason it's
>>> not that way? anyway xendomains do it in the save way.
>> The save/restore capability is currently only available in the KVM-ified
>> version of QEMU. We could make it try to save, and failing that destroy
>> the guest. The xendomains scripts isn't a good model to emulate though.
>> The autostart/kill functionality is part of the libvirt daemon itself. Any
>> save/restore capability would be best integrated there
> 
> for those who like to save and restore guest at libvirtd stop and start
> i attached a patch we use to for it. it's based on xen's sripts.
> LIBVIRTD_AUTO_ONLY still not implemented but the sysconfig file already
> contains it. if you like to set the default behavior to the current then
> set LIBVIRTD_RESTORE to false.
> imho it'd be useful to include in the upstream libvirtd too.
> 
and the patch:-)

-- 
  Levente                               "Si vis pacem para bellum!"
--- /etc/init.d/libvirtd.ori	2007-10-17 13:57:29.000000000 +0200
+++ /etc/init.d/libvirtd	2007-10-19 13:30:26.000000000 +0200
@@ -45,6 +45,7 @@
 then
     LIBVIRTD_CONFIG_ARGS="--config $LIBVIRTD_CONFIG"
 fi
+[ "$LIBVIRTD_RESTORE" != "true" ] || [ -d $LIBVIRTD_SAVE ] || mkdir -p $LIBVIRTD_SAVE
 
 RETVAL=0
 
@@ -53,12 +54,25 @@
     daemon --check $SERVICE $PROCESS --daemon $LIBVIRTD_CONFIG_ARGS $LIBVIRTD_ARGS
     RETVAL=$?
     echo
+    if [ $RETVAL -eq 0 -a "$LIBVIRTD_RESTORE" = "true" ]; then
+        for i in `ls $LIBVIRTD_SAVE`; do
+            echo "Restore guest from: $i"
+            virsh restore $LIBVIRTD_SAVE/$i >/dev/null
+            rm $LIBVIRTD_SAVE/$i
+        done
+    fi
     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SERVICE
 }
 
 stop() {
+    if [ "$LIBVIRTD_RESTORE" = "true" ]; then
+        for i in `virsh list|grep running|awk '{ print $1 }'`; do
+            NAME="`virsh list|grep " $i "|awk '{ print $2 }'`"
+            echo "Save guest: $NAME"
+            virsh save $i $LIBVIRTD_SAVE/$NAME >/dev/null
+        done
+    fi
     echo -n $"Stopping $SERVICE daemon: "
-
     killproc $PROCESS
     RETVAL=$?
     echo
--- /etc/sysconfig/libvirtd.ori	2007-10-17 13:57:24.000000000 +0200
+++ /etc/sysconfig/libvirtd	2007-10-19 13:54:12.000000000 +0200
@@ -4,3 +4,33 @@
 # Listen for TCP/IP connections
 # NB. must setup TLS/SSL keys prior to using this
 #LIBVIRTD_ARGS="--listen"
+
+## Type: string
+## Default: /var/lib/libvirt/save
+#
+# Directory to save running guests to when the system (host) is
+# shut down or libvirtd stop. Will also be used to restore guests from if
+# LIBVIRTD_RESTORE is set (see below). Leave empty to disable guest saving 
+# on shutdown (e.g. because you rather shut guests down).
+# If guest saving does succeed, SHUTDOWN will not be executed.
+#
+LIBVIRTD_SAVE=/var/lib/libvirt/save
+
+## Type: boolean
+## Default: true
+#
+# This variable determines whether saved guests from LIBVIRTD_SAVE
+# will be restored on system startup. 
+#
+LIBVIRTD_RESTORE=true
+
+## Type: boolean
+## Default: false
+# 
+# If this variable is set to "true", only the guests started via config 
+# files in autostart will be treated according to LIBVIRTD_SYSRQ,
+# LIBVIRTD_MIGRATE, LIBVIRTD_SAVE, LIBVIRTD_SHUTDOWN; otherwise
+# all running guests will be. 
+# Note that the name matching is somewhat fuzzy.
+# 
+LIBVIRTD_AUTO_ONLY=false
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]