Skip to content

Commit 376edf3

Browse files
committed
Basic working FileSR vdi_revert
Signed-off-by: Antoine Bartuccio <antoine.bartuccio@vates.tech>
1 parent ecedce7 commit 376edf3

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

drivers/FileSR.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -777,25 +777,27 @@ def revert(self, sr_uuid, src_uuid, dest_uuid):
777777
if not dest._checkpath(dest.path):
778778
raise xs_errors.XenError(f"Could not find {dest.path}")
779779

780-
def get_child_of(start: FileVDI, parent_uuid: str) -> Optional[str]:
781-
util.SMlog(f"Looking for common parent: {parent_uuid}")
782-
current = start.uuid
783-
while current is not None:
784-
path, _ = start._get_path_and_type(current)
785-
util.SMlog(f"Testing path {path}")
786-
if not path:
787-
return None
780+
def get_child_of(sr: FileSR, uuid: str, exclude: Optional[List[str]] = None) -> Optional[str]:
781+
if not exclude:
782+
exclude = []
788783

789-
parent = start.cowutil.getParent(path, FileVDI.extractUuid)
790-
util.SMlog(f"Testing {parent} == {parent_uuid}")
791-
if parent == parent_uuid:
792-
util.SMlog(f"Found {current} with next parent {parent}")
793-
return current
794-
current = parent
784+
excluded = set(exclude)
785+
sr._loadvdis()
795786

796-
return None
787+
children = []
788+
789+
for vdi in sr.vdis.values():
790+
if vdi.uuid == uuid:
791+
continue
792+
if vdi.parent == uuid and vdi.uuid not in excluded:
793+
children.append(vdi.uuid)
794+
795+
if len(children) != 1:
796+
return None
797+
798+
return children[0]
797799

798-
common_parent_uuid = get_child_of(dest, self.parent)
800+
common_parent_uuid = self.parent if self.parent == dest.parent else get_child_of(self.sr, self.parent, [self.uuid])
799801
if not common_parent_uuid:
800802
raise xs_errors.XenError(f"{self.uuid} and {dest.uuid} aren't on the same snapshot tree")
801803

@@ -884,7 +886,7 @@ def update_vdi_from_file(vdi: FileVDI, path: str):
884886

885887
dest._db_update()
886888

887-
return dest.get_params()
889+
return
888890

889891

890892
# except util.CommandException as inst:

0 commit comments

Comments
 (0)