aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nilfs2/inode.c')
-rw-r--r--fs/nilfs2/inode.c84
1 files changed, 49 insertions, 35 deletions
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 2fd440d8d6b8..c0aa27490c02 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -41,6 +41,24 @@ struct nilfs_iget_args {
41 int for_gc; 41 int for_gc;
42}; 42};
43 43
44void nilfs_inode_add_blocks(struct inode *inode, int n)
45{
46 struct nilfs_root *root = NILFS_I(inode)->i_root;
47
48 inode_add_bytes(inode, (1 << inode->i_blkbits) * n);
49 if (root)
50 atomic_add(n, &root->blocks_count);
51}
52
53void nilfs_inode_sub_blocks(struct inode *inode, int n)
54{
55 struct nilfs_root *root = NILFS_I(inode)->i_root;
56
57 inode_sub_bytes(inode, (1 << inode->i_blkbits) * n);
58 if (root)
59 atomic_sub(n, &root->blocks_count);
60}
61
44/** 62/**
45 * nilfs_get_block() - get a file block on the filesystem (callback function) 63 * nilfs_get_block() - get a file block on the filesystem (callback function)
46 * @inode - inode struct of the target file 64 * @inode - inode struct of the target file
@@ -262,7 +280,6 @@ nilfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
262const struct address_space_operations nilfs_aops = { 280const struct address_space_operations nilfs_aops = {
263 .writepage = nilfs_writepage, 281 .writepage = nilfs_writepage,
264 .readpage = nilfs_readpage, 282 .readpage = nilfs_readpage,
265 .sync_page = block_sync_page,
266 .writepages = nilfs_writepages, 283 .writepages = nilfs_writepages,
267 .set_page_dirty = nilfs_set_page_dirty, 284 .set_page_dirty = nilfs_set_page_dirty,
268 .readpages = nilfs_readpages, 285 .readpages = nilfs_readpages,
@@ -277,7 +294,7 @@ const struct address_space_operations nilfs_aops = {
277struct inode *nilfs_new_inode(struct inode *dir, int mode) 294struct inode *nilfs_new_inode(struct inode *dir, int mode)
278{ 295{
279 struct super_block *sb = dir->i_sb; 296 struct super_block *sb = dir->i_sb;
280 struct nilfs_sb_info *sbi = NILFS_SB(sb); 297 struct the_nilfs *nilfs = sb->s_fs_info;
281 struct inode *inode; 298 struct inode *inode;
282 struct nilfs_inode_info *ii; 299 struct nilfs_inode_info *ii;
283 struct nilfs_root *root; 300 struct nilfs_root *root;
@@ -315,19 +332,16 @@ struct inode *nilfs_new_inode(struct inode *dir, int mode)
315 /* No lock is needed; iget() ensures it. */ 332 /* No lock is needed; iget() ensures it. */
316 } 333 }
317 334
318 ii->i_flags = NILFS_I(dir)->i_flags; 335 ii->i_flags = nilfs_mask_flags(
319 if (S_ISLNK(mode)) 336 mode, NILFS_I(dir)->i_flags & NILFS_FL_INHERITED);
320 ii->i_flags &= ~(NILFS_IMMUTABLE_FL | NILFS_APPEND_FL);
321 if (!S_ISDIR(mode))
322 ii->i_flags &= ~NILFS_DIRSYNC_FL;
323 337
324 /* ii->i_file_acl = 0; */ 338 /* ii->i_file_acl = 0; */
325 /* ii->i_dir_acl = 0; */ 339 /* ii->i_dir_acl = 0; */
326 ii->i_dir_start_lookup = 0; 340 ii->i_dir_start_lookup = 0;
327 nilfs_set_inode_flags(inode); 341 nilfs_set_inode_flags(inode);
328 spin_lock(&sbi->s_next_gen_lock); 342 spin_lock(&nilfs->ns_next_gen_lock);
329 inode->i_generation = sbi->s_next_generation++; 343 inode->i_generation = nilfs->ns_next_generation++;
330 spin_unlock(&sbi->s_next_gen_lock); 344 spin_unlock(&nilfs->ns_next_gen_lock);
331 insert_inode_hash(inode); 345 insert_inode_hash(inode);
332 346
333 err = nilfs_init_acl(inode, dir); 347 err = nilfs_init_acl(inode, dir);
@@ -359,17 +373,15 @@ void nilfs_set_inode_flags(struct inode *inode)
359 373
360 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | 374 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
361 S_DIRSYNC); 375 S_DIRSYNC);
362 if (flags & NILFS_SYNC_FL) 376 if (flags & FS_SYNC_FL)
363 inode->i_flags |= S_SYNC; 377 inode->i_flags |= S_SYNC;
364 if (flags & NILFS_APPEND_FL) 378 if (flags & FS_APPEND_FL)
365 inode->i_flags |= S_APPEND; 379 inode->i_flags |= S_APPEND;
366 if (flags & NILFS_IMMUTABLE_FL) 380 if (flags & FS_IMMUTABLE_FL)
367 inode->i_flags |= S_IMMUTABLE; 381 inode->i_flags |= S_IMMUTABLE;
368#ifndef NILFS_ATIME_DISABLE 382 if (flags & FS_NOATIME_FL)
369 if (flags & NILFS_NOATIME_FL)
370#endif
371 inode->i_flags |= S_NOATIME; 383 inode->i_flags |= S_NOATIME;
372 if (flags & NILFS_DIRSYNC_FL) 384 if (flags & FS_DIRSYNC_FL)
373 inode->i_flags |= S_DIRSYNC; 385 inode->i_flags |= S_DIRSYNC;
374 mapping_set_gfp_mask(inode->i_mapping, 386 mapping_set_gfp_mask(inode->i_mapping,
375 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 387 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
@@ -420,7 +432,7 @@ static int __nilfs_read_inode(struct super_block *sb,
420 struct nilfs_root *root, unsigned long ino, 432 struct nilfs_root *root, unsigned long ino,
421 struct inode *inode) 433 struct inode *inode)
422{ 434{
423 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs; 435 struct the_nilfs *nilfs = sb->s_fs_info;
424 struct buffer_head *bh; 436 struct buffer_head *bh;
425 struct nilfs_inode *raw_inode; 437 struct nilfs_inode *raw_inode;
426 int err; 438 int err;
@@ -707,6 +719,7 @@ void nilfs_evict_inode(struct inode *inode)
707 struct nilfs_transaction_info ti; 719 struct nilfs_transaction_info ti;
708 struct super_block *sb = inode->i_sb; 720 struct super_block *sb = inode->i_sb;
709 struct nilfs_inode_info *ii = NILFS_I(inode); 721 struct nilfs_inode_info *ii = NILFS_I(inode);
722 int ret;
710 723
711 if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) { 724 if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) {
712 if (inode->i_data.nrpages) 725 if (inode->i_data.nrpages)
@@ -725,8 +738,9 @@ void nilfs_evict_inode(struct inode *inode)
725 nilfs_mark_inode_dirty(inode); 738 nilfs_mark_inode_dirty(inode);
726 end_writeback(inode); 739 end_writeback(inode);
727 740
728 nilfs_ifile_delete_inode(ii->i_root->ifile, inode->i_ino); 741 ret = nilfs_ifile_delete_inode(ii->i_root->ifile, inode->i_ino);
729 atomic_dec(&ii->i_root->inodes_count); 742 if (!ret)
743 atomic_dec(&ii->i_root->inodes_count);
730 744
731 nilfs_clear_inode(inode); 745 nilfs_clear_inode(inode);
732 746
@@ -792,18 +806,18 @@ int nilfs_permission(struct inode *inode, int mask, unsigned int flags)
792 806
793int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh) 807int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
794{ 808{
795 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb); 809 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
796 struct nilfs_inode_info *ii = NILFS_I(inode); 810 struct nilfs_inode_info *ii = NILFS_I(inode);
797 int err; 811 int err;
798 812
799 spin_lock(&sbi->s_inode_lock); 813 spin_lock(&nilfs->ns_inode_lock);
800 if (ii->i_bh == NULL) { 814 if (ii->i_bh == NULL) {
801 spin_unlock(&sbi->s_inode_lock); 815 spin_unlock(&nilfs->ns_inode_lock);
802 err = nilfs_ifile_get_inode_block(ii->i_root->ifile, 816 err = nilfs_ifile_get_inode_block(ii->i_root->ifile,
803 inode->i_ino, pbh); 817 inode->i_ino, pbh);
804 if (unlikely(err)) 818 if (unlikely(err))
805 return err; 819 return err;
806 spin_lock(&sbi->s_inode_lock); 820 spin_lock(&nilfs->ns_inode_lock);
807 if (ii->i_bh == NULL) 821 if (ii->i_bh == NULL)
808 ii->i_bh = *pbh; 822 ii->i_bh = *pbh;
809 else { 823 else {
@@ -814,36 +828,36 @@ int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh)
814 *pbh = ii->i_bh; 828 *pbh = ii->i_bh;
815 829
816 get_bh(*pbh); 830 get_bh(*pbh);
817 spin_unlock(&sbi->s_inode_lock); 831 spin_unlock(&nilfs->ns_inode_lock);
818 return 0; 832 return 0;
819} 833}
820 834
821int nilfs_inode_dirty(struct inode *inode) 835int nilfs_inode_dirty(struct inode *inode)
822{ 836{
823 struct nilfs_inode_info *ii = NILFS_I(inode); 837 struct nilfs_inode_info *ii = NILFS_I(inode);
824 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb); 838 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
825 int ret = 0; 839 int ret = 0;
826 840
827 if (!list_empty(&ii->i_dirty)) { 841 if (!list_empty(&ii->i_dirty)) {
828 spin_lock(&sbi->s_inode_lock); 842 spin_lock(&nilfs->ns_inode_lock);
829 ret = test_bit(NILFS_I_DIRTY, &ii->i_state) || 843 ret = test_bit(NILFS_I_DIRTY, &ii->i_state) ||
830 test_bit(NILFS_I_BUSY, &ii->i_state); 844 test_bit(NILFS_I_BUSY, &ii->i_state);
831 spin_unlock(&sbi->s_inode_lock); 845 spin_unlock(&nilfs->ns_inode_lock);
832 } 846 }
833 return ret; 847 return ret;
834} 848}
835 849
836int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty) 850int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty)
837{ 851{
838 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
839 struct nilfs_inode_info *ii = NILFS_I(inode); 852 struct nilfs_inode_info *ii = NILFS_I(inode);
853 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
840 854
841 atomic_add(nr_dirty, &sbi->s_nilfs->ns_ndirtyblks); 855 atomic_add(nr_dirty, &nilfs->ns_ndirtyblks);
842 856
843 if (test_and_set_bit(NILFS_I_DIRTY, &ii->i_state)) 857 if (test_and_set_bit(NILFS_I_DIRTY, &ii->i_state))
844 return 0; 858 return 0;
845 859
846 spin_lock(&sbi->s_inode_lock); 860 spin_lock(&nilfs->ns_inode_lock);
847 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && 861 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
848 !test_bit(NILFS_I_BUSY, &ii->i_state)) { 862 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
849 /* Because this routine may race with nilfs_dispose_list(), 863 /* Because this routine may race with nilfs_dispose_list(),
@@ -851,18 +865,18 @@ int nilfs_set_file_dirty(struct inode *inode, unsigned nr_dirty)
851 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) { 865 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) {
852 /* This will happen when somebody is freeing 866 /* This will happen when somebody is freeing
853 this inode. */ 867 this inode. */
854 nilfs_warning(sbi->s_super, __func__, 868 nilfs_warning(inode->i_sb, __func__,
855 "cannot get inode (ino=%lu)\n", 869 "cannot get inode (ino=%lu)\n",
856 inode->i_ino); 870 inode->i_ino);
857 spin_unlock(&sbi->s_inode_lock); 871 spin_unlock(&nilfs->ns_inode_lock);
858 return -EINVAL; /* NILFS_I_DIRTY may remain for 872 return -EINVAL; /* NILFS_I_DIRTY may remain for
859 freeing inode */ 873 freeing inode */
860 } 874 }
861 list_del(&ii->i_dirty); 875 list_del(&ii->i_dirty);
862 list_add_tail(&ii->i_dirty, &sbi->s_dirty_files); 876 list_add_tail(&ii->i_dirty, &nilfs->ns_dirty_files);
863 set_bit(NILFS_I_QUEUED, &ii->i_state); 877 set_bit(NILFS_I_QUEUED, &ii->i_state);
864 } 878 }
865 spin_unlock(&sbi->s_inode_lock); 879 spin_unlock(&nilfs->ns_inode_lock);
866 return 0; 880 return 0;
867} 881}
868 882