Skip to content

Commit 85d5098

Browse files
Christoph Hellwiggregkh
authored andcommitted
loop: factor out a loop_assign_backing_file helper
[ Upstream commit d278164 ] Split the code for setting up a backing file into a helper in preparation of adding more code to this path. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20250131120120.1315125-2-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk> Stable-dep-of: f5c84ef ("loop: Add sanity check for read/write_iter") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent af807e5 commit 85d5098

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/block/loop.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ static int loop_validate_file(struct file *file, struct block_device *bdev)
496496
return 0;
497497
}
498498

499+
static void loop_assign_backing_file(struct loop_device *lo, struct file *file)
500+
{
501+
lo->lo_backing_file = file;
502+
lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
503+
mapping_set_gfp_mask(file->f_mapping,
504+
lo->old_gfp_mask & ~(__GFP_IO | __GFP_FS));
505+
}
506+
499507
/*
500508
* loop_change_fd switched the backing store of a loopback device to
501509
* a new file. This is useful for operating system installers to free up
@@ -549,10 +557,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
549557
disk_force_media_change(lo->lo_disk);
550558
memflags = blk_mq_freeze_queue(lo->lo_queue);
551559
mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
552-
lo->lo_backing_file = file;
553-
lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
554-
mapping_set_gfp_mask(file->f_mapping,
555-
lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
560+
loop_assign_backing_file(lo, file);
556561
loop_update_dio(lo);
557562
blk_mq_unfreeze_queue(lo->lo_queue, memflags);
558563
partscan = lo->lo_flags & LO_FLAGS_PARTSCAN;
@@ -943,7 +948,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
943948
const struct loop_config *config)
944949
{
945950
struct file *file = fget(config->fd);
946-
struct address_space *mapping;
947951
struct queue_limits lim;
948952
int error;
949953
loff_t size;
@@ -979,8 +983,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
979983
if (error)
980984
goto out_unlock;
981985

982-
mapping = file->f_mapping;
983-
984986
if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0) {
985987
error = -EINVAL;
986988
goto out_unlock;
@@ -1012,9 +1014,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10121014
set_disk_ro(lo->lo_disk, (lo->lo_flags & LO_FLAGS_READ_ONLY) != 0);
10131015

10141016
lo->lo_device = bdev;
1015-
lo->lo_backing_file = file;
1016-
lo->old_gfp_mask = mapping_gfp_mask(mapping);
1017-
mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
1017+
loop_assign_backing_file(lo, file);
10181018

10191019
lim = queue_limits_start_update(lo->lo_queue);
10201020
loop_update_limits(lo, &lim, config->block_size);

0 commit comments

Comments
 (0)