linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@us.ibm.com>
To: Theodore Tso <tytso@mit.edu>, Jan Kara <jack@suse.cz>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
	"Darrick J. Wong" <djwong@us.ibm.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Jeff Layton <jlayton@redhat.com>,
	Dave Chinner <david@fromorbit.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Dave Hansen <dave@linux.vnet.ibm.com>,
	Christoph Hellwig <hch@infradead.org>,
	linux-mm@kvack.org, Chris Mason <chris.mason@oracle.com>,
	Joel Becker <jlbec@evilplan.org>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-ext4@vger.kernel.org, Mingming Cao <mcao@us.ibm.com>
Subject: [PATCH 7/7] fat: Lock buffer_head during metadata updates
Date: Mon, 09 May 2011 16:04:11 -0700	[thread overview]
Message-ID: <20110509230411.19566.66436.stgit@elm3c44.beaverton.ibm.com> (raw)
In-Reply-To: <20110509230318.19566.66202.stgit@elm3c44.beaverton.ibm.com>

In order to stabilize page writes during writeback operations, it is necessary
to enforce a rule that writes to memory pages containing metadata cannot happen
at the same time that the page is being written to disk.  To provide this, lock
the buffer_head representing a piece of metadata while updating memory.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---
 fs/fat/dir.c         |   14 ++++++++++++++
 fs/fat/fatent.c      |   12 ++++++++++++
 fs/fat/inode.c       |    2 ++
 fs/fat/misc.c        |    2 ++
 fs/fat/namei_msdos.c |    4 ++++
 fs/fat/namei_vfat.c  |    4 ++++
 6 files changed, 38 insertions(+), 0 deletions(-)


diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index ee42b9e..9efea13 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -958,11 +958,13 @@ static int __fat_remove_entries(struct inode *dir, loff_t pos, int nr_slots)
 
 		orig_slots = nr_slots;
 		endp = (struct msdos_dir_entry *)(bh->b_data + sb->s_blocksize);
+		lock_buffer(bh);
 		while (nr_slots && de < endp) {
 			de->name[0] = DELETED_FLAG;
 			de++;
 			nr_slots--;
 		}
+		unlock_buffer(bh);
 		mark_buffer_dirty_inode(bh, dir);
 		if (IS_DIRSYNC(dir))
 			err = sync_dirty_buffer(bh);
@@ -992,11 +994,13 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo)
 	sinfo->de = NULL;
 	bh = sinfo->bh;
 	sinfo->bh = NULL;
+	lock_buffer(bh);
 	while (nr_slots && de >= (struct msdos_dir_entry *)bh->b_data) {
 		de->name[0] = DELETED_FLAG;
 		de--;
 		nr_slots--;
 	}
+	unlock_buffer(bh);
 	mark_buffer_dirty_inode(bh, dir);
 	if (IS_DIRSYNC(dir))
 		err = sync_dirty_buffer(bh);
@@ -1045,7 +1049,9 @@ static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used,
 			err = -ENOMEM;
 			goto error;
 		}
+		lock_buffer(bhs[n]);
 		memset(bhs[n]->b_data, 0, sb->s_blocksize);
+		unlock_buffer(bhs[n]);
 		set_buffer_uptodate(bhs[n]);
 		mark_buffer_dirty_inode(bhs[n], dir);
 
@@ -1103,6 +1109,7 @@ int fat_alloc_new_dir(struct inode *dir, struct timespec *ts)
 	fat_time_unix2fat(sbi, ts, &time, &date, &time_cs);
 
 	de = (struct msdos_dir_entry *)bhs[0]->b_data;
+	lock_buffer(bhs[0]);
 	/* filling the new directory slots ("." and ".." entries) */
 	memcpy(de[0].name, MSDOS_DOT, MSDOS_NAME);
 	memcpy(de[1].name, MSDOS_DOTDOT, MSDOS_NAME);
@@ -1126,6 +1133,7 @@ int fat_alloc_new_dir(struct inode *dir, struct timespec *ts)
 	de[1].starthi = cpu_to_le16(MSDOS_I(dir)->i_logstart >> 16);
 	de[0].size = de[1].size = 0;
 	memset(de + 2, 0, sb->s_blocksize - 2 * sizeof(*de));
+	unlock_buffer(bhs[0]);
 	set_buffer_uptodate(bhs[0]);
 	mark_buffer_dirty_inode(bhs[0], dir);
 
@@ -1185,7 +1193,9 @@ static int fat_add_new_entries(struct inode *dir, void *slots, int nr_slots,
 
 			/* fill the directory entry */
 			copy = min(size, sb->s_blocksize);
+			lock_buffer(bhs[n]);
 			memcpy(bhs[n]->b_data, slots, copy);
+			unlock_buffer(bhs[n]);
 			slots += copy;
 			size -= copy;
 			set_buffer_uptodate(bhs[n]);
@@ -1288,7 +1298,9 @@ found:
 		/* Fill the long name slots. */
 		for (i = 0; i < long_bhs; i++) {
 			int copy = min_t(int, sb->s_blocksize - offset, size);
+			lock_buffer(bhs[i]);
 			memcpy(bhs[i]->b_data + offset, slots, copy);
+			unlock_buffer(bhs[i]);
 			mark_buffer_dirty_inode(bhs[i], dir);
 			offset = 0;
 			slots += copy;
@@ -1299,7 +1311,9 @@ found:
 		if (!err && i < nr_bhs) {
 			/* Fill the short name slot. */
 			int copy = min_t(int, sb->s_blocksize - offset, size);
+			lock_buffer(bhs[i]);
 			memcpy(bhs[i]->b_data + offset, slots, copy);
+			unlock_buffer(bhs[i]);
 			mark_buffer_dirty_inode(bhs[i], dir);
 			if (IS_DIRSYNC(dir))
 				err = sync_dirty_buffer(bhs[i]);
diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index b47d2c9..e49a9dd 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -160,6 +160,9 @@ static void fat12_ent_put(struct fat_entry *fatent, int new)
 	if (new == FAT_ENT_EOF)
 		new = EOF_FAT12;
 
+	lock_buffer(fatent->bhs[0]);
+	if (fatent->nr_bhs == 2)
+		lock_buffer(fatent->bhs[1]);
 	spin_lock(&fat12_entry_lock);
 	if (fatent->entry & 1) {
 		*ent12_p[0] = (new << 4) | (*ent12_p[0] & 0x0f);
@@ -169,6 +172,9 @@ static void fat12_ent_put(struct fat_entry *fatent, int new)
 		*ent12_p[1] = (*ent12_p[1] & 0xf0) | (new >> 8);
 	}
 	spin_unlock(&fat12_entry_lock);
+	if (fatent->nr_bhs == 2)
+		unlock_buffer(fatent->bhs[1]);
+	unlock_buffer(fatent->bhs[0]);
 
 	mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
 	if (fatent->nr_bhs == 2)
@@ -180,7 +186,9 @@ static void fat16_ent_put(struct fat_entry *fatent, int new)
 	if (new == FAT_ENT_EOF)
 		new = EOF_FAT16;
 
+	lock_buffer(fatent->bhs[0]);
 	*fatent->u.ent16_p = cpu_to_le16(new);
+	unlock_buffer(fatent->bhs[0]);
 	mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
 }
 
@@ -191,7 +199,9 @@ static void fat32_ent_put(struct fat_entry *fatent, int new)
 
 	WARN_ON(new & 0xf0000000);
 	new |= le32_to_cpu(*fatent->u.ent32_p) & ~0x0fffffff;
+	lock_buffer(fatent->bhs[0]);
 	*fatent->u.ent32_p = cpu_to_le32(new);
+	unlock_buffer(fatent->bhs[0]);
 	mark_buffer_dirty_inode(fatent->bhs[0], fatent->fat_inode);
 }
 
@@ -382,7 +392,9 @@ static int fat_mirror_bhs(struct super_block *sb, struct buffer_head **bhs,
 				err = -ENOMEM;
 				goto error;
 			}
+			lock_buffer(c_bh);
 			memcpy(c_bh->b_data, bhs[n]->b_data, sb->s_blocksize);
+			unlock_buffer(c_bh);
 			set_buffer_uptodate(c_bh);
 			mark_buffer_dirty_inode(c_bh, sbi->fat_inode);
 			if (sb->s_flags & MS_SYNCHRONOUS)
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 8d68690..96da554 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -623,6 +623,7 @@ retry:
 		       "for updating (i_pos %lld)\n", i_pos);
 		return -EIO;
 	}
+	lock_buffer(bh);
 	spin_lock(&sbi->inode_hash_lock);
 	if (i_pos != MSDOS_I(inode)->i_pos) {
 		spin_unlock(&sbi->inode_hash_lock);
@@ -649,6 +650,7 @@ retry:
 				  &raw_entry->adate, NULL);
 	}
 	spin_unlock(&sbi->inode_hash_lock);
+	unlock_buffer(bh);
 	mark_buffer_dirty(bh);
 	err = 0;
 	if (wait)
diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index 970e682..3386d81 100644
--- a/fs/fat/misc.c
+++ b/fs/fat/misc.c
@@ -70,10 +70,12 @@ int fat_clusters_flush(struct super_block *sb)
 		       le32_to_cpu(fsinfo->signature2),
 		       sbi->fsinfo_sector);
 	} else {
+		lock_buffer(bh);
 		if (sbi->free_clusters != -1)
 			fsinfo->free_clusters = cpu_to_le32(sbi->free_clusters);
 		if (sbi->prev_free != -1)
 			fsinfo->next_cluster = cpu_to_le32(sbi->prev_free);
+		unlock_buffer(bh);
 		mark_buffer_dirty(bh);
 	}
 	brelse(bh);
diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 7114990..cb53c8f 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -540,8 +540,10 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
 
 	if (update_dotdot) {
 		int start = MSDOS_I(new_dir)->i_logstart;
+		lock_buffer(dotdot_bh);
 		dotdot_de->start = cpu_to_le16(start);
 		dotdot_de->starthi = cpu_to_le16(start >> 16);
+		unlock_buffer(dotdot_bh);
 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
 		if (IS_DIRSYNC(new_dir)) {
 			err = sync_dirty_buffer(dotdot_bh);
@@ -582,8 +584,10 @@ error_dotdot:
 
 	if (update_dotdot) {
 		int start = MSDOS_I(old_dir)->i_logstart;
+		lock_buffer(dotdot_bh);
 		dotdot_de->start = cpu_to_le16(start);
 		dotdot_de->starthi = cpu_to_le16(start >> 16);
+		unlock_buffer(dotdot_bh);
 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
 		corrupt |= sync_dirty_buffer(dotdot_bh);
 	}
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index adae3fb..f7e43f4 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -978,8 +978,10 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
 
 	if (update_dotdot) {
 		int start = MSDOS_I(new_dir)->i_logstart;
+		lock_buffer(dotdot_bh);
 		dotdot_de->start = cpu_to_le16(start);
 		dotdot_de->starthi = cpu_to_le16(start >> 16);
+		unlock_buffer(dotdot_bh);
 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
 		if (IS_DIRSYNC(new_dir)) {
 			err = sync_dirty_buffer(dotdot_bh);
@@ -1022,8 +1024,10 @@ error_dotdot:
 
 	if (update_dotdot) {
 		int start = MSDOS_I(old_dir)->i_logstart;
+		lock_buffer(dotdot_bh);
 		dotdot_de->start = cpu_to_le16(start);
 		dotdot_de->starthi = cpu_to_le16(start >> 16);
+		unlock_buffer(dotdot_bh);
 		mark_buffer_dirty_inode(dotdot_bh, old_inode);
 		corrupt |= sync_dirty_buffer(dotdot_bh);
 	}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2011-05-09 23:04 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-09 23:03 [PATCHSET v3.1 0/7] data integrity: Stabilize pages during writeback for various fses Darrick J. Wong
2011-05-09 23:03 ` [PATCH 1/7] mm: Wait for writeback when grabbing pages to begin a write Darrick J. Wong
2011-05-09 23:03 ` [PATCH 2/7] fs: block_page_mkwrite should wait for writeback to finish Darrick J. Wong
2011-05-10 12:41   ` Jan Kara
2011-05-10 17:12     ` Darrick J. Wong
2011-05-09 23:03 ` [PATCH 3/7] mm: Provide stub page_mkwrite functionality to stabilize pages during writes Darrick J. Wong
2011-05-09 23:03 ` [PATCH 4/7] ext4: Clean up some wait_on_page_writeback calls Darrick J. Wong
2011-05-18 18:16   ` [4/7] " Ted Ts'o
2011-05-09 23:03 ` [PATCH 5/7] ext4: Wait for writeback to complete while making pages writable Darrick J. Wong
2011-05-18 18:17   ` [5/7] " Ted Ts'o
2011-05-09 23:04 ` [PATCH 6/7] ext2: Lock buffer_head during metadata update Darrick J. Wong
2011-05-09 23:04 ` Darrick J. Wong [this message]
2011-05-10  0:06 ` [PATCHSET v3.1 0/7] data integrity: Stabilize pages during writeback for various fses Dave Chinner
2011-05-10  1:59 ` OGAWA Hirofumi
2011-05-10 12:38   ` Jan Kara
2011-05-10 13:12     ` OGAWA Hirofumi
2011-05-10 13:29       ` Jan Kara
2011-05-10 13:46         ` OGAWA Hirofumi
2011-05-10 14:05           ` OGAWA Hirofumi
2011-05-10 14:54             ` Jan Kara
2011-05-10 16:12               ` OGAWA Hirofumi
2011-05-10 16:22                 ` Jan Kara
2011-05-10 16:28                   ` OGAWA Hirofumi
2011-05-16 18:47                     ` Darrick J. Wong
2011-05-16 19:31                       ` OGAWA Hirofumi
2011-05-17  1:23                         ` Darrick J. Wong
2011-05-17  3:30                           ` OGAWA Hirofumi
2011-10-23 16:38                   ` Andy Lutomirski
2011-05-10 13:36   ` Christoph Hellwig
2011-05-10 13:52     ` OGAWA Hirofumi
2011-05-10 14:49       ` Jan Kara
2011-05-10 15:24         ` OGAWA Hirofumi
2011-05-10 16:18           ` Jan Kara
2011-05-10 16:29             ` OGAWA Hirofumi
2011-05-10 17:03               ` Jan Kara
2011-05-10 17:03           ` Christoph Hellwig
2011-05-10 20:50             ` OGAWA Hirofumi
2011-05-11  5:55               ` Christoph Hellwig
2011-05-11  9:36                 ` OGAWA Hirofumi
2011-05-10 12:51 ` Jan Kara
2011-05-10 16:24   ` Chris Mason
2011-05-11 18:19   ` Darrick J. Wong
2011-05-12  9:42     ` Jan Kara
2011-05-16 18:49       ` Darrick J. Wong
2011-05-16 18:59         ` Jan Kara
2011-05-16 19:09           ` Darrick J. Wong
2011-05-16 19:04 ` Darrick J. Wong
2011-05-16 20:27   ` Christoph Hellwig
2011-05-16 20:55     ` Darrick J. Wong
2011-05-17 14:01       ` Christoph Hellwig

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=20110509230411.19566.66436.stgit@elm3c44.beaverton.ibm.com \
    --to=djwong@us.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=chris.mason@oracle.com \
    --cc=dave@linux.vnet.ibm.com \
    --cc=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=jack@suse.cz \
    --cc=jlayton@redhat.com \
    --cc=jlbec@evilplan.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mcao@us.ibm.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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).