Skip to content

Commit

Permalink
CA-292144 Avoid having an invalid leaf while taking a snapshot
Browse files Browse the repository at this point in the history
After the original leaf has been renamed, td-util is asked to create a
snapshot with the filename it originally had. This means that after
td-util creates the file there is a brief window before it finishes
populating it when an attempt to query it will fail because the file
contents are invalid.

If we instead create the new leaf with a temporary filename
(foo.vhd.new) and rename it afterwards, this window is converted into
one during which the file does not exist, a condition in which a query
attempt will be retried for up to 20 seconds.

If necessary, the window can be shrunk further by using links so that
the old and new names of the original leaf exist simultaneously until it
is time to rename the new leaf into place (this is necessary because
td-util's snapshot function requires the parent to exist and be valid,
otherwise we could just create the snapshot first).

Signed-off-by: Tim Smith <tim.smith@citrix.com>
  • Loading branch information
TimSmithCtx authored and MarkSymsCtx committed Jul 13, 2018
1 parent daf4290 commit f4049e6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/FileSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,14 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
raise

try:
util.ioretry(lambda: self._snap(src, newsrcname))
# Create the snapshot under a temporary name, then rename
# it afterwards. This avoids a small window where it exists
# but is invalid. We do not need to do this for
# snap_type == VDI.SNAPSHOT_DOUBLE because dst never existed
# before so nobody will try to query it.
tmpsrc = "%s.%s" % (src, "new")
util.ioretry(lambda: self._snap(tmpsrc, newsrcname))
util.ioretry(lambda: os.rename(tmpsrc, src))
if snap_type == VDI.SNAPSHOT_DOUBLE:
util.ioretry(lambda: self._snap(dst, newsrcname))
# mark the original file (in this case, its newsrc)
Expand Down

0 comments on commit f4049e6

Please sign in to comment.