@@ -251,8 +251,6 @@ struct dm_integrity_c {
251
251
252
252
struct workqueue_struct * recalc_wq ;
253
253
struct work_struct recalc_work ;
254
- u8 * recalc_buffer ;
255
- u8 * recalc_tags ;
256
254
257
255
struct bio_list flush_bio_list ;
258
256
@@ -2646,6 +2644,9 @@ static void recalc_write_super(struct dm_integrity_c *ic)
2646
2644
static void integrity_recalc (struct work_struct * w )
2647
2645
{
2648
2646
struct dm_integrity_c * ic = container_of (w , struct dm_integrity_c , recalc_work );
2647
+ size_t recalc_tags_size ;
2648
+ u8 * recalc_buffer = NULL ;
2649
+ u8 * recalc_tags = NULL ;
2649
2650
struct dm_integrity_range range ;
2650
2651
struct dm_io_request io_req ;
2651
2652
struct dm_io_region io_loc ;
@@ -2658,6 +2659,20 @@ static void integrity_recalc(struct work_struct *w)
2658
2659
int r ;
2659
2660
unsigned int super_counter = 0 ;
2660
2661
2662
+ recalc_buffer = __vmalloc (RECALC_SECTORS << SECTOR_SHIFT , GFP_NOIO );
2663
+ if (!recalc_buffer ) {
2664
+ DMCRIT ("out of memory for recalculate buffer - recalculation disabled" );
2665
+ goto free_ret ;
2666
+ }
2667
+ recalc_tags_size = (RECALC_SECTORS >> ic -> sb -> log2_sectors_per_block ) * ic -> tag_size ;
2668
+ if (crypto_shash_digestsize (ic -> internal_hash ) > ic -> tag_size )
2669
+ recalc_tags_size += crypto_shash_digestsize (ic -> internal_hash ) - ic -> tag_size ;
2670
+ recalc_tags = kvmalloc (recalc_tags_size , GFP_NOIO );
2671
+ if (!recalc_tags ) {
2672
+ DMCRIT ("out of memory for recalculate buffer - recalculation disabled" );
2673
+ goto free_ret ;
2674
+ }
2675
+
2661
2676
DEBUG_print ("start recalculation... (position %llx)\n" , le64_to_cpu (ic -> sb -> recalc_sector ));
2662
2677
2663
2678
spin_lock_irq (& ic -> endio_wait .lock );
@@ -2720,7 +2735,7 @@ static void integrity_recalc(struct work_struct *w)
2720
2735
2721
2736
io_req .bi_opf = REQ_OP_READ ;
2722
2737
io_req .mem .type = DM_IO_VMA ;
2723
- io_req .mem .ptr .addr = ic -> recalc_buffer ;
2738
+ io_req .mem .ptr .addr = recalc_buffer ;
2724
2739
io_req .notify .fn = NULL ;
2725
2740
io_req .client = ic -> io ;
2726
2741
io_loc .bdev = ic -> dev -> bdev ;
@@ -2733,15 +2748,15 @@ static void integrity_recalc(struct work_struct *w)
2733
2748
goto err ;
2734
2749
}
2735
2750
2736
- t = ic -> recalc_tags ;
2751
+ t = recalc_tags ;
2737
2752
for (i = 0 ; i < n_sectors ; i += ic -> sectors_per_block ) {
2738
- integrity_sector_checksum (ic , logical_sector + i , ic -> recalc_buffer + (i << SECTOR_SHIFT ), t );
2753
+ integrity_sector_checksum (ic , logical_sector + i , recalc_buffer + (i << SECTOR_SHIFT ), t );
2739
2754
t += ic -> tag_size ;
2740
2755
}
2741
2756
2742
2757
metadata_block = get_metadata_sector_and_offset (ic , area , offset , & metadata_offset );
2743
2758
2744
- r = dm_integrity_rw_tag (ic , ic -> recalc_tags , & metadata_block , & metadata_offset , t - ic -> recalc_tags , TAG_WRITE );
2759
+ r = dm_integrity_rw_tag (ic , recalc_tags , & metadata_block , & metadata_offset , t - recalc_tags , TAG_WRITE );
2745
2760
if (unlikely (r )) {
2746
2761
dm_integrity_io_error (ic , "writing tags" , r );
2747
2762
goto err ;
@@ -2769,12 +2784,16 @@ static void integrity_recalc(struct work_struct *w)
2769
2784
2770
2785
err :
2771
2786
remove_range (ic , & range );
2772
- return ;
2787
+ goto free_ret ;
2773
2788
2774
2789
unlock_ret :
2775
2790
spin_unlock_irq (& ic -> endio_wait .lock );
2776
2791
2777
2792
recalc_write_super (ic );
2793
+
2794
+ free_ret :
2795
+ vfree (recalc_buffer );
2796
+ kvfree (recalc_tags );
2778
2797
}
2779
2798
2780
2799
static void bitmap_block_work (struct work_struct * w )
@@ -4439,30 +4458,13 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv
4439
4458
}
4440
4459
4441
4460
if (ic -> internal_hash ) {
4442
- size_t recalc_tags_size ;
4443
-
4444
4461
ic -> recalc_wq = alloc_workqueue ("dm-integrity-recalc" , WQ_MEM_RECLAIM , 1 );
4445
4462
if (!ic -> recalc_wq ) {
4446
4463
ti -> error = "Cannot allocate workqueue" ;
4447
4464
r = - ENOMEM ;
4448
4465
goto bad ;
4449
4466
}
4450
4467
INIT_WORK (& ic -> recalc_work , integrity_recalc );
4451
- ic -> recalc_buffer = vmalloc (RECALC_SECTORS << SECTOR_SHIFT );
4452
- if (!ic -> recalc_buffer ) {
4453
- ti -> error = "Cannot allocate buffer for recalculating" ;
4454
- r = - ENOMEM ;
4455
- goto bad ;
4456
- }
4457
- recalc_tags_size = (RECALC_SECTORS >> ic -> sb -> log2_sectors_per_block ) * ic -> tag_size ;
4458
- if (crypto_shash_digestsize (ic -> internal_hash ) > ic -> tag_size )
4459
- recalc_tags_size += crypto_shash_digestsize (ic -> internal_hash ) - ic -> tag_size ;
4460
- ic -> recalc_tags = kvmalloc (recalc_tags_size , GFP_KERNEL );
4461
- if (!ic -> recalc_tags ) {
4462
- ti -> error = "Cannot allocate tags for recalculating" ;
4463
- r = - ENOMEM ;
4464
- goto bad ;
4465
- }
4466
4468
} else {
4467
4469
if (ic -> sb -> flags & cpu_to_le32 (SB_FLAG_RECALCULATING )) {
4468
4470
ti -> error = "Recalculate can only be specified with internal_hash" ;
@@ -4606,8 +4608,6 @@ static void dm_integrity_dtr(struct dm_target *ti)
4606
4608
destroy_workqueue (ic -> writer_wq );
4607
4609
if (ic -> recalc_wq )
4608
4610
destroy_workqueue (ic -> recalc_wq );
4609
- vfree (ic -> recalc_buffer );
4610
- kvfree (ic -> recalc_tags );
4611
4611
kvfree (ic -> bbs );
4612
4612
if (ic -> bufio )
4613
4613
dm_bufio_client_destroy (ic -> bufio );
0 commit comments