2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_format.h"
21 #include "xfs_log_format.h"
22 #include "xfs_trans_resv.h"
25 #include "xfs_mount.h"
26 #include "xfs_inode.h"
27 #include "xfs_trans.h"
28 #include "xfs_inode_item.h"
29 #include "xfs_error.h"
30 #include "xfs_trace.h"
31 #include "xfs_trans_priv.h"
32 #include "xfs_dinode.h"
35 kmem_zone_t *xfs_ili_zone; /* inode log item zone */
37 static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip)
39 return container_of(lip, struct xfs_inode_log_item, ili_item);
43 xfs_inode_item_data_fork_size(
44 struct xfs_inode_log_item *iip,
48 struct xfs_inode *ip = iip->ili_inode;
50 switch (ip->i_d.di_format) {
51 case XFS_DINODE_FMT_EXTENTS:
52 if ((iip->ili_fields & XFS_ILOG_DEXT) &&
53 ip->i_d.di_nextents > 0 &&
54 ip->i_df.if_bytes > 0) {
55 /* worst case, doesn't subtract delalloc extents */
56 *nbytes += XFS_IFORK_DSIZE(ip);
60 case XFS_DINODE_FMT_BTREE:
61 if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
62 ip->i_df.if_broot_bytes > 0) {
63 *nbytes += ip->i_df.if_broot_bytes;
67 case XFS_DINODE_FMT_LOCAL:
68 if ((iip->ili_fields & XFS_ILOG_DDATA) &&
69 ip->i_df.if_bytes > 0) {
70 *nbytes += roundup(ip->i_df.if_bytes, 4);
75 case XFS_DINODE_FMT_DEV:
76 case XFS_DINODE_FMT_UUID:
85 xfs_inode_item_attr_fork_size(
86 struct xfs_inode_log_item *iip,
90 struct xfs_inode *ip = iip->ili_inode;
92 switch (ip->i_d.di_aformat) {
93 case XFS_DINODE_FMT_EXTENTS:
94 if ((iip->ili_fields & XFS_ILOG_AEXT) &&
95 ip->i_d.di_anextents > 0 &&
96 ip->i_afp->if_bytes > 0) {
97 /* worst case, doesn't subtract unused space */
98 *nbytes += XFS_IFORK_ASIZE(ip);
102 case XFS_DINODE_FMT_BTREE:
103 if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
104 ip->i_afp->if_broot_bytes > 0) {
105 *nbytes += ip->i_afp->if_broot_bytes;
109 case XFS_DINODE_FMT_LOCAL:
110 if ((iip->ili_fields & XFS_ILOG_ADATA) &&
111 ip->i_afp->if_bytes > 0) {
112 *nbytes += roundup(ip->i_afp->if_bytes, 4);
123 * This returns the number of iovecs needed to log the given inode item.
125 * We need one iovec for the inode log format structure, one for the
126 * inode core, and possibly one for the inode data/extents/b-tree root
127 * and one for the inode attribute data/extents/b-tree root.
131 struct xfs_log_item *lip,
135 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
136 struct xfs_inode *ip = iip->ili_inode;
139 *nbytes += sizeof(struct xfs_inode_log_format) +
140 xfs_icdinode_size(ip->i_d.di_version);
142 xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
144 xfs_inode_item_attr_fork_size(iip, nvecs, nbytes);
148 * xfs_inode_item_format_extents - convert in-core extents to on-disk form
150 * For either the data or attr fork in extent format, we need to endian convert
151 * the in-core extent as we place them into the on-disk inode. In this case, we
152 * need to do this conversion before we write the extents into the log. Because
153 * we don't have the disk inode to write into here, we allocate a buffer and
154 * format the extents into it via xfs_iextents_copy(). We free the buffer in
155 * the unlock routine after the copy for the log has been made.
157 * In the case of the data fork, the in-core and on-disk fork sizes can be
158 * different due to delayed allocation extents. We only log on-disk extents
159 * here, so always use the physical fork size to determine the size of the
160 * buffer we need to allocate.
163 xfs_inode_item_format_extents(
164 struct xfs_inode *ip,
165 struct xfs_log_iovec *vecp,
169 xfs_bmbt_rec_t *ext_buffer;
171 ext_buffer = kmem_alloc(XFS_IFORK_SIZE(ip, whichfork), KM_SLEEP);
172 if (whichfork == XFS_DATA_FORK)
173 ip->i_itemp->ili_extents_buf = ext_buffer;
175 ip->i_itemp->ili_aextents_buf = ext_buffer;
177 vecp->i_addr = ext_buffer;
178 vecp->i_len = xfs_iextents_copy(ip, ext_buffer, whichfork);
183 * If this is a v1 format inode, then we need to log it as such. This means
184 * that we have to copy the link count from the new field to the old. We
185 * don't have to worry about the new fields, because nothing trusts them as
186 * long as the old inode version number is there.
189 xfs_inode_item_format_v1_inode(
190 struct xfs_inode *ip)
192 if (!xfs_sb_version_hasnlink(&ip->i_mount->m_sb)) {
196 ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1);
197 ip->i_d.di_onlink = ip->i_d.di_nlink;
200 * The superblock version has already been bumped,
201 * so just make the conversion to the new inode
204 ip->i_d.di_version = 2;
205 ip->i_d.di_onlink = 0;
206 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
210 STATIC struct xfs_log_iovec *
211 xfs_inode_item_format_data_fork(
212 struct xfs_inode_log_item *iip,
213 struct xfs_log_iovec *vecp,
216 struct xfs_inode *ip = iip->ili_inode;
219 switch (ip->i_d.di_format) {
220 case XFS_DINODE_FMT_EXTENTS:
222 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
223 XFS_ILOG_DEV | XFS_ILOG_UUID);
225 if ((iip->ili_fields & XFS_ILOG_DEXT) &&
226 ip->i_d.di_nextents > 0 &&
227 ip->i_df.if_bytes > 0) {
228 ASSERT(ip->i_df.if_u1.if_extents != NULL);
229 ASSERT(ip->i_df.if_bytes / sizeof(xfs_bmbt_rec_t) > 0);
230 ASSERT(iip->ili_extents_buf == NULL);
232 #ifdef XFS_NATIVE_HOST
233 if (ip->i_d.di_nextents == ip->i_df.if_bytes /
234 (uint)sizeof(xfs_bmbt_rec_t)) {
236 * There are no delayed allocation
237 * extents, so just point to the
238 * real extents array.
240 vecp->i_addr = ip->i_df.if_u1.if_extents;
241 vecp->i_len = ip->i_df.if_bytes;
242 vecp->i_type = XLOG_REG_TYPE_IEXT;
246 xfs_inode_item_format_extents(ip, vecp,
247 XFS_DATA_FORK, XLOG_REG_TYPE_IEXT);
249 ASSERT(vecp->i_len <= ip->i_df.if_bytes);
250 iip->ili_format.ilf_dsize = vecp->i_len;
254 iip->ili_fields &= ~XFS_ILOG_DEXT;
257 case XFS_DINODE_FMT_BTREE:
259 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT |
260 XFS_ILOG_DEV | XFS_ILOG_UUID);
262 if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
263 ip->i_df.if_broot_bytes > 0) {
264 ASSERT(ip->i_df.if_broot != NULL);
265 vecp->i_addr = ip->i_df.if_broot;
266 vecp->i_len = ip->i_df.if_broot_bytes;
267 vecp->i_type = XLOG_REG_TYPE_IBROOT;
270 iip->ili_format.ilf_dsize = ip->i_df.if_broot_bytes;
272 ASSERT(!(iip->ili_fields &
274 iip->ili_fields &= ~XFS_ILOG_DBROOT;
277 case XFS_DINODE_FMT_LOCAL:
279 ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT |
280 XFS_ILOG_DEV | XFS_ILOG_UUID);
281 if ((iip->ili_fields & XFS_ILOG_DDATA) &&
282 ip->i_df.if_bytes > 0) {
283 ASSERT(ip->i_df.if_u1.if_data != NULL);
284 ASSERT(ip->i_d.di_size > 0);
286 vecp->i_addr = ip->i_df.if_u1.if_data;
288 * Round i_bytes up to a word boundary.
289 * The underlying memory is guaranteed to
290 * to be there by xfs_idata_realloc().
292 data_bytes = roundup(ip->i_df.if_bytes, 4);
293 ASSERT((ip->i_df.if_real_bytes == 0) ||
294 (ip->i_df.if_real_bytes == data_bytes));
295 vecp->i_len = (int)data_bytes;
296 vecp->i_type = XLOG_REG_TYPE_ILOCAL;
299 iip->ili_format.ilf_dsize = (unsigned)data_bytes;
301 iip->ili_fields &= ~XFS_ILOG_DDATA;
304 case XFS_DINODE_FMT_DEV:
306 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
307 XFS_ILOG_DEXT | XFS_ILOG_UUID);
308 if (iip->ili_fields & XFS_ILOG_DEV) {
309 iip->ili_format.ilf_u.ilfu_rdev =
310 ip->i_df.if_u2.if_rdev;
313 case XFS_DINODE_FMT_UUID:
315 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
316 XFS_ILOG_DEXT | XFS_ILOG_DEV);
317 if (iip->ili_fields & XFS_ILOG_UUID) {
318 iip->ili_format.ilf_u.ilfu_uuid =
319 ip->i_df.if_u2.if_uuid;
330 STATIC struct xfs_log_iovec *
331 xfs_inode_item_format_attr_fork(
332 struct xfs_inode_log_item *iip,
333 struct xfs_log_iovec *vecp,
336 struct xfs_inode *ip = iip->ili_inode;
339 switch (ip->i_d.di_aformat) {
340 case XFS_DINODE_FMT_EXTENTS:
342 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
344 if ((iip->ili_fields & XFS_ILOG_AEXT) &&
345 ip->i_d.di_anextents > 0 &&
346 ip->i_afp->if_bytes > 0) {
347 ASSERT(ip->i_afp->if_bytes / sizeof(xfs_bmbt_rec_t) ==
348 ip->i_d.di_anextents);
349 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
350 #ifdef XFS_NATIVE_HOST
352 * There are not delayed allocation extents
353 * for attributes, so just point at the array.
355 vecp->i_addr = ip->i_afp->if_u1.if_extents;
356 vecp->i_len = ip->i_afp->if_bytes;
357 vecp->i_type = XLOG_REG_TYPE_IATTR_EXT;
359 ASSERT(iip->ili_aextents_buf == NULL);
360 xfs_inode_item_format_extents(ip, vecp,
361 XFS_ATTR_FORK, XLOG_REG_TYPE_IATTR_EXT);
363 iip->ili_format.ilf_asize = vecp->i_len;
367 iip->ili_fields &= ~XFS_ILOG_AEXT;
370 case XFS_DINODE_FMT_BTREE:
372 ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
374 if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
375 ip->i_afp->if_broot_bytes > 0) {
376 ASSERT(ip->i_afp->if_broot != NULL);
378 vecp->i_addr = ip->i_afp->if_broot;
379 vecp->i_len = ip->i_afp->if_broot_bytes;
380 vecp->i_type = XLOG_REG_TYPE_IATTR_BROOT;
383 iip->ili_format.ilf_asize = ip->i_afp->if_broot_bytes;
385 iip->ili_fields &= ~XFS_ILOG_ABROOT;
388 case XFS_DINODE_FMT_LOCAL:
390 ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
392 if ((iip->ili_fields & XFS_ILOG_ADATA) &&
393 ip->i_afp->if_bytes > 0) {
394 ASSERT(ip->i_afp->if_u1.if_data != NULL);
396 vecp->i_addr = ip->i_afp->if_u1.if_data;
398 * Round i_bytes up to a word boundary.
399 * The underlying memory is guaranteed to
400 * to be there by xfs_idata_realloc().
402 data_bytes = roundup(ip->i_afp->if_bytes, 4);
403 ASSERT((ip->i_afp->if_real_bytes == 0) ||
404 (ip->i_afp->if_real_bytes == data_bytes));
405 vecp->i_len = (int)data_bytes;
406 vecp->i_type = XLOG_REG_TYPE_IATTR_LOCAL;
409 iip->ili_format.ilf_asize = (unsigned)data_bytes;
411 iip->ili_fields &= ~XFS_ILOG_ADATA;
423 * This is called to fill in the vector of log iovecs for the given inode
424 * log item. It fills the first item with an inode log format structure,
425 * the second with the on-disk inode structure, and a possible third and/or
426 * fourth with the inode data/extents/b-tree root and inode attributes
427 * data/extents/b-tree root.
430 xfs_inode_item_format(
431 struct xfs_log_item *lip,
432 struct xfs_log_iovec *vecp)
434 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
435 struct xfs_inode *ip = iip->ili_inode;
438 vecp->i_addr = &iip->ili_format;
439 vecp->i_len = sizeof(xfs_inode_log_format_t);
440 vecp->i_type = XLOG_REG_TYPE_IFORMAT;
444 vecp->i_addr = &ip->i_d;
445 vecp->i_len = xfs_icdinode_size(ip->i_d.di_version);
446 vecp->i_type = XLOG_REG_TYPE_ICORE;
450 if (ip->i_d.di_version == 1)
451 xfs_inode_item_format_v1_inode(ip);
453 vecp = xfs_inode_item_format_data_fork(iip, vecp, &nvecs);
454 if (XFS_IFORK_Q(ip)) {
455 vecp = xfs_inode_item_format_attr_fork(iip, vecp, &nvecs);
458 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
462 * Now update the log format that goes out to disk from the in-core
463 * values. We always write the inode core to make the arithmetic
464 * games in recovery easier, which isn't a big deal as just about any
465 * transaction would dirty it anyway.
467 iip->ili_format.ilf_fields = XFS_ILOG_CORE |
468 (iip->ili_fields & ~XFS_ILOG_TIMESTAMP);
469 iip->ili_format.ilf_size = nvecs;
473 * This is called to pin the inode associated with the inode log
474 * item in memory so it cannot be written out.
478 struct xfs_log_item *lip)
480 struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
482 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
484 trace_xfs_inode_pin(ip, _RET_IP_);
485 atomic_inc(&ip->i_pincount);
490 * This is called to unpin the inode associated with the inode log
491 * item which was previously pinned with a call to xfs_inode_item_pin().
493 * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
496 xfs_inode_item_unpin(
497 struct xfs_log_item *lip,
500 struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
502 trace_xfs_inode_unpin(ip, _RET_IP_);
503 ASSERT(atomic_read(&ip->i_pincount) > 0);
504 if (atomic_dec_and_test(&ip->i_pincount))
505 wake_up_bit(&ip->i_flags, __XFS_IPINNED_BIT);
510 struct xfs_log_item *lip,
511 struct list_head *buffer_list)
513 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
514 struct xfs_inode *ip = iip->ili_inode;
515 struct xfs_buf *bp = NULL;
516 uint rval = XFS_ITEM_SUCCESS;
519 if (xfs_ipincount(ip) > 0)
520 return XFS_ITEM_PINNED;
522 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
523 return XFS_ITEM_LOCKED;
526 * Re-check the pincount now that we stabilized the value by
529 if (xfs_ipincount(ip) > 0) {
530 rval = XFS_ITEM_PINNED;
535 * Stale inode items should force out the iclog.
537 if (ip->i_flags & XFS_ISTALE) {
538 rval = XFS_ITEM_PINNED;
543 * Someone else is already flushing the inode. Nothing we can do
544 * here but wait for the flush to finish and remove the item from
547 if (!xfs_iflock_nowait(ip)) {
548 rval = XFS_ITEM_FLUSHING;
552 ASSERT(iip->ili_fields != 0 || XFS_FORCED_SHUTDOWN(ip->i_mount));
553 ASSERT(iip->ili_logged == 0 || XFS_FORCED_SHUTDOWN(ip->i_mount));
555 spin_unlock(&lip->li_ailp->xa_lock);
557 error = xfs_iflush(ip, &bp);
559 if (!xfs_buf_delwri_queue(bp, buffer_list))
560 rval = XFS_ITEM_FLUSHING;
564 spin_lock(&lip->li_ailp->xa_lock);
566 xfs_iunlock(ip, XFS_ILOCK_SHARED);
571 * Unlock the inode associated with the inode log item.
572 * Clear the fields of the inode and inode log item that
573 * are specific to the current transaction. If the
574 * hold flags is set, do not unlock the inode.
577 xfs_inode_item_unlock(
578 struct xfs_log_item *lip)
580 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
581 struct xfs_inode *ip = iip->ili_inode;
582 unsigned short lock_flags;
584 ASSERT(ip->i_itemp != NULL);
585 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
588 * If the inode needed a separate buffer with which to log
589 * its extents, then free it now.
591 if (iip->ili_extents_buf != NULL) {
592 ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS);
593 ASSERT(ip->i_d.di_nextents > 0);
594 ASSERT(iip->ili_fields & XFS_ILOG_DEXT);
595 ASSERT(ip->i_df.if_bytes > 0);
596 kmem_free(iip->ili_extents_buf);
597 iip->ili_extents_buf = NULL;
599 if (iip->ili_aextents_buf != NULL) {
600 ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS);
601 ASSERT(ip->i_d.di_anextents > 0);
602 ASSERT(iip->ili_fields & XFS_ILOG_AEXT);
603 ASSERT(ip->i_afp->if_bytes > 0);
604 kmem_free(iip->ili_aextents_buf);
605 iip->ili_aextents_buf = NULL;
608 lock_flags = iip->ili_lock_flags;
609 iip->ili_lock_flags = 0;
611 xfs_iunlock(ip, lock_flags);
615 * This is called to find out where the oldest active copy of the inode log
616 * item in the on disk log resides now that the last log write of it completed
617 * at the given lsn. Since we always re-log all dirty data in an inode, the
618 * latest copy in the on disk log is the only one that matters. Therefore,
619 * simply return the given lsn.
621 * If the inode has been marked stale because the cluster is being freed, we
622 * don't want to (re-)insert this inode into the AIL. There is a race condition
623 * where the cluster buffer may be unpinned before the inode is inserted into
624 * the AIL during transaction committed processing. If the buffer is unpinned
625 * before the inode item has been committed and inserted, then it is possible
626 * for the buffer to be written and IO completes before the inode is inserted
627 * into the AIL. In that case, we'd be inserting a clean, stale inode into the
628 * AIL which will never get removed. It will, however, get reclaimed which
629 * triggers an assert in xfs_inode_free() complaining about freein an inode
632 * To avoid this, just unpin the inode directly and return a LSN of -1 so the
633 * transaction committed code knows that it does not need to do any further
634 * processing on the item.
637 xfs_inode_item_committed(
638 struct xfs_log_item *lip,
641 struct xfs_inode_log_item *iip = INODE_ITEM(lip);
642 struct xfs_inode *ip = iip->ili_inode;
644 if (xfs_iflags_test(ip, XFS_ISTALE)) {
645 xfs_inode_item_unpin(lip, 0);
652 * XXX rcc - this one really has to do something. Probably needs
653 * to stamp in a new field in the incore inode.
656 xfs_inode_item_committing(
657 struct xfs_log_item *lip,
660 INODE_ITEM(lip)->ili_last_lsn = lsn;
664 * This is the ops vector shared by all buf log items.
666 static const struct xfs_item_ops xfs_inode_item_ops = {
667 .iop_size = xfs_inode_item_size,
668 .iop_format = xfs_inode_item_format,
669 .iop_pin = xfs_inode_item_pin,
670 .iop_unpin = xfs_inode_item_unpin,
671 .iop_unlock = xfs_inode_item_unlock,
672 .iop_committed = xfs_inode_item_committed,
673 .iop_push = xfs_inode_item_push,
674 .iop_committing = xfs_inode_item_committing
679 * Initialize the inode log item for a newly allocated (in-core) inode.
683 struct xfs_inode *ip,
684 struct xfs_mount *mp)
686 struct xfs_inode_log_item *iip;
688 ASSERT(ip->i_itemp == NULL);
689 iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
692 xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
693 &xfs_inode_item_ops);
694 iip->ili_format.ilf_type = XFS_LI_INODE;
695 iip->ili_format.ilf_ino = ip->i_ino;
696 iip->ili_format.ilf_blkno = ip->i_imap.im_blkno;
697 iip->ili_format.ilf_len = ip->i_imap.im_len;
698 iip->ili_format.ilf_boffset = ip->i_imap.im_boffset;
702 * Free the inode log item and any memory hanging off of it.
705 xfs_inode_item_destroy(
708 kmem_zone_free(xfs_ili_zone, ip->i_itemp);
713 * This is the inode flushing I/O completion routine. It is called
714 * from interrupt level when the buffer containing the inode is
715 * flushed to disk. It is responsible for removing the inode item
716 * from the AIL if it has not been re-logged, and unlocking the inode's
719 * To reduce AIL lock traffic as much as possible, we scan the buffer log item
720 * list for other inodes that will run this function. We remove them from the
721 * buffer list so we can process all the inode IO completions in one AIL lock
727 struct xfs_log_item *lip)
729 struct xfs_inode_log_item *iip;
730 struct xfs_log_item *blip;
731 struct xfs_log_item *next;
732 struct xfs_log_item *prev;
733 struct xfs_ail *ailp = lip->li_ailp;
737 * Scan the buffer IO completions for other inodes being completed and
738 * attach them to the current inode log item.
742 while (blip != NULL) {
743 if (lip->li_cb != xfs_iflush_done) {
745 blip = blip->li_bio_list;
749 /* remove from list */
750 next = blip->li_bio_list;
754 prev->li_bio_list = next;
757 /* add to current list */
758 blip->li_bio_list = lip->li_bio_list;
759 lip->li_bio_list = blip;
762 * while we have the item, do the unlocked check for needing
765 iip = INODE_ITEM(blip);
766 if (iip->ili_logged && blip->li_lsn == iip->ili_flush_lsn)
772 /* make sure we capture the state of the initial inode. */
773 iip = INODE_ITEM(lip);
774 if (iip->ili_logged && lip->li_lsn == iip->ili_flush_lsn)
778 * We only want to pull the item from the AIL if it is
779 * actually there and its location in the log has not
780 * changed since we started the flush. Thus, we only bother
781 * if the ili_logged flag is set and the inode's lsn has not
782 * changed. First we check the lsn outside
783 * the lock since it's cheaper, and then we recheck while
784 * holding the lock before removing the inode from the AIL.
787 struct xfs_log_item *log_items[need_ail];
789 spin_lock(&ailp->xa_lock);
790 for (blip = lip; blip; blip = blip->li_bio_list) {
791 iip = INODE_ITEM(blip);
792 if (iip->ili_logged &&
793 blip->li_lsn == iip->ili_flush_lsn) {
794 log_items[i++] = blip;
796 ASSERT(i <= need_ail);
798 /* xfs_trans_ail_delete_bulk() drops the AIL lock. */
799 xfs_trans_ail_delete_bulk(ailp, log_items, i,
800 SHUTDOWN_CORRUPT_INCORE);
805 * clean up and unlock the flush lock now we are done. We can clear the
806 * ili_last_fields bits now that we know that the data corresponding to
807 * them is safely on disk.
809 for (blip = lip; blip; blip = next) {
810 next = blip->li_bio_list;
811 blip->li_bio_list = NULL;
813 iip = INODE_ITEM(blip);
815 iip->ili_last_fields = 0;
816 xfs_ifunlock(iip->ili_inode);
821 * This is the inode flushing abort routine. It is called from xfs_iflush when
822 * the filesystem is shutting down to clean up the inode state. It is
823 * responsible for removing the inode item from the AIL if it has not been
824 * re-logged, and unlocking the inode's flush lock.
831 xfs_inode_log_item_t *iip = ip->i_itemp;
834 struct xfs_ail *ailp = iip->ili_item.li_ailp;
835 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
836 spin_lock(&ailp->xa_lock);
837 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
838 /* xfs_trans_ail_delete() drops the AIL lock. */
839 xfs_trans_ail_delete(ailp, &iip->ili_item,
841 SHUTDOWN_LOG_IO_ERROR :
842 SHUTDOWN_CORRUPT_INCORE);
844 spin_unlock(&ailp->xa_lock);
848 * Clear the ili_last_fields bits now that we know that the
849 * data corresponding to them is safely on disk.
851 iip->ili_last_fields = 0;
853 * Clear the inode logging fields so no more flushes are
859 * Release the inode's flush lock since we're done with it.
867 struct xfs_log_item *lip)
869 xfs_iflush_abort(INODE_ITEM(lip)->ili_inode, true);
873 * convert an xfs_inode_log_format struct from either 32 or 64 bit versions
874 * (which can have different field alignments) to the native version
877 xfs_inode_item_format_convert(
878 xfs_log_iovec_t *buf,
879 xfs_inode_log_format_t *in_f)
881 if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) {
882 xfs_inode_log_format_32_t *in_f32 = buf->i_addr;
884 in_f->ilf_type = in_f32->ilf_type;
885 in_f->ilf_size = in_f32->ilf_size;
886 in_f->ilf_fields = in_f32->ilf_fields;
887 in_f->ilf_asize = in_f32->ilf_asize;
888 in_f->ilf_dsize = in_f32->ilf_dsize;
889 in_f->ilf_ino = in_f32->ilf_ino;
890 /* copy biggest field of ilf_u */
891 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
892 in_f32->ilf_u.ilfu_uuid.__u_bits,
894 in_f->ilf_blkno = in_f32->ilf_blkno;
895 in_f->ilf_len = in_f32->ilf_len;
896 in_f->ilf_boffset = in_f32->ilf_boffset;
898 } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){
899 xfs_inode_log_format_64_t *in_f64 = buf->i_addr;
901 in_f->ilf_type = in_f64->ilf_type;
902 in_f->ilf_size = in_f64->ilf_size;
903 in_f->ilf_fields = in_f64->ilf_fields;
904 in_f->ilf_asize = in_f64->ilf_asize;
905 in_f->ilf_dsize = in_f64->ilf_dsize;
906 in_f->ilf_ino = in_f64->ilf_ino;
907 /* copy biggest field of ilf_u */
908 memcpy(in_f->ilf_u.ilfu_uuid.__u_bits,
909 in_f64->ilf_u.ilfu_uuid.__u_bits,
911 in_f->ilf_blkno = in_f64->ilf_blkno;
912 in_f->ilf_len = in_f64->ilf_len;
913 in_f->ilf_boffset = in_f64->ilf_boffset;