zfs_log.c revision 6ce0521ac291be36119f359237066c4fb8088683
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Common Development and Distribution License (the "License").
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * All the functions in this file are used to construct the log entries
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to record transactions. They allocate * a intent log transaction
fa9e4066f08beec538e775443c5be79dd423fcabahrens * structure (itx_t) and save within it all the information necessary to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * possibly replay the transaction. The itx is then assigned a sequence
fa9e4066f08beec538e775443c5be79dd423fcabahrens * number and inserted in the in-memory list anchored in the zilog.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_create() is used to handle TX_CREATE, TX_MKDIR and TX_MKXATTR
fa9e4066f08beec538e775443c5be79dd423fcabahrens * transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_create(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_remove() handles both TX_REMOVE and TX_RMDIR transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_link() handles TX_LINK transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_link(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_symlink() handles TX_SYMLINK transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_rename() handles TX_RENAME transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_write() handles TX_WRITE transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define ZIL_MAX_LOG_DATA (SPA_MAXBLOCKSIZE - sizeof (zil_trailer_t) - \
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens znode_t *zp, offset_t off, ssize_t resid, int ioflag)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Writes are handled in three different ways:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * WR_INDIRECT:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the write is greater than zfs_immediate_write_sz and there are
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * no separate logs in this pool then later *if* we need to log the
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * write then dmu_sync() is used to immediately write the block and
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * its block pointer is put in the log record.
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * WR_COPIED:
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * If we know we'll immediately be committing the
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * transaction (FDSYNC (O_DSYNC)), the we allocate a larger
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * log record here for the data and copy the data in.
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * WR_NEED_COPY:
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Otherwise we don't allocate a buffer, and *if* we need to
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * flush the write later then a buffer is allocated and
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * we retrieve the data using the dmu.
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * If there are slogs and the write would overflow the largest
fa9e4066f08beec538e775443c5be79dd423fcabahrens * block, then because we don't want to use the main pool
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * to dmu_sync, we have to split the write.
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_truncate() handles TX_TRUNCATE transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_setattr() handles TX_SETATTR transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_acl() handles TX_ACL transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + aclcnt * sizeof (ace_t));