file-item.c (860a7a0c321ce0267fdb6ebdcd03aa63c5fcb31d) | file-item.c (07d400a6df4767a90d49a153fdb7f4cfa1e3f23e) |
---|---|
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, --- 13 unchanged lines hidden (view full) --- 22#include "ctree.h" 23#include "disk-io.h" 24#include "transaction.h" 25#include "print-tree.h" 26 27#define MAX_CSUM_ITEMS(r, size) ((((BTRFS_LEAF_DATA_SIZE(r) - \ 28 sizeof(struct btrfs_item) * 2) / \ 29 size) - 1)) | 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, --- 13 unchanged lines hidden (view full) --- 22#include "ctree.h" 23#include "disk-io.h" 24#include "transaction.h" 25#include "print-tree.h" 26 27#define MAX_CSUM_ITEMS(r, size) ((((BTRFS_LEAF_DATA_SIZE(r) - \ 28 sizeof(struct btrfs_item) * 2) / \ 29 size) - 1)) |
30 31#define MAX_ORDERED_SUM_BYTES(r) ((PAGE_SIZE - \ 32 sizeof(struct btrfs_ordered_sum)) / \ 33 sizeof(struct btrfs_sector_sum) * \ 34 (r)->sectorsize - (r)->sectorsize) 35 |
|
30int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, 31 struct btrfs_root *root, 32 u64 objectid, u64 pos, 33 u64 disk_offset, u64 disk_num_bytes, 34 u64 num_bytes, u64 offset, u64 ram_bytes, 35 u8 compression, u8 encryption, u16 other_encoding) 36{ 37 int ret = 0; --- 216 unchanged lines hidden (view full) --- 254 255 path = btrfs_alloc_path(); 256 BUG_ON(!path); 257 258 key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; 259 key.offset = start; 260 key.type = BTRFS_EXTENT_CSUM_KEY; 261 | 36int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, 37 struct btrfs_root *root, 38 u64 objectid, u64 pos, 39 u64 disk_offset, u64 disk_num_bytes, 40 u64 num_bytes, u64 offset, u64 ram_bytes, 41 u8 compression, u8 encryption, u16 other_encoding) 42{ 43 int ret = 0; --- 216 unchanged lines hidden (view full) --- 260 261 path = btrfs_alloc_path(); 262 BUG_ON(!path); 263 264 key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; 265 key.offset = start; 266 key.type = BTRFS_EXTENT_CSUM_KEY; 267 |
262 ret = btrfs_search_slot(NULL, root->fs_info->csum_root, 263 &key, path, 0, 0); | 268 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); |
264 if (ret < 0) 265 goto fail; 266 if (ret > 0 && path->slots[0] > 0) { 267 leaf = path->nodes[0]; 268 btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1); 269 if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID && 270 key.type == BTRFS_EXTENT_CSUM_KEY) { 271 offset = (start - key.offset) >> 272 root->fs_info->sb->s_blocksize_bits; 273 if (offset * csum_size < 274 btrfs_item_size_nr(leaf, path->slots[0] - 1)) 275 path->slots[0]--; 276 } 277 } 278 279 while (start <= end) { 280 leaf = path->nodes[0]; 281 if (path->slots[0] >= btrfs_header_nritems(leaf)) { | 269 if (ret < 0) 270 goto fail; 271 if (ret > 0 && path->slots[0] > 0) { 272 leaf = path->nodes[0]; 273 btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1); 274 if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID && 275 key.type == BTRFS_EXTENT_CSUM_KEY) { 276 offset = (start - key.offset) >> 277 root->fs_info->sb->s_blocksize_bits; 278 if (offset * csum_size < 279 btrfs_item_size_nr(leaf, path->slots[0] - 1)) 280 path->slots[0]--; 281 } 282 } 283 284 while (start <= end) { 285 leaf = path->nodes[0]; 286 if (path->slots[0] >= btrfs_header_nritems(leaf)) { |
282 ret = btrfs_next_leaf(root->fs_info->csum_root, path); | 287 ret = btrfs_next_leaf(root, path); |
283 if (ret < 0) 284 goto fail; 285 if (ret > 0) 286 break; 287 leaf = path->nodes[0]; 288 } 289 290 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); --- 10 unchanged lines hidden (view full) --- 301 302 size = btrfs_item_size_nr(leaf, path->slots[0]); 303 csum_end = key.offset + (size / csum_size) * root->sectorsize; 304 if (csum_end <= start) { 305 path->slots[0]++; 306 continue; 307 } 308 | 288 if (ret < 0) 289 goto fail; 290 if (ret > 0) 291 break; 292 leaf = path->nodes[0]; 293 } 294 295 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); --- 10 unchanged lines hidden (view full) --- 306 307 size = btrfs_item_size_nr(leaf, path->slots[0]); 308 csum_end = key.offset + (size / csum_size) * root->sectorsize; 309 if (csum_end <= start) { 310 path->slots[0]++; 311 continue; 312 } 313 |
309 size = min(csum_end, end + 1) - start; 310 sums = kzalloc(btrfs_ordered_sum_size(root, size), GFP_NOFS); 311 BUG_ON(!sums); | 314 csum_end = min(csum_end, end + 1); 315 item = btrfs_item_ptr(path->nodes[0], path->slots[0], 316 struct btrfs_csum_item); 317 while (start < csum_end) { 318 size = min_t(size_t, csum_end - start, 319 MAX_ORDERED_SUM_BYTES(root)); 320 sums = kzalloc(btrfs_ordered_sum_size(root, size), 321 GFP_NOFS); 322 BUG_ON(!sums); |
312 | 323 |
313 sector_sum = sums->sums; 314 sums->bytenr = start; 315 sums->len = size; | 324 sector_sum = sums->sums; 325 sums->bytenr = start; 326 sums->len = size; |
316 | 327 |
317 offset = (start - key.offset) >> 318 root->fs_info->sb->s_blocksize_bits; 319 offset *= csum_size; | 328 offset = (start - key.offset) >> 329 root->fs_info->sb->s_blocksize_bits; 330 offset *= csum_size; |
320 | 331 |
321 item = btrfs_item_ptr(path->nodes[0], path->slots[0], 322 struct btrfs_csum_item); 323 while (size > 0) { 324 read_extent_buffer(path->nodes[0], §or_sum->sum, 325 ((unsigned long)item) + offset, 326 csum_size); 327 sector_sum->bytenr = start; | 332 while (size > 0) { 333 read_extent_buffer(path->nodes[0], 334 §or_sum->sum, 335 ((unsigned long)item) + 336 offset, csum_size); 337 sector_sum->bytenr = start; |
328 | 338 |
329 size -= root->sectorsize; 330 start += root->sectorsize; 331 offset += csum_size; 332 sector_sum++; | 339 size -= root->sectorsize; 340 start += root->sectorsize; 341 offset += csum_size; 342 sector_sum++; 343 } 344 list_add_tail(&sums->list, list); |
333 } | 345 } |
334 list_add_tail(&sums->list, list); 335 | |
336 path->slots[0]++; 337 } 338 ret = 0; 339fail: 340 btrfs_free_path(path); 341 return ret; 342} 343 --- 478 unchanged lines hidden --- | 346 path->slots[0]++; 347 } 348 ret = 0; 349fail: 350 btrfs_free_path(path); 351 return ret; 352} 353 --- 478 unchanged lines hidden --- |