git: 220427da0e9b - main - Set UFS/FFS file type to snapshot before changing its block pointers.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 12 Aug 2023 18:21:01 UTC
The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=220427da0e9b2c1d8e964120becc17eb7524e46f commit 220427da0e9b2c1d8e964120becc17eb7524e46f Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2023-08-12 18:20:08 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> 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