- implemented save state function for the disk image modes 'concat' and 'sparse'
- set timestamp of r/o disk in volatile mode, too (for save/restore support) - TODO: save state function for the remaining image modes, restore support
This commit is contained in:
parent
7da5057be5
commit
5cbf0894ac
@ -397,8 +397,10 @@ int concat_image_t::open(const char* pathname0)
|
||||
void concat_image_t::close()
|
||||
{
|
||||
BX_DEBUG(("concat_image_t.close"));
|
||||
if (fd > -1) {
|
||||
::close(fd);
|
||||
for (int index = 0; index < maxfd; index++) {
|
||||
if (fd_table[index] > -1) {
|
||||
::close(fd_table[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -466,6 +468,19 @@ ssize_t concat_image_t::write(const void* buf, size_t count)
|
||||
return ::write(fd, (char*) buf, count);
|
||||
}
|
||||
|
||||
bx_bool concat_image_t::save_state(const char *backup_fname)
|
||||
{
|
||||
bx_bool ret = 1;
|
||||
char tempfn[BX_PATHNAME_LEN];
|
||||
|
||||
for (int index = 0; index < maxfd; index++) {
|
||||
sprintf(tempfn, "%s%d", backup_fname, index);
|
||||
ret &= hdimage_backup_file(fd_table[index], tempfn);
|
||||
if (ret == 0) break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*** sparse_image_t function definitions ***/
|
||||
|
||||
sparse_image_t::sparse_image_t()
|
||||
@ -991,6 +1006,32 @@ ssize_t sparse_image_t::write(const void* buf, size_t count)
|
||||
return total_written;
|
||||
}
|
||||
|
||||
bx_bool sparse_image_t::save_state(const char *backup_fname)
|
||||
{
|
||||
if (parent_image != NULL) {
|
||||
int index = save_state_specific(0, backup_fname);
|
||||
return (index > 0) ? 1 : 0;
|
||||
} else {
|
||||
return hdimage_backup_file(fd, backup_fname);
|
||||
}
|
||||
}
|
||||
|
||||
int sparse_image_t::save_state_specific(int index, const char *backup_fname)
|
||||
{
|
||||
char tempfn[BX_PATHNAME_LEN];
|
||||
|
||||
if (parent_image != NULL) {
|
||||
index = parent_image->save_state_specific(index, backup_fname);
|
||||
if (index < 0) return -1;
|
||||
}
|
||||
sprintf(tempfn, "%s%d", backup_fname, index);
|
||||
if (hdimage_backup_file(fd, tempfn) != 0) {
|
||||
return ++index;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#if DLL_HD_SUPPORT
|
||||
|
||||
/*** dll_image_t function definitions ***/
|
||||
@ -1688,6 +1729,7 @@ int volatile_image_t::open(const char* pathname)
|
||||
{
|
||||
int filedes;
|
||||
const char *logname=NULL;
|
||||
Bit32u timestamp;
|
||||
|
||||
if (ro_disk->open(pathname, O_RDONLY)<0)
|
||||
return -1;
|
||||
@ -1726,6 +1768,10 @@ int volatile_image_t::open(const char* pathname)
|
||||
unlink(redolog_temp);
|
||||
#endif
|
||||
|
||||
// timestamp required for save/restore support
|
||||
timestamp = ro_disk->get_timestamp();
|
||||
redolog->set_timestamp(timestamp);
|
||||
|
||||
BX_INFO(("'volatile' disk opened: ro-file is '%s', redolog is '%s'", pathname, redolog_temp));
|
||||
|
||||
return 0;
|
||||
|
@ -229,6 +229,9 @@ class concat_image_t : public device_image_t
|
||||
// written (count).
|
||||
ssize_t write(const void* buf, size_t count);
|
||||
|
||||
// Save/restore support
|
||||
bx_bool save_state(const char *backup_fname);
|
||||
|
||||
private:
|
||||
#define BX_CONCAT_MAX_IMAGES 8
|
||||
int fd_table[BX_CONCAT_MAX_IMAGES];
|
||||
@ -281,6 +284,10 @@ class sparse_image_t : public device_image_t
|
||||
// written (count).
|
||||
ssize_t write(const void* buf, size_t count);
|
||||
|
||||
// Save/restore support
|
||||
bx_bool save_state(const char *backup_fname);
|
||||
int save_state_specific(int index, const char *backup_fname);
|
||||
|
||||
private:
|
||||
int fd;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user