seglist.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * seglist.h - expediential structure and routines to handle list of segments
  3. * (would be removed in a future release)
  4. *
  5. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * Written by Ryusuke Konishi <ryusuke@osrg.net>
  22. *
  23. */
  24. #ifndef _NILFS_SEGLIST_H
  25. #define _NILFS_SEGLIST_H
  26. #include <linux/fs.h>
  27. #include <linux/buffer_head.h>
  28. #include <linux/nilfs2_fs.h>
  29. #include "sufile.h"
  30. struct nilfs_segment_entry {
  31. __u64 segnum;
  32. #define NILFS_SLH_FREED 0x0001 /* The segment was freed provisonally.
  33. It must be cancelled if
  34. construction aborted */
  35. unsigned flags;
  36. struct list_head list;
  37. struct buffer_head *bh_su;
  38. struct nilfs_segment_usage *raw_su;
  39. };
  40. void nilfs_dispose_segment_list(struct list_head *);
  41. static inline struct nilfs_segment_entry *
  42. nilfs_alloc_segment_entry(__u64 segnum)
  43. {
  44. struct nilfs_segment_entry *ent = kmalloc(sizeof(*ent), GFP_NOFS);
  45. if (likely(ent)) {
  46. ent->segnum = segnum;
  47. ent->flags = 0;
  48. ent->bh_su = NULL;
  49. ent->raw_su = NULL;
  50. INIT_LIST_HEAD(&ent->list);
  51. }
  52. return ent;
  53. }
  54. static inline int nilfs_open_segment_entry(struct nilfs_segment_entry *ent,
  55. struct inode *sufile)
  56. {
  57. return nilfs_sufile_get_segment_usage(sufile, ent->segnum,
  58. &ent->raw_su, &ent->bh_su);
  59. }
  60. static inline void nilfs_close_segment_entry(struct nilfs_segment_entry *ent,
  61. struct inode *sufile)
  62. {
  63. if (!ent->bh_su)
  64. return;
  65. nilfs_sufile_put_segment_usage(sufile, ent->segnum, ent->bh_su);
  66. ent->bh_su = NULL;
  67. ent->raw_su = NULL;
  68. }
  69. static inline void nilfs_free_segment_entry(struct nilfs_segment_entry *ent)
  70. {
  71. kfree(ent);
  72. }
  73. #endif /* _NILFS_SEGLIST_H */