prevent unwanted zfs list in snapshot only mode

This commit is contained in:
Edwin Eefting
2021-02-06 14:05:44 +01:00
parent 6fefadf884
commit 0649f42d66

View File

@ -783,16 +783,18 @@ class ZfsDataset:
return ret return ret
def add_virtual_snapshot(self, snapshot): # def add_virtual_snapshot(self, snapshot):
"""pretend a snapshot exists (usefull in test mode)""" # """pretend a snapshot exists (usefull in test mode)"""
#
# NOTE: we could just call self.snapshots.append() but this would trigger a zfs list which is not always needed. # # NOTE: we could just call self.snapshots.append() but this would trigger a zfs list which is not always needed.
if CachedProperty.is_cached(self, 'snapshots'): # if CachedProperty.is_cached(self, 'snapshots'):
# already cached so add it # # already cached so add it
self.snapshots.append(snapshot) # print ("ADDED")
else: # self.snapshots.append(snapshot)
# self.snapshots will add it when requested # else:
self._virtual_snapshots.append(snapshot) # # self.snapshots will add it when requested
# print ("ADDED VIRT")
# self._virtual_snapshots.append(snapshot)
@CachedProperty @CachedProperty
def snapshots(self): def snapshots(self):
@ -807,10 +809,7 @@ class ZfsDataset:
"zfs", "list", "-d", "1", "-r", "-t", "snapshot", "-H", "-o", "name", self.name "zfs", "list", "-d", "1", "-r", "-t", "snapshot", "-H", "-o", "name", self.name
] ]
return ( return self.from_names(self.zfs_node.run(cmd=cmd, readonly=True))
self.from_names(self.zfs_node.run(cmd=cmd, readonly=True)) +
self._virtual_snapshots
)
@property @property
def our_snapshots(self): def our_snapshots(self):
@ -1468,7 +1467,6 @@ class ZfsNode(ExecuteNode):
def consistent_snapshot(self, datasets, snapshot_name, min_changed_bytes): def consistent_snapshot(self, datasets, snapshot_name, min_changed_bytes):
"""create a consistent (atomic) snapshot of specified datasets, per pool. """create a consistent (atomic) snapshot of specified datasets, per pool.
""" """
pools = {} pools = {}
@ -1489,8 +1487,9 @@ class ZfsNode(ExecuteNode):
pools[pool].append(snapshot) pools[pool].append(snapshot)
# add snapshot to cache (also useful in testmode) # update cache, but try to prevent an unneeded zfs list
dataset.snapshots.append(snapshot) # NOTE: this will trigger zfs list if self.readonly or CachedProperty.is_cached(dataset, 'snapshots'):
dataset.snapshots.append(snapshot) # NOTE: this will trigger zfs list if its not cached
if not pools: if not pools:
self.verbose("No changes anywhere: not creating snapshots.") self.verbose("No changes anywhere: not creating snapshots.")