Lines Matching refs:hio

69 struct hio {
77 TAILQ_ENTRY(hio) hio_next;
86 static TAILQ_HEAD(, hio) hio_free_list;
93 static TAILQ_HEAD(, hio) hio_disk_list;
100 static TAILQ_HEAD(, hio) hio_send_list;
114 #define QUEUE_INSERT(name, hio) do { \
118 TAILQ_INSERT_TAIL(&hio_##name##_list, (hio), hio_next); \
122 #define QUEUE_TAKE(name, hio) do { \
124 while (((hio) = TAILQ_FIRST(&hio_##name##_list)) == NULL) { \
130 TAILQ_REMOVE(&hio_##name##_list, (hio), hio_next); \
144 hio_clear(struct hio *hio)
147 hio->hio_seq = 0;
148 hio->hio_error = 0;
149 hio->hio_cmd = HIO_UNDEF;
150 hio->hio_offset = 0;
151 hio->hio_length = 0;
152 hio->hio_memsync = false;
156 hio_copy(const struct hio *srchio, struct hio *dsthio)
173 struct hio *hio;
193 hio = malloc(sizeof(*hio));
194 if (hio == NULL) {
196 "Unable to allocate memory (%zu bytes) for hio request.",
197 sizeof(*hio));
199 hio->hio_data = malloc(MAXPHYS);
200 if (hio->hio_data == NULL) {
205 hio_clear(hio);
206 TAILQ_INSERT_HEAD(&hio_free_list, hio, hio_next);
514 reqlog(int loglevel, int debuglevel, int error, struct hio *hio,
525 switch (hio->hio_cmd) {
528 "READ(%ju, %ju).", (uintmax_t)hio->hio_offset,
529 (uintmax_t)hio->hio_length);
533 "DELETE(%ju, %ju).", (uintmax_t)hio->hio_offset,
534 (uintmax_t)hio->hio_length);
541 "WRITE(%ju, %ju).", (uintmax_t)hio->hio_offset,
542 (uintmax_t)hio->hio_length);
549 "UNKNOWN(%u).", (unsigned int)hio->hio_cmd);
557 requnpack(struct hast_resource *res, struct hio *hio, struct nv *nv)
560 hio->hio_cmd = nv_get_uint8(nv, "cmd");
561 if (hio->hio_cmd == 0) {
563 hio->hio_error = EINVAL;
566 if (hio->hio_cmd != HIO_KEEPALIVE) {
567 hio->hio_seq = nv_get_uint64(nv, "seq");
568 if (hio->hio_seq == 0) {
570 hio->hio_error = EINVAL;
574 switch (hio->hio_cmd) {
579 hio->hio_memsync = nv_exists(nv, "memsync");
583 hio->hio_offset = nv_get_uint64(nv, "offset");
586 hio->hio_error = EINVAL;
589 hio->hio_length = nv_get_uint64(nv, "length");
592 hio->hio_error = EINVAL;
595 if (hio->hio_length == 0) {
597 hio->hio_error = EINVAL;
600 if (hio->hio_cmd != HIO_DELETE && hio->hio_length > MAXPHYS) {
602 (uintmax_t)hio->hio_length, (uintmax_t)MAXPHYS);
603 hio->hio_error = EINVAL;
606 if ((hio->hio_offset % res->hr_local_sectorsize) != 0) {
608 (uintmax_t)hio->hio_offset);
609 hio->hio_error = EINVAL;
612 if ((hio->hio_length % res->hr_local_sectorsize) != 0) {
614 (uintmax_t)hio->hio_length);
615 hio->hio_error = EINVAL;
618 if (hio->hio_offset + hio->hio_length >
621 (uintmax_t)(hio->hio_offset + hio->hio_length),
623 hio->hio_error = EINVAL;
629 hio->hio_cmd);
630 hio->hio_error = EINVAL;
633 hio->hio_error = 0;
635 return (hio->hio_error);
658 struct hio *hio, *mshio;
663 QUEUE_TAKE(free, hio);
664 pjdlog_debug(2, "recv: (%p) Got request.", hio);
669 if (requnpack(res, hio, nv) != 0) {
673 hio);
674 QUEUE_INSERT(send, hio);
677 switch (hio->hio_cmd) {
694 hio->hio_cmd);
696 reqlog(LOG_DEBUG, 2, -1, hio,
697 "recv: (%p) Got request header: ", hio);
698 if (hio->hio_cmd == HIO_KEEPALIVE) {
702 hio);
703 hio_clear(hio);
704 QUEUE_INSERT(free, hio);
706 } else if (hio->hio_cmd == HIO_WRITE) {
708 hio->hio_data, MAXPHYS) == -1) {
712 if (hio->hio_memsync) {
715 * Clone the hio so we can handle both of them.
721 hio_copy(hio, mshio);
727 hio->hio_memsync = false;
736 hio);
737 QUEUE_INSERT(disk, hio);
751 struct hio *hio;
759 QUEUE_TAKE(disk, hio);
791 reqlog(LOG_DEBUG, 2, -1, hio, "disk: (%p) Got request: ", hio);
794 switch (hio->hio_cmd) {
796 ret = pread(res->hr_localfd, hio->hio_data,
797 hio->hio_length,
798 hio->hio_offset + res->hr_localoff);
800 hio->hio_error = errno;
801 else if (ret != (int64_t)hio->hio_length)
802 hio->hio_error = EIO;
804 hio->hio_error = 0;
807 ret = pwrite(res->hr_localfd, hio->hio_data,
808 hio->hio_length,
809 hio->hio_offset + res->hr_localoff);
811 hio->hio_error = errno;
812 else if (ret != (int64_t)hio->hio_length)
813 hio->hio_error = EIO;
815 hio->hio_error = 0;
819 hio->hio_offset + res->hr_localoff,
820 hio->hio_length);
822 hio->hio_error = errno;
824 hio->hio_error = 0;
829 hio->hio_error = EOPNOTSUPP;
837 hio->hio_error = errno;
839 hio->hio_error = 0;
844 hio->hio_cmd);
846 if (logerror && hio->hio_error != 0) {
847 reqlog(LOG_ERR, 0, hio->hio_error, hio,
851 hio);
852 QUEUE_INSERT(send, hio);
866 struct hio *hio;
872 QUEUE_TAKE(send, hio);
873 reqlog(LOG_DEBUG, 2, -1, hio, "send: (%p) Got request: ", hio);
876 nv_add_uint64(nvout, hio->hio_seq, "seq");
877 if (hio->hio_memsync) {
878 PJDLOG_ASSERT(hio->hio_cmd == HIO_WRITE);
881 switch (hio->hio_cmd) {
883 if (hio->hio_error == 0) {
884 data = hio->hio_data;
885 length = hio->hio_length;
900 hio->hio_cmd);
902 if (hio->hio_error != 0) {
903 switch (hio->hio_cmd) {
917 nv_add_int16(nvout, hio->hio_error, "error");
925 hio);
926 hio_clear(hio);
927 QUEUE_INSERT(free, hio);