From nobody Mon Apr 21 03:49:51 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Zgrwb3pCkz5sqMv; Mon, 21 Apr 2025 03:49:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zgrwb2dy2z3Kkr; Mon, 21 Apr 2025 03:49:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745207391; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Si9HdEyMrv2coxa2MKFnL94EP2caWkzkzxJ5w0V2OAA=; b=PG9niMn9VXawNiUgkoEUCVHNeI6qqUwm4U+dcmDlCJV66VUti2Ipvw2uDlQvA9iY8IbFdt LSm9PptkRGNTTwipyftQ2qRdQYgNn2LuA6INF0/qvEiYSTR/XQlXSnKgMiujm4ocLdgSTJ cTncQVqyS91Gx5HiL4BrPIU8TaMZueeW4uNcYlt21kP2jYWUK48dHu0oce3yve3MzHy7kI 710LyN4zSwI46PlYQn/lNWAuoPDv2Ori1l0Afiyd2KTTuBCc6xK5JnxQwbeuVlUm/BUll3 noQQ38p4QR2oKpa81UV2k0+uBPWJSvv7bviFyyt2mnr8mL2dkbP7c2DeD8GuKA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745207391; a=rsa-sha256; cv=none; b=rXyUdXVZsxDMrAzmruLrW8/MvHlHMjmL4fk8OwtdGvvpDw2TNtbG9hcztWWcHEfH4LQfRi oc/NraFHO8zn6gXsEvY2tqAAXm+hBkWpCTeuFdrfidglX1xTosHxu2R/3vMsuMekZcNur+ yGUVQ3MnH/TJp+mQ5ryWpOU1C6pnSIzeqYa532ICmJ8TGxUqUVNwXemTx3WHsw0VU3CiEC ic3dGls2GZvWmsabeqq3EAjTbfIQaw1Uy1BBQH5aWal1ks3kL/PODQWtMVNguOPt3NP8w0 WtkwRlMSjwN9PBqLRLOJNURcJuvgMSVkarpZq0EIcrRkF1rtsIOEAbRCNMP2RA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745207391; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Si9HdEyMrv2coxa2MKFnL94EP2caWkzkzxJ5w0V2OAA=; b=Gg2wzuVLOyYs6Qq0nQZc5MdFZFhQdSQ5+HwNt9p5WsGiUildv8kSjTjh5ketDByPYB8Oy2 NssFgyHOd3lTk8x9BsXJl4o18OyAJfnUQlR9i9Z2nhU2k/zSbcHdVYWMc/WuIXIrw92fhd R2EI4ZWldGyQynFKAe/jbrRXm4Rk4cyUDfR9V3nxofi9Z9Gt6PHBKdbBqWTRSlS/6do6KP p9VP0PBHyIEbyGfBsokr7WAZFwz1qZ1fztl+iC5Nn9MyRCr/qnQFuKVqA7BFNebikRu3MA TiZ/9eAsGOGsjpARI9tU9ATq/bVVkHcieLljB1U/ffV23fse2PJIgx7BB+H76A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Zgrwb24VQzYxG; Mon, 21 Apr 2025 03:49:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53L3npdu062416; Mon, 21 Apr 2025 03:49:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53L3npP6062413; Mon, 21 Apr 2025 03:49:51 GMT (envelope-from git) Date: Mon, 21 Apr 2025 03:49:51 GMT Message-Id: <202504210349.53L3npP6062413@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: d6fbae084a2a - main - libbe: attempt to remove autocreated mountpoints at unmount time List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d6fbae084a2a0e07805633ca46935963357f1efa Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d6fbae084a2a0e07805633ca46935963357f1efa commit d6fbae084a2a0e07805633ca46935963357f1efa Author: Kyle Evans AuthorDate: 2025-04-21 03:47:59 +0000 Commit: Kyle Evans CommitDate: 2025-04-21 03:47:59 +0000 libbe: attempt to remove autocreated mountpoints at unmount time We use a be_mount.XXXX pattern to mkdtemp(3) when creating these, which seems reasonably unique enough to just continue using that. Record the mountpoint of the root dataset and check the dirname of that for the auto-creation trait. There's no sense in this bubbling up an error to callers, so we'll just ignore an error for now. Requested by: manu Differential Revision: https://reviews.freebsd.org/D42243 --- lib/libbe/be_access.c | 30 +++++++++++++++++++++++++++++- lib/libbe/libbe.3 | 7 +++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/libbe/be_access.c b/lib/libbe/be_access.c index 67b30d3fb4fb..51f5a75e957d 100644 --- a/lib/libbe/be_access.c +++ b/lib/libbe/be_access.c @@ -33,6 +33,8 @@ #include "be.h" #include "be_impl.h" +#define LIBBE_MOUNT_PREFIX "be_mount." /* XXX */ + struct be_mountcheck_info { const char *path; char *name; @@ -164,7 +166,11 @@ be_umount_iter(zfs_handle_t *zfs_hdl, void *data) if (!zfs_is_mounted(zfs_hdl, &mountpoint)) { return (0); } - free(mountpoint); + + if (info->depth == 0 && info->mountpoint == NULL) + info->mountpoint = mountpoint; + else + free(mountpoint); if (zfs_unmount(zfs_hdl, NULL, info->mntflags) != 0) { switch (errno) { @@ -307,10 +313,32 @@ be_unmount(libbe_handle_t *lbh, const char *bootenv, int flags) info.depth = 0; if ((err = be_umount_iter(root_hdl, &info)) != 0) { + free(__DECONST(char *, info.mountpoint)); zfs_close(root_hdl); return (err); } + /* + * We'll attempt to remove the directory if we created it on a + * best-effort basis. rmdir(2) failure will not be reported. + */ + if (info.mountpoint != NULL) { + const char *mdir; + + mdir = strrchr(info.mountpoint, '/'); + if (mdir == NULL) + mdir = info.mountpoint; + else + mdir++; + + if (strncmp(mdir, LIBBE_MOUNT_PREFIX, + sizeof(LIBBE_MOUNT_PREFIX) - 1) == 0) { + (void)rmdir(info.mountpoint); + } + } + + free(__DECONST(char *, info.mountpoint)); + zfs_close(root_hdl); return (BE_ERR_SUCCESS); } diff --git a/lib/libbe/libbe.3 b/lib/libbe/libbe.3 index 4d9439206b7b..113763311796 100644 --- a/lib/libbe/libbe.3 +++ b/lib/libbe/libbe.3 @@ -392,6 +392,13 @@ This list of properties matches the properties collected by The .Fn be_unmount function will unmount the given boot environment. +If the mount point looks like it was created by +.Fn be_mount , +then +.Fn be_unmount +will attempt to +.Xr rmdir 2 +the mountpoint after a successful unmount. Setting the .Dv BE_MNT_FORCE flag will pass