btt.c (4246a0b63bd8f56a1469b12eafeb875b1041a451) btt.c (fbde1414acc0440024083bf0c391b259bcfc4826)
1/*
2 * Block Translation Table
3 * Copyright (c) 2014-2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *

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

580 debugfs_remove_recursive(arena->debugfs_dir);
581 kfree(arena);
582 }
583}
584
585/*
586 * This function checks if the metadata layout is valid and error free
587 */
1/*
2 * Block Translation Table
3 * Copyright (c) 2014-2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *

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

580 debugfs_remove_recursive(arena->debugfs_dir);
581 kfree(arena);
582 }
583}
584
585/*
586 * This function checks if the metadata layout is valid and error free
587 */
588static int arena_is_valid(struct arena_info *arena, struct btt_sb *super,
589 u8 *uuid, u32 lbasize)
588static int arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super)
590{
591 u64 checksum;
592
589{
590 u64 checksum;
591
593 if (memcmp(super->uuid, uuid, 16))
592 if (memcmp(super->uuid, nd_btt->uuid, 16))
594 return 0;
595
596 checksum = le64_to_cpu(super->checksum);
597 super->checksum = 0;
598 if (checksum != nd_btt_sb_checksum(super))
599 return 0;
600 super->checksum = cpu_to_le64(checksum);
601
593 return 0;
594
595 checksum = le64_to_cpu(super->checksum);
596 super->checksum = 0;
597 if (checksum != nd_btt_sb_checksum(super))
598 return 0;
599 super->checksum = cpu_to_le64(checksum);
600
602 if (lbasize != le32_to_cpu(super->external_lbasize))
601 if (nd_btt->lbasize != le32_to_cpu(super->external_lbasize))
603 return 0;
604
605 /* TODO: figure out action for this */
606 if ((le32_to_cpu(super->flags) & IB_FLAG_ERROR_MASK) != 0)
602 return 0;
603
604 /* TODO: figure out action for this */
605 if ((le32_to_cpu(super->flags) & IB_FLAG_ERROR_MASK) != 0)
607 dev_info(to_dev(arena), "Found arena with an error flag\n");
606 dev_info(&nd_btt->dev, "Found arena with an error flag\n");
608
609 return 1;
610}
611
612/*
613 * This function reads an existing valid btt superblock and
614 * populates the corresponding arena_info struct
615 */

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

627 arena->nextoff = (super->nextoff == 0) ? 0 : (arena_off +
628 le64_to_cpu(super->nextoff));
629 arena->infooff = arena_off;
630 arena->dataoff = arena_off + le64_to_cpu(super->dataoff);
631 arena->mapoff = arena_off + le64_to_cpu(super->mapoff);
632 arena->logoff = arena_off + le64_to_cpu(super->logoff);
633 arena->info2off = arena_off + le64_to_cpu(super->info2off);
634
607
608 return 1;
609}
610
611/*
612 * This function reads an existing valid btt superblock and
613 * populates the corresponding arena_info struct
614 */

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

626 arena->nextoff = (super->nextoff == 0) ? 0 : (arena_off +
627 le64_to_cpu(super->nextoff));
628 arena->infooff = arena_off;
629 arena->dataoff = arena_off + le64_to_cpu(super->dataoff);
630 arena->mapoff = arena_off + le64_to_cpu(super->mapoff);
631 arena->logoff = arena_off + le64_to_cpu(super->logoff);
632 arena->info2off = arena_off + le64_to_cpu(super->info2off);
633
635 arena->size = (super->nextoff > 0) ? (le64_to_cpu(super->nextoff)) :
636 (arena->info2off - arena->infooff + BTT_PG_SIZE);
634 arena->size = (le64_to_cpu(super->nextoff) > 0)
635 ? (le64_to_cpu(super->nextoff))
636 : (arena->info2off - arena->infooff + BTT_PG_SIZE);
637
638 arena->flags = le32_to_cpu(super->flags);
639}
640
641static int discover_arenas(struct btt *btt)
642{
643 int ret = 0;
644 struct arena_info *arena;

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

660 goto out_super;
661 }
662
663 arena->infooff = cur_off;
664 ret = btt_info_read(arena, super);
665 if (ret)
666 goto out;
667
637
638 arena->flags = le32_to_cpu(super->flags);
639}
640
641static int discover_arenas(struct btt *btt)
642{
643 int ret = 0;
644 struct arena_info *arena;

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

660 goto out_super;
661 }
662
663 arena->infooff = cur_off;
664 ret = btt_info_read(arena, super);
665 if (ret)
666 goto out;
667
668 if (!arena_is_valid(arena, super, btt->nd_btt->uuid,
669 btt->lbasize)) {
668 if (!arena_is_valid(btt->nd_btt, super)) {
670 if (remaining == btt->rawsize) {
671 btt->init_state = INIT_NOTFOUND;
672 dev_info(to_dev(arena), "No existing arenas\n");
673 goto out;
674 } else {
675 dev_info(to_dev(arena),
676 "Found corrupted metadata!\n");
677 ret = -ENODEV;

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

750}
751
752/*
753 * This function completes arena initialization by writing
754 * all the metadata.
755 * It is only called for an uninitialized arena when a write
756 * to that arena occurs for the first time.
757 */
669 if (remaining == btt->rawsize) {
670 btt->init_state = INIT_NOTFOUND;
671 dev_info(to_dev(arena), "No existing arenas\n");
672 goto out;
673 } else {
674 dev_info(to_dev(arena),
675 "Found corrupted metadata!\n");
676 ret = -ENODEV;

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

749}
750
751/*
752 * This function completes arena initialization by writing
753 * all the metadata.
754 * It is only called for an uninitialized arena when a write
755 * to that arena occurs for the first time.
756 */
758static int btt_arena_write_layout(struct arena_info *arena, u8 *uuid)
757static int btt_arena_write_layout(struct arena_info *arena)
759{
760 int ret;
761 struct btt_sb *super;
758{
759 int ret;
760 struct btt_sb *super;
761 struct nd_btt *nd_btt = arena->nd_btt;
762
763 ret = btt_map_init(arena);
764 if (ret)
765 return ret;
766
767 ret = btt_log_init(arena);
768 if (ret)
769 return ret;
770
771 super = kzalloc(sizeof(struct btt_sb), GFP_NOIO);
772 if (!super)
773 return -ENOMEM;
774
775 strncpy(super->signature, BTT_SIG, BTT_SIG_LEN);
762
763 ret = btt_map_init(arena);
764 if (ret)
765 return ret;
766
767 ret = btt_log_init(arena);
768 if (ret)
769 return ret;
770
771 super = kzalloc(sizeof(struct btt_sb), GFP_NOIO);
772 if (!super)
773 return -ENOMEM;
774
775 strncpy(super->signature, BTT_SIG, BTT_SIG_LEN);
776 memcpy(super->uuid, uuid, 16);
776 memcpy(super->uuid, nd_btt->uuid, 16);
777 super->flags = cpu_to_le32(arena->flags);
778 super->version_major = cpu_to_le16(arena->version_major);
779 super->version_minor = cpu_to_le16(arena->version_minor);
780 super->external_lbasize = cpu_to_le32(arena->external_lbasize);
781 super->external_nlba = cpu_to_le32(arena->external_nlba);
782 super->internal_lbasize = cpu_to_le32(arena->internal_lbasize);
783 super->internal_nlba = cpu_to_le32(arena->internal_nlba);
784 super->nfree = cpu_to_le32(arena->nfree);

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

808 */
809static int btt_meta_init(struct btt *btt)
810{
811 int ret = 0;
812 struct arena_info *arena;
813
814 mutex_lock(&btt->init_lock);
815 list_for_each_entry(arena, &btt->arena_list, list) {
777 super->flags = cpu_to_le32(arena->flags);
778 super->version_major = cpu_to_le16(arena->version_major);
779 super->version_minor = cpu_to_le16(arena->version_minor);
780 super->external_lbasize = cpu_to_le32(arena->external_lbasize);
781 super->external_nlba = cpu_to_le32(arena->external_nlba);
782 super->internal_lbasize = cpu_to_le32(arena->internal_lbasize);
783 super->internal_nlba = cpu_to_le32(arena->internal_nlba);
784 super->nfree = cpu_to_le32(arena->nfree);

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

808 */
809static int btt_meta_init(struct btt *btt)
810{
811 int ret = 0;
812 struct arena_info *arena;
813
814 mutex_lock(&btt->init_lock);
815 list_for_each_entry(arena, &btt->arena_list, list) {
816 ret = btt_arena_write_layout(arena, btt->nd_btt->uuid);
816 ret = btt_arena_write_layout(arena);
817 if (ret)
818 goto unlock;
819
820 ret = btt_freelist_init(arena);
821 if (ret)
822 goto unlock;
823
824 ret = btt_rtt_init(arena);

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

1184
1185 /*
1186 * bio_integrity_enabled also checks if the bio already has an
1187 * integrity payload attached. If it does, we *don't* do a
1188 * bio_integrity_prep here - the payload has been generated by
1189 * another kernel subsystem, and we just pass it through.
1190 */
1191 if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
817 if (ret)
818 goto unlock;
819
820 ret = btt_freelist_init(arena);
821 if (ret)
822 goto unlock;
823
824 ret = btt_rtt_init(arena);

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

1184
1185 /*
1186 * bio_integrity_enabled also checks if the bio already has an
1187 * integrity payload attached. If it does, we *don't* do a
1188 * bio_integrity_prep here - the payload has been generated by
1189 * another kernel subsystem, and we just pass it through.
1190 */
1191 if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
1192 bio->bi_error = -EIO;
1192 err = -EIO;
1193 goto out;
1194 }
1195
1196 do_acct = nd_iostat_start(bio, &start);
1197 rw = bio_data_dir(bio);
1198 bio_for_each_segment(bvec, bio, iter) {
1199 unsigned int len = bvec.bv_len;
1200

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

1206
1207 err = btt_do_bvec(btt, bip, bvec.bv_page, len, bvec.bv_offset,
1208 rw, iter.bi_sector);
1209 if (err) {
1210 dev_info(&btt->nd_btt->dev,
1211 "io error in %s sector %lld, len %d,\n",
1212 (rw == READ) ? "READ" : "WRITE",
1213 (unsigned long long) iter.bi_sector, len);
1193 goto out;
1194 }
1195
1196 do_acct = nd_iostat_start(bio, &start);
1197 rw = bio_data_dir(bio);
1198 bio_for_each_segment(bvec, bio, iter) {
1199 unsigned int len = bvec.bv_len;
1200

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

1206
1207 err = btt_do_bvec(btt, bip, bvec.bv_page, len, bvec.bv_offset,
1208 rw, iter.bi_sector);
1209 if (err) {
1210 dev_info(&btt->nd_btt->dev,
1211 "io error in %s sector %lld, len %d,\n",
1212 (rw == READ) ? "READ" : "WRITE",
1213 (unsigned long long) iter.bi_sector, len);
1214 bio->bi_error = err;
1215 break;
1216 }
1217 }
1218 if (do_acct)
1219 nd_iostat_end(bio, start);
1220
1221out:
1214 break;
1215 }
1216 }
1217 if (do_acct)
1218 nd_iostat_end(bio, start);
1219
1220out:
1222 bio_endio(bio);
1221 bio_endio(bio, err);
1223}
1224
1225static int btt_rw_page(struct block_device *bdev, sector_t sector,
1226 struct page *page, int rw)
1227{
1228 struct btt *btt = bdev->bd_disk->private_data;
1229
1230 btt_do_bvec(btt, NULL, page, PAGE_CACHE_SIZE, 0, rw, sector);

--- 250 unchanged lines hidden ---
1222}
1223
1224static int btt_rw_page(struct block_device *bdev, sector_t sector,
1225 struct page *page, int rw)
1226{
1227 struct btt *btt = bdev->bd_disk->private_data;
1228
1229 btt_do_bvec(btt, NULL, page, PAGE_CACHE_SIZE, 0, rw, sector);

--- 250 unchanged lines hidden ---