Skip to content

Commit

Permalink
storage/reflink: implement usage_details(), handle absent pool
Browse files Browse the repository at this point in the history
Make only one statvfs() call to get consistent size and usage
information.

Also handle an absent pool correctly by returning an empty dict for
usage_details() and None for size() and usage() instead of raising
FileNotFoundError.

QubesOS/qubes-issues#8187
QubesOS/qubes-issues#8188

(cherry picked from commit 2deb827)
  • Loading branch information
rustybird authored and marmarek committed Jul 4, 2023
1 parent 43f01dd commit 0711068
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions qubes/storage/reflink.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,23 @@ def config(self):
'ephemeral_volatile': self.ephemeral_volatile,
}

@property
def usage_details(self):
with suppress(FileNotFoundError):
stat = os.statvfs(self.dir_path)
return {
'data_size': stat.f_frsize * stat.f_blocks,
'data_usage': stat.f_frsize * (stat.f_blocks - stat.f_bfree),
}
return {}

@property
def size(self):
statvfs = os.statvfs(self.dir_path)
return statvfs.f_frsize * statvfs.f_blocks
return self.usage_details.get('data_size')

@property
def usage(self):
statvfs = os.statvfs(self.dir_path)
return statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)
return self.usage_details.get('data_usage')

def included_in(self, app):
''' Check if there is pool containing this one - either as a
Expand Down

0 comments on commit 0711068

Please sign in to comment.