vnode.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. }