mirror of
https://git.proxmox.com/git/proxmox-backup-qemu
synced 2025-10-05 00:04:28 +00:00
cleanup: allways call _async functions instead of duplicating code
This commit is contained in:
parent
3fb097d5f4
commit
d43e9a0f67
76
src/lib.rs
76
src/lib.rs
@ -332,20 +332,19 @@ pub extern "C" fn proxmox_backup_register_image(
|
|||||||
incremental: bool,
|
incremental: bool,
|
||||||
error: * mut * mut c_char,
|
error: * mut * mut c_char,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
let task = backup_handle_to_task(handle);
|
|
||||||
|
|
||||||
let mut result: c_int = -1;
|
let mut result: c_int = -1;
|
||||||
|
|
||||||
let mut got_result_condition = GotResultCondition::new();
|
let mut got_result_condition = GotResultCondition::new();
|
||||||
|
|
||||||
let callback_info = got_result_condition.callback_info(&mut result, error);
|
let callback_info = got_result_condition.callback_info(&mut result, error);
|
||||||
|
|
||||||
let device_name = unsafe { tools::utf8_c_string_lossy_non_null(device_name) };
|
proxmox_backup_register_image_async(
|
||||||
|
handle, device_name, size, incremental,
|
||||||
task.runtime().spawn(async move {
|
callback_info.callback,
|
||||||
let result = task.register_image(device_name, size, incremental).await;
|
callback_info.callback_data,
|
||||||
callback_info.send_result(result);
|
callback_info.result,
|
||||||
});
|
callback_info.error,
|
||||||
|
);
|
||||||
|
|
||||||
got_result_condition.wait();
|
got_result_condition.wait();
|
||||||
|
|
||||||
@ -389,22 +388,19 @@ pub extern "C" fn proxmox_backup_add_config(
|
|||||||
size: u64,
|
size: u64,
|
||||||
error: * mut * mut c_char,
|
error: * mut * mut c_char,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
let task = backup_handle_to_task(handle);
|
|
||||||
|
|
||||||
let mut result: c_int = -1;
|
let mut result: c_int = -1;
|
||||||
|
|
||||||
let mut got_result_condition = GotResultCondition::new();
|
let mut got_result_condition = GotResultCondition::new();
|
||||||
|
|
||||||
let callback_info = got_result_condition.callback_info(&mut result, error);
|
let callback_info = got_result_condition.callback_info(&mut result, error);
|
||||||
|
|
||||||
let name = unsafe { tools::utf8_c_string_lossy_non_null(name) };
|
proxmox_backup_add_config_async(
|
||||||
|
handle, name, data, size,
|
||||||
let data: Vec<u8> = unsafe { std::slice::from_raw_parts(data, size as usize).to_vec() };
|
callback_info.callback,
|
||||||
|
callback_info.callback_data,
|
||||||
task.runtime().spawn(async move {
|
callback_info.result,
|
||||||
let result = task.add_config(name, data).await;
|
callback_info.error,
|
||||||
callback_info.send_result(result);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
got_result_condition.wait();
|
got_result_condition.wait();
|
||||||
|
|
||||||
@ -460,19 +456,19 @@ pub extern "C" fn proxmox_backup_write_data(
|
|||||||
size: u64,
|
size: u64,
|
||||||
error: * mut * mut c_char,
|
error: * mut * mut c_char,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
let task = backup_handle_to_task(handle);
|
|
||||||
|
|
||||||
let mut result: c_int = -1;
|
let mut result: c_int = -1;
|
||||||
|
|
||||||
let mut got_result_condition = GotResultCondition::new();
|
let mut got_result_condition = GotResultCondition::new();
|
||||||
|
|
||||||
let callback_info = got_result_condition.callback_info(&mut result, error);
|
let callback_info = got_result_condition.callback_info(&mut result, error);
|
||||||
let data = DataPointer(data);
|
|
||||||
|
|
||||||
task.runtime().spawn(async move {
|
proxmox_backup_write_data_async(
|
||||||
let result = task.write_data(dev_id, data, offset, size).await;
|
handle, dev_id, data, offset, size,
|
||||||
callback_info.send_result(result);
|
callback_info.callback,
|
||||||
});
|
callback_info.callback_data,
|
||||||
|
callback_info.result,
|
||||||
|
callback_info.error,
|
||||||
|
);
|
||||||
|
|
||||||
got_result_condition.wait();
|
got_result_condition.wait();
|
||||||
|
|
||||||
@ -524,18 +520,19 @@ pub extern "C" fn proxmox_backup_close_image(
|
|||||||
dev_id: u8,
|
dev_id: u8,
|
||||||
error: * mut * mut c_char,
|
error: * mut * mut c_char,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
let task = backup_handle_to_task(handle);
|
|
||||||
|
|
||||||
let mut result: c_int = -1;
|
let mut result: c_int = -1;
|
||||||
|
|
||||||
let mut got_result_condition = GotResultCondition::new();
|
let mut got_result_condition = GotResultCondition::new();
|
||||||
|
|
||||||
let callback_info = got_result_condition.callback_info(&mut result, error);
|
let callback_info = got_result_condition.callback_info(&mut result, error);
|
||||||
|
|
||||||
task.runtime().spawn(async move {
|
proxmox_backup_close_image_async(
|
||||||
let result = task.close_image(dev_id).await;
|
handle, dev_id,
|
||||||
callback_info.send_result(result);
|
callback_info.callback,
|
||||||
});
|
callback_info.callback_data,
|
||||||
|
callback_info.result,
|
||||||
|
callback_info.error,
|
||||||
|
);
|
||||||
|
|
||||||
got_result_condition.wait();
|
got_result_condition.wait();
|
||||||
|
|
||||||
@ -571,19 +568,19 @@ pub extern "C" fn proxmox_backup_finish(
|
|||||||
handle: *mut ProxmoxBackupHandle,
|
handle: *mut ProxmoxBackupHandle,
|
||||||
error: * mut * mut c_char,
|
error: * mut * mut c_char,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
let task = unsafe { & *(handle as * const Arc<BackupTask>) };
|
|
||||||
|
|
||||||
let mut result: c_int = -1;
|
let mut result: c_int = -1;
|
||||||
|
|
||||||
let mut got_result_condition = GotResultCondition::new();
|
let mut got_result_condition = GotResultCondition::new();
|
||||||
|
|
||||||
let callback_info = got_result_condition.callback_info(&mut result, error);
|
let callback_info = got_result_condition.callback_info(&mut result, error);
|
||||||
|
|
||||||
let task2 = task.clone();
|
proxmox_backup_finish_async(
|
||||||
task.runtime().spawn(async move {
|
handle,
|
||||||
let result = task2.finish().await;
|
callback_info.callback,
|
||||||
callback_info.send_result(result);
|
callback_info.callback_data,
|
||||||
});
|
callback_info.result,
|
||||||
|
callback_info.error,
|
||||||
|
);
|
||||||
|
|
||||||
got_result_condition.wait();
|
got_result_condition.wait();
|
||||||
|
|
||||||
@ -605,10 +602,9 @@ pub extern "C" fn proxmox_backup_finish_async(
|
|||||||
) {
|
) {
|
||||||
let task = unsafe { & *(handle as * const Arc<BackupTask>) };
|
let task = unsafe { & *(handle as * const Arc<BackupTask>) };
|
||||||
let callback_info = CallbackPointers { callback, callback_data, error, result };
|
let callback_info = CallbackPointers { callback, callback_data, error, result };
|
||||||
let task2 = task.clone();
|
|
||||||
|
|
||||||
task.runtime().spawn(async move {
|
task.runtime().spawn(async move {
|
||||||
let result = task2.finish().await;
|
let result = task.finish().await;
|
||||||
callback_info.send_result(result);
|
callback_info.send_result(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user