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