Module Name:    src
Committed By:   chs
Date:           Fri Jul 31 04:07:30 UTC 2020

Modified Files:
        src/sys/kern: vfs_bio.c
        src/sys/sys: buf.h
        src/sys/ufs/ffs: ffs_inode.c

Log Message:
fix the UFS2 extattr truncate code to play nice with wapbl.
also, rather than pull in the FreeBSD V_NORMAL/V_ALT flags to
vinvalbuf() and the buf b_xflags field and BX_ALTDATA flag,
add a binvalbuf() function to invalid a specific buffer
and use that to invalidate the two possible exattr bufs
during IO_EXT truncations.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/sys/kern/vfs_bio.c
cvs rdiff -u -r1.133 -r1.134 src/sys/sys/buf.h
cvs rdiff -u -r1.130 -r1.131 src/sys/ufs/ffs/ffs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_bio.c
diff -u src/sys/kern/vfs_bio.c:1.296 src/sys/kern/vfs_bio.c:1.297
--- src/sys/kern/vfs_bio.c:1.296	Thu Jun 11 19:20:46 2020
+++ src/sys/kern/vfs_bio.c	Fri Jul 31 04:07:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_bio.c,v 1.296 2020/06/11 19:20:46 ad Exp $	*/
+/*	$NetBSD: vfs_bio.c,v 1.297 2020/07/31 04:07:30 chs Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.296 2020/06/11 19:20:46 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.297 2020/07/31 04:07:30 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bufcache.h"
@@ -1516,6 +1516,36 @@ getnewbuf(int slpflag, int slptimeo, int
 }
 
 /*
+ * Invalidate the specified buffer if it exists.
+ */
+void
+binvalbuf(struct vnode *vp, daddr_t blkno)
+{
+	buf_t *bp;
+	int err;
+
+	mutex_enter(&bufcache_lock);
+
+ loop:
+	bp = incore(vp, blkno);
+	if (bp != NULL) {
+		err = bbusy(bp, 0, 0, NULL);
+		if (err == EPASSTHROUGH)
+			goto loop;
+		bremfree(bp);
+		if (ISSET(bp->b_oflags, BO_DELWRI)) {
+			SET(bp->b_cflags, BC_NOCACHE);
+			mutex_exit(&bufcache_lock);
+			bwrite(bp);
+		} else {
+			brelsel(bp, BC_INVAL);
+			mutex_exit(&bufcache_lock);
+		}
+	} else
+		mutex_exit(&bufcache_lock);
+}
+
+/*
  * Attempt to free an aged buffer off the queues.
  * Called with queue lock held.
  * Returns the amount of buffer memory freed.

Index: src/sys/sys/buf.h
diff -u src/sys/sys/buf.h:1.133 src/sys/sys/buf.h:1.134
--- src/sys/sys/buf.h:1.133	Mon Apr 20 21:39:05 2020
+++ src/sys/sys/buf.h	Fri Jul 31 04:07:30 2020
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.h,v 1.133 2020/04/20 21:39:05 ad Exp $ */
+/*     $NetBSD: buf.h,v 1.134 2020/07/31 04:07:30 chs Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
@@ -287,6 +287,7 @@ buf_t	*incore(struct vnode *, daddr_t);
 int	allocbuf(buf_t *, int, int);
 void	brelsel(buf_t *, int);
 void	brelse(buf_t *, int);
+void	binvalbuf(struct vnode *, daddr_t);
 
 /*
  * So-far indeterminate ops that might belong to either

Index: src/sys/ufs/ffs/ffs_inode.c
diff -u src/sys/ufs/ffs/ffs_inode.c:1.130 src/sys/ufs/ffs/ffs_inode.c:1.131
--- src/sys/ufs/ffs/ffs_inode.c:1.130	Sun Jul 26 00:21:24 2020
+++ src/sys/ufs/ffs/ffs_inode.c	Fri Jul 31 04:07:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_inode.c,v 1.130 2020/07/26 00:21:24 chs Exp $	*/
+/*	$NetBSD: ffs_inode.c,v 1.131 2020/07/31 04:07:30 chs Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.130 2020/07/26 00:21:24 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.131 2020/07/31 04:07:30 chs Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -208,6 +208,7 @@ ffs_truncate(struct vnode *ovp, off_t le
 {
 	daddr_t lastblock;
 	struct inode *oip = VTOI(ovp);
+	struct mount *omp = ovp->v_mount;
 	daddr_t bn, lastiblock[UFS_NIADDR], indir_lbn[UFS_NIADDR];
 	daddr_t blks[UFS_NDADDR + UFS_NIADDR], oldblks[UFS_NDADDR + UFS_NIADDR];
 	struct fs *fs;
@@ -220,6 +221,8 @@ ffs_truncate(struct vnode *ovp, off_t le
 	int sync;
 	struct ufsmount *ump = oip->i_ump;
 	void *dcookie;
+	long bsize;
+	bool wapbl = omp->mnt_wapbl != NULL;
 
 	UFS_WAPBL_JLOCK_ASSERT(ump->um_mountp);
 
@@ -255,11 +258,11 @@ ffs_truncate(struct vnode *ovp, off_t le
 #ifdef QUOTA
 			(void) chkdq(oip, -extblocks, NOCRED, FORCE);
 #endif
-			vinvalbuf(ovp, 0, cred, curlwp, 0, 0);
 			osize = oip->i_din2->di_extsize;
 			oip->i_din2->di_blocks -= extblocks;
 			oip->i_din2->di_extsize = 0;
 			for (i = 0; i < UFS_NXADDR; i++) {
+				binvalbuf(ovp, -1 - i);
 				oldblks[i] = oip->i_din2->di_extb[i];
 				oip->i_din2->di_extb[i] = 0;
 			}
@@ -269,8 +272,15 @@ ffs_truncate(struct vnode *ovp, off_t le
 			for (i = 0; i < UFS_NXADDR; i++) {
 				if (oldblks[i] == 0)
 					continue;
-				ffs_blkfree(fs, oip->i_devvp, oldblks[i],
-				    ffs_sblksize(fs, osize, i), oip->i_number);
+				bsize = ffs_sblksize(fs, osize, i);
+				if (wapbl) {
+					error = UFS_WAPBL_REGISTER_DEALLOCATION(omp,
+					    FFS_FSBTODB(fs, oldblks[i]), bsize, NULL);
+					if (error)
+						return error;
+				} else 
+					ffs_blkfree(fs, oip->i_devvp, oldblks[i],
+					    bsize, oip->i_number);
 			}
 			extblocks = 0;
 		}
@@ -501,8 +511,6 @@ ffs_truncate(struct vnode *ovp, off_t le
 	 * All whole direct blocks or frags.
 	 */
 	for (i = UFS_NDADDR - 1; i > lastblock; i--) {
-		long bsize;
-
 		bn = ffs_getdb(fs, oip, i);
 		if (bn == 0)
 			continue;

Reply via email to