Skip to content

Commit ae074d0

Browse files
Christoph Hellwigaxboe
authored andcommitted
loop: move updating lo_flags out of loop_set_status_from_info
While loop_configure simplify assigns the flags passed in by userspace, loop_set_status only looks at the two changeable flags, and currently has to do a complicate dance to implement that. Move assign lo->lo_flags out of loop_set_status_from_info into the callers and thus drastically simplify the lo_flags handling in loop_set_status. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent b03732a commit ae074d0

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

drivers/block/loop.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,6 @@ loop_set_status_from_info(struct loop_device *lo,
971971

972972
memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
973973
lo->lo_file_name[LO_NAME_SIZE-1] = 0;
974-
lo->lo_flags = info->lo_flags;
975974
return 0;
976975
}
977976

@@ -1069,6 +1068,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10691068
error = loop_set_status_from_info(lo, &config->info);
10701069
if (error)
10711070
goto out_unlock;
1071+
lo->lo_flags = config->info.lo_flags;
10721072

10731073
if (!(file->f_mode & FMODE_WRITE) || !(mode & BLK_OPEN_WRITE) ||
10741074
!file->f_op->write_iter)
@@ -1258,7 +1258,6 @@ static int
12581258
loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
12591259
{
12601260
int err;
1261-
int prev_lo_flags;
12621261
bool partscan = false;
12631262
bool size_changed = false;
12641263

@@ -1280,18 +1279,16 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
12801279
/* I/O need to be drained during transfer transition */
12811280
blk_mq_freeze_queue(lo->lo_queue);
12821281

1283-
prev_lo_flags = lo->lo_flags;
1284-
12851282
err = loop_set_status_from_info(lo, info);
12861283
if (err)
12871284
goto out_unfreeze;
12881285

1289-
/* Mask out flags that can't be set using LOOP_SET_STATUS. */
1290-
lo->lo_flags &= LOOP_SET_STATUS_SETTABLE_FLAGS;
1291-
/* For those flags, use the previous values instead */
1292-
lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_SETTABLE_FLAGS;
1293-
/* For flags that can't be cleared, use previous values too */
1294-
lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_CLEARABLE_FLAGS;
1286+
partscan = !(lo->lo_flags & LO_FLAGS_PARTSCAN) &&
1287+
(info->lo_flags & LO_FLAGS_PARTSCAN);
1288+
1289+
lo->lo_flags &= ~(LOOP_SET_STATUS_SETTABLE_FLAGS |
1290+
LOOP_SET_STATUS_CLEARABLE_FLAGS);
1291+
lo->lo_flags |= (info->lo_flags & LOOP_SET_STATUS_SETTABLE_FLAGS);
12951292

12961293
if (size_changed) {
12971294
loff_t new_size = get_size(lo->lo_offset, lo->lo_sizelimit,
@@ -1304,12 +1301,8 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
13041301

13051302
out_unfreeze:
13061303
blk_mq_unfreeze_queue(lo->lo_queue);
1307-
1308-
if (!err && (lo->lo_flags & LO_FLAGS_PARTSCAN) &&
1309-
!(prev_lo_flags & LO_FLAGS_PARTSCAN)) {
1304+
if (partscan)
13101305
clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
1311-
partscan = true;
1312-
}
13131306
out_unlock:
13141307
mutex_unlock(&lo->lo_mutex);
13151308
if (partscan)

0 commit comments

Comments
 (0)