Skip to content

Commit f815cd5

Browse files
committed
fix(FileSR): apply review suggestions for vdi_revert
Signed-off-by: Antoine Bartuccio <antoine.bartuccio@vates.tech>
1 parent 826df72 commit f815cd5

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

drivers/FileSR.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ def _undo_all_journals(self):
260260
if 'SRmaster' in self.dconf and self.dconf['SRmaster'] == 'true':
261261
is_master = True
262262

263-
if self.cmd in ["vdi_detach", "vdi_activate", "vdi_deactivate", "nop"]:
264-
return
263+
# if self.cmd in ["vdi_detach", "vdi_activate", "vdi_deactivate", "nop"]:
264+
# return
265265

266266
if not is_master:
267267
raise xs_errors.XenError(
@@ -530,13 +530,13 @@ def _rollback_revert_vdi(self, entry: RevertLogEntry):
530530
if not util.ioretry(lambda: util.pathexists(entry.dest.backup_path)):
531531
util.SMlog(f"Tried reverting {entry.dest.uuid} but backup {entry.dest.backup_path} not found, skpping")
532532
return
533+
533534
src_cowutil = getCowUtil(entry.src.vdi_type)
534535
util.SMlog(f"Restoring src vdi {entry.src.uuid}")
535536
if not util.ioretry(lambda: util.pathexists(entry.src.path)):
536537
util.SMlog(f"Restoring src vdi {entry.src.uuid} from {entry.inserted.uuid}")
537538
util.ioretry(lambda: os.rename(entry.inserted.path, entry.src.path))
538539

539-
util.SMlog(f"Restoring src vdi {entry.src.uuid}")
540540
src_cowutil.setHidden(entry.src.path, False)
541541

542542
src: "FileVDI" = self.vdi(entry.src.uuid) # type: ignore[assignment]
@@ -596,7 +596,7 @@ def _unlink_paths(self, *files: Union[Path, str]):
596596
def _handle_revert_journals(self):
597597
for uuid, value in self.journaler.getAll(RevertLogEntry.JRN_KEY).items():
598598
entry = RevertLogEntry.from_journal(uuid, value)
599-
util.SMlog(f"Reverting {entry.dest.uuid}")
599+
util.SMlog(f"Reverting journal {entry}")
600600

601601
self._rollback_revert_vdi(entry)
602602

@@ -1062,19 +1062,8 @@ def _revert(
10621062

10631063
util.fistpoint.activate("FileSR_revert_create_insert", self.sr.uuid)
10641064

1065-
# Create inserted base copy
1066-
util.ioretry(
1067-
lambda: self._snap(
1068-
self.path,
1069-
inserted_path,
1070-
False,
1071-
)
1072-
)
1073-
10741065
inserted = FileVDI(self.sr, inserted_uuid)
10751066

1076-
util.fistpoint.activate("FileSR_revert_create_src", self.sr.uuid)
1077-
10781067
inserted.label = "base copy"
10791068
inserted.read_only = True
10801069
inserted.location = inserted_uuid
@@ -1086,6 +1075,17 @@ def _revert(
10861075

10871076
inserted._db_introduce()
10881077

1078+
util.fistpoint.activate("FileSR_revert_create_src", self.sr.uuid)
1079+
1080+
# Create src again
1081+
util.ioretry(
1082+
lambda: self._snap(
1083+
self.path,
1084+
inserted_path,
1085+
False,
1086+
)
1087+
)
1088+
10891089
# Update src
10901090
self.load_from_file(self.path)
10911091
self._db_update()
@@ -1099,16 +1099,17 @@ def _revert(
10991099
)
11001100
)
11011101
self.cowutil.setHidden(dest.path, False)
1102-
## Force parent (it can be simplified by vhd tools)
1103-
self.cowutil.setParent(dest.path, inserted.path, False)
11041102

11051103
util.fistpoint.activate("FileSR_revert_create_dest", self.sr.uuid)
11061104

1105+
dest.load_from_file(dest.path)
1106+
dest._db_update()
1107+
11071108
## The new parent can now be set hidden and don't need to be protected by the GC
11081109
inserted.cowutil.setHidden(inserted.path, True)
1110+
inserted.load_from_file(inserted.path)
11091111

1110-
dest.load_from_file(dest.path)
1111-
dest._db_update()
1112+
inserted._db_update()
11121113

11131114
if src_cbtlog:
11141115
self._revert_cbt(dest)

drivers/SRCommand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _run(self, sr, target):
273273
elif self.cmd == 'vdi_revert':
274274
dest_uuid = self.params['args'][0]
275275
if dest_uuid.startswith("OpaqueRef:"):
276-
# TODO: remove once xapi sends an uuid instead of an OpaqueRef
276+
# TODO(XCPNG-3486): remove once xapi sends an uuid instead of an OpaqueRef
277277
dest_uuid = sr.session.xenapi.VDI.get_record(dest_uuid)["uuid"]
278278
return target.revert(
279279
self.params['sr_uuid'],

drivers/VDI.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
256256
"""
257257
raise xs_errors.XenError('Unimplemented')
258258

259-
def revert(self, sr_uuid: str, vdi_uuid: str, target_uuid: str) -> None:
259+
def revert(self, _sr_uuid: str, _vdi_uuid: str, target_uuid: str) -> None:
260260
"""Replaces the contents of the target_uuid VDI with the contents of the vdi_uuid
261261
without changing the identitity of the target (i.e. name-label, uuid and location
262262
are guaranteed to remain the same)..
@@ -964,11 +964,9 @@ def _disable_cbt_on_vdi(self, vdi: "VDI", alert_name: str, alert_str: str) -> No
964964
vdi._delete_cbt_log()
965965
vdi_ref = vdi.session.xenapi.VDI.get_by_uuid(vdi.uuid)
966966
vdi.session.xenapi.VDI.set_cbt_enabled(vdi_ref, False)
967-
alert_prio_warning = "3"
968-
alert_obj = "VDI"
969967
alert_uuid = str(vdi.uuid)
970968
vdi.session.xenapi.message.create(
971-
alert_name, alert_prio_warning, alert_obj, alert_uuid, alert_str
969+
alert_name, "3", "VDI", alert_uuid, alert_str
972970
)
973971

974972
def _create_cbt_log_with_size(self, size: int) -> str:

drivers/jutils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3
22
#
3-
# Copyright (C) 2020 Vates SAS - antoine.bartuccio@vates.fr
3+
# Copyright (C) 2026 Vates SAS - antoine.bartuccio@vates.fr
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -53,6 +53,8 @@ def _get_version_from_journal_id(journal_id: str) -> str:
5353

5454
@classmethod
5555
def from_journal(cls: Type[LogEntry], journal_id: str, value: str) -> LogEntry:
56+
"""Convert a compatilbe journal to a log entry
57+
Ensure that the type and version of the journal are compatible"""
5658
version = cls._get_version_from_journal_id(journal_id)
5759
if version != cls.CURRENT_VERSION:
5860
raise xs_errors.SRException(

0 commit comments

Comments
 (0)