linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Viro <viro@math.psu.edu>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] Re: test12-pre6
Date: Wed, 6 Dec 2000 03:03:12 -0500 (EST)	[thread overview]
Message-ID: <Pine.GSO.4.21.0012060254280.14974-100000@weyl.math.psu.edu> (raw)
In-Reply-To: <Pine.LNX.4.10.10012052318270.5786-100000@penguin.transmeta.com>

	If get_block() fails in block_prepare_write() we should zero
the blocks we've allocated and mark them dirty. We don't (i.e. we leave
the random junk in file in that case). Fix: do it. Moreover, if
->prepare_write() fails generic_file_write() is not going to write the user's
data into that page. It's OK if we were in hole (we got zeroes in all
new blocks, so it's equivalent to doing nothing with that page), but it's
not OK if we extended the file (we would get the file silently extended
with zeroes we've never intended to write there or we would get blocks
allocated past the ->i_size - the former screws applications, the latter
makes fsck unhappy).  Fix: if the failed call extended the file call
vmtruncate() to clean the mess up.

	Please, apply.

diff -urN rc12-pre6/fs/buffer.c rc12-pre6-get_block/fs/buffer.c
--- rc12-pre6/fs/buffer.c	Tue Dec  5 02:03:14 2000
+++ rc12-pre6-get_block/fs/buffer.c	Tue Dec  5 14:56:20 2000
@@ -1710,6 +1710,15 @@
 	}
 	return 0;
 out:
+	bh = head;
+	do {
+		if (buffer_new(bh) && !buffer_uptodate(bh)) {
+			memset(bh->b_data, 0, bh->b_size);
+			set_bit(BH_Uptodate, &bh->b_state);
+			mark_buffer_dirty(bh);
+		}
+		bh = bh->b_this_page;
+	} while (bh != head);
 	return err;
 }
 
diff -urN rc12-pre6/mm/filemap.c rc12-pre6-get_block/mm/filemap.c
--- rc12-pre6/mm/filemap.c	Tue Dec  5 02:03:20 2000
+++ rc12-pre6-get_block/mm/filemap.c	Tue Dec  5 14:56:20 2000
@@ -2382,6 +2382,7 @@
 	unsigned long	written;
 	long		status;
 	int		err;
+	unsigned	bytes;
 
 	cached_page = NULL;
 
@@ -2426,7 +2427,7 @@
 	}
 
 	while (count) {
-		unsigned long bytes, index, offset;
+		unsigned long index, offset;
 		char *kaddr;
 
 		/*
@@ -2451,7 +2452,7 @@
 
 		status = mapping->a_ops->prepare_write(file, page, offset, offset+bytes);
 		if (status)
-			goto unlock;
+			goto sync_failure;
 		kaddr = page_address(page);
 		status = copy_from_user(kaddr+offset, buf, bytes);
 		flush_dcache_page(page);
@@ -2476,6 +2477,7 @@
 		if (status < 0)
 			break;
 	}
+done:
 	*ppos = pos;
 
 	if (cached_page)
@@ -2496,6 +2498,13 @@
 	ClearPageUptodate(page);
 	kunmap(page);
 	goto unlock;
+sync_failure:
+	UnlockPage(page);
+	deactivate_page(page);
+	page_cache_release(page);
+	if (pos + bytes > inode->i_size)
+		vmtruncate(inode, inode->i_size);
+	goto done;
 }
 
 void __init page_cache_init(unsigned long mempages)


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

  parent reply	other threads:[~2000-12-06  8:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-06  7:25 test12-pre6 Linus Torvalds
2000-12-06  7:50 ` test12-pre6 Alexander Viro
2000-12-06  7:54 ` [PATCH] test12-pre6 Alexander Viro
2000-12-06  8:03 ` Alexander Viro [this message]
2000-12-06  8:06 ` Alexander Viro
2000-12-06  8:26   ` Tigran Aivazian
2000-12-06  8:38     ` Tigran Aivazian
2000-12-06  8:56       ` Tigran Aivazian
2000-12-06  9:07         ` Alexander Viro
2000-12-06  9:29           ` Tigran Aivazian
2000-12-06  8:11 ` Alexander Viro
2000-12-06 11:47 ` test12-pre6 Wakko Warner
2000-12-06 12:04   ` test12-pre6 Andrew Morton
2000-12-07  1:43     ` test12-pre6 Wakko Warner
2000-12-06 13:06 ` test12-pre6 Tobias Ringstrom
2000-12-06 13:29   ` test12-pre6 Miles Lane
2000-12-06 18:08 ` test12-pre6 Erik Mouw
2000-12-06 18:38   ` test12-pre6 Linus Torvalds
2000-12-06 19:08     ` test12-pre6 Erik Mouw
2000-12-06 19:38       ` test12-pre6 Linus Torvalds
2000-12-06 20:09         ` test12-pre6 Erik Mouw
2000-12-06 21:06           ` test12-pre6 Jeff Garzik
2000-12-06 22:57             ` test12-pre6 Miles Lane
2000-12-06 23:10               ` test12-pre6 Johannes Erdfelt
2000-12-06 23:13               ` test12-pre6 Jeff Garzik
2000-12-06 23:17                 ` test12-pre6 Miles Lane
2000-12-07  0:05           ` test12-pre6 Miles Lane

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.21.0012060254280.14974-100000@weyl.math.psu.edu \
    --to=viro@math.psu.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).