ufs: Use IS_SNAPSHOT()

Reviewed by:	markj, mckusick
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D34072
This commit is contained in:
Konstantin Belousov 2022-01-20 15:17:59 +02:00
parent 3d68c4e175
commit 0cdc603308
3 changed files with 13 additions and 16 deletions

View File

@ -217,14 +217,12 @@ ufs_bmaparray(vp, bn, bnp, nbp, runp, runb)
* return a request for a zeroed out buffer if attempts
* are made to read a BLK_NOCOPY or BLK_SNAP block.
*/
if ((ip->i_flags & SF_SNAPSHOT) && DIP(ip, i_db[bn]) > 0 &&
if (IS_SNAPSHOT(ip) && DIP(ip, i_db[bn]) > 0 &&
DIP(ip, i_db[bn]) < ump->um_seqinc) {
*bnp = -1;
} else if (*bnp == 0) {
if (ip->i_flags & SF_SNAPSHOT)
*bnp = blkptrtodb(ump, bn * ump->um_seqinc);
else
*bnp = -1;
*bnp = IS_SNAPSHOT(ip) ? blkptrtodb(ump,
bn * ump->um_seqinc) : -1;
} else if (runp) {
ufs2_daddr_t bnb = bn;
for (++bn; bn < UFS_NDADDR && *runp < maxrun &&
@ -320,13 +318,13 @@ ufs_bmaparray(vp, bn, bnp, nbp, runp, runb)
* return a request for a zeroed out buffer if attempts are made
* to read a BLK_NOCOPY or BLK_SNAP block.
*/
if ((ip->i_flags & SF_SNAPSHOT) && daddr > 0 && daddr < ump->um_seqinc){
if (IS_SNAPSHOT(ip) && daddr > 0 && daddr < ump->um_seqinc){
*bnp = -1;
return (0);
}
*bnp = blkptrtodb(ump, daddr);
if (*bnp == 0) {
if (ip->i_flags & SF_SNAPSHOT)
if (IS_SNAPSHOT(ip))
*bnp = blkptrtodb(ump, bn * ump->um_seqinc);
else
*bnp = -1;
@ -367,7 +365,7 @@ ufs_bmap_seekdata(vp, offp)
mp = vp->v_mount;
ump = VFSTOUFS(mp);
if (vp->v_type != VREG || (ip->i_flags & SF_SNAPSHOT) != 0)
if (vp->v_type != VREG || IS_SNAPSHOT(ip))
return (EINVAL);
if (*offp < 0 || *offp >= ip->i_size)
return (ENXIO);

View File

@ -1245,8 +1245,7 @@ out:
* drop its snapshot reference so that it will be reclaimed
* when last open reference goes away.
*/
if (ip != NULL && (ip->i_flags & SF_SNAPSHOT) != 0 &&
ip->i_effnlink == 0)
if (ip != NULL && IS_SNAPSHOT(ip) && ip->i_effnlink == 0)
UFS_SNAPGONE(ip);
return (error);
}
@ -1320,7 +1319,7 @@ ufs_dirrewrite(dp, oip, newinum, newtype, isrmdir)
* drop its snapshot reference so that it will be reclaimed
* when last open reference goes away.
*/
if ((oip->i_flags & SF_SNAPSHOT) != 0 && oip->i_effnlink == 0)
if (IS_SNAPSHOT(oip) && oip->i_effnlink == 0)
UFS_SNAPGONE(oip);
return (error);
}

View File

@ -702,7 +702,7 @@ ufs_setattr(ap)
*/
if (vp->v_mount->mnt_flag & MNT_RDONLY)
return (EROFS);
if ((ip->i_flags & SF_SNAPSHOT) != 0)
if (IS_SNAPSHOT(ip))
return (EPERM);
break;
default:
@ -726,7 +726,7 @@ ufs_setattr(ap)
vap->va_birthtime.tv_sec != VNOVAL) {
if (vp->v_mount->mnt_flag & MNT_RDONLY)
return (EROFS);
if ((ip->i_flags & SF_SNAPSHOT) != 0)
if (IS_SNAPSHOT(ip))
return (EPERM);
error = vn_utimes_perm(vp, vap, cred, td);
if (error != 0)
@ -754,8 +754,8 @@ ufs_setattr(ap)
if (vap->va_mode != (mode_t)VNOVAL) {
if (vp->v_mount->mnt_flag & MNT_RDONLY)
return (EROFS);
if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
(S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
if (IS_SNAPSHOT(ip) && (vap->va_mode & (S_IXUSR | S_IWUSR |
S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)) != 0)
return (EPERM);
error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
}
@ -1022,7 +1022,7 @@ ufs_remove(ap)
error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
if (ip->i_nlink <= 0)
vp->v_vflag |= VV_NOSYNC;
if ((ip->i_flags & SF_SNAPSHOT) != 0) {
if (IS_SNAPSHOT(ip)) {
/*
* Avoid deadlock where another thread is trying to
* update the inodeblock for dvp and is waiting on