zfs_log.c revision f7170741490edba9d1d9c697c177c887172bc741
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * 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
8f2529de2d60d4fff8eb4d86f71b51584342934eMark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * These zfs_log_* functions must be called within a dmu tx, in one
fa9e4066f08beec538e775443c5be79dd423fcabahrens * of 2 contexts depending on zilog->z_replay:
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin * Non replay mode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ---------------
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum * We need to record the transaction so that if it is committed to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the Intent Log then it can be replayed. An intent log transaction
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * structure (itx_t) is allocated and all the information necessary to
55434c770c89aa1b84474f2559a106803511aba0ek * possibly replay the transaction is saved in it. The itx is then assigned
55434c770c89aa1b84474f2559a106803511aba0ek * a sequence number and inserted in the in-memory list anchored in the zilog.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * Replay mode
55434c770c89aa1b84474f2559a106803511aba0ek * -----------
55434c770c89aa1b84474f2559a106803511aba0ek * We need to mark the intent log record as replayed in the log header.
55434c770c89aa1b84474f2559a106803511aba0ek * This is done in the same transaction as the replay so that they
55434c770c89aa1b84474f2559a106803511aba0ek * commit atomically.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
de8267e0f723ed2c38ea9def92d465f69a300f56timh switch (type) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /*NOTREACHED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens * build up the log data necessary for logging xvattr_t
fa9e4066f08beec538e775443c5be79dd423fcabahrens * First lr_attr_t is initialized. following the lr_attr_t
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is the mapsize and attribute bitmap copied from the xvattr_t.
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * Following the bitmap and bitmapsize two 64 bit words are reserved
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for the create time which may be set. Following the create time
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * records a single 64 bit integer which has the bits to set on
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee * replay for the xvattr.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Now pack the attributes up in a single uint64_t */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeestatic void *
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* First copy in the ACE FUIDs */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeestatic void *
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeezfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* now copy in the domain info, if any */
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum for (zdomain = list_head(&fuidp->z_domains); zdomain;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum zdomain = list_next(&fuidp->z_domains, zdomain)) {
6638ae1dc32acc370fecf2c4ce2e588f1183dd6eMark Shellenbaum * Handles TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, TX_MKDIR_ATTR and
d98a623207262a85cdeec6cc11efd4fcf11514beMark Shellenbaum * TK_MKXATTR transactions.
d98a623207262a85cdeec6cc11efd4fcf11514beMark Shellenbaum * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID
d98a623207262a85cdeec6cc11efd4fcf11514beMark Shellenbaum * domain information appended prior to the name. In this case the
d98a623207262a85cdeec6cc11efd4fcf11514beMark Shellenbaum * uid/gid in the log record will be a log centric FUID.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * may contain attributes, ACL and optional fuid information.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * and ACL and normal users/groups in the ACEs.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * There may be an optional xvattr attribute information similar
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * to zfs_log_setattr.
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Also, after the file name "domain" strings may be appended.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonzfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp,
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee size_t aclsize = (vsecp != NULL) ? vsecp->vsa_aclentsz : 0;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * If we have FUIDs present then add in space for
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * domains and ACE fuid's if any.
4e9583b23260dab68308b306795694143381ab0fTom Erickson if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
4e9583b23260dab68308b306795694143381ab0fTom Erickson (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
4e9583b23260dab68308b306795694143381ab0fTom Erickson txsize = sizeof (*lr) + namesize + fuidsz + xvatsize;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
4e9583b23260dab68308b306795694143381ab0fTom Erickson if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev,
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Fill in xvattr info if any
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson /* Now fill in any ACL info */
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson /* drop in FUID info */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Now place file name in log record
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee * Handles both TX_REMOVE and TX_RMDIR transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Handles TX_LINK transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Handles TX_SYMLINK transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Handles TX_RENAME transactions.
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightzfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t 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 * 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 resid, int ioflag)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1));
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * If the write would overflow the largest block then split it.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum itx = zil_itx_create(txtype, sizeof (*lr) +
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum itx = zil_itx_create(txtype, sizeof (*lr));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Handles TX_TRUNCATE transactions.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarkszfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * Handles TX_SETATTR transactions.
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarkszfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * If XVATTR set, then log record size needs to allow
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * for lr_attr_t + xvattr mask, mapsize and create time
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks * plus actual attribute values
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid))
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid))
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens * Now stick on domain information if any on end
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum * Handles TX_ACL transactions.
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrenszfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum bcopy(vsecp->vsa_aclentp, start, aclbytes);