[PATCH 1/2] btrfs: Strip off <FS_TREE>/
by Tony Asleson
This was added to the command line output which caused us to fail when
getting file systems. Strip it off when seen.
Yet another reason why parsing stdout is 'bad'. All functionality should
have a stable library.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
targetd/fs.py | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/targetd/fs.py b/targetd/fs.py
index 6b25649..238470f 100644
--- a/targetd/fs.py
+++ b/targetd/fs.py
@@ -88,11 +88,19 @@ def split_stdout(out):
"""
Split the text out as an array of text arrays.
"""
+ strip_it = '<FS_TREE>/'
+
rc = []
for line in out.split('\n'):
elem = line.split(' ')
if len(elem) > 1:
- rc.append(elem)
+ tmp = []
+ for z in elem:
+ if z.startswith(strip_it):
+ tmp.append(z[len(strip_it):])
+ else:
+ tmp.append(z)
+ rc.append(tmp)
return rc
--
1.7.1
8 years, 11 months
[PATCH] Check for -1 values when retrieving percentages
by Tony Asleson
targetd was returning -3169126500561983635456 for a thinpool free space
during testing. This was caused by the api returning -1 when retrieving
the property 'data_percent' & 'metadata_percent'. This patch checks for
this and returns the full size for the free size if we are unable to get
actual values of consumed percentages.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
targetd/block.py | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/targetd/block.py b/targetd/block.py
index 391fc29..9f04c5c 100644
--- a/targetd/block.py
+++ b/targetd/block.py
@@ -292,9 +292,24 @@ def block_pools(req):
# we can only get used percent, so calculate an approx. free bytes
# These return an integer in of millionths of a percent, so
# add them and get a decimalization by dividing by another 100
- used_pct = float(thinp.getProperty("data_percent")[0] + \
- thinp.getProperty("metadata_percent")[0])/100000000
- return int(thinp.getSize() * (1 - used_pct))
+ #
+ # Note: It is possible for percentages to return a (-1) which depending
+ # on lvm2app library version can be returned as -1 or 2**64-1
+
+ unsigned_val = (2 ** 64 - 1)
+ free_bytes = thinp.getSize()
+ dp = thinp.getProperty("data_percent")[0]
+ mp = thinp.getProperty("metadata_percent")[0]
+
+ if dp != -1 and dp != unsigned_val and mp != -1 and mp != unsigned_val:
+ used_pct = float(dp + mp) / 100000000
+ fs = int(free_bytes * (1 - used_pct))
+
+ # Sanity checking, domain of free bytes should be [0..total size]
+ if 0 <= fs < free_bytes:
+ free_bytes = fs
+
+ return free_bytes
for pool in pools:
vg_name, tp_name = get_vg_lv(pool)
--
1.8.2.1
8 years, 11 months