From 391ec7679865b1cbdeae7ad1c6e6a8fa6bf741fe Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 3 Jun 2020 14:00:13 +0200 Subject: [PATCH] fix backing up images that are not multiples of 'chunk_size' by removing the client side checks since the backup server has to check those things anyway, there is little benefit of checking it here, but poses a risk that there are two diverging checks for the client and server especially the next to last check (end_offset > device_size) was wrong, since we do not actually check the size of the actual chunk (which would be 'size'), but the generic set chunk size (defaults to 4M) which is obviously wrong (the last chunk is probably smaller) since it is not needed anymore, we can omit to get the 'device_size' fixes an issue where we could not backup an image which was not 4M aligned (or smaller than 4M altogether) Signed-off-by: Dominik Csapak --- src/commands.rs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index b3a46df..c4d9a5d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -213,30 +213,14 @@ pub(crate) async fn write_data( //println!("dev {}: write {} {}", dev_id, offset, size); - let (wid, mut upload_queue, zero_chunk_digest, device_size) = { + let (wid, mut upload_queue, zero_chunk_digest) = { let mut guard = registry.lock().unwrap(); let info = guard.lookup(dev_id)?; - (info.wid, info.upload_queue.clone(), info.zero_chunk_digest, info.device_size) + (info.wid, info.upload_queue.clone(), info.zero_chunk_digest) }; - // Note: last chunk may be smaller than chunk_size - if size > chunk_size { - bail!("write_data: got unexpected chunk size {}", size); - } - - if offset & (chunk_size - 1) != 0 { - bail!("write_data: offset {} is not correctly aligned", offset); - } - - let end_offset = offset + chunk_size; - if end_offset > device_size { - bail!("write_data: write out of range"); - } else if end_offset < device_size && size != chunk_size { - bail!("write_data: chunk too small {}", size); - } - let upload_future: Box> + Send + Unpin> = { if data.0.is_null() { if size != chunk_size {