~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to cim/constraint_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * constraint_common.c: common functions for constraint providers
3
 
 *
4
 
 * Author: Jia Ming Pan <jmltc@cn.ibm.com>
5
 
 * Copyright (c) 2005 International Business Machines
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
10
 
 * (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 
 *
21
 
 */
22
 
 
23
 
#include <lha_internal.h>
24
 
#include <stdlib.h>
25
 
#include <stdio.h>
26
 
#include <string.h>
27
 
#include <sys/stat.h>
28
 
#include <sys/types.h>
29
 
#include <unistd.h>
30
 
#include <cmpidt.h>
31
 
#include <cmpift.h>
32
 
#include <cmpimacs.h>
33
 
#include "cluster_info.h"
34
 
#include "constraint_common.h"
35
 
#include "cmpi_utils.h"
36
 
 
37
 
static char SystemName          [] = "LinuxHACluster";
38
 
static char SystemCrName        [] = "HA_Cluster";
39
 
 
40
 
static CMPIInstance *   make_instance_byid(CMPIBroker * broker, char * classname,
41
 
                                CMPIObjectPath * op, char * id, uint32_t type, 
42
 
                                CMPIStatus * rc);
43
 
static CMPIInstance *   make_instance(CMPIBroker * broker, char * classname, 
44
 
                                CMPIObjectPath *op, struct ha_msg *cons, 
45
 
                                int type, CMPIStatus * rc);
46
 
static CMPIInstance *
47
 
make_instance(CMPIBroker *broker, char *classname, CMPIObjectPath *op, 
48
 
               struct ha_msg* constraint, int type, CMPIStatus *rc)
49
 
{
50
 
        CMPIInstance * ci = NULL;
51
 
        char *id;
52
 
        char caption[MAXLEN];
53
 
 
54
 
        DEBUG_ENTER();
55
 
        ci = CMNewInstance(broker, op, rc);
56
 
        if ( CMIsNullObject(ci) ) {
57
 
                cl_log(LOG_ERR, "%s: can't create instance", __FUNCTION__);
58
 
                CMSetStatusWithChars(broker, rc, 
59
 
                       CMPI_RC_ERR_FAILED, "Can't get create instance");
60
 
                goto out;
61
 
        }
62
 
        
63
 
        id = cim_strdup(cl_get_string(constraint, "id"));
64
 
        if ( id == NULL ) { return NULL; }
65
 
 
66
 
        /* setting properties */
67
 
        CMSetProperty(ci, "Id", id, CMPI_chars);
68
 
        CMSetProperty(ci, "SystemCreationClassName", SystemCrName, CMPI_chars);
69
 
        CMSetProperty(ci, "SystemName", SystemName, CMPI_chars);
70
 
        CMSetProperty(ci, "CreationClassName", classname, CMPI_chars);
71
 
 
72
 
        if ( type == TID_CONS_ORDER ) {
73
 
                cmpi_msg2inst(broker, ci, 
74
 
                                HA_ORDER_CONSTRAINT, constraint, rc); 
75
 
        } else if ( type == TID_CONS_LOCATION ) {
76
 
                cmpi_msg2inst(broker, ci, 
77
 
                                HA_LOCATION_CONSTRAINT, constraint, rc);
78
 
        } else if ( type == TID_CONS_COLOCATION ) {
79
 
                cmpi_msg2inst(broker, ci, 
80
 
                                HA_COLOCATION_CONSTRAINT, constraint, rc);
81
 
        }
82
 
        snprintf(caption, MAXLEN, "Constraint.%s", id);
83
 
        CMSetProperty(ci, "Caption", caption, CMPI_chars);
84
 
        cim_free(id);
85
 
out:
86
 
        DEBUG_LEAVE();
87
 
        return ci; 
88
 
}
89
 
 
90
 
static CMPIInstance *
91
 
make_instance_byid(CMPIBroker * broker, char * classname, CMPIObjectPath * op, 
92
 
                     char * id, uint32_t type, CMPIStatus * rc) 
93
 
{
94
 
        CMPIInstance * ci;
95
 
        struct ha_msg *constraint;
96
 
        int funcid = 0;
97
 
 
98
 
        DEBUG_ENTER();
99
 
        switch(type) {
100
 
        case TID_CONS_LOCATION: funcid=GET_LOCATION_CONSTRAINT; break;
101
 
        case TID_CONS_COLOCATION: funcid=GET_COLOCATION_CONSTRAINT; break;
102
 
        case TID_CONS_ORDER: funcid=GET_ORDER_CONSTRAINT; break;
103
 
        default:break;
104
 
        }
105
 
 
106
 
        if ( (constraint= cim_query_dispatch(funcid, id, NULL)) == NULL ) { 
107
 
                return NULL; 
108
 
        }
109
 
        ci = make_instance(broker, classname, op, constraint, type, rc);
110
 
        ha_msg_del(constraint);
111
 
        DEBUG_LEAVE();
112
 
        return ci;
113
 
}
114
 
 
115
 
int
116
 
constraing_get_inst(CMPIBroker * broker, char * classname, CMPIContext * ctx, 
117
 
              CMPIResult * rslt, CMPIObjectPath * cop,
118
 
              char ** properties, uint32_t type, CMPIStatus * rc)
119
 
{
120
 
        CMPIInstance* ci = NULL;
121
 
        CMPIObjectPath * op = NULL;
122
 
        char * consid = NULL;
123
 
                
124
 
        DEBUG_ENTER();
125
 
        /* get the key from the object path */
126
 
        if (( consid = CMGetKeyString(cop, "Id", rc)) == NULL ) {
127
 
                cl_log(LOG_ERR, "%s: Id is missing.", __FUNCTION__);
128
 
                return HA_FAIL;
129
 
        }
130
 
 
131
 
        /* create a object path */
132
 
        op = CMNewObjectPath(broker, 
133
 
                CMGetCharPtr(CMGetNameSpace(cop, rc)), classname, rc);
134
 
        if ( CMIsNullObject(op) ){
135
 
                cl_log(LOG_ERR, "%s: Could not create object path.", 
136
 
                        __FUNCTION__);
137
 
                return HA_FAIL;
138
 
        }
139
 
 
140
 
        /* make an instance */
141
 
        ci = make_instance_byid(broker, classname, op, consid, type, rc);
142
 
        if ( CMIsNullObject(ci) ) {
143
 
                cl_log(LOG_ERR, "%s: Could not create instance.", 
144
 
                        __FUNCTION__);
145
 
                return HA_FAIL;
146
 
        }
147
 
 
148
 
        /* add the instance to result */
149
 
        CMReturnInstance(rslt, ci);
150
 
        CMReturnDone(rslt);
151
 
        return HA_OK;
152
 
}
153
 
 
154
 
int 
155
 
constraint_enum_insts(CMPIBroker * broker, char * classname, CMPIContext * ctx, 
156
 
               CMPIResult * rslt, CMPIObjectPath * ref, 
157
 
               int need_inst, uint32_t type, CMPIStatus * rc)
158
 
{
159
 
        char * namespace = NULL;
160
 
        CMPIObjectPath * op = NULL;
161
 
        int i, funcid = 0, len;
162
 
        struct ha_msg * cons;
163
 
 
164
 
        /* create object path */
165
 
        namespace = CMGetCharPtr(CMGetNameSpace(ref, rc));
166
 
        op = CMNewObjectPath(broker, namespace, classname, rc);
167
 
        if ( CMIsNullObject(op) ){
168
 
                return HA_FAIL;
169
 
        }
170
 
       
171
 
        switch(type){
172
 
                case TID_CONS_ORDER: 
173
 
                        funcid = GET_ORDER_CONS_LIST;break;
174
 
                case TID_CONS_LOCATION: 
175
 
                        funcid = GET_LOCATION_CONS_LIST; break;
176
 
                case TID_CONS_COLOCATION: 
177
 
                        funcid = GET_COLOCATION_CONS_LIST; break;
178
 
                default: break;
179
 
        } 
180
 
 
181
 
        if ( ( cons = cim_query_dispatch(funcid, NULL, NULL) ) == NULL ) {
182
 
                return HA_FAIL;
183
 
        }
184
 
 
185
 
        len = cim_list_length(cons);
186
 
        /* for each constraint */
187
 
        for ( i = 0; i < len; i++) {
188
 
                char * consid = cim_list_index(cons, i);
189
 
                if ( need_inst ) {
190
 
                        /* if need instance, make instance an return it */
191
 
                        CMPIInstance * ci = NULL;
192
 
                        ci = make_instance_byid(broker, classname, op, 
193
 
                                        consid, type, rc); 
194
 
                        if ( CMIsNullObject(ci) ){
195
 
                                cl_log(LOG_WARNING, 
196
 
                                   "%s: can not make instance", __FUNCTION__);
197
 
                                return HA_FAIL;
198
 
                        }
199
 
                        
200
 
                        cl_log(LOG_INFO, "%s: return instance", __FUNCTION__);
201
 
                        CMReturnInstance(rslt, ci);
202
 
                } else {
203
 
                        /* otherwise, just add keys to objectpath and return it */
204
 
                        CMAddKey(op, "Id", consid, CMPI_chars);      
205
 
                        CMAddKey(op, "SystemName", SystemName, CMPI_chars);
206
 
                        CMAddKey(op, "SystemCreationClassName", SystemCrName, CMPI_chars);
207
 
                        CMAddKey(op, "CreationClassName", classname, CMPI_chars);
208
 
 
209
 
                        /* add object to rslt */
210
 
                        CMReturnObjectPath(rslt, op);
211
 
                }
212
 
        }
213
 
        CMReturnDone(rslt);
214
 
        rc->rc = CMPI_RC_OK;
215
 
        ha_msg_del(cons);
216
 
        return HA_OK;
217
 
}
218
 
 
219
 
int     
220
 
constraint_delete_inst(CMPIBroker * broker, char * classname, 
221
 
                CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, 
222
 
                CMPIObjectPath * cop, uint32_t type, CMPIStatus * rc)
223
 
{
224
 
        const char * key [] = {"Id", "CreationClassName", "SystemName",
225
 
                        "SystemCreationClassName"};
226
 
        int funcid = 0;
227
 
        char * id;
228
 
 
229
 
        DEBUG_ENTER();
230
 
        if ((id = CMGetKeyString(cop, key[0], rc)) == NULL ) {
231
 
                rc->rc = CMPI_RC_ERR_FAILED;
232
 
                cl_log(LOG_ERR, "del_cons: can't get constraint id.");
233
 
                return HA_FAIL;
234
 
        }
235
 
        
236
 
        switch(type){
237
 
                case TID_CONS_ORDER: 
238
 
                        funcid = DEL_ORDER_CONSTRAINT;
239
 
                        break;
240
 
                case TID_CONS_LOCATION: 
241
 
                        funcid = DEL_LOCATION_CONSTRAINT; 
242
 
                        break;
243
 
                case TID_CONS_COLOCATION: 
244
 
                        funcid = DEL_COLOCATION_CONSTRAINT; 
245
 
                        break;
246
 
                default: 
247
 
                        cl_log(LOG_WARNING, "del_cons: Unknown type");
248
 
                        break;
249
 
        } 
250
 
        if ( cim_update_dispatch(funcid, id, NULL, NULL) == HA_OK ) {
251
 
                rc->rc = CMPI_RC_OK;
252
 
        } else {
253
 
                rc->rc = CMPI_RC_ERR_FAILED;
254
 
                cl_log(LOG_ERR, "del_cons: cim_update return error.");
255
 
        }
256
 
        DEBUG_LEAVE();
257
 
 
258
 
        return HA_OK;
259
 
}
260
 
 
261
 
int     
262
 
constraint_update_inst(CMPIBroker * broker, char * classname,
263
 
                CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, 
264
 
                CMPIObjectPath * cop, CMPIInstance * ci, char ** properties,
265
 
                uint32_t type, CMPIStatus * rc)
266
 
{
267
 
        struct ha_msg * t=NULL;
268
 
        const char * key [] = {"Id", "CreationClassName", "SystemName",
269
 
                                "SystemCreationClassName"};
270
 
        char * id, *crname, *sysname, *syscrname;
271
 
        int ret = HA_FAIL;
272
 
 
273
 
        DEBUG_ENTER();
274
 
        id        = CMGetKeyString(cop, key[0], rc);
275
 
        crname    = CMGetKeyString(cop, key[1], rc);
276
 
        sysname   = CMGetKeyString(cop, key[2], rc);
277
 
        syscrname = CMGetKeyString(cop, key[3], rc);
278
 
        
279
 
        switch(type){
280
 
        case TID_CONS_ORDER:
281
 
                t = cim_query_dispatch(GET_ORDER_CONSTRAINT, id, NULL); 
282
 
                cmpi_inst2msg(ci, HA_ORDER_CONSTRAINT, t, rc); 
283
 
                ret = cim_update_dispatch(UPDATE_ORDER_CONSTRAINT, NULL, t, NULL); 
284
 
                break;
285
 
        case TID_CONS_LOCATION:
286
 
                t = cim_query_dispatch(GET_LOCATION_CONSTRAINT, id, NULL); 
287
 
                cmpi_inst2msg(ci, HA_LOCATION_CONSTRAINT, t, rc); 
288
 
                ret = cim_update_dispatch(UPDATE_LOCATION_CONSTRAINT, NULL, t, NULL); 
289
 
                break;
290
 
        case TID_CONS_COLOCATION:
291
 
                t = cim_query_dispatch(GET_COLOCATION_CONSTRAINT, id, NULL); 
292
 
                cmpi_inst2msg(ci, HA_COLOCATION_CONSTRAINT, t, rc); 
293
 
                ret = cim_update_dispatch(UPDATE_COLOCATION_CONSTRAINT, NULL, t, NULL); 
294
 
                break;
295
 
        default: break;
296
 
        }
297
 
 
298
 
        ha_msg_del(t);
299
 
        /* if update OK, return CMPI_RC_OK */
300
 
        rc->rc = (ret == HA_OK)? CMPI_RC_OK : CMPI_RC_ERR_FAILED;
301
 
        DEBUG_ENTER();
302
 
        return HA_OK;
303
 
}
304
 
 
305
 
int
306
 
constraint_create_inst(CMPIBroker * broker, char * classname,
307
 
                CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, 
308
 
                CMPIObjectPath * cop, CMPIInstance * ci, uint32_t type, 
309
 
                CMPIStatus * rc)
310
 
{
311
 
        struct ha_msg *t;
312
 
 
313
 
        int ret = HA_FAIL;
314
 
        DEBUG_ENTER();
315
 
        if (( t = ha_msg_new(16)) == NULL ) {
316
 
                rc->rc = CMPI_RC_ERR_FAILED;
317
 
                DEBUG_LEAVE();
318
 
                return HA_FAIL;
319
 
        }
320
 
        switch(type){
321
 
        case TID_CONS_ORDER:
322
 
                cmpi_inst2msg(ci, HA_ORDER_CONSTRAINT, t, rc); 
323
 
                ret = cim_update_dispatch(UPDATE_ORDER_CONSTRAINT, NULL, t, NULL); 
324
 
                break;
325
 
        case TID_CONS_LOCATION:
326
 
                cmpi_inst2msg(ci, HA_LOCATION_CONSTRAINT, t, rc); 
327
 
                ret = cim_update_dispatch(UPDATE_LOCATION_CONSTRAINT, NULL, t, NULL); 
328
 
                break;
329
 
        case TID_CONS_COLOCATION:
330
 
                cmpi_inst2msg(ci, HA_COLOCATION_CONSTRAINT, t, rc); 
331
 
                ret = cim_update_dispatch(UPDATE_COLOCATION_CONSTRAINT, NULL, t, NULL); 
332
 
                break;
333
 
        default: break;
334
 
        }
335
 
        rc->rc = (ret==HA_OK)? CMPI_RC_OK : CMPI_RC_ERR_FAILED;
336
 
        ha_msg_del(t);
337
 
        DEBUG_LEAVE();
338
 
        return ret;
339
 
}
340