Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 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> |
Boaz Harrosh | aa281ac | 2014-10-19 19:38:58 +0300 | [diff] [blame] | 9 | * Boaz Harrosh <ooo@electrozaur.com> |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 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 | |
| 41 | #ifndef _OBJLAYOUT_H |
| 42 | #define _OBJLAYOUT_H |
| 43 | |
| 44 | #include <linux/nfs_fs.h> |
| 45 | #include <linux/pnfs_osd_xdr.h> |
| 46 | #include "../pnfs.h" |
| 47 | |
| 48 | /* |
Benny Halevy | e51b841 | 2011-05-22 19:51:48 +0300 | [diff] [blame] | 49 | * per-inode layout |
| 50 | */ |
| 51 | struct objlayout { |
| 52 | struct pnfs_layout_hdr pnfs_layout; |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 53 | |
Boaz Harrosh | a0fe8bf | 2011-05-22 19:54:13 +0300 | [diff] [blame] | 54 | /* for layout_commit */ |
| 55 | enum osd_delta_space_valid_enum { |
| 56 | OBJ_DSU_INIT = 0, |
| 57 | OBJ_DSU_VALID, |
| 58 | OBJ_DSU_INVALID, |
| 59 | } delta_space_valid; |
| 60 | s64 delta_space_used; /* consumed by write ops */ |
| 61 | |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 62 | /* for layout_return */ |
| 63 | spinlock_t lock; |
| 64 | struct list_head err_list; |
Benny Halevy | e51b841 | 2011-05-22 19:51:48 +0300 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static inline struct objlayout * |
| 68 | OBJLAYOUT(struct pnfs_layout_hdr *lo) |
| 69 | { |
| 70 | return container_of(lo, struct objlayout, pnfs_layout); |
| 71 | } |
| 72 | |
| 73 | /* |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 74 | * per-I/O operation state |
| 75 | * embedded in objects provider io_state data structure |
| 76 | */ |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 77 | struct objlayout_io_res { |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 78 | struct objlayout *objlay; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 79 | |
| 80 | void *rpcdata; |
| 81 | int status; /* res */ |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 82 | int committed; /* res */ |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 83 | |
| 84 | /* Error reporting (layout_return) */ |
| 85 | struct list_head err_list; |
| 86 | unsigned num_comps; |
| 87 | /* Pointer to array of error descriptors of size num_comps. |
| 88 | * It should contain as many entries as devices in the osd_layout |
| 89 | * that participate in the I/O. It is up to the io_engine to allocate |
| 90 | * needed space and set num_comps. |
| 91 | */ |
| 92 | struct pnfs_osd_ioerr *ioerrs; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 93 | }; |
| 94 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 95 | static inline |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 96 | void objlayout_init_ioerrs(struct objlayout_io_res *oir, unsigned num_comps, |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 97 | struct pnfs_osd_ioerr *ioerrs, void *rpcdata, |
| 98 | struct pnfs_layout_hdr *pnfs_layout_type) |
| 99 | { |
| 100 | oir->objlay = OBJLAYOUT(pnfs_layout_type); |
| 101 | oir->rpcdata = rpcdata; |
| 102 | INIT_LIST_HEAD(&oir->err_list); |
| 103 | oir->num_comps = num_comps; |
| 104 | oir->ioerrs = ioerrs; |
| 105 | } |
| 106 | |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 107 | /* |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 108 | * Raid engine I/O API |
| 109 | */ |
| 110 | extern int objio_alloc_lseg(struct pnfs_layout_segment **outp, |
| 111 | struct pnfs_layout_hdr *pnfslay, |
| 112 | struct pnfs_layout_range *range, |
| 113 | struct xdr_stream *xdr, |
| 114 | gfp_t gfp_flags); |
| 115 | extern void objio_free_lseg(struct pnfs_layout_segment *lseg); |
| 116 | |
Masanari Iida | a895d57 | 2013-04-09 02:06:50 +0900 | [diff] [blame] | 117 | /* objio_free_result will free these @oir structs received from |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 118 | * objlayout_{read,write}_done |
| 119 | */ |
| 120 | extern void objio_free_result(struct objlayout_io_res *oir); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 121 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 122 | extern int objio_read_pagelist(struct nfs_pgio_header *rdata); |
| 123 | extern int objio_write_pagelist(struct nfs_pgio_header *wdata, int how); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 124 | |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 125 | /* |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 126 | * callback API |
| 127 | */ |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 128 | extern void objlayout_io_set_result(struct objlayout_io_res *oir, |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 129 | unsigned index, struct pnfs_osd_objid *pooid, |
| 130 | int osd_error, u64 offset, u64 length, bool is_write); |
| 131 | |
Boaz Harrosh | a0fe8bf | 2011-05-22 19:54:13 +0300 | [diff] [blame] | 132 | static inline void |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 133 | objlayout_add_delta_space_used(struct objlayout *objlay, s64 space_used) |
Boaz Harrosh | a0fe8bf | 2011-05-22 19:54:13 +0300 | [diff] [blame] | 134 | { |
Boaz Harrosh | a0fe8bf | 2011-05-22 19:54:13 +0300 | [diff] [blame] | 135 | /* If one of the I/Os errored out and the delta_space_used was |
| 136 | * invalid we render the complete report as invalid. Protocol mandate |
| 137 | * the DSU be accurate or not reported. |
| 138 | */ |
| 139 | spin_lock(&objlay->lock); |
| 140 | if (objlay->delta_space_valid != OBJ_DSU_INVALID) { |
| 141 | objlay->delta_space_valid = OBJ_DSU_VALID; |
| 142 | objlay->delta_space_used += space_used; |
| 143 | } |
| 144 | spin_unlock(&objlay->lock); |
| 145 | } |
| 146 | |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 147 | extern void objlayout_read_done(struct objlayout_io_res *oir, |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 148 | ssize_t status, bool sync); |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 149 | extern void objlayout_write_done(struct objlayout_io_res *oir, |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 150 | ssize_t status, bool sync); |
| 151 | |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 152 | /* |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 153 | * exported generic objects function vectors |
| 154 | */ |
Benny Halevy | e51b841 | 2011-05-22 19:51:48 +0300 | [diff] [blame] | 155 | |
| 156 | extern struct pnfs_layout_hdr *objlayout_alloc_layout_hdr(struct inode *, gfp_t gfp_flags); |
| 157 | extern void objlayout_free_layout_hdr(struct pnfs_layout_hdr *); |
| 158 | |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 159 | extern struct pnfs_layout_segment *objlayout_alloc_lseg( |
| 160 | struct pnfs_layout_hdr *, |
| 161 | struct nfs4_layoutget_res *, |
| 162 | gfp_t gfp_flags); |
| 163 | extern void objlayout_free_lseg(struct pnfs_layout_segment *); |
| 164 | |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 165 | extern enum pnfs_try_status objlayout_read_pagelist( |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 166 | struct nfs_pgio_header *); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 167 | |
| 168 | extern enum pnfs_try_status objlayout_write_pagelist( |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 169 | struct nfs_pgio_header *, |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 170 | int how); |
| 171 | |
Boaz Harrosh | a0fe8bf | 2011-05-22 19:54:13 +0300 | [diff] [blame] | 172 | extern void objlayout_encode_layoutcommit( |
| 173 | struct pnfs_layout_hdr *, |
| 174 | struct xdr_stream *, |
| 175 | const struct nfs4_layoutcommit_args *); |
| 176 | |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 177 | extern void objlayout_encode_layoutreturn( |
| 178 | struct pnfs_layout_hdr *, |
| 179 | struct xdr_stream *, |
| 180 | const struct nfs4_layoutreturn_args *); |
| 181 | |
Sachin Bhamare | 18d98f6 | 2012-03-19 20:47:58 -0700 | [diff] [blame] | 182 | extern int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr); |
| 183 | |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 184 | #endif /* _OBJLAYOUT_H */ |