quota_tree.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * vfsv0 quota IO operations on file
  3. */
  4. #include <linux/errno.h>
  5. #include <linux/fs.h>
  6. #include <linux/mount.h>
  7. #include <linux/dqblk_v2.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/slab.h>
  12. #include <linux/quotaops.h>
  13. #include <asm/byteorder.h>
  14. #include "quota_tree.h"
  15. MODULE_AUTHOR("Jan Kara");
  16. MODULE_DESCRIPTION("Quota trie support");
  17. MODULE_LICENSE("GPL");
  18. #define __QUOTA_QT_PARANOIA
  19. static int get_index(struct qtree_mem_dqinfo *info, qid_t id, int depth)
  20. {
  21. unsigned int epb = info->dqi_usable_bs >> 2;
  22. depth = info->dqi_qtree_depth - depth - 1;
  23. while (depth--)
  24. id /= epb;
  25. return id % epb;
  26. }
  27. /* Number of entries in one blocks */
  28. static int qtree_dqstr_in_blk(struct qtree_mem_dqinfo *info)
  29. {
  30. return (info->dqi_usable_bs - sizeof(struct qt_disk_dqdbheader))
  31. / info->dqi_entry_size;
  32. }
  33. static char *getdqbuf(size_t size)
  34. {
  35. char *buf = kmalloc(size, GFP_NOFS);
  36. if (!buf)
  37. printk(KERN_WARNING
  38. "VFS: Not enough memory for quota buffers.\n");
  39. return buf;
  40. }
  41. static ssize_t read_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf)
  42. {
  43. struct super_block *sb = info->dqi_sb;
  44. memset(buf, 0, info->dqi_usable_bs);
  45. return sb->s_op->quota_read(sb, info->dqi_type, buf,
  46. info->dqi_usable_bs, blk << info->dqi_blocksize_bits);
  47. }
  48. static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf)
  49. {
  50. struct super_block *sb = info->dqi_sb;
  51. return sb->s_op->quota_write(sb, info->dqi_type, buf,
  52. info->dqi_usable_bs, blk << info->dqi_blocksize_bits);
  53. }
  54. /* Remove empty block from list and return it */
  55. static int get_free_dqblk(struct qtree_mem_dqinfo *info)
  56. {
  57. char *buf = getdqbuf(info->dqi_usable_bs);
  58. struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
  59. int ret, blk;
  60. if (!buf)
  61. return -ENOMEM;
  62. if (info->dqi_free_blk) {
  63. blk = info->dqi_free_blk;
  64. ret = read_blk(info, blk, buf);
  65. if (ret < 0)
  66. goto out_buf;
  67. info->dqi_free_blk = le32_to_cpu(dh->dqdh_next_free);
  68. }
  69. else {
  70. memset(buf, 0, info->dqi_usable_bs);
  71. /* Assure block allocation... */
  72. ret = write_blk(info, info->dqi_blocks, buf);
  73. if (ret < 0)
  74. goto out_buf;
  75. blk = info->dqi_blocks++;
  76. }
  77. mark_info_dirty(info->dqi_sb, info->dqi_type);
  78. ret = blk;
  79. out_buf:
  80. kfree(buf);
  81. return ret;
  82. }
  83. /* Insert empty block to the list */
  84. static int put_free_dqblk(struct qtree_mem_dqinfo *info, char *buf, uint blk)
  85. {
  86. struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
  87. int err;
  88. dh->dqdh_next_free = cpu_to_le32(info->dqi_free_blk);
  89. dh->dqdh_prev_free = cpu_to_le32(0);
  90. dh->dqdh_entries = cpu_to_le16(0);
  91. err = write_blk(info, blk, buf);
  92. if (err < 0)
  93. return err;
  94. info->dqi_free_blk = blk;
  95. mark_info_dirty(info->dqi_sb, info->dqi_type);
  96. return 0;
  97. }
  98. /* Remove given block from the list of blocks with free entries */
  99. static int remove_free_dqentry(struct qtree_mem_dqinfo *info, char *buf,
  100. uint blk)
  101. {
  102. char *tmpbuf = getdqbuf(info->dqi_usable_bs);
  103. struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
  104. uint nextblk = le32_to_cpu(dh->dqdh_next_free);
  105. uint prevblk = le32_to_cpu(dh->dqdh_prev_free);
  106. int err;
  107. if (!tmpbuf)
  108. return -ENOMEM;
  109. if (nextblk) {
  110. err = read_blk(info, nextblk, tmpbuf);
  111. if (err < 0)
  112. goto out_buf;
  113. ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_prev_free =
  114. dh->dqdh_prev_free;
  115. err = write_blk(info, nextblk, tmpbuf);
  116. if (err < 0)
  117. goto out_buf;
  118. }
  119. if (prevblk) {
  120. err = read_blk(info, prevblk, tmpbuf);
  121. if (err < 0)
  122. goto out_buf;
  123. ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_next_free =
  124. dh->dqdh_next_free;
  125. err = write_blk(info, prevblk, tmpbuf);
  126. if (err < 0)
  127. goto out_buf;
  128. } else {
  129. info->dqi_free_entry = nextblk;
  130. mark_info_dirty(info->dqi_sb, info->dqi_type);
  131. }
  132. kfree(tmpbuf);
  133. dh->dqdh_next_free = dh->dqdh_prev_free = cpu_to_le32(0);
  134. /* No matter whether write succeeds block is out of list */
  135. if (write_blk(info, blk, buf) < 0)
  136. printk(KERN_ERR
  137. "VFS: Can't write block (%u) with free entries.\n",
  138. blk);
  139. return 0;
  140. out_buf:
  141. kfree(tmpbuf);
  142. return err;
  143. }
  144. /* Insert given block to the beginning of list with free entries */
  145. static int insert_free_dqentry(struct qtree_mem_dqinfo *info, char *buf,
  146. uint blk)
  147. {
  148. char *tmpbuf = getdqbuf(info->dqi_usable_bs);
  149. struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
  150. int err;
  151. if (!tmpbuf)
  152. return -ENOMEM;
  153. dh->dqdh_next_free = cpu_to_le32(info->dqi_free_entry);
  154. dh->dqdh_prev_free = cpu_to_le32(0);
  155. err = write_blk(info, blk, buf);
  156. if (err < 0)
  157. goto out_buf;
  158. if (info->dqi_free_entry) {
  159. err = read_blk(info, info->dqi_free_entry, tmpbuf);
  160. if (err < 0)
  161. goto out_buf;
  162. ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_prev_free =
  163. cpu_to_le32(blk);
  164. err = write_blk(info, info->dqi_free_entry, tmpbuf);
  165. if (err < 0)
  166. goto out_buf;
  167. }
  168. kfree(tmpbuf);
  169. info->dqi_free_entry = blk;
  170. mark_info_dirty(info->dqi_sb, info->dqi_type);
  171. return 0;
  172. out_buf:
  173. kfree(tmpbuf);
  174. return err;
  175. }
  176. /* Is the entry in the block free? */
  177. int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk)
  178. {
  179. int i;
  180. for (i = 0; i < info->dqi_entry_size; i++)
  181. if (disk[i])
  182. return 0;
  183. return 1;
  184. }
  185. EXPORT_SYMBOL(qtree_entry_unused);
  186. /* Find space for dquot */
  187. static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
  188. struct dquot *dquot, int *err)
  189. {
  190. uint blk, i;
  191. struct qt_disk_dqdbheader *dh;
  192. char *buf = getdqbuf(info->dqi_usable_bs);
  193. char *ddquot;
  194. *err = 0;
  195. if (!buf) {
  196. *err = -ENOMEM;
  197. return 0;
  198. }
  199. dh = (struct qt_disk_dqdbheader *)buf;
  200. if (info->dqi_free_entry) {
  201. blk = info->dqi_free_entry;
  202. *err = read_blk(info, blk, buf);
  203. if (*err < 0)
  204. goto out_buf;
  205. } else {
  206. blk = get_free_dqblk(info);
  207. if ((int)blk < 0) {
  208. *err = blk;
  209. kfree(buf);
  210. return 0;
  211. }
  212. memset(buf, 0, info->dqi_usable_bs);
  213. /* This is enough as the block is already zeroed and the entry
  214. * list is empty... */
  215. info->dqi_free_entry = blk;
  216. mark_info_dirty(dquot->dq_sb, dquot->dq_type);
  217. }
  218. /* Block will be full? */
  219. if (le16_to_cpu(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) {
  220. *err = remove_free_dqentry(info, buf, blk);
  221. if (*err < 0) {
  222. printk(KERN_ERR "VFS: find_free_dqentry(): Can't "
  223. "remove block (%u) from entry free list.\n",
  224. blk);
  225. goto out_buf;
  226. }
  227. }
  228. le16_add_cpu(&dh->dqdh_entries, 1);
  229. /* Find free structure in block */
  230. ddquot = buf + sizeof(struct qt_disk_dqdbheader);
  231. for (i = 0; i < qtree_dqstr_in_blk(info); i++) {
  232. if (qtree_entry_unused(info, ddquot))
  233. break;
  234. ddquot += info->dqi_entry_size;
  235. }
  236. #ifdef __QUOTA_QT_PARANOIA
  237. if (i == qtree_dqstr_in_blk(info)) {
  238. printk(KERN_ERR "VFS: find_free_dqentry(): Data block full "
  239. "but it shouldn't.\n");
  240. *err = -EIO;
  241. goto out_buf;
  242. }
  243. #endif
  244. *err = write_blk(info, blk, buf);
  245. if (*err < 0) {
  246. printk(KERN_ERR "VFS: find_free_dqentry(): Can't write quota "
  247. "data block %u.\n", blk);
  248. goto out_buf;
  249. }
  250. dquot->dq_off = (blk << info->dqi_blocksize_bits) +
  251. sizeof(struct qt_disk_dqdbheader) +
  252. i * info->dqi_entry_size;
  253. kfree(buf);
  254. return blk;
  255. out_buf:
  256. kfree(buf);
  257. return 0;
  258. }
  259. /* Insert reference to structure into the trie */
  260. static int do_insert_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
  261. uint *treeblk, int depth)
  262. {
  263. char *buf = getdqbuf(info->dqi_usable_bs);
  264. int ret = 0, newson = 0, newact = 0;
  265. __le32 *ref;
  266. uint newblk;
  267. if (!buf)
  268. return -ENOMEM;
  269. if (!*treeblk) {
  270. ret = get_free_dqblk(info);
  271. if (ret < 0)
  272. goto out_buf;
  273. *treeblk = ret;
  274. memset(buf, 0, info->dqi_usable_bs);
  275. newact = 1;
  276. } else {
  277. ret = read_blk(info, *treeblk, buf);
  278. if (ret < 0) {
  279. printk(KERN_ERR "VFS: Can't read tree quota block "
  280. "%u.\n", *treeblk);
  281. goto out_buf;
  282. }
  283. }
  284. ref = (__le32 *)buf;
  285. newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
  286. if (!newblk)
  287. newson = 1;
  288. if (depth == info->dqi_qtree_depth - 1) {
  289. #ifdef __QUOTA_QT_PARANOIA
  290. if (newblk) {
  291. printk(KERN_ERR "VFS: Inserting already present quota "
  292. "entry (block %u).\n",
  293. le32_to_cpu(ref[get_index(info,
  294. dquot->dq_id, depth)]));
  295. ret = -EIO;
  296. goto out_buf;
  297. }
  298. #endif
  299. newblk = find_free_dqentry(info, dquot, &ret);
  300. } else {
  301. ret = do_insert_tree(info, dquot, &newblk, depth+1);
  302. }
  303. if (newson && ret >= 0) {
  304. ref[get_index(info, dquot->dq_id, depth)] =
  305. cpu_to_le32(newblk);
  306. ret = write_blk(info, *treeblk, buf);
  307. } else if (newact && ret < 0) {
  308. put_free_dqblk(info, buf, *treeblk);
  309. }
  310. out_buf:
  311. kfree(buf);
  312. return ret;
  313. }
  314. /* Wrapper for inserting quota structure into tree */
  315. static inline int dq_insert_tree(struct qtree_mem_dqinfo *info,
  316. struct dquot *dquot)
  317. {
  318. int tmp = QT_TREEOFF;
  319. return do_insert_tree(info, dquot, &tmp, 0);
  320. }
  321. /*
  322. * We don't have to be afraid of deadlocks as we never have quotas on quota
  323. * files...
  324. */
  325. int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
  326. {
  327. int type = dquot->dq_type;
  328. struct super_block *sb = dquot->dq_sb;
  329. ssize_t ret;
  330. char *ddquot = getdqbuf(info->dqi_entry_size);
  331. if (!ddquot)
  332. return -ENOMEM;
  333. /* dq_off is guarded by dqio_mutex */
  334. if (!dquot->dq_off) {
  335. ret = dq_insert_tree(info, dquot);
  336. if (ret < 0) {
  337. printk(KERN_ERR "VFS: Error %zd occurred while "
  338. "creating quota.\n", ret);
  339. kfree(ddquot);
  340. return ret;
  341. }
  342. }
  343. spin_lock(&dq_data_lock);
  344. info->dqi_ops->mem2disk_dqblk(ddquot, dquot);
  345. spin_unlock(&dq_data_lock);
  346. ret = sb->s_op->quota_write(sb, type, ddquot, info->dqi_entry_size,
  347. dquot->dq_off);
  348. if (ret != info->dqi_entry_size) {
  349. printk(KERN_WARNING "VFS: dquota write failed on dev %s\n",
  350. sb->s_id);
  351. if (ret >= 0)
  352. ret = -ENOSPC;
  353. } else {
  354. ret = 0;
  355. }
  356. dqstats.writes++;
  357. kfree(ddquot);
  358. return ret;
  359. }
  360. EXPORT_SYMBOL(qtree_write_dquot);
  361. /* Free dquot entry in data block */
  362. static int free_dqentry(struct qtree_mem_dqinfo *info, struct dquot *dquot,
  363. uint blk)
  364. {
  365. struct qt_disk_dqdbheader *dh;
  366. char *buf = getdqbuf(info->dqi_usable_bs);
  367. int ret = 0;
  368. if (!buf)
  369. return -ENOMEM;
  370. if (dquot->dq_off >> info->dqi_blocksize_bits != blk) {
  371. printk(KERN_ERR "VFS: Quota structure has offset to other "
  372. "block (%u) than it should (%u).\n", blk,
  373. (uint)(dquot->dq_off >> info->dqi_blocksize_bits));
  374. goto out_buf;
  375. }
  376. ret = read_blk(info, blk, buf);
  377. if (ret < 0) {
  378. printk(KERN_ERR "VFS: Can't read quota data block %u\n", blk);
  379. goto out_buf;
  380. }
  381. dh = (struct qt_disk_dqdbheader *)buf;
  382. le16_add_cpu(&dh->dqdh_entries, -1);
  383. if (!le16_to_cpu(dh->dqdh_entries)) { /* Block got free? */
  384. ret = remove_free_dqentry(info, buf, blk);
  385. if (ret >= 0)
  386. ret = put_free_dqblk(info, buf, blk);
  387. if (ret < 0) {
  388. printk(KERN_ERR "VFS: Can't move quota data block (%u) "
  389. "to free list.\n", blk);
  390. goto out_buf;
  391. }
  392. } else {
  393. memset(buf +
  394. (dquot->dq_off & ((1 << info->dqi_blocksize_bits) - 1)),
  395. 0, info->dqi_entry_size);
  396. if (le16_to_cpu(dh->dqdh_entries) ==
  397. qtree_dqstr_in_blk(info) - 1) {
  398. /* Insert will write block itself */
  399. ret = insert_free_dqentry(info, buf, blk);
  400. if (ret < 0) {
  401. printk(KERN_ERR "VFS: Can't insert quota data "
  402. "block (%u) to free entry list.\n", blk);
  403. goto out_buf;
  404. }
  405. } else {
  406. ret = write_blk(info, blk, buf);
  407. if (ret < 0) {
  408. printk(KERN_ERR "VFS: Can't write quota data "
  409. "block %u\n", blk);
  410. goto out_buf;
  411. }
  412. }
  413. }
  414. dquot->dq_off = 0; /* Quota is now unattached */
  415. out_buf:
  416. kfree(buf);
  417. return ret;
  418. }
  419. /* Remove reference to dquot from tree */
  420. static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
  421. uint *blk, int depth)
  422. {
  423. char *buf = getdqbuf(info->dqi_usable_bs);
  424. int ret = 0;
  425. uint newblk;
  426. __le32 *ref = (__le32 *)buf;
  427. if (!buf)
  428. return -ENOMEM;
  429. ret = read_blk(info, *blk, buf);
  430. if (ret < 0) {
  431. printk(KERN_ERR "VFS: Can't read quota data block %u\n", *blk);
  432. goto out_buf;
  433. }
  434. newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
  435. if (depth == info->dqi_qtree_depth - 1) {
  436. ret = free_dqentry(info, dquot, newblk);
  437. newblk = 0;
  438. } else {
  439. ret = remove_tree(info, dquot, &newblk, depth+1);
  440. }
  441. if (ret >= 0 && !newblk) {
  442. int i;
  443. ref[get_index(info, dquot->dq_id, depth)] = cpu_to_le32(0);
  444. /* Block got empty? */
  445. for (i = 0; i < (info->dqi_usable_bs >> 2) && !ref[i]; i++)
  446. ;
  447. /* Don't put the root block into the free block list */
  448. if (i == (info->dqi_usable_bs >> 2)
  449. && *blk != QT_TREEOFF) {
  450. put_free_dqblk(info, buf, *blk);
  451. *blk = 0;
  452. } else {
  453. ret = write_blk(info, *blk, buf);
  454. if (ret < 0)
  455. printk(KERN_ERR "VFS: Can't write quota tree "
  456. "block %u.\n", *blk);
  457. }
  458. }
  459. out_buf:
  460. kfree(buf);
  461. return ret;
  462. }
  463. /* Delete dquot from tree */
  464. int qtree_delete_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
  465. {
  466. uint tmp = QT_TREEOFF;
  467. if (!dquot->dq_off) /* Even not allocated? */
  468. return 0;
  469. return remove_tree(info, dquot, &tmp, 0);
  470. }
  471. EXPORT_SYMBOL(qtree_delete_dquot);
  472. /* Find entry in block */
  473. static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info,
  474. struct dquot *dquot, uint blk)
  475. {
  476. char *buf = getdqbuf(info->dqi_usable_bs);
  477. loff_t ret = 0;
  478. int i;
  479. char *ddquot;
  480. if (!buf)
  481. return -ENOMEM;
  482. ret = read_blk(info, blk, buf);
  483. if (ret < 0) {
  484. printk(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk);
  485. goto out_buf;
  486. }
  487. ddquot = buf + sizeof(struct qt_disk_dqdbheader);
  488. for (i = 0; i < qtree_dqstr_in_blk(info); i++) {
  489. if (info->dqi_ops->is_id(ddquot, dquot))
  490. break;
  491. ddquot += info->dqi_entry_size;
  492. }
  493. if (i == qtree_dqstr_in_blk(info)) {
  494. printk(KERN_ERR "VFS: Quota for id %u referenced "
  495. "but not present.\n", dquot->dq_id);
  496. ret = -EIO;
  497. goto out_buf;
  498. } else {
  499. ret = (blk << info->dqi_blocksize_bits) + sizeof(struct
  500. qt_disk_dqdbheader) + i * info->dqi_entry_size;
  501. }
  502. out_buf:
  503. kfree(buf);
  504. return ret;
  505. }
  506. /* Find entry for given id in the tree */
  507. static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info,
  508. struct dquot *dquot, uint blk, int depth)
  509. {
  510. char *buf = getdqbuf(info->dqi_usable_bs);
  511. loff_t ret = 0;
  512. __le32 *ref = (__le32 *)buf;
  513. if (!buf)
  514. return -ENOMEM;
  515. ret = read_blk(info, blk, buf);
  516. if (ret < 0) {
  517. printk(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk);
  518. goto out_buf;
  519. }
  520. ret = 0;
  521. blk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
  522. if (!blk) /* No reference? */
  523. goto out_buf;
  524. if (depth < info->dqi_qtree_depth - 1)
  525. ret = find_tree_dqentry(info, dquot, blk, depth+1);
  526. else
  527. ret = find_block_dqentry(info, dquot, blk);
  528. out_buf:
  529. kfree(buf);
  530. return ret;
  531. }
  532. /* Find entry for given id in the tree - wrapper function */
  533. static inline loff_t find_dqentry(struct qtree_mem_dqinfo *info,
  534. struct dquot *dquot)
  535. {
  536. return find_tree_dqentry(info, dquot, QT_TREEOFF, 0);
  537. }
  538. int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
  539. {
  540. int type = dquot->dq_type;
  541. struct super_block *sb = dquot->dq_sb;
  542. loff_t offset;
  543. char *ddquot;
  544. int ret = 0;
  545. #ifdef __QUOTA_QT_PARANOIA
  546. /* Invalidated quota? */
  547. if (!sb_dqopt(dquot->dq_sb)->files[type]) {
  548. printk(KERN_ERR "VFS: Quota invalidated while reading!\n");
  549. return -EIO;
  550. }
  551. #endif
  552. /* Do we know offset of the dquot entry in the quota file? */
  553. if (!dquot->dq_off) {
  554. offset = find_dqentry(info, dquot);
  555. if (offset <= 0) { /* Entry not present? */
  556. if (offset < 0)
  557. printk(KERN_ERR "VFS: Can't read quota "
  558. "structure for id %u.\n", dquot->dq_id);
  559. dquot->dq_off = 0;
  560. set_bit(DQ_FAKE_B, &dquot->dq_flags);
  561. memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk));
  562. ret = offset;
  563. goto out;
  564. }
  565. dquot->dq_off = offset;
  566. }
  567. ddquot = getdqbuf(info->dqi_entry_size);
  568. if (!ddquot)
  569. return -ENOMEM;
  570. ret = sb->s_op->quota_read(sb, type, ddquot, info->dqi_entry_size,
  571. dquot->dq_off);
  572. if (ret != info->dqi_entry_size) {
  573. if (ret >= 0)
  574. ret = -EIO;
  575. printk(KERN_ERR "VFS: Error while reading quota "
  576. "structure for id %u.\n", dquot->dq_id);
  577. set_bit(DQ_FAKE_B, &dquot->dq_flags);
  578. memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk));
  579. kfree(ddquot);
  580. goto out;
  581. }
  582. spin_lock(&dq_data_lock);
  583. info->dqi_ops->disk2mem_dqblk(dquot, ddquot);
  584. if (!dquot->dq_dqb.dqb_bhardlimit &&
  585. !dquot->dq_dqb.dqb_bsoftlimit &&
  586. !dquot->dq_dqb.dqb_ihardlimit &&
  587. !dquot->dq_dqb.dqb_isoftlimit)
  588. set_bit(DQ_FAKE_B, &dquot->dq_flags);
  589. spin_unlock(&dq_data_lock);
  590. kfree(ddquot);
  591. out:
  592. dqstats.reads++;
  593. return ret;
  594. }
  595. EXPORT_SYMBOL(qtree_read_dquot);
  596. /* Check whether dquot should not be deleted. We know we are
  597. * the only one operating on dquot (thanks to dq_lock) */
  598. int qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
  599. {
  600. if (test_bit(DQ_FAKE_B, &dquot->dq_flags) &&
  601. !(dquot->dq_dqb.dqb_curinodes | dquot->dq_dqb.dqb_curspace))
  602. return qtree_delete_dquot(info, dquot);
  603. return 0;
  604. }
  605. EXPORT_SYMBOL(qtree_release_dquot);