Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) International Business Machines Corp., 2000-2004 |
| 3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 7 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * (at your option) any later version. |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 16 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 18 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #ifndef _H_JFS_INCORE |
| 20 | #define _H_JFS_INCORE |
| 21 | |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/rwsem.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/bitops.h> |
Andy Shevchenko | 2e3bc61 | 2019-01-10 15:41:53 +0200 | [diff] [blame] | 26 | #include <linux/uuid.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "jfs_types.h" |
| 29 | #include "jfs_xtree.h" |
| 30 | #include "jfs_dtree.h" |
| 31 | |
| 32 | /* |
| 33 | * JFS magic number |
| 34 | */ |
| 35 | #define JFS_SUPER_MAGIC 0x3153464a /* "JFS1" */ |
| 36 | |
| 37 | /* |
| 38 | * JFS-private inode information |
| 39 | */ |
| 40 | struct jfs_inode_info { |
| 41 | int fileset; /* fileset number (always 16)*/ |
| 42 | uint mode2; /* jfs-specific mode */ |
Eric W. Biederman | c18cdc1 | 2012-02-10 11:40:34 -0800 | [diff] [blame] | 43 | kuid_t saved_uid; /* saved for uid mount option */ |
| 44 | kgid_t saved_gid; /* saved for gid mount option */ |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 45 | pxd_t ixpxd; /* inode extent descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | dxd_t acl; /* dxd describing acl */ |
| 47 | dxd_t ea; /* dxd describing ea */ |
Arnd Bergmann | bd64610 | 2018-06-19 17:51:02 +0200 | [diff] [blame] | 48 | time64_t otime; /* time created */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | uint next_index; /* next available directory entry index */ |
| 50 | int acltype; /* Type of ACL */ |
| 51 | short btorder; /* access order */ |
| 52 | short btindex; /* btpage entry index*/ |
| 53 | struct inode *ipimap; /* inode map */ |
Al Viro | 5ba2533 | 2007-10-14 19:35:50 +0100 | [diff] [blame] | 54 | unsigned long cflag; /* commit flags */ |
Dave Kleikamp | ecc9046 | 2011-06-20 17:53:24 -0500 | [diff] [blame] | 55 | u64 agstart; /* agstart of the containing IAG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | u16 bxflag; /* xflag of pseudo buffer? */ |
Dave Kleikamp | d31b53e | 2011-06-20 10:53:46 -0500 | [diff] [blame] | 57 | unchar pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | signed char active_ag; /* ag currently allocating from */ |
| 59 | lid_t blid; /* lid of pseudo buffer? */ |
| 60 | lid_t atlhead; /* anonymous tlock list head */ |
| 61 | lid_t atltail; /* anonymous tlock list tail */ |
| 62 | spinlock_t ag_lock; /* protects active_ag */ |
| 63 | struct list_head anon_inode_list; /* inodes having anonymous txns */ |
| 64 | /* |
| 65 | * rdwrlock serializes xtree between reads & writes and synchronizes |
| 66 | * changes to special inodes. It's use would be redundant on |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 67 | * directories since the i_mutex taken in the VFS is sufficient. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
| 69 | struct rw_semaphore rdwrlock; |
| 70 | /* |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 71 | * commit_mutex serializes transaction processing on an inode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * It must be taken after beginning a transaction (txBegin), since |
| 73 | * dirty inodes may be committed while a new transaction on the |
| 74 | * inode is blocked in txBegin or TxBeginAnon |
| 75 | */ |
Ingo Molnar | 1de8744 | 2006-01-24 15:22:50 -0600 | [diff] [blame] | 76 | struct mutex commit_mutex; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 77 | /* xattr_sem allows us to access the xattrs without taking i_mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | struct rw_semaphore xattr_sem; |
| 79 | lid_t xtlid; /* lid of xtree lock on directory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | union { |
| 81 | struct { |
| 82 | xtpage_t _xtroot; /* 288: xtree root */ |
| 83 | struct inomap *_imap; /* 4: inode map header */ |
| 84 | } file; |
| 85 | struct { |
| 86 | struct dir_table_slot _table[12]; /* 96: dir index */ |
| 87 | dtroot_t _dtroot; /* 288: dtree root */ |
| 88 | } dir; |
| 89 | struct { |
| 90 | unchar _unused[16]; /* 16: */ |
| 91 | dxd_t _dxd; /* 16: */ |
Kees Cook | 961b33c | 2018-08-03 12:52:58 -0700 | [diff] [blame] | 92 | /* _inline may overflow into _inline_ea when needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | unchar _inline[128]; /* 128: inline symlink */ |
| 94 | /* _inline_ea may overlay the last part of |
| 95 | * file._xtroot if maxentry = XTROOTINITSLOT |
| 96 | */ |
| 97 | unchar _inline_ea[128]; /* 128: inline extended attr */ |
| 98 | } link; |
| 99 | } u; |
Jan Kara | 507e1fa | 2014-10-01 11:19:12 +0200 | [diff] [blame] | 100 | #ifdef CONFIG_QUOTA |
| 101 | struct dquot *i_dquot[MAXQUOTAS]; |
| 102 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | u32 dev; /* will die when we get wide dev_t */ |
| 104 | struct inode vfs_inode; |
| 105 | }; |
| 106 | #define i_xtroot u.file._xtroot |
| 107 | #define i_imap u.file._imap |
| 108 | #define i_dirtable u.dir._table |
| 109 | #define i_dtroot u.dir._dtroot |
| 110 | #define i_inline u.link._inline |
| 111 | #define i_inline_ea u.link._inline_ea |
| 112 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 113 | #define IREAD_LOCK(ip, subclass) \ |
| 114 | down_read_nested(&JFS_IP(ip)->rdwrlock, subclass) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #define IREAD_UNLOCK(ip) up_read(&JFS_IP(ip)->rdwrlock) |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 116 | #define IWRITE_LOCK(ip, subclass) \ |
| 117 | down_write_nested(&JFS_IP(ip)->rdwrlock, subclass) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define IWRITE_UNLOCK(ip) up_write(&JFS_IP(ip)->rdwrlock) |
| 119 | |
| 120 | /* |
| 121 | * cflag |
| 122 | */ |
| 123 | enum cflags { |
| 124 | COMMIT_Nolink, /* inode committed with zero link count */ |
| 125 | COMMIT_Inlineea, /* commit inode inline EA */ |
| 126 | COMMIT_Freewmap, /* free WMAP at iClose() */ |
| 127 | COMMIT_Dirty, /* Inode is really dirty */ |
| 128 | COMMIT_Dirtable, /* commit changes to di_dirtable */ |
| 129 | COMMIT_Stale, /* data extent is no longer valid */ |
| 130 | COMMIT_Synclist, /* metadata pages on group commit synclist */ |
| 131 | }; |
| 132 | |
Dave Kleikamp | 82d5b9a | 2007-01-09 14:14:48 -0600 | [diff] [blame] | 133 | /* |
| 134 | * commit_mutex nesting subclasses: |
| 135 | */ |
| 136 | enum commit_mutex_class |
| 137 | { |
| 138 | COMMIT_MUTEX_PARENT, |
| 139 | COMMIT_MUTEX_CHILD, |
| 140 | COMMIT_MUTEX_SECOND_PARENT, /* Renaming */ |
| 141 | COMMIT_MUTEX_VICTIM /* Inode being unlinked due to rename */ |
| 142 | }; |
| 143 | |
| 144 | /* |
| 145 | * rdwrlock subclasses: |
| 146 | * The dmap inode may be locked while a normal inode or the imap inode are |
| 147 | * locked. |
| 148 | */ |
| 149 | enum rdwrlock_class |
| 150 | { |
| 151 | RDWRLOCK_NORMAL, |
| 152 | RDWRLOCK_IMAP, |
| 153 | RDWRLOCK_DMAP |
| 154 | }; |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | #define set_cflag(flag, ip) set_bit(flag, &(JFS_IP(ip)->cflag)) |
| 157 | #define clear_cflag(flag, ip) clear_bit(flag, &(JFS_IP(ip)->cflag)) |
| 158 | #define test_cflag(flag, ip) test_bit(flag, &(JFS_IP(ip)->cflag)) |
| 159 | #define test_and_clear_cflag(flag, ip) \ |
| 160 | test_and_clear_bit(flag, &(JFS_IP(ip)->cflag)) |
| 161 | /* |
| 162 | * JFS-private superblock information. |
| 163 | */ |
| 164 | struct jfs_sb_info { |
| 165 | struct super_block *sb; /* Point back to vfs super block */ |
| 166 | unsigned long mntflag; /* aggregate attributes */ |
| 167 | struct inode *ipbmap; /* block map inode */ |
| 168 | struct inode *ipaimap; /* aggregate inode map inode */ |
| 169 | struct inode *ipaimap2; /* secondary aimap inode */ |
| 170 | struct inode *ipimap; /* aggregate inode map inode */ |
| 171 | struct jfs_log *log; /* log */ |
| 172 | struct list_head log_list; /* volumes associated with a journal */ |
| 173 | short bsize; /* logical block size */ |
| 174 | short l2bsize; /* log2 logical block size */ |
| 175 | short nbperpage; /* blocks per page */ |
| 176 | short l2nbperpage; /* log2 blocks per page */ |
| 177 | short l2niperblk; /* log2 inodes per page */ |
| 178 | dev_t logdev; /* external log device */ |
| 179 | uint aggregate; /* volume identifier in log record */ |
| 180 | pxd_t logpxd; /* pxd describing log */ |
| 181 | pxd_t fsckpxd; /* pxd describing fsck wkspc */ |
| 182 | pxd_t ait2; /* pxd describing AIT copy */ |
Andy Shevchenko | 2e3bc61 | 2019-01-10 15:41:53 +0200 | [diff] [blame] | 183 | uuid_t uuid; /* 128-bit uuid for volume */ |
| 184 | uuid_t loguuid; /* 128-bit uuid for log */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* |
| 186 | * commit_state is used for synchronization of the jfs_commit |
| 187 | * threads. It is protected by LAZY_LOCK(). |
| 188 | */ |
| 189 | int commit_state; /* commit state */ |
| 190 | /* Formerly in ipimap */ |
| 191 | uint gengen; /* inode generation generator*/ |
| 192 | uint inostamp; /* shows inode belongs to fileset*/ |
| 193 | |
Dave Kleikamp | f720e3b | 2007-06-06 15:28:35 -0500 | [diff] [blame] | 194 | /* Formerly in ipbmap */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | struct bmap *bmap; /* incore bmap descriptor */ |
| 196 | struct nls_table *nls_tab; /* current codepage */ |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 197 | struct inode *direct_inode; /* metadata inode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | uint state; /* mount/recovery state */ |
| 199 | unsigned long flag; /* mount time flags */ |
| 200 | uint p_state; /* state prior to going no integrity */ |
Eric W. Biederman | c18cdc1 | 2012-02-10 11:40:34 -0800 | [diff] [blame] | 201 | kuid_t uid; /* uid to override on-disk uid */ |
| 202 | kgid_t gid; /* gid to override on-disk gid */ |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 203 | uint umask; /* umask to override on-disk umask */ |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 204 | uint minblks_trim; /* minimum blocks, for online trim */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | /* jfs_sb_info commit_state */ |
| 208 | #define IN_LAZYCOMMIT 1 |
| 209 | |
| 210 | static inline struct jfs_inode_info *JFS_IP(struct inode *inode) |
| 211 | { |
Rasmus Villemoes | db6172c | 2015-03-19 12:28:04 +0100 | [diff] [blame] | 212 | return container_of(inode, struct jfs_inode_info, vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static inline int jfs_dirtable_inline(struct inode *inode) |
| 216 | { |
| 217 | return (JFS_IP(inode)->next_index <= (MAX_INLINE_DIRTABLE_ENTRY + 1)); |
| 218 | } |
| 219 | |
| 220 | static inline struct jfs_sb_info *JFS_SBI(struct super_block *sb) |
| 221 | { |
| 222 | return sb->s_fs_info; |
| 223 | } |
| 224 | |
| 225 | static inline int isReadOnly(struct inode *inode) |
| 226 | { |
| 227 | if (JFS_SBI(inode->i_sb)->log) |
| 228 | return 0; |
| 229 | return 1; |
| 230 | } |
| 231 | #endif /* _H_JFS_INCORE */ |