This API can be used to terminate long running jobs on a volume like its building, resizing, wiping. Moreover, like virDomainAbortJob() calling this API will block until job has either completed or aborted. --- include/libvirt/libvirt.h.in | 3 ++ src/driver.h | 5 ++++ src/libvirt.c | 49 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 8 ++++++- src/remote_protocol-structs | 5 ++++ 7 files changed, 71 insertions(+), 1 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 7d41642..77ec3f0 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -2513,6 +2513,9 @@ int virStorageVolResize (virStorageVolPtr vol, unsigned long long capacity, unsigned int flags); +int virStorageVolAbortJob (virStorageVolPtr vol, + unsigned int flags); + /** * virKeycodeSet: diff --git a/src/driver.h b/src/driver.h index 03d249b..7845b06 100644 --- a/src/driver.h +++ b/src/driver.h @@ -1314,6 +1314,10 @@ typedef int unsigned int flags); typedef int + (*virDrvStorageVolAbortJob) (virStorageVolPtr vol, + unsigned int flags); + +typedef int (*virDrvStoragePoolIsActive)(virStoragePoolPtr pool); typedef int (*virDrvStoragePoolIsPersistent)(virStoragePoolPtr pool); @@ -1377,6 +1381,7 @@ struct _virStorageDriver { virDrvStorageVolResize volResize; virDrvStoragePoolIsActive poolIsActive; virDrvStoragePoolIsPersistent poolIsPersistent; + virDrvStorageVolAbortJob volAbortJob; }; # ifdef WITH_LIBVIRTD diff --git a/src/libvirt.c b/src/libvirt.c index e916aa0..8ce3234 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -13343,6 +13343,55 @@ error: } /** + * virStorageVolAbortJob: + * @vol: pointer to storage volume + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Requests that the current background job be aborted at the soonest + * opportunity. This will block until the job has either completed, + * or aborted. + * + * Returns: 0 in case of success + * -1 otherwise + */ +int +virStorageVolAbortJob(virStorageVolPtr vol, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("vol=%p flags=%x", vol, flags); + + virResetLastError(); + + if (!VIR_IS_STORAGE_VOL(vol)) { + virLibStorageVolError(VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + conn = vol->conn; + + if (conn->flags & VIR_CONNECT_RO) { + virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (conn->storageDriver && conn->storageDriver->volAbortJob) { + int ret; + ret = conn->storageDriver->volAbortJob(vol, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(vol->conn); + return -1; +} + +/** * virNodeNumOfDevices: * @conn: pointer to the hypervisor connection * @cap: capability name diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 46c13fb..cd3e2a6 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -532,6 +532,7 @@ LIBVIRT_0.9.10 { LIBVIRT_0.9.11 { global: virDomainPMWakeup; + virStorageVolAbortJob; } LIBVIRT_0.9.10; # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 031167a..3534ac0 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5013,6 +5013,7 @@ static virStorageDriver storage_driver = { .volResize = remoteStorageVolResize, /* 0.9.10 */ .poolIsActive = remoteStoragePoolIsActive, /* 0.7.3 */ .poolIsPersistent = remoteStoragePoolIsPersistent, /* 0.7.3 */ + .volAbortJob = remoteStorageVolAbortJob, /* 0.9.11 */ }; static virSecretDriver secret_driver = { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 4d845e7..014eade 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1754,6 +1754,11 @@ struct remote_storage_vol_resize_args { unsigned int flags; }; +struct remote_storage_vol_abort_job_args { + remote_nonnull_storage_vol vol; + unsigned int flags; +}; + /* Node driver calls: */ struct remote_node_num_of_devices_args { @@ -2765,7 +2770,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_METADATA = 264, /* autogen autogen */ REMOTE_PROC_DOMAIN_GET_METADATA = 265, /* autogen autogen */ REMOTE_PROC_DOMAIN_BLOCK_REBASE = 266, /* autogen autogen */ - REMOTE_PROC_DOMAIN_PM_WAKEUP = 267 /* autogen autogen */ + REMOTE_PROC_DOMAIN_PM_WAKEUP = 267, /* autogen autogen */ + REMOTE_PROC_STORAGE_VOL_ABORT_JOB = 268 /* autogen autogen */ /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 8f882b7..c80d5f0 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1317,6 +1317,10 @@ struct remote_storage_vol_resize_args { uint64_t capacity; u_int flags; }; +struct remote_storage_vol_abort_job_args { + remote_nonnull_storage_vol vol; + u_int flags; +}; struct remote_node_num_of_devices_args { remote_string cap; u_int flags; @@ -2178,4 +2182,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_METADATA = 265, REMOTE_PROC_DOMAIN_BLOCK_REBASE = 266, REMOTE_PROC_DOMAIN_PM_WAKEUP = 267, + REMOTE_PROC_STORAGE_VOL_ABORT_JOB = 268, }; -- 1.7.8.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list