vlclient.c 5.4 KB

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