daemon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /* Daemon interface
  2. *
  3. * Copyright (C) 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 Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include <linux/completion.h>
  15. #include <linux/slab.h>
  16. #include <linux/fs.h>
  17. #include <linux/file.h>
  18. #include <linux/namei.h>
  19. #include <linux/poll.h>
  20. #include <linux/mount.h>
  21. #include <linux/statfs.h>
  22. #include <linux/ctype.h>
  23. #include <linux/fs_struct.h>
  24. #include "internal.h"
  25. static int cachefiles_daemon_open(struct inode *, struct file *);
  26. static int cachefiles_daemon_release(struct inode *, struct file *);
  27. static ssize_t cachefiles_daemon_read(struct file *, char __user *, size_t,
  28. loff_t *);
  29. static ssize_t cachefiles_daemon_write(struct file *, const char __user *,
  30. size_t, loff_t *);
  31. static unsigned int cachefiles_daemon_poll(struct file *,
  32. struct poll_table_struct *);
  33. static int cachefiles_daemon_frun(struct cachefiles_cache *, char *);
  34. static int cachefiles_daemon_fcull(struct cachefiles_cache *, char *);
  35. static int cachefiles_daemon_fstop(struct cachefiles_cache *, char *);
  36. static int cachefiles_daemon_brun(struct cachefiles_cache *, char *);
  37. static int cachefiles_daemon_bcull(struct cachefiles_cache *, char *);
  38. static int cachefiles_daemon_bstop(struct cachefiles_cache *, char *);
  39. static int cachefiles_daemon_cull(struct cachefiles_cache *, char *);
  40. static int cachefiles_daemon_debug(struct cachefiles_cache *, char *);
  41. static int cachefiles_daemon_dir(struct cachefiles_cache *, char *);
  42. static int cachefiles_daemon_inuse(struct cachefiles_cache *, char *);
  43. static int cachefiles_daemon_secctx(struct cachefiles_cache *, char *);
  44. static int cachefiles_daemon_tag(struct cachefiles_cache *, char *);
  45. static unsigned long cachefiles_open;
  46. const struct file_operations cachefiles_daemon_fops = {
  47. .owner = THIS_MODULE,
  48. .open = cachefiles_daemon_open,
  49. .release = cachefiles_daemon_release,
  50. .read = cachefiles_daemon_read,
  51. .write = cachefiles_daemon_write,
  52. .poll = cachefiles_daemon_poll,
  53. };
  54. struct cachefiles_daemon_cmd {
  55. char name[8];
  56. int (*handler)(struct cachefiles_cache *cache, char *args);
  57. };
  58. static const struct cachefiles_daemon_cmd cachefiles_daemon_cmds[] = {
  59. { "bind", cachefiles_daemon_bind },
  60. { "brun", cachefiles_daemon_brun },
  61. { "bcull", cachefiles_daemon_bcull },
  62. { "bstop", cachefiles_daemon_bstop },
  63. { "cull", cachefiles_daemon_cull },
  64. { "debug", cachefiles_daemon_debug },
  65. { "dir", cachefiles_daemon_dir },
  66. { "frun", cachefiles_daemon_frun },
  67. { "fcull", cachefiles_daemon_fcull },
  68. { "fstop", cachefiles_daemon_fstop },
  69. { "inuse", cachefiles_daemon_inuse },
  70. { "secctx", cachefiles_daemon_secctx },
  71. { "tag", cachefiles_daemon_tag },
  72. { "", NULL }
  73. };
  74. /*
  75. * do various checks
  76. */
  77. static int cachefiles_daemon_open(struct inode *inode, struct file *file)
  78. {
  79. struct cachefiles_cache *cache;
  80. _enter("");
  81. /* only the superuser may do this */
  82. if (!capable(CAP_SYS_ADMIN))
  83. return -EPERM;
  84. /* the cachefiles device may only be open once at a time */
  85. if (xchg(&cachefiles_open, 1) == 1)
  86. return -EBUSY;
  87. /* allocate a cache record */
  88. cache = kzalloc(sizeof(struct cachefiles_cache), GFP_KERNEL);
  89. if (!cache) {
  90. cachefiles_open = 0;
  91. return -ENOMEM;
  92. }
  93. mutex_init(&cache->daemon_mutex);
  94. cache->active_nodes = RB_ROOT;
  95. rwlock_init(&cache->active_lock);
  96. init_waitqueue_head(&cache->daemon_pollwq);
  97. /* set default caching limits
  98. * - limit at 1% free space and/or free files
  99. * - cull below 5% free space and/or free files
  100. * - cease culling above 7% free space and/or free files
  101. */
  102. cache->frun_percent = 7;
  103. cache->fcull_percent = 5;
  104. cache->fstop_percent = 1;
  105. cache->brun_percent = 7;
  106. cache->bcull_percent = 5;
  107. cache->bstop_percent = 1;
  108. file->private_data = cache;
  109. cache->cachefilesd = file;
  110. return 0;
  111. }
  112. /*
  113. * release a cache
  114. */
  115. static int cachefiles_daemon_release(struct inode *inode, struct file *file)
  116. {
  117. struct cachefiles_cache *cache = file->private_data;
  118. _enter("");
  119. ASSERT(cache);
  120. set_bit(CACHEFILES_DEAD, &cache->flags);
  121. cachefiles_daemon_unbind(cache);
  122. ASSERT(!cache->active_nodes.rb_node);
  123. /* clean up the control file interface */
  124. cache->cachefilesd = NULL;
  125. file->private_data = NULL;
  126. cachefiles_open = 0;
  127. kfree(cache);
  128. _leave("");
  129. return 0;
  130. }
  131. /*
  132. * read the cache state
  133. */
  134. static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
  135. size_t buflen, loff_t *pos)
  136. {
  137. struct cachefiles_cache *cache = file->private_data;
  138. char buffer[256];
  139. int n;
  140. //_enter(",,%zu,", buflen);
  141. if (!test_bit(CACHEFILES_READY, &cache->flags))
  142. return 0;
  143. /* check how much space the cache has */
  144. cachefiles_has_space(cache, 0, 0);
  145. /* summarise */
  146. clear_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
  147. n = snprintf(buffer, sizeof(buffer),
  148. "cull=%c"
  149. " frun=%llx"
  150. " fcull=%llx"
  151. " fstop=%llx"
  152. " brun=%llx"
  153. " bcull=%llx"
  154. " bstop=%llx",
  155. test_bit(CACHEFILES_CULLING, &cache->flags) ? '1' : '0',
  156. (unsigned long long) cache->frun,
  157. (unsigned long long) cache->fcull,
  158. (unsigned long long) cache->fstop,
  159. (unsigned long long) cache->brun,
  160. (unsigned long long) cache->bcull,
  161. (unsigned long long) cache->bstop
  162. );
  163. if (n > buflen)
  164. return -EMSGSIZE;
  165. if (copy_to_user(_buffer, buffer, n) != 0)
  166. return -EFAULT;
  167. return n;
  168. }
  169. /*
  170. * command the cache
  171. */
  172. static ssize_t cachefiles_daemon_write(struct file *file,
  173. const char __user *_data,
  174. size_t datalen,
  175. loff_t *pos)
  176. {
  177. const struct cachefiles_daemon_cmd *cmd;
  178. struct cachefiles_cache *cache = file->private_data;
  179. ssize_t ret;
  180. char *data, *args, *cp;
  181. //_enter(",,%zu,", datalen);
  182. ASSERT(cache);
  183. if (test_bit(CACHEFILES_DEAD, &cache->flags))
  184. return -EIO;
  185. if (datalen < 0 || datalen > PAGE_SIZE - 1)
  186. return -EOPNOTSUPP;
  187. /* drag the command string into the kernel so we can parse it */
  188. data = kmalloc(datalen + 1, GFP_KERNEL);
  189. if (!data)
  190. return -ENOMEM;
  191. ret = -EFAULT;
  192. if (copy_from_user(data, _data, datalen) != 0)
  193. goto error;
  194. data[datalen] = '\0';
  195. ret = -EINVAL;
  196. if (memchr(data, '\0', datalen))
  197. goto error;
  198. /* strip any newline */
  199. cp = memchr(data, '\n', datalen);
  200. if (cp) {
  201. if (cp == data)
  202. goto error;
  203. *cp = '\0';
  204. }
  205. /* parse the command */
  206. ret = -EOPNOTSUPP;
  207. for (args = data; *args; args++)
  208. if (isspace(*args))
  209. break;
  210. if (*args) {
  211. if (args == data)
  212. goto error;
  213. *args = '\0';
  214. for (args++; isspace(*args); args++)
  215. continue;
  216. }
  217. /* run the appropriate command handler */
  218. for (cmd = cachefiles_daemon_cmds; cmd->name[0]; cmd++)
  219. if (strcmp(cmd->name, data) == 0)
  220. goto found_command;
  221. error:
  222. kfree(data);
  223. //_leave(" = %zd", ret);
  224. return ret;
  225. found_command:
  226. mutex_lock(&cache->daemon_mutex);
  227. ret = -EIO;
  228. if (!test_bit(CACHEFILES_DEAD, &cache->flags))
  229. ret = cmd->handler(cache, args);
  230. mutex_unlock(&cache->daemon_mutex);
  231. if (ret == 0)
  232. ret = datalen;
  233. goto error;
  234. }
  235. /*
  236. * poll for culling state
  237. * - use POLLOUT to indicate culling state
  238. */
  239. static unsigned int cachefiles_daemon_poll(struct file *file,
  240. struct poll_table_struct *poll)
  241. {
  242. struct cachefiles_cache *cache = file->private_data;
  243. unsigned int mask;
  244. poll_wait(file, &cache->daemon_pollwq, poll);
  245. mask = 0;
  246. if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))
  247. mask |= POLLIN;
  248. if (test_bit(CACHEFILES_CULLING, &cache->flags))
  249. mask |= POLLOUT;
  250. return mask;
  251. }
  252. /*
  253. * give a range error for cache space constraints
  254. * - can be tail-called
  255. */
  256. static int cachefiles_daemon_range_error(struct cachefiles_cache *cache,
  257. char *args)
  258. {
  259. kerror("Free space limits must be in range"
  260. " 0%%<=stop<cull<run<100%%");
  261. return -EINVAL;
  262. }
  263. /*
  264. * set the percentage of files at which to stop culling
  265. * - command: "frun <N>%"
  266. */
  267. static int cachefiles_daemon_frun(struct cachefiles_cache *cache, char *args)
  268. {
  269. unsigned long frun;
  270. _enter(",%s", args);
  271. if (!*args)
  272. return -EINVAL;
  273. frun = simple_strtoul(args, &args, 10);
  274. if (args[0] != '%' || args[1] != '\0')
  275. return -EINVAL;
  276. if (frun <= cache->fcull_percent || frun >= 100)
  277. return cachefiles_daemon_range_error(cache, args);
  278. cache->frun_percent = frun;
  279. return 0;
  280. }
  281. /*
  282. * set the percentage of files at which to start culling
  283. * - command: "fcull <N>%"
  284. */
  285. static int cachefiles_daemon_fcull(struct cachefiles_cache *cache, char *args)
  286. {
  287. unsigned long fcull;
  288. _enter(",%s", args);
  289. if (!*args)
  290. return -EINVAL;
  291. fcull = simple_strtoul(args, &args, 10);
  292. if (args[0] != '%' || args[1] != '\0')
  293. return -EINVAL;
  294. if (fcull <= cache->fstop_percent || fcull >= cache->frun_percent)
  295. return cachefiles_daemon_range_error(cache, args);
  296. cache->fcull_percent = fcull;
  297. return 0;
  298. }
  299. /*
  300. * set the percentage of files at which to stop allocating
  301. * - command: "fstop <N>%"
  302. */
  303. static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
  304. {
  305. unsigned long fstop;
  306. _enter(",%s", args);
  307. if (!*args)
  308. return -EINVAL;
  309. fstop = simple_strtoul(args, &args, 10);
  310. if (args[0] != '%' || args[1] != '\0')
  311. return -EINVAL;
  312. if (fstop < 0 || fstop >= cache->fcull_percent)
  313. return cachefiles_daemon_range_error(cache, args);
  314. cache->fstop_percent = fstop;
  315. return 0;
  316. }
  317. /*
  318. * set the percentage of blocks at which to stop culling
  319. * - command: "brun <N>%"
  320. */
  321. static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args)
  322. {
  323. unsigned long brun;
  324. _enter(",%s", args);
  325. if (!*args)
  326. return -EINVAL;
  327. brun = simple_strtoul(args, &args, 10);
  328. if (args[0] != '%' || args[1] != '\0')
  329. return -EINVAL;
  330. if (brun <= cache->bcull_percent || brun >= 100)
  331. return cachefiles_daemon_range_error(cache, args);
  332. cache->brun_percent = brun;
  333. return 0;
  334. }
  335. /*
  336. * set the percentage of blocks at which to start culling
  337. * - command: "bcull <N>%"
  338. */
  339. static int cachefiles_daemon_bcull(struct cachefiles_cache *cache, char *args)
  340. {
  341. unsigned long bcull;
  342. _enter(",%s", args);
  343. if (!*args)
  344. return -EINVAL;
  345. bcull = simple_strtoul(args, &args, 10);
  346. if (args[0] != '%' || args[1] != '\0')
  347. return -EINVAL;
  348. if (bcull <= cache->bstop_percent || bcull >= cache->brun_percent)
  349. return cachefiles_daemon_range_error(cache, args);
  350. cache->bcull_percent = bcull;
  351. return 0;
  352. }
  353. /*
  354. * set the percentage of blocks at which to stop allocating
  355. * - command: "bstop <N>%"
  356. */
  357. static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
  358. {
  359. unsigned long bstop;
  360. _enter(",%s", args);
  361. if (!*args)
  362. return -EINVAL;
  363. bstop = simple_strtoul(args, &args, 10);
  364. if (args[0] != '%' || args[1] != '\0')
  365. return -EINVAL;
  366. if (bstop < 0 || bstop >= cache->bcull_percent)
  367. return cachefiles_daemon_range_error(cache, args);
  368. cache->bstop_percent = bstop;
  369. return 0;
  370. }
  371. /*
  372. * set the cache directory
  373. * - command: "dir <name>"
  374. */
  375. static int cachefiles_daemon_dir(struct cachefiles_cache *cache, char *args)
  376. {
  377. char *dir;
  378. _enter(",%s", args);
  379. if (!*args) {
  380. kerror("Empty directory specified");
  381. return -EINVAL;
  382. }
  383. if (cache->rootdirname) {
  384. kerror("Second cache directory specified");
  385. return -EEXIST;
  386. }
  387. dir = kstrdup(args, GFP_KERNEL);
  388. if (!dir)
  389. return -ENOMEM;
  390. cache->rootdirname = dir;
  391. return 0;
  392. }
  393. /*
  394. * set the cache security context
  395. * - command: "secctx <ctx>"
  396. */
  397. static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args)
  398. {
  399. char *secctx;
  400. _enter(",%s", args);
  401. if (!*args) {
  402. kerror("Empty security context specified");
  403. return -EINVAL;
  404. }
  405. if (cache->secctx) {
  406. kerror("Second security context specified");
  407. return -EINVAL;
  408. }
  409. secctx = kstrdup(args, GFP_KERNEL);
  410. if (!secctx)
  411. return -ENOMEM;
  412. cache->secctx = secctx;
  413. return 0;
  414. }
  415. /*
  416. * set the cache tag
  417. * - command: "tag <name>"
  418. */
  419. static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args)
  420. {
  421. char *tag;
  422. _enter(",%s", args);
  423. if (!*args) {
  424. kerror("Empty tag specified");
  425. return -EINVAL;
  426. }
  427. if (cache->tag)
  428. return -EEXIST;
  429. tag = kstrdup(args, GFP_KERNEL);
  430. if (!tag)
  431. return -ENOMEM;
  432. cache->tag = tag;
  433. return 0;
  434. }
  435. /*
  436. * request a node in the cache be culled from the current working directory
  437. * - command: "cull <name>"
  438. */
  439. static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
  440. {
  441. struct fs_struct *fs;
  442. struct dentry *dir;
  443. const struct cred *saved_cred;
  444. int ret;
  445. _enter(",%s", args);
  446. if (strchr(args, '/'))
  447. goto inval;
  448. if (!test_bit(CACHEFILES_READY, &cache->flags)) {
  449. kerror("cull applied to unready cache");
  450. return -EIO;
  451. }
  452. if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
  453. kerror("cull applied to dead cache");
  454. return -EIO;
  455. }
  456. /* extract the directory dentry from the cwd */
  457. fs = current->fs;
  458. read_lock(&fs->lock);
  459. dir = dget(fs->pwd.dentry);
  460. read_unlock(&fs->lock);
  461. if (!S_ISDIR(dir->d_inode->i_mode))
  462. goto notdir;
  463. cachefiles_begin_secure(cache, &saved_cred);
  464. ret = cachefiles_cull(cache, dir, args);
  465. cachefiles_end_secure(cache, saved_cred);
  466. dput(dir);
  467. _leave(" = %d", ret);
  468. return ret;
  469. notdir:
  470. dput(dir);
  471. kerror("cull command requires dirfd to be a directory");
  472. return -ENOTDIR;
  473. inval:
  474. kerror("cull command requires dirfd and filename");
  475. return -EINVAL;
  476. }
  477. /*
  478. * set debugging mode
  479. * - command: "debug <mask>"
  480. */
  481. static int cachefiles_daemon_debug(struct cachefiles_cache *cache, char *args)
  482. {
  483. unsigned long mask;
  484. _enter(",%s", args);
  485. mask = simple_strtoul(args, &args, 0);
  486. if (args[0] != '\0')
  487. goto inval;
  488. cachefiles_debug = mask;
  489. _leave(" = 0");
  490. return 0;
  491. inval:
  492. kerror("debug command requires mask");
  493. return -EINVAL;
  494. }
  495. /*
  496. * find out whether an object in the current working directory is in use or not
  497. * - command: "inuse <name>"
  498. */
  499. static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
  500. {
  501. struct fs_struct *fs;
  502. struct dentry *dir;
  503. const struct cred *saved_cred;
  504. int ret;
  505. //_enter(",%s", args);
  506. if (strchr(args, '/'))
  507. goto inval;
  508. if (!test_bit(CACHEFILES_READY, &cache->flags)) {
  509. kerror("inuse applied to unready cache");
  510. return -EIO;
  511. }
  512. if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
  513. kerror("inuse applied to dead cache");
  514. return -EIO;
  515. }
  516. /* extract the directory dentry from the cwd */
  517. fs = current->fs;
  518. read_lock(&fs->lock);
  519. dir = dget(fs->pwd.dentry);
  520. read_unlock(&fs->lock);
  521. if (!S_ISDIR(dir->d_inode->i_mode))
  522. goto notdir;
  523. cachefiles_begin_secure(cache, &saved_cred);
  524. ret = cachefiles_check_in_use(cache, dir, args);
  525. cachefiles_end_secure(cache, saved_cred);
  526. dput(dir);
  527. //_leave(" = %d", ret);
  528. return ret;
  529. notdir:
  530. dput(dir);
  531. kerror("inuse command requires dirfd to be a directory");
  532. return -ENOTDIR;
  533. inval:
  534. kerror("inuse command requires dirfd and filename");
  535. return -EINVAL;
  536. }
  537. /*
  538. * see if we have space for a number of pages and/or a number of files in the
  539. * cache
  540. */
  541. int cachefiles_has_space(struct cachefiles_cache *cache,
  542. unsigned fnr, unsigned bnr)
  543. {
  544. struct kstatfs stats;
  545. int ret;
  546. //_enter("{%llu,%llu,%llu,%llu,%llu,%llu},%u,%u",
  547. // (unsigned long long) cache->frun,
  548. // (unsigned long long) cache->fcull,
  549. // (unsigned long long) cache->fstop,
  550. // (unsigned long long) cache->brun,
  551. // (unsigned long long) cache->bcull,
  552. // (unsigned long long) cache->bstop,
  553. // fnr, bnr);
  554. /* find out how many pages of blockdev are available */
  555. memset(&stats, 0, sizeof(stats));
  556. ret = vfs_statfs(cache->mnt->mnt_root, &stats);
  557. if (ret < 0) {
  558. if (ret == -EIO)
  559. cachefiles_io_error(cache, "statfs failed");
  560. _leave(" = %d", ret);
  561. return ret;
  562. }
  563. stats.f_bavail >>= cache->bshift;
  564. //_debug("avail %llu,%llu",
  565. // (unsigned long long) stats.f_ffree,
  566. // (unsigned long long) stats.f_bavail);
  567. /* see if there is sufficient space */
  568. if (stats.f_ffree > fnr)
  569. stats.f_ffree -= fnr;
  570. else
  571. stats.f_ffree = 0;
  572. if (stats.f_bavail > bnr)
  573. stats.f_bavail -= bnr;
  574. else
  575. stats.f_bavail = 0;
  576. ret = -ENOBUFS;
  577. if (stats.f_ffree < cache->fstop ||
  578. stats.f_bavail < cache->bstop)
  579. goto begin_cull;
  580. ret = 0;
  581. if (stats.f_ffree < cache->fcull ||
  582. stats.f_bavail < cache->bcull)
  583. goto begin_cull;
  584. if (test_bit(CACHEFILES_CULLING, &cache->flags) &&
  585. stats.f_ffree >= cache->frun &&
  586. stats.f_bavail >= cache->brun &&
  587. test_and_clear_bit(CACHEFILES_CULLING, &cache->flags)
  588. ) {
  589. _debug("cease culling");
  590. cachefiles_state_changed(cache);
  591. }
  592. //_leave(" = 0");
  593. return 0;
  594. begin_cull:
  595. if (!test_and_set_bit(CACHEFILES_CULLING, &cache->flags)) {
  596. _debug("### CULL CACHE ###");
  597. cachefiles_state_changed(cache);
  598. }
  599. _leave(" = %d", ret);
  600. return ret;
  601. }