From 6a49dee3f3994c91c3038752172c24a8a5c05d88 Mon Sep 17 00:00:00 2001 From: Joel Hestness Date: Fri, 23 Dec 2016 08:43:18 -0600 Subject: [PATCH] sim: Fix SE mode checkpoint restore file handling When restoring from a checkpoint, the simulation used to use file handles from the checkpoint. This disallows multiple separate restore simulations from using separate input and output files and directories, and plays havoc when the checkpointed file locations may have changed. Add handling to allow the command line specified files to be used as input/output for the restored simulation (Note: this is the similar functionality to FS mode for output and error). --- src/sim/process.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/sim/process.cc b/src/sim/process.cc index 0ba215511..ef3ab9ecd 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -336,6 +336,18 @@ Process::fixFileOffsets() // Search through the input options and set fd if match is found; // otherwise, open an input file and seek to location. FDEntry *fde_stdin = getFDEntry(STDIN_FILENO); + + // Check if user has specified a different input file, and if so, use it + // instead of the file specified in the checkpoint. This also resets the + // file offset from the checkpointed value + string new_in = ((ProcessParams*)params())->input; + if (new_in != fde_stdin->filename) { + warn("Using new input file (%s) rather than checkpointed (%s)\n", + new_in, fde_stdin->filename); + fde_stdin->filename = new_in; + fde_stdin->fileOffset = 0; + } + if ((it = imap.find(fde_stdin->filename)) != imap.end()) { fde_stdin->fd = it->second; } else { @@ -346,6 +358,18 @@ Process::fixFileOffsets() // Search through the output/error options and set fd if match is found; // otherwise, open an output file and seek to location. FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO); + + // Check if user has specified a different output file, and if so, use it + // instead of the file specified in the checkpoint. This also resets the + // file offset from the checkpointed value + string new_out = ((ProcessParams*)params())->output; + if (new_out != fde_stdout->filename) { + warn("Using new output file (%s) rather than checkpointed (%s)\n", + new_out, fde_stdout->filename); + fde_stdout->filename = new_out; + fde_stdout->fileOffset = 0; + } + if ((it = oemap.find(fde_stdout->filename)) != oemap.end()) { fde_stdout->fd = it->second; } else { @@ -354,6 +378,18 @@ Process::fixFileOffsets() } FDEntry *fde_stderr = getFDEntry(STDERR_FILENO); + + // Check if user has specified a different error file, and if so, use it + // instead of the file specified in the checkpoint. This also resets the + // file offset from the checkpointed value + string new_err = ((ProcessParams*)params())->errout; + if (new_err != fde_stderr->filename) { + warn("Using new error file (%s) rather than checkpointed (%s)\n", + new_err, fde_stderr->filename); + fde_stderr->filename = new_err; + fde_stderr->fileOffset = 0; + } + if (fde_stdout->filename == fde_stderr->filename) { // Reuse the same file descriptor if these match. fde_stderr->fd = fde_stdout->fd; -- 2.30.2