-
Notifications
You must be signed in to change notification settings - Fork 21
/
odl.c
1936 lines (1617 loc) · 57.1 KB
/
odl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************
*
* Copyright (c) 2007-2013 Broadcom Corporation
* All Rights Reserved
*
<:label-BRCM:2013:proprietary:standard
This program is the proprietary software of Broadcom and/or its
licensors, and may only be used, duplicated, modified or distributed pursuant
to the terms and conditions of a separate, written license agreement executed
between you and Broadcom (an "Authorized License"). Except as set forth in
an Authorized License, Broadcom grants no license (express or implied), right
to use, or waiver of any kind with respect to the Software, and Broadcom
expressly reserves all rights in and to the Software and all intellectual
property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE
NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY
BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
Except as expressly set forth in the Authorized License,
1. This program, including its structure, sequence and organization,
constitutes the valuable trade secrets of Broadcom, and you shall use
all reasonable efforts to protect the confidentiality thereof, and to
use this information only in connection with your use of Broadcom
integrated circuit products.
2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND
ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT,
FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE
TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR
PERFORMANCE OF THE SOFTWARE.
3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR
ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL,
INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY
WAY RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN
IF BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES;
OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS
SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY
LIMITED REMEDY.
:>
*
************************************************************************/
#include "cms.h"
#include "odl.h"
#include "cms_obj.h"
#include "cms_util.h"
#include "mdm.h"
/*
* One element in the set queue.
*/
typedef struct odl_set_entry
{
struct odl_set_entry *prev;
struct odl_set_entry *next;
MdmObjectNode *objNode;
InstanceIdStack iidStack;
UBOOL8 orderValueChanged;
void *newMdmObj;
void *currMdmObj;
} OdlSetQueueEntry;
/*
* Head of the set queue.
*/
typedef struct
{
OdlSetQueueEntry *head;
OdlSetQueueEntry *tail;
UINT32 count;
} OdlSetQueue;
static OdlSetQueue setQ = {0, 0, 0};
/** OdlGetCache is used by odl_get to cache a MdmObject.
*
* odl_get may be called multiple times to get different fields in
* the same object. So instead of calling the STL handler function for
* each field, odl_get uses the cached object as long as odl_get is
* being called for the same object and no other odl functions have
* been called.
*/
typedef struct
{
void *mdmObj;
InstanceIdStack iidStack;
CmsTimestamp tms;
} OdlGetCache;
static OdlGetCache getCache = {NULL, EMPTY_INSTANCE_ID_STACK, {0,0}};
#define INVALIDATE_ODL_GET_CACHE \
do {\
if (getCache.mdmObj != NULL) mdm_freeObject(&(getCache.mdmObj)); \
} while (0)
/** timeout mdmObj after 50 milli-seconds */
#define ODL_GET_CACHE_TIMEOUT 50
/** some macros to keep track of which function we are currently in */
#define ODL_RECORD_CALL_ENTRY(fcode, eoid) \
UINT8 lastFuncCode = mdmShmCtx->lockFuncCode; \
MdmObjectId lastOid = mdmShmCtx->oid; \
mdmShmCtx->lockFuncCode = (UINT8) (fcode); \
mdmShmCtx->oid = (eoid)
#define ODL_RECORD_CALL_EXIT \
mdmShmCtx->lockFuncCode = lastFuncCode; \
mdmShmCtx->oid = lastOid
/* local functions */
static void freeSetQueue(void);
void freeSetQueueEntry(OdlSetQueueEntry **entry);
static void reverseSetQueue(void);
static OdlSetQueueEntry *getSetQueueEntry(MdmObjectNode *objNode, const InstanceIdStack *iidStack);
static UBOOL8 findInSetQueue(MdmObjectId oid, const InstanceIdStack *iidStack, void **mdmObj);
static UBOOL8 findPointerInSetQueue(const void *mdmObj);
static UINT32 getSetQueueCount(void);
static CmsRet callSetHandlerFunc(MdmObjectNode *objNode,
const InstanceIdStack *iidStack,
void *newMdmObj,
const void *currMdmObj,
char **errorParam,
CmsRet *errorCode);
static void undoAllInstanceMovesUsingNewOrderValues(void);
CmsRet odl_init(void)
{
return CMSRET_SUCCESS;
}
void odl_cleanup(void)
{
INVALIDATE_ODL_GET_CACHE;
}
CmsRet odl_set(PhlSetParamValue_t *paramValueArray,
UINT32 numParamValues)
{
UINT32 i;
UINT32 numSetEntries=0;
MdmObjectNode *objNode;
MdmParamNode *paramNode;
CmsRet ret=CMSRET_SUCCESS;;
INVALIDATE_ODL_GET_CACHE;
for (i=0; (i < numParamValues) && (ret == CMSRET_SUCCESS); i++)
{
PhlSetParamValue_t *paramEntry;
OdlSetQueueEntry *setEntry;
paramEntry = &(paramValueArray[i]);
paramEntry->status = CMSRET_SUCCESS;
if (i == 0)
{
/*
* make sure there is nothing left over in the set queue.
* If there is, free it, but we can still continue on.
* XXX is this too restrictive? This means we cannot call
* cmsPhl_set from inside RCL/STL/RUT. So far, not a problem.
*/
if (setQ.count > 0)
{
cmsLog_error("still (%d) entries left in the queue, free all.",
setQ.count);
cmsAst_assert(0);
freeSetQueue();
}
}
cmsLog_debug("getting oid %d param %s", paramEntry->pathDesc.oid, paramEntry->pathDesc.paramName);
if (((objNode = mdm_getObjectNode(paramEntry->pathDesc.oid)) == NULL) ||
((paramNode = mdm_getParamNode(paramEntry->pathDesc.oid, paramEntry->pathDesc.paramName)) == NULL))
{
paramEntry->status = CMSRET_INVALID_PARAM_NAME;
undoAllInstanceMovesUsingNewOrderValues();
freeSetQueue();
return CMSRET_INVALID_ARGUMENTS;
}
/* either find an existing set entry or create a new one */
if ((setEntry = getSetQueueEntry(objNode, &(paramEntry->pathDesc.iidStack))) == NULL)
{
cmsLog_error("alloc of setEntry failed.");
paramEntry->status = CMSRET_RESOURCE_EXCEEDED;
undoAllInstanceMovesUsingNewOrderValues();
freeSetQueue();
return CMSRET_RESOURCE_EXCEEDED;
}
if (setEntry->newMdmObj == NULL)
{
cmsLog_debug("new setEntry for oid %d %s %s",
setEntry->objNode->oid,
mdm_oidToGenericPath(setEntry->objNode->oid),
cmsMdm_dumpIidStack(&(setEntry->iidStack)));
numSetEntries++;
/*
* Use OGF_NO_VALUE_UPDATE to get the newMdmObj directly from MDM.
* Do not trigger the STL handler func since we only want
* the current state of the MDM object.
*/
ret = odl_getObject(setEntry->objNode->oid,
&(setEntry->iidStack),
OGF_NO_VALUE_UPDATE,
&(setEntry->newMdmObj));
if (ret != CMSRET_SUCCESS)
{
cmsLog_error("could not get mdmObject for %s %s, ret=%d",
mdm_oidToGenericPath(setEntry->objNode->oid),
cmsMdm_dumpIidStack(&(setEntry->iidStack)),
ret);
paramEntry->status = ret;
undoAllInstanceMovesUsingNewOrderValues();
freeSetQueue();
return ret;
}
else
{
setEntry->currMdmObj = mdm_dupObject(setEntry->newMdmObj, mdmLibCtx.allocFlags);
if ((setEntry->newMdmObj == NULL))
{
cmsLog_error("malloc failed when duping newMdmObj");
paramEntry->status = CMSRET_RESOURCE_EXCEEDED;
undoAllInstanceMovesUsingNewOrderValues();
freeSetQueue();
return CMSRET_RESOURCE_EXCEEDED;
}
}
}
/*
* Now modify the parameter in the newMdmObj.
* The PHL has already validated this string value, so by the
* time we get here, we know that paramEntry->pValue is valid.
*/
ret = mdm_setParamNodeString(paramNode, paramEntry->pValue, mdmLibCtx.allocFlags, setEntry->newMdmObj);
paramEntry->status = ret;
/*
* Check if we need to deal with auto order.
*/
if ((ret == CMSRET_SUCCESS) &&
(IS_AUTO_ORDER_NODE(objNode)) &&
!cmsUtl_strcmp(paramNode->name, "Order"))
{
UINT32 newOrderVal = mdm_getOrderValue(objNode, setEntry->newMdmObj);
cmsLog_debug("detected change, newOrderVal=%d", newOrderVal);
mdm_moveInstanceUsingNewOrderValue(objNode, &(setEntry->iidStack), newOrderVal);
setEntry->orderValueChanged = TRUE;
}
} /* end of for loop over paramValueArray */
/*
* At this point, we have a set queue filled with modified objects
* and ready to be sent to the RCL handler functions. The objects
* are put in the queue in the same order as they appeared in the
* paramValueArray. In the unlikely event that the ACS sent the objects
* in an order that is incompatible with the order that our system/
* RCL handler functions expect them to be in, we can modify the
* order of the objects in the queue at this point.
*/
if (ret == CMSRET_SUCCESS)
{
OdlSetQueueEntry *forwardSetEntry = setQ.head;
OdlSetQueueEntry *backwardSetEntry;
char *errorParam = NULL;
CmsRet errorCode = CMSRET_SUCCESS;
while ((forwardSetEntry != NULL) && (IS_CMSRET_A_SUCCESS_VARIANT(ret)))
{
cmsLog_debug("calling rcl for %s %s newObj=%p currObj=%p",
mdm_oidToGenericPath(forwardSetEntry->objNode->oid),
cmsMdm_dumpIidStack(&(forwardSetEntry->iidStack)),
forwardSetEntry->newMdmObj,
forwardSetEntry->currMdmObj);
ret = callSetHandlerFunc(forwardSetEntry->objNode,
&(forwardSetEntry->iidStack),
forwardSetEntry->newMdmObj,
forwardSetEntry->currMdmObj,
&errorParam,
&errorCode);
if (!(IS_CMSRET_A_SUCCESS_VARIANT(ret)))
{
/* now we have to find the errorParam in the paramValueArray
* that caused the error and set status appropriately.
*/
UBOOL8 foundErrorParam=FALSE;
PhlSetParamValue_t *paramEntry=NULL;
for (i=0; (i < numParamValues) && (!foundErrorParam); i++)
{
paramEntry = &(paramValueArray[i]);
if ((errorParam != NULL) &&
(forwardSetEntry->objNode->oid == paramEntry->pathDesc.oid) &&
(cmsMdm_compareIidStacks(&(forwardSetEntry->iidStack), &(paramEntry->pathDesc.iidStack)) == 0) &&
(!strcasecmp(paramEntry->pathDesc.paramName, errorParam)))
{
paramEntry->status = (errorCode != CMSRET_SUCCESS) ?
errorCode : ret;
if (!(IS_CMSRET_A_TR69C_VARIANT(paramEntry->status)))
{
paramEntry->status = CMSRET_INTERNAL_ERROR;
}
foundErrorParam = TRUE;
}
}
if (!foundErrorParam)
{
if (errorParam == NULL)
{
cmsLog_error("rcl did not specify error param name on error %d on %s",
ret,
mdm_oidToGenericPath(forwardSetEntry->objNode->oid));
}
else
{
cmsLog_error("could not find rcl returned error param name %s in %s",
errorParam,
mdm_oidToGenericPath(forwardSetEntry->objNode->oid));
}
/* find the first parameter name in the current object and
* assign error to that parameter.
*/
for (i=0; (i < numParamValues) && (!foundErrorParam); i++)
{
paramEntry = &(paramValueArray[i]);
if ((forwardSetEntry->objNode->oid == paramEntry->pathDesc.oid) &&
(cmsMdm_compareIidStacks(&(forwardSetEntry->iidStack), &(paramEntry->pathDesc.iidStack)) == 0))
{
paramEntry->status = ret;
if (!(IS_CMSRET_A_TR69C_VARIANT(paramEntry->status)))
{
paramEntry->status = CMSRET_INTERNAL_ERROR;
}
foundErrorParam = TRUE;
}
}
if (foundErrorParam)
{
cmsLog_error("setting error %d on %s",
paramEntry->status, paramEntry->pathDesc.paramName);
}
else
{
cmsLog_error("Could not even find the object to assign error to, %s %s!",
mdm_oidToGenericPath(forwardSetEntry->objNode->oid),
cmsMdm_dumpIidStack(&(forwardSetEntry->iidStack)));
cmsAst_assert(0);
}
}
/*
* Since we have failed, undo any re-ordering of the instances
* that we have done prior to the set. Must do this before
* reverseSetQueue.
*/
undoAllInstanceMovesUsingNewOrderValues();
/*
* Now we have to roll back by calling the rcl handler funcs
* which we have called with MdmObject parameters reversed.
*/
reverseSetQueue();
backwardSetEntry = forwardSetEntry->prev;
while (backwardSetEntry != NULL)
{
CmsRet backwardRet;
backwardRet = callSetHandlerFunc(backwardSetEntry->objNode,
&(backwardSetEntry->iidStack),
backwardSetEntry->newMdmObj,
backwardSetEntry->currMdmObj,
&errorParam,
&errorCode);
/*
* ret already contains the error encountered during the set.
* We don't much care about any errors encountered during
* the undo, except for CMSRET_FAIL_REBOOT_REQUIRED.
*/
if (backwardRet == CMSRET_FAIL_REBOOT_REQUIRED)
{
ret = backwardRet;
}
backwardSetEntry = backwardSetEntry->prev;
} /* end of while loop over backwardSetEntry */
}
forwardSetEntry = forwardSetEntry->next;
} /* end of while loop to set all entries in set queue */
if (IS_CMSRET_A_SUCCESS_VARIANT(ret))
{
/*
* All the RCL handler functions have returned success,
* so now we can update the MDM with all the objects.
*/
OdlSetQueueEntry *forwardSetEntry = setQ.head;
while (forwardSetEntry != NULL)
{
CmsRet r2;
r2 = mdm_setObject(&(forwardSetEntry->newMdmObj),
&(forwardSetEntry->iidStack), TRUE);
if (r2 != CMSRET_SUCCESS)
{
/*
* We've done all the checking up front (valid parameters,
* access list), so we know that mdm_setObject will succeed
* at this point.
*/
cmsLog_error("mdm_setObject unexpectedly failed! ret=%d", ret);
}
/* Also normalize the Order values, if applicable */
if (IS_AUTO_ORDER_NODE(forwardSetEntry->objNode) &&
forwardSetEntry->orderValueChanged)
{
mdm_normalizeOrderValues(forwardSetEntry->objNode,
&(forwardSetEntry->iidStack));
}
forwardSetEntry = forwardSetEntry->next;
}
}
} /* end of if case where we decide to call rcl set handler funcs */
if (setQ.count != numSetEntries)
{
/*
* Something is wrong. The number of setq entries should match what
* we created in this function. Complain, but keep going.
*/
cmsLog_error("Expected %d setQ entries, got %d",
numSetEntries, setQ.count);
}
/*
* Is this too restrictive? We assume we are not called from a
* RCL/STL/RUT function, which may have created its own setq entry.
* So far, this is not a problem.
*/
freeSetQueue();
cmsLog_debug("Done, ret=%d", ret);
return ret;
}
CmsRet odl_setObjectExternal(const void *newMdmObj, const InstanceIdStack *iidStack)
{
MdmObjectId oid;
MdmObjectNode *objNode;
void *currMdmObj;
CmsRet ret;
if ((newMdmObj == NULL) || (iidStack == NULL))
{
cmsLog_error("bad input args");
return CMSRET_INVALID_ARGUMENTS;
}
oid = *((MdmObjectId *) newMdmObj);
if ((objNode = mdm_getObjectNode(oid)) == NULL)
{
cmsLog_error("Could not find objNode for oid %d", oid);
return CMSRET_INVALID_ARGUMENTS;
}
ret = mdm_getObject(oid, iidStack, &currMdmObj);
if (ret != CMSRET_SUCCESS)
{
cmsLog_error("Could not get currMdmObj for oid %d", oid);
return ret;
}
if (getSetQueueCount() != 0)
{
cmsLog_error("At begin of function, expected 0 entries in setqueue, "
"but got %d, free anyways", getSetQueueCount());
freeSetQueue();
}
cmsLog_debug("starting new external set of %s iidStack=%s", objNode->name, cmsMdm_dumpIidStack(iidStack));
ret = odl_setObjectInternal(newMdmObj, currMdmObj, iidStack);
cmsObj_free((void **) &currMdmObj);
cmsLog_debug("finished external set of %s iidStack=%s", objNode->name, cmsMdm_dumpIidStack(iidStack));
if (getSetQueueCount() != 0)
{
cmsLog_error("At end of function, expected 0 entries in setqueue, "
"but got %d, free anyways", getSetQueueCount());
freeSetQueue();
}
return ret;
}
CmsRet odl_setObjectInternal(const void *newMdmObj,
const void *currMdmObj,
const InstanceIdStack *iidStack)
{
MdmObjectId oid;
MdmObjectNode *objNode;
void *dupedNewMdmObj;
char *errorParam=NULL;
OdlSetQueueEntry *setEntry;
UBOOL8 orderValueChanged=FALSE;
CmsRet ret, errorCode=CMSRET_SUCCESS;
if ((newMdmObj == NULL) || (iidStack == NULL))
{
cmsLog_error("bad input args");
return CMSRET_INVALID_ARGUMENTS;
}
oid = *((MdmObjectId *) newMdmObj);
if ((objNode = mdm_getObjectNode(oid)) == NULL)
{
return CMSRET_INVALID_ARGUMENTS;
}
/*
* Make sure the new object is valid. Note that unlike the PHL->odl_set path,
* where the params are validated in the PHL, in the OBJ->odl_setObjectxxx path,
* the object is validated in the ODL.
*/
if ((ret = mdm_validateObject(newMdmObj, iidStack)) != CMSRET_SUCCESS)
{
return ret;
}
if (findPointerInSetQueue(newMdmObj))
{
/*
* The MdmObj to be set is in the set queue. Just return
* success indication to the caller. The MdmObj will be pushed into
* the MDM by the original caller.
*/
cmsLog_debug("found %s (%p) iidStack=%s in SetQueue", objNode->name, newMdmObj, cmsMdm_dumpIidStack(iidStack));
return CMSRET_SUCCESS;
}
cmsLog_debug("starting new internal set of %s iidStack=%s", objNode->name, cmsMdm_dumpIidStack(iidStack));
INVALIDATE_ODL_GET_CACHE;
/*
* We need to dup the newMdmObj because we might modify it,
* and then steal it. But in order to allow rcl/rut functions
* to call cmsObj_set, the caller will pass in a const pointer
* to newMdmObj, not the address of the pointer to newMdmObj.
* So we need to operate on a local copy of newMdmObj, not the
* newMdmObj passed in by caller.
*/
if ((dupedNewMdmObj = mdm_dupObject(newMdmObj, mdmLibCtx.allocFlags)) == NULL)
{
return CMSRET_RESOURCE_EXCEEDED;
}
/*
* This will push our object into the setQueue.
* We do this so that if the rcl handler function for this object
* calls an rut function, and then the rut function calls cmsObj_get on
* this object again, it will see the new object with the new values to
* be set instead of the curr object inside the MDM.
*/
if ((setEntry = getSetQueueEntry(objNode, iidStack)) == NULL)
{
cmsLog_error("alloc of setEntry failed.");
cmsObj_free(&dupedNewMdmObj);
return CMSRET_RESOURCE_EXCEEDED;
}
setEntry->newMdmObj = dupedNewMdmObj;
setEntry->currMdmObj = (void *) currMdmObj;
/*
* If this is an Auto Order objNode, and the Order param has changed,
* we must re-order the objects before calling the RCL handler function.
* If currMdmObj is NULL, that means we are doing activateObjects during
* startup. Do not need to deal with order changes during this time.
*/
if (IS_AUTO_ORDER_NODE(objNode))
{
UINT32 newOrderVal, currOrderVal=0;
newOrderVal = mdm_getOrderValue(objNode, dupedNewMdmObj);
if (currMdmObj)
{
currOrderVal = mdm_getOrderValue(objNode, currMdmObj);
}
if ((currOrderVal != 0) && (currOrderVal != newOrderVal))
{
mdm_moveInstanceUsingNewOrderValue(objNode, iidStack, newOrderVal);
orderValueChanged = TRUE;
}
}
ret = callSetHandlerFunc(objNode, iidStack, dupedNewMdmObj, currMdmObj,
&errorParam, &errorCode);
CMSMEM_FREE_BUF_AND_NULL_PTR(errorParam);
/*
* The dupedNewMdmObj will be dealt with (freed, stolen, etc) below.
* The currMdmObj will be dealt with by the caller.
* So clear the reference to both from the setEntry so that when we
* call freeSetQueueEntry(), that function doesn't also free the objects.
*/
setEntry->newMdmObj = NULL;
setEntry->currMdmObj = NULL;
freeSetQueueEntry(&setEntry);
if (IS_CMSRET_A_SUCCESS_VARIANT(ret))
{
CmsRet r2;
/*
* Tell the MDM to replace the current MdmObj with new one.
* Note that if mdm_setObject succeeds, dupedNewMdmObj will be stolen
* by MDM.
* Also be careful with return values here: overwrite ret only if
* r2 is an error. Otherwise, ret could be CMSRET_SUCCESS_REBOOT_NEEDED,
* and r2 is CMSRET_SUCCESS.
*/
r2 = mdm_setObject(&dupedNewMdmObj, iidStack, TRUE);
if (r2 != CMSRET_SUCCESS)
{
ret = r2;
mdm_freeObject(&dupedNewMdmObj);
}
if (orderValueChanged)
{
mdm_normalizeOrderValues(objNode, iidStack);
}
}
else
{
if (orderValueChanged)
{
/* undo the re-order of the table based on new Order value */
UINT32 currOrderVal = mdm_getOrderValue(objNode, currMdmObj);
mdm_moveInstanceUsingNewOrderValue(objNode, iidStack, currOrderVal);
}
mdm_freeObject(&dupedNewMdmObj);
}
cmsLog_debug("finished internal set of %s iidStack=%s, ret=%d", objNode->name, cmsMdm_dumpIidStack(iidStack), ret);
return ret;
}
/*
* This function was added by Jeff to deal with a "order" parameter in one
* of the QoS objects that needs to be renumbered and compacted whenever
* one of them changes. The original odl_setObject function was causing
* a bunch of recursive calls to renumber and compact, so this function
* was created which modifies the MDM object only, but does not call
* the RCL handler function.
* Starting with 4.14L.04, the "autoOrder" attribute will cause the MDM
* to do auto ordering, so developers do not have to use this function
* to manually re-order the objects which contain an "Order" param anymore.
* See the code in odl_set and odl_setObjectInternal.
*/
CmsRet odl_setObjectNoRclCallback(const void *newMdmObj,
const InstanceIdStack *iidStack)
{
MdmObjectId oid;
MdmObjectNode *objNode;
void *dupedNewMdmObj;
CmsRet ret;
if ((newMdmObj == NULL) || (iidStack == NULL))
{
cmsLog_error("bad input args");
return CMSRET_INVALID_ARGUMENTS;
}
oid = *((MdmObjectId *) newMdmObj);
if ((objNode = mdm_getObjectNode(oid)) == NULL)
{
return CMSRET_INVALID_ARGUMENTS;
}
/*
* Make sure the new object is valid. Note that unlike the PHL->odl_set path,
* where the params are validated in the PHL, in the OBJ->odl_setObjectxxx path,
* the object is validated in the ODL.
*/
if ((ret = mdm_validateObject(newMdmObj, iidStack)) != CMSRET_SUCCESS)
{
return ret;
}
if (findPointerInSetQueue(newMdmObj))
{
/*
* The MdmObj to be set is in the set queue. Just return
* success indication to the caller. The MdmObj will be pushed into
* the MDM by the original caller.
*/
cmsLog_debug("found %s (%p) iidStack=%s in SetQueue", objNode->name, newMdmObj, cmsMdm_dumpIidStack(iidStack));
return CMSRET_SUCCESS;
}
cmsLog_debug("starting new NO_RCL_CALLBACK set of %s iidStack=%s", objNode->name, cmsMdm_dumpIidStack(iidStack));
INVALIDATE_ODL_GET_CACHE;
/*
* We need to dup the newMdmObj because mdm_setObject will steal it,
* but we told the caller he is responsible for freeing his object.
*/
if ((dupedNewMdmObj = mdm_dupObject(newMdmObj, mdmLibCtx.allocFlags)) == NULL)
{
return CMSRET_RESOURCE_EXCEEDED;
}
/*
* Tell the MDM to replace the current MdmObj with new one.
* Note that if mdm_setObject succeeds, the newMdmObj will be stolen
* by MDM.
*/
ret = mdm_setObject(&dupedNewMdmObj, iidStack, TRUE);
if (ret != CMSRET_SUCCESS)
{
mdm_freeObject(&dupedNewMdmObj);
}
return ret;
}
/** Call the handler function associated with the objNode, but do not
* update the mdmObject in the MDM yet.
*/
CmsRet callSetHandlerFunc(MdmObjectNode *objNode,
const InstanceIdStack *iidStack,
void *newMdmObj,
const void *currMdmObj,
char **errorParam,
CmsRet *errorCode)
{
MdmObjectId oid = objNode->oid;
const MdmOidInfoEntry *oidInfo;
CmsRet ret;
if ((oidInfo = mdm_getOidInfo(oid)) == NULL)
{
cmsLog_error("Could not find OID info for oid %d", oid);
ret = CMSRET_INTERNAL_ERROR;
}
else
{
if (oidInfo->rclHandlerFunc == NULL)
{
cmsLog_error("oid %d has NULL rcl handler func", oid);
ret = CMSRET_INTERNAL_ERROR;
}
else
{
ODL_RECORD_CALL_ENTRY('r', oid);
ret = oidInfo->rclHandlerFunc(newMdmObj, currMdmObj,
iidStack,
errorParam, errorCode);
ODL_RECORD_CALL_EXIT;
}
}
return ret;
}
void odl_setCleanup(void)
{
freeSetQueue();
return;
}
OdlSetQueueEntry *getSetQueueEntry(MdmObjectNode *objNode, const InstanceIdStack *iidStack)
{
OdlSetQueueEntry *entry = setQ.head;
UBOOL8 found = FALSE;
while ((!found) && (entry != NULL))
{
if ((objNode == entry->objNode) &&
(!(cmsMdm_compareIidStacks(iidStack, &(entry->iidStack)))))
{
found = TRUE;
}
else
{
entry = entry->next;
}
}
if (found)
{
return entry;
}
/*
* We did not find an existing SetQueueEntry for this objNode.
* Allocate it and append at the end of setQ.
* The entry is only used internally by ODL, so it does not need
* to be in shared mem.
*/
entry = cmsMem_alloc(sizeof(OdlSetQueueEntry), ALLOC_ZEROIZE);
if (entry != NULL)
{
entry->objNode = objNode;
entry->iidStack = *iidStack;
setQ.count++;
if (setQ.head == NULL)
{
setQ.head = entry;
setQ.tail = entry;
}
else
{
(setQ.tail)->next = entry;
entry->prev = setQ.tail;
setQ.tail = entry;
}
}
return entry;
}
UBOOL8 findInSetQueue(MdmObjectId oid, const InstanceIdStack *iidStack, void **mdmObj)
{
OdlSetQueueEntry *entry = setQ.head;
UBOOL8 found=FALSE;
while ((entry != NULL) && (!found))
{
if ((entry->objNode->oid == oid) &&
(!cmsMdm_compareIidStacks(&(entry->iidStack), iidStack)))
{
(*mdmObj) = entry->newMdmObj;
found = TRUE;
}
entry = entry->next;
}
return found;
}
UBOOL8 findPointerInSetQueue(const void *mdmObj)
{
OdlSetQueueEntry *entry = setQ.head;
UBOOL8 found=FALSE;
while ((entry != NULL) && (!found))
{
if (entry->newMdmObj == mdmObj)
{
found = TRUE;
}
entry = entry->next;
}
return found;
}
/** Reverse the position of the newMdmObj and currMdmObj in the set queue.
*
* This is done if an error was encountered as we are travelling forward
* in the set queue. Now we need to undo. We have to switch the position
* of the mdmObj in the set queue itself because the rcl handler functions
* may call the odl_get family of functions to get objects, and those
* odl_get functions will look in the set queue. Reversing the position
* of the mdmObj in the set queue itself allows the rcl handler functions
* to get the right mdmObj from the set queue.
*/
void reverseSetQueue(void)
{
OdlSetQueueEntry *entry = setQ.head;
void *tmpMdmObj;
while (entry != NULL)
{
tmpMdmObj = entry->newMdmObj;
entry->newMdmObj = entry->currMdmObj;
entry->currMdmObj = tmpMdmObj;
entry = entry->next;
}
return;
}
/** If an error occured while we are processing a bunch of "sets" from the
* PHL layer, we might have re-ordered one or more auto order tables
* during the set processing. Undo those re-orders.
*/
void undoAllInstanceMovesUsingNewOrderValues()
{
OdlSetQueueEntry *entry = setQ.head;
UINT32 origOrderVal;
while (entry != NULL)
{
if (entry->orderValueChanged && entry->currMdmObj)
{
origOrderVal = mdm_getOrderValue(entry->objNode, entry->currMdmObj);
mdm_moveInstanceUsingNewOrderValue(entry->objNode, &entry->iidStack,
origOrderVal);
entry->orderValueChanged = FALSE;
}
entry = entry->next;
}
}
void freeSetQueue(void)
{
OdlSetQueueEntry *entry = setQ.head;
OdlSetQueueEntry *tmpEntry;
while (entry != NULL)