sufile.h 4.7 KB

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