Deleted Added
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

--- 28 unchanged lines hidden (view full) ---

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/*
47 * All the functions in this file are used to construct the log entries
48 * to record transactions. They allocate * an intent log transaction
49 * structure (itx_t) and save within it all the information necessary to
50 * possibly replay the transaction. The itx is then assigned a sequence
51 * number and inserted in the in-memory list anchored in the zilog.
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:

--- 171 unchanged lines hidden (view full) ---

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 }

--- 87 unchanged lines hidden (view full) ---

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}

--- 8 unchanged lines hidden (view full) ---

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;

--- 11 unchanged lines hidden (view full) ---

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;

--- 18 unchanged lines hidden (view full) ---

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);

--- 16 unchanged lines hidden (view full) ---

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.

--- 36 unchanged lines hidden (view full) ---

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,
511 zp->z_id, off, len, lr + 1) != 0) {
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;

--- 29 unchanged lines hidden (view full) ---

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);

--- 13 unchanged lines hidden (view full) ---

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

--- 50 unchanged lines hidden (view full) ---

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

--- 40 unchanged lines hidden ---