mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-09 18:51:16 +00:00
btrfs-progs: btrfsck operations should be exclusive
this patch will make btrfsck operations to open disk in exclusive mode, so that mount will fail when btrfsck is running Signed-off-by: Anand Jain <Anand.Jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
This commit is contained in:
parent
b2e99e1819
commit
f920dbce8d
@ -6390,7 +6390,8 @@ int cmd_check(int argc, char **argv)
|
|||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int init_csum_tree = 0;
|
int init_csum_tree = 0;
|
||||||
int init_extent_tree = 0;
|
int init_extent_tree = 0;
|
||||||
enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_PARTIAL;
|
enum btrfs_open_ctree_flags ctree_flags =
|
||||||
|
OPEN_CTREE_PARTIAL | OPEN_CTREE_EXCLUSIVE;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
int c;
|
int c;
|
||||||
|
10
disk-io.c
10
disk-io.c
@ -1057,6 +1057,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
|
|||||||
struct btrfs_fs_devices *fs_devices = NULL;
|
struct btrfs_fs_devices *fs_devices = NULL;
|
||||||
struct extent_buffer *eb;
|
struct extent_buffer *eb;
|
||||||
int ret;
|
int ret;
|
||||||
|
int oflags;
|
||||||
|
|
||||||
if (sb_bytenr == 0)
|
if (sb_bytenr == 0)
|
||||||
sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
|
sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
|
||||||
@ -1080,9 +1081,14 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
|
|||||||
|
|
||||||
fs_info->fs_devices = fs_devices;
|
fs_info->fs_devices = fs_devices;
|
||||||
if (flags & OPEN_CTREE_WRITES)
|
if (flags & OPEN_CTREE_WRITES)
|
||||||
ret = btrfs_open_devices(fs_devices, O_RDWR);
|
oflags = O_RDWR;
|
||||||
else
|
else
|
||||||
ret = btrfs_open_devices(fs_devices, O_RDONLY);
|
oflags = O_RDONLY;
|
||||||
|
|
||||||
|
if (flags & OPEN_CTREE_EXCLUSIVE)
|
||||||
|
oflags |= O_EXCL;
|
||||||
|
|
||||||
|
ret = btrfs_open_devices(fs_devices, oflags);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_devices;
|
goto out_devices;
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ enum btrfs_open_ctree_flags {
|
|||||||
OPEN_CTREE_RECOVER_SUPER = 8,
|
OPEN_CTREE_RECOVER_SUPER = 8,
|
||||||
OPEN_CTREE_RESTORE = 16,
|
OPEN_CTREE_RESTORE = 16,
|
||||||
OPEN_CTREE_NO_BLOCK_GROUPS = 32,
|
OPEN_CTREE_NO_BLOCK_GROUPS = 32,
|
||||||
|
OPEN_CTREE_EXCLUSIVE = 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline u64 btrfs_sb_offset(int mirror)
|
static inline u64 btrfs_sb_offset(int mirror)
|
||||||
|
@ -214,7 +214,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags)
|
|||||||
if (device->devid == fs_devices->lowest_devid)
|
if (device->devid == fs_devices->lowest_devid)
|
||||||
fs_devices->lowest_bdev = fd;
|
fs_devices->lowest_bdev = fd;
|
||||||
device->fd = fd;
|
device->fd = fd;
|
||||||
if (flags == O_RDWR)
|
if (flags & O_RDWR)
|
||||||
device->writeable = 1;
|
device->writeable = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user