diff options
author | Michael Scherle | 2022-06-08 17:43:28 +0200 |
---|---|---|
committer | Michael Scherle | 2022-06-08 17:43:28 +0200 |
commit | f77ab1e515903d0dae61883c0ada4516cab727ff (patch) | |
tree | f4f47d6ffbbeaf8de5d10fd5b4d849001ab34b6a | |
parent | fixed multiple compiler warnings (diff) | |
download | dnbd3-f77ab1e515903d0dae61883c0ada4516cab727ff.tar.gz dnbd3-f77ab1e515903d0dae61883c0ada4516cab727ff.tar.xz dnbd3-f77ab1e515903d0dae61883c0ada4516cab727ff.zip |
struct padding and type changes
-rw-r--r-- | src/cowtest/main.c | 20 | ||||
-rw-r--r-- | src/fuse/connection.c | 6 | ||||
-rw-r--r-- | src/fuse/cowfile.c | 11 | ||||
-rw-r--r-- | src/fuse/cowfile.h | 26 | ||||
-rw-r--r-- | src/fuse/main.h | 1 |
5 files changed, 36 insertions, 28 deletions
diff --git a/src/cowtest/main.c b/src/cowtest/main.c index 80620b4..c2c8643 100644 --- a/src/cowtest/main.c +++ b/src/cowtest/main.c @@ -61,9 +61,9 @@ void generateTestFile( char *path, size_t size ) void printUsage() { - printf( "Press the follwing for: \n" ); + printf( "Press the following for: \n" ); printf( " c <path> Creates test file at the path. \n" ); - printf( " t <path> Runs the standart test procedure. \n" ); + printf( " t <path> Runs the standard test procedure. \n" ); printf( " v <path> verifies a file. \n" ); } @@ -341,7 +341,7 @@ bool fileSizeChanges() return false; } // verify - printf( "truncate done, verifing...\n" ); + printf( "truncate done, verifying...\n" ); stat( filePath, &st ); size = st.st_size; if ( size != testFileSize ) { @@ -356,11 +356,11 @@ bool fileSizeChanges() perror( "fileSizeChanges test Failed: second increase failed." ); return false; } - printf( "truncate done, verifing...\n" ); + printf( "truncate done, verifying...\n" ); stat( filePath, &st ); size = st.st_size; if ( size != ( testFileSize + 2 * l2Capacity ) ) { - printf( "fileSizeChanges test Failed, increse not worked.\n expectedSize: %zu\n got: %zu\n", testFileSize, size ); + printf( "fileSizeChanges test Failed, increase not worked.\n expectedSize: %zu\n got: %zu\n", testFileSize, size ); return false; } printf( "size verified\n" ); @@ -554,7 +554,7 @@ void execCommand( char command, char *parameters ) printUsage(); break; } - printf( "starting standart test\n" ); + printf( "starting standard test\n" ); runTest( parameters ); break; case 'v': @@ -562,7 +562,7 @@ void execCommand( char command, char *parameters ) printUsage(); break; } - printf( "verifing file \n" ); + printf( "verifying file \n" ); verifyFinalFile( parameters ); break; default: @@ -585,12 +585,12 @@ int main( int argc, char *argv[] ) /* - methode to generate test file. + method to generate test file. */ -/* Tests to impelment: +/* Tests to implement: 1. Read & Writes over block borders (l1, l2, metadata). -2. Parallel writes on different unchanged blocks.(test for race condition on cow file increse). +2. Parallel writes on different unchanged blocks.(test for race condition on cow file increase). 3. Test truncate file (smaller and lager). 4. Random read writes. 5. Read & Writes over data which is partially in cow file diff --git a/src/fuse/connection.c b/src/fuse/connection.c index 2619d96..3aa0e5c 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -419,8 +419,8 @@ static void* connection_receiveThreadMain( void *sockPtr ) } unlock_rw( &altLock ); } - if(useCow){ - cowFile_handleCallback( request ); + if( useCow ) { + cowfile_handleCallback( request ); } else { fuse_reply_buf( request->fuse_req, request->buffer, request->length ); @@ -726,7 +726,7 @@ static void probeAltServers() } // Success, reply to fuse if( useCow ) { - cowFile_handleCallback( request ); + cowfile_handleCallback( request ); } else { fuse_reply_buf( request->fuse_req, request->buffer, request->length ); diff --git a/src/fuse/cowfile.c b/src/fuse/cowfile.c index 8fe9e4c..d16b2fd 100644 --- a/src/fuse/cowfile.c +++ b/src/fuse/cowfile.c @@ -385,7 +385,7 @@ bool finishUpload( CURLM *cm, CURLMsg *msg ) } // everything went ok, update timeUploaded - curlUploadBlock->block->timeUploaded = (atomic_uint_fast32_t)time; + curlUploadBlock->block->timeUploaded = curlUploadBlock->time; blocksUploaded++; free( curlUploadBlock ); CLEANUP: @@ -439,8 +439,8 @@ bool uploaderLoop( bool lastLoop, CURLM *cm ) continue; } if ( block->timeUploaded < block->timeChanged ) { - uint32_t relativeTime = (uint32_t)( time( NULL ) - metadata->creationTime ); - if ( ( ( relativeTime - block->timeChanged ) > COW_MIN_UPLOAD_DELAY ) || lastLoop ) { + + if ( ( time( NULL ) - block->timeChanged > COW_MIN_UPLOAD_DELAY ) || lastLoop ) { do { if ( !MessageHandler( cm, &activeUploads, true ) ) { success = false; @@ -451,6 +451,7 @@ bool uploaderLoop( bool lastLoop, CURLM *cm ) b->blocknumber = ( l1Offset * COW_L2_SIZE + l2Offset ); b->fails = 0; b->position = 0; + b->time = time( NULL ); addUpload( cm, b ); if ( lastLoop ) { @@ -796,7 +797,7 @@ static void writeData( const char *buffer, ssize_t size, size_t netSize, cow_req setBitsInBitfield( block->bitfield, (int)( inBlockOffset / DNBD3_BLOCK_SIZE ), (int)( ( inBlockOffset + totalBytesWritten - 1 ) / DNBD3_BLOCK_SIZE ) ); - block->timeChanged = (atomic_uint_fast32_t)( time( NULL ) - metadata->creationTime ); + block->timeChanged = time( NULL ) ; } /** @@ -934,7 +935,7 @@ static void padBlockFromRemote( fuse_req_t req, off_t offset, cow_request_t *cow } } -void cowFile_handleCallback( dnbd3_async_t *request ) +void cowfile_handleCallback( dnbd3_async_t *request ) { cow_sub_request_t *sRequest = container_of( request, cow_sub_request_t, dRequest ); sRequest->callback( sRequest ); diff --git a/src/fuse/cowfile.h b/src/fuse/cowfile.h index 205a1b3..ef429fb 100644 --- a/src/fuse/cowfile.h +++ b/src/fuse/cowfile.h @@ -1,8 +1,6 @@ #ifndef _COWFILE_H_ #define _COWFILE_H_ -#include "connection.h" -#include "main.h" #include <stdint.h> #include <stdlib.h> #include <stdatomic.h> @@ -12,6 +10,8 @@ #include <pthread.h> #include <errno.h> #include <curl/curl.h> +#include "main.h" +#include "connection.h" #define COW_METADATA_STORAGE_CAPACITY ( COW_BITFIELD_SIZE * 8 * DNBD3_BLOCK_SIZE ) @@ -19,9 +19,12 @@ #define COW_L2_STORAGE_CAPACITY ( COW_L2_SIZE * COW_METADATA_STORAGE_CAPACITY ) #define container_of( ptr, type, member ) ( (type *)( (char *)( ptr ) - (char *)&( ( (type *)NULL )->member ) ) ) +_Static_assert( ATOMIC_INT_LOCK_FREE == 2, "ATOMIC INT not lock free"); +_Static_assert( ATOMIC_LONG_LOCK_FREE == 2, "ATOMIC LONG not lock free"); +_Static_assert( ATOMIC_LLONG_LOCK_FREE == 2, "ATOMIC LLONG not lock free"); -#define COW_METADATA_HEADER_SIZE 317 -typedef struct __attribute__( ( packed ) ) cowfile_metadata_header +#define COW_METADATA_HEADER_SIZE 320 +typedef struct cowfile_metadata_header { uint64_t magicValue; // 8byte atomic_uint_fast64_t imageSize; // 8byte @@ -35,19 +38,23 @@ typedef struct __attribute__( ( packed ) ) cowfile_metadata_header atomic_size_t dataFileSize; // 8byte uint64_t maxImageSize; // 8byte uint64_t creationTime; // 8byte - char uuid[37]; // 37byte + char uuid[40]; // 40byte char imageName[200]; // 200byte } cowfile_metadata_header_t; _Static_assert( sizeof( cowfile_metadata_header_t ) == COW_METADATA_HEADER_SIZE, "cowfile_metadata_header is messed up" ); +#define COW_METADATA_METADATA_SIZE 64 typedef struct cow_block_metadata { atomic_long offset; - atomic_uint_fast32_t timeChanged; - atomic_uint_fast32_t timeUploaded; + atomic_uint_least64_t timeChanged; + atomic_uint_least64_t timeUploaded; atomic_char bitfield[40]; } cow_block_metadata_t; +_Static_assert( + sizeof( cow_block_metadata_t ) == COW_METADATA_METADATA_SIZE, "cow_block_metadata_t is messed up" ); + typedef struct cow_request { @@ -84,15 +91,16 @@ typedef struct cow_curl_read_upload size_t position; long unsigned int blocknumber; int fails; + uint64_t time; } cow_curl_read_upload_t; typedef int32_t l1; typedef cow_block_metadata_t l2[COW_L2_SIZE]; -bool cowfile_init( char *path, const char *image_Name, uint16_t imageVersion, atomic_uint_fast64_t **imageSizePtr, char *serverAdress, +bool cowfile_init( char *path, const char *image_Name, uint16_t imageVersion, atomic_uint_fast64_t **imageSizePtr, char *serverAddress, int isForeground ); -bool cowfile_load( char *path, atomic_uint_fast64_t **imageSizePtr, char *serverAdress, int isForeground ); +bool cowfile_load( char *path, atomic_uint_fast64_t **imageSizePtr, char *serverAddress, int isForeground ); void cowfile_read( fuse_req_t req, size_t size, off_t offset ); diff --git a/src/fuse/main.h b/src/fuse/main.h index e2514bd..721f251 100644 --- a/src/fuse/main.h +++ b/src/fuse/main.h @@ -1,6 +1,5 @@ #ifndef _MAIN_H_ #define _MAIN_H_ - #include "cowfile.h" #include "connection.h" #include "helper.h" |