[CRIU] [PATCH 03/12] p.haul: Implement class shared_ploop

Alexander Burluka aburluka at virtuozzo.com
Fri Apr 1 08:45:20 PDT 2016


This class is required to do migration on ploops located
on pstorage or other shared filesystems. That migration
is performed via two snapshot scheme.

Signed-off-by: Alexander Burluka <aburluka at virtuozzo.com>
---
 phaul/fs_haul_ploop.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/phaul/fs_haul_ploop.py b/phaul/fs_haul_ploop.py
index b436d19..61c7465 100644
--- a/phaul/fs_haul_ploop.py
+++ b/phaul/fs_haul_ploop.py
@@ -3,6 +3,7 @@
 #
 
 import os
+import shutil
 import logging
 import threading
 import libploop
@@ -31,6 +32,32 @@ def get_ploop_delta_abspath(delta_path, ct_priv):
 		return os.path.join(ct_priv, delta_path)
 
 
+def merge_ploop_snapshot(ddxml, guid):
+	libploop.snapshot(ddxml).delete(guid)
+
+
+class shared_ploop:
+	def __init__(self, path):
+		self.backup_ddxml = get_ddxml_path(path) + ".copy"
+		self.orig_ddxml = get_ddxml_path(path)
+
+	def prepare(self):
+		shutil.copyfile(self.orig_ddxml, self.backup_ddxml)
+		self.orig_guid = libploop.snapshot(self.orig_ddxml).create_offline()
+		self.backup_guid = libploop.snapshot(self.backup_ddxml).create()
+
+	def restore(self):
+		if self.backup_guid:
+			os.rename(self.backup_ddxml, self.orig_ddxml)
+			merge_ploop_snapshot(self.orig_ddxml, self.backup_guid)
+
+	def cleanup(self):
+		if self.orig_guid:
+			# TODO add delta removing when igor add it to libploop
+			os.remove(self.backup_ddxml)
+			os.remove(self.backup_ddxml + ".lck")
+
+
 class p_haul_fs:
 	def __init__(self, deltas, ct_priv):
 		"""Initialize ploop disks hauler
-- 
1.8.3.1



More information about the CRIU mailing list