gcdat.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * gcdat.c - NILFS shadow DAT inode for GC
  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
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * Written by Seiji Kihara <kihara@osrg.net>, Amagai Yoshiji <amagai@osrg.net>,
  21. * and Ryusuke Konishi <ryusuke@osrg.net>.
  22. *
  23. */
  24. #include <linux/buffer_head.h>
  25. #include "nilfs.h"
  26. #include "page.h"
  27. #include "mdt.h"
  28. int nilfs_init_gcdat_inode(struct the_nilfs *nilfs)
  29. {
  30. struct inode *dat = nilfs->ns_dat, *gcdat = nilfs->ns_gc_dat;
  31. struct nilfs_inode_info *dii = NILFS_I(dat), *gii = NILFS_I(gcdat);
  32. int err;
  33. gcdat->i_state = 0;
  34. gcdat->i_blocks = dat->i_blocks;
  35. gii->i_flags = dii->i_flags;
  36. gii->i_state = dii->i_state | (1 << NILFS_I_GCDAT);
  37. gii->i_cno = 0;
  38. nilfs_bmap_init_gcdat(gii->i_bmap, dii->i_bmap);
  39. err = nilfs_copy_dirty_pages(gcdat->i_mapping, dat->i_mapping);
  40. if (unlikely(err))
  41. return err;
  42. return nilfs_copy_dirty_pages(&gii->i_btnode_cache,
  43. &dii->i_btnode_cache);
  44. }
  45. void nilfs_commit_gcdat_inode(struct the_nilfs *nilfs)
  46. {
  47. struct inode *dat = nilfs->ns_dat, *gcdat = nilfs->ns_gc_dat;
  48. struct nilfs_inode_info *dii = NILFS_I(dat), *gii = NILFS_I(gcdat);
  49. struct address_space *mapping = dat->i_mapping;
  50. struct address_space *gmapping = gcdat->i_mapping;
  51. down_write(&NILFS_MDT(dat)->mi_sem);
  52. dat->i_blocks = gcdat->i_blocks;
  53. dii->i_flags = gii->i_flags;
  54. dii->i_state = gii->i_state & ~(1 << NILFS_I_GCDAT);
  55. nilfs_bmap_commit_gcdat(gii->i_bmap, dii->i_bmap);
  56. nilfs_clear_dirty_pages(mapping);
  57. nilfs_copy_back_pages(mapping, gmapping);
  58. /* note: mdt dirty flags should be cleared by segctor. */
  59. nilfs_clear_dirty_pages(&dii->i_btnode_cache);
  60. nilfs_copy_back_pages(&dii->i_btnode_cache, &gii->i_btnode_cache);
  61. up_write(&NILFS_MDT(dat)->mi_sem);
  62. }
  63. void nilfs_clear_gcdat_inode(struct the_nilfs *nilfs)
  64. {
  65. struct inode *gcdat = nilfs->ns_gc_dat;
  66. struct nilfs_inode_info *gii = NILFS_I(gcdat);
  67. gcdat->i_state = I_CLEAR;
  68. gii->i_flags = 0;
  69. truncate_inode_pages(gcdat->i_mapping, 0);
  70. truncate_inode_pages(&gii->i_btnode_cache, 0);
  71. }