git: 886fd36e1ac2 - main - Clean up and document UFS/FFS error returns.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Fri, 11 Aug 2023 00:54:20 UTC
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=886fd36e1ac2082f1b0decb89d70e1e7a0dc3043

commit 886fd36e1ac2082f1b0decb89d70e1e7a0dc3043
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2023-08-11 00:50:23 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2023-08-11 00:54:06 +0000

    Clean up and document UFS/FFS error returns.
    
    The ffs_inotovp() function returns a vnode from a mounted filesystem
    for an inode number with specified generation number. We now
    consistently return ESTALE if the inode with given generation number
    no longer exists on that filesystem.
    
    The ffs_reload() function reloads all incore data for a filesystem.
    It is used after running fsck on a mounted filesystem and finding
    things to fix. It now returns the EINTEGRITY error if it is unable
    to find a valid superblock.
    
    MFC-after:    1 week
    Sponsored-by: The FreeBSD Foundation
---
 sys/ufs/ffs/ffs_vfsops.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index b2cd2d30bc04..41c3582a91ae 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -796,7 +796,7 @@ ffs_reload(struct mount *mp, int flags)
 	    newfs->fs_bsize > MAXBSIZE ||
 	    newfs->fs_bsize < sizeof(struct fs)) {
 			brelse(bp);
-			return (EIO);		/* XXX needs translation */
+			return (EINTEGRITY);
 	}
 	/*
 	 * Preserve the summary information, read-only status, and
@@ -2052,6 +2052,11 @@ ffs_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp)
 	    vpp, 0));
 }
 
+/*
+ * Return a vnode from a mounted filesystem for inode with specified
+ * generation number. Return ESTALE if the inode with given generation
+ * number no longer exists on that filesystem.
+ */
 int
 ffs_inotovp(struct mount *mp,
 	ino_t ino,
@@ -2067,7 +2072,6 @@ ffs_inotovp(struct mount *mp,
 	struct cg *cgp;
 	struct buf *bp;
 	uint64_t cg;
-	int error;
 
 	ump = VFSTOUFS(mp);
 	fs = ump->um_fs;
@@ -2082,9 +2086,8 @@ ffs_inotovp(struct mount *mp,
 	 */
 	if (fs->fs_magic == FS_UFS2_MAGIC) {
 		cg = ino_to_cg(fs, ino);
-		error = ffs_getcg(fs, ump->um_devvp, cg, 0, &bp, &cgp);
-		if (error != 0)
-			return (error);
+		if (ffs_getcg(fs, ump->um_devvp, cg, 0, &bp, &cgp) != 0)
+			return (ESTALE);
 		if (ino >= cg * fs->fs_ipg + cgp->cg_initediblk) {
 			brelse(bp);
 			return (ESTALE);
@@ -2092,9 +2095,8 @@ ffs_inotovp(struct mount *mp,
 		brelse(bp);
 	}
 
-	error = ffs_vgetf(mp, ino, lflags, &nvp, ffs_flags);
-	if (error != 0)
-		return (error);
+	if (ffs_vgetf(mp, ino, lflags, &nvp, ffs_flags) != 0)
+		return (ESTALE);
 
 	ip = VTOI(nvp);
 	if (ip->i_mode == 0 || ip->i_gen != gen || ip->i_effnlink <= 0) {