Skip to content

Commit d9a0e98

Browse files
committed
fix(FileSR): Better protect against coalesce during revert
* Properly mark unmanaged base copy * Disable coalesce on VDIs being worked on * Fix permission on nfs-on-slave plugin Signed-off-by: Antoine Bartuccio <antoine.bartuccio@vates.tech>
1 parent f815cd5 commit d9a0e98

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

drivers/FileSR.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,9 @@ 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
265-
266263
if not is_master:
267264
raise xs_errors.XenError(
268-
"SRUnavailable", opterr="Critical journals are pending, please run a scan"
265+
"SRUnavailable", opterr="Critical journals are pending, please run a scan."
269266
)
270267

271268
self._check_o_direct()
@@ -544,6 +541,7 @@ def _rollback_revert_vdi(self, entry: RevertLogEntry):
544541
src.sm_config = src.session.xenapi.VDI.get_sm_config(src_ref)
545542
src.load_from_file(str(src.path))
546543
src._db_update()
544+
src.disable_leaf_on_secondary(src.uuid)
547545

548546
self.added_vdi(src)
549547

@@ -560,7 +558,9 @@ def _rollback_revert_vdi(self, entry: RevertLogEntry):
560558
if util.ioretry(lambda: util.pathexists(entry.inserted.path)):
561559
inserted: "FileVDI" = self.vdi(entry.inserted.uuid) # type: ignore[assignment]
562560
inserted._mark_hidden(entry.inserted.path)
563-
inserted._db_update_or_introduce()
561+
inserted_ref = inserted._db_update_or_introduce()
562+
inserted.session.xenapi.VDI.set_managed(inserted_ref, False)
563+
inserted.disable_leaf_on_secondary(inserted.uuid)
564564

565565
# Once we move the backup to it's old name, the journal can't be run again
566566
# If something fails from now, we might lose some info, most of them
@@ -575,6 +575,8 @@ def _rollback_revert_vdi(self, entry: RevertLogEntry):
575575

576576
dest.load_from_file(dest.path)
577577
dest._db_update()
578+
if dest.parent:
579+
dest.disable_leaf_on_secondary(dest.parent)
578580
self.added_vdi(dest)
579581

580582
# CBT might have been added when not needed or removed when needed
@@ -1049,6 +1051,10 @@ def _revert(
10491051
journal_id, journal_content = log_entry.to_journal()
10501052
self.sr.journaler.create(log_entry.JRN_KEY, journal_id, journal_content)
10511053

1054+
# Protect dest's parent against coalesce
1055+
if dest.parent:
1056+
dest.disable_leaf_on_secondary(dest.parent, True)
1057+
10521058
## First move the old vdi to a backup location to allow rolling back
10531059
## This has to be done first because it's used as a signal to the rollback
10541060
## algorithm to know if there is cleanup work to do
@@ -1057,6 +1063,9 @@ def _revert(
10571063
errlist=[errno.EIO, errno.EACCES],
10581064
)
10591065

1066+
# Protect src against coalesce
1067+
self.disable_leaf_on_secondary(self.uuid, True)
1068+
10601069
# Transform src into inserted
10611070
self._rename(self.path, inserted_path)
10621071

@@ -1073,10 +1082,13 @@ def _revert(
10731082
inserted.sm_config["key_hash"] = self.sm_config["key_hash"]
10741083
inserted.cbt_enabled = False # Base copies don't have cbt
10751084

1076-
inserted._db_introduce()
1085+
inserted_ref = inserted._db_introduce()
10771086

10781087
util.fistpoint.activate("FileSR_revert_create_src", self.sr.uuid)
10791088

1089+
# Protect inserted against coalesce
1090+
inserted.disable_leaf_on_secondary(inserted.uuid, True)
1091+
10801092
# Create src again
10811093
util.ioretry(
10821094
lambda: self._snap(
@@ -1107,9 +1119,15 @@ def _revert(
11071119

11081120
## The new parent can now be set hidden and don't need to be protected by the GC
11091121
inserted.cowutil.setHidden(inserted.path, True)
1122+
inserted._mark_hidden(inserted.path)
1123+
self.session.xenapi.VDI.set_managed(inserted_ref, False)
11101124
inserted.load_from_file(inserted.path)
11111125

1126+
## Inprotect src
1127+
self.disable_leaf_on_secondary(self.uuid, None)
1128+
11121129
inserted._db_update()
1130+
inserted.disable_leaf_on_secondary(inserted.uuid, None)
11131131

11141132
if src_cbtlog:
11151133
self._revert_cbt(dest)
@@ -1124,6 +1142,9 @@ def _revert(
11241142
)
11251143

11261144
# Cleanup
1145+
# Unprotect dest's parent against coalesce
1146+
if dest.parent:
1147+
dest.disable_leaf_on_secondary(dest.parent, None)
11271148
self.sr._unlink_paths(dest_backup_path)
11281149
self.sr.journaler.remove(log_entry.JRN_KEY, journal_id)
11291150

drivers/VDI.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ def _db_introduce(self):
528528

529529
def _db_update_or_introduce(self):
530530
try:
531-
self.sr.session.xenapi.VDI.get_by_uuid(self.uuid)
531+
vdi_ref = self.sr.session.xenapi.VDI.get_by_uuid(self.uuid)
532532
except XenAPI.Failure:
533-
self._db_introduce()
534-
return
533+
return self._db_introduce()
535534
self._db_update()
535+
return vdi_ref
536536

537537
def _db_forget(self):
538538
self.sr.forget_vdi(self.uuid)

drivers/nfs-on-slave

100644100755
File mode changed.

0 commit comments

Comments
 (0)