clean_process:
if (!is_process_running(pi.dwProcessId)) {
GetExitCodeProcess(pi.hProcess, (PDWORD)&exit_code);
+ if (!exit_code) {
+ // Child terminated unexpectedly.
+ exit_code = -ECHILD;
+ } else if (exit_code > 0) {
+ // Make sure to return a negative error code.
+ exit_code = -exit_code;
+ }
derr << "Daemon failed with: " << cpp_strerror(exit_code) << dendl;
} else {
// The process closed the pipe without notifying us or exiting.
return cct;
}
+// Wait for the mapped disk to become available.
+static int wait_mapped_disk(Config *cfg)
+{
+ DWORD status = WnbdPollDiskNumber(
+ cfg->devpath.c_str(),
+ TRUE, // ExpectMapped
+ TRUE, // TryOpen
+ cfg->image_map_timeout,
+ DISK_STATUS_POLLING_INTERVAL_MS,
+ (PDWORD) &cfg->disk_number);
+ if (status) {
+ derr << "WNBD disk unavailable, error: "
+ << win32_strerror(status) << dendl;
+ return -EINVAL;
+ }
+ dout(0) << "Successfully mapped image: " << cfg->devpath
+ << ". Windows disk path: "
+ << "\\\\.\\PhysicalDrive" + std::to_string(cfg->disk_number)
+ << dendl;
+ return 0;
+}
+
static int do_map(Config *cfg)
{
int r;
int err = 0;
if (g_conf()->daemonize && cfg->parent_pipe.empty()) {
- return send_map_request(get_cli_args());
+ r = send_map_request(get_cli_args());
+ if (r < 0) {
+ return r;
+ }
+
+ return wait_mapped_disk(cfg);
}
dout(0) << "Mapping RBD image: " << cfg->devpath << dendl;
goto close_ret;
}
+ // TODO: consider substracting the time it took to perform the
+ // above operations from cfg->image_map_timeout in wait_mapped_disk().
+ r = wait_mapped_disk(cfg);
+ if (r < 0) {
+ goto close_ret;
+ }
+
// We're informing the parent processes that the initialization
// was successful.
if (!cfg->parent_pipe.empty()) {