mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-29 06:27:57 +00:00
btrfs-progs: Refactor btrfs_find_device to use btrfs_fs_info
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
505639ee62
commit
de5d0cea24
@ -942,11 +942,12 @@ static int build_device_map_by_chunk_record(struct btrfs_root *root,
|
|||||||
u64 devid;
|
u64 devid;
|
||||||
u8 uuid[BTRFS_UUID_SIZE];
|
u8 uuid[BTRFS_UUID_SIZE];
|
||||||
u16 num_stripes;
|
u16 num_stripes;
|
||||||
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
||||||
struct btrfs_mapping_tree *map_tree;
|
struct btrfs_mapping_tree *map_tree;
|
||||||
struct map_lookup *map;
|
struct map_lookup *map;
|
||||||
struct stripe *stripe;
|
struct stripe *stripe;
|
||||||
|
|
||||||
map_tree = &root->fs_info->mapping_tree;
|
map_tree = &fs_info->mapping_tree;
|
||||||
num_stripes = chunk->num_stripes;
|
num_stripes = chunk->num_stripes;
|
||||||
map = malloc(btrfs_map_lookup_size(num_stripes));
|
map = malloc(btrfs_map_lookup_size(num_stripes));
|
||||||
if (!map)
|
if (!map)
|
||||||
@ -965,7 +966,7 @@ static int build_device_map_by_chunk_record(struct btrfs_root *root,
|
|||||||
devid = stripe->devid;
|
devid = stripe->devid;
|
||||||
memcpy(uuid, stripe->dev_uuid, BTRFS_UUID_SIZE);
|
memcpy(uuid, stripe->dev_uuid, BTRFS_UUID_SIZE);
|
||||||
map->stripes[i].physical = stripe->offset;
|
map->stripes[i].physical = stripe->offset;
|
||||||
map->stripes[i].dev = btrfs_find_device(root, devid,
|
map->stripes[i].dev = btrfs_find_device(fs_info, devid,
|
||||||
uuid, NULL);
|
uuid, NULL);
|
||||||
if (!map->stripes[i].dev) {
|
if (!map->stripes[i].dev) {
|
||||||
free(map);
|
free(map);
|
||||||
|
27
volumes.c
27
volumes.c
@ -1601,17 +1601,17 @@ out:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid,
|
struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
|
||||||
u8 *uuid, u8 *fsid)
|
u8 *uuid, u8 *fsid)
|
||||||
{
|
{
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
struct btrfs_fs_devices *cur_devices;
|
struct btrfs_fs_devices *cur_devices;
|
||||||
|
|
||||||
cur_devices = root->fs_info->fs_devices;
|
cur_devices = fs_info->fs_devices;
|
||||||
while (cur_devices) {
|
while (cur_devices) {
|
||||||
if (!fsid ||
|
if (!fsid ||
|
||||||
(!memcmp(cur_devices->fsid, fsid, BTRFS_UUID_SIZE) ||
|
(!memcmp(cur_devices->fsid, fsid, BTRFS_UUID_SIZE) ||
|
||||||
root->fs_info->ignore_fsid_mismatch)) {
|
fs_info->ignore_fsid_mismatch)) {
|
||||||
device = __find_device(&cur_devices->devices,
|
device = __find_device(&cur_devices->devices,
|
||||||
devid, uuid);
|
devid, uuid);
|
||||||
if (device)
|
if (device)
|
||||||
@ -1839,7 +1839,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
|
|||||||
read_extent_buffer(leaf, uuid, (unsigned long)
|
read_extent_buffer(leaf, uuid, (unsigned long)
|
||||||
btrfs_stripe_dev_uuid_nr(chunk, i),
|
btrfs_stripe_dev_uuid_nr(chunk, i),
|
||||||
BTRFS_UUID_SIZE);
|
BTRFS_UUID_SIZE);
|
||||||
map->stripes[i].dev = btrfs_find_device(root, devid, uuid,
|
map->stripes[i].dev = btrfs_find_device(fs_info, devid, uuid,
|
||||||
NULL);
|
NULL);
|
||||||
if (!map->stripes[i].dev) {
|
if (!map->stripes[i].dev) {
|
||||||
map->stripes[i].dev = fill_missing_device(devid);
|
map->stripes[i].dev = fill_missing_device(devid);
|
||||||
@ -1876,12 +1876,12 @@ static int fill_device_from_item(struct extent_buffer *leaf,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_seed_devices(struct btrfs_root *root, u8 *fsid)
|
static int open_seed_devices(struct btrfs_fs_info *fs_info, u8 *fsid)
|
||||||
{
|
{
|
||||||
struct btrfs_fs_devices *fs_devices;
|
struct btrfs_fs_devices *fs_devices;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fs_devices = root->fs_info->fs_devices->seed;
|
fs_devices = fs_info->fs_devices->seed;
|
||||||
while (fs_devices) {
|
while (fs_devices) {
|
||||||
if (!memcmp(fs_devices->fsid, fsid, BTRFS_UUID_SIZE)) {
|
if (!memcmp(fs_devices->fsid, fsid, BTRFS_UUID_SIZE)) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1907,8 +1907,8 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
fs_devices->seed = root->fs_info->fs_devices->seed;
|
fs_devices->seed = fs_info->fs_devices->seed;
|
||||||
root->fs_info->fs_devices->seed = fs_devices;
|
fs_info->fs_devices->seed = fs_devices;
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1917,6 +1917,7 @@ static int read_one_dev(struct btrfs_root *root,
|
|||||||
struct extent_buffer *leaf,
|
struct extent_buffer *leaf,
|
||||||
struct btrfs_dev_item *dev_item)
|
struct btrfs_dev_item *dev_item)
|
||||||
{
|
{
|
||||||
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
u64 devid;
|
u64 devid;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -1931,24 +1932,24 @@ static int read_one_dev(struct btrfs_root *root,
|
|||||||
(unsigned long)btrfs_device_fsid(dev_item),
|
(unsigned long)btrfs_device_fsid(dev_item),
|
||||||
BTRFS_UUID_SIZE);
|
BTRFS_UUID_SIZE);
|
||||||
|
|
||||||
if (memcmp(fs_uuid, root->fs_info->fsid, BTRFS_UUID_SIZE)) {
|
if (memcmp(fs_uuid, fs_info->fsid, BTRFS_UUID_SIZE)) {
|
||||||
ret = open_seed_devices(root, fs_uuid);
|
ret = open_seed_devices(fs_info, fs_uuid);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
device = btrfs_find_device(root, devid, dev_uuid, fs_uuid);
|
device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid);
|
||||||
if (!device) {
|
if (!device) {
|
||||||
device = kzalloc(sizeof(*device), GFP_NOFS);
|
device = kzalloc(sizeof(*device), GFP_NOFS);
|
||||||
if (!device)
|
if (!device)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
device->fd = -1;
|
device->fd = -1;
|
||||||
list_add(&device->dev_list,
|
list_add(&device->dev_list,
|
||||||
&root->fs_info->fs_devices->devices);
|
&fs_info->fs_devices->devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
fill_device_from_item(leaf, dev_item, device);
|
fill_device_from_item(leaf, dev_item, device);
|
||||||
device->dev_root = root->fs_info->dev_root;
|
device->dev_root = fs_info->dev_root;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
|
|||||||
struct btrfs_device *
|
struct btrfs_device *
|
||||||
btrfs_find_device_by_devid(struct btrfs_fs_devices *fs_devices,
|
btrfs_find_device_by_devid(struct btrfs_fs_devices *fs_devices,
|
||||||
u64 devid, int instance);
|
u64 devid, int instance);
|
||||||
struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid,
|
struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
|
||||||
u8 *uuid, u8 *fsid);
|
u8 *uuid, u8 *fsid);
|
||||||
int write_raid56_with_parity(struct btrfs_fs_info *info,
|
int write_raid56_with_parity(struct btrfs_fs_info *info,
|
||||||
struct extent_buffer *eb,
|
struct extent_buffer *eb,
|
||||||
|
Loading…
Reference in New Issue
Block a user