vlclient.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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_obj(struct afs_vldb_entry);
  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. .immediate_cancel = afs_vlserver_probe_result,
  320. .done = afs_vlserver_probe_result,
  321. .destructor = afs_destroy_vl_get_capabilities,
  322. };
  323. /*
  324. * Probe a volume server for the capabilities that it supports. This can
  325. * return up to 196 words.
  326. *
  327. * We use this to probe for service upgrade to determine what the server at the
  328. * other end supports.
  329. */
  330. struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
  331. struct afs_addr_list *alist,
  332. unsigned int addr_index,
  333. struct key *key,
  334. struct afs_vlserver *server,
  335. unsigned int server_index)
  336. {
  337. struct afs_call *call;
  338. __be32 *bp;
  339. _enter("");
  340. call = afs_alloc_flat_call(net, &afs_RXVLGetCapabilities, 1 * 4, 16 * 4);
  341. if (!call)
  342. return ERR_PTR(-ENOMEM);
  343. call->key = key;
  344. call->vlserver = afs_get_vlserver(server);
  345. call->server_index = server_index;
  346. call->peer = rxrpc_kernel_get_peer(alist->addrs[addr_index].peer);
  347. call->vl_probe = afs_get_addrlist(alist, afs_alist_trace_get_vlgetcaps);
  348. call->probe_index = addr_index;
  349. call->service_id = server->service_id;
  350. call->upgrade = true;
  351. call->async = true;
  352. call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
  353. /* marshall the parameters */
  354. bp = call->request;
  355. *bp++ = htonl(VLGETCAPABILITIES);
  356. /* Can't take a ref on server */
  357. trace_afs_make_vl_call(call);
  358. afs_make_call(call, GFP_KERNEL);
  359. return call;
  360. }
  361. /*
  362. * Deliver reply data to a YFSVL.GetEndpoints call.
  363. *
  364. * GetEndpoints(IN yfsServerAttributes *attr,
  365. * OUT opr_uuid *uuid,
  366. * OUT afs_int32 *uniquifier,
  367. * OUT endpoints *fsEndpoints,
  368. * OUT endpoints *volEndpoints)
  369. */
  370. static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
  371. {
  372. struct afs_addr_list *alist;
  373. __be32 *bp;
  374. u32 uniquifier, size;
  375. int ret;
  376. _enter("{%u,%zu,%u}",
  377. call->unmarshall, iov_iter_count(call->iter), call->count2);
  378. switch (call->unmarshall) {
  379. case 0:
  380. afs_extract_to_buf(call, sizeof(uuid_t) + 3 * sizeof(__be32));
  381. call->unmarshall = 1;
  382. /* Extract the returned uuid, uniquifier, fsEndpoints count and
  383. * either the first fsEndpoint type or the volEndpoints
  384. * count if there are no fsEndpoints. */
  385. fallthrough;
  386. case 1:
  387. ret = afs_extract_data(call, true);
  388. if (ret < 0)
  389. return ret;
  390. bp = call->buffer + sizeof(uuid_t);
  391. uniquifier = ntohl(*bp++);
  392. call->count = ntohl(*bp++);
  393. call->count2 = ntohl(*bp); /* Type or next count */
  394. if (call->count > YFS_MAXENDPOINTS)
  395. return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num);
  396. alist = afs_alloc_addrlist(call->count);
  397. if (!alist)
  398. return -ENOMEM;
  399. alist->version = uniquifier;
  400. call->ret_alist = alist;
  401. if (call->count == 0)
  402. goto extract_volendpoints;
  403. next_fsendpoint:
  404. switch (call->count2) {
  405. case YFS_ENDPOINT_IPV4:
  406. size = sizeof(__be32) * (1 + 1 + 1);
  407. break;
  408. case YFS_ENDPOINT_IPV6:
  409. size = sizeof(__be32) * (1 + 4 + 1);
  410. break;
  411. default:
  412. return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type);
  413. }
  414. size += sizeof(__be32);
  415. afs_extract_to_buf(call, size);
  416. call->unmarshall = 2;
  417. fallthrough; /* and extract fsEndpoints[] entries */
  418. case 2:
  419. ret = afs_extract_data(call, true);
  420. if (ret < 0)
  421. return ret;
  422. alist = call->ret_alist;
  423. bp = call->buffer;
  424. switch (call->count2) {
  425. case YFS_ENDPOINT_IPV4:
  426. if (ntohl(bp[0]) != sizeof(__be32) * 2)
  427. return afs_protocol_error(
  428. call, afs_eproto_yvl_fsendpt4_len);
  429. ret = afs_merge_fs_addr4(call->net, alist, bp[1], ntohl(bp[2]));
  430. if (ret < 0)
  431. return ret;
  432. bp += 3;
  433. break;
  434. case YFS_ENDPOINT_IPV6:
  435. if (ntohl(bp[0]) != sizeof(__be32) * 5)
  436. return afs_protocol_error(
  437. call, afs_eproto_yvl_fsendpt6_len);
  438. ret = afs_merge_fs_addr6(call->net, alist, bp + 1, ntohl(bp[5]));
  439. if (ret < 0)
  440. return ret;
  441. bp += 6;
  442. break;
  443. default:
  444. return afs_protocol_error(call, afs_eproto_yvl_fsendpt_type);
  445. }
  446. /* Got either the type of the next entry or the count of
  447. * volEndpoints if no more fsEndpoints.
  448. */
  449. call->count2 = ntohl(*bp++);
  450. call->count--;
  451. if (call->count > 0)
  452. goto next_fsendpoint;
  453. extract_volendpoints:
  454. /* Extract the list of volEndpoints. */
  455. call->count = call->count2;
  456. if (!call->count)
  457. goto end;
  458. if (call->count > YFS_MAXENDPOINTS)
  459. return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
  460. afs_extract_to_buf(call, 1 * sizeof(__be32));
  461. call->unmarshall = 3;
  462. /* Extract the type of volEndpoints[0]. Normally we would
  463. * extract the type of the next endpoint when we extract the
  464. * data of the current one, but this is the first...
  465. */
  466. fallthrough;
  467. case 3:
  468. ret = afs_extract_data(call, true);
  469. if (ret < 0)
  470. return ret;
  471. bp = call->buffer;
  472. next_volendpoint:
  473. call->count2 = ntohl(*bp++);
  474. switch (call->count2) {
  475. case YFS_ENDPOINT_IPV4:
  476. size = sizeof(__be32) * (1 + 1 + 1);
  477. break;
  478. case YFS_ENDPOINT_IPV6:
  479. size = sizeof(__be32) * (1 + 4 + 1);
  480. break;
  481. default:
  482. return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
  483. }
  484. if (call->count > 1)
  485. size += sizeof(__be32); /* Get next type too */
  486. afs_extract_to_buf(call, size);
  487. call->unmarshall = 4;
  488. fallthrough; /* and extract volEndpoints[] entries */
  489. case 4:
  490. ret = afs_extract_data(call, true);
  491. if (ret < 0)
  492. return ret;
  493. bp = call->buffer;
  494. switch (call->count2) {
  495. case YFS_ENDPOINT_IPV4:
  496. if (ntohl(bp[0]) != sizeof(__be32) * 2)
  497. return afs_protocol_error(
  498. call, afs_eproto_yvl_vlendpt4_len);
  499. bp += 3;
  500. break;
  501. case YFS_ENDPOINT_IPV6:
  502. if (ntohl(bp[0]) != sizeof(__be32) * 5)
  503. return afs_protocol_error(
  504. call, afs_eproto_yvl_vlendpt6_len);
  505. bp += 6;
  506. break;
  507. default:
  508. return afs_protocol_error(call, afs_eproto_yvl_vlendpt_type);
  509. }
  510. /* Got either the type of the next entry or the count of
  511. * volEndpoints if no more fsEndpoints.
  512. */
  513. call->count--;
  514. if (call->count > 0)
  515. goto next_volendpoint;
  516. end:
  517. afs_extract_discard(call, 0);
  518. call->unmarshall = 5;
  519. fallthrough; /* Done */
  520. case 5:
  521. ret = afs_extract_data(call, false);
  522. if (ret < 0)
  523. return ret;
  524. call->unmarshall = 6;
  525. fallthrough;
  526. case 6:
  527. break;
  528. }
  529. _leave(" = 0 [done]");
  530. return 0;
  531. }
  532. /*
  533. * YFSVL.GetEndpoints operation type.
  534. */
  535. static const struct afs_call_type afs_YFSVLGetEndpoints = {
  536. .name = "YFSVL.GetEndpoints",
  537. .op = afs_YFSVL_GetEndpoints,
  538. .deliver = afs_deliver_yfsvl_get_endpoints,
  539. .destructor = afs_flat_call_destructor,
  540. };
  541. /*
  542. * Dispatch an operation to get the addresses for a server, where the server is
  543. * nominated by UUID.
  544. */
  545. struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
  546. const uuid_t *uuid)
  547. {
  548. struct afs_addr_list *alist;
  549. struct afs_call *call;
  550. struct afs_net *net = vc->cell->net;
  551. __be32 *bp;
  552. _enter("");
  553. call = afs_alloc_flat_call(net, &afs_YFSVLGetEndpoints,
  554. sizeof(__be32) * 2 + sizeof(*uuid),
  555. sizeof(struct in6_addr) + sizeof(__be32) * 3);
  556. if (!call)
  557. return ERR_PTR(-ENOMEM);
  558. call->key = vc->key;
  559. call->ret_alist = NULL;
  560. call->max_lifespan = AFS_VL_MAX_LIFESPAN;
  561. call->peer = rxrpc_kernel_get_peer(vc->alist->addrs[vc->addr_index].peer);
  562. call->service_id = vc->server->service_id;
  563. /* Marshall the parameters */
  564. bp = call->request;
  565. *bp++ = htonl(YVLGETENDPOINTS);
  566. *bp++ = htonl(YFS_SERVER_UUID);
  567. memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */
  568. trace_afs_make_vl_call(call);
  569. afs_make_call(call, GFP_KERNEL);
  570. afs_wait_for_call_to_complete(call);
  571. vc->call_abort_code = call->abort_code;
  572. vc->call_error = call->error;
  573. vc->call_responded = call->responded;
  574. alist = call->ret_alist;
  575. afs_put_call(call);
  576. if (vc->call_error) {
  577. afs_put_addrlist(alist, afs_alist_trace_put_getaddru);
  578. return ERR_PTR(vc->call_error);
  579. }
  580. return alist;
  581. }
  582. /*
  583. * Deliver reply data to a YFSVL.GetCellName operation.
  584. */
  585. static int afs_deliver_yfsvl_get_cell_name(struct afs_call *call)
  586. {
  587. char *cell_name;
  588. u32 namesz, paddedsz;
  589. int ret;
  590. _enter("{%u,%zu/%u}",
  591. call->unmarshall, iov_iter_count(call->iter), call->count);
  592. switch (call->unmarshall) {
  593. case 0:
  594. afs_extract_to_tmp(call);
  595. call->unmarshall++;
  596. fallthrough; /* and extract the cell name length */
  597. case 1:
  598. ret = afs_extract_data(call, true);
  599. if (ret < 0)
  600. return ret;
  601. namesz = ntohl(call->tmp);
  602. if (namesz > YFS_VL_MAXCELLNAME)
  603. return afs_protocol_error(call, afs_eproto_cellname_len);
  604. paddedsz = (namesz + 3) & ~3;
  605. call->count = namesz;
  606. call->count2 = paddedsz - namesz;
  607. cell_name = kmalloc(namesz + 1, GFP_KERNEL);
  608. if (!cell_name)
  609. return -ENOMEM;
  610. cell_name[namesz] = 0;
  611. call->ret_str = cell_name;
  612. afs_extract_begin(call, cell_name, namesz);
  613. call->unmarshall++;
  614. fallthrough; /* and extract cell name */
  615. case 2:
  616. ret = afs_extract_data(call, true);
  617. if (ret < 0)
  618. return ret;
  619. afs_extract_discard(call, call->count2);
  620. call->unmarshall++;
  621. fallthrough; /* and extract padding */
  622. case 3:
  623. ret = afs_extract_data(call, false);
  624. if (ret < 0)
  625. return ret;
  626. call->unmarshall++;
  627. break;
  628. }
  629. _leave(" = 0 [done]");
  630. return 0;
  631. }
  632. /*
  633. * VL.GetCapabilities operation type
  634. */
  635. static const struct afs_call_type afs_YFSVLGetCellName = {
  636. .name = "YFSVL.GetCellName",
  637. .op = afs_YFSVL_GetCellName,
  638. .deliver = afs_deliver_yfsvl_get_cell_name,
  639. .destructor = afs_flat_call_destructor,
  640. };
  641. /*
  642. * Probe a volume server for the capabilities that it supports. This can
  643. * return up to 196 words.
  644. *
  645. * We use this to probe for service upgrade to determine what the server at the
  646. * other end supports.
  647. */
  648. char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc)
  649. {
  650. struct afs_call *call;
  651. struct afs_net *net = vc->cell->net;
  652. __be32 *bp;
  653. char *cellname;
  654. _enter("");
  655. call = afs_alloc_flat_call(net, &afs_YFSVLGetCellName, 1 * 4, 0);
  656. if (!call)
  657. return ERR_PTR(-ENOMEM);
  658. call->key = vc->key;
  659. call->ret_str = NULL;
  660. call->max_lifespan = AFS_VL_MAX_LIFESPAN;
  661. call->peer = rxrpc_kernel_get_peer(vc->alist->addrs[vc->addr_index].peer);
  662. call->service_id = vc->server->service_id;
  663. /* marshall the parameters */
  664. bp = call->request;
  665. *bp++ = htonl(YVLGETCELLNAME);
  666. /* Can't take a ref on server */
  667. trace_afs_make_vl_call(call);
  668. afs_make_call(call, GFP_KERNEL);
  669. afs_wait_for_call_to_complete(call);
  670. vc->call_abort_code = call->abort_code;
  671. vc->call_error = call->error;
  672. vc->call_responded = call->responded;
  673. cellname = call->ret_str;
  674. afs_put_call(call);
  675. if (vc->call_error) {
  676. kfree(cellname);
  677. return ERR_PTR(vc->call_error);
  678. }
  679. return cellname;
  680. }