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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/sysmacros.h>
32 #include <sys/cmn_err.h>
35 #include <sys/fcntl.h>
37 #include <sys/fs/zfs.h>
38 #include <sys/zfs_znode.h>
39 #include <sys/zfs_dir.h>
40 #include <sys/zfs_acl.h>
41 #include <sys/zfs_fuid.h>
44 #include <sys/byteorder.h>
47 #include <sys/atomic.h>
49 #include <sys/namei.h>
52 * Functions to replay ZFS intent log (ZIL) records
53 * The functions are called through a function vector (zfs_replay_vector)
54 * which is indexed by the transaction type.
58 zfs_init_vattr(vattr_t *vap, uint64_t mask, uint64_t mode,
59 uint64_t uid, uint64_t gid, uint64_t rdev, uint64_t nodeid)
62 vap->va_mask = (uint_t)mask;
64 vap->va_type = IFTOVT(mode);
66 vap->va_mode = mode & MODEMASK;
68 vap->va_uid = (uid_t)(IS_EPHEMERAL(uid)) ? -1 : uid;
70 vap->va_gid = (gid_t)(IS_EPHEMERAL(gid)) ? -1 : gid;
71 vap->va_rdev = zfs_cmpldev(rdev);
72 vap->va_nodeid = nodeid;
77 zfs_replay_error(zfsvfs_t *zfsvfs, lr_t *lr, boolean_t byteswap)
83 zfs_replay_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
85 xoptattr_t *xoap = NULL;
92 xvap->xva_vattr.va_mask |= AT_XVATTR;
93 if ((xoap = xva_getxoptattr(xvap)) == NULL) {
94 xvap->xva_vattr.va_mask &= ~AT_XVATTR; /* shouldn't happen */
98 ASSERT(lrattr->lr_attr_masksize == xvap->xva_mapsize);
100 bitmap = &lrattr->lr_attr_bitmap;
101 for (i = 0; i != lrattr->lr_attr_masksize; i++, bitmap++)
102 xvap->xva_reqattrmap[i] = *bitmap;
104 attrs = (uint64_t *)(lrattr + lrattr->lr_attr_masksize - 1);
106 scanstamp = (caddr_t)(crtime + 2);
108 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
109 xoap->xoa_hidden = ((*attrs & XAT0_HIDDEN) != 0);
110 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
111 xoap->xoa_system = ((*attrs & XAT0_SYSTEM) != 0);
112 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
113 xoap->xoa_archive = ((*attrs & XAT0_ARCHIVE) != 0);
114 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
115 xoap->xoa_readonly = ((*attrs & XAT0_READONLY) != 0);
116 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
117 xoap->xoa_immutable = ((*attrs & XAT0_IMMUTABLE) != 0);
118 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
119 xoap->xoa_nounlink = ((*attrs & XAT0_NOUNLINK) != 0);
120 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
121 xoap->xoa_appendonly = ((*attrs & XAT0_APPENDONLY) != 0);
122 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
123 xoap->xoa_nodump = ((*attrs & XAT0_NODUMP) != 0);
124 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
125 xoap->xoa_opaque = ((*attrs & XAT0_OPAQUE) != 0);
126 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
127 xoap->xoa_av_modified = ((*attrs & XAT0_AV_MODIFIED) != 0);
128 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
129 xoap->xoa_av_quarantined =
130 ((*attrs & XAT0_AV_QUARANTINED) != 0);
131 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
132 ZFS_TIME_DECODE(&xoap->xoa_createtime, crtime);
133 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
134 bcopy(scanstamp, xoap->xoa_av_scanstamp, AV_SCANSTAMP_SZ);
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 };
282 byteswap_uint64_array(lracl, sizeof (*lracl));
283 txtype = (int)lr->lr_common.lrc_txtype;
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)
324 switch ((int)lr->lr_common.lrc_txtype) {
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);
355 error = VOP_CREATE(ZTOV(dzp), name, &xva.xva_vattr,
356 0, 0, &vp, kcred, vflg, NULL, &vsec);
358 panic("%s:%u: unsupported condition", __func__, __LINE__);
362 aclstart = (caddr_t)(lracl + 1);
363 fuidstart = (caddr_t)aclstart +
364 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
365 zfsvfs->z_fuid_replay = zfs_replay_fuids(fuidstart,
366 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
367 lr->lr_uid, lr->lr_gid);
369 case TX_MKDIR_ACL_ATTR:
371 lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
372 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
373 zfs_replay_xvattr(lrattr, &xva);
375 vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
376 vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
377 vsec.vsa_aclcnt = lracl->lr_aclcnt;
378 vsec.vsa_aclentsz = lracl->lr_acl_bytes;
379 vsec.vsa_aclflags = lracl->lr_acl_flags;
380 if (zfsvfs->z_fuid_replay == NULL) {
381 fuidstart = (caddr_t)(lracl + 1) + xvatlen +
382 ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
383 zfsvfs->z_fuid_replay =
384 zfs_replay_fuids(fuidstart,
385 (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
386 lr->lr_uid, lr->lr_gid);
389 error = VOP_MKDIR(ZTOV(dzp), name, &xva.xva_vattr,
390 &vp, kcred, NULL, vflg, &vsec);
392 panic("%s:%u: unsupported condition", __func__, __LINE__);
400 if (error == 0 && vp != NULL)
405 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
406 zfsvfs->z_fuid_replay = NULL;
412 zfs_replay_create(zfsvfs_t *zfsvfs, lr_create_t *lr, boolean_t byteswap)
414 char *name = NULL; /* location determined later */
415 char *link; /* symlink content follows name */
420 size_t lrsize = sizeof (lr_create_t);
425 struct componentname cn;
429 byteswap_uint64_array(lr, sizeof (*lr));
430 txtype = (int)lr->lr_common.lrc_txtype;
431 if (txtype == TX_CREATE_ATTR || txtype == TX_MKDIR_ATTR)
432 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
436 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
440 zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
441 lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
444 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
445 * eventually end up in zfs_mknode(), which assigns the object's
446 * creation time and generation number. The generic VOP_CREATE()
447 * doesn't have either concept, so we smuggle the values inside
448 * the vattr's otherwise unused va_ctime and va_nblocks fields.
450 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
451 xva.xva_vattr.va_nblocks = lr->lr_gen;
453 error = dmu_object_info(zfsvfs->z_os, lr->lr_foid, NULL);
457 if (lr->lr_common.lrc_txtype & TX_CI)
461 * Symlinks don't have fuid info, and CIFS never creates
464 * The _ATTR versions will grab the fuid info in their subcases.
466 if ((int)lr->lr_common.lrc_txtype != TX_SYMLINK &&
467 (int)lr->lr_common.lrc_txtype != TX_MKDIR_ATTR &&
468 (int)lr->lr_common.lrc_txtype != TX_CREATE_ATTR) {
470 zfsvfs->z_fuid_replay =
471 zfs_replay_fuid_domain(start, &start,
472 lr->lr_uid, lr->lr_gid);
476 cn.cn_thread = curthread;
477 cn.cn_flags = SAVENAME;
479 vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY);
480 switch ((int)lr->lr_common.lrc_txtype) {
482 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
483 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
484 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
485 start = (caddr_t)(lr + 1) + xvatlen;
486 zfsvfs->z_fuid_replay =
487 zfs_replay_fuid_domain(start, &start,
488 lr->lr_uid, lr->lr_gid);
489 name = (char *)start;
494 name = (char *)start;
496 cn.cn_nameptr = name;
497 error = VOP_CREATE(ZTOV(dzp), &vp, &cn, &xva.xva_vattr /*,vflg*/);
500 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
501 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
502 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
503 start = (caddr_t)(lr + 1) + xvatlen;
504 zfsvfs->z_fuid_replay =
505 zfs_replay_fuid_domain(start, &start,
506 lr->lr_uid, lr->lr_gid);
507 name = (char *)start;
512 name = (char *)(lr + 1);
514 cn.cn_nameptr = name;
515 error = VOP_MKDIR(ZTOV(dzp), &vp, &cn, &xva.xva_vattr /*,vflg*/);
518 name = (char *)(lr + 1);
519 error = zfs_make_xattrdir(dzp, &xva.xva_vattr, &vp, kcred);
522 name = (char *)(lr + 1);
523 link = name + strlen(name) + 1;
524 cn.cn_nameptr = name;
525 error = VOP_SYMLINK(ZTOV(dzp), &vp, &cn, &xva.xva_vattr, link /*,vflg*/);
530 VOP_UNLOCK(ZTOV(dzp), 0);
533 if (error == 0 && vp != NULL) {
540 if (zfsvfs->z_fuid_replay)
541 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
542 zfsvfs->z_fuid_replay = NULL;
547 zfs_replay_remove(zfsvfs_t *zfsvfs, lr_remove_t *lr, boolean_t byteswap)
549 char *name = (char *)(lr + 1); /* name follows lr_remove_t */
551 struct componentname cn;
557 byteswap_uint64_array(lr, sizeof (*lr));
559 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
562 if (lr->lr_common.lrc_txtype & TX_CI)
564 cn.cn_nameptr = name;
565 cn.cn_namelen = strlen(name);
566 cn.cn_nameiop = DELETE;
567 cn.cn_flags = ISLASTCN | SAVENAME;
568 cn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
570 cn.cn_thread = curthread;
571 vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY);
572 error = VOP_LOOKUP(ZTOV(dzp), &vp, &cn);
574 VOP_UNLOCK(ZTOV(dzp), 0);
578 switch ((int)lr->lr_common.lrc_txtype) {
580 error = VOP_REMOVE(ZTOV(dzp), vp, &cn /*,vflg*/);
583 error = VOP_RMDIR(ZTOV(dzp), vp, &cn /*,vflg*/);
589 VOP_UNLOCK(ZTOV(dzp), 0);
597 zfs_replay_link(zfsvfs_t *zfsvfs, lr_link_t *lr, boolean_t byteswap)
599 char *name = (char *)(lr + 1); /* name follows lr_link_t */
601 struct componentname cn;
606 byteswap_uint64_array(lr, sizeof (*lr));
608 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
611 if ((error = zfs_zget(zfsvfs, lr->lr_link_obj, &zp)) != 0) {
616 if (lr->lr_common.lrc_txtype & TX_CI)
618 cn.cn_nameptr = name;
620 cn.cn_thread = curthread;
621 cn.cn_flags = SAVENAME;
623 vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY);
624 vn_lock(ZTOV(zp), LK_EXCLUSIVE | LK_RETRY);
625 error = VOP_LINK(ZTOV(dzp), ZTOV(zp), &cn /*,vflg*/);
626 VOP_UNLOCK(ZTOV(zp), 0);
627 VOP_UNLOCK(ZTOV(dzp), 0);
636 zfs_replay_rename(zfsvfs_t *zfsvfs, lr_rename_t *lr, boolean_t byteswap)
638 char *sname = (char *)(lr + 1); /* sname and tname follow lr_rename_t */
639 char *tname = sname + strlen(sname) + 1;
640 znode_t *sdzp, *tdzp;
641 struct componentname scn, tcn;
643 kthread_t *td = curthread;
648 byteswap_uint64_array(lr, sizeof (*lr));
650 if ((error = zfs_zget(zfsvfs, lr->lr_sdoid, &sdzp)) != 0)
653 if ((error = zfs_zget(zfsvfs, lr->lr_tdoid, &tdzp)) != 0) {
658 if (lr->lr_common.lrc_txtype & TX_CI)
662 scn.cn_nameptr = sname;
663 scn.cn_namelen = strlen(sname);
664 scn.cn_nameiop = DELETE;
665 scn.cn_flags = ISLASTCN | SAVENAME;
666 scn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
669 vn_lock(ZTOV(sdzp), LK_EXCLUSIVE | LK_RETRY);
670 error = VOP_LOOKUP(ZTOV(sdzp), &svp, &scn);
671 VOP_UNLOCK(ZTOV(sdzp), 0);
676 tcn.cn_nameptr = tname;
677 tcn.cn_namelen = strlen(tname);
678 tcn.cn_nameiop = RENAME;
679 tcn.cn_flags = ISLASTCN | SAVENAME;
680 tcn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
683 vn_lock(ZTOV(tdzp), LK_EXCLUSIVE | LK_RETRY);
684 error = VOP_LOOKUP(ZTOV(tdzp), &tvp, &tcn);
685 if (error == EJUSTRETURN)
687 else if (error != 0) {
688 VOP_UNLOCK(ZTOV(tdzp), 0);
692 error = VOP_RENAME(ZTOV(sdzp), svp, &scn, ZTOV(tdzp), tvp, &tcn /*,vflg*/);
706 zfs_replay_write(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
708 char *data = (char *)(lr + 1); /* data follows lr_write_t */
714 byteswap_uint64_array(lr, sizeof (*lr));
716 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
718 * As we can log writes out of order, it's possible the
719 * file has been removed. In this case just drop the write
720 * and return success.
727 error = vn_rdwr(UIO_WRITE, ZTOV(zp), data, lr->lr_length,
728 lr->lr_offset, UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
736 zfs_replay_truncate(zfsvfs_t *zfsvfs, lr_truncate_t *lr, boolean_t byteswap)
739 ZFS_LOG(0, "Unexpected code path, report to pjd@FreeBSD.org");
744 zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_setattr_t *lr, boolean_t byteswap)
748 vattr_t *vap = &xva.xva_vattr;
755 byteswap_uint64_array(lr, sizeof (*lr));
757 if ((lr->lr_mask & AT_XVATTR) &&
758 zfsvfs->z_version >= ZPL_VERSION_INITIAL)
759 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
762 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
764 * As we can log setattrs out of order, it's possible the
765 * file has been removed. In this case just drop the setattr
766 * and return success.
773 zfs_init_vattr(vap, lr->lr_mask, lr->lr_mode,
774 lr->lr_uid, lr->lr_gid, 0, lr->lr_foid);
776 vap->va_size = lr->lr_size;
777 ZFS_TIME_DECODE(&vap->va_atime, lr->lr_atime);
778 ZFS_TIME_DECODE(&vap->va_mtime, lr->lr_mtime);
781 * Fill in xvattr_t portions if necessary.
784 start = (lr_setattr_t *)(lr + 1);
785 if (vap->va_mask & AT_XVATTR) {
786 zfs_replay_xvattr((lr_attr_t *)start, &xva);
787 start = (caddr_t)start +
788 ZIL_XVAT_SIZE(((lr_attr_t *)start)->lr_attr_masksize);
790 xva.xva_vattr.va_mask &= ~AT_XVATTR;
792 zfsvfs->z_fuid_replay = zfs_replay_fuid_domain(start, &start,
793 lr->lr_uid, lr->lr_gid);
796 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
797 error = VOP_SETATTR(vp, vap, kcred);
800 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
801 zfsvfs->z_fuid_replay = NULL;
808 zfs_replay_acl_v0(zfsvfs_t *zfsvfs, lr_acl_v0_t *lr, boolean_t byteswap)
810 ace_t *ace = (ace_t *)(lr + 1); /* ace array follows lr_acl_t */
816 byteswap_uint64_array(lr, sizeof (*lr));
817 zfs_oldace_byteswap(ace, lr->lr_aclcnt);
820 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
822 * As we can log acls out of order, it's possible the
823 * file has been removed. In this case just drop the acl
824 * and return success.
831 bzero(&vsa, sizeof (vsa));
832 vsa.vsa_mask = VSA_ACE | VSA_ACECNT;
833 vsa.vsa_aclcnt = lr->lr_aclcnt;
834 vsa.vsa_aclentsz = sizeof (ace_t) * vsa.vsa_aclcnt;
835 vsa.vsa_aclflags = 0;
836 vsa.vsa_aclentp = ace;
839 error = VOP_SETSECATTR(ZTOV(zp), &vsa, 0, kcred, NULL);
841 panic("%s:%u: unsupported condition", __func__, __LINE__);
850 * Replaying ACLs is complicated by FUID support.
851 * The log record may contain some optional data
852 * to be used for replaying FUID's. These pieces
853 * are the actual FUIDs that were created initially.
854 * The FUID table index may no longer be valid and
855 * during zfs_create() a new index may be assigned.
856 * Because of this the log will contain the original
857 * doman+rid in order to create a new FUID.
859 * The individual ACEs may contain an ephemeral uid/gid which is no
860 * longer valid and will need to be replaced with an actual FUID.
864 zfs_replay_acl(zfsvfs_t *zfsvfs, lr_acl_t *lr, boolean_t byteswap)
866 ace_t *ace = (ace_t *)(lr + 1);
872 byteswap_uint64_array(lr, sizeof (*lr));
873 zfs_ace_byteswap(ace, lr->lr_acl_bytes, B_FALSE);
874 if (lr->lr_fuidcnt) {
875 byteswap_uint64_array((caddr_t)ace +
876 ZIL_ACE_LENGTH(lr->lr_acl_bytes),
877 lr->lr_fuidcnt * sizeof (uint64_t));
881 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
883 * As we can log acls out of order, it's possible the
884 * file has been removed. In this case just drop the acl
885 * and return success.
893 bzero(&vsa, sizeof (vsa));
894 vsa.vsa_mask = VSA_ACE | VSA_ACECNT | VSA_ACE_ACLFLAGS;
895 vsa.vsa_aclcnt = lr->lr_aclcnt;
896 vsa.vsa_aclentp = ace;
897 vsa.vsa_aclentsz = lr->lr_acl_bytes;
898 vsa.vsa_aclflags = lr->lr_acl_flags;
900 if (lr->lr_fuidcnt) {
901 void *fuidstart = (caddr_t)ace +
902 ZIL_ACE_LENGTH(lr->lr_acl_bytes);
904 zfsvfs->z_fuid_replay =
905 zfs_replay_fuids(fuidstart, &fuidstart,
906 lr->lr_fuidcnt, lr->lr_domcnt, 0, 0);
909 error = VOP_SETSECATTR(ZTOV(zp), &vsa, 0, kcred, NULL);
911 if (zfsvfs->z_fuid_replay)
912 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
917 zfsvfs->z_fuid_replay = NULL;
924 * Callback vectors for replaying records
926 zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE] = {
927 zfs_replay_error, /* 0 no such transaction type */
928 zfs_replay_create, /* TX_CREATE */
929 zfs_replay_create, /* TX_MKDIR */
930 zfs_replay_create, /* TX_MKXATTR */
931 zfs_replay_create, /* TX_SYMLINK */
932 zfs_replay_remove, /* TX_REMOVE */
933 zfs_replay_remove, /* TX_RMDIR */
934 zfs_replay_link, /* TX_LINK */
935 zfs_replay_rename, /* TX_RENAME */
936 zfs_replay_write, /* TX_WRITE */
937 zfs_replay_truncate, /* TX_TRUNCATE */
938 zfs_replay_setattr, /* TX_SETATTR */
939 zfs_replay_acl_v0, /* TX_ACL_V0 */
940 zfs_replay_acl, /* TX_ACL */
941 zfs_replay_create_acl, /* TX_CREATE_ACL */
942 zfs_replay_create, /* TX_CREATE_ATTR */
943 zfs_replay_create_acl, /* TX_CREATE_ACL_ATTR */
944 zfs_replay_create_acl, /* TX_MKDIR_ACL */
945 zfs_replay_create, /* TX_MKDIR_ATTR */
946 zfs_replay_create_acl, /* TX_MKDIR_ACL_ATTR */