Skip to content

Commit

Permalink
mxqd: Only start jobs we are qualified for
Browse files Browse the repository at this point in the history
Check, whether this server is qualified to start jobs from a group.

Lazy-evaluate qualification criteria defined in the group and cache the result.

The qualification criteria need to be reevaluated  when the active groups
were reloaded, because they may be changed by the user in existing
groups.

For now, the only qualification criteria are the groups blacklist and
whitelist. If a group has a whitelist, the short or long hostname of the
mxqd server needs to be on that list, otherwise the server is not
qualified for the group.

If the servers name is on the blacklist of the group, the server is not
qualified for the group.

Don't start jobs we are not qualified for.

This can later be expanded to additional criteria (e.g. hostconfig or
processor flags).
  • Loading branch information
donald committed Apr 15, 2020
1 parent 6873cf3 commit e9c0de8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "mxq.h"

#include "mxqd_control.h"
#include "keywordset.h"

#ifndef MXQ_INITIAL_PATH
# define MXQ_INITIAL_PATH "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
Expand Down Expand Up @@ -546,6 +547,16 @@ int server_init(struct mxq_server *server, int argc, char *argv[])
}

server->hostname = arg_hostname;
{
char *dot=index(arg_hostname,'.');
if (dot) {
server->hostname_short = mx_malloc_forever(dot-arg_hostname+1);
strncpy(server->hostname_short, arg_hostname, dot-arg_hostname);
server->hostname_short[dot-arg_hostname] = 0;
} else
server->hostname_short = mx_strdup_forever(arg_hostname);
}

server->daemon_name = arg_daemon_name;
server->initial_path = arg_initial_path;
server->initial_tmpdir = arg_initial_tmpdir;
Expand Down Expand Up @@ -1277,6 +1288,39 @@ unsigned long start_job(struct mxq_group_list *glist)

/**********************************************************************/

static int server_is_qualified(struct mxq_server *server, struct mxq_group *group) {

int is_qualified;

if (*group->group_whitelist != 0) {
is_qualified = 0;
struct keywordset *kws = keywordset_new(group->group_whitelist);
if ( keywordset_ismember(kws, server->hostname_short)
|| keywordset_ismember(kws, server->hostname) )
is_qualified = 1;
keywordset_free(kws);
} else {
is_qualified = 1;
}

if (*group->group_blacklist != 0) {
struct keywordset *kws = keywordset_new(group->group_blacklist);
if ( keywordset_ismember(kws, server->hostname_short)
|| keywordset_ismember(kws, server->hostname) )
is_qualified = 0;
keywordset_free(kws);
}
return (is_qualified);
}

static int server_is_qualified_cached(struct mxq_server *server, struct mxq_group_list *glist) {
if (!glist->server_is_qualified_evaluated) {
glist->server_is_qualified = server_is_qualified(server, &glist->group);
glist->server_is_qualified_evaluated = 1;
}
return glist->server_is_qualified;
}

unsigned long start_user(struct mxq_user_list *ulist, long slots_to_start)
{
struct mxq_server *server;
Expand Down Expand Up @@ -1319,6 +1363,8 @@ unsigned long start_user(struct mxq_user_list *ulist, long slots_to_start)
if (df_scratch/1024/1024/1024 < group->job_tmpdir_size + 20) {
continue;
}
if (!server_is_qualified_cached(server, glist))
continue;

mx_log_info(" group=%s(%d):%lu slots_to_start=%ld slots_per_job=%lu :: trying to start job for group.",
group->user_name, group->user_uid, group->group_id, slots_to_start, glist->slots_per_job);
Expand Down Expand Up @@ -1472,6 +1518,7 @@ void server_free(struct mxq_server *server)
mx_free_null(server->finished_jobsdir);
mx_flock_free(server->flock);
mx_free_null(server->supgid);
mx_free_null(server->hostname_short);

mx_log_finish();
}
Expand Down
4 changes: 4 additions & 0 deletions mxqd.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct mxq_group_list {
unsigned long global_threads_running;
unsigned long global_slots_running;

int server_is_qualified_evaluated;
int server_is_qualified;

short orphaned;
};

Expand Down Expand Up @@ -95,6 +98,7 @@ struct mxq_server {
unsigned long long int starttime;
char *host_id;
char *hostname;
char *hostname_short;
char *daemon_name;
char *pidfilename;
char *finished_jobsdir;
Expand Down
3 changes: 3 additions & 0 deletions mxqd_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ static void _group_list_init(struct mxq_group_list *glist)
glist->slots_max = slots_max;
glist->memory_max = memory_max;

glist->server_is_qualified_evaluated = 0;
glist->server_is_qualified = 0;

glist->orphaned = 0;
}

Expand Down

0 comments on commit e9c0de8

Please sign in to comment.