Skip to content

Commit d07d8ba

Browse files
konisakpm00
authored andcommitted
nilfs2: treat missing cpfile header block as metadata corruption
The cpfile, a metadata file that holds metadata for checkpoint management, also has statistical information in its first block, and if reading this block fails, it receives the internal code -ENOENT and returns that code to the callers. As with sufile, to prevent this -ENOENT from being propagated to system calls, return -EIO instead when reading the header block fails. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 62e6e78 commit d07d8ba

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

fs/nilfs2/cpfile.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,17 @@ static void nilfs_cpfile_block_init(struct inode *cpfile,
125125
}
126126
}
127127

128-
static inline int nilfs_cpfile_get_header_block(struct inode *cpfile,
129-
struct buffer_head **bhp)
128+
static int nilfs_cpfile_get_header_block(struct inode *cpfile,
129+
struct buffer_head **bhp)
130130
{
131-
return nilfs_mdt_get_block(cpfile, 0, 0, NULL, bhp);
131+
int err = nilfs_mdt_get_block(cpfile, 0, 0, NULL, bhp);
132+
133+
if (unlikely(err == -ENOENT)) {
134+
nilfs_error(cpfile->i_sb,
135+
"missing header block in checkpoint metadata");
136+
err = -EIO;
137+
}
138+
return err;
132139
}
133140

134141
static inline int nilfs_cpfile_get_checkpoint_block(struct inode *cpfile,
@@ -283,14 +290,9 @@ int nilfs_cpfile_create_checkpoint(struct inode *cpfile, __u64 cno)
283290

284291
down_write(&NILFS_MDT(cpfile)->mi_sem);
285292
ret = nilfs_cpfile_get_header_block(cpfile, &header_bh);
286-
if (unlikely(ret < 0)) {
287-
if (ret == -ENOENT) {
288-
nilfs_error(cpfile->i_sb,
289-
"checkpoint creation failed due to metadata corruption.");
290-
ret = -EIO;
291-
}
293+
if (unlikely(ret < 0))
292294
goto out_sem;
293-
}
295+
294296
ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 1, &cp_bh);
295297
if (unlikely(ret < 0))
296298
goto out_header;

0 commit comments

Comments
 (0)