git: c52b5d16ccf2 - main - Remove a partial UFS/FFS snapshot if it fails to build successfully.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 09 Aug 2023 23:44:43 UTC
The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=c52b5d16ccf29ad0e999a1f5f813ed6472aa3771 commit c52b5d16ccf29ad0e999a1f5f813ed6472aa3771 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2023-08-09 23:43:41 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2023-08-09 23:44:24 +0000 Remove a partial UFS/FFS snapshot if it fails to build successfully. When taking a UFS/FFS snapshot, it may not succeed for example if the filesystem is too full to hold it. When a snapshot is unable to be successfully taken, the partial snapshot should be removed. Reported-by: Peter Holm Tested-by: Peter Holm MFC-after: 1 week Sponsored-by: The FreeBSD Foundation --- sys/ufs/ffs/ffs_snapshot.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c index 26eecfcc5875..6a3329078817 100644 --- a/sys/ufs/ffs/ffs_snapshot.c +++ b/sys/ufs/ffs/ffs_snapshot.c @@ -851,7 +851,6 @@ done: free(copy_fs, M_UFSMNT); copy_fs = NULL; out: - NDFREE_PNBUF(&nd); if (saved_nice > 0) { struct proc *p; @@ -869,14 +868,30 @@ out: MNT_ILOCK(mp); mp->mnt_flag = (mp->mnt_flag & MNT_QUOTA) | (flag & ~MNT_QUOTA); MNT_IUNLOCK(mp); - if (error) - (void) ffs_truncate(vp, (off_t)0, 0, NOCRED); - (void) ffs_syncvnode(vp, MNT_WAIT, 0); - if (error) - vput(vp); - else - VOP_UNLOCK(vp); + NDFREE_PNBUF(&nd); vrele(nd.ni_dvp); + if (error == 0) { + (void) ffs_syncvnode(vp, MNT_WAIT, 0); + VOP_UNLOCK(vp); + } else if (VN_IS_DOOMED(vp)) { + vput(vp); + } else { + int rmerr; + + /* Remove snapshot as its creation has failed. */ + vput(vp); + NDINIT(&nd, DELETE, LOCKPARENT | LOCKLEAF, UIO_SYSSPACE, + snapfile); + if ((rmerr = namei(&nd)) != 0 || + (rmerr = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd)) != 0) + printf("Delete of %s failed with error %d\n", + nd.ni_dirp, rmerr); + NDFREE_PNBUF(&nd); + if (nd.ni_dvp != NULL) + vput(nd.ni_dvp); + if (nd.ni_vp != NULL) + vput(nd.ni_vp); + } vn_finished_write(wrtmp); process_deferred_inactive(mp); return (error);