usr/src/uts/common/fs/zfs/zfs_log.c
author ahrens
Fri, 10 Mar 2006 16:27:46 -0800
changeset 1596 2e2377ccbf85
parent 789 b348f31ed315
child 1669 3521dbbcb2e8
permissions -rw-r--r--
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr 6396359 infinite loop due to dangling dbufs (hang on unmount)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     5
 * Common Development and Distribution License, Version 1.0 only
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     6
 * (the "License").  You may not use this file except in compliance
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 * with the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/systm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/sysmacros.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/thread.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/vfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/zfs_znode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/zfs_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/byteorder.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/mode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/acl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/ddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 * All the functions in this file are used to construct the log entries
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 * to record transactions. They allocate * a intent log transaction
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 * structure (itx_t) and save within it all the information necessary to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 * possibly replay the transaction. The itx is then assigned a sequence
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
 * number and inserted in the in-memory list anchored in the zilog.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * zfs_log_create() is used to handle TX_CREATE, TX_MKDIR and TX_MKXATTR
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
	znode_t *dzp, znode_t *zp, char *name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	lr_create_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	size_t namesize = strlen(name) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
	if (zilog == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	lr = (lr_create_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	lr->lr_doid = dzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	lr->lr_foid = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	lr->lr_mode = zp->z_phys->zp_mode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	lr->lr_uid = zp->z_phys->zp_uid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
	lr->lr_gid = zp->z_phys->zp_gid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
	lr->lr_gen = zp->z_phys->zp_gen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	lr->lr_crtime[0] = zp->z_phys->zp_crtime[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	lr->lr_crtime[1] = zp->z_phys->zp_crtime[1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
	lr->lr_rdev = zp->z_phys->zp_rdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	bcopy(name, (char *)(lr + 1), namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
	dzp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
 * zfs_log_remove() handles both TX_REMOVE and TX_RMDIR transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	znode_t *dzp, char *name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	lr_remove_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	size_t namesize = strlen(name) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	if (zilog == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	lr = (lr_remove_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	lr->lr_doid = dzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	bcopy(name, (char *)(lr + 1), namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	dzp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
 * zfs_log_link() handles TX_LINK transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	znode_t *dzp, znode_t *zp, char *name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	lr_link_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	size_t namesize = strlen(name) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	if (zilog == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
	lr = (lr_link_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
	lr->lr_doid = dzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	lr->lr_link_obj = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
	bcopy(name, (char *)(lr + 1), namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
	dzp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
 * zfs_log_symlink() handles TX_SYMLINK transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	znode_t *dzp, znode_t *zp, char *name, char *link)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
	lr_create_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
	size_t namesize = strlen(name) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
	size_t linksize = strlen(link) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
	if (zilog == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
	lr = (lr_create_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
	lr->lr_doid = dzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
	lr->lr_foid = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
	lr->lr_mode = zp->z_phys->zp_mode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
	lr->lr_uid = zp->z_phys->zp_uid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
	lr->lr_gid = zp->z_phys->zp_gid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
	lr->lr_gen = zp->z_phys->zp_gen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
	lr->lr_crtime[0] = zp->z_phys->zp_crtime[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
	lr->lr_crtime[1] = zp->z_phys->zp_crtime[1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
	bcopy(name, (char *)(lr + 1), namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
	bcopy(link, (char *)(lr + 1) + namesize, linksize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
	dzp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
 * zfs_log_rename() handles TX_RENAME transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
	znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	lr_rename_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	size_t snamesize = strlen(sname) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	size_t dnamesize = strlen(dname) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
	if (zilog == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
	itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
	lr = (lr_rename_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
	lr->lr_sdoid = sdzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
	lr->lr_tdoid = tdzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	bcopy(sname, (char *)(lr + 1), snamesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
	bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
	sdzp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
	tdzp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
	szp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
 * zfs_log_write() handles TX_WRITE transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
 * We store data in the log buffers if it small enough.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
 * Otherwise we flush the data out via dmu_sync().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
ssize_t zfs_immediate_write_sz = 65536;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
	znode_t *zp, offset_t off, ssize_t len, int ioflag, uio_t *uio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
	lr_write_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	int dlen, err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	if (zilog == NULL || zp->z_reap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	dlen = (len <= zfs_immediate_write_sz ? len : 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	itx = zil_itx_create(txtype, sizeof (*lr) + dlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	itx->itx_data_copied = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	if ((ioflag & FDSYNC) && (dlen != 0)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
		err = xcopyin(uio->uio_iov->iov_base - len,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
		    (char *)itx + offsetof(itx_t, itx_lr) +  sizeof (*lr),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
		    len);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
		 * copyin shouldn't fault as we've already successfully
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
		 * copied it to a dmu buffer. However if it does we'll get
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
		 * the data from the dmu later.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
		if (!err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
			itx->itx_data_copied = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
	lr = (lr_write_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	lr->lr_foid = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
	lr->lr_offset = off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	lr->lr_length = len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
	lr->lr_blkoff = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	BP_ZERO(&lr->lr_blkptr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	itx->itx_private = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
 * zfs_log_truncate() handles TX_TRUNCATE transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
	znode_t *zp, uint64_t off, uint64_t len)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
	lr_truncate_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
	if (zilog == NULL || zp->z_reap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	itx = zil_itx_create(txtype, sizeof (*lr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	lr = (lr_truncate_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	lr->lr_foid = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	lr->lr_offset = off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	lr->lr_length = len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
 * zfs_log_setattr() handles TX_SETATTR transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
	znode_t *zp, vattr_t *vap, uint_t mask_applied)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	lr_setattr_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	if (zilog == NULL || zp->z_reap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	itx = zil_itx_create(txtype, sizeof (*lr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
	lr = (lr_setattr_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	lr->lr_foid = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	lr->lr_mask = (uint64_t)mask_applied;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
	lr->lr_mode = (uint64_t)vap->va_mode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	lr->lr_uid = (uint64_t)vap->va_uid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	lr->lr_gid = (uint64_t)vap->va_gid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	lr->lr_size = (uint64_t)vap->va_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
	ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
 * zfs_log_acl() handles TX_ACL transactions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	znode_t *zp, int aclcnt, ace_t *z_ace)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
	lr_acl_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	if (zilog == NULL || zp->z_reap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
	itx = zil_itx_create(txtype, sizeof (*lr) + aclcnt * sizeof (ace_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	lr = (lr_acl_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
	lr->lr_foid = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
	lr->lr_aclcnt = (uint64_t)aclcnt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
	bcopy(z_ace, (ace_t *)(lr + 1), aclcnt * sizeof (ace_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
	seq = zil_itx_assign(zilog, itx, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	zp->z_last_itx = seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
}