From nobody Sat Jul 11 22:05:25 2026 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 4gyN6t1Sv6z6lhNh for ; Sat, 11 Jul 2026 22:05:26 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gyN6s6tw5z3x3f for ; Sat, 11 Jul 2026 22:05:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783807526; 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=VeUQGKfT05uWm40VB7bGo+RwLDsFU379Cvsfrw8ojZk=; b=D/wkmu90zPghxZ1qzEHjl0tH6NH64xQeN/GoXl9y1fP5iUJavtlIgUUgf74QpF+kcA4viz jqnNACD3Y1syQ07TD/FmbSq5yWFxlFX6shtkp8/xVc9DNZnS+ZYkYSGLqQcBalsz509dti rsgUdOplAc6ZvR8HFPbPIaJwLpSMiHMJ/gQEugB8sT9t9NkNtXHFo3qoGXXch7S+01x4Id zXkvfF5CyvlFv/LKB5EDhdwyMVVzY4eyjE6+O6irY7VenxujwKH7jYuRfR61Twkc4LOkFW 6gUle77FYu2f0F4Ou3ieUNsQ2k7dmLOs9SKmgAjj8BScqjQo0EjSb1DWoqTPZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783807526; a=rsa-sha256; cv=none; b=hXgWtkpoIJ6OeQkaqP6PbfMIV2bBsseCGJQ9s5Y9bW7axrFl2iw9labegl+gNyjNxCTI4M QljjkuOGZ6ELulWO8L86VA7x4p9MT+VkKQ9QwASI7XS4aRFlXYsc8uQftublNHCvHVBOOd IHxfrKrgVserpL9SP+6UZHwmbTwQWC0QbBVJwK1dh2c0Ia7SO2VFfU9dnmQRdA+ttfzISP Hv0zGkNvz77jq1WKMa9nIgZ3kyYyyjsSNjzuTNmn0I0RyYCjadesV9XccpG90bybwewQBz 65ZS1+fN8zWIXyxrlcMwMc6AaCuKTEQRagdtyohKSDlcSX/GzecwzqwGb/g8RQ== 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=1783807526; 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=VeUQGKfT05uWm40VB7bGo+RwLDsFU379Cvsfrw8ojZk=; b=BWQZPouNTaGlOG8BuyIn3nVHdhXQNn1XoHhnNyvr7Y1wjCRpjwc5GM5GvXiLgNykRZEcjj fv0x0WofratjgPI/kNhtDpHgYQ64WAPZ/y9xJqxFnBKBjHe9rURx19YVVVRKlpPOYcVG49 HtE1JmhixjwcGeol3WXjJ6M0+MBH+HDiJuSYlwAV8NaJgN8O171PIh1WIg8uQE0kxMWaCS ScBdr/W5yw02QryFuaYc+q6qLE4sqDKHlkrtADnELg2uNFRrC4hpkA3ia7yER9W1VHovTh IOpQBT+Z0W/kVVxv7i8Y/1iV7Ttdz5Z8IB02cYdtKFtQDQmIIulHb+37/55u7A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gyN6s5g1jzyRj for ; Sat, 11 Jul 2026 22:05:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 40016 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 11 Jul 2026 22:05:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 5e0b96e728af - main - tmpfs: extract tmpfs_rename_check/set_parent() from tmpfs_rename() 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5e0b96e728af9916ac59d65e37155a95e06c3b5e Auto-Submitted: auto-generated Date: Sat, 11 Jul 2026 22:05:25 +0000 Message-Id: <6a52be25.40016.24568144@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5e0b96e728af9916ac59d65e37155a95e06c3b5e commit 5e0b96e728af9916ac59d65e37155a95e06c3b5e Author: Konstantin Belousov AuthorDate: 2026-06-18 20:01:35 +0000 Commit: Konstantin Belousov CommitDate: 2026-07-11 22:04:43 +0000 tmpfs: extract tmpfs_rename_check/set_parent() from tmpfs_rename() Reviewed by: mckusick Discussed with: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D57658 --- sys/fs/tmpfs/tmpfs_vnops.c | 167 ++++++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 78 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index b635450f205f..8021e42e7c06 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -962,6 +962,89 @@ releout: return (error); } +static int +tmpfs_rename_check_parent(struct tmpfs_mount *tmp, struct tmpfs_node *fdnode, + struct vnode *fvp, struct tmpfs_node *fnode, struct tmpfs_dirent *de, + struct tmpfs_node *tdnode, struct ucred *tcred) +{ + struct tmpfs_node *n; + int error; + + TMPFS_NODE_LOCK(fnode); + error = tmpfs_access_locked(fvp, fnode, VWRITE, tcred); + TMPFS_NODE_UNLOCK(fnode); + if (error != 0) + return (error); + + /* + * Ensure the target directory is not a child of the + * directory being moved. Otherwise, we'd end up + * with stale nodes. + * + * TMPFS_LOCK guarantees that no nodes are freed while + * traversing the list. Nodes can only be marked as + * removed: tn_parent == NULL. + */ + n = tdnode; + TMPFS_LOCK(tmp); + TMPFS_NODE_LOCK(n); + while (n != n->tn_dir.tn_parent) { + struct tmpfs_node *parent; + + if (n == fnode) { + TMPFS_NODE_UNLOCK(n); + TMPFS_UNLOCK(tmp); + return (EINVAL); + } + parent = n->tn_dir.tn_parent; + TMPFS_NODE_UNLOCK(n); + if (parent == NULL) { + n = NULL; + break; + } + TMPFS_NODE_LOCK(parent); + if (parent->tn_dir.tn_parent == NULL) { + TMPFS_NODE_UNLOCK(parent); + n = NULL; + break; + } + n = parent; + } + TMPFS_UNLOCK(tmp); + if (n == NULL) + return (EINVAL); + + TMPFS_NODE_UNLOCK(n); + + return (0); +} + +static void +tmpfs_rename_set_parent(struct tmpfs_node *fdnode, struct tmpfs_node *fnode, + struct tmpfs_dirent *de, struct tmpfs_node *tdnode) +{ + /* Adjust the parent pointer. */ + TMPFS_VALIDATE_DIR(fnode); + TMPFS_NODE_LOCK(de->td_node); + de->td_node->tn_dir.tn_parent = tdnode; + TMPFS_NODE_UNLOCK(de->td_node); + + /* + * As a result of changing the target of the '..' + * entry, the link count of the source and target + * directories has to be adjusted. + */ + TMPFS_NODE_LOCK(tdnode); + TMPFS_ASSERT_LOCKED(tdnode); + tdnode->tn_links++; + TMPFS_NODE_UNLOCK(tdnode); + + TMPFS_NODE_LOCK(fdnode); + TMPFS_ASSERT_LOCKED(fdnode); + fdnode->tn_links--; + TMPFS_NODE_UNLOCK(fdnode); +} + static int tmpfs_rename(struct vop_rename_args *v) { @@ -1129,86 +1212,14 @@ tmpfs_rename(struct vop_rename_args *v) * In case we are moving a directory, we have to adjust its * parent to point to the new parent. */ - if (de->td_node->tn_type == VDIR) { - struct tmpfs_node *n; - - TMPFS_NODE_LOCK(fnode); - error = tmpfs_access_locked(fvp, fnode, VWRITE, - tcnp->cn_cred); - TMPFS_NODE_UNLOCK(fnode); - if (error) { - if (newname != NULL) - free(newname, M_TMPFSNAME); + if (fnode->tn_type == VDIR) { + error = tmpfs_rename_check_parent(tmp, fdnode, fvp, + fnode, de, tdnode, tcnp->cn_cred); + if (error != 0) { + free(newname, M_TMPFSNAME); goto out_locked; } - - /* - * Ensure the target directory is not a child of the - * directory being moved. Otherwise, we'd end up - * with stale nodes. - */ - n = tdnode; - /* - * TMPFS_LOCK guaranties that no nodes are freed while - * traversing the list. Nodes can only be marked as - * removed: tn_parent == NULL. - */ - TMPFS_LOCK(tmp); - TMPFS_NODE_LOCK(n); - while (n != n->tn_dir.tn_parent) { - struct tmpfs_node *parent; - - if (n == fnode) { - TMPFS_NODE_UNLOCK(n); - TMPFS_UNLOCK(tmp); - error = EINVAL; - if (newname != NULL) - free(newname, M_TMPFSNAME); - goto out_locked; - } - parent = n->tn_dir.tn_parent; - TMPFS_NODE_UNLOCK(n); - if (parent == NULL) { - n = NULL; - break; - } - TMPFS_NODE_LOCK(parent); - if (parent->tn_dir.tn_parent == NULL) { - TMPFS_NODE_UNLOCK(parent); - n = NULL; - break; - } - n = parent; - } - TMPFS_UNLOCK(tmp); - if (n == NULL) { - error = EINVAL; - if (newname != NULL) - free(newname, M_TMPFSNAME); - goto out_locked; - } - TMPFS_NODE_UNLOCK(n); - - /* Adjust the parent pointer. */ - TMPFS_VALIDATE_DIR(fnode); - TMPFS_NODE_LOCK(de->td_node); - de->td_node->tn_dir.tn_parent = tdnode; - TMPFS_NODE_UNLOCK(de->td_node); - - /* - * As a result of changing the target of the '..' - * entry, the link count of the source and target - * directories has to be adjusted. - */ - TMPFS_NODE_LOCK(tdnode); - TMPFS_ASSERT_LOCKED(tdnode); - tdnode->tn_links++; - TMPFS_NODE_UNLOCK(tdnode); - - TMPFS_NODE_LOCK(fdnode); - TMPFS_ASSERT_LOCKED(fdnode); - fdnode->tn_links--; - TMPFS_NODE_UNLOCK(fdnode); + tmpfs_rename_set_parent(fdnode, fnode, de, tdnode); } }