sufile.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. static inline unsigned long nilfs_sufile_get_nsegments(struct inode *sufile)
  29. {
  30. return ((struct the_nilfs *)sufile->i_sb->s_fs_info)->ns_nsegments;
  31. }
  32. unsigned long nilfs_sufile_get_ncleansegs(struct inode *sufile);
  33. int nilfs_sufile_set_alloc_range(struct inode *sufile, __u64 start, __u64 end);
  34. int nilfs_sufile_alloc(struct inode *, __u64 *);
  35. int nilfs_sufile_mark_dirty(struct inode *sufile, __u64 segnum);
  36. int nilfs_sufile_set_segment_usage(struct inode *sufile, __u64 segnum,
  37. unsigned long nblocks, time_t modtime);
  38. int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *);
  39. ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, void *, unsigned,
  40. size_t);
  41. ssize_t nilfs_sufile_set_suinfo(struct inode *, void *, unsigned , size_t);
  42. int nilfs_sufile_updatev(struct inode *, __u64 *, size_t, int, size_t *,
  43. void (*dofunc)(struct inode *, __u64,
  44. struct buffer_head *,
  45. struct buffer_head *));
  46. int nilfs_sufile_update(struct inode *, __u64, int,
  47. void (*dofunc)(struct inode *, __u64,
  48. struct buffer_head *,
  49. struct buffer_head *));
  50. void nilfs_sufile_do_scrap(struct inode *, __u64, struct buffer_head *,
  51. struct buffer_head *);
  52. void nilfs_sufile_do_free(struct inode *, __u64, struct buffer_head *,
  53. struct buffer_head *);
  54. void nilfs_sufile_do_cancel_free(struct inode *, __u64, struct buffer_head *,
  55. struct buffer_head *);
  56. void nilfs_sufile_do_set_error(struct inode *, __u64, struct buffer_head *,
  57. struct buffer_head *);
  58. int nilfs_sufile_resize(struct inode *sufile, __u64 newnsegs);
  59. int nilfs_sufile_read(struct super_block *sb, size_t susize,
  60. struct nilfs_inode *raw_inode, struct inode **inodep);
  61. int nilfs_sufile_trim_fs(struct inode *sufile, struct fstrim_range *range);
  62. /**
  63. * nilfs_sufile_scrap - make a segment garbage
  64. * @sufile: inode of segment usage file
  65. * @segnum: segment number to be freed
  66. */
  67. static inline int nilfs_sufile_scrap(struct inode *sufile, __u64 segnum)
  68. {
  69. return nilfs_sufile_update(sufile, segnum, 1, nilfs_sufile_do_scrap);
  70. }
  71. /**
  72. * nilfs_sufile_free - free segment
  73. * @sufile: inode of segment usage file
  74. * @segnum: segment number to be freed
  75. */
  76. static inline int nilfs_sufile_free(struct inode *sufile, __u64 segnum)
  77. {
  78. return nilfs_sufile_update(sufile, segnum, 0, nilfs_sufile_do_free);
  79. }
  80. /**
  81. * nilfs_sufile_freev - free segments
  82. * @sufile: inode of segment usage file
  83. * @segnumv: array of segment numbers
  84. * @nsegs: size of @segnumv array
  85. * @ndone: place to store the number of freed segments
  86. */
  87. static inline int nilfs_sufile_freev(struct inode *sufile, __u64 *segnumv,
  88. size_t nsegs, size_t *ndone)
  89. {
  90. return nilfs_sufile_updatev(sufile, segnumv, nsegs, 0, ndone,
  91. nilfs_sufile_do_free);
  92. }
  93. /**
  94. * nilfs_sufile_cancel_freev - reallocate freeing segments
  95. * @sufile: inode of segment usage file
  96. * @segnumv: array of segment numbers
  97. * @nsegs: size of @segnumv array
  98. * @ndone: place to store the number of cancelled segments
  99. *
  100. * Return Value: On success, 0 is returned. On error, a negative error codes
  101. * is returned.
  102. */
  103. static inline int nilfs_sufile_cancel_freev(struct inode *sufile,
  104. __u64 *segnumv, size_t nsegs,
  105. size_t *ndone)
  106. {
  107. return nilfs_sufile_updatev(sufile, segnumv, nsegs, 0, ndone,
  108. nilfs_sufile_do_cancel_free);
  109. }
  110. /**
  111. * nilfs_sufile_set_error - mark a segment as erroneous
  112. * @sufile: inode of segment usage file
  113. * @segnum: segment number
  114. *
  115. * Description: nilfs_sufile_set_error() marks the segment specified by
  116. * @segnum as erroneous. The error segment will never be used again.
  117. *
  118. * Return Value: On success, 0 is returned. On error, one of the following
  119. * negative error codes is returned.
  120. *
  121. * %-EIO - I/O error.
  122. *
  123. * %-ENOMEM - Insufficient amount of memory available.
  124. *
  125. * %-EINVAL - Invalid segment usage number.
  126. */
  127. static inline int nilfs_sufile_set_error(struct inode *sufile, __u64 segnum)
  128. {
  129. return nilfs_sufile_update(sufile, segnum, 0,
  130. nilfs_sufile_do_set_error);
  131. }
  132. #endif /* _NILFS_SUFILE_H */