Re: [infiniband-diags] [1/2] support libibnetdisc caching overwrite flag

2010-04-19 Thread Sasha Khapyorsky
Hi Al,

On 16:52 Thu 15 Apr , Al Chu wrote:
 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;
 + }
   }

Wouldn't it be better to make it in opposite direction - overwrite file
by default and drop an error when exclusive flag is specified?

For me it looks as more intuitive behavior (similar to other
editors).

Sasha
--
To unsubscribe from this list: send the line unsubscribe linux-rdma in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[infiniband-diags] [1/2] support libibnetdisc caching overwrite flag

2010-04-15 Thread Al Chu
Hi Sasha,

This patch supports a flag in the libibnetdisc caching code to overwrite
a previous cache.

Al

-- 
Albert Chu
ch...@llnl.gov
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory
---BeginMessage---

Signed-off-by: Albert Chu ch...@llnl.gov
---
 .../libibnetdisc/include/infiniband/ibnetdisc.h|3 +++
 .../libibnetdisc/src/ibnetdisc_cache.c |   17 ++---
 2 files changed, 17 insertions(+), 3 deletions(-)

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   0x
+#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) {
-- 
1.5.4.5

---End Message---