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

« back to all changes in this revision

Viewing changes to services/testquorum.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-21 09:29:56 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821092956-w9qxxxx3zeoh8dem
Tags: 1.0.0-4ubuntu2
* debian/control:
  - 'Ubuntu Developers' instead of 'Ubuntu Core Developers'
    as maintainer
  - Bump debhelper dependecy to 7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2008, 2009 Red Hat, Inc.
 
3
 *
 
4
 * All rights reserved.
 
5
 *
 
6
 * Author: Christine Caulfield (ccaulfie@redhat.com)
 
7
 *
 
8
 * This software licensed under BSD license, the text of which follows:
 
9
 *
 
10
 * Redistribution and use in source and binary forms, with or without
 
11
 * modification, are permitted provided that the following conditions are met:
 
12
 *
 
13
 * - Redistributions of source code must retain the above copyright notice,
 
14
 *   this list of conditions and the following disclaimer.
 
15
 * - Redistributions in binary form must reproduce the above copyright notice,
 
16
 *   this list of conditions and the following disclaimer in the documentation
 
17
 *   and/or other materials provided with the distribution.
 
18
 * - Neither the name of Red Hat, Inc. nor the names of its
 
19
 *   contributors may be used to endorse or promote products derived from this
 
20
 *   software without specific prior written permission.
 
21
 *
 
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
23
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
25
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
26
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
27
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
28
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
29
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
30
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
31
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 
32
 * THE POSSIBILITY OF SUCH DAMAGE.
 
33
 */
 
34
 
 
35
#include <config.h>
 
36
 
 
37
#include <pwd.h>
 
38
#include <grp.h>
 
39
#include <sys/types.h>
 
40
#include <sys/poll.h>
 
41
#include <sys/uio.h>
 
42
#include <sys/mman.h>
 
43
#include <sys/socket.h>
 
44
#include <sys/un.h>
 
45
#include <sys/time.h>
 
46
#include <sys/resource.h>
 
47
#include <netinet/in.h>
 
48
#include <arpa/inet.h>
 
49
#include <unistd.h>
 
50
#include <fcntl.h>
 
51
#include <stdlib.h>
 
52
#include <stdio.h>
 
53
#include <errno.h>
 
54
#include <sched.h>
 
55
#include <time.h>
 
56
 
 
57
#include <corosync/corotypes.h>
 
58
#include <corosync/coroipc_types.h>
 
59
#include <corosync/corodefs.h>
 
60
#include <corosync/engine/logsys.h>
 
61
 
 
62
#include <corosync/mar_gen.h>
 
63
#include <corosync/lcr/lcr_comp.h>
 
64
#include <corosync/engine/coroapi.h>
 
65
 
 
66
#include <corosync/engine/quorum.h>
 
67
 
 
68
LOGSYS_DECLARE_SUBSYS ("TEST");
 
69
 
 
70
static void test_init(struct corosync_api_v1 *api, quorum_set_quorate_fn_t report);
 
71
 
 
72
/*
 
73
 * lcrso object definition
 
74
 */
 
75
static struct quorum_services_api_ver1 test_quorum_iface_ver0 = {
 
76
        .init                           = test_init
 
77
};
 
78
 
 
79
static struct lcr_iface corosync_test_quorum_ver0[1] = {
 
80
        {
 
81
                .name                   = "testquorum",
 
82
                .version                = 0,
 
83
                .versions_replace       = 0,
 
84
                .versions_replace_count = 0,
 
85
                .dependencies           = 0,
 
86
                .dependency_count       = 0,
 
87
                .constructor            = NULL,
 
88
                .destructor             = NULL,
 
89
                .interfaces             = (void **)(void *)&test_quorum_iface_ver0,
 
90
        },
 
91
};
 
92
 
 
93
static struct lcr_comp test_quorum_comp_ver0 = {
 
94
        .iface_count                    = 1,
 
95
        .ifaces                         = corosync_test_quorum_ver0
 
96
};
 
97
 
 
98
#ifdef COROSYNC_SOLARIS
 
99
void corosync_lcr_component_register (void);
 
100
 
 
101
void corosync_lcr_component_register (void) {
 
102
        logsys_subsys_init();
 
103
#else
 
104
__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
 
105
#endif
 
106
        lcr_interfaces_set (&corosync_test_quorum_ver0[0], &test_quorum_iface_ver0);
 
107
        lcr_component_register (&test_quorum_comp_ver0);
 
108
}
 
109
 
 
110
/* -------------------------------------------------- */
 
111
 
 
112
static quorum_set_quorate_fn_t set_quorum;
 
113
 
 
114
static void key_change_notify(object_change_type_t change_type,
 
115
                              hdb_handle_t parent_object_handle,
 
116
                              hdb_handle_t object_handle,
 
117
                              const void *object_name_pt, size_t object_name_len,
 
118
                              const void *key_name_pt, size_t key_len,
 
119
                              const void *key_value_pt, size_t key_value_len,
 
120
                              void *priv_data_pt)
 
121
{
 
122
        unsigned int members[1];
 
123
        struct memb_ring_id ring_id;
 
124
 
 
125
        memset(&ring_id, 0, sizeof(ring_id));
 
126
 
 
127
        /* If the 'quorum.quorate' key changes, then that changes quorum */
 
128
        if (strncmp(key_name_pt, "quorate", key_len) == 0) {
 
129
                set_quorum(members, 0, atoi(key_value_pt), &ring_id);
 
130
        }
 
131
}
 
132
 
 
133
static void quorum_callback(int quorate, void *context)
 
134
{
 
135
        log_printf(LOGSYS_LEVEL_DEBUG, "quorum callback: quorate = %d\n", quorate);
 
136
}
 
137
 
 
138
static void test_init(struct corosync_api_v1 *api,
 
139
                      quorum_set_quorate_fn_t report)
 
140
{
 
141
 
 
142
        hdb_handle_t find_handle;
 
143
        hdb_handle_t quorum_handle = 0;
 
144
 
 
145
        set_quorum = report;
 
146
 
 
147
        /*
 
148
         * Register for objdb changes on quorum { }
 
149
         */
 
150
        api->object_find_create(OBJECT_PARENT_HANDLE, "quorum", strlen("quorum"), &find_handle);
 
151
        api->object_find_next(find_handle, &quorum_handle);
 
152
        api->object_find_destroy(find_handle);
 
153
 
 
154
        api->object_track_start(quorum_handle,
 
155
                                1,
 
156
                                key_change_notify,
 
157
                                NULL, // object_create_notify
 
158
                                NULL, // object_destroy_notify
 
159
                                NULL, // object_reload_notify
 
160
                                NULL); // priv_data
 
161
 
 
162
        /* Register for quorum changes too! */
 
163
        api->quorum_register_callback(quorum_callback, NULL);
 
164
}