xref: /openbmc/linux/fs/btrfs/btrfs_inode.h (revision 32c00aff718bb54a214b39146bdd9ac01511cd25)
16cbd5570SChris Mason /*
26cbd5570SChris Mason  * Copyright (C) 2007 Oracle.  All rights reserved.
36cbd5570SChris Mason  *
46cbd5570SChris Mason  * This program is free software; you can redistribute it and/or
56cbd5570SChris Mason  * modify it under the terms of the GNU General Public
66cbd5570SChris Mason  * License v2 as published by the Free Software Foundation.
76cbd5570SChris Mason  *
86cbd5570SChris Mason  * This program is distributed in the hope that it will be useful,
96cbd5570SChris Mason  * but WITHOUT ANY WARRANTY; without even the implied warranty of
106cbd5570SChris Mason  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
116cbd5570SChris Mason  * General Public License for more details.
126cbd5570SChris Mason  *
136cbd5570SChris Mason  * You should have received a copy of the GNU General Public
146cbd5570SChris Mason  * License along with this program; if not, write to the
156cbd5570SChris Mason  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
166cbd5570SChris Mason  * Boston, MA 021110-1307, USA.
176cbd5570SChris Mason  */
186cbd5570SChris Mason 
192c90e5d6SChris Mason #ifndef __BTRFS_I__
202c90e5d6SChris Mason #define __BTRFS_I__
212c90e5d6SChris Mason 
22a52d9a80SChris Mason #include "extent_map.h"
23d1310b2eSChris Mason #include "extent_io.h"
24e6dcd2dcSChris Mason #include "ordered-data.h"
25a52d9a80SChris Mason 
26f1ace244SAneesh /* in memory btrfs inode */
272c90e5d6SChris Mason struct btrfs_inode {
28d352ac68SChris Mason 	/* which subvolume this inode belongs to */
29d6e4a428SChris Mason 	struct btrfs_root *root;
30d352ac68SChris Mason 
31d352ac68SChris Mason 	/* key used to find this inode on disk.  This is used by the code
32d352ac68SChris Mason 	 * to read in roots of subvolumes
33d352ac68SChris Mason 	 */
34d6e4a428SChris Mason 	struct btrfs_key location;
35d352ac68SChris Mason 
36d352ac68SChris Mason 	/* the extent_tree has caches of all the extent mappings to disk */
37a52d9a80SChris Mason 	struct extent_map_tree extent_tree;
38d352ac68SChris Mason 
39d352ac68SChris Mason 	/* the io_tree does range state (DIRTY, LOCKED etc) */
40d1310b2eSChris Mason 	struct extent_io_tree io_tree;
41d352ac68SChris Mason 
42d352ac68SChris Mason 	/* special utility tree used to record which mirrors have already been
43d352ac68SChris Mason 	 * tried when checksums fail for a given block
44d352ac68SChris Mason 	 */
457e38326fSChris Mason 	struct extent_io_tree io_failure_tree;
46d352ac68SChris Mason 
47d352ac68SChris Mason 	/* held while inesrting or deleting extents from files */
48ee6e6504SChris Mason 	struct mutex extent_mutex;
49d352ac68SChris Mason 
50d352ac68SChris Mason 	/* held while logging the inode in tree-log.c */
51e02119d5SChris Mason 	struct mutex log_mutex;
52d352ac68SChris Mason 
53d352ac68SChris Mason 	/* used to order data wrt metadata */
54e6dcd2dcSChris Mason 	struct btrfs_ordered_inode_tree ordered_tree;
5515ee9bc7SJosef Bacik 
567b128766SJosef Bacik 	/* for keeping track of orphaned inodes */
577b128766SJosef Bacik 	struct list_head i_orphan;
587b128766SJosef Bacik 
59d352ac68SChris Mason 	/* list of all the delalloc inodes in the FS.  There are times we need
60d352ac68SChris Mason 	 * to write all the delalloc pages to disk, and this list is used
61d352ac68SChris Mason 	 * to walk them all.
62d352ac68SChris Mason 	 */
63ea8c2819SChris Mason 	struct list_head delalloc_inodes;
64ea8c2819SChris Mason 
655a3f23d5SChris Mason 	/*
665a3f23d5SChris Mason 	 * list for tracking inodes that must be sent to disk before a
675a3f23d5SChris Mason 	 * rename or truncate commit
685a3f23d5SChris Mason 	 */
695a3f23d5SChris Mason 	struct list_head ordered_operations;
705a3f23d5SChris Mason 
715d4f98a2SYan Zheng 	/* node for the red-black tree that links inodes in subvolume root */
725d4f98a2SYan Zheng 	struct rb_node rb_node;
735d4f98a2SYan Zheng 
746a63209fSJosef Bacik 	/* the space_info for where this inode's data allocations are done */
756a63209fSJosef Bacik 	struct btrfs_space_info *space_info;
766a63209fSJosef Bacik 
77d352ac68SChris Mason 	/* full 64 bit generation number, struct vfs_inode doesn't have a big
78d352ac68SChris Mason 	 * enough field for this.
79d352ac68SChris Mason 	 */
80e02119d5SChris Mason 	u64 generation;
81e02119d5SChris Mason 
82c3027eb5SChris Mason 	/* sequence number for NFS changes */
83c3027eb5SChris Mason 	u64 sequence;
84c3027eb5SChris Mason 
8515ee9bc7SJosef Bacik 	/*
8615ee9bc7SJosef Bacik 	 * transid of the trans_handle that last modified this inode
8715ee9bc7SJosef Bacik 	 */
8815ee9bc7SJosef Bacik 	u64 last_trans;
89e02119d5SChris Mason 	/*
90e02119d5SChris Mason 	 * transid that last logged this inode
91e02119d5SChris Mason 	 */
92e02119d5SChris Mason 	u64 logged_trans;
9349eb7e46SChris Mason 
94d352ac68SChris Mason 	/* total number of bytes pending delalloc, used by stat to calc the
95d352ac68SChris Mason 	 * real block usage of the file
96d352ac68SChris Mason 	 */
979069218dSChris Mason 	u64 delalloc_bytes;
98d352ac68SChris Mason 
996a63209fSJosef Bacik 	/* total number of bytes that may be used for this inode for
1006a63209fSJosef Bacik 	 * delalloc
1016a63209fSJosef Bacik 	 */
1026a63209fSJosef Bacik 	u64 reserved_bytes;
1036a63209fSJosef Bacik 
104d352ac68SChris Mason 	/*
105d352ac68SChris Mason 	 * the size of the file stored in the metadata on disk.  data=ordered
106d352ac68SChris Mason 	 * means the in-memory i_size might be larger than the size on disk
107d352ac68SChris Mason 	 * because not all the blocks are written yet.
108d352ac68SChris Mason 	 */
109dbe674a9SChris Mason 	u64 disk_i_size;
110d352ac68SChris Mason 
111d352ac68SChris Mason 	/* flags field from the on disk inode */
112b98b6767SYan 	u32 flags;
113aec7477bSJosef Bacik 
114aec7477bSJosef Bacik 	/*
115aec7477bSJosef Bacik 	 * if this is a directory then index_cnt is the counter for the index
116aec7477bSJosef Bacik 	 * number for new files that are created
117aec7477bSJosef Bacik 	 */
118aec7477bSJosef Bacik 	u64 index_cnt;
119d352ac68SChris Mason 
120d2fb3437SYan Zheng 	/* the start of block group preferred for allocations. */
121d2fb3437SYan Zheng 	u64 block_group;
122d2fb3437SYan Zheng 
12312fcfd22SChris Mason 	/* the fsync log has some corner cases that mean we have to check
12412fcfd22SChris Mason 	 * directories to see if any unlinks have been done before
12512fcfd22SChris Mason 	 * the directory was logged.  See tree-log.c for all the
12612fcfd22SChris Mason 	 * details
12712fcfd22SChris Mason 	 */
12812fcfd22SChris Mason 	u64 last_unlink_trans;
12912fcfd22SChris Mason 
1305a3f23d5SChris Mason 	/*
131*32c00affSJosef Bacik 	 * Counters to keep track of the number of extent item's we may use due
132*32c00affSJosef Bacik 	 * to delalloc and such.  outstanding_extents is the number of extent
133*32c00affSJosef Bacik 	 * items we think we'll end up using, and reserved_extents is the number
134*32c00affSJosef Bacik 	 * of extent items we've reserved metadata for.
1359ed74f2dSJosef Bacik 	 */
136*32c00affSJosef Bacik 	spinlock_t accounting_lock;
137*32c00affSJosef Bacik 	int reserved_extents;
138*32c00affSJosef Bacik 	int outstanding_extents;
1399ed74f2dSJosef Bacik 
1409ed74f2dSJosef Bacik 	/*
1415a3f23d5SChris Mason 	 * ordered_data_close is set by truncate when a file that used
1425a3f23d5SChris Mason 	 * to have good data has been truncated to zero.  When it is set
1435a3f23d5SChris Mason 	 * the btrfs file release call will add this inode to the
1445a3f23d5SChris Mason 	 * ordered operations list so that we make sure to flush out any
1455a3f23d5SChris Mason 	 * new data the application may have written before commit.
1465a3f23d5SChris Mason 	 *
1475a3f23d5SChris Mason 	 * yes, its silly to have a single bitflag, but we might grow more
1485a3f23d5SChris Mason 	 * of these.
1495a3f23d5SChris Mason 	 */
1505a3f23d5SChris Mason 	unsigned ordered_data_close:1;
1514df27c4dSYan, Zheng 	unsigned dummy_inode:1;
1525a3f23d5SChris Mason 
153d352ac68SChris Mason 	struct inode vfs_inode;
1542c90e5d6SChris Mason };
155dbe674a9SChris Mason 
1562c90e5d6SChris Mason static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
1572c90e5d6SChris Mason {
1582c90e5d6SChris Mason 	return container_of(inode, struct btrfs_inode, vfs_inode);
1592c90e5d6SChris Mason }
1602c90e5d6SChris Mason 
161dbe674a9SChris Mason static inline void btrfs_i_size_write(struct inode *inode, u64 size)
162dbe674a9SChris Mason {
163dbe674a9SChris Mason 	inode->i_size = size;
164dbe674a9SChris Mason 	BTRFS_I(inode)->disk_i_size = size;
165dbe674a9SChris Mason }
166dbe674a9SChris Mason 
1672c90e5d6SChris Mason #endif
168