blob: a466ec41cfbb9cd1394b5196646b9a072a40cc95 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) International Business Machines Corp., 2000-2004
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
Dave Kleikamp63f83c92006-10-02 09:55:27 -05005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#ifndef _H_JFS_INCORE
7#define _H_JFS_INCORE
8
Ingo Molnar1de87442006-01-24 15:22:50 -06009#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/rwsem.h>
11#include <linux/slab.h>
12#include <linux/bitops.h>
Andy Shevchenko2e3bc612019-01-10 15:41:53 +020013#include <linux/uuid.h>
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "jfs_types.h"
16#include "jfs_xtree.h"
17#include "jfs_dtree.h"
18
19/*
20 * JFS magic number
21 */
22#define JFS_SUPER_MAGIC 0x3153464a /* "JFS1" */
23
24/*
25 * JFS-private inode information
26 */
27struct jfs_inode_info {
28 int fileset; /* fileset number (always 16)*/
29 uint mode2; /* jfs-specific mode */
Eric W. Biedermanc18cdc12012-02-10 11:40:34 -080030 kuid_t saved_uid; /* saved for uid mount option */
31 kgid_t saved_gid; /* saved for gid mount option */
Dave Kleikampf720e3b2007-06-06 15:28:35 -050032 pxd_t ixpxd; /* inode extent descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 dxd_t acl; /* dxd describing acl */
34 dxd_t ea; /* dxd describing ea */
Arnd Bergmannbd646102018-06-19 17:51:02 +020035 time64_t otime; /* time created */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 uint next_index; /* next available directory entry index */
37 int acltype; /* Type of ACL */
38 short btorder; /* access order */
39 short btindex; /* btpage entry index*/
40 struct inode *ipimap; /* inode map */
Al Viro5ba25332007-10-14 19:35:50 +010041 unsigned long cflag; /* commit flags */
Dave Kleikampecc90462011-06-20 17:53:24 -050042 u64 agstart; /* agstart of the containing IAG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 u16 bxflag; /* xflag of pseudo buffer? */
Dave Kleikampd31b53e2011-06-20 10:53:46 -050044 unchar pad;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 signed char active_ag; /* ag currently allocating from */
46 lid_t blid; /* lid of pseudo buffer? */
47 lid_t atlhead; /* anonymous tlock list head */
48 lid_t atltail; /* anonymous tlock list tail */
49 spinlock_t ag_lock; /* protects active_ag */
50 struct list_head anon_inode_list; /* inodes having anonymous txns */
51 /*
52 * rdwrlock serializes xtree between reads & writes and synchronizes
53 * changes to special inodes. It's use would be redundant on
Jes Sorensen1b1dcc12006-01-09 15:59:24 -080054 * directories since the i_mutex taken in the VFS is sufficient.
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 */
56 struct rw_semaphore rdwrlock;
57 /*
Ingo Molnar1de87442006-01-24 15:22:50 -060058 * commit_mutex serializes transaction processing on an inode.
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 * It must be taken after beginning a transaction (txBegin), since
60 * dirty inodes may be committed while a new transaction on the
61 * inode is blocked in txBegin or TxBeginAnon
62 */
Ingo Molnar1de87442006-01-24 15:22:50 -060063 struct mutex commit_mutex;
Jes Sorensen1b1dcc12006-01-09 15:59:24 -080064 /* xattr_sem allows us to access the xattrs without taking i_mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 struct rw_semaphore xattr_sem;
66 lid_t xtlid; /* lid of xtree lock on directory */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 union {
68 struct {
69 xtpage_t _xtroot; /* 288: xtree root */
70 struct inomap *_imap; /* 4: inode map header */
71 } file;
72 struct {
73 struct dir_table_slot _table[12]; /* 96: dir index */
74 dtroot_t _dtroot; /* 288: dtree root */
75 } dir;
76 struct {
77 unchar _unused[16]; /* 16: */
78 dxd_t _dxd; /* 16: */
Kees Cook961b33c2018-08-03 12:52:58 -070079 /* _inline may overflow into _inline_ea when needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unchar _inline[128]; /* 128: inline symlink */
81 /* _inline_ea may overlay the last part of
82 * file._xtroot if maxentry = XTROOTINITSLOT
83 */
84 unchar _inline_ea[128]; /* 128: inline extended attr */
85 } link;
86 } u;
Jan Kara507e1fa2014-10-01 11:19:12 +020087#ifdef CONFIG_QUOTA
88 struct dquot *i_dquot[MAXQUOTAS];
89#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 u32 dev; /* will die when we get wide dev_t */
91 struct inode vfs_inode;
92};
93#define i_xtroot u.file._xtroot
94#define i_imap u.file._imap
95#define i_dirtable u.dir._table
96#define i_dtroot u.dir._dtroot
97#define i_inline u.link._inline
98#define i_inline_ea u.link._inline_ea
99
Dave Kleikamp82d5b9a2007-01-09 14:14:48 -0600100#define IREAD_LOCK(ip, subclass) \
101 down_read_nested(&JFS_IP(ip)->rdwrlock, subclass)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define IREAD_UNLOCK(ip) up_read(&JFS_IP(ip)->rdwrlock)
Dave Kleikamp82d5b9a2007-01-09 14:14:48 -0600103#define IWRITE_LOCK(ip, subclass) \
104 down_write_nested(&JFS_IP(ip)->rdwrlock, subclass)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define IWRITE_UNLOCK(ip) up_write(&JFS_IP(ip)->rdwrlock)
106
107/*
108 * cflag
109 */
110enum cflags {
111 COMMIT_Nolink, /* inode committed with zero link count */
112 COMMIT_Inlineea, /* commit inode inline EA */
113 COMMIT_Freewmap, /* free WMAP at iClose() */
114 COMMIT_Dirty, /* Inode is really dirty */
115 COMMIT_Dirtable, /* commit changes to di_dirtable */
116 COMMIT_Stale, /* data extent is no longer valid */
117 COMMIT_Synclist, /* metadata pages on group commit synclist */
118};
119
Dave Kleikamp82d5b9a2007-01-09 14:14:48 -0600120/*
121 * commit_mutex nesting subclasses:
122 */
123enum commit_mutex_class
124{
125 COMMIT_MUTEX_PARENT,
126 COMMIT_MUTEX_CHILD,
127 COMMIT_MUTEX_SECOND_PARENT, /* Renaming */
128 COMMIT_MUTEX_VICTIM /* Inode being unlinked due to rename */
129};
130
131/*
132 * rdwrlock subclasses:
133 * The dmap inode may be locked while a normal inode or the imap inode are
134 * locked.
135 */
136enum rdwrlock_class
137{
138 RDWRLOCK_NORMAL,
139 RDWRLOCK_IMAP,
140 RDWRLOCK_DMAP
141};
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#define set_cflag(flag, ip) set_bit(flag, &(JFS_IP(ip)->cflag))
144#define clear_cflag(flag, ip) clear_bit(flag, &(JFS_IP(ip)->cflag))
145#define test_cflag(flag, ip) test_bit(flag, &(JFS_IP(ip)->cflag))
146#define test_and_clear_cflag(flag, ip) \
147 test_and_clear_bit(flag, &(JFS_IP(ip)->cflag))
148/*
149 * JFS-private superblock information.
150 */
151struct jfs_sb_info {
152 struct super_block *sb; /* Point back to vfs super block */
153 unsigned long mntflag; /* aggregate attributes */
154 struct inode *ipbmap; /* block map inode */
155 struct inode *ipaimap; /* aggregate inode map inode */
156 struct inode *ipaimap2; /* secondary aimap inode */
157 struct inode *ipimap; /* aggregate inode map inode */
158 struct jfs_log *log; /* log */
159 struct list_head log_list; /* volumes associated with a journal */
160 short bsize; /* logical block size */
161 short l2bsize; /* log2 logical block size */
162 short nbperpage; /* blocks per page */
163 short l2nbperpage; /* log2 blocks per page */
164 short l2niperblk; /* log2 inodes per page */
165 dev_t logdev; /* external log device */
166 uint aggregate; /* volume identifier in log record */
167 pxd_t logpxd; /* pxd describing log */
168 pxd_t fsckpxd; /* pxd describing fsck wkspc */
169 pxd_t ait2; /* pxd describing AIT copy */
Andy Shevchenko2e3bc612019-01-10 15:41:53 +0200170 uuid_t uuid; /* 128-bit uuid for volume */
171 uuid_t loguuid; /* 128-bit uuid for log */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /*
173 * commit_state is used for synchronization of the jfs_commit
174 * threads. It is protected by LAZY_LOCK().
175 */
176 int commit_state; /* commit state */
177 /* Formerly in ipimap */
178 uint gengen; /* inode generation generator*/
179 uint inostamp; /* shows inode belongs to fileset*/
180
Dave Kleikampf720e3b2007-06-06 15:28:35 -0500181 /* Formerly in ipbmap */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 struct bmap *bmap; /* incore bmap descriptor */
183 struct nls_table *nls_tab; /* current codepage */
Dave Kleikamp7fab4792005-05-02 12:25:02 -0600184 struct inode *direct_inode; /* metadata inode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 uint state; /* mount/recovery state */
186 unsigned long flag; /* mount time flags */
187 uint p_state; /* state prior to going no integrity */
Eric W. Biedermanc18cdc12012-02-10 11:40:34 -0800188 kuid_t uid; /* uid to override on-disk uid */
189 kgid_t gid; /* gid to override on-disk gid */
Dave Kleikamp69eb66d2006-03-09 13:59:30 -0600190 uint umask; /* umask to override on-disk umask */
Tino Reichardtb40c2e62012-09-17 11:58:19 -0500191 uint minblks_trim; /* minimum blocks, for online trim */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
194/* jfs_sb_info commit_state */
195#define IN_LAZYCOMMIT 1
196
197static inline struct jfs_inode_info *JFS_IP(struct inode *inode)
198{
Rasmus Villemoesdb6172c2015-03-19 12:28:04 +0100199 return container_of(inode, struct jfs_inode_info, vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
202static inline int jfs_dirtable_inline(struct inode *inode)
203{
204 return (JFS_IP(inode)->next_index <= (MAX_INLINE_DIRTABLE_ENTRY + 1));
205}
206
207static inline struct jfs_sb_info *JFS_SBI(struct super_block *sb)
208{
209 return sb->s_fs_info;
210}
211
212static inline int isReadOnly(struct inode *inode)
213{
214 if (JFS_SBI(inode->i_sb)->log)
215 return 0;
216 return 1;
217}
218#endif /* _H_JFS_INCORE */