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
d3bb909b
Commit
d3bb909b
authored
Sep 27, 2004
by
Siddharth Aggarwal
Browse files
started writing code for loading checkpoints from disk
parent
77cb5a5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
os/shd/shd.c
View file @
d3bb909b
...
...
@@ -111,7 +111,7 @@ long shadow_size; /* in BLOCK_SIZE byte blocks */
Trie
*
latest_trie
;
int
latest_version
;
long
copy_
block
(
struct
shd_softc
*
ss
,
struct
proc
*
p
,
long
src_block
,
long
dest_block
,
long
size
,
int
type
);
long
block
_copy
(
struct
shd_softc
*
ss
,
struct
proc
*
p
,
long
src_block
,
long
dest_block
,
long
size
,
int
direction
);
struct
TrieList
{
Trie
*
trie
;
...
...
@@ -146,7 +146,7 @@ Trie * create_new_trie (int version)
{
Trie
*
new_trie
=
0
;
struct
TrieList
*
current
;
if
(
TrieInit
(
&
new_trie
,
BlockAlloc
,
BlockFree
,
copy_
block
)
==
0
)
if
(
TrieInit
(
&
new_trie
,
BlockAlloc
,
BlockFree
,
block
_copy
)
==
0
)
{
printf
(
"Error initializing new trie
\n
"
);
return
0
;
...
...
@@ -640,7 +640,7 @@ void swapout_modified_blocks (struct shd_softc *ss, struct proc *p)
int
ix
;
int
ok
;
TrieIterator
pos
;
TrieInit
(
&
merged_trie
,
BlockAlloc
,
BlockFree
,
copy_
block
);
TrieInit
(
&
merged_trie
,
BlockAlloc
,
BlockFree
,
block
_copy
);
for
(
ix
=
latest_version
;
ix
>=
1
;
ix
--
)
{
...
...
@@ -665,7 +665,7 @@ void swapout_checkpoint (int version, struct shd_softc *ss, struct proc *p)
TrieIterator
pos
;
int
ix
;
int
ok
;
TrieInit
(
&
merged_trie
,
BlockAlloc
,
BlockFree
,
copy_
block
);
TrieInit
(
&
merged_trie
,
BlockAlloc
,
BlockFree
,
block
_copy
);
for
(
ix
=
latest_version
;
ix
>=
version
;
ix
--
)
{
...
...
@@ -691,7 +691,7 @@ void rollback_to_checkpoint (int version, struct shd_softc *ss, struct proc *p)
TrieIterator
pos
;
int
ix
;
int
ok
;
TrieInit
(
&
merged_trie
,
BlockAlloc
,
BlockFree
,
copy_
block
);
TrieInit
(
&
merged_trie
,
BlockAlloc
,
BlockFree
,
block
_copy
);
for
(
ix
=
latest_version
;
ix
>=
version
;
ix
--
)
{
...
...
@@ -711,7 +711,7 @@ void rollback_to_checkpoint (int version, struct shd_softc *ss, struct proc *p)
for
(
;
TrieIteratorIsValid
(
pos
);
TrieIteratorAdvance
(
&
pos
))
{
printf
(
"value = %ld, key = %ld, size = %d
\n
"
,
pos
->
value
,
pos
->
key
,
depthToSize
(
pos
->
maxDepth
));
copy_
block
(
ss
,
p
,
pos
->
value
,
pos
->
key
,
depthToSize
(
pos
->
maxDepth
),
SHADOW_TO_SRC
);
block
_copy
(
ss
,
p
,
pos
->
value
,
pos
->
key
,
depthToSize
(
pos
->
maxDepth
),
SHADOW_TO_SRC
);
}
TrieIteratorCleanup
(
&
pos
);
}
...
...
@@ -736,90 +736,46 @@ void print_checkpoint_map (int version)
void
load_checkpoint_map
(
struct
shd_softc
*
ss
,
struct
proc
*
p
)
{
long
temp_addr
[
128
];
long
int
temp_addr
[
128
];
int
ix
;
long
metadata_block
;
long
blocks_used
;
long
map
[
128
];
int
array_ix
;
int
i
;
long
read_start
;
int
lbn
;
int
pbn
;
int
lp_flag
;
long
size
;
int
failed
;
latest_version
=
1
;
int
i
,
j
,
k
;
int
write_start
;
int
current_block
;
int
read_start
;
int
num_blocks
;
metadata_block
=
2
;
blocks_used
=
0
;
array_ix
=
0
;
latest_version
=
0
;
for
(
i
=
0
;
i
<
512
/
sizeof
(
long
);
i
++
)
for
(
i
=
0
;
i
<
512
/
sizeof
(
long
int
);
i
++
)
{
map
[
i
]
=
0
;
temp_addr
[
i
]
=
0
;
map
[
i
]
=
0
;
}
if
(
read_block
(
ss
,
p
,
(
char
*
)
temp_addr
,
metadata_block
))
return
;
read_start
=
(
long
int
)
temp_addr
[
0
];
blocks_used
=
(
long
int
)
temp_addr
[
1
];
printf
(
"Read start = %ld
\n
"
,
read_start
);
printf
(
"Blocks used = %ld
\n
"
,
blocks_used
);
lp_flag
=
0
;
for
(
ix
=
0
;
ix
<
blocks_used
;
ix
++
)
}
read_block
(
ss
,
p
,
(
char
*
)
temp_addr
,
metadata_block
);
while
(
temp_addr
[
i
]
!=
0
)
{
if
(
read_block
(
ss
,
p
,
(
char
*
)
map
,
read_start
))
return
;
read_start
++
;
i
=
0
;
while
(
i
<
128
)
read_start
=
temp_addr
[
i
];
num_blocks
=
temp_addr
[
i
+
1
];
i
+=
2
;
for
(
j
=
0
;
j
<
num_blocks
;
j
++
)
{
if
(
0
==
map
[
i
])
read_block
(
ss
,
p
,
(
char
*
)
map
,
read_start
);
for
(
k
=
0
;
k
<
126
;
k
+=
3
)
{
if
(
0
==
map
[
i
+
1
])
{
i
=
128
;
continue
;
}
latest_version
++
;
i
++
;
if
(
i
>=
128
)
continue
;
/*TrieInsertWeak (map[k], map[k+1], map[k+2]); */
/* use non-allocating version of insertweak */
}
else
{
if
(
lp_flag
==
0
)
{
lbn
=
map
[
i
++
];
lp_flag
=
1
;
if
(
i
>=
128
)
continue
;
}
else
if
(
lp_flag
==
1
)
{
pbn
=
map
[
i
++
];
lp_flag
=
2
;
if
(
i
>=
128
)
continue
;
}
if
(
lp_flag
==
2
)
{
size
=
map
[
i
++
];
/* A trie function needed which can insert the lbn and pbn into the trie. unlike the COW, this function must not call BlockAlloc() */
/* failed = TrieInsertWeak (trie, bn, (bp->b_bcount)/512, ss, bp, p); */
lp_flag
=
0
;
if
(
i
>=
128
)
continue
;
}
}
}
read_start
++
;
}
latest_version
++
;
}
latest_version
++
;
}
}
void
save_checkpoint_map
(
struct
shd_softc
*
ss
,
struct
proc
*
p
)
{
...
...
@@ -941,7 +897,7 @@ int write_block (struct shd_softc *ss, struct proc *p, char block[512], long int
/* Copies "size" bytes starting at block src_block to block dest_block */
long
copy_
block
(
struct
shd_softc
*
ss
,
struct
proc
*
p
,
long
src_block
,
long
dest_block
,
long
num_blocks
,
int
type
)
long
block
_copy
(
struct
shd_softc
*
ss
,
struct
proc
*
p
,
long
src_block
,
long
dest_block
,
long
num_blocks
,
int
direction
)
{
int
error
=
0
;
struct
uio
auio
;
...
...
@@ -953,7 +909,7 @@ long copy_block (struct shd_softc *ss, struct proc *p, long src_block, long dest
size
=
num_blocks
*
512
;
/* convert number of blocks to number of bytes */
printf
(
"Copying %ld bytes from %d to %d
\n
"
,
size
,
src_block
,
dest_block
);
temp_addr
=
(
char
*
)
malloc
(
size
+
1
,
M_DEVBUF
,
M_NOWAIT
);
if
(
SRC_TO_SHADOW
==
type
)
{
if
(
SRC_TO_SHADOW
==
direction
)
{
vp
=
ss
->
sc_srcdisk
.
ci_vp
;
}
else
{
...
...
@@ -983,7 +939,7 @@ long copy_block (struct shd_softc *ss, struct proc *p, long src_block, long dest
/*Write this to block free_block in dest*/
if
(
SRC_TO_SHADOW
==
type
)
{
if
(
SRC_TO_SHADOW
==
direction
)
{
vp
=
ss
->
sc_copydisk
.
ci_vp
;
}
else
{
...
...
os/shd/shdconfig.c
View file @
d3bb909b
...
...
@@ -74,6 +74,7 @@ static void print_shd_info __P((struct shd_softc *, kvm_t *));
static
char
*
resolve_shdname
__P
((
char
*
));
static
void
usage
__P
((
void
));
int
save_checkpoint
(
char
*
shd
,
int
version
);
int
load_checkpoint
(
char
*
shd
,
int
version
);
int
main
(
argc
,
argv
)
...
...
@@ -197,7 +198,7 @@ do_single(argc, argv, action, flags)
{
version
=
atoi
(
*
argv
++
);
--
argc
;
printf
(
"Saving version %d
\n
"
,
version
);
save
_checkpoint
(
shd
,
version
);
load
_checkpoint
(
shd
,
version
);
}
printf
(
"shd%d: "
,
shio
.
shio_unit
);
printf
(
"%lu blocks "
,
(
u_long
)
shio
.
shio_size
);
...
...
@@ -627,8 +628,7 @@ int save_checkpoint (char * shd, int version)
struct
shd_readbuf
shread
;
char
buffer
[
MAXBUF
];
long
block
[
BLOCKSIZE
/
4
+
1
];
TrieIterator
pos
;
int
ok
;
off_t
off
;
int
i
;
int
ix
;
int
fd_read
;
...
...
@@ -686,7 +686,8 @@ int save_checkpoint (char * shd, int version)
read_start
=
(
long
)
block
[(
2
*
version
-
2
)];
num_blocks
=
(
long
)
block
[(
2
*
version
-
1
)];
write
(
fd_write_mdata
,
&
read_start
,
sizeof
(
long
));
write
(
fd_write_mdata
,
&
num_blocks
,
sizeof
(
long
));
printf
(
"read start = %ld, num blocks = %ld
\n
"
,
read_start
,
num_blocks
);
for
(
ix
=
0
;
ix
<
num_blocks
;
ix
++
)
{
...
...
@@ -695,7 +696,6 @@ int save_checkpoint (char * shd, int version)
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
);
...
...
@@ -708,6 +708,7 @@ int save_checkpoint (char * shd, int version)
perror
(
"error"
);
write
(
fd_write_mdata
,
&
block
[
i
],
sizeof
(
long
));
write
(
fd_write_mdata
,
&
block
[
i
+
1
],
sizeof
(
long
));
write
(
fd_write_mdata
,
&
block
[
i
+
2
],
sizeof
(
long
));
}
read_start
++
;
}
...
...
@@ -716,10 +717,107 @@ int save_checkpoint (char * shd, int version)
close
(
fd_write_data
);
close
(
fd_write_mdata
);
printf
(
"Save operation successful
\n
"
);
}
int
load_checkpoint
(
char
*
shd
,
int
version
)
{
char
buffer
[
MAXBUF
];
long
block
[
BLOCKSIZE
/
4
+
1
];
off_t
off
;
int
i
;
int
ix
;
int
fd_read_data
;
int
fd_read_mdata
;
int
fd_write_data
;
int
fd_write_mdata
;
int
size
;
int
write_start
;
int
num_blocks
;
long
byte_count
=
0
;
long
block_count
=
0
;
long
chunk_size
;
long
key
;
long
value
;
fd_write_data
=
open
(
"/dev/ad0s4"
,
O_RDWR
);
if
(
fd_write_data
<
0
)
{
perror
(
"error"
);
return
;
}
fd_write_mdata
=
open
(
"/dev/ad0s4"
,
O_RDWR
);
if
(
fd_write_mdata
<
0
)
{
perror
(
"error"
);
return
;
}
/* Similarly swap in blocks by changing fd_read, fd_write pointers */
/* Open the data file to read from */
fd_read_data
=
open
(
"/users/saggarwa/image1.data"
,
O_RDWR
);
if
(
fd_read_data
<
0
)
{
perror
(
"error"
);
return
;
}
/* Open the metadata file to read from */
fd_read_mdata
=
open
(
"/users/saggarwa/image1.mdata"
,
O_RDWR
);
if
(
fd_read_mdata
<
0
)
{
perror
(
"error"
);
return
;
}
for
(
i
=
0
;
i
<
128
;
i
++
)
block
[
i
]
=
0
;
return
;
read
(
fd_read_mdata
,
&
write_start
,
sizeof
(
long
));
read
(
fd_read_mdata
,
&
num_blocks
,
sizeof
(
long
));
printf
(
"Writing %ld blocks starting at %ld
\n
"
,
num_blocks
,
write_start
);
off
=
lseek
(
fd_write_mdata
,
write_start
*
BLOCKSIZE
,
SEEK_SET
);
while
(
read
(
fd_read_mdata
,
&
key
,
sizeof
(
long
)))
{
read
(
fd_read_mdata
,
&
value
,
sizeof
(
long
));
read
(
fd_read_mdata
,
&
chunk_size
,
sizeof
(
long
));
printf
(
"Read new triplet (%ld, %ld, %ld)
\n
"
,
key
,
value
,
chunk_size
);
off
=
lseek
(
fd_write_data
,
value
*
BLOCKSIZE
,
SEEK_SET
);
size
=
read
(
fd_read_data
,
&
buffer
,
chunk_size
*
BLOCKSIZE
);
if
(
size
<
0
)
perror
(
"error"
);
printf
(
"Read %ld bytes
\n
"
,
size
);
size
=
write
(
fd_write_data
,
&
buffer
,
size
);
if
(
size
<
0
)
perror
(
"error"
);
printf
(
"Wrote %ld bytes
\n
"
,
size
);
block
[
byte_count
++
]
=
key
;
block
[
byte_count
++
]
=
value
;
block
[
byte_count
++
]
=
chunk_size
;
if
(
byte_count
>=
125
)
{
byte_count
=
0
;
write
(
fd_write_mdata
,
&
block
,
BLOCKSIZE
);
for
(
i
=
0
;
i
<
128
;
i
++
)
block
[
i
]
=
0
;
write_start
++
;
block_count
++
;
if
(
block_count
>=
num_blocks
)
break
;
off
=
lseek
(
fd_write_mdata
,
write_start
*
BLOCKSIZE
,
SEEK_SET
);
}
}
if
(
byte_count
>
0
)
{
write
(
fd_write_mdata
,
&
block
,
BLOCKSIZE
);
}
close
(
fd_write_data
);
close
(
fd_write_mdata
);
close
(
fd_read_data
);
close
(
fd_read_mdata
);
printf
(
"Load operation successful
\n
"
);
}
/* Local Variables: */
...
...
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