vlclient.c 5.4 KB

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