]> git.proxmox.com Git - mirror_zfs.git/blob - module/zfs/zfs_log.c
Wrap with HAVE_XVATTR
[mirror_zfs.git] / module / zfs / zfs_log.c
1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/sysmacros.h>
30 #include <sys/cmn_err.h>
31 #include <sys/kmem.h>
32 #include <sys/thread.h>
33 #include <sys/file.h>
34 #include <sys/vfs.h>
35 #include <sys/zfs_znode.h>
36 #include <sys/zfs_dir.h>
37 #include <sys/zil.h>
38 #include <sys/zil_impl.h>
39 #include <sys/byteorder.h>
40 #include <sys/policy.h>
41 #include <sys/stat.h>
42 #include <sys/mode.h>
43 #include <sys/acl.h>
44 #include <sys/dmu.h>
45 #include <sys/spa.h>
46 #include <sys/zfs_fuid.h>
47 #include <sys/ddi.h>
48 #include <sys/dsl_dataset.h>
49
50 /*
51 * These zfs_log_* functions must be called within a dmu tx, in one
52 * of 2 contexts depending on zilog->z_replay:
53 *
54 * Non replay mode
55 * ---------------
56 * We need to record the transaction so that if it is committed to
57 * the Intent Log then it can be replayed. An intent log transaction
58 * structure (itx_t) is allocated and all the information necessary to
59 * possibly replay the transaction is saved in it. The itx is then assigned
60 * a sequence number and inserted in the in-memory list anchored in the zilog.
61 *
62 * Replay mode
63 * -----------
64 * We need to mark the intent log record as replayed in the log header.
65 * This is done in the same transaction as the replay so that they
66 * commit atomically.
67 */
68
69 int
70 zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
71 {
72 #ifdef HAVE_XVATTR
73 int isxvattr = (vap->va_mask & AT_XVATTR);
74 #else
75 int isxvattr = 0;
76 #endif /* HAVE_XVATTR */
77 switch (type) {
78 case Z_FILE:
79 if (vsecp == NULL && !isxvattr)
80 return (TX_CREATE);
81 if (vsecp && isxvattr)
82 return (TX_CREATE_ACL_ATTR);
83 if (vsecp)
84 return (TX_CREATE_ACL);
85 else
86 return (TX_CREATE_ATTR);
87 /*NOTREACHED*/
88 case Z_DIR:
89 if (vsecp == NULL && !isxvattr)
90 return (TX_MKDIR);
91 if (vsecp && isxvattr)
92 return (TX_MKDIR_ACL_ATTR);
93 if (vsecp)
94 return (TX_MKDIR_ACL);
95 else
96 return (TX_MKDIR_ATTR);
97 case Z_XATTRDIR:
98 return (TX_MKXATTR);
99 }
100 ASSERT(0);
101 return (TX_MAX_TYPE);
102 }
103
104 #ifdef HAVE_XVATTR
105 /*
106 * build up the log data necessary for logging xvattr_t
107 * First lr_attr_t is initialized. following the lr_attr_t
108 * is the mapsize and attribute bitmap copied from the xvattr_t.
109 * Following the bitmap and bitmapsize two 64 bit words are reserved
110 * for the create time which may be set. Following the create time
111 * records a single 64 bit integer which has the bits to set on
112 * replay for the xvattr.
113 */
114 static void
115 zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
116 {
117 uint32_t *bitmap;
118 uint64_t *attrs;
119 uint64_t *crtime;
120 xoptattr_t *xoap;
121 void *scanstamp;
122 int i;
123
124 xoap = xva_getxoptattr(xvap);
125 ASSERT(xoap);
126
127 lrattr->lr_attr_masksize = xvap->xva_mapsize;
128 bitmap = &lrattr->lr_attr_bitmap;
129 for (i = 0; i != xvap->xva_mapsize; i++, bitmap++) {
130 *bitmap = xvap->xva_reqattrmap[i];
131 }
132
133 /* Now pack the attributes up in a single uint64_t */
134 attrs = (uint64_t *)bitmap;
135 crtime = attrs + 1;
136 scanstamp = (caddr_t)(crtime + 2);
137 *attrs = 0;
138 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
139 *attrs |= (xoap->xoa_readonly == 0) ? 0 :
140 XAT0_READONLY;
141 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
142 *attrs |= (xoap->xoa_hidden == 0) ? 0 :
143 XAT0_HIDDEN;
144 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
145 *attrs |= (xoap->xoa_system == 0) ? 0 :
146 XAT0_SYSTEM;
147 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
148 *attrs |= (xoap->xoa_archive == 0) ? 0 :
149 XAT0_ARCHIVE;
150 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
151 *attrs |= (xoap->xoa_immutable == 0) ? 0 :
152 XAT0_IMMUTABLE;
153 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
154 *attrs |= (xoap->xoa_nounlink == 0) ? 0 :
155 XAT0_NOUNLINK;
156 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
157 *attrs |= (xoap->xoa_appendonly == 0) ? 0 :
158 XAT0_APPENDONLY;
159 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
160 *attrs |= (xoap->xoa_opaque == 0) ? 0 :
161 XAT0_APPENDONLY;
162 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
163 *attrs |= (xoap->xoa_nodump == 0) ? 0 :
164 XAT0_NODUMP;
165 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
166 *attrs |= (xoap->xoa_av_quarantined == 0) ? 0 :
167 XAT0_AV_QUARANTINED;
168 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
169 *attrs |= (xoap->xoa_av_modified == 0) ? 0 :
170 XAT0_AV_MODIFIED;
171 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
172 ZFS_TIME_ENCODE(&xoap->xoa_createtime, crtime);
173 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
174 bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ);
175 if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
176 *attrs |= (xoap->xoa_reparse == 0) ? 0 :
177 XAT0_REPARSE;
178 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
179 *attrs |= (xoap->xoa_offline == 0) ? 0 :
180 XAT0_OFFLINE;
181 if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
182 *attrs |= (xoap->xoa_sparse == 0) ? 0 :
183 XAT0_SPARSE;
184 }
185
186 static void *
187 zfs_log_fuid_ids(zfs_fuid_info_t *fuidp, void *start)
188 {
189 zfs_fuid_t *zfuid;
190 uint64_t *fuidloc = start;
191
192 /* First copy in the ACE FUIDs */
193 for (zfuid = list_head(&fuidp->z_fuids); zfuid;
194 zfuid = list_next(&fuidp->z_fuids, zfuid)) {
195 *fuidloc++ = zfuid->z_logfuid;
196 }
197 return (fuidloc);
198 }
199
200
201 static void *
202 zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
203 {
204 zfs_fuid_domain_t *zdomain;
205
206 /* now copy in the domain info, if any */
207 if (fuidp->z_domain_str_sz != 0) {
208 for (zdomain = list_head(&fuidp->z_domains); zdomain;
209 zdomain = list_next(&fuidp->z_domains, zdomain)) {
210 bcopy((void *)zdomain->z_domain, start,
211 strlen(zdomain->z_domain) + 1);
212 start = (caddr_t)start +
213 strlen(zdomain->z_domain) + 1;
214 }
215 }
216 return (start);
217 }
218 #endif /* HAVE_XVATTR */
219
220 /*
221 * zfs_log_create() is used to handle TX_CREATE, TX_CREATE_ATTR, TX_MKDIR,
222 * TX_MKDIR_ATTR and TX_MKXATTR
223 * transactions.
224 *
225 * TX_CREATE and TX_MKDIR are standard creates, but they may have FUID
226 * domain information appended prior to the name. In this case the
227 * uid/gid in the log record will be a log centric FUID.
228 *
229 * TX_CREATE_ACL_ATTR and TX_MKDIR_ACL_ATTR handle special creates that
230 * may contain attributes, ACL and optional fuid information.
231 *
232 * TX_CREATE_ACL and TX_MKDIR_ACL handle special creates that specify
233 * and ACL and normal users/groups in the ACEs.
234 *
235 * There may be an optional xvattr attribute information similar
236 * to zfs_log_setattr.
237 *
238 * Also, after the file name "domain" strings may be appended.
239 */
240 void
241 zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
242 znode_t *dzp, znode_t *zp, char *name, vsecattr_t *vsecp,
243 zfs_fuid_info_t *fuidp, vattr_t *vap)
244 {
245 itx_t *itx;
246 lr_create_t *lr;
247 #ifdef HAVE_XVATTR
248 lr_acl_create_t *lracl;
249 xvattr_t *xvap = (xvattr_t *)vap;
250 #endif /* HAVE_XVATTR */
251 size_t aclsize;
252 size_t xvatsize = 0;
253 size_t txsize;
254 void *end;
255 size_t lrsize;
256 size_t namesize = strlen(name) + 1;
257 size_t fuidsz = 0;
258
259 if (zil_replaying(zilog, tx))
260 return;
261
262 /*
263 * If we have FUIDs present then add in space for
264 * domains and ACE fuid's if any.
265 */
266 if (fuidp) {
267 fuidsz += fuidp->z_domain_str_sz;
268 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
269 }
270
271 #ifdef HAVE_XVATTR
272 if (vap->va_mask & AT_XVATTR)
273 xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize);
274 #endif /* HAVE_XVATTR */
275
276 if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
277 (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
278 (int)txtype == TX_MKXATTR) {
279 txsize = sizeof (*lr) + namesize + fuidsz + xvatsize;
280 lrsize = sizeof (*lr);
281 } else {
282 aclsize = (vsecp) ? vsecp->vsa_aclentsz : 0;
283 txsize =
284 sizeof (lr_acl_create_t) + namesize + fuidsz +
285 ZIL_ACE_LENGTH(aclsize) + xvatsize;
286 lrsize = sizeof (lr_acl_create_t);
287 }
288
289 itx = zil_itx_create(txtype, txsize);
290
291 lr = (lr_create_t *)&itx->itx_lr;
292 lr->lr_doid = dzp->z_id;
293 lr->lr_foid = zp->z_id;
294 lr->lr_mode = zp->z_mode;
295 if (!IS_EPHEMERAL(zp->z_uid)) {
296 lr->lr_uid = (uint64_t)zp->z_uid;
297 } else {
298 lr->lr_uid = fuidp->z_fuid_owner;
299 }
300 if (!IS_EPHEMERAL(zp->z_gid)) {
301 lr->lr_gid = (uint64_t)zp->z_gid;
302 } else {
303 lr->lr_gid = fuidp->z_fuid_group;
304 }
305 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(ZTOZSB(zp)), &lr->lr_gen,
306 sizeof (uint64_t));
307 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
308 lr->lr_crtime, sizeof (uint64_t) * 2);
309
310 if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(ZTOZSB(zp)), &lr->lr_rdev,
311 sizeof (lr->lr_rdev)) != 0)
312 lr->lr_rdev = 0;
313
314 /*
315 * Fill in xvattr info if any
316 */
317 #ifdef HAVE_XVATTR
318 if (vap->va_mask & AT_XVATTR) {
319 zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
320 end = (caddr_t)lr + lrsize + xvatsize;
321 } else {
322 end = (caddr_t)lr + lrsize;
323 }
324
325 /* Now fill in any ACL info */
326
327 if (vsecp) {
328 lracl = (lr_acl_create_t *)&itx->itx_lr;
329 lracl->lr_aclcnt = vsecp->vsa_aclcnt;
330 lracl->lr_acl_bytes = aclsize;
331 lracl->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
332 lracl->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
333 if (vsecp->vsa_aclflags & VSA_ACE_ACLFLAGS)
334 lracl->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
335 else
336 lracl->lr_acl_flags = 0;
337
338 bcopy(vsecp->vsa_aclentp, end, aclsize);
339 end = (caddr_t)end + ZIL_ACE_LENGTH(aclsize);
340 }
341
342 /* drop in FUID info */
343 if (fuidp) {
344 end = zfs_log_fuid_ids(fuidp, end);
345 end = zfs_log_fuid_domains(fuidp, end);
346 }
347 #else
348 end = (caddr_t)lr + lrsize;
349 #endif /* HAVE_XVATTR */
350 /*
351 * Now place file name in log record
352 */
353 bcopy(name, end, namesize);
354
355 zil_itx_assign(zilog, itx, tx);
356 }
357
358 /*
359 * zfs_log_remove() handles both TX_REMOVE and TX_RMDIR transactions.
360 */
361 void
362 zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
363 znode_t *dzp, char *name, uint64_t foid)
364 {
365 itx_t *itx;
366 lr_remove_t *lr;
367 size_t namesize = strlen(name) + 1;
368
369 if (zil_replaying(zilog, tx))
370 return;
371
372 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
373 lr = (lr_remove_t *)&itx->itx_lr;
374 lr->lr_doid = dzp->z_id;
375 bcopy(name, (char *)(lr + 1), namesize);
376
377 itx->itx_oid = foid;
378
379 zil_itx_assign(zilog, itx, tx);
380 }
381
382 /*
383 * zfs_log_link() handles TX_LINK transactions.
384 */
385 void
386 zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
387 znode_t *dzp, znode_t *zp, char *name)
388 {
389 itx_t *itx;
390 lr_link_t *lr;
391 size_t namesize = strlen(name) + 1;
392
393 if (zil_replaying(zilog, tx))
394 return;
395
396 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
397 lr = (lr_link_t *)&itx->itx_lr;
398 lr->lr_doid = dzp->z_id;
399 lr->lr_link_obj = zp->z_id;
400 bcopy(name, (char *)(lr + 1), namesize);
401
402 zil_itx_assign(zilog, itx, tx);
403 }
404
405 /*
406 * zfs_log_symlink() handles TX_SYMLINK transactions.
407 */
408 void
409 zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
410 znode_t *dzp, znode_t *zp, char *name, char *link)
411 {
412 itx_t *itx;
413 lr_create_t *lr;
414 size_t namesize = strlen(name) + 1;
415 size_t linksize = strlen(link) + 1;
416
417 if (zil_replaying(zilog, tx))
418 return;
419
420 itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
421 lr = (lr_create_t *)&itx->itx_lr;
422 lr->lr_doid = dzp->z_id;
423 lr->lr_foid = zp->z_id;
424 lr->lr_uid = zp->z_uid;
425 lr->lr_gid = zp->z_gid;
426 lr->lr_mode = zp->z_mode;
427 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(ZTOZSB(zp)), &lr->lr_gen,
428 sizeof (uint64_t));
429 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
430 lr->lr_crtime, sizeof (uint64_t) * 2);
431 bcopy(name, (char *)(lr + 1), namesize);
432 bcopy(link, (char *)(lr + 1) + namesize, linksize);
433
434 zil_itx_assign(zilog, itx, tx);
435 }
436
437 /*
438 * zfs_log_rename() handles TX_RENAME transactions.
439 */
440 void
441 zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
442 znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
443 {
444 itx_t *itx;
445 lr_rename_t *lr;
446 size_t snamesize = strlen(sname) + 1;
447 size_t dnamesize = strlen(dname) + 1;
448
449 if (zil_replaying(zilog, tx))
450 return;
451
452 itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
453 lr = (lr_rename_t *)&itx->itx_lr;
454 lr->lr_sdoid = sdzp->z_id;
455 lr->lr_tdoid = tdzp->z_id;
456 bcopy(sname, (char *)(lr + 1), snamesize);
457 bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
458 itx->itx_oid = szp->z_id;
459
460 zil_itx_assign(zilog, itx, tx);
461 }
462
463 /*
464 * zfs_log_write() handles TX_WRITE transactions.
465 */
466 ssize_t zfs_immediate_write_sz = 32768;
467
468 void
469 zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
470 znode_t *zp, offset_t off, ssize_t resid, int ioflag)
471 {
472 itx_wr_state_t write_state;
473 boolean_t slogging;
474 uintptr_t fsync_cnt;
475 ssize_t immediate_write_sz;
476
477 if (zil_replaying(zilog, tx) || zp->z_unlinked)
478 return;
479
480 immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
481 ? 0 : zfs_immediate_write_sz;
482
483 slogging = spa_has_slogs(zilog->zl_spa) &&
484 (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
485 if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
486 write_state = WR_INDIRECT;
487 else if (ioflag & (FSYNC | FDSYNC))
488 write_state = WR_COPIED;
489 else
490 write_state = WR_NEED_COPY;
491
492 if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) {
493 (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1));
494 }
495
496 while (resid) {
497 itx_t *itx;
498 lr_write_t *lr;
499 ssize_t len;
500
501 /*
502 * If the write would overflow the largest block then split it.
503 */
504 if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
505 len = SPA_MAXBLOCKSIZE >> 1;
506 else
507 len = resid;
508
509 itx = zil_itx_create(txtype, sizeof (*lr) +
510 (write_state == WR_COPIED ? len : 0));
511 lr = (lr_write_t *)&itx->itx_lr;
512 if (write_state == WR_COPIED && dmu_read(ZTOZSB(zp)->z_os,
513 zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
514 zil_itx_destroy(itx);
515 itx = zil_itx_create(txtype, sizeof (*lr));
516 lr = (lr_write_t *)&itx->itx_lr;
517 write_state = WR_NEED_COPY;
518 }
519
520 itx->itx_wr_state = write_state;
521 if (write_state == WR_NEED_COPY)
522 itx->itx_sod += len;
523 lr->lr_foid = zp->z_id;
524 lr->lr_offset = off;
525 lr->lr_length = len;
526 lr->lr_blkoff = 0;
527 BP_ZERO(&lr->lr_blkptr);
528
529 itx->itx_private = ZTOZSB(zp);
530
531 if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
532 (fsync_cnt == 0))
533 itx->itx_sync = B_FALSE;
534
535 zil_itx_assign(zilog, itx, tx);
536
537 off += len;
538 resid -= len;
539 }
540 }
541
542 /*
543 * zfs_log_truncate() handles TX_TRUNCATE transactions.
544 */
545 void
546 zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
547 znode_t *zp, uint64_t off, uint64_t len)
548 {
549 itx_t *itx;
550 lr_truncate_t *lr;
551
552 if (zil_replaying(zilog, tx) || zp->z_unlinked)
553 return;
554
555 itx = zil_itx_create(txtype, sizeof (*lr));
556 lr = (lr_truncate_t *)&itx->itx_lr;
557 lr->lr_foid = zp->z_id;
558 lr->lr_offset = off;
559 lr->lr_length = len;
560
561 itx->itx_sync = (zp->z_sync_cnt != 0);
562 zil_itx_assign(zilog, itx, tx);
563 }
564
565 /*
566 * zfs_log_setattr() handles TX_SETATTR transactions.
567 */
568 void
569 zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype, znode_t *zp,
570 struct iattr *attr, uint_t mask_applied, zfs_fuid_info_t *fuidp)
571 {
572 itx_t *itx;
573 lr_setattr_t *lr;
574 #ifdef HAVE_XVATTR
575 xvattr_t *xvap = (xvattr_t *)vap;
576 #endif /* HAVEXVATTR */
577 size_t recsize = sizeof (lr_setattr_t);
578 void *start;
579
580 if (zil_replaying(zilog, tx) || zp->z_unlinked)
581 return;
582
583 /*
584 * If XVATTR set, then log record size needs to allow
585 * for lr_attr_t + xvattr mask, mapsize and create time
586 * plus actual attribute values
587 */
588 #ifdef HAVE_XVATTR
589 if (attr->ia_valid & AT_XVATTR)
590 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
591
592 if (fuidp)
593 recsize += fuidp->z_domain_str_sz;
594 #endif /* HAVE_XVATTR */
595
596 itx = zil_itx_create(txtype, recsize);
597 lr = (lr_setattr_t *)&itx->itx_lr;
598 lr->lr_foid = zp->z_id;
599 lr->lr_mask = (uint64_t)mask_applied;
600 lr->lr_mode = (uint64_t)attr->ia_mode;
601 if ((mask_applied & ATTR_UID) && IS_EPHEMERAL(attr->ia_uid))
602 lr->lr_uid = fuidp->z_fuid_owner;
603 else
604 lr->lr_uid = (uint64_t)attr->ia_uid;
605
606 if ((mask_applied & ATTR_GID) && IS_EPHEMERAL(attr->ia_gid))
607 lr->lr_gid = fuidp->z_fuid_group;
608 else
609 lr->lr_gid = (uint64_t)attr->ia_gid;
610
611 lr->lr_size = (uint64_t)attr->ia_size;
612 ZFS_TIME_ENCODE(&attr->ia_atime, lr->lr_atime);
613 ZFS_TIME_ENCODE(&attr->ia_mtime, lr->lr_mtime);
614 start = (lr_setattr_t *)(lr + 1);
615 #ifdef HAVE_XVATTR
616 if (attr->ia_valid & ATTR_XVATTR) {
617 zfs_log_xvattr((lr_attr_t *)start, xvap);
618 start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
619 }
620
621 /*
622 * Now stick on domain information if any on end
623 */
624
625 if (fuidp)
626 (void) zfs_log_fuid_domains(fuidp, start);
627 #endif /* HAVE_XVATTR */
628
629 itx->itx_sync = (zp->z_sync_cnt != 0);
630 zil_itx_assign(zilog, itx, tx);
631 }
632
633 /*
634 * zfs_log_acl() handles TX_ACL transactions.
635 */
636 void
637 zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
638 vsecattr_t *vsecp, zfs_fuid_info_t *fuidp)
639 {
640 itx_t *itx;
641 lr_acl_v0_t *lrv0;
642 lr_acl_t *lr;
643 int txtype;
644 int lrsize;
645 size_t txsize;
646 size_t aclbytes = vsecp->vsa_aclentsz;
647
648 if (zil_replaying(zilog, tx) || zp->z_unlinked)
649 return;
650
651 txtype = (ZTOZSB(zp)->z_version < ZPL_VERSION_FUID) ?
652 TX_ACL_V0 : TX_ACL;
653
654 if (txtype == TX_ACL)
655 lrsize = sizeof (*lr);
656 else
657 lrsize = sizeof (*lrv0);
658
659 txsize = lrsize +
660 ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +
661 (fuidp ? fuidp->z_domain_str_sz : 0) +
662 sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0);
663
664 itx = zil_itx_create(txtype, txsize);
665
666 lr = (lr_acl_t *)&itx->itx_lr;
667 lr->lr_foid = zp->z_id;
668 if (txtype == TX_ACL) {
669 lr->lr_acl_bytes = aclbytes;
670 lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
671 lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
672 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS)
673 lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
674 else
675 lr->lr_acl_flags = 0;
676 }
677 lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt;
678
679 if (txtype == TX_ACL_V0) {
680 lrv0 = (lr_acl_v0_t *)lr;
681 bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes);
682 } else {
683 void *start = (ace_t *)(lr + 1);
684
685 bcopy(vsecp->vsa_aclentp, start, aclbytes);
686
687 start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes);
688
689 #ifdef HAVE_XVATTR
690 if (fuidp) {
691 start = zfs_log_fuid_ids(fuidp, start);
692 (void) zfs_log_fuid_domains(fuidp, start);
693 }
694 #endif /* HAVE_XVATTR */
695 }
696
697 itx->itx_sync = (zp->z_sync_cnt != 0);
698 zil_itx_assign(zilog, itx, tx);
699 }