blob: fefa1224aff3f9d7a2ffcf86876184840207fc90 [file] [log] [blame]
Boaz Harrosh09f5bf42011-05-22 19:50:20 +03001/*
2 * pNFS Objects layout driver high level definitions
3 *
4 * Copyright (C) 2007 Panasas Inc. [year of first publication]
5 * All rights reserved.
6 *
7 * Benny Halevy <bhalevy@panasas.com>
8 * Boaz Harrosh <bharrosh@panasas.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * See the file COPYING included with this distribution for more details.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of the Panasas company nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
28 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
34 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#include <scsi/osd_initiator.h>
41#include "objlayout.h"
42
43#define NFSDBG_FACILITY NFSDBG_PNFS_LD
44/*
Benny Halevye51b8412011-05-22 19:51:48 +030045 * Create a objlayout layout structure for the given inode and return it.
46 */
47struct pnfs_layout_hdr *
48objlayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
49{
50 struct objlayout *objlay;
51
52 objlay = kzalloc(sizeof(struct objlayout), gfp_flags);
Boaz Harroshadb58532011-05-26 21:49:46 +030053 if (objlay) {
54 spin_lock_init(&objlay->lock);
55 INIT_LIST_HEAD(&objlay->err_list);
56 }
Benny Halevye51b8412011-05-22 19:51:48 +030057 dprintk("%s: Return %p\n", __func__, objlay);
58 return &objlay->pnfs_layout;
59}
60
61/*
62 * Free an objlayout layout structure
63 */
64void
65objlayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
66{
67 struct objlayout *objlay = OBJLAYOUT(lo);
68
69 dprintk("%s: objlay %p\n", __func__, objlay);
70
Boaz Harroshadb58532011-05-26 21:49:46 +030071 WARN_ON(!list_empty(&objlay->err_list));
Benny Halevye51b8412011-05-22 19:51:48 +030072 kfree(objlay);
73}
74
75/*
Boaz Harrosh09f5bf42011-05-22 19:50:20 +030076 * Unmarshall layout and store it in pnfslay.
77 */
78struct pnfs_layout_segment *
79objlayout_alloc_lseg(struct pnfs_layout_hdr *pnfslay,
80 struct nfs4_layoutget_res *lgr,
81 gfp_t gfp_flags)
82{
83 int status = -ENOMEM;
84 struct xdr_stream stream;
85 struct xdr_buf buf = {
86 .pages = lgr->layoutp->pages,
87 .page_len = lgr->layoutp->len,
88 .buflen = lgr->layoutp->len,
89 .len = lgr->layoutp->len,
90 };
91 struct page *scratch;
92 struct pnfs_layout_segment *lseg;
93
94 dprintk("%s: Begin pnfslay %p\n", __func__, pnfslay);
95
96 scratch = alloc_page(gfp_flags);
97 if (!scratch)
98 goto err_nofree;
99
100 xdr_init_decode(&stream, &buf, NULL);
101 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
102
103 status = objio_alloc_lseg(&lseg, pnfslay, &lgr->range, &stream, gfp_flags);
104 if (unlikely(status)) {
105 dprintk("%s: objio_alloc_lseg Return err %d\n", __func__,
106 status);
107 goto err;
108 }
109
110 __free_page(scratch);
111
112 dprintk("%s: Return %p\n", __func__, lseg);
113 return lseg;
114
115err:
116 __free_page(scratch);
117err_nofree:
118 dprintk("%s: Err Return=>%d\n", __func__, status);
119 return ERR_PTR(status);
120}
121
122/*
123 * Free a layout segement
124 */
125void
126objlayout_free_lseg(struct pnfs_layout_segment *lseg)
127{
128 dprintk("%s: freeing layout segment %p\n", __func__, lseg);
129
130 if (unlikely(!lseg))
131 return;
132
133 objio_free_lseg(lseg);
134}
135
Boaz Harroshb6c05f12011-05-26 21:45:34 +0300136/*
Boaz Harrosh04f83452011-05-22 19:52:19 +0300137 * I/O Operations
138 */
139static inline u64
140end_offset(u64 start, u64 len)
141{
142 u64 end;
143
144 end = start + len;
145 return end >= start ? end : NFS4_MAX_UINT64;
146}
147
148/* last octet in a range */
149static inline u64
150last_byte_offset(u64 start, u64 len)
151{
152 u64 end;
153
154 BUG_ON(!len);
155 end = start + len;
156 return end > start ? end - 1 : NFS4_MAX_UINT64;
157}
158
159static struct objlayout_io_state *
160objlayout_alloc_io_state(struct pnfs_layout_hdr *pnfs_layout_type,
161 struct page **pages,
162 unsigned pgbase,
163 loff_t offset,
164 size_t count,
165 struct pnfs_layout_segment *lseg,
166 void *rpcdata,
167 gfp_t gfp_flags)
168{
169 struct objlayout_io_state *state;
170 u64 lseg_end_offset;
171
172 dprintk("%s: allocating io_state\n", __func__);
173 if (objio_alloc_io_state(lseg, &state, gfp_flags))
174 return NULL;
175
176 BUG_ON(offset < lseg->pls_range.offset);
177 lseg_end_offset = end_offset(lseg->pls_range.offset,
178 lseg->pls_range.length);
179 BUG_ON(offset >= lseg_end_offset);
180 if (offset + count > lseg_end_offset) {
181 count = lseg->pls_range.length -
182 (offset - lseg->pls_range.offset);
183 dprintk("%s: truncated count %Zd\n", __func__, count);
184 }
185
186 if (pgbase > PAGE_SIZE) {
187 pages += pgbase >> PAGE_SHIFT;
188 pgbase &= ~PAGE_MASK;
189 }
190
Boaz Harroshadb58532011-05-26 21:49:46 +0300191 INIT_LIST_HEAD(&state->err_list);
Boaz Harrosh04f83452011-05-22 19:52:19 +0300192 state->lseg = lseg;
193 state->rpcdata = rpcdata;
194 state->pages = pages;
195 state->pgbase = pgbase;
196 state->nr_pages = (pgbase + count + PAGE_SIZE - 1) >> PAGE_SHIFT;
197 state->offset = offset;
198 state->count = count;
199 state->sync = 0;
200
201 return state;
202}
203
204static void
205objlayout_free_io_state(struct objlayout_io_state *state)
206{
207 dprintk("%s: freeing io_state\n", __func__);
208 if (unlikely(!state))
209 return;
210
211 objio_free_io_state(state);
212}
213
214/*
215 * I/O done common code
216 */
217static void
218objlayout_iodone(struct objlayout_io_state *state)
219{
220 dprintk("%s: state %p status\n", __func__, state);
221
Boaz Harroshadb58532011-05-26 21:49:46 +0300222 if (likely(state->status >= 0)) {
223 objlayout_free_io_state(state);
224 } else {
225 struct objlayout *objlay = OBJLAYOUT(state->lseg->pls_layout);
226
227 spin_lock(&objlay->lock);
Boaz Harrosha0fe8bf2011-05-22 19:54:13 +0300228 objlay->delta_space_valid = OBJ_DSU_INVALID;
Boaz Harroshadb58532011-05-26 21:49:46 +0300229 list_add(&objlay->err_list, &state->err_list);
230 spin_unlock(&objlay->lock);
231 }
232}
233
234/*
235 * objlayout_io_set_result - Set an osd_error code on a specific osd comp.
236 *
237 * The @index component IO failed (error returned from target). Register
238 * the error for later reporting at layout-return.
239 */
240void
241objlayout_io_set_result(struct objlayout_io_state *state, unsigned index,
242 struct pnfs_osd_objid *pooid, int osd_error,
243 u64 offset, u64 length, bool is_write)
244{
245 struct pnfs_osd_ioerr *ioerr = &state->ioerrs[index];
246
247 BUG_ON(index >= state->num_comps);
248 if (osd_error) {
249 ioerr->oer_component = *pooid;
250 ioerr->oer_comp_offset = offset;
251 ioerr->oer_comp_length = length;
252 ioerr->oer_iswrite = is_write;
253 ioerr->oer_errno = osd_error;
254
255 dprintk("%s: err[%d]: errno=%d is_write=%d dev(%llx:%llx) "
256 "par=0x%llx obj=0x%llx offset=0x%llx length=0x%llx\n",
257 __func__, index, ioerr->oer_errno,
258 ioerr->oer_iswrite,
259 _DEVID_LO(&ioerr->oer_component.oid_device_id),
260 _DEVID_HI(&ioerr->oer_component.oid_device_id),
261 ioerr->oer_component.oid_partition_id,
262 ioerr->oer_component.oid_object_id,
263 ioerr->oer_comp_offset,
264 ioerr->oer_comp_length);
265 } else {
266 /* User need not call if no error is reported */
267 ioerr->oer_errno = 0;
268 }
Boaz Harrosh04f83452011-05-22 19:52:19 +0300269}
270
271/* Function scheduled on rpc workqueue to call ->nfs_readlist_complete().
272 * This is because the osd completion is called with ints-off from
273 * the block layer
274 */
275static void _rpc_read_complete(struct work_struct *work)
276{
277 struct rpc_task *task;
278 struct nfs_read_data *rdata;
279
280 dprintk("%s enter\n", __func__);
281 task = container_of(work, struct rpc_task, u.tk_work);
282 rdata = container_of(task, struct nfs_read_data, task);
283
284 pnfs_ld_read_done(rdata);
285}
286
287void
288objlayout_read_done(struct objlayout_io_state *state, ssize_t status, bool sync)
289{
290 int eof = state->eof;
291 struct nfs_read_data *rdata;
292
293 state->status = status;
David Howellsc7fd0622011-06-15 00:55:44 +0100294 dprintk("%s: Begin status=%zd eof=%d\n", __func__, status, eof);
Boaz Harrosh04f83452011-05-22 19:52:19 +0300295 rdata = state->rpcdata;
296 rdata->task.tk_status = status;
Boaz Harrosh8edf7c12012-01-06 09:28:12 +0200297 if (likely(status >= 0)) {
Boaz Harrosh04f83452011-05-22 19:52:19 +0300298 rdata->res.count = status;
299 rdata->res.eof = eof;
Boaz Harrosh8edf7c12012-01-06 09:28:12 +0200300 } else {
301 rdata->pnfs_error = status;
Boaz Harrosh04f83452011-05-22 19:52:19 +0300302 }
303 objlayout_iodone(state);
304 /* must not use state after this point */
305
306 if (sync)
307 pnfs_ld_read_done(rdata);
308 else {
309 INIT_WORK(&rdata->task.u.tk_work, _rpc_read_complete);
310 schedule_work(&rdata->task.u.tk_work);
311 }
312}
313
314/*
315 * Perform sync or async reads.
316 */
317enum pnfs_try_status
318objlayout_read_pagelist(struct nfs_read_data *rdata)
319{
320 loff_t offset = rdata->args.offset;
321 size_t count = rdata->args.count;
322 struct objlayout_io_state *state;
323 ssize_t status = 0;
324 loff_t eof;
325
326 dprintk("%s: Begin inode %p offset %llu count %d\n",
327 __func__, rdata->inode, offset, (int)count);
328
329 eof = i_size_read(rdata->inode);
330 if (unlikely(offset + count > eof)) {
331 if (offset >= eof) {
332 status = 0;
333 rdata->res.count = 0;
334 rdata->res.eof = 1;
335 goto out;
336 }
337 count = eof - offset;
338 }
339
340 state = objlayout_alloc_io_state(NFS_I(rdata->inode)->layout,
341 rdata->args.pages, rdata->args.pgbase,
342 offset, count,
343 rdata->lseg, rdata,
344 GFP_KERNEL);
345 if (unlikely(!state)) {
346 status = -ENOMEM;
347 goto out;
348 }
349
350 state->eof = state->offset + state->count >= eof;
351
352 status = objio_read_pagelist(state);
353 out:
354 dprintk("%s: Return status %Zd\n", __func__, status);
355 rdata->pnfs_error = status;
356 return PNFS_ATTEMPTED;
357}
358
359/* Function scheduled on rpc workqueue to call ->nfs_writelist_complete().
360 * This is because the osd completion is called with ints-off from
361 * the block layer
362 */
363static void _rpc_write_complete(struct work_struct *work)
364{
365 struct rpc_task *task;
366 struct nfs_write_data *wdata;
367
368 dprintk("%s enter\n", __func__);
369 task = container_of(work, struct rpc_task, u.tk_work);
370 wdata = container_of(task, struct nfs_write_data, task);
371
372 pnfs_ld_write_done(wdata);
373}
374
375void
376objlayout_write_done(struct objlayout_io_state *state, ssize_t status,
377 bool sync)
378{
379 struct nfs_write_data *wdata;
380
381 dprintk("%s: Begin\n", __func__);
382 wdata = state->rpcdata;
383 state->status = status;
384 wdata->task.tk_status = status;
Boaz Harrosh8edf7c12012-01-06 09:28:12 +0200385 if (likely(status >= 0)) {
Boaz Harrosh04f83452011-05-22 19:52:19 +0300386 wdata->res.count = status;
387 wdata->verf.committed = state->committed;
388 dprintk("%s: Return status %d committed %d\n",
389 __func__, wdata->task.tk_status,
390 wdata->verf.committed);
Boaz Harrosh8edf7c12012-01-06 09:28:12 +0200391 } else {
392 wdata->pnfs_error = status;
Boaz Harrosh04f83452011-05-22 19:52:19 +0300393 dprintk("%s: Return status %d\n",
394 __func__, wdata->task.tk_status);
Boaz Harrosh8edf7c12012-01-06 09:28:12 +0200395 }
Boaz Harrosh04f83452011-05-22 19:52:19 +0300396 objlayout_iodone(state);
397 /* must not use state after this point */
398
399 if (sync)
400 pnfs_ld_write_done(wdata);
401 else {
402 INIT_WORK(&wdata->task.u.tk_work, _rpc_write_complete);
403 schedule_work(&wdata->task.u.tk_work);
404 }
405}
406
407/*
408 * Perform sync or async writes.
409 */
410enum pnfs_try_status
411objlayout_write_pagelist(struct nfs_write_data *wdata,
412 int how)
413{
414 struct objlayout_io_state *state;
415 ssize_t status;
416
417 dprintk("%s: Begin inode %p offset %llu count %u\n",
418 __func__, wdata->inode, wdata->args.offset, wdata->args.count);
419
420 state = objlayout_alloc_io_state(NFS_I(wdata->inode)->layout,
421 wdata->args.pages,
422 wdata->args.pgbase,
423 wdata->args.offset,
424 wdata->args.count,
425 wdata->lseg, wdata,
426 GFP_NOFS);
427 if (unlikely(!state)) {
428 status = -ENOMEM;
429 goto out;
430 }
431
432 state->sync = how & FLUSH_SYNC;
433
434 status = objio_write_pagelist(state, how & FLUSH_STABLE);
435 out:
436 dprintk("%s: Return status %Zd\n", __func__, status);
437 wdata->pnfs_error = status;
438 return PNFS_ATTEMPTED;
439}
440
Boaz Harrosha0fe8bf2011-05-22 19:54:13 +0300441void
442objlayout_encode_layoutcommit(struct pnfs_layout_hdr *pnfslay,
443 struct xdr_stream *xdr,
444 const struct nfs4_layoutcommit_args *args)
445{
446 struct objlayout *objlay = OBJLAYOUT(pnfslay);
447 struct pnfs_osd_layoutupdate lou;
448 __be32 *start;
449
450 dprintk("%s: Begin\n", __func__);
451
452 spin_lock(&objlay->lock);
453 lou.dsu_valid = (objlay->delta_space_valid == OBJ_DSU_VALID);
454 lou.dsu_delta = objlay->delta_space_used;
455 objlay->delta_space_used = 0;
456 objlay->delta_space_valid = OBJ_DSU_INIT;
457 lou.olu_ioerr_flag = !list_empty(&objlay->err_list);
458 spin_unlock(&objlay->lock);
459
460 start = xdr_reserve_space(xdr, 4);
461
462 BUG_ON(pnfs_osd_xdr_encode_layoutupdate(xdr, &lou));
463
464 *start = cpu_to_be32((xdr->p - start - 1) * 4);
465
466 dprintk("%s: Return delta_space_used %lld err %d\n", __func__,
467 lou.dsu_delta, lou.olu_ioerr_flag);
468}
469
Boaz Harroshadb58532011-05-26 21:49:46 +0300470static int
471err_prio(u32 oer_errno)
472{
473 switch (oer_errno) {
474 case 0:
475 return 0;
476
477 case PNFS_OSD_ERR_RESOURCE:
478 return OSD_ERR_PRI_RESOURCE;
479 case PNFS_OSD_ERR_BAD_CRED:
480 return OSD_ERR_PRI_BAD_CRED;
481 case PNFS_OSD_ERR_NO_ACCESS:
482 return OSD_ERR_PRI_NO_ACCESS;
483 case PNFS_OSD_ERR_UNREACHABLE:
484 return OSD_ERR_PRI_UNREACHABLE;
485 case PNFS_OSD_ERR_NOT_FOUND:
486 return OSD_ERR_PRI_NOT_FOUND;
487 case PNFS_OSD_ERR_NO_SPACE:
488 return OSD_ERR_PRI_NO_SPACE;
489 default:
490 WARN_ON(1);
491 /* fallthrough */
492 case PNFS_OSD_ERR_EIO:
493 return OSD_ERR_PRI_EIO;
494 }
495}
496
497static void
498merge_ioerr(struct pnfs_osd_ioerr *dest_err,
499 const struct pnfs_osd_ioerr *src_err)
500{
501 u64 dest_end, src_end;
502
503 if (!dest_err->oer_errno) {
504 *dest_err = *src_err;
505 /* accumulated device must be blank */
506 memset(&dest_err->oer_component.oid_device_id, 0,
507 sizeof(dest_err->oer_component.oid_device_id));
508
509 return;
510 }
511
512 if (dest_err->oer_component.oid_partition_id !=
513 src_err->oer_component.oid_partition_id)
514 dest_err->oer_component.oid_partition_id = 0;
515
516 if (dest_err->oer_component.oid_object_id !=
517 src_err->oer_component.oid_object_id)
518 dest_err->oer_component.oid_object_id = 0;
519
520 if (dest_err->oer_comp_offset > src_err->oer_comp_offset)
521 dest_err->oer_comp_offset = src_err->oer_comp_offset;
522
523 dest_end = end_offset(dest_err->oer_comp_offset,
524 dest_err->oer_comp_length);
525 src_end = end_offset(src_err->oer_comp_offset,
526 src_err->oer_comp_length);
527 if (dest_end < src_end)
528 dest_end = src_end;
529
530 dest_err->oer_comp_length = dest_end - dest_err->oer_comp_offset;
531
532 if ((src_err->oer_iswrite == dest_err->oer_iswrite) &&
533 (err_prio(src_err->oer_errno) > err_prio(dest_err->oer_errno))) {
534 dest_err->oer_errno = src_err->oer_errno;
535 } else if (src_err->oer_iswrite) {
536 dest_err->oer_iswrite = true;
537 dest_err->oer_errno = src_err->oer_errno;
538 }
539}
540
541static void
542encode_accumulated_error(struct objlayout *objlay, __be32 *p)
543{
544 struct objlayout_io_state *state, *tmp;
545 struct pnfs_osd_ioerr accumulated_err = {.oer_errno = 0};
546
547 list_for_each_entry_safe(state, tmp, &objlay->err_list, err_list) {
548 unsigned i;
549
550 for (i = 0; i < state->num_comps; i++) {
551 struct pnfs_osd_ioerr *ioerr = &state->ioerrs[i];
552
553 if (!ioerr->oer_errno)
554 continue;
555
556 printk(KERN_ERR "%s: err[%d]: errno=%d is_write=%d "
557 "dev(%llx:%llx) par=0x%llx obj=0x%llx "
558 "offset=0x%llx length=0x%llx\n",
559 __func__, i, ioerr->oer_errno,
560 ioerr->oer_iswrite,
561 _DEVID_LO(&ioerr->oer_component.oid_device_id),
562 _DEVID_HI(&ioerr->oer_component.oid_device_id),
563 ioerr->oer_component.oid_partition_id,
564 ioerr->oer_component.oid_object_id,
565 ioerr->oer_comp_offset,
566 ioerr->oer_comp_length);
567
568 merge_ioerr(&accumulated_err, ioerr);
569 }
570 list_del(&state->err_list);
571 objlayout_free_io_state(state);
572 }
573
574 pnfs_osd_xdr_encode_ioerr(p, &accumulated_err);
575}
576
577void
578objlayout_encode_layoutreturn(struct pnfs_layout_hdr *pnfslay,
579 struct xdr_stream *xdr,
580 const struct nfs4_layoutreturn_args *args)
581{
582 struct objlayout *objlay = OBJLAYOUT(pnfslay);
583 struct objlayout_io_state *state, *tmp;
584 __be32 *start;
585
586 dprintk("%s: Begin\n", __func__);
587 start = xdr_reserve_space(xdr, 4);
588 BUG_ON(!start);
589
590 spin_lock(&objlay->lock);
591
592 list_for_each_entry_safe(state, tmp, &objlay->err_list, err_list) {
593 __be32 *last_xdr = NULL, *p;
594 unsigned i;
595 int res = 0;
596
597 for (i = 0; i < state->num_comps; i++) {
598 struct pnfs_osd_ioerr *ioerr = &state->ioerrs[i];
599
600 if (!ioerr->oer_errno)
601 continue;
602
603 dprintk("%s: err[%d]: errno=%d is_write=%d "
604 "dev(%llx:%llx) par=0x%llx obj=0x%llx "
605 "offset=0x%llx length=0x%llx\n",
606 __func__, i, ioerr->oer_errno,
607 ioerr->oer_iswrite,
608 _DEVID_LO(&ioerr->oer_component.oid_device_id),
609 _DEVID_HI(&ioerr->oer_component.oid_device_id),
610 ioerr->oer_component.oid_partition_id,
611 ioerr->oer_component.oid_object_id,
612 ioerr->oer_comp_offset,
613 ioerr->oer_comp_length);
614
615 p = pnfs_osd_xdr_ioerr_reserve_space(xdr);
616 if (unlikely(!p)) {
617 res = -E2BIG;
618 break; /* accumulated_error */
619 }
620
621 last_xdr = p;
622 pnfs_osd_xdr_encode_ioerr(p, &state->ioerrs[i]);
623 }
624
625 /* TODO: use xdr_write_pages */
626 if (unlikely(res)) {
627 /* no space for even one error descriptor */
628 BUG_ON(!last_xdr);
629
630 /* we've encountered a situation with lots and lots of
631 * errors and no space to encode them all. Use the last
632 * available slot to report the union of all the
633 * remaining errors.
634 */
635 encode_accumulated_error(objlay, last_xdr);
636 goto loop_done;
637 }
638 list_del(&state->err_list);
639 objlayout_free_io_state(state);
640 }
641loop_done:
642 spin_unlock(&objlay->lock);
643
644 *start = cpu_to_be32((xdr->p - start - 1) * 4);
645 dprintk("%s: Return\n", __func__);
646}
647
648
Boaz Harrosh04f83452011-05-22 19:52:19 +0300649/*
Boaz Harroshb6c05f12011-05-26 21:45:34 +0300650 * Get Device Info API for io engines
651 */
652struct objlayout_deviceinfo {
653 struct page *page;
654 struct pnfs_osd_deviceaddr da; /* This must be last */
655};
656
657/* Initialize and call nfs_getdeviceinfo, then decode and return a
658 * "struct pnfs_osd_deviceaddr *" Eventually objlayout_put_deviceinfo()
659 * should be called.
660 */
661int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
662 struct nfs4_deviceid *d_id, struct pnfs_osd_deviceaddr **deviceaddr,
663 gfp_t gfp_flags)
664{
665 struct objlayout_deviceinfo *odi;
666 struct pnfs_device pd;
667 struct super_block *sb;
668 struct page *page, **pages;
669 u32 *p;
670 int err;
671
672 page = alloc_page(gfp_flags);
673 if (!page)
674 return -ENOMEM;
675
676 pages = &page;
677 pd.pages = pages;
678
679 memcpy(&pd.dev_id, d_id, sizeof(*d_id));
680 pd.layout_type = LAYOUT_OSD2_OBJECTS;
681 pd.pages = &page;
682 pd.pgbase = 0;
683 pd.pglen = PAGE_SIZE;
684 pd.mincount = 0;
685
686 sb = pnfslay->plh_inode->i_sb;
687 err = nfs4_proc_getdeviceinfo(NFS_SERVER(pnfslay->plh_inode), &pd);
688 dprintk("%s nfs_getdeviceinfo returned %d\n", __func__, err);
689 if (err)
690 goto err_out;
691
692 p = page_address(page);
693 odi = kzalloc(sizeof(*odi), gfp_flags);
694 if (!odi) {
695 err = -ENOMEM;
696 goto err_out;
697 }
698 pnfs_osd_xdr_decode_deviceaddr(&odi->da, p);
699 odi->page = page;
700 *deviceaddr = &odi->da;
701 return 0;
702
703err_out:
704 __free_page(page);
705 return err;
706}
707
708void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
709{
710 struct objlayout_deviceinfo *odi = container_of(deviceaddr,
711 struct objlayout_deviceinfo,
712 da);
713
714 __free_page(odi->page);
715 kfree(odi);
716}