Deleted Added
sdiff udiff text old ( 230092 ) new ( 246922 )
full compact
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sbin/hastd/secondary.c 230092 2012-01-13 23:25:35Z pjd $");
33
34#include <sys/param.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/stat.h>
39
40#include <err.h>

--- 25 unchanged lines hidden (view full) ---

66
67struct hio {
68 uint64_t hio_seq;
69 int hio_error;
70 void *hio_data;
71 uint8_t hio_cmd;
72 uint64_t hio_offset;
73 uint64_t hio_length;
74 TAILQ_ENTRY(hio) hio_next;
75};
76
77static struct hast_resource *gres;
78
79/*
80 * Free list holds unused structures. When free list is empty, we have to wait
81 * until some in-progress requests are freed.

--- 48 unchanged lines hidden (view full) ---

130hio_clear(struct hio *hio)
131{
132
133 hio->hio_seq = 0;
134 hio->hio_error = 0;
135 hio->hio_cmd = HIO_UNDEF;
136 hio->hio_offset = 0;
137 hio->hio_length = 0;
138}
139
140static void
141init_environment(void)
142{
143 struct hio *hio;
144 unsigned int ii;
145
146 /*
147 * Initialize lists, their locks and theirs condition variables.
148 */

--- 389 unchanged lines hidden (view full) ---

538 hio->hio_error = EINVAL;
539 goto end;
540 }
541 }
542 switch (hio->hio_cmd) {
543 case HIO_FLUSH:
544 case HIO_KEEPALIVE:
545 break;
546 case HIO_READ:
547 case HIO_WRITE:
548 case HIO_DELETE:
549 hio->hio_offset = nv_get_uint64(nv, "offset");
550 if (nv_error(nv) != 0) {
551 pjdlog_error("Header is missing 'offset' field.");
552 hio->hio_error = EINVAL;
553 goto end;
554 }
555 hio->hio_length = nv_get_uint64(nv, "length");

--- 60 unchanged lines hidden (view full) ---

616
617/*
618 * Thread receives requests from the primary node.
619 */
620static void *
621recv_thread(void *arg)
622{
623 struct hast_resource *res = arg;
624 struct hio *hio;
625 struct nv *nv;
626
627 for (;;) {
628 pjdlog_debug(2, "recv: Taking free request.");
629 QUEUE_TAKE(free, hio);
630 pjdlog_debug(2, "recv: (%p) Got request.", hio);
631 if (hast_proto_recv_hdr(res->hr_remotein, &nv) == -1) {
632 secondary_exit(EX_TEMPFAIL,

--- 37 unchanged lines hidden (view full) ---

670 QUEUE_INSERT(free, hio);
671 continue;
672 } else if (hio->hio_cmd == HIO_WRITE) {
673 if (hast_proto_recv_data(res, res->hr_remotein, nv,
674 hio->hio_data, MAXPHYS) == -1) {
675 secondary_exit(EX_TEMPFAIL,
676 "Unable to receive request data");
677 }
678 }
679 nv_free(nv);
680 pjdlog_debug(2, "recv: (%p) Moving request to the disk queue.",
681 hio);
682 QUEUE_INSERT(disk, hio);
683 }
684 /* NOTREACHED */
685 return (NULL);

--- 127 unchanged lines hidden (view full) ---

813
814 for (;;) {
815 pjdlog_debug(2, "send: Taking request.");
816 QUEUE_TAKE(send, hio);
817 reqlog(LOG_DEBUG, 2, -1, hio, "send: (%p) Got request: ", hio);
818 nvout = nv_alloc();
819 /* Copy sequence number. */
820 nv_add_uint64(nvout, hio->hio_seq, "seq");
821 switch (hio->hio_cmd) {
822 case HIO_READ:
823 if (hio->hio_error == 0) {
824 data = hio->hio_data;
825 length = hio->hio_length;
826 break;
827 }
828 /*

--- 28 unchanged lines hidden ---