]> git.proxmox.com Git - mirror_zfs.git/blame - module/zfs/zfs_log.c
Fletcher4: Incremental updates and ctx calculation
[mirror_zfs.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/*
572e2857 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
34dc7c2f
BB
23 */
24
60101509 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
34dc7c2f 50/*
fb5f0bc8
BB
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.
34dc7c2f
BB
67 */
68
69int
70zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
71{
5484965a 72 int isxvattr = (vap->va_mask & ATTR_XVATTR);
34dc7c2f
BB
73 switch (type) {
74 case Z_FILE:
75 if (vsecp == NULL && !isxvattr)
76 return (TX_CREATE);
77 if (vsecp && isxvattr)
78 return (TX_CREATE_ACL_ATTR);
79 if (vsecp)
80 return (TX_CREATE_ACL);
81 else
82 return (TX_CREATE_ATTR);
83 /*NOTREACHED*/
84 case Z_DIR:
85 if (vsecp == NULL && !isxvattr)
86 return (TX_MKDIR);
87 if (vsecp && isxvattr)
88 return (TX_MKDIR_ACL_ATTR);
89 if (vsecp)
90 return (TX_MKDIR_ACL);
91 else
92 return (TX_MKDIR_ATTR);
93 case Z_XATTRDIR:
94 return (TX_MKXATTR);
95 }
96 ASSERT(0);
97 return (TX_MAX_TYPE);
98}
99
100/*
101 * build up the log data necessary for logging xvattr_t
102 * First lr_attr_t is initialized. following the lr_attr_t
103 * is the mapsize and attribute bitmap copied from the xvattr_t.
104 * Following the bitmap and bitmapsize two 64 bit words are reserved
105 * for the create time which may be set. Following the create time
106 * records a single 64 bit integer which has the bits to set on
107 * replay for the xvattr.
108 */
109static void
110zfs_log_xvattr(lr_attr_t *lrattr, xvattr_t *xvap)
111{
112 uint32_t *bitmap;
113 uint64_t *attrs;
114 uint64_t *crtime;
115 xoptattr_t *xoap;
116 void *scanstamp;
117 int i;
118
119 xoap = xva_getxoptattr(xvap);
120 ASSERT(xoap);
121
122 lrattr->lr_attr_masksize = xvap->xva_mapsize;
123 bitmap = &lrattr->lr_attr_bitmap;
124 for (i = 0; i != xvap->xva_mapsize; i++, bitmap++) {
125 *bitmap = xvap->xva_reqattrmap[i];
126 }
127
128 /* Now pack the attributes up in a single uint64_t */
129 attrs = (uint64_t *)bitmap;
130 crtime = attrs + 1;
131 scanstamp = (caddr_t)(crtime + 2);
132 *attrs = 0;
133 if (XVA_ISSET_REQ(xvap, XAT_READONLY))
134 *attrs |= (xoap->xoa_readonly == 0) ? 0 :
135 XAT0_READONLY;
136 if (XVA_ISSET_REQ(xvap, XAT_HIDDEN))
137 *attrs |= (xoap->xoa_hidden == 0) ? 0 :
138 XAT0_HIDDEN;
139 if (XVA_ISSET_REQ(xvap, XAT_SYSTEM))
140 *attrs |= (xoap->xoa_system == 0) ? 0 :
141 XAT0_SYSTEM;
142 if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE))
143 *attrs |= (xoap->xoa_archive == 0) ? 0 :
144 XAT0_ARCHIVE;
145 if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE))
146 *attrs |= (xoap->xoa_immutable == 0) ? 0 :
147 XAT0_IMMUTABLE;
148 if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK))
149 *attrs |= (xoap->xoa_nounlink == 0) ? 0 :
150 XAT0_NOUNLINK;
151 if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY))
152 *attrs |= (xoap->xoa_appendonly == 0) ? 0 :
153 XAT0_APPENDONLY;
154 if (XVA_ISSET_REQ(xvap, XAT_OPAQUE))
155 *attrs |= (xoap->xoa_opaque == 0) ? 0 :
156 XAT0_APPENDONLY;
157 if (XVA_ISSET_REQ(xvap, XAT_NODUMP))
158 *attrs |= (xoap->xoa_nodump == 0) ? 0 :
159 XAT0_NODUMP;
160 if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED))
161 *attrs |= (xoap->xoa_av_quarantined == 0) ? 0 :
162 XAT0_AV_QUARANTINED;
163 if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED))
164 *attrs |= (xoap->xoa_av_modified == 0) ? 0 :
165 XAT0_AV_MODIFIED;
166 if (XVA_ISSET_REQ(xvap, XAT_CREATETIME))
167 ZFS_TIME_ENCODE(&xoap->xoa_createtime, crtime);
168 if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
169 bcopy(xoap->xoa_av_scanstamp, scanstamp, AV_SCANSTAMP_SZ);
428870ff
BB
170 if (XVA_ISSET_REQ(xvap, XAT_REPARSE))
171 *attrs |= (xoap->xoa_reparse == 0) ? 0 :
172 XAT0_REPARSE;
572e2857
BB
173 if (XVA_ISSET_REQ(xvap, XAT_OFFLINE))
174 *attrs |= (xoap->xoa_offline == 0) ? 0 :
175 XAT0_OFFLINE;
176 if (XVA_ISSET_REQ(xvap, XAT_SPARSE))
177 *attrs |= (xoap->xoa_sparse == 0) ? 0 :
178 XAT0_SPARSE;
34dc7c2f
BB
179}
180
181static void *
182zfs_log_fuid_ids(zfs_fuid_info_t *fuidp, void *start)
183{
184 zfs_fuid_t *zfuid;
185 uint64_t *fuidloc = start;
186
187 /* First copy in the ACE FUIDs */
188 for (zfuid = list_head(&fuidp->z_fuids); zfuid;
189 zfuid = list_next(&fuidp->z_fuids, zfuid)) {
190 *fuidloc++ = zfuid->z_logfuid;
191 }
192 return (fuidloc);
193}
194
195
196static void *
197zfs_log_fuid_domains(zfs_fuid_info_t *fuidp, void *start)
198{
199 zfs_fuid_domain_t *zdomain;
200
201 /* now copy in the domain info, if any */
202 if (fuidp->z_domain_str_sz != 0) {
203 for (zdomain = list_head(&fuidp->z_domains); zdomain;
204 zdomain = list_next(&fuidp->z_domains, zdomain)) {
205 bcopy((void *)zdomain->z_domain, start,
206 strlen(zdomain->z_domain) + 1);
207 start = (caddr_t)start +
208 strlen(zdomain->z_domain) + 1;
209 }
210 }
211 return (start);
212}
213
214/*
d3cc8b15
WA
215 * Handles TX_CREATE, TX_CREATE_ATTR, TX_MKDIR, TX_MKDIR_ATTR and
216 * TK_MKXATTR transactions.
34dc7c2f
BB
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;
34dc7c2f
BB
239 lr_create_t *lr;
240 lr_acl_create_t *lracl;
5484965a 241 size_t aclsize = 0;
34dc7c2f
BB
242 size_t xvatsize = 0;
243 size_t txsize;
a117a6d6 244 xvattr_t *xvap = (xvattr_t *)vap;
34dc7c2f
BB
245 void *end;
246 size_t lrsize;
34dc7c2f
BB
247 size_t namesize = strlen(name) + 1;
248 size_t fuidsz = 0;
249
428870ff 250 if (zil_replaying(zilog, tx))
34dc7c2f
BB
251 return;
252
253 /*
254 * If we have FUIDs present then add in space for
255 * domains and ACE fuid's if any.
256 */
257 if (fuidp) {
258 fuidsz += fuidp->z_domain_str_sz;
259 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
260 }
261
5484965a 262 if (vap->va_mask & ATTR_XVATTR)
34dc7c2f
BB
263 xvatsize = ZIL_XVAT_SIZE(xvap->xva_mapsize);
264
265 if ((int)txtype == TX_CREATE_ATTR || (int)txtype == TX_MKDIR_ATTR ||
266 (int)txtype == TX_CREATE || (int)txtype == TX_MKDIR ||
267 (int)txtype == TX_MKXATTR) {
268 txsize = sizeof (*lr) + namesize + fuidsz + xvatsize;
269 lrsize = sizeof (*lr);
270 } else {
34dc7c2f
BB
271 txsize =
272 sizeof (lr_acl_create_t) + namesize + fuidsz +
273 ZIL_ACE_LENGTH(aclsize) + xvatsize;
274 lrsize = sizeof (lr_acl_create_t);
275 }
276
277 itx = zil_itx_create(txtype, txsize);
278
279 lr = (lr_create_t *)&itx->itx_lr;
280 lr->lr_doid = dzp->z_id;
281 lr->lr_foid = zp->z_id;
50c957f7
NB
282 /* Store dnode slot count in 8 bits above object id. */
283 LR_FOID_SET_SLOTS(lr->lr_foid, zp->z_dnodesize >> DNODE_SHIFT);
428870ff 284 lr->lr_mode = zp->z_mode;
2c6abf15
NB
285 if (!IS_EPHEMERAL(KUID_TO_SUID(ZTOI(zp)->i_uid))) {
286 lr->lr_uid = (uint64_t)KUID_TO_SUID(ZTOI(zp)->i_uid);
34dc7c2f
BB
287 } else {
288 lr->lr_uid = fuidp->z_fuid_owner;
289 }
2c6abf15
NB
290 if (!IS_EPHEMERAL(KGID_TO_SGID(ZTOI(zp)->i_gid))) {
291 lr->lr_gid = (uint64_t)KGID_TO_SGID(ZTOI(zp)->i_gid);
34dc7c2f
BB
292 } else {
293 lr->lr_gid = fuidp->z_fuid_group;
294 }
633e8030 295 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(ZTOZSB(zp)), &lr->lr_gen,
428870ff 296 sizeof (uint64_t));
633e8030 297 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
428870ff
BB
298 lr->lr_crtime, sizeof (uint64_t) * 2);
299
633e8030 300 if (sa_lookup(zp->z_sa_hdl, SA_ZPL_RDEV(ZTOZSB(zp)), &lr->lr_rdev,
428870ff
BB
301 sizeof (lr->lr_rdev)) != 0)
302 lr->lr_rdev = 0;
34dc7c2f
BB
303
304 /*
305 * Fill in xvattr info if any
306 */
5484965a 307 if (vap->va_mask & ATTR_XVATTR) {
34dc7c2f
BB
308 zfs_log_xvattr((lr_attr_t *)((caddr_t)lr + lrsize), xvap);
309 end = (caddr_t)lr + lrsize + xvatsize;
310 } else {
311 end = (caddr_t)lr + lrsize;
312 }
313
314 /* Now fill in any ACL info */
315
316 if (vsecp) {
317 lracl = (lr_acl_create_t *)&itx->itx_lr;
318 lracl->lr_aclcnt = vsecp->vsa_aclcnt;
319 lracl->lr_acl_bytes = aclsize;
320 lracl->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
321 lracl->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
322 if (vsecp->vsa_aclflags & VSA_ACE_ACLFLAGS)
323 lracl->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
324 else
325 lracl->lr_acl_flags = 0;
326
327 bcopy(vsecp->vsa_aclentp, end, aclsize);
328 end = (caddr_t)end + ZIL_ACE_LENGTH(aclsize);
329 }
330
331 /* drop in FUID info */
332 if (fuidp) {
333 end = zfs_log_fuid_ids(fuidp, end);
334 end = zfs_log_fuid_domains(fuidp, end);
335 }
336 /*
337 * Now place file name in log record
338 */
339 bcopy(name, end, namesize);
340
572e2857 341 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
342}
343
344/*
d3cc8b15 345 * Handles both TX_REMOVE and TX_RMDIR transactions.
34dc7c2f
BB
346 */
347void
348zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
572e2857 349 znode_t *dzp, char *name, uint64_t foid)
34dc7c2f
BB
350{
351 itx_t *itx;
34dc7c2f
BB
352 lr_remove_t *lr;
353 size_t namesize = strlen(name) + 1;
354
428870ff 355 if (zil_replaying(zilog, tx))
34dc7c2f
BB
356 return;
357
358 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
359 lr = (lr_remove_t *)&itx->itx_lr;
360 lr->lr_doid = dzp->z_id;
361 bcopy(name, (char *)(lr + 1), namesize);
362
572e2857
BB
363 itx->itx_oid = foid;
364
365 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
366}
367
368/*
d3cc8b15 369 * Handles TX_LINK transactions.
34dc7c2f
BB
370 */
371void
372zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
373 znode_t *dzp, znode_t *zp, char *name)
374{
375 itx_t *itx;
34dc7c2f
BB
376 lr_link_t *lr;
377 size_t namesize = strlen(name) + 1;
378
428870ff 379 if (zil_replaying(zilog, tx))
34dc7c2f
BB
380 return;
381
382 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
383 lr = (lr_link_t *)&itx->itx_lr;
384 lr->lr_doid = dzp->z_id;
385 lr->lr_link_obj = zp->z_id;
386 bcopy(name, (char *)(lr + 1), namesize);
387
572e2857 388 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
389}
390
391/*
d3cc8b15 392 * Handles TX_SYMLINK transactions.
34dc7c2f
BB
393 */
394void
395zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
396 znode_t *dzp, znode_t *zp, char *name, char *link)
397{
398 itx_t *itx;
34dc7c2f
BB
399 lr_create_t *lr;
400 size_t namesize = strlen(name) + 1;
401 size_t linksize = strlen(link) + 1;
402
428870ff 403 if (zil_replaying(zilog, tx))
34dc7c2f
BB
404 return;
405
406 itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
407 lr = (lr_create_t *)&itx->itx_lr;
408 lr->lr_doid = dzp->z_id;
409 lr->lr_foid = zp->z_id;
2c6abf15
NB
410 lr->lr_uid = KUID_TO_SUID(ZTOI(zp)->i_uid);
411 lr->lr_gid = KGID_TO_SGID(ZTOI(zp)->i_gid);
428870ff 412 lr->lr_mode = zp->z_mode;
3558fd73 413 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(ZTOZSB(zp)), &lr->lr_gen,
428870ff 414 sizeof (uint64_t));
3558fd73 415 (void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
428870ff 416 lr->lr_crtime, sizeof (uint64_t) * 2);
34dc7c2f
BB
417 bcopy(name, (char *)(lr + 1), namesize);
418 bcopy(link, (char *)(lr + 1) + namesize, linksize);
419
572e2857 420 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
421}
422
423/*
d3cc8b15 424 * Handles TX_RENAME transactions.
34dc7c2f
BB
425 */
426void
427zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype,
428 znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp)
429{
430 itx_t *itx;
34dc7c2f
BB
431 lr_rename_t *lr;
432 size_t snamesize = strlen(sname) + 1;
433 size_t dnamesize = strlen(dname) + 1;
434
428870ff 435 if (zil_replaying(zilog, tx))
34dc7c2f
BB
436 return;
437
438 itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
439 lr = (lr_rename_t *)&itx->itx_lr;
440 lr->lr_sdoid = sdzp->z_id;
441 lr->lr_tdoid = tdzp->z_id;
442 bcopy(sname, (char *)(lr + 1), snamesize);
443 bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
572e2857 444 itx->itx_oid = szp->z_id;
34dc7c2f 445
572e2857 446 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
447}
448
449/*
119a394a
ED
450 * zfs_log_write() handles TX_WRITE transactions. The specified callback is
451 * called as soon as the write is on stable storage (be it via a DMU sync or a
452 * ZIL commit).
34dc7c2f 453 */
15fd2749 454long zfs_immediate_write_sz = 32768;
34dc7c2f 455
34dc7c2f
BB
456void
457zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
119a394a
ED
458 znode_t *zp, offset_t off, ssize_t resid, int ioflag,
459 zil_callback_t callback, void *callback_data)
34dc7c2f
BB
460{
461 itx_wr_state_t write_state;
462 boolean_t slogging;
d5446cfc 463 uintptr_t fsync_cnt;
428870ff 464 ssize_t immediate_write_sz;
34dc7c2f 465
119a394a
ED
466 if (zil_replaying(zilog, tx) || zp->z_unlinked) {
467 if (callback != NULL)
468 callback(callback_data);
34dc7c2f 469 return;
119a394a 470 }
34dc7c2f 471
428870ff 472 immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT)
15fd2749 473 ? 0 : (ssize_t)zfs_immediate_write_sz;
fb5f0bc8 474
428870ff
BB
475 slogging = spa_has_slogs(zilog->zl_spa) &&
476 (zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
477 if (resid > immediate_write_sz && !slogging && resid <= zp->z_blksz)
34dc7c2f
BB
478 write_state = WR_INDIRECT;
479 else if (ioflag & (FSYNC | FDSYNC))
480 write_state = WR_COPIED;
481 else
482 write_state = WR_NEED_COPY;
483
d5446cfc
BB
484 if ((fsync_cnt = (uintptr_t)tsd_get(zfs_fsyncer_key)) != 0) {
485 (void) tsd_set(zfs_fsyncer_key, (void *)(fsync_cnt - 1));
486 }
487
34dc7c2f
BB
488 while (resid) {
489 itx_t *itx;
490 lr_write_t *lr;
491 ssize_t len;
492
493 /*
b128c09f 494 * If the write would overflow the largest block then split it.
34dc7c2f 495 */
b128c09f 496 if (write_state != WR_INDIRECT && resid > ZIL_MAX_LOG_DATA)
f1512ee6 497 len = SPA_OLD_MAXBLOCKSIZE >> 1;
34dc7c2f
BB
498 else
499 len = resid;
500
501 itx = zil_itx_create(txtype, sizeof (*lr) +
502 (write_state == WR_COPIED ? len : 0));
503 lr = (lr_write_t *)&itx->itx_lr;
3558fd73 504 if (write_state == WR_COPIED && dmu_read(ZTOZSB(zp)->z_os,
9babb374 505 zp->z_id, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) {
428870ff 506 zil_itx_destroy(itx);
34dc7c2f
BB
507 itx = zil_itx_create(txtype, sizeof (*lr));
508 lr = (lr_write_t *)&itx->itx_lr;
509 write_state = WR_NEED_COPY;
510 }
511
512 itx->itx_wr_state = write_state;
513 if (write_state == WR_NEED_COPY)
514 itx->itx_sod += len;
515 lr->lr_foid = zp->z_id;
516 lr->lr_offset = off;
517 lr->lr_length = len;
518 lr->lr_blkoff = 0;
519 BP_ZERO(&lr->lr_blkptr);
520
3558fd73 521 itx->itx_private = ZTOZSB(zp);
34dc7c2f 522
d5446cfc
BB
523 if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
524 (fsync_cnt == 0))
34dc7c2f
BB
525 itx->itx_sync = B_FALSE;
526
119a394a
ED
527 itx->itx_callback = callback;
528 itx->itx_callback_data = callback_data;
572e2857 529 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
530
531 off += len;
532 resid -= len;
533 }
534}
535
536/*
d3cc8b15 537 * Handles TX_TRUNCATE transactions.
34dc7c2f
BB
538 */
539void
540zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype,
541 znode_t *zp, uint64_t off, uint64_t len)
542{
543 itx_t *itx;
34dc7c2f
BB
544 lr_truncate_t *lr;
545
428870ff 546 if (zil_replaying(zilog, tx) || zp->z_unlinked)
34dc7c2f
BB
547 return;
548
549 itx = zil_itx_create(txtype, sizeof (*lr));
550 lr = (lr_truncate_t *)&itx->itx_lr;
551 lr->lr_foid = zp->z_id;
552 lr->lr_offset = off;
553 lr->lr_length = len;
554
555 itx->itx_sync = (zp->z_sync_cnt != 0);
572e2857 556 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
557}
558
559/*
d3cc8b15 560 * Handles TX_SETATTR transactions.
34dc7c2f
BB
561 */
562void
5484965a
BB
563zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype,
564 znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp)
34dc7c2f
BB
565{
566 itx_t *itx;
34dc7c2f
BB
567 lr_setattr_t *lr;
568 xvattr_t *xvap = (xvattr_t *)vap;
569 size_t recsize = sizeof (lr_setattr_t);
570 void *start;
571
428870ff 572 if (zil_replaying(zilog, tx) || zp->z_unlinked)
34dc7c2f
BB
573 return;
574
575 /*
576 * If XVATTR set, then log record size needs to allow
577 * for lr_attr_t + xvattr mask, mapsize and create time
578 * plus actual attribute values
579 */
5484965a 580 if (vap->va_mask & ATTR_XVATTR)
34dc7c2f
BB
581 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
582
583 if (fuidp)
584 recsize += fuidp->z_domain_str_sz;
585
586 itx = zil_itx_create(txtype, recsize);
587 lr = (lr_setattr_t *)&itx->itx_lr;
588 lr->lr_foid = zp->z_id;
589 lr->lr_mask = (uint64_t)mask_applied;
5484965a
BB
590 lr->lr_mode = (uint64_t)vap->va_mode;
591 if ((mask_applied & ATTR_UID) && IS_EPHEMERAL(vap->va_uid))
34dc7c2f
BB
592 lr->lr_uid = fuidp->z_fuid_owner;
593 else
5484965a 594 lr->lr_uid = (uint64_t)vap->va_uid;
34dc7c2f 595
5484965a 596 if ((mask_applied & ATTR_GID) && IS_EPHEMERAL(vap->va_gid))
34dc7c2f
BB
597 lr->lr_gid = fuidp->z_fuid_group;
598 else
5484965a 599 lr->lr_gid = (uint64_t)vap->va_gid;
34dc7c2f 600
5484965a
BB
601 lr->lr_size = (uint64_t)vap->va_size;
602 ZFS_TIME_ENCODE(&vap->va_atime, lr->lr_atime);
603 ZFS_TIME_ENCODE(&vap->va_mtime, lr->lr_mtime);
34dc7c2f 604 start = (lr_setattr_t *)(lr + 1);
5484965a 605 if (vap->va_mask & ATTR_XVATTR) {
34dc7c2f
BB
606 zfs_log_xvattr((lr_attr_t *)start, xvap);
607 start = (caddr_t)start + ZIL_XVAT_SIZE(xvap->xva_mapsize);
608 }
609
610 /*
611 * Now stick on domain information if any on end
612 */
613
614 if (fuidp)
615 (void) zfs_log_fuid_domains(fuidp, start);
616
617 itx->itx_sync = (zp->z_sync_cnt != 0);
572e2857 618 zil_itx_assign(zilog, itx, tx);
34dc7c2f
BB
619}
620
621/*
d3cc8b15 622 * Handles TX_ACL transactions.
34dc7c2f
BB
623 */
624void
625zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp,
626 vsecattr_t *vsecp, zfs_fuid_info_t *fuidp)
627{
628 itx_t *itx;
34dc7c2f
BB
629 lr_acl_v0_t *lrv0;
630 lr_acl_t *lr;
631 int txtype;
632 int lrsize;
633 size_t txsize;
634 size_t aclbytes = vsecp->vsa_aclentsz;
635
428870ff 636 if (zil_replaying(zilog, tx) || zp->z_unlinked)
b128c09f
BB
637 return;
638
3558fd73 639 txtype = (ZTOZSB(zp)->z_version < ZPL_VERSION_FUID) ?
34dc7c2f
BB
640 TX_ACL_V0 : TX_ACL;
641
642 if (txtype == TX_ACL)
643 lrsize = sizeof (*lr);
644 else
645 lrsize = sizeof (*lrv0);
646
34dc7c2f
BB
647 txsize = lrsize +
648 ((txtype == TX_ACL) ? ZIL_ACE_LENGTH(aclbytes) : aclbytes) +
649 (fuidp ? fuidp->z_domain_str_sz : 0) +
b128c09f 650 sizeof (uint64_t) * (fuidp ? fuidp->z_fuid_cnt : 0);
34dc7c2f
BB
651
652 itx = zil_itx_create(txtype, txsize);
653
654 lr = (lr_acl_t *)&itx->itx_lr;
655 lr->lr_foid = zp->z_id;
656 if (txtype == TX_ACL) {
657 lr->lr_acl_bytes = aclbytes;
658 lr->lr_domcnt = fuidp ? fuidp->z_domain_cnt : 0;
659 lr->lr_fuidcnt = fuidp ? fuidp->z_fuid_cnt : 0;
660 if (vsecp->vsa_mask & VSA_ACE_ACLFLAGS)
661 lr->lr_acl_flags = (uint64_t)vsecp->vsa_aclflags;
662 else
663 lr->lr_acl_flags = 0;
664 }
665 lr->lr_aclcnt = (uint64_t)vsecp->vsa_aclcnt;
666
667 if (txtype == TX_ACL_V0) {
668 lrv0 = (lr_acl_v0_t *)lr;
669 bcopy(vsecp->vsa_aclentp, (ace_t *)(lrv0 + 1), aclbytes);
670 } else {
671 void *start = (ace_t *)(lr + 1);
672
673 bcopy(vsecp->vsa_aclentp, start, aclbytes);
674
675 start = (caddr_t)start + ZIL_ACE_LENGTH(aclbytes);
676
677 if (fuidp) {
678 start = zfs_log_fuid_ids(fuidp, start);
679 (void) zfs_log_fuid_domains(fuidp, start);
680 }
681 }
682
683 itx->itx_sync = (zp->z_sync_cnt != 0);
572e2857 684 zil_itx_assign(zilog, itx, tx);
34dc7c2f 685}
15fd2749
CP
686
687#if defined(_KERNEL) && defined(HAVE_SPL)
688module_param(zfs_immediate_write_sz, long, 0644);
689MODULE_PARM_DESC(zfs_immediate_write_sz, "Largest data block to write to zil");
690#endif