Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
fc51687e
Commit
fc51687e
authored
Sep 27, 2004
by
Siddharth Aggarwal
Browse files
Fixed bugs in checkpoint saving code
parent
0153edc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
os/shd/shd.c
View file @
fc51687e
...
...
@@ -834,80 +834,53 @@ void save_checkpoint_map (struct shd_softc *ss, struct proc *p)
int
current_block
;
metadata_block
=
2
;
blocks_used
=
0
;
array_ix
=
0
;
write_start
=
BlockAlloc
(
1
);
current_block
=
write_start
;
for
(
i
=
0
;
i
<
512
/
sizeof
(
long
int
);
i
++
)
{
map
[
i
]
=
0
;
temp_addr
[
i
]
=
0
;
}
for
(
ix
=
1
;
ix
<
latest_version
;
ix
++
)
{
Trie
*
trie
=
get_trie_for_version
(
ix
);
TrieIterator
pos
;
int
ok
=
TrieIteratorInit
(
trie
,
&
pos
);
array_ix
=
0
;
if
(
ok
)
{
for
(
;
TrieIteratorIsValid
(
pos
);
TrieIteratorAdvance
(
&
pos
))
{
if
(
array_ix
>=
128
)
{
array_ix
=
0
;
blocks_used
++
;
if
(
write_block
(
ss
,
p
,
(
char
*
)
map
,
current_block
))
return
;
current_block
=
BlockAlloc
(
1
);
for
(
i
=
0
;
i
<
512
/
sizeof
(
long
int
);
i
++
)
map
[
i
]
=
0
;
}
current_block
=
write_start
=
BlockAlloc
(
1
);
blocks_used
=
0
;
for
(
;
TrieIteratorIsValid
(
pos
);
TrieIteratorAdvance
(
&
pos
))
{
map
[
array_ix
++
]
=
pos
->
key
;
if
(
array_ix
>=
128
)
{
array_ix
=
0
;
blocks_used
++
;
if
(
write_block
(
ss
,
p
,
(
char
*
)
map
,
current_block
))
return
;
current_block
=
BlockAlloc
(
1
);
for
(
i
=
0
;
i
<
512
/
sizeof
(
long
int
);
i
++
)
map
[
i
]
=
0
;
}
map
[
array_ix
++
]
=
pos
->
value
;
if
(
array_ix
>=
128
)
map
[
array_ix
++
]
=
depthToSize
(
pos
->
maxDepth
);
printf
(
"Saving (%ld, %ld, %ld)
\n
"
,
pos
->
key
,
pos
->
value
,
depthToSize
(
pos
->
maxDepth
));
if
(
array_ix
>=
125
)
{
array_ix
=
0
;
blocks_used
++
;
if
(
write_block
(
ss
,
p
,
(
char
*
)
map
,
current_block
))
return
;
current_block
=
BlockAlloc
(
1
);
for
(
i
=
0
;
i
<
512
/
sizeof
(
long
int
);
i
++
)
map
[
i
]
=
0
;
}
map
[
array_ix
++
]
=
depthToSize
(
pos
->
maxDepth
);
}
/* end of if */
}
/* end of for */
}
/* end of if */
if
(
array_ix
>
0
)
{
blocks_used
++
;
if
(
write_block
(
ss
,
p
,
(
char
*
)
map
,
current_block
))
return
;
}
}
map
[
array_ix
++
]
=
0
;
}
if
(
array_ix
>
0
)
{
blocks_used
++
;
if
(
write_block
(
ss
,
p
,
(
char
*
)
map
,
current_block
))
return
;
current_block
=
BlockAlloc
(
1
);
}
for
(
ix
=
0
;
ix
<
512
/
sizeof
(
long
int
);
ix
++
)
{
map
[
ix
]
=
0
;
temp_addr
[
ix
]
=
0
;
for
(
i
=
0
;
i
<
128
;
i
++
)
map
[
i
]
=
0
;
temp_addr
[
2
*
ix
-
2
]
=
(
long
int
)
write_start
;
temp_addr
[
2
*
ix
-
1
]
=
(
long
int
)
blocks_used
;
printf
(
"Saving version %d, %d blocks starting at %d
\n
"
,
ix
,
blocks_used
,
write_start
);
}
temp_addr
[
0
]
=
(
long
int
)
write_start
;
temp_addr
[
1
]
=
(
long
int
)
blocks_used
;
if
(
write_block
(
ss
,
p
,
(
char
*
)
temp_addr
,
metadata_block
))
return
;
printf
(
"Saved %ld blocks starting %ld
\n
"
,
blocks_used
,
write_start
);
}
int
read_block
(
struct
shd_softc
*
ss
,
struct
proc
*
p
,
char
block
[
512
],
long
int
block_num
)
...
...
@@ -1165,6 +1138,7 @@ shdioctl(dev, cmd, data, flag, p)
int
part
,
pmask
,
s
;
struct
shd_softc
*
ss
;
struct
shd_ioctl
*
shio
=
(
struct
shd_ioctl
*
)
data
;
struct
shd_readbuf
*
shread
;
struct
shddevice
shd
;
#ifdef SHDDEBUG
...
...
@@ -1181,6 +1155,9 @@ shdioctl(dev, cmd, data, flag, p)
switch
(
cmd
)
{
case
SHDREADBLOCK
:
shread
=
(
struct
shd_readbuf
*
)
data
;
printf
(
"Reading block %ld
\n
"
,
shread
->
block_num
);
read_block
(
ss
,
p
,
shread
->
buf
,
shread
->
block_num
);
break
;
case
SHDROLLBACK
:
printf
(
"Attempting to rollback from version %d to version %d
\n
"
,
latest_version
,
(
int
)
shio
->
version
);
...
...
@@ -1308,7 +1285,7 @@ shdioctl(dev, cmd, data, flag, p)
shdunlock
(
ss
);
return
(
error
);
}
InitBlockAllocator
(
EXPLICIT_CKPT_DELETE
,
2
,
shadow_size
);
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.
...
...
os/shd/shdconfig.c
View file @
fc51687e
...
...
@@ -179,8 +179,14 @@ do_single(argc, argv, action, flags)
if
(
do_io
(
shd
,
SHDROLLBACK
,
&
shio
))
return
(
1
);
}
else
if
(
strcmp
(
cp
,
"-sm"
)
==
0
)
{
if
(
do_io
(
shd
,
SHDSAVECHECKPOINTMAP
,
&
shio
))
return
(
1
);
}
else
if
(
strcmp
(
cp
,
"-s"
)
==
0
)
if
(
strcmp
(
cp
,
"-s
v
"
)
==
0
)
{
version
=
atoi
(
*
argv
++
);
--
argc
;
printf
(
"Saving version %d
\n
"
,
version
);
...
...
@@ -620,82 +626,96 @@ int save_checkpoint (char * shd, int version)
{
struct
shd_readbuf
shread
;
char
buffer
[
MAXBUF
];
char
block
[
BLOCKSIZE
];
long
block
[
BLOCKSIZE
/
4
+
1
];
TrieIterator
pos
;
int
ok
;
int
i
;
int
ix
;
int
fd_read
;
int
fd_write_data
;
int
fd_write_mdata
;
int
size
;
int
read_start
;
int
num_blocks
;
fd_read
=
open
(
"/dev/ad0s4"
,
O_RDWR
);
if
(
fd_read
<
=
0
)
if
(
fd_read
<
0
)
{
p
rintf
(
"Read device open failed
\n
"
);
p
error
(
"error
"
);
return
;
}
/* Open the data file to write to */
fd_write_data
=
open
(
"/users/saggarwa/image1.data"
,
O_
RDWR
);
if
(
fd_write_data
<
=
0
)
fd_write_data
=
open
(
"/users/saggarwa/image1.data"
,
O_
CREAT
);
if
(
fd_write_data
<
0
)
{
printf
(
"Write data device open failed in O_RDWR
\n
"
);
perror
(
"error"
);
return
;
}
else
close
(
fd_write_data
);
fd_write_data
=
open
(
"/users/saggarwa/image1.data"
,
O_WRONLY
);
if
(
fd_write_data
<
0
)
{
close
(
fd_write_data
);
fd_write_data
=
open
(
"/users/saggarwa/image1.data"
,
O_APPEND
);
if
(
fd_write_data
<=
0
)
{
printf
(
"Write data device open failed in O_APPEND
\n
"
);
perror
(
"error"
);
return
;
}
perror
(
"error"
);
return
;
}
/* Open the metadata file to write to */
fd_write_mdata
=
open
(
"/users/saggarwa/image1.mdata"
,
O_
RDWR
);
if
(
fd_write_mdata
<
=
0
)
fd_write_mdata
=
open
(
"/users/saggarwa/image1.mdata"
,
O_
CREAT
);
if
(
fd_write_mdata
<
0
)
{
p
rintf
(
"Write metadata device open failed in O_RDWR
\n
"
);
p
error
(
"error
"
);
return
;
}
else
close
(
fd_write_mdata
);
fd_write_mdata
=
open
(
"/users/saggarwa/image1.mdata"
,
O_WRONLY
);
if
(
fd_write_mdata
<
0
)
{
close
(
fd_write_mdata
);
fd_write_mdata
=
open
(
"/users/saggarwa/image1.mdata"
,
O_APPEND
);
if
(
fd_write_mdata
<=
0
)
{
printf
(
"Write metadata device open failed in O_APPEND
\n
"
);
return
;
}
perror
(
"error"
);
return
;
}
shread
.
block_num
=
2
;
shread
.
buf
=
&
block
;
if
(
do_io
(
shd
,
SHDREADBLOCK
,
&
shread
))
return
(
1
);
{
perror
(
"error"
);
return
(
1
);
}
/*printf ("Before TrieIteratorInit %x\n", trie);
ok = TrieIteratorInit(trie, &pos);
printf ("After TrieIteratorInit\n");
for ( ; TrieIteratorIsValid(pos); TrieIteratorAdvance(&pos))
read_start
=
(
long
)
block
[(
2
*
version
-
2
)];
num_blocks
=
(
long
)
block
[(
2
*
version
-
1
)];
printf
(
"read start = %ld, num blocks = %ld
\n
"
,
read_start
,
num_blocks
);
for
(
ix
=
0
;
ix
<
num_blocks
;
ix
++
)
{
off_t off;
printf ("Inside for loop\n");
off = lseek (fd_read, pos->value * BLOCKSIZE, SEEK_SET);
size = read (fd_read, &buffer, depthToSize(pos->maxDepth) * BLOCKSIZE);
size = write (fd_write_data, &buffer, size);
write (fd_write_mdata, &pos->key, sizeof (pos->key));
write (fd_write_mdata, &pos->value, sizeof (pos->value));
shread
.
block_num
=
read_start
;
if
(
do_io
(
shd
,
SHDREADBLOCK
,
&
shread
))
return
(
1
);
for
(
i
=
0
;
i
<
126
;
i
+=
3
)
{
off_t
off
;
if
(
0
==
block
[
i
])
break
;
printf
(
"(%ld, %ld, %ld)
\n
"
,
block
[
i
],
block
[
i
+
1
],
block
[
i
+
2
]
*
BLOCKSIZE
);
off
=
lseek
(
fd_read
,
block
[
i
+
1
]
*
BLOCKSIZE
,
SEEK_SET
);
size
=
read
(
fd_read
,
&
buffer
,
block
[
i
+
2
]
*
BLOCKSIZE
);
if
(
size
<
0
)
perror
(
"error"
);
size
=
write
(
fd_write_data
,
&
buffer
,
size
);
if
(
size
<
0
)
perror
(
"error"
);
write
(
fd_write_mdata
,
&
block
[
i
],
sizeof
(
long
));
write
(
fd_write_mdata
,
&
block
[
i
+
1
],
sizeof
(
long
));
}
read_start
++
;
}
TrieIteratorCleanup(&pos);*/
close
(
fd_read
);
close
(
fd_write_data
);
close
(
fd_write_mdata
);
printf
(
"Save operation successful
\n
"
);
/* Similarly swap in blocks by changing fd_read, fd_write pointers */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment