Lines Matching refs:inode

3  * NILFS inode operations.
29 * @ino: inode number
32 * @type: inode type
41 static int nilfs_iget_test(struct inode *inode, void *opaque);
43 void nilfs_inode_add_blocks(struct inode *inode, int n)
45 struct nilfs_root *root = NILFS_I(inode)->i_root;
47 inode_add_bytes(inode, i_blocksize(inode) * n);
52 void nilfs_inode_sub_blocks(struct inode *inode, int n)
54 struct nilfs_root *root = NILFS_I(inode)->i_root;
56 inode_sub_bytes(inode, i_blocksize(inode) * n);
63 * @inode: inode struct of the target file
72 int nilfs_get_block(struct inode *inode, sector_t blkoff,
75 struct nilfs_inode_info *ii = NILFS_I(inode);
76 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
79 unsigned int maxblocks = bh_result->b_size >> inode->i_blkbits;
85 map_bh(bh_result, inode->i_sb, blknum);
87 bh_result->b_size = (ret << inode->i_blkbits);
95 err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
104 * from multiple callers for an inode.
108 nilfs_warn(inode->i_sb,
110 __func__, inode->i_ino,
114 nilfs_transaction_abort(inode->i_sb);
117 nilfs_mark_inode_dirty_sync(inode);
118 nilfs_transaction_commit(inode->i_sb); /* never fails */
122 map_bh(bh_result, inode->i_sb, 0);
158 struct inode *inode = mapping->host;
161 if (sb_rdonly(inode->i_sb)) {
167 err = nilfs_construct_dsync_segment(inode->i_sb, inode,
176 struct inode *inode = folio->mapping->host;
179 if (sb_rdonly(inode->i_sb)) {
195 err = nilfs_construct_segment(inode->i_sb);
199 nilfs_flush_segment(inode->i_sb, inode->i_ino);
207 struct inode *inode = mapping->host;
229 nr_dirty = 1 << (folio_shift(folio) - inode->i_blkbits);
234 nilfs_set_file_dirty(inode, nr_dirty);
240 struct inode *inode = mapping->host;
242 if (to > inode->i_size) {
243 truncate_pagecache(inode, inode->i_size);
244 nilfs_truncate(inode);
253 struct inode *inode = mapping->host;
254 int err = nilfs_transaction_begin(inode->i_sb, NULL, 1);
262 nilfs_transaction_abort(inode->i_sb);
271 struct inode *inode = mapping->host;
280 nilfs_set_file_dirty(inode, nr_dirty);
281 err = nilfs_transaction_commit(inode->i_sb);
288 struct inode *inode = file_inode(iocb->ki_filp);
294 return blockdev_direct_IO(iocb, inode, iter, nilfs_get_block);
310 static int nilfs_insert_inode_locked(struct inode *inode,
318 return insert_inode_locked4(inode, ino, nilfs_iget_test, &args);
321 struct inode *nilfs_new_inode(struct inode *dir, umode_t mode)
324 struct inode *inode;
331 inode = new_inode(sb);
332 if (unlikely(!inode))
335 mapping_set_gfp_mask(inode->i_mapping,
336 mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS));
339 ii = NILFS_I(inode);
351 inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
352 inode->i_ino = ino;
353 simple_inode_init_ts(inode);
370 nilfs_set_inode_flags(inode);
371 inode->i_generation = get_random_u32();
372 if (nilfs_insert_inode_locked(inode, root, ino) < 0) {
377 err = nilfs_init_acl(inode, dir);
385 return inode;
388 clear_nlink(inode);
389 if (inode->i_state & I_NEW)
390 unlock_new_inode(inode);
391 iput(inode); /*
398 make_bad_inode(inode);
399 iput(inode);
404 void nilfs_set_inode_flags(struct inode *inode)
406 unsigned int flags = NILFS_I(inode)->i_flags;
419 inode_set_flags(inode, new_fl, S_SYNC | S_APPEND | S_IMMUTABLE |
423 int nilfs_read_inode_common(struct inode *inode,
426 struct nilfs_inode_info *ii = NILFS_I(inode);
429 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
430 i_uid_write(inode, le32_to_cpu(raw_inode->i_uid));
431 i_gid_write(inode, le32_to_cpu(raw_inode->i_gid));
432 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
433 inode->i_size = le64_to_cpu(raw_inode->i_size);
434 inode_set_atime(inode, le64_to_cpu(raw_inode->i_mtime),
436 inode_set_ctime(inode, le64_to_cpu(raw_inode->i_ctime),
438 inode_set_mtime(inode, le64_to_cpu(raw_inode->i_mtime),
440 if (nilfs_is_metadata_file_inode(inode) && !S_ISREG(inode->i_mode))
441 return -EIO; /* this inode is for metadata and corrupted */
442 if (inode->i_nlink == 0)
443 return -ESTALE; /* this inode is deleted */
445 inode->i_blocks = le64_to_cpu(raw_inode->i_blocks);
449 ii->i_dir_acl = S_ISREG(inode->i_mode) ?
453 inode->i_generation = le32_to_cpu(raw_inode->i_generation);
455 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
456 S_ISLNK(inode->i_mode)) {
468 struct inode *inode)
482 err = nilfs_read_inode_common(inode, raw_inode);
486 if (S_ISREG(inode->i_mode)) {
487 inode->i_op = &nilfs_file_inode_operations;
488 inode->i_fop = &nilfs_file_operations;
489 inode->i_mapping->a_ops = &nilfs_aops;
490 } else if (S_ISDIR(inode->i_mode)) {
491 inode->i_op = &nilfs_dir_inode_operations;
492 inode->i_fop = &nilfs_dir_operations;
493 inode->i_mapping->a_ops = &nilfs_aops;
494 } else if (S_ISLNK(inode->i_mode)) {
495 inode->i_op = &nilfs_symlink_inode_operations;
496 inode_nohighmem(inode);
497 inode->i_mapping->a_ops = &nilfs_aops;
499 inode->i_op = &nilfs_special_inode_operations;
501 inode, inode->i_mode,
507 nilfs_set_inode_flags(inode);
508 mapping_set_gfp_mask(inode->i_mapping,
509 mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS));
521 static int nilfs_iget_test(struct inode *inode, void *opaque)
526 if (args->ino != inode->i_ino || args->root != NILFS_I(inode)->i_root)
529 ii = NILFS_I(inode);
536 static int nilfs_iget_set(struct inode *inode, void *opaque)
540 inode->i_ino = args->ino;
541 NILFS_I(inode)->i_cno = args->cno;
542 NILFS_I(inode)->i_root = args->root;
543 NILFS_I(inode)->i_type = args->type;
549 struct inode *nilfs_ilookup(struct super_block *sb, struct nilfs_root *root,
559 struct inode *nilfs_iget_locked(struct super_block *sb, struct nilfs_root *root,
569 struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
572 struct inode *inode;
575 inode = nilfs_iget_locked(sb, root, ino);
576 if (unlikely(!inode))
578 if (!(inode->i_state & I_NEW))
579 return inode;
581 err = __nilfs_read_inode(sb, root, ino, inode);
583 iget_failed(inode);
586 unlock_new_inode(inode);
587 return inode;
590 struct inode *nilfs_iget_for_gc(struct super_block *sb, unsigned long ino,
596 struct inode *inode;
599 inode = iget5_locked(sb, ino, nilfs_iget_test, nilfs_iget_set, &args);
600 if (unlikely(!inode))
602 if (!(inode->i_state & I_NEW))
603 return inode;
605 err = nilfs_init_gcinode(inode);
607 iget_failed(inode);
610 unlock_new_inode(inode);
611 return inode;
615 * nilfs_attach_btree_node_cache - attach a B-tree node cache to the inode
616 * @inode: inode object
618 * nilfs_attach_btree_node_cache() attaches a B-tree node cache to @inode,
619 * or does nothing if the inode already has it. This function allocates
620 * an additional inode to maintain page cache of B-tree nodes one-on-one.
627 int nilfs_attach_btree_node_cache(struct inode *inode)
629 struct nilfs_inode_info *ii = NILFS_I(inode);
630 struct inode *btnc_inode;
636 args.ino = inode->i_ino;
641 btnc_inode = iget5_locked(inode->i_sb, inode->i_ino, nilfs_iget_test,
649 NILFS_I(btnc_inode)->i_assoc_inode = inode;
657 * nilfs_detach_btree_node_cache - detach the B-tree node cache from the inode
658 * @inode: inode object
661 * holder inode bound to @inode, or does nothing if @inode doesn't have it.
663 void nilfs_detach_btree_node_cache(struct inode *inode)
665 struct nilfs_inode_info *ii = NILFS_I(inode);
666 struct inode *btnc_inode = ii->i_assoc_inode;
676 * nilfs_iget_for_shadow - obtain inode for shadow mapping
677 * @inode: inode object that uses shadow mapping
681 * in one inode and the one for b-tree node pages is set up in the
682 * other inode, which is attached to the former inode.
684 * Return Value: On success, a pointer to the inode for data pages is
690 struct inode *nilfs_iget_for_shadow(struct inode *inode)
693 .ino = inode->i_ino, .root = NULL, .cno = 0,
696 struct inode *s_inode;
699 s_inode = iget5_locked(inode->i_sb, inode->i_ino, nilfs_iget_test,
704 return inode;
720 * nilfs_write_inode_common - export common inode information to on-disk inode
721 * @inode: inode object
722 * @raw_inode: on-disk inode
724 * This function writes standard information from the on-memory inode @inode
725 * to @raw_inode on ifile, cpfile or a super root block. Since inode bmap
729 void nilfs_write_inode_common(struct inode *inode,
732 struct nilfs_inode_info *ii = NILFS_I(inode);
734 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
735 raw_inode->i_uid = cpu_to_le32(i_uid_read(inode));
736 raw_inode->i_gid = cpu_to_le32(i_gid_read(inode));
737 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
738 raw_inode->i_size = cpu_to_le64(inode->i_size);
739 raw_inode->i_ctime = cpu_to_le64(inode_get_ctime_sec(inode));
740 raw_inode->i_mtime = cpu_to_le64(inode_get_mtime_sec(inode));
741 raw_inode->i_ctime_nsec = cpu_to_le32(inode_get_ctime_nsec(inode));
742 raw_inode->i_mtime_nsec = cpu_to_le32(inode_get_mtime_nsec(inode));
743 raw_inode->i_blocks = cpu_to_le64(inode->i_blocks);
746 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
749 * When extending inode, nilfs->ns_inode_size should be checked
754 void nilfs_update_inode(struct inode *inode, struct buffer_head *ibh, int flags)
756 ino_t ino = inode->i_ino;
757 struct nilfs_inode_info *ii = NILFS_I(inode);
758 struct inode *ifile = ii->i_root->ifile;
768 nilfs_write_inode_common(inode, raw_inode);
770 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
772 cpu_to_le64(huge_encode_dev(inode->i_rdev));
809 void nilfs_truncate(struct inode *inode)
814 struct super_block *sb = inode->i_sb;
815 struct nilfs_inode_info *ii = NILFS_I(inode);
819 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
823 blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
826 block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
830 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
831 if (IS_SYNC(inode))
834 nilfs_mark_inode_dirty(inode);
835 nilfs_set_file_dirty(inode, 0);
843 static void nilfs_clear_inode(struct inode *inode)
845 struct nilfs_inode_info *ii = NILFS_I(inode);
854 if (nilfs_is_metadata_file_inode(inode))
855 nilfs_mdt_clear(inode);
861 nilfs_detach_btree_node_cache(inode);
863 if (ii->i_root && inode->i_ino == NILFS_ROOT_INO)
867 void nilfs_evict_inode(struct inode *inode)
870 struct super_block *sb = inode->i_sb;
871 struct nilfs_inode_info *ii = NILFS_I(inode);
875 if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) {
876 truncate_inode_pages_final(&inode->i_data);
877 clear_inode(inode);
878 nilfs_clear_inode(inode);
883 truncate_inode_pages_final(&inode->i_data);
888 * If this inode is about to be disposed after the file system
896 clear_inode(inode);
897 nilfs_clear_inode(inode);
904 nilfs_mark_inode_dirty(inode);
905 clear_inode(inode);
907 ret = nilfs_ifile_delete_inode(ii->i_root->ifile, inode->i_ino);
911 nilfs_clear_inode(inode);
913 if (IS_SYNC(inode))
926 struct inode *inode = d_inode(dentry);
927 struct super_block *sb = inode->i_sb;
939 iattr->ia_size != i_size_read(inode)) {
940 inode_dio_wait(inode);
941 truncate_setsize(inode, iattr->ia_size);
942 nilfs_truncate(inode);
945 setattr_copy(&nop_mnt_idmap, inode, iattr);
946 mark_inode_dirty(inode);
949 err = nilfs_acl_chmod(inode);
961 int nilfs_permission(struct mnt_idmap *idmap, struct inode *inode,
964 struct nilfs_root *root = NILFS_I(inode)->i_root;
970 return generic_permission(&nop_mnt_idmap, inode, mask);
973 int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
975 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
976 struct nilfs_inode_info *ii = NILFS_I(inode);
983 inode->i_ino, pbh);
1004 int nilfs_inode_dirty(struct inode *inode)
1006 struct nilfs_inode_info *ii = NILFS_I(inode);
1007 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
1019 int nilfs_set_file_dirty(struct inode *inode, unsigned int nr_dirty)
1021 struct nilfs_inode_info *ii = NILFS_I(inode);
1022 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
1036 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) {
1039 * this inode.
1041 nilfs_warn(inode->i_sb,
1043 inode->i_ino);
1047 * freeing inode.
1057 int __nilfs_mark_inode_dirty(struct inode *inode, int flags)
1059 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
1070 err = nilfs_load_inode_block(inode, &ibh);
1072 nilfs_warn(inode->i_sb,
1073 "cannot mark inode dirty (ino=%lu): error %d loading inode block",
1074 inode->i_ino, err);
1077 nilfs_update_inode(inode, ibh, flags);
1079 nilfs_mdt_mark_dirty(NILFS_I(inode)->i_root->ifile);
1085 * nilfs_dirty_inode - reflect changes on given inode to an inode block.
1086 * @inode: inode of the file to be registered.
1087 * @flags: flags to determine the dirty state of the inode
1089 * nilfs_dirty_inode() loads a inode block containing the specified
1090 * @inode and copies data from a nilfs_inode to a corresponding inode
1091 * entry in the inode block. This operation is excluded from the segment
1095 void nilfs_dirty_inode(struct inode *inode, int flags)
1098 struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
1100 if (is_bad_inode(inode)) {
1101 nilfs_warn(inode->i_sb,
1107 nilfs_mdt_mark_dirty(inode);
1110 nilfs_transaction_begin(inode->i_sb, &ti, 0);
1111 __nilfs_mark_inode_dirty(inode, flags);
1112 nilfs_transaction_commit(inode->i_sb); /* never fails */
1115 int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1118 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
1125 unsigned int blkbits = inode->i_blkbits;
1128 ret = fiemap_prep(inode, fieinfo, start, &len, 0);
1132 inode_lock(inode);
1134 isize = i_size_read(inode);
1139 delalloc_blklen = nilfs_find_uncommitted_extent(inode, blkoff,
1164 inode, blkoff, &delalloc_blkoff);
1180 NILFS_I(inode)->i_bmap, blkoff, &blkphy, maxblocks);
1242 inode_unlock(inode);