Skip to content

Commit

Permalink
mxqd: Use helper to unmount tmpdir
Browse files Browse the repository at this point in the history
Use the external helper to unmount the tmpdir. We are going to
experiment with more complex tmpdir settings in the future which might
be difficult to code in C.
  • Loading branch information
donald committed Apr 20, 2022
1 parent ce29daf commit 7e12f25
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ static void exec_reaper(struct mxq_server *server,struct mxq_group_list *glist,
argv[0]);
}

static char tmpdir_script[] = LIBEXECDIR "/mxq/tmpdir-setup";

static unsigned long start_job(struct mxq_group_list *glist)
{
struct mxq_server *server;
Expand All @@ -1158,8 +1160,6 @@ static unsigned long start_job(struct mxq_group_list *glist)

struct mxq_daemon *daemon;

static char tmpdir_script[] = LIBEXECDIR "/mxq/tmpdir-setup";

pid_t pid;
int res;

Expand Down Expand Up @@ -1871,31 +1871,17 @@ static void rename_outfiles(struct mxq_server *server, struct mxq_group *group,
}
}

static char *job_tmpdir_path(unsigned long job_id) {
char *pathname;
pathname = mx_asprintf_forever("%s/%lu", MXQ_JOB_TMPDIR_MNTDIR, job_id);
return pathname;
}

static int unmount_and_remove(char *pathname) {
int res;
res = rmdir(pathname);
if (res && errno==EBUSY) {
res = umount(pathname);
if (res == 0) {
res = rmdir(pathname);
}
}
return res;
}

static void unmount_job_tmpdir(unsigned long job_id) {
char *pathname;
pathname=job_tmpdir_path(job_id);
if (unmount_and_remove(pathname)) {
mx_log_warning("failed to unmount/remove stale job tmpdir %s: %m", pathname);
}
free(pathname);
char *argv[] = {
tmpdir_script,
"cleanup",
mx_asprintf_forever("%lu", job_id),
NULL
};
int res = mx_call_external(tmpdir_script, argv);
free(argv[2]);
if (res == -1)
mx_log_err("cleanup job tmpdir: %m");
}

static void release_gpu(struct mxq_server *server, struct mxq_group *group, struct mxq_job *job) {
Expand Down

0 comments on commit 7e12f25

Please sign in to comment.