1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
6 #if !defined(__REISER4_INODE_H__)
7 #define __REISER4_INODE_H__
13 #include "plugin/plugin.h"
14 #include "plugin/file/cryptcompress.h"
15 #include "plugin/file/file.h"
16 #include "plugin/dir/dir.h"
17 #include "plugin/plugin_set.h"
18 #include "plugin/security/perm.h"
23 #include <linux/types.h> /* for __u?? , ino_t */
24 #include <linux/fs.h> /* for struct super_block, struct
25 * rw_semaphore, etc */
26 #include <linux/spinlock.h>
27 #include <asm/types.h>
29 /* reiser4-specific inode flags. They are "transient" and are not
30 supposed to be stored on disk. Used to trace "state" of
34 /* this is light-weight inode, inheriting some state from its
36 REISER4_LIGHT_WEIGHT
= 0,
37 /* stat data wasn't yet created */
39 /* internal immutable flag. Currently is only used
40 to avoid race condition during file creation.
41 See comment in create_object(). */
42 REISER4_IMMUTABLE
= 2,
43 /* inode was read from storage */
45 /* this bit is set for symlinks. inode->i_private points to target
47 REISER4_GENERIC_PTR_USED
= 4,
48 /* set if size of stat-data item for this inode is known. If this is
49 * set we can avoid recalculating size of stat-data on each update. */
50 REISER4_SDLEN_KNOWN
= 5,
51 /* reiser4_inode->crypt points to the crypto stat */
52 REISER4_CRYPTO_STAT_LOADED
= 6,
53 /* cryptcompress_inode_data points to the secret key */
54 REISER4_SECRET_KEY_INSTALLED
= 7,
55 /* File (possibly) has pages corresponding to the tail items, that
56 * were created by ->readpage. It is set by mmap_unix_file() and
57 * sendfile_unix_file(). This bit is inspected by write_unix_file and
58 * kill-hook of tail items. It is never cleared once set. This bit is
59 * modified and inspected under i_mutex. */
61 REISER4_PART_MIXED
= 9,
62 REISER4_PART_IN_CONV
= 10,
63 /* This flag indicates that file plugin conversion is in progress */
64 REISER4_FILE_CONV_IN_PROGRESS
= 11
65 } reiser4_file_plugin_flags
;
67 /* state associated with each inode.
70 NOTE-NIKITA In 2.5 kernels it is not necessary that all file-system inodes
71 be of the same size. File-system allocates inodes by itself through
72 s_op->allocate_inode() method. So, it is possible to adjust size of inode
73 at the time of its creation.
75 Invariants involving parts of this data-type:
81 typedef struct reiser4_inode reiser4_inode
;
82 /* return pointer to reiser4-specific part of inode */
83 static inline reiser4_inode
*reiser4_inode_data(const struct inode
*inode
84 /* inode queried */ );
86 #if BITS_PER_LONG == 64
88 #define REISER4_INO_IS_OID (1)
92 /* BITS_PER_LONG == 64 */
95 #define REISER4_INO_IS_OID (0)
96 typedef __u32 oid_hi_t
;
98 /* BITS_PER_LONG == 64 */
101 struct reiser4_inode
{
102 /* spin lock protecting fields of this structure. */
104 /* main plugin set that control the file
105 (see comments in plugin/plugin_set.c) */
107 /* plugin set for inheritance
108 (see comments in plugin/plugin_set.c) */
110 /* high 32 bits of object id */
112 /* seal for stat-data */
114 /* locality id for this file */
116 #if REISER4_LARGE_KEY
119 /* coord of stat-data in sealed node */
121 /* bit-mask of stat-data extentions used by this file */
123 /* bitmask of non-default plugins for this inode */
125 /* bitmask of set heir plugins for this inode. */
128 struct list_head readdir_list
;
129 struct list_head not_used
;
131 /* per-inode flags. Filled by values of reiser4_file_plugin_flags */
134 /* fields specific to unix_file plugin */
135 struct unix_file_info unix_file_info
;
136 /* fields specific to cryptcompress file plugin */
137 struct cryptcompress_info cryptcompress_info
;
140 /* this semaphore is to serialize readers and writers of @pset->file
141 * when file plugin conversion is enabled
143 struct rw_semaphore conv_sem
;
145 /* tree of jnodes. Phantom jnodes (ones not attched to any atom) are
146 tagged in that tree by EFLUSH_TAG_ANONYMOUS */
147 struct radix_tree_root jnodes_tree
;
149 /* number of unformatted node jnodes of this file in jnode hash table */
150 unsigned long nr_jnodes
;
153 /* block number of virtual root for this object. See comment above
154 * fs/reiser4/search.c:handle_vroot() */
155 reiser4_block_nr vroot
;
156 struct mutex loading
;
159 void loading_init_once(reiser4_inode
*);
160 void loading_alloc(reiser4_inode
*);
161 void loading_destroy(reiser4_inode
*);
163 struct reiser4_inode_object
{
166 /* generic fields not specific to reiser4, but used by VFS */
167 struct inode vfs_inode
;
170 /* return pointer to the reiser4 specific portion of @inode */
171 static inline reiser4_inode
*reiser4_inode_data(const struct inode
*inode
172 /* inode queried */ )
174 assert("nikita-254", inode
!= NULL
);
175 return &container_of(inode
, struct reiser4_inode_object
, vfs_inode
)->p
;
178 static inline struct inode
*inode_by_reiser4_inode(const reiser4_inode
*
179 r4_inode
/* inode queried */
182 return &container_of(r4_inode
, struct reiser4_inode_object
,
187 * reiser4 inodes are identified by 64bit object-id (oid_t), but in struct
188 * inode ->i_ino field is of type ino_t (long) that can be either 32 or 64
191 * If ->i_ino is 32 bits we store remaining 32 bits in reiser4 specific part
192 * of inode, otherwise whole oid is stored in i_ino.
194 * Wrappers below ([sg]et_inode_oid()) are used to hide this difference.
197 #define OID_HI_SHIFT (sizeof(ino_t) * 8)
199 #if REISER4_INO_IS_OID
201 static inline oid_t
get_inode_oid(const struct inode
*inode
)
206 static inline void set_inode_oid(struct inode
*inode
, oid_t oid
)
211 /* REISER4_INO_IS_OID */
214 static inline oid_t
get_inode_oid(const struct inode
*inode
)
217 ((__u64
) reiser4_inode_data(inode
)->oid_hi
<< OID_HI_SHIFT
) |
221 static inline void set_inode_oid(struct inode
*inode
, oid_t oid
)
223 assert("nikita-2519", inode
!= NULL
);
224 inode
->i_ino
= (ino_t
) (oid
);
225 reiser4_inode_data(inode
)->oid_hi
= (oid
) >> OID_HI_SHIFT
;
226 assert("nikita-2521", get_inode_oid(inode
) == (oid
));
229 /* REISER4_INO_IS_OID */
232 static inline oid_t
get_inode_locality(const struct inode
*inode
)
234 return reiser4_inode_data(inode
)->locality_id
;
237 #if REISER4_LARGE_KEY
238 static inline __u64
get_inode_ordering(const struct inode
*inode
)
240 return reiser4_inode_data(inode
)->ordering
;
243 static inline void set_inode_ordering(const struct inode
*inode
, __u64 ordering
)
245 reiser4_inode_data(inode
)->ordering
= ordering
;
250 #define get_inode_ordering(inode) (0)
251 #define set_inode_ordering(inode, val) noop
255 /* return inode in which @uf_info is embedded */
256 static inline struct inode
*
257 unix_file_info_to_inode(const struct unix_file_info
*uf_info
)
259 return &container_of(uf_info
, struct reiser4_inode_object
,
260 p
.file_plugin_data
.unix_file_info
)->vfs_inode
;
263 extern ino_t
oid_to_ino(oid_t oid
) __attribute__ ((const));
264 extern ino_t
oid_to_uino(oid_t oid
) __attribute__ ((const));
266 extern reiser4_tree
*reiser4_tree_by_inode(const struct inode
*inode
);
269 extern void reiser4_inode_invariant(const struct inode
*inode
);
270 extern int inode_has_no_jnodes(reiser4_inode
*);
272 #define reiser4_inode_invariant(inode) noop
275 static inline int spin_inode_is_locked(const struct inode
*inode
)
277 assert_spin_locked(&reiser4_inode_data(inode
)->guard
);
282 * spin_lock_inode - lock reiser4_inode' embedded spinlock
283 * @inode: inode to lock
285 * In debug mode it checks that lower priority locks are not held and
286 * increments reiser4_context's lock counters on which lock ordering checking
289 static inline void spin_lock_inode(struct inode
*inode
)
291 assert("", LOCK_CNT_NIL(spin_locked
));
292 /* check lock ordering */
293 assert_spin_not_locked(&d_lock
);
295 spin_lock(&reiser4_inode_data(inode
)->guard
);
297 LOCK_CNT_INC(spin_locked_inode
);
298 LOCK_CNT_INC(spin_locked
);
300 reiser4_inode_invariant(inode
);
304 * spin_unlock_inode - unlock reiser4_inode' embedded spinlock
305 * @inode: inode to unlock
307 * In debug mode it checks that spinlock is held and decrements
308 * reiser4_context's lock counters on which lock ordering checking is based.
310 static inline void spin_unlock_inode(struct inode
*inode
)
312 assert_spin_locked(&reiser4_inode_data(inode
)->guard
);
313 assert("nikita-1375", LOCK_CNT_GTZ(spin_locked_inode
));
314 assert("nikita-1376", LOCK_CNT_GTZ(spin_locked
));
316 reiser4_inode_invariant(inode
);
318 LOCK_CNT_DEC(spin_locked_inode
);
319 LOCK_CNT_DEC(spin_locked
);
321 spin_unlock(&reiser4_inode_data(inode
)->guard
);
324 extern znode
*inode_get_vroot(struct inode
*inode
);
325 extern void inode_set_vroot(struct inode
*inode
, znode
* vroot
);
327 extern int reiser4_max_filename_len(const struct inode
*inode
);
328 extern int max_hash_collisions(const struct inode
*dir
);
329 extern void reiser4_unlock_inode(struct inode
*inode
);
330 extern int is_reiser4_inode(const struct inode
*inode
);
331 extern int setup_inode_ops(struct inode
*inode
, reiser4_object_create_data
*);
332 extern struct inode
*reiser4_iget(struct super_block
*super
,
333 const reiser4_key
* key
, int silent
);
334 extern void reiser4_iget_complete(struct inode
*inode
);
335 extern void reiser4_inode_set_flag(struct inode
*inode
,
336 reiser4_file_plugin_flags f
);
337 extern void reiser4_inode_clr_flag(struct inode
*inode
,
338 reiser4_file_plugin_flags f
);
339 extern int reiser4_inode_get_flag(const struct inode
*inode
,
340 reiser4_file_plugin_flags f
);
342 /* has inode been initialized? */
344 is_inode_loaded(const struct inode
*inode
/* inode queried */)
346 assert("nikita-1120", inode
!= NULL
);
347 return reiser4_inode_get_flag(inode
, REISER4_LOADED
);
350 extern file_plugin
*inode_file_plugin(const struct inode
*inode
);
351 extern dir_plugin
*inode_dir_plugin(const struct inode
*inode
);
352 extern formatting_plugin
*inode_formatting_plugin(const struct inode
*inode
);
353 extern hash_plugin
*inode_hash_plugin(const struct inode
*inode
);
354 extern fibration_plugin
*inode_fibration_plugin(const struct inode
*inode
);
355 extern cipher_plugin
*inode_cipher_plugin(const struct inode
*inode
);
356 extern digest_plugin
*inode_digest_plugin(const struct inode
*inode
);
357 extern compression_plugin
*inode_compression_plugin(const struct inode
*inode
);
358 extern compression_mode_plugin
*inode_compression_mode_plugin(const struct inode
360 extern cluster_plugin
*inode_cluster_plugin(const struct inode
*inode
);
361 extern file_plugin
*inode_create_plugin(const struct inode
*inode
);
362 extern item_plugin
*inode_sd_plugin(const struct inode
*inode
);
363 extern item_plugin
*inode_dir_item_plugin(const struct inode
*inode
);
364 extern file_plugin
*child_create_plugin(const struct inode
*inode
);
366 extern void reiser4_make_bad_inode(struct inode
*inode
);
368 extern void inode_set_extension(struct inode
*inode
, sd_ext_bits ext
);
369 extern void inode_clr_extension(struct inode
*inode
, sd_ext_bits ext
);
370 extern void inode_check_scale(struct inode
*inode
, __u64 old
, __u64
new);
371 extern void inode_check_scale_nolock(struct inode
*inode
, __u64 old
, __u64
new);
373 #define INODE_SET_SIZE(i, value) \
380 inode_check_scale(__i, __i->i_size, __v); \
381 i_size_write(__i, __v); \
385 * update field @field in inode @i to contain value @value.
387 #define INODE_SET_FIELD(i, field, value) \
394 inode_check_scale(__i, __i->field, __v); \
398 #define INODE_INC_FIELD(i, field) \
403 inode_check_scale(__i, __i->field, __i->field + 1); \
407 #define INODE_DEC_FIELD(i, field) \
412 inode_check_scale(__i, __i->field, __i->field - 1); \
416 /* See comment before reiser4_readdir_common() for description. */
417 static inline struct list_head
*get_readdir_list(const struct inode
*inode
)
419 return &reiser4_inode_data(inode
)->lists
.readdir_list
;
422 extern void init_inode_ordering(struct inode
*inode
,
423 reiser4_object_create_data
* crd
, int create
);
425 static inline struct radix_tree_root
*jnode_tree_by_inode(struct inode
*inode
)
427 return &reiser4_inode_data(inode
)->jnodes_tree
;
430 static inline struct radix_tree_root
*jnode_tree_by_reiser4_inode(reiser4_inode
433 return &r4_inode
->jnodes_tree
;
437 extern void print_inode(const char *prefix
, const struct inode
*i
);
440 int is_dir_empty(const struct inode
*);
442 /* __REISER4_INODE_H__ */
447 c-indentation-style: "K&R"