Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame^] | 1 | /* |
| 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 | /* |
| 45 | * Unmarshall layout and store it in pnfslay. |
| 46 | */ |
| 47 | struct pnfs_layout_segment * |
| 48 | objlayout_alloc_lseg(struct pnfs_layout_hdr *pnfslay, |
| 49 | struct nfs4_layoutget_res *lgr, |
| 50 | gfp_t gfp_flags) |
| 51 | { |
| 52 | int status = -ENOMEM; |
| 53 | struct xdr_stream stream; |
| 54 | struct xdr_buf buf = { |
| 55 | .pages = lgr->layoutp->pages, |
| 56 | .page_len = lgr->layoutp->len, |
| 57 | .buflen = lgr->layoutp->len, |
| 58 | .len = lgr->layoutp->len, |
| 59 | }; |
| 60 | struct page *scratch; |
| 61 | struct pnfs_layout_segment *lseg; |
| 62 | |
| 63 | dprintk("%s: Begin pnfslay %p\n", __func__, pnfslay); |
| 64 | |
| 65 | scratch = alloc_page(gfp_flags); |
| 66 | if (!scratch) |
| 67 | goto err_nofree; |
| 68 | |
| 69 | xdr_init_decode(&stream, &buf, NULL); |
| 70 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
| 71 | |
| 72 | status = objio_alloc_lseg(&lseg, pnfslay, &lgr->range, &stream, gfp_flags); |
| 73 | if (unlikely(status)) { |
| 74 | dprintk("%s: objio_alloc_lseg Return err %d\n", __func__, |
| 75 | status); |
| 76 | goto err; |
| 77 | } |
| 78 | |
| 79 | __free_page(scratch); |
| 80 | |
| 81 | dprintk("%s: Return %p\n", __func__, lseg); |
| 82 | return lseg; |
| 83 | |
| 84 | err: |
| 85 | __free_page(scratch); |
| 86 | err_nofree: |
| 87 | dprintk("%s: Err Return=>%d\n", __func__, status); |
| 88 | return ERR_PTR(status); |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Free a layout segement |
| 93 | */ |
| 94 | void |
| 95 | objlayout_free_lseg(struct pnfs_layout_segment *lseg) |
| 96 | { |
| 97 | dprintk("%s: freeing layout segment %p\n", __func__, lseg); |
| 98 | |
| 99 | if (unlikely(!lseg)) |
| 100 | return; |
| 101 | |
| 102 | objio_free_lseg(lseg); |
| 103 | } |
| 104 | |