19888c340SDavid Sterba /* SPDX-License-Identifier: GPL-2.0 */ 26cbd5570SChris Mason /* 36cbd5570SChris Mason * Copyright (C) 2007 Oracle. All rights reserved. 46cbd5570SChris Mason */ 56cbd5570SChris Mason 69888c340SDavid Sterba #ifndef BTRFS_INODE_H 79888c340SDavid Sterba #define BTRFS_INODE_H 82c90e5d6SChris Mason 9778ba82bSFilipe David Borba Manana #include <linux/hash.h> 10e3b318d1SOmar Sandoval #include <linux/refcount.h> 11a52d9a80SChris Mason #include "extent_map.h" 12d1310b2eSChris Mason #include "extent_io.h" 13e6dcd2dcSChris Mason #include "ordered-data.h" 1416cdcec7SMiao Xie #include "delayed-inode.h" 15a52d9a80SChris Mason 1672ac3c0dSJosef Bacik /* 17528ee697SFilipe Manana * Since we search a directory based on f_pos (struct dir_context::pos) we have 18528ee697SFilipe Manana * to start at 2 since '.' and '..' have f_pos of 0 and 1 respectively, so 19528ee697SFilipe Manana * everybody else has to start at 2 (see btrfs_real_readdir() and dir_emit_dots()). 20528ee697SFilipe Manana */ 21528ee697SFilipe Manana #define BTRFS_DIR_START_INDEX 2 22528ee697SFilipe Manana 23528ee697SFilipe Manana /* 2472ac3c0dSJosef Bacik * ordered_data_close is set by truncate when a file that used 2572ac3c0dSJosef Bacik * to have good data has been truncated to zero. When it is set 2672ac3c0dSJosef Bacik * the btrfs file release call will add this inode to the 2772ac3c0dSJosef Bacik * ordered operations list so that we make sure to flush out any 2872ac3c0dSJosef Bacik * new data the application may have written before commit. 2972ac3c0dSJosef Bacik */ 307efc3e34SOmar Sandoval enum { 311fd4033dSNikolay Borisov BTRFS_INODE_FLUSH_ON_CLOSE, 327efc3e34SOmar Sandoval BTRFS_INODE_DUMMY, 337efc3e34SOmar Sandoval BTRFS_INODE_IN_DEFRAG, 347efc3e34SOmar Sandoval BTRFS_INODE_HAS_ASYNC_EXTENT, 3548778179SFilipe Manana /* 3648778179SFilipe Manana * Always set under the VFS' inode lock, otherwise it can cause races 3748778179SFilipe Manana * during fsync (we start as a fast fsync and then end up in a full 3848778179SFilipe Manana * fsync racing with ordered extent completion). 3948778179SFilipe Manana */ 407efc3e34SOmar Sandoval BTRFS_INODE_NEEDS_FULL_SYNC, 417efc3e34SOmar Sandoval BTRFS_INODE_COPY_EVERYTHING, 427efc3e34SOmar Sandoval BTRFS_INODE_IN_DELALLOC_LIST, 437efc3e34SOmar Sandoval BTRFS_INODE_HAS_PROPS, 443cd24c69SEthan Lien BTRFS_INODE_SNAPSHOT_FLUSH, 45f2f121abSFilipe Manana /* 46f2f121abSFilipe Manana * Set and used when logging an inode and it serves to signal that an 47f2f121abSFilipe Manana * inode does not have xattrs, so subsequent fsyncs can avoid searching 48f2f121abSFilipe Manana * for xattrs to log. This bit must be cleared whenever a xattr is added 49f2f121abSFilipe Manana * to an inode. 50f2f121abSFilipe Manana */ 51f2f121abSFilipe Manana BTRFS_INODE_NO_XATTRS, 523d45f221SFilipe Manana /* 533d45f221SFilipe Manana * Set when we are in a context where we need to start a transaction and 543d45f221SFilipe Manana * have dirty pages with the respective file range locked. This is to 553d45f221SFilipe Manana * ensure that when reserving space for the transaction, if we are low 563d45f221SFilipe Manana * on available space and need to flush delalloc, we will not flush 573d45f221SFilipe Manana * delalloc for this inode, because that could result in a deadlock (on 583d45f221SFilipe Manana * the file range, inode's io_tree). 593d45f221SFilipe Manana */ 603d45f221SFilipe Manana BTRFS_INODE_NO_DELALLOC_FLUSH, 6114605409SBoris Burkov /* 6214605409SBoris Burkov * Set when we are working on enabling verity for a file. Computing and 6314605409SBoris Burkov * writing the whole Merkle tree can take a while so we want to prevent 6414605409SBoris Burkov * races where two separate tasks attempt to simultaneously start verity 6514605409SBoris Burkov * on the same file. 6614605409SBoris Burkov */ 6714605409SBoris Burkov BTRFS_INODE_VERITY_IN_PROGRESS, 689b9b8854SJosef Bacik /* Set when this inode is a free space inode. */ 699b9b8854SJosef Bacik BTRFS_INODE_FREE_SPACE_INODE, 707efc3e34SOmar Sandoval }; 7172ac3c0dSJosef Bacik 72f1ace244SAneesh /* in memory btrfs inode */ 732c90e5d6SChris Mason struct btrfs_inode { 74d352ac68SChris Mason /* which subvolume this inode belongs to */ 75d6e4a428SChris Mason struct btrfs_root *root; 76d352ac68SChris Mason 77d352ac68SChris Mason /* key used to find this inode on disk. This is used by the code 78d352ac68SChris Mason * to read in roots of subvolumes 79d352ac68SChris Mason */ 80d6e4a428SChris Mason struct btrfs_key location; 81d352ac68SChris Mason 822f2ff0eeSFilipe Manana /* 832f2ff0eeSFilipe Manana * Lock for counters and all fields used to determine if the inode is in 842f2ff0eeSFilipe Manana * the log or not (last_trans, last_sub_trans, last_log_commit, 852766ff61SFilipe Manana * logged_trans), to access/update new_delalloc_bytes and to update the 862766ff61SFilipe Manana * VFS' inode number of bytes used. 872f2ff0eeSFilipe Manana */ 889e0baf60SJosef Bacik spinlock_t lock; 899e0baf60SJosef Bacik 90d352ac68SChris Mason /* the extent_tree has caches of all the extent mappings to disk */ 91a52d9a80SChris Mason struct extent_map_tree extent_tree; 92d352ac68SChris Mason 93d352ac68SChris Mason /* the io_tree does range state (DIRTY, LOCKED etc) */ 94d1310b2eSChris Mason struct extent_io_tree io_tree; 95d352ac68SChris Mason 96d352ac68SChris Mason /* special utility tree used to record which mirrors have already been 97d352ac68SChris Mason * tried when checksums fail for a given block 98d352ac68SChris Mason */ 9987c11705SJosef Bacik struct rb_root io_failure_tree; 10087c11705SJosef Bacik spinlock_t io_failure_lock; 101d352ac68SChris Mason 10241a2ee75SJosef Bacik /* 10341a2ee75SJosef Bacik * Keep track of where the inode has extent items mapped in order to 10441a2ee75SJosef Bacik * make sure the i_size adjustments are accurate 10541a2ee75SJosef Bacik */ 10641a2ee75SJosef Bacik struct extent_io_tree file_extent_tree; 10741a2ee75SJosef Bacik 108d352ac68SChris Mason /* held while logging the inode in tree-log.c */ 109e02119d5SChris Mason struct mutex log_mutex; 110d352ac68SChris Mason 111d352ac68SChris Mason /* used to order data wrt metadata */ 112e6dcd2dcSChris Mason struct btrfs_ordered_inode_tree ordered_tree; 11315ee9bc7SJosef Bacik 114d352ac68SChris Mason /* list of all the delalloc inodes in the FS. There are times we need 115d352ac68SChris Mason * to write all the delalloc pages to disk, and this list is used 116d352ac68SChris Mason * to walk them all. 117d352ac68SChris Mason */ 118ea8c2819SChris Mason struct list_head delalloc_inodes; 119ea8c2819SChris Mason 1205d4f98a2SYan Zheng /* node for the red-black tree that links inodes in subvolume root */ 1215d4f98a2SYan Zheng struct rb_node rb_node; 1225d4f98a2SYan Zheng 12372ac3c0dSJosef Bacik unsigned long runtime_flags; 12472ac3c0dSJosef Bacik 1259c931c5aSNathaniel Yazdani /* Keep track of who's O_SYNC/fsyncing currently */ 126b812ce28SJosef Bacik atomic_t sync_writers; 127b812ce28SJosef Bacik 128d352ac68SChris Mason /* full 64 bit generation number, struct vfs_inode doesn't have a big 129d352ac68SChris Mason * enough field for this. 130d352ac68SChris Mason */ 131e02119d5SChris Mason u64 generation; 132e02119d5SChris Mason 13315ee9bc7SJosef Bacik /* 13415ee9bc7SJosef Bacik * transid of the trans_handle that last modified this inode 13515ee9bc7SJosef Bacik */ 13615ee9bc7SJosef Bacik u64 last_trans; 137257c62e1SChris Mason 138257c62e1SChris Mason /* 139e02119d5SChris Mason * transid that last logged this inode 140e02119d5SChris Mason */ 141e02119d5SChris Mason u64 logged_trans; 14249eb7e46SChris Mason 143bb14a59bSMiao Xie /* 144bb14a59bSMiao Xie * log transid when this inode was last modified 145bb14a59bSMiao Xie */ 146bb14a59bSMiao Xie int last_sub_trans; 147bb14a59bSMiao Xie 148bb14a59bSMiao Xie /* a local copy of root's last_log_commit */ 149bb14a59bSMiao Xie int last_log_commit; 150bb14a59bSMiao Xie 151dc287224SFilipe Manana /* 152339d0354SFilipe Manana * Total number of bytes pending delalloc, used by stat to calculate the 153339d0354SFilipe Manana * real block usage of the file. This is used only for files. 154d352ac68SChris Mason */ 1559069218dSChris Mason u64 delalloc_bytes; 156d352ac68SChris Mason 157dc287224SFilipe Manana union { 158d352ac68SChris Mason /* 159a7e3b975SFilipe Manana * Total number of bytes pending delalloc that fall within a file 160a7e3b975SFilipe Manana * range that is either a hole or beyond EOF (and no prealloc extent 161dc287224SFilipe Manana * exists in the range). This is always <= delalloc_bytes and this 162dc287224SFilipe Manana * is used only for files. 163a7e3b975SFilipe Manana */ 164a7e3b975SFilipe Manana u64 new_delalloc_bytes; 165dc287224SFilipe Manana /* 166dc287224SFilipe Manana * The offset of the last dir index key that was logged. 167dc287224SFilipe Manana * This is used only for directories. 168dc287224SFilipe Manana */ 169dc287224SFilipe Manana u64 last_dir_index_offset; 170dc287224SFilipe Manana }; 171a7e3b975SFilipe Manana 172a7e3b975SFilipe Manana /* 17347059d93SWang Shilong * total number of bytes pending defrag, used by stat to check whether 17447059d93SWang Shilong * it needs COW. 17547059d93SWang Shilong */ 17647059d93SWang Shilong u64 defrag_bytes; 17747059d93SWang Shilong 17847059d93SWang Shilong /* 179d352ac68SChris Mason * the size of the file stored in the metadata on disk. data=ordered 180d352ac68SChris Mason * means the in-memory i_size might be larger than the size on disk 181d352ac68SChris Mason * because not all the blocks are written yet. 182d352ac68SChris Mason */ 183dbe674a9SChris Mason u64 disk_i_size; 184d352ac68SChris Mason 185aec7477bSJosef Bacik /* 186528ee697SFilipe Manana * If this is a directory then index_cnt is the counter for the index 187528ee697SFilipe Manana * number for new files that are created. For an empty directory, this 188528ee697SFilipe Manana * must be initialized to BTRFS_DIR_START_INDEX. 189aec7477bSJosef Bacik */ 190aec7477bSJosef Bacik u64 index_cnt; 191d352ac68SChris Mason 19267de1176SMiao Xie /* Cache the directory index number to speed the dir/file remove */ 19367de1176SMiao Xie u64 dir_index; 19467de1176SMiao Xie 19512fcfd22SChris Mason /* the fsync log has some corner cases that mean we have to check 19612fcfd22SChris Mason * directories to see if any unlinks have been done before 19712fcfd22SChris Mason * the directory was logged. See tree-log.c for all the 19812fcfd22SChris Mason * details 19912fcfd22SChris Mason */ 20012fcfd22SChris Mason u64 last_unlink_trans; 20112fcfd22SChris Mason 2027709cde3SJosef Bacik /* 2033ebac17cSFilipe Manana * The id/generation of the last transaction where this inode was 2043ebac17cSFilipe Manana * either the source or the destination of a clone/dedupe operation. 2053ebac17cSFilipe Manana * Used when logging an inode to know if there are shared extents that 2063ebac17cSFilipe Manana * need special care when logging checksum items, to avoid duplicate 2073ebac17cSFilipe Manana * checksum items in a log (which can lead to a corruption where we end 2083ebac17cSFilipe Manana * up with missing checksum ranges after log replay). 2093ebac17cSFilipe Manana * Protected by the vfs inode lock. 2103ebac17cSFilipe Manana */ 2113ebac17cSFilipe Manana u64 last_reflink_trans; 2123ebac17cSFilipe Manana 2133ebac17cSFilipe Manana /* 2147709cde3SJosef Bacik * Number of bytes outstanding that are going to need csums. This is 2157709cde3SJosef Bacik * used in ENOSPC accounting. 2167709cde3SJosef Bacik */ 2177709cde3SJosef Bacik u64 csum_bytes; 2187709cde3SJosef Bacik 21977eea05eSBoris Burkov /* Backwards incompatible flags, lower half of inode_item::flags */ 220f1bdcc0aSJosef Bacik u32 flags; 22177eea05eSBoris Burkov /* Read-only compatibility flags, upper half of inode_item::flags */ 22277eea05eSBoris Burkov u32 ro_flags; 223f1bdcc0aSJosef Bacik 2245a3f23d5SChris Mason /* 22532c00affSJosef Bacik * Counters to keep track of the number of extent item's we may use due 22632c00affSJosef Bacik * to delalloc and such. outstanding_extents is the number of extent 22732c00affSJosef Bacik * items we think we'll end up using, and reserved_extents is the number 22832c00affSJosef Bacik * of extent items we've reserved metadata for. 2299ed74f2dSJosef Bacik */ 2309e0baf60SJosef Bacik unsigned outstanding_extents; 23169fe2d75SJosef Bacik 23269fe2d75SJosef Bacik struct btrfs_block_rsv block_rsv; 2339ed74f2dSJosef Bacik 2349ed74f2dSJosef Bacik /* 235b52aa8c9SDavid Sterba * Cached values of inode properties 2361e701a32SChris Mason */ 237b52aa8c9SDavid Sterba unsigned prop_compress; /* per-file compression algorithm */ 238eec63c65SDavid Sterba /* 239eec63c65SDavid Sterba * Force compression on the file using the defrag ioctl, could be 240eec63c65SDavid Sterba * different from prop_compress and takes precedence if set 241eec63c65SDavid Sterba */ 242eec63c65SDavid Sterba unsigned defrag_compress; 2431e701a32SChris Mason 24416cdcec7SMiao Xie struct btrfs_delayed_node *delayed_node; 24516cdcec7SMiao Xie 2469cc97d64Schandan r /* File creation time. */ 247d3c6be6fSArnd Bergmann struct timespec64 i_otime; 2489cc97d64Schandan r 2498089fe62SDavid Sterba /* Hook into fs_info->delayed_iputs */ 2508089fe62SDavid Sterba struct list_head delayed_iput; 2518089fe62SDavid Sterba 2528318ba79SJosef Bacik struct rw_semaphore i_mmap_lock; 253d352ac68SChris Mason struct inode vfs_inode; 2542c90e5d6SChris Mason }; 255dbe674a9SChris Mason 2569a35b637SJeff Mahoney static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) 2572c90e5d6SChris Mason { 2582c90e5d6SChris Mason return container_of(inode, struct btrfs_inode, vfs_inode); 2592c90e5d6SChris Mason } 2602c90e5d6SChris Mason 261778ba82bSFilipe David Borba Manana static inline unsigned long btrfs_inode_hash(u64 objectid, 262778ba82bSFilipe David Borba Manana const struct btrfs_root *root) 263778ba82bSFilipe David Borba Manana { 2644fd786e6SMisono Tomohiro u64 h = objectid ^ (root->root_key.objectid * GOLDEN_RATIO_PRIME); 265778ba82bSFilipe David Borba Manana 266778ba82bSFilipe David Borba Manana #if BITS_PER_LONG == 32 267778ba82bSFilipe David Borba Manana h = (h >> 32) ^ (h & 0xffffffff); 268778ba82bSFilipe David Borba Manana #endif 269778ba82bSFilipe David Borba Manana 270778ba82bSFilipe David Borba Manana return (unsigned long)h; 271778ba82bSFilipe David Borba Manana } 272778ba82bSFilipe David Borba Manana 273cf2404a9SFilipe Manana #if BITS_PER_LONG == 32 274cf2404a9SFilipe Manana 275cf2404a9SFilipe Manana /* 276cf2404a9SFilipe Manana * On 32 bit systems the i_ino of struct inode is 32 bits (unsigned long), so 277cf2404a9SFilipe Manana * we use the inode's location objectid which is a u64 to avoid truncation. 278cf2404a9SFilipe Manana */ 2799a35b637SJeff Mahoney static inline u64 btrfs_ino(const struct btrfs_inode *inode) 28033345d01SLi Zefan { 2814a0cc7caSNikolay Borisov u64 ino = inode->location.objectid; 28233345d01SLi Zefan 283adac5584SFilipe Manana /* type == BTRFS_ROOT_ITEM_KEY: subvol dir */ 284adac5584SFilipe Manana if (inode->location.type == BTRFS_ROOT_ITEM_KEY) 2854a0cc7caSNikolay Borisov ino = inode->vfs_inode.i_ino; 28633345d01SLi Zefan return ino; 28733345d01SLi Zefan } 28833345d01SLi Zefan 289cf2404a9SFilipe Manana #else 290cf2404a9SFilipe Manana 291cf2404a9SFilipe Manana static inline u64 btrfs_ino(const struct btrfs_inode *inode) 292cf2404a9SFilipe Manana { 293cf2404a9SFilipe Manana return inode->vfs_inode.i_ino; 294cf2404a9SFilipe Manana } 295cf2404a9SFilipe Manana 296cf2404a9SFilipe Manana #endif 297cf2404a9SFilipe Manana 2986ef06d27SNikolay Borisov static inline void btrfs_i_size_write(struct btrfs_inode *inode, u64 size) 299dbe674a9SChris Mason { 3006ef06d27SNikolay Borisov i_size_write(&inode->vfs_inode, size); 3016ef06d27SNikolay Borisov inode->disk_i_size = size; 302dbe674a9SChris Mason } 303dbe674a9SChris Mason 30470ddc553SNikolay Borisov static inline bool btrfs_is_free_space_inode(struct btrfs_inode *inode) 3052cf8572dSChris Mason { 3069b9b8854SJosef Bacik return test_bit(BTRFS_INODE_FREE_SPACE_INODE, &inode->runtime_flags); 3072cf8572dSChris Mason } 3082cf8572dSChris Mason 30906f2548fSNikolay Borisov static inline bool is_data_inode(struct inode *inode) 31006f2548fSNikolay Borisov { 31106f2548fSNikolay Borisov return btrfs_ino(BTRFS_I(inode)) != BTRFS_BTREE_INODE_OBJECTID; 31206f2548fSNikolay Borisov } 31306f2548fSNikolay Borisov 3148b62f87bSJosef Bacik static inline void btrfs_mod_outstanding_extents(struct btrfs_inode *inode, 3158b62f87bSJosef Bacik int mod) 3168b62f87bSJosef Bacik { 3178b62f87bSJosef Bacik lockdep_assert_held(&inode->lock); 3188b62f87bSJosef Bacik inode->outstanding_extents += mod; 3198b62f87bSJosef Bacik if (btrfs_is_free_space_inode(inode)) 3208b62f87bSJosef Bacik return; 321dd48d407SJosef Bacik trace_btrfs_inode_mod_outstanding_extents(inode->root, btrfs_ino(inode), 322dd48d407SJosef Bacik mod); 3238b62f87bSJosef Bacik } 3248b62f87bSJosef Bacik 325bc0939fcSFilipe Manana /* 326bc0939fcSFilipe Manana * Called every time after doing a buffered, direct IO or memory mapped write. 327bc0939fcSFilipe Manana * 328bc0939fcSFilipe Manana * This is to ensure that if we write to a file that was previously fsynced in 329bc0939fcSFilipe Manana * the current transaction, then try to fsync it again in the same transaction, 330bc0939fcSFilipe Manana * we will know that there were changes in the file and that it needs to be 331bc0939fcSFilipe Manana * logged. 332bc0939fcSFilipe Manana */ 333bc0939fcSFilipe Manana static inline void btrfs_set_inode_last_sub_trans(struct btrfs_inode *inode) 334bc0939fcSFilipe Manana { 335bc0939fcSFilipe Manana spin_lock(&inode->lock); 336bc0939fcSFilipe Manana inode->last_sub_trans = inode->root->log_transid; 337bc0939fcSFilipe Manana spin_unlock(&inode->lock); 338bc0939fcSFilipe Manana } 339bc0939fcSFilipe Manana 34023e3337fSFilipe Manana /* 34123e3337fSFilipe Manana * Should be called while holding the inode's VFS lock in exclusive mode or in a 34223e3337fSFilipe Manana * context where no one else can access the inode concurrently (during inode 34323e3337fSFilipe Manana * creation or when loading an inode from disk). 34423e3337fSFilipe Manana */ 34523e3337fSFilipe Manana static inline void btrfs_set_inode_full_sync(struct btrfs_inode *inode) 34623e3337fSFilipe Manana { 34723e3337fSFilipe Manana set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags); 34823e3337fSFilipe Manana /* 34923e3337fSFilipe Manana * The inode may have been part of a reflink operation in the last 35023e3337fSFilipe Manana * transaction that modified it, and then a fsync has reset the 35123e3337fSFilipe Manana * last_reflink_trans to avoid subsequent fsyncs in the same 35223e3337fSFilipe Manana * transaction to do unnecessary work. So update last_reflink_trans 35323e3337fSFilipe Manana * to the last_trans value (we have to be pessimistic and assume a 35423e3337fSFilipe Manana * reflink happened). 35523e3337fSFilipe Manana * 35623e3337fSFilipe Manana * The ->last_trans is protected by the inode's spinlock and we can 35723e3337fSFilipe Manana * have a concurrent ordered extent completion update it. Also set 35823e3337fSFilipe Manana * last_reflink_trans to ->last_trans only if the former is less than 35923e3337fSFilipe Manana * the later, because we can be called in a context where 36023e3337fSFilipe Manana * last_reflink_trans was set to the current transaction generation 36123e3337fSFilipe Manana * while ->last_trans was not yet updated in the current transaction, 36223e3337fSFilipe Manana * and therefore has a lower value. 36323e3337fSFilipe Manana */ 36423e3337fSFilipe Manana spin_lock(&inode->lock); 36523e3337fSFilipe Manana if (inode->last_reflink_trans < inode->last_trans) 36623e3337fSFilipe Manana inode->last_reflink_trans = inode->last_trans; 36723e3337fSFilipe Manana spin_unlock(&inode->lock); 36823e3337fSFilipe Manana } 36923e3337fSFilipe Manana 370209ecbb8SFilipe Manana static inline bool btrfs_inode_in_log(struct btrfs_inode *inode, u64 generation) 37122ee6985SJosef Bacik { 372209ecbb8SFilipe Manana bool ret = false; 3732f2ff0eeSFilipe Manana 3740f8939b8SNikolay Borisov spin_lock(&inode->lock); 3750f8939b8SNikolay Borisov if (inode->logged_trans == generation && 3760f8939b8SNikolay Borisov inode->last_sub_trans <= inode->last_log_commit && 377209ecbb8SFilipe Manana inode->last_sub_trans <= inode->root->last_log_commit) 378209ecbb8SFilipe Manana ret = true; 3790f8939b8SNikolay Borisov spin_unlock(&inode->lock); 3802f2ff0eeSFilipe Manana return ret; 38122ee6985SJosef Bacik } 38222ee6985SJosef Bacik 383e6f9d696SChung-Chiang Cheng /* 384e6f9d696SChung-Chiang Cheng * Check if the inode has flags compatible with compression 385e6f9d696SChung-Chiang Cheng */ 386e6f9d696SChung-Chiang Cheng static inline bool btrfs_inode_can_compress(const struct btrfs_inode *inode) 387e6f9d696SChung-Chiang Cheng { 388e6f9d696SChung-Chiang Cheng if (inode->flags & BTRFS_INODE_NODATACOW || 389e6f9d696SChung-Chiang Cheng inode->flags & BTRFS_INODE_NODATASUM) 390e6f9d696SChung-Chiang Cheng return false; 391e6f9d696SChung-Chiang Cheng return true; 392e6f9d696SChung-Chiang Cheng } 393e6f9d696SChung-Chiang Cheng 39477eea05eSBoris Burkov /* 39577eea05eSBoris Burkov * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two 39677eea05eSBoris Burkov * separate u32s. These two functions convert between the two representations. 39777eea05eSBoris Burkov */ 39877eea05eSBoris Burkov static inline u64 btrfs_inode_combine_flags(u32 flags, u32 ro_flags) 39977eea05eSBoris Burkov { 40077eea05eSBoris Burkov return (flags | ((u64)ro_flags << 32)); 40177eea05eSBoris Burkov } 40277eea05eSBoris Burkov 40377eea05eSBoris Burkov static inline void btrfs_inode_split_flags(u64 inode_item_flags, 40477eea05eSBoris Burkov u32 *flags, u32 *ro_flags) 40577eea05eSBoris Burkov { 40677eea05eSBoris Burkov *flags = (u32)inode_item_flags; 40777eea05eSBoris Burkov *ro_flags = (u32)(inode_item_flags >> 32); 40877eea05eSBoris Burkov } 40977eea05eSBoris Burkov 4107ebc7e5fSJohannes Thumshirn /* Array of bytes with variable length, hexadecimal format 0x1234 */ 4117ebc7e5fSJohannes Thumshirn #define CSUM_FMT "0x%*phN" 4127ebc7e5fSJohannes Thumshirn #define CSUM_FMT_VALUE(size, bytes) size, bytes 4132885fd63SJosef Bacik 414535a7e5dSDavid Sterba void btrfs_submit_data_write_bio(struct btrfs_inode *inode, struct bio *bio, int mirror_num); 415b7620416SDavid Sterba void btrfs_submit_data_read_bio(struct btrfs_inode *inode, struct bio *bio, 4162885fd63SJosef Bacik int mirror_num, enum btrfs_compression_type compress_type); 417d781c1c3SDavid Sterba void btrfs_submit_dio_repair_bio(struct btrfs_inode *inode, struct bio *bio, int mirror_num); 418882681acSDavid Sterba blk_status_t btrfs_submit_bio_start(struct btrfs_inode *inode, struct bio *bio); 419bfa17066SDavid Sterba blk_status_t btrfs_submit_bio_start_direct_io(struct btrfs_inode *inode, 420ab2072b2SDavid Sterba struct bio *bio, 421ab2072b2SDavid Sterba u64 dio_file_offset); 4222885fd63SJosef Bacik int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page, 4232885fd63SJosef Bacik u32 pgoff, u8 *csum, const u8 * const csum_expected); 424621af94aSDavid Sterba int btrfs_check_data_csum(struct btrfs_inode *inode, struct btrfs_bio *bbio, 4252885fd63SJosef Bacik u32 bio_offset, struct page *page, u32 pgoff); 4262885fd63SJosef Bacik unsigned int btrfs_verify_data_csum(struct btrfs_bio *bbio, 4272885fd63SJosef Bacik u32 bio_offset, struct page *page, 4282885fd63SJosef Bacik u64 start, u64 end); 4292885fd63SJosef Bacik noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, 4302885fd63SJosef Bacik u64 *orig_start, u64 *orig_block_len, 4312885fd63SJosef Bacik u64 *ram_bytes, bool nowait, bool strict); 4322885fd63SJosef Bacik 4332885fd63SJosef Bacik void __btrfs_del_delalloc_inode(struct btrfs_root *root, struct btrfs_inode *inode); 4342885fd63SJosef Bacik struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); 4352885fd63SJosef Bacik int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index); 4362885fd63SJosef Bacik int btrfs_unlink_inode(struct btrfs_trans_handle *trans, 4372885fd63SJosef Bacik struct btrfs_inode *dir, struct btrfs_inode *inode, 4382885fd63SJosef Bacik const struct fscrypt_str *name); 4392885fd63SJosef Bacik int btrfs_add_link(struct btrfs_trans_handle *trans, 4402885fd63SJosef Bacik struct btrfs_inode *parent_inode, struct btrfs_inode *inode, 4412885fd63SJosef Bacik const struct fscrypt_str *name, int add_backref, u64 index); 4423c4f91e2SDavid Sterba int btrfs_delete_subvolume(struct btrfs_inode *dir, struct dentry *dentry); 4432885fd63SJosef Bacik int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, 4442885fd63SJosef Bacik int front); 4452885fd63SJosef Bacik 4462885fd63SJosef Bacik int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context); 4472885fd63SJosef Bacik int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr, 4482885fd63SJosef Bacik bool in_reclaim_context); 4492885fd63SJosef Bacik int btrfs_set_extent_delalloc(struct btrfs_inode *inode, u64 start, u64 end, 4502885fd63SJosef Bacik unsigned int extra_bits, 4512885fd63SJosef Bacik struct extent_state **cached_state); 4522885fd63SJosef Bacik 4532885fd63SJosef Bacik struct btrfs_new_inode_args { 4542885fd63SJosef Bacik /* Input */ 4552885fd63SJosef Bacik struct inode *dir; 4562885fd63SJosef Bacik struct dentry *dentry; 4572885fd63SJosef Bacik struct inode *inode; 4582885fd63SJosef Bacik bool orphan; 4592885fd63SJosef Bacik bool subvol; 4602885fd63SJosef Bacik 4612885fd63SJosef Bacik /* Output from btrfs_new_inode_prepare(), input to btrfs_create_new_inode(). */ 4622885fd63SJosef Bacik struct posix_acl *default_acl; 4632885fd63SJosef Bacik struct posix_acl *acl; 4642885fd63SJosef Bacik struct fscrypt_name fname; 4652885fd63SJosef Bacik }; 4662885fd63SJosef Bacik 4672885fd63SJosef Bacik int btrfs_new_inode_prepare(struct btrfs_new_inode_args *args, 4682885fd63SJosef Bacik unsigned int *trans_num_items); 4692885fd63SJosef Bacik int btrfs_create_new_inode(struct btrfs_trans_handle *trans, 4702885fd63SJosef Bacik struct btrfs_new_inode_args *args); 4712885fd63SJosef Bacik void btrfs_new_inode_args_destroy(struct btrfs_new_inode_args *args); 4722885fd63SJosef Bacik struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns, 4732885fd63SJosef Bacik struct inode *dir); 474*4c5d166fSDavid Sterba void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *state, 4752885fd63SJosef Bacik u32 bits); 4762885fd63SJosef Bacik void btrfs_clear_delalloc_extent(struct inode *inode, 4772885fd63SJosef Bacik struct extent_state *state, u32 bits); 4782454151cSDavid Sterba void btrfs_merge_delalloc_extent(struct btrfs_inode *inode, struct extent_state *new, 4792885fd63SJosef Bacik struct extent_state *other); 4802885fd63SJosef Bacik void btrfs_split_delalloc_extent(struct inode *inode, 4812885fd63SJosef Bacik struct extent_state *orig, u64 split); 4822885fd63SJosef Bacik void btrfs_set_range_writeback(struct btrfs_inode *inode, u64 start, u64 end); 4832885fd63SJosef Bacik vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf); 4842885fd63SJosef Bacik void btrfs_evict_inode(struct inode *inode); 4852885fd63SJosef Bacik struct inode *btrfs_alloc_inode(struct super_block *sb); 4862885fd63SJosef Bacik void btrfs_destroy_inode(struct inode *inode); 4872885fd63SJosef Bacik void btrfs_free_inode(struct inode *inode); 4882885fd63SJosef Bacik int btrfs_drop_inode(struct inode *inode); 4892885fd63SJosef Bacik int __init btrfs_init_cachep(void); 4902885fd63SJosef Bacik void __cold btrfs_destroy_cachep(void); 4912885fd63SJosef Bacik struct inode *btrfs_iget_path(struct super_block *s, u64 ino, 4922885fd63SJosef Bacik struct btrfs_root *root, struct btrfs_path *path); 4932885fd63SJosef Bacik struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root); 4942885fd63SJosef Bacik struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, 4952885fd63SJosef Bacik struct page *page, size_t pg_offset, 4962885fd63SJosef Bacik u64 start, u64 end); 4972885fd63SJosef Bacik int btrfs_update_inode(struct btrfs_trans_handle *trans, 4982885fd63SJosef Bacik struct btrfs_root *root, struct btrfs_inode *inode); 4992885fd63SJosef Bacik int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, 5002885fd63SJosef Bacik struct btrfs_root *root, struct btrfs_inode *inode); 5012885fd63SJosef Bacik int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct btrfs_inode *inode); 5022885fd63SJosef Bacik int btrfs_orphan_cleanup(struct btrfs_root *root); 5032885fd63SJosef Bacik int btrfs_cont_expand(struct btrfs_inode *inode, loff_t oldsize, loff_t size); 5042885fd63SJosef Bacik void btrfs_add_delayed_iput(struct inode *inode); 5052885fd63SJosef Bacik void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info); 5062885fd63SJosef Bacik int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info); 5072885fd63SJosef Bacik int btrfs_prealloc_file_range(struct inode *inode, int mode, 5082885fd63SJosef Bacik u64 start, u64 num_bytes, u64 min_size, 5092885fd63SJosef Bacik loff_t actual_len, u64 *alloc_hint); 5102885fd63SJosef Bacik int btrfs_prealloc_file_range_trans(struct inode *inode, 5112885fd63SJosef Bacik struct btrfs_trans_handle *trans, int mode, 5122885fd63SJosef Bacik u64 start, u64 num_bytes, u64 min_size, 5132885fd63SJosef Bacik loff_t actual_len, u64 *alloc_hint); 5142885fd63SJosef Bacik int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page, 5152885fd63SJosef Bacik u64 start, u64 end, int *page_started, 5162885fd63SJosef Bacik unsigned long *nr_written, struct writeback_control *wbc); 5172885fd63SJosef Bacik int btrfs_writepage_cow_fixup(struct page *page); 5182885fd63SJosef Bacik void btrfs_writepage_endio_finish_ordered(struct btrfs_inode *inode, 5192885fd63SJosef Bacik struct page *page, u64 start, 5202885fd63SJosef Bacik u64 end, bool uptodate); 5212885fd63SJosef Bacik int btrfs_encoded_io_compression_from_extent(struct btrfs_fs_info *fs_info, 5222885fd63SJosef Bacik int compress_type); 5232885fd63SJosef Bacik int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, 5242885fd63SJosef Bacik u64 file_offset, u64 disk_bytenr, 5252885fd63SJosef Bacik u64 disk_io_size, 5262885fd63SJosef Bacik struct page **pages); 5272885fd63SJosef Bacik ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, 5282885fd63SJosef Bacik struct btrfs_ioctl_encoded_io_args *encoded); 5292885fd63SJosef Bacik ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, 5302885fd63SJosef Bacik const struct btrfs_ioctl_encoded_io_args *encoded); 5312885fd63SJosef Bacik 5322885fd63SJosef Bacik ssize_t btrfs_dio_read(struct kiocb *iocb, struct iov_iter *iter, 5332885fd63SJosef Bacik size_t done_before); 5342885fd63SJosef Bacik struct iomap_dio *btrfs_dio_write(struct kiocb *iocb, struct iov_iter *iter, 5352885fd63SJosef Bacik size_t done_before); 5362885fd63SJosef Bacik 5372885fd63SJosef Bacik extern const struct dentry_operations btrfs_dentry_operations; 5382885fd63SJosef Bacik 5392885fd63SJosef Bacik /* Inode locking type flags, by default the exclusive lock is taken. */ 5402885fd63SJosef Bacik enum btrfs_ilock_type { 5412885fd63SJosef Bacik ENUM_BIT(BTRFS_ILOCK_SHARED), 5422885fd63SJosef Bacik ENUM_BIT(BTRFS_ILOCK_TRY), 5432885fd63SJosef Bacik ENUM_BIT(BTRFS_ILOCK_MMAP), 5442885fd63SJosef Bacik }; 5452885fd63SJosef Bacik 54629b6352bSDavid Sterba int btrfs_inode_lock(struct btrfs_inode *inode, unsigned int ilock_flags); 547e5d4d75bSDavid Sterba void btrfs_inode_unlock(struct btrfs_inode *inode, unsigned int ilock_flags); 5482885fd63SJosef Bacik void btrfs_update_inode_bytes(struct btrfs_inode *inode, const u64 add_bytes, 5492885fd63SJosef Bacik const u64 del_bytes); 5502885fd63SJosef Bacik void btrfs_assert_inode_range_clean(struct btrfs_inode *inode, u64 start, u64 end); 5512885fd63SJosef Bacik 5522c90e5d6SChris Mason #endif 553