From patchwork Wed Nov 13 16:27:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 3178761 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1D8239F43F for ; Wed, 13 Nov 2013 16:28:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F345A20775 for ; Wed, 13 Nov 2013 16:28:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D86B720773 for ; Wed, 13 Nov 2013 16:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755687Ab3KMQ2E (ORCPT ); Wed, 13 Nov 2013 11:28:04 -0500 Received: from mail-bk0-f42.google.com ([209.85.214.42]:38356 "EHLO mail-bk0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754138Ab3KMQ2D (ORCPT ); Wed, 13 Nov 2013 11:28:03 -0500 Received: by mail-bk0-f42.google.com with SMTP id w16so474285bkz.29 for ; Wed, 13 Nov 2013 08:27:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding; bh=NftNa/uXmRKYLGZiDe7q3ztGm0cHp9BbjxRILzsqfkc=; b=g92Z6V/P5EegavVP/qWiG+QpKXkGzv+aa/vENUGsA/PjDm2RsibrFbNKEFUsrw3Z32 TUznR0y5oXEgmEVvdmnbeF5MgyHs2eyooVBOlGUj3X1LDAl7iKxCi76vmMLE99wkRV1C ACwPIZAu+WQR4IOwpFbBz2fLqPXO/wKzMr74PwNQqGu0FiyHEHRQWuZUi37Rud3pULBW witkauA72r5chVh4hA4Okd1v+P5tvRYpMRAuuCmahvS48jWiS4tza0NfvFubmTz4R/OY 5Gu9lpi7AGFzX54BfJQACVbkXLZeG15OyjxKlUiulq0oT5/tPvoUgqczbJ+N8qtV0R+z OrPQ== X-Gm-Message-State: ALoCoQles01IBU65FlA/Pei3Ys3kV/QOnhctPjRd0D7jUORxQcYVpRgHRfJBHK3GP3HpMJPxpJVP X-Received: by 10.205.102.73 with SMTP id dd9mr17652bkc.62.1384360079511; Wed, 13 Nov 2013 08:27:59 -0800 (PST) Received: from [192.168.1.102] (c-98-229-118-119.hsd1.ma.comcast.net. [98.229.118.119]) by mx.google.com with ESMTPSA id qe6sm23801049bkb.5.2013.11.13.08.27.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Nov 2013 08:27:59 -0800 (PST) Message-ID: <5283A88D.9020608@dev.mellanox.co.il> Date: Wed, 13 Nov 2013 11:27:57 -0500 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: "linux-rdma (linux-rdma@vger.kernel.org)" CC: Vladimir Koushnir Subject: [PATCH opensm] Implement atomic update operation for sa_db_file Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)