~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to lib/coroipcc.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Loschwitz
  • Date: 2011-10-19 14:32:18 UTC
  • mfrom: (1.1.6 upstream) (5.1.16 sid)
  • Revision ID: james.westby@ubuntu.com-20111019143218-ew8phl0raqyog844
Tags: 1.4.2-1
* Changed my email address in debian/control
* Add corosync-blackbox to the corosync package
* Imported Upstream version 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        pthread_mutex_t mutex;
87
87
};
88
88
 
 
89
struct ipc_path_data {
 
90
        mar_req_setup_t req_setup;
 
91
        mar_res_setup_t res_setup;
 
92
        char control_map_path[PATH_MAX];
 
93
        char request_map_path[PATH_MAX];
 
94
        char response_map_path[PATH_MAX];
 
95
        char dispatch_map_path[PATH_MAX];
 
96
};
 
97
 
89
98
void ipc_hdb_destructor (void *context);
90
99
 
91
100
DECLARE_HDB_DATABASE(ipc_hdb,ipc_hdb_destructor);
227
236
                        goto res_exit;
228
237
                }
229
238
        }
230
 
#if defined(COROSYNC_SOLARIS) || defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
231
 
        /* On many OS poll never return POLLHUP or POLLERR.
232
 
         * EOF is detected when recvmsg return 0.
 
239
        /*
 
240
         * EOF is also detected when recvmsg return 0.
233
241
         */
234
242
        if (result == 0) {
235
243
                res = CS_ERR_LIBRARY;
236
244
                goto res_exit;
237
245
        }
238
 
#endif
239
246
 
240
247
        processed += result;
241
248
        if (processed != len) {
311
318
        }
312
319
 
313
320
        page_size = sysconf(_SC_PAGESIZE);
 
321
        if (page_size == -1) {
 
322
                goto error_close_unlink;
 
323
        }
 
324
 
314
325
        buffer = malloc (page_size);
315
326
        if (buffer == NULL) {
316
327
                goto error_close_unlink;
417
428
                goto error_close_unlink;
418
429
        }
419
430
        page_size = sysconf(_SC_PAGESIZE);
 
431
        if (page_size == -1) {
 
432
                goto error_close_unlink;
 
433
        }
 
434
 
420
435
        buffer = malloc (page_size);
421
436
        if (buffer == NULL) {
422
437
                goto error_close_unlink;
584
599
        union semun semun;
585
600
#endif
586
601
        int sys_res;
587
 
        mar_req_setup_t req_setup;
588
 
        mar_res_setup_t res_setup;
589
 
        char control_map_path[PATH_MAX];
590
 
        char request_map_path[PATH_MAX];
591
 
        char response_map_path[PATH_MAX];
592
 
        char dispatch_map_path[PATH_MAX];
 
602
        struct ipc_path_data *path_data;
593
603
 
594
604
        res = hdb_error_to_cs (hdb_handle_create (&ipc_hdb,
595
605
                sizeof (struct ipc_instance), handle));
602
612
                return (res);
603
613
        }
604
614
 
605
 
        res_setup.error = CS_ERR_LIBRARY;
606
 
 
607
615
#if defined(COROSYNC_SOLARIS)
608
616
        request_fd = socket (PF_UNIX, SOCK_STREAM, 0);
609
617
#else
616
624
        socket_nosigpipe (request_fd);
617
625
#endif
618
626
 
 
627
        path_data = malloc (sizeof(*path_data));
 
628
        if (path_data == NULL) {
 
629
                goto error_connect;
 
630
        }
 
631
        memset(path_data, 0, sizeof(*path_data));
 
632
 
 
633
        path_data->res_setup.error = CS_ERR_LIBRARY;
 
634
 
619
635
        memset (&address, 0, sizeof (struct sockaddr_un));
620
636
        address.sun_family = AF_UNIX;
621
637
#if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
635
651
        }
636
652
 
637
653
        sys_res = memory_map (
638
 
                control_map_path,
 
654
                path_data->control_map_path,
639
655
                "control_buffer-XXXXXX",
640
656
                (void *)&ipc_instance->control_buffer,
641
657
                8192);
645
661
        }
646
662
 
647
663
        sys_res = memory_map (
648
 
                request_map_path,
 
664
                path_data->request_map_path,
649
665
                "request_buffer-XXXXXX",
650
666
                (void *)&ipc_instance->request_buffer,
651
667
                request_size);
655
671
        }
656
672
 
657
673
        sys_res = memory_map (
658
 
                response_map_path,
 
674
                path_data->response_map_path,
659
675
                "response_buffer-XXXXXX",
660
676
                (void *)&ipc_instance->response_buffer,
661
677
                response_size);
665
681
        }
666
682
 
667
683
        sys_res = circular_memory_map (
668
 
                dispatch_map_path,
 
684
                path_data->dispatch_map_path,
669
685
                "dispatch_buffer-XXXXXX",
670
686
                (void *)&ipc_instance->dispatch_buffer,
671
687
                dispatch_size);
720
736
        /*
721
737
         * Initialize IPC setup message
722
738
         */
723
 
        req_setup.service = service;
724
 
        strcpy (req_setup.control_file, control_map_path);
725
 
        strcpy (req_setup.request_file, request_map_path);
726
 
        strcpy (req_setup.response_file, response_map_path);
727
 
        strcpy (req_setup.dispatch_file, dispatch_map_path);
728
 
        req_setup.control_size = 8192;
729
 
        req_setup.request_size = request_size;
730
 
        req_setup.response_size = response_size;
731
 
        req_setup.dispatch_size = dispatch_size;
 
739
        path_data->req_setup.service = service;
 
740
        strcpy (path_data->req_setup.control_file, path_data->control_map_path);
 
741
        strcpy (path_data->req_setup.request_file, path_data->request_map_path);
 
742
        strcpy (path_data->req_setup.response_file, path_data->response_map_path);
 
743
        strcpy (path_data->req_setup.dispatch_file, path_data->dispatch_map_path);
 
744
        path_data->req_setup.control_size = 8192;
 
745
        path_data->req_setup.request_size = request_size;
 
746
        path_data->req_setup.response_size = response_size;
 
747
        path_data->req_setup.dispatch_size = dispatch_size;
732
748
 
733
749
#if _POSIX_THREAD_PROCESS_SHARED < 1
734
 
        req_setup.semkey = semkey;
 
750
        path_data->req_setup.semkey = semkey;
735
751
#endif
736
752
 
737
 
        res = socket_send (request_fd, &req_setup, sizeof (mar_req_setup_t));
 
753
        res = socket_send (request_fd, &path_data->req_setup, sizeof (mar_req_setup_t));
738
754
        if (res != CS_OK) {
739
755
                goto error_exit;
740
756
        }
741
 
        res = socket_recv (request_fd, &res_setup, sizeof (mar_res_setup_t));
 
757
        res = socket_recv (request_fd, &path_data->res_setup, sizeof (mar_res_setup_t));
742
758
        if (res != CS_OK) {
743
759
                goto error_exit;
744
760
        }
745
761
 
746
762
        ipc_instance->fd = request_fd;
747
763
 
748
 
        if (res_setup.error == CS_ERR_TRY_AGAIN) {
749
 
                res = res_setup.error;
 
764
        if (path_data->res_setup.error == CS_ERR_TRY_AGAIN) {
 
765
                res = path_data->res_setup.error;
750
766
                goto error_exit;
751
767
        }
752
768
 
759
775
 
760
776
        hdb_handle_put (&ipc_hdb, *handle);
761
777
 
762
 
        return (res_setup.error);
 
778
        res = path_data->res_setup.error;
 
779
        free(path_data);
 
780
        return (res);
763
781
 
764
782
error_exit:
765
783
#if _POSIX_THREAD_PROCESS_SHARED < 1
778
796
 
779
797
        hdb_handle_destroy (&ipc_hdb, *handle);
780
798
        hdb_handle_put (&ipc_hdb, *handle);
 
799
        free(path_data);
781
800
 
782
801
        return (res);
783
802
}
858
877
                return (error);
859
878
        }
860
879
 
 
880
        if (shared_mem_dispatch_bytes_left (ipc_instance) > (ipc_instance->dispatch_size/2)) {
 
881
                /*
 
882
                 * Notify coroipcs to flush any pending dispatch messages
 
883
                 */
 
884
                res = ipc_sem_post (ipc_instance->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT);
 
885
                if (res != CS_OK) {
 
886
                        error = CS_ERR_LIBRARY;
 
887
                        goto error_put;
 
888
                }
 
889
        }
 
890
 
861
891
        *data = NULL;
862
892
 
863
893
        ufds.fd = ipc_instance->fd;
883
913
        }
884
914
 
885
915
        error = socket_recv (ipc_instance->fd, &buf, 1);
 
916
#if defined(COROSYNC_SOLARIS) || defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN)
 
917
        /* On many OS poll() never returns POLLHUP or POLLERR.
 
918
         * EOF is detected when recvmsg() return 0.
 
919
         */
 
920
        if ( error == CS_ERR_LIBRARY )
 
921
                goto error_put;
 
922
#endif
886
923
        assert (error == CS_OK);
887
924
 
888
 
        if (shared_mem_dispatch_bytes_left (ipc_instance) > 500000) {
 
925
        if (shared_mem_dispatch_bytes_left (ipc_instance) > (ipc_instance->dispatch_size/2)) {
889
926
                /*
890
927
                 * Notify coroipcs to flush any pending dispatch messages
891
928
                 */
941
978
        read_idx = ipc_instance->control_buffer->read;
942
979
        header = (coroipc_response_header_t *) &addr[read_idx];
943
980
        ipc_instance->control_buffer->read =
944
 
                (read_idx + header->size) % ipc_instance->dispatch_size;
 
981
                ((read_idx + header->size + 7) & 0xFFFFFFF8) %
 
982
                        ipc_instance->dispatch_size;
 
983
 
945
984
        /*
946
985
         * Put from dispatch get and also from this call's get
947
986
         */
1042
1081
{
1043
1082
        struct ipc_instance *ipc_instance;
1044
1083
        void *buf = NULL;
1045
 
        char path[128];
 
1084
        char path[PATH_MAX];
1046
1085
        unsigned int res;
1047
1086
        mar_req_coroipcc_zc_alloc_t req_coroipcc_zc_alloc;
1048
1087
        coroipc_response_header_t res_coroipcs_zc_alloc;