Lines Matching refs:res

209 init_local(struct hast_resource *res)  in init_local()  argument
212 if (metadata_read(res, true) == -1) in init_local()
217 init_remote(struct hast_resource *res, struct nv *nvin) in init_remote() argument
226 if (proto_send(res->hr_remoteout, NULL, 0) == -1) in init_remote()
231 nv_add_int64(nvout, (int64_t)res->hr_datasize, "datasize"); in init_remote()
232 nv_add_int32(nvout, (int32_t)res->hr_extentsize, "extentsize"); in init_remote()
234 res->hr_primary_localcnt = nv_get_uint64(nvin, "localcnt"); in init_remote()
235 res->hr_primary_remotecnt = nv_get_uint64(nvin, "remotecnt"); in init_remote()
236 nv_add_uint64(nvout, res->hr_secondary_localcnt, "localcnt"); in init_remote()
237 nv_add_uint64(nvout, res->hr_secondary_remotecnt, "remotecnt"); in init_remote()
238 mapsize = activemap_calc_ondisk_size(res->hr_local_mediasize - in init_remote()
239 METADATA_SIZE, res->hr_extentsize, res->hr_local_sectorsize); in init_remote()
284 if (res->hr_resuid == 0) { in init_remote()
291 PJDLOG_ASSERT(res->hr_secondary_localcnt == 0); in init_remote()
292 res->hr_resuid = resuid; in init_remote()
293 if (metadata_write(res) == -1) in init_remote()
304 } else if (res->hr_resuid != resuid) { in init_remote()
310 (uintmax_t)resuid, (uintmax_t)res->hr_resuid); in init_remote()
313 if (hast_proto_send(res, res->hr_remotein, nvout, in init_remote()
317 res->hr_remoteaddr); in init_remote()
323 (res->hr_secondary_localcnt > res->hr_primary_remotecnt && in init_remote()
324 res->hr_secondary_remotecnt == res->hr_primary_localcnt) || in init_remote()
326 (res->hr_secondary_localcnt == res->hr_primary_remotecnt && in init_remote()
327 res->hr_secondary_remotecnt == res->hr_primary_localcnt) || in init_remote()
329 (res->hr_secondary_localcnt == res->hr_primary_remotecnt && in init_remote()
330 res->hr_secondary_remotecnt < res->hr_primary_localcnt)) { in init_remote()
337 if (pread(res->hr_localfd, map, mapsize, METADATA_SIZE) != in init_remote()
341 if (res->hr_secondary_localcnt > res->hr_primary_remotecnt && in init_remote()
342 res->hr_secondary_remotecnt == res->hr_primary_localcnt) { in init_remote()
352 } else if (res->hr_secondary_localcnt > res->hr_primary_remotecnt && in init_remote()
353 res->hr_primary_localcnt > res->hr_secondary_remotecnt) { in init_remote()
360 if (hast_proto_send(res, res->hr_remotein, nvout, in init_remote()
364 res->hr_remoteaddr); in init_remote()
368 event_send(res, EVENT_SPLITBRAIN); in init_remote()
376 PJDLOG_ASSERT(res->hr_secondary_localcnt < res->hr_primary_remotecnt || in init_remote()
377 res->hr_primary_localcnt < res->hr_secondary_remotecnt); in init_remote()
378 mapsize = activemap_calc_ondisk_size(res->hr_local_mediasize - in init_remote()
379 METADATA_SIZE, res->hr_extentsize, in init_remote()
380 res->hr_local_sectorsize); in init_remote()
382 if (res->hr_secondary_localcnt > res->hr_primary_remotecnt) { in init_remote()
390 (uintmax_t)res->hr_primary_localcnt, in init_remote()
391 (uintmax_t)res->hr_primary_remotecnt, in init_remote()
392 (uintmax_t)res->hr_secondary_localcnt, in init_remote()
393 (uintmax_t)res->hr_secondary_remotecnt); in init_remote()
396 if (hast_proto_send(res, res->hr_remotein, nvout, map, mapsize) == -1) { in init_remote()
398 res->hr_remoteaddr); in init_remote()
405 if (proto_recv(res->hr_remotein, NULL, 0) == -1) in init_remote()
411 hastd_secondary(struct hast_resource *res, struct nv *nvin) in hastd_secondary() argument
421 if (proto_client(NULL, "socketpair://", &res->hr_ctrl) == -1) { in hastd_secondary()
429 if (proto_client(NULL, "socketpair://", &res->hr_event) == -1) { in hastd_secondary()
443 proto_close(res->hr_remotein); in hastd_secondary()
444 res->hr_remotein = NULL; in hastd_secondary()
445 proto_close(res->hr_remoteout); in hastd_secondary()
446 res->hr_remoteout = NULL; in hastd_secondary()
448 proto_recv(res->hr_event, NULL, 0); in hastd_secondary()
450 proto_send(res->hr_ctrl, NULL, 0); in hastd_secondary()
451 res->hr_workerpid = pid; in hastd_secondary()
455 gres = res; in hastd_secondary()
456 res->output_status_aux = output_status_aux; in hastd_secondary()
461 proto_send(res->hr_event, NULL, 0); in hastd_secondary()
463 proto_recv(res->hr_ctrl, NULL, 0); in hastd_secondary()
464 descriptors_cleanup(res); in hastd_secondary()
466 descriptors_assert(res, mode); in hastd_secondary()
470 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role)); in hastd_secondary()
471 setproctitle("%s (%s)", res->hr_name, role2str(res->hr_role)); in hastd_secondary()
477 if (proto_timeout(res->hr_remotein, 2 * HAST_KEEPALIVE) == -1) in hastd_secondary()
479 if (proto_timeout(res->hr_remoteout, res->hr_timeout) == -1) in hastd_secondary()
482 init_local(res); in hastd_secondary()
485 if (drop_privs(res) != 0) in hastd_secondary()
497 error = pthread_create(&td, NULL, ctrl_thread, res); in hastd_secondary()
500 init_remote(res, nvin); in hastd_secondary()
501 event_send(res, EVENT_CONNECT); in hastd_secondary()
503 error = pthread_create(&td, NULL, recv_thread, res); in hastd_secondary()
505 error = pthread_create(&td, NULL, disk_thread, res); in hastd_secondary()
507 (void)send_thread(res); in hastd_secondary()
554 requnpack(struct hast_resource *res, struct hio *hio, struct nv *nv) in requnpack() argument
603 if ((hio->hio_offset % res->hr_local_sectorsize) != 0) { in requnpack()
609 if ((hio->hio_length % res->hr_local_sectorsize) != 0) { in requnpack()
616 (uint64_t)res->hr_datasize) { in requnpack()
619 (uintmax_t)res->hr_datasize); in requnpack()
654 struct hast_resource *res = arg; in recv_thread() local
662 if (hast_proto_recv_hdr(res->hr_remotein, &nv) == -1) { in recv_thread()
666 if (requnpack(res, hio, nv) != 0) { in recv_thread()
676 res->hr_stat_read++; in recv_thread()
679 res->hr_stat_write++; in recv_thread()
682 res->hr_stat_delete++; in recv_thread()
685 res->hr_stat_flush++; in recv_thread()
704 if (hast_proto_recv_data(res, res->hr_remotein, nv, in recv_thread()
747 struct hast_resource *res = arg; in disk_thread() local
767 activemap_calc_ondisk_size(res->hr_local_mediasize - in disk_thread()
768 METADATA_SIZE, res->hr_extentsize, in disk_thread()
769 res->hr_local_sectorsize); in disk_thread()
775 if (pwrite(res->hr_localfd, map, mapsize, in disk_thread()
780 res->hr_stat_activemap_write_error++; in disk_thread()
793 ret = pread(res->hr_localfd, hio->hio_data, in disk_thread()
795 hio->hio_offset + res->hr_localoff); in disk_thread()
804 ret = pwrite(res->hr_localfd, hio->hio_data, in disk_thread()
806 hio->hio_offset + res->hr_localoff); in disk_thread()
815 ret = g_delete(res->hr_localfd, in disk_thread()
816 hio->hio_offset + res->hr_localoff, in disk_thread()
824 if (!res->hr_localflush) { in disk_thread()
830 ret = g_flush(res->hr_localfd); in disk_thread()
833 res->hr_localflush = false; in disk_thread()
861 struct hast_resource *res = arg; in send_thread() local
902 res->hr_stat_read_error++; in send_thread()
905 res->hr_stat_write_error++; in send_thread()
908 res->hr_stat_delete_error++; in send_thread()
911 res->hr_stat_flush_error++; in send_thread()
916 if (hast_proto_send(res, res->hr_remoteout, nvout, data, in send_thread()