1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #include <sys/types.h> 26 #include <sys/param.h> 27 #include <sys/systm.h> 28 #include <sys/sysmacros.h> 29 #include <sys/cmn_err.h> 30 #include <sys/kmem.h> 31 #include <sys/thread.h> 32 #include <sys/file.h> 33 #include <sys/vfs.h> 34 #include <sys/zfs_znode.h> 35 #include <sys/zfs_dir.h> 36 #include <sys/zil.h> 37 #include <sys/zil_impl.h> 38 #include <sys/byteorder.h> 39 #include <sys/policy.h> 40 #include <sys/stat.h> 41 #include <sys/mode.h> 42 #include <sys/acl.h> 43 #include <sys/dmu.h> 44 #include <sys/spa.h> 45 #include <sys/zfs_fuid.h> 46 #include <sys/ddi.h> 47 #include <sys/dsl_dataset.h> 48 #include <sys/zfs_events.h> 49 50 /* 51 * These zfs_log_* functions must be called within a dmu tx, in one 52 * of 2 contexts depending on zilog->z_replay: 53 * 54 * Non replay mode 55 * --------------- 56 * We need to record the transaction so that if it is committed to 57 * the Intent Log then it can be replayed. An intent log transaction 58 * structure (itx_t) is allocated and all the information necessary to 59 * possibly replay the transaction is saved in it. The itx is then assigned 60 * a sequence number and inserted in the in-memory list anchored in the zilog. 61 * 62 * Replay mode 63 * ----------- 64 * We need to mark the intent log record as replayed in the log header. 65 * This is done in the same transaction as the replay so that they 66 * commit atomically. 67 */ 68 69 int 70 zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap) 71 { 72 int isxvattr = (vap->va_mask & AT_XVATTR); 73 switch (type) { 74 case Z_FILE: 75 if (vsecp == NULL && !isxvattr) 76 return (TX_CREATE); 77 if (vsecp && isxvattr) 78 return (TX_CREATE_ACL_ATTR); 79 if (vsecp) 80 return (TX_CREATE_ACL); 81 else 82 return (TX_CREATE_ATTR); 83 /*NOTREACHED*/ 84 case Z_DIR: 85 if (vsecp == NULL && !isxvattr) 86 return (TX_MKDIR); 87 if (vsecp && isxvattr) 88 return (TX_MKDIR_ACL_ATTR); 89 if (vsecp) 90 return (TX_MKDIR_ACL); 91 else 92 return (TX_MKDIR_ATTR); 93 case Z_XATTRDIR: 94 return (TX_MKXATTR); 95 } 96 ASSERT(0); 97 return (TX_MAX_TYPE); 98 } 99 100 /* 101 * build up the log data necessary for logging xvattr_t 102 * First lr_attr_t is initialized. following the lr_attr_t 103 * is the mapsize and attribute bitmap copied from the xvattr_t. 104 * Following the bitmap and bitmapsize two 64 bit words are reserved 105 * for the create time which may be set. Following the create time 106 * records a single 64 bit integer which has the bits to set on 107 * replay for the xvattr. 108 */ 109 static void 110 zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap) 111 { 112 uint32_t *bitmap; 113 uint64_t *attrs; 114 uint64_t *crtime; 115 xoptattr_t *xoap; 116 void *scanstamp; 117 int i; 118 119 xoap = xva_getxoptattr(xvap); 120 ASSERT(xoap); 121 122 lrattr->lr_attr_masksize = xvap->xva_mapsize; 123 bitmap = &lrattr->lr_attr_bitmap; 124 for (i = 0; i != xvap->xva_mapsize; i++, bitmap++) { 125 *bitmap = xvap->xva_reqattrmap[i]; 126 } 127 128 /* Now pack the attributes up in a single uint64_t */ 129 attrs = (uint64_t *)bitmap; 130 crtime = attrs + 1; 131 scanstamp = (caddr_t)(crtime + 2); 132 *attrs = 0; 133 if (XVA_ISSET_REQ(xvap, XAT_READONLY)) 134 *attrs |= (xoap->xoa_readonly == 0) ? 0 : 135 XAT0_READONLY; 136 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) 137 *attrs |= (xoap->xoa_hidden == 0) ? 0 : 138 XAT0_HIDDEN; 139 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) 140 *attrs |= (xoap->xoa_system == 0) ? 0 : 141 XAT0_SYSTEM; 142 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) 143 *attrs |= (xoap->xoa_archive == 0) ? 0 : 144 XAT0_ARCHIVE; 145 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) 146 *attrs |= (xoap->xoa_immutable == 0) ? 0 : 147 XAT0_IMMUTABLE; 148 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) 149 *attrs |= (xoap->xoa_nounlink == 0) ? 0 : 150 XAT0_NOUNLINK; 151 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) 152 *attrs |= (xoap->xoa_appendonly == 0) ? 0 : 153 XAT0_APPENDONLY; 154 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) 155 *attrs |= (xoap->xoa_opaque == 0) ? 0 : 156 XAT0_APPENDONLY; 157 if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) 158 *attrs |= (xoap->xoa_nodump == 0) ? 0 : 159 XAT0_NODUMP; 160 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) 161 *attrs |= (xoap->xoa_av_quarantined == 0) ? 0 : 162 XAT0_AV_QUARANTINED; 163 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) 164 *attrs |= (xoap->xoa_av_modified == 0) ? 0 : 165 XAT0_AV_MODIFIED; 166 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) 167 ZFS_TIME_ENCODE(&xoap->xoa_createtime, crtime); 168 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) 169 bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ); 170 if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) 171 *attrs |= (xoap->xoa_reparse == 0) ? 0 : 172 XAT0_REPARSE; 173 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) 174 *attrs |= (xoap->xoa_offline == 0) ? 0 : 175 XAT0_OFFLINE; 176 if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) 177 *attrs |= (xoap->xoa_sparse == 0) ? 0 : 178 XAT0_SPARSE; 179 } 180 181 static void * 182 zfs_log_fuid_ids(zfs_fuid_info_t *fuidp, void *start) 183 { 184 zfs_fuid_t *zfuid; 185 uint64_t *fuidloc = start; 186 187 /* First copy in the ACE FUIDs */ 188 for (zfuid = list_head(&fuidp->z_fuids); zfuid; 189 zfuid = list_next(&fuidp->z_fuids, zfuid)) { 190 *fuidloc++ = zfuid->z_logfuid; 191 } 192 return (fuidloc); 193 } 194 195 196 static void * 197 zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start) 198 { 199 zfs_fuid_domain_t *zdomain; 200 201 /* now copy in the domain info, if any */ 202 if (fuidp->z_domain_str_sz != 0) { 203 for (zdomain = list_head(&fuidp->z_domains); zdomain; 204 zdomain = list_next(&fuidp->z_domains, zdomain)) { 205 bcopy((void *)zdomain->z_domain, start, 206 strlen(zdomain->z_domain) + 1); 207 start = (caddr_t)start + 208 strlen(zdomain->z_domain) + 1; 209 } 210 } 211 return (start); 212 } 213 214 /* 215 * Handles TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, TX_MKDIR_ATTR and 216 * TK_MKXATTR transactions. 217 * 218 * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID 219 * domain information appended prior to the name. In this case the 220 * uid/gid in the log record will be a log centric FUID. 221 * 222 * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that 223 * may contain attributes, ACL and optional fuid information. 224 * 225 * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify 226 * and ACL and normal users/groups in the ACEs. 227 * 228 * There may be an optional xvattr attribute information similar 229 * to zfs_log_setattr. 230 * 231 * Also, after the file name "domain" strings may be appended. 232 */ 233 void 234 zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 235 znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp, 236 zfs_fuid_info_t *fuidp, vattr_t *vap) 237 { 238 itx_t *itx; 239 lr_create_t *lr; 240 lr_acl_create_t *lracl; 241 size_t aclsize = (vsecp != NULL) ? vsecp->vsa_aclentsz : 0; 242 size_t xvatsize = 0; 243 size_t txsize; 244 xvattr_t *xvap = (xvattr_t *)vap; 245 void *end; 246 size_t lrsize; 247 size_t namesize = strlen(name) + 1; 248 size_t fuidsz = 0; 249 250 if (zil_replaying(zilog, tx)) 251 return; 252 253 /* 254 * If we have FUIDs present then add in space for 255 * domains and ACE fuid's if any. 256 */ 257 if (fuidp) { 258 fuidsz += fuidp->z_domain_str_sz; 259 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t); 260 } 261 262 if (vap->va_mask & AT_XVATTR) 263 xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize); 264 265 if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR || 266 (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR || 267 (int)txtype == TX_MKXATTR) { 268 txsize = sizeof (*lr) + namesize + fuidsz + xvatsize; 269 lrsize = sizeof (*lr); 270 } else { 271 txsize = 272 sizeof (lr_acl_create_t) + namesize + fuidsz + 273 ZIL_ACE_LENGTH(aclsize) + xvatsize; 274 lrsize = sizeof (lr_acl_create_t); 275 } 276 277 itx = zil_itx_create(txtype, txsize); 278 279 lr = (lr_create_t *)&itx->itx_lr; 280 lr->lr_doid = dzp->z_id; 281 lr->lr_foid = zp->z_id; 282 lr->lr_mode = zp->z_mode; 283 if (!IS_EPHEMERAL(zp->z_uid)) { 284 lr->lr_uid = (uint64_t)zp->z_uid; 285 } else { 286 lr->lr_uid = fuidp->z_fuid_owner; 287 } 288 if (!IS_EPHEMERAL(zp->z_gid)) { 289 lr->lr_gid = (uint64_t)zp->z_gid; 290 } else { 291 lr->lr_gid = fuidp->z_fuid_group; 292 } 293 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen, 294 sizeof (uint64_t)); 295 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs), 296 lr->lr_crtime, sizeof (uint64_t) * 2); 297 298 if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(zp->z_zfsvfs), &lr->lr_rdev, 299 sizeof (lr->lr_rdev)) != 0) 300 lr->lr_rdev = 0; 301 302 /* 303 * Fill in xvattr info if any 304 */ 305 if (vap->va_mask & AT_XVATTR) { 306 zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap); 307 end = (caddr_t)lr + lrsize + xvatsize; 308 } else { 309 end = (caddr_t)lr + lrsize; 310 } 311 312 /* Now fill in any ACL info */ 313 314 if (vsecp) { 315 lracl = (lr_acl_create_t *)&itx->itx_lr; 316 lracl->lr_aclcnt = vsecp->vsa_aclcnt; 317 lracl->lr_acl_bytes = aclsize; 318 lracl->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0; 319 lracl->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0; 320 if (vsecp->vsa_aclflags & VSA_ACE_ACLFLAGS) 321 lracl->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags; 322 else 323 lracl->lr_acl_flags = 0; 324 325 bcopy(vsecp->vsa_aclentp, end, aclsize); 326 end = (caddr_t)end + ZIL_ACE_LENGTH(aclsize); 327 } 328 329 /* drop in FUID info */ 330 if (fuidp) { 331 end = zfs_log_fuid_ids(fuidp, end); 332 end = zfs_log_fuid_domains(fuidp, end); 333 } 334 /* 335 * Now place file name in log record 336 */ 337 bcopy(name, end, namesize); 338 339 zil_itx_assign(zilog, itx, tx); 340 341 rw_enter(&rz_zev_rwlock, RW_READER); 342 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_create) 343 rz_zev_callbacks->rz_zev_znode_create(dzp, zp, tx, name, 344 txtype); 345 rw_exit(&rz_zev_rwlock); 346 } 347 348 /* 349 * Handles both TX_REMOVE and TX_RMDIR transactions. 350 */ 351 void 352 zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 353 znode_t *dzp, char *name, uint64_t foid) 354 { 355 itx_t *itx; 356 lr_remove_t *lr; 357 size_t namesize = strlen(name) + 1; 358 359 if (zil_replaying(zilog, tx)) 360 return; 361 362 itx = zil_itx_create(txtype, sizeof (*lr) + namesize); 363 lr = (lr_remove_t *)&itx->itx_lr; 364 lr->lr_doid = dzp->z_id; 365 bcopy(name, (char *)(lr + 1), namesize); 366 367 itx->itx_oid = foid; 368 369 zil_itx_assign(zilog, itx, tx); 370 } 371 372 /* 373 * Handles TX_LINK transactions. 374 */ 375 void 376 zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 377 znode_t *dzp, znode_t *zp, char *name) 378 { 379 itx_t *itx; 380 lr_link_t *lr; 381 size_t namesize = strlen(name) + 1; 382 383 if (zil_replaying(zilog, tx)) 384 return; 385 386 itx = zil_itx_create(txtype, sizeof (*lr) + namesize); 387 lr = (lr_link_t *)&itx->itx_lr; 388 lr->lr_doid = dzp->z_id; 389 lr->lr_link_obj = zp->z_id; 390 bcopy(name, (char *)(lr + 1), namesize); 391 392 zil_itx_assign(zilog, itx, tx); 393 394 rw_enter(&rz_zev_rwlock, RW_READER); 395 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_link) 396 rz_zev_callbacks->rz_zev_znode_link(dzp, zp, tx, name); 397 rw_exit(&rz_zev_rwlock); 398 } 399 400 /* 401 * Handles TX_SYMLINK transactions. 402 */ 403 void 404 zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 405 znode_t *dzp, znode_t *zp, char *name, char *link) 406 { 407 itx_t *itx; 408 lr_create_t *lr; 409 size_t namesize = strlen(name) + 1; 410 size_t linksize = strlen(link) + 1; 411 412 if (zil_replaying(zilog, tx)) 413 return; 414 415 itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize); 416 lr = (lr_create_t *)&itx->itx_lr; 417 lr->lr_doid = dzp->z_id; 418 lr->lr_foid = zp->z_id; 419 lr->lr_uid = zp->z_uid; 420 lr->lr_gid = zp->z_gid; 421 lr->lr_mode = zp->z_mode; 422 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zp->z_zfsvfs), &lr->lr_gen, 423 sizeof (uint64_t)); 424 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zp->z_zfsvfs), 425 lr->lr_crtime, sizeof (uint64_t) * 2); 426 bcopy(name, (char *)(lr + 1), namesize); 427 bcopy(link, (char *)(lr + 1) + namesize, linksize); 428 429 zil_itx_assign(zilog, itx, tx); 430 431 rw_enter(&rz_zev_rwlock, RW_READER); 432 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_symlink) 433 rz_zev_callbacks->rz_zev_znode_symlink(dzp, zp, tx, name, link); 434 rw_exit(&rz_zev_rwlock); 435 } 436 437 /* 438 * Handles TX_RENAME transactions. 439 */ 440 void 441 zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 442 znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp) 443 { 444 itx_t *itx; 445 lr_rename_t *lr; 446 size_t snamesize = strlen(sname) + 1; 447 size_t dnamesize = strlen(dname) + 1; 448 449 if (zil_replaying(zilog, tx)) 450 return; 451 452 itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize); 453 lr = (lr_rename_t *)&itx->itx_lr; 454 lr->lr_sdoid = sdzp->z_id; 455 lr->lr_tdoid = tdzp->z_id; 456 bcopy(sname, (char *)(lr + 1), snamesize); 457 bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize); 458 itx->itx_oid = szp->z_id; 459 460 zil_itx_assign(zilog, itx, tx); 461 462 rw_enter(&rz_zev_rwlock, RW_READER); 463 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_rename) 464 rz_zev_callbacks->rz_zev_znode_rename(sdzp, 465 sname, tdzp, dname, szp, tx); 466 rw_exit(&rz_zev_rwlock); 467 } 468 469 /* 470 * Handles TX_WRITE transactions. 471 */ 472 ssize_t zfs_immediate_write_sz = 32768; 473 474 void 475 zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype, 476 znode_t *zp, offset_t off, ssize_t resid, int ioflag) 477 { 478 itx_wr_state_t write_state; 479 boolean_t slogging; 480 uintptr_t fsync_cnt; 481 ssize_t immediate_write_sz; 482 483 if (zil_replaying(zilog, tx) || zp->z_unlinked) 484 return; 485 486 immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT) 487 ? 0 : zfs_immediate_write_sz; 488 489 slogging = spa_has_slogs(zilog->zl_spa) && 490 (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY); 491 if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz) 492 write_state = WR_INDIRECT; 493 else if (ioflag & (FSYNC | FDSYNC)) 494 write_state = WR_COPIED; 495 else 496 write_state = WR_NEED_COPY; 497 498 if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) { 499 (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1)); 500 } 501 502 while (resid) { 503 itx_t *itx; 504 lr_write_t *lr; 505 ssize_t len; 506 507 /* 508 * If the write would overflow the largest block then split it. 509 */ 510 if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA) 511 len = SPA_MAXBLOCKSIZE >> 1; 512 else 513 len = resid; 514 515 itx = zil_itx_create(txtype, sizeof (*lr) + 516 (write_state == WR_COPIED ? len : 0)); 517 lr = (lr_write_t *)&itx->itx_lr; 518 if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os, 519 zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) { 520 zil_itx_destroy(itx); 521 itx = zil_itx_create(txtype, sizeof (*lr)); 522 lr = (lr_write_t *)&itx->itx_lr; 523 write_state = WR_NEED_COPY; 524 } 525 526 itx->itx_wr_state = write_state; 527 if (write_state == WR_NEED_COPY) 528 itx->itx_sod += len; 529 lr->lr_foid = zp->z_id; 530 lr->lr_offset = off; 531 lr->lr_length = len; 532 lr->lr_blkoff = 0; 533 BP_ZERO(&lr->lr_blkptr); 534 535 itx->itx_private = zp->z_zfsvfs; 536 537 if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) && 538 (fsync_cnt == 0)) 539 itx->itx_sync = B_FALSE; 540 541 zil_itx_assign(zilog, itx, tx); 542 543 if (ZTOV(zp)->v_type == VREG) 544 atomic_add_32(&(zp->z_new_content), 1); 545 rw_enter(&rz_zev_rwlock, RW_READER); 546 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_write) 547 rz_zev_callbacks->rz_zev_znode_write(zp, tx, off, len); 548 rw_exit(&rz_zev_rwlock); 549 550 off += len; 551 resid -= len; 552 } 553 } 554 555 /* 556 * Handles TX_TRUNCATE transactions. 557 */ 558 void 559 zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype, 560 znode_t *zp, uint64_t off, uint64_t len) 561 { 562 itx_t *itx; 563 lr_truncate_t *lr; 564 565 if (zil_replaying(zilog, tx) || zp->z_unlinked) 566 return; 567 568 itx = zil_itx_create(txtype, sizeof (*lr)); 569 lr = (lr_truncate_t *)&itx->itx_lr; 570 lr->lr_foid = zp->z_id; 571 lr->lr_offset = off; 572 lr->lr_length = len; 573 574 itx->itx_sync = (zp->z_sync_cnt != 0); 575 zil_itx_assign(zilog, itx, tx); 576 577 if (ZTOV(zp)->v_type == VREG) 578 atomic_add_32(&(zp->z_new_content), 1); 579 rw_enter(&rz_zev_rwlock, RW_READER); 580 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_truncate) 581 rz_zev_callbacks->rz_zev_znode_truncate(zp, tx, off, len); 582 rw_exit(&rz_zev_rwlock); 583 } 584 585 /* 586 * Handles TX_SETATTR transactions. 587 */ 588 void 589 zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype, 590 znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp) 591 { 592 itx_t *itx; 593 lr_setattr_t *lr; 594 xvattr_t *xvap = (xvattr_t *)vap; 595 size_t recsize = sizeof (lr_setattr_t); 596 void *start; 597 598 if (zil_replaying(zilog, tx) || zp->z_unlinked) 599 return; 600 601 /* 602 * If XVATTR set, then log record size needs to allow 603 * for lr_attr_t + xvattr mask, mapsize and create time 604 * plus actual attribute values 605 */ 606 if (vap->va_mask & AT_XVATTR) 607 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize); 608 609 if (fuidp) 610 recsize += fuidp->z_domain_str_sz; 611 612 itx = zil_itx_create(txtype, recsize); 613 lr = (lr_setattr_t *)&itx->itx_lr; 614 lr->lr_foid = zp->z_id; 615 lr->lr_mask = (uint64_t)mask_applied; 616 lr->lr_mode = (uint64_t)vap->va_mode; 617 if ((mask_applied & AT_UID) && IS_EPHEMERAL(vap->va_uid)) 618 lr->lr_uid = fuidp->z_fuid_owner; 619 else 620 lr->lr_uid = (uint64_t)vap->va_uid; 621 622 if ((mask_applied & AT_GID) && IS_EPHEMERAL(vap->va_gid)) 623 lr->lr_gid = fuidp->z_fuid_group; 624 else 625 lr->lr_gid = (uint64_t)vap->va_gid; 626 627 lr->lr_size = (uint64_t)vap->va_size; 628 ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime); 629 ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime); 630 start = (lr_setattr_t *)(lr + 1); 631 if (vap->va_mask & AT_XVATTR) { 632 zfs_log_xvattr((lr_attr_t *)start, xvap); 633 start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize); 634 } 635 636 /* 637 * Now stick on domain information if any on end 638 */ 639 640 if (fuidp) 641 (void) zfs_log_fuid_domains(fuidp, start); 642 643 itx->itx_sync = (zp->z_sync_cnt != 0); 644 zil_itx_assign(zilog, itx, tx); 645 } 646 647 /* 648 * Handles TX_ACL transactions. 649 */ 650 void 651 zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp, 652 vsecattr_t *vsecp, zfs_fuid_info_t *fuidp) 653 { 654 itx_t *itx; 655 lr_acl_v0_t *lrv0; 656 lr_acl_t *lr; 657 int txtype; 658 int lrsize; 659 size_t txsize; 660 size_t aclbytes = vsecp->vsa_aclentsz; 661 662 if (zil_replaying(zilog, tx) || zp->z_unlinked) 663 return; 664 665 txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ? 666 TX_ACL_V0 : TX_ACL; 667 668 if (txtype == TX_ACL) 669 lrsize = sizeof (*lr); 670 else 671 lrsize = sizeof (*lrv0); 672 673 txsize = lrsize + 674 ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) + 675 (fuidp ? fuidp->z_domain_str_sz : 0) + 676 sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0); 677 678 itx = zil_itx_create(txtype, txsize); 679 680 lr = (lr_acl_t *)&itx->itx_lr; 681 lr->lr_foid = zp->z_id; 682 if (txtype == TX_ACL) { 683 lr->lr_acl_bytes = aclbytes; 684 lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0; 685 lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0; 686 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS) 687 lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags; 688 else 689 lr->lr_acl_flags = 0; 690 } 691 lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt; 692 693 if (txtype == TX_ACL_V0) { 694 lrv0 = (lr_acl_v0_t *)lr; 695 bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes); 696 } else { 697 void *start = (ace_t *)(lr + 1); 698 699 bcopy(vsecp->vsa_aclentp, start, aclbytes); 700 701 start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes); 702 703 if (fuidp) { 704 start = zfs_log_fuid_ids(fuidp, start); 705 (void) zfs_log_fuid_domains(fuidp, start); 706 } 707 } 708 709 itx->itx_sync = (zp->z_sync_cnt != 0); 710 zil_itx_assign(zilog, itx, tx); 711 712 rw_enter(&rz_zev_rwlock, RW_READER); 713 if (rz_zev_callbacks && rz_zev_callbacks->rz_zev_znode_acl) 714 rz_zev_callbacks->rz_zev_znode_acl(zp, tx); 715 rw_exit(&rz_zev_rwlock); 716 } 717