Lines Matching refs:tr

158 static void finish_end_thread(transaction *tr);
160 static int finish_end_transaction(transaction *tr, errno_t (*callback)(void*), void *callback_arg);
161 static int end_transaction(transaction *tr, int force_it, errno_t (*callback)(void*), void *callback_arg, boolean_t drop_lock, boolean_t must_wait);
162 static void abort_transaction(journal *jnl, transaction *tr);
219 #define CHECK_TRANSACTION(tr) \
221 if (tr == NULL) { \
224 if (tr->jnl == NULL) { \
225 panic("%s:%d: null tr->jnl ptr?\n", __FILE__, __LINE__); \
227 if (tr->blhdr != (block_list_header *)tr->tbuffer) { \
228 panic("%s:%d: blhdr (%p) != tbuffer (%p)\n", __FILE__, __LINE__, tr->blhdr, tr->tbuffer); \
230 if (tr->total_bytes < 0) { \
231 panic("%s:%d: tr total_bytes looks bad: %d\n", __FILE__, __LINE__, tr->total_bytes); \
233 if (tr->journal_start < 0) { \
234 panic("%s:%d: tr journal start looks bad: 0x%llx\n", __FILE__, __LINE__, tr->journal_start); \
236 if (tr->journal_end < 0) { \
237 panic("%s:%d: tr journal end looks bad: 0x%llx\n", __FILE__, __LINE__, tr->journal_end); \
239 if (tr->blhdr && (tr->blhdr->max_blocks <= 0 || tr->blhdr->max_blocks > (tr->jnl->jhdr->size/tr->jnl->jhdr->jhdr_size))) { \
240 panic("%s:%d: tr blhdr max_blocks looks bad: %d\n", __FILE__, __LINE__, tr->blhdr->max_blocks); \
516 transaction *tr, *next;
523 tr = jnl->tr_freeme;
527 for(; tr; tr=next) {
528 for (blhdr = tr->blhdr; blhdr; blhdr = next_blhdr) {
532 kmem_free(kernel_map, (vm_offset_t)blhdr, tr->tbuffer_size);
534 KERNEL_DEBUG(0xbbbbc01c, jnl, tr, tr->tbuffer_size, 0, 0);
536 next = tr->next;
537 FREE_ZONE(tr, sizeof(transaction), M_JNL_TR);
552 transaction *tr;
559 //printf("jnl: buf flush: bp @ 0x%x l/blkno %qd/%qd vp 0x%x tr @ 0x%x\n",
564 tr = (transaction *)arg;
567 if (tr == NULL) {
571 CHECK_TRANSACTION(tr);
573 jnl = tr->jnl;
580 amt_flushed = tr->num_killed;
581 total_bytes = tr->total_bytes;
587 // OSAddAtomic() returns the value of tr->num_flushed before the add
589 amt_flushed += OSAddAtomic(bufsize, &tr->num_flushed);
596 // the tr pointer after doing the OSAddAtomic(). if
598 // and then it's ok to dereference "tr".
607 if (tr->total_bytes == (int)0xfbadc0de) {
615 tr->total_bytes = 0xfbadc0de;
617 //printf("jnl: tr 0x%x (0x%llx 0x%llx) in jnl 0x%x completed.\n",
618 // tr, tr->journal_start, tr->journal_end, jnl);
623 if ((off_t)(jnl->old_start[i] & ~(0x8000000000000000ULL)) == tr->journal_start) {
630 panic("jnl: buffer_flushed: did not find tr w/start @ %lld (tr %p, jnl %p)\n",
631 tr->journal_start, tr, jnl);
637 if (tr->journal_start == jnl->active_start) {
638 jnl->active_start = tr->journal_end;
639 tr->journal_start = tr->journal_end = (off_t)0;
658 } else if (tr->journal_end == ctr->journal_start) {
659 ctr->journal_start = tr->journal_start;
662 tr->journal_start = tr->journal_end = (off_t)0;
663 } else if (tr->journal_start == ctr->journal_end) {
664 ctr->journal_end = tr->journal_end;
666 tr->journal_start = tr->journal_end = (off_t)0;
686 if (tr->journal_start != 0) {
692 for (ctr = jnl->completed_trs; ctr && tr->journal_start > ctr->journal_start; prev=ctr, ctr=ctr->next) {
697 jnl->completed_trs = tr;
698 tr->next = NULL;
700 tr->next = jnl->completed_trs;
701 jnl->completed_trs = tr;
703 tr->next = prev->next;
704 prev->next = tr;
707 // if we're here this tr got merged with someone else so
709 tr->next = jnl->tr_freeme;
710 jnl->tr_freeme = tr;
2213 transaction *tr = jnl->cur_tr;
2220 end_transaction(tr, 1, NULL, NULL, FALSE, TRUE);
2256 transaction *tr;
2259 tr = jnl->active_tr;
2262 tr = jnl->cur_tr;
2265 abort_transaction(jnl, tr);
2268 panic("jnl: %s: close: jnl @ %p had both an active and cur tr\n", jnl->jdev_name, jnl);
2373 panic("jnl: check_free_space: tr starting @ 0x%llx not flushing (jnl %p).\n",
2451 transaction *tr;
2453 MALLOC_ZONE(tr, transaction *, sizeof(transaction), M_JNL_TR, M_WAITOK);
2454 memset(tr, 0, sizeof(transaction));
2456 tr->tbuffer_size = jnl->tbuffer_size;
2458 if (kmem_alloc_kobject(kernel_map, (vm_offset_t *)&tr->tbuffer, tr->tbuffer_size)) {
2459 FREE_ZONE(tr, sizeof(transaction), M_JNL_TR);
2465 memset(tr->tbuffer, 0, BLHDR_CHECKSUM_SIZE);
2467 memset(tr->tbuffer + BLHDR_CHECKSUM_SIZE, 0x5a, jnl->jhdr->blhdr_size - BLHDR_CHECKSUM_SIZE);
2469 tr->blhdr = (block_list_header *)tr->tbuffer;
2470 tr->blhdr->max_blocks = (jnl->jhdr->blhdr_size / sizeof(block_info)) - 1;
2471 tr->blhdr->num_blocks = 1; // accounts for this header block
2472 tr->blhdr->bytes_used = jnl->jhdr->blhdr_size;
2473 tr->blhdr->flags = BLHDR_CHECK_CHECKSUMS | BLHDR_FIRST_HEADER;
2475 tr->sequence_num = ++jnl->sequence_num;
2476 tr->num_blhdrs = 1;
2477 tr->total_bytes = jnl->jhdr->blhdr_size;
2478 tr->jnl = jnl;
2480 jnl->active_tr = tr;
2545 // printf("jnl: start_tr: owner 0x%x new tr @ 0x%x\n", jnl->owner, jnl->active_tr);
2561 transaction *tr;
2578 tr = jnl->active_tr;
2579 CHECK_TRANSACTION(tr);
2587 // bp, buf_vnode(bp), buf_lblkno(bp), buf_blkno(bp), buf_size(bp), tr->total_bytes);
2639 if (tr->total_bytes+buf_size(bp) >= (jnl->jhdr->size - jnl->jhdr->jhdr_size)) {
2640 panic("jnl: transaction too big (%d >= %lld bytes, bufsize %d, tr %p bp %p)\n",
2641 tr->total_bytes, (tr->jnl->jhdr->size - jnl->jhdr->jhdr_size), buf_size(bp), tr, bp);
2669 transaction *tr;
2677 tr = jnl->active_tr;
2682 // that happened to be modified as part of another tr.
2684 if (tr == NULL) {
2695 CHECK_TRANSACTION(tr);
2702 // printf("jnl: modify_block_abort: tr 0x%x bp 0x%x\n", jnl->active_tr, bp);
2705 for (blhdr = tr->blhdr; blhdr; blhdr = (block_list_header *)((long)blhdr->binfo[0].bnum)) {
2739 transaction *tr;
2751 tr = jnl->active_tr;
2752 CHECK_TRANSACTION(tr);
2760 // bp, buf_vnode(bp), buf_lblkno(bp), buf_blkno(bp), buf_size(bp), tr->total_bytes);
2767 for (blhdr = tr->blhdr; blhdr; prev = blhdr, blhdr = (block_list_header *)((long)blhdr->binfo[0].bnum)) {
2789 && (prev->bytes_used+buf_size(bp)) <= (uint32_t)tr->tbuffer_size) {
2805 if (kmem_alloc_kobject(kernel_map, (vm_offset_t *)&nblhdr, tr->tbuffer_size)) {
2806 panic("jnl: end_tr: no space for new block tr @ %p (total bytes: %d)!\n",
2807 tr, tr->total_bytes);
2821 tr->num_blhdrs++;
2822 tr->total_bytes += jnl->jhdr->blhdr_size;
2860 tr->total_bytes += bsize;
2875 transaction *tr;
2885 tr = jnl->active_tr;
2886 CHECK_TRANSACTION(tr);
2902 for (blhdr = tr->blhdr; blhdr; blhdr = (block_list_header *)((long)blhdr->binfo[0].bnum)) {
2922 tr->num_killed += buf_size(bp);
2991 ; The allocated_count and extents fields of tr->trim are updated
3107 transaction *tr;
3119 tr = jnl->active_tr;
3120 CHECK_TRANSACTION(tr);
3123 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_ADD | DBG_FUNC_START, jnl, offset, length, tr->trim.extent_count, 0);
3140 extent = tr->trim.extents;
3142 while (insert_index < tr->trim.extent_count && extent->offset + extent->length < offset) {
3147 while (insert_index + replace_count < tr->trim.extent_count && extent->offset <= end) {
3158 if (tr->trim.extent_count == tr->trim.allocated_count) {
3159 if (trim_realloc(&tr->trim) != 0) {
3162 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_ADD | DBG_FUNC_END, ENOMEM, 0, 0, tr->trim.extent_count, 0);
3168 if (insert_index < tr->trim.extent_count) {
3169 memmove(&tr->trim.extents[insert_index+1],
3170 &tr->trim.extents[insert_index],
3171 (tr->trim.extent_count - insert_index) * sizeof(dk_extent_t));
3173 tr->trim.extent_count++;
3176 tr->trim.extents[insert_index].offset = offset;
3177 tr->trim.extents[insert_index].length = length;
3181 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_ADD | DBG_FUNC_END, 0, 0, 0, tr->trim.extent_count, 0);
3189 if (tr->trim.extents[insert_index].offset < offset)
3190 offset = tr->trim.extents[insert_index].offset;
3191 extent = &tr->trim.extents[insert_index + replace_count - 1];
3194 tr->trim.extents[insert_index].offset = offset;
3195 tr->trim.extents[insert_index].length = end - offset;
3205 if (replace_count > 1 && (insert_index + replace_count) < tr->trim.extent_count) {
3206 memmove(&tr->trim.extents[insert_index + 1],
3207 &tr->trim.extents[insert_index + replace_count],
3208 (tr->trim.extent_count - insert_index - replace_count) * sizeof(dk_extent_t));
3210 tr->trim.extent_count -= replace_count - 1;
3213 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_ADD | DBG_FUNC_END, 0, 0, 0, tr->trim.extent_count, 0);
3371 transaction *tr;
3380 tr = jnl->active_tr;
3381 CHECK_TRANSACTION(tr);
3384 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_REMOVE | DBG_FUNC_START, jnl, offset, length, tr->trim.extent_count, 0);
3393 error = trim_remove_extent(&tr->trim, offset, length);
3429 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_REMOVE | DBG_FUNC_END, error, 0, 0, tr->trim.extent_count, 0);
3435 journal_trim_flush(journal *jnl, transaction *tr)
3440 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_FLUSH | DBG_FUNC_START, jnl, tr, 0, tr->trim.extent_count, 0);
3443 if (tr->trim.extent_count > 0) {
3448 unmap.extents = tr->trim.extents;
3449 unmap.extentsCount = tr->trim.extent_count;
3451 KERNEL_DEBUG_CONSTANT(DBG_JOURNAL_TRIM_UNMAP | DBG_FUNC_START, jnl, tr, 0, tr->trim.extent_count, 0);
3473 jnl->trim_callback(jnl->trim_callback_arg, tr->trim.extent_count, tr->trim.extents);
3488 if (jnl->async_trim == &tr->trim)
3494 * of "tr", so it is safe for us to manipulate tr->trim without
3497 if (tr->trim.extents) {
3498 kfree(tr->trim.extents, tr->trim.allocated_count * sizeof(dk_extent_t));
3499 tr->trim.allocated_count = 0;
3500 tr->trim.extent_count = 0;
3501 tr->trim.extents = NULL;
3554 * tr Transaction to add to the journal
3564 end_transaction(transaction *tr, int force_it, errno_t (*callback)(void*), void *callback_arg, boolean_t drop_lock, boolean_t must_wait)
3569 journal *jnl = tr->jnl;
3575 panic("jnl: jnl @ %p already has cur_tr %p, new tr: %p\n",
3576 jnl, jnl->cur_tr, tr);
3581 if (tr->total_bytes == jnl->jhdr->blhdr_size) {
3582 jnl->cur_tr = tr;
3601 && tr->num_blhdrs < 3
3602 && (tr->total_bytes <= ((tr->tbuffer_size*tr->num_blhdrs) - tr->tbuffer_size/8))
3603 && (!(jnl->flags & JOURNAL_USE_UNMAP) || (tr->trim.extent_count < jnl_trim_flush_limit))) {
3605 jnl->cur_tr = tr;
3609 KERNEL_DEBUG(0xbbbbc018|DBG_FUNC_START, jnl, tr, drop_lock, must_wait, 0);
3623 abort_transaction(jnl, tr);
3625 KERNEL_DEBUG(0xbbbbc018|DBG_FUNC_END, jnl, tr, ret_val, 0, 0);
3641 if (tr->trim.extent_count > 0)
3642 jnl->async_trim = &tr->trim;
3664 check_free_space(jnl, tr->total_bytes, &tr->delayed_header_write, jnl->saved_sequence_num);
3666 KERNEL_DEBUG(0xbbbbc030 | DBG_FUNC_END, jnl, tr->delayed_header_write, 0, 0, 0);
3673 if (tr->delayed_header_write == TRUE) {
3689 tr->journal_start = jnl->jhdr->end;
3698 jnl->old_start[sizeof(jnl->old_start)/sizeof(jnl->old_start[0]) - 1] = tr->journal_start | 0x8000000000000000LL;
3703 for (blhdr = tr->blhdr; blhdr; blhdr = next) {
3719 panic("jnl: inconsistent binfo (NULL bp w/bnum %lld; jnl @ %p, tr %p)\n",
3720 blhdr->binfo[i].bnum, jnl, tr);
3819 ret_val = finish_end_transaction(tr, callback, callback_arg);
3828 kernel_thread_start((thread_continue_t)finish_end_thread, tr, &thread);
3830 KERNEL_DEBUG(0xbbbbc018|DBG_FUNC_END, jnl, tr, ret_val, 0, 0);
3841 finish_end_thread(transaction *tr)
3844 finish_end_transaction(tr, NULL, NULL);
3866 finish_end_transaction(transaction *tr, errno_t (*callback)(void*), void *callback_arg)
3871 journal *jnl = tr->jnl;
3879 KERNEL_DEBUG(0xbbbbc028|DBG_FUNC_START, jnl, tr, 0, 0, 0);
3883 for (blhdr = tr->blhdr; blhdr; blhdr = (block_list_header *)((long)blhdr->binfo[0].bnum)) {
3887 blhdr->binfo[0].u.bi.b.sequence_num = tr->sequence_num;
3917 printf("jnl: %s: end_tr: bad news! bp @ %p w/null vp and l/blkno = %qd/%qd. aborting the transaction (tr %p jnl %p).\n",
3918 jnl->jdev_name, bp, lblkno, blkno, tr, jnl);
3955 buf_setfilter(bp, buffer_flushed_callback, tr, &func, &arg);
4008 tr->journal_end = end; // the transaction ends here too
4010 if (tr->journal_start == 0 || tr->journal_end == 0) {
4011 panic("jnl: end_transaction: bad tr journal start/end: 0x%llx 0x%llx\n",
4012 tr->journal_start, tr->journal_end);
4033 journal_trim_flush(jnl, tr);
4039 tr->num_flushed = tr->num_blhdrs * jnl->jhdr->blhdr_size;
4046 for (blhdr = tr->blhdr; blhdr; blhdr = next) {
4099 tr->next = jnl->tr_freeme;
4100 jnl->tr_freeme = tr;
4107 //printf("jnl: end_tr: tr @ 0x%x, jnl-blocks: 0x%llx - 0x%llx. exit!\n",
4108 // tr, tr->journal_start, tr->journal_end);
4129 abort_transaction(jnl, tr); // cleans up list of extents to be trimmed
4135 KERNEL_DEBUG(0xbbbbc028|DBG_FUNC_END, jnl, tr, bufs_written, ret_val, 0);
4189 abort_transaction(journal *jnl, transaction *tr)
4203 KERNEL_DEBUG(0xbbbbc034|DBG_FUNC_START, jnl, tr, 0, 0, 0);
4205 for (blhdr = tr->blhdr; blhdr; blhdr = next) {
4248 KERNEL_DEBUG(0xbbbbc034|DBG_FUNC_NONE, jnl, tr, bp, 0, 0);
4269 kmem_free(kernel_map, (vm_offset_t)blhdr, tr->tbuffer_size);
4278 if (jnl->async_trim == &tr->trim)
4283 if (tr->trim.extents) {
4284 kfree(tr->trim.extents, tr->trim.allocated_count * sizeof(dk_extent_t));
4286 tr->trim.allocated_count = 0;
4287 tr->trim.extent_count = 0;
4288 tr->trim.extents = NULL;
4289 tr->tbuffer = NULL;
4290 tr->blhdr = NULL;
4291 tr->total_bytes = 0xdbadc0de;
4292 FREE_ZONE(tr, sizeof(transaction), M_JNL_TR);
4294 KERNEL_DEBUG(0xbbbbc034|DBG_FUNC_END, jnl, tr, 0, 0, 0);
4302 transaction *tr;
4327 panic("jnl: journal @ %p has active tr (%p) and cur tr (%p)\n",
4330 tr = jnl->active_tr;
4333 abort_transaction(jnl, tr);
4341 tr = jnl->active_tr;
4342 CHECK_TRANSACTION(tr);
4350 ret = end_transaction(tr, 0, NULL, NULL, TRUE, FALSE);
4404 transaction *tr = jnl->cur_tr;
4418 end_transaction(tr, 1, NULL, NULL, drop_lock, TRUE); // force it to get flushed
4526 transaction *tr;
4563 tr = jnl->active_tr;
4564 CHECK_TRANSACTION(tr);
4567 jnl->active_tr = tr;
4602 ret = end_transaction(tr, 1, callback, callback_arg, FALSE, TRUE);
4622 abort_transaction(jnl, tr);