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

« back to all changes in this revision

Viewing changes to exec/service.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2010-07-02 01:24:53 UTC
  • mfrom: (1.1.4 upstream) (5.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100702012453-qky79tg6hjly2dmq
Tags: 1.2.1-1ubuntu1
* Merge from debian unstable (LP: #600900). Remaining changes:
  - Raised consensus time out to 5000ms
  - debian/control, debian/rules: Removing now-unnecessary quilt build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
#include <corosync/engine/coroapi.h>
56
56
#include "service.h"
57
57
 
 
58
#include <corosync/coroipcs.h>
 
59
 
58
60
LOGSYS_DECLARE_SUBSYS ("SERV");
59
61
 
60
62
struct default_service {
89
91
        }
90
92
};
91
93
 
 
94
/*
 
95
 * service exit and unlink schedwrk handler data structure
 
96
 */
 
97
struct seus_handler_data {
 
98
        hdb_handle_t service_handle;
 
99
        int service_engine;
 
100
        struct corosync_api_v1 *api;
 
101
};
 
102
 
92
103
struct corosync_service_engine *ais_service[SERVICE_HANDLER_MAXIMUM_COUNT];
93
104
 
94
105
hdb_handle_t service_stats_handle[SERVICE_HANDLER_MAXIMUM_COUNT][64];
95
106
 
 
107
int ais_service_exiting[SERVICE_HANDLER_MAXIMUM_COUNT];
 
108
 
96
109
static hdb_handle_t object_internal_configuration_handle;
97
110
 
98
111
static hdb_handle_t object_stats_services_handle;
99
112
 
100
113
static void (*service_unlink_all_complete) (void) = NULL;
101
114
 
102
 
static hdb_handle_t unlink_all_handle;
103
 
 
 
115
static hdb_handle_t swrk_service_exit_handle;
 
116
static hdb_handle_t swrk_service_unlink_handle;
104
117
 
105
118
static unsigned int default_services_requested (struct corosync_api_v1 *corosync_api)
106
119
{
272
285
        struct corosync_api_v1 *corosync_api,
273
286
        int lowest_priority,
274
287
        int *current_priority,
275
 
        int *current_service_engine)
 
288
        int *current_service_engine,
 
289
        hdb_handle_t *current_service_handle)
276
290
{
277
291
        unsigned short *service_id;
278
292
        hdb_handle_t object_service_handle;
319
333
                                                        return (-1);
320
334
                                                }
321
335
                                        }
322
 
                                        log_printf(LOGSYS_LEVEL_NOTICE,
323
 
                                                "Service engine unloaded: %s\n",
324
 
                                                   ais_service[*current_service_engine]->name);
325
 
 
326
 
                                        ais_service[*current_service_engine] = NULL;
327
336
 
328
337
                                        res = corosync_api->object_key_get (
329
338
                                                object_service_handle,
331
340
                                                (void *)&found_service_handle,
332
341
                                                NULL);
333
342
 
334
 
                                        lcr_ifact_release (*found_service_handle);
335
 
 
336
 
                                        corosync_api->object_destroy (object_service_handle);
337
 
                                        break;
 
343
                                        *current_service_handle = *found_service_handle;
 
344
 
 
345
                                        ais_service_exiting[*current_service_engine] = 1;
 
346
 
 
347
                                        corosync_api->object_find_destroy (object_find_handle);
 
348
 
 
349
                                        /*
 
350
                                         * Call should call this function again
 
351
                                         */
 
352
                                        return (1);
338
353
                                }
339
354
                        }
340
355
 
341
356
                        corosync_api->object_find_destroy (object_find_handle);
342
357
                }
343
358
        }
344
 
        return 0;
 
359
        /*
 
360
         * We finish unlink of all services -> no need to call this function again
 
361
         */
 
362
        return (0);
345
363
}
346
364
 
347
365
static unsigned int service_unlink_and_exit (
538
556
        return (0);
539
557
}
540
558
 
541
 
static int unlink_all_schedwrk_handler (const void *data) {
 
559
/*
 
560
 * Declaration of exit_schedwrk_handler, because of cycle
 
561
 * (service_exit_schedwrk_handler calls service_unlink_schedwrk_handler, and vice-versa)
 
562
 */
 
563
static int service_exit_schedwrk_handler (const void *data);
 
564
 
 
565
static int service_unlink_schedwrk_handler (const void *data) {
 
566
        struct seus_handler_data *cb_data = (struct seus_handler_data *)data;
 
567
        struct corosync_api_v1 *api = (struct corosync_api_v1 *)cb_data->api;
 
568
 
 
569
        /*
 
570
         * Exit all ipc connections dependent on this service
 
571
         */
 
572
        if (coroipcs_ipc_service_exit (cb_data->service_engine) == -1)
 
573
                return -1;
 
574
 
 
575
        log_printf(LOGSYS_LEVEL_NOTICE,
 
576
                "Service engine unloaded: %s\n",
 
577
                ais_service[cb_data->service_engine]->name);
 
578
 
 
579
        ais_service[cb_data->service_engine] = NULL;
 
580
 
 
581
        lcr_ifact_release (cb_data->service_handle);
 
582
 
 
583
        api->schedwrk_create (
 
584
                &swrk_service_exit_handle,
 
585
                &service_exit_schedwrk_handler,
 
586
                data);
 
587
 
 
588
        return 0;
 
589
}
 
590
 
 
591
static int service_exit_schedwrk_handler (const void *data) {
542
592
        int res;
543
593
        static int current_priority = 0;
544
594
        static int current_service_engine = 0;
545
595
        static int called = 0;
546
 
        struct corosync_api_v1 *api = (struct corosync_api_v1 *)data;
 
596
        struct seus_handler_data *cb_data = (struct seus_handler_data *)data;
 
597
        struct corosync_api_v1 *api = (struct corosync_api_v1 *)cb_data->api;
 
598
        hdb_handle_t service_handle;
547
599
 
548
600
        if (called == 0) {
549
601
                log_printf(LOGSYS_LEVEL_NOTICE,
556
608
                api,
557
609
                0,
558
610
                &current_priority,
559
 
                &current_service_engine);
 
611
                &current_service_engine,
 
612
                &service_handle);
560
613
        if (res == 0) {
561
614
                service_unlink_all_complete();
562
 
        }
 
615
                return (res);
 
616
        }
 
617
 
 
618
        if (res == 1) {
 
619
                cb_data->service_engine = current_service_engine;
 
620
                cb_data->service_handle = service_handle;
 
621
 
 
622
                api->schedwrk_create_nolock (
 
623
                        &swrk_service_unlink_handle,
 
624
                        &service_unlink_schedwrk_handler,
 
625
                        data);
 
626
 
 
627
                return (0);
 
628
        }
 
629
 
563
630
        return (res);
564
631
}
565
632
                
568
635
        void (*unlink_all_complete) (void))
569
636
{
570
637
        static int called = 0;
 
638
        static struct seus_handler_data cb_data;
571
639
 
572
640
        assert (api);
573
641
 
579
647
        if (called == 0) {
580
648
                called = 1;
581
649
        }
582
 
        
 
650
 
 
651
        cb_data.api = api;
 
652
 
583
653
        api->schedwrk_create (
584
 
                &unlink_all_handle,
585
 
                &unlink_all_schedwrk_handler,
586
 
                api);
 
654
                &swrk_service_exit_handle,
 
655
                &service_exit_schedwrk_handler,
 
656
                &cb_data);
587
657
}
588
658
 
589
659
struct service_unlink_and_exit_data {