vnode.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /* AFS vnode management
  2. *
  3. * Copyright (C) 2002, 2007 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/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/fs.h>
  15. #include <linux/sched.h>
  16. #include "internal.h"
  17. #if 0
  18. static noinline bool dump_tree_aux(struct rb_node *node, struct rb_node *parent,
  19. int depth, char lr)
  20. {
  21. struct afs_vnode *vnode;
  22. bool bad = false;
  23. if (!node)
  24. return false;
  25. if (node->rb_left)
  26. bad = dump_tree_aux(node->rb_left, node, depth + 2, '/');
  27. vnode = rb_entry(node, struct afs_vnode, cb_promise);
  28. _debug("%c %*.*s%c%p {%d}",
  29. rb_is_red(node) ? 'R' : 'B',
  30. depth, depth, "", lr,
  31. vnode, vnode->cb_expires_at);
  32. if (rb_parent(node) != parent) {
  33. printk("BAD: %p != %p\n", rb_parent(node), parent);
  34. bad = true;
  35. }
  36. if (node->rb_right)
  37. bad |= dump_tree_aux(node->rb_right, node, depth + 2, '\\');
  38. return bad;
  39. }
  40. static noinline void dump_tree(const char *name, struct afs_server *server)
  41. {
  42. _enter("%s", name);
  43. if (dump_tree_aux(server->cb_promises.rb_node, NULL, 0, '-'))
  44. BUG();
  45. }
  46. #endif
  47. /*
  48. * insert a vnode into the backing server's vnode tree
  49. */
  50. static void afs_install_vnode(struct afs_vnode *vnode,
  51. struct afs_server *server)
  52. {
  53. struct afs_server *old_server = vnode->server;
  54. struct afs_vnode *xvnode;
  55. struct rb_node *parent, **p;
  56. _enter("%p,%p", vnode, server);
  57. if (old_server) {
  58. spin_lock(&old_server->fs_lock);
  59. rb_erase(&vnode->server_rb, &old_server->fs_vnodes);
  60. spin_unlock(&old_server->fs_lock);
  61. }
  62. afs_get_server(server);
  63. vnode->server = server;
  64. afs_put_server(old_server);
  65. /* insert into the server's vnode tree in FID order */
  66. spin_lock(&server->fs_lock);
  67. parent = NULL;
  68. p = &server->fs_vnodes.rb_node;
  69. while (*p) {
  70. parent = *p;
  71. xvnode = rb_entry(parent, struct afs_vnode, server_rb);
  72. if (vnode->fid.vid < xvnode->fid.vid)
  73. p = &(*p)->rb_left;
  74. else if (vnode->fid.vid > xvnode->fid.vid)
  75. p = &(*p)->rb_right;
  76. else if (vnode->fid.vnode < xvnode->fid.vnode)
  77. p = &(*p)->rb_left;
  78. else if (vnode->fid.vnode > xvnode->fid.vnode)
  79. p = &(*p)->rb_right;
  80. else if (vnode->fid.unique < xvnode->fid.unique)
  81. p = &(*p)->rb_left;
  82. else if (vnode->fid.unique > xvnode->fid.unique)
  83. p = &(*p)->rb_right;
  84. else
  85. BUG(); /* can't happen unless afs_iget() malfunctions */
  86. }
  87. rb_link_node(&vnode->server_rb, parent, p);
  88. rb_insert_color(&vnode->server_rb, &server->fs_vnodes);
  89. spin_unlock(&server->fs_lock);
  90. _leave("");
  91. }
  92. /*
  93. * insert a vnode into the promising server's update/expiration tree
  94. * - caller must hold vnode->lock
  95. */
  96. static void afs_vnode_note_promise(struct afs_vnode *vnode,
  97. struct afs_server *server)
  98. {
  99. struct afs_server *old_server;
  100. struct afs_vnode *xvnode;
  101. struct rb_node *parent, **p;
  102. _enter("%p,%p", vnode, server);
  103. ASSERT(server != NULL);
  104. old_server = vnode->server;
  105. if (vnode->cb_promised) {
  106. if (server == old_server &&
  107. vnode->cb_expires == vnode->cb_expires_at) {
  108. _leave(" [no change]");
  109. return;
  110. }
  111. spin_lock(&old_server->cb_lock);
  112. if (vnode->cb_promised) {
  113. _debug("delete");
  114. rb_erase(&vnode->cb_promise, &old_server->cb_promises);
  115. vnode->cb_promised = false;
  116. }
  117. spin_unlock(&old_server->cb_lock);
  118. }
  119. if (vnode->server != server)
  120. afs_install_vnode(vnode, server);
  121. vnode->cb_expires_at = vnode->cb_expires;
  122. _debug("PROMISE on %p {%lu}",
  123. vnode, (unsigned long) vnode->cb_expires_at);
  124. /* abuse an RB-tree to hold the expiration order (we may have multiple
  125. * items with the same expiration time) */
  126. spin_lock(&server->cb_lock);
  127. parent = NULL;
  128. p = &server->cb_promises.rb_node;
  129. while (*p) {
  130. parent = *p;
  131. xvnode = rb_entry(parent, struct afs_vnode, cb_promise);
  132. if (vnode->cb_expires_at < xvnode->cb_expires_at)
  133. p = &(*p)->rb_left;
  134. else
  135. p = &(*p)->rb_right;
  136. }
  137. rb_link_node(&vnode->cb_promise, parent, p);
  138. rb_insert_color(&vnode->cb_promise, &server->cb_promises);
  139. vnode->cb_promised = true;
  140. spin_unlock(&server->cb_lock);
  141. _leave("");
  142. }
  143. /*
  144. * handle remote file deletion by discarding the callback promise
  145. */
  146. static void afs_vnode_deleted_remotely(struct afs_vnode *vnode)
  147. {
  148. struct afs_server *server;
  149. _enter("{%p}", vnode->server);
  150. set_bit(AFS_VNODE_DELETED, &vnode->flags);
  151. server = vnode->server;
  152. if (server) {
  153. if (vnode->cb_promised) {
  154. spin_lock(&server->cb_lock);
  155. if (vnode->cb_promised) {
  156. rb_erase(&vnode->cb_promise,
  157. &server->cb_promises);
  158. vnode->cb_promised = false;
  159. }
  160. spin_unlock(&server->cb_lock);
  161. }
  162. spin_lock(&server->fs_lock);
  163. rb_erase(&vnode->server_rb, &server->fs_vnodes);
  164. spin_unlock(&server->fs_lock);
  165. vnode->server = NULL;
  166. afs_put_server(server);
  167. } else {
  168. ASSERT(!vnode->cb_promised);
  169. }
  170. _leave("");
  171. }
  172. /*
  173. * finish off updating the recorded status of a file after a successful
  174. * operation completion
  175. * - starts callback expiry timer
  176. * - adds to server's callback list
  177. */
  178. void afs_vnode_finalise_status_update(struct afs_vnode *vnode,
  179. struct afs_server *server)
  180. {
  181. struct afs_server *oldserver = NULL;
  182. _enter("%p,%p", vnode, server);
  183. spin_lock(&vnode->lock);
  184. clear_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
  185. afs_vnode_note_promise(vnode, server);
  186. vnode->update_cnt--;
  187. ASSERTCMP(vnode->update_cnt, >=, 0);
  188. spin_unlock(&vnode->lock);
  189. wake_up_all(&vnode->update_waitq);
  190. afs_put_server(oldserver);
  191. _leave("");
  192. }
  193. /*
  194. * finish off updating the recorded status of a file after an operation failed
  195. */
  196. static void afs_vnode_status_update_failed(struct afs_vnode *vnode, int ret)
  197. {
  198. _enter("{%x:%u},%d", vnode->fid.vid, vnode->fid.vnode, ret);
  199. spin_lock(&vnode->lock);
  200. clear_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
  201. if (ret == -ENOENT) {
  202. /* the file was deleted on the server */
  203. _debug("got NOENT from server - marking file deleted");
  204. afs_vnode_deleted_remotely(vnode);
  205. }
  206. vnode->update_cnt--;
  207. ASSERTCMP(vnode->update_cnt, >=, 0);
  208. spin_unlock(&vnode->lock);
  209. wake_up_all(&vnode->update_waitq);
  210. _leave("");
  211. }
  212. /*
  213. * fetch file status from the volume
  214. * - don't issue a fetch if:
  215. * - the changed bit is not set and there's a valid callback
  216. * - there are any outstanding ops that will fetch the status
  217. * - TODO implement local caching
  218. */
  219. int afs_vnode_fetch_status(struct afs_vnode *vnode,
  220. struct afs_vnode *auth_vnode, struct key *key)
  221. {
  222. struct afs_server *server;
  223. unsigned long acl_order;
  224. int ret;
  225. DECLARE_WAITQUEUE(myself, current);
  226. _enter("%s,{%x:%u.%u}",
  227. vnode->volume->vlocation->vldb.name,
  228. vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
  229. if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
  230. vnode->cb_promised) {
  231. _leave(" [unchanged]");
  232. return 0;
  233. }
  234. if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
  235. _leave(" [deleted]");
  236. return -ENOENT;
  237. }
  238. acl_order = 0;
  239. if (auth_vnode)
  240. acl_order = auth_vnode->acl_order;
  241. spin_lock(&vnode->lock);
  242. if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
  243. vnode->cb_promised) {
  244. spin_unlock(&vnode->lock);
  245. _leave(" [unchanged]");
  246. return 0;
  247. }
  248. ASSERTCMP(vnode->update_cnt, >=, 0);
  249. if (vnode->update_cnt > 0) {
  250. /* someone else started a fetch */
  251. _debug("wait on fetch %d", vnode->update_cnt);
  252. set_current_state(TASK_UNINTERRUPTIBLE);
  253. ASSERT(myself.func != NULL);
  254. add_wait_queue(&vnode->update_waitq, &myself);
  255. /* wait for the status to be updated */
  256. for (;;) {
  257. if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
  258. break;
  259. if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
  260. break;
  261. /* check to see if it got updated and invalidated all
  262. * before we saw it */
  263. if (vnode->update_cnt == 0) {
  264. remove_wait_queue(&vnode->update_waitq,
  265. &myself);
  266. set_current_state(TASK_RUNNING);
  267. goto get_anyway;
  268. }
  269. spin_unlock(&vnode->lock);
  270. schedule();
  271. set_current_state(TASK_UNINTERRUPTIBLE);
  272. spin_lock(&vnode->lock);
  273. }
  274. remove_wait_queue(&vnode->update_waitq, &myself);
  275. spin_unlock(&vnode->lock);
  276. set_current_state(TASK_RUNNING);
  277. return test_bit(AFS_VNODE_DELETED, &vnode->flags) ?
  278. -ENOENT : 0;
  279. }
  280. get_anyway:
  281. /* okay... we're going to have to initiate the op */
  282. vnode->update_cnt++;
  283. spin_unlock(&vnode->lock);
  284. /* merge AFS status fetches and clear outstanding callback on this
  285. * vnode */
  286. do {
  287. /* pick a server to query */
  288. server = afs_volume_pick_fileserver(vnode);
  289. if (IS_ERR(server))
  290. goto no_server;
  291. _debug("USING SERVER: %p{%08x}",
  292. server, ntohl(server->addr.s_addr));
  293. ret = afs_fs_fetch_file_status(server, key, vnode, NULL,
  294. &afs_sync_call);
  295. } while (!afs_volume_release_fileserver(vnode, server, ret));
  296. /* adjust the flags */
  297. if (ret == 0) {
  298. _debug("adjust");
  299. if (auth_vnode)
  300. afs_cache_permit(vnode, key, acl_order);
  301. afs_vnode_finalise_status_update(vnode, server);
  302. afs_put_server(server);
  303. } else {
  304. _debug("failed [%d]", ret);
  305. afs_vnode_status_update_failed(vnode, ret);
  306. }
  307. ASSERTCMP(vnode->update_cnt, >=, 0);
  308. _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
  309. return ret;
  310. no_server:
  311. spin_lock(&vnode->lock);
  312. vnode->update_cnt--;
  313. ASSERTCMP(vnode->update_cnt, >=, 0);
  314. spin_unlock(&vnode->lock);
  315. _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
  316. return PTR_ERR(server);
  317. }
  318. /*
  319. * fetch file data from the volume
  320. * - TODO implement caching
  321. */
  322. int afs_vnode_fetch_data(struct afs_vnode *vnode, struct key *key,
  323. off_t offset, size_t length, struct page *page)
  324. {
  325. struct afs_server *server;
  326. int ret;
  327. _enter("%s{%x:%u.%u},%x,,,",
  328. vnode->volume->vlocation->vldb.name,
  329. vnode->fid.vid,
  330. vnode->fid.vnode,
  331. vnode->fid.unique,
  332. key_serial(key));
  333. /* this op will fetch the status */
  334. spin_lock(&vnode->lock);
  335. vnode->update_cnt++;
  336. spin_unlock(&vnode->lock);
  337. /* merge in AFS status fetches and clear outstanding callback on this
  338. * vnode */
  339. do {
  340. /* pick a server to query */
  341. server = afs_volume_pick_fileserver(vnode);
  342. if (IS_ERR(server))
  343. goto no_server;
  344. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  345. ret = afs_fs_fetch_data(server, key, vnode, offset, length,
  346. page, &afs_sync_call);
  347. } while (!afs_volume_release_fileserver(vnode, server, ret));
  348. /* adjust the flags */
  349. if (ret == 0) {
  350. afs_vnode_finalise_status_update(vnode, server);
  351. afs_put_server(server);
  352. } else {
  353. afs_vnode_status_update_failed(vnode, ret);
  354. }
  355. _leave(" = %d", ret);
  356. return ret;
  357. no_server:
  358. spin_lock(&vnode->lock);
  359. vnode->update_cnt--;
  360. ASSERTCMP(vnode->update_cnt, >=, 0);
  361. spin_unlock(&vnode->lock);
  362. return PTR_ERR(server);
  363. }
  364. /*
  365. * make a file or a directory
  366. */
  367. int afs_vnode_create(struct afs_vnode *vnode, struct key *key,
  368. const char *name, umode_t mode, struct afs_fid *newfid,
  369. struct afs_file_status *newstatus,
  370. struct afs_callback *newcb, struct afs_server **_server)
  371. {
  372. struct afs_server *server;
  373. int ret;
  374. _enter("%s{%x:%u.%u},%x,%s,,",
  375. vnode->volume->vlocation->vldb.name,
  376. vnode->fid.vid,
  377. vnode->fid.vnode,
  378. vnode->fid.unique,
  379. key_serial(key),
  380. name);
  381. /* this op will fetch the status on the directory we're creating in */
  382. spin_lock(&vnode->lock);
  383. vnode->update_cnt++;
  384. spin_unlock(&vnode->lock);
  385. do {
  386. /* pick a server to query */
  387. server = afs_volume_pick_fileserver(vnode);
  388. if (IS_ERR(server))
  389. goto no_server;
  390. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  391. ret = afs_fs_create(server, key, vnode, name, mode, newfid,
  392. newstatus, newcb, &afs_sync_call);
  393. } while (!afs_volume_release_fileserver(vnode, server, ret));
  394. /* adjust the flags */
  395. if (ret == 0) {
  396. afs_vnode_finalise_status_update(vnode, server);
  397. *_server = server;
  398. } else {
  399. afs_vnode_status_update_failed(vnode, ret);
  400. *_server = NULL;
  401. }
  402. _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
  403. return ret;
  404. no_server:
  405. spin_lock(&vnode->lock);
  406. vnode->update_cnt--;
  407. ASSERTCMP(vnode->update_cnt, >=, 0);
  408. spin_unlock(&vnode->lock);
  409. _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
  410. return PTR_ERR(server);
  411. }
  412. /*
  413. * remove a file or directory
  414. */
  415. int afs_vnode_remove(struct afs_vnode *vnode, struct key *key, const char *name,
  416. bool isdir)
  417. {
  418. struct afs_server *server;
  419. int ret;
  420. _enter("%s{%x:%u.%u},%x,%s",
  421. vnode->volume->vlocation->vldb.name,
  422. vnode->fid.vid,
  423. vnode->fid.vnode,
  424. vnode->fid.unique,
  425. key_serial(key),
  426. name);
  427. /* this op will fetch the status on the directory we're removing from */
  428. spin_lock(&vnode->lock);
  429. vnode->update_cnt++;
  430. spin_unlock(&vnode->lock);
  431. do {
  432. /* pick a server to query */
  433. server = afs_volume_pick_fileserver(vnode);
  434. if (IS_ERR(server))
  435. goto no_server;
  436. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  437. ret = afs_fs_remove(server, key, vnode, name, isdir,
  438. &afs_sync_call);
  439. } while (!afs_volume_release_fileserver(vnode, server, ret));
  440. /* adjust the flags */
  441. if (ret == 0) {
  442. afs_vnode_finalise_status_update(vnode, server);
  443. afs_put_server(server);
  444. } else {
  445. afs_vnode_status_update_failed(vnode, ret);
  446. }
  447. _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
  448. return ret;
  449. no_server:
  450. spin_lock(&vnode->lock);
  451. vnode->update_cnt--;
  452. ASSERTCMP(vnode->update_cnt, >=, 0);
  453. spin_unlock(&vnode->lock);
  454. _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
  455. return PTR_ERR(server);
  456. }
  457. /*
  458. * create a hard link
  459. */
  460. int afs_vnode_link(struct afs_vnode *dvnode, struct afs_vnode *vnode,
  461. struct key *key, const char *name)
  462. {
  463. struct afs_server *server;
  464. int ret;
  465. _enter("%s{%x:%u.%u},%s{%x:%u.%u},%x,%s",
  466. dvnode->volume->vlocation->vldb.name,
  467. dvnode->fid.vid,
  468. dvnode->fid.vnode,
  469. dvnode->fid.unique,
  470. vnode->volume->vlocation->vldb.name,
  471. vnode->fid.vid,
  472. vnode->fid.vnode,
  473. vnode->fid.unique,
  474. key_serial(key),
  475. name);
  476. /* this op will fetch the status on the directory we're removing from */
  477. spin_lock(&vnode->lock);
  478. vnode->update_cnt++;
  479. spin_unlock(&vnode->lock);
  480. spin_lock(&dvnode->lock);
  481. dvnode->update_cnt++;
  482. spin_unlock(&dvnode->lock);
  483. do {
  484. /* pick a server to query */
  485. server = afs_volume_pick_fileserver(dvnode);
  486. if (IS_ERR(server))
  487. goto no_server;
  488. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  489. ret = afs_fs_link(server, key, dvnode, vnode, name,
  490. &afs_sync_call);
  491. } while (!afs_volume_release_fileserver(dvnode, server, ret));
  492. /* adjust the flags */
  493. if (ret == 0) {
  494. afs_vnode_finalise_status_update(vnode, server);
  495. afs_vnode_finalise_status_update(dvnode, server);
  496. afs_put_server(server);
  497. } else {
  498. afs_vnode_status_update_failed(vnode, ret);
  499. afs_vnode_status_update_failed(dvnode, ret);
  500. }
  501. _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
  502. return ret;
  503. no_server:
  504. spin_lock(&vnode->lock);
  505. vnode->update_cnt--;
  506. ASSERTCMP(vnode->update_cnt, >=, 0);
  507. spin_unlock(&vnode->lock);
  508. spin_lock(&dvnode->lock);
  509. dvnode->update_cnt--;
  510. ASSERTCMP(dvnode->update_cnt, >=, 0);
  511. spin_unlock(&dvnode->lock);
  512. _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
  513. return PTR_ERR(server);
  514. }
  515. /*
  516. * create a symbolic link
  517. */
  518. int afs_vnode_symlink(struct afs_vnode *vnode, struct key *key,
  519. const char *name, const char *content,
  520. struct afs_fid *newfid,
  521. struct afs_file_status *newstatus,
  522. struct afs_server **_server)
  523. {
  524. struct afs_server *server;
  525. int ret;
  526. _enter("%s{%x:%u.%u},%x,%s,%s,,,",
  527. vnode->volume->vlocation->vldb.name,
  528. vnode->fid.vid,
  529. vnode->fid.vnode,
  530. vnode->fid.unique,
  531. key_serial(key),
  532. name, content);
  533. /* this op will fetch the status on the directory we're creating in */
  534. spin_lock(&vnode->lock);
  535. vnode->update_cnt++;
  536. spin_unlock(&vnode->lock);
  537. do {
  538. /* pick a server to query */
  539. server = afs_volume_pick_fileserver(vnode);
  540. if (IS_ERR(server))
  541. goto no_server;
  542. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  543. ret = afs_fs_symlink(server, key, vnode, name, content,
  544. newfid, newstatus, &afs_sync_call);
  545. } while (!afs_volume_release_fileserver(vnode, server, ret));
  546. /* adjust the flags */
  547. if (ret == 0) {
  548. afs_vnode_finalise_status_update(vnode, server);
  549. *_server = server;
  550. } else {
  551. afs_vnode_status_update_failed(vnode, ret);
  552. *_server = NULL;
  553. }
  554. _leave(" = %d [cnt %d]", ret, vnode->update_cnt);
  555. return ret;
  556. no_server:
  557. spin_lock(&vnode->lock);
  558. vnode->update_cnt--;
  559. ASSERTCMP(vnode->update_cnt, >=, 0);
  560. spin_unlock(&vnode->lock);
  561. _leave(" = %ld [cnt %d]", PTR_ERR(server), vnode->update_cnt);
  562. return PTR_ERR(server);
  563. }
  564. /*
  565. * rename a file
  566. */
  567. int afs_vnode_rename(struct afs_vnode *orig_dvnode,
  568. struct afs_vnode *new_dvnode,
  569. struct key *key,
  570. const char *orig_name,
  571. const char *new_name)
  572. {
  573. struct afs_server *server;
  574. int ret;
  575. _enter("%s{%x:%u.%u},%s{%u,%u,%u},%x,%s,%s",
  576. orig_dvnode->volume->vlocation->vldb.name,
  577. orig_dvnode->fid.vid,
  578. orig_dvnode->fid.vnode,
  579. orig_dvnode->fid.unique,
  580. new_dvnode->volume->vlocation->vldb.name,
  581. new_dvnode->fid.vid,
  582. new_dvnode->fid.vnode,
  583. new_dvnode->fid.unique,
  584. key_serial(key),
  585. orig_name,
  586. new_name);
  587. /* this op will fetch the status on both the directories we're dealing
  588. * with */
  589. spin_lock(&orig_dvnode->lock);
  590. orig_dvnode->update_cnt++;
  591. spin_unlock(&orig_dvnode->lock);
  592. if (new_dvnode != orig_dvnode) {
  593. spin_lock(&new_dvnode->lock);
  594. new_dvnode->update_cnt++;
  595. spin_unlock(&new_dvnode->lock);
  596. }
  597. do {
  598. /* pick a server to query */
  599. server = afs_volume_pick_fileserver(orig_dvnode);
  600. if (IS_ERR(server))
  601. goto no_server;
  602. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  603. ret = afs_fs_rename(server, key, orig_dvnode, orig_name,
  604. new_dvnode, new_name, &afs_sync_call);
  605. } while (!afs_volume_release_fileserver(orig_dvnode, server, ret));
  606. /* adjust the flags */
  607. if (ret == 0) {
  608. afs_vnode_finalise_status_update(orig_dvnode, server);
  609. if (new_dvnode != orig_dvnode)
  610. afs_vnode_finalise_status_update(new_dvnode, server);
  611. afs_put_server(server);
  612. } else {
  613. afs_vnode_status_update_failed(orig_dvnode, ret);
  614. if (new_dvnode != orig_dvnode)
  615. afs_vnode_status_update_failed(new_dvnode, ret);
  616. }
  617. _leave(" = %d [cnt %d]", ret, orig_dvnode->update_cnt);
  618. return ret;
  619. no_server:
  620. spin_lock(&orig_dvnode->lock);
  621. orig_dvnode->update_cnt--;
  622. ASSERTCMP(orig_dvnode->update_cnt, >=, 0);
  623. spin_unlock(&orig_dvnode->lock);
  624. if (new_dvnode != orig_dvnode) {
  625. spin_lock(&new_dvnode->lock);
  626. new_dvnode->update_cnt--;
  627. ASSERTCMP(new_dvnode->update_cnt, >=, 0);
  628. spin_unlock(&new_dvnode->lock);
  629. }
  630. _leave(" = %ld [cnt %d]", PTR_ERR(server), orig_dvnode->update_cnt);
  631. return PTR_ERR(server);
  632. }
  633. /*
  634. * write to a file
  635. */
  636. int afs_vnode_store_data(struct afs_writeback *wb, pgoff_t first, pgoff_t last,
  637. unsigned offset, unsigned to)
  638. {
  639. struct afs_server *server;
  640. struct afs_vnode *vnode = wb->vnode;
  641. int ret;
  642. _enter("%s{%x:%u.%u},%x,%lx,%lx,%x,%x",
  643. vnode->volume->vlocation->vldb.name,
  644. vnode->fid.vid,
  645. vnode->fid.vnode,
  646. vnode->fid.unique,
  647. key_serial(wb->key),
  648. first, last, offset, to);
  649. /* this op will fetch the status */
  650. spin_lock(&vnode->lock);
  651. vnode->update_cnt++;
  652. spin_unlock(&vnode->lock);
  653. do {
  654. /* pick a server to query */
  655. server = afs_volume_pick_fileserver(vnode);
  656. if (IS_ERR(server))
  657. goto no_server;
  658. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  659. ret = afs_fs_store_data(server, wb, first, last, offset, to,
  660. &afs_sync_call);
  661. } while (!afs_volume_release_fileserver(vnode, server, ret));
  662. /* adjust the flags */
  663. if (ret == 0) {
  664. afs_vnode_finalise_status_update(vnode, server);
  665. afs_put_server(server);
  666. } else {
  667. afs_vnode_status_update_failed(vnode, ret);
  668. }
  669. _leave(" = %d", ret);
  670. return ret;
  671. no_server:
  672. spin_lock(&vnode->lock);
  673. vnode->update_cnt--;
  674. ASSERTCMP(vnode->update_cnt, >=, 0);
  675. spin_unlock(&vnode->lock);
  676. return PTR_ERR(server);
  677. }
  678. /*
  679. * set the attributes on a file
  680. */
  681. int afs_vnode_setattr(struct afs_vnode *vnode, struct key *key,
  682. struct iattr *attr)
  683. {
  684. struct afs_server *server;
  685. int ret;
  686. _enter("%s{%x:%u.%u},%x",
  687. vnode->volume->vlocation->vldb.name,
  688. vnode->fid.vid,
  689. vnode->fid.vnode,
  690. vnode->fid.unique,
  691. key_serial(key));
  692. /* this op will fetch the status */
  693. spin_lock(&vnode->lock);
  694. vnode->update_cnt++;
  695. spin_unlock(&vnode->lock);
  696. do {
  697. /* pick a server to query */
  698. server = afs_volume_pick_fileserver(vnode);
  699. if (IS_ERR(server))
  700. goto no_server;
  701. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  702. ret = afs_fs_setattr(server, key, vnode, attr, &afs_sync_call);
  703. } while (!afs_volume_release_fileserver(vnode, server, ret));
  704. /* adjust the flags */
  705. if (ret == 0) {
  706. afs_vnode_finalise_status_update(vnode, server);
  707. afs_put_server(server);
  708. } else {
  709. afs_vnode_status_update_failed(vnode, ret);
  710. }
  711. _leave(" = %d", ret);
  712. return ret;
  713. no_server:
  714. spin_lock(&vnode->lock);
  715. vnode->update_cnt--;
  716. ASSERTCMP(vnode->update_cnt, >=, 0);
  717. spin_unlock(&vnode->lock);
  718. return PTR_ERR(server);
  719. }
  720. /*
  721. * get the status of a volume
  722. */
  723. int afs_vnode_get_volume_status(struct afs_vnode *vnode, struct key *key,
  724. struct afs_volume_status *vs)
  725. {
  726. struct afs_server *server;
  727. int ret;
  728. _enter("%s{%x:%u.%u},%x,",
  729. vnode->volume->vlocation->vldb.name,
  730. vnode->fid.vid,
  731. vnode->fid.vnode,
  732. vnode->fid.unique,
  733. key_serial(key));
  734. do {
  735. /* pick a server to query */
  736. server = afs_volume_pick_fileserver(vnode);
  737. if (IS_ERR(server))
  738. goto no_server;
  739. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  740. ret = afs_fs_get_volume_status(server, key, vnode, vs, &afs_sync_call);
  741. } while (!afs_volume_release_fileserver(vnode, server, ret));
  742. /* adjust the flags */
  743. if (ret == 0)
  744. afs_put_server(server);
  745. _leave(" = %d", ret);
  746. return ret;
  747. no_server:
  748. return PTR_ERR(server);
  749. }
  750. /*
  751. * get a lock on a file
  752. */
  753. int afs_vnode_set_lock(struct afs_vnode *vnode, struct key *key,
  754. afs_lock_type_t type)
  755. {
  756. struct afs_server *server;
  757. int ret;
  758. _enter("%s{%x:%u.%u},%x,%u",
  759. vnode->volume->vlocation->vldb.name,
  760. vnode->fid.vid,
  761. vnode->fid.vnode,
  762. vnode->fid.unique,
  763. key_serial(key), type);
  764. do {
  765. /* pick a server to query */
  766. server = afs_volume_pick_fileserver(vnode);
  767. if (IS_ERR(server))
  768. goto no_server;
  769. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  770. ret = afs_fs_set_lock(server, key, vnode, type, &afs_sync_call);
  771. } while (!afs_volume_release_fileserver(vnode, server, ret));
  772. /* adjust the flags */
  773. if (ret == 0)
  774. afs_put_server(server);
  775. _leave(" = %d", ret);
  776. return ret;
  777. no_server:
  778. return PTR_ERR(server);
  779. }
  780. /*
  781. * extend a lock on a file
  782. */
  783. int afs_vnode_extend_lock(struct afs_vnode *vnode, struct key *key)
  784. {
  785. struct afs_server *server;
  786. int ret;
  787. _enter("%s{%x:%u.%u},%x",
  788. vnode->volume->vlocation->vldb.name,
  789. vnode->fid.vid,
  790. vnode->fid.vnode,
  791. vnode->fid.unique,
  792. key_serial(key));
  793. do {
  794. /* pick a server to query */
  795. server = afs_volume_pick_fileserver(vnode);
  796. if (IS_ERR(server))
  797. goto no_server;
  798. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  799. ret = afs_fs_extend_lock(server, key, vnode, &afs_sync_call);
  800. } while (!afs_volume_release_fileserver(vnode, server, ret));
  801. /* adjust the flags */
  802. if (ret == 0)
  803. afs_put_server(server);
  804. _leave(" = %d", ret);
  805. return ret;
  806. no_server:
  807. return PTR_ERR(server);
  808. }
  809. /*
  810. * release a lock on a file
  811. */
  812. int afs_vnode_release_lock(struct afs_vnode *vnode, struct key *key)
  813. {
  814. struct afs_server *server;
  815. int ret;
  816. _enter("%s{%x:%u.%u},%x",
  817. vnode->volume->vlocation->vldb.name,
  818. vnode->fid.vid,
  819. vnode->fid.vnode,
  820. vnode->fid.unique,
  821. key_serial(key));
  822. do {
  823. /* pick a server to query */
  824. server = afs_volume_pick_fileserver(vnode);
  825. if (IS_ERR(server))
  826. goto no_server;
  827. _debug("USING SERVER: %08x\n", ntohl(server->addr.s_addr));
  828. ret = afs_fs_release_lock(server, key, vnode, &afs_sync_call);
  829. } while (!afs_volume_release_fileserver(vnode, server, ret));
  830. /* adjust the flags */
  831. if (ret == 0)
  832. afs_put_server(server);
  833. _leave(" = %d", ret);
  834. return ret;
  835. no_server:
  836. return PTR_ERR(server);
  837. }