Lines Matching refs:inode

4  * (C) 1999 Andrea Arcangeli <andrea@suse.de> (dynamic inode allocation)
30 * inode->i_lock protects:
31 * inode->i_state, inode->i_hash, __iget(), inode->i_io_list
33 * inode->i_sb->s_inode_lru, inode->i_lru
34 * inode->i_sb->s_inode_list_lock protects:
35 * inode->i_sb->s_inodes, inode->i_sb_list
37 * bdi->wb.b_{dirty,io,more_io,dirty_time}, inode->i_io_list
39 * inode_hashtable, inode->i_hash
43 * inode->i_sb->s_inode_list_lock
44 * inode->i_lock
48 * inode->i_lock
51 * inode->i_sb->s_inode_list_lock
52 * inode->i_lock
120 .procname = "inode-nr",
127 .procname = "inode-state",
143 static int no_open(struct inode *inode, struct file *file)
149 * inode_init_always - perform inode structure initialisation
150 * @sb: superblock inode belongs to
151 * @inode: inode to initialise
153 * These are initializations that need to be done on every inode
156 int inode_init_always(struct super_block *sb, struct inode *inode)
160 struct address_space *const mapping = &inode->i_data;
162 inode->i_sb = sb;
163 inode->i_blkbits = sb->s_blocksize_bits;
164 inode->i_flags = 0;
165 atomic64_set(&inode->i_sequence, 0);
166 atomic_set(&inode->i_count, 1);
167 inode->i_op = &empty_iops;
168 inode->i_fop = &no_open_fops;
169 inode->i_ino = 0;
170 inode->__i_nlink = 1;
171 inode->i_opflags = 0;
173 inode->i_opflags |= IOP_XATTR;
174 i_uid_write(inode, 0);
175 i_gid_write(inode, 0);
176 atomic_set(&inode->i_writecount, 0);
177 inode->i_size = 0;
178 inode->i_write_hint = WRITE_LIFE_NOT_SET;
179 inode->i_blocks = 0;
180 inode->i_bytes = 0;
181 inode->i_generation = 0;
182 inode->i_pipe = NULL;
183 inode->i_cdev = NULL;
184 inode->i_link = NULL;
185 inode->i_dir_seq = 0;
186 inode->i_rdev = 0;
187 inode->dirtied_when = 0;
190 inode->i_wb_frn_winner = 0;
191 inode->i_wb_frn_avg_time = 0;
192 inode->i_wb_frn_history = 0;
195 spin_lock_init(&inode->i_lock);
196 lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
198 init_rwsem(&inode->i_rwsem);
199 lockdep_set_class(&inode->i_rwsem, &sb->s_type->i_mutex_key);
201 atomic_set(&inode->i_dio_count, 0);
204 mapping->host = inode;
220 inode->i_private = NULL;
221 inode->i_mapping = mapping;
222 INIT_HLIST_HEAD(&inode->i_dentry); /* buggered by rcu freeing */
224 inode->i_acl = inode->i_default_acl = ACL_NOT_CACHED;
228 inode->i_fsnotify_mask = 0;
230 inode->i_flctx = NULL;
232 if (unlikely(security_inode_alloc(inode)))
240 void free_inode_nonrcu(struct inode *inode)
242 kmem_cache_free(inode_cachep, inode);
248 struct inode *inode = container_of(head, struct inode, i_rcu);
249 if (inode->free_inode)
250 inode->free_inode(inode);
252 free_inode_nonrcu(inode);
255 static struct inode *alloc_inode(struct super_block *sb)
258 struct inode *inode;
261 inode = ops->alloc_inode(sb);
263 inode = alloc_inode_sb(sb, inode_cachep, GFP_KERNEL);
265 if (!inode)
268 if (unlikely(inode_init_always(sb, inode))) {
270 ops->destroy_inode(inode);
274 inode->free_inode = ops->free_inode;
275 i_callback(&inode->i_rcu);
279 return inode;
282 void __destroy_inode(struct inode *inode)
284 BUG_ON(inode_has_buffers(inode));
285 inode_detach_wb(inode);
286 security_inode_free(inode);
287 fsnotify_inode_delete(inode);
288 locks_free_lock_context(inode);
289 if (!inode->i_nlink) {
290 WARN_ON(atomic_long_read(&inode->i_sb->s_remove_count) == 0);
291 atomic_long_dec(&inode->i_sb->s_remove_count);
295 if (inode->i_acl && !is_uncached_acl(inode->i_acl))
296 posix_acl_release(inode->i_acl);
297 if (inode->i_default_acl && !is_uncached_acl(inode->i_default_acl))
298 posix_acl_release(inode->i_default_acl);
304 static void destroy_inode(struct inode *inode)
306 const struct super_operations *ops = inode->i_sb->s_op;
308 BUG_ON(!list_empty(&inode->i_lru));
309 __destroy_inode(inode);
311 ops->destroy_inode(inode);
315 inode->free_inode = ops->free_inode;
316 call_rcu(&inode->i_rcu, i_callback);
320 * drop_nlink - directly drop an inode's link count
321 * @inode: inode
330 void drop_nlink(struct inode *inode)
332 WARN_ON(inode->i_nlink == 0);
333 inode->__i_nlink--;
334 if (!inode->i_nlink)
335 atomic_long_inc(&inode->i_sb->s_remove_count);
340 * clear_nlink - directly zero an inode's link count
341 * @inode: inode
347 void clear_nlink(struct inode *inode)
349 if (inode->i_nlink) {
350 inode->__i_nlink = 0;
351 atomic_long_inc(&inode->i_sb->s_remove_count);
357 * set_nlink - directly set an inode's link count
358 * @inode: inode
364 void set_nlink(struct inode *inode, unsigned int nlink)
367 clear_nlink(inode);
370 if (inode->i_nlink == 0)
371 atomic_long_dec(&inode->i_sb->s_remove_count);
373 inode->__i_nlink = nlink;
379 * inc_nlink - directly increment an inode's link count
380 * @inode: inode
386 void inc_nlink(struct inode *inode)
388 if (unlikely(inode->i_nlink == 0)) {
389 WARN_ON(!(inode->i_state & I_LINKABLE));
390 atomic_long_dec(&inode->i_sb->s_remove_count);
393 inode->__i_nlink++;
416 * of the inode, so let the slab aware of that.
418 void inode_init_once(struct inode *inode)
420 memset(inode, 0, sizeof(*inode));
421 INIT_HLIST_NODE(&inode->i_hash);
422 INIT_LIST_HEAD(&inode->i_devices);
423 INIT_LIST_HEAD(&inode->i_io_list);
424 INIT_LIST_HEAD(&inode->i_wb_list);
425 INIT_LIST_HEAD(&inode->i_lru);
426 INIT_LIST_HEAD(&inode->i_sb_list);
427 __address_space_init_once(&inode->i_data);
428 i_size_ordered_init(inode);
434 struct inode *inode = (struct inode *) foo;
436 inode_init_once(inode);
440 * inode->i_lock must be held
442 void __iget(struct inode *inode)
444 atomic_inc(&inode->i_count);
448 * get additional reference to inode; caller must already hold one.
450 void ihold(struct inode *inode)
452 WARN_ON(atomic_inc_return(&inode->i_count) < 2);
456 static void __inode_add_lru(struct inode *inode, bool rotate)
458 if (inode->i_state & (I_DIRTY_ALL | I_SYNC | I_FREEING | I_WILL_FREE))
460 if (atomic_read(&inode->i_count))
462 if (!(inode->i_sb->s_flags & SB_ACTIVE))
464 if (!mapping_shrinkable(&inode->i_data))
467 if (list_lru_add_obj(&inode->i_sb->s_inode_lru, &inode->i_lru))
470 inode->i_state |= I_REFERENCED;
474 * Add inode to LRU if needed (inode is unused and clean).
476 * Needs inode->i_lock held.
478 void inode_add_lru(struct inode *inode)
480 __inode_add_lru(inode, false);
483 static void inode_lru_list_del(struct inode *inode)
485 if (list_lru_del_obj(&inode->i_sb->s_inode_lru, &inode->i_lru))
490 * inode_sb_list_add - add inode to the superblock list of inodes
491 * @inode: inode to add
493 void inode_sb_list_add(struct inode *inode)
495 spin_lock(&inode->i_sb->s_inode_list_lock);
496 list_add(&inode->i_sb_list, &inode->i_sb->s_inodes);
497 spin_unlock(&inode->i_sb->s_inode_list_lock);
501 static inline void inode_sb_list_del(struct inode *inode)
503 if (!list_empty(&inode->i_sb_list)) {
504 spin_lock(&inode->i_sb->s_inode_list_lock);
505 list_del_init(&inode->i_sb_list);
506 spin_unlock(&inode->i_sb->s_inode_list_lock);
521 * __insert_inode_hash - hash an inode
522 * @inode: unhashed inode
526 * Add an inode to the inode hash for this superblock.
528 void __insert_inode_hash(struct inode *inode, unsigned long hashval)
530 struct hlist_head *b = inode_hashtable + hash(inode->i_sb, hashval);
533 spin_lock(&inode->i_lock);
534 hlist_add_head_rcu(&inode->i_hash, b);
535 spin_unlock(&inode->i_lock);
541 * __remove_inode_hash - remove an inode from the hash
542 * @inode: inode to unhash
544 * Remove an inode from the superblock.
546 void __remove_inode_hash(struct inode *inode)
549 spin_lock(&inode->i_lock);
550 hlist_del_init_rcu(&inode->i_hash);
551 spin_unlock(&inode->i_lock);
558 struct inode *host;
582 pr_warn("aops:%ps invalid inode:%px\n", a_ops, host);
606 void clear_inode(struct inode *inode)
613 xa_lock_irq(&inode->i_data.i_pages);
614 BUG_ON(inode->i_data.nrpages);
616 * Almost always, mapping_empty(&inode->i_data) here; but there are
623 xa_unlock_irq(&inode->i_data.i_pages);
624 BUG_ON(!list_empty(&inode->i_data.i_private_list));
625 BUG_ON(!(inode->i_state & I_FREEING));
626 BUG_ON(inode->i_state & I_CLEAR);
627 BUG_ON(!list_empty(&inode->i_wb_list));
629 inode->i_state = I_FREEING | I_CLEAR;
634 * Free the inode passed in, removing it from the lists it is still connected
635 * to. We remove any pages still attached to the inode and wait for any IO that
636 * is still in progress before finally destroying the inode.
638 * An inode must already be marked I_FREEING so that we avoid the inode being
642 * An inode must already be removed from the LRU list before being evicted from
646 static void evict(struct inode *inode)
648 const struct super_operations *op = inode->i_sb->s_op;
650 BUG_ON(!(inode->i_state & I_FREEING));
651 BUG_ON(!list_empty(&inode->i_lru));
653 if (!list_empty(&inode->i_io_list))
654 inode_io_list_del(inode);
656 inode_sb_list_del(inode);
659 * Wait for flusher thread to be done with the inode so that filesystem
661 * the inode has I_FREEING set, flusher thread won't start new work on
662 * the inode. We just have to wait for running writeback to finish.
664 inode_wait_for_writeback(inode);
667 op->evict_inode(inode);
669 truncate_inode_pages_final(&inode->i_data);
670 clear_inode(inode);
672 if (S_ISCHR(inode->i_mode) && inode->i_cdev)
673 cd_forget(inode);
675 remove_inode_hash(inode);
677 spin_lock(&inode->i_lock);
678 wake_up_bit(&inode->i_state, __I_NEW);
679 BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
680 spin_unlock(&inode->i_lock);
682 destroy_inode(inode);
695 struct inode *inode;
697 inode = list_first_entry(head, struct inode, i_lru);
698 list_del_init(&inode->i_lru);
700 evict(inode);
711 * so any inode reaching zero refcount during or after that call will
716 struct inode *inode, *next;
721 list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
722 if (atomic_read(&inode->i_count))
725 spin_lock(&inode->i_lock);
726 if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
727 spin_unlock(&inode->i_lock);
731 inode->i_state |= I_FREEING;
732 inode_lru_list_del(inode);
733 spin_unlock(&inode->i_lock);
734 list_add(&inode->i_lru, &dispose);
762 struct inode *inode, *next;
767 list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
768 spin_lock(&inode->i_lock);
769 if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
770 spin_unlock(&inode->i_lock);
773 if (atomic_read(&inode->i_count)) {
774 spin_unlock(&inode->i_lock);
778 inode->i_state |= I_FREEING;
779 inode_lru_list_del(inode);
780 spin_unlock(&inode->i_lock);
781 list_add(&inode->i_lru, &dispose);
795 * Isolate the inode from the LRU in preparation for freeing it.
797 * If the inode has the I_REFERENCED flag set, then it means that it has been
799 * inode, clear the flag and move it to the back of the LRU so it gets another
809 struct inode *inode = container_of(item, struct inode, i_lru);
812 * We are inverting the lru lock/inode->i_lock here, so use a
815 if (!spin_trylock(&inode->i_lock))
824 if (atomic_read(&inode->i_count) ||
825 (inode->i_state & ~I_REFERENCED) ||
826 !mapping_shrinkable(&inode->i_data)) {
827 list_lru_isolate(lru, &inode->i_lru);
828 spin_unlock(&inode->i_lock);
834 if (inode->i_state & I_REFERENCED) {
835 inode->i_state &= ~I_REFERENCED;
836 spin_unlock(&inode->i_lock);
845 if (inode_has_buffers(inode) || !mapping_empty(&inode->i_data)) {
846 __iget(inode);
847 spin_unlock(&inode->i_lock);
849 if (remove_inode_buffers(inode)) {
851 reap = invalidate_mapping_pages(&inode->i_data, 0, -1);
858 iput(inode);
863 WARN_ON(inode->i_state & I_NEW);
864 inode->i_state |= I_FREEING;
865 list_lru_isolate_move(lru, &inode->i_lru, freeable);
866 spin_unlock(&inode->i_lock);
873 * Walk the superblock inode LRU for freeable inodes and attempt to free them.
889 static void __wait_on_freeing_inode(struct inode *inode);
891 * Called with the inode lock held.
893 static struct inode *find_inode(struct super_block *sb,
895 int (*test)(struct inode *, void *),
898 struct inode *inode = NULL;
901 hlist_for_each_entry(inode, head, i_hash) {
902 if (inode->i_sb != sb)
904 if (!test(inode, data))
906 spin_lock(&inode->i_lock);
907 if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
908 __wait_on_freeing_inode(inode);
911 if (unlikely(inode->i_state & I_CREATING)) {
912 spin_unlock(&inode->i_lock);
915 __iget(inode);
916 spin_unlock(&inode->i_lock);
917 return inode;
926 static struct inode *find_inode_fast(struct super_block *sb,
929 struct inode *inode = NULL;
932 hlist_for_each_entry(inode, head, i_hash) {
933 if (inode->i_ino != ino)
935 if (inode->i_sb != sb)
937 spin_lock(&inode->i_lock);
938 if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
939 __wait_on_freeing_inode(inode);
942 if (unlikely(inode->i_state & I_CREATING)) {
943 spin_unlock(&inode->i_lock);
946 __iget(inode);
947 spin_unlock(&inode->i_lock);
948 return inode;
959 * consume at most LAST_INO_BATCH-1 unused inode numbers. So there is
986 /* get_next_ino should not provide a 0 inode number */
996 * new_inode_pseudo - obtain an inode
999 * Allocates a new inode for given superblock.
1005 struct inode *new_inode_pseudo(struct super_block *sb)
1007 struct inode *inode = alloc_inode(sb);
1009 if (inode) {
1010 spin_lock(&inode->i_lock);
1011 inode->i_state = 0;
1012 spin_unlock(&inode->i_lock);
1014 return inode;
1018 * new_inode - obtain an inode
1021 * Allocates a new inode for given superblock. The default gfp_mask
1022 * for allocations related to inode->i_mapping is GFP_HIGHUSER_MOVABLE.
1026 * newly created inode's mapping
1029 struct inode *new_inode(struct super_block *sb)
1031 struct inode *inode;
1033 inode = new_inode_pseudo(sb);
1034 if (inode)
1035 inode_sb_list_add(inode);
1036 return inode;
1041 void lockdep_annotate_inode_mutex_key(struct inode *inode)
1043 if (S_ISDIR(inode->i_mode)) {
1044 struct file_system_type *type = inode->i_sb->s_type;
1047 if (lockdep_match_class(&inode->i_rwsem, &type->i_mutex_key)) {
1051 // mutex_destroy(&inode->i_mutex);
1052 init_rwsem(&inode->i_rwsem);
1053 lockdep_set_class(&inode->i_rwsem,
1063 * @inode: new inode to unlock
1065 * Called when the inode is fully initialised to clear the new state of the
1066 * inode and wake up anyone waiting for the inode to finish initialisation.
1068 void unlock_new_inode(struct inode *inode)
1070 lockdep_annotate_inode_mutex_key(inode);
1071 spin_lock(&inode->i_lock);
1072 WARN_ON(!(inode->i_state & I_NEW));
1073 inode->i_state &= ~I_NEW & ~I_CREATING;
1075 wake_up_bit(&inode->i_state, __I_NEW);
1076 spin_unlock(&inode->i_lock);
1080 void discard_new_inode(struct inode *inode)
1082 lockdep_annotate_inode_mutex_key(inode);
1083 spin_lock(&inode->i_lock);
1084 WARN_ON(!(inode->i_state & I_NEW));
1085 inode->i_state &= ~I_NEW;
1087 wake_up_bit(&inode->i_state, __I_NEW);
1088 spin_unlock(&inode->i_lock);
1089 iput(inode);
1099 * @inode1: first inode to lock
1100 * @inode2: second inode to lock
1102 void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
1119 * @inode1: first inode to unlock
1120 * @inode2: second inode to unlock
1122 void unlock_two_nondirectories(struct inode *inode1, struct inode *inode2)
1136 * inode_insert5 - obtain an inode from a mounted file system
1137 * @inode: pre-allocated inode to use for insert to cache
1138 * @hashval: hash value (usually inode number) to get
1140 * @set: callback used to initialize a new struct inode
1143 * Search for the inode specified by @hashval and @data in the inode cache,
1146 * allocation of inode.
1148 * If the inode is not in cache, insert the pre-allocated inode to cache and
1155 struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
1156 int (*test)(struct inode *, void *),
1157 int (*set)(struct inode *, void *), void *data)
1159 struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
1160 struct inode *old;
1164 old = find_inode(inode->i_sb, head, test, data);
1167 * Uhhuh, somebody else created the same inode under us.
1168 * Use the old inode instead of the preallocated one.
1181 if (set && unlikely(set(inode, data))) {
1182 inode = NULL;
1187 * Return the locked inode with I_NEW set, the
1190 spin_lock(&inode->i_lock);
1191 inode->i_state |= I_NEW;
1192 hlist_add_head_rcu(&inode->i_hash, head);
1193 spin_unlock(&inode->i_lock);
1196 * Add inode to the sb list if it's not already. It has I_NEW at this
1199 if (list_empty(&inode->i_sb_list))
1200 inode_sb_list_add(inode);
1204 return inode;
1209 * iget5_locked - obtain an inode from a mounted file system
1211 * @hashval: hash value (usually inode number) to get
1213 * @set: callback used to initialize a new struct inode
1216 * Search for the inode specified by @hashval and @data in the inode cache,
1218 * a generalized version of iget_locked() for file systems where the inode
1219 * number is not sufficient for unique identification of an inode.
1221 * If the inode is not in cache, allocate a new inode and return it locked,
1228 struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
1229 int (*test)(struct inode *, void *),
1230 int (*set)(struct inode *, void *), void *data)
1232 struct inode *inode = ilookup5(sb, hashval, test, data);
1234 if (!inode) {
1235 struct inode *new = alloc_inode(sb);
1239 inode = inode_insert5(new, hashval, test, set, data);
1240 if (unlikely(inode != new))
1244 return inode;
1249 * iget_locked - obtain an inode from a mounted file system
1251 * @ino: inode number to get
1253 * Search for the inode specified by @ino in the inode cache and if present
1255 * where the inode number is sufficient for unique identification of an inode.
1257 * If the inode is not in cache, allocate a new inode and return it locked,
1261 struct inode *iget_locked(struct super_block *sb, unsigned long ino)
1264 struct inode *inode;
1267 inode = find_inode_fast(sb, head, ino);
1269 if (inode) {
1270 if (IS_ERR(inode))
1272 wait_on_inode(inode);
1273 if (unlikely(inode_unhashed(inode))) {
1274 iput(inode);
1277 return inode;
1280 inode = alloc_inode(sb);
1281 if (inode) {
1282 struct inode *old;
1288 inode->i_ino = ino;
1289 spin_lock(&inode->i_lock);
1290 inode->i_state = I_NEW;
1291 hlist_add_head_rcu(&inode->i_hash, head);
1292 spin_unlock(&inode->i_lock);
1293 inode_sb_list_add(inode);
1296 /* Return the locked inode with I_NEW set, the
1299 return inode;
1303 * Uhhuh, somebody else created the same inode under
1304 * us. Use the old inode instead of the one we just
1308 destroy_inode(inode);
1311 inode = old;
1312 wait_on_inode(inode);
1313 if (unlikely(inode_unhashed(inode))) {
1314 iput(inode);
1318 return inode;
1323 * search the inode cache for a matching inode number.
1324 * If we find one, then the inode number we are trying to
1327 * Returns 1 if the inode number is unique, 0 if it is not.
1332 struct inode *inode;
1334 hlist_for_each_entry_rcu(inode, b, i_hash) {
1335 if (inode->i_ino == ino && inode->i_sb == sb)
1342 * iunique - get a unique inode number
1344 * @max_reserved: highest reserved inode number
1346 * Obtain an inode number that is unique on the system for a given
1348 * permanent inode numbering system. An inode number is returned that
1380 struct inode *igrab(struct inode *inode)
1382 spin_lock(&inode->i_lock);
1383 if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) {
1384 __iget(inode);
1385 spin_unlock(&inode->i_lock);
1387 spin_unlock(&inode->i_lock);
1391 * while the inode is getting freed.
1393 inode = NULL;
1395 return inode;
1400 * ilookup5_nowait - search for an inode in the inode cache
1402 * @hashval: hash value (usually inode number) to search for
1406 * Search for the inode specified by @hashval and @data in the inode cache.
1407 * If the inode is in the cache, the inode is returned with an incremented
1411 * with the returned inode. You probably should be using ilookup5() instead.
1415 struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
1416 int (*test)(struct inode *, void *), void *data)
1419 struct inode *inode;
1422 inode = find_inode(sb, head, test, data);
1425 return IS_ERR(inode) ? NULL : inode;
1430 * ilookup5 - search for an inode in the inode cache
1432 * @hashval: hash value (usually inode number) to search for
1436 * Search for the inode specified by @hashval and @data in the inode cache,
1437 * and if the inode is in the cache, return the inode with an incremented
1438 * reference count. Waits on I_NEW before returning the inode.
1442 * inode number is not sufficient for unique identification of an inode.
1446 struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
1447 int (*test)(struct inode *, void *), void *data)
1449 struct inode *inode;
1451 inode = ilookup5_nowait(sb, hashval, test, data);
1452 if (inode) {
1453 wait_on_inode(inode);
1454 if (unlikely(inode_unhashed(inode))) {
1455 iput(inode);
1459 return inode;
1464 * ilookup - search for an inode in the inode cache
1466 * @ino: inode number to search for
1468 * Search for the inode @ino in the inode cache, and if the inode is in the
1469 * cache, the inode is returned with an incremented reference count.
1471 struct inode *ilookup(struct super_block *sb, unsigned long ino)
1474 struct inode *inode;
1477 inode = find_inode_fast(sb, head, ino);
1480 if (inode) {
1481 if (IS_ERR(inode))
1483 wait_on_inode(inode);
1484 if (unlikely(inode_unhashed(inode))) {
1485 iput(inode);
1489 return inode;
1494 * find_inode_nowait - find an inode in the inode cache
1496 * @hashval: hash value (usually inode number) to search for
1500 * Search for the inode specified by @hashval and @data in the inode
1501 * cache, where the helper function @match will return 0 if the inode
1502 * does not match, 1 if the inode does match, and -1 if the search
1504 * taking the i_lock spin_lock and checking i_state for an inode being
1513 * inode eviction. The tradeoff is that the @match funtion must be
1516 struct inode *find_inode_nowait(struct super_block *sb,
1518 int (*match)(struct inode *, unsigned long,
1523 struct inode *inode, *ret_inode = NULL;
1527 hlist_for_each_entry(inode, head, i_hash) {
1528 if (inode->i_sb != sb)
1530 mval = match(inode, hashval, data);
1534 ret_inode = inode;
1544 * find_inode_rcu - find an inode in the inode cache
1547 * @test: Function to test match on an inode
1550 * Search for the inode specified by @hashval and @data in the inode cache,
1551 * where the helper function @test will return 0 if the inode does not match
1553 * i_lock spin_lock and checking i_state for an inode being freed or being
1556 * If successful, this will return the inode for which the @test function
1559 * The @test function is not permitted to take a ref on any inode presented.
1564 struct inode *find_inode_rcu(struct super_block *sb, unsigned long hashval,
1565 int (*test)(struct inode *, void *), void *data)
1568 struct inode *inode;
1573 hlist_for_each_entry_rcu(inode, head, i_hash) {
1574 if (inode->i_sb == sb &&
1575 !(READ_ONCE(inode->i_state) & (I_FREEING | I_WILL_FREE)) &&
1576 test(inode, data))
1577 return inode;
1584 * find_inode_by_ino_rcu - Find an inode in the inode cache
1586 * @ino: The inode number to match
1588 * Search for the inode specified by @hashval and @data in the inode cache,
1589 * where the helper function @test will return 0 if the inode does not match
1591 * i_lock spin_lock and checking i_state for an inode being freed or being
1594 * If successful, this will return the inode for which the @test function
1597 * The @test function is not permitted to take a ref on any inode presented.
1602 struct inode *find_inode_by_ino_rcu(struct super_block *sb,
1606 struct inode *inode;
1611 hlist_for_each_entry_rcu(inode, head, i_hash) {
1612 if (inode->i_ino == ino &&
1613 inode->i_sb == sb &&
1614 !(READ_ONCE(inode->i_state) & (I_FREEING | I_WILL_FREE)))
1615 return inode;
1621 int insert_inode_locked(struct inode *inode)
1623 struct super_block *sb = inode->i_sb;
1624 ino_t ino = inode->i_ino;
1628 struct inode *old = NULL;
1643 spin_lock(&inode->i_lock);
1644 inode->i_state |= I_NEW | I_CREATING;
1645 hlist_add_head_rcu(&inode->i_hash, head);
1646 spin_unlock(&inode->i_lock);
1668 int insert_inode_locked4(struct inode *inode, unsigned long hashval,
1669 int (*test)(struct inode *, void *), void *data)
1671 struct inode *old;
1673 inode->i_state |= I_CREATING;
1674 old = inode_insert5(inode, hashval, test, NULL, data);
1676 if (old != inode) {
1685 int generic_delete_inode(struct inode *inode)
1693 * to an inode.
1697 * us to evict inode, do so. Otherwise, retain inode
1701 static void iput_final(struct inode *inode)
1703 struct super_block *sb = inode->i_sb;
1704 const struct super_operations *op = inode->i_sb->s_op;
1708 WARN_ON(inode->i_state & I_NEW);
1711 drop = op->drop_inode(inode);
1713 drop = generic_drop_inode(inode);
1716 !(inode->i_state & I_DONTCACHE) &&
1718 __inode_add_lru(inode, true);
1719 spin_unlock(&inode->i_lock);
1723 state = inode->i_state;
1725 WRITE_ONCE(inode->i_state, state | I_WILL_FREE);
1726 spin_unlock(&inode->i_lock);
1728 write_inode_now(inode, 1);
1730 spin_lock(&inode->i_lock);
1731 state = inode->i_state;
1736 WRITE_ONCE(inode->i_state, state | I_FREEING);
1737 if (!list_empty(&inode->i_lru))
1738 inode_lru_list_del(inode);
1739 spin_unlock(&inode->i_lock);
1741 evict(inode);
1745 * iput - put an inode
1746 * @inode: inode to put
1748 * Puts an inode, dropping its usage count. If the inode use count hits
1749 * zero, the inode is then freed and may also be destroyed.
1753 void iput(struct inode *inode)
1755 if (!inode)
1757 BUG_ON(inode->i_state & I_CLEAR);
1759 if (atomic_dec_and_lock(&inode->i_count, &inode->i_lock)) {
1760 if (inode->i_nlink && (inode->i_state & I_DIRTY_TIME)) {
1761 atomic_inc(&inode->i_count);
1762 spin_unlock(&inode->i_lock);
1763 trace_writeback_lazytime_iput(inode);
1764 mark_inode_dirty_sync(inode);
1767 iput_final(inode);
1775 * @inode: inode owning the block number being requested
1780 * That is, asked for block 4 of inode 1 the function will replace the
1787 int bmap(struct inode *inode, sector_t *block)
1789 if (!inode->i_mapping->a_ops->bmap)
1792 *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block);
1803 static bool relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1813 atime = inode_get_atime(inode);
1814 mtime = inode_get_mtime(inode);
1820 ctime = inode_get_ctime(inode);
1837 * inode_update_timestamps - update the timestamps on the inode
1838 * @inode: inode to be updated
1841 * The update_time function is called when an inode's timestamps need to be
1843 * actual timestamps. It's up to the caller to ensure that the inode is marked
1852 int inode_update_timestamps(struct inode *inode, int flags)
1858 struct timespec64 ctime = inode_get_ctime(inode);
1859 struct timespec64 mtime = inode_get_mtime(inode);
1861 now = inode_set_ctime_current(inode);
1865 inode_set_mtime_to_ts(inode, now);
1868 if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated))
1871 now = current_time(inode);
1875 struct timespec64 atime = inode_get_atime(inode);
1878 inode_set_atime_to_ts(inode, now);
1887 * generic_update_time - update the timestamps on the inode
1888 * @inode: inode to be updated
1891 * The update_time function is called when an inode's timestamps need to be
1898 int generic_update_time(struct inode *inode, int flags)
1900 int updated = inode_update_timestamps(inode, flags);
1904 dirty_flags = inode->i_sb->s_flags & SB_LAZYTIME ? I_DIRTY_TIME : I_DIRTY_SYNC;
1907 __mark_inode_dirty(inode, dirty_flags);
1916 int inode_update_time(struct inode *inode, int flags)
1918 if (inode->i_op->update_time)
1919 return inode->i_op->update_time(inode, flags);
1920 generic_update_time(inode, flags);
1928 * @inode: inode to update
1930 * Update the accessed time on an inode and mark it for writeback.
1932 * as well as the "noatime" flag and inode specific "noatime" markers.
1934 bool atime_needs_update(const struct path *path, struct inode *inode)
1939 if (inode->i_flags & S_NOATIME)
1945 if (HAS_UNMAPPED_ID(mnt_idmap(mnt), inode))
1948 if (IS_NOATIME(inode))
1950 if ((inode->i_sb->s_flags & SB_NODIRATIME) && S_ISDIR(inode->i_mode))
1955 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1958 now = current_time(inode);
1960 if (!relatime_need_update(mnt, inode, now))
1963 atime = inode_get_atime(inode);
1973 struct inode *inode = d_inode(path->dentry);
1975 if (!atime_needs_update(path, inode))
1978 if (!sb_start_write_trylock(inode->i_sb))
1985 * allocate new space to modify an inode (such is the case for
1992 inode_update_time(inode, S_ATIME);
1995 sb_end_write(inode->i_sb);
2007 struct inode *inode = d_inode(dentry);
2011 if (IS_NOSEC(inode))
2014 mask = setattr_should_drop_suidgid(idmap, inode);
2039 struct inode *inode = file_inode(file);
2043 if (IS_NOSEC(inode) || !S_ISREG(inode->i_mode))
2058 inode_has_no_xattr(inode);
2078 static int inode_needs_update_time(struct inode *inode)
2081 struct timespec64 now = current_time(inode);
2085 if (IS_NOCMTIME(inode))
2088 ts = inode_get_mtime(inode);
2092 ts = inode_get_ctime(inode);
2096 if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))
2105 struct inode *inode = file_inode(file);
2109 ret = inode_update_time(inode, sync_mode);
2120 * Update the mtime and ctime members of an inode and mark the inode for
2123 * explicitly ignore updates via this function with the _NOCMTIME inode
2126 * allocate space in order to update an inode.
2133 struct inode *inode = file_inode(file);
2135 ret = inode_needs_update_time(inode);
2154 * Context: Caller must hold the file's inode lock.
2161 struct inode *inode = file_inode(file);
2174 ret = inode_needs_update_time(inode);
2190 * Context: Caller must hold the file's inode lock.
2207 * Context: Caller must hold the file's inode lock.
2217 int inode_needs_sync(struct inode *inode)
2219 if (IS_SYNC(inode))
2221 if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode))
2228 * If we try to find an inode in the inode hash while it is being
2232 * to recheck inode state.
2235 * wake_up_bit(&inode->i_state, __I_NEW) after removing from the hash list
2238 static void __wait_on_freeing_inode(struct inode *inode)
2241 DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW);
2242 wq = bit_waitqueue(&inode->i_state, __I_NEW);
2244 spin_unlock(&inode->i_lock);
2262 * Initialize the waitqueues and inode hash table.
2286 /* inode slab cache */
2288 sizeof(struct inode),
2310 void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
2312 inode->i_mode = mode;
2314 inode->i_fop = &def_chr_fops;
2315 inode->i_rdev = rdev;
2318 inode->i_fop = &def_blk_fops;
2319 inode->i_rdev = rdev;
2321 inode->i_fop = &pipefifo_fops;
2326 " inode %s:%lu\n", mode, inode->i_sb->s_id,
2327 inode->i_ino);
2332 * inode_init_owner - Init uid,gid,mode for new inode according to posix standards
2333 * @idmap: idmap of the mount the inode was created from
2334 * @inode: New inode
2335 * @dir: Directory inode
2336 * @mode: mode of the new inode
2338 * If the inode has been created through an idmapped mount the idmap of
2340 * care to map the inode according to @idmap before checking permissions
2342 * checking is to be performed on the raw inode simply pass @nop_mnt_idmap.
2344 void inode_init_owner(struct mnt_idmap *idmap, struct inode *inode,
2345 const struct inode *dir, umode_t mode)
2347 inode_fsuid_set(inode, idmap);
2349 inode->i_gid = dir->i_gid;
2355 inode_fsgid_set(inode, idmap);
2356 inode->i_mode = mode;
2361 * inode_owner_or_capable - check current task permissions to inode
2362 * @idmap: idmap of the mount the inode was found from
2363 * @inode: inode being checked
2366 * inode owner uid mapped, or owns the file.
2368 * If the inode has been found through an idmapped mount the idmap of
2370 * care to map the inode according to @idmap before checking permissions.
2372 * raw inode simply pass @nop_mnt_idmap.
2375 const struct inode *inode)
2380 vfsuid = i_uid_into_vfsuid(idmap, inode);
2394 static void __inode_dio_wait(struct inode *inode)
2396 wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_DIO_WAKEUP);
2397 DEFINE_WAIT_BIT(q, &inode->i_state, __I_DIO_WAKEUP);
2401 if (atomic_read(&inode->i_dio_count))
2403 } while (atomic_read(&inode->i_dio_count));
2409 * @inode: inode to wait for
2415 * to i_dio_count, usually by inode->i_mutex.
2417 void inode_dio_wait(struct inode *inode)
2419 if (atomic_read(&inode->i_dio_count))
2420 __inode_dio_wait(inode);
2425 * inode_set_flags - atomically set some inode flags
2428 * they have exclusive access to the inode structure (i.e., while the
2429 * inode is being instantiated). The reason for the cmpxchg() loop
2440 void inode_set_flags(struct inode *inode, unsigned int flags,
2444 set_mask_bits(&inode->i_flags, mask, flags);
2448 void inode_nohighmem(struct inode *inode)
2450 mapping_set_gfp_mask(inode->i_mapping, GFP_USER);
2457 * @inode: inode being updated
2460 * containing the inode. Always rounds down. gran must
2463 struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode)
2465 struct super_block *sb = inode->i_sb;
2487 * @inode: inode.
2492 * Note that inode and inode->sb cannot be NULL.
2495 struct timespec64 current_time(struct inode *inode)
2500 return timestamp_truncate(now, inode);
2506 * @inode: inode
2508 * Set the inode->i_ctime to the current value for the inode. Returns
2511 struct timespec64 inode_set_ctime_current(struct inode *inode)
2513 struct timespec64 now = current_time(inode);
2515 inode_set_ctime_to_ts(inode, now);
2522 * @idmap: idmap of the mount @inode was found from
2523 * @inode: inode to check
2524 * @vfsgid: the new/current vfsgid of @inode
2527 * privileged with CAP_FSETID over @inode. This can be used to determine
2533 const struct inode *inode, vfsgid_t vfsgid)
2537 if (capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
2544 * @idmap: idmap of the mount the inode was created from
2545 * @dir: parent directory inode
2557 const struct inode *dir, umode_t mode)