From 28823cabacd175c09c80849e5b4468fd0a828a9f Mon Sep 17 00:00:00 2001 From: Ingo Huerner Date: Wed, 16 Jul 2014 09:48:04 +0200 Subject: [PATCH] Now files will be correctly handled (cached/non cached) --- src/persistence_client_library_backup_filelist.c | 18 ++- src/persistence_client_library_backup_filelist.h | 4 +- src/persistence_client_library_db_access.c | 1 + src/persistence_client_library_file.c | 151 +++++++++++++++++++---- src/persistence_client_library_handle.c | 28 ++++- src/persistence_client_library_handle.h | 24 ++++ test/data/PAS_data.tar.gz | Bin 5918 -> 5897 bytes test/persistence_client_library_test.c | 44 ++++--- 8 files changed, 217 insertions(+), 53 deletions(-) diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c index 7b596dc..0af204e 100644 --- a/src/persistence_client_library_backup_filelist.c +++ b/src/persistence_client_library_backup_filelist.c @@ -317,7 +317,7 @@ static int pclBackupDoFileCopy(int srcFd, int dstFd) } -int pclCreateFile(const char* path) +int pclCreateFile(const char* path, int chached) { const char* delimiters = "/\n"; // search for blank and end of line char* tokenArray[24]; @@ -360,10 +360,20 @@ int pclCreateFile(const char* path) // finally create the file strncat(createPath, "/", DbPathMaxLen-1); strncat(createPath, tokenArray[i], DbPathMaxLen-1); + + + #if USE_FILECACHE - handle = pfcOpenFile(createPath, CreateFile); + if(chached == 0) + { + handle = open(createPath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + } + else + { + handle = pfcOpenFile(createPath, CreateFile); + } #else - handle = open(createPath, O_CREAT|O_RDWR |O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + handle = open(createPath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); #endif } else @@ -576,7 +586,7 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const char pathToCreate[DbPathMaxLen] = {0}; strncpy(pathToCreate, dstPath, DbPathMaxLen); - handle = pclCreateFile(pathToCreate); + handle = pclCreateFile(pathToCreate, 0); close(handle); // don't need the open file } diff --git a/src/persistence_client_library_backup_filelist.h b/src/persistence_client_library_backup_filelist.h index c940967..49d8a7c 100644 --- a/src/persistence_client_library_backup_filelist.h +++ b/src/persistence_client_library_backup_filelist.h @@ -38,10 +38,12 @@ int readBlacklistConfigFile(const char* filename); * @brief create the file * * @param path of the file to be created + * @param cached 1 if file should be cached, + * 0 if file should not be cached * * @return the handle to his file */ -int pclCreateFile(const char* path); +int pclCreateFile(const char* path, int chached); /** diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index cad0e5d..2bb6d58 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -482,6 +482,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID); } write_size = gPersCustomFuncs[idx].custom_plugin_set_data(pathKeyString, (char*)buffer, buffer_size); + //write_size = persComDbWriteKey(handleDB, key, (char*)buffer, buffer_size) ; if ((0 < write_size) && ((unsigned int)write_size == buffer_size)) /* Check return value and send notification if OK */ { diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index c2d20e7..f487d7c 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -92,7 +92,14 @@ int pclFileClose(int fd) } __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag #if USE_FILECACHE - rval = pfcCloseFile(fd); + if(get_file_cache_status(fd) == 1) + { + rval = pfcCloseFile(fd); + } + else + { + rval = close(fd); + } #else rval = close(fd); #endif @@ -114,14 +121,25 @@ int pclFileGetSize(int fd) if(gPclInitialized >= PCLinitialized) { + struct stat buf; #if USE_FILECACHE - size = pfcFileGetSize(fd); + if(get_file_cache_status(fd) == 1) + { + size = pfcFileGetSize(fd); + } + else + { + size = fstat(fd, &buf); + + if(size != -1) + { + size = buf.st_size; + } + } #else - struct stat buf; - size = fstat(fd, &buf); - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileGetSize fd: "), DLT_INT(fd)); + size = fstat(fd, &buf); if(size != -1) { @@ -169,6 +187,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n { int shared_DB = 0; int wantBackup = 1; + int cacheStatus = -1; PersistenceInfo_s dbContext; char dbKey[DbKeyMaxLen] = {0}; // database key @@ -185,7 +204,10 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n // get database context: database path and database key shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); - if(dbContext.configKey.type == PersistenceResourceType_file) // check if the resource is really a file + // + // check if the resource is marked as a file resource + // + if(dbContext.configKey.type == PersistenceResourceType_file) { // create backup path int length = 0; @@ -204,7 +226,10 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n snprintf(backupPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupPostfix); snprintf(csumPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupCsPostfix); - if(shared_DB >= 0) // check valid database context + // + // check valid database context + // + if(shared_DB >= 0) { int flags = pclGetPosixPermission(dbContext.configKey.permission); @@ -229,24 +254,44 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n } #if USE_FILECACHE - if(handle > 0) // when the file is open, close it and do a new open unde PFC control { close(handle); } - handle = pfcOpenFile(dbPath, DontCreateFile); + if(strstr(dbPath, WTPREFIX) != NULL) + { + // if it's a write through resource, add the O_SYNC and O_DIRECT flag to prevent caching + handle = open(dbPath, flags); + cacheStatus = 0; + } + else + { + handle = pfcOpenFile(dbPath, DontCreateFile); + cacheStatus = 1; + } + #else if(handle <= 0) // check if open is needed or already done in verifyConsistency { handle = open(dbPath, flags); + + if(strstr(dbPath, WTPREFIX) != NULL) + { + cacheStatus = 0; + } + else + { + cacheStatus = 1; + } } #endif - - if(handle == -1 && errno == ENOENT) // file does not exist, create file and folder + // + // file does not exist, create it and get default data + // + if(handle == -1 && errno == ENOENT) { - - if((handle = pclCreateFile(dbPath)) == -1) + if((handle = pclCreateFile(dbPath, cacheStatus)) == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => failed to create file: "), DLT_STRING(dbPath)); } @@ -257,6 +302,8 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileOpen: no default data available: "), DLT_STRING(resource_id)); } } + + set_file_cache_status(handle, cacheStatus); } if(dbContext.configKey.permission != PersistencePermission_ReadOnly) @@ -272,13 +319,16 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n handle = EPERS_MAXHANDLE; } } - } - else // requested resource is not in the RCT, so create resource as local/cached. + // + // requested resource is not in the RCT, so create resource as local/cached. + // + else { // assemble file string for local cached location snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); - handle = pclCreateFile(dbPath); + handle = pclCreateFile(dbPath, 1); + set_file_cache_status(handle, 1); if(handle != -1) { @@ -289,7 +339,11 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n } else { +#if USE_FILECACHE + pfcCloseFile(handle); +#else close(handle); +#endif handle = EPERS_MAXHANDLE; } } @@ -297,9 +351,9 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n } else { - handle = EPERS_RESOURCE_NO_FILE; + handle = EPERS_RESOURCE_NO_FILE; // resource is not marked as file in RCT } - } + } // initialized return handle; } @@ -310,11 +364,19 @@ int pclFileReadData(int fd, void * buffer, int buffer_size) { int readSize = EPERS_NOT_INITIALIZED; + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData fd: "), DLT_INT(fd)); if(gPclInitialized >= PCLinitialized) { #if USE_FILECACHE - readSize = pfcReadFile(fd, buffer, buffer_size); + if(get_file_cache_status(fd) == 1) + { + readSize = pfcReadFile(fd, buffer, buffer_size); + } + else + { + readSize = read(fd, buffer, buffer_size); + } #else readSize = read(fd, buffer, buffer_size); #endif @@ -384,7 +446,14 @@ int pclFileSeek(int fd, long int offset, int whence) if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { #if USE_FILECACHE - rval = pfcFileSeek(fd, offset, whence); + if(get_file_cache_status(fd) == 1) + { + rval = pfcFileSeek(fd, offset, whence); + } + else + { + rval = lseek(fd, offset, whence); + } #else rval = lseek(fd, offset, whence); #endif @@ -453,9 +522,24 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size) } #if USE_FILECACHE - size = pfcWriteFile(fd, buffer, buffer_size); + if(get_file_cache_status(fd) == 1) + { + size = pfcWriteFile(fd, buffer, buffer_size); + } + else + { + size = write(fd, buffer, buffer_size); + + if(fsync(fd) == -1) + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileWriteData: Failed to fsync ==>!"), DLT_STRING(strerror(errno))); + } #else size = write(fd, buffer, buffer_size); + if(get_file_cache_status(fd) == 1) + { + if(fsync(fd) == -1) + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileWriteData: Failed to fsync ==>!"), DLT_STRING(strerror(errno))); + } #endif } else @@ -510,7 +594,7 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int // file will be opened writable, so check about data consistency if( dbContext.configKey.permission != PersistencePermission_ReadOnly - && pclBackupNeeded( get_raw_string(dbPath)) == CREATE_BACKUP) + && pclBackupNeeded(get_raw_string(dbPath)) == CREATE_BACKUP) { snprintf(backupPath, DbPathMaxLen-1, "%s%s", dbPath, gBackupPostfix); snprintf(csumPath, DbPathMaxLen-1, "%s%s", dbPath, gBackupCsPostfix); @@ -547,9 +631,20 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int if(access(*path, F_OK) == -1) { - // file does not exist, create it. - int handle = 0; - if((handle = pclCreateFile(*path)) == -1) + int handle = 0, cacheStatus = -1; + if(strstr(dbPath, WTPREFIX) != NULL) + { + cacheStatus = 0; + } + else + { + cacheStatus = 1; + } + + handle = pclCreateFile(*path, cacheStatus); // file does not exist, create it. + set_file_cache_status(handle, cacheStatus); + + if(handle == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileCreatePath: error => failed to create file: "), DLT_STRING(*path)); } @@ -562,7 +657,6 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int close(handle); // don't need the open file } } - __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag set_ossfile_handle_data(handle, dbContext.configKey.permission, 0/*backupCreated*/, backupPath, csumPath, *path); @@ -581,7 +675,10 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int } } } - else // requested resource is not in the RCT, so create resource as local/cached. + // + // requested resource is not in the RCT, so create resource as local/cached. + // + else { // assemble file string for local cached location snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index aac4a71..60ea521 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -193,9 +193,10 @@ int set_file_handle_data(int idx, PersistencePermission_e permission, const char { strcpy(gFileHandleArray[idx].backupPath, backup); strcpy(gFileHandleArray[idx].csumPath, csumPath); - gFileHandleArray[idx].backupCreated = 0; // set to 0 by default + gFileHandleArray[idx].backupCreated = 0; // set to 0 by default gFileHandleArray[idx].permission = permission; - gFileHandleArray[idx].filePath = filePath; // check to do if this works + gFileHandleArray[idx].filePath = filePath; // check to do if this works + gFileHandleArray[idx].cacheStatus = -1; // set to -1 by default } pthread_mutex_unlock(&gFileHandleAccessMtx); } @@ -250,6 +251,29 @@ int get_file_backup_status(int idx) return gFileHandleArray[idx].backupCreated; } +void set_file_cache_status(int idx, int status) +{ + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + gFileHandleArray[idx].cacheStatus = status; + + pthread_mutex_unlock(&gFileHandleAccessMtx); + } +} + +int get_file_cache_status(int idx) +{ + int status = -1; + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + if(MaxPersHandle >= idx) + { + status = gFileHandleArray[idx].cacheStatus; + } + pthread_mutex_unlock(&gFileHandleAccessMtx); + } + return status; +} //---------------------------------------------------------- //---------------------------------------------------------- diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h index d4d1260..48ab055 100644 --- a/src/persistence_client_library_handle.h +++ b/src/persistence_client_library_handle.h @@ -45,6 +45,8 @@ typedef struct _PersistenceFileHandle_s PersistencePermission_e permission; /// flag to indicate if a backup has already been created int backupCreated; + /// flag to indicate if file must be cached + int cacheStatus; /// path to the backup file char backupPath[DbPathMaxLen]; /// path to the checksum file @@ -197,6 +199,28 @@ void set_file_backup_status(int idx, int status); */ int get_file_backup_status(int idx); + +/** + * @brief set the file cache status + * @attention "No index check will be done" + * + * @param idx the index + * @param status the cache status, 0 file must not be cached, + * 1 file must be cached + */ +void set_file_cache_status(int idx, int status); + + +/** + * @brief get the cache status of the file + * @attention "No index check will be done" + * + * @param idx the index + * + * @return 0 if file must not be cached, + * 1 if file must be cached + */ +int get_file_cache_status(int idx); //---------------------------------------------------------------- //---------------------------------------------------------------- diff --git a/test/data/PAS_data.tar.gz b/test/data/PAS_data.tar.gz index 6fc9000f1c8b2db25a51020d3769276ca60d706b..235ef1bbe47b904bb857509924263f5b8d3f842f 100644 GIT binary patch literal 5897 zcmZ{oS5%Zquz-;af@BauhKwRXk_6EK5y=^r%%CJiB*#VhB}hhA5Q#D%AUP)`4T$1O z4k7}QGYB~3Nq^tjb06;0?Wa1`)m2?}PM@y&5J~hDzh`zZBx%M!5{^9{yoO4-Q^qBLF_&95<)ZTEZ=eXEhd7_8oug*)Q6W%wB z7rOFEs^MeQ#X=>DsQT51$B)nTqnzIX(|!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hkb+R{#J2 diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index cb9cf21..e159491 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -644,7 +644,6 @@ START_TEST(test_DataFile) #if 1 writeBuffer = malloc(writeSize); - // fill buffer a sequence for(i = 0; i<(writeSize/8); i++) { @@ -672,6 +671,7 @@ START_TEST(test_DataFile) size = pclFileReadData(fd, buffer, READ_SIZE); + //printf("pclFileReadData:\n ist : \"%s\"\n soll: \"%s\" ==> ret: %d => fd: %d\n", buffer, refBuffer, size, fd); x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db"); x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf @@ -715,11 +715,11 @@ START_TEST(test_DataFile) // negative test size = pclFileGetSize(1024); - x_fail_unless(size == EPERS_NOKEYDATA, "Got size, but should not"); - + x_fail_unless(size < 0 , "Got size, but should not"); + /* ret = pclFileClose(fd); x_fail_unless(ret == 0, "Failed to close file"); - +*/ // test backup blacklist functionality fdArray[0] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 1, 1); @@ -960,19 +960,6 @@ START_TEST(test_DataHandle) ret = pclInitLibrary(gTheAppId, shutdownReg); x_fail_unless(ret <= 1, "Failed to init PCL"); #if 1 - // test file handles - handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1); - x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db"); - - ret = pclFileClose(handle1); - x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db"); - - ret = pclFileClose(1024); - x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!"); - - ret = pclFileClose(17); - x_fail_unless(ret == -1, "Could close file, but should not!!"); - // test multiple handles handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1); x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db"); @@ -986,22 +973,26 @@ START_TEST(test_DataHandle) handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1); x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db"); + memset(buffer, 0, READ_SIZE); ret = pclFileReadData(handleArray[0], buffer, READ_SIZE); x_fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!"); x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db", strlen("/user/1/seat/1/media/mediaDB_write_01.db")) == 0, "Buffer not correctly read => mediaDB_write_01.db"); + memset(buffer, 0, READ_SIZE); ret = pclFileReadData(handleArray[1], buffer, READ_SIZE); x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db", strlen("/user/1/seat/1/media/mediaDB_write_02.db")) == 0, "Buffer not correctly read => mediaDB_write_02.db"); + memset(buffer, 0, READ_SIZE); ret = pclFileReadData(handleArray[2], buffer, READ_SIZE); x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db", strlen("/user/1/seat/1/media/mediaDB_write_03.db")) == 0, "Buffer not correctly read => mediaDB_write_03.db"); + memset(buffer, 0, READ_SIZE); (void)pclFileReadData(handleArray[3], buffer, READ_SIZE); x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db", strlen("/user/1/seat/1/media/mediaDB_write_04.db")) @@ -1028,6 +1019,21 @@ START_TEST(test_DataHandle) ret = pclKeyHandleClose(1024); x_fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!"); + + + // test file handles + handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1); + x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db"); + + ret = pclFileClose(handle1); + x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db"); + + ret = pclFileClose(1024); + x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!"); + + ret = pclFileClose(19); + x_fail_unless(ret == -1, "Could close file, but should not!!"); + #endif pclDeinitLibrary(); } @@ -1279,7 +1285,7 @@ START_TEST(test_GetPath) int ret = 0; char* path = NULL; - const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db"; + const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db"; unsigned int pathSize = 0; unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; @@ -1410,7 +1416,7 @@ START_TEST(test_utf8_string) (void)pclInitLibrary(gTheAppId, shutdownReg); ret = pclKeyReadData(0xFF, "utf8String", 3, 2, buffer, READ_SIZE); - x_fail_unless(ret == strlen(utf8StringBuffer), "Wrong write size"); + x_fail_unless(ret == strlen(utf8StringBuffer), "Wrong read size"); x_fail_unless(strncmp((char*)buffer, utf8StringBuffer, ret-1) == 0, "Buffer not correctly read => 1"); size = pclKeyGetSize(0xFF, "utf8String", 3, 2); -- 2.7.4