Skip to content

Unhide shared ZFS zvol devices #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions libioc/Jail.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,7 @@ def start(
exec_start.append("service ipfw onestop")

if self.config["jail_zfs"] is True:
share_storage = libioc.ZFSShareStorage.QueuingZFSShareStorage(
jail=self,
logger=self.logger
)
share_storage = self._zfs_share_storage
share_storage.mount_zfs_shares()
exec_start += share_storage.read_commands("jail")
exec_created += share_storage.read_commands()
Expand Down Expand Up @@ -615,6 +612,15 @@ def _stop_failed_jail(

yield jailLaunchEvent.end(stdout=stdout)

@property
def _zfs_share_storage(
self
) -> libioc.ZFSShareStorage.QueuingZFSShareStorage:
return libioc.ZFSShareStorage.QueuingZFSShareStorage(
jail=self,
logger=self.logger
)

def _start_dependant_jails(
self,
terms: libioc.Filter.Terms,
Expand Down Expand Up @@ -1603,6 +1609,25 @@ def devfs_ruleset(self) -> libioc.DevfsRules.DevfsRuleset:
if self._allow_mount_zfs == "1":
devfs_ruleset.append("add path zfs unhide")

if self.config["jail_zfs"] is True:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do i understand the PR correctly that this can be both, a zfs dataset or a zvol?

unhidden_parents: typing.Set[str] = set()
shared_datasets = self._zfs_share_storage.get_zfs_datasets()
if len(shared_datasets) > 0:
devfs_ruleset.append("add path zvol unhide")
for shared_dataset in shared_datasets:
current_dataset_name = "zvol"
for fragment in shared_dataset.name.split("/"):
current_dataset_name += f"/{fragment}"
if current_dataset_name in unhidden_parents:
continue
unhidden_parents.add(current_dataset_name)
devfs_ruleset.append(
f"add path {current_dataset_name} unhide"
)
devfs_ruleset.append(
f"add path {current_dataset_name}/* unhide"
)

# create if the final rule combination does not exist as ruleset
if devfs_ruleset not in self.host.devfs:
self.logger.verbose("New devfs ruleset combination")
Expand Down
31 changes: 16 additions & 15 deletions libioc/ZFSShareStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""iocage ZFS share storage backend."""
import typing
import libzfs
import shlex

import libioc.errors
import libioc.helpers
Expand Down Expand Up @@ -58,23 +59,23 @@ def umount_zfs_shares(self) -> None:
"/sbin/zfs",
"set",
"jailed=off",
dataset.name
shlex.quote(dataset.name)
])
self._exec([
"/sbin/zfs",
"umount",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm surprised we're not doing this with libzfs

dataset.name
shlex.quote(dataset.name)
])
self._exec([
"/sbin/zfs",
"mount",
dataset.name
shlex.quote(dataset.name)
])
self._exec([
"/sbin/zfs",
"set",
"jailed=on",
dataset.name
shlex.quote(dataset.name)
])

def get_zfs_datasets(
Expand All @@ -87,18 +88,18 @@ def get_zfs_datasets(
datasets = set()
for name in dataset_names:

try:
zpool = self._get_pool_from_dataset_name(name)
except libioc.errors.ZFSPoolUnavailable:
# legacy support (datasets not prefixed with pool/)
zpool = self.jail.pool
name = f"{self.jail.pool_name}/{name}"
if auto_create is True:
try:
zpool = self._get_pool_from_dataset_name(name)
except libioc.errors.ZFSPoolUnavailable:
# legacy support (datasets not prefixed with pool/)
zpool = self.jail.pool
name = f"{self.jail.pool_name}/{name}"

try:
if auto_create is True:
try:
zpool.create(name, {}, create_ancestors=True)
except libzfs.ZFSException:
pass
except libzfs.ZFSException:
pass

try:
dataset = self.zfs.get_dataset(name)
Expand All @@ -125,7 +126,7 @@ def _mount_jail_datasets(

# ToDo: bake jail feature into py-libzfs
self._exec(
self._zfs_jail_command + [dataset.name],
self._zfs_jail_command + [shlex.quote(dataset.name)],
logger=self.logger
)

Expand Down