Deleted Added
full compact
zfs_log.c (185321) zfs_log.c (209962)
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>
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>
45
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
46/*
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.
52 */
53
54int
55zfs_log_create_txtype(zil_create_t type, vsecattr_t *vsecp, vattr_t *vap)
56{
57 int isxvattr = (vap->va_mask & AT_XVATTR);
58 switch (type) {
59 case Z_FILE:

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

231 void *end;
232 size_t lrsize;
233 size_t namesize = strlen(name) + 1;
234 size_t fuidsz = 0;
235
236 if (zilog == NULL)
237 return;
238
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
239 /*
240 * If we have FUIDs present then add in space for
241 * domains and ACE fuid's if any.
242 */
243 if (fuidp) {
244 fuidsz += fuidp->z_domain_str_sz;
245 fuidsz += fuidp->z_fuid_cnt * sizeof (uint64_t);
246 }

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

334 itx_t *itx;
335 uint64_t seq;
336 lr_remove_t *lr;
337 size_t namesize = strlen(name) + 1;
338
339 if (zilog == NULL)
340 return;
341
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
342 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
343 lr = (lr_remove_t *)&itx->itx_lr;
344 lr->lr_doid = dzp->z_id;
345 bcopy(name, (char *)(lr + 1), namesize);
346
347 seq = zil_itx_assign(zilog, itx, tx);
348 dzp->z_last_itx = seq;
349}

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

358 itx_t *itx;
359 uint64_t seq;
360 lr_link_t *lr;
361 size_t namesize = strlen(name) + 1;
362
363 if (zilog == NULL)
364 return;
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
366 itx = zil_itx_create(txtype, sizeof (*lr) + namesize);
367 lr = (lr_link_t *)&itx->itx_lr;
368 lr->lr_doid = dzp->z_id;
369 lr->lr_link_obj = zp->z_id;
370 bcopy(name, (char *)(lr + 1), namesize);
371
372 seq = zil_itx_assign(zilog, itx, tx);
373 dzp->z_last_itx = seq;

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

385 uint64_t seq;
386 lr_create_t *lr;
387 size_t namesize = strlen(name) + 1;
388 size_t linksize = strlen(link) + 1;
389
390 if (zilog == NULL)
391 return;
392
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
393 itx = zil_itx_create(txtype, sizeof (*lr) + namesize + linksize);
394 lr = (lr_create_t *)&itx->itx_lr;
395 lr->lr_doid = dzp->z_id;
396 lr->lr_foid = zp->z_id;
397 lr->lr_mode = zp->z_phys->zp_mode;
398 lr->lr_uid = zp->z_phys->zp_uid;
399 lr->lr_gid = zp->z_phys->zp_gid;
400 lr->lr_gen = zp->z_phys->zp_gen;

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

419 uint64_t seq;
420 lr_rename_t *lr;
421 size_t snamesize = strlen(sname) + 1;
422 size_t dnamesize = strlen(dname) + 1;
423
424 if (zilog == NULL)
425 return;
426
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
427 itx = zil_itx_create(txtype, sizeof (*lr) + snamesize + dnamesize);
428 lr = (lr_rename_t *)&itx->itx_lr;
429 lr->lr_sdoid = sdzp->z_id;
430 lr->lr_tdoid = tdzp->z_id;
431 bcopy(sname, (char *)(lr + 1), snamesize);
432 bcopy(dname, (char *)(lr + 1) + snamesize, dnamesize);
433
434 seq = zil_itx_assign(zilog, itx, tx);

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

451{
452 itx_wr_state_t write_state;
453 boolean_t slogging;
454 uintptr_t fsync_cnt;
455
456 if (zilog == NULL || zp->z_unlinked)
457 return;
458
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
459 /*
460 * Writes are handled in three different ways:
461 *
462 * WR_INDIRECT:
463 * In this mode, if we need to commit the write later, then the block
464 * is immediately written into the file system (using dmu_sync),
465 * and a pointer to the block is put into the log record.
466 * When the txg commits the block is linked in.

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

503 len = SPA_MAXBLOCKSIZE >> 1;
504 else
505 len = resid;
506
507 itx = zil_itx_create(txtype, sizeof (*lr) +
508 (write_state == WR_COPIED ? len : 0));
509 lr = (lr_write_t *)&itx->itx_lr;
510 if (write_state == WR_COPIED && dmu_read(zp->z_zfsvfs->z_os,
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) {
512 kmem_free(itx, offsetof(itx_t, itx_lr) +
513 itx->itx_lr.lrc_reclen);
514 itx = zil_itx_create(txtype, sizeof (*lr));
515 lr = (lr_write_t *)&itx->itx_lr;
516 write_state = WR_NEED_COPY;
517 }
518
519 itx->itx_wr_state = write_state;

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

549{
550 itx_t *itx;
551 uint64_t seq;
552 lr_truncate_t *lr;
553
554 if (zilog == NULL || zp->z_unlinked)
555 return;
556
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
557 itx = zil_itx_create(txtype, sizeof (*lr));
558 lr = (lr_truncate_t *)&itx->itx_lr;
559 lr->lr_foid = zp->z_id;
560 lr->lr_offset = off;
561 lr->lr_length = len;
562
563 itx->itx_sync = (zp->z_sync_cnt != 0);
564 seq = zil_itx_assign(zilog, itx, tx);

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

578 xvattr_t *xvap = (xvattr_t *)vap;
579 size_t recsize = sizeof (lr_setattr_t);
580 void *start;
581
582
583 if (zilog == NULL || zp->z_unlinked)
584 return;
585
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
586 /*
587 * If XVATTR set, then log record size needs to allow
588 * for lr_attr_t + xvattr mask, mapsize and create time
589 * plus actual attribute values
590 */
591 if (vap->va_mask & AT_XVATTR)
592 recsize = sizeof (*lr) + ZIL_XVAT_SIZE(xvap->xva_mapsize);
593

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

644 int txtype;
645 int lrsize;
646 size_t txsize;
647 size_t aclbytes = vsecp->vsa_aclentsz;
648
649 if (zilog == NULL || zp->z_unlinked)
650 return;
651
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
652 txtype = (zp->z_zfsvfs->z_version < ZPL_VERSION_FUID) ?
653 TX_ACL_V0 : TX_ACL;
654
655 if (txtype == TX_ACL)
656 lrsize = sizeof (*lr);
657 else
658 lrsize = sizeof (*lrv0);
659

--- 40 unchanged lines hidden ---
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 ---