]>
git.proxmox.com Git - mirror_zfs.git/blob - zfs/lib/libdmu-ctl/zfs_replay.c
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 "@(#)zfs_replay.c 1.7 08/01/14 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>
34 #include <sys/thread.h>
36 #include <sys/fcntl.h>
38 #include <sys/fs/zfs.h>
39 #include <sys/zfs_znode.h>
40 #include <sys/zfs_dir.h>
41 #include <sys/zfs_acl.h>
42 #include <sys/zfs_fuid.h>
45 #include <sys/byteorder.h>
49 #include <sys/atomic.h>
53 * Functions to replay ZFS intent log (ZIL) records
54 * The functions are called through a function vector (zfs_replay_vector)
55 * which is indexed by the transaction type.
59 zfs_init_vattr(vattr_t
*vap
, uint64_t mask
, uint64_t mode
,
60 uint64_t uid
, uint64_t gid
, uint64_t rdev
, uint64_t nodeid
)
62 bzero(vap
, sizeof (*vap
));
63 vap
->va_mask
= (uint_t
)mask
;
64 vap
->va_type
= IFTOVT(mode
);
65 vap
->va_mode
= mode
& MODEMASK
;
66 vap
->va_uid
= (uid_t
)(IS_EPHEMERAL(uid
)) ? -1 : uid
;
67 vap
->va_gid
= (gid_t
)(IS_EPHEMERAL(gid
)) ? -1 : gid
;
68 vap
->va_rdev
= zfs_cmpldev(rdev
);
69 vap
->va_nodeid
= nodeid
;
74 zfs_replay_error(zfsvfs_t
*zfsvfs
, lr_t
*lr
, boolean_t byteswap
)
80 zfs_replay_xvattr(lr_attr_t
*lrattr
, xvattr_t
*xvap
)
82 xoptattr_t
*xoap
= NULL
;
89 xvap
->xva_vattr
.va_mask
|= AT_XVATTR
;
90 if ((xoap
= xva_getxoptattr(xvap
)) == NULL
) {
91 xvap
->xva_vattr
.va_mask
&= ~AT_XVATTR
; /* shouldn't happen */
95 ASSERT(lrattr
->lr_attr_masksize
== xvap
->xva_mapsize
);
97 bitmap
= &lrattr
->lr_attr_bitmap
;
98 for (i
= 0; i
!= lrattr
->lr_attr_masksize
; i
++, bitmap
++)
99 xvap
->xva_reqattrmap
[i
] = *bitmap
;
101 attrs
= (uint64_t *)(lrattr
+ lrattr
->lr_attr_masksize
- 1);
103 scanstamp
= (caddr_t
)(crtime
+ 2);
105 if (XVA_ISSET_REQ(xvap
, XAT_HIDDEN
))
106 xoap
->xoa_hidden
= ((*attrs
& XAT0_HIDDEN
) != 0);
107 if (XVA_ISSET_REQ(xvap
, XAT_SYSTEM
))
108 xoap
->xoa_system
= ((*attrs
& XAT0_SYSTEM
) != 0);
109 if (XVA_ISSET_REQ(xvap
, XAT_ARCHIVE
))
110 xoap
->xoa_archive
= ((*attrs
& XAT0_ARCHIVE
) != 0);
111 if (XVA_ISSET_REQ(xvap
, XAT_READONLY
))
112 xoap
->xoa_readonly
= ((*attrs
& XAT0_READONLY
) != 0);
113 if (XVA_ISSET_REQ(xvap
, XAT_IMMUTABLE
))
114 xoap
->xoa_immutable
= ((*attrs
& XAT0_IMMUTABLE
) != 0);
115 if (XVA_ISSET_REQ(xvap
, XAT_NOUNLINK
))
116 xoap
->xoa_nounlink
= ((*attrs
& XAT0_NOUNLINK
) != 0);
117 if (XVA_ISSET_REQ(xvap
, XAT_APPENDONLY
))
118 xoap
->xoa_appendonly
= ((*attrs
& XAT0_APPENDONLY
) != 0);
119 if (XVA_ISSET_REQ(xvap
, XAT_NODUMP
))
120 xoap
->xoa_nodump
= ((*attrs
& XAT0_NODUMP
) != 0);
121 if (XVA_ISSET_REQ(xvap
, XAT_OPAQUE
))
122 xoap
->xoa_opaque
= ((*attrs
& XAT0_OPAQUE
) != 0);
123 if (XVA_ISSET_REQ(xvap
, XAT_AV_MODIFIED
))
124 xoap
->xoa_av_modified
= ((*attrs
& XAT0_AV_MODIFIED
) != 0);
125 if (XVA_ISSET_REQ(xvap
, XAT_AV_QUARANTINED
))
126 xoap
->xoa_av_quarantined
=
127 ((*attrs
& XAT0_AV_QUARANTINED
) != 0);
128 if (XVA_ISSET_REQ(xvap
, XAT_CREATETIME
))
129 ZFS_TIME_DECODE(&xoap
->xoa_createtime
, crtime
);
130 if (XVA_ISSET_REQ(xvap
, XAT_AV_SCANSTAMP
))
131 bcopy(scanstamp
, xoap
->xoa_av_scanstamp
, AV_SCANSTAMP_SZ
);
135 zfs_replay_domain_cnt(uint64_t uid
, uint64_t gid
)
141 uid_idx
= FUID_INDEX(uid
);
142 gid_idx
= FUID_INDEX(gid
);
145 if (gid_idx
> 0 && gid_idx
!= uid_idx
)
152 zfs_replay_fuid_domain_common(zfs_fuid_info_t
*fuid_infop
, void *start
,
157 for (i
= 0; i
!= domcnt
; i
++) {
158 fuid_infop
->z_domain_table
[i
] = start
;
159 start
= (caddr_t
)start
+ strlen(start
) + 1;
166 * Set the uid/gid in the fuid_info structure.
169 zfs_replay_fuid_ugid(zfs_fuid_info_t
*fuid_infop
, uint64_t uid
, uint64_t gid
)
172 * If owner or group are log specific FUIDs then slurp up
173 * domain information and build zfs_fuid_info_t
175 if (IS_EPHEMERAL(uid
))
176 fuid_infop
->z_fuid_owner
= uid
;
178 if (IS_EPHEMERAL(gid
))
179 fuid_infop
->z_fuid_group
= gid
;
183 * Load fuid domains into fuid_info_t
185 static zfs_fuid_info_t
*
186 zfs_replay_fuid_domain(void *buf
, void **end
, uint64_t uid
, uint64_t gid
)
190 zfs_fuid_info_t
*fuid_infop
;
192 fuid_infop
= zfs_fuid_info_alloc();
194 domcnt
= zfs_replay_domain_cnt(uid
, gid
);
199 fuid_infop
->z_domain_table
=
200 kmem_zalloc(domcnt
* sizeof (char **), KM_SLEEP
);
202 zfs_replay_fuid_ugid(fuid_infop
, uid
, gid
);
204 fuid_infop
->z_domain_cnt
= domcnt
;
205 *end
= zfs_replay_fuid_domain_common(fuid_infop
, buf
, domcnt
);
210 * load zfs_fuid_t's and fuid_domains into fuid_info_t
212 static zfs_fuid_info_t
*
213 zfs_replay_fuids(void *start
, void **end
, int idcnt
, int domcnt
, uint64_t uid
,
216 uint64_t *log_fuid
= (uint64_t *)start
;
217 zfs_fuid_info_t
*fuid_infop
;
220 fuid_infop
= zfs_fuid_info_alloc();
221 fuid_infop
->z_domain_cnt
= domcnt
;
223 fuid_infop
->z_domain_table
=
224 kmem_zalloc(domcnt
* sizeof (char **), KM_SLEEP
);
226 for (i
= 0; i
!= idcnt
; i
++) {
229 zfuid
= kmem_alloc(sizeof (zfs_fuid_t
), KM_SLEEP
);
230 zfuid
->z_logfuid
= *log_fuid
;
233 list_insert_tail(&fuid_infop
->z_fuids
, zfuid
);
237 zfs_replay_fuid_ugid(fuid_infop
, uid
, gid
);
239 *end
= zfs_replay_fuid_domain_common(fuid_infop
, log_fuid
, domcnt
);
244 zfs_replay_swap_attrs(lr_attr_t
*lrattr
)
246 /* swap the lr_attr structure */
247 byteswap_uint32_array(lrattr
, sizeof (*lrattr
));
248 /* swap the bitmap */
249 byteswap_uint32_array(lrattr
+ 1, (lrattr
->lr_attr_masksize
- 1) *
251 /* swap the attributes, create time + 64 bit word for attributes */
252 byteswap_uint64_array((caddr_t
)(lrattr
+ 1) + (sizeof (uint32_t) *
253 (lrattr
->lr_attr_masksize
- 1)), 3 * sizeof (uint64_t));
257 * Replay file create with optional ACL, xvattr information as well
258 * as option FUID information.
261 zfs_replay_create_acl(zfsvfs_t
*zfsvfs
,
262 lr_acl_create_t
*lracl
, boolean_t byteswap
)
264 char *name
= NULL
; /* location determined later */
265 lr_create_t
*lr
= (lr_create_t
*)lracl
;
270 vsecattr_t vsec
= { 0 };
279 byteswap_uint64_array(lracl
, sizeof (*lracl
));
280 txtype
= (int)lr
->lr_common
.lrc_txtype
;
281 if (txtype
== TX_CREATE_ACL_ATTR
||
282 txtype
== TX_MKDIR_ACL_ATTR
) {
283 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
284 zfs_replay_swap_attrs(lrattr
);
285 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
288 aclstart
= (caddr_t
)(lracl
+ 1) + xvatlen
;
289 zfs_ace_byteswap(aclstart
, lracl
->lr_acl_bytes
, B_FALSE
);
291 if (lracl
->lr_fuidcnt
) {
292 byteswap_uint64_array((caddr_t
)aclstart
+
293 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
),
294 lracl
->lr_fuidcnt
* sizeof (uint64_t));
298 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
302 zfs_init_vattr(&xva
.xva_vattr
, AT_TYPE
| AT_MODE
| AT_UID
| AT_GID
,
303 lr
->lr_mode
, lr
->lr_uid
, lr
->lr_gid
, lr
->lr_rdev
, lr
->lr_foid
);
306 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
307 * eventually end up in zfs_mknode(), which assigns the object's
308 * creation time and generation number. The generic VOP_CREATE()
309 * doesn't have either concept, so we smuggle the values inside
310 * the vattr's otherwise unused va_ctime and va_nblocks fields.
312 ZFS_TIME_DECODE(&xva
.xva_vattr
.va_ctime
, lr
->lr_crtime
);
313 xva
.xva_vattr
.va_nblocks
= lr
->lr_gen
;
315 error
= dmu_object_info(zfsvfs
->z_os
, lr
->lr_foid
, NULL
);
319 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
321 switch ((int)lr
->lr_common
.lrc_txtype
) {
323 aclstart
= (caddr_t
)(lracl
+ 1);
324 fuidstart
= (caddr_t
)aclstart
+
325 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
326 zfsvfs
->z_fuid_replay
= zfs_replay_fuids(fuidstart
,
327 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
328 lr
->lr_uid
, lr
->lr_gid
);
330 case TX_CREATE_ACL_ATTR
:
332 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
333 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
334 xva
.xva_vattr
.va_mask
|= AT_XVATTR
;
335 zfs_replay_xvattr(lrattr
, &xva
);
337 vsec
.vsa_mask
= VSA_ACE
| VSA_ACE_ACLFLAGS
;
338 vsec
.vsa_aclentp
= (caddr_t
)(lracl
+ 1) + xvatlen
;
339 vsec
.vsa_aclcnt
= lracl
->lr_aclcnt
;
340 vsec
.vsa_aclentsz
= lracl
->lr_acl_bytes
;
341 vsec
.vsa_aclflags
= lracl
->lr_acl_flags
;
342 if (zfsvfs
->z_fuid_replay
== NULL
) {
343 fuidstart
= (caddr_t
)(lracl
+ 1) + xvatlen
+
344 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
345 zfsvfs
->z_fuid_replay
=
346 zfs_replay_fuids(fuidstart
,
347 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
348 lr
->lr_uid
, lr
->lr_gid
);
351 error
= VOP_CREATE(ZTOV(dzp
), name
, &xva
.xva_vattr
,
352 0, 0, &vp
, kcred
, vflg
, NULL
, &vsec
);
355 aclstart
= (caddr_t
)(lracl
+ 1);
356 fuidstart
= (caddr_t
)aclstart
+
357 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
358 zfsvfs
->z_fuid_replay
= zfs_replay_fuids(fuidstart
,
359 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
360 lr
->lr_uid
, lr
->lr_gid
);
362 case TX_MKDIR_ACL_ATTR
:
364 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
365 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
366 zfs_replay_xvattr(lrattr
, &xva
);
368 vsec
.vsa_mask
= VSA_ACE
| VSA_ACE_ACLFLAGS
;
369 vsec
.vsa_aclentp
= (caddr_t
)(lracl
+ 1) + xvatlen
;
370 vsec
.vsa_aclcnt
= lracl
->lr_aclcnt
;
371 vsec
.vsa_aclentsz
= lracl
->lr_acl_bytes
;
372 vsec
.vsa_aclflags
= lracl
->lr_acl_flags
;
373 if (zfsvfs
->z_fuid_replay
== NULL
) {
374 fuidstart
= (caddr_t
)(lracl
+ 1) + xvatlen
+
375 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
376 zfsvfs
->z_fuid_replay
=
377 zfs_replay_fuids(fuidstart
,
378 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
379 lr
->lr_uid
, lr
->lr_gid
);
381 error
= VOP_MKDIR(ZTOV(dzp
), name
, &xva
.xva_vattr
,
382 &vp
, kcred
, NULL
, vflg
, &vsec
);
389 if (error
== 0 && vp
!= NULL
)
394 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
395 zfsvfs
->z_fuid_replay
= NULL
;
401 zfs_replay_create(zfsvfs_t
*zfsvfs
, lr_create_t
*lr
, boolean_t byteswap
)
403 char *name
= NULL
; /* location determined later */
404 char *link
; /* symlink content follows name */
409 size_t lrsize
= sizeof (lr_create_t
);
417 byteswap_uint64_array(lr
, sizeof (*lr
));
418 txtype
= (int)lr
->lr_common
.lrc_txtype
;
419 if (txtype
== TX_CREATE_ATTR
|| txtype
== TX_MKDIR_ATTR
)
420 zfs_replay_swap_attrs((lr_attr_t
*)(lr
+ 1));
424 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
428 zfs_init_vattr(&xva
.xva_vattr
, AT_TYPE
| AT_MODE
| AT_UID
| AT_GID
,
429 lr
->lr_mode
, lr
->lr_uid
, lr
->lr_gid
, lr
->lr_rdev
, lr
->lr_foid
);
432 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
433 * eventually end up in zfs_mknode(), which assigns the object's
434 * creation time and generation number. The generic VOP_CREATE()
435 * doesn't have either concept, so we smuggle the values inside
436 * the vattr's otherwise unused va_ctime and va_nblocks fields.
438 ZFS_TIME_DECODE(&xva
.xva_vattr
.va_ctime
, lr
->lr_crtime
);
439 xva
.xva_vattr
.va_nblocks
= lr
->lr_gen
;
441 error
= dmu_object_info(zfsvfs
->z_os
, lr
->lr_foid
, NULL
);
445 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
449 * Symlinks don't have fuid info, and CIFS never creates
452 * The _ATTR versions will grab the fuid info in their subcases.
454 if ((int)lr
->lr_common
.lrc_txtype
!= TX_SYMLINK
&&
455 (int)lr
->lr_common
.lrc_txtype
!= TX_MKDIR_ATTR
&&
456 (int)lr
->lr_common
.lrc_txtype
!= TX_CREATE_ATTR
) {
458 zfsvfs
->z_fuid_replay
=
459 zfs_replay_fuid_domain(start
, &start
,
460 lr
->lr_uid
, lr
->lr_gid
);
463 switch ((int)lr
->lr_common
.lrc_txtype
) {
465 lrattr
= (lr_attr_t
*)(caddr_t
)(lr
+ 1);
466 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
467 zfs_replay_xvattr((lr_attr_t
*)((caddr_t
)lr
+ lrsize
), &xva
);
468 start
= (caddr_t
)(lr
+ 1) + xvatlen
;
469 zfsvfs
->z_fuid_replay
=
470 zfs_replay_fuid_domain(start
, &start
,
471 lr
->lr_uid
, lr
->lr_gid
);
472 name
= (char *)start
;
477 name
= (char *)start
;
479 error
= VOP_CREATE(ZTOV(dzp
), name
, &xva
.xva_vattr
,
480 0, 0, &vp
, kcred
, vflg
, NULL
, NULL
);
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 *)(lr
+ 1);
497 error
= VOP_MKDIR(ZTOV(dzp
), name
, &xva
.xva_vattr
,
498 &vp
, kcred
, NULL
, vflg
, NULL
);
501 name
= (char *)(lr
+ 1);
502 error
= zfs_make_xattrdir(dzp
, &xva
.xva_vattr
, &vp
, kcred
);
505 name
= (char *)(lr
+ 1);
506 link
= name
+ strlen(name
) + 1;
507 error
= VOP_SYMLINK(ZTOV(dzp
), name
, &xva
.xva_vattr
,
508 link
, kcred
, NULL
, vflg
);
515 if (error
== 0 && vp
!= NULL
)
520 if (zfsvfs
->z_fuid_replay
)
521 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
522 zfsvfs
->z_fuid_replay
= NULL
;
527 zfs_replay_remove(zfsvfs_t
*zfsvfs
, lr_remove_t
*lr
, boolean_t byteswap
)
529 char *name
= (char *)(lr
+ 1); /* name follows lr_remove_t */
535 byteswap_uint64_array(lr
, sizeof (*lr
));
537 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
540 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
543 switch ((int)lr
->lr_common
.lrc_txtype
) {
545 error
= VOP_REMOVE(ZTOV(dzp
), name
, kcred
, NULL
, vflg
);
548 error
= VOP_RMDIR(ZTOV(dzp
), name
, NULL
, kcred
, NULL
, vflg
);
560 zfs_replay_link(zfsvfs_t
*zfsvfs
, lr_link_t
*lr
, boolean_t byteswap
)
562 char *name
= (char *)(lr
+ 1); /* name follows lr_link_t */
568 byteswap_uint64_array(lr
, sizeof (*lr
));
570 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
573 if ((error
= zfs_zget(zfsvfs
, lr
->lr_link_obj
, &zp
)) != 0) {
578 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
581 error
= VOP_LINK(ZTOV(dzp
), ZTOV(zp
), name
, kcred
, NULL
, vflg
);
590 zfs_replay_rename(zfsvfs_t
*zfsvfs
, lr_rename_t
*lr
, boolean_t byteswap
)
592 char *sname
= (char *)(lr
+ 1); /* sname and tname follow lr_rename_t */
593 char *tname
= sname
+ strlen(sname
) + 1;
594 znode_t
*sdzp
, *tdzp
;
599 byteswap_uint64_array(lr
, sizeof (*lr
));
601 if ((error
= zfs_zget(zfsvfs
, lr
->lr_sdoid
, &sdzp
)) != 0)
604 if ((error
= zfs_zget(zfsvfs
, lr
->lr_tdoid
, &tdzp
)) != 0) {
609 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
612 error
= VOP_RENAME(ZTOV(sdzp
), sname
, ZTOV(tdzp
), tname
, kcred
,
622 zfs_replay_write(zfsvfs_t
*zfsvfs
, lr_write_t
*lr
, boolean_t byteswap
)
624 char *data
= (char *)(lr
+ 1); /* data follows lr_write_t */
630 byteswap_uint64_array(lr
, sizeof (*lr
));
632 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
634 * As we can log writes out of order, it's possible the
635 * file has been removed. In this case just drop the write
636 * and return success.
643 error
= vn_rdwr(UIO_WRITE
, ZTOV(zp
), data
, lr
->lr_length
,
644 lr
->lr_offset
, UIO_SYSSPACE
, 0, RLIM64_INFINITY
, kcred
, &resid
);
652 zfs_replay_truncate(zfsvfs_t
*zfsvfs
, lr_truncate_t
*lr
, boolean_t byteswap
)
659 byteswap_uint64_array(lr
, sizeof (*lr
));
661 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
663 * As we can log truncates out of order, it's possible the
664 * file has been removed. In this case just drop the truncate
665 * and return success.
672 bzero(&fl
, sizeof (fl
));
675 fl
.l_start
= lr
->lr_offset
;
676 fl
.l_len
= lr
->lr_length
;
678 error
= VOP_SPACE(ZTOV(zp
), F_FREESP
, &fl
, FWRITE
| FOFFMAX
,
679 lr
->lr_offset
, kcred
, NULL
);
687 zfs_replay_setattr(zfsvfs_t
*zfsvfs
, lr_setattr_t
*lr
, boolean_t byteswap
)
691 vattr_t
*vap
= &xva
.xva_vattr
;
697 byteswap_uint64_array(lr
, sizeof (*lr
));
699 if ((lr
->lr_mask
& AT_XVATTR
) &&
700 zfsvfs
->z_version
>= ZPL_VERSION_INITIAL
)
701 zfs_replay_swap_attrs((lr_attr_t
*)(lr
+ 1));
704 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
706 * As we can log setattrs out of order, it's possible the
707 * file has been removed. In this case just drop the setattr
708 * and return success.
715 zfs_init_vattr(vap
, lr
->lr_mask
, lr
->lr_mode
,
716 lr
->lr_uid
, lr
->lr_gid
, 0, lr
->lr_foid
);
718 vap
->va_size
= lr
->lr_size
;
719 ZFS_TIME_DECODE(&vap
->va_atime
, lr
->lr_atime
);
720 ZFS_TIME_DECODE(&vap
->va_mtime
, lr
->lr_mtime
);
723 * Fill in xvattr_t portions if necessary.
726 start
= (lr_setattr_t
*)(lr
+ 1);
727 if (vap
->va_mask
& AT_XVATTR
) {
728 zfs_replay_xvattr((lr_attr_t
*)start
, &xva
);
729 start
= (caddr_t
)start
+
730 ZIL_XVAT_SIZE(((lr_attr_t
*)start
)->lr_attr_masksize
);
732 xva
.xva_vattr
.va_mask
&= ~AT_XVATTR
;
734 zfsvfs
->z_fuid_replay
= zfs_replay_fuid_domain(start
, &start
,
735 lr
->lr_uid
, lr
->lr_gid
);
737 error
= VOP_SETATTR(ZTOV(zp
), vap
, 0, kcred
, NULL
);
739 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
740 zfsvfs
->z_fuid_replay
= NULL
;
747 zfs_replay_acl_v0(zfsvfs_t
*zfsvfs
, lr_acl_v0_t
*lr
, boolean_t byteswap
)
749 ace_t
*ace
= (ace_t
*)(lr
+ 1); /* ace array follows lr_acl_t */
755 byteswap_uint64_array(lr
, sizeof (*lr
));
756 zfs_oldace_byteswap(ace
, lr
->lr_aclcnt
);
759 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
761 * As we can log acls out of order, it's possible the
762 * file has been removed. In this case just drop the acl
763 * and return success.
770 bzero(&vsa
, sizeof (vsa
));
771 vsa
.vsa_mask
= VSA_ACE
| VSA_ACECNT
;
772 vsa
.vsa_aclcnt
= lr
->lr_aclcnt
;
773 vsa
.vsa_aclentp
= ace
;
775 error
= VOP_SETSECATTR(ZTOV(zp
), &vsa
, 0, kcred
, NULL
);
783 * Replaying ACLs is complicated by FUID support.
784 * The log record may contain some optional data
785 * to be used for replaying FUID's. These pieces
786 * are the actual FUIDs that were created initially.
787 * The FUID table index may no longer be valid and
788 * during zfs_create() a new index may be assigned.
789 * Because of this the log will contain the original
790 * doman+rid in order to create a new FUID.
792 * The individual ACEs may contain an ephemeral uid/gid which is no
793 * longer valid and will need to be replaced with an actual FUID.
797 zfs_replay_acl(zfsvfs_t
*zfsvfs
, lr_acl_t
*lr
, boolean_t byteswap
)
799 ace_t
*ace
= (ace_t
*)(lr
+ 1);
805 byteswap_uint64_array(lr
, sizeof (*lr
));
806 zfs_ace_byteswap(ace
, lr
->lr_acl_bytes
, B_FALSE
);
807 if (lr
->lr_fuidcnt
) {
808 byteswap_uint64_array((caddr_t
)ace
+
809 ZIL_ACE_LENGTH(lr
->lr_acl_bytes
),
810 lr
->lr_fuidcnt
* sizeof (uint64_t));
814 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
816 * As we can log acls out of order, it's possible the
817 * file has been removed. In this case just drop the acl
818 * and return success.
825 bzero(&vsa
, sizeof (vsa
));
826 vsa
.vsa_mask
= VSA_ACE
| VSA_ACECNT
| VSA_ACE_ACLFLAGS
;
827 vsa
.vsa_aclcnt
= lr
->lr_aclcnt
;
828 vsa
.vsa_aclentp
= ace
;
829 vsa
.vsa_aclentsz
= lr
->lr_acl_bytes
;
830 vsa
.vsa_aclflags
= lr
->lr_acl_flags
;
832 if (lr
->lr_fuidcnt
) {
833 void *fuidstart
= (caddr_t
)ace
+
834 ZIL_ACE_LENGTH(lr
->lr_acl_bytes
);
836 zfsvfs
->z_fuid_replay
=
837 zfs_replay_fuids(fuidstart
, &fuidstart
,
838 lr
->lr_fuidcnt
, lr
->lr_domcnt
, 0, 0);
841 error
= VOP_SETSECATTR(ZTOV(zp
), &vsa
, 0, kcred
, NULL
);
843 if (zfsvfs
->z_fuid_replay
)
844 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
846 zfsvfs
->z_fuid_replay
= NULL
;
853 * Callback vectors for replaying records
855 zil_replay_func_t
*zfs_replay_vector
[TX_MAX_TYPE
] = {
856 zfs_replay_error
, /* 0 no such transaction type */
857 zfs_replay_create
, /* TX_CREATE */
858 zfs_replay_create
, /* TX_MKDIR */
859 zfs_replay_create
, /* TX_MKXATTR */
860 zfs_replay_create
, /* TX_SYMLINK */
861 zfs_replay_remove
, /* TX_REMOVE */
862 zfs_replay_remove
, /* TX_RMDIR */
863 zfs_replay_link
, /* TX_LINK */
864 zfs_replay_rename
, /* TX_RENAME */
865 zfs_replay_write
, /* TX_WRITE */
866 zfs_replay_truncate
, /* TX_TRUNCATE */
867 zfs_replay_setattr
, /* TX_SETATTR */
868 zfs_replay_acl_v0
, /* TX_ACL_V0 */
869 zfs_replay_acl
, /* TX_ACL */
870 zfs_replay_create_acl
, /* TX_CREATE_ACL */
871 zfs_replay_create
, /* TX_CREATE_ATTR */
872 zfs_replay_create_acl
, /* TX_CREATE_ACL_ATTR */
873 zfs_replay_create_acl
, /* TX_MKDIR_ACL */
874 zfs_replay_create
, /* TX_MKDIR_ATTR */
875 zfs_replay_create_acl
, /* TX_MKDIR_ACL_ATTR */