From nobody Sat Aug 12 18:21:01 2023 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 4RNTW20cNGz4qN7w; Sat, 12 Aug 2023 18:21:02 +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 4RNTW2060Gz3bPP; Sat, 12 Aug 2023 18:21:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691864462; 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=vYqlw7pVG0B4CagbxjCGJcibEObaa2F6Fexj1FgQYAo=; b=OZMTrf5fTbJ+8PXDeDvDSAPEa0+mWrKJ6rZ1vu4WRmeHISRkz3ANAVszZnxcJAV4oqWDb1 oTcc7KP2n/DDnJ4vyooMWKKYw4O7pPwlrqbBeRJPtW7il5stKyWjG2y4G4vhhloRc/Qb3v kuI34Dbf8CRRz51XZsl1unoXKXMx4R3bZD0z+dgFCeWiG3uoQTmUU+YYYXaAjuoOAC6Sfi AsP3d5uzIvqUg3HC+zoxwU1QnOeNI/+1niM2UqAd9yl2F3WXkXf9SZoVW8Fl8nrCTDbws0 kLLaZ2CQcWPHbOb0KBheJqhSq5Jvc1XhNwNAEHotxoPHTgn1Sx/z+YVSUv1eSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691864462; 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=vYqlw7pVG0B4CagbxjCGJcibEObaa2F6Fexj1FgQYAo=; b=sxUBb3ph6fyChcPHkWFVXvvKygYwfRnbTLgiccpgAyMjJZGgKjV9mRpPDksEJADCr6hvsp DbZtrNe5O5l9q3DTAXZjWbsudVqpche9aG8M7JVhLTzk4NugBFYQ8Dk7gS6K5UuC/llEHP zQbteOZUQTtgE/c88rTDEGSIKMZRPNhzP+wTcPdg3876tGs1Y8O6BFJ0Hdqs8Kbo2pQrLQ svD9CpEnnr6W4NznHwRGBZjBSCNoVZogLPuKqF1UvlUqeFiKWEhxk655fQX3ns91Iv7gx4 PJT1cOTAd6kJOZSNOF2zqsUyekhG20ObGa5aZujSq04/MDNIUpnFcIgjv85VQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691864462; a=rsa-sha256; cv=none; b=B+TGR4hr9EKNoPqJQgeKuIyGH7GWQcTiFGVmX7Q/hnTPk1FGDw6SGHbggxqZNOJZdG5r6A qkSQi/koxCeAHnvW9N89j/Bh2rS6R9Rnnv7dpw5KJaG6xBxtIlPB5qO4zXHBSbh8weAMDu jmzC59OcPVrApsFQhDxpma0HH3yo5Wv/WLtcmMggDcTV5DeqrFswui4TcpZAtaC/tri2FT 11fjEzWfOvDU0wnwY83bIa3etHwuPPrVgY95AjOaXIHK/G2QhC/U27z1hzcRT6n22ocgx1 qtsi9/Y7yykONwUeFFnNAClplNKSJyeQbawXVzaZxfjq3K6aj/ORyqaUxizH0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RNTW16GhlzWHD; Sat, 12 Aug 2023 18:21:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37CIL1Il016575; Sat, 12 Aug 2023 18:21:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37CIL1ja016572; Sat, 12 Aug 2023 18:21:01 GMT (envelope-from git) Date: Sat, 12 Aug 2023 18:21:01 GMT Message-Id: <202308121821.37CIL1ja016572@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: 220427da0e9b - main - Set UFS/FFS file type to snapshot before changing its block pointers. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 220427da0e9b2c1d8e964120becc17eb7524e46f Auto-Submitted: auto-generated The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=220427da0e9b2c1d8e964120becc17eb7524e46f commit 220427da0e9b2c1d8e964120becc17eb7524e46f Author: Kirk McKusick AuthorDate: 2023-08-12 18:20:08 +0000 Commit: Kirk McKusick CommitDate: 2023-08-12 18:20:40 +0000 Set UFS/FFS file type to snapshot before changing its block pointers. A UFS/FFS snapshot file is identified with the SF_SNAPSHOT flag to identify it as a snapshot. This flag needs to be set before setting some of its block pointers to the special values BLK_SNAP and BLK_NOCOPY. If the snapshot creation fails and we call VOP_REMOVE(), the SF_SNAPSHOT flag will let the remove routine know that the special block pointer values need to be rolled back before attempting deletion of the file. Also ensure that an fsck is required after setting superblock values in the ffs_checkcgintegrity() routine. Reported-by: Peter Holm Tested-by: Peter Holm MFC-after: 1 week Sponsored-by: The FreeBSD Foundation --- sys/ufs/ffs/ffs_alloc.c | 1 + sys/ufs/ffs/ffs_snapshot.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index d2627647360a..a1da0b05678a 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -3130,6 +3130,7 @@ ffs_checkcgintegrity(struct fs *fs, fs->fs_cstotal.cs_nifree -= fs->fs_cs(fs, cg).cs_nifree; fs->fs_cs(fs, cg).cs_nifree = 0; fs->fs_maxcluster[cg] = 0; + fs->fs_flags |= FS_NEEDSFSCK; fs->fs_fmod = 1; } diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c index 6a3329078817..9cfd56472a78 100644 --- a/sys/ufs/ffs/ffs_snapshot.c +++ b/sys/ufs/ffs/ffs_snapshot.c @@ -368,6 +368,15 @@ restart: goto out; } } + /* + * Change inode to snapshot type file. Before setting its block + * pointers to BLK_SNAP and BLK_NOCOPY in cgaccount, we have to + * set its type to SF_SNAPSHOT so that VOP_REMOVE will know that + * they need to be rolled back before attempting deletion. + */ + ip->i_flags |= SF_SNAPSHOT; + DIP_SET(ip, i_flags, ip->i_flags); + UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_UPDATE); /* * Copy all the cylinder group maps. Although the * filesystem is still active, we hope that only a few @@ -393,12 +402,6 @@ restart: if (error) goto out; } - /* - * Change inode to snapshot type file. - */ - ip->i_flags |= SF_SNAPSHOT; - DIP_SET(ip, i_flags, ip->i_flags); - UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_UPDATE); /* * Ensure that the snapshot is completely on disk. * Since we have marked it as a snapshot it is safe to