zfs_log.c revision 104e2ed78d9ef0a0f89f320108b8ca29ca3850d5
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 2006 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 return (0);
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 return (0);
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 return (0);
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 return (0);
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 return (0);
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.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens znode_t *zp, offset_t off, ssize_t len, int ioflag, uio_t *uio)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Writes are handled in three different ways:
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * WR_INDIRECT:
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * If the write is greater than zfs_immediate_write_sz then
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * later *if* we need to log the write then dmu_sync() is used
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * to immediately write the block and it's block pointer is put
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * 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 (char *)itx + offsetof(itx_t, itx_lr) + sizeof (*lr), len);
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * xcopyin shouldn't error as we've already successfully
fa9e4066f08beec538e775443c5be79dd423fcabahrens * copied it to a dmu buffer. However if it does we'll get
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the data from the dmu later.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_truncate() handles TX_TRUNCATE transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_setattr() handles TX_SETATTR transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zfs_log_acl() handles TX_ACL transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + aclcnt * sizeof (ace_t));