1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51669Sperrin * Common Development and Distribution License (the "License"). 61669Sperrin * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 21789Sahrens /* 22*11935SMark.Shellenbaum@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23789Sahrens * Use is subject to license terms. 24789Sahrens */ 25789Sahrens 26789Sahrens #include <sys/types.h> 27789Sahrens #include <sys/param.h> 28789Sahrens #include <sys/systm.h> 29789Sahrens #include <sys/sysmacros.h> 30789Sahrens #include <sys/cmn_err.h> 31789Sahrens #include <sys/kmem.h> 32789Sahrens #include <sys/thread.h> 33789Sahrens #include <sys/file.h> 34789Sahrens #include <sys/vfs.h> 35789Sahrens #include <sys/zfs_znode.h> 36789Sahrens #include <sys/zfs_dir.h> 37789Sahrens #include <sys/zil.h> 384620Sperrin #include <sys/zil_impl.h> 39789Sahrens #include <sys/byteorder.h> 40789Sahrens #include <sys/policy.h> 41789Sahrens #include <sys/stat.h> 42789Sahrens #include <sys/mode.h> 43789Sahrens #include <sys/acl.h> 44789Sahrens #include <sys/dmu.h> 45789Sahrens #include <sys/spa.h> 465331Samw #include <sys/zfs_fuid.h> 47789Sahrens #include <sys/ddi.h> 488227SNeil.Perrin@Sun.COM #include <sys/dsl_dataset.h> 498227SNeil.Perrin@Sun.COM 50789Sahrens /* 518227SNeil.Perrin@Sun.COM * These zfs_log_* functions must be called within a dmu tx, in one 528227SNeil.Perrin@Sun.COM * of 2 contexts depending on zilog->z_replay: 538227SNeil.Perrin@Sun.COM * 548227SNeil.Perrin@Sun.COM * Non replay mode 558227SNeil.Perrin@Sun.COM * --------------- 568227SNeil.Perrin@Sun.COM * We need to record the transaction so that if it is committed to 578227SNeil.Perrin@Sun.COM * the Intent Log then it can be replayed. An intent log transaction 588227SNeil.Perrin@Sun.COM * structure (itx_t) is allocated and all the information necessary to 598227SNeil.Perrin@Sun.COM * possibly replay the transaction is saved in it. The itx is then assigned 608227SNeil.Perrin@Sun.COM * a sequence number and inserted in the in-memory list anchored in the zilog. 618227SNeil.Perrin@Sun.COM * 628227SNeil.Perrin@Sun.COM * Replay mode 638227SNeil.Perrin@Sun.COM * ----------- 648227SNeil.Perrin@Sun.COM * We need to mark the intent log record as replayed in the log header. 658227SNeil.Perrin@Sun.COM * This is done in the same transaction as the replay so that they 668227SNeil.Perrin@Sun.COM * commit atomically. 67789Sahrens */ 68789Sahrens 695331Samw int 705331Samw zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap) 715331Samw { 725331Samw int isxvattr = (vap->va_mask & AT_XVATTR); 735331Samw switch (type) { 745331Samw case Z_FILE: 755331Samw if (vsecp == NULL && !isxvattr) 765331Samw return (TX_CREATE); 775331Samw if (vsecp && isxvattr) 785331Samw return (TX_CREATE_ACL_ATTR); 795331Samw if (vsecp) 805331Samw return (TX_CREATE_ACL); 815331Samw else 825331Samw return (TX_CREATE_ATTR); 835331Samw /*NOTREACHED*/ 845331Samw case Z_DIR: 855331Samw if (vsecp == NULL && !isxvattr) 865331Samw return (TX_MKDIR); 875331Samw if (vsecp && isxvattr) 885331Samw return (TX_MKDIR_ACL_ATTR); 895331Samw if (vsecp) 905331Samw return (TX_MKDIR_ACL); 915331Samw else 925331Samw return (TX_MKDIR_ATTR); 935331Samw case Z_XATTRDIR: 945331Samw return (TX_MKXATTR); 955331Samw } 965331Samw ASSERT(0); 975331Samw return (TX_MAX_TYPE); 985331Samw } 995331Samw 100789Sahrens /* 1015331Samw * build up the log data necessary for logging xvattr_t 1025331Samw * First lr_attr_t is initialized. following the lr_attr_t 1035331Samw * is the mapsize and attribute bitmap copied from the xvattr_t. 1045331Samw * Following the bitmap and bitmapsize two 64 bit words are reserved 1055331Samw * for the create time which may be set. Following the create time 1065331Samw * records a single 64 bit integer which has the bits to set on 1075331Samw * replay for the xvattr. 1085331Samw */ 1095331Samw static void 1105331Samw zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap) 1115331Samw { 1125331Samw uint32_t *bitmap; 1135331Samw uint64_t *attrs; 1145331Samw uint64_t *crtime; 1155331Samw xoptattr_t *xoap; 1165331Samw void *scanstamp; 1175331Samw int i; 1185331Samw 1195331Samw xoap = xva_getxoptattr(xvap); 1205331Samw ASSERT(xoap); 1215331Samw 1225331Samw lrattr->lr_attr_masksize = xvap->xva_mapsize; 1235331Samw bitmap = &lrattr->lr_attr_bitmap; 1245331Samw for (i = 0; i != xvap->xva_mapsize; i++, bitmap++) { 1255331Samw *bitmap = xvap->xva_reqattrmap[i]; 1265331Samw } 1275331Samw 1285331Samw /* Now pack the attributes up in a single uint64_t */ 1295331Samw attrs = (uint64_t *)bitmap; 1305331Samw crtime = attrs + 1; 1315331Samw scanstamp = (caddr_t)(crtime + 2); 1325331Samw *attrs = 0; 1335331Samw if (XVA_ISSET_REQ(xvap, XAT_READONLY)) 1345331Samw *attrs |= (xoap->xoa_readonly == 0) ? 0 : 1355331Samw XAT0_READONLY; 1365331Samw if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) 1375331Samw *attrs |= (xoap->xoa_hidden == 0) ? 0 : 1385331Samw XAT0_HIDDEN; 1395331Samw if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) 1405331Samw *attrs |= (xoap->xoa_system == 0) ? 0 : 1415331Samw XAT0_SYSTEM; 1425331Samw if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) 1435331Samw *attrs |= (xoap->xoa_archive == 0) ? 0 : 1445331Samw XAT0_ARCHIVE; 1455331Samw if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) 1465331Samw *attrs |= (xoap->xoa_immutable == 0) ? 0 : 1475331Samw XAT0_IMMUTABLE; 1485331Samw if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) 1495331Samw *attrs |= (xoap->xoa_nounlink == 0) ? 0 : 1505331Samw XAT0_NOUNLINK; 1515331Samw if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) 1525331Samw *attrs |= (xoap->xoa_appendonly == 0) ? 0 : 1535331Samw XAT0_APPENDONLY; 1545331Samw if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) 1555331Samw *attrs |= (xoap->xoa_opaque == 0) ? 0 : 1565331Samw XAT0_APPENDONLY; 1575331Samw if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) 1585331Samw *attrs |= (xoap->xoa_nodump == 0) ? 0 : 1595331Samw XAT0_NODUMP; 1605331Samw if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) 1615331Samw *attrs |= (xoap->xoa_av_quarantined == 0) ? 0 : 1625331Samw XAT0_AV_QUARANTINED; 1635331Samw if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) 1645331Samw *attrs |= (xoap->xoa_av_modified == 0) ? 0 : 1655331Samw XAT0_AV_MODIFIED; 1665331Samw if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) 1675331Samw ZFS_TIME_ENCODE(&xoap->xoa_createtime, crtime); 1685331Samw if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) 1695331Samw bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ); 17010793Sdai.ngo@sun.com if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) 17110793Sdai.ngo@sun.com *attrs |= (xoap->xoa_reparse == 0) ? 0 : 17210793Sdai.ngo@sun.com XAT0_REPARSE; 1735331Samw } 1745331Samw 1755331Samw static void * 1765331Samw zfs_log_fuid_ids(zfs_fuid_info_t *fuidp, void *start) 1775331Samw { 1785331Samw zfs_fuid_t *zfuid; 1795331Samw uint64_t *fuidloc = start; 1805331Samw 1815331Samw /* First copy in the ACE FUIDs */ 1825331Samw for (zfuid = list_head(&fuidp->z_fuids); zfuid; 1835331Samw zfuid = list_next(&fuidp->z_fuids, zfuid)) { 1845331Samw *fuidloc++ = zfuid->z_logfuid; 1855331Samw } 1865331Samw return (fuidloc); 1875331Samw } 1885331Samw 1895331Samw 1905331Samw static void * 1915331Samw zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start) 1925331Samw { 1935331Samw zfs_fuid_domain_t *zdomain; 1945331Samw 1955331Samw /* now copy in the domain info, if any */ 1965331Samw if (fuidp->z_domain_str_sz != 0) { 1975331Samw for (zdomain = list_head(&fuidp->z_domains); zdomain; 1985331Samw zdomain = list_next(&fuidp->z_domains, zdomain)) { 1995331Samw bcopy((void *)zdomain->z_domain, start, 2005331Samw strlen(zdomain->z_domain) + 1); 2015331Samw start = (caddr_t)start + 2025331Samw strlen(zdomain->z_domain) + 1; 2035331Samw } 2045331Samw } 2055331Samw return (start); 2065331Samw } 2075331Samw 2085331Samw /* 2095331Samw * zfs_log_create() is used to handle TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, 2105331Samw * TX_MKDIR_ATTR and TX_MKXATTR 211789Sahrens * transactions. 2125331Samw * 2135331Samw * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID 2145331Samw * domain information appended prior to the name. In this case the 2155331Samw * uid/gid in the log record will be a log centric FUID. 2165331Samw * 2175331Samw * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that 2185331Samw * may contain attributes, ACL and optional fuid information. 2195331Samw * 2205331Samw * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify 2215331Samw * and ACL and normal users/groups in the ACEs. 2225331Samw * 2235331Samw * There may be an optional xvattr attribute information similar 2245331Samw * to zfs_log_setattr. 2255331Samw * 2265331Samw * Also, after the file name "domain" strings may be appended. 227789Sahrens */ 2282638Sperrin void 2295331Samw zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 2305331Samw znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp, 2315331Samw zfs_fuid_info_t *fuidp, vattr_t *vap) 232789Sahrens { 233789Sahrens itx_t *itx; 234789Sahrens uint64_t seq; 235789Sahrens lr_create_t *lr; 2365331Samw lr_acl_create_t *lracl; 2375331Samw size_t aclsize; 2385331Samw size_t xvatsize = 0; 2395331Samw size_t txsize; 2405331Samw xvattr_t *xvap = (xvattr_t *)vap; 2415331Samw void *end; 2425331Samw size_t lrsize; 243789Sahrens size_t namesize = strlen(name) + 1; 2445331Samw size_t fuidsz = 0; 245789Sahrens 24610922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx)) 2472638Sperrin return; 248789Sahrens 2495331Samw /* 2505331Samw * If we have FUIDs present then add in space for 2515331Samw * domains and ACE fuid's if any. 2525331Samw */ 2535331Samw if (fuidp) { 2545331Samw fuidsz += fuidp->z_domain_str_sz; 2555331Samw fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t); 2565331Samw } 2575331Samw 2585331Samw if (vap->va_mask & AT_XVATTR) 2595331Samw xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize); 2605331Samw 2615331Samw if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR || 2625331Samw (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR || 2635331Samw (int)txtype == TX_MKXATTR) { 2645331Samw txsize = sizeof (*lr) + namesize + fuidsz + xvatsize; 2655331Samw lrsize = sizeof (*lr); 2665331Samw } else { 2675331Samw aclsize = (vsecp) ? vsecp->vsa_aclentsz : 0; 2685331Samw txsize = 2695331Samw sizeof (lr_acl_create_t) + namesize + fuidsz + 2705435Smarks ZIL_ACE_LENGTH(aclsize) + xvatsize; 2715331Samw lrsize = sizeof (lr_acl_create_t); 2725331Samw } 2735331Samw 2745331Samw itx = zil_itx_create(txtype, txsize); 2755331Samw 276789Sahrens lr = (lr_create_t *)&itx->itx_lr; 277789Sahrens lr->lr_doid = dzp->z_id; 278789Sahrens lr->lr_foid = zp->z_id; 279*11935SMark.Shellenbaum@Sun.COM lr->lr_mode = zp->z_mode; 280*11935SMark.Shellenbaum@Sun.COM if (!IS_EPHEMERAL(zp->z_uid)) { 281*11935SMark.Shellenbaum@Sun.COM lr->lr_uid = (uint64_t)zp->z_uid; 2825331Samw } else { 2835331Samw lr->lr_uid = fuidp->z_fuid_owner; 2845331Samw } 285*11935SMark.Shellenbaum@Sun.COM if (!IS_EPHEMERAL(zp->z_gid)) { 286*11935SMark.Shellenbaum@Sun.COM lr->lr_gid = (uint64_t)zp->z_gid; 2875331Samw } else { 2885331Samw lr->lr_gid = fuidp->z_fuid_group; 2895331Samw } 290*11935SMark.Shellenbaum@Sun.COM (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen, 291*11935SMark.Shellenbaum@Sun.COM sizeof (uint64_t)); 292*11935SMark.Shellenbaum@Sun.COM (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs), 293*11935SMark.Shellenbaum@Sun.COM lr->lr_crtime, sizeof (uint64_t) * 2); 294*11935SMark.Shellenbaum@Sun.COM 295*11935SMark.Shellenbaum@Sun.COM if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev, 296*11935SMark.Shellenbaum@Sun.COM sizeof (lr->lr_rdev)) != 0) 297*11935SMark.Shellenbaum@Sun.COM lr->lr_rdev = 0; 2985331Samw 2995331Samw /* 3005331Samw * Fill in xvattr info if any 3015331Samw */ 3025331Samw if (vap->va_mask & AT_XVATTR) { 3035331Samw zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap); 3045331Samw end = (caddr_t)lr + lrsize + xvatsize; 3055331Samw } else { 3065331Samw end = (caddr_t)lr + lrsize; 3075331Samw } 3085331Samw 3095331Samw /* Now fill in any ACL info */ 3105331Samw 3115331Samw if (vsecp) { 3125331Samw lracl = (lr_acl_create_t *)&itx->itx_lr; 3135331Samw lracl->lr_aclcnt = vsecp->vsa_aclcnt; 3145331Samw lracl->lr_acl_bytes = aclsize; 3155331Samw lracl->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0; 3165331Samw lracl->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0; 3175331Samw if (vsecp->vsa_aclflags & VSA_ACE_ACLFLAGS) 3185331Samw lracl->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags; 3195331Samw else 3205331Samw lracl->lr_acl_flags = 0; 3215331Samw 3225331Samw bcopy(vsecp->vsa_aclentp, end, aclsize); 3235435Smarks end = (caddr_t)end + ZIL_ACE_LENGTH(aclsize); 3245331Samw } 3255331Samw 3265331Samw /* drop in FUID info */ 3275331Samw if (fuidp) { 3285331Samw end = zfs_log_fuid_ids(fuidp, end); 3295331Samw end = zfs_log_fuid_domains(fuidp, end); 3305331Samw } 3315331Samw /* 3325331Samw * Now place file name in log record 3335331Samw */ 3345331Samw bcopy(name, end, namesize); 335789Sahrens 336789Sahrens seq = zil_itx_assign(zilog, itx, tx); 337789Sahrens dzp->z_last_itx = seq; 338789Sahrens zp->z_last_itx = seq; 339789Sahrens } 340789Sahrens 341789Sahrens /* 342789Sahrens * zfs_log_remove() handles both TX_REMOVE and TX_RMDIR transactions. 343789Sahrens */ 3442638Sperrin void 3455331Samw zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 346789Sahrens znode_t *dzp, char *name) 347789Sahrens { 348789Sahrens itx_t *itx; 349789Sahrens uint64_t seq; 350789Sahrens lr_remove_t *lr; 351789Sahrens size_t namesize = strlen(name) + 1; 352789Sahrens 35310922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx)) 3542638Sperrin return; 355789Sahrens 356789Sahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize); 357789Sahrens lr = (lr_remove_t *)&itx->itx_lr; 358789Sahrens lr->lr_doid = dzp->z_id; 359789Sahrens bcopy(name, (char *)(lr + 1), namesize); 360789Sahrens 361789Sahrens seq = zil_itx_assign(zilog, itx, tx); 362789Sahrens dzp->z_last_itx = seq; 363789Sahrens } 364789Sahrens 365789Sahrens /* 366789Sahrens * zfs_log_link() handles TX_LINK transactions. 367789Sahrens */ 3682638Sperrin void 3695331Samw zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 370789Sahrens znode_t *dzp, znode_t *zp, char *name) 371789Sahrens { 372789Sahrens itx_t *itx; 373789Sahrens uint64_t seq; 374789Sahrens lr_link_t *lr; 375789Sahrens size_t namesize = strlen(name) + 1; 376789Sahrens 37710922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx)) 3782638Sperrin return; 379789Sahrens 380789Sahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize); 381789Sahrens lr = (lr_link_t *)&itx->itx_lr; 382789Sahrens lr->lr_doid = dzp->z_id; 383789Sahrens lr->lr_link_obj = zp->z_id; 384789Sahrens bcopy(name, (char *)(lr + 1), namesize); 385789Sahrens 386789Sahrens seq = zil_itx_assign(zilog, itx, tx); 387789Sahrens dzp->z_last_itx = seq; 388789Sahrens zp->z_last_itx = seq; 389789Sahrens } 390789Sahrens 391789Sahrens /* 392789Sahrens * zfs_log_symlink() handles TX_SYMLINK transactions. 393789Sahrens */ 3942638Sperrin void 3955331Samw zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 3965331Samw znode_t *dzp, znode_t *zp, char *name, char *link) 397789Sahrens { 398789Sahrens itx_t *itx; 399789Sahrens uint64_t seq; 400789Sahrens lr_create_t *lr; 401789Sahrens size_t namesize = strlen(name) + 1; 402789Sahrens size_t linksize = strlen(link) + 1; 403789Sahrens 40410922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx)) 4052638Sperrin return; 406789Sahrens 407789Sahrens itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize); 408789Sahrens lr = (lr_create_t *)&itx->itx_lr; 409789Sahrens lr->lr_doid = dzp->z_id; 410789Sahrens lr->lr_foid = zp->z_id; 411*11935SMark.Shellenbaum@Sun.COM lr->lr_uid = zp->z_uid; 412*11935SMark.Shellenbaum@Sun.COM lr->lr_gid = zp->z_gid; 413*11935SMark.Shellenbaum@Sun.COM lr->lr_mode = zp->z_mode; 414*11935SMark.Shellenbaum@Sun.COM (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen, 415*11935SMark.Shellenbaum@Sun.COM sizeof (uint64_t)); 416*11935SMark.Shellenbaum@Sun.COM (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs), 417*11935SMark.Shellenbaum@Sun.COM lr->lr_crtime, sizeof (uint64_t) * 2); 418789Sahrens bcopy(name, (char *)(lr + 1), namesize); 419789Sahrens bcopy(link, (char *)(lr + 1) + namesize, linksize); 420789Sahrens 421789Sahrens seq = zil_itx_assign(zilog, itx, tx); 422789Sahrens dzp->z_last_itx = seq; 423789Sahrens zp->z_last_itx = seq; 424789Sahrens } 425789Sahrens 426789Sahrens /* 427789Sahrens * zfs_log_rename() handles TX_RENAME transactions. 428789Sahrens */ 4292638Sperrin void 4305331Samw zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 431789Sahrens znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp) 432789Sahrens { 433789Sahrens itx_t *itx; 434789Sahrens uint64_t seq; 435789Sahrens lr_rename_t *lr; 436789Sahrens size_t snamesize = strlen(sname) + 1; 437789Sahrens size_t dnamesize = strlen(dname) + 1; 438789Sahrens 43910922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx)) 4402638Sperrin return; 441789Sahrens 442789Sahrens itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize); 443789Sahrens lr = (lr_rename_t *)&itx->itx_lr; 444789Sahrens lr->lr_sdoid = sdzp->z_id; 445789Sahrens lr->lr_tdoid = tdzp->z_id; 446789Sahrens bcopy(sname, (char *)(lr + 1), snamesize); 447789Sahrens bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize); 448789Sahrens 449789Sahrens seq = zil_itx_assign(zilog, itx, tx); 450789Sahrens sdzp->z_last_itx = seq; 451789Sahrens tdzp->z_last_itx = seq; 452789Sahrens szp->z_last_itx = seq; 453789Sahrens } 454789Sahrens 455789Sahrens /* 456789Sahrens * zfs_log_write() handles TX_WRITE transactions. 457789Sahrens */ 4582237Smaybee ssize_t zfs_immediate_write_sz = 32768; 459789Sahrens 4602638Sperrin void 461789Sahrens zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype, 4624620Sperrin znode_t *zp, offset_t off, ssize_t resid, int ioflag) 463789Sahrens { 4641669Sperrin itx_wr_state_t write_state; 4654620Sperrin boolean_t slogging; 4664720Sfr157268 uintptr_t fsync_cnt; 46710310SNeil.Perrin@Sun.COM ssize_t immediate_write_sz; 468789Sahrens 46910922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx) || zp->z_unlinked) 4702638Sperrin return; 471789Sahrens 47210310SNeil.Perrin@Sun.COM immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT) 47310310SNeil.Perrin@Sun.COM ? 0 : zfs_immediate_write_sz; 47410310SNeil.Perrin@Sun.COM 47510310SNeil.Perrin@Sun.COM slogging = spa_has_slogs(zilog->zl_spa) && 47610310SNeil.Perrin@Sun.COM (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY); 47710310SNeil.Perrin@Sun.COM if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz) 4781669Sperrin write_state = WR_INDIRECT; 4796396Sperrin else if (ioflag & (FSYNC | FDSYNC)) 4801669Sperrin write_state = WR_COPIED; 4813638Sbillm else 4821669Sperrin write_state = WR_NEED_COPY; 4833638Sbillm 4844720Sfr157268 if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) { 4854720Sfr157268 (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1)); 4864720Sfr157268 } 4874720Sfr157268 4884620Sperrin while (resid) { 4894620Sperrin itx_t *itx; 4904620Sperrin lr_write_t *lr; 4914620Sperrin ssize_t len; 4924620Sperrin 4934620Sperrin /* 4947360SNeil.Perrin@Sun.COM * If the write would overflow the largest block then split it. 4954620Sperrin */ 4967360SNeil.Perrin@Sun.COM if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA) 4974620Sperrin len = SPA_MAXBLOCKSIZE >> 1; 4984620Sperrin else 4994620Sperrin len = resid; 5004620Sperrin 5014620Sperrin itx = zil_itx_create(txtype, sizeof (*lr) + 5024620Sperrin (write_state == WR_COPIED ? len : 0)); 5034620Sperrin lr = (lr_write_t *)&itx->itx_lr; 5044620Sperrin if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os, 5059512SNeil.Perrin@Sun.COM zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) { 50610922SJeff.Bonwick@Sun.COM zil_itx_destroy(itx); 5071669Sperrin itx = zil_itx_create(txtype, sizeof (*lr)); 5083638Sbillm lr = (lr_write_t *)&itx->itx_lr; 5091669Sperrin write_state = WR_NEED_COPY; 5101669Sperrin } 5114620Sperrin 5124620Sperrin itx->itx_wr_state = write_state; 5136101Sperrin if (write_state == WR_NEED_COPY) 5146101Sperrin itx->itx_sod += len; 5154620Sperrin lr->lr_foid = zp->z_id; 5164620Sperrin lr->lr_offset = off; 5174620Sperrin lr->lr_length = len; 5184620Sperrin lr->lr_blkoff = 0; 5194620Sperrin BP_ZERO(&lr->lr_blkptr); 5203638Sbillm 5214620Sperrin itx->itx_private = zp->z_zfsvfs; 522789Sahrens 5236396Sperrin if ((zp->z_sync_cnt != 0) || (fsync_cnt != 0) || 5246396Sperrin (ioflag & (FSYNC | FDSYNC))) 5254720Sfr157268 itx->itx_sync = B_TRUE; 5264720Sfr157268 else 5274720Sfr157268 itx->itx_sync = B_FALSE; 5284720Sfr157268 5294620Sperrin zp->z_last_itx = zil_itx_assign(zilog, itx, tx); 530789Sahrens 5314620Sperrin off += len; 5324620Sperrin resid -= len; 5334620Sperrin } 534789Sahrens } 535789Sahrens 536789Sahrens /* 537789Sahrens * zfs_log_truncate() handles TX_TRUNCATE transactions. 538789Sahrens */ 5392638Sperrin void 540789Sahrens zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype, 541789Sahrens znode_t *zp, uint64_t off, uint64_t len) 542789Sahrens { 543789Sahrens itx_t *itx; 544789Sahrens uint64_t seq; 545789Sahrens lr_truncate_t *lr; 546789Sahrens 54710922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx) || zp->z_unlinked) 5482638Sperrin return; 549789Sahrens 550789Sahrens itx = zil_itx_create(txtype, sizeof (*lr)); 551789Sahrens lr = (lr_truncate_t *)&itx->itx_lr; 552789Sahrens lr->lr_foid = zp->z_id; 553789Sahrens lr->lr_offset = off; 554789Sahrens lr->lr_length = len; 555789Sahrens 5563063Sperrin itx->itx_sync = (zp->z_sync_cnt != 0); 557789Sahrens seq = zil_itx_assign(zilog, itx, tx); 558789Sahrens zp->z_last_itx = seq; 559789Sahrens } 560789Sahrens 561789Sahrens /* 562789Sahrens * zfs_log_setattr() handles TX_SETATTR transactions. 563789Sahrens */ 5642638Sperrin void 565789Sahrens zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype, 5665331Samw znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp) 567789Sahrens { 5685331Samw itx_t *itx; 5695331Samw uint64_t seq; 5705331Samw lr_setattr_t *lr; 5715331Samw xvattr_t *xvap = (xvattr_t *)vap; 5725331Samw size_t recsize = sizeof (lr_setattr_t); 5735331Samw void *start; 5745331Samw 57510922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx) || zp->z_unlinked) 5762638Sperrin return; 577789Sahrens 5785331Samw /* 5795331Samw * If XVATTR set, then log record size needs to allow 5805331Samw * for lr_attr_t + xvattr mask, mapsize and create time 5815331Samw * plus actual attribute values 5825331Samw */ 5835331Samw if (vap->va_mask & AT_XVATTR) 5845331Samw recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize); 5855331Samw 5865331Samw if (fuidp) 5875331Samw recsize += fuidp->z_domain_str_sz; 5885331Samw 5895331Samw itx = zil_itx_create(txtype, recsize); 590789Sahrens lr = (lr_setattr_t *)&itx->itx_lr; 591789Sahrens lr->lr_foid = zp->z_id; 592789Sahrens lr->lr_mask = (uint64_t)mask_applied; 593789Sahrens lr->lr_mode = (uint64_t)vap->va_mode; 5945331Samw if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid)) 5955331Samw lr->lr_uid = fuidp->z_fuid_owner; 5965331Samw else 5975331Samw lr->lr_uid = (uint64_t)vap->va_uid; 5985331Samw 5995331Samw if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid)) 6005331Samw lr->lr_gid = fuidp->z_fuid_group; 6015331Samw else 6025331Samw lr->lr_gid = (uint64_t)vap->va_gid; 6035331Samw 604789Sahrens lr->lr_size = (uint64_t)vap->va_size; 605789Sahrens ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime); 606789Sahrens ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime); 6075331Samw start = (lr_setattr_t *)(lr + 1); 6085331Samw if (vap->va_mask & AT_XVATTR) { 6095331Samw zfs_log_xvattr((lr_attr_t *)start, xvap); 6105331Samw start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize); 6115331Samw } 6125331Samw 6135331Samw /* 6145331Samw * Now stick on domain information if any on end 6155331Samw */ 6165331Samw 6175331Samw if (fuidp) 6185331Samw (void) zfs_log_fuid_domains(fuidp, start); 619789Sahrens 6203063Sperrin itx->itx_sync = (zp->z_sync_cnt != 0); 621789Sahrens seq = zil_itx_assign(zilog, itx, tx); 622789Sahrens zp->z_last_itx = seq; 623789Sahrens } 624789Sahrens 625789Sahrens /* 626789Sahrens * zfs_log_acl() handles TX_ACL transactions. 627789Sahrens */ 6282638Sperrin void 6295331Samw zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp, 6305331Samw vsecattr_t *vsecp, zfs_fuid_info_t *fuidp) 631789Sahrens { 632789Sahrens itx_t *itx; 633789Sahrens uint64_t seq; 6345331Samw lr_acl_v0_t *lrv0; 635789Sahrens lr_acl_t *lr; 6365331Samw int txtype; 6375331Samw int lrsize; 6385331Samw size_t txsize; 6395331Samw size_t aclbytes = vsecp->vsa_aclentsz; 6405331Samw 64110922SJeff.Bonwick@Sun.COM if (zil_replaying(zilog, tx) || zp->z_unlinked) 6426514Smarks return; 6436514Smarks 6446514Smarks txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ? 6455331Samw TX_ACL_V0 : TX_ACL; 6465331Samw 6475331Samw if (txtype == TX_ACL) 6485331Samw lrsize = sizeof (*lr); 6495331Samw else 6505331Samw lrsize = sizeof (*lrv0); 651789Sahrens 6525435Smarks txsize = lrsize + 6535435Smarks ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) + 6545435Smarks (fuidp ? fuidp->z_domain_str_sz : 0) + 6556514Smarks sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0); 6565331Samw 6575331Samw itx = zil_itx_create(txtype, txsize); 6585331Samw 659789Sahrens lr = (lr_acl_t *)&itx->itx_lr; 660789Sahrens lr->lr_foid = zp->z_id; 6615331Samw if (txtype == TX_ACL) { 6625331Samw lr->lr_acl_bytes = aclbytes; 6635331Samw lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0; 6645331Samw lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0; 6655331Samw if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS) 6665331Samw lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags; 6675331Samw else 6685331Samw lr->lr_acl_flags = 0; 6695331Samw } 6705331Samw lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt; 6715331Samw 6725331Samw if (txtype == TX_ACL_V0) { 6735331Samw lrv0 = (lr_acl_v0_t *)lr; 6745331Samw bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes); 6755331Samw } else { 6765331Samw void *start = (ace_t *)(lr + 1); 6775331Samw 6785331Samw bcopy(vsecp->vsa_aclentp, start, aclbytes); 6795331Samw 6805435Smarks start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes); 6815331Samw 6825331Samw if (fuidp) { 6835331Samw start = zfs_log_fuid_ids(fuidp, start); 6845331Samw (void) zfs_log_fuid_domains(fuidp, start); 6855331Samw } 6865331Samw } 687789Sahrens 6883063Sperrin itx->itx_sync = (zp->z_sync_cnt != 0); 689789Sahrens seq = zil_itx_assign(zilog, itx, tx); 690789Sahrens zp->z_last_itx = seq; 691789Sahrens } 692