]>
git.proxmox.com Git - mirror_zfs.git/blob - module/zfs/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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 Cyril Plisko. All rights reserved.
24 * Copyright (c) 2013, 2017 by Delphix. All rights reserved.
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/sysmacros.h>
30 #include <sys/cmn_err.h>
32 #include <sys/thread.h>
34 #include <sys/fcntl.h>
36 #include <sys/fs/zfs.h>
37 #include <sys/zfs_znode.h>
38 #include <sys/zfs_dir.h>
39 #include <sys/zfs_acl.h>
40 #include <sys/zfs_fuid.h>
41 #include <sys/zfs_vnops.h>
44 #include <sys/byteorder.h>
48 #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
);
66 vap
->va_uid
= (uid_t
)(IS_EPHEMERAL(uid
)) ? -1 : uid
;
67 vap
->va_gid
= (gid_t
)(IS_EPHEMERAL(gid
)) ? -1 : gid
;
69 vap
->va_nodeid
= nodeid
;
74 zfs_replay_error(void *arg1
, void *arg2
, boolean_t byteswap
)
76 return (SET_ERROR(ENOTSUP
));
80 zfs_replay_xvattr(lr_attr_t
*lrattr
, xvattr_t
*xvap
)
82 xoptattr_t
*xoap
= NULL
;
89 xvap
->xva_vattr
.va_mask
|= ATTR_XVATTR
;
90 if ((xoap
= xva_getxoptattr(xvap
)) == NULL
) {
91 xvap
->xva_vattr
.va_mask
&= ~ATTR_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 ASSERT(!XVA_ISSET_REQ(xvap
, XAT_PROJID
));
133 bcopy(scanstamp
, xoap
->xoa_av_scanstamp
, AV_SCANSTAMP_SZ
);
134 } else if (XVA_ISSET_REQ(xvap
, XAT_PROJID
)) {
136 * XAT_PROJID and XAT_AV_SCANSTAMP will never be valid
137 * at the same time, so we can share the same space.
139 bcopy(scanstamp
, &xoap
->xoa_projid
, sizeof (uint64_t));
141 if (XVA_ISSET_REQ(xvap
, XAT_REPARSE
))
142 xoap
->xoa_reparse
= ((*attrs
& XAT0_REPARSE
) != 0);
143 if (XVA_ISSET_REQ(xvap
, XAT_OFFLINE
))
144 xoap
->xoa_offline
= ((*attrs
& XAT0_OFFLINE
) != 0);
145 if (XVA_ISSET_REQ(xvap
, XAT_SPARSE
))
146 xoap
->xoa_sparse
= ((*attrs
& XAT0_SPARSE
) != 0);
147 if (XVA_ISSET_REQ(xvap
, XAT_PROJINHERIT
))
148 xoap
->xoa_projinherit
= ((*attrs
& XAT0_PROJINHERIT
) != 0);
152 zfs_replay_domain_cnt(uint64_t uid
, uint64_t gid
)
158 uid_idx
= FUID_INDEX(uid
);
159 gid_idx
= FUID_INDEX(gid
);
162 if (gid_idx
> 0 && gid_idx
!= uid_idx
)
169 zfs_replay_fuid_domain_common(zfs_fuid_info_t
*fuid_infop
, void *start
,
174 for (i
= 0; i
!= domcnt
; i
++) {
175 fuid_infop
->z_domain_table
[i
] = start
;
176 start
= (caddr_t
)start
+ strlen(start
) + 1;
183 * Set the uid/gid in the fuid_info structure.
186 zfs_replay_fuid_ugid(zfs_fuid_info_t
*fuid_infop
, uint64_t uid
, uint64_t gid
)
189 * If owner or group are log specific FUIDs then slurp up
190 * domain information and build zfs_fuid_info_t
192 if (IS_EPHEMERAL(uid
))
193 fuid_infop
->z_fuid_owner
= uid
;
195 if (IS_EPHEMERAL(gid
))
196 fuid_infop
->z_fuid_group
= gid
;
200 * Load fuid domains into fuid_info_t
202 static zfs_fuid_info_t
*
203 zfs_replay_fuid_domain(void *buf
, void **end
, uint64_t uid
, uint64_t gid
)
207 zfs_fuid_info_t
*fuid_infop
;
209 fuid_infop
= zfs_fuid_info_alloc();
211 domcnt
= zfs_replay_domain_cnt(uid
, gid
);
216 fuid_infop
->z_domain_table
=
217 kmem_zalloc(domcnt
* sizeof (char *), KM_SLEEP
);
219 zfs_replay_fuid_ugid(fuid_infop
, uid
, gid
);
221 fuid_infop
->z_domain_cnt
= domcnt
;
222 *end
= zfs_replay_fuid_domain_common(fuid_infop
, buf
, domcnt
);
227 * load zfs_fuid_t's and fuid_domains into fuid_info_t
229 static zfs_fuid_info_t
*
230 zfs_replay_fuids(void *start
, void **end
, int idcnt
, int domcnt
, uint64_t uid
,
233 uint64_t *log_fuid
= (uint64_t *)start
;
234 zfs_fuid_info_t
*fuid_infop
;
237 fuid_infop
= zfs_fuid_info_alloc();
238 fuid_infop
->z_domain_cnt
= domcnt
;
240 fuid_infop
->z_domain_table
=
241 kmem_zalloc(domcnt
* sizeof (char *), KM_SLEEP
);
243 for (i
= 0; i
!= idcnt
; i
++) {
246 zfuid
= kmem_alloc(sizeof (zfs_fuid_t
), KM_SLEEP
);
247 zfuid
->z_logfuid
= *log_fuid
;
250 list_insert_tail(&fuid_infop
->z_fuids
, zfuid
);
254 zfs_replay_fuid_ugid(fuid_infop
, uid
, gid
);
256 *end
= zfs_replay_fuid_domain_common(fuid_infop
, log_fuid
, domcnt
);
261 zfs_replay_swap_attrs(lr_attr_t
*lrattr
)
263 /* swap the lr_attr structure */
264 byteswap_uint32_array(lrattr
, sizeof (*lrattr
));
265 /* swap the bitmap */
266 byteswap_uint32_array(lrattr
+ 1, (lrattr
->lr_attr_masksize
- 1) *
268 /* swap the attributes, create time + 64 bit word for attributes */
269 byteswap_uint64_array((caddr_t
)(lrattr
+ 1) + (sizeof (uint32_t) *
270 (lrattr
->lr_attr_masksize
- 1)), 3 * sizeof (uint64_t));
274 * Replay file create with optional ACL, xvattr information as well
275 * as option FUID information.
278 zfs_replay_create_acl(void *arg1
, void *arg2
, boolean_t byteswap
)
280 zfsvfs_t
*zfsvfs
= arg1
;
281 lr_acl_create_t
*lracl
= arg2
;
282 char *name
= NULL
; /* location determined later */
283 lr_create_t
*lr
= (lr_create_t
*)lracl
;
285 struct inode
*ip
= NULL
;
288 vsecattr_t vsec
= { 0 };
298 txtype
= (lr
->lr_common
.lrc_txtype
& ~TX_CI
);
300 byteswap_uint64_array(lracl
, sizeof (*lracl
));
301 if (txtype
== TX_CREATE_ACL_ATTR
||
302 txtype
== TX_MKDIR_ACL_ATTR
) {
303 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
304 zfs_replay_swap_attrs(lrattr
);
305 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
308 aclstart
= (caddr_t
)(lracl
+ 1) + xvatlen
;
309 zfs_ace_byteswap(aclstart
, lracl
->lr_acl_bytes
, B_FALSE
);
311 if (lracl
->lr_fuidcnt
) {
312 byteswap_uint64_array((caddr_t
)aclstart
+
313 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
),
314 lracl
->lr_fuidcnt
* sizeof (uint64_t));
318 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
321 objid
= LR_FOID_GET_OBJ(lr
->lr_foid
);
322 dnodesize
= LR_FOID_GET_SLOTS(lr
->lr_foid
) << DNODE_SHIFT
;
325 zfs_init_vattr(&xva
.xva_vattr
, ATTR_MODE
| ATTR_UID
| ATTR_GID
,
326 lr
->lr_mode
, lr
->lr_uid
, lr
->lr_gid
, lr
->lr_rdev
, objid
);
329 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
330 * eventually end up in zfs_mknode(), which assigns the object's
331 * creation time, generation number, and dnode size. The generic
332 * zfs_create() has no concept of these attributes, so we smuggle
333 * the values inside the vattr's otherwise unused va_ctime,
334 * va_nblocks, and va_fsid fields.
336 ZFS_TIME_DECODE(&xva
.xva_vattr
.va_ctime
, lr
->lr_crtime
);
337 xva
.xva_vattr
.va_nblocks
= lr
->lr_gen
;
338 xva
.xva_vattr
.va_fsid
= dnodesize
;
340 error
= dmu_object_info(zfsvfs
->z_os
, lr
->lr_foid
, NULL
);
344 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
348 aclstart
= (caddr_t
)(lracl
+ 1);
349 fuidstart
= (caddr_t
)aclstart
+
350 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
351 zfsvfs
->z_fuid_replay
= zfs_replay_fuids(fuidstart
,
352 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
353 lr
->lr_uid
, lr
->lr_gid
);
355 case TX_CREATE_ACL_ATTR
:
357 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
358 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
359 xva
.xva_vattr
.va_mask
|= ATTR_XVATTR
;
360 zfs_replay_xvattr(lrattr
, &xva
);
362 vsec
.vsa_mask
= VSA_ACE
| VSA_ACE_ACLFLAGS
;
363 vsec
.vsa_aclentp
= (caddr_t
)(lracl
+ 1) + xvatlen
;
364 vsec
.vsa_aclcnt
= lracl
->lr_aclcnt
;
365 vsec
.vsa_aclentsz
= lracl
->lr_acl_bytes
;
366 vsec
.vsa_aclflags
= lracl
->lr_acl_flags
;
367 if (zfsvfs
->z_fuid_replay
== NULL
) {
368 fuidstart
= (caddr_t
)(lracl
+ 1) + xvatlen
+
369 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
370 zfsvfs
->z_fuid_replay
=
371 zfs_replay_fuids(fuidstart
,
372 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
373 lr
->lr_uid
, lr
->lr_gid
);
376 error
= zfs_create(ZTOI(dzp
), name
, &xva
.xva_vattr
,
377 0, 0, &ip
, kcred
, vflg
, &vsec
);
380 aclstart
= (caddr_t
)(lracl
+ 1);
381 fuidstart
= (caddr_t
)aclstart
+
382 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
383 zfsvfs
->z_fuid_replay
= zfs_replay_fuids(fuidstart
,
384 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
385 lr
->lr_uid
, lr
->lr_gid
);
387 case TX_MKDIR_ACL_ATTR
:
389 lrattr
= (lr_attr_t
*)(caddr_t
)(lracl
+ 1);
390 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
391 zfs_replay_xvattr(lrattr
, &xva
);
393 vsec
.vsa_mask
= VSA_ACE
| VSA_ACE_ACLFLAGS
;
394 vsec
.vsa_aclentp
= (caddr_t
)(lracl
+ 1) + xvatlen
;
395 vsec
.vsa_aclcnt
= lracl
->lr_aclcnt
;
396 vsec
.vsa_aclentsz
= lracl
->lr_acl_bytes
;
397 vsec
.vsa_aclflags
= lracl
->lr_acl_flags
;
398 if (zfsvfs
->z_fuid_replay
== NULL
) {
399 fuidstart
= (caddr_t
)(lracl
+ 1) + xvatlen
+
400 ZIL_ACE_LENGTH(lracl
->lr_acl_bytes
);
401 zfsvfs
->z_fuid_replay
=
402 zfs_replay_fuids(fuidstart
,
403 (void *)&name
, lracl
->lr_fuidcnt
, lracl
->lr_domcnt
,
404 lr
->lr_uid
, lr
->lr_gid
);
406 error
= zfs_mkdir(ZTOI(dzp
), name
, &xva
.xva_vattr
,
407 &ip
, kcred
, vflg
, &vsec
);
410 error
= SET_ERROR(ENOTSUP
);
414 if (error
== 0 && ip
!= NULL
)
419 if (zfsvfs
->z_fuid_replay
)
420 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
421 zfsvfs
->z_fuid_replay
= NULL
;
427 zfs_replay_create(void *arg1
, void *arg2
, boolean_t byteswap
)
429 zfsvfs_t
*zfsvfs
= arg1
;
430 lr_create_t
*lr
= arg2
;
431 char *name
= NULL
; /* location determined later */
432 char *link
; /* symlink content follows name */
434 struct inode
*ip
= NULL
;
437 size_t lrsize
= sizeof (lr_create_t
);
446 txtype
= (lr
->lr_common
.lrc_txtype
& ~TX_CI
);
448 byteswap_uint64_array(lr
, sizeof (*lr
));
449 if (txtype
== TX_CREATE_ATTR
|| txtype
== TX_MKDIR_ATTR
)
450 zfs_replay_swap_attrs((lr_attr_t
*)(lr
+ 1));
454 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
457 objid
= LR_FOID_GET_OBJ(lr
->lr_foid
);
458 dnodesize
= LR_FOID_GET_SLOTS(lr
->lr_foid
) << DNODE_SHIFT
;
461 zfs_init_vattr(&xva
.xva_vattr
, ATTR_MODE
| ATTR_UID
| ATTR_GID
,
462 lr
->lr_mode
, lr
->lr_uid
, lr
->lr_gid
, lr
->lr_rdev
, objid
);
465 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
466 * eventually end up in zfs_mknode(), which assigns the object's
467 * creation time, generation number, and dnode slot count. The
468 * generic zfs_create() has no concept of these attributes, so
469 * we smuggle the values inside the vattr's otherwise unused
470 * va_ctime, va_nblocks, and va_fsid fields.
472 ZFS_TIME_DECODE(&xva
.xva_vattr
.va_ctime
, lr
->lr_crtime
);
473 xva
.xva_vattr
.va_nblocks
= lr
->lr_gen
;
474 xva
.xva_vattr
.va_fsid
= dnodesize
;
476 error
= dmu_object_info(zfsvfs
->z_os
, objid
, NULL
);
480 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
484 * Symlinks don't have fuid info, and CIFS never creates
487 * The _ATTR versions will grab the fuid info in their subcases.
489 if ((int)lr
->lr_common
.lrc_txtype
!= TX_SYMLINK
&&
490 (int)lr
->lr_common
.lrc_txtype
!= TX_MKDIR_ATTR
&&
491 (int)lr
->lr_common
.lrc_txtype
!= TX_CREATE_ATTR
) {
493 zfsvfs
->z_fuid_replay
=
494 zfs_replay_fuid_domain(start
, &start
,
495 lr
->lr_uid
, lr
->lr_gid
);
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 *)start
;
514 error
= zfs_create(ZTOI(dzp
), name
, &xva
.xva_vattr
,
515 0, 0, &ip
, kcred
, vflg
, NULL
);
518 lrattr
= (lr_attr_t
*)(caddr_t
)(lr
+ 1);
519 xvatlen
= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
520 zfs_replay_xvattr((lr_attr_t
*)((caddr_t
)lr
+ lrsize
), &xva
);
521 start
= (caddr_t
)(lr
+ 1) + xvatlen
;
522 zfsvfs
->z_fuid_replay
=
523 zfs_replay_fuid_domain(start
, &start
,
524 lr
->lr_uid
, lr
->lr_gid
);
525 name
= (char *)start
;
530 name
= (char *)(lr
+ 1);
532 error
= zfs_mkdir(ZTOI(dzp
), name
, &xva
.xva_vattr
,
533 &ip
, kcred
, vflg
, NULL
);
536 error
= zfs_make_xattrdir(dzp
, &xva
.xva_vattr
, &ip
, kcred
);
539 name
= (char *)(lr
+ 1);
540 link
= name
+ strlen(name
) + 1;
541 error
= zfs_symlink(ZTOI(dzp
), name
, &xva
.xva_vattr
,
542 link
, &ip
, kcred
, vflg
);
545 error
= SET_ERROR(ENOTSUP
);
549 if (error
== 0 && ip
!= NULL
)
554 if (zfsvfs
->z_fuid_replay
)
555 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
556 zfsvfs
->z_fuid_replay
= NULL
;
561 zfs_replay_remove(void *arg1
, void *arg2
, boolean_t byteswap
)
563 zfsvfs_t
*zfsvfs
= arg1
;
564 lr_remove_t
*lr
= arg2
;
565 char *name
= (char *)(lr
+ 1); /* name follows lr_remove_t */
571 byteswap_uint64_array(lr
, sizeof (*lr
));
573 if ((error
= zfs_zget(zfsvfs
, lr
->lr_doid
, &dzp
)) != 0)
576 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
579 switch ((int)lr
->lr_common
.lrc_txtype
) {
581 error
= zfs_remove(ZTOI(dzp
), name
, kcred
, vflg
);
584 error
= zfs_rmdir(ZTOI(dzp
), name
, NULL
, kcred
, vflg
);
587 error
= SET_ERROR(ENOTSUP
);
596 zfs_replay_link(void *arg1
, void *arg2
, boolean_t byteswap
)
598 zfsvfs_t
*zfsvfs
= arg1
;
599 lr_link_t
*lr
= arg2
;
600 char *name
= (char *)(lr
+ 1); /* name follows lr_link_t */
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
)
619 error
= zfs_link(ZTOI(dzp
), ZTOI(zp
), name
, kcred
, vflg
);
628 zfs_replay_rename(void *arg1
, void *arg2
, boolean_t byteswap
)
630 zfsvfs_t
*zfsvfs
= arg1
;
631 lr_rename_t
*lr
= arg2
;
632 char *sname
= (char *)(lr
+ 1); /* sname and tname follow lr_rename_t */
633 char *tname
= sname
+ strlen(sname
) + 1;
634 znode_t
*sdzp
, *tdzp
;
639 byteswap_uint64_array(lr
, sizeof (*lr
));
641 if ((error
= zfs_zget(zfsvfs
, lr
->lr_sdoid
, &sdzp
)) != 0)
644 if ((error
= zfs_zget(zfsvfs
, lr
->lr_tdoid
, &tdzp
)) != 0) {
649 if (lr
->lr_common
.lrc_txtype
& TX_CI
)
652 error
= zfs_rename(ZTOI(sdzp
), sname
, ZTOI(tdzp
), tname
, kcred
, vflg
);
661 zfs_replay_write(void *arg1
, void *arg2
, boolean_t byteswap
)
663 zfsvfs_t
*zfsvfs
= arg1
;
664 lr_write_t
*lr
= arg2
;
665 char *data
= (char *)(lr
+ 1); /* data follows lr_write_t */
668 uint64_t eod
, offset
, length
;
671 byteswap_uint64_array(lr
, sizeof (*lr
));
673 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0) {
675 * As we can log writes out of order, it's possible the
676 * file has been removed. In this case just drop the write
677 * and return success.
684 offset
= lr
->lr_offset
;
685 length
= lr
->lr_length
;
686 eod
= offset
+ length
; /* end of data for this write */
689 * This may be a write from a dmu_sync() for a whole block,
690 * and may extend beyond the current end of the file.
691 * We can't just replay what was written for this TX_WRITE as
692 * a future TX_WRITE2 may extend the eof and the data for that
693 * write needs to be there. So we write the whole block and
694 * reduce the eof. This needs to be done within the single dmu
695 * transaction created within vn_rdwr -> zfs_write. So a possible
696 * new end of file is passed through in zfsvfs->z_replay_eof
699 zfsvfs
->z_replay_eof
= 0; /* 0 means don't change end of file */
701 /* If it's a dmu_sync() block, write the whole block */
702 if (lr
->lr_common
.lrc_reclen
== sizeof (lr_write_t
)) {
703 uint64_t blocksize
= BP_GET_LSIZE(&lr
->lr_blkptr
);
704 if (length
< blocksize
) {
705 offset
-= offset
% blocksize
;
708 if (zp
->z_size
< eod
)
709 zfsvfs
->z_replay_eof
= eod
;
712 written
= zpl_write_common(ZTOI(zp
), data
, length
, &offset
,
713 UIO_SYSSPACE
, 0, kcred
);
716 else if (written
< length
)
717 error
= SET_ERROR(EIO
); /* short write */
720 zfsvfs
->z_replay_eof
= 0; /* safety */
726 * TX_WRITE2 are only generated when dmu_sync() returns EALREADY
727 * meaning the pool block is already being synced. So now that we always write
728 * out full blocks, all we have to do is expand the eof if
732 zfs_replay_write2(void *arg1
, void *arg2
, boolean_t byteswap
)
734 zfsvfs_t
*zfsvfs
= arg1
;
735 lr_write_t
*lr
= arg2
;
741 byteswap_uint64_array(lr
, sizeof (*lr
));
743 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0)
747 end
= lr
->lr_offset
+ lr
->lr_length
;
748 if (end
> zp
->z_size
) {
749 dmu_tx_t
*tx
= dmu_tx_create(zfsvfs
->z_os
);
752 dmu_tx_hold_sa(tx
, zp
->z_sa_hdl
, B_FALSE
);
753 error
= dmu_tx_assign(tx
, TXG_WAIT
);
756 if (error
== ERESTART
) {
764 (void) sa_update(zp
->z_sa_hdl
, SA_ZPL_SIZE(zfsvfs
),
765 (void *)&zp
->z_size
, sizeof (uint64_t), tx
);
767 /* Ensure the replayed seq is updated */
768 (void) zil_replaying(zfsvfs
->z_log
, tx
);
779 zfs_replay_truncate(void *arg1
, void *arg2
, boolean_t byteswap
)
781 zfsvfs_t
*zfsvfs
= arg1
;
782 lr_truncate_t
*lr
= arg2
;
788 byteswap_uint64_array(lr
, sizeof (*lr
));
790 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0)
793 bzero(&fl
, sizeof (fl
));
796 fl
.l_start
= lr
->lr_offset
;
797 fl
.l_len
= lr
->lr_length
;
799 error
= zfs_space(ZTOI(zp
), F_FREESP
, &fl
, FWRITE
| FOFFMAX
,
800 lr
->lr_offset
, kcred
);
808 zfs_replay_setattr(void *arg1
, void *arg2
, boolean_t byteswap
)
810 zfsvfs_t
*zfsvfs
= arg1
;
811 lr_setattr_t
*lr
= arg2
;
814 vattr_t
*vap
= &xva
.xva_vattr
;
820 byteswap_uint64_array(lr
, sizeof (*lr
));
822 if ((lr
->lr_mask
& ATTR_XVATTR
) &&
823 zfsvfs
->z_version
>= ZPL_VERSION_INITIAL
)
824 zfs_replay_swap_attrs((lr_attr_t
*)(lr
+ 1));
827 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0)
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
);
836 gethrestime(&vap
->va_ctime
);
837 vap
->va_mask
|= ATTR_CTIME
;
840 * Fill in xvattr_t portions if necessary.
843 start
= (lr_setattr_t
*)(lr
+ 1);
844 if (vap
->va_mask
& ATTR_XVATTR
) {
845 zfs_replay_xvattr((lr_attr_t
*)start
, &xva
);
846 start
= (caddr_t
)start
+
847 ZIL_XVAT_SIZE(((lr_attr_t
*)start
)->lr_attr_masksize
);
849 xva
.xva_vattr
.va_mask
&= ~ATTR_XVATTR
;
851 zfsvfs
->z_fuid_replay
= zfs_replay_fuid_domain(start
, &start
,
852 lr
->lr_uid
, lr
->lr_gid
);
854 error
= zfs_setattr(ZTOI(zp
), vap
, 0, kcred
);
856 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
857 zfsvfs
->z_fuid_replay
= NULL
;
864 zfs_replay_acl_v0(void *arg1
, void *arg2
, boolean_t byteswap
)
866 zfsvfs_t
*zfsvfs
= arg1
;
867 lr_acl_v0_t
*lr
= arg2
;
868 ace_t
*ace
= (ace_t
*)(lr
+ 1); /* ace array follows lr_acl_t */
874 byteswap_uint64_array(lr
, sizeof (*lr
));
875 zfs_oldace_byteswap(ace
, lr
->lr_aclcnt
);
878 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0)
881 bzero(&vsa
, sizeof (vsa
));
882 vsa
.vsa_mask
= VSA_ACE
| VSA_ACECNT
;
883 vsa
.vsa_aclcnt
= lr
->lr_aclcnt
;
884 vsa
.vsa_aclentsz
= sizeof (ace_t
) * vsa
.vsa_aclcnt
;
885 vsa
.vsa_aclflags
= 0;
886 vsa
.vsa_aclentp
= ace
;
888 error
= zfs_setsecattr(ZTOI(zp
), &vsa
, 0, kcred
);
896 * Replaying ACLs is complicated by FUID support.
897 * The log record may contain some optional data
898 * to be used for replaying FUID's. These pieces
899 * are the actual FUIDs that were created initially.
900 * The FUID table index may no longer be valid and
901 * during zfs_create() a new index may be assigned.
902 * Because of this the log will contain the original
903 * domain+rid in order to create a new FUID.
905 * The individual ACEs may contain an ephemeral uid/gid which is no
906 * longer valid and will need to be replaced with an actual FUID.
910 zfs_replay_acl(void *arg1
, void *arg2
, boolean_t byteswap
)
912 zfsvfs_t
*zfsvfs
= arg1
;
914 ace_t
*ace
= (ace_t
*)(lr
+ 1);
920 byteswap_uint64_array(lr
, sizeof (*lr
));
921 zfs_ace_byteswap(ace
, lr
->lr_acl_bytes
, B_FALSE
);
922 if (lr
->lr_fuidcnt
) {
923 byteswap_uint64_array((caddr_t
)ace
+
924 ZIL_ACE_LENGTH(lr
->lr_acl_bytes
),
925 lr
->lr_fuidcnt
* sizeof (uint64_t));
929 if ((error
= zfs_zget(zfsvfs
, lr
->lr_foid
, &zp
)) != 0)
932 bzero(&vsa
, sizeof (vsa
));
933 vsa
.vsa_mask
= VSA_ACE
| VSA_ACECNT
| VSA_ACE_ACLFLAGS
;
934 vsa
.vsa_aclcnt
= lr
->lr_aclcnt
;
935 vsa
.vsa_aclentp
= ace
;
936 vsa
.vsa_aclentsz
= lr
->lr_acl_bytes
;
937 vsa
.vsa_aclflags
= lr
->lr_acl_flags
;
939 if (lr
->lr_fuidcnt
) {
940 void *fuidstart
= (caddr_t
)ace
+
941 ZIL_ACE_LENGTH(lr
->lr_acl_bytes
);
943 zfsvfs
->z_fuid_replay
=
944 zfs_replay_fuids(fuidstart
, &fuidstart
,
945 lr
->lr_fuidcnt
, lr
->lr_domcnt
, 0, 0);
948 error
= zfs_setsecattr(ZTOI(zp
), &vsa
, 0, kcred
);
950 if (zfsvfs
->z_fuid_replay
)
951 zfs_fuid_info_free(zfsvfs
->z_fuid_replay
);
953 zfsvfs
->z_fuid_replay
= NULL
;
960 * Callback vectors for replaying records
962 zil_replay_func_t
*zfs_replay_vector
[TX_MAX_TYPE
] = {
963 zfs_replay_error
, /* no such type */
964 zfs_replay_create
, /* TX_CREATE */
965 zfs_replay_create
, /* TX_MKDIR */
966 zfs_replay_create
, /* TX_MKXATTR */
967 zfs_replay_create
, /* TX_SYMLINK */
968 zfs_replay_remove
, /* TX_REMOVE */
969 zfs_replay_remove
, /* TX_RMDIR */
970 zfs_replay_link
, /* TX_LINK */
971 zfs_replay_rename
, /* TX_RENAME */
972 zfs_replay_write
, /* TX_WRITE */
973 zfs_replay_truncate
, /* TX_TRUNCATE */
974 zfs_replay_setattr
, /* TX_SETATTR */
975 zfs_replay_acl_v0
, /* TX_ACL_V0 */
976 zfs_replay_acl
, /* TX_ACL */
977 zfs_replay_create_acl
, /* TX_CREATE_ACL */
978 zfs_replay_create
, /* TX_CREATE_ATTR */
979 zfs_replay_create_acl
, /* TX_CREATE_ACL_ATTR */
980 zfs_replay_create_acl
, /* TX_MKDIR_ACL */
981 zfs_replay_create
, /* TX_MKDIR_ATTR */
982 zfs_replay_create_acl
, /* TX_MKDIR_ACL_ATTR */
983 zfs_replay_write2
, /* TX_WRITE2 */