cpfile.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * NILFS checkpoint file.
  4. *
  5. * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * Written by Koji Sato.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/fs.h>
  11. #include <linux/string.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/errno.h>
  14. #include "mdt.h"
  15. #include "cpfile.h"
  16. static inline unsigned long
  17. nilfs_cpfile_checkpoints_per_block(const struct inode *cpfile)
  18. {
  19. return NILFS_MDT(cpfile)->mi_entries_per_block;
  20. }
  21. /* block number from the beginning of the file */
  22. static unsigned long
  23. nilfs_cpfile_get_blkoff(const struct inode *cpfile, __u64 cno)
  24. {
  25. __u64 tcno = cno + NILFS_MDT(cpfile)->mi_first_entry_offset - 1;
  26. tcno = div64_ul(tcno, nilfs_cpfile_checkpoints_per_block(cpfile));
  27. return (unsigned long)tcno;
  28. }
  29. /* offset in block */
  30. static unsigned long
  31. nilfs_cpfile_get_offset(const struct inode *cpfile, __u64 cno)
  32. {
  33. __u64 tcno = cno + NILFS_MDT(cpfile)->mi_first_entry_offset - 1;
  34. return do_div(tcno, nilfs_cpfile_checkpoints_per_block(cpfile));
  35. }
  36. static __u64 nilfs_cpfile_first_checkpoint_in_block(const struct inode *cpfile,
  37. unsigned long blkoff)
  38. {
  39. return (__u64)nilfs_cpfile_checkpoints_per_block(cpfile) * blkoff
  40. + 1 - NILFS_MDT(cpfile)->mi_first_entry_offset;
  41. }
  42. static unsigned long
  43. nilfs_cpfile_checkpoints_in_block(const struct inode *cpfile,
  44. __u64 curr,
  45. __u64 max)
  46. {
  47. return min_t(__u64,
  48. nilfs_cpfile_checkpoints_per_block(cpfile) -
  49. nilfs_cpfile_get_offset(cpfile, curr),
  50. max - curr);
  51. }
  52. static inline int nilfs_cpfile_is_in_first(const struct inode *cpfile,
  53. __u64 cno)
  54. {
  55. return nilfs_cpfile_get_blkoff(cpfile, cno) == 0;
  56. }
  57. static unsigned int
  58. nilfs_cpfile_block_add_valid_checkpoints(const struct inode *cpfile,
  59. struct buffer_head *bh,
  60. unsigned int n)
  61. {
  62. struct nilfs_checkpoint *cp;
  63. unsigned int count;
  64. cp = kmap_local_folio(bh->b_folio,
  65. offset_in_folio(bh->b_folio, bh->b_data));
  66. count = le32_to_cpu(cp->cp_checkpoints_count) + n;
  67. cp->cp_checkpoints_count = cpu_to_le32(count);
  68. kunmap_local(cp);
  69. return count;
  70. }
  71. static unsigned int
  72. nilfs_cpfile_block_sub_valid_checkpoints(const struct inode *cpfile,
  73. struct buffer_head *bh,
  74. unsigned int n)
  75. {
  76. struct nilfs_checkpoint *cp;
  77. unsigned int count;
  78. cp = kmap_local_folio(bh->b_folio,
  79. offset_in_folio(bh->b_folio, bh->b_data));
  80. WARN_ON(le32_to_cpu(cp->cp_checkpoints_count) < n);
  81. count = le32_to_cpu(cp->cp_checkpoints_count) - n;
  82. cp->cp_checkpoints_count = cpu_to_le32(count);
  83. kunmap_local(cp);
  84. return count;
  85. }
  86. static void nilfs_cpfile_block_init(struct inode *cpfile,
  87. struct buffer_head *bh,
  88. void *from)
  89. {
  90. struct nilfs_checkpoint *cp = from;
  91. size_t cpsz = NILFS_MDT(cpfile)->mi_entry_size;
  92. int n = nilfs_cpfile_checkpoints_per_block(cpfile);
  93. while (n-- > 0) {
  94. nilfs_checkpoint_set_invalid(cp);
  95. cp = (void *)cp + cpsz;
  96. }
  97. }
  98. /**
  99. * nilfs_cpfile_checkpoint_offset - calculate the byte offset of a checkpoint
  100. * entry in the folio containing it
  101. * @cpfile: checkpoint file inode
  102. * @cno: checkpoint number
  103. * @bh: buffer head of block containing checkpoint indexed by @cno
  104. *
  105. * Return: Byte offset in the folio of the checkpoint specified by @cno.
  106. */
  107. static size_t nilfs_cpfile_checkpoint_offset(const struct inode *cpfile,
  108. __u64 cno,
  109. struct buffer_head *bh)
  110. {
  111. return offset_in_folio(bh->b_folio, bh->b_data) +
  112. nilfs_cpfile_get_offset(cpfile, cno) *
  113. NILFS_MDT(cpfile)->mi_entry_size;
  114. }
  115. /**
  116. * nilfs_cpfile_cp_snapshot_list_offset - calculate the byte offset of a
  117. * checkpoint snapshot list in the folio
  118. * containing it
  119. * @cpfile: checkpoint file inode
  120. * @cno: checkpoint number
  121. * @bh: buffer head of block containing checkpoint indexed by @cno
  122. *
  123. * Return: Byte offset in the folio of the checkpoint snapshot list specified
  124. * by @cno.
  125. */
  126. static size_t nilfs_cpfile_cp_snapshot_list_offset(const struct inode *cpfile,
  127. __u64 cno,
  128. struct buffer_head *bh)
  129. {
  130. return nilfs_cpfile_checkpoint_offset(cpfile, cno, bh) +
  131. offsetof(struct nilfs_checkpoint, cp_snapshot_list);
  132. }
  133. /**
  134. * nilfs_cpfile_ch_snapshot_list_offset - calculate the byte offset of the
  135. * snapshot list in the header
  136. *
  137. * Return: Byte offset in the folio of the checkpoint snapshot list
  138. */
  139. static size_t nilfs_cpfile_ch_snapshot_list_offset(void)
  140. {
  141. return offsetof(struct nilfs_cpfile_header, ch_snapshot_list);
  142. }
  143. static int nilfs_cpfile_get_header_block(struct inode *cpfile,
  144. struct buffer_head **bhp)
  145. {
  146. int err = nilfs_mdt_get_block(cpfile, 0, 0, NULL, bhp);
  147. if (unlikely(err == -ENOENT)) {
  148. nilfs_error(cpfile->i_sb,
  149. "missing header block in checkpoint metadata");
  150. err = -EIO;
  151. }
  152. return err;
  153. }
  154. static inline int nilfs_cpfile_get_checkpoint_block(struct inode *cpfile,
  155. __u64 cno,
  156. int create,
  157. struct buffer_head **bhp)
  158. {
  159. return nilfs_mdt_get_block(cpfile,
  160. nilfs_cpfile_get_blkoff(cpfile, cno),
  161. create, nilfs_cpfile_block_init, bhp);
  162. }
  163. /**
  164. * nilfs_cpfile_find_checkpoint_block - find and get a buffer on cpfile
  165. * @cpfile: inode of cpfile
  166. * @start_cno: start checkpoint number (inclusive)
  167. * @end_cno: end checkpoint number (inclusive)
  168. * @cnop: place to store the next checkpoint number
  169. * @bhp: place to store a pointer to buffer_head struct
  170. *
  171. * Return: 0 on success, or one of the following negative error codes on
  172. * failure:
  173. * * %-EIO - I/O error (including metadata corruption).
  174. * * %-ENOENT - no block exists in the range.
  175. * * %-ENOMEM - Insufficient memory available.
  176. */
  177. static int nilfs_cpfile_find_checkpoint_block(struct inode *cpfile,
  178. __u64 start_cno, __u64 end_cno,
  179. __u64 *cnop,
  180. struct buffer_head **bhp)
  181. {
  182. unsigned long start, end, blkoff;
  183. int ret;
  184. if (unlikely(start_cno > end_cno))
  185. return -ENOENT;
  186. start = nilfs_cpfile_get_blkoff(cpfile, start_cno);
  187. end = nilfs_cpfile_get_blkoff(cpfile, end_cno);
  188. ret = nilfs_mdt_find_block(cpfile, start, end, &blkoff, bhp);
  189. if (!ret)
  190. *cnop = (blkoff == start) ? start_cno :
  191. nilfs_cpfile_first_checkpoint_in_block(cpfile, blkoff);
  192. return ret;
  193. }
  194. static inline int nilfs_cpfile_delete_checkpoint_block(struct inode *cpfile,
  195. __u64 cno)
  196. {
  197. return nilfs_mdt_delete_block(cpfile,
  198. nilfs_cpfile_get_blkoff(cpfile, cno));
  199. }
  200. /**
  201. * nilfs_cpfile_read_checkpoint - read a checkpoint entry in cpfile
  202. * @cpfile: checkpoint file inode
  203. * @cno: number of checkpoint entry to read
  204. * @root: nilfs root object
  205. * @ifile: ifile's inode to read and attach to @root
  206. *
  207. * This function imports checkpoint information from the checkpoint file and
  208. * stores it to the inode file given by @ifile and the nilfs root object
  209. * given by @root.
  210. *
  211. * Return: 0 on success, or one of the following negative error codes on
  212. * failure:
  213. * * %-EINVAL - Invalid checkpoint.
  214. * * %-ENOMEM - Insufficient memory available.
  215. * * %-EIO - I/O error (including metadata corruption).
  216. */
  217. int nilfs_cpfile_read_checkpoint(struct inode *cpfile, __u64 cno,
  218. struct nilfs_root *root, struct inode *ifile)
  219. {
  220. struct buffer_head *cp_bh;
  221. struct nilfs_checkpoint *cp;
  222. size_t offset;
  223. int ret;
  224. if (cno < 1 || cno > nilfs_mdt_cno(cpfile))
  225. return -EINVAL;
  226. down_read(&NILFS_MDT(cpfile)->mi_sem);
  227. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh);
  228. if (unlikely(ret < 0)) {
  229. if (ret == -ENOENT)
  230. ret = -EINVAL;
  231. goto out_sem;
  232. }
  233. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  234. cp = kmap_local_folio(cp_bh->b_folio, offset);
  235. if (nilfs_checkpoint_invalid(cp)) {
  236. ret = -EINVAL;
  237. goto put_cp;
  238. }
  239. ret = nilfs_read_inode_common(ifile, &cp->cp_ifile_inode);
  240. if (unlikely(ret)) {
  241. /*
  242. * Since this inode is on a checkpoint entry, treat errors
  243. * as metadata corruption.
  244. */
  245. nilfs_err(cpfile->i_sb,
  246. "ifile inode (checkpoint number=%llu) corrupted",
  247. (unsigned long long)cno);
  248. ret = -EIO;
  249. goto put_cp;
  250. }
  251. /* Configure the nilfs root object */
  252. atomic64_set(&root->inodes_count, le64_to_cpu(cp->cp_inodes_count));
  253. atomic64_set(&root->blocks_count, le64_to_cpu(cp->cp_blocks_count));
  254. root->ifile = ifile;
  255. put_cp:
  256. kunmap_local(cp);
  257. brelse(cp_bh);
  258. out_sem:
  259. up_read(&NILFS_MDT(cpfile)->mi_sem);
  260. return ret;
  261. }
  262. /**
  263. * nilfs_cpfile_create_checkpoint - create a checkpoint entry on cpfile
  264. * @cpfile: checkpoint file inode
  265. * @cno: number of checkpoint to set up
  266. *
  267. * This function creates a checkpoint with the number specified by @cno on
  268. * cpfile. If the specified checkpoint entry already exists due to a past
  269. * failure, it will be reused without returning an error.
  270. * In either case, the buffer of the block containing the checkpoint entry
  271. * and the cpfile inode are made dirty for inclusion in the write log.
  272. *
  273. * Return: 0 on success, or one of the following negative error codes on
  274. * failure:
  275. * * %-ENOMEM - Insufficient memory available.
  276. * * %-EIO - I/O error (including metadata corruption).
  277. * * %-EROFS - Read only filesystem
  278. */
  279. int nilfs_cpfile_create_checkpoint(struct inode *cpfile, __u64 cno)
  280. {
  281. struct buffer_head *header_bh, *cp_bh;
  282. struct nilfs_cpfile_header *header;
  283. struct nilfs_checkpoint *cp;
  284. size_t offset;
  285. int ret;
  286. if (WARN_ON_ONCE(cno < 1))
  287. return -EIO;
  288. down_write(&NILFS_MDT(cpfile)->mi_sem);
  289. ret = nilfs_cpfile_get_header_block(cpfile, &header_bh);
  290. if (unlikely(ret < 0))
  291. goto out_sem;
  292. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 1, &cp_bh);
  293. if (unlikely(ret < 0))
  294. goto out_header;
  295. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  296. cp = kmap_local_folio(cp_bh->b_folio, offset);
  297. if (nilfs_checkpoint_invalid(cp)) {
  298. /* a newly-created checkpoint */
  299. nilfs_checkpoint_clear_invalid(cp);
  300. kunmap_local(cp);
  301. if (!nilfs_cpfile_is_in_first(cpfile, cno))
  302. nilfs_cpfile_block_add_valid_checkpoints(cpfile, cp_bh,
  303. 1);
  304. header = kmap_local_folio(header_bh->b_folio, 0);
  305. le64_add_cpu(&header->ch_ncheckpoints, 1);
  306. kunmap_local(header);
  307. mark_buffer_dirty(header_bh);
  308. } else {
  309. kunmap_local(cp);
  310. }
  311. /* Force the buffer and the inode to become dirty */
  312. mark_buffer_dirty(cp_bh);
  313. brelse(cp_bh);
  314. nilfs_mdt_mark_dirty(cpfile);
  315. out_header:
  316. brelse(header_bh);
  317. out_sem:
  318. up_write(&NILFS_MDT(cpfile)->mi_sem);
  319. return ret;
  320. }
  321. /**
  322. * nilfs_cpfile_finalize_checkpoint - fill in a checkpoint entry in cpfile
  323. * @cpfile: checkpoint file inode
  324. * @cno: checkpoint number
  325. * @root: nilfs root object
  326. * @blkinc: number of blocks added by this checkpoint
  327. * @ctime: checkpoint creation time
  328. * @minor: minor checkpoint flag
  329. *
  330. * This function completes the checkpoint entry numbered by @cno in the
  331. * cpfile with the data given by the arguments @root, @blkinc, @ctime, and
  332. * @minor.
  333. *
  334. * Return: 0 on success, or one of the following negative error codes on
  335. * failure:
  336. * * %-ENOMEM - Insufficient memory available.
  337. * * %-EIO - I/O error (including metadata corruption).
  338. */
  339. int nilfs_cpfile_finalize_checkpoint(struct inode *cpfile, __u64 cno,
  340. struct nilfs_root *root, __u64 blkinc,
  341. time64_t ctime, bool minor)
  342. {
  343. struct buffer_head *cp_bh;
  344. struct nilfs_checkpoint *cp;
  345. size_t offset;
  346. int ret;
  347. if (WARN_ON_ONCE(cno < 1))
  348. return -EIO;
  349. down_write(&NILFS_MDT(cpfile)->mi_sem);
  350. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh);
  351. if (unlikely(ret < 0)) {
  352. if (ret == -ENOENT)
  353. goto error;
  354. goto out_sem;
  355. }
  356. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  357. cp = kmap_local_folio(cp_bh->b_folio, offset);
  358. if (unlikely(nilfs_checkpoint_invalid(cp))) {
  359. kunmap_local(cp);
  360. brelse(cp_bh);
  361. goto error;
  362. }
  363. cp->cp_snapshot_list.ssl_next = 0;
  364. cp->cp_snapshot_list.ssl_prev = 0;
  365. cp->cp_inodes_count = cpu_to_le64(atomic64_read(&root->inodes_count));
  366. cp->cp_blocks_count = cpu_to_le64(atomic64_read(&root->blocks_count));
  367. cp->cp_nblk_inc = cpu_to_le64(blkinc);
  368. cp->cp_create = cpu_to_le64(ctime);
  369. cp->cp_cno = cpu_to_le64(cno);
  370. if (minor)
  371. nilfs_checkpoint_set_minor(cp);
  372. else
  373. nilfs_checkpoint_clear_minor(cp);
  374. nilfs_write_inode_common(root->ifile, &cp->cp_ifile_inode);
  375. nilfs_bmap_write(NILFS_I(root->ifile)->i_bmap, &cp->cp_ifile_inode);
  376. kunmap_local(cp);
  377. brelse(cp_bh);
  378. out_sem:
  379. up_write(&NILFS_MDT(cpfile)->mi_sem);
  380. return ret;
  381. error:
  382. nilfs_error(cpfile->i_sb,
  383. "checkpoint finalization failed due to metadata corruption.");
  384. ret = -EIO;
  385. goto out_sem;
  386. }
  387. /**
  388. * nilfs_cpfile_delete_checkpoints - delete checkpoints
  389. * @cpfile: inode of checkpoint file
  390. * @start: start checkpoint number
  391. * @end: end checkpoint number
  392. *
  393. * Description: nilfs_cpfile_delete_checkpoints() deletes the checkpoints in
  394. * the period from @start to @end, excluding @end itself. The checkpoints
  395. * which have been already deleted are ignored.
  396. *
  397. * Return: 0 on success, or one of the following negative error codes on
  398. * failure:
  399. * * %-EINVAL - Invalid checkpoints.
  400. * * %-EIO - I/O error (including metadata corruption).
  401. * * %-ENOMEM - Insufficient memory available.
  402. */
  403. int nilfs_cpfile_delete_checkpoints(struct inode *cpfile,
  404. __u64 start,
  405. __u64 end)
  406. {
  407. struct buffer_head *header_bh, *cp_bh;
  408. struct nilfs_cpfile_header *header;
  409. struct nilfs_checkpoint *cp;
  410. size_t cpsz = NILFS_MDT(cpfile)->mi_entry_size;
  411. __u64 cno;
  412. size_t offset;
  413. void *kaddr;
  414. unsigned long tnicps;
  415. int ret, ncps, nicps, nss, count, i;
  416. if (unlikely(start == 0 || start > end)) {
  417. nilfs_err(cpfile->i_sb,
  418. "cannot delete checkpoints: invalid range [%llu, %llu)",
  419. (unsigned long long)start, (unsigned long long)end);
  420. return -EINVAL;
  421. }
  422. down_write(&NILFS_MDT(cpfile)->mi_sem);
  423. ret = nilfs_cpfile_get_header_block(cpfile, &header_bh);
  424. if (ret < 0)
  425. goto out_sem;
  426. tnicps = 0;
  427. nss = 0;
  428. for (cno = start; cno < end; cno += ncps) {
  429. ncps = nilfs_cpfile_checkpoints_in_block(cpfile, cno, end);
  430. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh);
  431. if (ret < 0) {
  432. if (ret != -ENOENT)
  433. break;
  434. /* skip hole */
  435. ret = 0;
  436. continue;
  437. }
  438. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  439. cp = kaddr = kmap_local_folio(cp_bh->b_folio, offset);
  440. nicps = 0;
  441. for (i = 0; i < ncps; i++, cp = (void *)cp + cpsz) {
  442. if (nilfs_checkpoint_snapshot(cp)) {
  443. nss++;
  444. } else if (!nilfs_checkpoint_invalid(cp)) {
  445. nilfs_checkpoint_set_invalid(cp);
  446. nicps++;
  447. }
  448. }
  449. kunmap_local(kaddr);
  450. if (nicps <= 0) {
  451. brelse(cp_bh);
  452. continue;
  453. }
  454. tnicps += nicps;
  455. mark_buffer_dirty(cp_bh);
  456. nilfs_mdt_mark_dirty(cpfile);
  457. if (nilfs_cpfile_is_in_first(cpfile, cno)) {
  458. brelse(cp_bh);
  459. continue;
  460. }
  461. count = nilfs_cpfile_block_sub_valid_checkpoints(cpfile, cp_bh,
  462. nicps);
  463. brelse(cp_bh);
  464. if (count)
  465. continue;
  466. /* Delete the block if there are no more valid checkpoints */
  467. ret = nilfs_cpfile_delete_checkpoint_block(cpfile, cno);
  468. if (unlikely(ret)) {
  469. nilfs_err(cpfile->i_sb,
  470. "error %d deleting checkpoint block", ret);
  471. break;
  472. }
  473. }
  474. if (tnicps > 0) {
  475. header = kmap_local_folio(header_bh->b_folio, 0);
  476. le64_add_cpu(&header->ch_ncheckpoints, -(u64)tnicps);
  477. mark_buffer_dirty(header_bh);
  478. nilfs_mdt_mark_dirty(cpfile);
  479. kunmap_local(header);
  480. }
  481. brelse(header_bh);
  482. if (nss > 0)
  483. ret = -EBUSY;
  484. out_sem:
  485. up_write(&NILFS_MDT(cpfile)->mi_sem);
  486. return ret;
  487. }
  488. static void nilfs_cpfile_checkpoint_to_cpinfo(struct inode *cpfile,
  489. struct nilfs_checkpoint *cp,
  490. struct nilfs_cpinfo *ci)
  491. {
  492. ci->ci_flags = le32_to_cpu(cp->cp_flags);
  493. ci->ci_cno = le64_to_cpu(cp->cp_cno);
  494. ci->ci_create = le64_to_cpu(cp->cp_create);
  495. ci->ci_nblk_inc = le64_to_cpu(cp->cp_nblk_inc);
  496. ci->ci_inodes_count = le64_to_cpu(cp->cp_inodes_count);
  497. ci->ci_blocks_count = le64_to_cpu(cp->cp_blocks_count);
  498. ci->ci_next = le64_to_cpu(cp->cp_snapshot_list.ssl_next);
  499. }
  500. static ssize_t nilfs_cpfile_do_get_cpinfo(struct inode *cpfile, __u64 *cnop,
  501. void *buf, unsigned int cisz,
  502. size_t nci)
  503. {
  504. struct nilfs_checkpoint *cp;
  505. struct nilfs_cpinfo *ci = buf;
  506. struct buffer_head *bh;
  507. size_t cpsz = NILFS_MDT(cpfile)->mi_entry_size;
  508. __u64 cur_cno = nilfs_mdt_cno(cpfile), cno = *cnop;
  509. size_t offset;
  510. void *kaddr;
  511. int n, ret;
  512. int ncps, i;
  513. if (cno == 0)
  514. return -ENOENT; /* checkpoint number 0 is invalid */
  515. down_read(&NILFS_MDT(cpfile)->mi_sem);
  516. for (n = 0; n < nci; cno += ncps) {
  517. ret = nilfs_cpfile_find_checkpoint_block(
  518. cpfile, cno, cur_cno - 1, &cno, &bh);
  519. if (ret < 0) {
  520. if (likely(ret == -ENOENT))
  521. break;
  522. goto out;
  523. }
  524. ncps = nilfs_cpfile_checkpoints_in_block(cpfile, cno, cur_cno);
  525. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, bh);
  526. cp = kaddr = kmap_local_folio(bh->b_folio, offset);
  527. for (i = 0; i < ncps && n < nci; i++, cp = (void *)cp + cpsz) {
  528. if (!nilfs_checkpoint_invalid(cp)) {
  529. nilfs_cpfile_checkpoint_to_cpinfo(cpfile, cp,
  530. ci);
  531. ci = (void *)ci + cisz;
  532. n++;
  533. }
  534. }
  535. kunmap_local(kaddr);
  536. brelse(bh);
  537. }
  538. ret = n;
  539. if (n > 0) {
  540. ci = (void *)ci - cisz;
  541. *cnop = ci->ci_cno + 1;
  542. }
  543. out:
  544. up_read(&NILFS_MDT(cpfile)->mi_sem);
  545. return ret;
  546. }
  547. static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 *cnop,
  548. void *buf, unsigned int cisz,
  549. size_t nci)
  550. {
  551. struct buffer_head *bh;
  552. struct nilfs_cpfile_header *header;
  553. struct nilfs_checkpoint *cp;
  554. struct nilfs_cpinfo *ci = buf;
  555. __u64 curr = *cnop, next;
  556. unsigned long curr_blkoff, next_blkoff;
  557. size_t offset;
  558. int n = 0, ret;
  559. down_read(&NILFS_MDT(cpfile)->mi_sem);
  560. if (curr == 0) {
  561. ret = nilfs_cpfile_get_header_block(cpfile, &bh);
  562. if (ret < 0)
  563. goto out;
  564. header = kmap_local_folio(bh->b_folio, 0);
  565. curr = le64_to_cpu(header->ch_snapshot_list.ssl_next);
  566. kunmap_local(header);
  567. brelse(bh);
  568. if (curr == 0) {
  569. ret = 0;
  570. goto out;
  571. }
  572. } else if (unlikely(curr == ~(__u64)0)) {
  573. ret = 0;
  574. goto out;
  575. }
  576. curr_blkoff = nilfs_cpfile_get_blkoff(cpfile, curr);
  577. ret = nilfs_cpfile_get_checkpoint_block(cpfile, curr, 0, &bh);
  578. if (unlikely(ret < 0)) {
  579. if (ret == -ENOENT)
  580. ret = 0; /* No snapshots (started from a hole block) */
  581. goto out;
  582. }
  583. offset = nilfs_cpfile_checkpoint_offset(cpfile, curr, bh);
  584. cp = kmap_local_folio(bh->b_folio, offset);
  585. while (n < nci) {
  586. curr = ~(__u64)0; /* Terminator */
  587. if (unlikely(nilfs_checkpoint_invalid(cp) ||
  588. !nilfs_checkpoint_snapshot(cp)))
  589. break;
  590. nilfs_cpfile_checkpoint_to_cpinfo(cpfile, cp, ci);
  591. ci = (void *)ci + cisz;
  592. n++;
  593. next = le64_to_cpu(cp->cp_snapshot_list.ssl_next);
  594. if (next == 0)
  595. break; /* reach end of the snapshot list */
  596. kunmap_local(cp);
  597. next_blkoff = nilfs_cpfile_get_blkoff(cpfile, next);
  598. if (curr_blkoff != next_blkoff) {
  599. brelse(bh);
  600. ret = nilfs_cpfile_get_checkpoint_block(cpfile, next,
  601. 0, &bh);
  602. if (unlikely(ret < 0)) {
  603. WARN_ON(ret == -ENOENT);
  604. goto out;
  605. }
  606. }
  607. offset = nilfs_cpfile_checkpoint_offset(cpfile, next, bh);
  608. cp = kmap_local_folio(bh->b_folio, offset);
  609. curr = next;
  610. curr_blkoff = next_blkoff;
  611. }
  612. kunmap_local(cp);
  613. brelse(bh);
  614. *cnop = curr;
  615. ret = n;
  616. out:
  617. up_read(&NILFS_MDT(cpfile)->mi_sem);
  618. return ret;
  619. }
  620. /**
  621. * nilfs_cpfile_get_cpinfo - get information on checkpoints
  622. * @cpfile: checkpoint file inode
  623. * @cnop: place to pass a starting checkpoint number and receive a
  624. * checkpoint number to continue the search
  625. * @mode: mode of checkpoints that the caller wants to retrieve
  626. * @buf: buffer for storing checkpoints' information
  627. * @cisz: byte size of one checkpoint info item in array
  628. * @nci: number of checkpoint info items to retrieve
  629. *
  630. * nilfs_cpfile_get_cpinfo() searches for checkpoints in @mode state
  631. * starting from the checkpoint number stored in @cnop, and stores
  632. * information about found checkpoints in @buf.
  633. * The buffer pointed to by @buf must be large enough to store information
  634. * for @nci checkpoints. If at least one checkpoint information is
  635. * successfully retrieved, @cnop is updated to point to the checkpoint
  636. * number to continue searching.
  637. *
  638. * Return: Count of checkpoint info items stored in the output buffer on
  639. * success, or one of the following negative error codes on failure:
  640. * * %-EINVAL - Invalid checkpoint mode.
  641. * * %-ENOMEM - Insufficient memory available.
  642. * * %-EIO - I/O error (including metadata corruption).
  643. * * %-ENOENT - Invalid checkpoint number specified.
  644. */
  645. ssize_t nilfs_cpfile_get_cpinfo(struct inode *cpfile, __u64 *cnop, int mode,
  646. void *buf, unsigned int cisz, size_t nci)
  647. {
  648. switch (mode) {
  649. case NILFS_CHECKPOINT:
  650. return nilfs_cpfile_do_get_cpinfo(cpfile, cnop, buf, cisz, nci);
  651. case NILFS_SNAPSHOT:
  652. return nilfs_cpfile_do_get_ssinfo(cpfile, cnop, buf, cisz, nci);
  653. default:
  654. return -EINVAL;
  655. }
  656. }
  657. /**
  658. * nilfs_cpfile_delete_checkpoint - delete a checkpoint
  659. * @cpfile: checkpoint file inode
  660. * @cno: checkpoint number to delete
  661. *
  662. * Return: 0 on success, or one of the following negative error codes on
  663. * failure:
  664. * * %-EBUSY - Checkpoint in use (snapshot specified).
  665. * * %-EIO - I/O error (including metadata corruption).
  666. * * %-ENOENT - No valid checkpoint found.
  667. * * %-ENOMEM - Insufficient memory available.
  668. */
  669. int nilfs_cpfile_delete_checkpoint(struct inode *cpfile, __u64 cno)
  670. {
  671. struct nilfs_cpinfo ci;
  672. __u64 tcno = cno;
  673. ssize_t nci;
  674. nci = nilfs_cpfile_do_get_cpinfo(cpfile, &tcno, &ci, sizeof(ci), 1);
  675. if (nci < 0)
  676. return nci;
  677. else if (nci == 0 || ci.ci_cno != cno)
  678. return -ENOENT;
  679. else if (nilfs_cpinfo_snapshot(&ci))
  680. return -EBUSY;
  681. return nilfs_cpfile_delete_checkpoints(cpfile, cno, cno + 1);
  682. }
  683. static int nilfs_cpfile_set_snapshot(struct inode *cpfile, __u64 cno)
  684. {
  685. struct buffer_head *header_bh, *curr_bh, *prev_bh, *cp_bh;
  686. struct nilfs_cpfile_header *header;
  687. struct nilfs_checkpoint *cp;
  688. struct nilfs_snapshot_list *list;
  689. __u64 curr, prev;
  690. unsigned long curr_blkoff, prev_blkoff;
  691. size_t offset, curr_list_offset, prev_list_offset;
  692. int ret;
  693. if (cno == 0)
  694. return -ENOENT; /* checkpoint number 0 is invalid */
  695. down_write(&NILFS_MDT(cpfile)->mi_sem);
  696. ret = nilfs_cpfile_get_header_block(cpfile, &header_bh);
  697. if (unlikely(ret < 0))
  698. goto out_sem;
  699. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh);
  700. if (ret < 0)
  701. goto out_header;
  702. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  703. cp = kmap_local_folio(cp_bh->b_folio, offset);
  704. if (nilfs_checkpoint_invalid(cp)) {
  705. ret = -ENOENT;
  706. kunmap_local(cp);
  707. goto out_cp;
  708. }
  709. if (nilfs_checkpoint_snapshot(cp)) {
  710. ret = 0;
  711. kunmap_local(cp);
  712. goto out_cp;
  713. }
  714. kunmap_local(cp);
  715. /*
  716. * Find the last snapshot before the checkpoint being changed to
  717. * snapshot mode by going backwards through the snapshot list.
  718. * Set "prev" to its checkpoint number, or 0 if not found.
  719. */
  720. header = kmap_local_folio(header_bh->b_folio, 0);
  721. list = &header->ch_snapshot_list;
  722. curr_bh = header_bh;
  723. get_bh(curr_bh);
  724. curr = 0;
  725. curr_blkoff = 0;
  726. curr_list_offset = nilfs_cpfile_ch_snapshot_list_offset();
  727. prev = le64_to_cpu(list->ssl_prev);
  728. while (prev > cno) {
  729. prev_blkoff = nilfs_cpfile_get_blkoff(cpfile, prev);
  730. curr = prev;
  731. kunmap_local(list);
  732. if (curr_blkoff != prev_blkoff) {
  733. brelse(curr_bh);
  734. ret = nilfs_cpfile_get_checkpoint_block(cpfile, curr,
  735. 0, &curr_bh);
  736. if (unlikely(ret < 0))
  737. goto out_cp;
  738. }
  739. curr_list_offset = nilfs_cpfile_cp_snapshot_list_offset(
  740. cpfile, curr, curr_bh);
  741. list = kmap_local_folio(curr_bh->b_folio, curr_list_offset);
  742. curr_blkoff = prev_blkoff;
  743. prev = le64_to_cpu(list->ssl_prev);
  744. }
  745. kunmap_local(list);
  746. if (prev != 0) {
  747. ret = nilfs_cpfile_get_checkpoint_block(cpfile, prev, 0,
  748. &prev_bh);
  749. if (ret < 0)
  750. goto out_curr;
  751. prev_list_offset = nilfs_cpfile_cp_snapshot_list_offset(
  752. cpfile, prev, prev_bh);
  753. } else {
  754. prev_bh = header_bh;
  755. get_bh(prev_bh);
  756. prev_list_offset = nilfs_cpfile_ch_snapshot_list_offset();
  757. }
  758. /* Update the list entry for the next snapshot */
  759. list = kmap_local_folio(curr_bh->b_folio, curr_list_offset);
  760. list->ssl_prev = cpu_to_le64(cno);
  761. kunmap_local(list);
  762. /* Update the checkpoint being changed to a snapshot */
  763. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  764. cp = kmap_local_folio(cp_bh->b_folio, offset);
  765. cp->cp_snapshot_list.ssl_next = cpu_to_le64(curr);
  766. cp->cp_snapshot_list.ssl_prev = cpu_to_le64(prev);
  767. nilfs_checkpoint_set_snapshot(cp);
  768. kunmap_local(cp);
  769. /* Update the list entry for the previous snapshot */
  770. list = kmap_local_folio(prev_bh->b_folio, prev_list_offset);
  771. list->ssl_next = cpu_to_le64(cno);
  772. kunmap_local(list);
  773. /* Update the statistics in the header */
  774. header = kmap_local_folio(header_bh->b_folio, 0);
  775. le64_add_cpu(&header->ch_nsnapshots, 1);
  776. kunmap_local(header);
  777. mark_buffer_dirty(prev_bh);
  778. mark_buffer_dirty(curr_bh);
  779. mark_buffer_dirty(cp_bh);
  780. mark_buffer_dirty(header_bh);
  781. nilfs_mdt_mark_dirty(cpfile);
  782. brelse(prev_bh);
  783. out_curr:
  784. brelse(curr_bh);
  785. out_cp:
  786. brelse(cp_bh);
  787. out_header:
  788. brelse(header_bh);
  789. out_sem:
  790. up_write(&NILFS_MDT(cpfile)->mi_sem);
  791. return ret;
  792. }
  793. static int nilfs_cpfile_clear_snapshot(struct inode *cpfile, __u64 cno)
  794. {
  795. struct buffer_head *header_bh, *next_bh, *prev_bh, *cp_bh;
  796. struct nilfs_cpfile_header *header;
  797. struct nilfs_checkpoint *cp;
  798. struct nilfs_snapshot_list *list;
  799. __u64 next, prev;
  800. size_t offset, next_list_offset, prev_list_offset;
  801. int ret;
  802. if (cno == 0)
  803. return -ENOENT; /* checkpoint number 0 is invalid */
  804. down_write(&NILFS_MDT(cpfile)->mi_sem);
  805. ret = nilfs_cpfile_get_header_block(cpfile, &header_bh);
  806. if (unlikely(ret < 0))
  807. goto out_sem;
  808. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh);
  809. if (ret < 0)
  810. goto out_header;
  811. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
  812. cp = kmap_local_folio(cp_bh->b_folio, offset);
  813. if (nilfs_checkpoint_invalid(cp)) {
  814. ret = -ENOENT;
  815. kunmap_local(cp);
  816. goto out_cp;
  817. }
  818. if (!nilfs_checkpoint_snapshot(cp)) {
  819. ret = 0;
  820. kunmap_local(cp);
  821. goto out_cp;
  822. }
  823. list = &cp->cp_snapshot_list;
  824. next = le64_to_cpu(list->ssl_next);
  825. prev = le64_to_cpu(list->ssl_prev);
  826. kunmap_local(cp);
  827. if (next != 0) {
  828. ret = nilfs_cpfile_get_checkpoint_block(cpfile, next, 0,
  829. &next_bh);
  830. if (ret < 0)
  831. goto out_cp;
  832. next_list_offset = nilfs_cpfile_cp_snapshot_list_offset(
  833. cpfile, next, next_bh);
  834. } else {
  835. next_bh = header_bh;
  836. get_bh(next_bh);
  837. next_list_offset = nilfs_cpfile_ch_snapshot_list_offset();
  838. }
  839. if (prev != 0) {
  840. ret = nilfs_cpfile_get_checkpoint_block(cpfile, prev, 0,
  841. &prev_bh);
  842. if (ret < 0)
  843. goto out_next;
  844. prev_list_offset = nilfs_cpfile_cp_snapshot_list_offset(
  845. cpfile, prev, prev_bh);
  846. } else {
  847. prev_bh = header_bh;
  848. get_bh(prev_bh);
  849. prev_list_offset = nilfs_cpfile_ch_snapshot_list_offset();
  850. }
  851. /* Update the list entry for the next snapshot */
  852. list = kmap_local_folio(next_bh->b_folio, next_list_offset);
  853. list->ssl_prev = cpu_to_le64(prev);
  854. kunmap_local(list);
  855. /* Update the list entry for the previous snapshot */
  856. list = kmap_local_folio(prev_bh->b_folio, prev_list_offset);
  857. list->ssl_next = cpu_to_le64(next);
  858. kunmap_local(list);
  859. /* Update the snapshot being changed back to a plain checkpoint */
  860. cp = kmap_local_folio(cp_bh->b_folio, offset);
  861. cp->cp_snapshot_list.ssl_next = cpu_to_le64(0);
  862. cp->cp_snapshot_list.ssl_prev = cpu_to_le64(0);
  863. nilfs_checkpoint_clear_snapshot(cp);
  864. kunmap_local(cp);
  865. /* Update the statistics in the header */
  866. header = kmap_local_folio(header_bh->b_folio, 0);
  867. le64_add_cpu(&header->ch_nsnapshots, -1);
  868. kunmap_local(header);
  869. mark_buffer_dirty(next_bh);
  870. mark_buffer_dirty(prev_bh);
  871. mark_buffer_dirty(cp_bh);
  872. mark_buffer_dirty(header_bh);
  873. nilfs_mdt_mark_dirty(cpfile);
  874. brelse(prev_bh);
  875. out_next:
  876. brelse(next_bh);
  877. out_cp:
  878. brelse(cp_bh);
  879. out_header:
  880. brelse(header_bh);
  881. out_sem:
  882. up_write(&NILFS_MDT(cpfile)->mi_sem);
  883. return ret;
  884. }
  885. /**
  886. * nilfs_cpfile_is_snapshot - determine if checkpoint is a snapshot
  887. * @cpfile: inode of checkpoint file
  888. * @cno: checkpoint number
  889. *
  890. * Return: 1 if the checkpoint specified by @cno is a snapshot, 0 if not, or
  891. * one of the following negative error codes on failure:
  892. * * %-EIO - I/O error (including metadata corruption).
  893. * * %-ENOENT - No such checkpoint.
  894. * * %-ENOMEM - Insufficient memory available.
  895. */
  896. int nilfs_cpfile_is_snapshot(struct inode *cpfile, __u64 cno)
  897. {
  898. struct buffer_head *bh;
  899. struct nilfs_checkpoint *cp;
  900. size_t offset;
  901. int ret;
  902. /*
  903. * CP number is invalid if it's zero or larger than the
  904. * largest existing one.
  905. */
  906. if (cno == 0 || cno >= nilfs_mdt_cno(cpfile))
  907. return -ENOENT;
  908. down_read(&NILFS_MDT(cpfile)->mi_sem);
  909. ret = nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &bh);
  910. if (ret < 0)
  911. goto out;
  912. offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, bh);
  913. cp = kmap_local_folio(bh->b_folio, offset);
  914. if (nilfs_checkpoint_invalid(cp))
  915. ret = -ENOENT;
  916. else
  917. ret = nilfs_checkpoint_snapshot(cp);
  918. kunmap_local(cp);
  919. brelse(bh);
  920. out:
  921. up_read(&NILFS_MDT(cpfile)->mi_sem);
  922. return ret;
  923. }
  924. /**
  925. * nilfs_cpfile_change_cpmode - change checkpoint mode
  926. * @cpfile: inode of checkpoint file
  927. * @cno: checkpoint number
  928. * @mode: mode of checkpoint
  929. *
  930. * Description: nilfs_change_cpmode() changes the mode of the checkpoint
  931. * specified by @cno. The mode @mode is NILFS_CHECKPOINT or NILFS_SNAPSHOT.
  932. *
  933. * Return: 0 on success, or one of the following negative error codes on
  934. * failure:
  935. * * %-EIO - I/O error (including metadata corruption).
  936. * * %-ENOENT - No such checkpoint.
  937. * * %-ENOMEM - Insufficient memory available.
  938. */
  939. int nilfs_cpfile_change_cpmode(struct inode *cpfile, __u64 cno, int mode)
  940. {
  941. int ret;
  942. switch (mode) {
  943. case NILFS_CHECKPOINT:
  944. if (nilfs_checkpoint_is_mounted(cpfile->i_sb, cno))
  945. /*
  946. * Current implementation does not have to protect
  947. * plain read-only mounts since they are exclusive
  948. * with a read/write mount and are protected from the
  949. * cleaner.
  950. */
  951. ret = -EBUSY;
  952. else
  953. ret = nilfs_cpfile_clear_snapshot(cpfile, cno);
  954. return ret;
  955. case NILFS_SNAPSHOT:
  956. return nilfs_cpfile_set_snapshot(cpfile, cno);
  957. default:
  958. return -EINVAL;
  959. }
  960. }
  961. /**
  962. * nilfs_cpfile_get_stat - get checkpoint statistics
  963. * @cpfile: inode of checkpoint file
  964. * @cpstat: pointer to a structure of checkpoint statistics
  965. *
  966. * Description: nilfs_cpfile_get_stat() returns information about checkpoints.
  967. * The checkpoint statistics are stored in the location pointed to by @cpstat.
  968. *
  969. * Return: 0 on success, or one of the following negative error codes on
  970. * failure:
  971. * * %-EIO - I/O error (including metadata corruption).
  972. * * %-ENOMEM - Insufficient memory available.
  973. */
  974. int nilfs_cpfile_get_stat(struct inode *cpfile, struct nilfs_cpstat *cpstat)
  975. {
  976. struct buffer_head *bh;
  977. struct nilfs_cpfile_header *header;
  978. int ret;
  979. down_read(&NILFS_MDT(cpfile)->mi_sem);
  980. ret = nilfs_cpfile_get_header_block(cpfile, &bh);
  981. if (ret < 0)
  982. goto out_sem;
  983. header = kmap_local_folio(bh->b_folio, 0);
  984. cpstat->cs_cno = nilfs_mdt_cno(cpfile);
  985. cpstat->cs_ncps = le64_to_cpu(header->ch_ncheckpoints);
  986. cpstat->cs_nsss = le64_to_cpu(header->ch_nsnapshots);
  987. kunmap_local(header);
  988. brelse(bh);
  989. out_sem:
  990. up_read(&NILFS_MDT(cpfile)->mi_sem);
  991. return ret;
  992. }
  993. /**
  994. * nilfs_cpfile_read - read or get cpfile inode
  995. * @sb: super block instance
  996. * @cpsize: size of a checkpoint entry
  997. * @raw_inode: on-disk cpfile inode
  998. * @inodep: buffer to store the inode
  999. *
  1000. * Return: 0 on success, or a negative error code on failure.
  1001. */
  1002. int nilfs_cpfile_read(struct super_block *sb, size_t cpsize,
  1003. struct nilfs_inode *raw_inode, struct inode **inodep)
  1004. {
  1005. struct inode *cpfile;
  1006. int err;
  1007. if (cpsize > sb->s_blocksize) {
  1008. nilfs_err(sb, "too large checkpoint size: %zu bytes", cpsize);
  1009. return -EINVAL;
  1010. } else if (cpsize < NILFS_MIN_CHECKPOINT_SIZE) {
  1011. nilfs_err(sb, "too small checkpoint size: %zu bytes", cpsize);
  1012. return -EINVAL;
  1013. }
  1014. cpfile = nilfs_iget_locked(sb, NULL, NILFS_CPFILE_INO);
  1015. if (unlikely(!cpfile))
  1016. return -ENOMEM;
  1017. if (!(inode_state_read_once(cpfile) & I_NEW))
  1018. goto out;
  1019. err = nilfs_mdt_init(cpfile, NILFS_MDT_GFP, 0);
  1020. if (err)
  1021. goto failed;
  1022. nilfs_mdt_set_entry_size(cpfile, cpsize,
  1023. sizeof(struct nilfs_cpfile_header));
  1024. err = nilfs_read_inode_common(cpfile, raw_inode);
  1025. if (err)
  1026. goto failed;
  1027. unlock_new_inode(cpfile);
  1028. out:
  1029. *inodep = cpfile;
  1030. return 0;
  1031. failed:
  1032. iget_failed(cpfile);
  1033. return err;
  1034. }