vlclient.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* AFS Volume Location Service client
  3. *
  4. * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include <linux/gfp.h>
  8. #include <linux/init.h>
  9. #include <linux/sched.h>
  10. #include "afs_fs.h"
  11. #include "internal.h"
  12. /*
  13. * Deliver reply data to a VL.GetEntryByNameU call.
  14. */
  15. static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
  16. {
  17. struct afs_uvldbentry__xdr *uvldb;
  18. struct afs_vldb_entry *entry;
  19. bool new_only = false;
  20. u32 tmp, nr_servers, vlflags;
  21. int i, ret;
  22. _enter("");
  23. ret = afs_transfer_reply(call);
  24. if (ret < 0)
  25. return ret;
  26. /* unmarshall the reply once we've received all of it */
  27. uvldb = call->buffer;
  28. entry = call->ret_vldb;
  29. nr_servers = ntohl(uvldb->nServers);
  30. if (nr_servers > AFS_NMAXNSERVERS)
  31. nr_servers = AFS_NMAXNSERVERS;
  32. for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
  33. entry->name[i] = (u8)ntohl(uvldb->name[i]);
  34. entry->name[i] = 0;
  35. entry->name_len = strlen(entry->name);
  36. /* If there is a new replication site that we can use, ignore all the
  37. * sites that aren't marked as new.
  38. */
  39. for (i = 0; i < nr_servers; i++) {
  40. tmp = ntohl(uvldb->serverFlags[i]);
  41. if (!(tmp & AFS_VLSF_DONTUSE) &&
  42. (tmp & AFS_VLSF_NEWREPSITE))
  43. new_only = true;
  44. }
  45. vlflags = ntohl(uvldb->flags);
  46. for (i = 0; i < nr_servers; i++) {
  47. struct afs_uuid__xdr *xdr;
  48. struct afs_uuid *uuid;
  49. int j;
  50. int n = entry->nr_servers;
  51. tmp = ntohl(uvldb->serverFlags[i]);
  52. if (tmp & AFS_VLSF_DONTUSE ||
  53. (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
  54. continue;
  55. if (tmp & AFS_VLSF_RWVOL) {
  56. entry->fs_mask[n] |= AFS_VOL_VTM_RW;
  57. if (vlflags & AFS_VLF_BACKEXISTS)
  58. entry->fs_mask[n] |= AFS_VOL_VTM_BAK;
  59. }
  60. if (tmp & AFS_VLSF_ROVOL)
  61. entry->fs_mask[n] |= AFS_VOL_VTM_RO;
  62. if (!entry->fs_mask[n])
  63. continue;
  64. xdr = &uvldb->serverNumber[i];
  65. uuid = (struct afs_uuid *)&entry->fs_server[n];
  66. uuid->time_low = xdr->time_low;
  67. uuid->time_mid = htons(ntohl(xdr->time_mid));
  68. uuid->time_hi_and_version = htons(ntohl(xdr->time_hi_and_version));
  69. uuid->clock_seq_hi_and_reserved = (u8)ntohl(xdr->clock_seq_hi_and_reserved);
  70. uuid->clock_seq_low = (u8)ntohl(xdr->clock_seq_low);
  71. for (j = 0; j < 6; j++)
  72. uuid->node[j] = (u8)ntohl(xdr->node[j]);
  73. entry->addr_version[n] = ntohl(uvldb->serverUnique[i]);
  74. entry->nr_servers++;
  75. }
  76. for (i = 0; i < AFS_MAXTYPES; i++)
  77. entry->vid[i] = ntohl(uvldb->volumeId[i]);
  78. if (vlflags & AFS_VLF_RWEXISTS)
  79. __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
  80. if (vlflags & AFS_VLF_ROEXISTS)
  81. __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
  82. if (vlflags & AFS_VLF_BACKEXISTS)
  83. __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
  84. if (!(vlflags & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
  85. entry->error = -ENOMEDIUM;
  86. __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
  87. }
  88. __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
  89. _leave(" = 0 [done]");
  90. return 0;
  91. }
  92. static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
  93. {
  94. kfree(call->ret_vldb);
  95. afs_flat_call_destructor(call);
  96. }
  97. /*
  98. * VL.GetEntryByNameU operation type.
  99. */
  100. static const struct afs_call_type afs_RXVLGetEntryByNameU = {
  101. .name = "VL.GetEntryByNameU",
  102. .op = afs_VL_GetEntryByNameU,
  103. .deliver = afs_deliver_vl_get_entry_by_name_u,
  104. .destructor = afs_destroy_vl_get_entry_by_name_u,
  105. };
  106. /*
  107. * Dispatch a get volume entry by name or ID operation (uuid variant). If the
  108. * volname is a decimal number then it's a volume ID not a volume name.
  109. */
  110. struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *vc,
  111. const char *volname,
  112. int volnamesz)
  113. {
  114. struct afs_vldb_entry *entry;
  115. struct afs_call *call;
  116. struct afs_net *net = vc->cell->net;
  117. size_t reqsz, padsz;
  118. __be32 *bp;
  119. _enter("");
  120. padsz = (4 - (volnamesz & 3)) & 3;
  121. reqsz = 8 + volnamesz + padsz;
  122. entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
  123. if (!entry)
  124. return ERR_PTR(-ENOMEM);
  125. call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
  126. sizeof(struct afs_uvldbentry__xdr));
  127. if (!call) {
  128. kfree(entry);
  129. return ERR_PTR(-ENOMEM);
  130. }
  131. call->key = vc->key;
  132. call->ret_vldb = entry;
  133. call->max_lifespan = AFS_VL_MAX_LIFESPAN;
  134. /* Marshall the parameters */
  135. bp = call->request;
  136. *bp++ = htonl(VLGETENTRYBYNAMEU);
  137. *bp++ = htonl(volnamesz);
  138. memcpy(bp, volname, volnamesz);
  139. if (padsz > 0)
  140. memset((void *)bp + volnamesz, 0, padsz);
  141. trace_afs_make_vl_call(call);
  142. afs_make_call(&vc->ac, call, GFP_KERNEL);
  143. return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->ac);
  144. }
  145. /*
  146. * Deliver reply data to a VL.GetAddrsU call.
  147. *
  148. * GetAddrsU(IN ListAddrByAttributes *inaddr,
  149. * OUT afsUUID *uuidp1,
  150. * OUT uint32_t *uniquifier,
  151. * OUT uint32_t *nentries,
  152. * OUT bulkaddrs *blkaddrs);
  153. */
  154. static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
  155. {
  156. struct afs_addr_list *alist;
  157. __be32 *bp;
  158. u32 uniquifier, nentries, count;
  159. int i, ret;
  160. _enter("{%u,%zu/%u}",
  161. call->unmarshall, iov_iter_count(call->iter), call->count);
  162. switch (call->unmarshall) {
  163. case 0:
  164. afs_extract_to_buf(call,
  165. sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
  166. call->unmarshall++;
  167. /* Extract the returned uuid, uniquifier, nentries and
  168. * blkaddrs size */
  169. fallthrough;
  170. case 1:
  171. ret = afs_extract_data(call, true);
  172. if (ret < 0)
  173. return ret;
  174. bp = call->buffer + sizeof(struct afs_uuid__xdr);
  175. uniquifier = ntohl(*bp++);
  176. nentries = ntohl(*bp++);
  177. count = ntohl(*bp);
  178. nentries = min(nentries, count);
  179. alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
  180. if (!alist)
  181. return -ENOMEM;
  182. alist->version = uniquifier;
  183. call->ret_alist = alist;
  184. call->count = count;
  185. call->count2 = nentries;
  186. call->unmarshall++;
  187. more_entries:
  188. count = min(call->count, 4U);
  189. afs_extract_to_buf(call, count * sizeof(__be32));
  190. fallthrough; /* and extract entries */
  191. case 2:
  192. ret = afs_extract_data(call, call->count > 4);
  193. if (ret < 0)
  194. return ret;
  195. alist = call->ret_alist;
  196. bp = call->buffer;
  197. count = min(call->count, 4U);
  198. for (i = 0; i < count; i++)
  199. if (alist->nr_addrs < call->count2)
  200. afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT);
  201. call->count -= count;
  202. if (call->count > 0)
  203. goto more_entries;
  204. call->unmarshall++;
  205. break;
  206. }
  207. _leave(" = 0 [done]");
  208. return 0;
  209. }
  210. static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
  211. {
  212. afs_put_addrlist(call->ret_alist);
  213. return afs_flat_call_destructor(call);
  214. }
  215. /*
  216. * VL.GetAddrsU operation type.
  217. */
  218. static const struct afs_call_type afs_RXVLGetAddrsU = {
  219. .name = "VL.GetAddrsU",
  220. .op = afs_VL_GetAddrsU,
  221. .deliver = afs_deliver_vl_get_addrs_u,
  222. .destructor = afs_vl_get_addrs_u_destructor,
  223. };
  224. /*
  225. * Dispatch an operation to get the addresses for a server, where the server is
  226. * nominated by UUID.
  227. */
  228. struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
  229. const uuid_t *uuid)
  230. {
  231. struct afs_ListAddrByAttributes__xdr *r;
  232. const struct afs_uuid *u = (const struct afs_uuid *)uuid;
  233. struct afs_call *call;
  234. struct afs_net *net = vc->cell->net;
  235. __be32 *bp;
  236. int i;
  237. _enter("");
  238. call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
  239. sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
  240. sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
  241. if (!call)
  242. return ERR_PTR(-ENOMEM);
  243. call->key = vc->key;
  244. call->ret_alist = NULL;
  245. call->max_lifespan = AFS_VL_MAX_LIFESPAN;
  246. /* Marshall the parameters */
  247. bp = call->request;
  248. *bp++ = htonl(VLGETADDRSU);
  249. r = (struct afs_ListAddrByAttributes__xdr *)bp;
  250. r->Mask = htonl(AFS_VLADDR_UUID);
  251. r->ipaddr = 0;
  252. r->index = 0;
  253. r->spare = 0;
  254. r->uuid.time_low = u->time_low;
  255. r->uuid.time_mid = htonl(ntohs(u->time_mid));
  256. r->uuid.time_hi_and_version = htonl(ntohs(u->time_hi_and_version));
  257. r->uuid.clock_seq_hi_and_reserved = htonl(u->clock_seq_hi_and_reserved);
  258. r->uuid.clock_seq_low = htonl(u->clock_seq_low);
  259. for (i = 0; i < 6; i++)
  260. r->uuid.node[i] = htonl(u->node[i]);
  261. trace_afs_make_vl_call(call);
  262. afs_make_call(&vc->ac, call, GFP_KERNEL);
  263. return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
  264. }
  265. /*
  266. * Deliver reply data to an VL.GetCapabilities operation.
  267. */
  268. static int afs_deliver_vl_get_capabilities(struct afs_call *call)
  269. {
  270. u32 count;
  271. int ret;
  272. _enter("{%u,%zu/%u}",
  273. call->unmarshall, iov_iter_count(call->iter), call->count);
  274. switch (call->unmarshall) {
  275. case 0:
  276. afs_extract_to_tmp(call);
  277. call->unmarshall++;
  278. fallthrough; /* and extract the capabilities word count */
  279. case 1:
  280. ret = afs_extract_data(call, true);
  281. if (ret < 0)
  282. return ret;
  283. count = ntohl(call->tmp);
  284. call->count = count;
  285. call->count2 = count;
  286. call->unmarshall++;
  287. afs_extract_discard(call, count * sizeof(__be32));
  288. fallthrough; /* and extract capabilities words */
  289. case 2:
  290. ret = afs_extract_data(call, false);
  291. if (ret < 0)
  292. return ret;
  293. /* TODO: Examine capabilities */
  294. call->unmarshall++;
  295. break;
  296. }
  297. _leave(" = 0 [done]");
  298. return 0;
  299. }
  300. static void afs_destroy_vl_get_capabilities(struct afs_call *call)
  301. {
  302. afs_put_vlserver(call->net, call->vlserver);
  303. afs_flat_call_destructor(call);
  304. }
  305. /*
  306. * VL.GetCapabilities operation type
  307. */
  308. static const struct afs_call_type afs_RXVLGetCapabilities = {
  309. .name = "VL.GetCapabilities",
  310. .op = afs_VL_GetCapabilities,
  311. .deliver = afs_deliver_vl_get_capabilities,
  312. .done = afs_vlserver_probe_result,
  313. .destructor = afs_destroy_vl_get_capabilities,
  314. };
  315. /*
  316. * Probe a volume server for the capabilities that it supports. This can
  317. * return up to 196 words.
  318. *
  319. * We use this to probe for service upgrade to determine what the server at the
  320. * other end supports.
  321. */
  322. struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
  323. struct afs_addr_cursor *ac,
  324. struct key *key,
  325. struct afs_vlserver *server,
  326. unsigned int server_index)
  327. {
  328. struct afs_call *call;
  329. __be32 *bp;
  330. _enter("");
  331. call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
  332. if (!call)
  333. return ERR_PTR(-ENOMEM);
  334. call->key = key;
  335. call->vlserver = afs_get_vlserver(server);
  336. call->server_index = server_index;
  337. call->upgrade = true;
  338. call->async = true;
  339. call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
  340. /* marshall the parameters */
  341. bp = call->request;
  342. *bp++ = htonl(VLGETCAPABILITIES);
  343. /* Can't take a ref on server */
  344. trace_afs_make_vl_call(call);
  345. afs_make_call(ac, call, GFP_KERNEL);
  346. return call;
  347. }
  348. /*
  349. * Deliver reply data to a YFSVL.GetEndpoints call.
  350. *
  351. * GetEndpoints(IN yfsServerAttributes *attr,
  352. * OUT opr_uuid *uuid,
  353. * OUT afs_int32 *uniquifier,
  354. * OUT endpoints *fsEndpoints,
  355. * OUT endpoints *volEndpoints)
  356. */
  357. static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
  358. {
  359. struct afs_addr_list *alist;
  360. __be32 *bp;
  361. u32 uniquifier, size;
  362. int ret;
  363. _enter("{%u,%zu,%u}",
  364. call->unmarshall, iov_iter_count(call->iter), call->count2);
  365. switch (call->unmarshall) {
  366. case 0:
  367. afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
  368. call->unmarshall = 1;
  369. /* Extract the returned uuid, uniquifier, fsEndpoints count and
  370. * either the first fsEndpoint type or the volEndpoints
  371. * count if there are no fsEndpoints. */
  372. fallthrough;
  373. case 1:
  374. ret = afs_extract_data(call, true);
  375. if (ret < 0)
  376. return ret;
  377. bp = call->buffer + sizeof(uuid_t);
  378. uniquifier = ntohl(*bp++);
  379. call->count = ntohl(*bp++);
  380. call->count2 = ntohl(*bp); /* Type or next count */
  381. if (call->count > YFS_MAXENDPOINTS)
  382. return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num);
  383. alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
  384. if (!alist)
  385. return -ENOMEM;
  386. alist->version = uniquifier;
  387. call->ret_alist = alist;
  388. if (call->count == 0)
  389. goto extract_volendpoints;
  390. next_fsendpoint:
  391. switch (call->count2) {
  392. case YFS_ENDPOINT_IPV4:
  393. size = sizeof(__be32) * (1 + 1 + 1);
  394. break;
  395. case YFS_ENDPOINT_IPV6:
  396. size = sizeof(__be32) * (1 + 4 + 1);
  397. break;
  398. default:
  399. return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type);
  400. }
  401. size += sizeof(__be32);
  402. afs_extract_to_buf(call, size);
  403. call->unmarshall = 2;
  404. fallthrough; /* and extract fsEndpoints[] entries */
  405. case 2:
  406. ret = afs_extract_data(call, true);
  407. if (ret < 0)
  408. return ret;
  409. alist = call->ret_alist;
  410. bp = call->buffer;
  411. switch (call->count2) {
  412. case YFS_ENDPOINT_IPV4:
  413. if (ntohl(bp[0]) != sizeof(__be32) * 2)
  414. return afs_protocol_error(
  415. call, afs_eproto_yvl_fsendpt4_len);
  416. afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2]));
  417. bp += 3;
  418. break;
  419. case YFS_ENDPOINT_IPV6:
  420. if (ntohl(bp[0]) != sizeof(__be32) * 5)
  421. return afs_protocol_error(
  422. call, afs_eproto_yvl_fsendpt6_len);
  423. afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
  424. bp += 6;
  425. break;
  426. default:
  427. return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type);
  428. }
  429. /* Got either the type of the next entry or the count of
  430. * volEndpoints if no more fsEndpoints.
  431. */
  432. call->count2 = ntohl(*bp++);
  433. call->count--;
  434. if (call->count > 0)
  435. goto next_fsendpoint;
  436. extract_volendpoints:
  437. /* Extract the list of volEndpoints. */
  438. call->count = call->count2;
  439. if (!call->count)
  440. goto end;
  441. if (call->count > YFS_MAXENDPOINTS)
  442. return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
  443. afs_extract_to_buf(call, 1 * sizeof(__be32));
  444. call->unmarshall = 3;
  445. /* Extract the type of volEndpoints[0]. Normally we would
  446. * extract the type of the next endpoint when we extract the
  447. * data of the current one, but this is the first...
  448. */
  449. fallthrough;
  450. case 3:
  451. ret = afs_extract_data(call, true);
  452. if (ret < 0)
  453. return ret;
  454. bp = call->buffer;
  455. next_volendpoint:
  456. call->count2 = ntohl(*bp++);
  457. switch (call->count2) {
  458. case YFS_ENDPOINT_IPV4:
  459. size = sizeof(__be32) * (1 + 1 + 1);
  460. break;
  461. case YFS_ENDPOINT_IPV6:
  462. size = sizeof(__be32) * (1 + 4 + 1);
  463. break;
  464. default:
  465. return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
  466. }
  467. if (call->count > 1)
  468. size += sizeof(__be32); /* Get next type too */
  469. afs_extract_to_buf(call, size);
  470. call->unmarshall = 4;
  471. fallthrough; /* and extract volEndpoints[] entries */
  472. case 4:
  473. ret = afs_extract_data(call, true);
  474. if (ret < 0)
  475. return ret;
  476. bp = call->buffer;
  477. switch (call->count2) {
  478. case YFS_ENDPOINT_IPV4:
  479. if (ntohl(bp[0]) != sizeof(__be32) * 2)
  480. return afs_protocol_error(
  481. call, afs_eproto_yvl_vlendpt4_len);
  482. bp += 3;
  483. break;
  484. case YFS_ENDPOINT_IPV6:
  485. if (ntohl(bp[0]) != sizeof(__be32) * 5)
  486. return afs_protocol_error(
  487. call, afs_eproto_yvl_vlendpt6_len);
  488. bp += 6;
  489. break;
  490. default:
  491. return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
  492. }
  493. /* Got either the type of the next entry or the count of
  494. * volEndpoints if no more fsEndpoints.
  495. */
  496. call->count--;
  497. if (call->count > 0)
  498. goto next_volendpoint;
  499. end:
  500. afs_extract_discard(call, 0);
  501. call->unmarshall = 5;
  502. fallthrough; /* Done */
  503. case 5:
  504. ret = afs_extract_data(call, false);
  505. if (ret < 0)
  506. return ret;
  507. call->unmarshall = 6;
  508. case 6:
  509. break;
  510. }
  511. _leave(" = 0 [done]");
  512. return 0;
  513. }
  514. /*
  515. * YFSVL.GetEndpoints operation type.
  516. */
  517. static const struct afs_call_type afs_YFSVLGetEndpoints = {
  518. .name = "YFSVL.GetEndpoints",
  519. .op = afs_YFSVL_GetEndpoints,
  520. .deliver = afs_deliver_yfsvl_get_endpoints,
  521. .destructor = afs_vl_get_addrs_u_destructor,
  522. };
  523. /*
  524. * Dispatch an operation to get the addresses for a server, where the server is
  525. * nominated by UUID.
  526. */
  527. struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
  528. const uuid_t *uuid)
  529. {
  530. struct afs_call *call;
  531. struct afs_net *net = vc->cell->net;
  532. __be32 *bp;
  533. _enter("");
  534. call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
  535. sizeof(__be32) * 2 + sizeof(*uuid),
  536. sizeof(struct in6_addr) + sizeof(__be32) * 3);
  537. if (!call)
  538. return ERR_PTR(-ENOMEM);
  539. call->key = vc->key;
  540. call->ret_alist = NULL;
  541. call->max_lifespan = AFS_VL_MAX_LIFESPAN;
  542. /* Marshall the parameters */
  543. bp = call->request;
  544. *bp++ = htonl(YVLGETENDPOINTS);
  545. *bp++ = htonl(YFS_SERVER_UUID);
  546. memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */
  547. trace_afs_make_vl_call(call);
  548. afs_make_call(&vc->ac, call, GFP_KERNEL);
  549. return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->ac);
  550. }
  551. /*
  552. * Deliver reply data to a YFSVL.GetCellName operation.
  553. */
  554. static int afs_deliver_yfsvl_get_cell_name(struct afs_call *call)
  555. {
  556. char *cell_name;
  557. u32 namesz, paddedsz;
  558. int ret;
  559. _enter("{%u,%zu/%u}",
  560. call->unmarshall, iov_iter_count(call->iter), call->count);
  561. switch (call->unmarshall) {
  562. case 0:
  563. afs_extract_to_tmp(call);
  564. call->unmarshall++;
  565. fallthrough; /* and extract the cell name length */
  566. case 1:
  567. ret = afs_extract_data(call, true);
  568. if (ret < 0)
  569. return ret;
  570. namesz = ntohl(call->tmp);
  571. if (namesz > AFS_MAXCELLNAME)
  572. return afs_protocol_error(call, afs_eproto_cellname_len);
  573. paddedsz = (namesz + 3) & ~3;
  574. call->count = namesz;
  575. call->count2 = paddedsz - namesz;
  576. cell_name = kmalloc(namesz + 1, GFP_KERNEL);
  577. if (!cell_name)
  578. return -ENOMEM;
  579. cell_name[namesz] = 0;
  580. call->ret_str = cell_name;
  581. afs_extract_begin(call, cell_name, namesz);
  582. call->unmarshall++;
  583. fallthrough; /* and extract cell name */
  584. case 2:
  585. ret = afs_extract_data(call, true);
  586. if (ret < 0)
  587. return ret;
  588. afs_extract_discard(call, call->count2);
  589. call->unmarshall++;
  590. fallthrough; /* and extract padding */
  591. case 3:
  592. ret = afs_extract_data(call, false);
  593. if (ret < 0)
  594. return ret;
  595. call->unmarshall++;
  596. break;
  597. }
  598. _leave(" = 0 [done]");
  599. return 0;
  600. }
  601. static void afs_destroy_yfsvl_get_cell_name(struct afs_call *call)
  602. {
  603. kfree(call->ret_str);
  604. afs_flat_call_destructor(call);
  605. }
  606. /*
  607. * VL.GetCapabilities operation type
  608. */
  609. static const struct afs_call_type afs_YFSVLGetCellName = {
  610. .name = "YFSVL.GetCellName",
  611. .op = afs_YFSVL_GetCellName,
  612. .deliver = afs_deliver_yfsvl_get_cell_name,
  613. .destructor = afs_destroy_yfsvl_get_cell_name,
  614. };
  615. /*
  616. * Probe a volume server for the capabilities that it supports. This can
  617. * return up to 196 words.
  618. *
  619. * We use this to probe for service upgrade to determine what the server at the
  620. * other end supports.
  621. */
  622. char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc)
  623. {
  624. struct afs_call *call;
  625. struct afs_net *net = vc->cell->net;
  626. __be32 *bp;
  627. _enter("");
  628. call = afs_alloc_flat_call(net, &afs_YFSVLGetCellName, 1 * 4, 0);
  629. if (!call)
  630. return ERR_PTR(-ENOMEM);
  631. call->key = vc->key;
  632. call->ret_str = NULL;
  633. call->max_lifespan = AFS_VL_MAX_LIFESPAN;
  634. /* marshall the parameters */
  635. bp = call->request;
  636. *bp++ = htonl(YVLGETCELLNAME);
  637. /* Can't take a ref on server */
  638. trace_afs_make_vl_call(call);
  639. afs_make_call(&vc->ac, call, GFP_KERNEL);
  640. return (char *)afs_wait_for_call_to_complete(call, &vc->ac);
  641. }