Lines Matching refs:lc
299 static int rw_header(struct log_c *lc, enum req_op op)
301 lc->io_req.bi_opf = op;
303 return dm_io(&lc->io_req, 1, &lc->header_location, NULL, IOPRIO_DEFAULT);
306 static int flush_header(struct log_c *lc)
309 .bdev = lc->header_location.bdev,
314 lc->io_req.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
316 return dm_io(&lc->io_req, 1, &null_location, NULL, IOPRIO_DEFAULT);
374 struct log_c *lc;
405 lc = kmalloc(sizeof(*lc), GFP_KERNEL);
406 if (!lc) {
411 lc->ti = ti;
412 lc->touched_dirtied = 0;
413 lc->touched_cleaned = 0;
414 lc->flush_failed = 0;
415 lc->region_size = region_size;
416 lc->region_count = region_count;
417 lc->sync = sync;
425 lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits);
431 lc->clean_bits = vmalloc(bitset_size);
432 if (!lc->clean_bits) {
434 kfree(lc);
437 lc->disk_header = NULL;
439 lc->log_dev = dev;
440 lc->log_dev_failed = 0;
441 lc->log_dev_flush_failed = 0;
442 lc->header_location.bdev = lc->log_dev->bdev;
443 lc->header_location.sector = 0;
450 bdev_logical_block_size(lc->header_location.bdev));
455 kfree(lc);
459 lc->header_location.count = buf_size >> SECTOR_SHIFT;
461 lc->io_req.mem.type = DM_IO_VMA;
462 lc->io_req.notify.fn = NULL;
463 lc->io_req.client = dm_io_client_create();
464 if (IS_ERR(lc->io_req.client)) {
465 r = PTR_ERR(lc->io_req.client);
467 kfree(lc);
471 lc->disk_header = vmalloc(buf_size);
472 if (!lc->disk_header) {
474 dm_io_client_destroy(lc->io_req.client);
475 kfree(lc);
479 lc->io_req.mem.ptr.vma = lc->disk_header;
480 lc->clean_bits = (void *)lc->disk_header +
484 memset(lc->clean_bits, -1, bitset_size);
486 lc->sync_bits = vmalloc(bitset_size);
487 if (!lc->sync_bits) {
490 vfree(lc->clean_bits);
492 dm_io_client_destroy(lc->io_req.client);
493 vfree(lc->disk_header);
494 kfree(lc);
497 memset(lc->sync_bits, (sync == NOSYNC) ? -1 : 0, bitset_size);
498 lc->sync_count = (sync == NOSYNC) ? region_count : 0;
500 lc->recovering_bits = vzalloc(bitset_size);
501 if (!lc->recovering_bits) {
503 vfree(lc->sync_bits);
505 vfree(lc->clean_bits);
507 dm_io_client_destroy(lc->io_req.client);
508 vfree(lc->disk_header);
509 kfree(lc);
512 lc->sync_search = 0;
513 log->context = lc;
524 static void destroy_log_context(struct log_c *lc)
526 vfree(lc->sync_bits);
527 vfree(lc->recovering_bits);
528 kfree(lc);
533 struct log_c *lc = log->context;
535 vfree(lc->clean_bits);
536 destroy_log_context(lc);
572 struct log_c *lc = log->context;
574 dm_put_device(lc->ti, lc->log_dev);
575 vfree(lc->disk_header);
576 dm_io_client_destroy(lc->io_req.client);
577 destroy_log_context(lc);
580 static void fail_log_device(struct log_c *lc)
582 if (lc->log_dev_failed)
585 lc->log_dev_failed = 1;
586 dm_table_event(lc->ti->table);
593 struct log_c *lc = log->context;
594 size_t size = lc->bitset_uint32_count * sizeof(uint32_t);
597 r = read_header(lc);
600 lc->log_dev->name);
601 fail_log_device(lc);
609 lc->header.nr_regions = 0;
613 if (lc->sync == NOSYNC)
614 for (i = lc->header.nr_regions; i < lc->region_count; i++)
616 log_set_bit(lc, lc->clean_bits, i);
618 for (i = lc->header.nr_regions; i < lc->region_count; i++)
620 log_clear_bit(lc, lc->clean_bits, i);
623 for (i = lc->region_count; i % BITS_PER_LONG; i++)
624 log_clear_bit(lc, lc->clean_bits, i);
627 memcpy(lc->sync_bits, lc->clean_bits, size);
628 lc->sync_count = memweight(lc->clean_bits,
629 lc->bitset_uint32_count * sizeof(uint32_t));
630 lc->sync_search = 0;
633 lc->header.nr_regions = lc->region_count;
635 header_to_disk(&lc->header, lc->disk_header);
638 r = rw_header(lc, REQ_OP_WRITE);
640 r = flush_header(lc);
642 lc->log_dev_flush_failed = 1;
646 lc->log_dev->name);
647 fail_log_device(lc);
655 struct log_c *lc = log->context;
657 return lc->region_size;
662 struct log_c *lc = log->context;
664 lc->sync_search = 0;
670 struct log_c *lc = log->context;
672 return log_test_bit(lc->clean_bits, region);
677 struct log_c *lc = log->context;
679 return log_test_bit(lc->sync_bits, region);
691 struct log_c *lc = log->context;
694 if (!lc->touched_cleaned && !lc->touched_dirtied)
697 if (lc->touched_cleaned && log->flush_callback_fn &&
698 log->flush_callback_fn(lc->ti)) {
705 lc->flush_failed = 1;
706 for (i = 0; i < lc->region_count; i++)
707 log_clear_bit(lc, lc->clean_bits, i);
710 r = rw_header(lc, REQ_OP_WRITE);
712 fail_log_device(lc);
714 if (lc->touched_dirtied) {
715 r = flush_header(lc);
717 lc->log_dev_flush_failed = 1;
718 fail_log_device(lc);
720 lc->touched_dirtied = 0;
722 lc->touched_cleaned = 0;
730 struct log_c *lc = log->context;
732 log_clear_bit(lc, lc->clean_bits, region);
737 struct log_c *lc = log->context;
739 if (likely(!lc->flush_failed))
740 log_set_bit(lc, lc->clean_bits, region);
745 struct log_c *lc = log->context;
747 if (lc->sync_search >= lc->region_count)
751 *region = find_next_zero_bit_le(lc->sync_bits,
752 lc->region_count,
753 lc->sync_search);
754 lc->sync_search = *region + 1;
756 if (*region >= lc->region_count)
759 } while (log_test_bit(lc->recovering_bits, *region));
761 log_set_bit(lc, lc->recovering_bits, *region);
768 struct log_c *lc = log->context;
770 log_clear_bit(lc, lc->recovering_bits, region);
772 log_set_bit(lc, lc->sync_bits, region);
773 lc->sync_count++;
774 } else if (log_test_bit(lc->sync_bits, region)) {
775 lc->sync_count--;
776 log_clear_bit(lc, lc->sync_bits, region);
782 struct log_c *lc = log->context;
784 return lc->sync_count;
789 if (lc->sync != DEFAULTSYNC) \
790 DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : ""); \
797 struct log_c *lc = log->context;
806 lc->sync == DEFAULTSYNC ? 1 : 2, lc->region_size);
822 struct log_c *lc = log->context;
826 DMEMIT("3 %s %s %c", log->type->name, lc->log_dev->name,
827 lc->log_dev_flush_failed ? 'F' :
828 lc->log_dev_failed ? 'D' :
834 lc->sync == DEFAULTSYNC ? 2 : 3, lc->log_dev->name,
835 lc->region_size);