Skip to content

Commit

Permalink
Merge branch 'develop' into msl/loom-migration-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Oct 30, 2023
2 parents 574bf78 + 2b024e9 commit 0269cf7
Show file tree
Hide file tree
Showing 30 changed files with 1,344 additions and 628 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ jobs:
upload: true
next: ${{ github.ref_name }}
secrets: inherit

docker:
uses: ./.github/workflows/docker-shared.yml
secrets: inherit
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# IDEs.
/.vscode
/.idea

# Bazel.
/.user.bazelrc
/bazel-*
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12
3.0
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
mkdir(a, b);})
# define c3_rmdir(a) ({ \
rmdir(a);})
# define c3_link(a, b) ({ \
link(a, b);})
# define c3_unlink(a) ({ \
unlink(a);})
# define c3_fopen(a, b) ({ \
Expand Down
122 changes: 72 additions & 50 deletions pkg/noun/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,14 @@ _ce_ephemeral_open(c3_i* eph_i)
/* _ce_image_open(): open or create image.
*/
static c3_o
_ce_image_open(u3e_image* img_u)
_ce_image_open(u3e_image* img_u, c3_c* ful_c)
{
c3_i mod_i = O_RDWR | O_CREAT;
c3_c ful_c[8193];

snprintf(ful_c, 8192, "%s", u3P.dir_c);
c3_mkdir(ful_c, 0700);

snprintf(ful_c, 8192, "%s/.urb", u3P.dir_c);
c3_mkdir(ful_c, 0700);

snprintf(ful_c, 8192, "%s/.urb/chk", u3P.dir_c);
c3_mkdir(ful_c, 0700);

snprintf(ful_c, 8192, "%s/.urb/chk/%s.bin", u3P.dir_c, img_u->nam_c);
if ( -1 == (img_u->fid_i = c3_open(ful_c, mod_i, 0666)) ) {
fprintf(stderr, "loom: c3_open %s: %s\r\n", ful_c, strerror(errno));
c3_c pax_c[8192];
snprintf(pax_c, 8192, "%s/%s.bin", ful_c, img_u->nam_c);
if ( -1 == (img_u->fid_i = c3_open(pax_c, mod_i, 0666)) ) {
fprintf(stderr, "loom: c3_open %s: %s\r\n", pax_c, strerror(errno));
return c3n;
}
else if ( c3n == _ce_image_stat(img_u, &img_u->pgs_w) ) {
Expand Down Expand Up @@ -787,14 +778,16 @@ _ce_patch_sync(u3_ce_patch* pat_u)

/* _ce_image_sync(): make sure image is synced to disk.
*/
static void
static c3_o
_ce_image_sync(u3e_image* img_u)
{
if ( -1 == c3_sync(img_u->fid_i) ) {
fprintf(stderr, "loom: image (%s) sync failed: %s\r\n",
img_u->nam_c, strerror(errno));
u3_assert(!"loom: image sync");
return c3n;
}

return c3y;
}

/* _ce_image_resize(): resize image, truncating if it shrunk.
Expand Down Expand Up @@ -1345,54 +1338,77 @@ _ce_image_copy(u3e_image* fom_u, u3e_image* tou_u)
return c3y;
}

/* u3e_backup(): copy snapshot to .urb/bhk (if it doesn't exist yet).
/* u3e_backup(): copy snapshot from [pux_c] to [pax_c],
* overwriting optionally. note that image files must
* be named "north" and "south".
*/
c3_o
u3e_backup(c3_o ovw_o)
u3e_backup(c3_c* pux_c, c3_c* pax_c, c3_o ovw_o)
{
u3e_image nop_u = { .nam_c = "north", .pgs_w = 0 };
u3e_image sop_u = { .nam_c = "south", .pgs_w = 0 };
c3_i mod_i = O_RDWR | O_CREAT; // XX O_TRUNC ?
c3_c ful_c[8193];
// source image files from [pux_c]
u3e_image nux_u = { .nam_c = "north", .pgs_w = 0 };
u3e_image sux_u = { .nam_c = "south", .pgs_w = 0 };

// destination image files to [pax_c]
u3e_image nax_u = { .nam_c = "north", .pgs_w = 0 };
u3e_image sax_u = { .nam_c = "south", .pgs_w = 0 };

snprintf(ful_c, 8192, "%s/.urb/bhk", u3P.dir_c);
c3_i mod_i = O_RDWR | O_CREAT;

if ( !pux_c || !pax_c ) {
fprintf(stderr, "loom: image backup: bad path\r\n");
return c3n;
}

if ( (c3n == ovw_o) && c3_mkdir(ful_c, 0700) ) {
if ( (c3n == ovw_o) && c3_mkdir(pax_c, 0700) ) {
if ( EEXIST != errno ) {
fprintf(stderr, "loom: image backup: %s\r\n", strerror(errno));
}
return c3n;
}

snprintf(ful_c, 8192, "%s/.urb/bhk/%s.bin", u3P.dir_c, nop_u.nam_c);

if ( -1 == (nop_u.fid_i = c3_open(ful_c, mod_i, 0666)) ) {
fprintf(stderr, "loom: c3_open %s: %s\r\n", ful_c, strerror(errno));
// open source image files if they exist
//
c3_c nux_c[8193];
snprintf(nux_c, 8192, "%s/%s.bin", pux_c, nux_u.nam_c);
if ( (0 != access(nux_c, F_OK)) || (c3n == _ce_image_open(&nux_u, pux_c)) ) {
fprintf(stderr, "loom: couldn't open north image at %s\r\n", pux_c);
return c3n;
}
c3_c sux_c[8193];
snprintf(sux_c, 8192, "%s/%s.bin", pux_c, sux_u.nam_c);
if ( (0 != access(sux_c, F_OK)) || (c3n == _ce_image_open(&sux_u, pux_c)) ) {
fprintf(stderr, "loom: couldn't open south image at %s\r\n", pux_c);
return c3n;
}

snprintf(ful_c, 8192, "%s/.urb/bhk/%s.bin", u3P.dir_c, sop_u.nam_c);

if ( -1 == (sop_u.fid_i = c3_open(ful_c, mod_i, 0666)) ) {
fprintf(stderr, "loom: c3_open %s: %s\r\n", ful_c, strerror(errno));
// open destination image files
c3_c nax_c[8193];
snprintf(nax_c, 8192, "%s/%s.bin", pax_c, nax_u.nam_c);
if ( -1 == (nax_u.fid_i = c3_open(nax_c, mod_i, 0666)) ) {
fprintf(stderr, "loom: c3_open %s: %s\r\n", nax_c, strerror(errno));
return c3n;
}
c3_c sax_c[8193];
snprintf(sax_c, 8192, "%s/%s.bin", pax_c, sax_u.nam_c);
if ( -1 == (sax_u.fid_i = c3_open(sax_c, mod_i, 0666)) ) {
fprintf(stderr, "loom: c3_open %s: %s\r\n", sax_c, strerror(errno));
return c3n;
}

if ( (c3n == _ce_image_copy(&u3P.nor_u, &nop_u))
|| (c3n == _ce_image_copy(&u3P.sou_u, &sop_u)) )
if ( (c3n == _ce_image_copy(&nux_u, &nax_u))
|| (c3n == _ce_image_copy(&sux_u, &sax_u))
|| (c3n == _ce_image_sync(&nax_u))
|| (c3n == _ce_image_sync(&sax_u)) )
{

c3_unlink(ful_c);
snprintf(ful_c, 8192, "%s/.urb/bhk/%s.bin", u3P.dir_c, nop_u.nam_c);
c3_unlink(ful_c);
snprintf(ful_c, 8192, "%s/.urb/bhk", u3P.dir_c);
c3_rmdir(ful_c);
c3_unlink(nax_c);
c3_unlink(sax_c);
fprintf(stderr, "loom: image backup failed\r\n");
return c3n;
}

close(nop_u.fid_i);
close(sop_u.fid_i);
close(nax_u.fid_i);
close(sax_u.fid_i);
fprintf(stderr, "loom: image backup complete\r\n");
return c3y;
}
Expand Down Expand Up @@ -1462,8 +1478,9 @@ u3e_save(u3_post low_p, u3_post hig_p)

_ce_patch_apply(pat_u);

_ce_image_sync(&u3P.nor_u);
_ce_image_sync(&u3P.sou_u);
u3_assert( c3y == _ce_image_sync(&u3P.nor_u) );
u3_assert( c3y == _ce_image_sync(&u3P.sou_u) );

_ce_patch_free(pat_u);
_ce_patch_delete();

Expand Down Expand Up @@ -1502,8 +1519,6 @@ u3e_save(u3_post low_p, u3_post hig_p)
}

u3e_toss(low_p, hig_p);

u3e_backup(c3n);
}

/* _ce_toss_pages(): discard ephemeral pages.
Expand Down Expand Up @@ -1573,8 +1588,10 @@ u3e_live(c3_o nuu_o, c3_c* dir_c)

// Open image files.
//
if ( (c3n == _ce_image_open(&u3P.nor_u)) ||
(c3n == _ce_image_open(&u3P.sou_u)) )
c3_c chk_c[8193];
snprintf(chk_c, 8193, "%s/.urb/chk", u3P.dir_c);
if ( (c3n == _ce_image_open(&u3P.nor_u, chk_c)) ||
(c3n == _ce_image_open(&u3P.sou_u, chk_c)) )
{
fprintf(stderr, "boot: image failed\r\n");
exit(1);
Expand All @@ -1587,8 +1604,8 @@ u3e_live(c3_o nuu_o, c3_c* dir_c)
*/
if ( 0 != (pat_u = _ce_patch_open()) ) {
_ce_patch_apply(pat_u);
_ce_image_sync(&u3P.nor_u);
_ce_image_sync(&u3P.sou_u);
u3_assert( c3y == _ce_image_sync(&u3P.nor_u) );
u3_assert( c3y == _ce_image_sync(&u3P.sou_u) );
_ce_patch_free(pat_u);
_ce_patch_delete();
}
Expand Down Expand Up @@ -1659,6 +1676,9 @@ u3e_stop(void)
close(u3P.eph_i);
unlink(u3C.eph_c);
}

close(u3P.sou_u.fid_i);
close(u3P.sou_u.fid_i);
}

/* u3e_yolo(): disable dirty page tracking, read/write whole loom.
Expand Down Expand Up @@ -1698,6 +1718,8 @@ u3e_init(void)
{
u3P.pag_w = u3C.wor_i >> u3a_page;

u3P.nor_u.fid_i = u3P.sou_u.fid_i = -1;

u3e_foul();

#ifdef U3_GUARD_PAGE
Expand Down
7 changes: 4 additions & 3 deletions pkg/noun/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@

/** Functions.
**/
/* u3e_backup(): copy the snapshot from chk to bhk.
/* u3e_backup(): copy the snapshot from [pux_c] to [pax_c],
* overwriting optional.
*/
c3_o
u3e_backup(c3_o ovw_o);
c3_o
u3e_backup(c3_c* pux_c, c3_c* pax_c, c3_o ovw_o);

/* u3e_fault(): handle a memory fault.
*/
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/jets/c/dor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


u3_noun
u3qc_dor(u3_atom a,
u3_atom b)
u3qc_dor(u3_noun a,
u3_noun b)
{
if ( c3y == u3r_sing(a, b) ) {
return c3y;
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/jets/c/mor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


u3_noun
u3qc_mor(u3_atom a,
u3_atom b)
u3qc_mor(u3_noun a,
u3_noun b)
{
c3_w c_w = u3r_mug(u3r_mug(a));
c3_w d_w = u3r_mug(u3r_mug(b));
Expand Down
7 changes: 2 additions & 5 deletions pkg/noun/jets/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2224,11 +2224,8 @@ static u3j_core _139_qua_d[] =
{ "mole", 7, _140_qua_mole_a, 0, no_hashes },
{ "mule", 7, _140_qua_mule_a, 0, no_hashes },

// XX disabled, implicated in memory corruption
// write tests and re-enable
//
// { "scot", 7, _140_qua_scot_a, 0, no_hashes },
// { "scow", 7, _140_qua_scow_a, 0, no_hashes },
{ "scot", 7, _140_qua_scot_a, 0, no_hashes },
{ "scow", 7, _140_qua_scow_a, 0, no_hashes },
{ "slaw", 7, _140_qua_slaw_a, 0, no_hashes },
{}
};
Expand Down
46 changes: 37 additions & 9 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1766,14 +1766,6 @@ _cm_limits(void)
# endif
}

/* u3m_backup(): copy snapshot to .urb/bhk (if it doesn't exist yet).
*/
c3_o
u3m_backup(c3_o ovw_o)
{
return u3e_backup(ovw_o);
}

/* u3m_fault(): handle a memory event with libsigsegv protocol.
*/
c3_i
Expand Down Expand Up @@ -2094,6 +2086,42 @@ u3m_stop()
u3je_secp_stop();
}

/* u3m_pier(): make a pier.
*/
c3_c*
u3m_pier(c3_c* dir_c)
{
c3_c ful_c[8193];

u3C.dir_c = dir_c;

snprintf(ful_c, 8192, "%s", dir_c);
if ( c3_mkdir(ful_c, 0700) ) {
if ( EEXIST != errno ) {
fprintf(stderr, "loom: pier create: %s\r\n", strerror(errno));
exit(1);
}
}

snprintf(ful_c, 8192, "%s/.urb", dir_c);
if ( c3_mkdir(ful_c, 0700) ) {
if ( EEXIST != errno ) {
fprintf(stderr, "loom: .urb create: %s\r\n", strerror(errno));
exit(1);
}
}

snprintf(ful_c, 8192, "%s/.urb/chk", dir_c);
if ( c3_mkdir(ful_c, 0700) ) {
if ( EEXIST != errno ) {
fprintf(stderr, "loom: .urb/chk create: %s\r\n", strerror(errno));
exit(1);
}
}

return strdup(dir_c);
}

/* u3m_boot(): start the u3 system. return next event, starting from 1.
*/
c3_d
Expand All @@ -2109,7 +2137,7 @@ u3m_boot(c3_c* dir_c, size_t len_i)

/* Activate the storage system.
*/
nuu_o = u3e_live(c3n, dir_c);
nuu_o = u3e_live(c3n, u3m_pier(dir_c));

/* Activate tracing.
*/
Expand Down
Loading

0 comments on commit 0269cf7

Please sign in to comment.