objlayout.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Data types and function declerations for interfacing with the
  3. * pNFS standard object layout driver.
  4. *
  5. * Copyright (C) 2007 Panasas Inc. [year of first publication]
  6. * All rights reserved.
  7. *
  8. * Benny Halevy <bhalevy@panasas.com>
  9. * Boaz Harrosh <bharrosh@panasas.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2
  13. * See the file COPYING included with this distribution for more details.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. *
  19. * 1. Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * 3. Neither the name of the Panasas company nor the names of its
  25. * contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  32. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  35. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. */
  40. #ifndef _OBJLAYOUT_H
  41. #define _OBJLAYOUT_H
  42. #include <linux/nfs_fs.h>
  43. #include <linux/pnfs_osd_xdr.h>
  44. #include "../pnfs.h"
  45. /*
  46. * per-inode layout
  47. */
  48. struct objlayout {
  49. struct pnfs_layout_hdr pnfs_layout;
  50. /* for layout_commit */
  51. enum osd_delta_space_valid_enum {
  52. OBJ_DSU_INIT = 0,
  53. OBJ_DSU_VALID,
  54. OBJ_DSU_INVALID,
  55. } delta_space_valid;
  56. s64 delta_space_used; /* consumed by write ops */
  57. /* for layout_return */
  58. spinlock_t lock;
  59. struct list_head err_list;
  60. };
  61. static inline struct objlayout *
  62. OBJLAYOUT(struct pnfs_layout_hdr *lo)
  63. {
  64. return container_of(lo, struct objlayout, pnfs_layout);
  65. }
  66. /*
  67. * per-I/O operation state
  68. * embedded in objects provider io_state data structure
  69. */
  70. struct objlayout_io_state {
  71. struct pnfs_layout_segment *lseg;
  72. struct page **pages;
  73. unsigned pgbase;
  74. unsigned nr_pages;
  75. unsigned long count;
  76. loff_t offset;
  77. bool sync;
  78. void *rpcdata;
  79. int status; /* res */
  80. int committed; /* res */
  81. /* Error reporting (layout_return) */
  82. struct list_head err_list;
  83. unsigned num_comps;
  84. /* Pointer to array of error descriptors of size num_comps.
  85. * It should contain as many entries as devices in the osd_layout
  86. * that participate in the I/O. It is up to the io_engine to allocate
  87. * needed space and set num_comps.
  88. */
  89. struct pnfs_osd_ioerr *ioerrs;
  90. };
  91. /*
  92. * Raid engine I/O API
  93. */
  94. extern int objio_alloc_lseg(struct pnfs_layout_segment **outp,
  95. struct pnfs_layout_hdr *pnfslay,
  96. struct pnfs_layout_range *range,
  97. struct xdr_stream *xdr,
  98. gfp_t gfp_flags);
  99. extern void objio_free_lseg(struct pnfs_layout_segment *lseg);
  100. extern int objio_alloc_io_state(
  101. struct pnfs_layout_segment *lseg,
  102. struct objlayout_io_state **outp,
  103. gfp_t gfp_flags);
  104. extern void objio_free_io_state(struct objlayout_io_state *state);
  105. extern int objio_read_pagelist(struct objlayout_io_state *ol_state);
  106. extern int objio_write_pagelist(struct objlayout_io_state *ol_state,
  107. bool stable);
  108. /*
  109. * callback API
  110. */
  111. extern void objlayout_io_set_result(struct objlayout_io_state *state,
  112. unsigned index, struct pnfs_osd_objid *pooid,
  113. int osd_error, u64 offset, u64 length, bool is_write);
  114. static inline void
  115. objlayout_add_delta_space_used(struct objlayout_io_state *state, s64 space_used)
  116. {
  117. struct objlayout *objlay = OBJLAYOUT(state->lseg->pls_layout);
  118. /* If one of the I/Os errored out and the delta_space_used was
  119. * invalid we render the complete report as invalid. Protocol mandate
  120. * the DSU be accurate or not reported.
  121. */
  122. spin_lock(&objlay->lock);
  123. if (objlay->delta_space_valid != OBJ_DSU_INVALID) {
  124. objlay->delta_space_valid = OBJ_DSU_VALID;
  125. objlay->delta_space_used += space_used;
  126. }
  127. spin_unlock(&objlay->lock);
  128. }
  129. extern void objlayout_read_done(struct objlayout_io_state *state,
  130. ssize_t status, bool sync);
  131. extern void objlayout_write_done(struct objlayout_io_state *state,
  132. ssize_t status, bool sync);
  133. extern int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
  134. struct nfs4_deviceid *d_id, struct pnfs_osd_deviceaddr **deviceaddr,
  135. gfp_t gfp_flags);
  136. extern void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr);
  137. /*
  138. * exported generic objects function vectors
  139. */
  140. extern struct pnfs_layout_hdr *objlayout_alloc_layout_hdr(struct inode *, gfp_t gfp_flags);
  141. extern void objlayout_free_layout_hdr(struct pnfs_layout_hdr *);
  142. extern struct pnfs_layout_segment *objlayout_alloc_lseg(
  143. struct pnfs_layout_hdr *,
  144. struct nfs4_layoutget_res *,
  145. gfp_t gfp_flags);
  146. extern void objlayout_free_lseg(struct pnfs_layout_segment *);
  147. extern enum pnfs_try_status objlayout_read_pagelist(
  148. struct nfs_read_data *);
  149. extern enum pnfs_try_status objlayout_write_pagelist(
  150. struct nfs_write_data *,
  151. int how);
  152. extern void objlayout_encode_layoutcommit(
  153. struct pnfs_layout_hdr *,
  154. struct xdr_stream *,
  155. const struct nfs4_layoutcommit_args *);
  156. extern void objlayout_encode_layoutreturn(
  157. struct pnfs_layout_hdr *,
  158. struct xdr_stream *,
  159. const struct nfs4_layoutreturn_args *);
  160. #endif /* _OBJLAYOUT_H */