Skip to content

Commit 1b9e619

Browse files
osandovkdave
authored andcommitted
Btrfs: disable FUA if mounted with nobarrier
I was seeing disk flushes still happening when I mounted a Btrfs filesystem with nobarrier for testing. This is because we use FUA to write out the first super block, and on devices without FUA support, the block layer translates FUA to a flush. Even on devices supporting true FUA, using FUA when we asked for no barriers is surprising. Fixes: 387125f ("Btrfs: fix barrier flushes") Signed-off-by: Omar Sandoval <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e19182c commit 1b9e619

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

fs/btrfs/disk-io.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,7 @@ static int write_dev_supers(struct btrfs_device *device,
32313231
int errors = 0;
32323232
u32 crc;
32333233
u64 bytenr;
3234+
int op_flags;
32343235

32353236
if (max_mirrors == 0)
32363237
max_mirrors = BTRFS_SUPER_MIRROR_MAX;
@@ -3273,13 +3274,10 @@ static int write_dev_supers(struct btrfs_device *device,
32733274
* we fua the first super. The others we allow
32743275
* to go down lazy.
32753276
*/
3276-
if (i == 0) {
3277-
ret = btrfsic_submit_bh(REQ_OP_WRITE,
3278-
REQ_SYNC | REQ_FUA | REQ_META | REQ_PRIO, bh);
3279-
} else {
3280-
ret = btrfsic_submit_bh(REQ_OP_WRITE,
3281-
REQ_SYNC | REQ_META | REQ_PRIO, bh);
3282-
}
3277+
op_flags = REQ_SYNC | REQ_META | REQ_PRIO;
3278+
if (i == 0 && !btrfs_test_opt(device->fs_info, NOBARRIER))
3279+
op_flags |= REQ_FUA;
3280+
ret = btrfsic_submit_bh(REQ_OP_WRITE, op_flags, bh);
32833281
if (ret)
32843282
errors++;
32853283
}

0 commit comments

Comments
 (0)