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
5002558f6bfef3915c7f3b4ecb7c19c7f044bf5bNeil Perrin * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie * Copyright (c) 2015 by Delphix. All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * These zfs_log_* functions must be called within a dmu tx, in one
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * of 2 contexts depending on zilog->z_replay:
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * Non replay mode
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * ---------------
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * We need to record the transaction so that if it is committed to
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * the Intent Log then it can be replayed. An intent log transaction
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * structure (itx_t) is allocated and all the information necessary to
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * possibly replay the transaction is saved in it. The itx is then assigned
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * a sequence number and inserted in the in-memory list anchored in the zilog.
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * Replay mode
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * -----------
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * We need to mark the intent log record as replayed in the log header.
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * This is done in the same transaction as the replay so that they
1209a471b5681c43d839d4b890f708f500da7346Neil Perrin * commit atomically.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (type) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*NOTREACHED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * build up the log data necessary for logging xvattr_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * First lr_attr_t is initialized. following the lr_attr_t
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is the mapsize and attribute bitmap copied from the xvattr_t.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Following the bitmap and bitmapsize two 64 bit words are reserved
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for the create time which may be set. Following the create time
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * records a single 64 bit integer which has the bits to set on
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * replay for the xvattr.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Now pack the attributes up in a single uint64_t */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* First copy in the ACE FUIDs */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* now copy in the domain info, if any */
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, TX_MKDIR_ATTR and
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * TK_MKXATTR transactions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domain information appended prior to the name. In this case the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * uid/gid in the log record will be a log centric FUID.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * may contain attributes, ACL and optional fuid information.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and ACL and normal users/groups in the ACEs.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * There may be an optional xvattr attribute information similar
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to zfs_log_setattr.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Also, after the file name "domain" strings may be appended.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp,
d5285cae913f4e01ffa0e6693a6d8ef1fbea30baGeorge Wilson size_t aclsize = (vsecp != NULL) ? vsecp->vsa_aclentsz : 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If we have FUIDs present then add in space for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domains and ACE fuid's if any.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Fill in xvattr info if any
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Now fill in any ACL info */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* drop in FUID info */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Now place file name in log record
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles both TX_REMOVE and TX_RMDIR transactions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_LINK transactions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_SYMLINK transactions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs),
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_RENAME transactions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwzfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie 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);
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_WRITE transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie znode_t *zp, offset_t off, ssize_t resid, int ioflag)
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (zil_replaying(zilog, tx) || zp->z_unlinked)
e09fa4dacfb671e707d50a55ae9b5cc191e1b8cbNeil Perrin immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
e09fa4dacfb671e707d50a55ae9b5cc191e1b8cbNeil Perrin if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
ec533521f091387e2911769818ae4be26219fca2fr if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) {
ec533521f091387e2911769818ae4be26219fca2fr (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1));
5f8955b490223718ae28a25ea5894b7affa19b3bNeil Perrin * If the write would overflow the largest block then split it.
5f8955b490223718ae28a25ea5894b7affa19b3bNeil Perrin if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
6ce0521ac291be36119f359237066c4fb8088683perrin if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
7bfdf011e081684f853a3242d0296695110d9d84Neil Perrin zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
5002558f6bfef3915c7f3b4ecb7c19c7f044bf5bNeil Perrin if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_TRUNCATE transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (zil_replaying(zilog, tx) || zp->z_unlinked)
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_SETATTR transactions.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (zil_replaying(zilog, tx) || zp->z_unlinked)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If XVATTR set, then log record size needs to allow
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for lr_attr_t + xvattr mask, mapsize and create time
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * plus actual attribute values
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Now stick on domain information if any on end
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Handles TX_ACL transactions.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (zil_replaying(zilog, tx) || zp->z_unlinked)
31e69ea4bce567a03de57e063cb36ef69af61470marks txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
569e6c63191416b7413c148fd5a6194a0b820b2cmarks ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +