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_types.h"
23 #include "xfs_trans.h"
26 #include "xfs_mount.h"
27 #include "xfs_trans_priv.h"
28 #include "xfs_bmap_btree.h"
29 #include "xfs_dinode.h"
30 #include "xfs_inode.h"
31 #include "xfs_inode_item.h"
32 #include "xfs_error.h"
33 #include "xfs_trace.h"
36 kmem_zone_t
*xfs_ili_zone
; /* inode log item zone */
38 static inline struct xfs_inode_log_item
*INODE_ITEM(struct xfs_log_item
*lip
)
40 return container_of(lip
, struct xfs_inode_log_item
, ili_item
);
45 * This returns the number of iovecs needed to log the given inode item.
47 * We need one iovec for the inode log format structure, one for the
48 * inode core, and possibly one for the inode data/extents/b-tree root
49 * and one for the inode attribute data/extents/b-tree root.
53 struct xfs_log_item
*lip
)
55 struct xfs_inode_log_item
*iip
= INODE_ITEM(lip
);
56 struct xfs_inode
*ip
= iip
->ili_inode
;
59 switch (ip
->i_d
.di_format
) {
60 case XFS_DINODE_FMT_EXTENTS
:
61 if ((iip
->ili_fields
& XFS_ILOG_DEXT
) &&
62 ip
->i_d
.di_nextents
> 0 &&
63 ip
->i_df
.if_bytes
> 0)
67 case XFS_DINODE_FMT_BTREE
:
68 if ((iip
->ili_fields
& XFS_ILOG_DBROOT
) &&
69 ip
->i_df
.if_broot_bytes
> 0)
73 case XFS_DINODE_FMT_LOCAL
:
74 if ((iip
->ili_fields
& XFS_ILOG_DDATA
) &&
75 ip
->i_df
.if_bytes
> 0)
79 case XFS_DINODE_FMT_DEV
:
80 case XFS_DINODE_FMT_UUID
:
93 * Log any necessary attribute data.
95 switch (ip
->i_d
.di_aformat
) {
96 case XFS_DINODE_FMT_EXTENTS
:
97 if ((iip
->ili_fields
& XFS_ILOG_AEXT
) &&
98 ip
->i_d
.di_anextents
> 0 &&
99 ip
->i_afp
->if_bytes
> 0)
103 case XFS_DINODE_FMT_BTREE
:
104 if ((iip
->ili_fields
& XFS_ILOG_ABROOT
) &&
105 ip
->i_afp
->if_broot_bytes
> 0)
109 case XFS_DINODE_FMT_LOCAL
:
110 if ((iip
->ili_fields
& XFS_ILOG_ADATA
) &&
111 ip
->i_afp
->if_bytes
> 0)
124 * xfs_inode_item_format_extents - convert in-core extents to on-disk form
126 * For either the data or attr fork in extent format, we need to endian convert
127 * the in-core extent as we place them into the on-disk inode. In this case, we
128 * need to do this conversion before we write the extents into the log. Because
129 * we don't have the disk inode to write into here, we allocate a buffer and
130 * format the extents into it via xfs_iextents_copy(). We free the buffer in
131 * the unlock routine after the copy for the log has been made.
133 * In the case of the data fork, the in-core and on-disk fork sizes can be
134 * different due to delayed allocation extents. We only log on-disk extents
135 * here, so always use the physical fork size to determine the size of the
136 * buffer we need to allocate.
139 xfs_inode_item_format_extents(
140 struct xfs_inode
*ip
,
141 struct xfs_log_iovec
*vecp
,
145 xfs_bmbt_rec_t
*ext_buffer
;
147 ext_buffer
= kmem_alloc(XFS_IFORK_SIZE(ip
, whichfork
), KM_SLEEP
);
148 if (whichfork
== XFS_DATA_FORK
)
149 ip
->i_itemp
->ili_extents_buf
= ext_buffer
;
151 ip
->i_itemp
->ili_aextents_buf
= ext_buffer
;
153 vecp
->i_addr
= ext_buffer
;
154 vecp
->i_len
= xfs_iextents_copy(ip
, ext_buffer
, whichfork
);
159 * This is called to fill in the vector of log iovecs for the
160 * given inode log item. It fills the first item with an inode
161 * log format structure, the second with the on-disk inode structure,
162 * and a possible third and/or fourth with the inode data/extents/b-tree
163 * root and inode attributes data/extents/b-tree root.
166 xfs_inode_item_format(
167 struct xfs_log_item
*lip
,
168 struct xfs_log_iovec
*vecp
)
170 struct xfs_inode_log_item
*iip
= INODE_ITEM(lip
);
171 struct xfs_inode
*ip
= iip
->ili_inode
;
176 vecp
->i_addr
= &iip
->ili_format
;
177 vecp
->i_len
= sizeof(xfs_inode_log_format_t
);
178 vecp
->i_type
= XLOG_REG_TYPE_IFORMAT
;
182 vecp
->i_addr
= &ip
->i_d
;
183 vecp
->i_len
= sizeof(struct xfs_icdinode
);
184 vecp
->i_type
= XLOG_REG_TYPE_ICORE
;
189 * If this is really an old format inode, then we need to
190 * log it as such. This means that we have to copy the link
191 * count from the new field to the old. We don't have to worry
192 * about the new fields, because nothing trusts them as long as
193 * the old inode version number is there. If the superblock already
194 * has a new version number, then we don't bother converting back.
197 ASSERT(ip
->i_d
.di_version
== 1 || xfs_sb_version_hasnlink(&mp
->m_sb
));
198 if (ip
->i_d
.di_version
== 1) {
199 if (!xfs_sb_version_hasnlink(&mp
->m_sb
)) {
203 ASSERT(ip
->i_d
.di_nlink
<= XFS_MAXLINK_1
);
204 ip
->i_d
.di_onlink
= ip
->i_d
.di_nlink
;
207 * The superblock version has already been bumped,
208 * so just make the conversion to the new inode
211 ip
->i_d
.di_version
= 2;
212 ip
->i_d
.di_onlink
= 0;
213 memset(&(ip
->i_d
.di_pad
[0]), 0, sizeof(ip
->i_d
.di_pad
));
217 switch (ip
->i_d
.di_format
) {
218 case XFS_DINODE_FMT_EXTENTS
:
220 ~(XFS_ILOG_DDATA
| XFS_ILOG_DBROOT
|
221 XFS_ILOG_DEV
| XFS_ILOG_UUID
);
223 if ((iip
->ili_fields
& XFS_ILOG_DEXT
) &&
224 ip
->i_d
.di_nextents
> 0 &&
225 ip
->i_df
.if_bytes
> 0) {
226 ASSERT(ip
->i_df
.if_u1
.if_extents
!= NULL
);
227 ASSERT(ip
->i_df
.if_bytes
/ sizeof(xfs_bmbt_rec_t
) > 0);
228 ASSERT(iip
->ili_extents_buf
== NULL
);
230 #ifdef XFS_NATIVE_HOST
231 if (ip
->i_d
.di_nextents
== ip
->i_df
.if_bytes
/
232 (uint
)sizeof(xfs_bmbt_rec_t
)) {
234 * There are no delayed allocation
235 * extents, so just point to the
236 * real extents array.
238 vecp
->i_addr
= ip
->i_df
.if_u1
.if_extents
;
239 vecp
->i_len
= ip
->i_df
.if_bytes
;
240 vecp
->i_type
= XLOG_REG_TYPE_IEXT
;
244 xfs_inode_item_format_extents(ip
, vecp
,
245 XFS_DATA_FORK
, XLOG_REG_TYPE_IEXT
);
247 ASSERT(vecp
->i_len
<= ip
->i_df
.if_bytes
);
248 iip
->ili_format
.ilf_dsize
= vecp
->i_len
;
252 iip
->ili_fields
&= ~XFS_ILOG_DEXT
;
256 case XFS_DINODE_FMT_BTREE
:
258 ~(XFS_ILOG_DDATA
| XFS_ILOG_DEXT
|
259 XFS_ILOG_DEV
| XFS_ILOG_UUID
);
261 if ((iip
->ili_fields
& XFS_ILOG_DBROOT
) &&
262 ip
->i_df
.if_broot_bytes
> 0) {
263 ASSERT(ip
->i_df
.if_broot
!= NULL
);
264 vecp
->i_addr
= ip
->i_df
.if_broot
;
265 vecp
->i_len
= ip
->i_df
.if_broot_bytes
;
266 vecp
->i_type
= XLOG_REG_TYPE_IBROOT
;
269 iip
->ili_format
.ilf_dsize
= ip
->i_df
.if_broot_bytes
;
271 ASSERT(!(iip
->ili_fields
&
273 #ifdef XFS_TRANS_DEBUG
274 if (iip
->ili_root_size
> 0) {
275 ASSERT(iip
->ili_root_size
==
276 ip
->i_df
.if_broot_bytes
);
277 ASSERT(memcmp(iip
->ili_orig_root
,
279 iip
->ili_root_size
) == 0);
281 ASSERT(ip
->i_df
.if_broot_bytes
== 0);
284 iip
->ili_fields
&= ~XFS_ILOG_DBROOT
;
288 case XFS_DINODE_FMT_LOCAL
:
290 ~(XFS_ILOG_DEXT
| XFS_ILOG_DBROOT
|
291 XFS_ILOG_DEV
| XFS_ILOG_UUID
);
292 if ((iip
->ili_fields
& XFS_ILOG_DDATA
) &&
293 ip
->i_df
.if_bytes
> 0) {
294 ASSERT(ip
->i_df
.if_u1
.if_data
!= NULL
);
295 ASSERT(ip
->i_d
.di_size
> 0);
297 vecp
->i_addr
= ip
->i_df
.if_u1
.if_data
;
299 * Round i_bytes up to a word boundary.
300 * The underlying memory is guaranteed to
301 * to be there by xfs_idata_realloc().
303 data_bytes
= roundup(ip
->i_df
.if_bytes
, 4);
304 ASSERT((ip
->i_df
.if_real_bytes
== 0) ||
305 (ip
->i_df
.if_real_bytes
== data_bytes
));
306 vecp
->i_len
= (int)data_bytes
;
307 vecp
->i_type
= XLOG_REG_TYPE_ILOCAL
;
310 iip
->ili_format
.ilf_dsize
= (unsigned)data_bytes
;
312 iip
->ili_fields
&= ~XFS_ILOG_DDATA
;
316 case XFS_DINODE_FMT_DEV
:
318 ~(XFS_ILOG_DDATA
| XFS_ILOG_DBROOT
|
319 XFS_ILOG_DEXT
| XFS_ILOG_UUID
);
320 if (iip
->ili_fields
& XFS_ILOG_DEV
) {
321 iip
->ili_format
.ilf_u
.ilfu_rdev
=
322 ip
->i_df
.if_u2
.if_rdev
;
326 case XFS_DINODE_FMT_UUID
:
328 ~(XFS_ILOG_DDATA
| XFS_ILOG_DBROOT
|
329 XFS_ILOG_DEXT
| XFS_ILOG_DEV
);
330 if (iip
->ili_fields
& XFS_ILOG_UUID
) {
331 iip
->ili_format
.ilf_u
.ilfu_uuid
=
332 ip
->i_df
.if_u2
.if_uuid
;
342 * If there are no attributes associated with the file, then we're done.
344 if (!XFS_IFORK_Q(ip
)) {
346 ~(XFS_ILOG_ADATA
| XFS_ILOG_ABROOT
| XFS_ILOG_AEXT
);
350 switch (ip
->i_d
.di_aformat
) {
351 case XFS_DINODE_FMT_EXTENTS
:
353 ~(XFS_ILOG_ADATA
| XFS_ILOG_ABROOT
);
355 if ((iip
->ili_fields
& XFS_ILOG_AEXT
) &&
356 ip
->i_d
.di_anextents
> 0 &&
357 ip
->i_afp
->if_bytes
> 0) {
358 ASSERT(ip
->i_afp
->if_bytes
/ sizeof(xfs_bmbt_rec_t
) ==
359 ip
->i_d
.di_anextents
);
360 ASSERT(ip
->i_afp
->if_u1
.if_extents
!= NULL
);
361 #ifdef XFS_NATIVE_HOST
363 * There are not delayed allocation extents
364 * for attributes, so just point at the array.
366 vecp
->i_addr
= ip
->i_afp
->if_u1
.if_extents
;
367 vecp
->i_len
= ip
->i_afp
->if_bytes
;
368 vecp
->i_type
= XLOG_REG_TYPE_IATTR_EXT
;
370 ASSERT(iip
->ili_aextents_buf
== NULL
);
371 xfs_inode_item_format_extents(ip
, vecp
,
372 XFS_ATTR_FORK
, XLOG_REG_TYPE_IATTR_EXT
);
374 iip
->ili_format
.ilf_asize
= vecp
->i_len
;
378 iip
->ili_fields
&= ~XFS_ILOG_AEXT
;
382 case XFS_DINODE_FMT_BTREE
:
384 ~(XFS_ILOG_ADATA
| XFS_ILOG_AEXT
);
386 if ((iip
->ili_fields
& XFS_ILOG_ABROOT
) &&
387 ip
->i_afp
->if_broot_bytes
> 0) {
388 ASSERT(ip
->i_afp
->if_broot
!= NULL
);
390 vecp
->i_addr
= ip
->i_afp
->if_broot
;
391 vecp
->i_len
= ip
->i_afp
->if_broot_bytes
;
392 vecp
->i_type
= XLOG_REG_TYPE_IATTR_BROOT
;
395 iip
->ili_format
.ilf_asize
= ip
->i_afp
->if_broot_bytes
;
397 iip
->ili_fields
&= ~XFS_ILOG_ABROOT
;
401 case XFS_DINODE_FMT_LOCAL
:
403 ~(XFS_ILOG_AEXT
| XFS_ILOG_ABROOT
);
405 if ((iip
->ili_fields
& XFS_ILOG_ADATA
) &&
406 ip
->i_afp
->if_bytes
> 0) {
407 ASSERT(ip
->i_afp
->if_u1
.if_data
!= NULL
);
409 vecp
->i_addr
= ip
->i_afp
->if_u1
.if_data
;
411 * Round i_bytes up to a word boundary.
412 * The underlying memory is guaranteed to
413 * to be there by xfs_idata_realloc().
415 data_bytes
= roundup(ip
->i_afp
->if_bytes
, 4);
416 ASSERT((ip
->i_afp
->if_real_bytes
== 0) ||
417 (ip
->i_afp
->if_real_bytes
== data_bytes
));
418 vecp
->i_len
= (int)data_bytes
;
419 vecp
->i_type
= XLOG_REG_TYPE_IATTR_LOCAL
;
422 iip
->ili_format
.ilf_asize
= (unsigned)data_bytes
;
424 iip
->ili_fields
&= ~XFS_ILOG_ADATA
;
435 * Now update the log format that goes out to disk from the in-core
436 * values. We always write the inode core to make the arithmetic
437 * games in recovery easier, which isn't a big deal as just about any
438 * transaction would dirty it anyway.
440 iip
->ili_format
.ilf_fields
= XFS_ILOG_CORE
|
441 (iip
->ili_fields
& ~XFS_ILOG_TIMESTAMP
);
442 iip
->ili_format
.ilf_size
= nvecs
;
447 * This is called to pin the inode associated with the inode log
448 * item in memory so it cannot be written out.
452 struct xfs_log_item
*lip
)
454 struct xfs_inode
*ip
= INODE_ITEM(lip
)->ili_inode
;
456 ASSERT(xfs_isilocked(ip
, XFS_ILOCK_EXCL
));
458 trace_xfs_inode_pin(ip
, _RET_IP_
);
459 atomic_inc(&ip
->i_pincount
);
464 * This is called to unpin the inode associated with the inode log
465 * item which was previously pinned with a call to xfs_inode_item_pin().
467 * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
470 xfs_inode_item_unpin(
471 struct xfs_log_item
*lip
,
474 struct xfs_inode
*ip
= INODE_ITEM(lip
)->ili_inode
;
476 trace_xfs_inode_unpin(ip
, _RET_IP_
);
477 ASSERT(atomic_read(&ip
->i_pincount
) > 0);
478 if (atomic_dec_and_test(&ip
->i_pincount
))
479 wake_up_bit(&ip
->i_flags
, __XFS_IPINNED_BIT
);
484 struct xfs_log_item
*lip
,
485 struct list_head
*buffer_list
)
487 struct xfs_inode_log_item
*iip
= INODE_ITEM(lip
);
488 struct xfs_inode
*ip
= iip
->ili_inode
;
489 struct xfs_buf
*bp
= NULL
;
490 uint rval
= XFS_ITEM_SUCCESS
;
493 if (xfs_ipincount(ip
) > 0)
494 return XFS_ITEM_PINNED
;
496 if (!xfs_ilock_nowait(ip
, XFS_ILOCK_SHARED
))
497 return XFS_ITEM_LOCKED
;
500 * Re-check the pincount now that we stabilized the value by
503 if (xfs_ipincount(ip
) > 0) {
504 rval
= XFS_ITEM_PINNED
;
509 * Someone else is already flushing the inode. Nothing we can do
510 * here but wait for the flush to finish and remove the item from
513 if (!xfs_iflock_nowait(ip
)) {
514 rval
= XFS_ITEM_FLUSHING
;
519 * Stale inode items should force out the iclog.
521 if (ip
->i_flags
& XFS_ISTALE
) {
523 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
524 return XFS_ITEM_PINNED
;
527 ASSERT(iip
->ili_fields
!= 0 || XFS_FORCED_SHUTDOWN(ip
->i_mount
));
528 ASSERT(iip
->ili_logged
== 0 || XFS_FORCED_SHUTDOWN(ip
->i_mount
));
530 spin_unlock(&lip
->li_ailp
->xa_lock
);
532 error
= xfs_iflush(ip
, &bp
);
534 if (!xfs_buf_delwri_queue(bp
, buffer_list
))
535 rval
= XFS_ITEM_FLUSHING
;
539 spin_lock(&lip
->li_ailp
->xa_lock
);
541 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
546 * Unlock the inode associated with the inode log item.
547 * Clear the fields of the inode and inode log item that
548 * are specific to the current transaction. If the
549 * hold flags is set, do not unlock the inode.
552 xfs_inode_item_unlock(
553 struct xfs_log_item
*lip
)
555 struct xfs_inode_log_item
*iip
= INODE_ITEM(lip
);
556 struct xfs_inode
*ip
= iip
->ili_inode
;
557 unsigned short lock_flags
;
559 ASSERT(ip
->i_itemp
!= NULL
);
560 ASSERT(xfs_isilocked(ip
, XFS_ILOCK_EXCL
));
563 * If the inode needed a separate buffer with which to log
564 * its extents, then free it now.
566 if (iip
->ili_extents_buf
!= NULL
) {
567 ASSERT(ip
->i_d
.di_format
== XFS_DINODE_FMT_EXTENTS
);
568 ASSERT(ip
->i_d
.di_nextents
> 0);
569 ASSERT(iip
->ili_fields
& XFS_ILOG_DEXT
);
570 ASSERT(ip
->i_df
.if_bytes
> 0);
571 kmem_free(iip
->ili_extents_buf
);
572 iip
->ili_extents_buf
= NULL
;
574 if (iip
->ili_aextents_buf
!= NULL
) {
575 ASSERT(ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
);
576 ASSERT(ip
->i_d
.di_anextents
> 0);
577 ASSERT(iip
->ili_fields
& XFS_ILOG_AEXT
);
578 ASSERT(ip
->i_afp
->if_bytes
> 0);
579 kmem_free(iip
->ili_aextents_buf
);
580 iip
->ili_aextents_buf
= NULL
;
583 lock_flags
= iip
->ili_lock_flags
;
584 iip
->ili_lock_flags
= 0;
586 xfs_iunlock(ip
, lock_flags
);
590 * This is called to find out where the oldest active copy of the inode log
591 * item in the on disk log resides now that the last log write of it completed
592 * at the given lsn. Since we always re-log all dirty data in an inode, the
593 * latest copy in the on disk log is the only one that matters. Therefore,
594 * simply return the given lsn.
596 * If the inode has been marked stale because the cluster is being freed, we
597 * don't want to (re-)insert this inode into the AIL. There is a race condition
598 * where the cluster buffer may be unpinned before the inode is inserted into
599 * the AIL during transaction committed processing. If the buffer is unpinned
600 * before the inode item has been committed and inserted, then it is possible
601 * for the buffer to be written and IO completes before the inode is inserted
602 * into the AIL. In that case, we'd be inserting a clean, stale inode into the
603 * AIL which will never get removed. It will, however, get reclaimed which
604 * triggers an assert in xfs_inode_free() complaining about freein an inode
607 * To avoid this, just unpin the inode directly and return a LSN of -1 so the
608 * transaction committed code knows that it does not need to do any further
609 * processing on the item.
612 xfs_inode_item_committed(
613 struct xfs_log_item
*lip
,
616 struct xfs_inode_log_item
*iip
= INODE_ITEM(lip
);
617 struct xfs_inode
*ip
= iip
->ili_inode
;
619 if (xfs_iflags_test(ip
, XFS_ISTALE
)) {
620 xfs_inode_item_unpin(lip
, 0);
627 * XXX rcc - this one really has to do something. Probably needs
628 * to stamp in a new field in the incore inode.
631 xfs_inode_item_committing(
632 struct xfs_log_item
*lip
,
635 INODE_ITEM(lip
)->ili_last_lsn
= lsn
;
639 * This is the ops vector shared by all buf log items.
641 static const struct xfs_item_ops xfs_inode_item_ops
= {
642 .iop_size
= xfs_inode_item_size
,
643 .iop_format
= xfs_inode_item_format
,
644 .iop_pin
= xfs_inode_item_pin
,
645 .iop_unpin
= xfs_inode_item_unpin
,
646 .iop_unlock
= xfs_inode_item_unlock
,
647 .iop_committed
= xfs_inode_item_committed
,
648 .iop_push
= xfs_inode_item_push
,
649 .iop_committing
= xfs_inode_item_committing
654 * Initialize the inode log item for a newly allocated (in-core) inode.
658 struct xfs_inode
*ip
,
659 struct xfs_mount
*mp
)
661 struct xfs_inode_log_item
*iip
;
663 ASSERT(ip
->i_itemp
== NULL
);
664 iip
= ip
->i_itemp
= kmem_zone_zalloc(xfs_ili_zone
, KM_SLEEP
);
667 xfs_log_item_init(mp
, &iip
->ili_item
, XFS_LI_INODE
,
668 &xfs_inode_item_ops
);
669 iip
->ili_format
.ilf_type
= XFS_LI_INODE
;
670 iip
->ili_format
.ilf_ino
= ip
->i_ino
;
671 iip
->ili_format
.ilf_blkno
= ip
->i_imap
.im_blkno
;
672 iip
->ili_format
.ilf_len
= ip
->i_imap
.im_len
;
673 iip
->ili_format
.ilf_boffset
= ip
->i_imap
.im_boffset
;
677 * Free the inode log item and any memory hanging off of it.
680 xfs_inode_item_destroy(
683 #ifdef XFS_TRANS_DEBUG
684 if (ip
->i_itemp
->ili_root_size
!= 0) {
685 kmem_free(ip
->i_itemp
->ili_orig_root
);
688 kmem_zone_free(xfs_ili_zone
, ip
->i_itemp
);
693 * This is the inode flushing I/O completion routine. It is called
694 * from interrupt level when the buffer containing the inode is
695 * flushed to disk. It is responsible for removing the inode item
696 * from the AIL if it has not been re-logged, and unlocking the inode's
699 * To reduce AIL lock traffic as much as possible, we scan the buffer log item
700 * list for other inodes that will run this function. We remove them from the
701 * buffer list so we can process all the inode IO completions in one AIL lock
707 struct xfs_log_item
*lip
)
709 struct xfs_inode_log_item
*iip
;
710 struct xfs_log_item
*blip
;
711 struct xfs_log_item
*next
;
712 struct xfs_log_item
*prev
;
713 struct xfs_ail
*ailp
= lip
->li_ailp
;
717 * Scan the buffer IO completions for other inodes being completed and
718 * attach them to the current inode log item.
722 while (blip
!= NULL
) {
723 if (lip
->li_cb
!= xfs_iflush_done
) {
725 blip
= blip
->li_bio_list
;
729 /* remove from list */
730 next
= blip
->li_bio_list
;
734 prev
->li_bio_list
= next
;
737 /* add to current list */
738 blip
->li_bio_list
= lip
->li_bio_list
;
739 lip
->li_bio_list
= blip
;
742 * while we have the item, do the unlocked check for needing
745 iip
= INODE_ITEM(blip
);
746 if (iip
->ili_logged
&& blip
->li_lsn
== iip
->ili_flush_lsn
)
752 /* make sure we capture the state of the initial inode. */
753 iip
= INODE_ITEM(lip
);
754 if (iip
->ili_logged
&& lip
->li_lsn
== iip
->ili_flush_lsn
)
758 * We only want to pull the item from the AIL if it is
759 * actually there and its location in the log has not
760 * changed since we started the flush. Thus, we only bother
761 * if the ili_logged flag is set and the inode's lsn has not
762 * changed. First we check the lsn outside
763 * the lock since it's cheaper, and then we recheck while
764 * holding the lock before removing the inode from the AIL.
767 struct xfs_log_item
*log_items
[need_ail
];
769 spin_lock(&ailp
->xa_lock
);
770 for (blip
= lip
; blip
; blip
= blip
->li_bio_list
) {
771 iip
= INODE_ITEM(blip
);
772 if (iip
->ili_logged
&&
773 blip
->li_lsn
== iip
->ili_flush_lsn
) {
774 log_items
[i
++] = blip
;
776 ASSERT(i
<= need_ail
);
778 /* xfs_trans_ail_delete_bulk() drops the AIL lock. */
779 xfs_trans_ail_delete_bulk(ailp
, log_items
, i
,
780 SHUTDOWN_CORRUPT_INCORE
);
785 * clean up and unlock the flush lock now we are done. We can clear the
786 * ili_last_fields bits now that we know that the data corresponding to
787 * them is safely on disk.
789 for (blip
= lip
; blip
; blip
= next
) {
790 next
= blip
->li_bio_list
;
791 blip
->li_bio_list
= NULL
;
793 iip
= INODE_ITEM(blip
);
795 iip
->ili_last_fields
= 0;
796 xfs_ifunlock(iip
->ili_inode
);
801 * This is the inode flushing abort routine. It is called from xfs_iflush when
802 * the filesystem is shutting down to clean up the inode state. It is
803 * responsible for removing the inode item from the AIL if it has not been
804 * re-logged, and unlocking the inode's flush lock.
811 xfs_inode_log_item_t
*iip
= ip
->i_itemp
;
814 struct xfs_ail
*ailp
= iip
->ili_item
.li_ailp
;
815 if (iip
->ili_item
.li_flags
& XFS_LI_IN_AIL
) {
816 spin_lock(&ailp
->xa_lock
);
817 if (iip
->ili_item
.li_flags
& XFS_LI_IN_AIL
) {
818 /* xfs_trans_ail_delete() drops the AIL lock. */
819 xfs_trans_ail_delete(ailp
, &iip
->ili_item
,
821 SHUTDOWN_LOG_IO_ERROR
:
822 SHUTDOWN_CORRUPT_INCORE
);
824 spin_unlock(&ailp
->xa_lock
);
828 * Clear the ili_last_fields bits now that we know that the
829 * data corresponding to them is safely on disk.
831 iip
->ili_last_fields
= 0;
833 * Clear the inode logging fields so no more flushes are
839 * Release the inode's flush lock since we're done with it.
847 struct xfs_log_item
*lip
)
849 xfs_iflush_abort(INODE_ITEM(lip
)->ili_inode
, true);
853 * convert an xfs_inode_log_format struct from either 32 or 64 bit versions
854 * (which can have different field alignments) to the native version
857 xfs_inode_item_format_convert(
858 xfs_log_iovec_t
*buf
,
859 xfs_inode_log_format_t
*in_f
)
861 if (buf
->i_len
== sizeof(xfs_inode_log_format_32_t
)) {
862 xfs_inode_log_format_32_t
*in_f32
= buf
->i_addr
;
864 in_f
->ilf_type
= in_f32
->ilf_type
;
865 in_f
->ilf_size
= in_f32
->ilf_size
;
866 in_f
->ilf_fields
= in_f32
->ilf_fields
;
867 in_f
->ilf_asize
= in_f32
->ilf_asize
;
868 in_f
->ilf_dsize
= in_f32
->ilf_dsize
;
869 in_f
->ilf_ino
= in_f32
->ilf_ino
;
870 /* copy biggest field of ilf_u */
871 memcpy(in_f
->ilf_u
.ilfu_uuid
.__u_bits
,
872 in_f32
->ilf_u
.ilfu_uuid
.__u_bits
,
874 in_f
->ilf_blkno
= in_f32
->ilf_blkno
;
875 in_f
->ilf_len
= in_f32
->ilf_len
;
876 in_f
->ilf_boffset
= in_f32
->ilf_boffset
;
878 } else if (buf
->i_len
== sizeof(xfs_inode_log_format_64_t
)){
879 xfs_inode_log_format_64_t
*in_f64
= buf
->i_addr
;
881 in_f
->ilf_type
= in_f64
->ilf_type
;
882 in_f
->ilf_size
= in_f64
->ilf_size
;
883 in_f
->ilf_fields
= in_f64
->ilf_fields
;
884 in_f
->ilf_asize
= in_f64
->ilf_asize
;
885 in_f
->ilf_dsize
= in_f64
->ilf_dsize
;
886 in_f
->ilf_ino
= in_f64
->ilf_ino
;
887 /* copy biggest field of ilf_u */
888 memcpy(in_f
->ilf_u
.ilfu_uuid
.__u_bits
,
889 in_f64
->ilf_u
.ilfu_uuid
.__u_bits
,
891 in_f
->ilf_blkno
= in_f64
->ilf_blkno
;
892 in_f
->ilf_len
= in_f64
->ilf_len
;
893 in_f
->ilf_boffset
= in_f64
->ilf_boffset
;