objlayout.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <scsi/osd_initiator.h>
  40. #include "objlayout.h"
  41. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  42. /*
  43. * Unmarshall layout and store it in pnfslay.
  44. */
  45. struct pnfs_layout_segment *
  46. objlayout_alloc_lseg(struct pnfs_layout_hdr *pnfslay,
  47. struct nfs4_layoutget_res *lgr,
  48. gfp_t gfp_flags)
  49. {
  50. int status = -ENOMEM;
  51. struct xdr_stream stream;
  52. struct xdr_buf buf = {
  53. .pages = lgr->layoutp->pages,
  54. .page_len = lgr->layoutp->len,
  55. .buflen = lgr->layoutp->len,
  56. .len = lgr->layoutp->len,
  57. };
  58. struct page *scratch;
  59. struct pnfs_layout_segment *lseg;
  60. dprintk("%s: Begin pnfslay %p\n", __func__, pnfslay);
  61. scratch = alloc_page(gfp_flags);
  62. if (!scratch)
  63. goto err_nofree;
  64. xdr_init_decode(&stream, &buf, NULL);
  65. xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
  66. status = objio_alloc_lseg(&lseg, pnfslay, &lgr->range, &stream, gfp_flags);
  67. if (unlikely(status)) {
  68. dprintk("%s: objio_alloc_lseg Return err %d\n", __func__,
  69. status);
  70. goto err;
  71. }
  72. __free_page(scratch);
  73. dprintk("%s: Return %p\n", __func__, lseg);
  74. return lseg;
  75. err:
  76. __free_page(scratch);
  77. err_nofree:
  78. dprintk("%s: Err Return=>%d\n", __func__, status);
  79. return ERR_PTR(status);
  80. }
  81. /*
  82. * Free a layout segement
  83. */
  84. void
  85. objlayout_free_lseg(struct pnfs_layout_segment *lseg)
  86. {
  87. dprintk("%s: freeing layout segment %p\n", __func__, lseg);
  88. if (unlikely(!lseg))
  89. return;
  90. objio_free_lseg(lseg);
  91. }