vlclient.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* AFS Volume Location Service client
  2. *
  3. * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/gfp.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include "internal.h"
  15. /*
  16. * map volume locator abort codes to error codes
  17. */
  18. static int afs_vl_abort_to_error(u32 abort_code)
  19. {
  20. _enter("%u", abort_code);
  21. switch (abort_code) {
  22. case AFSVL_IDEXIST: return -EEXIST;
  23. case AFSVL_IO: return -EREMOTEIO;
  24. case AFSVL_NAMEEXIST: return -EEXIST;
  25. case AFSVL_CREATEFAIL: return -EREMOTEIO;
  26. case AFSVL_NOENT: return -ENOMEDIUM;
  27. case AFSVL_EMPTY: return -ENOMEDIUM;
  28. case AFSVL_ENTDELETED: return -ENOMEDIUM;
  29. case AFSVL_BADNAME: return -EINVAL;
  30. case AFSVL_BADINDEX: return -EINVAL;
  31. case AFSVL_BADVOLTYPE: return -EINVAL;
  32. case AFSVL_BADSERVER: return -EINVAL;
  33. case AFSVL_BADPARTITION: return -EINVAL;
  34. case AFSVL_REPSFULL: return -EFBIG;
  35. case AFSVL_NOREPSERVER: return -ENOENT;
  36. case AFSVL_DUPREPSERVER: return -EEXIST;
  37. case AFSVL_RWNOTFOUND: return -ENOENT;
  38. case AFSVL_BADREFCOUNT: return -EINVAL;
  39. case AFSVL_SIZEEXCEEDED: return -EINVAL;
  40. case AFSVL_BADENTRY: return -EINVAL;
  41. case AFSVL_BADVOLIDBUMP: return -EINVAL;
  42. case AFSVL_IDALREADYHASHED: return -EINVAL;
  43. case AFSVL_ENTRYLOCKED: return -EBUSY;
  44. case AFSVL_BADVOLOPER: return -EBADRQC;
  45. case AFSVL_BADRELLOCKTYPE: return -EINVAL;
  46. case AFSVL_RERELEASE: return -EREMOTEIO;
  47. case AFSVL_BADSERVERFLAG: return -EINVAL;
  48. case AFSVL_PERM: return -EACCES;
  49. case AFSVL_NOMEM: return -EREMOTEIO;
  50. default:
  51. return afs_abort_to_error(abort_code);
  52. }
  53. }
  54. /*
  55. * deliver reply data to a VL.GetEntryByXXX call
  56. */
  57. static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call,
  58. struct sk_buff *skb, bool last)
  59. {
  60. struct afs_cache_vlocation *entry;
  61. __be32 *bp;
  62. u32 tmp;
  63. int loop, ret;
  64. _enter(",,%u", last);
  65. ret = afs_transfer_reply(call, skb, last);
  66. if (ret < 0)
  67. return ret;
  68. /* unmarshall the reply once we've received all of it */
  69. entry = call->reply;
  70. bp = call->buffer;
  71. for (loop = 0; loop < 64; loop++)
  72. entry->name[loop] = ntohl(*bp++);
  73. entry->name[loop] = 0;
  74. bp++; /* final NUL */
  75. bp++; /* type */
  76. entry->nservers = ntohl(*bp++);
  77. for (loop = 0; loop < 8; loop++)
  78. entry->servers[loop].s_addr = *bp++;
  79. bp += 8; /* partition IDs */
  80. for (loop = 0; loop < 8; loop++) {
  81. tmp = ntohl(*bp++);
  82. entry->srvtmask[loop] = 0;
  83. if (tmp & AFS_VLSF_RWVOL)
  84. entry->srvtmask[loop] |= AFS_VOL_VTM_RW;
  85. if (tmp & AFS_VLSF_ROVOL)
  86. entry->srvtmask[loop] |= AFS_VOL_VTM_RO;
  87. if (tmp & AFS_VLSF_BACKVOL)
  88. entry->srvtmask[loop] |= AFS_VOL_VTM_BAK;
  89. }
  90. entry->vid[0] = ntohl(*bp++);
  91. entry->vid[1] = ntohl(*bp++);
  92. entry->vid[2] = ntohl(*bp++);
  93. bp++; /* clone ID */
  94. tmp = ntohl(*bp++); /* flags */
  95. entry->vidmask = 0;
  96. if (tmp & AFS_VLF_RWEXISTS)
  97. entry->vidmask |= AFS_VOL_VTM_RW;
  98. if (tmp & AFS_VLF_ROEXISTS)
  99. entry->vidmask |= AFS_VOL_VTM_RO;
  100. if (tmp & AFS_VLF_BACKEXISTS)
  101. entry->vidmask |= AFS_VOL_VTM_BAK;
  102. if (!entry->vidmask)
  103. return -EBADMSG;
  104. _leave(" = 0 [done]");
  105. return 0;
  106. }
  107. /*
  108. * VL.GetEntryByName operation type
  109. */
  110. static const struct afs_call_type afs_RXVLGetEntryByName = {
  111. .name = "VL.GetEntryByName",
  112. .deliver = afs_deliver_vl_get_entry_by_xxx,
  113. .abort_to_error = afs_vl_abort_to_error,
  114. .destructor = afs_flat_call_destructor,
  115. };
  116. /*
  117. * VL.GetEntryById operation type
  118. */
  119. static const struct afs_call_type afs_RXVLGetEntryById = {
  120. .name = "VL.GetEntryById",
  121. .deliver = afs_deliver_vl_get_entry_by_xxx,
  122. .abort_to_error = afs_vl_abort_to_error,
  123. .destructor = afs_flat_call_destructor,
  124. };
  125. /*
  126. * dispatch a get volume entry by name operation
  127. */
  128. int afs_vl_get_entry_by_name(struct in_addr *addr,
  129. struct key *key,
  130. const char *volname,
  131. struct afs_cache_vlocation *entry,
  132. const struct afs_wait_mode *wait_mode)
  133. {
  134. struct afs_call *call;
  135. size_t volnamesz, reqsz, padsz;
  136. __be32 *bp;
  137. _enter("");
  138. volnamesz = strlen(volname);
  139. padsz = (4 - (volnamesz & 3)) & 3;
  140. reqsz = 8 + volnamesz + padsz;
  141. call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384);
  142. if (!call)
  143. return -ENOMEM;
  144. call->key = key;
  145. call->reply = entry;
  146. call->service_id = VL_SERVICE;
  147. call->port = htons(AFS_VL_PORT);
  148. /* marshall the parameters */
  149. bp = call->request;
  150. *bp++ = htonl(VLGETENTRYBYNAME);
  151. *bp++ = htonl(volnamesz);
  152. memcpy(bp, volname, volnamesz);
  153. if (padsz > 0)
  154. memset((void *) bp + volnamesz, 0, padsz);
  155. /* initiate the call */
  156. return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
  157. }
  158. /*
  159. * dispatch a get volume entry by ID operation
  160. */
  161. int afs_vl_get_entry_by_id(struct in_addr *addr,
  162. struct key *key,
  163. afs_volid_t volid,
  164. afs_voltype_t voltype,
  165. struct afs_cache_vlocation *entry,
  166. const struct afs_wait_mode *wait_mode)
  167. {
  168. struct afs_call *call;
  169. __be32 *bp;
  170. _enter("");
  171. call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384);
  172. if (!call)
  173. return -ENOMEM;
  174. call->key = key;
  175. call->reply = entry;
  176. call->service_id = VL_SERVICE;
  177. call->port = htons(AFS_VL_PORT);
  178. /* marshall the parameters */
  179. bp = call->request;
  180. *bp++ = htonl(VLGETENTRYBYID);
  181. *bp++ = htonl(volid);
  182. *bp = htonl(voltype);
  183. /* initiate the call */
  184. return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
  185. }