45 static struct xlog_ticket *
46 xlog_cil_ticket_alloc(
49 struct xlog_ticket *tic;
77 log->l_cilp->xc_ctx->ticket = xlog_cil_ticket_alloc(log);
78 log->l_cilp->xc_ctx->sequence = 1;
79 log->l_cilp->xc_ctx->commit_lsn = xlog_assign_lsn(log->l_curr_cycle,
110 xlog_cil_prepare_log_vecs(
111 struct xfs_trans *tp)
119 if (list_empty(&tp->t_items)) {
151 for (index = 0; index < new_lv->
lv_niovecs; index++)
159 for (index = 0; index < new_lv->
lv_niovecs; index++) {
222 lv->
lv_item->li_seq = log->l_cilp->xc_ctx->sequence;
233 xlog_cil_insert_items(
236 struct xlog_ticket *ticket)
238 struct xfs_cil *cil = log->l_cilp;
239 struct xfs_cil_ctx *
ctx = cil->xc_ctx;
262 for (lv = log_vector; lv; lv = lv->
lv_next)
268 spin_lock(&cil->xc_cil_lock);
271 for (lv = log_vector; lv; lv = lv->
lv_next)
272 list_move_tail(&lv->
lv_item->li_cil, &cil->xc_cil);
274 ctx->nvecs += diff_iovecs;
283 if (ctx->ticket->t_curr_res == 0) {
285 ASSERT(ticket->t_curr_res >= ctx->ticket->t_unit_res + len);
286 ctx->ticket->t_curr_res = ctx->ticket->t_unit_res;
287 ticket->t_curr_res -= ctx->ticket->t_unit_res;
291 iclog_space = log->l_iclog_size - log->l_iclog_hsize;
292 if (len > 0 && (ctx->space_used / iclog_space !=
293 (ctx->space_used + len) / iclog_space)) {
296 hdrs = (len + iclog_space - 1) / iclog_space;
299 ctx->ticket->t_unit_res += hdrs;
300 ctx->ticket->t_curr_res += hdrs;
301 ticket->t_curr_res -= hdrs;
302 ASSERT(ticket->t_curr_res >= len);
304 ticket->t_curr_res -= len;
305 ctx->space_used += len;
307 spin_unlock(&cil->xc_cil_lock);
311 xlog_cil_free_logvec(
316 for (lv = log_vector; lv; ) {
334 struct xfs_cil_ctx *ctx = args;
335 struct xfs_mount *
mp = ctx->cil->xc_log->l_mp;
338 ctx->start_lsn, abort);
340 xfs_extent_busy_sort(&ctx->busy_extents);
342 (mp->m_flags & XFS_MOUNT_DISCARD) && !abort);
344 spin_lock(&ctx->cil->xc_cil_lock);
346 spin_unlock(&ctx->cil->xc_cil_lock);
348 xlog_cil_free_logvec(ctx->lv_chain);
350 if (!list_empty(&ctx->busy_extents)) {
351 ASSERT(mp->m_flags & XFS_MOUNT_DISCARD);
378 struct xfs_cil *cil = log->l_cilp;
380 struct xfs_cil_ctx *
ctx;
381 struct xfs_cil_ctx *new_ctx;
382 struct xlog_in_core *commit_iclog;
383 struct xlog_ticket *tic;
398 new_ctx->ticket = xlog_cil_ticket_alloc(log);
403 spin_lock(&cil->xc_cil_lock);
404 push_seq = cil->xc_push_seq;
412 if (list_empty(&cil->xc_cil)) {
413 cil->xc_push_seq = 0;
414 spin_unlock(&cil->xc_cil_lock);
417 spin_unlock(&cil->xc_cil_lock);
421 if (push_seq < cil->xc_ctx->sequence)
434 while (!list_empty(&cil->xc_cil)) {
435 struct xfs_log_item *
item;
439 struct xfs_log_item, li_cil);
440 list_del_init(&item->li_cil);
442 ctx->lv_chain = item->li_lv;
460 INIT_LIST_HEAD(&new_ctx->committing);
461 INIT_LIST_HEAD(&new_ctx->busy_extents);
462 new_ctx->sequence = ctx->sequence + 1;
464 cil->xc_ctx = new_ctx;
471 cil->xc_current_sequence = new_ctx->sequence;
492 spin_lock(&cil->xc_cil_lock);
493 list_add(&ctx->committing, &cil->xc_committing);
494 spin_unlock(&cil->xc_cil_lock);
522 goto out_abort_free_ticket;
529 spin_lock(&cil->xc_cil_lock);
535 if (new_ctx->sequence >= ctx->sequence)
537 if (!new_ctx->commit_lsn) {
542 xlog_wait(&cil->xc_commit_wait, &cil->xc_cil_lock);
546 spin_unlock(&cil->xc_cil_lock);
549 commit_lsn =
xfs_log_done(log->l_mp, tic, &commit_iclog, 0);
550 if (commit_lsn == -1)
554 ctx->log_cb.cb_func = xlog_cil_committed;
555 ctx->log_cb.cb_arg =
ctx;
565 spin_lock(&cil->xc_cil_lock);
566 ctx->commit_lsn = commit_lsn;
568 spin_unlock(&cil->xc_cil_lock);
579 out_abort_free_ticket:
582 xlog_cil_committed(ctx, XFS_LI_ABORTED);
590 struct xfs_cil *cil =
container_of(work,
struct xfs_cil,
603 xlog_cil_push_background(
606 struct xfs_cil *cil = log->l_cilp;
612 ASSERT(!list_empty(&cil->xc_cil));
618 if (cil->xc_ctx->space_used < XLOG_CIL_SPACE_LIMIT(log))
621 spin_lock(&cil->xc_cil_lock);
622 if (cil->xc_push_seq < cil->xc_current_sequence) {
623 cil->xc_push_seq = cil->xc_current_sequence;
624 queue_work(log->l_mp->m_cil_workqueue, &cil->xc_push_work);
626 spin_unlock(&cil->xc_cil_lock);
631 xlog_cil_push_foreground(
635 struct xfs_cil *cil = log->l_cilp;
640 ASSERT(push_seq && push_seq <= cil->xc_current_sequence);
649 spin_lock(&cil->xc_cil_lock);
650 if (list_empty(&cil->xc_cil) || push_seq <= cil->xc_push_seq) {
651 spin_unlock(&cil->xc_cil_lock);
655 cil->xc_push_seq = push_seq;
656 spin_unlock(&cil->xc_cil_lock);
681 struct xfs_mount *mp,
682 struct xfs_trans *tp,
686 struct xlog *log = mp->m_log;
691 log_flags = XFS_LOG_REL_PERM_RESERV;
699 log_vector = xlog_cil_prepare_log_vecs(tp);
706 *commit_lsn = log->l_cilp->xc_ctx->sequence;
708 xlog_cil_insert_items(log, log_vector, tp->t_ticket);
711 if (tp->t_ticket->t_curr_res < 0)
715 if (!list_empty(&tp->t_busy)) {
716 spin_lock(&log->l_cilp->xc_cil_lock);
717 list_splice_init(&tp->t_busy,
718 &log->l_cilp->xc_ctx->busy_extents);
719 spin_unlock(&log->l_cilp->xc_cil_lock);
722 tp->t_commit_lsn = *commit_lsn;
739 xlog_cil_push_background(log);
741 up_read(&log->l_cilp->xc_ctx_lock);
760 struct xfs_cil *cil = log->l_cilp;
761 struct xfs_cil_ctx *
ctx;
764 ASSERT(sequence <= cil->xc_current_sequence);
771 xlog_cil_push_foreground(log, sequence);
780 spin_lock(&cil->xc_cil_lock);
782 if (ctx->sequence > sequence)
784 if (!ctx->commit_lsn) {
789 xlog_wait(&cil->xc_commit_wait, &cil->xc_cil_lock);
792 if (ctx->sequence != sequence)
795 commit_lsn = ctx->commit_lsn;
797 spin_unlock(&cil->xc_cil_lock);
812 struct xfs_log_item *
lip)
814 struct xfs_cil_ctx *
ctx;
816 if (list_empty(&lip->li_cil))
819 ctx = lip->li_mountp->m_log->l_cilp->xc_ctx;
826 if (XFS_LSN_CMP(lip->li_seq, ctx->sequence) != 0)
839 struct xfs_cil_ctx *
ctx;
851 INIT_WORK(&cil->xc_push_work, xlog_cil_push_work);
852 INIT_LIST_HEAD(&cil->xc_cil);
853 INIT_LIST_HEAD(&cil->xc_committing);
858 INIT_LIST_HEAD(&ctx->committing);
859 INIT_LIST_HEAD(&ctx->busy_extents);
863 cil->xc_current_sequence = ctx->sequence;
874 if (log->l_cilp->xc_ctx) {
875 if (log->l_cilp->xc_ctx->ticket)
880 ASSERT(list_empty(&log->l_cilp->xc_cil));