summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dev/storage/disk_image.cc29
-rw-r--r--src/dev/storage/disk_image.hh4
2 files changed, 31 insertions, 2 deletions
diff --git a/src/dev/storage/disk_image.cc b/src/dev/storage/disk_image.cc
index 24688f55a..e7fda40a2 100644
--- a/src/dev/storage/disk_image.cc
+++ b/src/dev/storage/disk_image.cc
@@ -65,6 +65,17 @@ RawDiskImage::~RawDiskImage()
{ close(); }
void
+RawDiskImage::notifyFork()
+{
+ if (initialized && !readonly)
+ panic("Attempting to fork system with read-write raw disk image.");
+
+ const Params *p(dynamic_cast<const Params *>(params()));
+ close();
+ open(p->image_file, p->read_only);
+}
+
+void
RawDiskImage::open(const string &filename, bool rd_only)
{
if (!filename.empty()) {
@@ -198,6 +209,16 @@ CowDiskImage::~CowDiskImage()
}
void
+CowDiskImage::notifyFork()
+{
+ if (!dynamic_cast<const Params *>(params())->read_only &&
+ !filename.empty()) {
+ inform("Disabling saving of COW image in forked child process.\n");
+ filename = "";
+ }
+}
+
+void
SafeRead(ifstream &stream, void *data, int count)
{
stream.read((char *)data, count);
@@ -311,8 +332,12 @@ SafeWriteSwap(ofstream &stream, const T &data)
void
CowDiskImage::save() const
{
- save(filename);
-}
+ // filename will be set to the empty string to disable saving of
+ // the COW image in a forked child process. Save will still be
+ // called because there is no easy way to unregister the exit
+ // callback.
+ if (!filename.empty())
+ save(filename);}
void
CowDiskImage::save(const string &file) const
diff --git a/src/dev/storage/disk_image.hh b/src/dev/storage/disk_image.hh
index 43e6adf5e..2a59dc0c3 100644
--- a/src/dev/storage/disk_image.hh
+++ b/src/dev/storage/disk_image.hh
@@ -82,6 +82,8 @@ class RawDiskImage : public DiskImage
RawDiskImage(const Params *p);
~RawDiskImage();
+ void notifyFork() override;
+
void close();
void open(const std::string &filename, bool rd_only = false);
@@ -123,6 +125,8 @@ class CowDiskImage : public DiskImage
CowDiskImage(const Params *p);
~CowDiskImage();
+ void notifyFork() override;
+
void initSectorTable(int hash_size);
bool open(const std::string &file);
void save() const;