Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
tkt-64899: Rewrite IOCZFS to use subprocess calls (#731)
Browse files Browse the repository at this point in the history
* Rewrite IOCZFS to use subprocess calls

libzfs writes to stderr, and messing with fd's is not very clean. This also seems to perform better

FreeNAS Ticket: #64899

* Address review by @william-gr

- Remove zpool property, iocage doesn't use this
- Set the right prop as p
  • Loading branch information
Brandon Schneider committed Dec 18, 2018
1 parent 6522b2f commit 8a73125
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion iocage_lib/ioc_fetch.py
Expand Up @@ -875,7 +875,7 @@ def fetch_extract(self, f):

def fetch_update(self, cli=False, uuid=None):
"""This calls 'freebsd-update' to update the fetched RELEASE."""
tmp_dataset = self.zfs_get_dataset_name('/tmp', type='path')
tmp_dataset = self.zfs_get_dataset_name('/tmp')
tmp_val = self.zfs_get_property(tmp_dataset, 'exec')

if tmp_val == 'off':
Expand Down
55 changes: 34 additions & 21 deletions iocage_lib/ioc_json.py
Expand Up @@ -50,36 +50,49 @@ def __init__(self):
self.zfs = libzfs.ZFS(history=True, history_prefix="<iocage>")

def _zfs_get_properties(self, identifier):
if "/" in identifier:
dataset = self.zfs.get_dataset(identifier)
p_dict = {}

props = su.run(
[
'zfs',
'get',
'-pHo',
'property, value',
'all',
identifier
], stdout=su.PIPE, stderr=su.PIPE
).stdout.decode().splitlines()

for prop in props:
try:
p, v = prop.split()
except ValueError:
p, v = prop.strip(), '-'

return dataset.properties
else:
pool = self.zfs.get(identifier)
p_dict[p] = v

return pool.root_dataset.properties
return p_dict

def zfs_get_property(self, identifier, key):
try:
return self._zfs_get_properties(identifier)[key].value
return self._zfs_get_properties(identifier)[key]
except Exception:
return "-"
return '-'

def zfs_set_property(self, identifier, key, value):
ds = self._zfs_get_properties(identifier)

if ":" in key:
ds[key] = libzfs.ZFSUserProperty(value)
else:
ds[key].value = value
su.run(
[
'zfs', 'set', f'{key}={value}', identifier
], stdout=su.PIPE, stderr=su.PIPE
)

def zfs_get_dataset_name(self, name, type='name'):
def zfs_get_dataset_name(self, name):
try:
if type == 'name':
ds = self.zfs.get_dataset(name).name
else:
ds = self.zfs.get_dataset_by_path(name).name
except Exception:
ds = su.run(
['zfs', 'get', '-pHo', 'name', 'mountpoint', name],
stdout=su.PIPE, stderr=su.PIPE
).stdout.decode()
except su.CalledProcessError:
ds = None

return ds
Expand Down Expand Up @@ -216,7 +229,7 @@ def get_pool():
"INFO",
"message":
f"Setting up zpool [{zpool}] for"
" iocage usage\n If you wish to change"
" iocage usage\nIf you wish to change"
" please use \"iocage activate\""
},
_callback=self.callback,
Expand Down
2 changes: 1 addition & 1 deletion iocage_lib/ioc_upgrade.py
Expand Up @@ -79,7 +79,7 @@ def __init__(self,
self.callback = callback

def upgrade_jail(self):
tmp_dataset = self.zfs_get_dataset_name('/tmp', type='path')
tmp_dataset = self.zfs_get_dataset_name('/tmp')
tmp_val = self.zfs_get_property(tmp_dataset, 'exec')

if tmp_val == 'off':
Expand Down

0 comments on commit 8a73125

Please sign in to comment.