sufile.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * sufile.h - NILFS segment usage file.
  3. *
  4. * Copyright (C) 2006-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 Koji Sato <koji@osrg.net>.
  21. */
  22. #ifndef _NILFS_SUFILE_H
  23. #define _NILFS_SUFILE_H
  24. #include <linux/fs.h>
  25. #include <linux/buffer_head.h>
  26. #include <linux/nilfs2_fs.h>
  27. #include "mdt.h"
  28. #define NILFS_SUFILE_GFP NILFS_MDT_GFP
  29. static inline unsigned long nilfs_sufile_get_nsegments(struct inode *sufile)
  30. {
  31. return NILFS_MDT(sufile)->mi_nilfs->ns_nsegments;
  32. }
  33. int nilfs_sufile_alloc(struct inode *, __u64 *);
  34. int nilfs_sufile_get_segment_usage(struct inode *, __u64,
  35. struct nilfs_segment_usage **,
  36. struct buffer_head **);
  37. void nilfs_sufile_put_segment_usage(struct inode *, __u64,
  38. struct buffer_head *);
  39. int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *);
  40. int nilfs_sufile_get_ncleansegs(struct inode *, unsigned long *);
  41. ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, struct nilfs_suinfo *,
  42. size_t);
  43. int nilfs_sufile_update(struct inode *, __u64, int,
  44. void (*dofunc)(struct inode *, __u64,
  45. struct buffer_head *,
  46. struct buffer_head *));
  47. void nilfs_sufile_do_cancel_free(struct inode *, __u64, struct buffer_head *,
  48. struct buffer_head *);
  49. void nilfs_sufile_do_scrap(struct inode *, __u64, struct buffer_head *,
  50. struct buffer_head *);
  51. void nilfs_sufile_do_free(struct inode *, __u64, struct buffer_head *,
  52. struct buffer_head *);
  53. void nilfs_sufile_do_set_error(struct inode *, __u64, struct buffer_head *,
  54. struct buffer_head *);
  55. /**
  56. * nilfs_sufile_cancel_free -
  57. * @sufile: inode of segment usage file
  58. * @segnum: segment number
  59. *
  60. * Description:
  61. *
  62. * Return Value: On success, 0 is returned. On error, one of the following
  63. * negative error codes is returned.
  64. *
  65. * %-EIO - I/O error.
  66. *
  67. * %-ENOMEM - Insufficient amount of memory available.
  68. */
  69. static inline int nilfs_sufile_cancel_free(struct inode *sufile, __u64 segnum)
  70. {
  71. return nilfs_sufile_update(sufile, segnum, 0,
  72. nilfs_sufile_do_cancel_free);
  73. }
  74. /**
  75. * nilfs_sufile_scrap - make a segment garbage
  76. * @sufile: inode of segment usage file
  77. * @segnum: segment number to be freed
  78. */
  79. static inline int nilfs_sufile_scrap(struct inode *sufile, __u64 segnum)
  80. {
  81. return nilfs_sufile_update(sufile, segnum, 1, nilfs_sufile_do_scrap);
  82. }
  83. /**
  84. * nilfs_sufile_free - free segment
  85. * @sufile: inode of segment usage file
  86. * @segnum: segment number to be freed
  87. */
  88. static inline int nilfs_sufile_free(struct inode *sufile, __u64 segnum)
  89. {
  90. return nilfs_sufile_update(sufile, segnum, 0, nilfs_sufile_do_free);
  91. }
  92. /**
  93. * nilfs_sufile_set_error - mark a segment as erroneous
  94. * @sufile: inode of segment usage file
  95. * @segnum: segment number
  96. *
  97. * Description: nilfs_sufile_set_error() marks the segment specified by
  98. * @segnum as erroneous. The error segment will never be used again.
  99. *
  100. * Return Value: On success, 0 is returned. On error, one of the following
  101. * negative error codes is returned.
  102. *
  103. * %-EIO - I/O error.
  104. *
  105. * %-ENOMEM - Insufficient amount of memory available.
  106. *
  107. * %-EINVAL - Invalid segment usage number.
  108. */
  109. static inline int nilfs_sufile_set_error(struct inode *sufile, __u64 segnum)
  110. {
  111. return nilfs_sufile_update(sufile, segnum, 0,
  112. nilfs_sufile_do_set_error);
  113. }
  114. #endif /* _NILFS_SUFILE_H */