xref: /openbmc/linux/fs/btrfs/volumes.h (revision a512bbf8)
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;
260b86a832SChris Mason struct btrfs_device {
270b86a832SChris Mason 	struct list_head dev_list;
28b3075717SChris Mason 	struct list_head dev_alloc_list;
292b82032cSYan Zheng 	struct btrfs_fs_devices *fs_devices;
300b86a832SChris Mason 	struct btrfs_root *dev_root;
318b712842SChris Mason 	struct bio *pending_bios;
328b712842SChris Mason 	struct bio *pending_bio_tail;
338b712842SChris Mason 	int running_pending;
34dfe25020SChris Mason 	u64 generation;
35b3075717SChris Mason 
36f2984462SChris Mason 	int barriers;
372b82032cSYan Zheng 	int writeable;
38dfe25020SChris Mason 	int in_fs_metadata;
39b3075717SChris Mason 
408790d502SChris Mason 	spinlock_t io_lock;
410b86a832SChris Mason 
420b86a832SChris Mason 	struct block_device *bdev;
430b86a832SChris Mason 
4415916de8SChris Mason 	/* the mode sent to open_bdev_exclusive */
4515916de8SChris Mason 	fmode_t mode;
4615916de8SChris Mason 
478a4b83ccSChris Mason 	char *name;
488a4b83ccSChris Mason 
490b86a832SChris Mason 	/* the internal btrfs device id */
500b86a832SChris Mason 	u64 devid;
510b86a832SChris Mason 
520b86a832SChris Mason 	/* size of the device */
530b86a832SChris Mason 	u64 total_bytes;
540b86a832SChris Mason 
550b86a832SChris Mason 	/* bytes used */
560b86a832SChris Mason 	u64 bytes_used;
570b86a832SChris Mason 
580b86a832SChris Mason 	/* optimal io alignment for this device */
590b86a832SChris Mason 	u32 io_align;
600b86a832SChris Mason 
610b86a832SChris Mason 	/* optimal io width for this device */
620b86a832SChris Mason 	u32 io_width;
630b86a832SChris Mason 
640b86a832SChris Mason 	/* minimal io size for this device */
650b86a832SChris Mason 	u32 sector_size;
660b86a832SChris Mason 
670b86a832SChris Mason 	/* type and info about this device */
680b86a832SChris Mason 	u64 type;
690b86a832SChris Mason 
700b86a832SChris Mason 	/* physical drive uuid (or lvm uuid) */
71e17cade2SChris Mason 	u8 uuid[BTRFS_UUID_SIZE];
728b712842SChris Mason 
738b712842SChris Mason 	struct btrfs_work work;
740b86a832SChris Mason };
750b86a832SChris Mason 
768a4b83ccSChris Mason struct btrfs_fs_devices {
778a4b83ccSChris Mason 	u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
788a4b83ccSChris Mason 
798a4b83ccSChris Mason 	/* the device with this id has the most recent coyp of the super */
808a4b83ccSChris Mason 	u64 latest_devid;
818a4b83ccSChris Mason 	u64 latest_trans;
828a4b83ccSChris Mason 	u64 num_devices;
83a0af469bSChris Mason 	u64 open_devices;
842b82032cSYan Zheng 	u64 rw_devices;
852b82032cSYan Zheng 	u64 total_rw_bytes;
868a4b83ccSChris Mason 	struct block_device *latest_bdev;
87b3075717SChris Mason 	/* all of the devices in the FS */
888a4b83ccSChris Mason 	struct list_head devices;
89b3075717SChris Mason 
90b3075717SChris Mason 	/* devices not currently being allocated */
91b3075717SChris Mason 	struct list_head alloc_list;
928a4b83ccSChris Mason 	struct list_head list;
932b82032cSYan Zheng 
942b82032cSYan Zheng 	struct btrfs_fs_devices *seed;
952b82032cSYan Zheng 	int seeding;
962b82032cSYan Zheng 	int sprouted;
972b82032cSYan Zheng 
982b82032cSYan Zheng 	int opened;
998a4b83ccSChris Mason };
1008a4b83ccSChris Mason 
101cea9e445SChris Mason struct btrfs_bio_stripe {
102cea9e445SChris Mason 	struct btrfs_device *dev;
103cea9e445SChris Mason 	u64 physical;
104cea9e445SChris Mason };
105cea9e445SChris Mason 
106cea9e445SChris Mason struct btrfs_multi_bio {
107cea9e445SChris Mason 	atomic_t stripes_pending;
108cea9e445SChris Mason 	bio_end_io_t *end_io;
1097d2b4daaSChris Mason 	struct bio *orig_bio;
110cea9e445SChris Mason 	void *private;
111a236aed1SChris Mason 	atomic_t error;
112a236aed1SChris Mason 	int max_errors;
113cea9e445SChris Mason 	int num_stripes;
114cea9e445SChris Mason 	struct btrfs_bio_stripe stripes[];
115cea9e445SChris Mason };
116cea9e445SChris Mason 
117cea9e445SChris Mason #define btrfs_multi_bio_size(n) (sizeof(struct btrfs_multi_bio) + \
118cea9e445SChris Mason 			    (sizeof(struct btrfs_bio_stripe) * (n)))
119cea9e445SChris Mason 
1200b86a832SChris Mason int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
1210b86a832SChris Mason 			   struct btrfs_device *device,
122e17cade2SChris Mason 			   u64 chunk_tree, u64 chunk_objectid,
1232b82032cSYan Zheng 			   u64 chunk_offset, u64 start, u64 num_bytes);
124cea9e445SChris Mason int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
125cea9e445SChris Mason 		    u64 logical, u64 *length,
126f188591eSChris Mason 		    struct btrfs_multi_bio **multi_ret, int mirror_num);
127a512bbf8SYan Zheng int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
128a512bbf8SYan Zheng 		     u64 chunk_start, u64 physical, u64 devid,
129a512bbf8SYan Zheng 		     u64 **logical, int *naddrs, int *stripe_len);
130a512bbf8SYan Zheng int btrfs_read_sys_array(struct btrfs_root *root, u64 sb_bytenr);
1310b86a832SChris Mason int btrfs_read_chunk_tree(struct btrfs_root *root);
1320b86a832SChris Mason int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
1332b82032cSYan Zheng 		      struct btrfs_root *extent_root, u64 type);
1340b86a832SChris Mason void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
1350b86a832SChris Mason void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
136f188591eSChris Mason int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
1378b712842SChris Mason 		  int mirror_num, int async_submit);
1380d81ba5dSChris Mason int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf);
1398a4b83ccSChris Mason int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
14097288f2cSChristoph Hellwig 		       fmode_t flags, void *holder);
14197288f2cSChristoph Hellwig int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
1428a4b83ccSChris Mason 			  struct btrfs_fs_devices **fs_devices_ret);
1438a4b83ccSChris Mason int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
144dfe25020SChris Mason int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices);
1458a4b83ccSChris Mason int btrfs_add_device(struct btrfs_trans_handle *trans,
1468a4b83ccSChris Mason 		     struct btrfs_root *root,
1478a4b83ccSChris Mason 		     struct btrfs_device *device);
148a061fc8dSChris Mason int btrfs_rm_device(struct btrfs_root *root, char *device_path);
1498a4b83ccSChris Mason int btrfs_cleanup_fs_uuids(void);
150f188591eSChris Mason int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len);
151f2d8d74dSChris Mason int btrfs_unplug_page(struct btrfs_mapping_tree *map_tree,
152f2d8d74dSChris Mason 		      u64 logical, struct page *page);
1538f18cf13SChris Mason int btrfs_grow_device(struct btrfs_trans_handle *trans,
1548f18cf13SChris Mason 		      struct btrfs_device *device, u64 new_size);
1558f18cf13SChris Mason struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid,
1562b82032cSYan Zheng 				       u8 *uuid, u8 *fsid);
1578f18cf13SChris Mason int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
158788f20ebSChris Mason int btrfs_init_new_device(struct btrfs_root *root, char *path);
159ec44a35cSChris Mason int btrfs_balance(struct btrfs_root *dev_root);
160a061fc8dSChris Mason void btrfs_unlock_volumes(void);
161a061fc8dSChris Mason void btrfs_lock_volumes(void);
1622b82032cSYan Zheng int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
1630b86a832SChris Mason #endif
164