Lines Matching refs:inode
4 * (C) 1999 Andrea Arcangeli <andrea@suse.de> (dynamic inode allocation)
29 * inode->i_lock protects:
30 * inode->i_state, inode->i_hash, __iget(), inode->i_io_list
32 * inode->i_sb->s_inode_lru, inode->i_lru
33 * inode->i_sb->s_inode_list_lock protects:
34 * inode->i_sb->s_inodes, inode->i_sb_list
36 * bdi->wb.b_{dirty,io,more_io,dirty_time}, inode->i_io_list
38 * inode_hashtable, inode->i_hash
42 * inode->i_sb->s_inode_list_lock
43 * inode->i_lock
47 * inode->i_lock
50 * inode->i_sb->s_inode_list_lock
51 * inode->i_lock
119 .procname = "inode-nr",
126 .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(&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(&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);
605 void clear_inode(struct inode *inode)
612 xa_lock_irq(&inode->i_data.i_pages);
613 BUG_ON(inode->i_data.nrpages);
615 * Almost always, mapping_empty(&inode->i_data) here; but there are
622 xa_unlock_irq(&inode->i_data.i_pages);
623 BUG_ON(!list_empty(&inode->i_data.private_list));
624 BUG_ON(!(inode->i_state & I_FREEING));
625 BUG_ON(inode->i_state & I_CLEAR);
626 BUG_ON(!list_empty(&inode->i_wb_list));
628 inode->i_state = I_FREEING | I_CLEAR;
633 * Free the inode passed in, removing it from the lists it is still connected
634 * to. We remove any pages still attached to the inode and wait for any IO that
635 * is still in progress before finally destroying the inode.
637 * An inode must already be marked I_FREEING so that we avoid the inode being
641 * An inode must already be removed from the LRU list before being evicted from
645 static void evict(struct inode *inode)
647 const struct super_operations *op = inode->i_sb->s_op;
649 BUG_ON(!(inode->i_state & I_FREEING));
650 BUG_ON(!list_empty(&inode->i_lru));
652 if (!list_empty(&inode->i_io_list))
653 inode_io_list_del(inode);
655 inode_sb_list_del(inode);
658 * Wait for flusher thread to be done with the inode so that filesystem
660 * the inode has I_FREEING set, flusher thread won't start new work on
661 * the inode. We just have to wait for running writeback to finish.
663 inode_wait_for_writeback(inode);
666 op->evict_inode(inode);
668 truncate_inode_pages_final(&inode->i_data);
669 clear_inode(inode);
671 if (S_ISCHR(inode->i_mode) && inode->i_cdev)
672 cd_forget(inode);
674 remove_inode_hash(inode);
676 spin_lock(&inode->i_lock);
677 wake_up_bit(&inode->i_state, __I_NEW);
678 BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
679 spin_unlock(&inode->i_lock);
681 destroy_inode(inode);
694 struct inode *inode;
696 inode = list_first_entry(head, struct inode, i_lru);
697 list_del_init(&inode->i_lru);
699 evict(inode);
710 * so any inode reaching zero refcount during or after that call will
715 struct inode *inode, *next;
720 list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
721 if (atomic_read(&inode->i_count))
724 spin_lock(&inode->i_lock);
725 if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
726 spin_unlock(&inode->i_lock);
730 inode->i_state |= I_FREEING;
731 inode_lru_list_del(inode);
732 spin_unlock(&inode->i_lock);
733 list_add(&inode->i_lru, &dispose);
761 struct inode *inode, *next;
766 list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
767 spin_lock(&inode->i_lock);
768 if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
769 spin_unlock(&inode->i_lock);
772 if (atomic_read(&inode->i_count)) {
773 spin_unlock(&inode->i_lock);
777 inode->i_state |= I_FREEING;
778 inode_lru_list_del(inode);
779 spin_unlock(&inode->i_lock);
780 list_add(&inode->i_lru, &dispose);
794 * Isolate the inode from the LRU in preparation for freeing it.
796 * If the inode has the I_REFERENCED flag set, then it means that it has been
798 * inode, clear the flag and move it to the back of the LRU so it gets another
808 struct inode *inode = container_of(item, struct inode, i_lru);
811 * We are inverting the lru lock/inode->i_lock here, so use a
814 if (!spin_trylock(&inode->i_lock))
823 if (atomic_read(&inode->i_count) ||
824 (inode->i_state & ~I_REFERENCED) ||
825 !mapping_shrinkable(&inode->i_data)) {
826 list_lru_isolate(lru, &inode->i_lru);
827 spin_unlock(&inode->i_lock);
833 if (inode->i_state & I_REFERENCED) {
834 inode->i_state &= ~I_REFERENCED;
835 spin_unlock(&inode->i_lock);
844 if (inode_has_buffers(inode) || !mapping_empty(&inode->i_data)) {
845 __iget(inode);
846 spin_unlock(&inode->i_lock);
848 if (remove_inode_buffers(inode)) {
850 reap = invalidate_mapping_pages(&inode->i_data, 0, -1);
857 iput(inode);
862 WARN_ON(inode->i_state & I_NEW);
863 inode->i_state |= I_FREEING;
864 list_lru_isolate_move(lru, &inode->i_lru, freeable);
865 spin_unlock(&inode->i_lock);
872 * Walk the superblock inode LRU for freeable inodes and attempt to free them.
888 static void __wait_on_freeing_inode(struct inode *inode);
890 * Called with the inode lock held.
892 static struct inode *find_inode(struct super_block *sb,
894 int (*test)(struct inode *, void *),
897 struct inode *inode = NULL;
900 hlist_for_each_entry(inode, head, i_hash) {
901 if (inode->i_sb != sb)
903 if (!test(inode, data))
905 spin_lock(&inode->i_lock);
906 if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
907 __wait_on_freeing_inode(inode);
910 if (unlikely(inode->i_state & I_CREATING)) {
911 spin_unlock(&inode->i_lock);
914 __iget(inode);
915 spin_unlock(&inode->i_lock);
916 return inode;
925 static struct inode *find_inode_fast(struct super_block *sb,
928 struct inode *inode = NULL;
931 hlist_for_each_entry(inode, head, i_hash) {
932 if (inode->i_ino != ino)
934 if (inode->i_sb != sb)
936 spin_lock(&inode->i_lock);
937 if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
938 __wait_on_freeing_inode(inode);
941 if (unlikely(inode->i_state & I_CREATING)) {
942 spin_unlock(&inode->i_lock);
945 __iget(inode);
946 spin_unlock(&inode->i_lock);
947 return inode;
958 * consume at most LAST_INO_BATCH-1 unused inode numbers. So there is
985 /* get_next_ino should not provide a 0 inode number */
995 * new_inode_pseudo - obtain an inode
998 * Allocates a new inode for given superblock.
1004 struct inode *new_inode_pseudo(struct super_block *sb)
1006 struct inode *inode = alloc_inode(sb);
1008 if (inode) {
1009 spin_lock(&inode->i_lock);
1010 inode->i_state = 0;
1011 spin_unlock(&inode->i_lock);
1013 return inode;
1017 * new_inode - obtain an inode
1020 * Allocates a new inode for given superblock. The default gfp_mask
1021 * for allocations related to inode->i_mapping is GFP_HIGHUSER_MOVABLE.
1025 * newly created inode's mapping
1028 struct inode *new_inode(struct super_block *sb)
1030 struct inode *inode;
1032 inode = new_inode_pseudo(sb);
1033 if (inode)
1034 inode_sb_list_add(inode);
1035 return inode;
1040 void lockdep_annotate_inode_mutex_key(struct inode *inode)
1042 if (S_ISDIR(inode->i_mode)) {
1043 struct file_system_type *type = inode->i_sb->s_type;
1046 if (lockdep_match_class(&inode->i_rwsem, &type->i_mutex_key)) {
1050 // mutex_destroy(&inode->i_mutex);
1051 init_rwsem(&inode->i_rwsem);
1052 lockdep_set_class(&inode->i_rwsem,
1062 * @inode: new inode to unlock
1064 * Called when the inode is fully initialised to clear the new state of the
1065 * inode and wake up anyone waiting for the inode to finish initialisation.
1067 void unlock_new_inode(struct inode *inode)
1069 lockdep_annotate_inode_mutex_key(inode);
1070 spin_lock(&inode->i_lock);
1071 WARN_ON(!(inode->i_state & I_NEW));
1072 inode->i_state &= ~I_NEW & ~I_CREATING;
1074 wake_up_bit(&inode->i_state, __I_NEW);
1075 spin_unlock(&inode->i_lock);
1079 void discard_new_inode(struct inode *inode)
1081 lockdep_annotate_inode_mutex_key(inode);
1082 spin_lock(&inode->i_lock);
1083 WARN_ON(!(inode->i_state & I_NEW));
1084 inode->i_state &= ~I_NEW;
1086 wake_up_bit(&inode->i_state, __I_NEW);
1087 spin_unlock(&inode->i_lock);
1088 iput(inode);
1099 * @inode1: first inode to lock
1100 * @inode2: second inode to lock
1101 * @subclass1: inode lock subclass for the first lock obtained
1102 * @subclass2: inode lock subclass for the second lock obtained
1104 void lock_two_inodes(struct inode *inode1, struct inode *inode2,
1140 * @inode1: first inode to lock
1141 * @inode2: second inode to lock
1143 void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
1155 * @inode1: first inode to unlock
1156 * @inode2: second inode to unlock
1158 void unlock_two_nondirectories(struct inode *inode1, struct inode *inode2)
1172 * inode_insert5 - obtain an inode from a mounted file system
1173 * @inode: pre-allocated inode to use for insert to cache
1174 * @hashval: hash value (usually inode number) to get
1176 * @set: callback used to initialize a new struct inode
1179 * Search for the inode specified by @hashval and @data in the inode cache,
1182 * allocation of inode.
1184 * If the inode is not in cache, insert the pre-allocated inode to cache and
1191 struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
1192 int (*test)(struct inode *, void *),
1193 int (*set)(struct inode *, void *), void *data)
1195 struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
1196 struct inode *old;
1200 old = find_inode(inode->i_sb, head, test, data);
1203 * Uhhuh, somebody else created the same inode under us.
1204 * Use the old inode instead of the preallocated one.
1217 if (set && unlikely(set(inode, data))) {
1218 inode = NULL;
1223 * Return the locked inode with I_NEW set, the
1226 spin_lock(&inode->i_lock);
1227 inode->i_state |= I_NEW;
1228 hlist_add_head_rcu(&inode->i_hash, head);
1229 spin_unlock(&inode->i_lock);
1232 * Add inode to the sb list if it's not already. It has I_NEW at this
1235 if (list_empty(&inode->i_sb_list))
1236 inode_sb_list_add(inode);
1240 return inode;
1245 * iget5_locked - obtain an inode from a mounted file system
1247 * @hashval: hash value (usually inode number) to get
1249 * @set: callback used to initialize a new struct inode
1252 * Search for the inode specified by @hashval and @data in the inode cache,
1254 * a generalized version of iget_locked() for file systems where the inode
1255 * number is not sufficient for unique identification of an inode.
1257 * If the inode is not in cache, allocate a new inode and return it locked,
1264 struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
1265 int (*test)(struct inode *, void *),
1266 int (*set)(struct inode *, void *), void *data)
1268 struct inode *inode = ilookup5(sb, hashval, test, data);
1270 if (!inode) {
1271 struct inode *new = alloc_inode(sb);
1275 inode = inode_insert5(new, hashval, test, set, data);
1276 if (unlikely(inode != new))
1280 return inode;
1285 * iget_locked - obtain an inode from a mounted file system
1287 * @ino: inode number to get
1289 * Search for the inode specified by @ino in the inode cache and if present
1291 * where the inode number is sufficient for unique identification of an inode.
1293 * If the inode is not in cache, allocate a new inode and return it locked,
1297 struct inode *iget_locked(struct super_block *sb, unsigned long ino)
1300 struct inode *inode;
1303 inode = find_inode_fast(sb, head, ino);
1305 if (inode) {
1306 if (IS_ERR(inode))
1308 wait_on_inode(inode);
1309 if (unlikely(inode_unhashed(inode))) {
1310 iput(inode);
1313 return inode;
1316 inode = alloc_inode(sb);
1317 if (inode) {
1318 struct inode *old;
1324 inode->i_ino = ino;
1325 spin_lock(&inode->i_lock);
1326 inode->i_state = I_NEW;
1327 hlist_add_head_rcu(&inode->i_hash, head);
1328 spin_unlock(&inode->i_lock);
1329 inode_sb_list_add(inode);
1332 /* Return the locked inode with I_NEW set, the
1335 return inode;
1339 * Uhhuh, somebody else created the same inode under
1340 * us. Use the old inode instead of the one we just
1344 destroy_inode(inode);
1347 inode = old;
1348 wait_on_inode(inode);
1349 if (unlikely(inode_unhashed(inode))) {
1350 iput(inode);
1354 return inode;
1359 * search the inode cache for a matching inode number.
1360 * If we find one, then the inode number we are trying to
1363 * Returns 1 if the inode number is unique, 0 if it is not.
1368 struct inode *inode;
1370 hlist_for_each_entry_rcu(inode, b, i_hash) {
1371 if (inode->i_ino == ino && inode->i_sb == sb)
1378 * iunique - get a unique inode number
1380 * @max_reserved: highest reserved inode number
1382 * Obtain an inode number that is unique on the system for a given
1384 * permanent inode numbering system. An inode number is returned that
1416 struct inode *igrab(struct inode *inode)
1418 spin_lock(&inode->i_lock);
1419 if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) {
1420 __iget(inode);
1421 spin_unlock(&inode->i_lock);
1423 spin_unlock(&inode->i_lock);
1427 * while the inode is getting freed.
1429 inode = NULL;
1431 return inode;
1436 * ilookup5_nowait - search for an inode in the inode cache
1438 * @hashval: hash value (usually inode number) to search for
1442 * Search for the inode specified by @hashval and @data in the inode cache.
1443 * If the inode is in the cache, the inode is returned with an incremented
1447 * with the returned inode. You probably should be using ilookup5() instead.
1451 struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
1452 int (*test)(struct inode *, void *), void *data)
1455 struct inode *inode;
1458 inode = find_inode(sb, head, test, data);
1461 return IS_ERR(inode) ? NULL : inode;
1466 * ilookup5 - search for an inode in the inode cache
1468 * @hashval: hash value (usually inode number) to search for
1472 * Search for the inode specified by @hashval and @data in the inode cache,
1473 * and if the inode is in the cache, return the inode with an incremented
1474 * reference count. Waits on I_NEW before returning the inode.
1478 * inode number is not sufficient for unique identification of an inode.
1482 struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
1483 int (*test)(struct inode *, void *), void *data)
1485 struct inode *inode;
1487 inode = ilookup5_nowait(sb, hashval, test, data);
1488 if (inode) {
1489 wait_on_inode(inode);
1490 if (unlikely(inode_unhashed(inode))) {
1491 iput(inode);
1495 return inode;
1500 * ilookup - search for an inode in the inode cache
1502 * @ino: inode number to search for
1504 * Search for the inode @ino in the inode cache, and if the inode is in the
1505 * cache, the inode is returned with an incremented reference count.
1507 struct inode *ilookup(struct super_block *sb, unsigned long ino)
1510 struct inode *inode;
1513 inode = find_inode_fast(sb, head, ino);
1516 if (inode) {
1517 if (IS_ERR(inode))
1519 wait_on_inode(inode);
1520 if (unlikely(inode_unhashed(inode))) {
1521 iput(inode);
1525 return inode;
1530 * find_inode_nowait - find an inode in the inode cache
1532 * @hashval: hash value (usually inode number) to search for
1536 * Search for the inode specified by @hashval and @data in the inode
1537 * cache, where the helper function @match will return 0 if the inode
1538 * does not match, 1 if the inode does match, and -1 if the search
1540 * taking the i_lock spin_lock and checking i_state for an inode being
1549 * inode eviction. The tradeoff is that the @match funtion must be
1552 struct inode *find_inode_nowait(struct super_block *sb,
1554 int (*match)(struct inode *, unsigned long,
1559 struct inode *inode, *ret_inode = NULL;
1563 hlist_for_each_entry(inode, head, i_hash) {
1564 if (inode->i_sb != sb)
1566 mval = match(inode, hashval, data);
1570 ret_inode = inode;
1580 * find_inode_rcu - find an inode in the inode cache
1583 * @test: Function to test match on an inode
1586 * Search for the inode specified by @hashval and @data in the inode cache,
1587 * where the helper function @test will return 0 if the inode does not match
1589 * i_lock spin_lock and checking i_state for an inode being freed or being
1592 * If successful, this will return the inode for which the @test function
1595 * The @test function is not permitted to take a ref on any inode presented.
1600 struct inode *find_inode_rcu(struct super_block *sb, unsigned long hashval,
1601 int (*test)(struct inode *, void *), void *data)
1604 struct inode *inode;
1609 hlist_for_each_entry_rcu(inode, head, i_hash) {
1610 if (inode->i_sb == sb &&
1611 !(READ_ONCE(inode->i_state) & (I_FREEING | I_WILL_FREE)) &&
1612 test(inode, data))
1613 return inode;
1620 * find_inode_by_ino_rcu - Find an inode in the inode cache
1622 * @ino: The inode number to match
1624 * Search for the inode specified by @hashval and @data in the inode cache,
1625 * where the helper function @test will return 0 if the inode does not match
1627 * i_lock spin_lock and checking i_state for an inode being freed or being
1630 * If successful, this will return the inode for which the @test function
1633 * The @test function is not permitted to take a ref on any inode presented.
1638 struct inode *find_inode_by_ino_rcu(struct super_block *sb,
1642 struct inode *inode;
1647 hlist_for_each_entry_rcu(inode, head, i_hash) {
1648 if (inode->i_ino == ino &&
1649 inode->i_sb == sb &&
1650 !(READ_ONCE(inode->i_state) & (I_FREEING | I_WILL_FREE)))
1651 return inode;
1657 int insert_inode_locked(struct inode *inode)
1659 struct super_block *sb = inode->i_sb;
1660 ino_t ino = inode->i_ino;
1664 struct inode *old = NULL;
1679 spin_lock(&inode->i_lock);
1680 inode->i_state |= I_NEW | I_CREATING;
1681 hlist_add_head_rcu(&inode->i_hash, head);
1682 spin_unlock(&inode->i_lock);
1704 int insert_inode_locked4(struct inode *inode, unsigned long hashval,
1705 int (*test)(struct inode *, void *), void *data)
1707 struct inode *old;
1709 inode->i_state |= I_CREATING;
1710 old = inode_insert5(inode, hashval, test, NULL, data);
1712 if (old != inode) {
1721 int generic_delete_inode(struct inode *inode)
1729 * to an inode.
1733 * us to evict inode, do so. Otherwise, retain inode
1737 static void iput_final(struct inode *inode)
1739 struct super_block *sb = inode->i_sb;
1740 const struct super_operations *op = inode->i_sb->s_op;
1744 WARN_ON(inode->i_state & I_NEW);
1747 drop = op->drop_inode(inode);
1749 drop = generic_drop_inode(inode);
1752 !(inode->i_state & I_DONTCACHE) &&
1754 __inode_add_lru(inode, true);
1755 spin_unlock(&inode->i_lock);
1759 state = inode->i_state;
1761 WRITE_ONCE(inode->i_state, state | I_WILL_FREE);
1762 spin_unlock(&inode->i_lock);
1764 write_inode_now(inode, 1);
1766 spin_lock(&inode->i_lock);
1767 state = inode->i_state;
1772 WRITE_ONCE(inode->i_state, state | I_FREEING);
1773 if (!list_empty(&inode->i_lru))
1774 inode_lru_list_del(inode);
1775 spin_unlock(&inode->i_lock);
1777 evict(inode);
1781 * iput - put an inode
1782 * @inode: inode to put
1784 * Puts an inode, dropping its usage count. If the inode use count hits
1785 * zero, the inode is then freed and may also be destroyed.
1789 void iput(struct inode *inode)
1791 if (!inode)
1793 BUG_ON(inode->i_state & I_CLEAR);
1795 if (atomic_dec_and_lock(&inode->i_count, &inode->i_lock)) {
1796 if (inode->i_nlink && (inode->i_state & I_DIRTY_TIME)) {
1797 atomic_inc(&inode->i_count);
1798 spin_unlock(&inode->i_lock);
1799 trace_writeback_lazytime_iput(inode);
1800 mark_inode_dirty_sync(inode);
1803 iput_final(inode);
1811 * @inode: inode owning the block number being requested
1816 * That is, asked for block 4 of inode 1 the function will replace the
1823 int bmap(struct inode *inode, sector_t *block)
1825 if (!inode->i_mapping->a_ops->bmap)
1828 *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block);
1839 static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1849 if (timespec64_compare(&inode->i_mtime, &inode->i_atime) >= 0)
1854 ctime = inode_get_ctime(inode);
1855 if (timespec64_compare(&ctime, &inode->i_atime) >= 0)
1862 if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
1871 * inode_update_timestamps - update the timestamps on the inode
1872 * @inode: inode to be updated
1875 * The update_time function is called when an inode's timestamps need to be
1877 * actual timestamps. It's up to the caller to ensure that the inode is marked
1886 int inode_update_timestamps(struct inode *inode, int flags)
1892 struct timespec64 ctime = inode_get_ctime(inode);
1894 now = inode_set_ctime_current(inode);
1897 if (!timespec64_equal(&now, &inode->i_mtime)) {
1898 inode->i_mtime = now;
1901 if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated))
1904 now = current_time(inode);
1908 if (!timespec64_equal(&now, &inode->i_atime)) {
1909 inode->i_atime = now;
1918 * generic_update_time - update the timestamps on the inode
1919 * @inode: inode to be updated
1922 * The update_time function is called when an inode's timestamps need to be
1929 int generic_update_time(struct inode *inode, int flags)
1931 int updated = inode_update_timestamps(inode, flags);
1935 dirty_flags = inode->i_sb->s_flags & SB_LAZYTIME ? I_DIRTY_TIME : I_DIRTY_SYNC;
1938 __mark_inode_dirty(inode, dirty_flags);
1947 int inode_update_time(struct inode *inode, int flags)
1949 if (inode->i_op->update_time)
1950 return inode->i_op->update_time(inode, flags);
1951 generic_update_time(inode, flags);
1959 * @inode: inode to update
1961 * Update the accessed time on an inode and mark it for writeback.
1963 * as well as the "noatime" flag and inode specific "noatime" markers.
1965 bool atime_needs_update(const struct path *path, struct inode *inode)
1970 if (inode->i_flags & S_NOATIME)
1976 if (HAS_UNMAPPED_ID(mnt_idmap(mnt), inode))
1979 if (IS_NOATIME(inode))
1981 if ((inode->i_sb->s_flags & SB_NODIRATIME) && S_ISDIR(inode->i_mode))
1986 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1989 now = current_time(inode);
1991 if (!relatime_need_update(mnt, inode, now))
1994 if (timespec64_equal(&inode->i_atime, &now))
2003 struct inode *inode = d_inode(path->dentry);
2005 if (!atime_needs_update(path, inode))
2008 if (!sb_start_write_trylock(inode->i_sb))
2015 * allocate new space to modify an inode (such is the case for
2022 inode_update_time(inode, S_ATIME);
2025 sb_end_write(inode->i_sb);
2037 struct inode *inode = d_inode(dentry);
2041 if (IS_NOSEC(inode))
2044 mask = setattr_should_drop_suidgid(idmap, inode);
2069 struct inode *inode = file_inode(file);
2073 if (IS_NOSEC(inode) || !S_ISREG(inode->i_mode))
2088 inode_has_no_xattr(inode);
2107 static int inode_needs_update_time(struct inode *inode)
2110 struct timespec64 now = current_time(inode);
2114 if (IS_NOCMTIME(inode))
2117 if (!timespec64_equal(&inode->i_mtime, &now))
2120 ctime = inode_get_ctime(inode);
2124 if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode))
2133 struct inode *inode = file_inode(file);
2137 ret = inode_update_time(inode, sync_mode);
2148 * Update the mtime and ctime members of an inode and mark the inode for
2151 * explicitly ignore updates via this function with the _NOCMTIME inode
2154 * allocate space in order to update an inode.
2161 struct inode *inode = file_inode(file);
2163 ret = inode_needs_update_time(inode);
2182 * Context: Caller must hold the file's inode lock.
2189 struct inode *inode = file_inode(file);
2202 ret = inode_needs_update_time(inode);
2218 * Context: Caller must hold the file's inode lock.
2235 * Context: Caller must hold the file's inode lock.
2245 int inode_needs_sync(struct inode *inode)
2247 if (IS_SYNC(inode))
2249 if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode))
2256 * If we try to find an inode in the inode hash while it is being
2260 * to recheck inode state.
2263 * wake_up_bit(&inode->i_state, __I_NEW) after removing from the hash list
2266 static void __wait_on_freeing_inode(struct inode *inode)
2269 DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW);
2270 wq = bit_waitqueue(&inode->i_state, __I_NEW);
2272 spin_unlock(&inode->i_lock);
2290 * Initialize the waitqueues and inode hash table.
2314 /* inode slab cache */
2316 sizeof(struct inode),
2338 void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
2340 inode->i_mode = mode;
2342 inode->i_fop = &def_chr_fops;
2343 inode->i_rdev = rdev;
2346 inode->i_fop = &def_blk_fops;
2347 inode->i_rdev = rdev;
2349 inode->i_fop = &pipefifo_fops;
2354 " inode %s:%lu\n", mode, inode->i_sb->s_id,
2355 inode->i_ino);
2360 * inode_init_owner - Init uid,gid,mode for new inode according to posix standards
2361 * @idmap: idmap of the mount the inode was created from
2362 * @inode: New inode
2363 * @dir: Directory inode
2364 * @mode: mode of the new inode
2366 * If the inode has been created through an idmapped mount the idmap of
2368 * care to map the inode according to @idmap before checking permissions
2370 * checking is to be performed on the raw inode simply pass @nop_mnt_idmap.
2372 void inode_init_owner(struct mnt_idmap *idmap, struct inode *inode,
2373 const struct inode *dir, umode_t mode)
2375 inode_fsuid_set(inode, idmap);
2377 inode->i_gid = dir->i_gid;
2383 inode_fsgid_set(inode, idmap);
2384 inode->i_mode = mode;
2389 * inode_owner_or_capable - check current task permissions to inode
2390 * @idmap: idmap of the mount the inode was found from
2391 * @inode: inode being checked
2394 * inode owner uid mapped, or owns the file.
2396 * If the inode has been found through an idmapped mount the idmap of
2398 * care to map the inode according to @idmap before checking permissions.
2400 * raw inode simply passs @nop_mnt_idmap.
2403 const struct inode *inode)
2408 vfsuid = i_uid_into_vfsuid(idmap, inode);
2422 static void __inode_dio_wait(struct inode *inode)
2424 wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_DIO_WAKEUP);
2425 DEFINE_WAIT_BIT(q, &inode->i_state, __I_DIO_WAKEUP);
2429 if (atomic_read(&inode->i_dio_count))
2431 } while (atomic_read(&inode->i_dio_count));
2437 * @inode: inode to wait for
2443 * to i_dio_count, usually by inode->i_mutex.
2445 void inode_dio_wait(struct inode *inode)
2447 if (atomic_read(&inode->i_dio_count))
2448 __inode_dio_wait(inode);
2453 * inode_set_flags - atomically set some inode flags
2456 * they have exclusive access to the inode structure (i.e., while the
2457 * inode is being instantiated). The reason for the cmpxchg() loop
2468 void inode_set_flags(struct inode *inode, unsigned int flags,
2472 set_mask_bits(&inode->i_flags, mask, flags);
2476 void inode_nohighmem(struct inode *inode)
2478 mapping_set_gfp_mask(inode->i_mapping, GFP_USER);
2485 * @inode: inode being updated
2488 * containing the inode. Always rounds down. gran must
2491 struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode)
2493 struct super_block *sb = inode->i_sb;
2515 * @inode: inode.
2520 * Note that inode and inode->sb cannot be NULL.
2523 struct timespec64 current_time(struct inode *inode)
2528 return timestamp_truncate(now, inode);
2534 * @inode: inode
2536 * Set the inode->i_ctime to the current value for the inode. Returns
2539 struct timespec64 inode_set_ctime_current(struct inode *inode)
2541 struct timespec64 now = current_time(inode);
2543 inode_set_ctime(inode, now.tv_sec, now.tv_nsec);
2550 * @idmap: idmap of the mount @inode was found from
2551 * @inode: inode to check
2552 * @vfsgid: the new/current vfsgid of @inode
2555 * privileged with CAP_FSETID over @inode. This can be used to determine
2561 const struct inode *inode, vfsgid_t vfsgid)
2565 if (capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
2572 * @idmap: idmap of the mount the inode was created from
2573 * @dir: parent directory inode
2585 const struct inode *dir, umode_t mode)