1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
12 #include "xfs_mount.h"
13 #include "xfs_inode.h"
14 #include "xfs_trans.h"
15 #include "xfs_inode_item.h"
16 #include "xfs_trace.h"
17 #include "xfs_trans_priv.h"
18 #include "xfs_buf_item.h"
20 #include "xfs_log_priv.h"
21 #include "xfs_error.h"
23 #include <linux/iversion.h>
25 struct kmem_cache *xfs_ili_cache; /* inode log item */
27 static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip)
29 return container_of(lip, struct xfs_inode_log_item, ili_item);
33 * The logged size of an inode fork is always the current size of the inode
34 * fork. This means that when an inode fork is relogged, the size of the logged
35 * region is determined by the current state, not the combination of the
36 * previously logged state + the current state. This is different relogging
37 * behaviour to most other log items which will retain the size of the
38 * previously logged changes when smaller regions are relogged.
40 * Hence operations that remove data from the inode fork (e.g. shortform
41 * dir/attr remove, extent form extent removal, etc), the size of the relogged
42 * inode gets -smaller- rather than stays the same size as the previously logged
43 * size and this can result in the committing transaction reducing the amount of
44 * space being consumed by the CIL.
47 xfs_inode_item_data_fork_size(
48 struct xfs_inode_log_item *iip,
52 struct xfs_inode *ip = iip->ili_inode;
54 switch (ip->i_df.if_format) {
55 case XFS_DINODE_FMT_EXTENTS:
56 if ((iip->ili_fields & XFS_ILOG_DEXT) &&
57 ip->i_df.if_nextents > 0 &&
58 ip->i_df.if_bytes > 0) {
59 /* worst case, doesn't subtract delalloc extents */
60 *nbytes += XFS_IFORK_DSIZE(ip);
64 case XFS_DINODE_FMT_BTREE:
65 if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
66 ip->i_df.if_broot_bytes > 0) {
67 *nbytes += ip->i_df.if_broot_bytes;
71 case XFS_DINODE_FMT_LOCAL:
72 if ((iip->ili_fields & XFS_ILOG_DDATA) &&
73 ip->i_df.if_bytes > 0) {
74 *nbytes += roundup(ip->i_df.if_bytes, 4);
79 case XFS_DINODE_FMT_DEV:
88 xfs_inode_item_attr_fork_size(
89 struct xfs_inode_log_item *iip,
93 struct xfs_inode *ip = iip->ili_inode;
95 switch (ip->i_afp->if_format) {
96 case XFS_DINODE_FMT_EXTENTS:
97 if ((iip->ili_fields & XFS_ILOG_AEXT) &&
98 ip->i_afp->if_nextents > 0 &&
99 ip->i_afp->if_bytes > 0) {
100 /* worst case, doesn't subtract unused space */
101 *nbytes += XFS_IFORK_ASIZE(ip);
105 case XFS_DINODE_FMT_BTREE:
106 if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
107 ip->i_afp->if_broot_bytes > 0) {
108 *nbytes += ip->i_afp->if_broot_bytes;
112 case XFS_DINODE_FMT_LOCAL:
113 if ((iip->ili_fields & XFS_ILOG_ADATA) &&
114 ip->i_afp->if_bytes > 0) {
115 *nbytes += roundup(ip->i_afp->if_bytes, 4);
126 * This returns the number of iovecs needed to log the given inode item.
128 * We need one iovec for the inode log format structure, one for the
129 * inode core, and possibly one for the inode data/extents/b-tree root
130 * and one for the inode attribute data/extents/b-tree root.
134 struct xfs_log_item *lip,
138 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
139 struct xfs_inode *ip = iip->ili_inode;
142 *nbytes += sizeof(struct xfs_inode_log_format) +
143 xfs_log_dinode_size(ip->i_mount);
145 xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
147 xfs_inode_item_attr_fork_size(iip, nvecs, nbytes);
151 xfs_inode_item_format_data_fork(
152 struct xfs_inode_log_item *iip,
153 struct xfs_inode_log_format *ilf,
154 struct xfs_log_vec *lv,
155 struct xfs_log_iovec **vecp)
157 struct xfs_inode *ip = iip->ili_inode;
160 switch (ip->i_df.if_format) {
161 case XFS_DINODE_FMT_EXTENTS:
163 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
165 if ((iip->ili_fields & XFS_ILOG_DEXT) &&
166 ip->i_df.if_nextents > 0 &&
167 ip->i_df.if_bytes > 0) {
168 struct xfs_bmbt_rec *p;
170 ASSERT(xfs_iext_count(&ip->i_df) > 0);
172 p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IEXT);
173 data_bytes = xfs_iextents_copy(ip, p, XFS_DATA_FORK);
174 xlog_finish_iovec(lv, *vecp, data_bytes);
176 ASSERT(data_bytes <= ip->i_df.if_bytes);
178 ilf->ilf_dsize = data_bytes;
181 iip->ili_fields &= ~XFS_ILOG_DEXT;
184 case XFS_DINODE_FMT_BTREE:
186 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | XFS_ILOG_DEV);
188 if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
189 ip->i_df.if_broot_bytes > 0) {
190 ASSERT(ip->i_df.if_broot != NULL);
191 xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IBROOT,
193 ip->i_df.if_broot_bytes);
194 ilf->ilf_dsize = ip->i_df.if_broot_bytes;
197 ASSERT(!(iip->ili_fields &
199 iip->ili_fields &= ~XFS_ILOG_DBROOT;
202 case XFS_DINODE_FMT_LOCAL:
204 ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
205 if ((iip->ili_fields & XFS_ILOG_DDATA) &&
206 ip->i_df.if_bytes > 0) {
208 * Round i_bytes up to a word boundary.
209 * The underlying memory is guaranteed
210 * to be there by xfs_idata_realloc().
212 data_bytes = roundup(ip->i_df.if_bytes, 4);
213 ASSERT(ip->i_df.if_u1.if_data != NULL);
214 ASSERT(ip->i_disk_size > 0);
215 xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_ILOCAL,
216 ip->i_df.if_u1.if_data, data_bytes);
217 ilf->ilf_dsize = (unsigned)data_bytes;
220 iip->ili_fields &= ~XFS_ILOG_DDATA;
223 case XFS_DINODE_FMT_DEV:
225 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEXT);
226 if (iip->ili_fields & XFS_ILOG_DEV)
227 ilf->ilf_u.ilfu_rdev = sysv_encode_dev(VFS_I(ip)->i_rdev);
236 xfs_inode_item_format_attr_fork(
237 struct xfs_inode_log_item *iip,
238 struct xfs_inode_log_format *ilf,
239 struct xfs_log_vec *lv,
240 struct xfs_log_iovec **vecp)
242 struct xfs_inode *ip = iip->ili_inode;
245 switch (ip->i_afp->if_format) {
246 case XFS_DINODE_FMT_EXTENTS:
248 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
250 if ((iip->ili_fields & XFS_ILOG_AEXT) &&
251 ip->i_afp->if_nextents > 0 &&
252 ip->i_afp->if_bytes > 0) {
253 struct xfs_bmbt_rec *p;
255 ASSERT(xfs_iext_count(ip->i_afp) ==
256 ip->i_afp->if_nextents);
258 p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_EXT);
259 data_bytes = xfs_iextents_copy(ip, p, XFS_ATTR_FORK);
260 xlog_finish_iovec(lv, *vecp, data_bytes);
262 ilf->ilf_asize = data_bytes;
265 iip->ili_fields &= ~XFS_ILOG_AEXT;
268 case XFS_DINODE_FMT_BTREE:
270 ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
272 if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
273 ip->i_afp->if_broot_bytes > 0) {
274 ASSERT(ip->i_afp->if_broot != NULL);
276 xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_BROOT,
278 ip->i_afp->if_broot_bytes);
279 ilf->ilf_asize = ip->i_afp->if_broot_bytes;
282 iip->ili_fields &= ~XFS_ILOG_ABROOT;
285 case XFS_DINODE_FMT_LOCAL:
287 ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
289 if ((iip->ili_fields & XFS_ILOG_ADATA) &&
290 ip->i_afp->if_bytes > 0) {
292 * Round i_bytes up to a word boundary.
293 * The underlying memory is guaranteed
294 * to be there by xfs_idata_realloc().
296 data_bytes = roundup(ip->i_afp->if_bytes, 4);
297 ASSERT(ip->i_afp->if_u1.if_data != NULL);
298 xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_LOCAL,
299 ip->i_afp->if_u1.if_data,
301 ilf->ilf_asize = (unsigned)data_bytes;
304 iip->ili_fields &= ~XFS_ILOG_ADATA;
314 * Convert an incore timestamp to a log timestamp. Note that the log format
315 * specifies host endian format!
317 static inline xfs_log_timestamp_t
318 xfs_inode_to_log_dinode_ts(
319 struct xfs_inode *ip,
320 const struct timespec64 tv)
322 struct xfs_log_legacy_timestamp *lits;
323 xfs_log_timestamp_t its;
325 if (xfs_inode_has_bigtime(ip))
326 return xfs_inode_encode_bigtime(tv);
328 lits = (struct xfs_log_legacy_timestamp *)&its;
329 lits->t_sec = tv.tv_sec;
330 lits->t_nsec = tv.tv_nsec;
336 * The legacy DMAPI fields are only present in the on-disk and in-log inodes,
337 * but not in the in-memory one. But we are guaranteed to have an inode buffer
338 * in memory when logging an inode, so we can just copy it from the on-disk
339 * inode to the in-log inode here so that recovery of file system with these
340 * fields set to non-zero values doesn't lose them. For all other cases we zero
344 xfs_copy_dm_fields_to_log_dinode(
345 struct xfs_inode *ip,
346 struct xfs_log_dinode *to)
348 struct xfs_dinode *dip;
350 dip = xfs_buf_offset(ip->i_itemp->ili_item.li_buf,
351 ip->i_imap.im_boffset);
353 if (xfs_iflags_test(ip, XFS_IPRESERVE_DM_FIELDS)) {
354 to->di_dmevmask = be32_to_cpu(dip->di_dmevmask);
355 to->di_dmstate = be16_to_cpu(dip->di_dmstate);
363 xfs_inode_to_log_dinode(
364 struct xfs_inode *ip,
365 struct xfs_log_dinode *to,
368 struct inode *inode = VFS_I(ip);
370 to->di_magic = XFS_DINODE_MAGIC;
371 to->di_format = xfs_ifork_format(&ip->i_df);
372 to->di_uid = i_uid_read(inode);
373 to->di_gid = i_gid_read(inode);
374 to->di_projid_lo = ip->i_projid & 0xffff;
375 to->di_projid_hi = ip->i_projid >> 16;
377 memset(to->di_pad, 0, sizeof(to->di_pad));
378 memset(to->di_pad3, 0, sizeof(to->di_pad3));
379 to->di_atime = xfs_inode_to_log_dinode_ts(ip, inode->i_atime);
380 to->di_mtime = xfs_inode_to_log_dinode_ts(ip, inode->i_mtime);
381 to->di_ctime = xfs_inode_to_log_dinode_ts(ip, inode->i_ctime);
382 to->di_nlink = inode->i_nlink;
383 to->di_gen = inode->i_generation;
384 to->di_mode = inode->i_mode;
386 to->di_size = ip->i_disk_size;
387 to->di_nblocks = ip->i_nblocks;
388 to->di_extsize = ip->i_extsize;
389 to->di_nextents = xfs_ifork_nextents(&ip->i_df);
390 to->di_anextents = xfs_ifork_nextents(ip->i_afp);
391 to->di_forkoff = ip->i_forkoff;
392 to->di_aformat = xfs_ifork_format(ip->i_afp);
393 to->di_flags = ip->i_diflags;
395 xfs_copy_dm_fields_to_log_dinode(ip, to);
397 /* log a dummy value to ensure log structure is fully initialised */
398 to->di_next_unlinked = NULLAGINO;
400 if (xfs_has_v3inodes(ip->i_mount)) {
402 to->di_changecount = inode_peek_iversion(inode);
403 to->di_crtime = xfs_inode_to_log_dinode_ts(ip, ip->i_crtime);
404 to->di_flags2 = ip->i_diflags2;
405 to->di_cowextsize = ip->i_cowextsize;
406 to->di_ino = ip->i_ino;
408 memset(to->di_pad2, 0, sizeof(to->di_pad2));
409 uuid_copy(&to->di_uuid, &ip->i_mount->m_sb.sb_meta_uuid);
410 to->di_flushiter = 0;
413 to->di_flushiter = ip->i_flushiter;
418 * Format the inode core. Current timestamp data is only in the VFS inode
419 * fields, so we need to grab them from there. Hence rather than just copying
420 * the XFS inode core structure, format the fields directly into the iovec.
423 xfs_inode_item_format_core(
424 struct xfs_inode *ip,
425 struct xfs_log_vec *lv,
426 struct xfs_log_iovec **vecp)
428 struct xfs_log_dinode *dic;
430 dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE);
431 xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
432 xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_mount));
436 * This is called to fill in the vector of log iovecs for the given inode
437 * log item. It fills the first item with an inode log format structure,
438 * the second with the on-disk inode structure, and a possible third and/or
439 * fourth with the inode data/extents/b-tree root and inode attributes
440 * data/extents/b-tree root.
442 * Note: Always use the 64 bit inode log format structure so we don't
443 * leave an uninitialised hole in the format item on 64 bit systems. Log
444 * recovery on 32 bit systems handles this just fine, so there's no reason
445 * for not using an initialising the properly padded structure all the time.
448 xfs_inode_item_format(
449 struct xfs_log_item *lip,
450 struct xfs_log_vec *lv)
452 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
453 struct xfs_inode *ip = iip->ili_inode;
454 struct xfs_log_iovec *vecp = NULL;
455 struct xfs_inode_log_format *ilf;
457 ilf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_IFORMAT);
458 ilf->ilf_type = XFS_LI_INODE;
459 ilf->ilf_ino = ip->i_ino;
460 ilf->ilf_blkno = ip->i_imap.im_blkno;
461 ilf->ilf_len = ip->i_imap.im_len;
462 ilf->ilf_boffset = ip->i_imap.im_boffset;
463 ilf->ilf_fields = XFS_ILOG_CORE;
464 ilf->ilf_size = 2; /* format + core */
467 * make sure we don't leak uninitialised data into the log in the case
468 * when we don't log every field in the inode.
473 memset(&ilf->ilf_u, 0, sizeof(ilf->ilf_u));
475 xlog_finish_iovec(lv, vecp, sizeof(*ilf));
477 xfs_inode_item_format_core(ip, lv, &vecp);
478 xfs_inode_item_format_data_fork(iip, ilf, lv, &vecp);
479 if (XFS_IFORK_Q(ip)) {
480 xfs_inode_item_format_attr_fork(iip, ilf, lv, &vecp);
483 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
486 /* update the format with the exact fields we actually logged */
487 ilf->ilf_fields |= (iip->ili_fields & ~XFS_ILOG_TIMESTAMP);
491 * This is called to pin the inode associated with the inode log
492 * item in memory so it cannot be written out.
496 struct xfs_log_item *lip)
498 struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
500 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
503 trace_xfs_inode_pin(ip, _RET_IP_);
504 atomic_inc(&ip->i_pincount);
509 * This is called to unpin the inode associated with the inode log
510 * item which was previously pinned with a call to xfs_inode_item_pin().
512 * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
514 * Note that unpin can race with inode cluster buffer freeing marking the buffer
515 * stale. In that case, flush completions are run from the buffer unpin call,
516 * which may happen before the inode is unpinned. If we lose the race, there
517 * will be no buffer attached to the log item, but the inode will be marked
521 xfs_inode_item_unpin(
522 struct xfs_log_item *lip,
525 struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
527 trace_xfs_inode_unpin(ip, _RET_IP_);
528 ASSERT(lip->li_buf || xfs_iflags_test(ip, XFS_ISTALE));
529 ASSERT(atomic_read(&ip->i_pincount) > 0);
530 if (atomic_dec_and_test(&ip->i_pincount))
531 wake_up_bit(&ip->i_flags, __XFS_IPINNED_BIT);
536 struct xfs_log_item *lip,
537 struct list_head *buffer_list)
538 __releases(&lip->li_ailp->ail_lock)
539 __acquires(&lip->li_ailp->ail_lock)
541 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
542 struct xfs_inode *ip = iip->ili_inode;
543 struct xfs_buf *bp = lip->li_buf;
544 uint rval = XFS_ITEM_SUCCESS;
547 ASSERT(iip->ili_item.li_buf);
549 if (xfs_ipincount(ip) > 0 || xfs_buf_ispinned(bp) ||
550 (ip->i_flags & XFS_ISTALE))
551 return XFS_ITEM_PINNED;
553 if (xfs_iflags_test(ip, XFS_IFLUSHING))
554 return XFS_ITEM_FLUSHING;
556 if (!xfs_buf_trylock(bp))
557 return XFS_ITEM_LOCKED;
559 spin_unlock(&lip->li_ailp->ail_lock);
562 * We need to hold a reference for flushing the cluster buffer as it may
563 * fail the buffer without IO submission. In which case, we better get a
564 * reference for that completion because otherwise we don't get a
565 * reference for IO until we queue the buffer for delwri submission.
568 error = xfs_iflush_cluster(bp);
570 if (!xfs_buf_delwri_queue(bp, buffer_list))
571 rval = XFS_ITEM_FLUSHING;
575 * Release the buffer if we were unable to flush anything. On
576 * any other error, the buffer has already been released.
578 if (error == -EAGAIN)
580 rval = XFS_ITEM_LOCKED;
583 spin_lock(&lip->li_ailp->ail_lock);
588 * Unlock the inode associated with the inode log item.
591 xfs_inode_item_release(
592 struct xfs_log_item *lip)
594 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
595 struct xfs_inode *ip = iip->ili_inode;
596 unsigned short lock_flags;
598 ASSERT(ip->i_itemp != NULL);
599 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
601 lock_flags = iip->ili_lock_flags;
602 iip->ili_lock_flags = 0;
604 xfs_iunlock(ip, lock_flags);
608 * This is called to find out where the oldest active copy of the inode log
609 * item in the on disk log resides now that the last log write of it completed
610 * at the given lsn. Since we always re-log all dirty data in an inode, the
611 * latest copy in the on disk log is the only one that matters. Therefore,
612 * simply return the given lsn.
614 * If the inode has been marked stale because the cluster is being freed, we
615 * don't want to (re-)insert this inode into the AIL. There is a race condition
616 * where the cluster buffer may be unpinned before the inode is inserted into
617 * the AIL during transaction committed processing. If the buffer is unpinned
618 * before the inode item has been committed and inserted, then it is possible
619 * for the buffer to be written and IO completes before the inode is inserted
620 * into the AIL. In that case, we'd be inserting a clean, stale inode into the
621 * AIL which will never get removed. It will, however, get reclaimed which
622 * triggers an assert in xfs_inode_free() complaining about freein an inode
625 * To avoid this, just unpin the inode directly and return a LSN of -1 so the
626 * transaction committed code knows that it does not need to do any further
627 * processing on the item.
630 xfs_inode_item_committed(
631 struct xfs_log_item *lip,
634 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
635 struct xfs_inode *ip = iip->ili_inode;
637 if (xfs_iflags_test(ip, XFS_ISTALE)) {
638 xfs_inode_item_unpin(lip, 0);
645 xfs_inode_item_committing(
646 struct xfs_log_item *lip,
649 INODE_ITEM(lip)->ili_commit_seq = seq;
650 return xfs_inode_item_release(lip);
653 static const struct xfs_item_ops xfs_inode_item_ops = {
654 .iop_size = xfs_inode_item_size,
655 .iop_format = xfs_inode_item_format,
656 .iop_pin = xfs_inode_item_pin,
657 .iop_unpin = xfs_inode_item_unpin,
658 .iop_release = xfs_inode_item_release,
659 .iop_committed = xfs_inode_item_committed,
660 .iop_push = xfs_inode_item_push,
661 .iop_committing = xfs_inode_item_committing,
666 * Initialize the inode log item for a newly allocated (in-core) inode.
670 struct xfs_inode *ip,
671 struct xfs_mount *mp)
673 struct xfs_inode_log_item *iip;
675 ASSERT(ip->i_itemp == NULL);
676 iip = ip->i_itemp = kmem_cache_zalloc(xfs_ili_cache,
677 GFP_KERNEL | __GFP_NOFAIL);
680 spin_lock_init(&iip->ili_lock);
681 xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
682 &xfs_inode_item_ops);
686 * Free the inode log item and any memory hanging off of it.
689 xfs_inode_item_destroy(
690 struct xfs_inode *ip)
692 struct xfs_inode_log_item *iip = ip->i_itemp;
694 ASSERT(iip->ili_item.li_buf == NULL);
697 kmem_free(iip->ili_item.li_lv_shadow);
698 kmem_cache_free(xfs_ili_cache, iip);
703 * We only want to pull the item from the AIL if it is actually there
704 * and its location in the log has not changed since we started the
705 * flush. Thus, we only bother if the inode's lsn has not changed.
708 xfs_iflush_ail_updates(
709 struct xfs_ail *ailp,
710 struct list_head *list)
712 struct xfs_log_item *lip;
713 xfs_lsn_t tail_lsn = 0;
715 /* this is an opencoded batch version of xfs_trans_ail_delete */
716 spin_lock(&ailp->ail_lock);
717 list_for_each_entry(lip, list, li_bio_list) {
720 clear_bit(XFS_LI_FAILED, &lip->li_flags);
721 if (INODE_ITEM(lip)->ili_flush_lsn != lip->li_lsn)
725 * dgc: Not sure how this happens, but it happens very
726 * occassionaly via generic/388. xfs_iflush_abort() also
727 * silently handles this same "under writeback but not in AIL at
728 * shutdown" condition via xfs_trans_ail_delete().
730 if (!test_bit(XFS_LI_IN_AIL, &lip->li_flags)) {
731 ASSERT(xlog_is_shutdown(lip->li_log));
735 lsn = xfs_ail_delete_one(ailp, lip);
736 if (!tail_lsn && lsn)
739 xfs_ail_update_finish(ailp, tail_lsn);
743 * Walk the list of inodes that have completed their IOs. If they are clean
744 * remove them from the list and dissociate them from the buffer. Buffers that
745 * are still dirty remain linked to the buffer and on the list. Caller must
746 * handle them appropriately.
751 struct list_head *list)
753 struct xfs_log_item *lip, *n;
755 list_for_each_entry_safe(lip, n, list, li_bio_list) {
756 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
757 bool drop_buffer = false;
759 spin_lock(&iip->ili_lock);
762 * Remove the reference to the cluster buffer if the inode is
763 * clean in memory and drop the buffer reference once we've
764 * dropped the locks we hold.
766 ASSERT(iip->ili_item.li_buf == bp);
767 if (!iip->ili_fields) {
768 iip->ili_item.li_buf = NULL;
769 list_del_init(&lip->li_bio_list);
772 iip->ili_last_fields = 0;
773 iip->ili_flush_lsn = 0;
774 spin_unlock(&iip->ili_lock);
775 xfs_iflags_clear(iip->ili_inode, XFS_IFLUSHING);
782 * Inode buffer IO completion routine. It is responsible for removing inodes
783 * attached to the buffer from the AIL if they have not been re-logged and
784 * completing the inode flush.
787 xfs_buf_inode_iodone(
790 struct xfs_log_item *lip, *n;
791 LIST_HEAD(flushed_inodes);
792 LIST_HEAD(ail_updates);
795 * Pull the attached inodes from the buffer one at a time and take the
796 * appropriate action on them.
798 list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) {
799 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
801 if (xfs_iflags_test(iip->ili_inode, XFS_ISTALE)) {
802 xfs_iflush_abort(iip->ili_inode);
805 if (!iip->ili_last_fields)
808 /* Do an unlocked check for needing the AIL lock. */
809 if (iip->ili_flush_lsn == lip->li_lsn ||
810 test_bit(XFS_LI_FAILED, &lip->li_flags))
811 list_move_tail(&lip->li_bio_list, &ail_updates);
813 list_move_tail(&lip->li_bio_list, &flushed_inodes);
816 if (!list_empty(&ail_updates)) {
817 xfs_iflush_ail_updates(bp->b_mount->m_ail, &ail_updates);
818 list_splice_tail(&ail_updates, &flushed_inodes);
821 xfs_iflush_finish(bp, &flushed_inodes);
822 if (!list_empty(&flushed_inodes))
823 list_splice_tail(&flushed_inodes, &bp->b_li_list);
827 xfs_buf_inode_io_fail(
830 struct xfs_log_item *lip;
832 list_for_each_entry(lip, &bp->b_li_list, li_bio_list)
833 set_bit(XFS_LI_FAILED, &lip->li_flags);
837 * This is the inode flushing abort routine. It is called when
838 * the filesystem is shutting down to clean up the inode state. It is
839 * responsible for removing the inode item from the AIL if it has not been
840 * re-logged and clearing the inode's flush state.
844 struct xfs_inode *ip)
846 struct xfs_inode_log_item *iip = ip->i_itemp;
847 struct xfs_buf *bp = NULL;
851 * Clear the failed bit before removing the item from the AIL so
852 * xfs_trans_ail_delete() doesn't try to clear and release the
853 * buffer attached to the log item before we are done with it.
855 clear_bit(XFS_LI_FAILED, &iip->ili_item.li_flags);
856 xfs_trans_ail_delete(&iip->ili_item, 0);
859 * Clear the inode logging fields so no more flushes are
862 spin_lock(&iip->ili_lock);
863 iip->ili_last_fields = 0;
865 iip->ili_fsync_fields = 0;
866 iip->ili_flush_lsn = 0;
867 bp = iip->ili_item.li_buf;
868 iip->ili_item.li_buf = NULL;
869 list_del_init(&iip->ili_item.li_bio_list);
870 spin_unlock(&iip->ili_lock);
872 xfs_iflags_clear(ip, XFS_IFLUSHING);
878 * convert an xfs_inode_log_format struct from the old 32 bit version
879 * (which can have different field alignments) to the native 64 bit version
882 xfs_inode_item_format_convert(
883 struct xfs_log_iovec *buf,
884 struct xfs_inode_log_format *in_f)
886 struct xfs_inode_log_format_32 *in_f32 = buf->i_addr;
888 if (buf->i_len != sizeof(*in_f32)) {
889 XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
890 return -EFSCORRUPTED;
893 in_f->ilf_type = in_f32->ilf_type;
894 in_f->ilf_size = in_f32->ilf_size;
895 in_f->ilf_fields = in_f32->ilf_fields;
896 in_f->ilf_asize = in_f32->ilf_asize;
897 in_f->ilf_dsize = in_f32->ilf_dsize;
898 in_f->ilf_ino = in_f32->ilf_ino;
899 memcpy(&in_f->ilf_u, &in_f32->ilf_u, sizeof(in_f->ilf_u));
900 in_f->ilf_blkno = in_f32->ilf_blkno;
901 in_f->ilf_len = in_f32->ilf_len;
902 in_f->ilf_boffset = in_f32->ilf_boffset;