cleaning files beyond EOF

Konstantin Belousov kostikbel at gmail.com
Fri Feb 22 08:38:39 UTC 2013


On Sun, Feb 17, 2013 at 09:48:32AM +0200, Konstantin Belousov wrote:
> But the ffs_getpages() might be indeed the culprit. It calls
> vm_page_zero_invalid(), which only has DEV_BSIZE granularity. I think
> that ffs_getpages() also should zero the after eof part of the last page
> of the file to fix your damage, since device read cannot read less than
> DEV_BSIZE.
> 

Here is the updated patch, with the bug fixed which mis-calculated the
size for pmap_zero_page_area().

diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index 5c99d5b..08508a4 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -829,9 +829,9 @@ static int
 ffs_getpages(ap)
 	struct vop_getpages_args *ap;
 {
-	int i;
 	vm_page_t mreq;
-	int pcount;
+	uint64_t size;
+	int i, isize, pcount;
 
 	pcount = round_page(ap->a_count) / PAGE_SIZE;
 	mreq = ap->a_m[ap->a_reqpage];
@@ -846,6 +846,11 @@ ffs_getpages(ap)
 	if (mreq->valid) {
 		if (mreq->valid != VM_PAGE_BITS_ALL)
 			vm_page_zero_invalid(mreq, TRUE);
+		size = VTOI(ap->a_vp)->i_size;
+		if (mreq->pindex == OFF_TO_IDX(size)) {
+			isize = size & PAGE_MASK;
+			pmap_zero_page_area(mreq, isize, PAGE_SIZE - isize);
+		}
 		for (i = 0; i < pcount; i++) {
 			if (i != ap->a_reqpage) {
 				vm_page_lock(ap->a_m[i]);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20130222/4ae71476/attachment.sig>


More information about the freebsd-fs mailing list