FreeBSD/sbin/hastd/control.c
/*
 * Thread handles control requests from the parent.
 */
Thread handles control requests from the parent.
Thread handles control requests from the parent .
void *
ctrl_thread(void *arg)
{
	struct hast_resource *res = arg;
	struct nv *nvin, *nvout;
	uint8_t cmd;
	for (;;) {
		if (hast_proto_recv_hdr(res->hr_ctrl, &nvin) == -1) {
			if (sigexit_received)
				pthread_exit(NULL);
			pjdlog_errno(LOG_ERR,
			    "Unable to receive control message");
			kill(getpid(), SIGTERM);
			pthread_exit(NULL);
		}
		cmd = nv_get_uint8(nvin, "cmd");
		if (cmd == 0) {
			pjdlog_error("Control message is missing 'cmd' field.");
			nv_free(nvin);
			continue;
		}
		nvout = nv_alloc();
		switch (cmd) {
		case CONTROL_STATUS:
			if (res->hr_remotein != NULL &&
			    res->hr_remoteout != NULL) {
				nv_add_string(nvout, "complete", "status");
			} else {
				nv_add_string(nvout, "degraded", "status");
			}
			nv_add_uint32(nvout, (uint32_t)res->hr_extentsize,
			    "extentsize");
			if (res->hr_role == HAST_ROLE_PRIMARY) {
				nv_add_uint32(nvout,
				    (uint32_t)res->hr_keepdirty, "keepdirty");
				nv_add_uint64(nvout,
				    (uint64_t)(activemap_ndirty(res->hr_amp) *
				    res->hr_extentsize), "dirty");
			} else {
				nv_add_uint32(nvout, (uint32_t)0, "keepdirty");
				nv_add_uint64(nvout, (uint64_t)0, "dirty");
			}
			nv_add_uint64(nvout, res->hr_stat_read, "stat_read");
			nv_add_uint64(nvout, res->hr_stat_write, "stat_write");
			nv_add_uint64(nvout, res->hr_stat_delete,
			    "stat_delete");
			nv_add_uint64(nvout, res->hr_stat_flush, "stat_flush");
			nv_add_uint64(nvout, res->hr_stat_activemap_update,
			    "stat_activemap_update");
			nv_add_uint64(nvout, res->hr_stat_read_error,
			    "stat_read_error");
			nv_add_uint64(nvout, res->hr_stat_write_error +
			    res->hr_stat_activemap_write_error,
			    "stat_write_error");
			nv_add_uint64(nvout, res->hr_stat_delete_error,
			    "stat_delete_error");
			nv_add_uint64(nvout, res->hr_stat_flush_error +
			    res->hr_stat_activemap_flush_error,
			    "stat_flush_error");
			res->output_status_aux(nvout);
			nv_add_int16(nvout, 0, "error");
			break;
		case CONTROL_RELOAD:
			PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY);
			primary_config_reload(res, nvin);
			nv_add_int16(nvout, 0, "error");
			break;
		default:
			nv_add_int16(nvout, EINVAL, "error");
			break;
		}
		nv_free(nvin);
		if (nv_error(nvout) != 0) {
			pjdlog_error("Unable to create answer on control message.");
			nv_free(nvout);
			continue;
		}
		if (hast_proto_send(NULL, res->hr_ctrl, nvout, NULL, 0) == -1) {
			pjdlog_errno(LOG_ERR,
			    "Unable to send reply to control message");
		}
		nv_free(nvout);
	}
	return (NULL);
}
void * ctrl_thread ( void * arg ) { struct hast_resource * res = arg ; struct nv * nvin , * nvout ; uint8_t cmd ; for ( ; ; ) { if ( hast_proto_recv_hdr ( res -> hr_ctrl , & nvin ) == -1 ) { if ( sigexit_received ) pthread_exit ( NULL ) ; pjdlog_errno ( LOG_ERR , " " ) ; kill ( getpid ( ) , SIGTERM ) ; pthread_exit ( NULL ) ; } cmd = nv_get_uint8 ( nvin , " " ) ; if ( cmd == 0 ) { pjdlog_error ( " " ) ; nv_free ( nvin ) ; continue ; } nvout = nv_alloc ( ) ; switch ( cmd ) { case CONTROL_STATUS : if ( res -> hr_remotein != NULL && res -> hr_remoteout != NULL ) { nv_add_string ( nvout , " " , " " ) ; } else { nv_add_string ( nvout , " " , " " ) ; } nv_add_uint32 ( nvout , ( uint32_t ) res -> hr_extentsize , " " ) ; if ( res -> hr_role == HAST_ROLE_PRIMARY ) { nv_add_uint32 ( nvout , ( uint32_t ) res -> hr_keepdirty , " " ) ; nv_add_uint64 ( nvout , ( uint64_t ) ( activemap_ndirty ( res -> hr_amp ) * res -> hr_extentsize ) , " " ) ; } else { nv_add_uint32 ( nvout , ( uint32_t ) 0 , " " ) ; nv_add_uint64 ( nvout , ( uint64_t ) 0 , " " ) ; } nv_add_uint64 ( nvout , res -> hr_stat_read , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_write , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_delete , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_flush , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_activemap_update , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_read_error , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_write_error + res -> hr_stat_activemap_write_error , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_delete_error , " " ) ; nv_add_uint64 ( nvout , res -> hr_stat_flush_error + res -> hr_stat_activemap_flush_error , " " ) ; res -> output_status_aux ( nvout ) ; nv_add_int16 ( nvout , 0 , " " ) ; break ; case CONTROL_RELOAD : PJDLOG_ASSERT ( res -> hr_role == HAST_ROLE_PRIMARY ) ; primary_config_reload ( res , nvin ) ; nv_add_int16 ( nvout , 0 , " " ) ; break ; default : nv_add_int16 ( nvout , EINVAL , " " ) ; break ; } nv_free ( nvin ) ; if ( nv_error ( nvout ) != 0 ) { pjdlog_error ( " " ) ; nv_free ( nvout ) ; continue ; } if ( hast_proto_send ( NULL , res -> hr_ctrl , nvout , NULL , 0 ) == -1 ) { pjdlog_errno ( LOG_ERR , " " ) ; } nv_free ( nvout ) ; } return ( NULL ) ; }
Thread handles control requests from the parent.
Thread handles control requests from the parent .
/*
			 * When parent receives SIGHUP and discovers that
			 * something related to us has changes, it sends reload
			 * message to us.
			 */ /* NOTREACHED */