@@ -28,6 +28,9 @@ using namespace android;
28
28
using namespace android ::dm;
29
29
using android::base::unique_fd;
30
30
31
+ #define SNAP_LOG (level ) LOG(level) << misc_name_ << " : "
32
+ #define SNAP_PLOG (level ) PLOG(level) << misc_name_ << " : "
33
+
31
34
static constexpr size_t PAYLOAD_SIZE = (1UL << 16 );
32
35
33
36
static_assert (PAYLOAD_SIZE >= BLOCK_SIZE);
@@ -94,7 +97,7 @@ void Snapuserd::ConstructKernelCowHeader() {
94
97
// it will be de-compressed.
95
98
bool Snapuserd::ProcessReplaceOp (const CowOperation* cow_op) {
96
99
if (!reader_->ReadData (*cow_op, &bufsink_)) {
97
- LOG (ERROR) << " ReadData failed for chunk: " << cow_op->new_block ;
100
+ SNAP_LOG (ERROR) << " ReadData failed for chunk: " << cow_op->new_block ;
98
101
return false ;
99
102
}
100
103
@@ -111,7 +114,7 @@ bool Snapuserd::ProcessCopyOp(const CowOperation* cow_op) {
111
114
// if the successive blocks are contiguous.
112
115
if (!android::base::ReadFullyAtOffset (backing_store_fd_, buffer, BLOCK_SIZE,
113
116
cow_op->source * BLOCK_SIZE)) {
114
- LOG (ERROR) << " Copy-op failed. Read from backing store at: " << cow_op->source ;
117
+ SNAP_LOG (ERROR) << " Copy-op failed. Read from backing store at: " << cow_op->source ;
115
118
return false ;
116
119
}
117
120
@@ -180,14 +183,14 @@ bool Snapuserd::ReadData(chunk_t chunk, size_t size) {
180
183
}
181
184
182
185
default : {
183
- LOG (ERROR) << " Unknown operation-type found: " << cow_op->type ;
186
+ SNAP_LOG (ERROR) << " Unknown operation-type found: " << cow_op->type ;
184
187
ret = false ;
185
188
break ;
186
189
}
187
190
}
188
191
189
192
if (!ret) {
190
- LOG (ERROR) << " ReadData failed for operation: " << cow_op->type ;
193
+ SNAP_LOG (ERROR) << " ReadData failed for operation: " << cow_op->type ;
191
194
return false ;
192
195
}
193
196
@@ -322,7 +325,7 @@ loff_t Snapuserd::GetMergeStartOffset(void* merged_buffer, void* unmerged_buffer
322
325
323
326
CHECK (!(*unmerged_exceptions == exceptions_per_area_));
324
327
325
- LOG (DEBUG) << " Unmerged_Exceptions: " << *unmerged_exceptions << " Offset: " << offset;
328
+ SNAP_LOG (DEBUG) << " Unmerged_Exceptions: " << *unmerged_exceptions << " Offset: " << offset;
326
329
return offset;
327
330
}
328
331
@@ -355,11 +358,11 @@ int Snapuserd::GetNumberOfMergedOps(void* merged_buffer, void* unmerged_buffer,
355
358
CHECK (cow_de->new_chunk == 0 );
356
359
break ;
357
360
} else {
358
- LOG (ERROR) << " Error in merge operation. Found invalid metadata" ;
359
- LOG (ERROR) << " merged_de-old-chunk: " << merged_de->old_chunk ;
360
- LOG (ERROR) << " merged_de-new-chunk: " << merged_de->new_chunk ;
361
- LOG (ERROR) << " cow_de-old-chunk: " << cow_de->old_chunk ;
362
- LOG (ERROR) << " cow_de-new-chunk: " << cow_de->new_chunk ;
361
+ SNAP_LOG (ERROR) << " Error in merge operation. Found invalid metadata" ;
362
+ SNAP_LOG (ERROR) << " merged_de-old-chunk: " << merged_de->old_chunk ;
363
+ SNAP_LOG (ERROR) << " merged_de-new-chunk: " << merged_de->new_chunk ;
364
+ SNAP_LOG (ERROR) << " cow_de-old-chunk: " << cow_de->old_chunk ;
365
+ SNAP_LOG (ERROR) << " cow_de-new-chunk: " << cow_de->new_chunk ;
363
366
return -1 ;
364
367
}
365
368
}
@@ -384,19 +387,19 @@ bool Snapuserd::AdvanceMergedOps(int merged_ops_cur_iter) {
384
387
385
388
if (!(cow_op->type == kCowReplaceOp || cow_op->type == kCowZeroOp ||
386
389
cow_op->type == kCowCopyOp )) {
387
- LOG (ERROR) << " Unknown operation-type found during merge: " << cow_op->type ;
390
+ SNAP_LOG (ERROR) << " Unknown operation-type found during merge: " << cow_op->type ;
388
391
return false ;
389
392
}
390
393
391
394
merged_ops_cur_iter -= 1 ;
392
- LOG (DEBUG) << " Merge op found of type " << cow_op->type
393
- << " Pending-merge-ops: " << merged_ops_cur_iter;
395
+ SNAP_LOG (DEBUG) << " Merge op found of type " << cow_op->type
396
+ << " Pending-merge-ops: " << merged_ops_cur_iter;
394
397
cowop_iter_->Next ();
395
398
}
396
399
397
400
if (cowop_iter_->Done ()) {
398
401
CHECK (merged_ops_cur_iter == 0 );
399
- LOG (DEBUG) << " All cow operations merged successfully in this cycle" ;
402
+ SNAP_LOG (DEBUG) << " All cow operations merged successfully in this cycle" ;
400
403
}
401
404
402
405
return true ;
@@ -407,14 +410,15 @@ bool Snapuserd::ProcessMergeComplete(chunk_t chunk, void* buffer) {
407
410
CowHeader header;
408
411
409
412
if (!reader_->GetHeader (&header)) {
410
- LOG (ERROR) << " Failed to get header" ;
413
+ SNAP_LOG (ERROR) << " Failed to get header" ;
411
414
return false ;
412
415
}
413
416
414
417
// ChunkID to vector index
415
418
lldiv_t divresult = lldiv (chunk, stride);
416
419
CHECK (divresult.quot < vec_.size ());
417
- LOG (DEBUG) << " ProcessMergeComplete: chunk: " << chunk << " Metadata-Index: " << divresult.quot ;
420
+ SNAP_LOG (DEBUG) << " ProcessMergeComplete: chunk: " << chunk
421
+ << " Metadata-Index: " << divresult.quot ;
418
422
419
423
int unmerged_exceptions = 0 ;
420
424
loff_t offset = GetMergeStartOffset (buffer, vec_[divresult.quot ].get (), &unmerged_exceptions);
@@ -429,11 +433,11 @@ bool Snapuserd::ProcessMergeComplete(chunk_t chunk, void* buffer) {
429
433
header.num_merge_ops += merged_ops_cur_iter;
430
434
reader_->UpdateMergeProgress (merged_ops_cur_iter);
431
435
if (!writer_->CommitMerge (merged_ops_cur_iter)) {
432
- LOG (ERROR) << " CommitMerge failed..." ;
436
+ SNAP_LOG (ERROR) << " CommitMerge failed..." ;
433
437
return false ;
434
438
}
435
439
436
- LOG (DEBUG) << " Merge success" ;
440
+ SNAP_LOG (DEBUG) << " Merge success" ;
437
441
return true ;
438
442
}
439
443
@@ -513,21 +517,21 @@ bool Snapuserd::ReadMetadata() {
513
517
bool prev_copy_op = false ;
514
518
bool metadata_found = false ;
515
519
516
- LOG (DEBUG) << " ReadMetadata Start..." ;
520
+ SNAP_LOG (DEBUG) << " ReadMetadata Start..." ;
517
521
518
522
if (!reader_->Parse (cow_fd_)) {
519
- LOG (ERROR) << " Failed to parse" ;
523
+ SNAP_LOG (ERROR) << " Failed to parse" ;
520
524
return false ;
521
525
}
522
526
523
527
if (!reader_->GetHeader (&header)) {
524
- LOG (ERROR) << " Failed to get header" ;
528
+ SNAP_LOG (ERROR) << " Failed to get header" ;
525
529
return false ;
526
530
}
527
531
528
532
CHECK (header.block_size == BLOCK_SIZE);
529
533
530
- LOG (DEBUG) << " Merge-ops: " << header.num_merge_ops ;
534
+ SNAP_LOG (DEBUG) << " Merge-ops: " << header.num_merge_ops ;
531
535
532
536
writer_ = std::make_unique<CowWriter>(options);
533
537
writer_->InitializeMerge (cow_fd_.get (), &header);
@@ -563,7 +567,7 @@ bool Snapuserd::ReadMetadata() {
563
567
564
568
if (!(cow_op->type == kCowReplaceOp || cow_op->type == kCowZeroOp ||
565
569
cow_op->type == kCowCopyOp )) {
566
- LOG (ERROR) << " Unknown operation-type found: " << cow_op->type ;
570
+ SNAP_LOG (ERROR) << " Unknown operation-type found: " << cow_op->type ;
567
571
return false ;
568
572
}
569
573
@@ -578,7 +582,7 @@ bool Snapuserd::ReadMetadata() {
578
582
de->old_chunk = cow_op->new_block ;
579
583
de->new_chunk = next_free;
580
584
581
- LOG (DEBUG) << " Old-chunk: " << de->old_chunk << " New-chunk: " << de->new_chunk ;
585
+ SNAP_LOG (DEBUG) << " Old-chunk: " << de->old_chunk << " New-chunk: " << de->new_chunk ;
582
586
583
587
// Store operation pointer.
584
588
chunk_map_[next_free] = cow_op;
@@ -602,7 +606,7 @@ bool Snapuserd::ReadMetadata() {
602
606
603
607
if (cowop_riter_->Done ()) {
604
608
vec_.push_back (std::move (de_ptr));
605
- LOG (DEBUG) << " ReadMetadata() completed; Number of Areas: " << vec_.size ();
609
+ SNAP_LOG (DEBUG) << " ReadMetadata() completed; Number of Areas: " << vec_.size ();
606
610
}
607
611
}
608
612
@@ -614,12 +618,12 @@ bool Snapuserd::ReadMetadata() {
614
618
// is aware that merge is completed.
615
619
if (num_ops || !metadata_found) {
616
620
vec_.push_back (std::move (de_ptr));
617
- LOG (DEBUG) << " ReadMetadata() completed. Partially filled area num_ops: " << num_ops
618
- << " Areas : " << vec_.size ();
621
+ SNAP_LOG (DEBUG) << " ReadMetadata() completed. Partially filled area num_ops: " << num_ops
622
+ << " Areas : " << vec_.size ();
619
623
}
620
624
621
- LOG (DEBUG) << " ReadMetadata() completed. chunk_id: " << next_free
622
- << " Num Sector: " << ChunkToSector (next_free);
625
+ SNAP_LOG (DEBUG) << " ReadMetadata() completed. chunk_id: " << next_free
626
+ << " Num Sector: " << ChunkToSector (next_free);
623
627
624
628
// Initialize the iterator for merging
625
629
cowop_iter_ = reader_->GetOpIter ();
@@ -643,7 +647,7 @@ void MyLogger(android::base::LogId, android::base::LogSeverity severity, const c
643
647
// us the sector number for which IO is issued by dm-snapshot device
644
648
bool Snapuserd::ReadDmUserHeader () {
645
649
if (!android::base::ReadFully (ctrl_fd_, bufsink_.GetBufPtr (), sizeof (struct dm_user_header ))) {
646
- PLOG (ERROR) << " ReadDmUserHeader failed" ;
650
+ SNAP_PLOG (ERROR) << " Control-read failed" ;
647
651
return false ;
648
652
}
649
653
@@ -654,7 +658,7 @@ bool Snapuserd::ReadDmUserHeader() {
654
658
bool Snapuserd::WriteDmUserPayload (size_t size) {
655
659
if (!android::base::WriteFully (ctrl_fd_, bufsink_.GetBufPtr (),
656
660
sizeof (struct dm_user_header ) + size)) {
657
- PLOG (ERROR) << " Write to dm-user failed" ;
661
+ SNAP_PLOG (ERROR) << " Write to dm-user failed" ;
658
662
return false ;
659
663
}
660
664
@@ -663,7 +667,7 @@ bool Snapuserd::WriteDmUserPayload(size_t size) {
663
667
664
668
bool Snapuserd::ReadDmUserPayload (void * buffer, size_t size) {
665
669
if (!android::base::ReadFully (ctrl_fd_, buffer, size)) {
666
- PLOG (ERROR) << " ReadDmUserPayload failed" ;
670
+ SNAP_PLOG (ERROR) << " ReadDmUserPayload failed" ;
667
671
return false ;
668
672
}
669
673
@@ -673,7 +677,7 @@ bool Snapuserd::ReadDmUserPayload(void* buffer, size_t size) {
673
677
bool Snapuserd::InitCowDevice () {
674
678
cow_fd_.reset (open (cow_device_.c_str (), O_RDWR));
675
679
if (cow_fd_ < 0 ) {
676
- PLOG (ERROR) << " Open Failed: " << cow_device_;
680
+ SNAP_PLOG (ERROR) << " Open Failed: " << cow_device_;
677
681
return false ;
678
682
}
679
683
@@ -690,13 +694,13 @@ bool Snapuserd::InitCowDevice() {
690
694
bool Snapuserd::InitBackingAndControlDevice () {
691
695
backing_store_fd_.reset (open (backing_store_device_.c_str (), O_RDONLY));
692
696
if (backing_store_fd_ < 0 ) {
693
- PLOG (ERROR) << " Open Failed: " << backing_store_device_;
697
+ SNAP_PLOG (ERROR) << " Open Failed: " << backing_store_device_;
694
698
return false ;
695
699
}
696
700
697
701
ctrl_fd_.reset (open (control_device_.c_str (), O_RDWR));
698
702
if (ctrl_fd_ < 0 ) {
699
- PLOG (ERROR) << " Unable to open " << control_device_;
703
+ SNAP_PLOG (ERROR) << " Unable to open " << control_device_;
700
704
return false ;
701
705
}
702
706
@@ -709,15 +713,15 @@ bool Snapuserd::Run() {
709
713
bufsink_.Clear ();
710
714
711
715
if (!ReadDmUserHeader ()) {
712
- LOG (ERROR) << " ReadDmUserHeader failed" ;
716
+ SNAP_LOG (ERROR) << " ReadDmUserHeader failed" ;
713
717
return false ;
714
718
}
715
719
716
- LOG (DEBUG) << " msg->seq: " << std::hex << header->seq ;
717
- LOG (DEBUG) << " msg->type: " << std::hex << header->type ;
718
- LOG (DEBUG) << " msg->flags: " << std::hex << header->flags ;
719
- LOG (DEBUG) << " msg->sector: " << std::hex << header->sector ;
720
- LOG (DEBUG) << " msg->len: " << std::hex << header->len ;
720
+ SNAP_LOG (DEBUG) << " msg->seq: " << std::hex << header->seq ;
721
+ SNAP_LOG (DEBUG) << " msg->type: " << std::hex << header->type ;
722
+ SNAP_LOG (DEBUG) << " msg->flags: " << std::hex << header->flags ;
723
+ SNAP_LOG (DEBUG) << " msg->sector: " << std::hex << header->sector ;
724
+ SNAP_LOG (DEBUG) << " msg->len: " << std::hex << header->len ;
721
725
722
726
switch (header->type ) {
723
727
case DM_USER_REQ_MAP_READ: {
@@ -736,7 +740,7 @@ bool Snapuserd::Run() {
736
740
CHECK (metadata_read_done_ == true );
737
741
CHECK (read_size == BLOCK_SIZE);
738
742
ConstructKernelCowHeader ();
739
- LOG (DEBUG) << " Kernel header constructed" ;
743
+ SNAP_LOG (DEBUG) << " Kernel header constructed" ;
740
744
} else {
741
745
// Convert the sector number to a chunk ID.
742
746
//
@@ -747,22 +751,22 @@ bool Snapuserd::Run() {
747
751
748
752
if (chunk_map_.find (chunk) == chunk_map_.end ()) {
749
753
if (!ReadDiskExceptions (chunk, read_size)) {
750
- LOG (ERROR) << " ReadDiskExceptions failed for chunk id: " << chunk
751
- << " Sector: " << header->sector ;
754
+ SNAP_LOG (ERROR) << " ReadDiskExceptions failed for chunk id: " << chunk
755
+ << " Sector: " << header->sector ;
752
756
header->type = DM_USER_RESP_ERROR;
753
757
} else {
754
- LOG (DEBUG) << " ReadDiskExceptions success for chunk id: " << chunk
755
- << " Sector: " << header->sector ;
758
+ SNAP_LOG (DEBUG) << " ReadDiskExceptions success for chunk id: " << chunk
759
+ << " Sector: " << header->sector ;
756
760
}
757
761
} else {
758
762
chunk_t num_chunks_read = (offset >> BLOCK_SHIFT);
759
763
if (!ReadData (chunk + num_chunks_read, read_size)) {
760
- LOG (ERROR) << " ReadData failed for chunk id: " << chunk
761
- << " Sector: " << header->sector ;
764
+ SNAP_LOG (ERROR) << " ReadData failed for chunk id: " << chunk
765
+ << " Sector: " << header->sector ;
762
766
header->type = DM_USER_RESP_ERROR;
763
767
} else {
764
- LOG (DEBUG) << " ReadData success for chunk id: " << chunk
765
- << " Sector: " << header->sector ;
768
+ SNAP_LOG (DEBUG) << " ReadData success for chunk id: " << chunk
769
+ << " Sector: " << header->sector ;
766
770
}
767
771
}
768
772
}
@@ -817,18 +821,18 @@ bool Snapuserd::Run() {
817
821
header->type = DM_USER_RESP_SUCCESS;
818
822
819
823
if (!ReadDmUserPayload (buffer, read_size)) {
820
- LOG (ERROR) << " ReadDmUserPayload failed for chunk id: " << chunk
821
- << " Sector: " << header->sector ;
824
+ SNAP_LOG (ERROR) << " ReadDmUserPayload failed for chunk id: " << chunk
825
+ << " Sector: " << header->sector ;
822
826
header->type = DM_USER_RESP_ERROR;
823
827
}
824
828
825
829
if (header->type == DM_USER_RESP_SUCCESS && !ProcessMergeComplete (chunk, buffer)) {
826
- LOG (ERROR) << " ProcessMergeComplete failed for chunk id: " << chunk
827
- << " Sector: " << header->sector ;
830
+ SNAP_LOG (ERROR) << " ProcessMergeComplete failed for chunk id: " << chunk
831
+ << " Sector: " << header->sector ;
828
832
header->type = DM_USER_RESP_ERROR;
829
833
} else {
830
- LOG (DEBUG) << " ProcessMergeComplete success for chunk id: " << chunk
831
- << " Sector: " << header->sector ;
834
+ SNAP_LOG (DEBUG) << " ProcessMergeComplete success for chunk id: " << chunk
835
+ << " Sector: " << header->sector ;
832
836
}
833
837
834
838
if (!WriteDmUserPayload (0 )) {
0 commit comments