From nobody Thu Mar 16 12:19:59 2023 X-Original-To: dev-commits-src-main@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 4PcmYC4pNzz3y3Bn; Thu, 16 Mar 2023 12:19:59 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PcmYC3s0Qz4KJH; Thu, 16 Mar 2023 12:19:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678969199; 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=u+JKUxxlz0vbPFt3yb9ZKY4LVzzQ8c2YADXzoIlnUk0=; b=VbkaPYnfGCH+KpRybYNSrEdflYXP4qiMK7H85K/9ZvSYrvEwCHk6AfceY7N938RPI1LsSq dUuz75CB48JQRQy7PRcdz15MPqeHBfoyV3icqyXoKx5xobpNtXVlMG/e8LF12Stfx7vXjq MESoozVyPhya97M6HKRySxsIJ3WFoNRdgndZRmvO/NPnOhZvJgatNOf1F486FrA6bNXJVE luMtEmemXEqAQMbBd9+gFSAeRHs/FnE/MKV0zXXx0kWH4f8zc6sm5B2aThrAIg0DyDda7W nUNulsrIMGBLpCOB7G004XRulgsDWZ1PP21FsSqfFgReMJ6SogVBNSZRJwWHoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678969199; 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=u+JKUxxlz0vbPFt3yb9ZKY4LVzzQ8c2YADXzoIlnUk0=; b=PRqq11hzXxK3SKoo2WnjOBHN4PYJuCAmnlIgrlcEgCh6wk5uPXyOl845mClRh3Z95Z7dR4 /vc1M4LsHzeuoVlhmyq+XyKgFMqzLFyBBG1A25+xhwn5SJeRCOufIF8To1BZjiBgQyq0Vb ifVZkG2DhpbzTLZEa6IyrxBKquFAL4ztoHzKuW0O52xcU5ogCQrD8aZT2mrtx+ElTNNW1v ryFuK2Igp5K5qtovfj6BZd9dJ0C/Hqati1KKSmY9JvFHpUlL7wFjU7M+oArpkk4SdBIZT4 Pk0G8ytqnyU5zmfqLT0zmAS5Nj/Uga/JZCzlKh5gv4x+BcqlrXG5yyiOUl7LHg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678969199; a=rsa-sha256; cv=none; b=ZNGGOih7k+q2+1wlNcFNyht5r8Pv2m6/EckqQzFvqD6jLdyYK9EW33fI7biOEvyD+Q1WnR gnCQg/Vvm3ST9afJrAwoRd1VVZzXagmYr3z7bR4Fa2IooKpmicVJfBAuOzm0EzuYHhWvR4 yRZkoDLjc7uQSgcQRwN6yxL+KTw0CCIDjmPxNvd8YSCerLyEpbrl0oaADNT9vEuWuD2yxh MkUEiKqdSaaD+tLslesOGcXsDcNMKwT2KTVLc+GEPYKYz09WyEsd2b35GZnNduyl+Ecw6l G6pvuB3Y2L2Dvk10x3pDIiVmkyj52CgdTpPZqnwFQW3rAfdH50faPMm6O50Q8A== 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 4PcmYC2fByzjmr; Thu, 16 Mar 2023 12:19:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32GCJxVg079845; Thu, 16 Mar 2023 12:19:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32GCJxF1079844; Thu, 16 Mar 2023 12:19:59 GMT (envelope-from git) Date: Thu, 16 Mar 2023 12:19:59 GMT Message-Id: <202303161219.32GCJxF1079844@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: fd8c98a52f71 - main - tarfs: Correctly track link count. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fd8c98a52f7178d8071cf201f2eb14f00d904a7d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=fd8c98a52f7178d8071cf201f2eb14f00d904a7d commit fd8c98a52f7178d8071cf201f2eb14f00d904a7d Author: Dag-Erling Smørgrav AuthorDate: 2023-03-16 11:31:06 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-03-16 11:31:22 +0000 tarfs: Correctly track link count. Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D39019 --- sys/fs/tarfs/tarfs_subr.c | 13 +++++++++++++ sys/fs/tarfs/tarfs_vfsops.c | 7 +++---- tests/sys/fs/tarfs/tarfs_test.sh | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sys/fs/tarfs/tarfs_subr.c b/sys/fs/tarfs/tarfs_subr.c index 0cba43a8c21b..6aa7eaedb773 100644 --- a/sys/fs/tarfs/tarfs_subr.c +++ b/sys/fs/tarfs/tarfs_subr.c @@ -384,6 +384,18 @@ tarfs_free_node(struct tarfs_node *tnp) tmp = tnp->tmp; switch (tnp->type) { + case VREG: + if (tnp->nlink-- > 1) + return; + if (tnp->other != NULL) + tarfs_free_node(tnp->other); + break; + case VDIR: + if (tnp->nlink-- > 2) + return; + if (tnp->parent != NULL && tnp->parent != tnp) + tarfs_free_node(tnp->parent); + break; case VLNK: if (tnp->link.name) free(tnp->link.name, M_TARFSNAME); @@ -397,6 +409,7 @@ tarfs_free_node(struct tarfs_node *tnp) free(tnp->blk, M_TARFSBLK); if (tnp->ino >= TARFS_MININO) free_unr(tmp->ino_unr, tnp->ino); + TAILQ_REMOVE(&tmp->allnodes, tnp, entries); free(tnp, M_TARFSNODE); tmp->nfiles--; } diff --git a/sys/fs/tarfs/tarfs_vfsops.c b/sys/fs/tarfs/tarfs_vfsops.c index 03dc598f4b69..9d7297eb9d73 100644 --- a/sys/fs/tarfs/tarfs_vfsops.c +++ b/sys/fs/tarfs/tarfs_vfsops.c @@ -406,16 +406,14 @@ static void tarfs_free_mount(struct tarfs_mount *tmp) { struct mount *mp; - struct tarfs_node *tnp; + struct tarfs_node *tnp, *tnp_next; MPASS(tmp != NULL); TARFS_DPF(ALLOC, "%s: Freeing mount structure %p\n", __func__, tmp); TARFS_DPF(ALLOC, "%s: freeing tarfs_node structures\n", __func__); - while (!TAILQ_EMPTY(&tmp->allnodes)) { - tnp = TAILQ_FIRST(&tmp->allnodes); - TAILQ_REMOVE(&tmp->allnodes, tnp, entries); + TAILQ_FOREACH_SAFE(tnp, &tmp->allnodes, entries, tnp_next) { tarfs_free_node(tnp); } @@ -744,6 +742,7 @@ again: error = EINVAL; goto bad; } + tnp->other->nlink++; break; case TAR_TYPE_SYMLINK: if (link == NULL) { diff --git a/tests/sys/fs/tarfs/tarfs_test.sh b/tests/sys/fs/tarfs/tarfs_test.sh index 6e44a8081cb2..50d98f857e06 100644 --- a/tests/sys/fs/tarfs/tarfs_test.sh +++ b/tests/sys/fs/tarfs/tarfs_test.sh @@ -59,6 +59,8 @@ tarfs_basic_body() { atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -L -f%d,%i "${mnt}"/short_link)" atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -L -f%d,%i "${mnt}"/long_link)" atf_check_equal "$(sha256 -q "${mnt}"/sparse_file)" ${sum} + atf_check_equal "$(stat -f%l "${mnt}"/sparse_file)" 2 + atf_check_equal "$(stat -f%l "${mnt}"/hard_link)" 2 } tarfs_basic_cleanup() { umount "${mnt}" || true