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
;
63 vap
->va_type
= IFTOVT(mode
);
64 vap
->va_mode
= mode
& MODEMASK
;
65 vap
->va_uid
= (uid_t
)(IS_EPHEMERAL(uid
)) ? -1 : uid
;
66 vap
->va_gid
= (gid_t
)(IS_EPHEMERAL(gid
)) ? -1 : gid
;
67 vap
->va_rdev
= zfs_cmpldev(rdev
);
68 vap
->va_nodeid
= nodeid
;
73 zfs_replay_error(zfsvfs_t
*zfsvfs
, lr_t
*lr
, boolean_t byteswap
)
79 zfs_replay_xvattr(lr_attr_t
*lrattr
, xvattr_t
*xvap
)
81 xoptattr_t
*xoap
= NULL
;
88 xvap
->xva_vattr
.va_mask
|= AT_XVATTR
;
89 if ((xoap
= xva_getxoptattr(xvap
)) == NULL
) {
90 xvap
->xva_vattr
.va_mask
&= ~AT_XVATTR
; /* shouldn't happen */
94 ASSERT(lrattr
->lr_attr_masksize
== xvap
->xva_mapsize
);
96 bitmap
= &lrattr
->lr_attr_bitmap
;
97 for (i
= 0; i
!= lrattr
->lr_attr_masksize
; i
++, bitmap
++)
98 xvap
->xva_reqattrmap
[i
] = *bitmap
;
100 attrs
= (uint64_t *)(lrattr
+ lrattr
->lr_attr_masksize
- 1);
102 scanstamp
= (caddr_t
)(crtime
+ 2);
104 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
))
105 xoap
->xoa_hidden
= ((*attrs
& XAT0_HIDDEN
) != 0);
106 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
))
107 xoap
->xoa_system
= ((*attrs
& XAT0_SYSTEM
) != 0);
108 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
))
109 xoap
->xoa_archive
= ((*attrs
& XAT0_ARCHIVE
) != 0);
110 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
))
111 xoap
->xoa_readonly
= ((*attrs
& XAT0_READONLY
) != 0);
112 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
))
113 xoap
->xoa_immutable
= ((*attrs
& XAT0_IMMUTABLE
) != 0);
114 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
))
115 xoap
->xoa_nounlink
= ((*attrs
& XAT0_NOUNLINK
) != 0);
116 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
))
117 xoap
->xoa_appendonly
= ((*attrs
& XAT0_APPENDONLY
) != 0);
118 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
))
119 xoap
->xoa_nodump
= ((*attrs
& XAT0_NODUMP
) != 0);
120 if (XVA_ISSET_REQ(xvap
, XAT_OPAQUE
))
121 xoap
->xoa_opaque
= ((*attrs
& XAT0_OPAQUE
) != 0);
122 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
))
123 xoap
->xoa_av_modified
= ((*attrs
& XAT0_AV_MODIFIED
) != 0);
124 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
))
125 xoap
->xoa_av_quarantined
=
126 ((*attrs
& XAT0_AV_QUARANTINED
) != 0);
127 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
))
128 ZFS_TIME_DECODE(&xoap
->xoa_createtime
, crtime
);
129 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
))
130 bcopy(scanstamp
, xoap
->xoa_av_scanstamp
, AV_SCANSTAMP_SZ
);
134 zfs_replay_domain_cnt(uint64_t uid
, uint64_t gid
)
140 uid_idx
= FUID_INDEX(uid
);
141 gid_idx
= FUID_INDEX(gid
);
144 if (gid_idx
> 0 && gid_idx
!= uid_idx
)
151 zfs_replay_fuid_domain_common(zfs_fuid_info_t
*fuid_infop
, void *start
,
156 for (i
= 0; i
!= domcnt
; i
++) {
157 fuid_infop
->z_domain_table
[i
] = start
;
158 start
= (caddr_t
)start
+ strlen(start
) + 1;
165 * Set the uid/gid in the fuid_info structure.
168 zfs_replay_fuid_ugid(zfs_fuid_info_t
*fuid_infop
, uint64_t uid
, uint64_t gid
)
171 * If owner or group are log specific FUIDs then slurp up
172 * domain information and build zfs_fuid_info_t
174 if (IS_EPHEMERAL(uid
))
175 fuid_infop
->z_fuid_owner
= uid
;
177 if (IS_EPHEMERAL(gid
))
178 fuid_infop
->z_fuid_group
= gid
;
182 * Load fuid domains into fuid_info_t
184 static zfs_fuid_info_t
*
185 zfs_replay_fuid_domain(void *buf
, void **end
, uint64_t uid
, uint64_t gid
)
189 zfs_fuid_info_t
*fuid_infop
;
191 fuid_infop
= zfs_fuid_info_alloc();
193 domcnt
= zfs_replay_domain_cnt(uid
, gid
);
198 fuid_infop
->z_domain_table
=
199 kmem_zalloc(domcnt
* sizeof (char **), KM_SLEEP
);
201 zfs_replay_fuid_ugid(fuid_infop
, uid
, gid
);
203 fuid_infop
->z_domain_cnt
= domcnt
;
204 *end
= zfs_replay_fuid_domain_common(fuid_infop
, buf
, domcnt
);
209 * load zfs_fuid_t's and fuid_domains into fuid_info_t
211 static zfs_fuid_info_t
*
212 zfs_replay_fuids(void *start
, void **end
, int idcnt
, int domcnt
, uint64_t uid
,
215 uint64_t *log_fuid
= (uint64_t *)start
;
216 zfs_fuid_info_t
*fuid_infop
;
219 fuid_infop
= zfs_fuid_info_alloc();
220 fuid_infop
->z_domain_cnt
= domcnt
;
222 fuid_infop
->z_domain_table
=
223 kmem_zalloc(domcnt
* sizeof (char **), KM_SLEEP
);
225 for (i
= 0; i
!= idcnt
; i
++) {
228 zfuid
= kmem_alloc(sizeof (zfs_fuid_t
), KM_SLEEP
);
229 zfuid
->z_logfuid
= *log_fuid
;
232 list_insert_tail(&fuid_infop
->z_fuids
, zfuid
);
236 zfs_replay_fuid_ugid(fuid_infop
, uid
, gid
);
238 *end
= zfs_replay_fuid_domain_common(fuid_infop
, log_fuid
, domcnt
);
243 zfs_replay_swap_attrs(lr_attr_t
*lrattr
)
245 /* swap the lr_attr structure */
246 byteswap_uint32_array(lrattr
, sizeof (*lrattr
));
247 /* swap the bitmap */
248 byteswap_uint32_array(lrattr
+ 1, (lrattr
->lr_attr_masksize
- 1) *
250 /* swap the attributes, create time + 64 bit word for attributes */
251 byteswap_uint64_array((caddr_t
)(lrattr
+ 1) + (sizeof (uint32_t) *
252 (lrattr
->lr_attr_masksize
- 1)), 3 * sizeof (uint64_t));
256 * Replay file create with optional ACL, xvattr information as well
257 * as option FUID information.
260 zfs_replay_create_acl(zfsvfs_t
*zfsvfs
,
261 lr_acl_create_t
*lracl
, boolean_t byteswap
)
263 char *name
= NULL
; /* location determined later */
264 lr_create_t
*lr
= (lr_create_t
*)lracl
;
269 vsecattr_t vsec
= { 0 };
278 byteswap_uint64_array(lracl
, sizeof (*lracl
));
279 txtype
= (int)lr
->lr_common
.lrc_txtype
;
280 if (txtype
== TX_CREATE_ACL_ATTR
||
281 txtype
== TX_MKDIR_ACL_ATTR
) {
282 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
283 zfs_replay_swap_attrs(lrattr
);
284 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
287 aclstart
= (caddr_t
)(lracl
+ 1) + xvatlen
;
288 zfs_ace_byteswap(aclstart
, lracl
->lr_acl_bytes
, B_FALSE
);
290 if (lracl
->lr_fuidcnt
) {
291 byteswap_uint64_array((caddr_t
)aclstart
+
292 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
),
293 lracl
->lr_fuidcnt
* sizeof (uint64_t));
297 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
301 zfs_init_vattr(&xva
.xva_vattr
, AT_TYPE
| AT_MODE
| AT_UID
| AT_GID
,
302 lr
->lr_mode
, lr
->lr_uid
, lr
->lr_gid
, lr
->lr_rdev
, lr
->lr_foid
);
305 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
306 * eventually end up in zfs_mknode(), which assigns the object's
307 * creation time and generation number. The generic VOP_CREATE()
308 * doesn't have either concept, so we smuggle the values inside
309 * the vattr's otherwise unused va_ctime and va_nblocks fields.
311 ZFS_TIME_DECODE(&xva
.xva_vattr
.va_ctime
, lr
->lr_crtime
);
312 xva
.xva_vattr
.va_nblocks
= lr
->lr_gen
;
314 error
= dmu_object_info(zfsvfs
->z_os
, lr
->lr_foid
, NULL
);
318 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
320 switch ((int)lr
->lr_common
.lrc_txtype
) {
322 aclstart
= (caddr_t
)(lracl
+ 1);
323 fuidstart
= (caddr_t
)aclstart
+
324 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
325 zfsvfs
->z_fuid_replay
= zfs_replay_fuids(fuidstart
,
326 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
327 lr
->lr_uid
, lr
->lr_gid
);
329 case TX_CREATE_ACL_ATTR
:
331 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
332 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
333 xva
.xva_vattr
.va_mask
|= AT_XVATTR
;
334 zfs_replay_xvattr(lrattr
, &xva
);
336 vsec
.vsa_mask
= VSA_ACE
| VSA_ACE_ACLFLAGS
;
337 vsec
.vsa_aclentp
= (caddr_t
)(lracl
+ 1) + xvatlen
;
338 vsec
.vsa_aclcnt
= lracl
->lr_aclcnt
;
339 vsec
.vsa_aclentsz
= lracl
->lr_acl_bytes
;
340 vsec
.vsa_aclflags
= lracl
->lr_acl_flags
;
341 if (zfsvfs
->z_fuid_replay
== NULL
) {
342 fuidstart
= (caddr_t
)(lracl
+ 1) + xvatlen
+
343 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
344 zfsvfs
->z_fuid_replay
=
345 zfs_replay_fuids(fuidstart
,
346 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
347 lr
->lr_uid
, lr
->lr_gid
);
351 error
= VOP_CREATE(ZTOV(dzp
), name
, &xva
.xva_vattr
,
352 0, 0, &vp
, kcred
, vflg
, NULL
, &vsec
);
354 panic("%s:%u: unsupported condition", __func__
, __LINE__
);
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
);
385 error
= VOP_MKDIR(ZTOV(dzp
), name
, &xva
.xva_vattr
,
386 &vp
, kcred
, NULL
, vflg
, &vsec
);
388 panic("%s:%u: unsupported condition", __func__
, __LINE__
);
396 if (error
== 0 && vp
!= NULL
)
401 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
402 zfsvfs
->z_fuid_replay
= NULL
;
408 zfs_replay_create(zfsvfs_t
*zfsvfs
, lr_create_t
*lr
, boolean_t byteswap
)
410 char *name
= NULL
; /* location determined later */
411 char *link
; /* symlink content follows name */
416 size_t lrsize
= sizeof (lr_create_t
);
421 struct componentname cn
;
425 byteswap_uint64_array(lr
, sizeof (*lr
));
426 txtype
= (int)lr
->lr_common
.lrc_txtype
;
427 if (txtype
== TX_CREATE_ATTR
|| txtype
== TX_MKDIR_ATTR
)
428 zfs_replay_swap_attrs((lr_attr_t
*)(lr
+ 1));
432 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
436 zfs_init_vattr(&xva
.xva_vattr
, AT_TYPE
| AT_MODE
| AT_UID
| AT_GID
,
437 lr
->lr_mode
, lr
->lr_uid
, lr
->lr_gid
, lr
->lr_rdev
, lr
->lr_foid
);
440 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
441 * eventually end up in zfs_mknode(), which assigns the object's
442 * creation time and generation number. The generic VOP_CREATE()
443 * doesn't have either concept, so we smuggle the values inside
444 * the vattr's otherwise unused va_ctime and va_nblocks fields.
446 ZFS_TIME_DECODE(&xva
.xva_vattr
.va_ctime
, lr
->lr_crtime
);
447 xva
.xva_vattr
.va_nblocks
= lr
->lr_gen
;
449 error
= dmu_object_info(zfsvfs
->z_os
, lr
->lr_foid
, NULL
);
453 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
457 * Symlinks don't have fuid info, and CIFS never creates
460 * The _ATTR versions will grab the fuid info in their subcases.
462 if ((int)lr
->lr_common
.lrc_txtype
!= TX_SYMLINK
&&
463 (int)lr
->lr_common
.lrc_txtype
!= TX_MKDIR_ATTR
&&
464 (int)lr
->lr_common
.lrc_txtype
!= TX_CREATE_ATTR
) {
466 zfsvfs
->z_fuid_replay
=
467 zfs_replay_fuid_domain(start
, &start
,
468 lr
->lr_uid
, lr
->lr_gid
);
472 cn
.cn_flags
= SAVENAME
;
474 vn_lock(ZTOV(dzp
), LK_EXCLUSIVE
| LK_RETRY
);
475 switch ((int)lr
->lr_common
.lrc_txtype
) {
477 lrattr
= (lr_attr_t
*)(caddr_t
)(lr
+ 1);
478 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
479 zfs_replay_xvattr((lr_attr_t
*)((caddr_t
)lr
+ lrsize
), &xva
);
480 start
= (caddr_t
)(lr
+ 1) + xvatlen
;
481 zfsvfs
->z_fuid_replay
=
482 zfs_replay_fuid_domain(start
, &start
,
483 lr
->lr_uid
, lr
->lr_gid
);
484 name
= (char *)start
;
489 name
= (char *)start
;
491 cn
.cn_nameptr
= name
;
492 error
= VOP_CREATE(ZTOV(dzp
), &vp
, &cn
, &xva
.xva_vattr
/*,vflg*/);
495 lrattr
= (lr_attr_t
*)(caddr_t
)(lr
+ 1);
496 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
497 zfs_replay_xvattr((lr_attr_t
*)((caddr_t
)lr
+ lrsize
), &xva
);
498 start
= (caddr_t
)(lr
+ 1) + xvatlen
;
499 zfsvfs
->z_fuid_replay
=
500 zfs_replay_fuid_domain(start
, &start
,
501 lr
->lr_uid
, lr
->lr_gid
);
502 name
= (char *)start
;
507 name
= (char *)(lr
+ 1);
509 cn
.cn_nameptr
= name
;
510 error
= VOP_MKDIR(ZTOV(dzp
), &vp
, &cn
, &xva
.xva_vattr
/*,vflg*/);
513 name
= (char *)(lr
+ 1);
514 error
= zfs_make_xattrdir(dzp
, &xva
.xva_vattr
, &vp
, kcred
);
517 name
= (char *)(lr
+ 1);
518 link
= name
+ strlen(name
) + 1;
519 cn
.cn_nameptr
= name
;
520 error
= VOP_SYMLINK(ZTOV(dzp
), &vp
, &cn
, &xva
.xva_vattr
, link
/*,vflg*/);
525 VOP_UNLOCK(ZTOV(dzp
), 0);
528 if (error
== 0 && vp
!= NULL
) {
535 if (zfsvfs
->z_fuid_replay
)
536 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
537 zfsvfs
->z_fuid_replay
= NULL
;
542 zfs_replay_remove(zfsvfs_t
*zfsvfs
, lr_remove_t
*lr
, boolean_t byteswap
)
544 char *name
= (char *)(lr
+ 1); /* name follows lr_remove_t */
546 struct componentname cn
;
552 byteswap_uint64_array(lr
, sizeof (*lr
));
554 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
557 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
559 cn
.cn_nameptr
= name
;
560 cn
.cn_namelen
= strlen(name
);
561 cn
.cn_nameiop
= DELETE
;
562 cn
.cn_flags
= ISLASTCN
| SAVENAME
;
563 //cn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
565 vn_lock(ZTOV(dzp
), LK_EXCLUSIVE
| LK_RETRY
);
566 error
= VOP_LOOKUP(ZTOV(dzp
), &vp
, &cn
);
568 VOP_UNLOCK(ZTOV(dzp
), 0);
572 switch ((int)lr
->lr_common
.lrc_txtype
) {
574 error
= VOP_REMOVE(ZTOV(dzp
), vp
, &cn
/*,vflg*/);
577 error
= VOP_RMDIR(ZTOV(dzp
), vp
, &cn
/*,vflg*/);
583 VOP_UNLOCK(ZTOV(dzp
), 0);
591 zfs_replay_link(zfsvfs_t
*zfsvfs
, lr_link_t
*lr
, boolean_t byteswap
)
593 char *name
= (char *)(lr
+ 1); /* name follows lr_link_t */
595 struct componentname cn
;
600 byteswap_uint64_array(lr
, sizeof (*lr
));
602 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
605 if ((error
= zfs_zget(zfsvfs
, lr
->lr_link_obj
, &zp
)) != 0) {
610 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
612 cn
.cn_nameptr
= name
;
614 cn
.cn_flags
= SAVENAME
;
616 vn_lock(ZTOV(dzp
), LK_EXCLUSIVE
| LK_RETRY
);
617 vn_lock(ZTOV(zp
), LK_EXCLUSIVE
| LK_RETRY
);
618 error
= VOP_LINK(ZTOV(dzp
), ZTOV(zp
), &cn
/*,vflg*/);
619 VOP_UNLOCK(ZTOV(zp
), 0);
620 VOP_UNLOCK(ZTOV(dzp
), 0);
629 zfs_replay_rename(zfsvfs_t
*zfsvfs
, lr_rename_t
*lr
, boolean_t byteswap
)
631 char *sname
= (char *)(lr
+ 1); /* sname and tname follow lr_rename_t */
632 char *tname
= sname
+ strlen(sname
) + 1;
633 znode_t
*sdzp
, *tdzp
;
634 struct componentname scn
, tcn
;
636 kthread_t
*td
= curthread
;
641 byteswap_uint64_array(lr
, sizeof (*lr
));
643 if ((error
= zfs_zget(zfsvfs
, lr
->lr_sdoid
, &sdzp
)) != 0)
646 if ((error
= zfs_zget(zfsvfs
, lr
->lr_tdoid
, &tdzp
)) != 0) {
651 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
655 scn
.cn_nameptr
= sname
;
656 scn
.cn_namelen
= strlen(sname
);
657 scn
.cn_nameiop
= DELETE
;
658 scn
.cn_flags
= ISLASTCN
| SAVENAME
;
659 // scn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
661 vn_lock(ZTOV(sdzp
), LK_EXCLUSIVE
| LK_RETRY
);
662 error
= VOP_LOOKUP(ZTOV(sdzp
), &svp
, &scn
);
663 VOP_UNLOCK(ZTOV(sdzp
), 0);
668 tcn
.cn_nameptr
= tname
;
669 tcn
.cn_namelen
= strlen(tname
);
670 tcn
.cn_nameiop
= RENAME
;
671 tcn
.cn_flags
= ISLASTCN
| SAVENAME
;
672 // tcn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY;
674 vn_lock(ZTOV(tdzp
), LK_EXCLUSIVE
| LK_RETRY
);
675 error
= VOP_LOOKUP(ZTOV(tdzp
), &tvp
, &tcn
);
676 if (error
== EJUSTRETURN
)
678 else if (error
!= 0) {
679 VOP_UNLOCK(ZTOV(tdzp
), 0);
683 error
= VOP_RENAME(ZTOV(sdzp
), svp
, &scn
, ZTOV(tdzp
), tvp
, &tcn
/*,vflg*/);
697 zfs_replay_write(zfsvfs_t
*zfsvfs
, lr_write_t
*lr
, boolean_t byteswap
)
699 char *data
= (char *)(lr
+ 1); /* data follows lr_write_t */
705 byteswap_uint64_array(lr
, sizeof (*lr
));
707 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
709 * As we can log writes out of order, it's possible the
710 * file has been removed. In this case just drop the write
711 * and return success.
718 error
= vn_rdwr(UIO_WRITE
, ZTOV(zp
), data
, lr
->lr_length
,
719 lr
->lr_offset
, UIO_SYSSPACE
, 0, RLIM64_INFINITY
, kcred
, &resid
);
727 zfs_replay_truncate(zfsvfs_t
*zfsvfs
, lr_truncate_t
*lr
, boolean_t byteswap
)
730 ZFS_LOG(0, "Unexpected code path, report to pjd@FreeBSD.org");
735 zfs_replay_setattr(zfsvfs_t
*zfsvfs
, lr_setattr_t
*lr
, boolean_t byteswap
)
739 vattr_t
*vap
= &xva
.xva_vattr
;
746 byteswap_uint64_array(lr
, sizeof (*lr
));
748 if ((lr
->lr_mask
& AT_XVATTR
) &&
749 zfsvfs
->z_version
>= ZPL_VERSION_INITIAL
)
750 zfs_replay_swap_attrs((lr_attr_t
*)(lr
+ 1));
753 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
755 * As we can log setattrs out of order, it's possible the
756 * file has been removed. In this case just drop the setattr
757 * and return success.
764 zfs_init_vattr(vap
, lr
->lr_mask
, lr
->lr_mode
,
765 lr
->lr_uid
, lr
->lr_gid
, 0, lr
->lr_foid
);
767 vap
->va_size
= lr
->lr_size
;
768 ZFS_TIME_DECODE(&vap
->va_atime
, lr
->lr_atime
);
769 ZFS_TIME_DECODE(&vap
->va_mtime
, lr
->lr_mtime
);
772 * Fill in xvattr_t portions if necessary.
775 start
= (lr_setattr_t
*)(lr
+ 1);
776 if (vap
->va_mask
& AT_XVATTR
) {
777 zfs_replay_xvattr((lr_attr_t
*)start
, &xva
);
778 start
= (caddr_t
)start
+
779 ZIL_XVAT_SIZE(((lr_attr_t
*)start
)->lr_attr_masksize
);
781 xva
.xva_vattr
.va_mask
&= ~AT_XVATTR
;
783 zfsvfs
->z_fuid_replay
= zfs_replay_fuid_domain(start
, &start
,
784 lr
->lr_uid
, lr
->lr_gid
);
787 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
788 error
= VOP_SETATTR(vp
, vap
, kcred
);
791 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
792 zfsvfs
->z_fuid_replay
= NULL
;
799 zfs_replay_acl_v0(zfsvfs_t
*zfsvfs
, lr_acl_v0_t
*lr
, boolean_t byteswap
)
801 ace_t
*ace
= (ace_t
*)(lr
+ 1); /* ace array follows lr_acl_t */
807 byteswap_uint64_array(lr
, sizeof (*lr
));
808 zfs_oldace_byteswap(ace
, lr
->lr_aclcnt
);
811 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
813 * As we can log acls out of order, it's possible the
814 * file has been removed. In this case just drop the acl
815 * and return success.
822 bzero(&vsa
, sizeof (vsa
));
823 vsa
.vsa_mask
= VSA_ACE
| VSA_ACECNT
;
824 vsa
.vsa_aclcnt
= lr
->lr_aclcnt
;
825 vsa
.vsa_aclentsz
= sizeof (ace_t
) * vsa
.vsa_aclcnt
;
826 vsa
.vsa_aclflags
= 0;
827 vsa
.vsa_aclentp
= ace
;
830 error
= VOP_SETSECATTR(ZTOV(zp
), &vsa
, 0, kcred
, NULL
);
832 panic("%s:%u: unsupported condition", __func__
, __LINE__
);
841 * Replaying ACLs is complicated by FUID support.
842 * The log record may contain some optional data
843 * to be used for replaying FUID's. These pieces
844 * are the actual FUIDs that were created initially.
845 * The FUID table index may no longer be valid and
846 * during zfs_create() a new index may be assigned.
847 * Because of this the log will contain the original
848 * doman+rid in order to create a new FUID.
850 * The individual ACEs may contain an ephemeral uid/gid which is no
851 * longer valid and will need to be replaced with an actual FUID.
855 zfs_replay_acl(zfsvfs_t
*zfsvfs
, lr_acl_t
*lr
, boolean_t byteswap
)
857 ace_t
*ace
= (ace_t
*)(lr
+ 1);
863 byteswap_uint64_array(lr
, sizeof (*lr
));
864 zfs_ace_byteswap(ace
, lr
->lr_acl_bytes
, B_FALSE
);
865 if (lr
->lr_fuidcnt
) {
866 byteswap_uint64_array((caddr_t
)ace
+
867 ZIL_ACE_LENGTH(lr
->lr_acl_bytes
),
868 lr
->lr_fuidcnt
* sizeof (uint64_t));
872 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
874 * As we can log acls out of order, it's possible the
875 * file has been removed. In this case just drop the acl
876 * and return success.
884 bzero(&vsa
, sizeof (vsa
));
885 vsa
.vsa_mask
= VSA_ACE
| VSA_ACECNT
| VSA_ACE_ACLFLAGS
;
886 vsa
.vsa_aclcnt
= lr
->lr_aclcnt
;
887 vsa
.vsa_aclentp
= ace
;
888 vsa
.vsa_aclentsz
= lr
->lr_acl_bytes
;
889 vsa
.vsa_aclflags
= lr
->lr_acl_flags
;
891 if (lr
->lr_fuidcnt
) {
892 void *fuidstart
= (caddr_t
)ace
+
893 ZIL_ACE_LENGTH(lr
->lr_acl_bytes
);
895 zfsvfs
->z_fuid_replay
=
896 zfs_replay_fuids(fuidstart
, &fuidstart
,
897 lr
->lr_fuidcnt
, lr
->lr_domcnt
, 0, 0);
900 error
= VOP_SETSECATTR(ZTOV(zp
), &vsa
, 0, kcred
, NULL
);
902 if (zfsvfs
->z_fuid_replay
)
903 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
908 zfsvfs
->z_fuid_replay
= NULL
;
915 * Callback vectors for replaying records
917 zil_replay_func_t
*zfs_replay_vector
[TX_MAX_TYPE
] = {
918 zfs_replay_error
, /* 0 no such transaction type */
919 zfs_replay_create
, /* TX_CREATE */
920 zfs_replay_create
, /* TX_MKDIR */
921 zfs_replay_create
, /* TX_MKXATTR */
922 zfs_replay_create
, /* TX_SYMLINK */
923 zfs_replay_remove
, /* TX_REMOVE */
924 zfs_replay_remove
, /* TX_RMDIR */
925 zfs_replay_link
, /* TX_LINK */
926 zfs_replay_rename
, /* TX_RENAME */
927 zfs_replay_write
, /* TX_WRITE */
928 zfs_replay_truncate
, /* TX_TRUNCATE */
929 zfs_replay_setattr
, /* TX_SETATTR */
930 zfs_replay_acl_v0
, /* TX_ACL_V0 */
931 zfs_replay_acl
, /* TX_ACL */
932 zfs_replay_create_acl
, /* TX_CREATE_ACL */
933 zfs_replay_create
, /* TX_CREATE_ATTR */
934 zfs_replay_create_acl
, /* TX_CREATE_ACL_ATTR */
935 zfs_replay_create_acl
, /* TX_MKDIR_ACL */
936 zfs_replay_create
, /* TX_MKDIR_ATTR */
937 zfs_replay_create_acl
, /* TX_MKDIR_ACL_ATTR */