shrub/v/save.c

121 lines
2.1 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* v/save.c
**
** This file is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
2014-01-16 00:21:04 +04:00
#include <sys/wait.h>
2013-09-29 00:21:18 +04:00
#include <unistd.h>
#include <setjmp.h>
#include <gmp.h>
#include <stdint.h>
#include <termios.h>
#include <uv.h>
#include "all.h"
#include "v/vere.h"
2013-10-14 22:23:55 +04:00
/* _save_sign_cb: signal callback.
*/
static void
_save_sign_cb(uv_signal_t* sil_u, c3_i num_i)
{
uL(fprintf(uH, "save: signal %d\n", num_i));
{
switch ( num_i ) {
2014-09-11 04:01:32 +04:00
case SIGCHLD: u3_save_ef_chld(); break;
}
}
2013-10-14 22:23:55 +04:00
}
2013-09-29 00:21:18 +04:00
/* _save_time_cb(): timer callback.
*/
static void
_save_time_cb(uv_timer_t* tim_u, c3_i sas_i)
{
2014-09-11 04:01:32 +04:00
u3_save* sav_u = &u3_Host.sav_u;
2013-09-29 00:21:18 +04:00
2013-10-04 00:38:37 +04:00
if ( sav_u->pid_w ) {
return;
}
2014-09-11 04:01:32 +04:00
if ( u3A->ent_d > sav_u->ent_d ) {
// uL(fprintf(uH, "autosaving... ent_d %llu\n", u3A->ent_d));
2013-09-29 00:21:18 +04:00
2014-09-11 04:01:32 +04:00
u3_cm_purge();
// u3_lo_grab("save", u3_none);
2013-09-29 00:21:18 +04:00
2013-10-04 00:38:37 +04:00
#ifdef FORKPT
c3_w pid_w;
2013-10-04 00:38:37 +04:00
if ( 0 == (pid_w = fork()) ) {
2014-09-11 04:01:32 +04:00
u3_loom_save(u3A->ent_d);
2013-10-04 00:38:37 +04:00
exit(0);
}
2013-10-04 00:38:37 +04:00
else {
uL(fprintf(uH, "checkpoint: process %d\n", pid_w));
2013-10-04 00:38:37 +04:00
2014-09-11 04:01:32 +04:00
sav_u->ent_d = u3A->ent_d;
2013-10-04 00:38:37 +04:00
sav_u->pid_w = pid_w;
}
#else
2014-09-11 04:01:32 +04:00
u3_loom_save(u3A->ent_d);
sav_u->ent_d = u3A->ent_d;
2013-10-04 00:38:37 +04:00
#endif
}
2013-10-04 00:38:37 +04:00
}
2014-09-11 04:01:32 +04:00
/* u3_save_ef_chld(): report save termination.
2013-10-04 00:38:37 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_save_ef_chld(void)
2013-10-04 00:38:37 +04:00
{
2014-09-11 04:01:32 +04:00
u3_save* sav_u = &u3_Host.sav_u;
2013-10-04 00:38:37 +04:00
c3_i loc_i;
c3_w pid_w;
/* modified for cases with no pid_w
*/
uL(fprintf(uH, "checkpoint: complete %d\n", sav_u->pid_w));
2013-10-04 00:38:37 +04:00
pid_w = wait(&loc_i);
2013-11-12 11:09:11 +04:00
if (0 != sav_u->pid_w) {
c3_assert(pid_w == sav_u->pid_w);
}
2013-11-12 11:09:11 +04:00
else {
c3_assert(pid_w > 0);
}
2013-10-04 00:38:37 +04:00
sav_u->pid_w = 0;
2013-09-29 00:21:18 +04:00
}
2014-09-11 04:01:32 +04:00
/* u3_save_io_init(): initialize autosave.
2013-09-29 00:21:18 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_save_io_init(void)
2013-09-29 00:21:18 +04:00
{
2014-09-11 04:01:32 +04:00
u3_save* sav_u = &u3_Host.sav_u;
2013-09-29 00:21:18 +04:00
2014-04-08 20:25:49 +04:00
sav_u->ent_d = 0;
2013-10-04 00:38:37 +04:00
sav_u->pid_w = 0;
2014-09-11 04:01:32 +04:00
uv_timer_init(u3L, &sav_u->tim_u);
2013-11-12 11:09:11 +04:00
uv_timer_start(&sav_u->tim_u, _save_time_cb, 15000, 15000);
2013-10-14 22:23:55 +04:00
uv_signal_start(&sav_u->sil_u, _save_sign_cb, SIGCHLD);
2013-09-29 00:21:18 +04:00
}
2014-09-11 04:01:32 +04:00
/* u3_save_io_exit(): terminate save I/O.
2013-09-29 00:21:18 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_save_io_exit(void)
2013-09-29 00:21:18 +04:00
{
}
2014-09-11 04:01:32 +04:00
/* u3_save_io_poll(): poll kernel for save I/O.
2013-09-29 00:21:18 +04:00
*/
void
2014-09-11 04:01:32 +04:00
u3_save_io_poll(void)
2013-09-29 00:21:18 +04:00
{
}