WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xend: check file exist for xm save

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] xend: check file exist for xm save
From: Wei Kong <weikong.cn@xxxxxxxxx>
Date: Mon, 18 May 2009 17:42:05 +0800
Delivery-date: Mon, 18 May 2009 02:42:36 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=K+uVkddajWG7VQfn7922hc1BodztOrXPrjImL2tX0kQ=; b=CFJoksK4Vc4rKkS1IYq3xAGkAqvX5yvMcuXN2CeOJnryDHrdG3Dql1cWbi/Uhg54Ry BQEeMSJQQxm5DFKFOGe4xircXjOTXMblYSMv/ONLPxAMDmx1BU9SZ3ykJueqd9W7ThIH zIpLG7NCnEuWGXeWp1iYvEGx+Mlesy+JZUwYo=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Czns+qLyv9v5bd5pcWzKoyGIHft9XBhBJGSByMuvG/KoBuKIdS7NnKA2Yn+8unBlQk Rx70daEFuu8flA364fmhvIXFHWvqdHIXcaXCsBp3pNgOKjnWLebh5zwNObpeLQN2L5rO hELUEMIh84R+/7VBeqE0oBZz6vKG3fB5/NUbc=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Check file exist for xm save, allow force to overwrite.

Signed-off-by: Wei Kong <weikong.cn@gmail.com>

diff -uNrp xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py
--- xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py  2009-05-19 01:52:28.000000000 +0800
+++ xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py  2009-05-19 01:52:44.000000000 +0800
@@ -1809,10 +1809,10 @@ class XendAPI(object):
                               bool(live), port, node, ssl)
         return xen_api_success_void()

-    def VM_save(self, _, vm_ref, dest, checkpoint):
+    def VM_save(self, _, vm_ref, dest, checkpoint, force):
         xendom = XendDomain.instance()
         xeninfo = xendom.get_vm_by_uuid(vm_ref)
-        xendom.domain_save(xeninfo.getDomid(), dest, checkpoint)
+        xendom.domain_save(xeninfo.getDomid(), dest, checkpoint, force)
         return xen_api_success_void()

     def VM_restore(self, _, src, paused):
diff -uNrp xen-3.4.0-testing/tools/python/xen/xend/XendDomain.py xen-3.4.0-testing/tools/python/xen/xend/XendDomain.py
--- xen-3.4.0-testing/tools/python/xen/xend/XendDomain.py       2009-05-19 01:52:28.000000000 +0800
+++ xen-3.4.0-testing/tools/python/xen/xend/XendDomain.py       2009-05-19 01:52:44.000000000 +0800
@@ -1381,7 +1381,7 @@ class XendDomain:
             finally:
                 sock.close()

-    def domain_save(self, domid, dst, checkpoint=False):
+    def domain_save(self, domid, dst, checkpoint=False, force=False):
         """Start saving a domain to file.

         @param domid: Domain ID or Name
@@ -1397,6 +1397,9 @@ class XendDomain:
             if not dominfo:
                 raise XendInvalidDomain(str(domid))

+            if os.access(dst, os.F_OK) and not force:
+                raise XendError("Save file:%s exist!\n" % dst)
+
             if dominfo.getDomid() == DOM0_ID:
                 raise XendError("Cannot save privileged domain %s" % str(domid))
             if dominfo._stateGet() != DOM_STATE_RUNNING:
diff -uNrp xen-3.4.0-testing/tools/python/xen/xm/main.py xen-3.4.0-testing/tools/python/xen/xm/main.py
--- xen-3.4.0-testing/tools/python/xen/xm/main.py       2009-05-19 01:52:28.000000000 +0800
+++ xen-3.4.0-testing/tools/python/xen/xm/main.py       2009-05-19 01:57:31.000000000 +0800
@@ -118,7 +118,7 @@ SUBCOMMAND_HELP = {
     'reset'       : ('<Domain>', 'Reset a domain.'),
     'restore'     : ('<CheckpointFile> [-p]',
                      'Restore a domain from a saved state.'),
-    'save'        : ('[-c] <Domain> <CheckpointFile>',
+    'save'        : ('[-c|-f] <Domain> <CheckpointFile>',
                      'Save a domain state to restore later.'),
     'snapshot-create' : ('[-d] <Domain> <SnapshotName>',
                          'Snapshot a running domain.'),
@@ -283,6 +283,7 @@ SUBCOMMAND_OPTIONS = {
     ),
     'save': (
        ('-c', '--checkpoint', 'Leave domain running after creating snapshot'),
+       ('-f', '--force', 'Force to overwrite exist file'),
     ),
     'snapshot-create': (
        ('-d', '--diskonly', 'Perform disk only snapshot of domain'),
@@ -801,18 +802,21 @@ def xm_snapshot_delete(args):

 def xm_save(args):

-    arg_check(args, "save", 2, 3)
+    arg_check(args, "save", 2, 4)

     try:
-        (options, params) = getopt.gnu_getopt(args, 'c', ['checkpoint'])
+        (options, params) = getopt.gnu_getopt(args, 'cf', ['checkpoint', 'force'])
     except getopt.GetoptError, opterr:
         err(opterr)
         usage('save')

     checkpoint = False
+    force = False
     for (k, v) in options:
         if k in ['-c', '--checkpoint']:
             checkpoint = True
+        if k in ['-f', '--force']:
+            force = True

     if len(params) != 2:
         err("Wrong number of parameters")
@@ -826,9 +830,9 @@ def xm_save(args):
         sys.exit(1)

     if serverType == SERVER_XEN_API:
-        server.xenapi.VM.save(get_single_vm(dom), savefile, checkpoint)
+        server.xenapi.VM.save(get_single_vm(dom), savefile, checkpoint, force)
     else:
-        server.xend.domain.save(dom, savefile, checkpoint)
+        server.xend.domain.save(dom, savefile, checkpoint, force)

 def xm_restore(args):
     arg_check(args, "restore", 1, 2)

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] xend: check file exist for xm save, Wei Kong <=