vlclient.c 19 KB

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