0001
0002
0003
0004
0005
0006 #ifndef __XFS_INODE_H__
0007 #define __XFS_INODE_H__
0008
0009 #include "xfs_inode_buf.h"
0010 #include "xfs_inode_fork.h"
0011
0012
0013
0014
0015 struct xfs_dinode;
0016 struct xfs_inode;
0017 struct xfs_buf;
0018 struct xfs_bmbt_irec;
0019 struct xfs_inode_log_item;
0020 struct xfs_mount;
0021 struct xfs_trans;
0022 struct xfs_dquot;
0023
0024 typedef struct xfs_inode {
0025
0026 struct xfs_mount *i_mount;
0027 struct xfs_dquot *i_udquot;
0028 struct xfs_dquot *i_gdquot;
0029 struct xfs_dquot *i_pdquot;
0030
0031
0032 xfs_ino_t i_ino;
0033 struct xfs_imap i_imap;
0034
0035
0036 struct xfs_ifork *i_cowfp;
0037 struct xfs_ifork i_df;
0038 struct xfs_ifork i_af;
0039
0040
0041 struct xfs_inode_log_item *i_itemp;
0042 mrlock_t i_lock;
0043 atomic_t i_pincount;
0044 struct llist_node i_gclist;
0045
0046
0047
0048
0049
0050 uint16_t i_checked;
0051 uint16_t i_sick;
0052
0053 spinlock_t i_flags_lock;
0054
0055 unsigned long i_flags;
0056 uint64_t i_delayed_blks;
0057 xfs_fsize_t i_disk_size;
0058 xfs_rfsblock_t i_nblocks;
0059 prid_t i_projid;
0060 xfs_extlen_t i_extsize;
0061
0062 union {
0063 xfs_extlen_t i_cowextsize;
0064 uint16_t i_flushiter;
0065 };
0066 uint8_t i_forkoff;
0067 uint16_t i_diflags;
0068 uint64_t i_diflags2;
0069 struct timespec64 i_crtime;
0070
0071
0072 xfs_agino_t i_next_unlinked;
0073 xfs_agino_t i_prev_unlinked;
0074
0075
0076 struct inode i_vnode;
0077
0078
0079 spinlock_t i_ioend_lock;
0080 struct work_struct i_ioend_work;
0081 struct list_head i_ioend_list;
0082 } xfs_inode_t;
0083
0084 static inline bool xfs_inode_has_attr_fork(struct xfs_inode *ip)
0085 {
0086 return ip->i_forkoff > 0;
0087 }
0088
0089 static inline struct xfs_ifork *
0090 xfs_ifork_ptr(
0091 struct xfs_inode *ip,
0092 int whichfork)
0093 {
0094 switch (whichfork) {
0095 case XFS_DATA_FORK:
0096 return &ip->i_df;
0097 case XFS_ATTR_FORK:
0098 if (!xfs_inode_has_attr_fork(ip))
0099 return NULL;
0100 return &ip->i_af;
0101 case XFS_COW_FORK:
0102 return ip->i_cowfp;
0103 default:
0104 ASSERT(0);
0105 return NULL;
0106 }
0107 }
0108
0109 static inline unsigned int xfs_inode_fork_boff(struct xfs_inode *ip)
0110 {
0111 return ip->i_forkoff << 3;
0112 }
0113
0114 static inline unsigned int xfs_inode_data_fork_size(struct xfs_inode *ip)
0115 {
0116 if (xfs_inode_has_attr_fork(ip))
0117 return xfs_inode_fork_boff(ip);
0118
0119 return XFS_LITINO(ip->i_mount);
0120 }
0121
0122 static inline unsigned int xfs_inode_attr_fork_size(struct xfs_inode *ip)
0123 {
0124 if (xfs_inode_has_attr_fork(ip))
0125 return XFS_LITINO(ip->i_mount) - xfs_inode_fork_boff(ip);
0126 return 0;
0127 }
0128
0129 static inline unsigned int
0130 xfs_inode_fork_size(
0131 struct xfs_inode *ip,
0132 int whichfork)
0133 {
0134 switch (whichfork) {
0135 case XFS_DATA_FORK:
0136 return xfs_inode_data_fork_size(ip);
0137 case XFS_ATTR_FORK:
0138 return xfs_inode_attr_fork_size(ip);
0139 default:
0140 return 0;
0141 }
0142 }
0143
0144
0145 static inline struct xfs_inode *XFS_I(struct inode *inode)
0146 {
0147 return container_of(inode, struct xfs_inode, i_vnode);
0148 }
0149
0150
0151 static inline struct inode *VFS_I(struct xfs_inode *ip)
0152 {
0153 return &ip->i_vnode;
0154 }
0155
0156
0157
0158
0159
0160
0161 static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
0162 {
0163 if (S_ISREG(VFS_I(ip)->i_mode))
0164 return i_size_read(VFS_I(ip));
0165 return ip->i_disk_size;
0166 }
0167
0168
0169
0170
0171
0172 static inline xfs_fsize_t
0173 xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
0174 {
0175 xfs_fsize_t i_size = i_size_read(VFS_I(ip));
0176
0177 if (new_size > i_size || new_size < 0)
0178 new_size = i_size;
0179 return new_size > ip->i_disk_size ? new_size : 0;
0180 }
0181
0182
0183
0184
0185 static inline void
0186 __xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
0187 {
0188 ip->i_flags |= flags;
0189 }
0190
0191 static inline void
0192 xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
0193 {
0194 spin_lock(&ip->i_flags_lock);
0195 __xfs_iflags_set(ip, flags);
0196 spin_unlock(&ip->i_flags_lock);
0197 }
0198
0199 static inline void
0200 xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
0201 {
0202 spin_lock(&ip->i_flags_lock);
0203 ip->i_flags &= ~flags;
0204 spin_unlock(&ip->i_flags_lock);
0205 }
0206
0207 static inline int
0208 __xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
0209 {
0210 return (ip->i_flags & flags);
0211 }
0212
0213 static inline int
0214 xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
0215 {
0216 int ret;
0217 spin_lock(&ip->i_flags_lock);
0218 ret = __xfs_iflags_test(ip, flags);
0219 spin_unlock(&ip->i_flags_lock);
0220 return ret;
0221 }
0222
0223 static inline int
0224 xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
0225 {
0226 int ret;
0227
0228 spin_lock(&ip->i_flags_lock);
0229 ret = ip->i_flags & flags;
0230 if (ret)
0231 ip->i_flags &= ~flags;
0232 spin_unlock(&ip->i_flags_lock);
0233 return ret;
0234 }
0235
0236 static inline int
0237 xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
0238 {
0239 int ret;
0240
0241 spin_lock(&ip->i_flags_lock);
0242 ret = ip->i_flags & flags;
0243 if (!ret)
0244 ip->i_flags |= flags;
0245 spin_unlock(&ip->i_flags_lock);
0246 return ret;
0247 }
0248
0249 static inline prid_t
0250 xfs_get_initial_prid(struct xfs_inode *dp)
0251 {
0252 if (dp->i_diflags & XFS_DIFLAG_PROJINHERIT)
0253 return dp->i_projid;
0254
0255 return XFS_PROJID_DEFAULT;
0256 }
0257
0258 static inline bool xfs_is_reflink_inode(struct xfs_inode *ip)
0259 {
0260 return ip->i_diflags2 & XFS_DIFLAG2_REFLINK;
0261 }
0262
0263 static inline bool xfs_is_metadata_inode(struct xfs_inode *ip)
0264 {
0265 struct xfs_mount *mp = ip->i_mount;
0266
0267 return ip == mp->m_rbmip || ip == mp->m_rsumip ||
0268 xfs_is_quota_inode(&mp->m_sb, ip->i_ino);
0269 }
0270
0271
0272
0273
0274
0275 static inline bool xfs_inode_has_cow_data(struct xfs_inode *ip)
0276 {
0277 return ip->i_cowfp && ip->i_cowfp->if_bytes;
0278 }
0279
0280 static inline bool xfs_inode_has_bigtime(struct xfs_inode *ip)
0281 {
0282 return ip->i_diflags2 & XFS_DIFLAG2_BIGTIME;
0283 }
0284
0285 static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)
0286 {
0287 return ip->i_diflags2 & XFS_DIFLAG2_NREXT64;
0288 }
0289
0290
0291
0292
0293 #define xfs_inode_buftarg(ip) \
0294 (XFS_IS_REALTIME_INODE(ip) ? \
0295 (ip)->i_mount->m_rtdev_targp : (ip)->i_mount->m_ddev_targp)
0296
0297
0298
0299
0300 #define XFS_IRECLAIM (1 << 0)
0301 #define XFS_ISTALE (1 << 1)
0302 #define XFS_IRECLAIMABLE (1 << 2)
0303 #define XFS_INEW (1 << 3)
0304 #define XFS_IPRESERVE_DM_FIELDS (1 << 4)
0305 #define XFS_ITRUNCATED (1 << 5)
0306 #define XFS_IDIRTY_RELEASE (1 << 6)
0307 #define XFS_IFLUSHING (1 << 7)
0308 #define __XFS_IPINNED_BIT 8
0309 #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
0310 #define XFS_IEOFBLOCKS (1 << 9)
0311 #define XFS_NEED_INACTIVE (1 << 10)
0312
0313
0314
0315
0316
0317 #define XFS_IRECOVERY (1 << 11)
0318 #define XFS_ICOWBLOCKS (1 << 12)
0319
0320
0321
0322
0323
0324
0325
0326
0327 #define XFS_INACTIVATING (1 << 13)
0328
0329
0330 #define XFS_ALL_IRECLAIM_FLAGS (XFS_IRECLAIMABLE | \
0331 XFS_IRECLAIM | \
0332 XFS_NEED_INACTIVE | \
0333 XFS_INACTIVATING)
0334
0335
0336
0337
0338
0339
0340 #define XFS_IRECLAIM_RESET_FLAGS \
0341 (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
0342 XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | XFS_NEED_INACTIVE | \
0343 XFS_INACTIVATING)
0344
0345
0346
0347
0348
0349
0350 #define XFS_IOLOCK_EXCL (1u << 0)
0351 #define XFS_IOLOCK_SHARED (1u << 1)
0352 #define XFS_ILOCK_EXCL (1u << 2)
0353 #define XFS_ILOCK_SHARED (1u << 3)
0354 #define XFS_MMAPLOCK_EXCL (1u << 4)
0355 #define XFS_MMAPLOCK_SHARED (1u << 5)
0356
0357 #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
0358 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
0359 | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
0360
0361 #define XFS_LOCK_FLAGS \
0362 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
0363 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
0364 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
0365 { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \
0366 { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \
0367 { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420 #define XFS_IOLOCK_SHIFT 16
0421 #define XFS_IOLOCK_MAX_SUBCLASS 3
0422 #define XFS_IOLOCK_DEP_MASK 0x000f0000u
0423
0424 #define XFS_MMAPLOCK_SHIFT 20
0425 #define XFS_MMAPLOCK_NUMORDER 0
0426 #define XFS_MMAPLOCK_MAX_SUBCLASS 3
0427 #define XFS_MMAPLOCK_DEP_MASK 0x00f00000u
0428
0429 #define XFS_ILOCK_SHIFT 24
0430 #define XFS_ILOCK_PARENT_VAL 5u
0431 #define XFS_ILOCK_MAX_SUBCLASS (XFS_ILOCK_PARENT_VAL - 1)
0432 #define XFS_ILOCK_RTBITMAP_VAL 6u
0433 #define XFS_ILOCK_RTSUM_VAL 7u
0434 #define XFS_ILOCK_DEP_MASK 0xff000000u
0435 #define XFS_ILOCK_PARENT (XFS_ILOCK_PARENT_VAL << XFS_ILOCK_SHIFT)
0436 #define XFS_ILOCK_RTBITMAP (XFS_ILOCK_RTBITMAP_VAL << XFS_ILOCK_SHIFT)
0437 #define XFS_ILOCK_RTSUM (XFS_ILOCK_RTSUM_VAL << XFS_ILOCK_SHIFT)
0438
0439 #define XFS_LOCK_SUBCLASS_MASK (XFS_IOLOCK_DEP_MASK | \
0440 XFS_MMAPLOCK_DEP_MASK | \
0441 XFS_ILOCK_DEP_MASK)
0442
0443 #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) \
0444 >> XFS_IOLOCK_SHIFT)
0445 #define XFS_MMAPLOCK_DEP(flags) (((flags) & XFS_MMAPLOCK_DEP_MASK) \
0446 >> XFS_MMAPLOCK_SHIFT)
0447 #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) \
0448 >> XFS_ILOCK_SHIFT)
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459 enum layout_break_reason {
0460 BREAK_WRITE,
0461 BREAK_UNMAP,
0462 };
0463
0464
0465
0466
0467
0468
0469 #define XFS_INHERIT_GID(pip) \
0470 (xfs_has_grpid((pip)->i_mount) || (VFS_I(pip)->i_mode & S_ISGID))
0471
0472 int xfs_release(struct xfs_inode *ip);
0473 void xfs_inactive(struct xfs_inode *ip);
0474 int xfs_lookup(struct xfs_inode *dp, const struct xfs_name *name,
0475 struct xfs_inode **ipp, struct xfs_name *ci_name);
0476 int xfs_create(struct user_namespace *mnt_userns,
0477 struct xfs_inode *dp, struct xfs_name *name,
0478 umode_t mode, dev_t rdev, bool need_xattr,
0479 struct xfs_inode **ipp);
0480 int xfs_create_tmpfile(struct user_namespace *mnt_userns,
0481 struct xfs_inode *dp, umode_t mode,
0482 struct xfs_inode **ipp);
0483 int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
0484 struct xfs_inode *ip);
0485 int xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
0486 struct xfs_name *target_name);
0487 int xfs_rename(struct user_namespace *mnt_userns,
0488 struct xfs_inode *src_dp, struct xfs_name *src_name,
0489 struct xfs_inode *src_ip, struct xfs_inode *target_dp,
0490 struct xfs_name *target_name,
0491 struct xfs_inode *target_ip, unsigned int flags);
0492
0493 void xfs_ilock(xfs_inode_t *, uint);
0494 int xfs_ilock_nowait(xfs_inode_t *, uint);
0495 void xfs_iunlock(xfs_inode_t *, uint);
0496 void xfs_ilock_demote(xfs_inode_t *, uint);
0497 bool xfs_isilocked(struct xfs_inode *, uint);
0498 uint xfs_ilock_data_map_shared(struct xfs_inode *);
0499 uint xfs_ilock_attr_map_shared(struct xfs_inode *);
0500
0501 uint xfs_ip2xflags(struct xfs_inode *);
0502 int xfs_ifree(struct xfs_trans *, struct xfs_inode *);
0503 int xfs_itruncate_extents_flags(struct xfs_trans **,
0504 struct xfs_inode *, int, xfs_fsize_t, int);
0505 void xfs_iext_realloc(xfs_inode_t *, int, int);
0506
0507 int xfs_log_force_inode(struct xfs_inode *ip);
0508 void xfs_iunpin_wait(xfs_inode_t *);
0509 #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
0510
0511 int xfs_iflush_cluster(struct xfs_buf *);
0512 void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,
0513 struct xfs_inode *ip1, uint ip1_mode);
0514
0515 xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
0516 xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip);
0517
0518 int xfs_init_new_inode(struct user_namespace *mnt_userns, struct xfs_trans *tp,
0519 struct xfs_inode *pip, xfs_ino_t ino, umode_t mode,
0520 xfs_nlink_t nlink, dev_t rdev, prid_t prid, bool init_xattrs,
0521 struct xfs_inode **ipp);
0522
0523 static inline int
0524 xfs_itruncate_extents(
0525 struct xfs_trans **tpp,
0526 struct xfs_inode *ip,
0527 int whichfork,
0528 xfs_fsize_t new_size)
0529 {
0530 return xfs_itruncate_extents_flags(tpp, ip, whichfork, new_size, 0);
0531 }
0532
0533
0534 int xfs_break_dax_layouts(struct inode *inode, bool *retry);
0535 int xfs_break_layouts(struct inode *inode, uint *iolock,
0536 enum layout_break_reason reason);
0537
0538
0539 extern void xfs_setup_inode(struct xfs_inode *ip);
0540 extern void xfs_setup_iops(struct xfs_inode *ip);
0541 extern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init);
0542
0543
0544
0545
0546
0547
0548
0549
0550 static inline void xfs_finish_inode_setup(struct xfs_inode *ip)
0551 {
0552 xfs_iflags_clear(ip, XFS_INEW);
0553 barrier();
0554 unlock_new_inode(VFS_I(ip));
0555 }
0556
0557 static inline void xfs_setup_existing_inode(struct xfs_inode *ip)
0558 {
0559 xfs_setup_inode(ip);
0560 xfs_setup_iops(ip);
0561 xfs_finish_inode_setup(ip);
0562 }
0563
0564 void xfs_irele(struct xfs_inode *ip);
0565
0566 extern struct kmem_cache *xfs_inode_cache;
0567
0568
0569 #define XFS_DEFAULT_COWEXTSZ_HINT 32
0570
0571 bool xfs_inode_needs_inactive(struct xfs_inode *ip);
0572
0573 void xfs_end_io(struct work_struct *work);
0574
0575 int xfs_ilock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
0576 void xfs_iunlock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
0577
0578 #endif