make ext2_get_page() and friends work without external serialization

Right now ext2_get_page() (and its analogues in a bunch of other filesystems)
relies upon the directory being locked - the way it sets and tests Checked and
Error bits would be racy without that.  Switch to a slightly different scheme,
_not_ setting Checked in case of failure.  That way the logics becomes
	if Checked => OK
	else if Error => fail
	else if !validate => fail
	else => OK
with validation setting Checked or Error on success and failure resp. and
returning which one had happened.  Equivalent to the current logics, but unlike
the current logics not sensitive to the order of set_bit, test_bit getting
reordered by CPU, etc.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro
2016-04-22 15:06:44 -04:00
parent b9e1d435fd
commit be5b82dbfe
5 changed files with 35 additions and 35 deletions

View File

@@ -102,7 +102,7 @@ static void nilfs_commit_chunk(struct page *page,
unlock_page(page);
}
static void nilfs_check_page(struct page *page)
static bool nilfs_check_page(struct page *page)
{
struct inode *dir = page->mapping->host;
struct super_block *sb = dir->i_sb;
@@ -137,7 +137,7 @@ static void nilfs_check_page(struct page *page)
goto Eend;
out:
SetPageChecked(page);
return;
return true;
/* Too bad, we had an error */
@@ -173,8 +173,8 @@ Eend:
dir->i_ino, (page->index<<PAGE_SHIFT)+offs,
(unsigned long) le64_to_cpu(p->inode));
fail:
SetPageChecked(page);
SetPageError(page);
return false;
}
static struct page *nilfs_get_page(struct inode *dir, unsigned long n)
@@ -184,10 +184,10 @@ static struct page *nilfs_get_page(struct inode *dir, unsigned long n)
if (!IS_ERR(page)) {
kmap(page);
if (!PageChecked(page))
nilfs_check_page(page);
if (PageError(page))
goto fail;
if (unlikely(!PageChecked(page))) {
if (PageError(page) || !nilfs_check_page(page))
goto fail;
}
}
return page;