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 };
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);
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 if (zfsvfs->z_fuid_replay)
406 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
407 zfsvfs->z_fuid_replay = NULL;
413 zfs_replay_create(zfsvfs_t *zfsvfs, lr_create_t *lr, boolean_t byteswap)
415 char *name = NULL; /* location determined later */
416 char *link; /* symlink content follows name */
421 size_t lrsize = sizeof (lr_create_t);
426 struct componentname cn;
429 txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
431 byteswap_uint64_array(lr, sizeof (*lr));
432 if (txtype == TX_CREATE_ATTR || txtype == TX_MKDIR_ATTR)
433 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
437 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
441 zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
442 lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
445 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
446 * eventually end up in zfs_mknode(), which assigns the object's
447 * creation time and generation number. The generic VOP_CREATE()
448 * doesn't have either concept, so we smuggle the values inside
449 * the vattr's otherwise unused va_ctime and va_nblocks fields.
451 ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
452 xva.xva_vattr.va_nblocks = lr->lr_gen;
454 error = dmu_object_info(zfsvfs->z_os, lr->lr_foid, NULL);
458 if (lr->lr_common.lrc_txtype & TX_CI)
462 * Symlinks don't have fuid info, and CIFS never creates
465 * The _ATTR versions will grab the fuid info in their subcases.
467 if ((int)lr->lr_common.lrc_txtype != TX_SYMLINK &&
468 (int)lr->lr_common.lrc_txtype != TX_MKDIR_ATTR &&
469 (int)lr->lr_common.lrc_txtype != TX_CREATE_ATTR) {
471 zfsvfs->z_fuid_replay =
472 zfs_replay_fuid_domain(start, &start,
473 lr->lr_uid, lr->lr_gid);
477 cn.cn_thread = curthread;
478 cn.cn_flags = SAVENAME;
480 vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY);
483 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
484 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
485 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
486 start = (caddr_t)(lr + 1) + xvatlen;
487 zfsvfs->z_fuid_replay =
488 zfs_replay_fuid_domain(start, &start,
489 lr->lr_uid, lr->lr_gid);
490 name = (char *)start;
495 name = (char *)start;
497 cn.cn_nameptr = name;
498 error = VOP_CREATE(ZTOV(dzp), &vp, &cn, &xva.xva_vattr /*,vflg*/);
501 lrattr = (lr_attr_t *)(caddr_t)(lr + 1);
502 xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
503 zfs_replay_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), &xva);
504 start = (caddr_t)(lr + 1) + xvatlen;
505 zfsvfs->z_fuid_replay =
506 zfs_replay_fuid_domain(start, &start,
507 lr->lr_uid, lr->lr_gid);
508 name = (char *)start;
513 name = (char *)(lr + 1);
515 cn.cn_nameptr = name;
516 error = VOP_MKDIR(ZTOV(dzp), &vp, &cn, &xva.xva_vattr /*,vflg*/);
519 name = (char *)(lr + 1);
520 error = zfs_make_xattrdir(dzp, &xva.xva_vattr, &vp, kcred);
523 name = (char *)(lr + 1);
524 link = name + strlen(name) + 1;
525 cn.cn_nameptr = name;
526 error = VOP_SYMLINK(ZTOV(dzp), &vp, &cn, &xva.xva_vattr, link /*,vflg*/);
531 VOP_UNLOCK(ZTOV(dzp), 0);
534 if (error == 0 && vp != NULL) {
541 if (zfsvfs->z_fuid_replay)
542 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
543 zfsvfs->z_fuid_replay = NULL;
548 zfs_replay_remove(zfsvfs_t *zfsvfs, lr_remove_t *lr, boolean_t byteswap)
550 char *name = (char *)(lr + 1); /* name follows lr_remove_t */
552 struct componentname cn;
558 byteswap_uint64_array(lr, sizeof (*lr));
560 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
563 if (lr->lr_common.lrc_txtype & TX_CI)
565 cn.cn_nameptr = name;
566 cn.cn_namelen = strlen(name);
567 cn.cn_nameiop = DELETE;
568 cn.cn_flags = ISLASTCN | SAVENAME;
569 cn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
571 cn.cn_thread = curthread;
572 vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY);
573 error = VOP_LOOKUP(ZTOV(dzp), &vp, &cn);
575 VOP_UNLOCK(ZTOV(dzp), 0);
579 switch ((int)lr->lr_common.lrc_txtype) {
581 error = VOP_REMOVE(ZTOV(dzp), vp, &cn /*,vflg*/);
584 error = VOP_RMDIR(ZTOV(dzp), vp, &cn /*,vflg*/);
590 VOP_UNLOCK(ZTOV(dzp), 0);
598 zfs_replay_link(zfsvfs_t *zfsvfs, lr_link_t *lr, boolean_t byteswap)
600 char *name = (char *)(lr + 1); /* name follows lr_link_t */
602 struct componentname cn;
607 byteswap_uint64_array(lr, sizeof (*lr));
609 if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
612 if ((error = zfs_zget(zfsvfs, lr->lr_link_obj, &zp)) != 0) {
617 if (lr->lr_common.lrc_txtype & TX_CI)
619 cn.cn_nameptr = name;
621 cn.cn_thread = curthread;
622 cn.cn_flags = SAVENAME;
624 vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY);
625 vn_lock(ZTOV(zp), LK_EXCLUSIVE | LK_RETRY);
626 error = VOP_LINK(ZTOV(dzp), ZTOV(zp), &cn /*,vflg*/);
627 VOP_UNLOCK(ZTOV(zp), 0);
628 VOP_UNLOCK(ZTOV(dzp), 0);
637 zfs_replay_rename(zfsvfs_t *zfsvfs, lr_rename_t *lr, boolean_t byteswap)
639 char *sname = (char *)(lr + 1); /* sname and tname follow lr_rename_t */
640 char *tname = sname + strlen(sname) + 1;
641 znode_t *sdzp, *tdzp;
642 struct componentname scn, tcn;
644 kthread_t *td = curthread;
649 byteswap_uint64_array(lr, sizeof (*lr));
651 if ((error = zfs_zget(zfsvfs, lr->lr_sdoid, &sdzp)) != 0)
654 if ((error = zfs_zget(zfsvfs, lr->lr_tdoid, &tdzp)) != 0) {
659 if (lr->lr_common.lrc_txtype & TX_CI)
663 scn.cn_nameptr = sname;
664 scn.cn_namelen = strlen(sname);
665 scn.cn_nameiop = DELETE;
666 scn.cn_flags = ISLASTCN | SAVENAME;
667 scn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
670 vn_lock(ZTOV(sdzp), LK_EXCLUSIVE | LK_RETRY);
671 error = VOP_LOOKUP(ZTOV(sdzp), &svp, &scn);
672 VOP_UNLOCK(ZTOV(sdzp), 0);
677 tcn.cn_nameptr = tname;
678 tcn.cn_namelen = strlen(tname);
679 tcn.cn_nameiop = RENAME;
680 tcn.cn_flags = ISLASTCN | SAVENAME;
681 tcn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
684 vn_lock(ZTOV(tdzp), LK_EXCLUSIVE | LK_RETRY);
685 error = VOP_LOOKUP(ZTOV(tdzp), &tvp, &tcn);
686 if (error == EJUSTRETURN)
688 else if (error != 0) {
689 VOP_UNLOCK(ZTOV(tdzp), 0);
693 error = VOP_RENAME(ZTOV(sdzp), svp, &scn, ZTOV(tdzp), tvp, &tcn /*,vflg*/);
707 zfs_replay_write(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
709 char *data = (char *)(lr + 1); /* data follows lr_write_t */
713 uint64_t orig_eof, eod;
716 byteswap_uint64_array(lr, sizeof (*lr));
718 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
720 * As we can log writes out of order, it's possible the
721 * file has been removed. In this case just drop the write
722 * and return success.
728 orig_eof = zp->z_phys->zp_size;
729 eod = lr->lr_offset + lr->lr_length; /* end of data for this write */
731 /* If it's a dmu_sync() block get the data and write the whole block */
732 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t))
733 zil_get_replay_data(zfsvfs->z_log, lr);
735 error = vn_rdwr(UIO_WRITE, ZTOV(zp), data, lr->lr_length,
736 lr->lr_offset, UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
739 * This may be a write from a dmu_sync() for a whole block,
740 * and may extend beyond the current end of the file.
741 * We can't just replay what was written for this TX_WRITE as
742 * a future TX_WRITE2 may extend the eof and the data for that
743 * write needs to be there. So we write the whole block and
746 if (orig_eof < zp->z_phys->zp_size) /* file length grew ? */
747 zp->z_phys->zp_size = eod;
755 * TX_WRITE2 are only generated when dmu_sync() returns EALREADY
756 * meaning the pool block is already being synced. So now that we always write
757 * out full blocks, all we have to do is expand the eof if
761 zfs_replay_write2(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap)
768 byteswap_uint64_array(lr, sizeof (*lr));
770 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
772 * As we can log writes out of order, it's possible the
773 * file has been removed. In this case just drop the write
774 * and return success.
781 end = lr->lr_offset + lr->lr_length;
782 if (end > zp->z_phys->zp_size) {
783 ASSERT3U(end - zp->z_phys->zp_size, <, zp->z_blksz);
784 zp->z_phys->zp_size = end;
793 zfs_replay_truncate(zfsvfs_t *zfsvfs, lr_truncate_t *lr, boolean_t byteswap)
796 ZFS_LOG(0, "Unexpected code path, report to pjd@FreeBSD.org");
801 zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_setattr_t *lr, boolean_t byteswap)
805 vattr_t *vap = &xva.xva_vattr;
812 byteswap_uint64_array(lr, sizeof (*lr));
814 if ((lr->lr_mask & AT_XVATTR) &&
815 zfsvfs->z_version >= ZPL_VERSION_INITIAL)
816 zfs_replay_swap_attrs((lr_attr_t *)(lr + 1));
819 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
821 * As we can log setattrs out of order, it's possible the
822 * file has been removed. In this case just drop the setattr
823 * and return success.
830 zfs_init_vattr(vap, lr->lr_mask, lr->lr_mode,
831 lr->lr_uid, lr->lr_gid, 0, lr->lr_foid);
833 vap->va_size = lr->lr_size;
834 ZFS_TIME_DECODE(&vap->va_atime, lr->lr_atime);
835 ZFS_TIME_DECODE(&vap->va_mtime, lr->lr_mtime);
838 * Fill in xvattr_t portions if necessary.
841 start = (lr_setattr_t *)(lr + 1);
842 if (vap->va_mask & AT_XVATTR) {
843 zfs_replay_xvattr((lr_attr_t *)start, &xva);
844 start = (caddr_t)start +
845 ZIL_XVAT_SIZE(((lr_attr_t *)start)->lr_attr_masksize);
847 xva.xva_vattr.va_mask &= ~AT_XVATTR;
849 zfsvfs->z_fuid_replay = zfs_replay_fuid_domain(start, &start,
850 lr->lr_uid, lr->lr_gid);
853 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
854 error = VOP_SETATTR(vp, vap, kcred);
857 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
858 zfsvfs->z_fuid_replay = NULL;
865 zfs_replay_acl_v0(zfsvfs_t *zfsvfs, lr_acl_v0_t *lr, boolean_t byteswap)
867 ace_t *ace = (ace_t *)(lr + 1); /* ace array follows lr_acl_t */
873 byteswap_uint64_array(lr, sizeof (*lr));
874 zfs_oldace_byteswap(ace, lr->lr_aclcnt);
877 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
879 * As we can log acls out of order, it's possible the
880 * file has been removed. In this case just drop the acl
881 * and return success.
888 bzero(&vsa, sizeof (vsa));
889 vsa.vsa_mask = VSA_ACE | VSA_ACECNT;
890 vsa.vsa_aclcnt = lr->lr_aclcnt;
891 vsa.vsa_aclentsz = sizeof (ace_t) * vsa.vsa_aclcnt;
892 vsa.vsa_aclflags = 0;
893 vsa.vsa_aclentp = ace;
896 error = VOP_SETSECATTR(ZTOV(zp), &vsa, 0, kcred, NULL);
898 panic("%s:%u: unsupported condition", __func__, __LINE__);
907 * Replaying ACLs is complicated by FUID support.
908 * The log record may contain some optional data
909 * to be used for replaying FUID's. These pieces
910 * are the actual FUIDs that were created initially.
911 * The FUID table index may no longer be valid and
912 * during zfs_create() a new index may be assigned.
913 * Because of this the log will contain the original
914 * doman+rid in order to create a new FUID.
916 * The individual ACEs may contain an ephemeral uid/gid which is no
917 * longer valid and will need to be replaced with an actual FUID.
921 zfs_replay_acl(zfsvfs_t *zfsvfs, lr_acl_t *lr, boolean_t byteswap)
923 ace_t *ace = (ace_t *)(lr + 1);
929 byteswap_uint64_array(lr, sizeof (*lr));
930 zfs_ace_byteswap(ace, lr->lr_acl_bytes, B_FALSE);
931 if (lr->lr_fuidcnt) {
932 byteswap_uint64_array((caddr_t)ace +
933 ZIL_ACE_LENGTH(lr->lr_acl_bytes),
934 lr->lr_fuidcnt * sizeof (uint64_t));
938 if ((error = zfs_zget(zfsvfs, lr->lr_foid, &zp)) != 0) {
940 * As we can log acls out of order, it's possible the
941 * file has been removed. In this case just drop the acl
942 * and return success.
950 bzero(&vsa, sizeof (vsa));
951 vsa.vsa_mask = VSA_ACE | VSA_ACECNT | VSA_ACE_ACLFLAGS;
952 vsa.vsa_aclcnt = lr->lr_aclcnt;
953 vsa.vsa_aclentp = ace;
954 vsa.vsa_aclentsz = lr->lr_acl_bytes;
955 vsa.vsa_aclflags = lr->lr_acl_flags;
957 if (lr->lr_fuidcnt) {
958 void *fuidstart = (caddr_t)ace +
959 ZIL_ACE_LENGTH(lr->lr_acl_bytes);
961 zfsvfs->z_fuid_replay =
962 zfs_replay_fuids(fuidstart, &fuidstart,
963 lr->lr_fuidcnt, lr->lr_domcnt, 0, 0);
966 error = VOP_SETSECATTR(ZTOV(zp), &vsa, 0, kcred, NULL);
968 if (zfsvfs->z_fuid_replay)
969 zfs_fuid_info_free(zfsvfs->z_fuid_replay);
974 zfsvfs->z_fuid_replay = NULL;
981 * Callback vectors for replaying records
983 zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE] = {
984 zfs_replay_error, /* 0 no such transaction type */
985 zfs_replay_create, /* TX_CREATE */
986 zfs_replay_create, /* TX_MKDIR */
987 zfs_replay_create, /* TX_MKXATTR */
988 zfs_replay_create, /* TX_SYMLINK */
989 zfs_replay_remove, /* TX_REMOVE */
990 zfs_replay_remove, /* TX_RMDIR */
991 zfs_replay_link, /* TX_LINK */
992 zfs_replay_rename, /* TX_RENAME */
993 zfs_replay_write, /* TX_WRITE */
994 zfs_replay_truncate, /* TX_TRUNCATE */
995 zfs_replay_setattr, /* TX_SETATTR */
996 zfs_replay_acl_v0, /* TX_ACL_V0 */
997 zfs_replay_acl, /* TX_ACL */
998 zfs_replay_create_acl, /* TX_CREATE_ACL */
999 zfs_replay_create, /* TX_CREATE_ATTR */
1000 zfs_replay_create_acl, /* TX_CREATE_ACL_ATTR */
1001 zfs_replay_create_acl, /* TX_MKDIR_ACL */
1002 zfs_replay_create, /* TX_MKDIR_ATTR */
1003 zfs_replay_create_acl, /* TX_MKDIR_ACL_ATTR */
1004 zfs_replay_write2, /* TX_WRITE2 */