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 /* 1772ac3c0dSJosef Bacik * ordered_data_close is set by truncate when a file that used 1872ac3c0dSJosef Bacik * to have good data has been truncated to zero. When it is set 1972ac3c0dSJosef Bacik * the btrfs file release call will add this inode to the 2072ac3c0dSJosef Bacik * ordered operations list so that we make sure to flush out any 2172ac3c0dSJosef Bacik * new data the application may have written before commit. 2272ac3c0dSJosef Bacik */ 237efc3e34SOmar Sandoval enum { 241fd4033dSNikolay Borisov BTRFS_INODE_FLUSH_ON_CLOSE, 257efc3e34SOmar Sandoval BTRFS_INODE_DUMMY, 267efc3e34SOmar Sandoval BTRFS_INODE_IN_DEFRAG, 277efc3e34SOmar Sandoval BTRFS_INODE_HAS_ASYNC_EXTENT, 2848778179SFilipe Manana /* 2948778179SFilipe Manana * Always set under the VFS' inode lock, otherwise it can cause races 3048778179SFilipe Manana * during fsync (we start as a fast fsync and then end up in a full 3148778179SFilipe Manana * fsync racing with ordered extent completion). 3248778179SFilipe Manana */ 337efc3e34SOmar Sandoval BTRFS_INODE_NEEDS_FULL_SYNC, 347efc3e34SOmar Sandoval BTRFS_INODE_COPY_EVERYTHING, 357efc3e34SOmar Sandoval BTRFS_INODE_IN_DELALLOC_LIST, 367efc3e34SOmar Sandoval BTRFS_INODE_HAS_PROPS, 373cd24c69SEthan Lien BTRFS_INODE_SNAPSHOT_FLUSH, 38f2f121abSFilipe Manana /* 39f2f121abSFilipe Manana * Set and used when logging an inode and it serves to signal that an 40f2f121abSFilipe Manana * inode does not have xattrs, so subsequent fsyncs can avoid searching 41f2f121abSFilipe Manana * for xattrs to log. This bit must be cleared whenever a xattr is added 42f2f121abSFilipe Manana * to an inode. 43f2f121abSFilipe Manana */ 44f2f121abSFilipe Manana BTRFS_INODE_NO_XATTRS, 453d45f221SFilipe Manana /* 463d45f221SFilipe Manana * Set when we are in a context where we need to start a transaction and 473d45f221SFilipe Manana * have dirty pages with the respective file range locked. This is to 483d45f221SFilipe Manana * ensure that when reserving space for the transaction, if we are low 493d45f221SFilipe Manana * on available space and need to flush delalloc, we will not flush 503d45f221SFilipe Manana * delalloc for this inode, because that could result in a deadlock (on 513d45f221SFilipe Manana * the file range, inode's io_tree). 523d45f221SFilipe Manana */ 533d45f221SFilipe Manana BTRFS_INODE_NO_DELALLOC_FLUSH, 5414605409SBoris Burkov /* 5514605409SBoris Burkov * Set when we are working on enabling verity for a file. Computing and 5614605409SBoris Burkov * writing the whole Merkle tree can take a while so we want to prevent 5714605409SBoris Burkov * races where two separate tasks attempt to simultaneously start verity 5814605409SBoris Burkov * on the same file. 5914605409SBoris Burkov */ 6014605409SBoris Burkov BTRFS_INODE_VERITY_IN_PROGRESS, 617efc3e34SOmar Sandoval }; 6272ac3c0dSJosef Bacik 63f1ace244SAneesh /* in memory btrfs inode */ 642c90e5d6SChris Mason struct btrfs_inode { 65d352ac68SChris Mason /* which subvolume this inode belongs to */ 66d6e4a428SChris Mason struct btrfs_root *root; 67d352ac68SChris Mason 68d352ac68SChris Mason /* key used to find this inode on disk. This is used by the code 69d352ac68SChris Mason * to read in roots of subvolumes 70d352ac68SChris Mason */ 71d6e4a428SChris Mason struct btrfs_key location; 72d352ac68SChris Mason 732f2ff0eeSFilipe Manana /* 742f2ff0eeSFilipe Manana * Lock for counters and all fields used to determine if the inode is in 752f2ff0eeSFilipe Manana * the log or not (last_trans, last_sub_trans, last_log_commit, 762766ff61SFilipe Manana * logged_trans), to access/update new_delalloc_bytes and to update the 772766ff61SFilipe Manana * VFS' inode number of bytes used. 782f2ff0eeSFilipe Manana */ 799e0baf60SJosef Bacik spinlock_t lock; 809e0baf60SJosef Bacik 81d352ac68SChris Mason /* the extent_tree has caches of all the extent mappings to disk */ 82a52d9a80SChris Mason struct extent_map_tree extent_tree; 83d352ac68SChris Mason 84d352ac68SChris Mason /* the io_tree does range state (DIRTY, LOCKED etc) */ 85d1310b2eSChris Mason struct extent_io_tree io_tree; 86d352ac68SChris Mason 87d352ac68SChris Mason /* special utility tree used to record which mirrors have already been 88d352ac68SChris Mason * tried when checksums fail for a given block 89d352ac68SChris Mason */ 907e38326fSChris Mason struct extent_io_tree io_failure_tree; 91d352ac68SChris Mason 9241a2ee75SJosef Bacik /* 9341a2ee75SJosef Bacik * Keep track of where the inode has extent items mapped in order to 9441a2ee75SJosef Bacik * make sure the i_size adjustments are accurate 9541a2ee75SJosef Bacik */ 9641a2ee75SJosef Bacik struct extent_io_tree file_extent_tree; 9741a2ee75SJosef Bacik 98d352ac68SChris Mason /* held while logging the inode in tree-log.c */ 99e02119d5SChris Mason struct mutex log_mutex; 100d352ac68SChris Mason 101d352ac68SChris Mason /* used to order data wrt metadata */ 102e6dcd2dcSChris Mason struct btrfs_ordered_inode_tree ordered_tree; 10315ee9bc7SJosef Bacik 104d352ac68SChris Mason /* list of all the delalloc inodes in the FS. There are times we need 105d352ac68SChris Mason * to write all the delalloc pages to disk, and this list is used 106d352ac68SChris Mason * to walk them all. 107d352ac68SChris Mason */ 108ea8c2819SChris Mason struct list_head delalloc_inodes; 109ea8c2819SChris Mason 1105d4f98a2SYan Zheng /* node for the red-black tree that links inodes in subvolume root */ 1115d4f98a2SYan Zheng struct rb_node rb_node; 1125d4f98a2SYan Zheng 11372ac3c0dSJosef Bacik unsigned long runtime_flags; 11472ac3c0dSJosef Bacik 1159c931c5aSNathaniel Yazdani /* Keep track of who's O_SYNC/fsyncing currently */ 116b812ce28SJosef Bacik atomic_t sync_writers; 117b812ce28SJosef Bacik 118d352ac68SChris Mason /* full 64 bit generation number, struct vfs_inode doesn't have a big 119d352ac68SChris Mason * enough field for this. 120d352ac68SChris Mason */ 121e02119d5SChris Mason u64 generation; 122e02119d5SChris Mason 12315ee9bc7SJosef Bacik /* 12415ee9bc7SJosef Bacik * transid of the trans_handle that last modified this inode 12515ee9bc7SJosef Bacik */ 12615ee9bc7SJosef Bacik u64 last_trans; 127257c62e1SChris Mason 128257c62e1SChris Mason /* 129e02119d5SChris Mason * transid that last logged this inode 130e02119d5SChris Mason */ 131e02119d5SChris Mason u64 logged_trans; 13249eb7e46SChris Mason 133bb14a59bSMiao Xie /* 134bb14a59bSMiao Xie * log transid when this inode was last modified 135bb14a59bSMiao Xie */ 136bb14a59bSMiao Xie int last_sub_trans; 137bb14a59bSMiao Xie 138bb14a59bSMiao Xie /* a local copy of root's last_log_commit */ 139bb14a59bSMiao Xie int last_log_commit; 140bb14a59bSMiao Xie 141*dc287224SFilipe Manana union { 142*dc287224SFilipe Manana /* 143*dc287224SFilipe Manana * Total number of bytes pending delalloc, used by stat to 144*dc287224SFilipe Manana * calculate the real block usage of the file. This is used 145*dc287224SFilipe Manana * only for files. 146d352ac68SChris Mason */ 1479069218dSChris Mason u64 delalloc_bytes; 148*dc287224SFilipe Manana /* 149*dc287224SFilipe Manana * The offset of the last dir item key that was logged. 150*dc287224SFilipe Manana * This is used only for directories. 151*dc287224SFilipe Manana */ 152*dc287224SFilipe Manana u64 last_dir_item_offset; 153*dc287224SFilipe Manana }; 154d352ac68SChris Mason 155*dc287224SFilipe Manana union { 156d352ac68SChris Mason /* 157a7e3b975SFilipe Manana * Total number of bytes pending delalloc that fall within a file 158a7e3b975SFilipe Manana * range that is either a hole or beyond EOF (and no prealloc extent 159*dc287224SFilipe Manana * exists in the range). This is always <= delalloc_bytes and this 160*dc287224SFilipe Manana * is used only for files. 161a7e3b975SFilipe Manana */ 162a7e3b975SFilipe Manana u64 new_delalloc_bytes; 163*dc287224SFilipe Manana /* 164*dc287224SFilipe Manana * The offset of the last dir index key that was logged. 165*dc287224SFilipe Manana * This is used only for directories. 166*dc287224SFilipe Manana */ 167*dc287224SFilipe Manana u64 last_dir_index_offset; 168*dc287224SFilipe Manana }; 169a7e3b975SFilipe Manana 170a7e3b975SFilipe Manana /* 17147059d93SWang Shilong * total number of bytes pending defrag, used by stat to check whether 17247059d93SWang Shilong * it needs COW. 17347059d93SWang Shilong */ 17447059d93SWang Shilong u64 defrag_bytes; 17547059d93SWang Shilong 17647059d93SWang Shilong /* 177d352ac68SChris Mason * the size of the file stored in the metadata on disk. data=ordered 178d352ac68SChris Mason * means the in-memory i_size might be larger than the size on disk 179d352ac68SChris Mason * because not all the blocks are written yet. 180d352ac68SChris Mason */ 181dbe674a9SChris Mason u64 disk_i_size; 182d352ac68SChris Mason 183aec7477bSJosef Bacik /* 184aec7477bSJosef Bacik * if this is a directory then index_cnt is the counter for the index 185aec7477bSJosef Bacik * number for new files that are created 186aec7477bSJosef Bacik */ 187aec7477bSJosef Bacik u64 index_cnt; 188d352ac68SChris Mason 18967de1176SMiao Xie /* Cache the directory index number to speed the dir/file remove */ 19067de1176SMiao Xie u64 dir_index; 19167de1176SMiao Xie 19212fcfd22SChris Mason /* the fsync log has some corner cases that mean we have to check 19312fcfd22SChris Mason * directories to see if any unlinks have been done before 19412fcfd22SChris Mason * the directory was logged. See tree-log.c for all the 19512fcfd22SChris Mason * details 19612fcfd22SChris Mason */ 19712fcfd22SChris Mason u64 last_unlink_trans; 19812fcfd22SChris Mason 1997709cde3SJosef Bacik /* 2003ebac17cSFilipe Manana * The id/generation of the last transaction where this inode was 2013ebac17cSFilipe Manana * either the source or the destination of a clone/dedupe operation. 2023ebac17cSFilipe Manana * Used when logging an inode to know if there are shared extents that 2033ebac17cSFilipe Manana * need special care when logging checksum items, to avoid duplicate 2043ebac17cSFilipe Manana * checksum items in a log (which can lead to a corruption where we end 2053ebac17cSFilipe Manana * up with missing checksum ranges after log replay). 2063ebac17cSFilipe Manana * Protected by the vfs inode lock. 2073ebac17cSFilipe Manana */ 2083ebac17cSFilipe Manana u64 last_reflink_trans; 2093ebac17cSFilipe Manana 2103ebac17cSFilipe Manana /* 2117709cde3SJosef Bacik * Number of bytes outstanding that are going to need csums. This is 2127709cde3SJosef Bacik * used in ENOSPC accounting. 2137709cde3SJosef Bacik */ 2147709cde3SJosef Bacik u64 csum_bytes; 2157709cde3SJosef Bacik 21677eea05eSBoris Burkov /* Backwards incompatible flags, lower half of inode_item::flags */ 217f1bdcc0aSJosef Bacik u32 flags; 21877eea05eSBoris Burkov /* Read-only compatibility flags, upper half of inode_item::flags */ 21977eea05eSBoris Burkov u32 ro_flags; 220f1bdcc0aSJosef Bacik 2215a3f23d5SChris Mason /* 22232c00affSJosef Bacik * Counters to keep track of the number of extent item's we may use due 22332c00affSJosef Bacik * to delalloc and such. outstanding_extents is the number of extent 22432c00affSJosef Bacik * items we think we'll end up using, and reserved_extents is the number 22532c00affSJosef Bacik * of extent items we've reserved metadata for. 2269ed74f2dSJosef Bacik */ 2279e0baf60SJosef Bacik unsigned outstanding_extents; 22869fe2d75SJosef Bacik 22969fe2d75SJosef Bacik struct btrfs_block_rsv block_rsv; 2309ed74f2dSJosef Bacik 2319ed74f2dSJosef Bacik /* 232b52aa8c9SDavid Sterba * Cached values of inode properties 2331e701a32SChris Mason */ 234b52aa8c9SDavid Sterba unsigned prop_compress; /* per-file compression algorithm */ 235eec63c65SDavid Sterba /* 236eec63c65SDavid Sterba * Force compression on the file using the defrag ioctl, could be 237eec63c65SDavid Sterba * different from prop_compress and takes precedence if set 238eec63c65SDavid Sterba */ 239eec63c65SDavid Sterba unsigned defrag_compress; 2401e701a32SChris Mason 24116cdcec7SMiao Xie struct btrfs_delayed_node *delayed_node; 24216cdcec7SMiao Xie 2439cc97d64Schandan r /* File creation time. */ 244d3c6be6fSArnd Bergmann struct timespec64 i_otime; 2459cc97d64Schandan r 2468089fe62SDavid Sterba /* Hook into fs_info->delayed_iputs */ 2478089fe62SDavid Sterba struct list_head delayed_iput; 2488089fe62SDavid Sterba 2498318ba79SJosef Bacik struct rw_semaphore i_mmap_lock; 250d352ac68SChris Mason struct inode vfs_inode; 2512c90e5d6SChris Mason }; 252dbe674a9SChris Mason 2536fee248dSNikolay Borisov static inline u32 btrfs_inode_sectorsize(const struct btrfs_inode *inode) 2546fee248dSNikolay Borisov { 2556fee248dSNikolay Borisov return inode->root->fs_info->sectorsize; 2566fee248dSNikolay Borisov } 2576fee248dSNikolay Borisov 2589a35b637SJeff Mahoney static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) 2592c90e5d6SChris Mason { 2602c90e5d6SChris Mason return container_of(inode, struct btrfs_inode, vfs_inode); 2612c90e5d6SChris Mason } 2622c90e5d6SChris Mason 263778ba82bSFilipe David Borba Manana static inline unsigned long btrfs_inode_hash(u64 objectid, 264778ba82bSFilipe David Borba Manana const struct btrfs_root *root) 265778ba82bSFilipe David Borba Manana { 2664fd786e6SMisono Tomohiro u64 h = objectid ^ (root->root_key.objectid * GOLDEN_RATIO_PRIME); 267778ba82bSFilipe David Borba Manana 268778ba82bSFilipe David Borba Manana #if BITS_PER_LONG == 32 269778ba82bSFilipe David Borba Manana h = (h >> 32) ^ (h & 0xffffffff); 270778ba82bSFilipe David Borba Manana #endif 271778ba82bSFilipe David Borba Manana 272778ba82bSFilipe David Borba Manana return (unsigned long)h; 273778ba82bSFilipe David Borba Manana } 274778ba82bSFilipe David Borba Manana 275778ba82bSFilipe David Borba Manana static inline void btrfs_insert_inode_hash(struct inode *inode) 276778ba82bSFilipe David Borba Manana { 277778ba82bSFilipe David Borba Manana unsigned long h = btrfs_inode_hash(inode->i_ino, BTRFS_I(inode)->root); 278778ba82bSFilipe David Borba Manana 279778ba82bSFilipe David Borba Manana __insert_inode_hash(inode, h); 280778ba82bSFilipe David Borba Manana } 281778ba82bSFilipe David Borba Manana 2829a35b637SJeff Mahoney static inline u64 btrfs_ino(const struct btrfs_inode *inode) 28333345d01SLi Zefan { 2844a0cc7caSNikolay Borisov u64 ino = inode->location.objectid; 28533345d01SLi Zefan 28614c7cca7SLiu Bo /* 28714c7cca7SLiu Bo * !ino: btree_inode 28814c7cca7SLiu Bo * type == BTRFS_ROOT_ITEM_KEY: subvol dir 28914c7cca7SLiu Bo */ 2904a0cc7caSNikolay Borisov if (!ino || inode->location.type == BTRFS_ROOT_ITEM_KEY) 2914a0cc7caSNikolay Borisov ino = inode->vfs_inode.i_ino; 29233345d01SLi Zefan return ino; 29333345d01SLi Zefan } 29433345d01SLi Zefan 2956ef06d27SNikolay Borisov static inline void btrfs_i_size_write(struct btrfs_inode *inode, u64 size) 296dbe674a9SChris Mason { 2976ef06d27SNikolay Borisov i_size_write(&inode->vfs_inode, size); 2986ef06d27SNikolay Borisov inode->disk_i_size = size; 299dbe674a9SChris Mason } 300dbe674a9SChris Mason 30170ddc553SNikolay Borisov static inline bool btrfs_is_free_space_inode(struct btrfs_inode *inode) 3022cf8572dSChris Mason { 30370ddc553SNikolay Borisov struct btrfs_root *root = inode->root; 30483eea1f1SLiu Bo 30551a8cf9dSLiu Bo if (root == root->fs_info->tree_root && 30670ddc553SNikolay Borisov btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) 30751a8cf9dSLiu Bo return true; 30870ddc553SNikolay Borisov if (inode->location.objectid == BTRFS_FREE_INO_OBJECTID) 3092cf8572dSChris Mason return true; 3102cf8572dSChris Mason return false; 3112cf8572dSChris Mason } 3122cf8572dSChris Mason 31306f2548fSNikolay Borisov static inline bool is_data_inode(struct inode *inode) 31406f2548fSNikolay Borisov { 31506f2548fSNikolay Borisov return btrfs_ino(BTRFS_I(inode)) != BTRFS_BTREE_INODE_OBJECTID; 31606f2548fSNikolay Borisov } 31706f2548fSNikolay Borisov 3188b62f87bSJosef Bacik static inline void btrfs_mod_outstanding_extents(struct btrfs_inode *inode, 3198b62f87bSJosef Bacik int mod) 3208b62f87bSJosef Bacik { 3218b62f87bSJosef Bacik lockdep_assert_held(&inode->lock); 3228b62f87bSJosef Bacik inode->outstanding_extents += mod; 3238b62f87bSJosef Bacik if (btrfs_is_free_space_inode(inode)) 3248b62f87bSJosef Bacik return; 325dd48d407SJosef Bacik trace_btrfs_inode_mod_outstanding_extents(inode->root, btrfs_ino(inode), 326dd48d407SJosef Bacik mod); 3278b62f87bSJosef Bacik } 3288b62f87bSJosef Bacik 329bc0939fcSFilipe Manana /* 330bc0939fcSFilipe Manana * Called every time after doing a buffered, direct IO or memory mapped write. 331bc0939fcSFilipe Manana * 332bc0939fcSFilipe Manana * This is to ensure that if we write to a file that was previously fsynced in 333bc0939fcSFilipe Manana * the current transaction, then try to fsync it again in the same transaction, 334bc0939fcSFilipe Manana * we will know that there were changes in the file and that it needs to be 335bc0939fcSFilipe Manana * logged. 336bc0939fcSFilipe Manana */ 337bc0939fcSFilipe Manana static inline void btrfs_set_inode_last_sub_trans(struct btrfs_inode *inode) 338bc0939fcSFilipe Manana { 339bc0939fcSFilipe Manana spin_lock(&inode->lock); 340bc0939fcSFilipe Manana inode->last_sub_trans = inode->root->log_transid; 341bc0939fcSFilipe Manana spin_unlock(&inode->lock); 342bc0939fcSFilipe Manana } 343bc0939fcSFilipe Manana 344209ecbb8SFilipe Manana static inline bool btrfs_inode_in_log(struct btrfs_inode *inode, u64 generation) 34522ee6985SJosef Bacik { 346209ecbb8SFilipe Manana bool ret = false; 3472f2ff0eeSFilipe Manana 3480f8939b8SNikolay Borisov spin_lock(&inode->lock); 3490f8939b8SNikolay Borisov if (inode->logged_trans == generation && 3500f8939b8SNikolay Borisov inode->last_sub_trans <= inode->last_log_commit && 351209ecbb8SFilipe Manana inode->last_sub_trans <= inode->root->last_log_commit) 352209ecbb8SFilipe Manana ret = true; 3530f8939b8SNikolay Borisov spin_unlock(&inode->lock); 3542f2ff0eeSFilipe Manana return ret; 35522ee6985SJosef Bacik } 35622ee6985SJosef Bacik 357facc8a22SMiao Xie struct btrfs_dio_private { 358facc8a22SMiao Xie struct inode *inode; 359facc8a22SMiao Xie u64 logical_offset; 360facc8a22SMiao Xie u64 disk_bytenr; 361523929f1SQu Wenruo /* Used for bio::bi_size */ 362523929f1SQu Wenruo u32 bytes; 363facc8a22SMiao Xie 364e3b318d1SOmar Sandoval /* 365e3b318d1SOmar Sandoval * References to this structure. There is one reference per in-flight 366e3b318d1SOmar Sandoval * bio plus one while we're still setting up. 367e3b318d1SOmar Sandoval */ 368e3b318d1SOmar Sandoval refcount_t refs; 369facc8a22SMiao Xie 370facc8a22SMiao Xie /* dio_bio came from fs/direct-io.c */ 371facc8a22SMiao Xie struct bio *dio_bio; 372c1dc0896SMiao Xie 37385879573SOmar Sandoval /* Array of checksums */ 37485879573SOmar Sandoval u8 csums[]; 375facc8a22SMiao Xie }; 376facc8a22SMiao Xie 37777eea05eSBoris Burkov /* 37877eea05eSBoris Burkov * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two 37977eea05eSBoris Burkov * separate u32s. These two functions convert between the two representations. 38077eea05eSBoris Burkov */ 38177eea05eSBoris Burkov static inline u64 btrfs_inode_combine_flags(u32 flags, u32 ro_flags) 38277eea05eSBoris Burkov { 38377eea05eSBoris Burkov return (flags | ((u64)ro_flags << 32)); 38477eea05eSBoris Burkov } 38577eea05eSBoris Burkov 38677eea05eSBoris Burkov static inline void btrfs_inode_split_flags(u64 inode_item_flags, 38777eea05eSBoris Burkov u32 *flags, u32 *ro_flags) 38877eea05eSBoris Burkov { 38977eea05eSBoris Burkov *flags = (u32)inode_item_flags; 39077eea05eSBoris Burkov *ro_flags = (u32)(inode_item_flags >> 32); 39177eea05eSBoris Burkov } 39277eea05eSBoris Burkov 3937ebc7e5fSJohannes Thumshirn /* Array of bytes with variable length, hexadecimal format 0x1234 */ 3947ebc7e5fSJohannes Thumshirn #define CSUM_FMT "0x%*phN" 3957ebc7e5fSJohannes Thumshirn #define CSUM_FMT_VALUE(size, bytes) size, bytes 3967ebc7e5fSJohannes Thumshirn 3970970a22eSNikolay Borisov static inline void btrfs_print_data_csum_error(struct btrfs_inode *inode, 398ea41d6b2SJohannes Thumshirn u64 logical_start, u8 *csum, u8 *csum_expected, int mirror_num) 3996f6b643eSQu Wenruo { 4000970a22eSNikolay Borisov struct btrfs_root *root = inode->root; 401223486c2SDavid Sterba const u32 csum_size = root->fs_info->csum_size; 4026f6b643eSQu Wenruo 4036f6b643eSQu Wenruo /* Output minus objectid, which is more meaningful */ 4044fd786e6SMisono Tomohiro if (root->root_key.objectid >= BTRFS_LAST_FREE_OBJECTID) 4056f6b643eSQu Wenruo btrfs_warn_rl(root->fs_info, 4067ebc7e5fSJohannes Thumshirn "csum failed root %lld ino %lld off %llu csum " CSUM_FMT " expected csum " CSUM_FMT " mirror %d", 4074fd786e6SMisono Tomohiro root->root_key.objectid, btrfs_ino(inode), 4087ebc7e5fSJohannes Thumshirn logical_start, 409ea41d6b2SJohannes Thumshirn CSUM_FMT_VALUE(csum_size, csum), 410ea41d6b2SJohannes Thumshirn CSUM_FMT_VALUE(csum_size, csum_expected), 4117ebc7e5fSJohannes Thumshirn mirror_num); 4126f6b643eSQu Wenruo else 4136f6b643eSQu Wenruo btrfs_warn_rl(root->fs_info, 4147ebc7e5fSJohannes Thumshirn "csum failed root %llu ino %llu off %llu csum " CSUM_FMT " expected csum " CSUM_FMT " mirror %d", 4154fd786e6SMisono Tomohiro root->root_key.objectid, btrfs_ino(inode), 4167ebc7e5fSJohannes Thumshirn logical_start, 417ea41d6b2SJohannes Thumshirn CSUM_FMT_VALUE(csum_size, csum), 418ea41d6b2SJohannes Thumshirn CSUM_FMT_VALUE(csum_size, csum_expected), 4197ebc7e5fSJohannes Thumshirn mirror_num); 4206f6b643eSQu Wenruo } 4216f6b643eSQu Wenruo 4222c90e5d6SChris Mason #endif 423