Skip to content

Commit 5124a0a

Browse files
konisakpm00
authored andcommitted
nilfs2: replace WARN_ONs for invalid DAT metadata block requests
If DAT metadata file block access fails due to corruption of the DAT file or abnormal virtual block numbers held by b-trees or inodes, a kernel warning is generated. This replaces the WARN_ONs by error output, so that a kernel, booted with panic_on_warn, does not panic. This patch also replaces the detected return code -ENOENT with another internal code -EINVAL to notify the bmap layer of metadata corruption. When the bmap layer sees -EINVAL, it handles the abnormal situation with nilfs_bmap_convert_error() and finally returns code -EIO as it should. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Reported-by: <[email protected]> Tested-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1b381f6 commit 5124a0a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

fs/nilfs2/dat.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,21 @@ static inline struct nilfs_dat_info *NILFS_DAT_I(struct inode *dat)
4040
static int nilfs_dat_prepare_entry(struct inode *dat,
4141
struct nilfs_palloc_req *req, int create)
4242
{
43-
return nilfs_palloc_get_entry_block(dat, req->pr_entry_nr,
44-
create, &req->pr_entry_bh);
43+
int ret;
44+
45+
ret = nilfs_palloc_get_entry_block(dat, req->pr_entry_nr,
46+
create, &req->pr_entry_bh);
47+
if (unlikely(ret == -ENOENT)) {
48+
nilfs_err(dat->i_sb,
49+
"DAT doesn't have a block to manage vblocknr = %llu",
50+
(unsigned long long)req->pr_entry_nr);
51+
/*
52+
* Return internal code -EINVAL to notify bmap layer of
53+
* metadata corruption.
54+
*/
55+
ret = -EINVAL;
56+
}
57+
return ret;
4558
}
4659

4760
static void nilfs_dat_commit_entry(struct inode *dat,
@@ -123,11 +136,7 @@ static void nilfs_dat_commit_free(struct inode *dat,
123136

124137
int nilfs_dat_prepare_start(struct inode *dat, struct nilfs_palloc_req *req)
125138
{
126-
int ret;
127-
128-
ret = nilfs_dat_prepare_entry(dat, req, 0);
129-
WARN_ON(ret == -ENOENT);
130-
return ret;
139+
return nilfs_dat_prepare_entry(dat, req, 0);
131140
}
132141

133142
void nilfs_dat_commit_start(struct inode *dat, struct nilfs_palloc_req *req,
@@ -154,10 +163,8 @@ int nilfs_dat_prepare_end(struct inode *dat, struct nilfs_palloc_req *req)
154163
int ret;
155164

156165
ret = nilfs_dat_prepare_entry(dat, req, 0);
157-
if (ret < 0) {
158-
WARN_ON(ret == -ENOENT);
166+
if (ret < 0)
159167
return ret;
160-
}
161168

162169
kaddr = kmap_atomic(req->pr_entry_bh->b_page);
163170
entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,

0 commit comments

Comments
 (0)