From f42d526383ad005af180072a8e54b35656a6d42e Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 23 Sep 2015 12:56:58 +0200 Subject: [PATCH 01/11] mx_util: Add mx_read_first_line_from_file() --- mx_util.c | 28 ++++++++++++++++++++++++++++ mx_util.h | 11 +++++++++++ test_mx_util.c | 22 ++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/mx_util.c b/mx_util.c index 199bcd5c..612e9fee 100644 --- a/mx_util.c +++ b/mx_util.c @@ -752,6 +752,34 @@ int mx_open_newfile(char *fname) return fh; } +int mx_read_first_line_from_file(char *fname, char **line) +{ + _mx_cleanup_fclose_ FILE *fp; + char *buf = NULL; + size_t n = 0; + ssize_t res; + + fp = fopen(fname, "r"); + if (!fp) + return -errno; + + res = getline(&buf, &n, fp); + if (res == -1) + return -errno; + + *line = buf; + + if (!res) + return res; + + res--; + + if (buf[res] == '\n') + buf[res] = 0; + + return res; +} + int mx_sleep(unsigned int seconds) { if (seconds) diff --git a/mx_util.h b/mx_util.h index d805aef3..7cd10d01 100644 --- a/mx_util.h +++ b/mx_util.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "mx_log.h" @@ -46,9 +47,17 @@ static inline void __mx_free(void *ptr) { free(*(void **)ptr); } +static inline void __mx_fclose(FILE **ptr) { + if (*ptr) + fclose(*ptr); +} + #undef _mx_cleanup_free_ #define _mx_cleanup_free_ _mx_cleanup_(__mx_free) +#undef _mx_cleanup_fclose_ +#define _mx_cleanup_fclose_ _mx_cleanup_(__mx_fclose) + #undef likely #define likely(x) __builtin_expect((x),1) @@ -106,6 +115,8 @@ int mx_setenvf_forever(const char *name, char *fmt, ...) __attribute__ ((format( int mx_open_newfile(char *fname); +int mx_read_first_line_from_file(char *fname, char **line); + int mx_sleep(unsigned int seconds); int mx_sleep_nofail(unsigned int seconds); diff --git a/test_mx_util.c b/test_mx_util.c index 66dd7766..6e956f3f 100644 --- a/test_mx_util.c +++ b/test_mx_util.c @@ -44,6 +44,7 @@ static void test_mx_strtoul(void) assert(mx_strtoul("-1", &l) == -ERANGE); assert(mx_strtoul(" -1", &l) == -ERANGE); + assert(mx_strtoul("123 123", &l) == -EINVAL); assert(mx_strtoul("123s", &l) == -EINVAL); assert(mx_strtoul("0888", &l) == -EINVAL); assert(mx_strtoul("1.2", &l) == -EINVAL); @@ -271,6 +272,26 @@ static void test_mx_strtobytes(void) assert(mx_strtobytes("test", &l) == -EINVAL); } +static void test_mx_read_first_line_from_file(void) +{ + char *str; + + assert(mx_read_first_line_from_file("/proc/sys/kernel/random/boot_id", &str) == 36); + assert(str); + mx_free_null(str); + + assert(mx_read_first_line_from_file("/proc/sys/kernel/random/uuid", &str) == 36); + assert(str); + mx_free_null(str); + + assert(mx_read_first_line_from_file("/proc/no_such_file", &str) == -ENOENT); + assert(str == NULL); + + assert(mx_read_first_line_from_file("/proc/self/stat", &str) > 0); + assert(str); + mx_free_null(str); +} + int main(int argc, char *argv[]) { test_mx_strskipwhitespaces(); @@ -284,5 +305,6 @@ int main(int argc, char *argv[]) test_mx_strtoseconds(); test_mx_strtominutes(); test_mx_strtobytes(); + test_mx_read_first_line_from_file(); return 0; } From bbc2071df957e3f791129914611a4fc786e7da38 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 23 Sep 2015 16:40:06 +0200 Subject: [PATCH 02/11] mx_util: Add mx_strscan_ull() and mx_strscan_ll() --- mx_util.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ mx_util.h | 3 +++ test_mx_util.c | 42 ++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/mx_util.c b/mx_util.c index 612e9fee..7c423344 100644 --- a/mx_util.c +++ b/mx_util.c @@ -780,6 +780,68 @@ int mx_read_first_line_from_file(char *fname, char **line) return res; } +int mx_strscan_ull(char **str, unsigned long long int *to) +{ + unsigned long long int l; + char *s; + char *p; + char o = 0; + int res; + + s = *str; + + p = strchr(s, ' '); + if (p) { + o = *p; + *p = 0; + p++; + } else { + p = s + strlen(s); + } + + res = mx_strtoull(s, &l); + if (o) + *(p-1) = o; + + if (res == 0) { + *to = l; + *str = p; + } + + return res; +} + +int mx_strscan_ll(char **str, long long int *to) +{ + long long int l; + char *s; + char *p; + char o = 0; + int res; + + s = *str; + + p = strchr(s, ' '); + if (p) { + o = *p; + *p = 0; + p++; + } else { + p = s + strlen(s); + } + + res = mx_strtoll(s, &l); + if (o) + *(p-1) = o; + + if (res == 0) { + *to = l; + *str = p; + } + + return res; +} + int mx_sleep(unsigned int seconds) { if (seconds) diff --git a/mx_util.h b/mx_util.h index 7cd10d01..e6787dba 100644 --- a/mx_util.h +++ b/mx_util.h @@ -117,6 +117,9 @@ int mx_open_newfile(char *fname); int mx_read_first_line_from_file(char *fname, char **line); +int mx_strscan_ull(char **str, unsigned long long int *to); +int mx_strscan_ll(char **str, long long int *to); + int mx_sleep(unsigned int seconds); int mx_sleep_nofail(unsigned int seconds); diff --git a/test_mx_util.c b/test_mx_util.c index 6e956f3f..6263acfe 100644 --- a/test_mx_util.c +++ b/test_mx_util.c @@ -292,6 +292,47 @@ static void test_mx_read_first_line_from_file(void) mx_free_null(str); } +static void test_mx_strscan(void) +{ + _mx_cleanup_free_ char *s = NULL; + char *str; + unsigned long long int ull; + long long int ll; + + assert(s = strdup("123 456 -789 246 abc")); + str = s; + + assert(mx_strscan_ull(&str, &ull) == 0); + assert(ull == 123); + + assert(mx_strscan_ull(&str, &ull) == 0); + assert(ull == 456); + + assert(mx_strscan_ull(&str, &ull) == -ERANGE); + assert(mx_streq(str, "-789 246 abc")); + + assert(mx_strscan_ll(&str, &ll) == 0); + assert(ll == -789); + assert(mx_streq(str, "246 abc")); + + assert(mx_strscan_ll(&str, &ll) == 0); + assert(ll == 246); + assert(mx_streq(str, "abc")); + + assert(mx_strscan_ull(&str, &ull) == -EINVAL); + assert(mx_streq(str, "abc")); + assert(mx_streq(s, "123 456 -789 246 abc")); + mx_free_null(s); + + assert(s = strdup("123")); + str = s; + assert(mx_strscan_ull(&str, &ull) == 0); + assert(ull == 123); + assert(mx_streq(str, "")); + assert(mx_streq(s, "123")); + +} + int main(int argc, char *argv[]) { test_mx_strskipwhitespaces(); @@ -306,5 +347,6 @@ int main(int argc, char *argv[]) test_mx_strtominutes(); test_mx_strtobytes(); test_mx_read_first_line_from_file(); + test_mx_strscan(); return 0; } From 426ffedb34b61153766e46a3c399d463ea92554c Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 23 Sep 2015 16:41:23 +0200 Subject: [PATCH 03/11] mx_util: Add mx_proc_pid_stat() --- mx_util.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ mx_util.h | 51 ++++++++++++++++++++++++++ test_mx_util.c | 24 +++++++++++++ 3 files changed, 173 insertions(+) diff --git a/mx_util.c b/mx_util.c index 7c423344..efde13f5 100644 --- a/mx_util.c +++ b/mx_util.c @@ -842,6 +842,104 @@ int mx_strscan_ll(char **str, long long int *to) return res; } +int mx_strscan_proc_pid_stat(char *str, struct proc_pid_stat *pps) +{ + size_t res = 0; + char *p; + char *s; + + pps->comm = NULL; + + s = str; + + res += mx_strscan_ll(&s, &(pps->pid)); + + p = strrchr(s, ')'); + if (!p) + return -(errno=EINVAL); + + *p = 0; + s++; + + pps->comm = mx_strdup_forever(s); + s = p + 2; + + pps->state = *s; + res += !(*(s+1) == ' '); + s += 2; + + res += mx_strscan_ll(&s, &(pps->ppid)); + res += mx_strscan_ll(&s, &(pps->pgrp)); + res += mx_strscan_ll(&s, &(pps->session)); + res += mx_strscan_ll(&s, &(pps->tty_nr)); + res += mx_strscan_ll(&s, &(pps->tpgid)); + res += mx_strscan_ull(&s, &(pps->flags)); + res += mx_strscan_ull(&s, &(pps->minflt)); + res += mx_strscan_ull(&s, &(pps->cminflt)); + res += mx_strscan_ull(&s, &(pps->majflt)); + res += mx_strscan_ull(&s, &(pps->cmajflt)); + res += mx_strscan_ull(&s, &(pps->utime)); + res += mx_strscan_ull(&s, &(pps->stime)); + res += mx_strscan_ll(&s, &(pps->cutime)); + res += mx_strscan_ll(&s, &(pps->cstime)); + res += mx_strscan_ll(&s, &(pps->priority)); + res += mx_strscan_ll(&s, &(pps->nice)); + res += mx_strscan_ll(&s, &(pps->num_threads)); + res += mx_strscan_ll(&s, &(pps->itrealvalue)); + res += mx_strscan_ull(&s, &(pps->starttime)); + res += mx_strscan_ull(&s, &(pps->vsize)); + res += mx_strscan_ll(&s, &(pps->rss)); + res += mx_strscan_ull(&s, &(pps->rsslim)); + res += mx_strscan_ull(&s, &(pps->startcode)); + res += mx_strscan_ull(&s, &(pps->endcode)); + res += mx_strscan_ull(&s, &(pps->startstack)); + res += mx_strscan_ull(&s, &(pps->kstkesp)); + res += mx_strscan_ull(&s, &(pps->kstkeip)); + res += mx_strscan_ull(&s, &(pps->signal)); + res += mx_strscan_ull(&s, &(pps->blocked)); + res += mx_strscan_ull(&s, &(pps->sigignore)); + res += mx_strscan_ull(&s, &(pps->sigcatch)); + res += mx_strscan_ull(&s, &(pps->wchan)); + res += mx_strscan_ull(&s, &(pps->nswap)); + res += mx_strscan_ull(&s, &(pps->cnswap)); + res += mx_strscan_ll(&s, &(pps->exit_signal)); + res += mx_strscan_ll(&s, &(pps->processor)); + res += mx_strscan_ull(&s, &(pps->rt_priority)); + res += mx_strscan_ull(&s, &(pps->policy)); + res += mx_strscan_ull(&s, &(pps->delayacct_blkio_ticks)); + res += mx_strscan_ull(&s, &(pps->guest_time)); + res += mx_strscan_ll(&s, &(pps->cguest_time)); + + if (res != 0) + return -(errno=EINVAL); + + return 0; +} + +int mx_proc_pid_stat(struct proc_pid_stat *pps, pid_t pid) +{ + _mx_cleanup_free_ char *fname = NULL; + _mx_cleanup_free_ char *line = NULL; + int res; + + mx_asprintf_forever(&fname, "/proc/%d/stat", pid); + + res = mx_read_first_line_from_file(fname, &line); + if (res < 0) + return res; + + res = mx_strscan_proc_pid_stat(line, pps); + if (res < 0) + return res; + + return 0; +} + +void mx_proc_pid_stat_free(struct proc_pid_stat *pps) +{ + mx_free_null(pps->comm); +} + int mx_sleep(unsigned int seconds) { if (seconds) diff --git a/mx_util.h b/mx_util.h index e6787dba..f79d77fa 100644 --- a/mx_util.h +++ b/mx_util.h @@ -9,6 +9,53 @@ #include "mx_log.h" +struct proc_pid_stat { + long long int pid; /* 1 */ + char *comm; /* 2 (comm) */ + char state; /* 3 "RSDZTW" */ + long long int ppid; /* 4 */ + long long int pgrp; /* 5 */ + long long int session; /* 6 */ + long long int tty_nr; /* 7 */ + long long int tpgid; /* 8 */ + unsigned long long int flags; /* 9 */ + unsigned long long int minflt; /* 10 */ + unsigned long long int cminflt; /* 11 */ + unsigned long long int majflt; /* 12 */ + unsigned long long int cmajflt; /* 13 */ + unsigned long long int utime; /* 14 */ + unsigned long long int stime; /* 15 */ + long long int cutime; /* 16 */ + long long int cstime; /* 17 */ + long long int priority; /* 18 */ + long long int nice; /* 19 */ + long long int num_threads; /* 20 */ + long long int itrealvalue; /* 21 */ + unsigned long long int starttime; /* 22 */ + unsigned long long int vsize; /* 23 */ + long long int rss; /* 24 */ + unsigned long long int rsslim; /* 25 */ + unsigned long long int startcode; /* 26 */ + unsigned long long int endcode; /* 27 */ + unsigned long long int startstack; /* 28 */ + unsigned long long int kstkesp; /* 29 */ + unsigned long long int kstkeip; /* 30 */ + unsigned long long int signal; /* 31 */ + unsigned long long int blocked; /* 32 */ + unsigned long long int sigignore; /* 33 */ + unsigned long long int sigcatch; /* 34 */ + unsigned long long int wchan; /* 35 */ + unsigned long long int nswap; /* 36 */ + unsigned long long int cnswap; /* 37 */ + long long int exit_signal; /* 38 */ + long long int processor; /* 39 */ + unsigned long long int rt_priority; /* 40 */ + unsigned long long int policy; /* 41 */ + unsigned long long int delayacct_blkio_ticks; /* 42 */ + unsigned long long int guest_time; /* 43 */ + long long int cguest_time; /* 44 */ +}; + #ifdef MX_NDEBUG # include # define mx_assert_return_minus_errno(test, eno) \ @@ -119,6 +166,10 @@ int mx_read_first_line_from_file(char *fname, char **line); int mx_strscan_ull(char **str, unsigned long long int *to); int mx_strscan_ll(char **str, long long int *to); +int mx_strscan_proc_pid_stat(char *str, struct proc_pid_stat *pps); + +int mx_proc_pid_stat(struct proc_pid_stat *pps, pid_t pid); +void mx_proc_pid_stat_free(struct proc_pid_stat *pps); int mx_sleep(unsigned int seconds); int mx_sleep_nofail(unsigned int seconds); diff --git a/test_mx_util.c b/test_mx_util.c index 6263acfe..5700e807 100644 --- a/test_mx_util.c +++ b/test_mx_util.c @@ -1,7 +1,11 @@ +#define _GNU_SOURCE + #include #include #include +#include +#include #include "mx_util.h" @@ -275,6 +279,7 @@ static void test_mx_strtobytes(void) static void test_mx_read_first_line_from_file(void) { char *str; + long long int l; assert(mx_read_first_line_from_file("/proc/sys/kernel/random/boot_id", &str) == 36); assert(str); @@ -289,6 +294,7 @@ static void test_mx_read_first_line_from_file(void) assert(mx_read_first_line_from_file("/proc/self/stat", &str) > 0); assert(str); + mx_strtoll(str, &l); mx_free_null(str); } @@ -298,6 +304,9 @@ static void test_mx_strscan(void) char *str; unsigned long long int ull; long long int ll; + _mx_cleanup_free_ char *line = NULL; + struct proc_pid_stat pps = {0}; + struct proc_pid_stat pps2 = {0}; assert(s = strdup("123 456 -789 246 abc")); str = s; @@ -331,8 +340,23 @@ static void test_mx_strscan(void) assert(mx_streq(str, "")); assert(mx_streq(s, "123")); + assert(mx_read_first_line_from_file("/proc/self/stat", &line) > 0); + assert(mx_strscan_proc_pid_stat(line, &pps) == 0); + assert(pps.pid == getpid()); + assert(pps.ppid == getppid()); + assert(pps.state == 'R'); + assert(mx_streq(pps.comm, program_invocation_short_name) || mx_streq(pps.comm, "memcheck-amd64-")); + mx_proc_pid_stat_free(&pps); + + assert(mx_proc_pid_stat(&pps2, getpid()) == 0); + assert(pps2.pid == getpid()); + assert(pps2.ppid == getppid()); + assert(pps2.state == 'R'); + assert(mx_streq(pps2.comm, program_invocation_short_name) || mx_streq(pps2.comm, "memcheck-amd64-")); + mx_proc_pid_stat_free(&pps2); } + int main(int argc, char *argv[]) { test_mx_strskipwhitespaces(); From 6057a124d448885b5c98b35dbe2a9d3785d0aac4 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 23 Sep 2015 21:46:33 +0200 Subject: [PATCH 04/11] mxqd: set MXQ_HOSTNAME and MXQ_SERVERID --- mxqd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mxqd.c b/mxqd.c index 73fef9af..552af71f 100644 --- a/mxqd.c +++ b/mxqd.c @@ -808,6 +808,8 @@ static int init_child_process(struct mxq_group_list *group, struct mxq_job *j) mx_setenvf_forever("MXQ_MEMORY", "%lu", g->job_memory); mx_setenvf_forever("MXQ_TIME", "%d", g->job_time); mx_setenvf_forever("MXQ_HOSTID", "%s::%s", s->hostname, s->server_id); + mx_setenv_forever("MXQ_HOSTNAME", s->hostname); + mx_setenv_forever("MXQ_SERVERID", s->server_id); fh = open("/proc/self/loginuid", O_WRONLY|O_TRUNC); if (fh == -1) { From 4f2859e17aeee74e878133f4ccece884431c142c Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 10:40:06 +0200 Subject: [PATCH 05/11] mxqd: Set MXQ_HOSTID to bootid-hex(starttime)-pid --- mxqd.c | 21 ++++++++++++++++++++- mxqd.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mxqd.c b/mxqd.c index 552af71f..d69017b8 100644 --- a/mxqd.c +++ b/mxqd.c @@ -203,11 +203,13 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) char *arg_initial_tmpdir; char arg_daemonize = 0; char arg_nolog = 0; + char *str_bootid; int opt; unsigned long threads_total = 1; unsigned long memory_total = 2048; unsigned long memory_max = 0; int i; + struct proc_pid_stat pps = {0}; struct mx_getopt_ctl optctl; struct mx_option opts[] = { @@ -409,6 +411,20 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) } } + res = mx_read_first_line_from_file("/proc/sys/kernel/random/boot_id", &str_bootid); + assert(res == 36); + assert(str_bootid); + + server->boot_id = str_bootid; + + res = mx_proc_pid_stat(&pps, getpid()); + assert(res == 0); + + server->starttime = pps.starttime; + mx_proc_pid_stat_free(&pps); + + mx_asprintf_forever(&server->host_id, "%s-%llx-%x", server->boot_id, server->starttime, getpid()); + server->slots = threads_total;; server->memory_total = memory_total; server->memory_max_per_slot = memory_max; @@ -807,7 +823,7 @@ static int init_child_process(struct mxq_group_list *group, struct mxq_job *j) mx_setenvf_forever("MXQ_SLOTS", "%lu", group->slots_per_job); mx_setenvf_forever("MXQ_MEMORY", "%lu", g->job_memory); mx_setenvf_forever("MXQ_TIME", "%d", g->job_time); - mx_setenvf_forever("MXQ_HOSTID", "%s::%s", s->hostname, s->server_id); + mx_setenv_forever("MXQ_HOSTID", s->host_id); mx_setenv_forever("MXQ_HOSTNAME", s->hostname); mx_setenv_forever("MXQ_SERVERID", s->server_id); @@ -1351,6 +1367,8 @@ void server_close(struct mxq_server *server) unlink(server->pidfilename); mx_funlock(server->flock); + + mx_free_null(server->boot_id); } int killall(struct mxq_server *server, int sig, unsigned int pgrp) @@ -1693,6 +1711,7 @@ int main(int argc, char *argv[]) mx_log_info(" by Marius Tolzmann " MXQ_VERSIONDATE); mx_log_info(" Max Planck Institute for Molecular Genetics - Berlin Dahlem"); mx_log_info("hostname=%s server_id=%s :: MXQ server started.", server.hostname, server.server_id); + mx_log_info(" host_id=%s", server.host_id); mx_log_info("slots=%lu memory_total=%lu memory_avg_per_slot=%.0Lf memory_max_per_slot=%ld :: server initialized.", server.slots, server.memory_total, server.memory_avg_per_slot, server.memory_max_per_slot); diff --git a/mxqd.h b/mxqd.h index 57c9b4f7..c4db22d3 100644 --- a/mxqd.h +++ b/mxqd.h @@ -70,6 +70,9 @@ struct mxq_server { struct mx_mysql *mysql; + char *boot_id; + unsigned long long int starttime; + char *host_id; char *hostname; char *server_id; char *lockfilename; From 7e1dd39d47b92d4d5eefad788f8d34b9474472fa Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 14:59:16 +0200 Subject: [PATCH 06/11] mysql: Add new field host_id to table mxq_job --- mysql/alter_tables_0.15.0.sql | 6 ++++++ mysql/create_tables.sql | 1 + mysql/fix_host_id.sql | 7 +++++++ 3 files changed, 14 insertions(+) create mode 100644 mysql/fix_host_id.sql diff --git a/mysql/alter_tables_0.15.0.sql b/mysql/alter_tables_0.15.0.sql index b1e8d15f..95faa894 100644 --- a/mysql/alter_tables_0.15.0.sql +++ b/mysql/alter_tables_0.15.0.sql @@ -3,3 +3,9 @@ ALTER TABLE mxq_group job_max_per_node INT2 UNSIGNED NOT NULL DEFAULT 0 AFTER job_time; + +ALTER TABLE mxq_job + ADD COLUMN + host_id VARCHAR(1023) NOT NULL DEFAULT "" + AFTER + server_id; diff --git a/mysql/create_tables.sql b/mysql/create_tables.sql index cee2cd03..c203fa2a 100644 --- a/mysql/create_tables.sql +++ b/mysql/create_tables.sql @@ -83,6 +83,7 @@ CREATE TABLE IF NOT EXISTS mxq_job ( host_submit VARCHAR(64) NOT NULL DEFAULT "localhost", server_id VARCHAR(1023) NOT NULL DEFAULT "", + host_id VARCHAR(1023) NOT NULL DEFAULT "", host_hostname VARCHAR(64) NOT NULL DEFAULT "", host_pid INT4 UNSIGNED NOT NULL DEFAULT 0, diff --git a/mysql/fix_host_id.sql b/mysql/fix_host_id.sql new file mode 100644 index 00000000..c3c6fa35 --- /dev/null +++ b/mysql/fix_host_id.sql @@ -0,0 +1,7 @@ +UPDATE mxq_job + SET + host_id = CONCAT(host_hostname, '::', server_id) + WHERE + host_id = "" + AND server_id != "" + AND host_hostname != ""; From 19458bd19e4054d9f0de46d8308e7a7d400550b4 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 14:59:50 +0200 Subject: [PATCH 07/11] web: Display host_id in job view --- web/pages/mxq/mxq.in | 1 + 1 file changed, 1 insertion(+) diff --git a/web/pages/mxq/mxq.in b/web/pages/mxq/mxq.in index 0e85317c..9794b9ba 100755 --- a/web/pages/mxq/mxq.in +++ b/web/pages/mxq/mxq.in @@ -347,6 +347,7 @@ job_umask: : $job_umask_text host_submit : $o{host_submit} server_id : $o{server_id} +host_id : $o{host_id} host_hostname : $o{host_hostname} host_pid : $o{host_pid} From 8f9edb250ecf6aaefdbc3d800a76e1114f13ea8f Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 15:00:43 +0200 Subject: [PATCH 08/11] mxq_job: Load field host_id from table mxq_job --- mxq_job.c | 22 +++++++++++++--------- mxq_job.h | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mxq_job.c b/mxq_job.c index 16a64af5..a0789f8a 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -16,7 +16,7 @@ #include "mxq_group.h" #include "mxq_job.h" -#define JOB_FIELDS_CNT 34 +#define JOB_FIELDS_CNT 35 #define JOB_FIELDS \ " job_id, " \ " job_status, " \ @@ -32,28 +32,29 @@ \ " job_umask, " \ " host_submit, " \ + " host_id, " \ " server_id, " \ " host_hostname, " \ - " host_pid, " \ \ + " host_pid, " \ " host_slots, " \ " UNIX_TIMESTAMP(date_submit) as date_submit, " \ " UNIX_TIMESTAMP(date_start) as date_start, " \ " UNIX_TIMESTAMP(date_end) as date_end, " \ - " stats_status, " \ \ + " stats_status, " \ " stats_utime_sec, " \ " stats_utime_usec, " \ " stats_stime_sec, " \ " stats_stime_usec, " \ - " stats_real_sec, " \ \ + " stats_real_sec, " \ " stats_real_usec, " \ " stats_maxrss, " \ " stats_minflt, " \ " stats_majflt, " \ - " stats_nswap, " \ \ + " stats_nswap, " \ " stats_inblock, " \ " stats_oublock, " \ " stats_nvcsw, " \ @@ -81,28 +82,29 @@ static int bind_result_job_fields(struct mx_mysql_bind *result, struct mxq_job * res += mx_mysql_bind_var(result, idx++, uint32, &(j->job_umask)); res += mx_mysql_bind_var(result, idx++, string, &(j->host_submit)); + res += mx_mysql_bind_var(result, idx++, string, &(j->host_id)); res += mx_mysql_bind_var(result, idx++, string, &(j->server_id)); res += mx_mysql_bind_var(result, idx++, string, &(j->host_hostname)); - res += mx_mysql_bind_var(result, idx++, uint32, &(j->host_pid)); + res += mx_mysql_bind_var(result, idx++, uint32, &(j->host_pid)); res += mx_mysql_bind_var(result, idx++, uint32, &(j->host_slots)); res += mx_mysql_bind_var(result, idx++, int64, &(j->date_submit)); res += mx_mysql_bind_var(result, idx++, int64, &(j->date_start)); res += mx_mysql_bind_var(result, idx++, int64, &(j->date_end)); - res += mx_mysql_bind_var(result, idx++, int32, &(j->stats_status)); + res += mx_mysql_bind_var(result, idx++, int32, &(j->stats_status)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_utime.tv_sec)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_utime.tv_usec)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_stime.tv_sec)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_stime.tv_usec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_sec)); + res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_sec)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_usec)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_maxrss)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_minflt)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_majflt)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nswap)); + res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nswap)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_inblock)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_oublock)); res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nvcsw)); @@ -175,6 +177,8 @@ void mxq_job_free_content(struct mxq_job *j) mx_free_null(j->host_submit); j->_host_submit_length = 0; + mx_free_null(j->host_id); + mx_free_null(j->server_id); j->_server_id_length = 0; diff --git a/mxq_job.h b/mxq_job.h index 5d78ba1f..872010e8 100644 --- a/mxq_job.h +++ b/mxq_job.h @@ -40,6 +40,7 @@ struct mxq_job { char * host_submit; unsigned long _host_submit_length; + char * host_id; char * server_id; unsigned long _server_id_length; From 9c739de4d3a69e624e24251d04682b089ceab2cb Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 15:17:27 +0200 Subject: [PATCH 09/11] mxq_group/mxq_job: Cleanup old mxq_mysql fields not needed anymore --- mxq_group.c | 7 ------- mxq_group.h | 4 ---- mxq_job.c | 15 --------------- mxq_job.h | 7 ------- 4 files changed, 33 deletions(-) diff --git a/mxq_group.c b/mxq_group.c index 558fabdc..65f7757a 100644 --- a/mxq_group.c +++ b/mxq_group.c @@ -100,16 +100,9 @@ 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->group_name); - g->_group_name_length = 0; - mx_free_null(g->user_name); - g->_user_name_length = 0; - mx_free_null(g->user_group); - g->_user_group_length = 0; - mx_free_null(g->job_command); - g->_job_command_length = 0; } diff --git a/mxq_group.h b/mxq_group.h index db6b441e..e678cb31 100644 --- a/mxq_group.h +++ b/mxq_group.h @@ -10,7 +10,6 @@ struct mxq_group { uint64_t group_id; char * group_name; - unsigned long _group_name_length; uint8_t group_status; uint64_t group_flags; @@ -18,14 +17,11 @@ struct mxq_group { uint32_t user_uid; char * user_name; - unsigned long _user_name_length; uint32_t user_gid; char * user_group; - unsigned long _user_group_length; char * job_command; - unsigned long _job_command_length; uint16_t job_threads; uint64_t job_memory; diff --git a/mxq_job.c b/mxq_job.c index a0789f8a..1deabdb8 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -156,16 +156,9 @@ char *mxq_job_status_to_name(uint64_t status) void mxq_job_free_content(struct mxq_job *j) { mx_free_null(j->job_workdir); - j->_job_workdir_length = 0; - mx_free_null(j->job_argv_str); - j->_job_argv_str_length = 0; - mx_free_null(j->job_stdout); - j->_job_stdout_length = 0; - mx_free_null(j->job_stderr); - j->_job_stderr_length = 0; if (j->tmp_stderr == j->tmp_stdout) { j->tmp_stdout = NULL; @@ -173,18 +166,10 @@ void mxq_job_free_content(struct mxq_job *j) mx_free_null(j->tmp_stdout); } mx_free_null(j->tmp_stderr); - mx_free_null(j->host_submit); - j->_host_submit_length = 0; - mx_free_null(j->host_id); - mx_free_null(j->server_id); - j->_server_id_length = 0; - mx_free_null(j->host_hostname); - j->_host_hostname_length = 0; - mx_free_null(j->job_argv); j->job_argv = NULL; } diff --git a/mxq_job.h b/mxq_job.h index 872010e8..506849c9 100644 --- a/mxq_job.h +++ b/mxq_job.h @@ -19,18 +19,14 @@ struct mxq_job { struct mxq_group * group_ptr; char * job_workdir; - unsigned long _job_workdir_length; uint16_t job_argc; char ** job_argv; char * job_argv_str; - unsigned long _job_argv_str_length; char * job_stdout; - unsigned long _job_stdout_length; char * job_stderr; - unsigned long _job_stderr_length; char * tmp_stdout; char * tmp_stderr; @@ -38,14 +34,11 @@ struct mxq_job { uint32_t job_umask; char * host_submit; - unsigned long _host_submit_length; char * host_id; char * server_id; - unsigned long _server_id_length; char * host_hostname; - unsigned long _host_hostname_length; uint32_t host_pid; uint32_t host_slots; From 4834dda44afefe67c4337bd2c78e048a58790fd4 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 15:40:43 +0200 Subject: [PATCH 10/11] mxqd: Fix max job per node limit fixes 603a8c8 --- mxqd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxqd.c b/mxqd.c index e923b065..17ba8772 100644 --- a/mxqd.c +++ b/mxqd.c @@ -447,7 +447,7 @@ void group_init(struct mxq_group_list *group) jobs_max /= g->job_threads; /* limit maximum number of jobs on user/group request */ - if (jobs_max > g->job_max_per_node) + if (g->job_max_per_node && jobs_max > g->job_max_per_node) jobs_max = g->job_max_per_node; slots_max = jobs_max * slots_per_job; From 1db234809267ef6328fd783fe7d9ed7aa4fc81d5 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 24 Sep 2015 15:03:31 +0200 Subject: [PATCH 11/11] mxqd: Set host_id for job after loading job from database --- mxq_job.c | 17 ++++++++++++----- mxq_job.h | 2 +- mxqd.c | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mxq_job.c b/mxq_job.c index a0789f8a..0a129ce3 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -395,19 +395,21 @@ int mxq_set_job_status_loaded_on_server(struct mx_mysql *mysql, struct mxq_job * char *query = "UPDATE mxq_job SET" " job_status = " status_str(MXQ_JOB_STATUS_LOADED) + ", host_id = ?" " WHERE job_id = ?" " AND job_status = " status_str(MXQ_JOB_STATUS_ASSIGNED) " AND host_hostname = ?" " AND server_id = ?" " AND host_pid = 0"; - res = mx_mysql_bind_init_param(¶m, 3); + res = mx_mysql_bind_init_param(¶m, 4); assert(res == 0); res = 0; - res += mx_mysql_bind_var(¶m, 0, uint64, &(job->job_id)); - res += mx_mysql_bind_var(¶m, 1, string, &(job->host_hostname)); - res += mx_mysql_bind_var(¶m, 2, string, &(job->server_id)); + res += mx_mysql_bind_var(¶m, 0, string, &(job->host_id)); + res += mx_mysql_bind_var(¶m, 1, uint64, &(job->job_id)); + res += mx_mysql_bind_var(¶m, 2, string, &(job->host_hostname)); + res += mx_mysql_bind_var(¶m, 3, string, &(job->server_id)); assert(res == 0); res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); @@ -666,7 +668,7 @@ int mxq_load_job_assigned_to_server(struct mx_mysql *mysql, struct mxq_job **mxq return res; } -int mxq_load_job_from_group_for_server(struct mx_mysql *mysql, struct mxq_job *mxqjob, uint64_t group_id, char *hostname, char *server_id) +int mxq_load_job_from_group_for_server(struct mx_mysql *mysql, struct mxq_job *mxqjob, uint64_t group_id, char *hostname, char *server_id, char *host_id) { int res; struct mxq_job *jobs = NULL; @@ -677,6 +679,8 @@ int mxq_load_job_from_group_for_server(struct mx_mysql *mysql, struct mxq_job *m assert(*hostname); assert(server_id); assert(*server_id); + assert(host_id); + assert(*host_id); do { res = mxq_load_job_assigned_to_server(mysql, &jobs, hostname, server_id); @@ -701,6 +705,9 @@ int mxq_load_job_from_group_for_server(struct mx_mysql *mysql, struct mxq_job *m } } while (1); + mx_free_null(mxqjob->host_id); + mxqjob->host_id = mx_strdup_forever(host_id); + res = mxq_set_job_status_loaded_on_server(mysql, mxqjob); if (res < 0) { mx_log_err(" group_id=%lu job_id=%lu :: mxq_set_job_status_loaded_on_server(): %m", group_id, mxqjob->job_id); diff --git a/mxq_job.h b/mxq_job.h index 872010e8..4b092593 100644 --- a/mxq_job.h +++ b/mxq_job.h @@ -108,6 +108,6 @@ int mxq_set_job_status_exited(struct mx_mysql *mysql, struct mxq_job *job); int mxq_set_job_status_unknown_for_server(struct mx_mysql *mysql, char *hostname, char *server_id); int mxq_job_set_tmpfilenames(struct mxq_group *g, struct mxq_job *j); int mxq_load_job_assigned_to_server(struct mx_mysql *mysql, struct mxq_job **mxq_jobs, char *hostname, char *server_id); -int mxq_load_job_from_group_for_server(struct mx_mysql *mysql, struct mxq_job *mxqjob, uint64_t group_id, char *hostname, char *server_id); +int mxq_load_job_from_group_for_server(struct mx_mysql *mysql, struct mxq_job *mxqjob, uint64_t group_id, char *hostname, char *server_id, char *host_id); #endif diff --git a/mxqd.c b/mxqd.c index d69017b8..54cca2ae 100644 --- a/mxqd.c +++ b/mxqd.c @@ -1019,7 +1019,7 @@ unsigned long start_job(struct mxq_group_list *group) server = group->user->server; - res = mxq_load_job_from_group_for_server(server->mysql, &mxqjob, group->group.group_id, server->hostname, server->server_id); + res = mxq_load_job_from_group_for_server(server->mysql, &mxqjob, group->group.group_id, server->hostname, server->server_id, server->host_id); if (!res) { return 0;