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> 238b712842SChris Mason #include "async-thread.h" 24cea9e445SChris Mason 25f2984462SChris Mason struct buffer_head; 26ffbd517dSChris Mason struct btrfs_pending_bios { 27ffbd517dSChris Mason struct bio *head; 28ffbd517dSChris Mason struct bio *tail; 29ffbd517dSChris Mason }; 30ffbd517dSChris Mason 310b86a832SChris Mason struct btrfs_device { 320b86a832SChris Mason struct list_head dev_list; 33b3075717SChris Mason struct list_head dev_alloc_list; 342b82032cSYan Zheng struct btrfs_fs_devices *fs_devices; 350b86a832SChris Mason struct btrfs_root *dev_root; 36ffbd517dSChris Mason 37ffbd517dSChris Mason /* regular prio bios */ 38ffbd517dSChris Mason struct btrfs_pending_bios pending_bios; 39ffbd517dSChris Mason /* WRITE_SYNC bios */ 40ffbd517dSChris Mason struct btrfs_pending_bios pending_sync_bios; 41ffbd517dSChris Mason 428b712842SChris Mason int running_pending; 43dfe25020SChris Mason u64 generation; 44b3075717SChris Mason 45f2984462SChris Mason int barriers; 462b82032cSYan Zheng int writeable; 47dfe25020SChris Mason int in_fs_metadata; 48b3075717SChris Mason 498790d502SChris Mason spinlock_t io_lock; 500b86a832SChris Mason 510b86a832SChris Mason struct block_device *bdev; 520b86a832SChris Mason 5315916de8SChris Mason /* the mode sent to open_bdev_exclusive */ 5415916de8SChris Mason fmode_t mode; 5515916de8SChris Mason 568a4b83ccSChris Mason char *name; 578a4b83ccSChris Mason 580b86a832SChris Mason /* the internal btrfs device id */ 590b86a832SChris Mason u64 devid; 600b86a832SChris Mason 610b86a832SChris Mason /* size of the device */ 620b86a832SChris Mason u64 total_bytes; 630b86a832SChris Mason 64d6397baeSChris Ball /* size of the disk */ 65d6397baeSChris Ball u64 disk_total_bytes; 66d6397baeSChris Ball 670b86a832SChris Mason /* bytes used */ 680b86a832SChris Mason u64 bytes_used; 690b86a832SChris Mason 700b86a832SChris Mason /* optimal io alignment for this device */ 710b86a832SChris Mason u32 io_align; 720b86a832SChris Mason 730b86a832SChris Mason /* optimal io width for this device */ 740b86a832SChris Mason u32 io_width; 750b86a832SChris Mason 760b86a832SChris Mason /* minimal io size for this device */ 770b86a832SChris Mason u32 sector_size; 780b86a832SChris Mason 790b86a832SChris Mason /* type and info about this device */ 800b86a832SChris Mason u64 type; 810b86a832SChris Mason 820b86a832SChris Mason /* physical drive uuid (or lvm uuid) */ 83e17cade2SChris Mason u8 uuid[BTRFS_UUID_SIZE]; 848b712842SChris Mason 858b712842SChris Mason struct btrfs_work work; 860b86a832SChris Mason }; 870b86a832SChris Mason 888a4b83ccSChris Mason struct btrfs_fs_devices { 898a4b83ccSChris Mason u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ 908a4b83ccSChris Mason 91d4a78947SWu Fengguang /* the device with this id has the most recent copy of the super */ 928a4b83ccSChris Mason u64 latest_devid; 938a4b83ccSChris Mason u64 latest_trans; 948a4b83ccSChris Mason u64 num_devices; 95a0af469bSChris Mason u64 open_devices; 962b82032cSYan Zheng u64 rw_devices; 972b82032cSYan Zheng u64 total_rw_bytes; 988a4b83ccSChris Mason struct block_device *latest_bdev; 99e5e9a520SChris Mason 100e5e9a520SChris Mason /* all of the devices in the FS, protected by a mutex 101e5e9a520SChris Mason * so we can safely walk it to write out the supers without 102e5e9a520SChris Mason * worrying about add/remove by the multi-device code 103e5e9a520SChris Mason */ 104e5e9a520SChris Mason struct mutex device_list_mutex; 1058a4b83ccSChris Mason struct list_head devices; 106b3075717SChris Mason 107b3075717SChris Mason /* devices not currently being allocated */ 108b3075717SChris Mason struct list_head alloc_list; 1098a4b83ccSChris Mason struct list_head list; 1102b82032cSYan Zheng 1112b82032cSYan Zheng struct btrfs_fs_devices *seed; 1122b82032cSYan Zheng int seeding; 1132b82032cSYan Zheng 1142b82032cSYan Zheng int opened; 115c289811cSChris Mason 116c289811cSChris Mason /* set when we find or add a device that doesn't have the 117c289811cSChris Mason * nonrot flag set 118c289811cSChris Mason */ 119c289811cSChris Mason int rotating; 1208a4b83ccSChris Mason }; 1218a4b83ccSChris Mason 122cea9e445SChris Mason struct btrfs_bio_stripe { 123cea9e445SChris Mason struct btrfs_device *dev; 124cea9e445SChris Mason u64 physical; 125cea9e445SChris Mason }; 126cea9e445SChris Mason 127cea9e445SChris Mason struct btrfs_multi_bio { 128cea9e445SChris Mason atomic_t stripes_pending; 129cea9e445SChris Mason bio_end_io_t *end_io; 1307d2b4daaSChris Mason struct bio *orig_bio; 131cea9e445SChris Mason void *private; 132a236aed1SChris Mason atomic_t error; 133a236aed1SChris Mason int max_errors; 134cea9e445SChris Mason int num_stripes; 135cea9e445SChris Mason struct btrfs_bio_stripe stripes[]; 136cea9e445SChris Mason }; 137cea9e445SChris Mason 138cea9e445SChris Mason #define btrfs_multi_bio_size(n) (sizeof(struct btrfs_multi_bio) + \ 139cea9e445SChris Mason (sizeof(struct btrfs_bio_stripe) * (n))) 140cea9e445SChris Mason 1410b86a832SChris Mason int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, 1420b86a832SChris Mason struct btrfs_device *device, 143e17cade2SChris Mason u64 chunk_tree, u64 chunk_objectid, 1442b82032cSYan Zheng u64 chunk_offset, u64 start, u64 num_bytes); 145cea9e445SChris Mason int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, 146cea9e445SChris Mason u64 logical, u64 *length, 147f188591eSChris Mason struct btrfs_multi_bio **multi_ret, int mirror_num); 148a512bbf8SYan Zheng int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, 149a512bbf8SYan Zheng u64 chunk_start, u64 physical, u64 devid, 150a512bbf8SYan Zheng u64 **logical, int *naddrs, int *stripe_len); 151e4404d6eSYan Zheng int btrfs_read_sys_array(struct btrfs_root *root); 1520b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root); 1530b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, 1542b82032cSYan Zheng struct btrfs_root *extent_root, u64 type); 1550b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree); 1560b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); 157f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, 1588b712842SChris Mason int mirror_num, int async_submit); 1590d81ba5dSChris Mason int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf); 1608a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, 16197288f2cSChristoph Hellwig fmode_t flags, void *holder); 16297288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, 1638a4b83ccSChris Mason struct btrfs_fs_devices **fs_devices_ret); 1648a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); 165dfe25020SChris Mason int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices); 1668a4b83ccSChris Mason int btrfs_add_device(struct btrfs_trans_handle *trans, 1678a4b83ccSChris Mason struct btrfs_root *root, 1688a4b83ccSChris Mason struct btrfs_device *device); 169a061fc8dSChris Mason int btrfs_rm_device(struct btrfs_root *root, char *device_path); 1708a4b83ccSChris Mason int btrfs_cleanup_fs_uuids(void); 171f188591eSChris Mason int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len); 172f2d8d74dSChris Mason int btrfs_unplug_page(struct btrfs_mapping_tree *map_tree, 173f2d8d74dSChris Mason u64 logical, struct page *page); 1748f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans, 1758f18cf13SChris Mason struct btrfs_device *device, u64 new_size); 1768f18cf13SChris Mason struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid, 1772b82032cSYan Zheng u8 *uuid, u8 *fsid); 1788f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); 179788f20ebSChris Mason int btrfs_init_new_device(struct btrfs_root *root, char *path); 180ec44a35cSChris Mason int btrfs_balance(struct btrfs_root *dev_root); 181a061fc8dSChris Mason void btrfs_unlock_volumes(void); 182a061fc8dSChris Mason void btrfs_lock_volumes(void); 1832b82032cSYan Zheng int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); 184ba1bf481SJosef Bacik int find_free_dev_extent(struct btrfs_trans_handle *trans, 185ba1bf481SJosef Bacik struct btrfs_device *device, u64 num_bytes, 186ba1bf481SJosef Bacik u64 *start, u64 *max_avail); 1870b86a832SChris Mason #endif 188