1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
5 #if !defined( __REISER4_INODE_H__ )
6 #define __REISER4_INODE_H__
12 #include "plugin/plugin.h"
13 #include "plugin/file/cryptcompress.h"
14 #include "plugin/file/file.h"
15 #include "plugin/dir/dir.h"
16 #include "plugin/plugin_set.h"
17 #include "plugin/security/perm.h"
22 #include <linux/types.h> /* for __u?? , ino_t */
23 #include <linux/fs.h> /* for struct super_block, struct
24 * rw_semaphore, etc */
25 #include <linux/spinlock.h>
26 #include <asm/types.h>
28 /* reiser4-specific inode flags. They are "transient" and are not
29 supposed to be stored on disk. Used to trace "state" of
33 /* this is light-weight inode, inheriting some state from its
35 REISER4_LIGHT_WEIGHT
= 0,
36 /* stat data wasn't yet created */
38 /* internal immutable flag. Currently is only used
39 to avoid race condition during file creation.
40 See comment in create_object(). */
41 REISER4_IMMUTABLE
= 2,
42 /* inode was read from storage */
44 /* this bit is set for symlinks. inode->i_private points to target
46 REISER4_GENERIC_PTR_USED
= 4,
47 /* set if size of stat-data item for this inode is known. If this is
48 * set we can avoid recalculating size of stat-data on each update. */
49 REISER4_SDLEN_KNOWN
= 5,
50 /* reiser4_inode->crypt points to the crypto stat */
51 REISER4_CRYPTO_STAT_LOADED
= 6,
52 /* cryptcompress_inode_data points to the secret key */
53 REISER4_SECRET_KEY_INSTALLED
= 7,
54 /* File (possibly) has pages corresponding to the tail items, that
55 * were created by ->readpage. It is set by mmap_unix_file() and
56 * sendfile_unix_file(). This bit is inspected by write_unix_file and
57 * kill-hook of tail items. It is never cleared once set. This bit is
58 * modified and inspected under i_mutex. */
60 REISER4_PART_MIXED
= 9,
61 REISER4_PART_IN_CONV
= 10,
62 /* This flag indicates that file plugin conversion is in progress */
63 REISER4_FILE_CONV_IN_PROGRESS
= 11
64 } reiser4_file_plugin_flags
;
66 /* state associated with each inode.
69 NOTE-NIKITA In 2.5 kernels it is not necessary that all file-system inodes
70 be of the same size. File-system allocates inodes by itself through
71 s_op->allocate_inode() method. So, it is possible to adjust size of inode
72 at the time of its creation.
74 Invariants involving parts of this data-type:
80 typedef struct reiser4_inode reiser4_inode
;
81 /* return pointer to reiser4-specific part of inode */
82 static inline reiser4_inode
*reiser4_inode_data(const struct inode
*inode
83 /* inode queried */ );
85 #if BITS_PER_LONG == 64
87 #define REISER4_INO_IS_OID (1)
91 /* BITS_PER_LONG == 64 */
94 #define REISER4_INO_IS_OID (0)
95 typedef __u32 oid_hi_t
;
97 /* BITS_PER_LONG == 64 */
100 struct reiser4_inode
{
101 /* spin lock protecting fields of this structure. */
103 /* main plugin set that control the file
104 (see comments in plugin/plugin_set.c) */
106 /* plugin set for inheritance
107 (see comments in plugin/plugin_set.c) */
109 /* high 32 bits of object id */
111 /* seal for stat-data */
113 /* locality id for this file */
115 #if REISER4_LARGE_KEY
118 /* coord of stat-data in sealed node */
120 /* bit-mask of stat-data extentions used by this file */
122 /* bitmask of non-default plugins for this inode */
124 /* bitmask of set heir plugins for this inode. */
127 struct list_head readdir_list
;
128 struct list_head not_used
;
130 /* per-inode flags. Filled by values of reiser4_file_plugin_flags */
133 /* fields specific to unix_file plugin */
134 struct unix_file_info unix_file_info
;
135 /* fields specific to cryptcompress file plugin */
136 struct cryptcompress_info cryptcompress_info
;
139 /* this semaphore is to serialize readers and writers of @pset->file
140 * when file plugin conversion is enabled
142 struct rw_semaphore conv_sem
;
144 /* tree of jnodes. Phantom jnodes (ones not attched to any atom) are
145 tagged in that tree by EFLUSH_TAG_ANONYMOUS */
146 struct radix_tree_root jnodes_tree
;
148 /* number of unformatted node jnodes of this file in jnode hash table */
149 unsigned long nr_jnodes
;
152 /* block number of virtual root for this object. See comment above
153 * fs/reiser4/search.c:handle_vroot() */
154 reiser4_block_nr vroot
;
155 struct mutex loading
;
158 void loading_init_once(reiser4_inode
*);
159 void loading_alloc(reiser4_inode
*);
160 void loading_destroy(reiser4_inode
*);
162 struct reiser4_inode_object
{
165 /* generic fields not specific to reiser4, but used by VFS */
166 struct inode vfs_inode
;
169 /* return pointer to the reiser4 specific portion of @inode */
170 static inline reiser4_inode
*reiser4_inode_data(const struct inode
*inode
171 /* inode queried */ )
173 assert("nikita-254", inode
!= NULL
);
174 return &container_of(inode
, struct reiser4_inode_object
, vfs_inode
)->p
;
177 static inline struct inode
*inode_by_reiser4_inode(const reiser4_inode
*
178 r4_inode
/* inode queried */
181 return &container_of(r4_inode
, struct reiser4_inode_object
, p
)->vfs_inode
;
185 * reiser4 inodes are identified by 64bit object-id (oid_t), but in struct
186 * inode ->i_ino field is of type ino_t (long) that can be either 32 or 64
189 * If ->i_ino is 32 bits we store remaining 32 bits in reiser4 specific part
190 * of inode, otherwise whole oid is stored in i_ino.
192 * Wrappers below ([sg]et_inode_oid()) are used to hide this difference.
195 #define OID_HI_SHIFT (sizeof(ino_t) * 8)
197 #if REISER4_INO_IS_OID
199 static inline oid_t
get_inode_oid(const struct inode
*inode
)
204 static inline void set_inode_oid(struct inode
*inode
, oid_t oid
)
209 /* REISER4_INO_IS_OID */
212 static inline oid_t
get_inode_oid(const struct inode
*inode
)
215 ((__u64
) reiser4_inode_data(inode
)->oid_hi
<< OID_HI_SHIFT
) |
219 static inline void set_inode_oid(struct inode
*inode
, oid_t oid
)
221 assert("nikita-2519", inode
!= NULL
);
222 inode
->i_ino
= (ino_t
) (oid
);
223 reiser4_inode_data(inode
)->oid_hi
= (oid
) >> OID_HI_SHIFT
;
224 assert("nikita-2521", get_inode_oid(inode
) == (oid
));
227 /* REISER4_INO_IS_OID */
230 static inline oid_t
get_inode_locality(const struct inode
*inode
)
232 return reiser4_inode_data(inode
)->locality_id
;
235 #if REISER4_LARGE_KEY
236 static inline __u64
get_inode_ordering(const struct inode
*inode
)
238 return reiser4_inode_data(inode
)->ordering
;
241 static inline void set_inode_ordering(const struct inode
*inode
, __u64 ordering
)
243 reiser4_inode_data(inode
)->ordering
= ordering
;
248 #define get_inode_ordering(inode) (0)
249 #define set_inode_ordering(inode, val) noop
253 /* return inode in which @uf_info is embedded */
254 static inline struct inode
*
255 unix_file_info_to_inode(const struct unix_file_info
* uf_info
)
257 return &container_of(uf_info
, struct reiser4_inode_object
,
258 p
.file_plugin_data
.unix_file_info
)->vfs_inode
;
261 extern ino_t
oid_to_ino(oid_t oid
) __attribute__ ((const));
262 extern ino_t
oid_to_uino(oid_t oid
) __attribute__ ((const));
264 extern reiser4_tree
*reiser4_tree_by_inode(const struct inode
*inode
);
267 extern void reiser4_inode_invariant(const struct inode
*inode
);
268 extern int inode_has_no_jnodes(reiser4_inode
*);
270 #define reiser4_inode_invariant(inode) noop
273 static inline int spin_inode_is_locked(const struct inode
*inode
)
275 assert_spin_locked(&reiser4_inode_data(inode
)->guard
);
280 * spin_lock_inode - lock reiser4_inode' embedded spinlock
281 * @inode: inode to lock
283 * In debug mode it checks that lower priority locks are not held and
284 * increments reiser4_context's lock counters on which lock ordering checking
287 static inline void spin_lock_inode(struct inode
*inode
)
289 assert("", LOCK_CNT_NIL(spin_locked
));
290 /* check lock ordering */
291 assert_spin_not_locked(&d_lock
);
293 spin_lock(&reiser4_inode_data(inode
)->guard
);
295 LOCK_CNT_INC(spin_locked_inode
);
296 LOCK_CNT_INC(spin_locked
);
298 reiser4_inode_invariant(inode
);
302 * spin_unlock_inode - unlock reiser4_inode' embedded spinlock
303 * @inode: inode to unlock
305 * In debug mode it checks that spinlock is held and decrements
306 * reiser4_context's lock counters on which lock ordering checking is based.
308 static inline void spin_unlock_inode(struct inode
*inode
)
310 assert_spin_locked(&reiser4_inode_data(inode
)->guard
);
311 assert("nikita-1375", LOCK_CNT_GTZ(spin_locked_inode
));
312 assert("nikita-1376", LOCK_CNT_GTZ(spin_locked
));
314 reiser4_inode_invariant(inode
);
316 LOCK_CNT_DEC(spin_locked_inode
);
317 LOCK_CNT_DEC(spin_locked
);
319 spin_unlock(&reiser4_inode_data(inode
)->guard
);
322 extern znode
*inode_get_vroot(struct inode
*inode
);
323 extern void inode_set_vroot(struct inode
*inode
, znode
* vroot
);
325 extern int reiser4_max_filename_len(const struct inode
*inode
);
326 extern int max_hash_collisions(const struct inode
*dir
);
327 extern void reiser4_unlock_inode(struct inode
*inode
);
328 extern int is_reiser4_inode(const struct inode
*inode
);
329 extern int setup_inode_ops(struct inode
*inode
, reiser4_object_create_data
*);
330 extern struct inode
*reiser4_iget(struct super_block
*super
,
331 const reiser4_key
* key
, int silent
);
332 extern void reiser4_iget_complete(struct inode
*inode
);
333 extern void reiser4_inode_set_flag(struct inode
*inode
, reiser4_file_plugin_flags f
);
334 extern void reiser4_inode_clr_flag(struct inode
*inode
, reiser4_file_plugin_flags f
);
335 extern int reiser4_inode_get_flag(const struct inode
*inode
,
336 reiser4_file_plugin_flags f
);
338 /* has inode been initialized? */
340 is_inode_loaded(const struct inode
*inode
/* inode queried */ )
342 assert("nikita-1120", inode
!= NULL
);
343 return reiser4_inode_get_flag(inode
, REISER4_LOADED
);
346 extern file_plugin
*inode_file_plugin(const struct inode
*inode
);
347 extern dir_plugin
*inode_dir_plugin(const struct inode
*inode
);
348 extern formatting_plugin
*inode_formatting_plugin(const struct inode
*inode
);
349 extern hash_plugin
*inode_hash_plugin(const struct inode
*inode
);
350 extern fibration_plugin
*inode_fibration_plugin(const struct inode
*inode
);
351 extern cipher_plugin
*inode_cipher_plugin(const struct inode
*inode
);
352 extern digest_plugin
*inode_digest_plugin(const struct inode
*inode
);
353 extern compression_plugin
*inode_compression_plugin(const struct inode
*inode
);
354 extern compression_mode_plugin
*inode_compression_mode_plugin(const struct inode
356 extern cluster_plugin
*inode_cluster_plugin(const struct inode
*inode
);
357 extern file_plugin
*inode_create_plugin(const struct inode
*inode
);
358 extern item_plugin
*inode_sd_plugin(const struct inode
*inode
);
359 extern item_plugin
*inode_dir_item_plugin(const struct inode
*inode
);
360 extern file_plugin
*child_create_plugin(const struct inode
*inode
);
362 extern void reiser4_make_bad_inode(struct inode
*inode
);
364 extern void inode_set_extension(struct inode
*inode
, sd_ext_bits ext
);
365 extern void inode_clr_extension(struct inode
*inode
, sd_ext_bits ext
);
366 extern void inode_check_scale(struct inode
*inode
, __u64 old
, __u64
new);
367 extern void inode_check_scale_nolock(struct inode
* inode
, __u64 old
, __u64
new);
369 #define INODE_SET_SIZE(i, value) \
376 inode_check_scale(__i, __i->i_size, __v); \
377 i_size_write(__i, __v); \
381 * update field @field in inode @i to contain value @value.
383 #define INODE_SET_FIELD(i, field, value) \
390 inode_check_scale(__i, __i->field, __v); \
394 #define INODE_INC_FIELD(i, field) \
399 inode_check_scale(__i, __i->field, __i->field + 1); \
403 #define INODE_DEC_FIELD(i, field) \
408 inode_check_scale(__i, __i->field, __i->field - 1); \
412 /* See comment before reiser4_readdir_common() for description. */
413 static inline struct list_head
*get_readdir_list(const struct inode
*inode
)
415 return &reiser4_inode_data(inode
)->lists
.readdir_list
;
418 extern void init_inode_ordering(struct inode
*inode
,
419 reiser4_object_create_data
* crd
, int create
);
421 static inline struct radix_tree_root
*jnode_tree_by_inode(struct inode
*inode
)
423 return &reiser4_inode_data(inode
)->jnodes_tree
;
426 static inline struct radix_tree_root
*jnode_tree_by_reiser4_inode(reiser4_inode
429 return &r4_inode
->jnodes_tree
;
433 extern void print_inode(const char *prefix
, const struct inode
*i
);
436 int is_dir_empty(const struct inode
*);
438 /* __REISER4_INODE_H__ */
443 c-indentation-style: "K&R"