diff options
Diffstat (limited to 'src/H5FDlog.c')
-rw-r--r-- | src/H5FDlog.c | 266 |
1 files changed, 132 insertions, 134 deletions
diff --git a/src/H5FDlog.c b/src/H5FDlog.c index dee4581..0da5765 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -190,8 +190,9 @@ static herr_t H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr size_t size, void *buf); static herr_t H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, const void *buf); -static herr_t H5FD_log_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); +static herr_t H5FD_log_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); +#ifdef OLD_WAY /* * The free list map which causes each request type to use no free lists */ @@ -204,6 +205,7 @@ static herr_t H5FD_log_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); H5FD_MEM_NOLIST, /*lheap*/ \ H5FD_MEM_NOLIST /*ohdr*/ \ } +#endif /* OLD_WAY */ static const H5FD_class_t H5FD_log_g = { "log", /*name */ @@ -223,6 +225,7 @@ static const H5FD_class_t H5FD_log_g = { H5FD_log_close, /*close */ H5FD_log_cmp, /*cmp */ H5FD_log_query, /*query */ + NULL, /*get_type_map */ H5FD_log_alloc, /*alloc */ NULL, /*free */ H5FD_log_get_eoa, /*get_eoa */ @@ -231,14 +234,11 @@ static const H5FD_class_t H5FD_log_g = { H5FD_log_get_handle, /*get_handle */ H5FD_log_read, /*read */ H5FD_log_write, /*write */ - H5FD_log_flush, /*flush */ + NULL, /*flush */ + H5FD_log_truncate, /*truncate */ NULL, /*lock */ NULL, /*unlock */ -#ifdef OLD_WAY - H5FD_FLMAP_NOLIST /*fl_map */ -#else /* OLD_WAY */ H5FD_FLMAP_SINGLE /*fl_map */ -#endif /* OLD_WAY */ }; @@ -289,7 +289,7 @@ H5FD_log_init(void) FUNC_ENTER_NOAPI(H5FD_log_init, FAIL) if (H5I_VFL!=H5Iget_type(H5FD_LOG_g)) - H5FD_LOG_g = H5FD_register(&H5FD_log_g,sizeof(H5FD_class_t)); + H5FD_LOG_g = H5FD_register(&H5FD_log_g,sizeof(H5FD_class_t),FALSE); /* Set return value */ ret_value=H5FD_LOG_g; @@ -358,14 +358,14 @@ H5Pset_fapl_log(hid_t fapl_id, const char *logfile, unsigned flags, size_t buf_s if(NULL == (plist = H5P_object_verify(fapl_id,H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list") - fa.logfile=(char*)logfile; - fa.flags=flags; - fa.buf_size=buf_size; - ret_value= H5P_set_driver(plist, H5FD_LOG, &fa); + fa.logfile = (char *)logfile; + fa.flags = flags; + fa.buf_size = buf_size; + ret_value = H5P_set_driver(plist, H5FD_LOG, &fa); done: FUNC_LEAVE_API(ret_value) -} +} /* end H5Pset_fapl_log() */ /*------------------------------------------------------------------------- @@ -409,39 +409,47 @@ done: * Purpose: Copies the log-specific file access properties. * * Return: Success: Ptr to a new property list - * * Failure: NULL * * Programmer: Quincey Koziol * Thursday, April 20, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static void * H5FD_log_fapl_copy(const void *_old_fa) { const H5FD_log_fapl_t *old_fa = (const H5FD_log_fapl_t*)_old_fa; - H5FD_log_fapl_t *new_fa = H5MM_malloc(sizeof(H5FD_log_fapl_t)); + H5FD_log_fapl_t *new_fa = NULL; /* New FAPL info */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5FD_log_fapl_copy, NULL) - assert(new_fa); + HDassert(old_fa); + + /* Allocate the new FAPL info */ + if(NULL == (new_fa = (H5FD_log_fapl_t *)H5MM_calloc(sizeof(H5FD_log_fapl_t)))) + HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL") /* Copy the general information */ HDmemcpy(new_fa, old_fa, sizeof(H5FD_log_fapl_t)); /* Deep copy the log file name */ - if(old_fa->logfile!=NULL) - if (NULL==(new_fa->logfile=H5MM_xstrdup(old_fa->logfile))) + if(old_fa->logfile != NULL) + if(NULL == (new_fa->logfile = H5MM_xstrdup(old_fa->logfile))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate log file name") /* Set return value */ - ret_value=new_fa; + ret_value = new_fa; done: + if(NULL == ret_value) + if(new_fa) { + if(new_fa->logfile) + H5MM_free(new_fa->logfile); + H5MM_free(new_fa); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_log_fapl_copy() */ @@ -452,31 +460,26 @@ done: * Purpose: Frees the log-specific file access properties. * * Return: Success: 0 - * * Failure: -1 * * Programmer: Quincey Koziol * Thursday, April 20, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t H5FD_log_fapl_free(void *_fa) { H5FD_log_fapl_t *fa = (H5FD_log_fapl_t*)_fa; - herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5FD_log_fapl_free, FAIL) + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_fapl_free) /* Free the fapl information */ if(fa->logfile) H5MM_xfree(fa->logfile); H5MM_xfree(fa); -done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD_log_fapl_free() */ @@ -488,65 +491,66 @@ done: * Return: Success: A pointer to a new file data structure. The * public fields will be initialized by the * caller, which is always H5FD_open(). - * * Failure: NULL * * Programmer: Robb Matzke * Thursday, July 29, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ static H5FD_t * H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) { - int o_flags; - int fd=(-1); - H5FD_log_t *file=NULL; + int o_flags; + int fd = (-1); + H5FD_log_t *file = NULL; H5FD_log_fapl_t *fa; /* File access property list information */ #ifdef _WIN32 HFILE filehandle; struct _BY_HANDLE_FILE_INFORMATION fileinfo; #endif - h5_stat_t sb; + h5_stat_t sb; H5P_genplist_t *plist; /* Property list */ H5FD_t *ret_value; FUNC_ENTER_NOAPI(H5FD_log_open, NULL) /* Check arguments */ - if (!name || !*name) + if(!name || !*name) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name") - if (0==maxaddr || HADDR_UNDEF==maxaddr) + if(0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr") - if (ADDR_OVERFLOW(maxaddr)) + if(ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr") /* Build the open flags */ o_flags = (H5F_ACC_RDWR & flags) ? O_RDWR : O_RDONLY; - if (H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC; - if (H5F_ACC_CREAT & flags) o_flags |= O_CREAT; - if (H5F_ACC_EXCL & flags) o_flags |= O_EXCL; + if(H5F_ACC_TRUNC & flags) + o_flags |= O_TRUNC; + if(H5F_ACC_CREAT & flags) + o_flags |= O_CREAT; + if(H5F_ACC_EXCL & flags) + o_flags |= O_EXCL; /* Open the file */ - if ((fd=HDopen(name, o_flags, 0666))<0) + if((fd = HDopen(name, o_flags, 0666)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") - if (HDfstat(fd, &sb)<0) + if(HDfstat(fd, &sb) < 0) HGOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") /* Create the new file struct */ - if (NULL==(file=H5MM_calloc(sizeof(H5FD_log_t)))) + if(NULL == (file = (H5FD_log_t *)H5MM_calloc(sizeof(H5FD_log_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct") /* Get the driver specific information */ - if(NULL == (plist = H5P_object_verify(fapl_id,H5P_FILE_ACCESS))) + if(NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") - fa = H5P_get_driver_info(plist); + fa = (H5FD_log_fapl_t *)H5P_get_driver_info(plist); + HDassert(fa); file->fd = fd; - H5_ASSIGN_OVERFLOW(file->eof,sb.st_size,h5_stat_size_t,haddr_t); + H5_ASSIGN_OVERFLOW(file->eof, sb.st_size, h5_stat_size_t, haddr_t); file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; #ifdef _WIN32 @@ -560,36 +564,37 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, #endif /* Get the flags for logging */ - file->fa.flags=fa->flags; + file->fa.flags = fa->flags; /* Check if we are doing any logging at all */ - if(file->fa.flags!=0) { - file->iosize=fa->buf_size; - if(file->fa.flags&H5FD_LOG_FILE_READ) { - file->nread=H5MM_calloc(file->iosize); - assert(file->nread); + if(file->fa.flags != 0) { + file->iosize = fa->buf_size; + if(file->fa.flags & H5FD_LOG_FILE_READ) { + file->nread = (unsigned char *)H5MM_calloc(file->iosize); + HDassert(file->nread); } /* end if */ - if(file->fa.flags&H5FD_LOG_FILE_WRITE) { - file->nwrite=H5MM_calloc(file->iosize); - assert(file->nwrite); + if(file->fa.flags & H5FD_LOG_FILE_WRITE) { + file->nwrite = (unsigned char *)H5MM_calloc(file->iosize); + HDassert(file->nwrite); } /* end if */ - if(file->fa.flags&H5FD_LOG_FLAVOR) { - file->flavor=H5MM_calloc(file->iosize); - assert(file->flavor); + if(file->fa.flags & H5FD_LOG_FLAVOR) { + file->flavor = (unsigned char *)H5MM_calloc(file->iosize); + HDassert(file->flavor); } /* end if */ if(fa->logfile) - file->logfp=HDfopen(fa->logfile,"w"); + file->logfp = HDfopen(fa->logfile, "w"); else - file->logfp=stderr; + file->logfp = stderr; } /* end if */ /* Set return value */ - ret_value=(H5FD_t*)file; + ret_value = (H5FD_t*)file; done: - if(ret_value==NULL) { - if(fd>=0) + if(NULL == ret_value) { + if(fd >= 0) HDclose(fd); + file = (H5FD_log_t *)H5MM_xfree(file); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -602,14 +607,11 @@ done: * Purpose: Closes a Unix file. * * Return: Success: 0 - * * Failure: -1, file not closed. * * Programmer: Robb Matzke * Thursday, July 29, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t @@ -620,7 +622,7 @@ H5FD_log_close(H5FD_t *_file) struct timeval timeval_start,timeval_stop; struct timeval timeval_diff; #endif /* H5_HAVE_GETTIMEOFDAY */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5FD_log_close, FAIL) @@ -628,7 +630,7 @@ H5FD_log_close(H5FD_t *_file) if(file->fa.flags&H5FD_LOG_TIME_CLOSE) HDgettimeofday(&timeval_start,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ - if (HDclose(file->fd)<0) + if(HDclose(file->fd) < 0) HGOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file") #ifdef H5_HAVE_GETTIMEOFDAY if(file->fa.flags&H5FD_LOG_TIME_CLOSE) @@ -636,83 +638,83 @@ H5FD_log_close(H5FD_t *_file) #endif /* H5_HAVE_GETTIMEOFDAY */ /* Dump I/O information */ - if(file->fa.flags!=0) { + if(file->fa.flags != 0) { haddr_t addr; haddr_t last_addr; unsigned char last_val; #ifdef H5_HAVE_GETTIMEOFDAY - if(file->fa.flags&H5FD_LOG_TIME_CLOSE) { + if(file->fa.flags & H5FD_LOG_TIME_CLOSE) { /* Calculate the elapsed gettimeofday time */ - timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec; - timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec; - if(timeval_diff.tv_usec<0) { - timeval_diff.tv_usec+=1000000; + timeval_diff.tv_usec = timeval_stop.tv_usec - timeval_start.tv_usec; + timeval_diff.tv_sec = timeval_stop.tv_sec - timeval_start.tv_sec; + if(timeval_diff.tv_usec < 0) { + timeval_diff.tv_usec += 1000000; timeval_diff.tv_sec--; } /* end if */ - HDfprintf(file->logfp,"Close took: (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + HDfprintf(file->logfp, "Close took: (%f s)\n", (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0)); } /* end if */ #endif /* H5_HAVE_GETTIMEOFDAY */ /* Dump the write I/O information */ - if(file->fa.flags&H5FD_LOG_FILE_WRITE) { - HDfprintf(file->logfp,"Dumping write I/O information:\n"); - last_val=file->nwrite[0]; - last_addr=0; - addr=1; - while(addr<file->eoa) { - if(file->nwrite[addr]!=last_val) { - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); - last_val=file->nwrite[addr]; - last_addr=addr; + if(file->fa.flags & H5FD_LOG_FILE_WRITE) { + HDfprintf(file->logfp, "Dumping write I/O information:\n"); + last_val = file->nwrite[0]; + last_addr = 0; + addr = 1; + while(addr < file->eoa) { + if(file->nwrite[addr] != last_val) { + HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) written to %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val); + last_val = file->nwrite[addr]; + last_addr = addr; } /* end if */ addr++; } /* end while */ - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) written to %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val); } /* end if */ /* Dump the read I/O information */ - if(file->fa.flags&H5FD_LOG_FILE_READ) { - HDfprintf(file->logfp,"Dumping read I/O information:\n"); - last_val=file->nread[0]; - last_addr=0; - addr=1; - while(addr<file->eoa) { - if(file->nread[addr]!=last_val) { - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); - last_val=file->nread[addr]; - last_addr=addr; + if(file->fa.flags & H5FD_LOG_FILE_READ) { + HDfprintf(file->logfp, "Dumping read I/O information:\n"); + last_val = file->nread[0]; + last_addr = 0; + addr = 1; + while(addr < file->eoa) { + if(file->nread[addr] != last_val) { + HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) read from %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val); + last_val = file->nread[addr]; + last_addr = addr; } /* end if */ addr++; } /* end while */ - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) read from %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val); } /* end if */ /* Dump the I/O flavor information */ - if(file->fa.flags&H5FD_LOG_FLAVOR) { - HDfprintf(file->logfp,"Dumping I/O flavor information:\n"); - last_val=file->flavor[0]; - last_addr=0; - addr=1; - while(addr<file->eoa) { - if(file->flavor[addr]!=last_val) { - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]); - last_val=file->flavor[addr]; - last_addr=addr; + if(file->fa.flags & H5FD_LOG_FLAVOR) { + HDfprintf(file->logfp, "Dumping I/O flavor information:\n"); + last_val = file->flavor[0]; + last_addr = 0; + addr = 1; + while(addr < file->eoa) { + if(file->flavor[addr] != last_val) { + HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) flavor is %s\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), flavors[last_val]); + last_val = file->flavor[addr]; + last_addr = addr; } /* end if */ addr++; } /* end while */ - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]); + HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) flavor is %s\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), flavors[last_val]); } /* end if */ /* Free the logging information */ - if(file->fa.flags&H5FD_LOG_FILE_WRITE) - file->nwrite=H5MM_xfree(file->nwrite); - if(file->fa.flags&H5FD_LOG_FILE_READ) - file->nread=H5MM_xfree(file->nread); - if(file->fa.flags&H5FD_LOG_FLAVOR) - file->flavor=H5MM_xfree(file->flavor); - if(file->logfp!=stderr) + if(file->fa.flags & H5FD_LOG_FILE_WRITE) + file->nwrite = (unsigned char *)H5MM_xfree(file->nwrite); + if(file->fa.flags & H5FD_LOG_FILE_READ) + file->nread = (unsigned char *)H5MM_xfree(file->nread); + if(file->fa.flags & H5FD_LOG_FLAVOR) + file->flavor = (unsigned char *)H5MM_xfree(file->flavor); + if(file->logfp != stderr) fclose(file->logfp); } /* end if */ @@ -720,7 +722,7 @@ H5FD_log_close(H5FD_t *_file) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5FD_log_close() */ /*------------------------------------------------------------------------- @@ -800,22 +802,20 @@ done: static herr_t H5FD_log_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */) { - herr_t ret_value=SUCCEED; - - FUNC_ENTER_NOAPI(H5FD_log_query, FAIL) + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_query) /* Set the VFL feature flags that this driver supports */ if(flags) { *flags = 0; - *flags|=H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */ - *flags|=H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */ - *flags|=H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */ - *flags|=H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */ - } + *flags |= H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */ + *flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */ + *flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */ + *flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */ + *flags |= H5FD_FEAT_POSIX_COMPAT_HANDLE; /* VFD handle is POSIX I/O call compatible */ + } /* end if */ -done: - FUNC_LEAVE_NOAPI(ret_value) -} + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FD_log_query() */ /*------------------------------------------------------------------------- @@ -1303,30 +1303,27 @@ done: /*------------------------------------------------------------------------- - * Function: H5FD_log_flush + * Function: H5FD_log_truncate * * Purpose: Makes sure that the true file size is the same (or larger) * than the end-of-address. * * Return: Success: Non-negative - * * Failure: Negative * * Programmer: Robb Matzke * Wednesday, August 4, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ static herr_t -H5FD_log_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) +H5FD_log_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) { H5FD_log_t *file = (H5FD_log_t*)_file; herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI(H5FD_log_flush, FAIL) + FUNC_ENTER_NOAPI(H5FD_log_truncate, FAIL) if(file->eoa>file->eof) { if(-1 == file_seek(file->fd, (file_offset_t)(file->eoa - 1), SEEK_SET)) @@ -1340,4 +1337,5 @@ H5FD_log_flush(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing) done: FUNC_LEAVE_NOAPI(ret_value) -} +} /* end H5FD_log_truncate() */ + |