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.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
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>
31 #include <sys/thread.h>
33 #include <sys/fcntl.h>
35 #include <sys/fs/zfs.h>
36 #include <sys/zfs_znode.h>
37 #include <sys/zfs_dir.h>
38 #include <sys/zfs_acl.h>
39 #include <sys/zfs_fuid.h>
42 #include <sys/byteorder.h>
46 #include <sys/atomic.h>
50 * Functions to replay ZFS intent log (ZIL) records
51 * The functions are called through a function vector (zfs_replay_vector)
52 * which is indexed by the transaction type.
56 zfs_init_vattr(vattr_t *vap, uint64_t mask, uint64_t mode,
57 uint64_t uid, uint64_t gid, uint64_t rdev, uint64_t nodeid)
59 bzero(vap, sizeof (*vap));
60 vap->va_mask = (uint_t)mask;
61 vap->va_type = IFTOVT(mode);
62 vap->va_mode = mode & MODEMASK;
63 vap->va_uid = (uid_t)(IS_EPHEMERAL(uid)) ? -1 : uid;
64 vap->va_gid = (gid_t)(IS_EPHEMERAL(gid)) ? -1 : gid;
65 vap->va_rdev = zfs_cmpldev(rdev);
66 vap->va_nodeid = nodeid;
71 zfs_replay_error(zfsvfs_t *zfsvfs, lr_t *lr, boolean_t byteswap)
77 zfs_replay_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
79 xoptattr_t *xoap = NULL;
86 xvap->xva_vattr.va_mask |= AT_XVATTR;
87 if ((xoap = xva_getxoptattr(xvap)) == NULL) {
88 xvap->xva_vattr.va_mask &= ~AT_XVATTR; /* shouldn't happen */
92 ASSERT(lrattr->lr_attr_masksize == xvap->xva_mapsize);
94 bitmap = &lrattr->lr_attr_bitmap;
95 for (i = 0; i != lrattr->lr_attr_masksize; i++, bitmap++)
96 xvap->xva_reqattrmap[i] = *bitmap;
98 attrs = (uint64_t *)(lrattr + lrattr->lr_attr_masksize - 1);
100 scanstamp = (caddr_t)(crtime + 2);
102 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
103 xoap->xoa_hidden = ((*attrs & XAT0_HIDDEN) != 0);
104 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
105 xoap->xoa_system = ((*attrs & XAT0_SYSTEM) != 0);
106 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
107 xoap->xoa_archive = ((*attrs & XAT0_ARCHIVE) != 0);
108 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
109 xoap->xoa_readonly = ((*attrs & XAT0_READONLY) != 0);
110 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
111 xoap->xoa_immutable = ((*attrs & XAT0_IMMUTABLE) != 0);
112 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
113 xoap->xoa_nounlink = ((*attrs & XAT0_NOUNLINK) != 0);
114 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
115 xoap->xoa_appendonly = ((*attrs & XAT0_APPENDONLY) != 0);
116 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
117 xoap->xoa_nodump = ((*attrs & XAT0_NODUMP) != 0);
118 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
119 xoap->xoa_opaque = ((*attrs & XAT0_OPAQUE) != 0);
120 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
121 xoap->xoa_av_modified = ((*attrs & XAT0_AV_MODIFIED) != 0);
122 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
123 xoap->xoa_av_quarantined =
124 ((*attrs & XAT0_AV_QUARANTINED) != 0);
125 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
126 ZFS_TIME_DECODE(&xoap->xoa_createtime, crtime);
127 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
128 bcopy(scanstamp, xoap->xoa_av_scanstamp, AV_SCANSTAMP_SZ);
129 if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
130 xoap->xoa_reparse = ((*attrs & XAT0_REPARSE) != 0);
131 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
132 xoap->xoa_offline = ((*attrs & XAT0_OFFLINE) != 0);
133 if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
134 xoap->xoa_sparse = ((*attrs & XAT0_SPARSE) != 0);
138 zfs_replay_domain_cnt(uint64_t uid, uint64_t gid)
144 uid_idx = FUID_INDEX(uid);
145 gid_idx = FUID_INDEX(gid);
148 if (gid_idx > 0 && gid_idx != uid_idx)
155 zfs_replay_fuid_domain_common(zfs_fuid_info_t *fuid_infop, void *start,
160 for (i = 0; i != domcnt; i++) {
161 fuid_infop->z_domain_table[i] = start;
162 start = (caddr_t)start + strlen(start) + 1;
169 * Set the uid/gid in the fuid_info structure.
172 zfs_replay_fuid_ugid(zfs_fuid_info_t *fuid_infop, uint64_t uid, uint64_t gid)
175 * If owner or group are log specific FUIDs then slurp up
176 * domain information and build zfs_fuid_info_t
178 if (IS_EPHEMERAL(uid))
179 fuid_infop->z_fuid_owner = uid;
181 if (IS_EPHEMERAL(gid))
182 fuid_infop->z_fuid_group = gid;
186 * Load fuid domains into fuid_info_t
188 static zfs_fuid_info_t *
189 zfs_replay_fuid_domain(void *buf, void **end, uint64_t uid, uint64_t gid)
193 zfs_fuid_info_t *fuid_infop;
195 fuid_infop = zfs_fuid_info_alloc();
197 domcnt = zfs_replay_domain_cnt(uid, gid);
202 fuid_infop->z_domain_table =
203 kmem_zalloc(domcnt * sizeof (char **), KM_SLEEP);
205 zfs_replay_fuid_ugid(fuid_infop, uid, gid);
207 fuid_infop->z_domain_cnt = domcnt;
208 *end = zfs_replay_fuid_domain_common(fuid_infop, buf, domcnt);
213 * load zfs_fuid_t's and fuid_domains into fuid_info_t
215 static zfs_fuid_info_t *
216 zfs_replay_fuids(void *start, void **end, int idcnt, int domcnt, uint64_t uid,
219 uint64_t *log_fuid = (uint64_t *)start;
220 zfs_fuid_info_t *fuid_infop;
223 fuid_infop = zfs_fuid_info_alloc();
224 fuid_infop->z_domain_cnt = domcnt;
226 fuid_infop->z_domain_table =
227 kmem_zalloc(domcnt * sizeof (char **), KM_SLEEP);
229 for (i = 0; i != idcnt; i++) {
232 zfuid = kmem_alloc(sizeof (zfs_fuid_t), KM_SLEEP);
233 zfuid->z_logfuid = *log_fuid;
236 list_insert_tail(&fuid_infop->z_fuids, zfuid);
240 zfs_replay_fuid_ugid(fuid_infop, uid, gid);
242 *end = zfs_replay_fuid_domain_common(fuid_infop, log_fuid, domcnt);
247 zfs_replay_swap_attrs(lr_attr_t *lrattr)
249 /* swap the lr_attr structure */
250 byteswap_uint32_array(lrattr, sizeof (*lrattr));
251 /* swap the bitmap */
252 byteswap_uint32_array(lrattr + 1, (lrattr->lr_attr_masksize - 1) *
254 /* swap the attributes, create time + 64 bit word for attributes */
255 byteswap_uint64_array((caddr_t)(lrattr + 1) + (sizeof (uint32_t) *
256 (lrattr->lr_attr_masksize - 1)), 3 * sizeof (uint64_t));
260 * Replay file create with optional ACL, xvattr information as well
261 * as option FUID information.
264 zfs_replay_create_acl(zfsvfs_t *zfsvfs,
265 lr_acl_create_t *lracl, boolean_t byteswap)
267 char *name = NULL; /* location determined later */
268 lr_create_t *lr = (lr_create_t *)lracl;
273 vsecattr_t vsec = { 0 };
281 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
283 byteswap_uint64_array(lracl, sizeof (*lracl));
284 if (txtype == TX_CREATE_ACL_ATTR ||
285 txtype == TX_MKDIR_ACL_ATTR) {
286 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
287 zfs_replay_swap_attrs(lrattr);
288 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
291 aclstart = (caddr_t)(lracl + 1) + xvatlen;
292 zfs_ace_byteswap(aclstart, lracl->lr_acl_bytes, B_FALSE);
294 if (lracl->lr_fuidcnt) {
295 byteswap_uint64_array((caddr_t)aclstart +
296 ZIL_ACE_LENGTH(lracl->lr_acl_bytes),
297 lracl->lr_fuidcnt * sizeof (uint64_t));
301 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
305 zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
306 lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
309 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
310 * eventually end up in zfs_mknode(), which assigns the object's
311 * creation time and generation number. The generic VOP_CREATE()
312 * doesn't have either concept, so we smuggle the values inside
313 * the vattr's otherwise unused va_ctime and va_nblocks fields.
315 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
316 xva.xva_vattr.va_nblocks = lr->lr_gen;
318 error = dmu_object_info(zfsvfs->z_os, lr->lr_foid, NULL);
322 if (lr->lr_common.lrc_txtype & TX_CI)
326 aclstart = (caddr_t)(lracl + 1);
327 fuidstart = (caddr_t)aclstart +
328 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
329 zfsvfs->z_fuid_replay = zfs_replay_fuids(fuidstart,
330 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
331 lr->lr_uid, lr->lr_gid);
333 case TX_CREATE_ACL_ATTR:
335 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
336 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
337 xva.xva_vattr.va_mask |= AT_XVATTR;
338 zfs_replay_xvattr(lrattr, &xva);
340 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
341 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
342 vsec.vsa_aclcnt = lracl->lr_aclcnt;
343 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
344 vsec.vsa_aclflags = lracl->lr_acl_flags;
345 if (zfsvfs->z_fuid_replay == NULL) {
346 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
347 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
348 zfsvfs->z_fuid_replay =
349 zfs_replay_fuids(fuidstart,
350 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
351 lr->lr_uid, lr->lr_gid);
354 error = VOP_CREATE(ZTOV(dzp), name, &xva.xva_vattr,
355 0, 0, &vp, kcred, vflg, NULL, &vsec);
358 aclstart = (caddr_t)(lracl + 1);
359 fuidstart = (caddr_t)aclstart +
360 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
361 zfsvfs->z_fuid_replay = zfs_replay_fuids(fuidstart,
362 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
363 lr->lr_uid, lr->lr_gid);
365 case TX_MKDIR_ACL_ATTR:
367 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
368 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
369 zfs_replay_xvattr(lrattr, &xva);
371 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
372 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
373 vsec.vsa_aclcnt = lracl->lr_aclcnt;
374 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
375 vsec.vsa_aclflags = lracl->lr_acl_flags;
376 if (zfsvfs->z_fuid_replay == NULL) {
377 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
378 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
379 zfsvfs->z_fuid_replay =
380 zfs_replay_fuids(fuidstart,
381 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
382 lr->lr_uid, lr->lr_gid);
384 error = VOP_MKDIR(ZTOV(dzp), name, &xva.xva_vattr,
385 &vp, kcred, NULL, vflg, &vsec);
392 if (error == 0 && vp != NULL)
397 if (zfsvfs->z_fuid_replay)
398 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
399 zfsvfs->z_fuid_replay = NULL;
405 zfs_replay_create(zfsvfs_t *zfsvfs, lr_create_t *lr, boolean_t byteswap)
407 char *name = NULL; /* location determined later */
408 char *link; /* symlink content follows name */
413 size_t lrsize = sizeof (lr_create_t);
420 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
422 byteswap_uint64_array(lr, sizeof (*lr));
423 if (txtype == TX_CREATE_ATTR || txtype == TX_MKDIR_ATTR)
424 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
428 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
432 zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
433 lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
436 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
437 * eventually end up in zfs_mknode(), which assigns the object's
438 * creation time and generation number. The generic VOP_CREATE()
439 * doesn't have either concept, so we smuggle the values inside
440 * the vattr's otherwise unused va_ctime and va_nblocks fields.
442 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
443 xva.xva_vattr.va_nblocks = lr->lr_gen;
445 error = dmu_object_info(zfsvfs->z_os, lr->lr_foid, NULL);
449 if (lr->lr_common.lrc_txtype & TX_CI)
453 * Symlinks don't have fuid info, and CIFS never creates
456 * The _ATTR versions will grab the fuid info in their subcases.
458 if ((int)lr->lr_common.lrc_txtype != TX_SYMLINK &&
459 (int)lr->lr_common.lrc_txtype != TX_MKDIR_ATTR &&
460 (int)lr->lr_common.lrc_txtype != TX_CREATE_ATTR) {
462 zfsvfs->z_fuid_replay =
463 zfs_replay_fuid_domain(start, &start,
464 lr->lr_uid, lr->lr_gid);
469 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
470 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
471 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
472 start = (caddr_t)(lr + 1) + xvatlen;
473 zfsvfs->z_fuid_replay =
474 zfs_replay_fuid_domain(start, &start,
475 lr->lr_uid, lr->lr_gid);
476 name = (char *)start;
481 name = (char *)start;
483 error = VOP_CREATE(ZTOV(dzp), name, &xva.xva_vattr,
484 0, 0, &vp, kcred, vflg, NULL, NULL);
487 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
488 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
489 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
490 start = (caddr_t)(lr + 1) + xvatlen;
491 zfsvfs->z_fuid_replay =
492 zfs_replay_fuid_domain(start, &start,
493 lr->lr_uid, lr->lr_gid);
494 name = (char *)start;
499 name = (char *)(lr + 1);
501 error = VOP_MKDIR(ZTOV(dzp), name, &xva.xva_vattr,
502 &vp, kcred, NULL, vflg, NULL);
505 error = zfs_make_xattrdir(dzp, &xva.xva_vattr, &vp, kcred);
508 name = (char *)(lr + 1);
509 link = name + strlen(name) + 1;
510 error = VOP_SYMLINK(ZTOV(dzp), name, &xva.xva_vattr,
511 link, kcred, NULL, vflg);
518 if (error == 0 && vp != NULL)
523 if (zfsvfs->z_fuid_replay)
524 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
525 zfsvfs->z_fuid_replay = NULL;
530 zfs_replay_remove(zfsvfs_t *zfsvfs, lr_remove_t *lr, boolean_t byteswap)
532 char *name = (char *)(lr + 1); /* name follows lr_remove_t */
538 byteswap_uint64_array(lr, sizeof (*lr));
540 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
543 if (lr->lr_common.lrc_txtype & TX_CI)
546 switch ((int)lr->lr_common.lrc_txtype) {
548 error = VOP_REMOVE(ZTOV(dzp), name, kcred, NULL, vflg);
551 error = VOP_RMDIR(ZTOV(dzp), name, NULL, kcred, NULL, vflg);
563 zfs_replay_link(zfsvfs_t *zfsvfs, lr_link_t *lr, boolean_t byteswap)
565 char *name = (char *)(lr + 1); /* name follows lr_link_t */
571 byteswap_uint64_array(lr, sizeof (*lr));
573 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
576 if ((error = zfs_zget(zfsvfs, lr->lr_link_obj, &zp)) != 0) {
581 if (lr->lr_common.lrc_txtype & TX_CI)
584 error = VOP_LINK(ZTOV(dzp), ZTOV(zp), name, kcred, NULL, vflg);
593 zfs_replay_rename(zfsvfs_t *zfsvfs, lr_rename_t *lr, boolean_t byteswap)
595 char *sname = (char *)(lr + 1); /* sname and tname follow lr_rename_t */
596 char *tname = sname + strlen(sname) + 1;
597 znode_t *sdzp, *tdzp;
602 byteswap_uint64_array(lr, sizeof (*lr));
604 if ((error = zfs_zget(zfsvfs, lr->lr_sdoid, &sdzp)) != 0)
607 if ((error = zfs_zget(zfsvfs, lr->lr_tdoid, &tdzp)) != 0) {
612 if (lr->lr_common.lrc_txtype & TX_CI)
615 error = VOP_RENAME(ZTOV(sdzp), sname, ZTOV(tdzp), tname, kcred,
625 zfs_replay_write(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
627 char *data = (char *)(lr + 1); /* data follows lr_write_t */
631 uint64_t eod, offset, length;
634 byteswap_uint64_array(lr, sizeof (*lr));
636 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
638 * As we can log writes out of order, it's possible the
639 * file has been removed. In this case just drop the write
640 * and return success.
647 offset = lr->lr_offset;
648 length = lr->lr_length;
649 eod = offset + length; /* end of data for this write */
652 * This may be a write from a dmu_sync() for a whole block,
653 * and may extend beyond the current end of the file.
654 * We can't just replay what was written for this TX_WRITE as
655 * a future TX_WRITE2 may extend the eof and the data for that
656 * write needs to be there. So we write the whole block and
657 * reduce the eof. This needs to be done within the single dmu
658 * transaction created within vn_rdwr -> zfs_write. So a possible
659 * new end of file is passed through in zfsvfs->z_replay_eof
662 zfsvfs->z_replay_eof = 0; /* 0 means don't change end of file */
664 /* If it's a dmu_sync() block, write the whole block */
665 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
666 uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr);
667 if (length < blocksize) {
668 offset -= offset % blocksize;
671 if (zp->z_size < eod)
672 zfsvfs->z_replay_eof = eod;
675 error = vn_rdwr(UIO_WRITE, ZTOV(zp), data, length, offset,
676 UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
679 zfsvfs->z_replay_eof = 0; /* safety */
685 * TX_WRITE2 are only generated when dmu_sync() returns EALREADY
686 * meaning the pool block is already being synced. So now that we always write
687 * out full blocks, all we have to do is expand the eof if
691 zfs_replay_write2(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
698 byteswap_uint64_array(lr, sizeof (*lr));
700 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
704 end = lr->lr_offset + lr->lr_length;
705 if (end > zp->z_size) {
706 dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
709 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
710 error = dmu_tx_assign(tx, TXG_WAIT);
713 if (error == ERESTART) {
721 (void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
722 (void *)&zp->z_size, sizeof (uint64_t), tx);
724 /* Ensure the replayed seq is updated */
725 (void) zil_replaying(zfsvfs->z_log, tx);
736 zfs_replay_truncate(zfsvfs_t *zfsvfs, lr_truncate_t *lr, boolean_t byteswap)
743 byteswap_uint64_array(lr, sizeof (*lr));
745 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
748 bzero(&fl, sizeof (fl));
751 fl.l_start = lr->lr_offset;
752 fl.l_len = lr->lr_length;
754 error = VOP_SPACE(ZTOV(zp), F_FREESP, &fl, FWRITE | FOFFMAX,
755 lr->lr_offset, kcred, NULL);
763 zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_setattr_t *lr, boolean_t byteswap)
767 vattr_t *vap = &xva.xva_vattr;
773 byteswap_uint64_array(lr, sizeof (*lr));
775 if ((lr->lr_mask & AT_XVATTR) &&
776 zfsvfs->z_version >= ZPL_VERSION_INITIAL)
777 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
780 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
783 zfs_init_vattr(vap, lr->lr_mask, lr->lr_mode,
784 lr->lr_uid, lr->lr_gid, 0, lr->lr_foid);
786 vap->va_size = lr->lr_size;
787 ZFS_TIME_DECODE(&vap->va_atime, lr->lr_atime);
788 ZFS_TIME_DECODE(&vap->va_mtime, lr->lr_mtime);
791 * Fill in xvattr_t portions if necessary.
794 start = (lr_setattr_t *)(lr + 1);
795 if (vap->va_mask & AT_XVATTR) {
796 zfs_replay_xvattr((lr_attr_t *)start, &xva);
797 start = (caddr_t)start +
798 ZIL_XVAT_SIZE(((lr_attr_t *)start)->lr_attr_masksize);
800 xva.xva_vattr.va_mask &= ~AT_XVATTR;
802 zfsvfs->z_fuid_replay = zfs_replay_fuid_domain(start, &start,
803 lr->lr_uid, lr->lr_gid);
805 error = VOP_SETATTR(ZTOV(zp), vap, 0, kcred, NULL);
807 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
808 zfsvfs->z_fuid_replay = NULL;
815 zfs_replay_acl_v0(zfsvfs_t *zfsvfs, lr_acl_v0_t *lr, boolean_t byteswap)
817 ace_t *ace = (ace_t *)(lr + 1); /* ace array follows lr_acl_t */
823 byteswap_uint64_array(lr, sizeof (*lr));
824 zfs_oldace_byteswap(ace, lr->lr_aclcnt);
827 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
830 bzero(&vsa, sizeof (vsa));
831 vsa.vsa_mask = VSA_ACE | VSA_ACECNT;
832 vsa.vsa_aclcnt = lr->lr_aclcnt;
833 vsa.vsa_aclentsz = sizeof (ace_t) * vsa.vsa_aclcnt;
834 vsa.vsa_aclflags = 0;
835 vsa.vsa_aclentp = ace;
837 error = VOP_SETSECATTR(ZTOV(zp), &vsa, 0, kcred, NULL);
845 * Replaying ACLs is complicated by FUID support.
846 * The log record may contain some optional data
847 * to be used for replaying FUID's. These pieces
848 * are the actual FUIDs that were created initially.
849 * The FUID table index may no longer be valid and
850 * during zfs_create() a new index may be assigned.
851 * Because of this the log will contain the original
852 * doman+rid in order to create a new FUID.
854 * The individual ACEs may contain an ephemeral uid/gid which is no
855 * longer valid and will need to be replaced with an actual FUID.
859 zfs_replay_acl(zfsvfs_t *zfsvfs, lr_acl_t *lr, boolean_t byteswap)
861 ace_t *ace = (ace_t *)(lr + 1);
867 byteswap_uint64_array(lr, sizeof (*lr));
868 zfs_ace_byteswap(ace, lr->lr_acl_bytes, B_FALSE);
869 if (lr->lr_fuidcnt) {
870 byteswap_uint64_array((caddr_t)ace +
871 ZIL_ACE_LENGTH(lr->lr_acl_bytes),
872 lr->lr_fuidcnt * sizeof (uint64_t));
876 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0)
879 bzero(&vsa, sizeof (vsa));
880 vsa.vsa_mask = VSA_ACE | VSA_ACECNT | VSA_ACE_ACLFLAGS;
881 vsa.vsa_aclcnt = lr->lr_aclcnt;
882 vsa.vsa_aclentp = ace;
883 vsa.vsa_aclentsz = lr->lr_acl_bytes;
884 vsa.vsa_aclflags = lr->lr_acl_flags;
886 if (lr->lr_fuidcnt) {
887 void *fuidstart = (caddr_t)ace +
888 ZIL_ACE_LENGTH(lr->lr_acl_bytes);
890 zfsvfs->z_fuid_replay =
891 zfs_replay_fuids(fuidstart, &fuidstart,
892 lr->lr_fuidcnt, lr->lr_domcnt, 0, 0);
895 error = VOP_SETSECATTR(ZTOV(zp), &vsa, 0, kcred, NULL);
897 if (zfsvfs->z_fuid_replay)
898 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
900 zfsvfs->z_fuid_replay = NULL;
907 * Callback vectors for replaying records
909 zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE] = {
910 zfs_replay_error, /* 0 no such transaction type */
911 zfs_replay_create, /* TX_CREATE */
912 zfs_replay_create, /* TX_MKDIR */
913 zfs_replay_create, /* TX_MKXATTR */
914 zfs_replay_create, /* TX_SYMLINK */
915 zfs_replay_remove, /* TX_REMOVE */
916 zfs_replay_remove, /* TX_RMDIR */
917 zfs_replay_link, /* TX_LINK */
918 zfs_replay_rename, /* TX_RENAME */
919 zfs_replay_write, /* TX_WRITE */
920 zfs_replay_truncate, /* TX_TRUNCATE */
921 zfs_replay_setattr, /* TX_SETATTR */
922 zfs_replay_acl_v0, /* TX_ACL_V0 */
923 zfs_replay_acl, /* TX_ACL */
924 zfs_replay_create_acl, /* TX_CREATE_ACL */
925 zfs_replay_create, /* TX_CREATE_ATTR */
926 zfs_replay_create_acl, /* TX_CREATE_ACL_ATTR */
927 zfs_replay_create_acl, /* TX_MKDIR_ACL */
928 zfs_replay_create, /* TX_MKDIR_ATTR */
929 zfs_replay_create_acl, /* TX_MKDIR_ACL_ATTR */
930 zfs_replay_write2, /* TX_WRITE2 */