file-item.c (76b36fa896a2db64582690e085f36adc76604134) file-item.c (c40a3d38aff4e1c832d1692850621be7d5e5308c)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

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

167 struct btrfs_csum_item *item = NULL;
168 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
169 struct btrfs_path *path;
170 u8 *csum;
171 u64 offset = 0;
172 u64 item_start_offset = 0;
173 u64 item_last_offset = 0;
174 u64 disk_bytenr;
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

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

167 struct btrfs_csum_item *item = NULL;
168 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
169 struct btrfs_path *path;
170 u8 *csum;
171 u64 offset = 0;
172 u64 item_start_offset = 0;
173 u64 item_last_offset = 0;
174 u64 disk_bytenr;
175 u64 page_bytes_left;
175 u32 diff;
176 int nblocks;
177 int bio_index = 0;
178 int count;
179 u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
180
181 path = btrfs_alloc_path();
182 if (!path)

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

215 if (btrfs_is_free_space_inode(inode)) {
216 path->search_commit_root = 1;
217 path->skip_locking = 1;
218 }
219
220 disk_bytenr = (u64)bio->bi_iter.bi_sector << 9;
221 if (dio)
222 offset = logical_offset;
176 u32 diff;
177 int nblocks;
178 int bio_index = 0;
179 int count;
180 u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
181
182 path = btrfs_alloc_path();
183 if (!path)

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

216 if (btrfs_is_free_space_inode(inode)) {
217 path->search_commit_root = 1;
218 path->skip_locking = 1;
219 }
220
221 disk_bytenr = (u64)bio->bi_iter.bi_sector << 9;
222 if (dio)
223 offset = logical_offset;
224
225 page_bytes_left = bvec->bv_len;
223 while (bio_index < bio->bi_vcnt) {
224 if (!dio)
225 offset = page_offset(bvec->bv_page) + bvec->bv_offset;
226 count = btrfs_find_ordered_sum(inode, offset, disk_bytenr,
227 (u32 *)csum, nblocks);
228 if (count)
229 goto found;
230

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

238 item = btrfs_lookup_csum(NULL, root->fs_info->csum_root,
239 path, disk_bytenr, 0);
240 if (IS_ERR(item)) {
241 count = 1;
242 memset(csum, 0, csum_size);
243 if (BTRFS_I(inode)->root->root_key.objectid ==
244 BTRFS_DATA_RELOC_TREE_OBJECTID) {
245 set_extent_bits(io_tree, offset,
226 while (bio_index < bio->bi_vcnt) {
227 if (!dio)
228 offset = page_offset(bvec->bv_page) + bvec->bv_offset;
229 count = btrfs_find_ordered_sum(inode, offset, disk_bytenr,
230 (u32 *)csum, nblocks);
231 if (count)
232 goto found;
233

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

241 item = btrfs_lookup_csum(NULL, root->fs_info->csum_root,
242 path, disk_bytenr, 0);
243 if (IS_ERR(item)) {
244 count = 1;
245 memset(csum, 0, csum_size);
246 if (BTRFS_I(inode)->root->root_key.objectid ==
247 BTRFS_DATA_RELOC_TREE_OBJECTID) {
248 set_extent_bits(io_tree, offset,
246 offset + bvec->bv_len - 1,
249 offset + root->sectorsize - 1,
247 EXTENT_NODATASUM, GFP_NOFS);
248 } else {
249 btrfs_info(BTRFS_I(inode)->root->fs_info,
250 "no csum found for inode %llu start %llu",
251 btrfs_ino(inode), offset);
252 }
253 item = NULL;
254 btrfs_release_path(path);

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

276 count = min_t(int, nblocks, (item_last_offset - disk_bytenr) >>
277 inode->i_sb->s_blocksize_bits);
278 read_extent_buffer(path->nodes[0], csum,
279 ((unsigned long)item) + diff,
280 csum_size * count);
281found:
282 csum += count * csum_size;
283 nblocks -= count;
250 EXTENT_NODATASUM, GFP_NOFS);
251 } else {
252 btrfs_info(BTRFS_I(inode)->root->fs_info,
253 "no csum found for inode %llu start %llu",
254 btrfs_ino(inode), offset);
255 }
256 item = NULL;
257 btrfs_release_path(path);

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

279 count = min_t(int, nblocks, (item_last_offset - disk_bytenr) >>
280 inode->i_sb->s_blocksize_bits);
281 read_extent_buffer(path->nodes[0], csum,
282 ((unsigned long)item) + diff,
283 csum_size * count);
284found:
285 csum += count * csum_size;
286 nblocks -= count;
284 bio_index += count;
287
285 while (count--) {
288 while (count--) {
286 disk_bytenr += bvec->bv_len;
287 offset += bvec->bv_len;
288 bvec++;
289 disk_bytenr += root->sectorsize;
290 offset += root->sectorsize;
291 page_bytes_left -= root->sectorsize;
292 if (!page_bytes_left) {
293 bio_index++;
294 bvec++;
295 page_bytes_left = bvec->bv_len;
296 }
297
289 }
290 }
291 btrfs_free_path(path);
292 return 0;
293}
294
295int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
296 struct bio *bio, u32 *dst)

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

427 struct bio *bio, u64 file_start, int contig)
428{
429 struct btrfs_ordered_sum *sums;
430 struct btrfs_ordered_extent *ordered;
431 char *data;
432 struct bio_vec *bvec = bio->bi_io_vec;
433 int bio_index = 0;
434 int index;
298 }
299 }
300 btrfs_free_path(path);
301 return 0;
302}
303
304int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
305 struct bio *bio, u32 *dst)

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

436 struct bio *bio, u64 file_start, int contig)
437{
438 struct btrfs_ordered_sum *sums;
439 struct btrfs_ordered_extent *ordered;
440 char *data;
441 struct bio_vec *bvec = bio->bi_io_vec;
442 int bio_index = 0;
443 int index;
444 int nr_sectors;
445 int i;
435 unsigned long total_bytes = 0;
436 unsigned long this_sum_bytes = 0;
437 u64 offset;
438
439 WARN_ON(bio->bi_vcnt <= 0);
440 sums = kzalloc(btrfs_ordered_sum_size(root, bio->bi_iter.bi_size),
441 GFP_NOFS);
442 if (!sums)

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

454 BUG_ON(!ordered); /* Logic error */
455 sums->bytenr = (u64)bio->bi_iter.bi_sector << 9;
456 index = 0;
457
458 while (bio_index < bio->bi_vcnt) {
459 if (!contig)
460 offset = page_offset(bvec->bv_page) + bvec->bv_offset;
461
446 unsigned long total_bytes = 0;
447 unsigned long this_sum_bytes = 0;
448 u64 offset;
449
450 WARN_ON(bio->bi_vcnt <= 0);
451 sums = kzalloc(btrfs_ordered_sum_size(root, bio->bi_iter.bi_size),
452 GFP_NOFS);
453 if (!sums)

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

465 BUG_ON(!ordered); /* Logic error */
466 sums->bytenr = (u64)bio->bi_iter.bi_sector << 9;
467 index = 0;
468
469 while (bio_index < bio->bi_vcnt) {
470 if (!contig)
471 offset = page_offset(bvec->bv_page) + bvec->bv_offset;
472
462 if (offset >= ordered->file_offset + ordered->len ||
463 offset < ordered->file_offset) {
464 unsigned long bytes_left;
465 sums->len = this_sum_bytes;
466 this_sum_bytes = 0;
467 btrfs_add_ordered_sum(inode, ordered, sums);
468 btrfs_put_ordered_extent(ordered);
473 data = kmap_atomic(bvec->bv_page);
469
474
470 bytes_left = bio->bi_iter.bi_size - total_bytes;
475 nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info,
476 bvec->bv_len + root->sectorsize
477 - 1);
471
478
472 sums = kzalloc(btrfs_ordered_sum_size(root, bytes_left),
473 GFP_NOFS);
474 BUG_ON(!sums); /* -ENOMEM */
475 sums->len = bytes_left;
476 ordered = btrfs_lookup_ordered_extent(inode, offset);
477 BUG_ON(!ordered); /* Logic error */
478 sums->bytenr = ((u64)bio->bi_iter.bi_sector << 9) +
479 total_bytes;
480 index = 0;
479 for (i = 0; i < nr_sectors; i++) {
480 if (offset >= ordered->file_offset + ordered->len ||
481 offset < ordered->file_offset) {
482 unsigned long bytes_left;
483
484 kunmap_atomic(data);
485 sums->len = this_sum_bytes;
486 this_sum_bytes = 0;
487 btrfs_add_ordered_sum(inode, ordered, sums);
488 btrfs_put_ordered_extent(ordered);
489
490 bytes_left = bio->bi_iter.bi_size - total_bytes;
491
492 sums = kzalloc(btrfs_ordered_sum_size(root, bytes_left),
493 GFP_NOFS);
494 BUG_ON(!sums); /* -ENOMEM */
495 sums->len = bytes_left;
496 ordered = btrfs_lookup_ordered_extent(inode,
497 offset);
498 ASSERT(ordered); /* Logic error */
499 sums->bytenr = ((u64)bio->bi_iter.bi_sector << 9)
500 + total_bytes;
501 index = 0;
502
503 data = kmap_atomic(bvec->bv_page);
504 }
505
506 sums->sums[index] = ~(u32)0;
507 sums->sums[index]
508 = btrfs_csum_data(data + bvec->bv_offset
509 + (i * root->sectorsize),
510 sums->sums[index],
511 root->sectorsize);
512 btrfs_csum_final(sums->sums[index],
513 (char *)(sums->sums + index));
514 index++;
515 offset += root->sectorsize;
516 this_sum_bytes += root->sectorsize;
517 total_bytes += root->sectorsize;
481 }
482
518 }
519
483 data = kmap_atomic(bvec->bv_page);
484 sums->sums[index] = ~(u32)0;
485 sums->sums[index] = btrfs_csum_data(data + bvec->bv_offset,
486 sums->sums[index],
487 bvec->bv_len);
488 kunmap_atomic(data);
520 kunmap_atomic(data);
489 btrfs_csum_final(sums->sums[index],
490 (char *)(sums->sums + index));
491
492 bio_index++;
521
522 bio_index++;
493 index++;
494 total_bytes += bvec->bv_len;
495 this_sum_bytes += bvec->bv_len;
496 offset += bvec->bv_len;
497 bvec++;
498 }
499 this_sum_bytes = 0;
500 btrfs_add_ordered_sum(inode, ordered, sums);
501 btrfs_put_ordered_extent(ordered);
502 return 0;
503}
504

--- 449 unchanged lines hidden ---
523 bvec++;
524 }
525 this_sum_bytes = 0;
526 btrfs_add_ordered_sum(inode, ordered, sums);
527 btrfs_put_ordered_extent(ordered);
528 return 0;
529}
530

--- 449 unchanged lines hidden ---