Skip to content

Commit 5f118f0

Browse files
committed
EH: CS-2059: Add role user_list check to verify_userset_deletion()
EH: CS-2060: Post-startup integrity scan: log warnings for dangling role references
1 parent f9ed375 commit 5f118f0

5 files changed

Lines changed: 67 additions & 3 deletions

File tree

source/common/msg_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,4 +1142,7 @@
11421142
#define MSG_GDI_USAGE_srolel_OPT "[-srolel]"
11431143
#define MSG_GDI_UTEXT_srolel_OPT _MESSAGE(60757, _("show all role names"))
11441144

1145+
#define MSG_ROLE_INTEGRITY_USERSET_SS _MESSAGE(60758, _("startup integrity: role " SFQ " references userset " SFQ " which does not exist"))
1146+
#define MSG_ROLE_INTEGRITY_PARENT_SS _MESSAGE(60759, _("startup integrity: role " SFQ " references parent role " SFQ " which does not exist"))
1147+
11451148
// clang-format on

source/daemons/qmaster/setup_qmaster.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959

6060
#include "sgeobj/parse.h"
6161
#include "sgeobj/cull/sge_all_listsL.h"
62+
#include "sgeobj/ocs_DataStore.h"
63+
#include "sgeobj/ocs_Role.h"
6264
#include "sgeobj/ocs_Session.h"
6365
#include "sgeobj/sge_host.h"
6466
#include "sgeobj/sge_utility.h"
@@ -72,7 +74,6 @@
7274
#include "sgeobj/sge_manop.h"
7375
#include "sgeobj/sge_centry.h"
7476
#include "sgeobj/sge_conf.h"
75-
#include "sgeobj/ocs_DataStore.h"
7677

7778
#include "gdi/ocs_gdi_ClientBase.h"
7879

@@ -1203,6 +1204,16 @@ setup_qmaster() {
12031204
master_project_list, master_userset_list, master_rqs_list,
12041205
master_cqueue_list, master_pe_list, master_host_list);
12051206

1207+
// post-load integrity scan: warn about dangling role references (does not abort startup)
1208+
{
1209+
lList *integrity_answers = nullptr;
1210+
ocs::Role::check_integrity(*ocs::DataStore::get_master_list(SGE_TYPE_RL),
1211+
*ocs::DataStore::get_master_list(SGE_TYPE_USERSET),
1212+
&integrity_answers);
1213+
answer_list_output(&integrity_answers);
1214+
lFreeList(&integrity_answers);
1215+
}
1216+
12061217
DRETURN(0);
12071218
}
12081219

source/daemons/qmaster/sge_userset_qmaster.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "uti/sge_rmon_macros.h"
3838

3939
#include "sgeobj/sge_userset.h"
40+
#include "sgeobj/ocs_Role.h"
4041
#include "sgeobj/sge_conf.h"
4142
#include "sgeobj/sge_answer.h"
4243
#include "sgeobj/sge_qinstance.h"
@@ -364,6 +365,7 @@ verify_userset_deletion(lList **alpp, const char *userset_name) {
364365
const lList *master_pe_list = *ocs::DataStore::get_master_list(SGE_TYPE_PE);
365366
const lList *master_project_list = *ocs::DataStore::get_master_list(SGE_TYPE_PROJECT);
366367
const lList *master_ehost_list = *ocs::DataStore::get_master_list(SGE_TYPE_EXECHOST);
368+
const lList *master_role_list = *ocs::DataStore::get_master_list(SGE_TYPE_RL);
367369

368370

369371
/*
@@ -427,6 +429,15 @@ verify_userset_deletion(lList **alpp, const char *userset_name) {
427429
}
428430
}
429431

432+
// refuse deletion if any role still references this userset in its user_list
433+
for_each_ep_lv(role_ep, master_role_list) {
434+
if (lGetElemStr(lGetList(role_ep, RL_user_list), US_name, userset_name)) {
435+
ERROR(MSG_SGETEXT_USERSETSTILLREFERENCED_SSSS, userset_name, MSG_OBJ_USERLIST, MSG_OBJ_ROLE, lGetString(role_ep, RL_name));
436+
answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
437+
ret = STATUS_EUNKNOWN;
438+
}
439+
}
440+
430441
/* global configuration */
431442
user_lists = mconf_get_user_lists();
432443
if (lGetElemStr(user_lists, US_name, userset_name)) {

source/libs/sgeobj/ocs_Role.cc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include "cull/cull_list.h"
2525

2626
#include "sgeobj/sge_answer.h"
27+
#include "sgeobj/sge_userset.h"
2728
#include "sgeobj/sge_utility.h"
29+
#include "sgeobj/cull/sge_str_ST_L.h"
2830
#include "sgeobj/ocs_Role.h"
2931

3032
#include "msg_common.h"
@@ -36,7 +38,7 @@ ocs::Role::locate(const lList *role_list, const char *name) {
3638
}
3739

3840
bool
39-
ocs::Role::validate(lListElem *role, lList **answer_list, bool startup) {
41+
ocs::Role::validate(const lListElem *role, lList **answer_list, bool startup) {
4042
DENTER(TOP_LAYER);
4143

4244
if (const char *name = lGetString(role, RL_name);
@@ -47,6 +49,35 @@ ocs::Role::validate(lListElem *role, lList **answer_list, bool startup) {
4749
DRETURN(true);
4850
}
4951

52+
void
53+
ocs::Role::check_integrity(const lList *role_list, const lList *userset_list, lList **answer_list) {
54+
DENTER(TOP_LAYER);
55+
56+
for_each_ep_lv(role, role_list) {
57+
const char *role_name = lGetString(role, RL_name);
58+
59+
// check each user_list entry against the master userset list
60+
for_each_ep_lv(user_ep, lGetList(role, RL_user_list)) {
61+
const char *userset_name = lGetString(user_ep, US_name);
62+
if (!lGetElemStr(userset_list, US_name, userset_name)) {
63+
WARNING(MSG_ROLE_INTEGRITY_USERSET_SS, role_name, userset_name);
64+
answer_list_add(answer_list, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_WARNING);
65+
}
66+
}
67+
68+
// check each parent_role_list entry against the master role list
69+
for_each_ep_lv(parent_ep, lGetList(role, RL_parent_role_list)) {
70+
const char *parent_name = lGetString(parent_ep, ST_name);
71+
if (!lGetElemStr(role_list, RL_name, parent_name)) {
72+
WARNING(MSG_ROLE_INTEGRITY_PARENT_SS, role_name, parent_name);
73+
answer_list_add(answer_list, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_WARNING);
74+
}
75+
}
76+
}
77+
78+
DRETURN_VOID;
79+
}
80+
5081
lListElem *
5182
ocs::Role::create_template() {
5283
DENTER(TOP_LAYER);

source/libs/sgeobj/ocs_Role.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ namespace ocs {
4242
* @param startup True when called during qmaster startup (relaxes some checks).
4343
* @return True if the role is valid.
4444
*/
45-
static bool validate(lListElem *role, lList **answer_list, bool startup);
45+
static bool validate(const lListElem *role, lList **answer_list, bool startup);
46+
47+
/**
48+
* Post-startup integrity scan for dangling role references.
49+
* Logs a WARNING for each RL_user_list entry whose userset does not exist in
50+
* userset_list and each RL_parent_role_list entry whose parent role does not
51+
* exist in role_list. Does not abort startup.
52+
*/
53+
static void check_integrity(const lList *role_list, const lList *userset_list, lList **answer_list);
4654

4755
/**
4856
* Create a Role template element with default attribute values.

0 commit comments

Comments
 (0)