blob: 4edac9b6ac0c585494b324f193674dbd9f0147d2 [file] [log] [blame]
Boaz Harrosh09f5bf42011-05-22 19:50:20 +03001/*
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
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 Halevye51b8412011-05-22 19:51:48 +030049 * per-inode layout
50 */
51struct objlayout {
52 struct pnfs_layout_hdr pnfs_layout;
Boaz Harroshadb58532011-05-26 21:49:46 +030053
Boaz Harrosha0fe8bf2011-05-22 19:54:13 +030054 /* 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 Harroshadb58532011-05-26 21:49:46 +030062 /* for layout_return */
63 spinlock_t lock;
64 struct list_head err_list;
Benny Halevye51b8412011-05-22 19:51:48 +030065};
66
67static inline struct objlayout *
68OBJLAYOUT(struct pnfs_layout_hdr *lo)
69{
70 return container_of(lo, struct objlayout, pnfs_layout);
71}
72
73/*
Boaz Harrosh04f83452011-05-22 19:52:19 +030074 * per-I/O operation state
75 * embedded in objects provider io_state data structure
76 */
77struct objlayout_io_state {
78 struct pnfs_layout_segment *lseg;
79
80 struct page **pages;
81 unsigned pgbase;
82 unsigned nr_pages;
83 unsigned long count;
84 loff_t offset;
85 bool sync;
86
87 void *rpcdata;
88 int status; /* res */
Boaz Harrosh04f83452011-05-22 19:52:19 +030089 int committed; /* res */
Boaz Harroshadb58532011-05-26 21:49:46 +030090
91 /* Error reporting (layout_return) */
92 struct list_head err_list;
93 unsigned num_comps;
94 /* Pointer to array of error descriptors of size num_comps.
95 * It should contain as many entries as devices in the osd_layout
96 * that participate in the I/O. It is up to the io_engine to allocate
97 * needed space and set num_comps.
98 */
99 struct pnfs_osd_ioerr *ioerrs;
Boaz Harrosh04f83452011-05-22 19:52:19 +0300100};
101
102/*
Boaz Harrosh09f5bf42011-05-22 19:50:20 +0300103 * Raid engine I/O API
104 */
105extern int objio_alloc_lseg(struct pnfs_layout_segment **outp,
106 struct pnfs_layout_hdr *pnfslay,
107 struct pnfs_layout_range *range,
108 struct xdr_stream *xdr,
109 gfp_t gfp_flags);
110extern void objio_free_lseg(struct pnfs_layout_segment *lseg);
111
Boaz Harrosh04f83452011-05-22 19:52:19 +0300112extern int objio_alloc_io_state(
113 struct pnfs_layout_segment *lseg,
114 struct objlayout_io_state **outp,
115 gfp_t gfp_flags);
116extern void objio_free_io_state(struct objlayout_io_state *state);
117
Boaz Harroshe6c40fe2011-10-31 14:45:46 -0700118extern int objio_read_pagelist(struct objlayout_io_state *ol_state);
119extern int objio_write_pagelist(struct objlayout_io_state *ol_state,
Boaz Harrosh04f83452011-05-22 19:52:19 +0300120 bool stable);
121
Boaz Harrosh09f5bf42011-05-22 19:50:20 +0300122/*
Boaz Harroshb6c05f12011-05-26 21:45:34 +0300123 * callback API
124 */
Boaz Harroshadb58532011-05-26 21:49:46 +0300125extern void objlayout_io_set_result(struct objlayout_io_state *state,
126 unsigned index, struct pnfs_osd_objid *pooid,
127 int osd_error, u64 offset, u64 length, bool is_write);
128
Boaz Harrosha0fe8bf2011-05-22 19:54:13 +0300129static inline void
130objlayout_add_delta_space_used(struct objlayout_io_state *state, s64 space_used)
131{
132 struct objlayout *objlay = OBJLAYOUT(state->lseg->pls_layout);
133
134 /* If one of the I/Os errored out and the delta_space_used was
135 * invalid we render the complete report as invalid. Protocol mandate
136 * the DSU be accurate or not reported.
137 */
138 spin_lock(&objlay->lock);
139 if (objlay->delta_space_valid != OBJ_DSU_INVALID) {
140 objlay->delta_space_valid = OBJ_DSU_VALID;
141 objlay->delta_space_used += space_used;
142 }
143 spin_unlock(&objlay->lock);
144}
145
Boaz Harrosh04f83452011-05-22 19:52:19 +0300146extern void objlayout_read_done(struct objlayout_io_state *state,
147 ssize_t status, bool sync);
148extern void objlayout_write_done(struct objlayout_io_state *state,
149 ssize_t status, bool sync);
150
Boaz Harroshb6c05f12011-05-26 21:45:34 +0300151extern int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
152 struct nfs4_deviceid *d_id, struct pnfs_osd_deviceaddr **deviceaddr,
153 gfp_t gfp_flags);
154extern void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr);
155
156/*
Boaz Harrosh09f5bf42011-05-22 19:50:20 +0300157 * exported generic objects function vectors
158 */
Benny Halevye51b8412011-05-22 19:51:48 +0300159
160extern struct pnfs_layout_hdr *objlayout_alloc_layout_hdr(struct inode *, gfp_t gfp_flags);
161extern void objlayout_free_layout_hdr(struct pnfs_layout_hdr *);
162
Boaz Harrosh09f5bf42011-05-22 19:50:20 +0300163extern struct pnfs_layout_segment *objlayout_alloc_lseg(
164 struct pnfs_layout_hdr *,
165 struct nfs4_layoutget_res *,
166 gfp_t gfp_flags);
167extern void objlayout_free_lseg(struct pnfs_layout_segment *);
168
Boaz Harrosh04f83452011-05-22 19:52:19 +0300169extern enum pnfs_try_status objlayout_read_pagelist(
170 struct nfs_read_data *);
171
172extern enum pnfs_try_status objlayout_write_pagelist(
173 struct nfs_write_data *,
174 int how);
175
Boaz Harrosha0fe8bf2011-05-22 19:54:13 +0300176extern void objlayout_encode_layoutcommit(
177 struct pnfs_layout_hdr *,
178 struct xdr_stream *,
179 const struct nfs4_layoutcommit_args *);
180
Boaz Harroshadb58532011-05-26 21:49:46 +0300181extern void objlayout_encode_layoutreturn(
182 struct pnfs_layout_hdr *,
183 struct xdr_stream *,
184 const struct nfs4_layoutreturn_args *);
185
Boaz Harrosh09f5bf42011-05-22 19:50:20 +0300186#endif /* _OBJLAYOUT_H */