FreeBSD/sbin/hastd/primary.c
/*
 * Thread sends answer to the kernel.
 */
Thread sends answer to the kernel.
Thread sends answer to the kernel .
static void *
ggate_send_thread(void *arg)
{
	struct hast_resource *res = arg;
	struct g_gate_ctl_io *ggio;
	struct hio *hio;
	unsigned int ii, ncomps;
	ncomps = HAST_NCOMPONENTS;
	for (;;) {
		pjdlog_debug(2, "ggate_send: Taking request.");
		QUEUE_TAKE2(hio, done);
		pjdlog_debug(2, "ggate_send: (%p) Got request.", hio);
		ggio = &hio->hio_ggio;
		for (ii = 0; ii < ncomps; ii++) {
			if (hio->hio_errors[ii] == 0) {
				ggio->gctl_error = 0;
				break;
			}
		}
		if (ii == ncomps) {
			if (ggio->gctl_cmd == BIO_READ &&
			    res->hr_syncsrc == HAST_SYNCSRC_SECONDARY)
				ggio->gctl_error = hio->hio_errors[1];
			else
				ggio->gctl_error = hio->hio_errors[0];
		}
		if (ggio->gctl_error == 0 && ggio->gctl_cmd == BIO_WRITE) {
			mtx_lock(&res->hr_amp_lock);
			if (activemap_write_complete(res->hr_amp,
			    ggio->gctl_offset, ggio->gctl_length)) {
				res->hr_stat_activemap_update++;
				(void)hast_activemap_flush(res);
			} else {
				mtx_unlock(&res->hr_amp_lock);
			}
		}
		if (ggio->gctl_cmd == BIO_WRITE) {
			mtx_lock(&range_lock);
			rangelock_del(range_regular, ggio->gctl_offset,
			    ggio->gctl_length);
			if (range_sync_wait)
				cv_signal(&range_sync_cond);
			mtx_unlock(&range_lock);
			if (!hio->hio_done)
				write_complete(res, hio);
		} else {
			if (ioctl(res->hr_ggatefd, G_GATE_CMD_DONE, ggio) == -1) {
				primary_exit(EX_OSERR,
				    "G_GATE_CMD_DONE failed");
			}
		}
		if (hio->hio_errors[0]) {
			switch (ggio->gctl_cmd) {
			case BIO_READ:
				res->hr_stat_read_error++;
				break;
			case BIO_WRITE:
				res->hr_stat_write_error++;
				break;
			case BIO_DELETE:
				res->hr_stat_delete_error++;
				break;
			case BIO_FLUSH:
				res->hr_stat_flush_error++;
				break;
			}
		}
		pjdlog_debug(2,
		    "ggate_send: (%p) Moving request to the free queue.", hio);
		QUEUE_INSERT2(hio, free);
	}
	return (NULL);
}
static void * ggate_send_thread ( void * arg ) { struct hast_resource * res = arg ; struct g_gate_ctl_io * ggio ; struct hio * hio ; unsigned int ii , ncomps ; ncomps = HAST_NCOMPONENTS ; for ( ; ; ) { pjdlog_debug ( 2 , " " ) ; QUEUE_TAKE2 ( hio , done ) ; pjdlog_debug ( 2 , " " , hio ) ; ggio = & hio -> hio_ggio ; for ( ii = 0 ; ii < ncomps ; ii ++ ) { if ( hio -> hio_errors [ ii ] == 0 ) { ggio -> gctl_error = 0 ; break ; } } if ( ii == ncomps ) { if ( ggio -> gctl_cmd == BIO_READ && res -> hr_syncsrc == HAST_SYNCSRC_SECONDARY ) ggio -> gctl_error = hio -> hio_errors [ 1 ] ; else ggio -> gctl_error = hio -> hio_errors [ 0 ] ; } if ( ggio -> gctl_error == 0 && ggio -> gctl_cmd == BIO_WRITE ) { mtx_lock ( & res -> hr_amp_lock ) ; if ( activemap_write_complete ( res -> hr_amp , ggio -> gctl_offset , ggio -> gctl_length ) ) { res -> hr_stat_activemap_update ++ ; ( void ) hast_activemap_flush ( res ) ; } else { mtx_unlock ( & res -> hr_amp_lock ) ; } } if ( ggio -> gctl_cmd == BIO_WRITE ) { mtx_lock ( & range_lock ) ; rangelock_del ( range_regular , ggio -> gctl_offset , ggio -> gctl_length ) ; if ( range_sync_wait ) cv_signal ( & range_sync_cond ) ; mtx_unlock ( & range_lock ) ; if ( ! hio -> hio_done ) write_complete ( res , hio ) ; } else { if ( ioctl ( res -> hr_ggatefd , G_GATE_CMD_DONE , ggio ) == -1 ) { primary_exit ( EX_OSERR , " " ) ; } } if ( hio -> hio_errors [ 0 ] ) { switch ( ggio -> gctl_cmd ) { case BIO_READ : res -> hr_stat_read_error ++ ; break ; case BIO_WRITE : res -> hr_stat_write_error ++ ; break ; case BIO_DELETE : res -> hr_stat_delete_error ++ ; break ; case BIO_FLUSH : res -> hr_stat_flush_error ++ ; break ; } } pjdlog_debug ( 2 , " " , hio ) ; QUEUE_INSERT2 ( hio , free ) ; } return ( NULL ) ; }
Thread sends answer to the kernel.
Thread sends answer to the kernel .
/*
				 * One successful request is enough to declare
				 * success.
				 */ /*
			 * None of the requests were successful.
			 * Use the error from local component except the
			 * case when we did only remote request.
			 */ /*
			 * Unlock range we locked.
			 */ /* NOTREACHED */