vlclient.c 5.3 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. {
  59. struct afs_cache_vlocation *entry;
  60. __be32 *bp;
  61. u32 tmp;
  62. int loop, ret;
  63. _enter("");
  64. ret = afs_transfer_reply(call);
  65. if (ret < 0)
  66. return ret;
  67. /* unmarshall the reply once we've received all of it */
  68. entry = call->reply;
  69. bp = call->buffer;
  70. for (loop = 0; loop < 64; loop++)
  71. entry->name[loop] = ntohl(*bp++);
  72. entry->name[loop] = 0;
  73. bp++; /* final NUL */
  74. bp++; /* type */
  75. entry->nservers = ntohl(*bp++);
  76. for (loop = 0; loop < 8; loop++)
  77. entry->servers[loop].s_addr = *bp++;
  78. bp += 8; /* partition IDs */
  79. for (loop = 0; loop < 8; loop++) {
  80. tmp = ntohl(*bp++);
  81. entry->srvtmask[loop] = 0;
  82. if (tmp & AFS_VLSF_RWVOL)
  83. entry->srvtmask[loop] |= AFS_VOL_VTM_RW;
  84. if (tmp & AFS_VLSF_ROVOL)
  85. entry->srvtmask[loop] |= AFS_VOL_VTM_RO;
  86. if (tmp & AFS_VLSF_BACKVOL)
  87. entry->srvtmask[loop] |= AFS_VOL_VTM_BAK;
  88. }
  89. entry->vid[0] = ntohl(*bp++);
  90. entry->vid[1] = ntohl(*bp++);
  91. entry->vid[2] = ntohl(*bp++);
  92. bp++; /* clone ID */
  93. tmp = ntohl(*bp++); /* flags */
  94. entry->vidmask = 0;
  95. if (tmp & AFS_VLF_RWEXISTS)
  96. entry->vidmask |= AFS_VOL_VTM_RW;
  97. if (tmp & AFS_VLF_ROEXISTS)
  98. entry->vidmask |= AFS_VOL_VTM_RO;
  99. if (tmp & AFS_VLF_BACKEXISTS)
  100. entry->vidmask |= AFS_VOL_VTM_BAK;
  101. if (!entry->vidmask)
  102. return -EBADMSG;
  103. _leave(" = 0 [done]");
  104. return 0;
  105. }
  106. /*
  107. * VL.GetEntryByName operation type
  108. */
  109. static const struct afs_call_type afs_RXVLGetEntryByName = {
  110. .name = "VL.GetEntryByName",
  111. .deliver = afs_deliver_vl_get_entry_by_xxx,
  112. .abort_to_error = afs_vl_abort_to_error,
  113. .destructor = afs_flat_call_destructor,
  114. };
  115. /*
  116. * VL.GetEntryById operation type
  117. */
  118. static const struct afs_call_type afs_RXVLGetEntryById = {
  119. .name = "VL.GetEntryById",
  120. .deliver = afs_deliver_vl_get_entry_by_xxx,
  121. .abort_to_error = afs_vl_abort_to_error,
  122. .destructor = afs_flat_call_destructor,
  123. };
  124. /*
  125. * dispatch a get volume entry by name operation
  126. */
  127. int afs_vl_get_entry_by_name(struct in_addr *addr,
  128. struct key *key,
  129. const char *volname,
  130. struct afs_cache_vlocation *entry,
  131. const struct afs_wait_mode *wait_mode)
  132. {
  133. struct afs_call *call;
  134. size_t volnamesz, reqsz, padsz;
  135. __be32 *bp;
  136. _enter("");
  137. volnamesz = strlen(volname);
  138. padsz = (4 - (volnamesz & 3)) & 3;
  139. reqsz = 8 + volnamesz + padsz;
  140. call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384);
  141. if (!call)
  142. return -ENOMEM;
  143. call->key = key;
  144. call->reply = entry;
  145. call->service_id = VL_SERVICE;
  146. call->port = htons(AFS_VL_PORT);
  147. /* marshall the parameters */
  148. bp = call->request;
  149. *bp++ = htonl(VLGETENTRYBYNAME);
  150. *bp++ = htonl(volnamesz);
  151. memcpy(bp, volname, volnamesz);
  152. if (padsz > 0)
  153. memset((void *) bp + volnamesz, 0, padsz);
  154. /* initiate the call */
  155. return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
  156. }
  157. /*
  158. * dispatch a get volume entry by ID operation
  159. */
  160. int afs_vl_get_entry_by_id(struct in_addr *addr,
  161. struct key *key,
  162. afs_volid_t volid,
  163. afs_voltype_t voltype,
  164. struct afs_cache_vlocation *entry,
  165. const struct afs_wait_mode *wait_mode)
  166. {
  167. struct afs_call *call;
  168. __be32 *bp;
  169. _enter("");
  170. call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384);
  171. if (!call)
  172. return -ENOMEM;
  173. call->key = key;
  174. call->reply = entry;
  175. call->service_id = VL_SERVICE;
  176. call->port = htons(AFS_VL_PORT);
  177. /* marshall the parameters */
  178. bp = call->request;
  179. *bp++ = htonl(VLGETENTRYBYID);
  180. *bp++ = htonl(volid);
  181. *bp = htonl(voltype);
  182. /* initiate the call */
  183. return afs_make_call(addr, call, GFP_KERNEL, wait_mode);
  184. }