Re: [PATCH] IPC: don't block forever on a recv msg as corosync might be gone.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reviewed-by: Steven Dake <sdake@xxxxxxxxxx>

On 01/08/2012 05:47 PM, Angus Salkeld wrote:
> This at least will not make the client hang forever.
> 
> Signed-off-by: Angus Salkeld <asalkeld@xxxxxxxxxx>
> ---
>  include/corosync/corotypes.h |    1 +
>  lib/cfg.c                    |   24 ++++++++++++------------
>  lib/cmap.c                   |   18 +++++++++---------
>  lib/cpg.c                    |    3 ++-
>  lib/evs.c                    |   10 +++++-----
>  lib/pload.c                  |    2 +-
>  lib/quorum.c                 |    6 +++---
>  lib/votequorum.c             |   22 +++++++++++-----------
>  8 files changed, 44 insertions(+), 42 deletions(-)
> 
> diff --git a/include/corosync/corotypes.h b/include/corosync/corotypes.h
> index 7484a94..acae884 100644
> --- a/include/corosync/corotypes.h
> +++ b/include/corosync/corotypes.h
> @@ -106,6 +106,7 @@ typedef enum {
>     CS_ERR_SECURITY = 100
>  } cs_error_t;
>  
> +#define CS_IPC_TIMEOUT_MS 1000
>  
>  #define CS_TIME_MS_IN_SEC   1000ULL
>  #define CS_TIME_US_IN_SEC   1000000ULL
> diff --git a/lib/cfg.c b/lib/cfg.c
> index 1828dfa..23d6768 100644
> --- a/lib/cfg.c
> +++ b/lib/cfg.c
> @@ -286,7 +286,7 @@ corosync_cfg_ring_status_get (
>  		&iov,
>  		1,
>  		&res_lib_cfg_ringstatusget,
> -		sizeof (struct res_lib_cfg_ringstatusget), -1));
> +		sizeof (struct res_lib_cfg_ringstatusget), CS_IPC_TIMEOUT_MS));
>  
>  	*interface_count = res_lib_cfg_ringstatusget.interface_count;
>  	*interface_names = malloc (sizeof (char *) * *interface_count);
> @@ -366,7 +366,7 @@ corosync_cfg_ring_reenable (
>  		&iov,
>  		1,
>  		&res_lib_cfg_ringreenable,
> -		sizeof (struct res_lib_cfg_ringreenable), -1));
> +		sizeof (struct res_lib_cfg_ringreenable), CS_IPC_TIMEOUT_MS));
>  
>  	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
>  
> @@ -405,7 +405,7 @@ corosync_cfg_service_load (
>  		&iov,
>  		1,
>  		&res_lib_cfg_serviceload,
> -		sizeof (struct res_lib_cfg_serviceload), -1));
> +		sizeof (struct res_lib_cfg_serviceload), CS_IPC_TIMEOUT_MS));
>  
>  	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
>  
> @@ -444,7 +444,7 @@ corosync_cfg_service_unload (
>  		&iov,
>  		1,
>  		&res_lib_cfg_serviceunload,
> -		sizeof (struct res_lib_cfg_serviceunload), -1));
> +		sizeof (struct res_lib_cfg_serviceunload), CS_IPC_TIMEOUT_MS));
>  
>  	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
>  
> @@ -480,7 +480,7 @@ corosync_cfg_state_track (
>  		&iov,
>  		1,
>  		&res_lib_cfg_statetrack,
> -		sizeof (struct res_lib_cfg_statetrack), -1));
> +		sizeof (struct res_lib_cfg_statetrack), CS_IPC_TIMEOUT_MS));
>  
>  	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
>  
> @@ -513,7 +513,7 @@ corosync_cfg_state_track_stop (
>  		&iov,
>  		1,
>  		&res_lib_cfg_statetrackstop,
> -		sizeof (struct res_lib_cfg_statetrackstop), -1));
> +		sizeof (struct res_lib_cfg_statetrackstop), CS_IPC_TIMEOUT_MS));
>  
>  	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
>  
> @@ -554,7 +554,7 @@ corosync_cfg_kill_node (
>  		&iov,
>  		1,
>  		&res_lib_cfg_killnode,
> -		sizeof (struct res_lib_cfg_killnode), -1));
> +		sizeof (struct res_lib_cfg_killnode), CS_IPC_TIMEOUT_MS));
>  
>  	error = res_lib_cfg_killnode.header.error;
>  
> @@ -591,7 +591,7 @@ corosync_cfg_try_shutdown (
>  		&iov,
>  		1,
>  		&res_lib_cfg_tryshutdown,
> -		sizeof (struct res_lib_cfg_tryshutdown), -1));
> +		sizeof (struct res_lib_cfg_tryshutdown), CS_IPC_TIMEOUT_MS));
>  
>  	(void)hdb_handle_put (&cfg_hdb, cfg_handle);
>  
> @@ -626,7 +626,7 @@ corosync_cfg_replyto_shutdown (
>  		&iov,
>  		1,
>  		&res_lib_cfg_replytoshutdown,
> -		sizeof (struct res_lib_cfg_replytoshutdown), -1));
> +		sizeof (struct res_lib_cfg_replytoshutdown), CS_IPC_TIMEOUT_MS));
>  
>  	return (error);
>  }
> @@ -664,7 +664,7 @@ cs_error_t corosync_cfg_get_node_addrs (
>  	error = qb_to_cs_error (qb_ipcc_sendv_recv (
>  		cfg_inst->c,
>  		&iov, 1,
> -		response_buf, IPC_RESPONSE_SIZE, -1));
> +		response_buf, IPC_RESPONSE_SIZE, CS_IPC_TIMEOUT_MS));
>  	res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)response_buf;
>  
>  	if (error != CS_OK) {
> @@ -730,7 +730,7 @@ cs_error_t corosync_cfg_local_get (
>  		&iov,
>  		1,
>  		&res_lib_cfg_local_get,
> -		sizeof (struct res_lib_cfg_local_get), -1));
> +		sizeof (struct res_lib_cfg_local_get), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -774,7 +774,7 @@ corosync_cfg_crypto_set (
>  		&iov,
>  		1,
>  		&res_lib_cfg_crypto_set,
> -		sizeof (struct res_lib_cfg_crypto_set), -1));
> +		sizeof (struct res_lib_cfg_crypto_set), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK)
>  		error = res_lib_cfg_crypto_set.header.error;
> diff --git a/lib/cmap.c b/lib/cmap.c
> index 05be657..252bf86 100644
> --- a/lib/cmap.c
> +++ b/lib/cmap.c
> @@ -359,7 +359,7 @@ cs_error_t cmap_set (
>  		iov,
>  		2,
>  		&res_lib_cmap_set,
> -		sizeof (struct res_lib_cmap_set), -1));
> +		sizeof (struct res_lib_cmap_set), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_set.header.error;
> @@ -457,7 +457,7 @@ cs_error_t cmap_delete(cmap_handle_t handle, const char *key_name)
>  		&iov,
>  		1,
>  		&res_lib_cmap_delete,
> -		sizeof (struct res_lib_cmap_delete), -1));
> +		sizeof (struct res_lib_cmap_delete), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_delete.header.error;
> @@ -519,7 +519,7 @@ cs_error_t cmap_get(
>  		&iov,
>  		1,
>  		res_lib_cmap_get,
> -		res_size, -1));
> +		res_size, CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_get->header.error;
> @@ -705,7 +705,7 @@ static cs_error_t cmap_adjust_int(cmap_handle_t handle, const char *key_name, in
>  		&iov,
>  		1,
>  		&res_lib_cmap_adjust_int,
> -		sizeof (struct res_lib_cmap_adjust_int), -1));
> +		sizeof (struct res_lib_cmap_adjust_int), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_adjust_int.header.error;
> @@ -761,7 +761,7 @@ cs_error_t cmap_iter_init(
>  		&iov,
>  		1,
>  		&res_lib_cmap_iter_init,
> -		sizeof (struct res_lib_cmap_iter_init), -1));
> +		sizeof (struct res_lib_cmap_iter_init), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_iter_init.header.error;
> @@ -807,7 +807,7 @@ cs_error_t cmap_iter_next(
>  		&iov,
>  		1,
>  		&res_lib_cmap_iter_next,
> -		sizeof (struct res_lib_cmap_iter_next), -1));
> +		sizeof (struct res_lib_cmap_iter_next), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_iter_next.header.error;
> @@ -858,7 +858,7 @@ cs_error_t cmap_iter_finalize(
>  		&iov,
>  		1,
>  		&res_lib_cmap_iter_finalize,
> -		sizeof (struct res_lib_cmap_iter_finalize), -1));
> +		sizeof (struct res_lib_cmap_iter_finalize), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_iter_finalize.header.error;
> @@ -926,7 +926,7 @@ cs_error_t cmap_track_add(
>  		&iov,
>  		1,
>  		&res_lib_cmap_track_add,
> -		sizeof (struct res_lib_cmap_track_add), -1));
> +		sizeof (struct res_lib_cmap_track_add), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_track_add.header.error;
> @@ -982,7 +982,7 @@ cs_error_t cmap_track_delete(
>  		&iov,
>  		1,
>  		&res_lib_cmap_track_delete,
> -		sizeof (struct res_lib_cmap_track_delete), -1));
> +		sizeof (struct res_lib_cmap_track_delete), CS_IPC_TIMEOUT_MS));
>  
>  	if (error == CS_OK) {
>  		error = res_lib_cmap_track_delete.header.error;
> diff --git a/lib/cpg.c b/lib/cpg.c
> index c7f51f7..e8d8614 100644
> --- a/lib/cpg.c
> +++ b/lib/cpg.c
> @@ -97,7 +97,8 @@ coroipcc_msg_send_reply_receive (
>  	void *res_msg,
>  	size_t res_len)
>  {
> -	return qb_to_cs_error(qb_ipcc_sendv_recv(c, iov, iov_len, res_msg, res_len, -1));
> +	return qb_to_cs_error(qb_ipcc_sendv_recv(c, iov, iov_len, res_msg, res_len,
> +				CS_IPC_TIMEOUT_MS));
>  }
>  
>  static void cpg_iteration_instance_finalize (struct cpg_iteration_instance_t *cpg_iteration_instance)
> diff --git a/lib/evs.c b/lib/evs.c
> index 067ad76..0f9daf1 100644
> --- a/lib/evs.c
> +++ b/lib/evs.c
> @@ -347,7 +347,7 @@ evs_error_t evs_join (
>  	iov[1].iov_len = (group_entries * sizeof (struct evs_group));
>  
>  	error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov, 2,
> -		&res_lib_evs_join, sizeof (struct res_lib_evs_join), -1));
> +		&res_lib_evs_join, sizeof (struct res_lib_evs_join), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -388,7 +388,7 @@ evs_error_t evs_leave (
>  	iov[1].iov_len = (group_entries * sizeof (struct evs_group));
>  
>  	error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov, 2,
> -		&res_lib_evs_leave, sizeof (struct res_lib_evs_leave), -1));
> +		&res_lib_evs_leave, sizeof (struct res_lib_evs_leave), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -439,7 +439,7 @@ evs_error_t evs_mcast_joined (
>  	error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov,
>  		iov_len + 1,
>  		&res_lib_evs_mcast_joined,
> -		sizeof (struct res_lib_evs_mcast_joined), -1));
> +		sizeof (struct res_lib_evs_mcast_joined), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -492,7 +492,7 @@ evs_error_t evs_mcast_groups (
>  	error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov,
>  		iov_len + 2,
>  		&res_lib_evs_mcast_groups,
> -		sizeof (struct res_lib_evs_mcast_groups), -1));
> +		sizeof (struct res_lib_evs_mcast_groups), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -533,7 +533,7 @@ evs_error_t evs_membership_get (
>  		&iov,
>  		1,
>  		&res_lib_evs_membership_get,
> -		sizeof (struct res_lib_evs_membership_get), -1));
> +		sizeof (struct res_lib_evs_membership_get), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> diff --git a/lib/pload.c b/lib/pload.c
> index 8f41e72..e5a6543 100644
> --- a/lib/pload.c
> +++ b/lib/pload.c
> @@ -185,7 +185,7 @@ unsigned int pload_start (
>  		&iov,
>  		1,
>  		&res_lib_pload_start,
> -		sizeof (struct res_lib_pload_start), -1));
> +		sizeof (struct res_lib_pload_start), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> diff --git a/lib/quorum.c b/lib/quorum.c
> index 8fc7ef0..c55f6c6 100644
> --- a/lib/quorum.c
> +++ b/lib/quorum.c
> @@ -160,7 +160,7 @@ cs_error_t quorum_getquorate (
>  		&iov,
>  		1,
>  		&res_lib_quorum_getquorate,
> -		sizeof (struct res_lib_quorum_getquorate), -1));
> +		sizeof (struct res_lib_quorum_getquorate), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -262,7 +262,7 @@ cs_error_t quorum_trackstart (
>                  &iov,
>                  1,
>                  &res,
> -                sizeof (res), -1));
> +                sizeof (res), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -301,7 +301,7 @@ cs_error_t quorum_trackstop (
>                  &iov,
>                  1,
>                  &res,
> -                sizeof (res), -1));
> +                sizeof (res), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> diff --git a/lib/votequorum.c b/lib/votequorum.c
> index 60d91b7..095f7c4 100644
> --- a/lib/votequorum.c
> +++ b/lib/votequorum.c
> @@ -165,7 +165,7 @@ cs_error_t votequorum_getinfo (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_getinfo,
> -		sizeof (struct res_lib_votequorum_getinfo), -1));
> +		sizeof (struct res_lib_votequorum_getinfo), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -215,7 +215,7 @@ cs_error_t votequorum_setexpected (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -258,7 +258,7 @@ cs_error_t votequorum_setvotes (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -305,7 +305,7 @@ cs_error_t votequorum_qdisk_register (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -347,7 +347,7 @@ cs_error_t votequorum_qdisk_poll (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -386,7 +386,7 @@ cs_error_t votequorum_qdisk_unregister (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -429,7 +429,7 @@ cs_error_t votequorum_qdisk_getinfo (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_qdisk_getinfo,
> -		sizeof (struct res_lib_votequorum_qdisk_getinfo), -1));
> +		sizeof (struct res_lib_votequorum_qdisk_getinfo), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -473,7 +473,7 @@ cs_error_t votequorum_setstate (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -513,7 +513,7 @@ cs_error_t votequorum_leaving (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -556,7 +556,7 @@ cs_error_t votequorum_trackstart (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;
> @@ -595,7 +595,7 @@ cs_error_t votequorum_trackstop (
>  		&iov,
>  		1,
>                  &res_lib_votequorum_status,
> -		sizeof (struct res_lib_votequorum_status), -1));
> +		sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
>  
>  	if (error != CS_OK) {
>  		goto error_exit;

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss


[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux