write_data: return 0 for reused chunks

This commit is contained in:
Dietmar Maurer 2020-07-02 10:34:10 +02:00
parent 0e78f924a9
commit 3b024418cc
3 changed files with 29 additions and 3 deletions

View File

@ -199,7 +199,13 @@ void proxmox_backup_register_image_async(ProxmoxBackupHandle *handle,
*
* Upload a chunk of data for the <dev_id> image.
*
* data may be NULL in order to write the zero chunk (only allowed if size == chunk_size)
* The data pointer may be NULL in order to write the zero chunk
* (only allowed if size == chunk_size)
*
* Returns:
* -1: on error
* 0: successful, chunk already exists on server, so it was resued
* size: successful, chunk uploaded
*/
int proxmox_backup_write_data(ProxmoxBackupHandle *handle,
uint8_t dev_id,
@ -218,6 +224,11 @@ int proxmox_backup_write_data(ProxmoxBackupHandle *handle,
*
* Note: The data pointer needs to be valid until the async
* opteration is finished.
*
* Returns:
* -1: on error
* 0: successful, chunk already exists on server, so it was resued
* size: successful, chunk uploaded
*/
void proxmox_backup_write_data_async(ProxmoxBackupHandle *handle,
uint8_t dev_id,

View File

@ -274,12 +274,15 @@ pub(crate) async fn write_data(
(info.wid, info.upload_queue.clone(), info.zero_chunk_digest)
};
let mut reused = false;
let upload_future: Box<dyn Future<Output = Result<ChunkUploadInfo, Error>> + Send + Unpin> = {
if data.0.is_null() {
if size != chunk_size {
bail!("write_data: got invalid null chunk");
}
let upload_info = ChunkUploadInfo { digest: zero_chunk_digest, offset, size, chunk_is_known: true };
reused = true;
Box::new(futures::future::ok(upload_info))
} else {
let data: &[u8] = unsafe { std::slice::from_raw_parts(data.0, size as usize) };
@ -299,6 +302,7 @@ pub(crate) async fn write_data(
if chunk_is_known {
let upload_info = ChunkUploadInfo { digest: *digest, offset, size, chunk_is_known: true };
reused = true;
Box::new(futures::future::ok(upload_info))
} else {
let (chunk, digest) = chunk_builder.build()?;
@ -363,7 +367,7 @@ pub(crate) async fn write_data(
//println!("upload chunk sucessful");
Ok(size as c_int)
Ok(if reused { 0 } else { size as c_int })
}
pub(crate) async fn finish_backup(

View File

@ -387,7 +387,13 @@ pub extern "C" fn proxmox_backup_add_config_async(
///
/// Upload a chunk of data for the <dev_id> image.
///
/// data may be NULL in order to write the zero chunk (only allowed if size == chunk_size)
/// The data pointer may be NULL in order to write the zero chunk
/// (only allowed if size == chunk_size)
///
/// Returns:
/// -1: on error
/// 0: successful, chunk already exists on server, so it was resued
/// size: successful, chunk uploaded
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn proxmox_backup_write_data(
@ -426,6 +432,11 @@ pub extern "C" fn proxmox_backup_write_data(
///
/// Note: The data pointer needs to be valid until the async
/// opteration is finished.
///
/// Returns:
/// -1: on error
/// 0: successful, chunk already exists on server, so it was resued
/// size: successful, chunk uploaded
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn proxmox_backup_write_data_async(