nfs4state.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. /*
  2. * fs/nfs/nfs4state.c
  3. *
  4. * Client-side XDR for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of the University nor the names of its
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  25. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  31. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * Implementation of the NFSv4 state model. For the time being,
  37. * this is minimal, but will be made much more complex in a
  38. * subsequent patch.
  39. */
  40. #include <linux/kernel.h>
  41. #include <linux/slab.h>
  42. #include <linux/smp_lock.h>
  43. #include <linux/nfs_fs.h>
  44. #include <linux/nfs_idmap.h>
  45. #include <linux/kthread.h>
  46. #include <linux/module.h>
  47. #include <linux/random.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/bitops.h>
  50. #include "nfs4_fs.h"
  51. #include "callback.h"
  52. #include "delegation.h"
  53. #include "internal.h"
  54. #define OPENOWNER_POOL_SIZE 8
  55. const nfs4_stateid zero_stateid;
  56. static LIST_HEAD(nfs4_clientid_list);
  57. static int nfs4_init_client(struct nfs_client *clp, struct rpc_cred *cred)
  58. {
  59. int status = nfs4_proc_setclientid(clp, NFS4_CALLBACK,
  60. nfs_callback_tcpport, cred);
  61. if (status == 0)
  62. status = nfs4_proc_setclientid_confirm(clp, cred);
  63. if (status == 0)
  64. nfs4_schedule_state_renewal(clp);
  65. return status;
  66. }
  67. static struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp)
  68. {
  69. struct rpc_cred *cred = NULL;
  70. if (clp->cl_machine_cred != NULL)
  71. cred = get_rpccred(clp->cl_machine_cred);
  72. return cred;
  73. }
  74. static void nfs4_clear_machine_cred(struct nfs_client *clp)
  75. {
  76. struct rpc_cred *cred;
  77. spin_lock(&clp->cl_lock);
  78. cred = clp->cl_machine_cred;
  79. clp->cl_machine_cred = NULL;
  80. spin_unlock(&clp->cl_lock);
  81. if (cred != NULL)
  82. put_rpccred(cred);
  83. }
  84. struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
  85. {
  86. struct nfs4_state_owner *sp;
  87. struct rb_node *pos;
  88. struct rpc_cred *cred = NULL;
  89. for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
  90. sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
  91. if (list_empty(&sp->so_states))
  92. continue;
  93. cred = get_rpccred(sp->so_cred);
  94. break;
  95. }
  96. return cred;
  97. }
  98. static struct rpc_cred *nfs4_get_renew_cred(struct nfs_client *clp)
  99. {
  100. struct rpc_cred *cred;
  101. spin_lock(&clp->cl_lock);
  102. cred = nfs4_get_renew_cred_locked(clp);
  103. spin_unlock(&clp->cl_lock);
  104. return cred;
  105. }
  106. static struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp)
  107. {
  108. struct nfs4_state_owner *sp;
  109. struct rb_node *pos;
  110. struct rpc_cred *cred;
  111. spin_lock(&clp->cl_lock);
  112. cred = nfs4_get_machine_cred_locked(clp);
  113. if (cred != NULL)
  114. goto out;
  115. pos = rb_first(&clp->cl_state_owners);
  116. if (pos != NULL) {
  117. sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
  118. cred = get_rpccred(sp->so_cred);
  119. }
  120. out:
  121. spin_unlock(&clp->cl_lock);
  122. return cred;
  123. }
  124. static void nfs_alloc_unique_id(struct rb_root *root, struct nfs_unique_id *new,
  125. __u64 minval, int maxbits)
  126. {
  127. struct rb_node **p, *parent;
  128. struct nfs_unique_id *pos;
  129. __u64 mask = ~0ULL;
  130. if (maxbits < 64)
  131. mask = (1ULL << maxbits) - 1ULL;
  132. /* Ensure distribution is more or less flat */
  133. get_random_bytes(&new->id, sizeof(new->id));
  134. new->id &= mask;
  135. if (new->id < minval)
  136. new->id += minval;
  137. retry:
  138. p = &root->rb_node;
  139. parent = NULL;
  140. while (*p != NULL) {
  141. parent = *p;
  142. pos = rb_entry(parent, struct nfs_unique_id, rb_node);
  143. if (new->id < pos->id)
  144. p = &(*p)->rb_left;
  145. else if (new->id > pos->id)
  146. p = &(*p)->rb_right;
  147. else
  148. goto id_exists;
  149. }
  150. rb_link_node(&new->rb_node, parent, p);
  151. rb_insert_color(&new->rb_node, root);
  152. return;
  153. id_exists:
  154. for (;;) {
  155. new->id++;
  156. if (new->id < minval || (new->id & mask) != new->id) {
  157. new->id = minval;
  158. break;
  159. }
  160. parent = rb_next(parent);
  161. if (parent == NULL)
  162. break;
  163. pos = rb_entry(parent, struct nfs_unique_id, rb_node);
  164. if (new->id < pos->id)
  165. break;
  166. }
  167. goto retry;
  168. }
  169. static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id)
  170. {
  171. rb_erase(&id->rb_node, root);
  172. }
  173. static struct nfs4_state_owner *
  174. nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred)
  175. {
  176. struct nfs_client *clp = server->nfs_client;
  177. struct rb_node **p = &clp->cl_state_owners.rb_node,
  178. *parent = NULL;
  179. struct nfs4_state_owner *sp, *res = NULL;
  180. while (*p != NULL) {
  181. parent = *p;
  182. sp = rb_entry(parent, struct nfs4_state_owner, so_client_node);
  183. if (server < sp->so_server) {
  184. p = &parent->rb_left;
  185. continue;
  186. }
  187. if (server > sp->so_server) {
  188. p = &parent->rb_right;
  189. continue;
  190. }
  191. if (cred < sp->so_cred)
  192. p = &parent->rb_left;
  193. else if (cred > sp->so_cred)
  194. p = &parent->rb_right;
  195. else {
  196. atomic_inc(&sp->so_count);
  197. res = sp;
  198. break;
  199. }
  200. }
  201. return res;
  202. }
  203. static struct nfs4_state_owner *
  204. nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new)
  205. {
  206. struct rb_node **p = &clp->cl_state_owners.rb_node,
  207. *parent = NULL;
  208. struct nfs4_state_owner *sp;
  209. while (*p != NULL) {
  210. parent = *p;
  211. sp = rb_entry(parent, struct nfs4_state_owner, so_client_node);
  212. if (new->so_server < sp->so_server) {
  213. p = &parent->rb_left;
  214. continue;
  215. }
  216. if (new->so_server > sp->so_server) {
  217. p = &parent->rb_right;
  218. continue;
  219. }
  220. if (new->so_cred < sp->so_cred)
  221. p = &parent->rb_left;
  222. else if (new->so_cred > sp->so_cred)
  223. p = &parent->rb_right;
  224. else {
  225. atomic_inc(&sp->so_count);
  226. return sp;
  227. }
  228. }
  229. nfs_alloc_unique_id(&clp->cl_openowner_id, &new->so_owner_id, 1, 64);
  230. rb_link_node(&new->so_client_node, parent, p);
  231. rb_insert_color(&new->so_client_node, &clp->cl_state_owners);
  232. return new;
  233. }
  234. static void
  235. nfs4_remove_state_owner(struct nfs_client *clp, struct nfs4_state_owner *sp)
  236. {
  237. if (!RB_EMPTY_NODE(&sp->so_client_node))
  238. rb_erase(&sp->so_client_node, &clp->cl_state_owners);
  239. nfs_free_unique_id(&clp->cl_openowner_id, &sp->so_owner_id);
  240. }
  241. /*
  242. * nfs4_alloc_state_owner(): this is called on the OPEN or CREATE path to
  243. * create a new state_owner.
  244. *
  245. */
  246. static struct nfs4_state_owner *
  247. nfs4_alloc_state_owner(void)
  248. {
  249. struct nfs4_state_owner *sp;
  250. sp = kzalloc(sizeof(*sp),GFP_KERNEL);
  251. if (!sp)
  252. return NULL;
  253. spin_lock_init(&sp->so_lock);
  254. INIT_LIST_HEAD(&sp->so_states);
  255. INIT_LIST_HEAD(&sp->so_delegations);
  256. rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue");
  257. sp->so_seqid.sequence = &sp->so_sequence;
  258. spin_lock_init(&sp->so_sequence.lock);
  259. INIT_LIST_HEAD(&sp->so_sequence.list);
  260. atomic_set(&sp->so_count, 1);
  261. return sp;
  262. }
  263. static void
  264. nfs4_drop_state_owner(struct nfs4_state_owner *sp)
  265. {
  266. if (!RB_EMPTY_NODE(&sp->so_client_node)) {
  267. struct nfs_client *clp = sp->so_client;
  268. spin_lock(&clp->cl_lock);
  269. rb_erase(&sp->so_client_node, &clp->cl_state_owners);
  270. RB_CLEAR_NODE(&sp->so_client_node);
  271. spin_unlock(&clp->cl_lock);
  272. }
  273. }
  274. struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct rpc_cred *cred)
  275. {
  276. struct nfs_client *clp = server->nfs_client;
  277. struct nfs4_state_owner *sp, *new;
  278. spin_lock(&clp->cl_lock);
  279. sp = nfs4_find_state_owner(server, cred);
  280. spin_unlock(&clp->cl_lock);
  281. if (sp != NULL)
  282. return sp;
  283. new = nfs4_alloc_state_owner();
  284. if (new == NULL)
  285. return NULL;
  286. new->so_client = clp;
  287. new->so_server = server;
  288. new->so_cred = cred;
  289. spin_lock(&clp->cl_lock);
  290. sp = nfs4_insert_state_owner(clp, new);
  291. spin_unlock(&clp->cl_lock);
  292. if (sp == new)
  293. get_rpccred(cred);
  294. else {
  295. rpc_destroy_wait_queue(&new->so_sequence.wait);
  296. kfree(new);
  297. }
  298. return sp;
  299. }
  300. void nfs4_put_state_owner(struct nfs4_state_owner *sp)
  301. {
  302. struct nfs_client *clp = sp->so_client;
  303. struct rpc_cred *cred = sp->so_cred;
  304. if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock))
  305. return;
  306. nfs4_remove_state_owner(clp, sp);
  307. spin_unlock(&clp->cl_lock);
  308. rpc_destroy_wait_queue(&sp->so_sequence.wait);
  309. put_rpccred(cred);
  310. kfree(sp);
  311. }
  312. static struct nfs4_state *
  313. nfs4_alloc_open_state(void)
  314. {
  315. struct nfs4_state *state;
  316. state = kzalloc(sizeof(*state), GFP_KERNEL);
  317. if (!state)
  318. return NULL;
  319. atomic_set(&state->count, 1);
  320. INIT_LIST_HEAD(&state->lock_states);
  321. spin_lock_init(&state->state_lock);
  322. seqlock_init(&state->seqlock);
  323. return state;
  324. }
  325. void
  326. nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode)
  327. {
  328. if (state->state == fmode)
  329. return;
  330. /* NB! List reordering - see the reclaim code for why. */
  331. if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) {
  332. if (fmode & FMODE_WRITE)
  333. list_move(&state->open_states, &state->owner->so_states);
  334. else
  335. list_move_tail(&state->open_states, &state->owner->so_states);
  336. }
  337. state->state = fmode;
  338. }
  339. static struct nfs4_state *
  340. __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner)
  341. {
  342. struct nfs_inode *nfsi = NFS_I(inode);
  343. struct nfs4_state *state;
  344. list_for_each_entry(state, &nfsi->open_states, inode_states) {
  345. if (state->owner != owner)
  346. continue;
  347. if (atomic_inc_not_zero(&state->count))
  348. return state;
  349. }
  350. return NULL;
  351. }
  352. static void
  353. nfs4_free_open_state(struct nfs4_state *state)
  354. {
  355. kfree(state);
  356. }
  357. struct nfs4_state *
  358. nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
  359. {
  360. struct nfs4_state *state, *new;
  361. struct nfs_inode *nfsi = NFS_I(inode);
  362. spin_lock(&inode->i_lock);
  363. state = __nfs4_find_state_byowner(inode, owner);
  364. spin_unlock(&inode->i_lock);
  365. if (state)
  366. goto out;
  367. new = nfs4_alloc_open_state();
  368. spin_lock(&owner->so_lock);
  369. spin_lock(&inode->i_lock);
  370. state = __nfs4_find_state_byowner(inode, owner);
  371. if (state == NULL && new != NULL) {
  372. state = new;
  373. state->owner = owner;
  374. atomic_inc(&owner->so_count);
  375. list_add(&state->inode_states, &nfsi->open_states);
  376. state->inode = igrab(inode);
  377. spin_unlock(&inode->i_lock);
  378. /* Note: The reclaim code dictates that we add stateless
  379. * and read-only stateids to the end of the list */
  380. list_add_tail(&state->open_states, &owner->so_states);
  381. spin_unlock(&owner->so_lock);
  382. } else {
  383. spin_unlock(&inode->i_lock);
  384. spin_unlock(&owner->so_lock);
  385. if (new)
  386. nfs4_free_open_state(new);
  387. }
  388. out:
  389. return state;
  390. }
  391. void nfs4_put_open_state(struct nfs4_state *state)
  392. {
  393. struct inode *inode = state->inode;
  394. struct nfs4_state_owner *owner = state->owner;
  395. if (!atomic_dec_and_lock(&state->count, &owner->so_lock))
  396. return;
  397. spin_lock(&inode->i_lock);
  398. list_del(&state->inode_states);
  399. list_del(&state->open_states);
  400. spin_unlock(&inode->i_lock);
  401. spin_unlock(&owner->so_lock);
  402. iput(inode);
  403. nfs4_free_open_state(state);
  404. nfs4_put_state_owner(owner);
  405. }
  406. /*
  407. * Close the current file.
  408. */
  409. static void __nfs4_close(struct path *path, struct nfs4_state *state, fmode_t fmode, int wait)
  410. {
  411. struct nfs4_state_owner *owner = state->owner;
  412. int call_close = 0;
  413. fmode_t newstate;
  414. atomic_inc(&owner->so_count);
  415. /* Protect against nfs4_find_state() */
  416. spin_lock(&owner->so_lock);
  417. switch (fmode & (FMODE_READ | FMODE_WRITE)) {
  418. case FMODE_READ:
  419. state->n_rdonly--;
  420. break;
  421. case FMODE_WRITE:
  422. state->n_wronly--;
  423. break;
  424. case FMODE_READ|FMODE_WRITE:
  425. state->n_rdwr--;
  426. }
  427. newstate = FMODE_READ|FMODE_WRITE;
  428. if (state->n_rdwr == 0) {
  429. if (state->n_rdonly == 0) {
  430. newstate &= ~FMODE_READ;
  431. call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
  432. call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
  433. }
  434. if (state->n_wronly == 0) {
  435. newstate &= ~FMODE_WRITE;
  436. call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
  437. call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
  438. }
  439. if (newstate == 0)
  440. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  441. }
  442. nfs4_state_set_mode_locked(state, newstate);
  443. spin_unlock(&owner->so_lock);
  444. if (!call_close) {
  445. nfs4_put_open_state(state);
  446. nfs4_put_state_owner(owner);
  447. } else
  448. nfs4_do_close(path, state, wait);
  449. }
  450. void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode)
  451. {
  452. __nfs4_close(path, state, fmode, 0);
  453. }
  454. void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode)
  455. {
  456. __nfs4_close(path, state, fmode, 1);
  457. }
  458. /*
  459. * Search the state->lock_states for an existing lock_owner
  460. * that is compatible with current->files
  461. */
  462. static struct nfs4_lock_state *
  463. __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
  464. {
  465. struct nfs4_lock_state *pos;
  466. list_for_each_entry(pos, &state->lock_states, ls_locks) {
  467. if (pos->ls_owner != fl_owner)
  468. continue;
  469. atomic_inc(&pos->ls_count);
  470. return pos;
  471. }
  472. return NULL;
  473. }
  474. /*
  475. * Return a compatible lock_state. If no initialized lock_state structure
  476. * exists, return an uninitialized one.
  477. *
  478. */
  479. static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
  480. {
  481. struct nfs4_lock_state *lsp;
  482. struct nfs_client *clp = state->owner->so_client;
  483. lsp = kzalloc(sizeof(*lsp), GFP_KERNEL);
  484. if (lsp == NULL)
  485. return NULL;
  486. rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue");
  487. spin_lock_init(&lsp->ls_sequence.lock);
  488. INIT_LIST_HEAD(&lsp->ls_sequence.list);
  489. lsp->ls_seqid.sequence = &lsp->ls_sequence;
  490. atomic_set(&lsp->ls_count, 1);
  491. lsp->ls_owner = fl_owner;
  492. spin_lock(&clp->cl_lock);
  493. nfs_alloc_unique_id(&clp->cl_lockowner_id, &lsp->ls_id, 1, 64);
  494. spin_unlock(&clp->cl_lock);
  495. INIT_LIST_HEAD(&lsp->ls_locks);
  496. return lsp;
  497. }
  498. static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
  499. {
  500. struct nfs_client *clp = lsp->ls_state->owner->so_client;
  501. spin_lock(&clp->cl_lock);
  502. nfs_free_unique_id(&clp->cl_lockowner_id, &lsp->ls_id);
  503. spin_unlock(&clp->cl_lock);
  504. rpc_destroy_wait_queue(&lsp->ls_sequence.wait);
  505. kfree(lsp);
  506. }
  507. /*
  508. * Return a compatible lock_state. If no initialized lock_state structure
  509. * exists, return an uninitialized one.
  510. *
  511. */
  512. static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner)
  513. {
  514. struct nfs4_lock_state *lsp, *new = NULL;
  515. for(;;) {
  516. spin_lock(&state->state_lock);
  517. lsp = __nfs4_find_lock_state(state, owner);
  518. if (lsp != NULL)
  519. break;
  520. if (new != NULL) {
  521. new->ls_state = state;
  522. list_add(&new->ls_locks, &state->lock_states);
  523. set_bit(LK_STATE_IN_USE, &state->flags);
  524. lsp = new;
  525. new = NULL;
  526. break;
  527. }
  528. spin_unlock(&state->state_lock);
  529. new = nfs4_alloc_lock_state(state, owner);
  530. if (new == NULL)
  531. return NULL;
  532. }
  533. spin_unlock(&state->state_lock);
  534. if (new != NULL)
  535. nfs4_free_lock_state(new);
  536. return lsp;
  537. }
  538. /*
  539. * Release reference to lock_state, and free it if we see that
  540. * it is no longer in use
  541. */
  542. void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
  543. {
  544. struct nfs4_state *state;
  545. if (lsp == NULL)
  546. return;
  547. state = lsp->ls_state;
  548. if (!atomic_dec_and_lock(&lsp->ls_count, &state->state_lock))
  549. return;
  550. list_del(&lsp->ls_locks);
  551. if (list_empty(&state->lock_states))
  552. clear_bit(LK_STATE_IN_USE, &state->flags);
  553. spin_unlock(&state->state_lock);
  554. nfs4_free_lock_state(lsp);
  555. }
  556. static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
  557. {
  558. struct nfs4_lock_state *lsp = src->fl_u.nfs4_fl.owner;
  559. dst->fl_u.nfs4_fl.owner = lsp;
  560. atomic_inc(&lsp->ls_count);
  561. }
  562. static void nfs4_fl_release_lock(struct file_lock *fl)
  563. {
  564. nfs4_put_lock_state(fl->fl_u.nfs4_fl.owner);
  565. }
  566. static struct file_lock_operations nfs4_fl_lock_ops = {
  567. .fl_copy_lock = nfs4_fl_copy_lock,
  568. .fl_release_private = nfs4_fl_release_lock,
  569. };
  570. int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
  571. {
  572. struct nfs4_lock_state *lsp;
  573. if (fl->fl_ops != NULL)
  574. return 0;
  575. lsp = nfs4_get_lock_state(state, fl->fl_owner);
  576. if (lsp == NULL)
  577. return -ENOMEM;
  578. fl->fl_u.nfs4_fl.owner = lsp;
  579. fl->fl_ops = &nfs4_fl_lock_ops;
  580. return 0;
  581. }
  582. /*
  583. * Byte-range lock aware utility to initialize the stateid of read/write
  584. * requests.
  585. */
  586. void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner)
  587. {
  588. struct nfs4_lock_state *lsp;
  589. int seq;
  590. do {
  591. seq = read_seqbegin(&state->seqlock);
  592. memcpy(dst, &state->stateid, sizeof(*dst));
  593. } while (read_seqretry(&state->seqlock, seq));
  594. if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
  595. return;
  596. spin_lock(&state->state_lock);
  597. lsp = __nfs4_find_lock_state(state, fl_owner);
  598. if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
  599. memcpy(dst, &lsp->ls_stateid, sizeof(*dst));
  600. spin_unlock(&state->state_lock);
  601. nfs4_put_lock_state(lsp);
  602. }
  603. struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter)
  604. {
  605. struct nfs_seqid *new;
  606. new = kmalloc(sizeof(*new), GFP_KERNEL);
  607. if (new != NULL) {
  608. new->sequence = counter;
  609. INIT_LIST_HEAD(&new->list);
  610. }
  611. return new;
  612. }
  613. void nfs_free_seqid(struct nfs_seqid *seqid)
  614. {
  615. if (!list_empty(&seqid->list)) {
  616. struct rpc_sequence *sequence = seqid->sequence->sequence;
  617. spin_lock(&sequence->lock);
  618. list_del(&seqid->list);
  619. spin_unlock(&sequence->lock);
  620. rpc_wake_up(&sequence->wait);
  621. }
  622. kfree(seqid);
  623. }
  624. /*
  625. * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or
  626. * failed with a seqid incrementing error -
  627. * see comments nfs_fs.h:seqid_mutating_error()
  628. */
  629. static void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
  630. {
  631. BUG_ON(list_first_entry(&seqid->sequence->sequence->list, struct nfs_seqid, list) != seqid);
  632. switch (status) {
  633. case 0:
  634. break;
  635. case -NFS4ERR_BAD_SEQID:
  636. if (seqid->sequence->flags & NFS_SEQID_CONFIRMED)
  637. return;
  638. printk(KERN_WARNING "NFS: v4 server returned a bad"
  639. " sequence-id error on an"
  640. " unconfirmed sequence %p!\n",
  641. seqid->sequence);
  642. case -NFS4ERR_STALE_CLIENTID:
  643. case -NFS4ERR_STALE_STATEID:
  644. case -NFS4ERR_BAD_STATEID:
  645. case -NFS4ERR_BADXDR:
  646. case -NFS4ERR_RESOURCE:
  647. case -NFS4ERR_NOFILEHANDLE:
  648. /* Non-seqid mutating errors */
  649. return;
  650. };
  651. /*
  652. * Note: no locking needed as we are guaranteed to be first
  653. * on the sequence list
  654. */
  655. seqid->sequence->counter++;
  656. }
  657. void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid)
  658. {
  659. if (status == -NFS4ERR_BAD_SEQID) {
  660. struct nfs4_state_owner *sp = container_of(seqid->sequence,
  661. struct nfs4_state_owner, so_seqid);
  662. nfs4_drop_state_owner(sp);
  663. }
  664. nfs_increment_seqid(status, seqid);
  665. }
  666. /*
  667. * Increment the seqid if the LOCK/LOCKU succeeded, or
  668. * failed with a seqid incrementing error -
  669. * see comments nfs_fs.h:seqid_mutating_error()
  670. */
  671. void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid)
  672. {
  673. nfs_increment_seqid(status, seqid);
  674. }
  675. int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task)
  676. {
  677. struct rpc_sequence *sequence = seqid->sequence->sequence;
  678. int status = 0;
  679. spin_lock(&sequence->lock);
  680. if (list_empty(&seqid->list))
  681. list_add_tail(&seqid->list, &sequence->list);
  682. if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid)
  683. goto unlock;
  684. rpc_sleep_on(&sequence->wait, task, NULL);
  685. status = -EAGAIN;
  686. unlock:
  687. spin_unlock(&sequence->lock);
  688. return status;
  689. }
  690. static int nfs4_run_state_manager(void *);
  691. static void nfs4_clear_state_manager_bit(struct nfs_client *clp)
  692. {
  693. smp_mb__before_clear_bit();
  694. clear_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state);
  695. smp_mb__after_clear_bit();
  696. wake_up_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING);
  697. rpc_wake_up(&clp->cl_rpcwaitq);
  698. }
  699. /*
  700. * Schedule the nfs_client asynchronous state management routine
  701. */
  702. void nfs4_schedule_state_manager(struct nfs_client *clp)
  703. {
  704. struct task_struct *task;
  705. if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
  706. return;
  707. __module_get(THIS_MODULE);
  708. atomic_inc(&clp->cl_count);
  709. task = kthread_run(nfs4_run_state_manager, clp, "%s-manager",
  710. rpc_peeraddr2str(clp->cl_rpcclient,
  711. RPC_DISPLAY_ADDR));
  712. if (!IS_ERR(task))
  713. return;
  714. nfs4_clear_state_manager_bit(clp);
  715. nfs_put_client(clp);
  716. module_put(THIS_MODULE);
  717. }
  718. /*
  719. * Schedule a state recovery attempt
  720. */
  721. void nfs4_schedule_state_recovery(struct nfs_client *clp)
  722. {
  723. if (!clp)
  724. return;
  725. if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  726. set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
  727. nfs4_schedule_state_manager(clp);
  728. }
  729. static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
  730. {
  731. set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
  732. /* Don't recover state that expired before the reboot */
  733. if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) {
  734. clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
  735. return 0;
  736. }
  737. set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags);
  738. set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
  739. return 1;
  740. }
  741. int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state)
  742. {
  743. set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
  744. clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
  745. set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags);
  746. set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
  747. return 1;
  748. }
  749. static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
  750. {
  751. struct inode *inode = state->inode;
  752. struct nfs_inode *nfsi = NFS_I(inode);
  753. struct file_lock *fl;
  754. int status = 0;
  755. down_write(&nfsi->rwsem);
  756. for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
  757. if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
  758. continue;
  759. if (nfs_file_open_context(fl->fl_file)->state != state)
  760. continue;
  761. status = ops->recover_lock(state, fl);
  762. if (status >= 0)
  763. continue;
  764. switch (status) {
  765. default:
  766. printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n",
  767. __func__, status);
  768. case -NFS4ERR_EXPIRED:
  769. case -NFS4ERR_NO_GRACE:
  770. case -NFS4ERR_RECLAIM_BAD:
  771. case -NFS4ERR_RECLAIM_CONFLICT:
  772. /* kill_proc(fl->fl_pid, SIGLOST, 1); */
  773. break;
  774. case -NFS4ERR_STALE_CLIENTID:
  775. goto out_err;
  776. }
  777. }
  778. up_write(&nfsi->rwsem);
  779. return 0;
  780. out_err:
  781. up_write(&nfsi->rwsem);
  782. return status;
  783. }
  784. static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
  785. {
  786. struct nfs4_state *state;
  787. struct nfs4_lock_state *lock;
  788. int status = 0;
  789. /* Note: we rely on the sp->so_states list being ordered
  790. * so that we always reclaim open(O_RDWR) and/or open(O_WRITE)
  791. * states first.
  792. * This is needed to ensure that the server won't give us any
  793. * read delegations that we have to return if, say, we are
  794. * recovering after a network partition or a reboot from a
  795. * server that doesn't support a grace period.
  796. */
  797. restart:
  798. spin_lock(&sp->so_lock);
  799. list_for_each_entry(state, &sp->so_states, open_states) {
  800. if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
  801. continue;
  802. if (state->state == 0)
  803. continue;
  804. atomic_inc(&state->count);
  805. spin_unlock(&sp->so_lock);
  806. status = ops->recover_open(sp, state);
  807. if (status >= 0) {
  808. status = nfs4_reclaim_locks(state, ops);
  809. if (status >= 0) {
  810. list_for_each_entry(lock, &state->lock_states, ls_locks) {
  811. if (!(lock->ls_flags & NFS_LOCK_INITIALIZED))
  812. printk("%s: Lock reclaim failed!\n",
  813. __func__);
  814. }
  815. nfs4_put_open_state(state);
  816. goto restart;
  817. }
  818. }
  819. switch (status) {
  820. default:
  821. printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n",
  822. __func__, status);
  823. case -ENOENT:
  824. case -ESTALE:
  825. /*
  826. * Open state on this file cannot be recovered
  827. * All we can do is revert to using the zero stateid.
  828. */
  829. memset(state->stateid.data, 0,
  830. sizeof(state->stateid.data));
  831. /* Mark the file as being 'closed' */
  832. state->state = 0;
  833. break;
  834. case -NFS4ERR_RECLAIM_BAD:
  835. case -NFS4ERR_RECLAIM_CONFLICT:
  836. nfs4_state_mark_reclaim_nograce(sp->so_client, state);
  837. break;
  838. case -NFS4ERR_EXPIRED:
  839. case -NFS4ERR_NO_GRACE:
  840. nfs4_state_mark_reclaim_nograce(sp->so_client, state);
  841. case -NFS4ERR_STALE_CLIENTID:
  842. goto out_err;
  843. }
  844. nfs4_put_open_state(state);
  845. goto restart;
  846. }
  847. spin_unlock(&sp->so_lock);
  848. return 0;
  849. out_err:
  850. nfs4_put_open_state(state);
  851. return status;
  852. }
  853. static void nfs4_clear_open_state(struct nfs4_state *state)
  854. {
  855. struct nfs4_lock_state *lock;
  856. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  857. clear_bit(NFS_O_RDONLY_STATE, &state->flags);
  858. clear_bit(NFS_O_WRONLY_STATE, &state->flags);
  859. clear_bit(NFS_O_RDWR_STATE, &state->flags);
  860. list_for_each_entry(lock, &state->lock_states, ls_locks) {
  861. lock->ls_seqid.flags = 0;
  862. lock->ls_flags &= ~NFS_LOCK_INITIALIZED;
  863. }
  864. }
  865. static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp, int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
  866. {
  867. struct nfs4_state_owner *sp;
  868. struct rb_node *pos;
  869. struct nfs4_state *state;
  870. /* Reset all sequence ids to zero */
  871. for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
  872. sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
  873. sp->so_seqid.flags = 0;
  874. spin_lock(&sp->so_lock);
  875. list_for_each_entry(state, &sp->so_states, open_states) {
  876. if (mark_reclaim(clp, state))
  877. nfs4_clear_open_state(state);
  878. }
  879. spin_unlock(&sp->so_lock);
  880. }
  881. }
  882. static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
  883. {
  884. /* Mark all delegations for reclaim */
  885. nfs_delegation_mark_reclaim(clp);
  886. nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot);
  887. }
  888. static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
  889. {
  890. struct nfs4_state_owner *sp;
  891. struct rb_node *pos;
  892. struct nfs4_state *state;
  893. if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
  894. return;
  895. for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
  896. sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
  897. spin_lock(&sp->so_lock);
  898. list_for_each_entry(state, &sp->so_states, open_states) {
  899. if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags))
  900. continue;
  901. nfs4_state_mark_reclaim_nograce(clp, state);
  902. }
  903. spin_unlock(&sp->so_lock);
  904. }
  905. nfs_delegation_reap_unclaimed(clp);
  906. }
  907. static void nfs_delegation_clear_all(struct nfs_client *clp)
  908. {
  909. nfs_delegation_mark_reclaim(clp);
  910. nfs_delegation_reap_unclaimed(clp);
  911. }
  912. static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
  913. {
  914. nfs_delegation_clear_all(clp);
  915. nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
  916. }
  917. static void nfs4_state_end_reclaim_nograce(struct nfs_client *clp)
  918. {
  919. clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
  920. }
  921. static void nfs4_recovery_handle_error(struct nfs_client *clp, int error)
  922. {
  923. switch (error) {
  924. case -NFS4ERR_CB_PATH_DOWN:
  925. nfs_handle_cb_pathdown(clp);
  926. break;
  927. case -NFS4ERR_STALE_CLIENTID:
  928. case -NFS4ERR_LEASE_MOVED:
  929. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  930. nfs4_state_start_reclaim_reboot(clp);
  931. break;
  932. case -NFS4ERR_EXPIRED:
  933. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  934. nfs4_state_start_reclaim_nograce(clp);
  935. }
  936. }
  937. static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops)
  938. {
  939. struct rb_node *pos;
  940. int status = 0;
  941. restart:
  942. spin_lock(&clp->cl_lock);
  943. for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
  944. struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
  945. if (!test_and_clear_bit(ops->owner_flag_bit, &sp->so_flags))
  946. continue;
  947. atomic_inc(&sp->so_count);
  948. spin_unlock(&clp->cl_lock);
  949. status = nfs4_reclaim_open_state(sp, ops);
  950. if (status < 0) {
  951. set_bit(ops->owner_flag_bit, &sp->so_flags);
  952. nfs4_put_state_owner(sp);
  953. nfs4_recovery_handle_error(clp, status);
  954. return status;
  955. }
  956. nfs4_put_state_owner(sp);
  957. goto restart;
  958. }
  959. spin_unlock(&clp->cl_lock);
  960. return status;
  961. }
  962. static int nfs4_check_lease(struct nfs_client *clp)
  963. {
  964. struct rpc_cred *cred;
  965. int status = -NFS4ERR_EXPIRED;
  966. /* Is the client already known to have an expired lease? */
  967. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  968. return 0;
  969. cred = nfs4_get_renew_cred(clp);
  970. if (cred == NULL) {
  971. cred = nfs4_get_setclientid_cred(clp);
  972. if (cred == NULL)
  973. goto out;
  974. }
  975. status = nfs4_proc_renew(clp, cred);
  976. put_rpccred(cred);
  977. out:
  978. nfs4_recovery_handle_error(clp, status);
  979. return status;
  980. }
  981. static int nfs4_reclaim_lease(struct nfs_client *clp)
  982. {
  983. struct rpc_cred *cred;
  984. int status = -ENOENT;
  985. cred = nfs4_get_setclientid_cred(clp);
  986. if (cred != NULL) {
  987. status = nfs4_init_client(clp, cred);
  988. put_rpccred(cred);
  989. /* Handle case where the user hasn't set up machine creds */
  990. if (status == -EACCES && cred == clp->cl_machine_cred) {
  991. nfs4_clear_machine_cred(clp);
  992. status = -EAGAIN;
  993. }
  994. }
  995. return status;
  996. }
  997. static void nfs4_state_manager(struct nfs_client *clp)
  998. {
  999. int status = 0;
  1000. /* Ensure exclusive access to NFSv4 state */
  1001. for(;;) {
  1002. if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) {
  1003. /* We're going to have to re-establish a clientid */
  1004. status = nfs4_reclaim_lease(clp);
  1005. if (status) {
  1006. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  1007. if (status == -EAGAIN)
  1008. continue;
  1009. goto out_error;
  1010. }
  1011. clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
  1012. }
  1013. if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) {
  1014. status = nfs4_check_lease(clp);
  1015. if (status != 0)
  1016. continue;
  1017. }
  1018. /* First recover reboot state... */
  1019. if (test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
  1020. status = nfs4_do_reclaim(clp, &nfs4_reboot_recovery_ops);
  1021. if (status == -NFS4ERR_STALE_CLIENTID)
  1022. continue;
  1023. nfs4_state_end_reclaim_reboot(clp);
  1024. continue;
  1025. }
  1026. /* Now recover expired state... */
  1027. if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
  1028. status = nfs4_do_reclaim(clp, &nfs4_nograce_recovery_ops);
  1029. if (status < 0) {
  1030. set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
  1031. if (status == -NFS4ERR_STALE_CLIENTID)
  1032. continue;
  1033. if (status == -NFS4ERR_EXPIRED)
  1034. continue;
  1035. goto out_error;
  1036. } else
  1037. nfs4_state_end_reclaim_nograce(clp);
  1038. continue;
  1039. }
  1040. if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) {
  1041. nfs_client_return_marked_delegations(clp);
  1042. continue;
  1043. }
  1044. nfs4_clear_state_manager_bit(clp);
  1045. /* Did we race with an attempt to give us more work? */
  1046. if (clp->cl_state == 0)
  1047. break;
  1048. if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
  1049. break;
  1050. }
  1051. return;
  1052. out_error:
  1053. printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s"
  1054. " with error %d\n", clp->cl_hostname, -status);
  1055. if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
  1056. nfs4_state_end_reclaim_reboot(clp);
  1057. nfs4_clear_state_manager_bit(clp);
  1058. }
  1059. static int nfs4_run_state_manager(void *ptr)
  1060. {
  1061. struct nfs_client *clp = ptr;
  1062. allow_signal(SIGKILL);
  1063. nfs4_state_manager(clp);
  1064. nfs_put_client(clp);
  1065. module_put_and_exit(0);
  1066. return 0;
  1067. }
  1068. /*
  1069. * Local variables:
  1070. * c-basic-offset: 8
  1071. * End:
  1072. */