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