Skip to content

Commit 0a52d10

Browse files
committed
btrfs: defrag: make readahead state allocation failure non-fatal
All sorts of readahead errors are not considered fatal. We can continue defragmentation without it, with some potential slow down, which will last only for the current inode. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 63e727e commit 0a52d10

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎fs/btrfs/ioctl.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,14 +1273,14 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
12731273
extent_thresh = SZ_256K;
12741274

12751275
/*
1276-
* if we were not given a file, allocate a readahead
1277-
* context
1276+
* If we were not given a file, allocate a readahead context. As
1277+
* readahead is just an optimization, defrag will work without it so
1278+
* we don't error out.
12781279
*/
12791280
if (!file) {
12801281
ra = kzalloc(sizeof(*ra), GFP_KERNEL);
1281-
if (!ra)
1282-
return -ENOMEM;
1283-
file_ra_state_init(ra, inode->i_mapping);
1282+
if (ra)
1283+
file_ra_state_init(ra, inode->i_mapping);
12841284
} else {
12851285
ra = &file->f_ra;
12861286
}
@@ -1363,8 +1363,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
13631363

13641364
if (i + cluster > ra_index) {
13651365
ra_index = max(i, ra_index);
1366-
btrfs_force_ra(inode->i_mapping, ra, file, ra_index,
1367-
cluster);
1366+
if (ra)
1367+
btrfs_force_ra(inode->i_mapping, ra, file,
1368+
ra_index, cluster);
13681369
ra_index += cluster;
13691370
}
13701371

0 commit comments

Comments
 (0)