-
Notifications
You must be signed in to change notification settings - Fork 5
/
current-api.h
447 lines (404 loc) · 15.7 KB
/
current-api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*
* A Proxmox Backup Server C interface, intended for use inside Qemu
*
* Copyright (C) 2019 Proxmox Server Solutions GmbH
*
* Authors:
* Dietmar Maurer ([email protected])
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
*
*
* NOTE: Async Commands
*
* Most commands are asynchronous (marked as _async). They run in a
* separate thread and have the following parameters:
*
* callback: extern "C" fn(*mut c_void),
* callback_data: *mut c_void,
* result: *mut c_int,
* error: *mut *mut c_char,
*
* The callback function is called when the async function is ready.
* Possible errors are returned in 'error'.
*/
#ifndef PROXMOX_BACKUP_QEMU_H
#define PROXMOX_BACKUP_QEMU_H
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE ((1024 * 1024) * 4)
/**
* Opaque handle for backups jobs
*/
typedef struct ProxmoxBackupHandle {
} ProxmoxBackupHandle;
/**
* Opaque handle for restore jobs
*/
typedef struct ProxmoxRestoreHandle {
} ProxmoxRestoreHandle;
/**
* Return a read-only pointer to a string containing the version of the library.
*/
const char *proxmox_backup_qemu_version(void);
/**
* Free returned error messages
*
* All calls can return error messages, but they are allocated using
* the rust standard library. This call moves ownership back to rust
* and free the allocated memory.
*/
void proxmox_backup_free_error(char *ptr);
/**
* Returns the text presentation (relative path) for a backup snapshot
*
* The returned value is allocated with strdup(), and can be freed
* with free().
*/
const char *proxmox_backup_snapshot_string(const char *backup_type,
const char *backup_id,
int64_t backup_time,
char **error);
/**
* DEPRECATED: Create a new instance in the root namespace.
*
* Uses `PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE` if `chunk_size` is zero.
*
* Deprecated in favor of `proxmox_backup_new_ns` which includes a namespace parameter.
*/
struct ProxmoxBackupHandle *proxmox_backup_new(const char *repo,
const char *backup_id,
uint64_t backup_time,
uint64_t chunk_size,
const char *password,
const char *keyfile,
const char *key_password,
const char *master_keyfile,
bool compress,
bool encrypt,
const char *fingerprint,
char **error);
/**
* Create a new instance.
*
* `backup_ns` may be NULL and defaults to the root namespace.
*
* Uses `PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE` if `chunk_size` is zero.
*/
struct ProxmoxBackupHandle *proxmox_backup_new_ns(const char *repo,
const char *backup_ns,
const char *backup_id,
uint64_t backup_time,
uint64_t chunk_size,
const char *password,
const char *keyfile,
const char *key_password,
const char *master_keyfile,
bool compress,
bool encrypt,
const char *fingerprint,
char **error);
/**
* Open connection to the backup server (sync)
*
* Returns:
* 0 ... Success (no previous backup)
* 1 ... Success (found previous backup)
* -1 ... Error
*/
int proxmox_backup_connect(struct ProxmoxBackupHandle *handle, char **error);
/**
* Open connection to the backup server
*
* Returns:
* 0 ... Success (no previous backup)
* 1 ... Success (found previous backup)
* -1 ... Error
*/
void proxmox_backup_connect_async(struct ProxmoxBackupHandle *handle,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Abort a running backup task
*
* This stops the current backup task. It is still necessary to call
* proxmox_backup_disconnect() to close the connection and free
* allocated memory.
*/
void proxmox_backup_abort(struct ProxmoxBackupHandle *handle, const char *reason);
/**
* Check if we can do incremental backups.
*
* This method compares the csum from last backup manifest with the
* checksum stored locally.
*/
int proxmox_backup_check_incremental(struct ProxmoxBackupHandle *handle,
const char *device_name,
uint64_t size);
/**
* Register a backup image (sync)
*/
int proxmox_backup_register_image(struct ProxmoxBackupHandle *handle,
const char *device_name,
uint64_t size,
bool incremental,
char **error);
/**
* Register a backup image
*
* Create a new image archive on the backup server
* ('<device_name>.img.fidx'). The returned integer is the dev_id
* parameter for the proxmox_backup_write_data_async() method.
*/
void proxmox_backup_register_image_async(struct ProxmoxBackupHandle *handle,
const char *device_name,
uint64_t size,
bool incremental,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Add a configuration blob to the backup (sync)
*/
int proxmox_backup_add_config(struct ProxmoxBackupHandle *handle,
const char *name,
const uint8_t *data,
uint64_t size,
char **error);
/**
* Add a configuration blob to the backup
*
* Create and upload a data blob "<name>.blob".
*/
void proxmox_backup_add_config_async(struct ProxmoxBackupHandle *handle,
const char *name,
const uint8_t *data,
uint64_t size,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Write data to into a registered image (sync)
*
* Upload a chunk of data for the <dev_id> image.
*
* 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 reused
* size: successful, chunk uploaded
*/
int proxmox_backup_write_data(struct ProxmoxBackupHandle *handle,
uint8_t dev_id,
const uint8_t *data,
uint64_t offset,
uint64_t size,
char **error);
/**
* Write data to into a registered image
*
* Upload a chunk of data for the <dev_id> image.
*
* The data pointer may be NULL in order to write the zero chunk
* (only allowed if size == chunk_size)
*
* Note: The data pointer needs to be valid until the async
* operation is finished.
*
* Returns:
* -1: on error
* 0: successful, chunk already exists on server, so it was reused
* size: successful, chunk uploaded
*/
void proxmox_backup_write_data_async(struct ProxmoxBackupHandle *handle,
uint8_t dev_id,
const uint8_t *data,
uint64_t offset,
uint64_t size,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Close a registered image (sync)
*/
int proxmox_backup_close_image(struct ProxmoxBackupHandle *handle, uint8_t dev_id, char **error);
/**
* Close a registered image
*
* Mark the image as closed. Further writes are not possible.
*/
void proxmox_backup_close_image_async(struct ProxmoxBackupHandle *handle,
uint8_t dev_id,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Finish the backup (sync)
*/
int proxmox_backup_finish(struct ProxmoxBackupHandle *handle, char **error);
/**
* Finish the backup
*
* Finish the backup by creating and uploading the backup manifest.
* All registered images have to be closed before calling this.
*/
void proxmox_backup_finish_async(struct ProxmoxBackupHandle *handle,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Disconnect and free allocated memory
*
* The handle becomes invalid after this call.
*/
void proxmox_backup_disconnect(struct ProxmoxBackupHandle *handle);
/**
* DEPRECATED: Connect to the backup server for restore (sync)
*
* Deprecated in favor of `proxmox_restore_new_ns` which includes a namespace parameter.
* Also, it used "lossy" utf8 decoding on the snapshot name which is not the case in the new
* version anymore.
*/
struct ProxmoxRestoreHandle *proxmox_restore_new(const char *repo,
const char *snapshot,
const char *password,
const char *keyfile,
const char *key_password,
const char *fingerprint,
char **error);
/**
* Connect to the backup server for restore (sync)
*/
struct ProxmoxRestoreHandle *proxmox_restore_new_ns(const char *repo,
const char *snapshot,
const char *namespace_,
const char *password,
const char *keyfile,
const char *key_password,
const char *fingerprint,
char **error);
/**
* Open connection to the backup server (sync)
*
* Returns:
* 0 ... Success (no previous backup)
* -1 ... Error
*/
int proxmox_restore_connect(struct ProxmoxRestoreHandle *handle, char **error);
/**
* Open connection to the backup server (async)
*
* Returns:
* 0 ... Success (no previous backup)
* -1 ... Error
*/
void proxmox_restore_connect_async(struct ProxmoxRestoreHandle *handle,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Disconnect and free allocated memory
*
* The handle becomes invalid after this call.
*/
void proxmox_restore_disconnect(struct ProxmoxRestoreHandle *handle);
/**
* Restore an image (sync)
*
* Image data is downloaded and sequentially dumped to the callback.
*/
int proxmox_restore_image(struct ProxmoxRestoreHandle *handle,
const char *archive_name,
int (*callback)(void*, uint64_t, const unsigned char*, uint64_t),
void *callback_data,
char **error,
bool verbose);
/**
* Retrieve the ID of a handle used to access data in the given archive (sync)
*/
int proxmox_restore_open_image(struct ProxmoxRestoreHandle *handle,
const char *archive_name,
char **error);
/**
* Retrieve the ID of a handle used to access data in the given archive (async)
*/
void proxmox_restore_open_image_async(struct ProxmoxRestoreHandle *handle,
const char *archive_name,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Retrieve the length of a given archive handle in bytes
*/
long proxmox_restore_get_image_length(struct ProxmoxRestoreHandle *handle,
uint8_t aid,
char **error);
/**
* Read data from the backup image at the given offset (sync)
*
* Reads up to size bytes from handle aid at offset. On success,
* returns the number of bytes read. (a return of zero indicates end
* of file).
*
* Note: It is not an error for a successful call to transfer fewer
* bytes than requested.
*/
int proxmox_restore_read_image_at(struct ProxmoxRestoreHandle *handle,
uint8_t aid,
uint8_t *data,
uint64_t offset,
uint64_t size,
char **error);
/**
* Read data from the backup image at the given offset (async)
*
* Reads up to size bytes from handle aid at offset. On success,
* returns the number of bytes read. (a return of zero indicates end
* of file).
*
* Note: The data pointer needs to be valid until the async
* operation is finished.
*
* Note: The call will only ever transfer less than 'size' bytes if
* the end of the file has been reached.
*/
void proxmox_restore_read_image_at_async(struct ProxmoxRestoreHandle *handle,
uint8_t aid,
uint8_t *data,
uint64_t offset,
uint64_t size,
void (*callback)(void*),
void *callback_data,
int *result,
char **error);
/**
* Serialize all state data into a byte buffer. Can be loaded again with
* proxmox_import_state. Use for migration for example.
*
* Length of the returned buffer is written to buf_size. Returned buffer must
* be freed with proxmox_free_state_buf.
*/
uint8_t *proxmox_export_state(uintptr_t *buf_size);
/**
* Load state serialized by proxmox_export_state. If loading fails, a message
* will be logged to stderr, but the function will not fail.
*/
void proxmox_import_state(const uint8_t *buf, uintptr_t buf_size);
/**
* Free a buffer acquired from proxmox_export_state.
*/
void proxmox_free_state_buf(uint8_t *buf);
#endif /* PROXMOX_BACKUP_QEMU_H */