You need to sign in or sign up before continuing.
提交 8d6e3edd 编写于 作者: J Jiri Denemark

Introduce virConnectSetKeepAlive

virConnectSetKeepAlive public API can be used by a client connecting to
remote server to start using keepalive protocol. The API is handled
directly by remote driver and not transmitted over the wire to the
server.
上级 71b779a1
...@@ -3387,6 +3387,10 @@ typedef struct _virTypedParameter virMemoryParameter; ...@@ -3387,6 +3387,10 @@ typedef struct _virTypedParameter virMemoryParameter;
*/ */
typedef virMemoryParameter *virMemoryParameterPtr; typedef virMemoryParameter *virMemoryParameterPtr;
int virConnectSetKeepAlive(virConnectPtr conn,
int interval,
unsigned int count);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -740,6 +740,10 @@ typedef int ...@@ -740,6 +740,10 @@ typedef int
(*virDrvDomainBlockPull)(virDomainPtr dom, const char *path, (*virDrvDomainBlockPull)(virDomainPtr dom, const char *path,
unsigned long bandwidth, unsigned int flags); unsigned long bandwidth, unsigned int flags);
typedef int
(*virDrvSetKeepAlive)(virConnectPtr conn,
int interval,
unsigned int count);
/** /**
* _virDriver: * _virDriver:
...@@ -899,6 +903,7 @@ struct _virDriver { ...@@ -899,6 +903,7 @@ struct _virDriver {
virDrvDomainGetBlockJobInfo domainGetBlockJobInfo; virDrvDomainGetBlockJobInfo domainGetBlockJobInfo;
virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed; virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed;
virDrvDomainBlockPull domainBlockPull; virDrvDomainBlockPull domainBlockPull;
virDrvSetKeepAlive setKeepAlive;
}; };
typedef int typedef int
......
...@@ -17188,3 +17188,61 @@ error: ...@@ -17188,3 +17188,61 @@ error:
virDispatchError(dom->conn); virDispatchError(dom->conn);
return -1; return -1;
} }
/**
* virConnectSetKeepAlive:
* @conn: pointer to a hypervisor connection
* @interval: number of seconds of inactivity before a keepalive message is sent
* @count: number of messages that can be sent in a row
*
* Start sending keepalive messages after interval second of inactivity and
* consider the connection to be broken when no response is received after
* count keepalive messages sent in a row. In other words, sending count + 1
* keepalive message results in closing the connection. When interval is <= 0,
* no keepalive messages will be sent. When count is 0, the connection will be
* automatically closed after interval seconds of inactivity without sending
* any keepalive messages.
*
* Note: client has to implement and run event loop to be able to use keepalive
* messages. Failure to do so may result in connections being closed
* unexpectedly.
*
* Returns -1 on error, 0 on success, 1 when remote party doesn't support
* keepalive messages.
*/
int virConnectSetKeepAlive(virConnectPtr conn,
int interval,
unsigned int count)
{
int ret = -1;
VIR_DEBUG("conn=%p, interval=%d, count=%u", conn, interval, count);
virResetLastError();
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (interval <= 0) {
virLibConnError(VIR_ERR_INVALID_ARG,
_("negative or zero interval make no sense"));
goto error;
}
if (conn->driver->setKeepAlive) {
ret = conn->driver->setKeepAlive(conn, interval, count);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
virDispatchError(conn);
return -1;
}
...@@ -39,8 +39,8 @@ int virStateActive(void); ...@@ -39,8 +39,8 @@ int virStateActive(void);
* *
* The remote driver passes features through to the real driver at the * The remote driver passes features through to the real driver at the
* remote end unmodified, except if you query a VIR_DRV_FEATURE_REMOTE* * remote end unmodified, except if you query a VIR_DRV_FEATURE_REMOTE*
* feature. * feature. Queries for VIR_DRV_FEATURE_PROGRAM* features are answered
* * directly by the RPC layer and not by the real driver.
*/ */
enum { enum {
/* Driver supports V1-style virDomainMigrate, ie. domainMigratePrepare/ /* Driver supports V1-style virDomainMigrate, ie. domainMigratePrepare/
...@@ -89,6 +89,12 @@ enum { ...@@ -89,6 +89,12 @@ enum {
* Support for VIR_TYPED_PARAM_STRING * Support for VIR_TYPED_PARAM_STRING
*/ */
VIR_DRV_FEATURE_TYPED_PARAM_STRING = 9, VIR_DRV_FEATURE_TYPED_PARAM_STRING = 9,
/*
* Remote party supports keepalive program (i.e., sending keepalive
* messages).
*/
VIR_DRV_FEATURE_PROGRAM_KEEPALIVE = 10,
}; };
......
...@@ -498,4 +498,9 @@ LIBVIRT_0.9.7 { ...@@ -498,4 +498,9 @@ LIBVIRT_0.9.7 {
virDomainSnapshotNumChildren; virDomainSnapshotNumChildren;
} LIBVIRT_0.9.5; } LIBVIRT_0.9.5;
LIBVIRT_0.9.8 {
global:
virConnectSetKeepAlive;
} LIBVIRT_0.9.7;
# .... define new API here using predicted next version number .... # .... define new API here using predicted next version number ....
...@@ -193,9 +193,9 @@ void virEventRegisterImpl(virEventAddHandleFunc addHandle, ...@@ -193,9 +193,9 @@ void virEventRegisterImpl(virEventAddHandleFunc addHandle,
* not have a need to integrate with an external event * not have a need to integrate with an external event
* loop impl. * loop impl.
* *
* Once registered, the application can invoke * Once registered, the application has to invoke virEventRunDefaultImpl in
* virEventRunDefaultImpl in a loop to process * a loop to process events. Failure to do so may result in connections being
* events * closed unexpectedly as a result of keepalive timeout.
* *
* Returns 0 on success, -1 on failure. * Returns 0 on success, -1 on failure.
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册