From 5e23bd91449aea0883a492b74570f36c06a9e2ba Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 28 Apr 2017 11:11:38 +0800 Subject: [PATCH] bug fixed: file_offset has no effect when use trunk file --- HISTORY | 3 +++ storage/storage_dio.c | 60 +++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/HISTORY b/HISTORY index c5973dd..4b1ec44 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 5.11 2017-04-28 + * bug fixed: file_offset has no effect when use trunk file + Version 5.10 2017-03-29 * use fc_safe_read instead of read, and fc_safe_write instead of write you must upgrade libfastcommon to V1.35 or later diff --git a/storage/storage_dio.c b/storage/storage_dio.c index f8893b8..f34eda0 100644 --- a/storage/storage_dio.c +++ b/storage/storage_dio.c @@ -255,41 +255,39 @@ int dio_open_file(StorageFileContext *pFileContext) { int result; - if (pFileContext->fd >= 0) - { - return 0; - } - - pFileContext->fd = open(pFileContext->filename, - pFileContext->open_flags, 0644); if (pFileContext->fd < 0) - { - result = errno != 0 ? errno : EACCES; - logError("file: "__FILE__", line: %d, " \ - "open file: %s fail, " \ - "errno: %d, error info: %s", \ - __LINE__, pFileContext->filename, \ - result, STRERROR(result)); - } - else - { - result = 0; - } + { + pFileContext->fd = open(pFileContext->filename, + pFileContext->open_flags, 0644); + if (pFileContext->fd < 0) + { + result = errno != 0 ? errno : EACCES; + logError("file: "__FILE__", line: %d, " \ + "open file: %s fail, " \ + "errno: %d, error info: %s", \ + __LINE__, pFileContext->filename, \ + result, STRERROR(result)); + } + else + { + result = 0; + } - pthread_mutex_lock(&g_dio_thread_lock); - g_storage_stat.total_file_open_count++; - if (result == 0) - { - g_storage_stat.success_file_open_count++; - } - pthread_mutex_unlock(&g_dio_thread_lock); + pthread_mutex_lock(&g_dio_thread_lock); + g_storage_stat.total_file_open_count++; + if (result == 0) + { + g_storage_stat.success_file_open_count++; + } + pthread_mutex_unlock(&g_dio_thread_lock); - if (result != 0) - { - return result; - } + if (result != 0) + { + return result; + } + } - if (pFileContext->offset > 0 && lseek(pFileContext->fd, \ + if (pFileContext->offset > 0 && lseek(pFileContext->fd, pFileContext->offset, SEEK_SET) < 0) { result = errno != 0 ? errno : EIO;