|
|
4ee10e |
From 32de33be68f3892698d492b9ab8f21f9186b3f4c Mon Sep 17 00:00:00 2001
|
|
|
4ee10e |
From: Ming-Hung Tsai <mtsai@redhat.com>
|
|
|
4ee10e |
Date: Wed, 2 Jun 2021 01:23:13 +0800
|
|
|
4ee10e |
Subject: [PATCH 05/10] [thin_show_duplicates] Fix potential errors
|
|
|
4ee10e |
|
|
|
4ee10e |
- Fix error if no --block-sector provided
|
|
|
4ee10e |
- Fix errors on pools without mappings, or zero-length file
|
|
|
4ee10e |
---
|
|
|
4ee10e |
thin-provisioning/thin_show_duplicates.cc | 8 ++++++--
|
|
|
4ee10e |
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
4ee10e |
|
|
|
4ee10e |
diff --git a/thin-provisioning/thin_show_duplicates.cc b/thin-provisioning/thin_show_duplicates.cc
|
|
|
4ee10e |
index b1eebb7..f7354eb 100644
|
|
|
4ee10e |
--- a/thin-provisioning/thin_show_duplicates.cc
|
|
|
4ee10e |
+++ b/thin-provisioning/thin_show_duplicates.cc
|
|
|
4ee10e |
@@ -56,7 +56,7 @@ using namespace thin_provisioning;
|
|
|
4ee10e |
|
|
|
4ee10e |
namespace {
|
|
|
4ee10e |
bool factor_of(block_address f, block_address n) {
|
|
|
4ee10e |
- return (n % f) == 0;
|
|
|
4ee10e |
+ return f && (n % f) == 0;
|
|
|
4ee10e |
}
|
|
|
4ee10e |
|
|
|
4ee10e |
uint64_t parse_int(string const &str, string const &desc) {
|
|
|
4ee10e |
@@ -132,11 +132,15 @@ namespace {
|
|
|
4ee10e |
class duplicate_detector {
|
|
|
4ee10e |
public:
|
|
|
4ee10e |
void scan_with_variable_sized_chunks(chunk_stream &stream) {
|
|
|
4ee10e |
+ if (!stream.size())
|
|
|
4ee10e |
+ return;
|
|
|
4ee10e |
variable_chunk_stream vstream(stream, 4096);
|
|
|
4ee10e |
scan(vstream);
|
|
|
4ee10e |
}
|
|
|
4ee10e |
|
|
|
4ee10e |
void scan_with_fixed_sized_chunks(chunk_stream &stream, block_address chunk_size) {
|
|
|
4ee10e |
+ if (!stream.size())
|
|
|
4ee10e |
+ return;
|
|
|
4ee10e |
fixed_chunk_stream fstream(stream, chunk_size);
|
|
|
4ee10e |
scan(fstream);
|
|
|
4ee10e |
}
|
|
|
4ee10e |
@@ -222,7 +226,7 @@ namespace {
|
|
|
4ee10e |
if (fs.content_based_chunks)
|
|
|
4ee10e |
detector.scan_with_variable_sized_chunks(pstream);
|
|
|
4ee10e |
else {
|
|
|
4ee10e |
- if (*fs.block_size) {
|
|
|
4ee10e |
+ if (!!fs.block_size) {
|
|
|
4ee10e |
if (factor_of(*fs.block_size, block_size))
|
|
|
4ee10e |
block_size = *fs.block_size;
|
|
|
4ee10e |
else
|
|
|
4ee10e |
--
|
|
|
4ee10e |
1.8.3.1
|
|
|
4ee10e |
|