File: sge_qinstance_qmaster.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-13.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 57,140 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,445; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,704; csh: 3,934; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (1310 lines) | stat: -rw-r--r-- 52,423 bytes parent folder | download | duplicates (6)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2001 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Portions of this software are Copyright (c) 2011 Univa Corporation
 *
 ************************************************************************/
/*___INFO__MARK_END__*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>

#include "uti/sge_rmon.h"
#include "uti/sge_log.h"
#include "uti/sge_time.h"
#include "uti/sge_signal.h"
#include "uti/sge_parse_num_par.h"

#include "sgeobj/sge_event.h"
#include "sgeobj/sge_qinstance.h"
#include "sgeobj/sge_qinstance_state.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_ja_task.h"
#include "sgeobj/sge_attr.h"
#include "sgeobj/sge_calendar.h"
#include "sgeobj/sge_centry.h"
#include "sgeobj/sge_answer.h"
#include "sgeobj/sge_cqueue.h"
#include "sgeobj/sge_object.h"
#include "sgeobj/sge_subordinate.h"
#include "sgeobj/sge_advance_reservation.h"
#include "sgeobj/sge_advance_reservation.h"
#include "sgeobj/sge_conf.h"

#include "sched/sge_resource_utilization.h"
#include "sched/sge_serf.h"

#include "sge.h"
#include "sge_event_master.h"
#include "sge_persistence_qmaster.h"
#include "sge_queue_event_master.h"
#include "sge_qinstance_qmaster.h"
#include "sge_subordinate_qmaster.h"
#include "sge_qmod_qmaster.h"
#include "sge_reporting_qmaster.h"
#include "sge_advance_reservation_qmaster.h"
#include "sge_calendar_qmaster.h"
#include "msg_qmaster.h"

typedef struct {
   u_long32 transition;
   long state_mask;
   bool (*has_state)(const lListElem *this_elem);
   bool is;
   bool (*set_state)(lListElem *this_elem, bool set); 
   bool set;
   const char *success_msg;
} change_state_t;

static bool
qinstance_change_state_on_calender_(sge_gdi_ctx_class_t *ctx,
                                    lListElem *qi_elem, u_long32 cal_order, 
                                    lList **state_change_list, monitoring_t *monitor);

bool
qinstance_modify_attribute(sge_gdi_ctx_class_t *ctx,
                           lListElem *this_elem, lList **answer_list,
                           const lListElem *cqueue, 
                           int attribute_name, 
                           int cqueue_attibute_name,
                           int sub_host_name, int sub_value_name,
                           int subsub_key, 
                           const char **matching_host_or_group,
                           const char **matching_group,
                           bool *is_ambiguous, 
                           bool *has_changed_conf_attr, 
                           bool *has_changed_state_attr,
                           const bool initial_modify,
                           bool *need_reinitialize,
                           monitoring_t *monitor)
{
#if 0 /* EB: DEBUG: enable debugging for qinstance_modify_attribute() */
#define QINSTANCE_MODIFY_DEBUG
#endif
   bool ret = true;
  
#ifdef QINSTANCE_MODIFY_DEBUG
   DENTER(TOP_LAYER, "qinstance_modify_attribute");
#else 
   DENTER(BASIS_LAYER, "qinstance_modify_attribute");
#endif

   if (this_elem != NULL && cqueue != NULL && 
      attribute_name != NoName && cqueue_attibute_name != NoName) {
      const char *hostname = lGetHost(this_elem, QU_qhostname);
      const lList *attr_list = lGetList(cqueue, cqueue_attibute_name);
      const lDescr *descr = lGetElemDescr(this_elem);
      int pos = lGetPosInDescr(descr, attribute_name);
      int type = lGetPosType(descr, pos);
      bool value_found = true;

      switch (cqueue_attibute_name) {
         case CQ_calendar:
            {
               const char *old_value = lGetString(this_elem, attribute_name);
               const char *new_value;

               str_attr_list_find_value(attr_list, answer_list,
                                        hostname, &new_value, 
                                        matching_host_or_group,
                                        matching_group, is_ambiguous);
               if (old_value == NULL || new_value == NULL ||
                   strcmp(old_value, new_value)) {
                  lList *master_calendar_list = 
                             *(object_type_get_master_list(SGE_TYPE_CALENDAR)); 
                  lListElem *calendar = 
                         calendar_list_locate(master_calendar_list, new_value);
  
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ" from "SFQ" to "SFQ"\n",
                           lNm2Str(attribute_name),
                           old_value ? old_value : "<null>",
                           new_value ? new_value : "<null>"));
#endif
                  /* check if the modification is possible or if
                   * an existing AR would be violated by the modification
                   */
                  if (!initial_modify && sge_ar_list_conflicts_with_calendar(answer_list, lGetString(this_elem, QU_full_name),
                                                      calendar, *object_type_get_master_list(SGE_TYPE_AR))) {
                     ret = false;
                     break;
                  }

                  if (calendar != NULL) { 
                     qinstance_change_state_on_calendar(ctx, this_elem, calendar, monitor);
                  } else {
                     sge_qmaster_qinstance_state_set_cal_disabled(this_elem, false);
                     sge_qmaster_qinstance_state_set_cal_suspended(this_elem, false);
                     lSetList(this_elem, QU_state_changes, NULL);
                  }
                  lSetString(this_elem, attribute_name, new_value);
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_qtype:
            {
               u_long32 old_value = lGetUlong(this_elem, attribute_name);
               u_long32 new_value;

               qtlist_attr_list_find_value(attr_list, answer_list, 
                                           hostname, &new_value,
                                           matching_host_or_group,
                                           matching_group,
                                           is_ambiguous);
               if (old_value != new_value) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ" from "sge_u32" to "sge_u32"\n",
                           lNm2Str(attribute_name), old_value, new_value));
#endif
                  lSetUlong(this_elem, attribute_name, new_value);
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_s_fsize:
         case CQ_h_fsize:
         case CQ_s_data:
         case CQ_h_data:
         case CQ_s_stack:
         case CQ_h_stack:
         case CQ_s_core:
         case CQ_h_core:
         case CQ_s_rss:
         case CQ_h_rss:
         case CQ_s_vmem:
         case CQ_h_vmem:
            {
               const char *old_value = lGetString(this_elem, attribute_name);
               const char *new_value = NULL;

               mem_attr_list_find_value(attr_list, answer_list, 
                                        hostname, &new_value, 
                                        matching_host_or_group,
                                        matching_group, is_ambiguous);
               if (old_value == NULL || new_value == NULL ||
                   strcmp(old_value, new_value)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ" from "SFQ" to "SFQ"\n",
                           lNm2Str(attribute_name),
                           old_value ? old_value : "<null>",
                           new_value ? new_value : "<null>")); 
#endif
                  lSetString(this_elem, attribute_name, new_value);
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_s_rt:
         case CQ_h_rt:
         case CQ_s_cpu:
         case CQ_h_cpu:
            {
               const char *old_value = lGetString(this_elem, attribute_name);
               const char *new_value = NULL;

               time_attr_list_find_value(attr_list, answer_list, 
                                         hostname, &new_value, 
                                         matching_host_or_group,
                                         matching_group,
                                         is_ambiguous);

               if (old_value == NULL || new_value == NULL ||
                   strcmp(old_value, new_value)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ" from "SFQ" to "SFQ"\n",
                           lNm2Str(attribute_name),
                           old_value ? old_value : "<null>",
                           new_value ? new_value : "<null>")); 
#endif
                  lSetString(this_elem, attribute_name, new_value);
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_suspend_interval:
         case CQ_min_cpu_interval:
         case CQ_notify:
            {
               const char *old_value = lGetString(this_elem, attribute_name);
               const char *new_value = NULL;

               inter_attr_list_find_value(attr_list, answer_list, 
                                          hostname, &new_value, 
                                          matching_host_or_group,
                                          matching_group, is_ambiguous);
               if (old_value == NULL || new_value == NULL ||
                   strcmp(old_value, new_value)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ" from "SFQ" to "SFQ"\n",
                           lNm2Str(attribute_name),
                           old_value ? old_value : "<null>",
                           new_value ? new_value : "<null>"));
#endif
                  if (attribute_name == QU_suspend_interval &&
                      new_value != NULL) {
                     u_long32 interval;

                     parse_ulong_val(NULL, &interval, TYPE_TIM,
                                     new_value, NULL, 0);
                     if (interval == 0) {
                        /*
                         * Suspend Threshold state will be reset later 
                         */
                        lSetUlong(this_elem, QU_gdi_do_later, GDI_DO_LATER); 
                     }
                  }
                       
                  lSetString(this_elem, attribute_name, new_value);
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_ckpt_list:
         case CQ_pe_list:
            {
               lList *old_value = lGetList(this_elem, attribute_name);
               lList *new_value = NULL;

               strlist_attr_list_find_value(attr_list, answer_list,
                                            hostname, &new_value, 
                                            matching_host_or_group,
                                            matching_group, is_ambiguous);
               if (object_list_has_differences(old_value, answer_list, 
                                               new_value, false)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ"\n", lNm2Str(attribute_name)));
#endif
                  /*
                   * check if the modification is possible or if 
                   * an existing AR violates that modification
                   */
                  if (cqueue_attibute_name == CQ_ckpt_list &&
                      ar_list_has_reservation_due_to_ckpt(
                           *object_type_get_master_list(SGE_TYPE_AR), answer_list, 
                           lGetString(this_elem, QU_full_name), new_value)) {
                     ret = false;
                     break;
                  } else if (!initial_modify && cqueue_attibute_name == CQ_pe_list &&
                             ar_list_has_reservation_due_to_pe(
                                 *object_type_get_master_list(SGE_TYPE_AR), answer_list,
                                 lGetString(this_elem, QU_full_name), new_value)) {
                     ret = false;
                     break;
                  }

                  lSetList(this_elem, attribute_name, lCopyList("", new_value));
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_owner_list:
         case CQ_acl:
         case CQ_xacl:
            {
               lList *old_value = lGetList(this_elem, attribute_name);
               lList *new_value = NULL;
   
               usrlist_attr_list_find_value(attr_list, answer_list,
                                            hostname, &new_value, 
                                            matching_host_or_group,
                                            matching_group, is_ambiguous);
               if (object_list_has_differences(old_value, answer_list,
                                               new_value, false)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ"\n", lNm2Str(attribute_name)));
#endif
                  lSetList(this_elem, attribute_name, lCopyList("", new_value));
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_projects:
         case CQ_xprojects:
            {
               lList *old_value = lGetList(this_elem, attribute_name);
               lList *new_value = NULL;

               prjlist_attr_list_find_value(attr_list, answer_list,
                                            hostname, &new_value, 
                                            matching_host_or_group,
                                            matching_group, is_ambiguous);
               if (object_list_has_differences(old_value, answer_list,
                                               new_value, false)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ"\n", lNm2Str(attribute_name)));
#endif
                  lSetList(this_elem, attribute_name, lCopyList("", new_value));
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_job_slots:
            {
               u_long32 old_value = lGetUlong(this_elem, attribute_name);
               u_long32 new_value;

               ulng_attr_list_find_value(attr_list, answer_list, hostname, 
                                         &new_value, 
                                         matching_host_or_group,
                                         matching_group, is_ambiguous);
               if (old_value != new_value) {
                  int slots_reserved = qinstance_slots_reserved(this_elem);
                  DPRINTF(("reserved slots %d\n", slots_reserved));
                  if (!initial_modify && new_value < slots_reserved) {
                     answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
                                             MSG_QINSTANCE_SLOTSRESERVED_USS, slots_reserved,
                                             lGetString(this_elem, QU_qname), hostname);
                     ret &= false;
                  } else {
#ifdef QINSTANCE_MODIFY_DEBUG
                     DPRINTF(("Changed "SFQ" from "sge_u32" to "sge_u32"\n",
                              lNm2Str(attribute_name),
                              old_value, new_value));
#endif
                     lSetUlong(this_elem, attribute_name, new_value);
                     *has_changed_conf_attr = true;
                     if (need_reinitialize != NULL) {
                        *need_reinitialize = true;
                     }
                  }
               }
            }
            break;
         case CQ_consumable_config_list:
            {
               lList *old_value = lGetList(this_elem, attribute_name);
               lList *new_value = NULL;
               bool created_new_value = false;
               lList *master_centry_list = *object_type_get_master_list(SGE_TYPE_CENTRY);

               celist_attr_list_find_value(attr_list, answer_list,
                                           hostname, &new_value, 
                                           matching_host_or_group,
                                           matching_group, is_ambiguous);

               if (centry_list_fill_request(new_value, answer_list, master_centry_list, 
                                        true, true, false) == 0) {
                  lListElem *slots_ce = NULL;

                  /* implicit slots entry */
                  if (lGetElemStr(new_value, CE_name, "slots") == NULL) {
                     lList *cq_slots_attr = lGetList(cqueue, CQ_job_slots);
                     u_long32 slots_value;
                     dstring buffer = DSTRING_INIT;

                     ulng_attr_list_find_value(cq_slots_attr, answer_list, hostname, 
                                               &slots_value, 
                                               matching_host_or_group,
                                               matching_group, is_ambiguous);
                     sge_dstring_sprintf(&buffer, sge_u32, slots_value);

                     if (new_value == NULL) {
                        created_new_value = true;
                     }
                     slots_ce = lAddElemStr(&new_value, CE_name, "slots", CE_Type);
                     lSetDouble(slots_ce, CE_doubleval, slots_value);
                     lSetString(slots_ce, CE_stringval, sge_dstring_get_string(&buffer));
                     sge_dstring_free(&buffer);
                  }
                  
                  if (object_list_has_differences(old_value, answer_list,
                                                  new_value, false)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                     DPRINTF(("Changed "SFQ"\n", lNm2Str(attribute_name)));
#endif
                     if (!initial_modify && ar_list_has_reservation_due_to_qinstance_complex_attr(*object_type_get_master_list(SGE_TYPE_AR), answer_list, 
                                                                                this_elem, *object_type_get_master_list(SGE_TYPE_CENTRY))) {
                        ret = false;
                     } else {
                        if (need_reinitialize != NULL) {
                           *need_reinitialize = true;
                        }

                        lSetList(this_elem, attribute_name, lCopyList("", new_value));
                        *has_changed_conf_attr = true;
                     }
                  }
                  lRemoveElem(new_value, &slots_ce);
               } else {
                   ret &= false;
               }
               if (created_new_value) {
                  lFreeList(&new_value);
               }
            }
            break;
         case CQ_load_thresholds:
         case CQ_suspend_thresholds:
            {
               lList *old_value = lGetList(this_elem, attribute_name);
               lList *new_value = NULL;

               celist_attr_list_find_value(attr_list, answer_list,
                                           hostname, &new_value, 
                                           matching_host_or_group,
                                           matching_group, is_ambiguous);
               if (object_list_has_differences(old_value, answer_list,
                                               new_value, false)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ"\n", lNm2Str(attribute_name)));
#endif
                  /*
                   * Suspend Threshold state will be reset later 
                   */
                  if (attribute_name == QU_suspend_thresholds) {
                     lSetUlong(this_elem, QU_gdi_do_later, GDI_DO_LATER);
                  }
   
                  lSetList(this_elem, attribute_name, lCopyList("", new_value));
                  *has_changed_conf_attr = true;
               }
            }
            break;
         case CQ_subordinate_list:
            {
               lList *old_value = NULL;          /* SO_Type list */
               lList *new_value = NULL;          /* SO_Type list */

               old_value = lGetList(this_elem, attribute_name);
               solist_attr_list_find_value(attr_list, answer_list,
                                           hostname, &new_value, 
                                           matching_host_or_group,
                                           matching_group, is_ambiguous);
               if (object_list_has_differences(old_value, answer_list, new_value, false)) {
                  lList *master_list = *(object_type_get_master_list(SGE_TYPE_CQUEUE));
                  lList *unsuspended_so = NULL;  /* SO_Type list */
                  lList *suspended_so = NULL;    /* SO_Type list */
                  lListElem *first_old_elem = NULL;
                  lListElem *first_new_elem = NULL;
                  bool valid_config = false;

                  /*
                   * check slotwise subordinations
                   */
                  /*
                   * Check if there are loops in the slotwise subordination tree.
                   */
                  lList *old_value_copy = NULL;  /* SO_Type list */
                  lList *new_value_copy = NULL;  /* SO_Type list */

                  old_value_copy = lCopyList("copy_old", old_value);
                  new_value_copy = lCopyList("copy_new", new_value);

                  /*
                   * Find all queues that were slotwise subordinated before
                   * and are no longer subordinated now and trigger them.
                   */
                  lDiffListStr(SO_name, &old_value_copy, &new_value_copy);
                  valid_config = check_new_slotwise_subordinate_tree(this_elem,
                                                    new_value_copy, answer_list);

                  lFreeList(&old_value_copy);
                  lFreeList(&new_value_copy);

                  if (valid_config == false) {
                     ret = false;
                     break;
                  }

                  /*
                   * Detect queues that are no longer subordinated to this queue and
                   * trigger recalculation for them.
                   */
                  hostname = lGetHost(this_elem, QU_qhostname);
                  first_old_elem = lFirst(old_value);
                  first_new_elem = lFirst(new_value);

                  if (first_old_elem != NULL && lGetUlong(first_old_elem, SO_slots_sum) > 0 &&
                      first_new_elem != NULL && lGetUlong(first_new_elem, SO_slots_sum) == 0) {
                      /*
                       * If there was slotwise preemption configured before and there is
                       * either no subordination or queue wise subordination configured
                       * now, unsuspend all tasks. Queue wise subordination will be
                       * calculated in the "classic"  section below.
                       */
                      unsuspend_all_tasks_in_slotwise_sub_tree(ctx, this_elem, monitor);
                  } else {
                     /*
                      * If there was slotwise preemption configured and is still slotwise
                      * preemption configured, unsuspend all task in the dechained queues.
                      * New suspension will be calculated in cqueue_success().
                      */

                     /*
                      * Find all queues that were slotwise subordinated before,
                      * are still slotwise subordinated but have different
                      * seq_no now.
                      * TODO: HP: Make sure these two lDiffListUlong() always
                      *           return the results we expect!
                      */
                     if (do_slotwise_subordinate_lists_differ(old_value, new_value) == true) { 
                        /*
                         * unsuspend all tasks in the whole subtree, new suspends will
                         * be calculated in cqueue_success().
                         */
                        unsuspend_all_tasks_in_slotwise_sub_tree(ctx, this_elem, monitor);
                     }
                  }

                  /*
                   * check "classic" queuewise subordinations
                   */
#ifdef QINSTANCE_MODIFY_DEBUG
                  DPRINTF(("Changed "SFQ"\n", lNm2Str(attribute_name)));
#endif

                  /*
                   * Find list of subordinates that are suspended currently 
                   *
                   * This queue can't have any running jobs and thus can't
                   * subordinate anything if the queue was freshly added
                   */
                  if (initial_modify == false) {
                     qinstance_find_suspended_subordinates(this_elem,
                                                           answer_list,
                                                           &unsuspended_so);
                  }

                  /*
                   * Modify sublist
                   */
                  lSetList(this_elem, attribute_name, lCopyList("", new_value));
                  *has_changed_conf_attr = true;

                  if (initial_modify == false) {
                     /*
                      * Find list of subordinates that have to be suspended after
                      * the modification of CQ_subordinate_list-sublist 
                      */
                     qinstance_find_suspended_subordinates(this_elem,
                                                                  answer_list,
                                                                  &suspended_so);

                     /* 
                      * Remove equal entries in both lists 
                      */
                     lDiffListStr(SO_name, &suspended_so, &unsuspended_so);
                     
                     /*
                      * (Un)suspend subordinated queue instances
                      */
                     cqueue_list_x_on_subordinate_so(ctx,
                                                     master_list, answer_list, 
                                                     false, unsuspended_so, monitor);
                     cqueue_list_x_on_subordinate_so(ctx,
                                                     master_list, answer_list, 
                                                     true, suspended_so, monitor);
                  }

                  /*
                   * Cleanup
                   */
                  lFreeList(&suspended_so);
                  lFreeList(&unsuspended_so);
               }
            }
            break;
         default:
            value_found = false;
            break;
      }

      if (!value_found) {
         switch (type) {
            case lStringT:
               {
                  const char *old_value = lGetString(this_elem, attribute_name);
                  const char *new_value = NULL;

                  str_attr_list_find_value(attr_list, answer_list,
                                           hostname, &new_value, 
                                           matching_host_or_group,
                                           matching_group, is_ambiguous);
                  if (old_value == NULL || new_value == NULL ||
                      strcmp(old_value, new_value)) {
#ifdef QINSTANCE_MODIFY_DEBUG
                     DPRINTF(("Changed "SFQ" from "SFQ" to "SFQ"\n",
                              lNm2Str(attribute_name),
                              old_value ? old_value : "<null>",
                              new_value ? new_value : "<null>"));
#endif
                     lSetString(this_elem, attribute_name, new_value);
                     *has_changed_conf_attr = true;
                  }
               }
               break;
            case lUlongT:
               {
                  u_long32 old_value = lGetUlong(this_elem, attribute_name);
                  u_long32 new_value;

                  ulng_attr_list_find_value(attr_list, answer_list, hostname, 
                                            &new_value, 
                                            matching_host_or_group,
                                            matching_group, is_ambiguous);
                  if (old_value != new_value) {
#ifdef QINSTANCE_MODIFY_DEBUG
                     DPRINTF(("Changed "SFQ" from "sge_u32" to "sge_u32"\n",
                              lNm2Str(attribute_name),
                              old_value, new_value));
#endif
                     lSetUlong(this_elem, attribute_name, new_value);
                     *has_changed_conf_attr = true;
                     if (attribute_name == QU_nsuspend &&
                                new_value == 0) {
                        /*
                         * Suspend Threshold state will be reset later 
                         */

                        lSetUlong(this_elem, QU_gdi_do_later, GDI_DO_LATER);
                     }
                  }
               }
               break;
            case lBoolT:
               {
                  bool old_value = lGetBool(this_elem, attribute_name) ? true : false;
                  bool new_value;

                  bool_attr_list_find_value(attr_list, answer_list,
                                            hostname, &new_value, 
                                            matching_host_or_group,
                                            matching_group, is_ambiguous);
                  if (old_value != new_value) {
#ifdef QINSTANCE_MODIFY_DEBUG
                     DPRINTF(("Changed "SFQ" from "SFQ" to "SFQ"\n",
                              lNm2Str(attribute_name),
                              (old_value ? "true" : "false"),
                              (new_value ? "true" : "false")));
#endif
                     lSetBool(this_elem, attribute_name, new_value);
                     *has_changed_conf_attr = true;
                  }
               }
               break;
            default:
               DPRINTF(("unhandled attribute\n"));
               break;
         }
      }
   }
   DRETURN(ret);
}

bool
qinstance_change_state_on_command(sge_gdi_ctx_class_t *ctx,
                                  lListElem *this_elem, lList**answer_list,
                                  u_long32 transition, bool force_transition,
                                  const char *user, const char *host,
                                  bool is_operator, bool is_owner, monitoring_t *monitor)
{
   bool ret = true;
   dstring buffer = DSTRING_INIT;
   const char *qinstance_name = qinstance_get_name(this_elem, &buffer);
   change_state_t transitions[] = {
      { QI_DO_CLEARERROR,     ~QI_ERROR,     qinstance_state_is_error,            true,  sge_qmaster_qinstance_state_set_error,            false, NULL},
      { QI_DO_ENABLE,         ~QI_DISABLED,  qinstance_state_is_manual_disabled,  true,  sge_qmaster_qinstance_state_set_manual_disabled,  false, NULL},
      { QI_DO_DISABLE,        QI_DISABLED,   qinstance_state_is_manual_disabled,  false, sge_qmaster_qinstance_state_set_manual_disabled,  true, NULL},
      { QI_DO_SUSPEND,        QI_SUSPENDED,  qinstance_state_is_manual_suspended, false, sge_qmaster_qinstance_state_set_manual_suspended, true, NULL},
      { QI_DO_UNSUSPEND,      ~QI_SUSPENDED, qinstance_state_is_manual_suspended, true,  sge_qmaster_qinstance_state_set_manual_suspended, false, NULL},
#ifdef __SGE_QINSTANCE_STATE_DEBUG__
      { QI_DO_SETERROR,       QI_ERROR,      qinstance_state_is_error,            false, sge_qmaster_qinstance_state_set_error,            true, NULL},
      { QI_DO_SETORPHANED,    QI_ORPHANED,   qinstance_state_is_orphaned,         false, sge_qmaster_qinstance_state_set_orphaned,         true, NULL},
      { QI_DO_CLEARORPHANED,  ~QI_ORPHANED,  qinstance_state_is_orphaned,         true,  sge_qmaster_qinstance_state_set_orphaned,         false, NULL},
      { QI_DO_SETUNKNOWN,     QI_UNKNOWN,    qinstance_state_is_unknown,          false, sge_qmaster_qinstance_state_set_unknown,          true, NULL},
      { QI_DO_CLEARUNKNOWN,   ~QI_UNKNOWN,   qinstance_state_is_unknown,          true,  sge_qmaster_qinstance_state_set_unknown,          false, NULL},
      { QI_DO_SETAMBIGUOUS,   QI_AMBIGUOUS,  qinstance_state_is_ambiguous,        false, sge_qmaster_qinstance_state_set_ambiguous,        true, NULL},
      { QI_DO_CLEARAMBIGUOUS, ~QI_AMBIGUOUS, qinstance_state_is_ambiguous,        true,  sge_qmaster_qinstance_state_set_ambiguous,        false, NULL},
#endif
      { QI_DO_NOTHING,        0,             NULL,                                true,  NULL,                                 true, NULL}
   };

   DENTER(TOP_LAYER, "qinstance_change_state_on_command");
   if (is_owner || is_operator) {
      int i = 0;

      while (transitions[i].transition != QI_DO_NOTHING) {
         if (transitions[i].transition == transition) {
            break;
         }
         i++;
      }

      /*
       * Verify current state
       */
      if (transitions[i].has_state(this_elem) == transitions[i].is ||
          force_transition) {
         bool did_something = false;

         DTRACE;

         /*
          * Some transitions need extra work
          */
          switch(transition){
            case QI_DO_SUSPEND : 
                  if ((!qinstance_state_is_susp_on_sub(this_elem) &&
                       !qinstance_state_is_cal_suspended(this_elem)) ||
                      force_transition) {
                     sge_signal_queue(ctx, SGE_SIGSTOP, this_elem, NULL, NULL, monitor);
                     did_something = true;
                  }   
               break;
            case QI_DO_UNSUSPEND :    
                  if (!qinstance_state_is_susp_on_sub(this_elem) &&
                      !qinstance_state_is_cal_suspended(this_elem)) {
                     sge_signal_queue(ctx, SGE_SIGCONT, this_elem, NULL, NULL, monitor);
                     did_something = true;
                  }   
               break;
            case QI_DO_CLEARERROR :
                  qinstance_message_trash_all_of_type_X(this_elem, QI_ERROR);
                  did_something = true;
               break;   
#ifdef __SGE_QINSTANCE_STATE_DEBUG__
            case QI_DO_SETERROR :
                 qinstance_message_add(this_elem, QI_ERROR, "this is a debug message\n");
                 did_something = true;
               break;  
#endif                  
            default:   
                  did_something = true;
         }
      
         /*
          * Change state
          */
         if (did_something) {
            transitions[i].set_state(this_elem, transitions[i].set);
         }

         /*
          * Make changes persistent
          */
         if (did_something) {
            qinstance_increase_qversion(this_elem);
            ret &= sge_event_spool(ctx,
                                   answer_list, 0, sgeE_QINSTANCE_MOD,
                                   0, 0, lGetString(this_elem, QU_qname),
                                   lGetHost(this_elem, QU_qhostname), NULL,
                                   this_elem, NULL, NULL, true, true);

            if (ret) {
               if (force_transition) {
                  INFO((SGE_EVENT, MSG_QINSTANCE_FORCEDSTATE_SSSS,
                        user, host, qinstance_name, 
                        qinstance_state_as_string(transitions[i].state_mask)));
               } else {
                  INFO((SGE_EVENT, MSG_QINSTANCE_CHANGEDST_SSSS,
                        user, host, qinstance_name, 
                        qinstance_state_as_string(transitions[i].state_mask)));
               }
               answer_list_add(answer_list, SGE_EVENT,
                               STATUS_OK, ANSWER_QUALITY_INFO);
            } else {
               ERROR((SGE_EVENT, MSG_QINSTANCE_STATENOTMOD_S, qinstance_name));
               answer_list_add(answer_list, SGE_EVENT,
                               STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);

               /*
                * Rollback
                */
               if (!force_transition) {
                  transitions[i].set_state(this_elem, transitions[i].set ? false : true);
               }
            }
         }
      } else {
         INFO((SGE_EVENT, MSG_QINSTANCE_HASSTATE_SS, qinstance_name, 
               qinstance_state_as_string(transitions[i].state_mask)));
         answer_list_add(answer_list, SGE_EVENT,
                         STATUS_ESEMANTIC, ANSWER_QUALITY_WARNING);
      }
   } else {
      WARNING((SGE_EVENT, MSG_QINSTANCE_STATENOTMODPERM_S, qinstance_name));
      answer_list_add(answer_list, SGE_EVENT,
                      STATUS_ESEMANTIC, ANSWER_QUALITY_WARNING);
   }
   sge_dstring_free(&buffer);
   DEXIT;
   return ret;
}


/****** sge_qinstance_qmaster/qinstance_change_state_on_calendar() *************
*  NAME
*     qinstance_change_state_on_calendar() --- changes the state of a given qi (wraper)
*
*  SYNOPSIS
*     bool qinstance_change_state_on_calendar(lListElem *this_elem, const 
*     lListElem *calendar) 
*
*  FUNCTION
*     Changes the state of a given qi based on its calendar.
*
*  INPUTS
*     lListElem *this_elem      - quinstance
*     const lListElem *calendar - calendar
*
*  RESULT
*     bool - state got changed or not
*
*  NOTES
*     MT-NOTE: qinstance_change_state_on_calendar() is MT safe 
*
*******************************************************************************/
bool qinstance_change_state_on_calendar(sge_gdi_ctx_class_t *ctx,
             lListElem *this_elem, const lListElem *calendar, monitoring_t *monitor)
{
   bool ret = true;

   DENTER(TOP_LAYER, "qinstance_change_state_on_calendar");

   if (this_elem != NULL && calendar != NULL) {
      lList *state_changes_list = NULL;
      u_long32 state;
      time_t when = 0; 

      state = calender_state_changes(calendar, &state_changes_list, &when, NULL);

      ret = qinstance_change_state_on_calender_(ctx, this_elem, state, &state_changes_list, monitor);

   }
   DRETURN(ret);
}

/****** sge_qinstance_qmaster/qinstance_change_state_on_calendar_all() *********
*  NAME
*     qinstance_change_state_on_calendar_all() -- changes the state of all qis (wraper)
*
*  SYNOPSIS
*     bool qinstance_change_state_on_calendar_all(const char* cal_name, 
*     u_long32 cal_order, const lList *state_change_list) 
*
*  FUNCTION
*     ??? 
*
*  INPUTS
*     const char* cal_name     - calendar name
*     u_long32 cal_order       - calendar state (todo)
*     const lList *state_change_list - state list for the qis
*
*  RESULT
*     bool - true, if it worked
*
*  NOTES
*     MT-NOTE: qinstance_change_state_on_calendar_all() is not MT safe 
*     Directly access the cluster queue list
*
*******************************************************************************/
bool qinstance_change_state_on_calendar_all(sge_gdi_ctx_class_t *ctx,
                                            const char* cal_name, u_long32 cal_order, 
                                            const lList *state_change_list, monitoring_t *monitor)
{
   bool ret = true;
   lListElem *cqueue;

   DENTER(TOP_LAYER, "qinstance_signal_on_calendar_all");

   for_each (cqueue, *(object_type_get_master_list(SGE_TYPE_CQUEUE))) {
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
      lListElem *qinstance = NULL;

      for_each(qinstance, qinstance_list) {
         const char *queue_calendar = lGetString(qinstance, QU_calendar);

         if (queue_calendar != NULL && !strcmp(queue_calendar, cal_name)) {
            lList *copy_state_change_list = lCopyList("state list", state_change_list);
            ret = qinstance_change_state_on_calender_(ctx, qinstance, cal_order, &copy_state_change_list, monitor);
         }
      }
   }

   DEXIT;
   return ret;
}

/****** sge_qinstance_qmaster/qinstance_change_state_on_calender_() ************
*  NAME
*     qinstance_change_state_on_calender_() -- changes qi state based on calendar
*
*  SYNOPSIS
*     static bool qinstance_change_state_on_calender_(lListElem *this_elem, 
*     u_long32 cal_order, lList **state_change_list) 
*
*  FUNCTION
*     ??? 
*
*  INPUTS
*     lListElem *this_elem     - qi
*     u_long32 cal_order       - next state (order)
*     lList **state_change_list - qi state list
*
*  RESULT
*     static bool - true, if it worked
*
*  NOTES
*     MT-NOTE: qinstance_change_state_on_calender_() is MT safe 
*
*******************************************************************************/
static bool qinstance_change_state_on_calender_(sge_gdi_ctx_class_t *ctx,
                                                lListElem *this_elem, u_long32 cal_order, 
                                                lList **state_change_list, monitoring_t *monitor) 
{
   bool ret = true;
   bool old_cal_disabled = qinstance_state_is_cal_disabled(this_elem);
   bool old_cal_suspended = qinstance_state_is_cal_suspended(this_elem);
   bool new_cal_disabled = (cal_order == QI_DO_CAL_DISABLE) ? true : false;
   bool new_cal_suspended = (cal_order == QI_DO_CAL_SUSPEND) ? true : false;

   DENTER(TOP_LAYER, "qinstance_signal_on_calendar_");

   lSetList(this_elem, QU_state_changes, *state_change_list);
   *state_change_list = NULL;

   if (old_cal_disabled != new_cal_disabled) {
      sge_qmaster_qinstance_state_set_cal_disabled(this_elem, new_cal_disabled);
   }
   
   if (old_cal_suspended != new_cal_suspended) {
      const char *name = lGetString(this_elem, QU_full_name);

      sge_qmaster_qinstance_state_set_cal_suspended(this_elem, new_cal_suspended);
      if (new_cal_suspended) {
         if (qinstance_state_is_susp_on_sub(this_elem)) {
            INFO((SGE_EVENT, MSG_QINSTANCE_NOUSSOS_S, name));
         } else if (qinstance_state_is_manual_suspended(this_elem)) {
            INFO((SGE_EVENT, MSG_QINSTANCE_NOUSADM_S, name));
         } else {
            sge_signal_queue(ctx, SGE_SIGSTOP, this_elem, NULL, NULL, monitor);
         }
      } else {
         if (qinstance_state_is_susp_on_sub(this_elem)) {
            INFO((SGE_EVENT, MSG_QINSTANCE_NOSSOS_S, name));
         } else if (qinstance_state_is_manual_suspended(this_elem)) {
            INFO((SGE_EVENT, MSG_QINSTANCE_NOSADM_S, name));
         } else {
            sge_signal_queue(ctx, SGE_SIGCONT, this_elem, NULL, NULL, monitor);
         }
      }
   }

   qinstance_add_event(this_elem, sgeE_QINSTANCE_MOD);

   DRETURN(ret);
}


bool
sge_qmaster_qinstance_state_set_alarm(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_alarm(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
   }

   return changed;
}

bool
sge_qmaster_qinstance_state_set_suspend_alarm(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_suspend_alarm(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
   }

   return changed;
}

bool
sge_qmaster_qinstance_state_set_manual_disabled(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_manual_disabled(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
      sge_ar_list_set_error_state(*object_type_get_master_list(SGE_TYPE_AR),
                                  lGetString(this_elem, QU_full_name), 
                                  QI_DISABLED,
                                  set_state);
   }


   return changed;
}

bool
sge_qmaster_qinstance_state_set_manual_suspended(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_manual_suspended(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
      sge_ar_list_set_error_state(*object_type_get_master_list(SGE_TYPE_AR),
                                  lGetString(this_elem, QU_full_name), 
                                  QI_SUSPENDED,
                                  set_state);
   }


   return changed;
}

bool
sge_qmaster_qinstance_state_set_unknown(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_unknown(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
      if (mconf_get_simulate_execds()) {
         sge_ar_list_set_error_state(*object_type_get_master_list(SGE_TYPE_AR),
                                        lGetString(this_elem, QU_full_name), 
                                        QI_UNKNOWN,
                                        false);
      } else {
         sge_ar_list_set_error_state(*object_type_get_master_list(SGE_TYPE_AR),
                                        lGetString(this_elem, QU_full_name), 
                                        QI_UNKNOWN,
                                        set_state);
      }
   }


   return changed;
}

bool
sge_qmaster_qinstance_state_set_error(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_error(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
      sge_ar_list_set_error_state(*object_type_get_master_list(SGE_TYPE_AR),
                                  lGetString(this_elem, QU_full_name), 
                                  QI_ERROR,
                                  set_state);
   }


   return changed;
}

bool
sge_qmaster_qinstance_state_set_susp_on_sub(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_susp_on_sub(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
   }

   return changed;
}

bool
sge_qmaster_qinstance_state_set_cal_disabled(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_cal_disabled(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
   }

   return changed;
}

bool
sge_qmaster_qinstance_state_set_cal_suspended(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_cal_suspended(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
   }

   return changed;
}

bool
sge_qmaster_qinstance_state_set_orphaned(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_orphaned(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
   }

   return changed;
}

bool
sge_qmaster_qinstance_state_set_ambiguous(lListElem *this_elem, bool set_state)
{
   bool changed;
   changed = qinstance_state_set_ambiguous(this_elem, set_state);
   if (changed) {
      reporting_create_queue_record(NULL, this_elem, sge_get_gmt());
      sge_ar_list_set_error_state(*object_type_get_master_list(SGE_TYPE_AR),
                                  lGetString(this_elem, QU_full_name), 
                                  QI_AMBIGUOUS,
                                  set_state);
   }


   return changed;
}

/* ret: did the state change */
bool
sge_qmaster_qinstance_set_initial_state(lListElem *this_elem)
{
   bool ret = false;
   const char *state_string = lGetString(this_elem, QU_initial_state);

#ifdef QINSTANCE_MODIFY_DEBUG
   DENTER(TOP_LAYER, "sge_qmaster_qinstance_set_initial_state");
#else 
   DENTER(BASIS_LAYER, "sge_qmaster_qinstance_set_initial_state");
#endif

   if (state_string != NULL && strcmp(state_string, "default")) {
      bool do_disable = strcmp(state_string, "disabled") == 0 ? true : false;

      if (do_disable != qinstance_state_is_manual_disabled(this_elem)) {
         ret = true;
         sge_qmaster_qinstance_state_set_manual_disabled(this_elem, do_disable);
      }
   }
   DRETURN(ret);
}

/****** daemons/qmaster/qinstance_reinit_consumable_actual_list() ************
*  NAME
*     qinstance_reinit_consumable_actual_list() -- as it says 
*
*  SYNOPSIS
*     static bool 
*     qinstance_reinit_consumable_actual_list(lListElem *this_elem, 
*                                             lList **answer_list) 
*
*  FUNCTION
*     Reinitialize the consumable actual values. 
*
*  INPUTS
*     lListElem *this_elem - QU_Type element 
*     lList **answer_list  - AN_Type element 
*
*  RESULT
*     static bool - error result
*        true  - success
*        false - error
*
*  NOTES
*     MT-NOTE: qinstance_reinit_consumable_actual_list() is MT safe 
*******************************************************************************/
bool
qinstance_reinit_consumable_actual_list(lListElem *this_elem,
                                        lList **answer_list)
{
   bool ret = true;

   DENTER(TOP_LAYER, "qinstance_reinit_consumable_actual_list");

   if (this_elem != NULL) {
      const char *name = lGetString(this_elem, QU_full_name);
      lList *job_list = *(object_type_get_master_list(SGE_TYPE_JOB));
      lList *centry_list = *(object_type_get_master_list(SGE_TYPE_CENTRY));
      lList *ar_list = *(object_type_get_master_list(SGE_TYPE_AR));
      lListElem *ep = NULL;

      lSetList(this_elem, QU_resource_utilization, NULL);
      qinstance_set_conf_slots_used(this_elem);
      qinstance_debit_consumable(this_elem, NULL, centry_list, 0, true, NULL);

      for_each(ep, job_list) {
         lList *ja_task_list = lGetList(ep, JB_ja_tasks);
         lListElem *ja_task = NULL;

         for_each(ja_task, ja_task_list) {
            lList *gdil = lGetList(ja_task, JAT_granted_destin_identifier_list);
            lListElem *gdil_ep = lGetElemStr(gdil, JG_qname, name);

            if (gdil_ep != NULL) {
               bool is_master_task = false;
               int slots = lGetUlong(gdil_ep, JG_slots);

               if (gdil_ep == lFirst(gdil)) {
                  is_master_task = true;
               }

               if (slots > 0) {
                  qinstance_debit_consumable(this_elem, ep, centry_list, slots, is_master_task, NULL);
               }
            }
         }
      }
      for_each(ep, ar_list) {
         lList *gdil = lGetList(ep, AR_granted_slots);
         lListElem *gdil_ep = lGetElemStr(gdil, JG_qname, name);


         if (gdil_ep != NULL) {
            bool is_master_task = false;
            lListElem *dummy_job = lCreateElem(JB_Type);

            if (gdil_ep == lFirst(gdil)) {
               is_master_task = true;
            }
         
            lSetList(dummy_job, JB_hard_resource_list, lCopyList("", lGetList(ep, AR_resource_list)));

            rc_add_job_utilization(dummy_job, 0, SCHEDULING_RECORD_ENTRY_TYPE_RESERVING,
                                   this_elem, centry_list, lGetUlong(gdil_ep, JG_slots),
                                   QU_consumable_config_list, QU_resource_utilization, name,
                                   lGetUlong(ep, AR_start_time), lGetUlong(ep, AR_duration),
                                   QUEUE_TAG, false, is_master_task);
            lFreeElem(&dummy_job);
         }
      }
   }

   DRETURN(ret);
}