Use nsenter with pid:host to run zpool in host mount namespace
This commit is contained in:
@@ -15,16 +15,18 @@ async def get_zfs_pool_map() -> dict[str, str]:
|
||||
"""
|
||||
pool_map = {}
|
||||
try:
|
||||
env = os.environ.copy()
|
||||
host_lib = os.environ.get("ZFS_HOST_LIB")
|
||||
if host_lib:
|
||||
env["LD_LIBRARY_PATH"] = host_lib
|
||||
# When running in a container with pid:host, use nsenter to run
|
||||
# zpool in the host mount namespace so it finds its own libs.
|
||||
use_nsenter = os.environ.get("ZFS_USE_NSENTER", "").lower() in ("1", "true")
|
||||
if use_nsenter:
|
||||
cmd = ["nsenter", "-t", "1", "-m", "--", "zpool", "status", "-P"]
|
||||
else:
|
||||
cmd = [ZPOOL_BIN, "status", "-P"]
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
ZPOOL_BIN, "status", "-P",
|
||||
*cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
env=env,
|
||||
)
|
||||
stdout, _ = await proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
|
||||
Reference in New Issue
Block a user