inode.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. /*
  2. * Copyright (C) 2005, 2006
  3. * Avishay Traeger (avishay@gmail.com)
  4. * Copyright (C) 2008, 2009
  5. * Boaz Harrosh <bharrosh@panasas.com>
  6. *
  7. * Copyrights for code taken from ext2:
  8. * Copyright (C) 1992, 1993, 1994, 1995
  9. * Remy Card (card@masi.ibp.fr)
  10. * Laboratoire MASI - Institut Blaise Pascal
  11. * Universite Pierre et Marie Curie (Paris VI)
  12. * from
  13. * linux/fs/minix/inode.c
  14. * Copyright (C) 1991, 1992 Linus Torvalds
  15. *
  16. * This file is part of exofs.
  17. *
  18. * exofs is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation. Since it is based on ext2, and the only
  21. * valid version of GPL for the Linux kernel is version 2, the only valid
  22. * version of GPL for exofs is version 2.
  23. *
  24. * exofs is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with exofs; if not, write to the Free Software
  31. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  32. */
  33. #include <linux/writeback.h>
  34. #include <linux/buffer_head.h>
  35. #include <scsi/scsi_device.h>
  36. #include "exofs.h"
  37. #define EXOFS_DBGMSG2(M...) do {} while (0)
  38. enum { BIO_MAX_PAGES_KMALLOC =
  39. (PAGE_SIZE - sizeof(struct bio)) / sizeof(struct bio_vec),
  40. };
  41. struct page_collect {
  42. struct exofs_sb_info *sbi;
  43. struct request_queue *req_q;
  44. struct inode *inode;
  45. unsigned expected_pages;
  46. struct exofs_io_state *ios;
  47. struct bio *bio;
  48. unsigned nr_pages;
  49. unsigned long length;
  50. loff_t pg_first; /* keep 64bit also in 32-arches */
  51. };
  52. static void _pcol_init(struct page_collect *pcol, unsigned expected_pages,
  53. struct inode *inode)
  54. {
  55. struct exofs_sb_info *sbi = inode->i_sb->s_fs_info;
  56. pcol->sbi = sbi;
  57. /* Create master bios on first Q, later on cloning, each clone will be
  58. * allocated on it's destination Q
  59. */
  60. pcol->req_q = osd_request_queue(sbi->layout.s_ods[0]);
  61. pcol->inode = inode;
  62. pcol->expected_pages = expected_pages;
  63. pcol->ios = NULL;
  64. pcol->bio = NULL;
  65. pcol->nr_pages = 0;
  66. pcol->length = 0;
  67. pcol->pg_first = -1;
  68. }
  69. static void _pcol_reset(struct page_collect *pcol)
  70. {
  71. pcol->expected_pages -= min(pcol->nr_pages, pcol->expected_pages);
  72. pcol->bio = NULL;
  73. pcol->nr_pages = 0;
  74. pcol->length = 0;
  75. pcol->pg_first = -1;
  76. pcol->ios = NULL;
  77. /* this is probably the end of the loop but in writes
  78. * it might not end here. don't be left with nothing
  79. */
  80. if (!pcol->expected_pages)
  81. pcol->expected_pages = BIO_MAX_PAGES_KMALLOC;
  82. }
  83. static int pcol_try_alloc(struct page_collect *pcol)
  84. {
  85. int pages = min_t(unsigned, pcol->expected_pages,
  86. BIO_MAX_PAGES_KMALLOC);
  87. if (!pcol->ios) { /* First time allocate io_state */
  88. int ret = exofs_get_io_state(&pcol->sbi->layout, &pcol->ios);
  89. if (ret)
  90. return ret;
  91. }
  92. for (; pages; pages >>= 1) {
  93. pcol->bio = bio_kmalloc(GFP_KERNEL, pages);
  94. if (likely(pcol->bio))
  95. return 0;
  96. }
  97. EXOFS_ERR("Failed to bio_kmalloc expected_pages=%u\n",
  98. pcol->expected_pages);
  99. return -ENOMEM;
  100. }
  101. static void pcol_free(struct page_collect *pcol)
  102. {
  103. if (pcol->bio) {
  104. bio_put(pcol->bio);
  105. pcol->bio = NULL;
  106. }
  107. if (pcol->ios) {
  108. exofs_put_io_state(pcol->ios);
  109. pcol->ios = NULL;
  110. }
  111. }
  112. static int pcol_add_page(struct page_collect *pcol, struct page *page,
  113. unsigned len)
  114. {
  115. int added_len = bio_add_pc_page(pcol->req_q, pcol->bio, page, len, 0);
  116. if (unlikely(len != added_len))
  117. return -ENOMEM;
  118. ++pcol->nr_pages;
  119. pcol->length += len;
  120. return 0;
  121. }
  122. static int update_read_page(struct page *page, int ret)
  123. {
  124. if (ret == 0) {
  125. /* Everything is OK */
  126. SetPageUptodate(page);
  127. if (PageError(page))
  128. ClearPageError(page);
  129. } else if (ret == -EFAULT) {
  130. /* In this case we were trying to read something that wasn't on
  131. * disk yet - return a page full of zeroes. This should be OK,
  132. * because the object should be empty (if there was a write
  133. * before this read, the read would be waiting with the page
  134. * locked */
  135. clear_highpage(page);
  136. SetPageUptodate(page);
  137. if (PageError(page))
  138. ClearPageError(page);
  139. ret = 0; /* recovered error */
  140. EXOFS_DBGMSG("recovered read error\n");
  141. } else /* Error */
  142. SetPageError(page);
  143. return ret;
  144. }
  145. static void update_write_page(struct page *page, int ret)
  146. {
  147. if (ret) {
  148. mapping_set_error(page->mapping, ret);
  149. SetPageError(page);
  150. }
  151. end_page_writeback(page);
  152. }
  153. /* Called at the end of reads, to optionally unlock pages and update their
  154. * status.
  155. */
  156. static int __readpages_done(struct page_collect *pcol, bool do_unlock)
  157. {
  158. struct bio_vec *bvec;
  159. int i;
  160. u64 resid;
  161. u64 good_bytes;
  162. u64 length = 0;
  163. int ret = exofs_check_io(pcol->ios, &resid);
  164. if (likely(!ret))
  165. good_bytes = pcol->length;
  166. else
  167. good_bytes = pcol->length - resid;
  168. EXOFS_DBGMSG2("readpages_done(0x%lx) good_bytes=0x%llx"
  169. " length=0x%lx nr_pages=%u\n",
  170. pcol->inode->i_ino, _LLU(good_bytes), pcol->length,
  171. pcol->nr_pages);
  172. __bio_for_each_segment(bvec, pcol->bio, i, 0) {
  173. struct page *page = bvec->bv_page;
  174. struct inode *inode = page->mapping->host;
  175. int page_stat;
  176. if (inode != pcol->inode)
  177. continue; /* osd might add more pages at end */
  178. if (likely(length < good_bytes))
  179. page_stat = 0;
  180. else
  181. page_stat = ret;
  182. EXOFS_DBGMSG2(" readpages_done(0x%lx, 0x%lx) %s\n",
  183. inode->i_ino, page->index,
  184. page_stat ? "bad_bytes" : "good_bytes");
  185. ret = update_read_page(page, page_stat);
  186. if (do_unlock)
  187. unlock_page(page);
  188. length += bvec->bv_len;
  189. }
  190. pcol_free(pcol);
  191. EXOFS_DBGMSG2("readpages_done END\n");
  192. return ret;
  193. }
  194. /* callback of async reads */
  195. static void readpages_done(struct exofs_io_state *ios, void *p)
  196. {
  197. struct page_collect *pcol = p;
  198. __readpages_done(pcol, true);
  199. atomic_dec(&pcol->sbi->s_curr_pending);
  200. kfree(pcol);
  201. }
  202. static void _unlock_pcol_pages(struct page_collect *pcol, int ret, int rw)
  203. {
  204. struct bio_vec *bvec;
  205. int i;
  206. __bio_for_each_segment(bvec, pcol->bio, i, 0) {
  207. struct page *page = bvec->bv_page;
  208. if (rw == READ)
  209. update_read_page(page, ret);
  210. else
  211. update_write_page(page, ret);
  212. unlock_page(page);
  213. }
  214. }
  215. static int read_exec(struct page_collect *pcol, bool is_sync)
  216. {
  217. struct exofs_i_info *oi = exofs_i(pcol->inode);
  218. struct exofs_io_state *ios = pcol->ios;
  219. struct page_collect *pcol_copy = NULL;
  220. int ret;
  221. if (!pcol->bio)
  222. return 0;
  223. /* see comment in _readpage() about sync reads */
  224. WARN_ON(is_sync && (pcol->nr_pages != 1));
  225. ios->bio = pcol->bio;
  226. ios->length = pcol->length;
  227. ios->offset = pcol->pg_first << PAGE_CACHE_SHIFT;
  228. if (is_sync) {
  229. exofs_oi_read(oi, pcol->ios);
  230. return __readpages_done(pcol, false);
  231. }
  232. pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL);
  233. if (!pcol_copy) {
  234. ret = -ENOMEM;
  235. goto err;
  236. }
  237. *pcol_copy = *pcol;
  238. ios->done = readpages_done;
  239. ios->private = pcol_copy;
  240. ret = exofs_oi_read(oi, ios);
  241. if (unlikely(ret))
  242. goto err;
  243. atomic_inc(&pcol->sbi->s_curr_pending);
  244. EXOFS_DBGMSG2("read_exec obj=0x%llx start=0x%llx length=0x%lx\n",
  245. ios->obj.id, _LLU(ios->offset), pcol->length);
  246. /* pages ownership was passed to pcol_copy */
  247. _pcol_reset(pcol);
  248. return 0;
  249. err:
  250. if (!is_sync)
  251. _unlock_pcol_pages(pcol, ret, READ);
  252. pcol_free(pcol);
  253. kfree(pcol_copy);
  254. return ret;
  255. }
  256. /* readpage_strip is called either directly from readpage() or by the VFS from
  257. * within read_cache_pages(), to add one more page to be read. It will try to
  258. * collect as many contiguous pages as posible. If a discontinuity is
  259. * encountered, or it runs out of resources, it will submit the previous segment
  260. * and will start a new collection. Eventually caller must submit the last
  261. * segment if present.
  262. */
  263. static int readpage_strip(void *data, struct page *page)
  264. {
  265. struct page_collect *pcol = data;
  266. struct inode *inode = pcol->inode;
  267. struct exofs_i_info *oi = exofs_i(inode);
  268. loff_t i_size = i_size_read(inode);
  269. pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
  270. size_t len;
  271. int ret;
  272. /* FIXME: Just for debugging, will be removed */
  273. if (PageUptodate(page))
  274. EXOFS_ERR("PageUptodate(0x%lx, 0x%lx)\n", pcol->inode->i_ino,
  275. page->index);
  276. if (page->index < end_index)
  277. len = PAGE_CACHE_SIZE;
  278. else if (page->index == end_index)
  279. len = i_size & ~PAGE_CACHE_MASK;
  280. else
  281. len = 0;
  282. if (!len || !obj_created(oi)) {
  283. /* this will be out of bounds, or doesn't exist yet.
  284. * Current page is cleared and the request is split
  285. */
  286. clear_highpage(page);
  287. SetPageUptodate(page);
  288. if (PageError(page))
  289. ClearPageError(page);
  290. unlock_page(page);
  291. EXOFS_DBGMSG("readpage_strip(0x%lx, 0x%lx) empty page,"
  292. " splitting\n", inode->i_ino, page->index);
  293. return read_exec(pcol, false);
  294. }
  295. try_again:
  296. if (unlikely(pcol->pg_first == -1)) {
  297. pcol->pg_first = page->index;
  298. } else if (unlikely((pcol->pg_first + pcol->nr_pages) !=
  299. page->index)) {
  300. /* Discontinuity detected, split the request */
  301. ret = read_exec(pcol, false);
  302. if (unlikely(ret))
  303. goto fail;
  304. goto try_again;
  305. }
  306. if (!pcol->bio) {
  307. ret = pcol_try_alloc(pcol);
  308. if (unlikely(ret))
  309. goto fail;
  310. }
  311. if (len != PAGE_CACHE_SIZE)
  312. zero_user(page, len, PAGE_CACHE_SIZE - len);
  313. EXOFS_DBGMSG2(" readpage_strip(0x%lx, 0x%lx) len=0x%zx\n",
  314. inode->i_ino, page->index, len);
  315. ret = pcol_add_page(pcol, page, len);
  316. if (ret) {
  317. EXOFS_DBGMSG2("Failed pcol_add_page pages[i]=%p "
  318. "this_len=0x%zx nr_pages=%u length=0x%lx\n",
  319. page, len, pcol->nr_pages, pcol->length);
  320. /* split the request, and start again with current page */
  321. ret = read_exec(pcol, false);
  322. if (unlikely(ret))
  323. goto fail;
  324. goto try_again;
  325. }
  326. return 0;
  327. fail:
  328. /* SetPageError(page); ??? */
  329. unlock_page(page);
  330. return ret;
  331. }
  332. static int exofs_readpages(struct file *file, struct address_space *mapping,
  333. struct list_head *pages, unsigned nr_pages)
  334. {
  335. struct page_collect pcol;
  336. int ret;
  337. _pcol_init(&pcol, nr_pages, mapping->host);
  338. ret = read_cache_pages(mapping, pages, readpage_strip, &pcol);
  339. if (ret) {
  340. EXOFS_ERR("read_cache_pages => %d\n", ret);
  341. return ret;
  342. }
  343. return read_exec(&pcol, false);
  344. }
  345. static int _readpage(struct page *page, bool is_sync)
  346. {
  347. struct page_collect pcol;
  348. int ret;
  349. _pcol_init(&pcol, 1, page->mapping->host);
  350. /* readpage_strip might call read_exec(,is_sync==false) at several
  351. * places but not if we have a single page.
  352. */
  353. ret = readpage_strip(&pcol, page);
  354. if (ret) {
  355. EXOFS_ERR("_readpage => %d\n", ret);
  356. return ret;
  357. }
  358. return read_exec(&pcol, is_sync);
  359. }
  360. /*
  361. * We don't need the file
  362. */
  363. static int exofs_readpage(struct file *file, struct page *page)
  364. {
  365. return _readpage(page, false);
  366. }
  367. /* Callback for osd_write. All writes are asynchronous */
  368. static void writepages_done(struct exofs_io_state *ios, void *p)
  369. {
  370. struct page_collect *pcol = p;
  371. struct bio_vec *bvec;
  372. int i;
  373. u64 resid;
  374. u64 good_bytes;
  375. u64 length = 0;
  376. int ret = exofs_check_io(ios, &resid);
  377. atomic_dec(&pcol->sbi->s_curr_pending);
  378. if (likely(!ret))
  379. good_bytes = pcol->length;
  380. else
  381. good_bytes = pcol->length - resid;
  382. EXOFS_DBGMSG2("writepages_done(0x%lx) good_bytes=0x%llx"
  383. " length=0x%lx nr_pages=%u\n",
  384. pcol->inode->i_ino, _LLU(good_bytes), pcol->length,
  385. pcol->nr_pages);
  386. __bio_for_each_segment(bvec, pcol->bio, i, 0) {
  387. struct page *page = bvec->bv_page;
  388. struct inode *inode = page->mapping->host;
  389. int page_stat;
  390. if (inode != pcol->inode)
  391. continue; /* osd might add more pages to a bio */
  392. if (likely(length < good_bytes))
  393. page_stat = 0;
  394. else
  395. page_stat = ret;
  396. update_write_page(page, page_stat);
  397. unlock_page(page);
  398. EXOFS_DBGMSG2(" writepages_done(0x%lx, 0x%lx) status=%d\n",
  399. inode->i_ino, page->index, page_stat);
  400. length += bvec->bv_len;
  401. }
  402. pcol_free(pcol);
  403. kfree(pcol);
  404. EXOFS_DBGMSG2("writepages_done END\n");
  405. }
  406. static int write_exec(struct page_collect *pcol)
  407. {
  408. struct exofs_i_info *oi = exofs_i(pcol->inode);
  409. struct exofs_io_state *ios = pcol->ios;
  410. struct page_collect *pcol_copy = NULL;
  411. int ret;
  412. if (!pcol->bio)
  413. return 0;
  414. pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL);
  415. if (!pcol_copy) {
  416. EXOFS_ERR("write_exec: Faild to kmalloc(pcol)\n");
  417. ret = -ENOMEM;
  418. goto err;
  419. }
  420. *pcol_copy = *pcol;
  421. pcol_copy->bio->bi_rw |= (1 << BIO_RW); /* FIXME: bio_set_dir() */
  422. ios->bio = pcol_copy->bio;
  423. ios->offset = pcol_copy->pg_first << PAGE_CACHE_SHIFT;
  424. ios->length = pcol_copy->length;
  425. ios->done = writepages_done;
  426. ios->private = pcol_copy;
  427. ret = exofs_oi_write(oi, ios);
  428. if (unlikely(ret)) {
  429. EXOFS_ERR("write_exec: exofs_oi_write() Faild\n");
  430. goto err;
  431. }
  432. atomic_inc(&pcol->sbi->s_curr_pending);
  433. EXOFS_DBGMSG2("write_exec(0x%lx, 0x%llx) start=0x%llx length=0x%lx\n",
  434. pcol->inode->i_ino, pcol->pg_first, _LLU(ios->offset),
  435. pcol->length);
  436. /* pages ownership was passed to pcol_copy */
  437. _pcol_reset(pcol);
  438. return 0;
  439. err:
  440. _unlock_pcol_pages(pcol, ret, WRITE);
  441. pcol_free(pcol);
  442. kfree(pcol_copy);
  443. return ret;
  444. }
  445. /* writepage_strip is called either directly from writepage() or by the VFS from
  446. * within write_cache_pages(), to add one more page to be written to storage.
  447. * It will try to collect as many contiguous pages as possible. If a
  448. * discontinuity is encountered or it runs out of resources it will submit the
  449. * previous segment and will start a new collection.
  450. * Eventually caller must submit the last segment if present.
  451. */
  452. static int writepage_strip(struct page *page,
  453. struct writeback_control *wbc_unused, void *data)
  454. {
  455. struct page_collect *pcol = data;
  456. struct inode *inode = pcol->inode;
  457. struct exofs_i_info *oi = exofs_i(inode);
  458. loff_t i_size = i_size_read(inode);
  459. pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
  460. size_t len;
  461. int ret;
  462. BUG_ON(!PageLocked(page));
  463. ret = wait_obj_created(oi);
  464. if (unlikely(ret))
  465. goto fail;
  466. if (page->index < end_index)
  467. /* in this case, the page is within the limits of the file */
  468. len = PAGE_CACHE_SIZE;
  469. else {
  470. len = i_size & ~PAGE_CACHE_MASK;
  471. if (page->index > end_index || !len) {
  472. /* in this case, the page is outside the limits
  473. * (truncate in progress)
  474. */
  475. ret = write_exec(pcol);
  476. if (unlikely(ret))
  477. goto fail;
  478. if (PageError(page))
  479. ClearPageError(page);
  480. unlock_page(page);
  481. EXOFS_DBGMSG("writepage_strip(0x%lx, 0x%lx) "
  482. "outside the limits\n",
  483. inode->i_ino, page->index);
  484. return 0;
  485. }
  486. }
  487. try_again:
  488. if (unlikely(pcol->pg_first == -1)) {
  489. pcol->pg_first = page->index;
  490. } else if (unlikely((pcol->pg_first + pcol->nr_pages) !=
  491. page->index)) {
  492. /* Discontinuity detected, split the request */
  493. ret = write_exec(pcol);
  494. if (unlikely(ret))
  495. goto fail;
  496. EXOFS_DBGMSG("writepage_strip(0x%lx, 0x%lx) Discontinuity\n",
  497. inode->i_ino, page->index);
  498. goto try_again;
  499. }
  500. if (!pcol->bio) {
  501. ret = pcol_try_alloc(pcol);
  502. if (unlikely(ret))
  503. goto fail;
  504. }
  505. EXOFS_DBGMSG2(" writepage_strip(0x%lx, 0x%lx) len=0x%zx\n",
  506. inode->i_ino, page->index, len);
  507. ret = pcol_add_page(pcol, page, len);
  508. if (unlikely(ret)) {
  509. EXOFS_DBGMSG2("Failed pcol_add_page "
  510. "nr_pages=%u total_length=0x%lx\n",
  511. pcol->nr_pages, pcol->length);
  512. /* split the request, next loop will start again */
  513. ret = write_exec(pcol);
  514. if (unlikely(ret)) {
  515. EXOFS_DBGMSG("write_exec faild => %d", ret);
  516. goto fail;
  517. }
  518. goto try_again;
  519. }
  520. BUG_ON(PageWriteback(page));
  521. set_page_writeback(page);
  522. return 0;
  523. fail:
  524. EXOFS_DBGMSG("Error: writepage_strip(0x%lx, 0x%lx)=>%d\n",
  525. inode->i_ino, page->index, ret);
  526. set_bit(AS_EIO, &page->mapping->flags);
  527. unlock_page(page);
  528. return ret;
  529. }
  530. static int exofs_writepages(struct address_space *mapping,
  531. struct writeback_control *wbc)
  532. {
  533. struct page_collect pcol;
  534. long start, end, expected_pages;
  535. int ret;
  536. start = wbc->range_start >> PAGE_CACHE_SHIFT;
  537. end = (wbc->range_end == LLONG_MAX) ?
  538. start + mapping->nrpages :
  539. wbc->range_end >> PAGE_CACHE_SHIFT;
  540. if (start || end)
  541. expected_pages = end - start + 1;
  542. else
  543. expected_pages = mapping->nrpages;
  544. if (expected_pages < 32L)
  545. expected_pages = 32L;
  546. EXOFS_DBGMSG2("inode(0x%lx) wbc->start=0x%llx wbc->end=0x%llx "
  547. "nrpages=%lu start=0x%lx end=0x%lx expected_pages=%ld\n",
  548. mapping->host->i_ino, wbc->range_start, wbc->range_end,
  549. mapping->nrpages, start, end, expected_pages);
  550. _pcol_init(&pcol, expected_pages, mapping->host);
  551. ret = write_cache_pages(mapping, wbc, writepage_strip, &pcol);
  552. if (ret) {
  553. EXOFS_ERR("write_cache_pages => %d\n", ret);
  554. return ret;
  555. }
  556. return write_exec(&pcol);
  557. }
  558. static int exofs_writepage(struct page *page, struct writeback_control *wbc)
  559. {
  560. struct page_collect pcol;
  561. int ret;
  562. _pcol_init(&pcol, 1, page->mapping->host);
  563. ret = writepage_strip(page, NULL, &pcol);
  564. if (ret) {
  565. EXOFS_ERR("exofs_writepage => %d\n", ret);
  566. return ret;
  567. }
  568. return write_exec(&pcol);
  569. }
  570. int exofs_write_begin(struct file *file, struct address_space *mapping,
  571. loff_t pos, unsigned len, unsigned flags,
  572. struct page **pagep, void **fsdata)
  573. {
  574. int ret = 0;
  575. struct page *page;
  576. page = *pagep;
  577. if (page == NULL) {
  578. ret = simple_write_begin(file, mapping, pos, len, flags, pagep,
  579. fsdata);
  580. if (ret) {
  581. EXOFS_DBGMSG("simple_write_begin faild\n");
  582. return ret;
  583. }
  584. page = *pagep;
  585. }
  586. /* read modify write */
  587. if (!PageUptodate(page) && (len != PAGE_CACHE_SIZE)) {
  588. ret = _readpage(page, true);
  589. if (ret) {
  590. /*SetPageError was done by _readpage. Is it ok?*/
  591. unlock_page(page);
  592. EXOFS_DBGMSG("__readpage_filler faild\n");
  593. }
  594. }
  595. return ret;
  596. }
  597. static int exofs_write_begin_export(struct file *file,
  598. struct address_space *mapping,
  599. loff_t pos, unsigned len, unsigned flags,
  600. struct page **pagep, void **fsdata)
  601. {
  602. *pagep = NULL;
  603. return exofs_write_begin(file, mapping, pos, len, flags, pagep,
  604. fsdata);
  605. }
  606. static int exofs_write_end(struct file *file, struct address_space *mapping,
  607. loff_t pos, unsigned len, unsigned copied,
  608. struct page *page, void *fsdata)
  609. {
  610. struct inode *inode = mapping->host;
  611. /* According to comment in simple_write_end i_mutex is held */
  612. loff_t i_size = inode->i_size;
  613. int ret;
  614. ret = simple_write_end(file, mapping,pos, len, copied, page, fsdata);
  615. if (i_size != inode->i_size)
  616. mark_inode_dirty(inode);
  617. return ret;
  618. }
  619. const struct address_space_operations exofs_aops = {
  620. .readpage = exofs_readpage,
  621. .readpages = exofs_readpages,
  622. .writepage = exofs_writepage,
  623. .writepages = exofs_writepages,
  624. .write_begin = exofs_write_begin_export,
  625. .write_end = exofs_write_end,
  626. };
  627. /******************************************************************************
  628. * INODE OPERATIONS
  629. *****************************************************************************/
  630. /*
  631. * Test whether an inode is a fast symlink.
  632. */
  633. static inline int exofs_inode_is_fast_symlink(struct inode *inode)
  634. {
  635. struct exofs_i_info *oi = exofs_i(inode);
  636. return S_ISLNK(inode->i_mode) && (oi->i_data[0] != 0);
  637. }
  638. /*
  639. * get_block_t - Fill in a buffer_head
  640. * An OSD takes care of block allocation so we just fake an allocation by
  641. * putting in the inode's sector_t in the buffer_head.
  642. * TODO: What about the case of create==0 and @iblock does not exist in the
  643. * object?
  644. */
  645. static int exofs_get_block(struct inode *inode, sector_t iblock,
  646. struct buffer_head *bh_result, int create)
  647. {
  648. map_bh(bh_result, inode->i_sb, iblock);
  649. return 0;
  650. }
  651. const struct osd_attr g_attr_logical_length = ATTR_DEF(
  652. OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8);
  653. static int _do_truncate(struct inode *inode)
  654. {
  655. struct exofs_i_info *oi = exofs_i(inode);
  656. loff_t isize = i_size_read(inode);
  657. int ret;
  658. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  659. nobh_truncate_page(inode->i_mapping, isize, exofs_get_block);
  660. ret = exofs_oi_truncate(oi, (u64)isize);
  661. EXOFS_DBGMSG("(0x%lx) size=0x%llx\n", inode->i_ino, isize);
  662. return ret;
  663. }
  664. /*
  665. * Truncate a file to the specified size - all we have to do is set the size
  666. * attribute. We make sure the object exists first.
  667. */
  668. void exofs_truncate(struct inode *inode)
  669. {
  670. struct exofs_i_info *oi = exofs_i(inode);
  671. int ret;
  672. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
  673. || S_ISLNK(inode->i_mode)))
  674. return;
  675. if (exofs_inode_is_fast_symlink(inode))
  676. return;
  677. if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
  678. return;
  679. /* if we are about to truncate an object, and it hasn't been
  680. * created yet, wait
  681. */
  682. if (unlikely(wait_obj_created(oi)))
  683. goto fail;
  684. ret = _do_truncate(inode);
  685. if (ret)
  686. goto fail;
  687. out:
  688. mark_inode_dirty(inode);
  689. return;
  690. fail:
  691. make_bad_inode(inode);
  692. goto out;
  693. }
  694. /*
  695. * Set inode attributes - just call generic functions.
  696. */
  697. int exofs_setattr(struct dentry *dentry, struct iattr *iattr)
  698. {
  699. struct inode *inode = dentry->d_inode;
  700. int error;
  701. error = inode_change_ok(inode, iattr);
  702. if (error)
  703. return error;
  704. error = inode_setattr(inode, iattr);
  705. return error;
  706. }
  707. static const struct osd_attr g_attr_inode_file_layout = ATTR_DEF(
  708. EXOFS_APAGE_FS_DATA,
  709. EXOFS_ATTR_INODE_FILE_LAYOUT,
  710. 0);
  711. static const struct osd_attr g_attr_inode_dir_layout = ATTR_DEF(
  712. EXOFS_APAGE_FS_DATA,
  713. EXOFS_ATTR_INODE_DIR_LAYOUT,
  714. 0);
  715. /*
  716. * Read the Linux inode info from the OSD, and return it as is. In exofs the
  717. * inode info is in an application specific page/attribute of the osd-object.
  718. */
  719. static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi,
  720. struct exofs_fcb *inode)
  721. {
  722. struct exofs_sb_info *sbi = sb->s_fs_info;
  723. struct osd_attr attrs[] = {
  724. [0] = g_attr_inode_data,
  725. [1] = g_attr_inode_file_layout,
  726. [2] = g_attr_inode_dir_layout,
  727. };
  728. struct exofs_io_state *ios;
  729. struct exofs_on_disk_inode_layout *layout;
  730. int ret;
  731. ret = exofs_get_io_state(&sbi->layout, &ios);
  732. if (unlikely(ret)) {
  733. EXOFS_ERR("%s: exofs_get_io_state failed.\n", __func__);
  734. return ret;
  735. }
  736. ios->obj.id = exofs_oi_objno(oi);
  737. exofs_make_credential(oi->i_cred, &ios->obj);
  738. ios->cred = oi->i_cred;
  739. attrs[1].len = exofs_on_disk_inode_layout_size(sbi->layout.s_numdevs);
  740. attrs[2].len = exofs_on_disk_inode_layout_size(sbi->layout.s_numdevs);
  741. ios->in_attr = attrs;
  742. ios->in_attr_len = ARRAY_SIZE(attrs);
  743. ret = exofs_sbi_read(ios);
  744. if (ret)
  745. goto out;
  746. ret = extract_attr_from_ios(ios, &attrs[0]);
  747. if (ret) {
  748. EXOFS_ERR("%s: extract_attr of inode_data failed\n", __func__);
  749. goto out;
  750. }
  751. WARN_ON(attrs[0].len != EXOFS_INO_ATTR_SIZE);
  752. memcpy(inode, attrs[0].val_ptr, EXOFS_INO_ATTR_SIZE);
  753. ret = extract_attr_from_ios(ios, &attrs[1]);
  754. if (ret) {
  755. EXOFS_ERR("%s: extract_attr of inode_data failed\n", __func__);
  756. goto out;
  757. }
  758. if (attrs[1].len) {
  759. layout = attrs[1].val_ptr;
  760. if (layout->gen_func != cpu_to_le16(LAYOUT_MOVING_WINDOW)) {
  761. EXOFS_ERR("%s: unsupported files layout %d\n",
  762. __func__, layout->gen_func);
  763. ret = -ENOTSUPP;
  764. goto out;
  765. }
  766. }
  767. ret = extract_attr_from_ios(ios, &attrs[2]);
  768. if (ret) {
  769. EXOFS_ERR("%s: extract_attr of inode_data failed\n", __func__);
  770. goto out;
  771. }
  772. if (attrs[2].len) {
  773. layout = attrs[2].val_ptr;
  774. if (layout->gen_func != cpu_to_le16(LAYOUT_MOVING_WINDOW)) {
  775. EXOFS_ERR("%s: unsupported meta-data layout %d\n",
  776. __func__, layout->gen_func);
  777. ret = -ENOTSUPP;
  778. goto out;
  779. }
  780. }
  781. out:
  782. exofs_put_io_state(ios);
  783. return ret;
  784. }
  785. static void __oi_init(struct exofs_i_info *oi)
  786. {
  787. init_waitqueue_head(&oi->i_wq);
  788. oi->i_flags = 0;
  789. }
  790. /*
  791. * Fill in an inode read from the OSD and set it up for use
  792. */
  793. struct inode *exofs_iget(struct super_block *sb, unsigned long ino)
  794. {
  795. struct exofs_i_info *oi;
  796. struct exofs_fcb fcb;
  797. struct inode *inode;
  798. int ret;
  799. inode = iget_locked(sb, ino);
  800. if (!inode)
  801. return ERR_PTR(-ENOMEM);
  802. if (!(inode->i_state & I_NEW))
  803. return inode;
  804. oi = exofs_i(inode);
  805. __oi_init(oi);
  806. /* read the inode from the osd */
  807. ret = exofs_get_inode(sb, oi, &fcb);
  808. if (ret)
  809. goto bad_inode;
  810. set_obj_created(oi);
  811. /* copy stuff from on-disk struct to in-memory struct */
  812. inode->i_mode = le16_to_cpu(fcb.i_mode);
  813. inode->i_uid = le32_to_cpu(fcb.i_uid);
  814. inode->i_gid = le32_to_cpu(fcb.i_gid);
  815. inode->i_nlink = le16_to_cpu(fcb.i_links_count);
  816. inode->i_ctime.tv_sec = (signed)le32_to_cpu(fcb.i_ctime);
  817. inode->i_atime.tv_sec = (signed)le32_to_cpu(fcb.i_atime);
  818. inode->i_mtime.tv_sec = (signed)le32_to_cpu(fcb.i_mtime);
  819. inode->i_ctime.tv_nsec =
  820. inode->i_atime.tv_nsec = inode->i_mtime.tv_nsec = 0;
  821. oi->i_commit_size = le64_to_cpu(fcb.i_size);
  822. i_size_write(inode, oi->i_commit_size);
  823. inode->i_blkbits = EXOFS_BLKSHIFT;
  824. inode->i_generation = le32_to_cpu(fcb.i_generation);
  825. oi->i_dir_start_lookup = 0;
  826. if ((inode->i_nlink == 0) && (inode->i_mode == 0)) {
  827. ret = -ESTALE;
  828. goto bad_inode;
  829. }
  830. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
  831. if (fcb.i_data[0])
  832. inode->i_rdev =
  833. old_decode_dev(le32_to_cpu(fcb.i_data[0]));
  834. else
  835. inode->i_rdev =
  836. new_decode_dev(le32_to_cpu(fcb.i_data[1]));
  837. } else {
  838. memcpy(oi->i_data, fcb.i_data, sizeof(fcb.i_data));
  839. }
  840. if (S_ISREG(inode->i_mode)) {
  841. inode->i_op = &exofs_file_inode_operations;
  842. inode->i_fop = &exofs_file_operations;
  843. inode->i_mapping->a_ops = &exofs_aops;
  844. } else if (S_ISDIR(inode->i_mode)) {
  845. inode->i_op = &exofs_dir_inode_operations;
  846. inode->i_fop = &exofs_dir_operations;
  847. inode->i_mapping->a_ops = &exofs_aops;
  848. } else if (S_ISLNK(inode->i_mode)) {
  849. if (exofs_inode_is_fast_symlink(inode))
  850. inode->i_op = &exofs_fast_symlink_inode_operations;
  851. else {
  852. inode->i_op = &exofs_symlink_inode_operations;
  853. inode->i_mapping->a_ops = &exofs_aops;
  854. }
  855. } else {
  856. inode->i_op = &exofs_special_inode_operations;
  857. if (fcb.i_data[0])
  858. init_special_inode(inode, inode->i_mode,
  859. old_decode_dev(le32_to_cpu(fcb.i_data[0])));
  860. else
  861. init_special_inode(inode, inode->i_mode,
  862. new_decode_dev(le32_to_cpu(fcb.i_data[1])));
  863. }
  864. unlock_new_inode(inode);
  865. return inode;
  866. bad_inode:
  867. iget_failed(inode);
  868. return ERR_PTR(ret);
  869. }
  870. int __exofs_wait_obj_created(struct exofs_i_info *oi)
  871. {
  872. if (!obj_created(oi)) {
  873. BUG_ON(!obj_2bcreated(oi));
  874. wait_event(oi->i_wq, obj_created(oi));
  875. }
  876. return unlikely(is_bad_inode(&oi->vfs_inode)) ? -EIO : 0;
  877. }
  878. /*
  879. * Callback function from exofs_new_inode(). The important thing is that we
  880. * set the obj_created flag so that other methods know that the object exists on
  881. * the OSD.
  882. */
  883. static void create_done(struct exofs_io_state *ios, void *p)
  884. {
  885. struct inode *inode = p;
  886. struct exofs_i_info *oi = exofs_i(inode);
  887. struct exofs_sb_info *sbi = inode->i_sb->s_fs_info;
  888. int ret;
  889. ret = exofs_check_io(ios, NULL);
  890. exofs_put_io_state(ios);
  891. atomic_dec(&sbi->s_curr_pending);
  892. if (unlikely(ret)) {
  893. EXOFS_ERR("object=0x%llx creation faild in pid=0x%llx",
  894. _LLU(exofs_oi_objno(oi)), _LLU(sbi->layout.s_pid));
  895. /*TODO: When FS is corrupted creation can fail, object already
  896. * exist. Get rid of this asynchronous creation, if exist
  897. * increment the obj counter and try the next object. Until we
  898. * succeed. All these dangling objects will be made into lost
  899. * files by chkfs.exofs
  900. */
  901. }
  902. set_obj_created(oi);
  903. atomic_dec(&inode->i_count);
  904. wake_up(&oi->i_wq);
  905. }
  906. /*
  907. * Set up a new inode and create an object for it on the OSD
  908. */
  909. struct inode *exofs_new_inode(struct inode *dir, int mode)
  910. {
  911. struct super_block *sb;
  912. struct inode *inode;
  913. struct exofs_i_info *oi;
  914. struct exofs_sb_info *sbi;
  915. struct exofs_io_state *ios;
  916. int ret;
  917. sb = dir->i_sb;
  918. inode = new_inode(sb);
  919. if (!inode)
  920. return ERR_PTR(-ENOMEM);
  921. oi = exofs_i(inode);
  922. __oi_init(oi);
  923. set_obj_2bcreated(oi);
  924. sbi = sb->s_fs_info;
  925. sb->s_dirt = 1;
  926. inode->i_uid = current->cred->fsuid;
  927. if (dir->i_mode & S_ISGID) {
  928. inode->i_gid = dir->i_gid;
  929. if (S_ISDIR(mode))
  930. mode |= S_ISGID;
  931. } else {
  932. inode->i_gid = current->cred->fsgid;
  933. }
  934. inode->i_mode = mode;
  935. inode->i_ino = sbi->s_nextid++;
  936. inode->i_blkbits = EXOFS_BLKSHIFT;
  937. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  938. oi->i_commit_size = inode->i_size = 0;
  939. spin_lock(&sbi->s_next_gen_lock);
  940. inode->i_generation = sbi->s_next_generation++;
  941. spin_unlock(&sbi->s_next_gen_lock);
  942. insert_inode_hash(inode);
  943. mark_inode_dirty(inode);
  944. ret = exofs_get_io_state(&sbi->layout, &ios);
  945. if (unlikely(ret)) {
  946. EXOFS_ERR("exofs_new_inode: exofs_get_io_state failed\n");
  947. return ERR_PTR(ret);
  948. }
  949. ios->obj.id = exofs_oi_objno(oi);
  950. exofs_make_credential(oi->i_cred, &ios->obj);
  951. /* increment the refcount so that the inode will still be around when we
  952. * reach the callback
  953. */
  954. atomic_inc(&inode->i_count);
  955. ios->done = create_done;
  956. ios->private = inode;
  957. ios->cred = oi->i_cred;
  958. ret = exofs_sbi_create(ios);
  959. if (ret) {
  960. atomic_dec(&inode->i_count);
  961. exofs_put_io_state(ios);
  962. return ERR_PTR(ret);
  963. }
  964. atomic_inc(&sbi->s_curr_pending);
  965. return inode;
  966. }
  967. /*
  968. * struct to pass two arguments to update_inode's callback
  969. */
  970. struct updatei_args {
  971. struct exofs_sb_info *sbi;
  972. struct exofs_fcb fcb;
  973. };
  974. /*
  975. * Callback function from exofs_update_inode().
  976. */
  977. static void updatei_done(struct exofs_io_state *ios, void *p)
  978. {
  979. struct updatei_args *args = p;
  980. exofs_put_io_state(ios);
  981. atomic_dec(&args->sbi->s_curr_pending);
  982. kfree(args);
  983. }
  984. /*
  985. * Write the inode to the OSD. Just fill up the struct, and set the attribute
  986. * synchronously or asynchronously depending on the do_sync flag.
  987. */
  988. static int exofs_update_inode(struct inode *inode, int do_sync)
  989. {
  990. struct exofs_i_info *oi = exofs_i(inode);
  991. struct super_block *sb = inode->i_sb;
  992. struct exofs_sb_info *sbi = sb->s_fs_info;
  993. struct exofs_io_state *ios;
  994. struct osd_attr attr;
  995. struct exofs_fcb *fcb;
  996. struct updatei_args *args;
  997. int ret;
  998. args = kzalloc(sizeof(*args), GFP_KERNEL);
  999. if (!args) {
  1000. EXOFS_DBGMSG("Faild kzalloc of args\n");
  1001. return -ENOMEM;
  1002. }
  1003. fcb = &args->fcb;
  1004. fcb->i_mode = cpu_to_le16(inode->i_mode);
  1005. fcb->i_uid = cpu_to_le32(inode->i_uid);
  1006. fcb->i_gid = cpu_to_le32(inode->i_gid);
  1007. fcb->i_links_count = cpu_to_le16(inode->i_nlink);
  1008. fcb->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec);
  1009. fcb->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
  1010. fcb->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
  1011. oi->i_commit_size = i_size_read(inode);
  1012. fcb->i_size = cpu_to_le64(oi->i_commit_size);
  1013. fcb->i_generation = cpu_to_le32(inode->i_generation);
  1014. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
  1015. if (old_valid_dev(inode->i_rdev)) {
  1016. fcb->i_data[0] =
  1017. cpu_to_le32(old_encode_dev(inode->i_rdev));
  1018. fcb->i_data[1] = 0;
  1019. } else {
  1020. fcb->i_data[0] = 0;
  1021. fcb->i_data[1] =
  1022. cpu_to_le32(new_encode_dev(inode->i_rdev));
  1023. fcb->i_data[2] = 0;
  1024. }
  1025. } else
  1026. memcpy(fcb->i_data, oi->i_data, sizeof(fcb->i_data));
  1027. ret = exofs_get_io_state(&sbi->layout, &ios);
  1028. if (unlikely(ret)) {
  1029. EXOFS_ERR("%s: exofs_get_io_state failed.\n", __func__);
  1030. goto free_args;
  1031. }
  1032. attr = g_attr_inode_data;
  1033. attr.val_ptr = fcb;
  1034. ios->out_attr_len = 1;
  1035. ios->out_attr = &attr;
  1036. if (!obj_created(oi)) {
  1037. EXOFS_DBGMSG("!obj_created\n");
  1038. BUG_ON(!obj_2bcreated(oi));
  1039. wait_event(oi->i_wq, obj_created(oi));
  1040. EXOFS_DBGMSG("wait_event done\n");
  1041. }
  1042. if (!do_sync) {
  1043. args->sbi = sbi;
  1044. ios->done = updatei_done;
  1045. ios->private = args;
  1046. }
  1047. ret = exofs_oi_write(oi, ios);
  1048. if (!do_sync && !ret) {
  1049. atomic_inc(&sbi->s_curr_pending);
  1050. goto out; /* deallocation in updatei_done */
  1051. }
  1052. exofs_put_io_state(ios);
  1053. free_args:
  1054. kfree(args);
  1055. out:
  1056. EXOFS_DBGMSG("(0x%lx) do_sync=%d ret=>%d\n",
  1057. inode->i_ino, do_sync, ret);
  1058. return ret;
  1059. }
  1060. int exofs_write_inode(struct inode *inode, int wait)
  1061. {
  1062. return exofs_update_inode(inode, wait);
  1063. }
  1064. /*
  1065. * Callback function from exofs_delete_inode() - don't have much cleaning up to
  1066. * do.
  1067. */
  1068. static void delete_done(struct exofs_io_state *ios, void *p)
  1069. {
  1070. struct exofs_sb_info *sbi = p;
  1071. exofs_put_io_state(ios);
  1072. atomic_dec(&sbi->s_curr_pending);
  1073. }
  1074. /*
  1075. * Called when the refcount of an inode reaches zero. We remove the object
  1076. * from the OSD here. We make sure the object was created before we try and
  1077. * delete it.
  1078. */
  1079. void exofs_delete_inode(struct inode *inode)
  1080. {
  1081. struct exofs_i_info *oi = exofs_i(inode);
  1082. struct super_block *sb = inode->i_sb;
  1083. struct exofs_sb_info *sbi = sb->s_fs_info;
  1084. struct exofs_io_state *ios;
  1085. int ret;
  1086. truncate_inode_pages(&inode->i_data, 0);
  1087. if (is_bad_inode(inode))
  1088. goto no_delete;
  1089. mark_inode_dirty(inode);
  1090. exofs_update_inode(inode, inode_needs_sync(inode));
  1091. inode->i_size = 0;
  1092. if (inode->i_blocks)
  1093. exofs_truncate(inode);
  1094. clear_inode(inode);
  1095. ret = exofs_get_io_state(&sbi->layout, &ios);
  1096. if (unlikely(ret)) {
  1097. EXOFS_ERR("%s: exofs_get_io_state failed\n", __func__);
  1098. return;
  1099. }
  1100. /* if we are deleting an obj that hasn't been created yet, wait */
  1101. if (!obj_created(oi)) {
  1102. BUG_ON(!obj_2bcreated(oi));
  1103. wait_event(oi->i_wq, obj_created(oi));
  1104. }
  1105. ios->obj.id = exofs_oi_objno(oi);
  1106. ios->done = delete_done;
  1107. ios->private = sbi;
  1108. ios->cred = oi->i_cred;
  1109. ret = exofs_sbi_remove(ios);
  1110. if (ret) {
  1111. EXOFS_ERR("%s: exofs_sbi_remove failed\n", __func__);
  1112. exofs_put_io_state(ios);
  1113. return;
  1114. }
  1115. atomic_inc(&sbi->s_curr_pending);
  1116. return;
  1117. no_delete:
  1118. clear_inode(inode);
  1119. }