diff options
author | Andreas Rohner <andreas.rohner@gmx.net> | 2014-04-03 17:50:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-03 19:21:25 -0400 |
commit | 00e9ffcd27cc5d0af9076383c6242c32335546f8 (patch) | |
tree | 762e868d94f5bac1d976a77c5c092a3c8de7a59c /fs/nilfs2 | |
parent | 90ccf7dde9527672553c3a809aa93654c95672d0 (diff) |
nilfs2: add nilfs_sufile_set_suinfo to update segment usage
Introduce nilfs_sufile_set_suinfo(), which expects an array of
nilfs_suinfo_update structures and updates the segment usage information
accordingly.
This is basically a helper function for the newly introduced
NILFS_IOCTL_SET_SUINFO ioctl.
[konishi.ryusuke@lab.ntt.co.jp: use put_bh() instead of brelse() because we know bh != NULL]
Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2')
-rw-r--r-- | fs/nilfs2/sufile.c | 131 | ||||
-rw-r--r-- | fs/nilfs2/sufile.h | 1 |
2 files changed, 132 insertions, 0 deletions
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c index 3127e9f438a7..5628b99d454e 100644 --- a/fs/nilfs2/sufile.c +++ b/fs/nilfs2/sufile.c | |||
@@ -870,6 +870,137 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf, | |||
870 | } | 870 | } |
871 | 871 | ||
872 | /** | 872 | /** |
873 | * nilfs_sufile_set_suinfo - sets segment usage info | ||
874 | * @sufile: inode of segment usage file | ||
875 | * @buf: array of suinfo_update | ||
876 | * @supsz: byte size of suinfo_update | ||
877 | * @nsup: size of suinfo_update array | ||
878 | * | ||
879 | * Description: Takes an array of nilfs_suinfo_update structs and updates | ||
880 | * segment usage accordingly. Only the fields indicated by the sup_flags | ||
881 | * are updated. | ||
882 | * | ||
883 | * Return Value: On success, 0 is returned. On error, one of the | ||
884 | * following negative error codes is returned. | ||
885 | * | ||
886 | * %-EIO - I/O error. | ||
887 | * | ||
888 | * %-ENOMEM - Insufficient amount of memory available. | ||
889 | * | ||
890 | * %-EINVAL - Invalid values in input (segment number, flags or nblocks) | ||
891 | */ | ||
892 | ssize_t nilfs_sufile_set_suinfo(struct inode *sufile, void *buf, | ||
893 | unsigned supsz, size_t nsup) | ||
894 | { | ||
895 | struct the_nilfs *nilfs = sufile->i_sb->s_fs_info; | ||
896 | struct buffer_head *header_bh, *bh; | ||
897 | struct nilfs_suinfo_update *sup, *supend = buf + supsz * nsup; | ||
898 | struct nilfs_segment_usage *su; | ||
899 | void *kaddr; | ||
900 | unsigned long blkoff, prev_blkoff; | ||
901 | int cleansi, cleansu, dirtysi, dirtysu; | ||
902 | long ncleaned = 0, ndirtied = 0; | ||
903 | int ret = 0; | ||
904 | |||
905 | if (unlikely(nsup == 0)) | ||
906 | return ret; | ||
907 | |||
908 | for (sup = buf; sup < supend; sup = (void *)sup + supsz) { | ||
909 | if (sup->sup_segnum >= nilfs->ns_nsegments | ||
910 | || (sup->sup_flags & | ||
911 | (~0UL << __NR_NILFS_SUINFO_UPDATE_FIELDS)) | ||
912 | || (nilfs_suinfo_update_nblocks(sup) && | ||
913 | sup->sup_sui.sui_nblocks > | ||
914 | nilfs->ns_blocks_per_segment)) | ||
915 | return -EINVAL; | ||
916 | } | ||
917 | |||
918 | down_write(&NILFS_MDT(sufile)->mi_sem); | ||
919 | |||
920 | ret = nilfs_sufile_get_header_block(sufile, &header_bh); | ||
921 | if (ret < 0) | ||
922 | goto out_sem; | ||
923 | |||
924 | sup = buf; | ||
925 | blkoff = nilfs_sufile_get_blkoff(sufile, sup->sup_segnum); | ||
926 | ret = nilfs_mdt_get_block(sufile, blkoff, 1, NULL, &bh); | ||
927 | if (ret < 0) | ||
928 | goto out_header; | ||
929 | |||
930 | for (;;) { | ||
931 | kaddr = kmap_atomic(bh->b_page); | ||
932 | su = nilfs_sufile_block_get_segment_usage( | ||
933 | sufile, sup->sup_segnum, bh, kaddr); | ||
934 | |||
935 | if (nilfs_suinfo_update_lastmod(sup)) | ||
936 | su->su_lastmod = cpu_to_le64(sup->sup_sui.sui_lastmod); | ||
937 | |||
938 | if (nilfs_suinfo_update_nblocks(sup)) | ||
939 | su->su_nblocks = cpu_to_le32(sup->sup_sui.sui_nblocks); | ||
940 | |||
941 | if (nilfs_suinfo_update_flags(sup)) { | ||
942 | /* | ||
943 | * Active flag is a virtual flag projected by running | ||
944 | * nilfs kernel code - drop it not to write it to | ||
945 | * disk. | ||
946 | */ | ||
947 | sup->sup_sui.sui_flags &= | ||
948 | ~(1UL << NILFS_SEGMENT_USAGE_ACTIVE); | ||
949 | |||
950 | cleansi = nilfs_suinfo_clean(&sup->sup_sui); | ||
951 | cleansu = nilfs_segment_usage_clean(su); | ||
952 | dirtysi = nilfs_suinfo_dirty(&sup->sup_sui); | ||
953 | dirtysu = nilfs_segment_usage_dirty(su); | ||
954 | |||
955 | if (cleansi && !cleansu) | ||
956 | ++ncleaned; | ||
957 | else if (!cleansi && cleansu) | ||
958 | --ncleaned; | ||
959 | |||
960 | if (dirtysi && !dirtysu) | ||
961 | ++ndirtied; | ||
962 | else if (!dirtysi && dirtysu) | ||
963 | --ndirtied; | ||
964 | |||
965 | su->su_flags = cpu_to_le32(sup->sup_sui.sui_flags); | ||
966 | } | ||
967 | |||
968 | kunmap_atomic(kaddr); | ||
969 | |||
970 | sup = (void *)sup + supsz; | ||
971 | if (sup >= supend) | ||
972 | break; | ||
973 | |||
974 | prev_blkoff = blkoff; | ||
975 | blkoff = nilfs_sufile_get_blkoff(sufile, sup->sup_segnum); | ||
976 | if (blkoff == prev_blkoff) | ||
977 | continue; | ||
978 | |||
979 | /* get different block */ | ||
980 | mark_buffer_dirty(bh); | ||
981 | put_bh(bh); | ||
982 | ret = nilfs_mdt_get_block(sufile, blkoff, 1, NULL, &bh); | ||
983 | if (unlikely(ret < 0)) | ||
984 | goto out_mark; | ||
985 | } | ||
986 | mark_buffer_dirty(bh); | ||
987 | put_bh(bh); | ||
988 | |||
989 | out_mark: | ||
990 | if (ncleaned || ndirtied) { | ||
991 | nilfs_sufile_mod_counter(header_bh, (u64)ncleaned, | ||
992 | (u64)ndirtied); | ||
993 | NILFS_SUI(sufile)->ncleansegs += ncleaned; | ||
994 | } | ||
995 | nilfs_mdt_mark_dirty(sufile); | ||
996 | out_header: | ||
997 | put_bh(header_bh); | ||
998 | out_sem: | ||
999 | up_write(&NILFS_MDT(sufile)->mi_sem); | ||
1000 | return ret; | ||
1001 | } | ||
1002 | |||
1003 | /** | ||
873 | * nilfs_sufile_read - read or get sufile inode | 1004 | * nilfs_sufile_read - read or get sufile inode |
874 | * @sb: super block instance | 1005 | * @sb: super block instance |
875 | * @susize: size of a segment usage entry | 1006 | * @susize: size of a segment usage entry |
diff --git a/fs/nilfs2/sufile.h b/fs/nilfs2/sufile.h index e84bc5b51fc1..366003c93ec9 100644 --- a/fs/nilfs2/sufile.h +++ b/fs/nilfs2/sufile.h | |||
@@ -44,6 +44,7 @@ int nilfs_sufile_set_segment_usage(struct inode *sufile, __u64 segnum, | |||
44 | int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *); | 44 | int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *); |
45 | ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, void *, unsigned, | 45 | ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, void *, unsigned, |
46 | size_t); | 46 | size_t); |
47 | ssize_t nilfs_sufile_set_suinfo(struct inode *, void *, unsigned , size_t); | ||
47 | 48 | ||
48 | int nilfs_sufile_updatev(struct inode *, __u64 *, size_t, int, size_t *, | 49 | int nilfs_sufile_updatev(struct inode *, __u64 *, size_t, int, size_t *, |
49 | void (*dofunc)(struct inode *, __u64, | 50 | void (*dofunc)(struct inode *, __u64, |