Skip to content

Commit 8b41e6b

Browse files
committed
Add REQUEST_SBCAST_CRED_NO_JOB message
Issue #2
1 parent acbc0b0 commit 8b41e6b

File tree

7 files changed

+140
-0
lines changed

7 files changed

+140
-0
lines changed

slurm/slurm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,6 +3234,10 @@ typedef struct job_sbcast_cred_msg {
32343234
void *sbcast_cred; /* opaque data structure */
32353235
} job_sbcast_cred_msg_t;
32363236

3237+
typedef struct sbcast_cred_req_msg {
3238+
char *node_list;
3239+
} sbcast_cred_req_msg_t;
3240+
32373241
typedef struct {
32383242
uint32_t lifespan;
32393243
char *username;

src/common/msg_type.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const static entry_t msg_types[] = {
160160
ENTRY(REQUEST_JOB_END_TIME),
161161
ENTRY(REQUEST_JOB_NOTIFY),
162162
ENTRY(REQUEST_JOB_SBCAST_CRED),
163+
ENTRY(REQUEST_SBCAST_CRED_NO_JOB),
163164
ENTRY(RESPONSE_JOB_SBCAST_CRED),
164165
ENTRY(REQUEST_HET_JOB_ALLOCATION),
165166
ENTRY(RESPONSE_HET_JOB_ALLOCATION),

src/common/msg_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ typedef enum {
190190
RESPONSE_HET_JOB_ALLOCATION,
191191
REQUEST_HET_JOB_ALLOC_INFO,
192192
REQUEST_SUBMIT_BATCH_HET_JOB,
193+
REQUEST_SBCAST_CRED_NO_JOB,
193194

194195
REQUEST_CTLD_MULT_MSG = 4500,
195196
RESPONSE_CTLD_MULT_MSG,

src/common/slurm_protocol_defs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,15 @@ extern void slurm_free_node_registration_status_msg(
19171917
}
19181918
}
19191919

1920+
extern void slurm_free_sbcast_cred_req_msg(sbcast_cred_req_msg_t *msg)
1921+
{
1922+
if (!msg)
1923+
return;
1924+
1925+
xfree(msg->node_list);
1926+
xfree(msg);
1927+
}
1928+
19201929
extern void slurm_free_node_reg_resp_msg(
19211930
slurm_node_reg_resp_msg_t *msg)
19221931
{
@@ -4933,6 +4942,9 @@ extern int slurm_free_msg_data(slurm_msg_type_t type, void *data)
49334942
case REQUEST_JOB_SBCAST_CRED:
49344943
slurm_destroy_selected_step(data);
49354944
break;
4945+
case REQUEST_SBCAST_CRED_NO_JOB:
4946+
slurm_free_sbcast_cred_req_msg(data);
4947+
break;
49364948
case REQUEST_SHUTDOWN:
49374949
slurm_free_shutdown_msg(data);
49384950
break;

src/common/slurm_protocol_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ extern void slurm_free_crontab_update_request_msg(
16291629
extern void slurm_free_crontab_update_response_msg(
16301630
crontab_update_response_msg_t *msg);
16311631
extern void slurm_free_suspend_exc_update_msg(suspend_exc_update_msg_t *msg);
1632+
extern void slurm_free_sbcast_cred_req_msg(sbcast_cred_req_msg_t *msg);
16321633

16331634
extern const char *preempt_mode_string(uint16_t preempt_mode);
16341635
extern uint16_t preempt_mode_num(const char *preempt_mode);

src/common/slurm_protocol_pack.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7330,6 +7330,41 @@ _unpack_step_alloc_info_msg(step_alloc_info_msg_t **
73307330
return SLURM_SUCCESS;
73317331
}
73327332

7333+
static void _pack_sbcast_cred_no_job_msg(sbcast_cred_req_msg_t *msg,
7334+
buf_t *buffer,
7335+
uint16_t protocol_version)
7336+
{
7337+
xassert(msg);
7338+
7339+
if (protocol_version >= SLURM_24_11_PROTOCOL_VERSION) {
7340+
packstr(msg->node_list, buffer);
7341+
}
7342+
}
7343+
7344+
static int _unpack_sbcast_cred_no_job_msg(sbcast_cred_req_msg_t **msg,
7345+
buf_t *buffer,
7346+
uint16_t protocol_version)
7347+
{
7348+
sbcast_cred_req_msg_t *cred_msg;
7349+
7350+
xassert(buffer);
7351+
xassert(msg);
7352+
7353+
if (protocol_version >= SLURM_24_11_PROTOCOL_VERSION) {
7354+
cred_msg = xmalloc(sizeof(*cred_msg));
7355+
*msg = cred_msg;
7356+
7357+
safe_unpackstr(&cred_msg->node_list, buffer);
7358+
}
7359+
7360+
return SLURM_SUCCESS;
7361+
7362+
unpack_error:
7363+
slurm_free_sbcast_cred_req_msg(cred_msg);
7364+
*msg = NULL;
7365+
return SLURM_ERROR;
7366+
}
7367+
73337368
static void _pack_node_reg_resp(
73347369
slurm_node_reg_resp_msg_t *msg,
73357370
buf_t *buffer, uint16_t protocol_version)
@@ -13184,6 +13219,11 @@ pack_msg(slurm_msg_t const *msg, buf_t *buffer)
1318413219
_pack_step_alloc_info_msg((step_alloc_info_msg_t *) msg->data,
1318513220
buffer, msg->protocol_version);
1318613221
break;
13222+
case REQUEST_SBCAST_CRED_NO_JOB:
13223+
_pack_sbcast_cred_no_job_msg(
13224+
(sbcast_cred_req_msg_t *) msg->data, buffer,
13225+
msg->protocol_version);
13226+
break;
1318713227
case RESPONSE_NODE_REGISTRATION:
1318813228
_pack_node_reg_resp(
1318913229
(slurm_node_reg_resp_msg_t *)msg->data,
@@ -13837,6 +13877,11 @@ unpack_msg(slurm_msg_t * msg, buf_t *buffer)
1383713877
(msg->data), buffer,
1383813878
msg->protocol_version);
1383913879
break;
13880+
case REQUEST_SBCAST_CRED_NO_JOB:
13881+
rc = _unpack_sbcast_cred_no_job_msg(
13882+
(sbcast_cred_req_msg_t **) &(msg->data), buffer,
13883+
msg->protocol_version);
13884+
break;
1384013885
case RESPONSE_NODE_REGISTRATION:
1384113886
rc = _unpack_node_reg_resp(
1384213887
(slurm_node_reg_resp_msg_t **)&msg->data,

src/slurmctld/proc_req.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,79 @@ static void _slurm_rpc_job_sbcast_cred(slurm_msg_t *msg)
30583058
#endif
30593059
}
30603060

3061+
static void _slurm_rpc_sbcast_cred_no_job(slurm_msg_t *msg)
3062+
{
3063+
#ifdef HAVE_FRONT_END
3064+
slurm_send_rc_msg(msg, ESLURM_NOT_SUPPORTED);
3065+
return;
3066+
#endif
3067+
job_sbcast_cred_msg_t *cred_resp_msg = NULL;
3068+
sbcast_cred_req_msg_t *cred_req_msg = msg->data;
3069+
sbcast_cred_arg_t sbcast_arg = { 0 };
3070+
sbcast_cred_t *sbcast_cred;
3071+
hostlist_t *req_node_list;
3072+
char *node_name;
3073+
bool node_exists = false;
3074+
int rc;
3075+
3076+
DEF_TIMERS;
3077+
START_TIMER;
3078+
3079+
if (!validate_slurm_user(msg->auth_uid)) {
3080+
error("%s: sbcast --no-allocation/-Z credential requested from uid '%u' which is not root/SlurmUser",
3081+
__func__, msg->auth_uid);
3082+
rc = ESLURM_USER_ID_MISSING;
3083+
goto fail;
3084+
}
3085+
3086+
req_node_list = hostlist_create(cred_req_msg->node_list);
3087+
while ((node_name = hostlist_shift(req_node_list))) {
3088+
node_exists = find_node_record(node_name);
3089+
3090+
if (!node_exists) {
3091+
debug("%s: sbcast --nodelist contains at least one invalid node '%s'",
3092+
__func__, node_name);
3093+
free(node_name);
3094+
break;
3095+
}
3096+
free(node_name);
3097+
}
3098+
FREE_NULL_HOSTLIST(req_node_list);
3099+
3100+
if (!node_exists) {
3101+
(void) slurm_send_rc_msg(msg, ESLURM_INVALID_NODE_NAME);
3102+
return;
3103+
}
3104+
3105+
sbcast_arg.nodes = cred_req_msg->node_list;
3106+
sbcast_arg.expiration = time(NULL) + HOUR_SECONDS;
3107+
3108+
if (!(sbcast_cred = create_sbcast_cred(&sbcast_arg, msg->auth_uid,
3109+
msg->auth_gid,
3110+
msg->protocol_version))) {
3111+
error("%s: Could not create sbcast cred for --no-allocate/-Z request",
3112+
__func__);
3113+
rc = SLURM_ERROR;
3114+
goto fail;
3115+
}
3116+
END_TIMER2(__func__);
3117+
3118+
cred_resp_msg = xmalloc(sizeof(*cred_resp_msg));
3119+
cred_resp_msg->job_id = NO_VAL;
3120+
cred_resp_msg->node_list = xstrdup(cred_req_msg->node_list);
3121+
cred_resp_msg->sbcast_cred = sbcast_cred;
3122+
3123+
(void) send_msg_response(msg, RESPONSE_JOB_SBCAST_CRED, cred_resp_msg);
3124+
3125+
slurm_free_sbcast_cred_msg(cred_resp_msg);
3126+
3127+
return;
3128+
3129+
fail:
3130+
END_TIMER2(__func__);
3131+
(void) slurm_send_rc_msg(msg, rc);
3132+
}
3133+
30613134
/* _slurm_rpc_ping - process ping RPC */
30623135
static void _slurm_rpc_ping(slurm_msg_t *msg)
30633136
{
@@ -6622,6 +6695,9 @@ slurmctld_rpc_t slurmctld_rpcs[] =
66226695
},{
66236696
.msg_type = REQUEST_JOB_SBCAST_CRED,
66246697
.func = _slurm_rpc_job_sbcast_cred,
6698+
},{
6699+
.msg_type = REQUEST_SBCAST_CRED_NO_JOB,
6700+
.func = _slurm_rpc_sbcast_cred_no_job,
66256701
},{
66266702
.msg_type = REQUEST_PING,
66276703
.func = _slurm_rpc_ping,

0 commit comments

Comments
 (0)