10b86a832SChris Mason /* 20b86a832SChris Mason * Copyright (C) 2007 Oracle. All rights reserved. 30b86a832SChris Mason * 40b86a832SChris Mason * This program is free software; you can redistribute it and/or 50b86a832SChris Mason * modify it under the terms of the GNU General Public 60b86a832SChris Mason * License v2 as published by the Free Software Foundation. 70b86a832SChris Mason * 80b86a832SChris Mason * This program is distributed in the hope that it will be useful, 90b86a832SChris Mason * but WITHOUT ANY WARRANTY; without even the implied warranty of 100b86a832SChris Mason * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 110b86a832SChris Mason * General Public License for more details. 120b86a832SChris Mason * 130b86a832SChris Mason * You should have received a copy of the GNU General Public 140b86a832SChris Mason * License along with this program; if not, write to the 150b86a832SChris Mason * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 160b86a832SChris Mason * Boston, MA 021110-1307, USA. 170b86a832SChris Mason */ 180b86a832SChris Mason 190b86a832SChris Mason #ifndef __BTRFS_VOLUMES_ 200b86a832SChris Mason #define __BTRFS_VOLUMES_ 218790d502SChris Mason 22cea9e445SChris Mason #include <linux/bio.h> 23cea9e445SChris Mason 240b86a832SChris Mason struct btrfs_device { 250b86a832SChris Mason struct list_head dev_list; 260b86a832SChris Mason struct btrfs_root *dev_root; 278790d502SChris Mason spinlock_t io_lock; 280b86a832SChris Mason 290b86a832SChris Mason struct block_device *bdev; 300b86a832SChris Mason 318790d502SChris Mason u64 total_ios; 328790d502SChris Mason 338a4b83ccSChris Mason char *name; 348a4b83ccSChris Mason 350b86a832SChris Mason /* the internal btrfs device id */ 360b86a832SChris Mason u64 devid; 370b86a832SChris Mason 380b86a832SChris Mason /* size of the device */ 390b86a832SChris Mason u64 total_bytes; 400b86a832SChris Mason 410b86a832SChris Mason /* bytes used */ 420b86a832SChris Mason u64 bytes_used; 430b86a832SChris Mason 440b86a832SChris Mason /* optimal io alignment for this device */ 450b86a832SChris Mason u32 io_align; 460b86a832SChris Mason 470b86a832SChris Mason /* optimal io width for this device */ 480b86a832SChris Mason u32 io_width; 490b86a832SChris Mason 500b86a832SChris Mason /* minimal io size for this device */ 510b86a832SChris Mason u32 sector_size; 520b86a832SChris Mason 530b86a832SChris Mason /* type and info about this device */ 540b86a832SChris Mason u64 type; 550b86a832SChris Mason 560b86a832SChris Mason /* physical drive uuid (or lvm uuid) */ 570b86a832SChris Mason u8 uuid[BTRFS_DEV_UUID_SIZE]; 580b86a832SChris Mason }; 590b86a832SChris Mason 608a4b83ccSChris Mason struct btrfs_fs_devices { 618a4b83ccSChris Mason u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ 628a4b83ccSChris Mason 638a4b83ccSChris Mason /* the device with this id has the most recent coyp of the super */ 648a4b83ccSChris Mason u64 latest_devid; 658a4b83ccSChris Mason u64 latest_trans; 668a4b83ccSChris Mason u64 lowest_devid; 678a4b83ccSChris Mason u64 num_devices; 688a4b83ccSChris Mason struct block_device *latest_bdev; 698a4b83ccSChris Mason struct block_device *lowest_bdev; 708a4b83ccSChris Mason struct list_head devices; 718a4b83ccSChris Mason struct list_head list; 728a4b83ccSChris Mason }; 738a4b83ccSChris Mason 74cea9e445SChris Mason struct btrfs_bio_stripe { 75cea9e445SChris Mason struct btrfs_device *dev; 76cea9e445SChris Mason u64 physical; 77cea9e445SChris Mason }; 78cea9e445SChris Mason 79cea9e445SChris Mason struct btrfs_multi_bio { 80cea9e445SChris Mason atomic_t stripes_pending; 81cea9e445SChris Mason bio_end_io_t *end_io; 82cea9e445SChris Mason void *private; 83cea9e445SChris Mason int error; 84cea9e445SChris Mason int num_stripes; 85cea9e445SChris Mason struct btrfs_bio_stripe stripes[]; 86cea9e445SChris Mason }; 87cea9e445SChris Mason 88cea9e445SChris Mason #define btrfs_multi_bio_size(n) (sizeof(struct btrfs_multi_bio) + \ 89cea9e445SChris Mason (sizeof(struct btrfs_bio_stripe) * (n))) 90cea9e445SChris Mason 910b86a832SChris Mason int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, 920b86a832SChris Mason struct btrfs_device *device, 930b86a832SChris Mason u64 owner, u64 num_bytes, u64 *start); 94cea9e445SChris Mason int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, 95cea9e445SChris Mason u64 logical, u64 *length, 96f188591eSChris Mason struct btrfs_multi_bio **multi_ret, int mirror_num); 970b86a832SChris Mason int btrfs_read_sys_array(struct btrfs_root *root); 980b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root); 990b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 1000b86a832SChris Mason struct btrfs_root *extent_root, u64 *start, 1016324fbf3SChris Mason u64 *num_bytes, u64 type); 1020b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree); 1030b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 104f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, 105f188591eSChris Mason int mirror_num); 1060d81ba5dSChris Mason int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf); 1078a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 1088a4b83ccSChris Mason int flags, void *holder); 1098a4b83ccSChris Mason int btrfs_scan_one_device(const char *path, int flags, void *holder, 1108a4b83ccSChris Mason struct btrfs_fs_devices **fs_devices_ret); 1118a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 1128a4b83ccSChris Mason int btrfs_add_device(struct btrfs_trans_handle *trans, 1138a4b83ccSChris Mason struct btrfs_root *root, 1148a4b83ccSChris Mason struct btrfs_device *device); 1158a4b83ccSChris Mason int btrfs_cleanup_fs_uuids(void); 116f188591eSChris Mason int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len); 1170b86a832SChris Mason #endif 118