Skip to content

Add exclusive mode and prerequisites #86

Merged
merged 38 commits into from Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
35e6314
test_mx_util: Test mx_strvec functions used by daemon
donald Apr 17, 2020
d954e89
test_mx_util: Remove mx_strvec cache test
donald Apr 17, 2020
102f936
mx_util: Remove mx_strvec cache
donald Apr 17, 2020
edc5bd6
mxqd: Don't try to unmount noexisting job tmpdir
donald Apr 17, 2020
47e6d34
Build: Fix dependencies for mxqset
donald Apr 17, 2020
de092e0
sql: Add column daemon_flags
donald Apr 17, 2020
278ee8a
web: Add column daemon_flags
donald Apr 17, 2020
7f9c214
mxq_daemon.h: Add column daemon_flags
donald Apr 17, 2020
990514b
mxq_daemon.c: Add column daemon_flags
donald Apr 17, 2020
9a47128
mxqd.c: Add --exclusive option
donald Apr 17, 2020
5f0f6d9
mxqd.c: Require whitelist on exclusive daemon
donald Apr 17, 2020
5072c87
mxqsub: Fix sql parameter error for mxqsub -g
donald Apr 18, 2020
6362a8d
keywordset: Fix wrong substring match
donald Apr 18, 2020
dbaa76b
test_keywordset: Add test for substring bug
donald Apr 19, 2020
c083e4f
keywordset: Add keywordset_add
donald Apr 16, 2020
19d0aac
test_keywordset: Add test for keywordset_add
donald Apr 19, 2020
62c4f57
keywordset.h: Add keywordset_free_byref
donald Apr 19, 2020
1b24dab
Makefile: Let test_mxqd_control use keywordset
donald Apr 19, 2020
74aaa54
Add parser.y
donald Apr 16, 2020
90e790b
Add test_parser
donald Apr 16, 2020
fca297c
Add parser to Makefile
donald Apr 16, 2020
12945aa
.gitignore: Add parser
donald Apr 16, 2020
ab90990
sql: Add column prerequisites for the daemon
donald Apr 18, 2020
2a8be9f
mxq_daemon.h: Add prerequisites
donald Apr 18, 2020
a10e639
mxq_daemon.c: Add prerequisites
donald Apr 18, 2020
5dfc5a8
sql: Add column prerequisites for group
donald Apr 18, 2020
2463cb9
mxq_group.h: Add prerequisites for group
donald Apr 18, 2020
9fe7aed
mxq_group.c: Add prerequisites for group
donald Apr 18, 2020
10af18a
Makefile: Let mxqd depend on keywordset.h
donald Apr 18, 2020
e982239
mxqd.h: Add prerequisites to server struct
donald Apr 18, 2020
4850634
mxqd: Init server prerequisties
donald Apr 18, 2020
4761df0
Makefile: Let mxqd depend on parser.tab
donald Apr 18, 2020
1b3faf5
mxqd: Reformulate server_is_qualified
donald Apr 18, 2020
338b12d
mxqd: Check prerequisites
donald Apr 18, 2020
190d7d2
Makefile: Use parser.tab for mxqsub
donald Apr 18, 2020
405bfcb
mxqsub: Add --prerequisites
donald Apr 18, 2020
c487c6c
web: Add server detail page
donald Apr 19, 2020
63d6f12
web: Show prerequisites for group
donald Apr 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -24,6 +24,11 @@ mxqd_control.o
keywordset.o
test_keywordset.o
mxqset.o
parser.tab.c
parser.tab.h
parser.tab.o
test_parser.o
test_parser


mxqsub
Expand Down
25 changes: 21 additions & 4 deletions Makefile
Expand Up @@ -329,6 +329,7 @@ mxq_daemon.h += mxq_daemon.h
### mxqd.h -------------------------------------------------------------

mxqd.h += mxqd.h
mxqd.h += keywordset.h

### mxqd_conrol.h ------------------------------------------------------

Expand Down Expand Up @@ -418,10 +419,10 @@ clean: CLEAN += mxqadmin.o

### mxqset.o ----------------------------------------------------------

mxqsset.o: $(mx_mysql.h)
mxqsset.o: $(keywordset.h)
mxqkill.o: $(mxq.h)
mxqkill.o: $(mxq_group.h)
mxqset.o: $(mx_mysql.h)
mxqset.o: $(keywordset.h)
mxqset.o: $(mxq.h)
mxqset.o: $(mxq_group.h)
mxqset.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqsset.o
Expand Down Expand Up @@ -487,6 +488,7 @@ mxqd.o: $(mxq_group.h)
mxqd.o: $(mxq_job.h)
mxqd.o: $(mx_mysql.h)
mxqd.o: $(keywordset.h)
mxqd.o: parser.tab.h
mxqd.o: CFLAGS += $(CFLAGS_MYSQL)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_PATH)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_TMPDIR)
Expand All @@ -506,6 +508,7 @@ mxqsub.o: $(mxq_group.h)
mxqsub.o: $(mxq_job.h)
mxqsub.o: $(mx_util.h)
mxqsub.o: $(keywordset.h)
mxqsub.o: parser.tab.h
mxqsub.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqsub.o
Expand Down Expand Up @@ -533,6 +536,7 @@ mxqd: mxq_job.o
mxqd: mx_mysql.o
mxqd: mxqd_control.o
mxqd: keywordset.o
mxqd: parser.tab.o
mxqd: LDLIBS += $(LDLIBS_MYSQL)

build: mxqd
Expand All @@ -549,6 +553,7 @@ mxqsub: mx_util.o
mxqsub: mx_log.o
mxqsub: mx_mysql.o
mxqsub: keywordset.o
mxqsub: parser.tab.o
mxqsub: LDLIBS += $(LDLIBS_MYSQL)

build: mxqsub
Expand Down Expand Up @@ -713,6 +718,7 @@ test_mxqd_control: mx_log.o
test_mxqd_control: mx_util.o
test_mxqd_control: mx_mysql.o
test_mxqd_control: mxq_group.o
test_mxqd_control: keywordset.o
test_mxqd_control: LDLIBS += $(LDLIBS_MYSQL)

clean: CLEAN += test_mxqd_control
Expand All @@ -724,3 +730,14 @@ test_keywordset: test_keywordset.o
test_keywordset: keywordset.o
clean: CLEAN += test_keywordset.o
test: test_keywordset

%.tab.c %.tab.h: %.y
$(call quiet-command,bison -d $<," BISON $@")

clean: CLEAN += parser.tab.c parser.tab.h
test: test_parser
clean: CLEAN += test_parser
clean: CLEAN += test_parser.o
test_parser: test_parser.o parser.tab.o keywordset.o
test_parser.o: parser.tab.h keywordset.h
clean: CLEAN += parser.tab.o
23 changes: 21 additions & 2 deletions keywordset.c
Expand Up @@ -24,8 +24,12 @@ static int find_name(struct keywordset *kws, char *name, size_t len) {
if (kws->names[i][j] != name[j])
break;
j++;
if (j==len)
return i;
if (j==len) {
if (kws->names[i][j] == 0)
return i;
else
break;
}
}
}
return -1;
Expand Down Expand Up @@ -111,6 +115,21 @@ void keywordset_update(struct keywordset *kws, char *input) {
keywordset_update_phase(kws, input, PHASE_UPDATE);
}

void keywordset_add(struct keywordset *kws, char *input) {
char *c=input;
char *name_start;
while (*c) {
while (*c && isspace(*c))
c++;
if (*c) {
name_start=c++;
while (*c && !isspace(*c))
c++;
add_name(kws, name_start, c-name_start);
}
}
}

struct keywordset *keywordset_new(char *input) {
struct keywordset *kws = xmalloc(sizeof(*kws));
kws->nr_slots = KEYWORDSET_INITIAL_SLOTS;
Expand Down
3 changes: 3 additions & 0 deletions keywordset.h
Expand Up @@ -3,9 +3,12 @@

struct keywordset *keywordset_new(char *input);
void keywordset_update(struct keywordset *kws, char *input);
void keywordset_add(struct keywordset *kws, char *input);
char *keywordset_get(struct keywordset *kws);
int keywordset_ismember(struct keywordset *kws, char *name);
void keywordset_purge(struct keywordset *kws);
void keywordset_free(struct keywordset *kws);

__attribute__ ((unused)) static void keywordset_free_byref (struct keywordset **kws) { keywordset_free(*kws); }

#endif
38 changes: 0 additions & 38 deletions mx_util.c
Expand Up @@ -19,8 +19,6 @@
#include "mx_log.h"
#include "mx_util.h"

static inline size_t mx_strvec_length_cache(char **strvec, int32_t len);

static inline int _mx_strbeginswith(char *str, const char *start, char **endptr, short ignore_case)
{
size_t len;
Expand Down Expand Up @@ -933,40 +931,14 @@ void *mx_calloc_forever_sec(size_t nmemb, size_t size, unsigned int time)
char **mx_strvec_new(void)
{
char **strvec;
size_t len;

strvec = calloc(sizeof(*strvec), 1);
if (!strvec)
return NULL;

len = mx_strvec_length_cache(strvec, -1);
if (len != -1)
mx_strvec_length_cache(strvec, 0);

return strvec;
}

static inline size_t mx_strvec_length_cache(char **strvec, int32_t len)
{
static char ** sv = NULL;
static size_t l = 0;

if (likely(len == -1)) {
if (likely(sv == strvec)) {
return l;
}
return -1;
}

if (likely(sv == strvec)) {
l = len;
} else {
sv = strvec;
l = len;
}
return l;
}

size_t mx_strvec_length(char ** strvec)
{
char ** sv;
Expand All @@ -975,15 +947,9 @@ size_t mx_strvec_length(char ** strvec)
assert(strvec);

sv = strvec;

len = mx_strvec_length_cache(sv, -1);
if (len != -1)
return len;

for (; *sv; sv++);

len = sv-strvec;
mx_strvec_length_cache(sv, len);
return len;
}

Expand All @@ -1007,8 +973,6 @@ int mx_strvec_push_str(char *** strvecp, char * str)
sv[len++] = str;
sv[len] = NULL;

mx_strvec_length_cache(sv, len);

*strvecp = sv;

return 1;
Expand All @@ -1035,8 +999,6 @@ int mx_strvec_push_strvec(char ***strvecp, char **strvec)

memcpy(sv+len1, strvec, sizeof(*strvec) * (len2 + 1));

mx_strvec_length_cache(sv, len1+len2);

*strvecp = sv;

return 1;
Expand Down
13 changes: 11 additions & 2 deletions mxq_daemon.c
Expand Up @@ -34,7 +34,9 @@
" daemon_memory_used," \
" UNIX_TIMESTAMP(mtime) as mtime," \
" UNIX_TIMESTAMP(daemon_start) as daemon_start," \
" UNIX_TIMESTAMP(daemon_stop) as daemon_stop"
" UNIX_TIMESTAMP(daemon_stop) as daemon_stop," \
" daemon_flags," \
" prerequisites"

#undef _to_string
#undef status_str
Expand Down Expand Up @@ -75,6 +77,9 @@ static int bind_result_daemon_fields(struct mx_mysql_bind *result, struct mxq_da
res += mx_mysql_bind_var(result, idx++, int64, &(daemon->daemon_start.tv_sec));
res += mx_mysql_bind_var(result, idx++, int64, &(daemon->daemon_stop.tv_sec));

res += mx_mysql_bind_var(result, idx++, int32, &(daemon->daemon_flags));
res += mx_mysql_bind_var(result, idx++, string, &(daemon->prerequisites));

return res;
}

Expand Down Expand Up @@ -136,7 +141,9 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon)
" daemon_memory_used = 0,"
" mtime = NULL,"
" daemon_start = CURRENT_TIMESTAMP(),"
" daemon_stop = 0"
" daemon_stop = 0,"
" daemon_flags = ?,"
" prerequisites = ?"
);
if (!stmt) {
mx_log_err("mx_mysql_statement_prepare(): %m");
Expand All @@ -161,6 +168,8 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon)

res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_soft));
res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_hard));
res += mx_mysql_statement_param_bind(stmt, idx++, int32, &(daemon->daemon_flags));
res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->prerequisites));

assert(res ==0);

Expand Down
3 changes: 3 additions & 0 deletions mxq_daemon.h
Expand Up @@ -46,6 +46,9 @@ struct mxq_daemon {

struct timeval daemon_start;
struct timeval daemon_stop;

int daemon_flags;
char *prerequisites;
};

void mxq_daemon_free_content(struct mxq_daemon *daemon);
Expand Down
5 changes: 4 additions & 1 deletion mxq_group.c
Expand Up @@ -12,7 +12,7 @@
#include "mx_util.h"
#include "mx_mysql.h"

#define GROUP_FIELDS_CNT 35
#define GROUP_FIELDS_CNT 36
#define GROUP_FIELDS \
" group_id," \
" group_name," \
Expand All @@ -21,6 +21,7 @@
" group_priority," \
" group_blacklist," \
" group_whitelist," \
" prerequisites," \
" user_uid," \
" user_name," \
" user_gid," \
Expand Down Expand Up @@ -66,6 +67,7 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro
res += mx_mysql_bind_var(result, idx++, uint16, &(g->group_priority));
res += mx_mysql_bind_var(result, idx++, string, &(g->group_blacklist));
res += mx_mysql_bind_var(result, idx++, string, &(g->group_whitelist));
res += mx_mysql_bind_var(result, idx++, string, &(g->prerequisites));

res += mx_mysql_bind_var(result, idx++, uint32, &(g->user_uid));
res += mx_mysql_bind_var(result, idx++, string, &(g->user_name));
Expand Down Expand Up @@ -109,6 +111,7 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro

void mxq_group_free_content(struct mxq_group *g)
{
mx_free_null(g->prerequisites);
mx_free_null(g->group_whitelist);
mx_free_null(g->group_blacklist);
mx_free_null(g->group_name);
Expand Down
1 change: 1 addition & 0 deletions mxq_group.h
Expand Up @@ -16,6 +16,7 @@ struct mxq_group {
uint16_t group_priority;
char * group_blacklist;
char * group_whitelist;
char * prerequisites;

uint32_t user_uid;
char * user_name;
Expand Down