changeset 17e33647b5d1 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=17e33647b5d1
description:
dev: Add post-fork handling for disk images
This changeset adds support for notifying the disk images that the
simulator has
been forked. We need to disable the saving of the CoW disk image from
the child
process, and we need to make sure that systems which use a raw disk
image are
not allowed to fork to avoid two or more gem5 processes writing to the
same disk
image.
Signed-off-by: Andreas Sandberg <[email protected]>
[[email protected]: Rebased patches onto a newer gem5 version]
Signed-off-by: Sascha Bischoff <[email protected]>
Signed-off-by: Andreas Sandberg <[email protected]>
diffstat:
src/dev/storage/disk_image.cc | 29 +++++++++++++++++++++++++++--
src/dev/storage/disk_image.hh | 4 ++++
2 files changed, 31 insertions(+), 2 deletions(-)
diffs (74 lines):
diff -r 40be59176869 -r 17e33647b5d1 src/dev/storage/disk_image.cc
--- a/src/dev/storage/disk_image.cc Thu Nov 26 10:03:43 2015 +0000
+++ b/src/dev/storage/disk_image.cc Thu Nov 26 10:11:52 2015 +0000
@@ -65,6 +65,17 @@
{ 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 @@
}
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 @@
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 -r 40be59176869 -r 17e33647b5d1 src/dev/storage/disk_image.hh
--- a/src/dev/storage/disk_image.hh Thu Nov 26 10:03:43 2015 +0000
+++ b/src/dev/storage/disk_image.hh Thu Nov 26 10:11:52 2015 +0000
@@ -82,6 +82,8 @@
RawDiskImage(const Params *p);
~RawDiskImage();
+ void notifyFork() override;
+
void close();
void open(const std::string &filename, bool rd_only = false);
@@ -123,6 +125,8 @@
CowDiskImage(const Params *p);
~CowDiskImage();
+ void notifyFork() override;
+
void initSectorTable(int hash_size);
bool open(const std::string &file);
void save() const;
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev