From: Hal Rosenstock Subject: [PATCH opensm] Implement atomic update operation for sa_db_file Date: Wed, 13 Nov 2013 11:27:57 -0500 Message-ID: <5283A88D.9020608@dev.mellanox.co.il> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Sender: linux-rdma-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: "linux-rdma (linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org)" Cc: Vladimir Koushnir List-Id: linux-rdma@vger.kernel.org From: Vladimir Koushnir Signed-off-by: Vladimir Koushnir --- opensm/osm_sa.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/opensm/osm_sa.c b/opensm/osm_sa.c index 8c5ef5d..d5c1275 100644 --- a/opensm/osm_sa.c +++ b/opensm/osm_sa.c @@ -525,25 +525,37 @@ opensm_dump_to_file(osm_opensm_t * p_osm, const char *file_name, void (*dump_func) (osm_opensm_t * p_osm, FILE * file)) { char path[1024]; + char path_tmp[1032]; FILE *file; + int status = 0; snprintf(path, sizeof(path), "%s/%s", p_osm->subn.opt.dump_files_dir, file_name); - file = fopen(path, "w"); + snprintf(path_tmp, sizeof(path_tmp), "%s.tmp", path); + + file = fopen(path_tmp, "w"); if (!file) { OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR 4C01: " "cannot open file \'%s\': %s\n", - file_name, strerror(errno)); + path_tmp, strerror(errno)); return -1; } - chmod(path, S_IRUSR | S_IWUSR); + chmod(path_tmp, S_IRUSR | S_IWUSR); dump_func(p_osm, file); fclose(file); - return 0; + + status = rename(path_tmp, path); + if (status) { + OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR 4C0B: " + "Failed to rename file:%s (err:%s)\n", + path_tmp, strerror(errno)); + } + + return status; } static void mcast_mgr_dump_one_port(cl_map_item_t * p_map_item, void *cxt) -- 1.7.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html