From patchwork Thu Apr 15 23:52:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Chu X-Patchwork-Id: 93037 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3FNqTkb022500 for ; Thu, 15 Apr 2010 23:52:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758135Ab0DOXw2 (ORCPT ); Thu, 15 Apr 2010 19:52:28 -0400 Received: from nspiron-3.llnl.gov ([128.115.41.83]:54160 "EHLO smtp.llnl.gov" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758117Ab0DOXw2 (ORCPT ); Thu, 15 Apr 2010 19:52:28 -0400 X-Attachments: 0001-support-libibnetdisc-caching-overwrite-flag.patch Received: from auk31.llnl.gov (HELO [134.9.93.159]) ([134.9.93.159]) by smtp.llnl.gov with ESMTP; 15 Apr 2010 16:52:27 -0700 Subject: [infiniband-diags] [1/2] support libibnetdisc caching overwrite flag From: Al Chu To: Sasha Khapyorsky Cc: "linux-rdma@vger.kernel.org" Date: Thu, 15 Apr 2010 16:52:27 -0700 Message-Id: <1271375547.17987.178.camel@auk31.llnl.gov> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-19.el5) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 15 Apr 2010 23:52:29 +0000 (UTC) diff --git a/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h b/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h index 136282c..c83bd0b 100644 --- a/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h +++ b/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h @@ -181,6 +181,9 @@ MAD_EXPORT void ibnd_destroy_fabric(ibnd_fabric_t * fabric); MAD_EXPORT ibnd_fabric_t *ibnd_load_fabric(const char *file, unsigned int flags); +#define IBND_CACHE_FABRIC_FLAG_DEFAULT 0x0000 +#define IBND_CACHE_FABRIC_FLAG_OVERWRITE 0x0001 + MAD_EXPORT int ibnd_cache_fabric(ibnd_fabric_t * fabric, const char *file, unsigned int flags); diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c b/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c index 480a0a2..6cf7d4d 100644 --- a/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c +++ b/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c @@ -876,9 +876,20 @@ int ibnd_cache_fabric(ibnd_fabric_t * fabric, const char *file, return -1; } - if (!stat(file, &statbuf)) { - IBND_DEBUG("file '%s' already exists\n", file); - return -1; + if (flags & IBND_CACHE_FABRIC_FLAG_OVERWRITE) { + if (!stat(file, &statbuf)) { + if (unlink(file) < 0) { + IBND_DEBUG("error removing '%s': %s\n", + file, strerror(errno)); + return -1; + } + } + } + else { + if (!stat(file, &statbuf)) { + IBND_DEBUG("file '%s' already exists\n", file); + return -1; + } } if ((fd = open(file, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) {