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"
24 #include "xfs_trans.h"
25 #include "xfs_buf_item.h"
30 #include "xfs_dmapi.h"
31 #include "xfs_mount.h"
32 #include "xfs_trans_priv.h"
33 #include "xfs_bmap_btree.h"
34 #include "xfs_alloc_btree.h"
35 #include "xfs_ialloc_btree.h"
36 #include "xfs_dir_sf.h"
37 #include "xfs_dir2_sf.h"
38 #include "xfs_attr_sf.h"
39 #include "xfs_dinode.h"
40 #include "xfs_inode.h"
41 #include "xfs_inode_item.h"
42 #include "xfs_btree.h"
43 #include "xfs_ialloc.h"
47 kmem_zone_t *xfs_ili_zone; /* inode log item zone */
50 * This returns the number of iovecs needed to log the given inode item.
52 * We need one iovec for the inode log format structure, one for the
53 * inode core, and possibly one for the inode data/extents/b-tree root
54 * and one for the inode attribute data/extents/b-tree root.
58 xfs_inode_log_item_t *iip)
67 * Only log the data/extents/b-tree root if there is something
70 iip->ili_format.ilf_fields |= XFS_ILOG_CORE;
72 switch (ip->i_d.di_format) {
73 case XFS_DINODE_FMT_EXTENTS:
74 iip->ili_format.ilf_fields &=
75 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
76 XFS_ILOG_DEV | XFS_ILOG_UUID);
77 if ((iip->ili_format.ilf_fields & XFS_ILOG_DEXT) &&
78 (ip->i_d.di_nextents > 0) &&
79 (ip->i_df.if_bytes > 0)) {
80 ASSERT(ip->i_df.if_u1.if_extents != NULL);
83 iip->ili_format.ilf_fields &= ~XFS_ILOG_DEXT;
87 case XFS_DINODE_FMT_BTREE:
88 ASSERT(ip->i_df.if_ext_max ==
89 XFS_IFORK_DSIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t));
90 iip->ili_format.ilf_fields &=
91 ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT |
92 XFS_ILOG_DEV | XFS_ILOG_UUID);
93 if ((iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) &&
94 (ip->i_df.if_broot_bytes > 0)) {
95 ASSERT(ip->i_df.if_broot != NULL);
98 ASSERT(!(iip->ili_format.ilf_fields &
100 #ifdef XFS_TRANS_DEBUG
101 if (iip->ili_root_size > 0) {
102 ASSERT(iip->ili_root_size ==
103 ip->i_df.if_broot_bytes);
104 ASSERT(memcmp(iip->ili_orig_root,
106 iip->ili_root_size) == 0);
108 ASSERT(ip->i_df.if_broot_bytes == 0);
111 iip->ili_format.ilf_fields &= ~XFS_ILOG_DBROOT;
115 case XFS_DINODE_FMT_LOCAL:
116 iip->ili_format.ilf_fields &=
117 ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT |
118 XFS_ILOG_DEV | XFS_ILOG_UUID);
119 if ((iip->ili_format.ilf_fields & XFS_ILOG_DDATA) &&
120 (ip->i_df.if_bytes > 0)) {
121 ASSERT(ip->i_df.if_u1.if_data != NULL);
122 ASSERT(ip->i_d.di_size > 0);
125 iip->ili_format.ilf_fields &= ~XFS_ILOG_DDATA;
129 case XFS_DINODE_FMT_DEV:
130 iip->ili_format.ilf_fields &=
131 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
132 XFS_ILOG_DEXT | XFS_ILOG_UUID);
135 case XFS_DINODE_FMT_UUID:
136 iip->ili_format.ilf_fields &=
137 ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
138 XFS_ILOG_DEXT | XFS_ILOG_DEV);
147 * If there are no attributes associated with this file,
148 * then there cannot be anything more to log.
149 * Clear all attribute-related log flags.
151 if (!XFS_IFORK_Q(ip)) {
152 iip->ili_format.ilf_fields &=
153 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
158 * Log any necessary attribute data.
160 switch (ip->i_d.di_aformat) {
161 case XFS_DINODE_FMT_EXTENTS:
162 iip->ili_format.ilf_fields &=
163 ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
164 if ((iip->ili_format.ilf_fields & XFS_ILOG_AEXT) &&
165 (ip->i_d.di_anextents > 0) &&
166 (ip->i_afp->if_bytes > 0)) {
167 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
170 iip->ili_format.ilf_fields &= ~XFS_ILOG_AEXT;
174 case XFS_DINODE_FMT_BTREE:
175 iip->ili_format.ilf_fields &=
176 ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
177 if ((iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) &&
178 (ip->i_afp->if_broot_bytes > 0)) {
179 ASSERT(ip->i_afp->if_broot != NULL);
182 iip->ili_format.ilf_fields &= ~XFS_ILOG_ABROOT;
186 case XFS_DINODE_FMT_LOCAL:
187 iip->ili_format.ilf_fields &=
188 ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
189 if ((iip->ili_format.ilf_fields & XFS_ILOG_ADATA) &&
190 (ip->i_afp->if_bytes > 0)) {
191 ASSERT(ip->i_afp->if_u1.if_data != NULL);
194 iip->ili_format.ilf_fields &= ~XFS_ILOG_ADATA;
207 * This is called to fill in the vector of log iovecs for the
208 * given inode log item. It fills the first item with an inode
209 * log format structure, the second with the on-disk inode structure,
210 * and a possible third and/or fourth with the inode data/extents/b-tree
211 * root and inode attributes data/extents/b-tree root.
214 xfs_inode_item_format(
215 xfs_inode_log_item_t *iip,
216 xfs_log_iovec_t *log_vector)
219 xfs_log_iovec_t *vecp;
222 xfs_bmbt_rec_t *ext_buffer;
229 vecp->i_addr = (xfs_caddr_t)&iip->ili_format;
230 vecp->i_len = sizeof(xfs_inode_log_format_t);
231 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IFORMAT);
236 * Clear i_update_core if the timestamps (or any other
237 * non-transactional modification) need flushing/logging
238 * and we're about to log them with the rest of the core.
240 * This is the same logic as xfs_iflush() but this code can't
241 * run at the same time as xfs_iflush because we're in commit
242 * processing here and so we have the inode lock held in
243 * exclusive mode. Although it doesn't really matter
244 * for the timestamps if both routines were to grab the
245 * timestamps or not. That would be ok.
247 * We clear i_update_core before copying out the data.
248 * This is for coordination with our timestamp updates
249 * that don't hold the inode lock. They will always
250 * update the timestamps BEFORE setting i_update_core,
251 * so if we clear i_update_core after they set it we
252 * are guaranteed to see their updates to the timestamps
253 * either here. Likewise, if they set it after we clear it
254 * here, we'll see it either on the next commit of this
255 * inode or the next time the inode gets flushed via
256 * xfs_iflush(). This depends on strongly ordered memory
257 * semantics, but we have that. We use the SYNCHRONIZE
258 * macro to make sure that the compiler does not reorder
259 * the i_update_core access below the data copy below.
261 if (ip->i_update_core) {
262 ip->i_update_core = 0;
267 * We don't have to worry about re-ordering here because
268 * the update_size field is protected by the inode lock
269 * and we have that held in exclusive mode.
271 if (ip->i_update_size)
272 ip->i_update_size = 0;
274 vecp->i_addr = (xfs_caddr_t)&ip->i_d;
275 vecp->i_len = sizeof(xfs_dinode_core_t);
276 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_ICORE);
279 iip->ili_format.ilf_fields |= XFS_ILOG_CORE;
282 * If this is really an old format inode, then we need to
283 * log it as such. This means that we have to copy the link
284 * count from the new field to the old. We don't have to worry
285 * about the new fields, because nothing trusts them as long as
286 * the old inode version number is there. If the superblock already
287 * has a new version number, then we don't bother converting back.
290 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1 ||
291 XFS_SB_VERSION_HASNLINK(&mp->m_sb));
292 if (ip->i_d.di_version == XFS_DINODE_VERSION_1) {
293 if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) {
297 ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1);
298 ip->i_d.di_onlink = ip->i_d.di_nlink;
301 * The superblock version has already been bumped,
302 * so just make the conversion to the new inode
305 ip->i_d.di_version = XFS_DINODE_VERSION_2;
306 ip->i_d.di_onlink = 0;
307 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
311 switch (ip->i_d.di_format) {
312 case XFS_DINODE_FMT_EXTENTS:
313 ASSERT(!(iip->ili_format.ilf_fields &
314 (XFS_ILOG_DDATA | XFS_ILOG_DBROOT |
315 XFS_ILOG_DEV | XFS_ILOG_UUID)));
316 if (iip->ili_format.ilf_fields & XFS_ILOG_DEXT) {
317 ASSERT(ip->i_df.if_bytes > 0);
318 ASSERT(ip->i_df.if_u1.if_extents != NULL);
319 ASSERT(ip->i_d.di_nextents > 0);
320 ASSERT(iip->ili_extents_buf == NULL);
321 nrecs = ip->i_df.if_bytes /
322 (uint)sizeof(xfs_bmbt_rec_t);
324 #ifdef XFS_NATIVE_HOST
325 if (nrecs == ip->i_d.di_nextents) {
327 * There are no delayed allocation
328 * extents, so just point to the
329 * real extents array.
332 (char *)(ip->i_df.if_u1.if_extents);
333 vecp->i_len = ip->i_df.if_bytes;
334 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IEXT);
339 * There are delayed allocation extents
340 * in the inode, or we need to convert
341 * the extents to on disk format.
342 * Use xfs_iextents_copy()
343 * to copy only the real extents into
344 * a separate buffer. We'll free the
345 * buffer in the unlock routine.
347 ext_buffer = kmem_alloc(ip->i_df.if_bytes,
349 iip->ili_extents_buf = ext_buffer;
350 vecp->i_addr = (xfs_caddr_t)ext_buffer;
351 vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
353 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IEXT);
355 ASSERT(vecp->i_len <= ip->i_df.if_bytes);
356 iip->ili_format.ilf_dsize = vecp->i_len;
362 case XFS_DINODE_FMT_BTREE:
363 ASSERT(!(iip->ili_format.ilf_fields &
364 (XFS_ILOG_DDATA | XFS_ILOG_DEXT |
365 XFS_ILOG_DEV | XFS_ILOG_UUID)));
366 if (iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) {
367 ASSERT(ip->i_df.if_broot_bytes > 0);
368 ASSERT(ip->i_df.if_broot != NULL);
369 vecp->i_addr = (xfs_caddr_t)ip->i_df.if_broot;
370 vecp->i_len = ip->i_df.if_broot_bytes;
371 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IBROOT);
374 iip->ili_format.ilf_dsize = ip->i_df.if_broot_bytes;
378 case XFS_DINODE_FMT_LOCAL:
379 ASSERT(!(iip->ili_format.ilf_fields &
380 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
381 XFS_ILOG_DEV | XFS_ILOG_UUID)));
382 if (iip->ili_format.ilf_fields & XFS_ILOG_DDATA) {
383 ASSERT(ip->i_df.if_bytes > 0);
384 ASSERT(ip->i_df.if_u1.if_data != NULL);
385 ASSERT(ip->i_d.di_size > 0);
387 vecp->i_addr = (xfs_caddr_t)ip->i_df.if_u1.if_data;
389 * Round i_bytes up to a word boundary.
390 * The underlying memory is guaranteed to
391 * to be there by xfs_idata_realloc().
393 data_bytes = roundup(ip->i_df.if_bytes, 4);
394 ASSERT((ip->i_df.if_real_bytes == 0) ||
395 (ip->i_df.if_real_bytes == data_bytes));
396 vecp->i_len = (int)data_bytes;
397 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_ILOCAL);
400 iip->ili_format.ilf_dsize = (unsigned)data_bytes;
404 case XFS_DINODE_FMT_DEV:
405 ASSERT(!(iip->ili_format.ilf_fields &
406 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
407 XFS_ILOG_DDATA | XFS_ILOG_UUID)));
408 if (iip->ili_format.ilf_fields & XFS_ILOG_DEV) {
409 iip->ili_format.ilf_u.ilfu_rdev =
410 ip->i_df.if_u2.if_rdev;
414 case XFS_DINODE_FMT_UUID:
415 ASSERT(!(iip->ili_format.ilf_fields &
416 (XFS_ILOG_DBROOT | XFS_ILOG_DEXT |
417 XFS_ILOG_DDATA | XFS_ILOG_DEV)));
418 if (iip->ili_format.ilf_fields & XFS_ILOG_UUID) {
419 iip->ili_format.ilf_u.ilfu_uuid =
420 ip->i_df.if_u2.if_uuid;
430 * If there are no attributes associated with the file,
432 * Assert that no attribute-related log flags are set.
434 if (!XFS_IFORK_Q(ip)) {
435 ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
436 iip->ili_format.ilf_size = nvecs;
437 ASSERT(!(iip->ili_format.ilf_fields &
438 (XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
442 switch (ip->i_d.di_aformat) {
443 case XFS_DINODE_FMT_EXTENTS:
444 ASSERT(!(iip->ili_format.ilf_fields &
445 (XFS_ILOG_ADATA | XFS_ILOG_ABROOT)));
446 if (iip->ili_format.ilf_fields & XFS_ILOG_AEXT) {
447 ASSERT(ip->i_afp->if_bytes > 0);
448 ASSERT(ip->i_afp->if_u1.if_extents != NULL);
449 ASSERT(ip->i_d.di_anextents > 0);
451 nrecs = ip->i_afp->if_bytes /
452 (uint)sizeof(xfs_bmbt_rec_t);
455 ASSERT(nrecs == ip->i_d.di_anextents);
456 #ifdef XFS_NATIVE_HOST
458 * There are not delayed allocation extents
459 * for attributes, so just point at the array.
461 vecp->i_addr = (char *)(ip->i_afp->if_u1.if_extents);
462 vecp->i_len = ip->i_afp->if_bytes;
464 ASSERT(iip->ili_aextents_buf == NULL);
466 * Need to endian flip before logging
468 ext_buffer = kmem_alloc(ip->i_afp->if_bytes,
470 iip->ili_aextents_buf = ext_buffer;
471 vecp->i_addr = (xfs_caddr_t)ext_buffer;
472 vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
475 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IATTR_EXT);
476 iip->ili_format.ilf_asize = vecp->i_len;
482 case XFS_DINODE_FMT_BTREE:
483 ASSERT(!(iip->ili_format.ilf_fields &
484 (XFS_ILOG_ADATA | XFS_ILOG_AEXT)));
485 if (iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) {
486 ASSERT(ip->i_afp->if_broot_bytes > 0);
487 ASSERT(ip->i_afp->if_broot != NULL);
488 vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_broot;
489 vecp->i_len = ip->i_afp->if_broot_bytes;
490 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IATTR_BROOT);
493 iip->ili_format.ilf_asize = ip->i_afp->if_broot_bytes;
497 case XFS_DINODE_FMT_LOCAL:
498 ASSERT(!(iip->ili_format.ilf_fields &
499 (XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
500 if (iip->ili_format.ilf_fields & XFS_ILOG_ADATA) {
501 ASSERT(ip->i_afp->if_bytes > 0);
502 ASSERT(ip->i_afp->if_u1.if_data != NULL);
504 vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_u1.if_data;
506 * Round i_bytes up to a word boundary.
507 * The underlying memory is guaranteed to
508 * to be there by xfs_idata_realloc().
510 data_bytes = roundup(ip->i_afp->if_bytes, 4);
511 ASSERT((ip->i_afp->if_real_bytes == 0) ||
512 (ip->i_afp->if_real_bytes == data_bytes));
513 vecp->i_len = (int)data_bytes;
514 XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_IATTR_LOCAL);
517 iip->ili_format.ilf_asize = (unsigned)data_bytes;
526 ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
527 iip->ili_format.ilf_size = nvecs;
532 * This is called to pin the inode associated with the inode log
533 * item in memory so it cannot be written out. Do this by calling
534 * xfs_ipin() to bump the pin count in the inode while holding the
539 xfs_inode_log_item_t *iip)
541 ASSERT(ismrlocked(&(iip->ili_inode->i_lock), MR_UPDATE));
542 xfs_ipin(iip->ili_inode);
547 * This is called to unpin the inode associated with the inode log
548 * item which was previously pinned with a call to xfs_inode_item_pin().
549 * Just call xfs_iunpin() on the inode to do this.
553 xfs_inode_item_unpin(
554 xfs_inode_log_item_t *iip,
557 xfs_iunpin(iip->ili_inode);
562 xfs_inode_item_unpin_remove(
563 xfs_inode_log_item_t *iip,
566 xfs_iunpin(iip->ili_inode);
570 * This is called to attempt to lock the inode associated with this
571 * inode log item, in preparation for the push routine which does the actual
572 * iflush. Don't sleep on the inode lock or the flush lock.
574 * If the flush lock is already held, indicating that the inode has
575 * been or is in the process of being flushed, then (ideally) we'd like to
576 * see if the inode's buffer is still incore, and if so give it a nudge.
577 * We delay doing so until the pushbuf routine, though, to avoid holding
578 * the AIL lock across a call to the blackhole which is the buffercache.
579 * Also we don't want to sleep in any device strategy routines, which can happen
580 * if we do the subsequent bawrite in here.
583 xfs_inode_item_trylock(
584 xfs_inode_log_item_t *iip)
586 register xfs_inode_t *ip;
590 if (xfs_ipincount(ip) > 0) {
591 return XFS_ITEM_PINNED;
594 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
595 return XFS_ITEM_LOCKED;
598 if (!xfs_iflock_nowait(ip)) {
600 * If someone else isn't already trying to push the inode
601 * buffer, we get to do it.
603 if (iip->ili_pushbuf_flag == 0) {
604 iip->ili_pushbuf_flag = 1;
606 iip->ili_push_owner = get_thread_id();
609 * Inode is left locked in shared mode.
610 * Pushbuf routine gets to unlock it.
612 return XFS_ITEM_PUSHBUF;
615 * We hold the AIL_LOCK, so we must specify the
616 * NONOTIFY flag so that we won't double trip.
618 xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
619 return XFS_ITEM_FLUSHING;
624 /* Stale items should force out the iclog */
625 if (ip->i_flags & XFS_ISTALE) {
627 xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
628 return XFS_ITEM_PINNED;
632 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
633 ASSERT(iip->ili_format.ilf_fields != 0);
634 ASSERT(iip->ili_logged == 0);
635 ASSERT(iip->ili_item.li_flags & XFS_LI_IN_AIL);
638 return XFS_ITEM_SUCCESS;
642 * Unlock the inode associated with the inode log item.
643 * Clear the fields of the inode and inode log item that
644 * are specific to the current transaction. If the
645 * hold flags is set, do not unlock the inode.
648 xfs_inode_item_unlock(
649 xfs_inode_log_item_t *iip)
657 ASSERT(iip->ili_inode->i_itemp != NULL);
658 ASSERT(ismrlocked(&(iip->ili_inode->i_lock), MR_UPDATE));
659 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
660 XFS_ILI_IOLOCKED_EXCL)) ||
661 ismrlocked(&(iip->ili_inode->i_iolock), MR_UPDATE));
662 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
663 XFS_ILI_IOLOCKED_SHARED)) ||
664 ismrlocked(&(iip->ili_inode->i_iolock), MR_ACCESS));
666 * Clear the transaction pointer in the inode.
672 * If the inode needed a separate buffer with which to log
673 * its extents, then free it now.
675 if (iip->ili_extents_buf != NULL) {
676 ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS);
677 ASSERT(ip->i_d.di_nextents > 0);
678 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_DEXT);
679 ASSERT(ip->i_df.if_bytes > 0);
680 kmem_free(iip->ili_extents_buf, ip->i_df.if_bytes);
681 iip->ili_extents_buf = NULL;
683 if (iip->ili_aextents_buf != NULL) {
684 ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS);
685 ASSERT(ip->i_d.di_anextents > 0);
686 ASSERT(iip->ili_format.ilf_fields & XFS_ILOG_AEXT);
687 ASSERT(ip->i_afp->if_bytes > 0);
688 kmem_free(iip->ili_aextents_buf, ip->i_afp->if_bytes);
689 iip->ili_aextents_buf = NULL;
693 * Figure out if we should unlock the inode or not.
695 hold = iip->ili_flags & XFS_ILI_HOLD;
698 * Before clearing out the flags, remember whether we
699 * are holding the inode's IO lock.
701 iolocked = iip->ili_flags & XFS_ILI_IOLOCKED_ANY;
704 * Clear out the fields of the inode log item particular
705 * to the current transaction.
707 iip->ili_ilock_recur = 0;
708 iip->ili_iolock_recur = 0;
712 * Unlock the inode if XFS_ILI_HOLD was not set.
715 lock_flags = XFS_ILOCK_EXCL;
716 if (iolocked & XFS_ILI_IOLOCKED_EXCL) {
717 lock_flags |= XFS_IOLOCK_EXCL;
718 } else if (iolocked & XFS_ILI_IOLOCKED_SHARED) {
719 lock_flags |= XFS_IOLOCK_SHARED;
721 xfs_iput(iip->ili_inode, lock_flags);
726 * This is called to find out where the oldest active copy of the
727 * inode log item in the on disk log resides now that the last log
728 * write of it completed at the given lsn. Since we always re-log
729 * all dirty data in an inode, the latest copy in the on disk log
730 * is the only one that matters. Therefore, simply return the
735 xfs_inode_item_committed(
736 xfs_inode_log_item_t *iip,
743 * The transaction with the inode locked has aborted. The inode
744 * must not be dirty within the transaction (unless we're forcibly
745 * shutting down). We simply unlock just as if the transaction
746 * had been cancelled.
749 xfs_inode_item_abort(
750 xfs_inode_log_item_t *iip)
752 xfs_inode_item_unlock(iip);
758 * This gets called by xfs_trans_push_ail(), when IOP_TRYLOCK
759 * failed to get the inode flush lock but did get the inode locked SHARED.
760 * Here we're trying to see if the inode buffer is incore, and if so whether it's
761 * marked delayed write. If that's the case, we'll initiate a bawrite on that
762 * buffer to expedite the process.
764 * We aren't holding the AIL_LOCK (or the flush lock) when this gets called,
765 * so it is inherently race-y.
768 xfs_inode_item_pushbuf(
769 xfs_inode_log_item_t *iip)
778 ASSERT(ismrlocked(&(ip->i_lock), MR_ACCESS));
781 * The ili_pushbuf_flag keeps others from
782 * trying to duplicate our effort.
784 ASSERT(iip->ili_pushbuf_flag != 0);
785 ASSERT(iip->ili_push_owner == get_thread_id());
788 * If flushlock isn't locked anymore, chances are that the
789 * inode flush completed and the inode was taken off the AIL.
792 if ((valusema(&(ip->i_flock)) > 0) ||
793 ((iip->ili_item.li_flags & XFS_LI_IN_AIL) == 0)) {
794 iip->ili_pushbuf_flag = 0;
795 xfs_iunlock(ip, XFS_ILOCK_SHARED);
800 bp = xfs_incore(mp->m_ddev_targp, iip->ili_format.ilf_blkno,
801 iip->ili_format.ilf_len, XFS_INCORE_TRYLOCK);
804 if (XFS_BUF_ISDELAYWRITE(bp)) {
806 * We were racing with iflush because we don't hold
807 * the AIL_LOCK or the flush lock. However, at this point,
808 * we have the buffer, and we know that it's dirty.
809 * So, it's possible that iflush raced with us, and
810 * this item is already taken off the AIL.
811 * If not, we can flush it async.
813 dopush = ((iip->ili_item.li_flags & XFS_LI_IN_AIL) &&
814 (valusema(&(ip->i_flock)) <= 0));
815 iip->ili_pushbuf_flag = 0;
816 xfs_iunlock(ip, XFS_ILOCK_SHARED);
817 xfs_buftrace("INODE ITEM PUSH", bp);
818 if (XFS_BUF_ISPINNED(bp)) {
819 xfs_log_force(mp, (xfs_lsn_t)0,
828 iip->ili_pushbuf_flag = 0;
829 xfs_iunlock(ip, XFS_ILOCK_SHARED);
835 * We have to be careful about resetting pushbuf flag too early (above).
836 * Even though in theory we can do it as soon as we have the buflock,
837 * we don't want others to be doing work needlessly. They'll come to
838 * this function thinking that pushing the buffer is their
839 * responsibility only to find that the buffer is still locked by
840 * another doing the same thing
842 iip->ili_pushbuf_flag = 0;
843 xfs_iunlock(ip, XFS_ILOCK_SHARED);
849 * This is called to asynchronously write the inode associated with this
850 * inode log item out to disk. The inode will already have been locked by
851 * a successful call to xfs_inode_item_trylock().
855 xfs_inode_log_item_t *iip)
861 ASSERT(ismrlocked(&(ip->i_lock), MR_ACCESS));
862 ASSERT(valusema(&(ip->i_flock)) <= 0);
864 * Since we were able to lock the inode's flush lock and
865 * we found it on the AIL, the inode must be dirty. This
866 * is because the inode is removed from the AIL while still
867 * holding the flush lock in xfs_iflush_done(). Thus, if
868 * we found it in the AIL and were able to obtain the flush
869 * lock without sleeping, then there must not have been
870 * anyone in the process of flushing the inode.
872 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) ||
873 iip->ili_format.ilf_fields != 0);
876 * Write out the inode. The completion routine ('iflush_done') will
877 * pull it from the AIL, mark it clean, unlock the flush lock.
879 (void) xfs_iflush(ip, XFS_IFLUSH_ASYNC);
880 xfs_iunlock(ip, XFS_ILOCK_SHARED);
886 * XXX rcc - this one really has to do something. Probably needs
887 * to stamp in a new field in the incore inode.
891 xfs_inode_item_committing(
892 xfs_inode_log_item_t *iip,
895 iip->ili_last_lsn = lsn;
900 * This is the ops vector shared by all buf log items.
902 STATIC struct xfs_item_ops xfs_inode_item_ops = {
903 .iop_size = (uint(*)(xfs_log_item_t*))xfs_inode_item_size,
904 .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
905 xfs_inode_item_format,
906 .iop_pin = (void(*)(xfs_log_item_t*))xfs_inode_item_pin,
907 .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_inode_item_unpin,
908 .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
909 xfs_inode_item_unpin_remove,
910 .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_inode_item_trylock,
911 .iop_unlock = (void(*)(xfs_log_item_t*))xfs_inode_item_unlock,
912 .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
913 xfs_inode_item_committed,
914 .iop_push = (void(*)(xfs_log_item_t*))xfs_inode_item_push,
915 .iop_abort = (void(*)(xfs_log_item_t*))xfs_inode_item_abort,
916 .iop_pushbuf = (void(*)(xfs_log_item_t*))xfs_inode_item_pushbuf,
917 .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
918 xfs_inode_item_committing
923 * Initialize the inode log item for a newly allocated (in-core) inode.
930 xfs_inode_log_item_t *iip;
932 ASSERT(ip->i_itemp == NULL);
933 iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
935 iip->ili_item.li_type = XFS_LI_INODE;
936 iip->ili_item.li_ops = &xfs_inode_item_ops;
937 iip->ili_item.li_mountp = mp;
941 We have zeroed memory. No need ...
942 iip->ili_extents_buf = NULL;
943 iip->ili_pushbuf_flag = 0;
946 iip->ili_format.ilf_type = XFS_LI_INODE;
947 iip->ili_format.ilf_ino = ip->i_ino;
948 iip->ili_format.ilf_blkno = ip->i_blkno;
949 iip->ili_format.ilf_len = ip->i_len;
950 iip->ili_format.ilf_boffset = ip->i_boffset;
954 * Free the inode log item and any memory hanging off of it.
957 xfs_inode_item_destroy(
960 #ifdef XFS_TRANS_DEBUG
961 if (ip->i_itemp->ili_root_size != 0) {
962 kmem_free(ip->i_itemp->ili_orig_root,
963 ip->i_itemp->ili_root_size);
966 kmem_zone_free(xfs_ili_zone, ip->i_itemp);
971 * This is the inode flushing I/O completion routine. It is called
972 * from interrupt level when the buffer containing the inode is
973 * flushed to disk. It is responsible for removing the inode item
974 * from the AIL if it has not been re-logged, and unlocking the inode's
981 xfs_inode_log_item_t *iip)
989 * We only want to pull the item from the AIL if it is
990 * actually there and its location in the log has not
991 * changed since we started the flush. Thus, we only bother
992 * if the ili_logged flag is set and the inode's lsn has not
993 * changed. First we check the lsn outside
994 * the lock since it's cheaper, and then we recheck while
995 * holding the lock before removing the inode from the AIL.
997 if (iip->ili_logged &&
998 (iip->ili_item.li_lsn == iip->ili_flush_lsn)) {
999 AIL_LOCK(ip->i_mount, s);
1000 if (iip->ili_item.li_lsn == iip->ili_flush_lsn) {
1002 * xfs_trans_delete_ail() drops the AIL lock.
1004 xfs_trans_delete_ail(ip->i_mount,
1005 (xfs_log_item_t*)iip, s);
1007 AIL_UNLOCK(ip->i_mount, s);
1011 iip->ili_logged = 0;
1014 * Clear the ili_last_fields bits now that we know that the
1015 * data corresponding to them is safely on disk.
1017 iip->ili_last_fields = 0;
1020 * Release the inode's flush lock since we're done with it.
1028 * This is the inode flushing abort routine. It is called
1029 * from xfs_iflush when the filesystem is shutting down to clean
1030 * up the inode state.
1031 * It is responsible for removing the inode item
1032 * from the AIL if it has not been re-logged, and unlocking the inode's
1039 xfs_inode_log_item_t *iip;
1046 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
1048 if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
1050 * xfs_trans_delete_ail() drops the AIL lock.
1052 xfs_trans_delete_ail(mp, (xfs_log_item_t *)iip,
1057 iip->ili_logged = 0;
1059 * Clear the ili_last_fields bits now that we know that the
1060 * data corresponding to them is safely on disk.
1062 iip->ili_last_fields = 0;
1064 * Clear the inode logging fields so no more flushes are
1067 iip->ili_format.ilf_fields = 0;
1070 * Release the inode's flush lock since we're done with it.
1078 xfs_inode_log_item_t *iip)
1080 xfs_iflush_abort(iip->ili_inode);