btt_devs.c (527c465a3c8716d93201ae34b7fc52679610596d) | btt_devs.c (ab45e7632717b811e0786e46ca5ad279cb731b66) |
---|---|
1/* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 328 unchanged lines hidden (view full) --- 337{ 338 struct device *dev = __nd_btt_create(nd_region, 0, NULL, NULL); 339 340 if (dev) 341 __nd_device_register(dev); 342 return dev; 343} 344 | 1/* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 328 unchanged lines hidden (view full) --- 337{ 338 struct device *dev = __nd_btt_create(nd_region, 0, NULL, NULL); 339 340 if (dev) 341 __nd_device_register(dev); 342 return dev; 343} 344 |
345/** 346 * nd_btt_arena_is_valid - check if the metadata layout is valid 347 * @nd_btt: device with BTT geometry and backing device info 348 * @super: pointer to the arena's info block being tested 349 * 350 * Check consistency of the btt info block with itself by validating 351 * the checksum. 352 * 353 * Returns: 354 * false for an invalid info block, true for a valid one 355 */ 356bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super) 357{ 358 u64 checksum; 359 360 if (memcmp(super->signature, BTT_SIG, BTT_SIG_LEN) != 0) 361 return false; 362 363 checksum = le64_to_cpu(super->checksum); 364 super->checksum = 0; 365 if (checksum != nd_btt_sb_checksum(super)) 366 return false; 367 super->checksum = cpu_to_le64(checksum); 368 369 /* TODO: figure out action for this */ 370 if ((le32_to_cpu(super->flags) & IB_FLAG_ERROR_MASK) != 0) 371 dev_info(&nd_btt->dev, "Found arena with an error flag\n"); 372 373 return true; 374} 375EXPORT_SYMBOL(nd_btt_arena_is_valid); 376 |
|
345/* 346 * nd_btt_sb_checksum: compute checksum for btt info block 347 * 348 * Returns a fletcher64 checksum of everything in the given info block 349 * except the last field (since that's where the checksum lives). 350 */ 351u64 nd_btt_sb_checksum(struct btt_sb *btt_sb) 352{ --- 6 unchanged lines hidden (view full) --- 359 btt_sb->checksum = sum_save; 360 return sum; 361} 362EXPORT_SYMBOL(nd_btt_sb_checksum); 363 364static int __nd_btt_probe(struct nd_btt *nd_btt, 365 struct nd_namespace_common *ndns, struct btt_sb *btt_sb) 366{ | 377/* 378 * nd_btt_sb_checksum: compute checksum for btt info block 379 * 380 * Returns a fletcher64 checksum of everything in the given info block 381 * except the last field (since that's where the checksum lives). 382 */ 383u64 nd_btt_sb_checksum(struct btt_sb *btt_sb) 384{ --- 6 unchanged lines hidden (view full) --- 391 btt_sb->checksum = sum_save; 392 return sum; 393} 394EXPORT_SYMBOL(nd_btt_sb_checksum); 395 396static int __nd_btt_probe(struct nd_btt *nd_btt, 397 struct nd_namespace_common *ndns, struct btt_sb *btt_sb) 398{ |
367 u64 checksum; 368 | |
369 if (!btt_sb || !ndns || !nd_btt) 370 return -ENODEV; 371 372 if (nvdimm_read_bytes(ndns, SZ_4K, btt_sb, sizeof(*btt_sb))) 373 return -ENXIO; 374 375 if (nvdimm_namespace_capacity(ndns) < SZ_16M) 376 return -ENXIO; 377 | 399 if (!btt_sb || !ndns || !nd_btt) 400 return -ENODEV; 401 402 if (nvdimm_read_bytes(ndns, SZ_4K, btt_sb, sizeof(*btt_sb))) 403 return -ENXIO; 404 405 if (nvdimm_namespace_capacity(ndns) < SZ_16M) 406 return -ENXIO; 407 |
378 if (memcmp(btt_sb->signature, BTT_SIG, BTT_SIG_LEN) != 0) | 408 if (!nd_btt_arena_is_valid(nd_btt, btt_sb)) |
379 return -ENODEV; 380 | 409 return -ENODEV; 410 |
381 checksum = le64_to_cpu(btt_sb->checksum); 382 btt_sb->checksum = 0; 383 if (checksum != nd_btt_sb_checksum(btt_sb)) 384 return -ENODEV; 385 btt_sb->checksum = cpu_to_le64(checksum); 386 | |
387 nd_btt->lbasize = le32_to_cpu(btt_sb->external_lbasize); 388 nd_btt->uuid = kmemdup(btt_sb->uuid, 16, GFP_KERNEL); 389 if (!nd_btt->uuid) 390 return -ENOMEM; 391 392 __nd_device_register(&nd_btt->dev); 393 394 return 0; --- 31 unchanged lines hidden --- | 411 nd_btt->lbasize = le32_to_cpu(btt_sb->external_lbasize); 412 nd_btt->uuid = kmemdup(btt_sb->uuid, 16, GFP_KERNEL); 413 if (!nd_btt->uuid) 414 return -ENOMEM; 415 416 __nd_device_register(&nd_btt->dev); 417 418 return 0; --- 31 unchanged lines hidden --- |