inode.c (ea77f7a2e8561012cf100c530170f12351c3b53e) inode.c (aa38572954ade525817fe88c54faebf85e5a61c0)
1/*
2 * inode.c - NILFS inode operations.
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 60 unchanged lines hidden (view full) ---

69 *
70 * This function does not issue actual read request of the specified data
71 * block. It is done by VFS.
72 */
73int nilfs_get_block(struct inode *inode, sector_t blkoff,
74 struct buffer_head *bh_result, int create)
75{
76 struct nilfs_inode_info *ii = NILFS_I(inode);
1/*
2 * inode.c - NILFS inode operations.
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 60 unchanged lines hidden (view full) ---

69 *
70 * This function does not issue actual read request of the specified data
71 * block. It is done by VFS.
72 */
73int nilfs_get_block(struct inode *inode, sector_t blkoff,
74 struct buffer_head *bh_result, int create)
75{
76 struct nilfs_inode_info *ii = NILFS_I(inode);
77 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
77 __u64 blknum = 0;
78 int err = 0, ret;
78 __u64 blknum = 0;
79 int err = 0, ret;
79 struct inode *dat = NILFS_I_NILFS(inode)->ns_dat;
80 unsigned maxblocks = bh_result->b_size >> inode->i_blkbits;
81
80 unsigned maxblocks = bh_result->b_size >> inode->i_blkbits;
81
82 down_read(&NILFS_MDT(dat)->mi_sem);
82 down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
83 ret = nilfs_bmap_lookup_contig(ii->i_bmap, blkoff, &blknum, maxblocks);
83 ret = nilfs_bmap_lookup_contig(ii->i_bmap, blkoff, &blknum, maxblocks);
84 up_read(&NILFS_MDT(dat)->mi_sem);
84 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
85 if (ret >= 0) { /* found */
86 map_bh(bh_result, inode->i_sb, blknum);
87 if (ret > 0)
88 bh_result->b_size = (ret << inode->i_blkbits);
89 goto out;
90 }
91 /* data block was not found */
92 if (ret == -ENOENT && create) {

--- 498 unchanged lines hidden (view full) ---

591 raw_inode->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
592 raw_inode->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
593 raw_inode->i_mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
594 raw_inode->i_blocks = cpu_to_le64(inode->i_blocks);
595
596 raw_inode->i_flags = cpu_to_le32(ii->i_flags);
597 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
598
85 if (ret >= 0) { /* found */
86 map_bh(bh_result, inode->i_sb, blknum);
87 if (ret > 0)
88 bh_result->b_size = (ret << inode->i_blkbits);
89 goto out;
90 }
91 /* data block was not found */
92 if (ret == -ENOENT && create) {

--- 498 unchanged lines hidden (view full) ---

591 raw_inode->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
592 raw_inode->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
593 raw_inode->i_mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
594 raw_inode->i_blocks = cpu_to_le64(inode->i_blocks);
595
596 raw_inode->i_flags = cpu_to_le32(ii->i_flags);
597 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
598
599 if (NILFS_ROOT_METADATA_FILE(inode->i_ino)) {
600 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
601
602 /* zero-fill unused portion in the case of super root block */
603 raw_inode->i_xattr = 0;
604 raw_inode->i_pad = 0;
605 memset((void *)raw_inode + sizeof(*raw_inode), 0,
606 nilfs->ns_inode_size - sizeof(*raw_inode));
607 }
608
599 if (has_bmap)
600 nilfs_bmap_write(ii->i_bmap, raw_inode);
601 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
602 raw_inode->i_device_code =
603 cpu_to_le64(huge_encode_dev(inode->i_rdev));
604 /* When extending inode, nilfs->ns_inode_size should be checked
605 for substitutions of appended fields */
606}

--- 260 unchanged lines hidden (view full) ---

867 this inode. */
868 nilfs_warning(inode->i_sb, __func__,
869 "cannot get inode (ino=%lu)\n",
870 inode->i_ino);
871 spin_unlock(&nilfs->ns_inode_lock);
872 return -EINVAL; /* NILFS_I_DIRTY may remain for
873 freeing inode */
874 }
609 if (has_bmap)
610 nilfs_bmap_write(ii->i_bmap, raw_inode);
611 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
612 raw_inode->i_device_code =
613 cpu_to_le64(huge_encode_dev(inode->i_rdev));
614 /* When extending inode, nilfs->ns_inode_size should be checked
615 for substitutions of appended fields */
616}

--- 260 unchanged lines hidden (view full) ---

877 this inode. */
878 nilfs_warning(inode->i_sb, __func__,
879 "cannot get inode (ino=%lu)\n",
880 inode->i_ino);
881 spin_unlock(&nilfs->ns_inode_lock);
882 return -EINVAL; /* NILFS_I_DIRTY may remain for
883 freeing inode */
884 }
875 list_del(&ii->i_dirty);
876 list_add_tail(&ii->i_dirty, &nilfs->ns_dirty_files);
885 list_move_tail(&ii->i_dirty, &nilfs->ns_dirty_files);
877 set_bit(NILFS_I_QUEUED, &ii->i_state);
878 }
879 spin_unlock(&nilfs->ns_inode_lock);
880 return 0;
881}
882
883int nilfs_mark_inode_dirty(struct inode *inode)
884{
885 struct buffer_head *ibh;
886 int err;
887
888 err = nilfs_load_inode_block(inode, &ibh);
889 if (unlikely(err)) {
890 nilfs_warning(inode->i_sb, __func__,
891 "failed to reget inode block.\n");
892 return err;
893 }
894 nilfs_update_inode(inode, ibh);
886 set_bit(NILFS_I_QUEUED, &ii->i_state);
887 }
888 spin_unlock(&nilfs->ns_inode_lock);
889 return 0;
890}
891
892int nilfs_mark_inode_dirty(struct inode *inode)
893{
894 struct buffer_head *ibh;
895 int err;
896
897 err = nilfs_load_inode_block(inode, &ibh);
898 if (unlikely(err)) {
899 nilfs_warning(inode->i_sb, __func__,
900 "failed to reget inode block.\n");
901 return err;
902 }
903 nilfs_update_inode(inode, ibh);
895 nilfs_mdt_mark_buffer_dirty(ibh);
904 mark_buffer_dirty(ibh);
896 nilfs_mdt_mark_dirty(NILFS_I(inode)->i_root->ifile);
897 brelse(ibh);
898 return 0;
899}
900
901/**
902 * nilfs_dirty_inode - reflect changes on given inode to an inode block.
903 * @inode: inode of the file to be registered.
904 *
905 * nilfs_dirty_inode() loads a inode block containing the specified
906 * @inode and copies data from a nilfs_inode to a corresponding inode
907 * entry in the inode block. This operation is excluded from the segment
908 * construction. This function can be called both as a single operation
909 * and as a part of indivisible file operations.
910 */
905 nilfs_mdt_mark_dirty(NILFS_I(inode)->i_root->ifile);
906 brelse(ibh);
907 return 0;
908}
909
910/**
911 * nilfs_dirty_inode - reflect changes on given inode to an inode block.
912 * @inode: inode of the file to be registered.
913 *
914 * nilfs_dirty_inode() loads a inode block containing the specified
915 * @inode and copies data from a nilfs_inode to a corresponding inode
916 * entry in the inode block. This operation is excluded from the segment
917 * construction. This function can be called both as a single operation
918 * and as a part of indivisible file operations.
919 */
911void nilfs_dirty_inode(struct inode *inode)
920void nilfs_dirty_inode(struct inode *inode, int flags)
912{
913 struct nilfs_transaction_info ti;
914 struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
915
916 if (is_bad_inode(inode)) {
917 nilfs_warning(inode->i_sb, __func__,
918 "tried to mark bad_inode dirty. ignored.\n");
919 dump_stack();

--- 6 unchanged lines hidden (view full) ---

926 nilfs_transaction_begin(inode->i_sb, &ti, 0);
927 nilfs_mark_inode_dirty(inode);
928 nilfs_transaction_commit(inode->i_sb); /* never fails */
929}
930
931int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
932 __u64 start, __u64 len)
933{
921{
922 struct nilfs_transaction_info ti;
923 struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
924
925 if (is_bad_inode(inode)) {
926 nilfs_warning(inode->i_sb, __func__,
927 "tried to mark bad_inode dirty. ignored.\n");
928 dump_stack();

--- 6 unchanged lines hidden (view full) ---

935 nilfs_transaction_begin(inode->i_sb, &ti, 0);
936 nilfs_mark_inode_dirty(inode);
937 nilfs_transaction_commit(inode->i_sb); /* never fails */
938}
939
940int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
941 __u64 start, __u64 len)
942{
934 struct the_nilfs *nilfs = NILFS_I_NILFS(inode);
943 struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
935 __u64 logical = 0, phys = 0, size = 0;
936 __u32 flags = 0;
937 loff_t isize;
938 sector_t blkoff, end_blkoff;
939 sector_t delalloc_blkoff;
940 unsigned long delalloc_blklen;
941 unsigned int blkbits = inode->i_blkbits;
942 int ret, n;

--- 118 unchanged lines hidden ---
944 __u64 logical = 0, phys = 0, size = 0;
945 __u32 flags = 0;
946 loff_t isize;
947 sector_t blkoff, end_blkoff;
948 sector_t delalloc_blkoff;
949 unsigned long delalloc_blklen;
950 unsigned int blkbits = inode->i_blkbits;
951 int ret, n;

--- 118 unchanged lines hidden ---