Commit 97c60ef0 authored by Siddharth Aggarwal's avatar Siddharth Aggarwal

works with imagezip now

parent d806e950
......@@ -207,37 +207,54 @@ void (*shdrebootp)(void);
int checkpt_flag = 0;
int checkpt_process_sleep_variable = 0;
extern int getmntinfo(struct statfs **mntbufp, int flags);
void sync_before_checkpoint (void)
{
register struct buf *bp;
int iter, nbusy, pbusy;
struct nameidata nd[5];
/*struct nameidata nd;
int mnt_cnt;
struct statfs *mntbuf;
int i;*/
/*struct nameidata nd;*/
int i;
int error;
/*register struct mount *mp, *nmp;
struct statfs *sp, sb;
char mntonname[128];*/
waittime = 0;
printf("\nsyncing disks... ");
checkpt_flag = 1;
/*mnt_cnt = getmntinfo(&mntbuf, MNT_NOWAIT);
if (mnt_cnt > 0)
/*for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp)
{
for (i = 0; i < mnt_cnt; i++)
if (strcmp (mntbuf[i].f_fstypename, "ufs") == 0)
if (prison_valid_mount(curproc->p_prison, mp, mntonname))
{
sp = &mp->mnt_stat;
error = VFS_STATFS(mp, sp, curproc);
if (error)
{
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, mntbuf[i].f_mntonname, curproc);
if ((error = namei(&nd)) != 0)
printf ("error calling VFS_STATFS\n");
}
if (*mntonname)
{
bcopy((caddr_t)sp, (caddr_t)&sb, sizeof(sb));
if (sb.f_fstypename[0] == 'u' && sb.f_fstypename[1] == 'f' && sb.f_fstypename[2] == 's')
{
printf ("Found %s\n", sb.f_mntonname);
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, sb.f_mntonname, curproc);
if ((error = namei(&nd)) != 0)
printf ("Error = %d\n", error);
while (nd.ni_vp->v_mount->mnt_ops_in_progress)
while (nd.ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
NDFREE(&nd, NDF_ONLY_PNBUF);
NDFREE(&nd, NDF_ONLY_PNBUF);
}
}
}
nmp = TAILQ_NEXT(mp, mnt_list);
}*/
NDINIT(&nd[0], LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc);
if ((error = namei(&nd[0])) != 0)
printf ("Error = %d\n", error);
......@@ -247,47 +264,28 @@ void sync_before_checkpoint (void)
NDINIT(&nd[2], LOOKUP, FOLLOW, UIO_SYSSPACE, "/var", curproc);
if ((error = namei(&nd[2])) != 0)
printf ("Error = %d\n", error);
NDINIT(&nd[3], LOOKUP, FOLLOW, UIO_SYSSPACE, "/tmp", curproc);
/*NDINIT(&nd[3], LOOKUP, FOLLOW, UIO_SYSSPACE, "/tmp", curproc);
if ((error = namei(&nd[3])) != 0)
printf ("Error = %d\n", error);
printf ("Error = %d\n", error);*/
/*
printf ("vp0 = %x\n", nd[0]);
printf ("vp1 = %x\n", nd[1]);
printf ("vp2 = %x\n", nd[2]);
printf ("vp3 = %x\n", nd[3]);
printf ("vp0 vp = %x\n", nd[0].ni_vp);
printf ("vp1 vp = %x\n", nd[1].ni_vp);
printf ("vp2 vp = %x\n", nd[2].ni_vp);
printf ("vp3 vp = %x\n", nd[3].ni_vp);
printf ("vp0 vp mount= %x\n", nd[0].ni_vp->v_mount);
printf ("vp1 vp mount= %x\n", nd[1].ni_vp->v_mount);
printf ("vp2 vp mount= %x\n", nd[2].ni_vp->v_mount);
printf ("vp3 vp mount= %x\n", nd[3].ni_vp->v_mount);
printf ("vp0 vp mount mnt_ops_in_progress= %x\n", nd[0].ni_vp->v_mount->mnt_ops_in_progress);
printf ("vp1 vp mount mnt_ops_in_progress= %x\n", nd[1].ni_vp->v_mount->mnt_ops_in_progress);
printf ("vp2 vp mount mnt_ops_in_progress= %x\n", nd[2].ni_vp->v_mount->mnt_ops_in_progress);
printf ("vp3 vp mount mnt_ops_in_progress= %x\n", nd[3].ni_vp->v_mount->mnt_ops_in_progress);*/
while (nd[0].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
while (nd[1].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
while (nd[2].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
while (nd[3].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
/* while (nd[3].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);*/
NDFREE(&nd[0], NDF_ONLY_PNBUF);
NDFREE(&nd[1], NDF_ONLY_PNBUF);
NDFREE(&nd[2], NDF_ONLY_PNBUF);
NDFREE(&nd[3], NDF_ONLY_PNBUF);
/*NDFREE(&nd[3], NDF_ONLY_PNBUF);*/
vrele(nd[0].ni_vp);
vrele(nd[1].ni_vp);
vrele(nd[2].ni_vp);
/* vrele(nd[3].ni_vp);*/
sync(&proc0, NULL);
......@@ -456,7 +454,7 @@ boot(howto)
if (panicstr == 0)
{
/*struct nameidata nd;
/* struct nameidata nd;
int mnt_cnt;
struct statfs *mntbuf;
int i;
......@@ -490,10 +488,10 @@ boot(howto)
NDINIT(&nd[2], LOOKUP, FOLLOW, UIO_SYSSPACE, "/var", curproc);
if ((error = namei(&nd[2])) != 0)
printf ("Error = %d\n", error);
/*
NDINIT(&nd[3], LOOKUP, FOLLOW, UIO_SYSSPACE, "/tmp", curproc);
if ((error = namei(&nd[3])) != 0)
printf ("Error = %d\n", error);
printf ("Error = %d\n", error);*/
while (nd[0].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
......@@ -501,14 +499,19 @@ boot(howto)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
while (nd[2].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
while (nd[3].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
/* while (nd[3].ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);*/
NDFREE(&nd[0], NDF_ONLY_PNBUF);
NDFREE(&nd[1], NDF_ONLY_PNBUF);
NDFREE(&nd[2], NDF_ONLY_PNBUF);
NDFREE(&nd[3], NDF_ONLY_PNBUF);
/* NDFREE(&nd[3], NDF_ONLY_PNBUF);*/
vrele(nd[0].ni_vp);
vrele(nd[1].ni_vp);
vrele(nd[2].ni_vp);
DELAY (10000000);
printf ("Unmounting filesystems...");
vfs_unmountall();
printf ("Done!\n");
......
......@@ -27,6 +27,7 @@
#include <dev/shd/shdconf.h>
#include <vm/vm_zone.h>
#include <sys/time.h>
#ifdef SHDDEBUG
int shddebug = SHDB_FOLLOW|SHDB_INIT|SHDB_IO|SHDB_MAP|SHDB_MAPDETAIL|SHDB_ERROR;
......@@ -122,6 +123,8 @@ struct TrieList
{
Trie *trie;
int version;
char *name;
char *time;
struct TrieList *next;
} *head_trie;
......@@ -266,6 +269,40 @@ void reorder_trie_versions ()
}
}
set_checkpoint (int pos, char *name, char *time)
{
int pos_count;
struct TrieList *current = head_trie;
while (current != 0)
{
pos_count++;
if (pos_count == pos)
{
current->name = (char *) malloc (strlen (name) + 1, M_DEVBUF, M_NOWAIT);
current->time = (char *) malloc (strlen (time) + 1, M_DEVBUF, M_NOWAIT);
bcopy (name, current->name, strlen (name) + 1);
bcopy (time, current->time, strlen (time) + 1);
return;
}
current = current->next;
}
}
print_checkpoint_time (int version)
{
int pos_count;
struct TrieList *current = head_trie;
while (current != 0)
{
if (current->version == version)
{
printf ("Name = %s, Time = %s\n", current->name, current->time);
return;
}
current = current->next;
}
}
/*
* Called by main() during pseudo-device attachment. All we need
* to do is allocate enough space for devices to be configured later, and
......@@ -444,7 +481,33 @@ shd_timeout(void *notused)
}
timeout((timeout_t *)shd_timeout, 0, SHD_TIMEOUT * hz);
}
int bInit;
int shd_iocset()
{
int error;
int unit = 0;
struct shd_softc *ss;
struct shddevice shd;
bcopy(&shddevs[unit], &shd, sizeof(shd));
latest_version = 1;
bCheckpoint = 0;
init_trie_list ();
if (0 == create_new_trie (1))
{
printf ("Error creating trie!!!\n");
return (EINVAL);
}
InitBlockAllocator (EXPLICIT_CKPT_DELETE, 3, shadow_size);
/*
* The shd has been successfully initialized, so
* we can place it into the array and read2 the disklabel.
*/
bCheckpoint = 1;
bcopy(&shd, &shddevs[unit], sizeof(shd));
}
void root_init (void)
{
int error;
......@@ -455,7 +518,6 @@ void root_init (void)
static char *copypath = "/dev/ad0s4";
ss = &shd_softc[unit];
bInit = 0;
bzero(&shd, sizeof(shd));
shd.shd_unit = unit;
......@@ -477,7 +539,7 @@ void root_init (void)
return (error);
}
bcopy(&shd, &shddevs[unit], sizeof(shd));
shd_iocset();
shdunlock(ss);
}
......@@ -504,7 +566,6 @@ shd_init(shd, p)
error = shd_getcinfo(shd, p, 0);
if (error)
goto bad;
printf ("shadow size = %ld\n", shadow_size);
/*
* Source sector size must be at least as large as the copy
......@@ -577,6 +638,7 @@ shd_deinit(struct shddevice *shd, struct proc *p)
ss->sc_flags &= ~SHDF_INITED;
}
/* ARGSUSED */
static int
shdopen(dev, flags, fmt, p)
......@@ -657,6 +719,7 @@ shdclose(dev, flags, fmt, p)
shdunlock(ss);
return (0);
}
static void
shdstrategy(bp)
struct buf *bp;
......@@ -667,6 +730,7 @@ shdstrategy(bp)
struct disklabel *lp;
int error;
/*#ifdef SHDDEBUG
if (shddebug & SHDB_FOLLOW)
printf("shd%d: strategy: %s bp %p, bn %d, size %lu\n",
......@@ -1171,7 +1235,6 @@ long block_copy (struct shd_softc *ss, struct proc *p, long src_block, long dest
return 0;
}
static void
shdio(struct shd_softc *ss, struct buf *bp, struct proc *p)
{
......@@ -1196,6 +1259,7 @@ shdio(struct shd_softc *ss, struct buf *bp, struct proc *p)
/*
* Translate the partition-relative block number to an absolute.
*/
bn = bp->b_blkno;
if (shdpart(bp->b_dev) != RAW_PART)
bn += ss->sc_label.d_partitions[shdpart(bp->b_dev)].p_offset;
......@@ -1212,6 +1276,7 @@ shdio(struct shd_softc *ss, struct buf *bp, struct proc *p)
{
/* Search in Trie and do a copy on write */
int failed;
failed = TrieInsertWeak (get_trie_for_version (latest_version), bn, (bp->b_bcount)/512, ss, bp, p);
if (failed < 0)
{
......@@ -1412,6 +1477,7 @@ shdioctl(dev, cmd, data, flag, p)
struct shd_readbuf *shread;
struct shddevice shd;
struct shd_modinfo *shmod;
struct shd_ckpt *ckpt;
struct vnode * vp;
/*#ifdef SHDDEBUG
......@@ -1427,7 +1493,7 @@ shdioctl(dev, cmd, data, flag, p)
shd.shd_unit = unit;
switch (cmd) {
case SHDGETMODBLOCKS:
case SHDGETMODIFIEDRANGES:
shmod = (struct shd_modinfo *) data;
shmod->retsiz = get_mod_blocks (shmod->command, shmod->buf, shmod->bufsiz);
break;
......@@ -1459,6 +1525,7 @@ shdioctl(dev, cmd, data, flag, p)
bCheckpoint = 0;
break;
case SHDCHECKPOINT:
ckpt = (struct shd_ckpt *) data;
printf ("[SHDCHECKPOINT] Received checkpoint command!\n");
sync_before_checkpoint (); /*Uncomment this*/
if (MAX_CHECKPOINTS <= latest_version)
......@@ -1472,6 +1539,8 @@ shdioctl(dev, cmd, data, flag, p)
{
return (EINVAL);
}
printf ("Setting checkpoint name %s time %s\n", ckpt->name, ckpt->time);
/*set_checkpoint (latest_version, ckpt->name, ckpt->time);*/
break;
case SHDGETCHECKPOINTS:
if (latest_version < 1)
......@@ -1479,6 +1548,7 @@ shdioctl(dev, cmd, data, flag, p)
for (version = 1; version <= latest_version; ++version)
{
printf ("Checkpoint version %d is ===>\n", version);
/*print_checkpoint_time (version);*/
print_checkpoint_map (version);
printf ("\n");
}
......@@ -1505,31 +1575,6 @@ shdioctl(dev, cmd, data, flag, p)
if ((error = shdlock(ss)) != 0)
return (error);
/* Fill in some important bits. */
switch (shio->shio_flags & (SHDF_COR|SHDF_COW)) {
case SHDF_COR|SHDF_COW:
printf("shd%d: can't specify both COR and COW, using COW\n",
unit);
shio->shio_flags &= ~SHDF_COR;
break;
case 0:
shio->shio_flags |= SHDF_COW;
break;
}
switch (shio->shio_flags & (SHDF_ONETOONE|SHDF_COMPACT)) {
case SHDF_ONETOONE|SHDF_COMPACT:
printf("shd%d: can't specify both ONETOONE and COMPACT, using COMPACT\n",
unit);
shio->shio_flags &= ~SHDF_ONETOONE;
break;
case 0:
shio->shio_flags |= SHDF_COMPACT;
break;
}
shio->shio_flags |= SHDF_ONETOONE;
shd.shd_flags = shio->shio_flags & SHDF_USERMASK;
if (shd.shd_srcsize < 0 || shd.shd_copysize < 0) {
shdunlock(ss);
return (EINVAL);
......@@ -1550,8 +1595,6 @@ shdioctl(dev, cmd, data, flag, p)
shio->shio_unit = unit;
shio->shio_size = ss->sc_size;
shdgetdisklabel(dev);
/*shd_refresh_devices (&shd, p);
InitBlockAllocator (EXPLICIT_CKPT_DELETE, 3, shadow_size);*/
shdunlock(ss);
break;
......
......@@ -153,7 +153,17 @@ do_single(argc, argv, action, flags)
else
if (strcmp (cp, "-c") == 0)
{
if (do_io(shd, SHDCHECKPOINT, &shio))
time_t rawtime;
struct tm * timeinfo;
struct shd_ckpt ckpt;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
if (*argv)
ckpt.name = *argv++; --argc;
ckpt.time = asctime (timeinfo);
printf ("Name = %s\n", ckpt.name);
printf ("Time = %s\n", ckpt.time);
if (do_io(shd, SHDCHECKPOINT, &ckpt))
{
return (1);
}
......@@ -260,7 +270,7 @@ do_single(argc, argv, action, flags)
for (i = 0; i < 512; i++)
buf[i] = 0;
mod.retsiz = 0;
if (do_io(shd, SHDGETMODBLOCKS, &mod))
if (do_io(shd, SHDGETMODIFIEDRANGES, &mod))
return (1);
printf ("retsize = %d\n", mod.retsiz);
for (i = 0; i < mod.retsiz; i++)
......@@ -273,7 +283,7 @@ do_single(argc, argv, action, flags)
buf[i] = 0;
mod.retsiz = 0;
mod.command = 2;
if (do_io(shd, SHDGETMODBLOCKS, &mod))
if (do_io(shd, SHDGETMODIFIEDRANGES, &mod))
return (1);
printf ("retsize = %d\n", mod.retsiz);
for (i = 0; i < mod.retsiz; i++)
......@@ -283,7 +293,7 @@ do_single(argc, argv, action, flags)
}
mod.command = 3; /* Close iterator */
if (do_io(shd, SHDGETMODBLOCKS, &mod))
if (do_io(shd, SHDGETMODIFIEDRANGES, &mod))
return (1);
}
......
......@@ -40,6 +40,11 @@ struct shd_readbuf {
long block_num;
char *buf;
};
struct shd_ckpt {
char *time;
char *name;
};
/* shd_flags */
#define SHDF_ONETOONE 0x01 /* 1-to-1 mapping with source disk */
......@@ -130,7 +135,7 @@ struct shd_softc {
*/
#define SHDIOCSET _IOWR('S', 16, struct shd_ioctl) /* enable shd */
#define SHDIOCCLR _IOW('S', 17, struct shd_ioctl) /* disable shd */
#define SHDCHECKPOINT _IOWR('S', 18, struct shd_ioctl)
#define SHDCHECKPOINT _IOWR('S', 18, struct shd_ckpt)
#define SHDGETCHECKPOINTS _IOWR('S', 19, struct shd_ioctl)
#define SHDENABLECHECKPOINTING _IOWR('S', 20, struct shd_ioctl)
#define SHDDISABLECHECKPOINTING _IOWR('S', 21, struct shd_ioctl)
......@@ -141,5 +146,5 @@ struct shd_softc {
#define SHDDELETECHECKPOINTS _IOWR('S', 26, struct shd_ioctl)
#define SHDREADBLOCK _IOWR('S', 27, struct shd_readbuf)
#define SHDSETREBOOTVERSION _IOWR('S', 28, struct shd_ioctl)
#define SHDGETMODBLOCKS _IOWR('S', 29, struct shd_modinfo)
#define SHDGETMODIFIEDRANGES _IOWR('S', 29, struct shd_modinfo)
......@@ -106,6 +106,7 @@ int TrieInit(Trie ** trieOutPtr, BlockAllocateFunction blockAlloc,
result = 1;
if (trie == 0)
{
printf ("Error doing TrieInit! Not enough memory!\n");
result = 0;
}
else
......@@ -424,6 +425,7 @@ static int addChild(Trie * triePtr, TrieNode * parent, TrieKey key,
}
else
{
printf ("Error doing addChild for Trie! Not enough memory!\n");
result = -1;
}
return result;
......@@ -577,6 +579,7 @@ static TrieNode * pushDown(Trie * triePtr, TrieNode * node)
}
else
{
printf ("Error doing pushDown for Trie! Not enough memory!\n");
middle = 0;
}
return middle;
......
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