diff options
author | Kirk McKusick <mckusick@FreeBSD.org> | 2023-08-12 18:20:08 +0000 |
---|---|---|
committer | Kirk McKusick <mckusick@FreeBSD.org> | 2023-08-12 18:20:40 +0000 |
commit | 220427da0e9b2c1d8e964120becc17eb7524e46f (patch) | |
tree | 02b847d5e49e6762e4f8f7043d1587bf99fd2367 | |
parent | b1a39c31a3569bd045a0f40057c3773fc8166f6d (diff) | |
download | src-220427da0e9b2c1d8e964120becc17eb7524e46f.tar.gz src-220427da0e9b2c1d8e964120becc17eb7524e46f.zip |
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
-rw-r--r-- | sys/ufs/ffs/ffs_alloc.c | 1 | ||||
-rw-r--r-- | 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 @@ -369,6 +369,15 @@ restart: } } /* + * 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 * cylinder groups will change between now and when we @@ -394,12 +403,6 @@ restart: 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 * unlock it as no process will be allowed to write to it. |