xfs_trans_inode.c 3.5 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
4
 *
5 6
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
L
Linus Torvalds 已提交
7 8
 * published by the Free Software Foundation.
 *
9 10 11 12
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
L
Linus Torvalds 已提交
13
 *
14 15 16
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18
 */
#include "xfs.h"
19
#include "xfs_fs.h"
L
Linus Torvalds 已提交
20 21 22 23 24 25 26
#include "xfs_types.h"
#include "xfs_log.h"
#include "xfs_trans.h"
#include "xfs_sb.h"
#include "xfs_ag.h"
#include "xfs_mount.h"
#include "xfs_bmap_btree.h"
27
#include "xfs_alloc_btree.h"
L
Linus Torvalds 已提交
28 29 30
#include "xfs_ialloc_btree.h"
#include "xfs_dinode.h"
#include "xfs_inode.h"
31 32 33
#include "xfs_btree.h"
#include "xfs_trans_priv.h"
#include "xfs_inode_item.h"
34
#include "xfs_trace.h"
L
Linus Torvalds 已提交
35 36

/*
37 38 39
 * Add a locked inode to the transaction.
 *
 * The inode must be locked, and it cannot be associated with any transaction.
40
 * If lock_flags is non-zero the inode will be unlocked on transaction commit.
L
Linus Torvalds 已提交
41 42 43
 */
void
xfs_trans_ijoin(
44
	struct xfs_trans	*tp,
45 46
	struct xfs_inode	*ip,
	uint			lock_flags)
L
Linus Torvalds 已提交
47 48 49
{
	xfs_inode_log_item_t	*iip;

C
Christoph Hellwig 已提交
50
	ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
L
Linus Torvalds 已提交
51 52 53
	if (ip->i_itemp == NULL)
		xfs_inode_item_init(ip, ip->i_mount);
	iip = ip->i_itemp;
54

55
	ASSERT(iip->ili_lock_flags == 0);
56
	iip->ili_lock_flags = lock_flags;
L
Linus Torvalds 已提交
57 58 59 60

	/*
	 * Get a log_item_desc to point at the new item.
	 */
61
	xfs_trans_add_item(tp, &iip->ili_item);
L
Linus Torvalds 已提交
62 63
}

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/*
 * Transactional inode timestamp update. Requires the inode to be locked and
 * joined to the transaction supplied. Relies on the transaction subsystem to
 * track dirty state and update/writeback the inode accordingly.
 */
void
xfs_trans_ichgtime(
	struct xfs_trans	*tp,
	struct xfs_inode	*ip,
	int			flags)
{
	struct inode		*inode = VFS_I(ip);
	timespec_t		tv;

	ASSERT(tp);
	ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));

	tv = current_fs_time(inode->i_sb);

	if ((flags & XFS_ICHGTIME_MOD) &&
	    !timespec_equal(&inode->i_mtime, &tv)) {
		inode->i_mtime = tv;
C
Christoph Hellwig 已提交
86 87
		ip->i_d.di_mtime.t_sec = tv.tv_sec;
		ip->i_d.di_mtime.t_nsec = tv.tv_nsec;
88 89 90 91
	}
	if ((flags & XFS_ICHGTIME_CHG) &&
	    !timespec_equal(&inode->i_ctime, &tv)) {
		inode->i_ctime = tv;
C
Christoph Hellwig 已提交
92 93
		ip->i_d.di_ctime.t_sec = tv.tv_sec;
		ip->i_d.di_ctime.t_nsec = tv.tv_nsec;
94 95 96
	}
}

L
Linus Torvalds 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/*
 * This is called to mark the fields indicated in fieldmask as needing
 * to be logged when the transaction is committed.  The inode must
 * already be associated with the given transaction.
 *
 * The values for fieldmask are defined in xfs_inode_item.h.  We always
 * log all of the core inode if any of it has changed, and we always log
 * all of the inline data/extents/b-tree root if any of them has changed.
 */
void
xfs_trans_log_inode(
	xfs_trans_t	*tp,
	xfs_inode_t	*ip,
	uint		flags)
{
	ASSERT(ip->i_itemp != NULL);
C
Christoph Hellwig 已提交
113
	ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
L
Linus Torvalds 已提交
114 115

	tp->t_flags |= XFS_TRANS_DIRTY;
116
	ip->i_itemp->ili_item.li_desc->lid_flags |= XFS_LID_DIRTY;
L
Linus Torvalds 已提交
117 118 119 120

	/*
	 * Always OR in the bits from the ili_last_fields field.
	 * This is to coordinate with the xfs_iflush() and xfs_iflush_done()
121
	 * routines in the eventual clearing of the ili_fields bits.
L
Linus Torvalds 已提交
122
	 * See the big comment in xfs_iflush() for an explanation of
123
	 * this coordination mechanism.
L
Linus Torvalds 已提交
124 125
	 */
	flags |= ip->i_itemp->ili_last_fields;
126
	ip->i_itemp->ili_fields |= flags;
L
Linus Torvalds 已提交
127
}