Commit 92c4ec59 authored by Siddharth Aggarwal's avatar Siddharth Aggarwal

Code works for checkpointing an active filesystem on s1

parent 94ccc3f4
......@@ -9,3 +9,4 @@ BINGRP= kmem
BINMODE= 2555
.include <bsd.prog.mk>
......@@ -10,6 +10,7 @@ void InitBlockAllocator (int method, long range_start, long range_size)
{
reclaim_method = method;
block_range.start = range_start;
range_size = 200;
block_range.end = range_start + range_size;
block_range.ptr = range_start;
printf ("Initialized block allocator to start = %ld, end = %ld\n", block_range.ptr, block_range.end);
......@@ -57,16 +58,20 @@ int BlockFree (long start, long size)
struct FreeSpaceQueue* temp = head;
long end = (start + size) % shadow_size;
/*printf ("Freeing blocks %ld to %ld\n", start, end);*/
printf ("Free space queue before deleting block = \n");
PrintFreeSpaceQueue ();
printf ("Freeing blocks %ld to %ld\n", start, end);
while (temp != 0)
{
if (temp->start == (end + 1) % shadow_size)
if ((temp->start == (end + 1) % shadow_size)
|| (temp->start == end))
{
temp->start = start;
return 0;
}
else
if ((temp->end + 1) % shadow_size == start)
if (((temp->end + 1) % shadow_size == start)
|| (temp->end == start))
{
temp->end = end;
return 0;
......@@ -74,6 +79,8 @@ int BlockFree (long start, long size)
temp = temp->next;
}
AddFreeSpaceToQueue (start, end);
printf ("Free space queue after deleting block = \n");
PrintFreeSpaceQueue ();
return 0;
}
......@@ -81,6 +88,8 @@ long BlockAlloc (int size)
{
struct FreeSpaceQueue* temp = 0;
long retVal;
printf ("Free space queue before allocating block = \n");
PrintFreeSpaceQueue ();
switch (reclaim_method)
{
case LAST_CKPT_AUTO_DELETE:
......@@ -96,8 +105,6 @@ long BlockAlloc (int size)
case EXPLICIT_CKPT_DELETE:
while (CurrentFreeBlockSize () < size)
{
/*printf ("size = %d, free_block_size = %d\n", size, CurrentFreeBlockSize());
printf ("end = %ld, ptr = %ld\n", block_range.end, block_range.ptr);*/
if (-1 == MergeWithNextFreeBlockRange ( CurrentFreeBlockSize() ))
{
printf ("Error! No more free space on disk\n");
......@@ -108,7 +115,9 @@ long BlockAlloc (int size)
}
retVal = block_range.ptr;
block_range.ptr += size;
/*printf ("Allocating %d blocks starting %d\n", size, retVal);*/
printf ("Allocating %d blocks starting %d\n", size, retVal);
printf ("Free space queue after allocating block = \n");
PrintFreeSpaceQueue ();
return retVal;
}
......@@ -172,9 +181,10 @@ int PrintFreeSpaceQueue()
struct FreeSpaceQueue* current = head;
while (current != 0)
{
printf ("%ld %ld\n", current->start, current->end);
printf ("%ld<->%ld ", current->start, current->end);
current = current->next;
}
printf ("\n");
return 0;
}
......
This diff is collapsed.
......@@ -26,6 +26,8 @@ static const char rcsid[] =
#include "pathnames.h"
#include "trie.h"
extern struct proc *curproc;
#define MAXBUF 65316
#define BLOCKSIZE 512
......@@ -152,7 +154,9 @@ do_single(argc, argv, action, flags)
if (strcmp (cp, "-c") == 0)
{
if (do_io(shd, SHDCHECKPOINT, &shio))
{
return (1);
}
}
else
if (strcmp (cp, "-g") == 0)
......@@ -191,6 +195,15 @@ do_single(argc, argv, action, flags)
return (1);
}
else
if (strcmp (cp, "-rv") == 0)
{
version = atoi(*argv++); --argc;
printf ("Reboot version set to %d\n", version);
shio.version = version;
if (do_io(shd, SHDSETREBOOTVERSION, &shio))
return (1);
}
else
if (strcmp (cp, "-sm") == 0)
{
if (do_io(shd, SHDSAVECHECKPOINTMAP, &shio))
......@@ -200,8 +213,12 @@ do_single(argc, argv, action, flags)
if (strcmp (cp, "-sv") == 0)
{
version = atoi(*argv++); --argc;
printf ("Saving version %d\n", version);
save_checkpoint (shd, version);
maxversion = atoi(*argv++); --argc;
for (old_ver = version; old_ver <= maxversion; old_ver++)
{
printf ("Saving version %d\n", old_ver);
save_checkpoint (shd, old_ver);
}
}
else
if (strcmp (cp, "-l") == 0)
......@@ -214,7 +231,6 @@ do_single(argc, argv, action, flags)
perror ("error");
return;
}
version = atoi(*argv++); --argc;
maxversion = atoi(*argv++); --argc;
off = lseek (fd_write_mdata, 2 * BLOCKSIZE, SEEK_SET);
......@@ -655,6 +671,16 @@ usage()
exit(1);
}
char *
itoa(int value)
{
static char buf[13];
snprintf(buf, 12, "%d", value);
return buf;
}
int save_checkpoint (char * shd, int version)
{
struct shd_readbuf shread;
......@@ -670,9 +696,9 @@ int save_checkpoint (char * shd, int version)
int read_start;
int num_blocks;
char path[256];
char ver[2];
ver[0] = (char *) version;
ver[1] = 0;
char ver_buf[2];
char *ver = &ver_buf;
ver = itoa (version);
strcpy (path, "/users/saggarwa/image");
strcat (path, ver);
strcat (path, ".data");
......@@ -783,9 +809,9 @@ int load_checkpoint (char * shd, int version, int newversion)
long key;
long value;
char path[256];
char ver[2];
ver[0] = (char *) version;
ver[1] = 0;
char ver_buf[2];
char *ver = &ver_buf;
ver = itoa (version);
strcpy (path, "/users/saggarwa/image");
strcat (path, ver);
strcat (path, ".data");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment