This patch allows online compacting to be done under Windows. To achieve the above we need to close all file handles before trying to rename the file, switch from rename to MoveFileEx (because rename/MoveFile fails if the destination exists), reopen the right type of log after the rename.
Signed-off-by: Alin Gabriel Serdean <aserd...@cloudbasesolutions.com> --- ovsdb/file.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ovsdb/file.c b/ovsdb/file.c index 7f8554a..71e597b 100644 --- a/ovsdb/file.c +++ b/ovsdb/file.c @@ -667,28 +667,63 @@ ovsdb_file_compact(struct ovsdb_file *file) goto exit; } +#ifdef _WIN32 + /* On Windows we must close the file handles before trying to rename */ + ovsdb_log_close(file->log); + ovsdb_log_close(new_log); +#endif + /* Replace original by temporary. */ +#ifdef _WIN32 + if (!MoveFileEx(tmp_name, file->file_name, MOVEFILE_REPLACE_EXISTING + | MOVEFILE_WRITE_THROUGH)) { + VLOG_ERR("fcntl: %s", ovs_lasterror_to_string()); + error = ovsdb_io_error(EACCES, "failed to rename \"%s\" to \"%s\"", + tmp_name, file->file_name); + goto exit; + } +#else if (rename(tmp_name, file->file_name)) { error = ovsdb_io_error(errno, "failed to rename \"%s\" to \"%s\"", tmp_name, file->file_name); goto exit; } +#endif fsync_parent_dir(file->file_name); exit: if (!error) { +#ifdef _WIN32 + error = ovsdb_log_open(file->file_name, OVSDB_LOG_READ_WRITE, 0, + &new_log); + if (error) { + goto cleanup; + } +#else ovsdb_log_close(file->log); +#endif file->log = new_log; file->last_compact = time_msec(); file->next_compact = file->last_compact + COMPACT_MIN_MSEC; file->n_transactions = 1; } else { +#ifdef _WIN32 + error = ovsdb_log_open(file->file_name, OVSDB_LOG_READ_WRITE, 0, + file->log); + if (error) { + goto cleanup; + } +#else ovsdb_log_close(new_log); +#endif if (tmp_lock) { unlink(tmp_name); } } +#ifdef _WIN32 +cleanup: +#endif lockfile_unlock(tmp_lock); free(tmp_name); free(comment); -- 2.9.2.windows.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev