[zz]libvirt - Progress monitoring & cancellation of jobs

本文介绍了一系列新API,允许用户监控并取消长时间运行的任务,适用于virDomainMigrate、virDomainSave等操作。具体实现了QEMU的API,但其他支持的API可以自定义实现。使用这些API需要多线程或多连接,因为主要API调用仍然完全阻塞。通过virsh命令可以查看任务状态,如保存、迁移和核心转储。新API还引入了virDomainAbortJob()方法,用于在另一个线程中终止正在进行的任务。该方法在QEMU中不支持监控传入迁移,因此无法完成virDomainRestore的配置。此外,新的virDomainJobInfo()方法提供了查询状态的功能,包括剩余数据和内存使用情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This series introduces 2 new APIs to allow long running jobs to
be monitored and cancelled. This applies to virDomainMigrate,
virDomainSave, virDomainRestore and virDomainCoreDump at least.
The implementation is provided for QEMU only, any others that
are able to implementation can do so as desired.

Usefulness of these new APIs requires use of multiple threads on
a single connection, or multiple connections, since the main
API calls are still all fully blocking. Instead a parallel thread
or process can monitor. This can be seen with virsh

In termainl 1

 $ virsh save demo demo.img

In terminal 2

 $ ./virsh domjobinfo demo
  Job type:         Unbounded   
  Time elapsed:     795          ms
  Data processed:   22446080     bytes
  Data remaining:   219119616    bytes
  Data total:       241565696    bytes
  Memory processed: 22446080     bytes
  Memory remaining: 219119616    bytes
  Memory total:     241565696    bytes

 $ ./virsh domjobinfo demo
  Job type:         Unbounded   
  Time elapsed:     1669         ms
  Data processed:   139784192    bytes
  Data remaining:   101781504    bytes
  Data total:       241565696    bytes
  Memory processed: 139784192    bytes
  Memory remaining: 101781504    bytes
  Memory total:     241565696    bytes

 $ ./virsh domjobabort demo


Back in terminal 1

  error: Failed to save domain demo to demo.img
  error: operation failed: Migration was cancelled by client
Daniel P. Berrange 2010年02月05日 星期五 01时25分07秒
The new virDomainAbortJob() method provides a way for a second
thread to abort an ongoing job run by another thread. This
extends to any API with  which the virDomainGetJobInfo() API
is intended to work. Cancellation is not guarenteed, rather best
effort on part of the hypervisor and not required to be implmented.

* include/libvirt/libvirt.h.in: Define virDomainAbortJob()
---
 include/libvirt/libvirt.h.in |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 5058bc0..0ffcf11 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1804,6 +1804,8 @@ struct _virDomainJobInfo {
 int virDomainGetJobInfo(virDomainPtr dom,
                         virDomainJobInfoPtr info);+int virDomainAbortJob(virDomainPtr dom);
+
 #ifdef __cplusplus
 }
 #endif
Daniel P. Berrange 2010年02月05日 星期五 01时25分09秒
Introduce support for  virDomainGetJobInfo in the QEMU driver. This
allows for monitoring of any API that uses the 'info migrate' monitor
command. ie virDomainMigrate, virDomainSave and virDomainCoreDump

Unfortunately QEMU does not provide a way to monitor incoming migration
so we can't wire up virDomainRestore yet.

The virsh tool gets a new command 'domjobinfo' to query status
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值