osd.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2005, 2006
  3. * Avishay Traeger (avishay@gmail.com)
  4. * Copyright (C) 2008, 2009
  5. * Boaz Harrosh <bharrosh@panasas.com>
  6. *
  7. * This file is part of exofs.
  8. *
  9. * exofs is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation. Since it is based on ext2, and the only
  12. * valid version of GPL for the Linux kernel is version 2, the only valid
  13. * version of GPL for exofs is version 2.
  14. *
  15. * exofs is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with exofs; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <scsi/scsi_device.h>
  25. #include <scsi/osd_sense.h>
  26. #include "exofs.h"
  27. int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid)
  28. {
  29. struct osd_sense_info osi;
  30. int ret = osd_req_decode_sense(or, &osi);
  31. if (ret) { /* translate to Linux codes */
  32. if (osi.additional_code == scsi_invalid_field_in_cdb) {
  33. if (osi.cdb_field_offset == OSD_CFO_STARTING_BYTE)
  34. ret = -EFAULT;
  35. if (osi.cdb_field_offset == OSD_CFO_OBJECT_ID)
  36. ret = -ENOENT;
  37. else
  38. ret = -EINVAL;
  39. } else if (osi.additional_code == osd_quota_error)
  40. ret = -ENOSPC;
  41. else
  42. ret = -EIO;
  43. }
  44. /* FIXME: should be include in osd_sense_info */
  45. if (in_resid)
  46. *in_resid = or->in.req ? or->in.req->resid_len : 0;
  47. if (out_resid)
  48. *out_resid = or->out.req ? or->out.req->resid_len : 0;
  49. return ret;
  50. }
  51. void exofs_make_credential(u8 cred_a[OSD_CAP_LEN], const struct osd_obj_id *obj)
  52. {
  53. osd_sec_init_nosec_doall_caps(cred_a, obj, false, true);
  54. }
  55. /*
  56. * Perform a synchronous OSD operation.
  57. */
  58. int exofs_sync_op(struct osd_request *or, int timeout, uint8_t *credential)
  59. {
  60. int ret;
  61. or->timeout = timeout;
  62. ret = osd_finalize_request(or, 0, credential, NULL);
  63. if (ret) {
  64. EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", ret);
  65. return ret;
  66. }
  67. ret = osd_execute_request(or);
  68. if (ret)
  69. EXOFS_DBGMSG("osd_execute_request() => %d\n", ret);
  70. /* osd_req_decode_sense(or, ret); */
  71. return ret;
  72. }
  73. /*
  74. * Perform an asynchronous OSD operation.
  75. */
  76. int exofs_async_op(struct osd_request *or, osd_req_done_fn *async_done,
  77. void *caller_context, u8 *cred)
  78. {
  79. int ret;
  80. ret = osd_finalize_request(or, 0, cred, NULL);
  81. if (ret) {
  82. EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", ret);
  83. return ret;
  84. }
  85. ret = osd_execute_request_async(or, async_done, caller_context);
  86. if (ret)
  87. EXOFS_DBGMSG("osd_execute_request_async() => %d\n", ret);
  88. return ret;
  89. }
  90. int extract_attr_from_req(struct osd_request *or, struct osd_attr *attr)
  91. {
  92. struct osd_attr cur_attr = {.attr_page = 0}; /* start with zeros */
  93. void *iter = NULL;
  94. int nelem;
  95. do {
  96. nelem = 1;
  97. osd_req_decode_get_attr_list(or, &cur_attr, &nelem, &iter);
  98. if ((cur_attr.attr_page == attr->attr_page) &&
  99. (cur_attr.attr_id == attr->attr_id)) {
  100. attr->len = cur_attr.len;
  101. attr->val_ptr = cur_attr.val_ptr;
  102. return 0;
  103. }
  104. } while (iter);
  105. return -EIO;
  106. }