Commit 02231633 authored by Siddharth Aggarwal's avatar Siddharth Aggarwal
Browse files

the problem on /var solved

parent bfb38f51
......@@ -10,7 +10,7 @@ void InitBlockAllocator (int method, long range_start, long range_size)
{
reclaim_method = method;
block_range.start = range_start;
range_size = 200;
/*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);
......@@ -58,9 +58,9 @@ int BlockFree (long start, long size)
struct FreeSpaceQueue* temp = head;
long end = (start + size) % shadow_size;
printf ("Free space queue before deleting block = \n");
/*printf ("Free space queue before deleting block = \n");
PrintFreeSpaceQueue ();
printf ("Freeing blocks %ld to %ld\n", start, end);
printf ("Freeing blocks %ld to %ld\n", start, end);*/
while (temp != 0)
{
if ((temp->start == (end + 1) % shadow_size)
......@@ -79,8 +79,8 @@ int BlockFree (long start, long size)
temp = temp->next;
}
AddFreeSpaceToQueue (start, end);
printf ("Free space queue after deleting block = \n");
PrintFreeSpaceQueue ();
/*printf ("Free space queue after deleting block = \n");
PrintFreeSpaceQueue ();*/
return 0;
}
......@@ -88,8 +88,8 @@ long BlockAlloc (int size)
{
struct FreeSpaceQueue* temp = 0;
long retVal;
printf ("Free space queue before allocating block = \n");
PrintFreeSpaceQueue ();
/*printf ("Free space queue before allocating block = \n");
PrintFreeSpaceQueue ();*/
switch (reclaim_method)
{
case LAST_CKPT_AUTO_DELETE:
......@@ -115,9 +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 ();
PrintFreeSpaceQueue ();*/
return retVal;
}
......
......@@ -69,6 +69,9 @@
#include <sys/signalvar.h>
#include <sys/namei.h>
#include <sys/ucred.h>
#ifndef PANIC_REBOOT_WAIT_TIME
#define PANIC_REBOOT_WAIT_TIME 15 /* default to 15 seconds */
#endif
......@@ -202,16 +205,90 @@ print_uptime()
void (*shdrebootp)(void);
int checkpt_flag = 0;
int checkpt_process_sleep_variable = 0;
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;*/
int error;
waittime = 0;
printf("\nsyncing disks... ");
checkpt_flag = 1;
/*mnt_cnt = getmntinfo(&mntbuf, MNT_NOWAIT);
if (mnt_cnt > 0)
{
for (i = 0; i < mnt_cnt; i++)
if (strcmp (mntbuf[i].f_fstypename, "ufs") == 0)
{
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, mntbuf[i].f_mntonname, curproc);
if ((error = namei(&nd)) != 0)
printf ("Error = %d\n", error);
while (nd.ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
NDFREE(&nd, NDF_ONLY_PNBUF);
}
}*/
NDINIT(&nd[0], LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc);
if ((error = namei(&nd[0])) != 0)
printf ("Error = %d\n", error);
NDINIT(&nd[1], LOOKUP, FOLLOW, UIO_SYSSPACE, "/usr", curproc);
if ((error = namei(&nd[1])) != 0)
printf ("Error = %d\n", error);
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 ("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);
NDFREE(&nd[0], NDF_ONLY_PNBUF);
NDFREE(&nd[1], NDF_ONLY_PNBUF);
NDFREE(&nd[2], NDF_ONLY_PNBUF);
NDFREE(&nd[3], NDF_ONLY_PNBUF);
sync(&proc0, NULL);
/*
......@@ -273,8 +350,6 @@ void sync_before_checkpoint (void)
checkpt_flag = 0;
wakeup ((caddr_t)&checkpt_flag);
/*printf ("Returning from sync_before_checkpoint\n");
DELAY(1000000);*/
}
/*
* Go through the rigmarole of shutting down..
......@@ -303,8 +378,7 @@ boot(howto)
* Now sync filesystems
*/
/*printf ("cold = %d, howto = %d, waittime = %d\n", cold, howto, waittime);
if (!cold && (howto & RB_NOSYNC) == 0 && waittime < 0) {*/
/*if (!cold && (howto & RB_NOSYNC) == 0 && waittime < 0) {*/
if (1) {
register struct buf *bp;
int iter, nbusy, pbusy;
......@@ -379,16 +453,70 @@ boot(howto)
/*
* Unmount filesystems
*/
if (panicstr == 0)
{
/*struct nameidata nd;
int mnt_cnt;
struct statfs *mntbuf;
int i;
int error;
mnt_cnt = getmntinfo(&mntbuf, MNT_NOWAIT);
if (mnt_cnt > 0)
{
for (i = 0; i < mnt_cnt; i++)
if (strcmp (mntbuf[i].f_fstypename, "ufs") == 0)
{
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, mntbuf[i].f_mntonname, curproc);
if ((error = namei(&nd)) != 0)
printf ("Error = %d\n", error);
while (nd.ni_vp->v_mount->mnt_ops_in_progress)
tsleep(&checkpt_process_sleep_variable, PINOD, "mountpointlock", 0);
NDFREE(&nd, NDF_ONLY_PNBUF);
}
} */
struct nameidata nd[5];
int error;
NDINIT(&nd[0], LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc);
if ((error = namei(&nd[0])) != 0)
printf ("Error = %d\n", error);
NDINIT(&nd[1], LOOKUP, FOLLOW, UIO_SYSSPACE, "/usr", curproc);
if ((error = namei(&nd[1])) != 0)
printf ("Error = %d\n", error);
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);
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);
NDFREE(&nd[0], NDF_ONLY_PNBUF);
NDFREE(&nd[1], NDF_ONLY_PNBUF);
NDFREE(&nd[2], NDF_ONLY_PNBUF);
NDFREE(&nd[3], NDF_ONLY_PNBUF);
printf ("Unmounting filesystems...");
vfs_unmountall();
printf ("Done!\n");
DELAY(10000000);
printf ("Copying blocks\n");
(*shdrebootp)();
printf ("Done!\n");
DELAY(10000000);
printf ("Unmounting filesystems...");
vfs_unmountall();
printf ("Done!\n");
}
}
DELAY(100000); /* wait for console output to finish */
......@@ -396,9 +524,7 @@ boot(howto)
print_uptime();
/*DELAY(10000000);
(*shdrebootp)();*/
DELAY(10000000);
/*DELAY(10000000);*/
/*
* Ok, now do things that assume all filesystem activity has
* been completed.
......
......@@ -284,7 +284,6 @@ shd_attach()
if (num == 1)
num = 16;
printf ("\n\nInside shd_attach\n\n");
/*printf("shd[0-%d]: Shadow disk devices\n", num-1);*/
shd_softc = (struct shd_softc *)malloc(num * sizeof(struct shd_softc),
......@@ -381,22 +380,7 @@ shd_getcinfo(struct shddevice *shd, struct proc *p, int issrc)
reqsize = shd->shd_copysize;
}
ci->ci_vp = vp;
/* reqsize = 1024 * 1024; hardcoded value */
/*bzero(tmppath, sizeof(tmppath));
error = copyinstr(pp, tmppath, MAXPATHLEN, &ci->ci_pathlen);
if (error) {
#ifdef SHDDEBUG
if (shddebug & (SHDB_INIT|SHDB_ERROR))
printf("shd%d: can't copy path, error = %d\n",
shd->shd_unit, error);
#endif
return (error);
}
ci->ci_path = malloc(ci->ci_pathlen, M_DEVBUF, M_WAITOK);
bcopy(tmppath, ci->ci_path, ci->ci_pathlen);*/
/*ci->ci_dev = vn_todev(vp); */
ci->ci_path = malloc(11, M_DEVBUF, M_WAITOK);
ci->ci_pathlen = 11;
if (issrc)
......@@ -417,21 +401,11 @@ shd_getcinfo(struct shddevice *shd, struct proc *p, int issrc)
*/
size = 0;
secsize = DEV_BSIZE;
/*if (vn_isdisk(vp, &error)) {*/
if (devsw(ci->ci_dev)->d_psize != NULL)
size = (*devsw(ci->ci_dev)->d_psize)(ci->ci_dev);
if (reqsize > 0 && reqsize < size)
size = reqsize;
secsize = ci->ci_dev->si_bsize_phys;
/*} else if (vp->v_type == VREG) {
struct vattr vattr;
error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
if (error == 0)
size = vattr.va_size / secsize;
if (reqsize > 0)
size = reqsize;
}*/
if (size == 0) {
free(ci->ci_path, M_DEVBUF);
......@@ -491,63 +465,19 @@ void root_init (void)
return;
}
/*error = shd_lookup("/dev/ad0s1", curproc, FREAD,
&shd.shd_srcvp);
if (error) {
printf ("shd_lookup for /dev/ad0s1 failed\n");
shdunlock(ss);
return;
}*/
shd.shd_srcpath = srcpath;
/*error = shd_lookup("/dev/ad0s4", curproc, FREAD,
&shd.shd_copyvp);
if (error) {
printf ("shd_lookup for /dev/ad0s4 failed\n");
(void)vn_close(shd.shd_srcvp, FREAD, curproc->p_ucred, curproc);
shdunlock(ss);
return;
}*/
shd.shd_copypath = copypath;
error = shd_init(&shd, curproc);
if (error) {
printf ("shd_init failed\n");
printf ("shd_init failed. error = %d\n", error);
bzero(&shd_softc[unit], sizeof(struct shd_softc));
shdunlock(ss);
return (error);
}
bcopy(&shd, &shddevs[unit], sizeof(shd));
/* Put the vp pointers here
if (0 == bInit) {
bcopy(&shddevs[unit], &shd, sizeof(shd));
bInit = 1;
printf ("Before lookup on source\n");
error = shd_lookup("/dev/ad0s1", curproc, FREAD,
&shd.shd_srcvp);
printf ("After lookup on source\n");
if (error) {
shdunlock(ss);
return;
}
printf ("Before lookup on copy\n");
error = shd_lookup("/dev/ad0s4", curproc, FREAD|FWRITE,
&shd.shd_copyvp);
printf ("After lookup on copy\n");
if (error) {
(void)vn_close(shd.shd_srcvp, FREAD, curproc->p_ucred, curproc);
shdunlock(ss);
return;
}
bcopy(&shd, &shddevs[unit], sizeof(shd));
ss->sc_srcdisk.ci_vp = shd.shd_srcvp;
ss->sc_copydisk.ci_vp = shd.shd_copyvp;
printf ("Src vp = %x, Copy vp = %x\n", ss->sc_srcdisk.ci_vp, ss->sc_copydisk.ci_vp);
}
*/
shdunlock(ss);
}
......@@ -600,15 +530,6 @@ shd_init(shd, p)
ss->sc_cred = crdup(p->p_ucred);
ss->sc_secsize = ss->sc_srcdisk.ci_secsize;
/*
* Initialize the copy block map
error = (*ss->sc_mapops->init)(ss, p);
if (error)
{
printf ("ss->sc_mapops->init failed \n");
goto bad;
} */
/*
* Add an devstat entry for this device.
......@@ -790,7 +711,7 @@ shdstrategy(bp)
if (bounds_check_with_label(bp, lp, wlabel) <= 0) {
biodone(bp);
printf ("Error! Bounds checking and transfer adjust failed\n");
/*return;*/
return;
}
} else {
int pbn; /* in sc_secsize chunks */
......@@ -1367,13 +1288,13 @@ shdio(struct shd_softc *ss, struct buf *bp, struct proc *p)
biodone(bp);
}
int reboot_machine = 0;
void reboot_to_checkpoint (void)
{
struct shd_softc *ss;
struct vnode *vp;
int unit = 0;
ss = &shd_softc[unit];
bCheckpoint = 0;
if (reboot_version > latest_version)
{
printf ("Error! Cannot rollback to version %d because you have only %d previous checkpoints so far\n", reboot_version, latest_version);
......@@ -1382,6 +1303,8 @@ void reboot_to_checkpoint (void)
if (reboot_version != 0 && latest_version != 0)
{
printf ("Rolling back disk state from checkpoint version %d to version %d\n\n", latest_version, reboot_version);
bCheckpoint = 0;
/*reboot_machine = 1;*/
rollback_to_checkpoint (reboot_version, ss, curproc);
sync(curproc, 0);
/*save_checkpoint_map (ss, curproc);*/
......@@ -1391,29 +1314,85 @@ void reboot_to_checkpoint (void)
extern void sync_before_checkpoint (void);
struct vnode * lock_filesystem()
Trie *mod_trie = 0;
TrieIterator mod_pos = 0;
int mod_ok = 0;
int get_mod_blocks (int command, long *buf, long bufsiz)
{
struct nameidata nd;
struct vnode *vp = 0;
int error;
printf ("Inside lock_filesystem\n");
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc);
printf ("After NDINIT\n");
if ((error = vn_open(&nd, FREAD, 0)) != 0) {
printf ("Error opening filesystem \n");
return 0;
}
vp = nd.ni_vp;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
printf ("After vn_lock\n");
NDFREE(&nd, NDF_ONLY_PNBUF);
printf ("After NDFREE\n");
return vp;
}
int ix;
int retsiz = 0;
unlock_filesystem(struct vnode * vp)
{
VOP_UNLOCK(vp, 0, curproc);
switch (command)
{
case 1:
if (0 == mod_trie || 0 == mod_pos)
{
TrieInit (&mod_trie, BlockAlloc, BlockFree, block_copy);
for (ix = latest_version; ix >= 1; ix--)
{
merge (mod_trie, get_trie_for_version (ix), DEFAULT_OVERLAP);
}
mod_ok = TrieIteratorInit(mod_trie, &mod_pos);
}
if (mod_ok)
{
retsiz = 0;
for ( ; TrieIteratorIsValid(mod_pos); TrieIteratorAdvance(&mod_pos))
{
buf[retsiz] = mod_pos->key;
buf[retsiz+1] = mod_pos->key + depthToSize(mod_pos->maxDepth);
retsiz+=2;
if (retsiz >= bufsiz)
return retsiz/2;
}
TrieIteratorCleanup(&mod_pos);
TrieCleanup(mod_trie);
mod_pos = 0;
mod_trie = 0;
return retsiz/2;
}
else
{
printf ("Error getting modified blocks. Data structures not initialized\n");
return -1;
}
break;
case 2:
if (mod_ok)
{
retsiz = 0;
for ( ; TrieIteratorIsValid(mod_pos); TrieIteratorAdvance(&mod_pos))
{
buf[retsiz] = mod_pos->key;
buf[retsiz+1] = mod_pos->key + depthToSize(mod_pos->maxDepth);
retsiz+=2;
if (retsiz >= bufsiz)
return retsiz/2;
}
TrieIteratorCleanup(&mod_pos);
TrieCleanup(mod_trie);
mod_pos = 0;
mod_trie = 0;
return retsiz/2;
}
else
{
printf ("Error getting modified blocks. Data structures not initialized\n");
return -1;
}
break;
case 3:
if (mod_pos)
{
TrieIteratorCleanup(&mod_pos);
}
if (mod_trie)
{
TrieCleanup(mod_trie);
}
break;
}
}
static int
......@@ -1432,6 +1411,7 @@ shdioctl(dev, cmd, data, flag, p)
struct shd_ioctl *shio = (struct shd_ioctl *)data;
struct shd_readbuf *shread;
struct shddevice shd;
struct shd_mod *shmod;
struct vnode * vp;
/*#ifdef SHDDEBUG
......@@ -1447,6 +1427,10 @@ shdioctl(dev, cmd, data, flag, p)
shd.shd_unit = unit;
switch (cmd) {
case SHDGETMODBLOCKS:
shmod = (struct shd_mod *) data;
shmod->retsiz = get_mod_blocks (shmod->command, shmod->buf, shmod->bufsiz);
break;
case SHDREADBLOCK:
shread = (struct shd_readbuf *) data;
read_block (ss, p, shread->buf, shread->block_num);
......@@ -1455,7 +1439,6 @@ shdioctl(dev, cmd, data, flag, p)
reboot_version = shio->version;
break;
case SHDROLLBACK:
/*printf ("Attempting to rollback from version %d to version %d\n", latest_version, (int )shio->version);*/
if (shio->version > latest_version)
{
printf ("Error! Cannot rollback to version %d because you have only %d previous checkpoints so far\n", (int) shio->version, latest_version);
......@@ -1477,7 +1460,6 @@ shdioctl(dev, cmd, data, flag, p)
break;
case SHDCHECKPOINT:
printf ("[SHDCHECKPOINT] Received checkpoint command!\n");
/*vp = lock_filesystem();*/
sync_before_checkpoint (); /*Uncomment this*/
if (MAX_CHECKPOINTS <= latest_version)
{
......@@ -1488,12 +1470,8 @@ shdioctl(dev, cmd, data, flag, p)
latest_version++;
else
{
/*if (vp != 0)
unlock_filesystem(vp);*/
return (EINVAL);
}
/*if (vp != 0)
unlock_filesystem(vp); */
break;
case SHDGETCHECKPOINTS:
if (latest_version < 1)
......@@ -1518,13 +1496,9 @@ shdioctl(dev, cmd, data, flag, p)
latest_version = 1;
bCheckpoint = 0;
init_trie_list ();
printf ("unit = %d, curproc = %x\n", unit, curproc);
if (0 == create_new_trie (1))
return (EINVAL);
/*if (ss->sc_flags & SHDF_INITED)
return (EBUSY);*/
if ((flag & FWRITE) == 0)
return (EBADF);
......@@ -1561,40 +1535,12 @@ shdioctl(dev, cmd, data, flag, p)
return (EINVAL);
}
/*printf ("Before lookup on source\n");
error = shd_lookup(shio->shio_srcdisk, p, FREAD,
&shd.shd_srcvp);
printf ("After lookup on source\n");
if (error) {
shdunlock(ss);
return (error);
}*/
shd.shd_srcpath = shio->shio_srcdisk;
shd.shd_srcsize = shio->shio_srcsize;
/*printf ("Before lookup on copy\n");
error = shd_lookup(shio->shio_copydisk, p, FREAD|FWRITE,
&shd.shd_copyvp);
printf ("After lookup on copy\n");
if (error) {
(void)vn_close(shd.shd_srcvp, FREAD, p->p_ucred, p);
shdunlock(ss);
return (error);
}*/
shd.shd_copypath = shio->shio_copydisk;
shd.shd_copysize = shio->shio_copysize;
/*
* Initialize the shd. Fills in the softc for us.
*/
/*error = shd_init(&shd, p);
if (error) {
printf ("shd_init failed\n");*/
/* vnodes closed by shd_init */
/* bzero(&shd_softc[unit], sizeof(struct shd_softc));
shdunlock(ss);
return (error);
}*/
InitBlockAllocator (EXPLICIT_CKPT_DELETE, 3, shadow_size);
/*
* The shd has been successfully initialized, so
......@@ -1604,7 +1550,8 @@ shdioctl(dev, cmd, data, flag, p)
shio->shio_unit = unit;
shio->shio_size = ss->sc_size;
shdgetdisklabel(dev);
shd_refresh_devices (&shd, p);
/*shd_refresh_devices (&shd, p);
InitBlockAllocator (EXPLICIT_CKPT_DELETE, 3, shadow_size);*/
shdunlock(ss);
break;
...