summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Scherle2022-06-20 07:53:15 +0200
committerMichael Scherle2022-06-20 07:53:15 +0200
commit7e85cf910154a90be752fd6eda1f4e1083b9f8d9 (patch)
treea8450b5fc5f384cb2e3d515aee46b0e267f9b6b5
parentAdded better stats (diff)
downloaddnbd3-7e85cf910154a90be752fd6eda1f4e1083b9f8d9.tar.gz
dnbd3-7e85cf910154a90be752fd6eda1f4e1083b9f8d9.tar.xz
dnbd3-7e85cf910154a90be752fd6eda1f4e1083b9f8d9.zip
fixed not waiting for statupdater thread
-rw-r--r--src/cowtest/main.c133
-rw-r--r--src/cowtest/readme.md9
-rw-r--r--src/fuse/cowfile.c7
3 files changed, 96 insertions, 53 deletions
diff --git a/src/cowtest/main.c b/src/cowtest/main.c
index 66980fa..7c27f0f 100644
--- a/src/cowtest/main.c
+++ b/src/cowtest/main.c
@@ -27,7 +27,7 @@ const size_t l2Capacity = l2Size * DNBD3_BLOCK_SIZE * bitfieldByteSize * 8;
const size_t testFileSize = l2Capacity * 2.9L;
-
+int delay = 0;
static char filePath[400];
static int fh = 0;
@@ -62,6 +62,7 @@ void generateTestFile( char *path, size_t size )
void printUsage()
{
printf( "Press the following for: \n" );
+ printf( " d <delay> Delay in Seconds for multiple block write (must be first).\n" );
printf( " c <path> Creates test file at the path. \n" );
printf( " t <path> Runs the standard test procedure. \n" );
printf( " v <path> verifies a file. \n" );
@@ -447,6 +448,47 @@ bool interleavedTest()
return verifyInterleavedTest();
}
+bool verifyMultipleWrites(){
+ size_t size = DNBD3_BLOCK_SIZE * 10 * bitfieldByteSize;
+ char buff[size];
+ char expected[size];
+ off_t offset = 100 * DNBD3_BLOCK_SIZE * bitfieldByteSize;
+ memset( expected, 3, size );
+ if ( !readSizeTested( fh, buff, size , offset, "multipleWrites test Failed: read to small" ) )
+ return false;
+ if ( !compare( buff, expected, size, "multipleWrites: read incorrect data" ) )
+ return false;
+ printf( "MultipleWrites successful!\n" );
+ return true;
+}
+
+bool multipleWrites(){
+ printf( "starting multipleWrites\n" );
+ size_t size = DNBD3_BLOCK_SIZE * 10 * bitfieldByteSize;
+ char buff[size];
+ char expected[size];
+ off_t offset = 100 * DNBD3_BLOCK_SIZE * bitfieldByteSize;
+
+ for (int i = 1; i <= 3; i++ ){
+ printf( "multipleWrites: %i/3 \n", i );
+
+ memset( expected, i, size );
+ if ( !writeSizeTested( fh, expected, size, offset, "multipleWrites: write Failed" ) )
+ return false;
+ if ( !readSizeTested( fh, buff, size, offset, "multipleWrites test Failed: read to small" ) )
+ return false;
+ if ( !compare( buff, expected, size, "multipleWrites: read incorrect data" ) )
+ return false;
+ if( delay > 0 && i < 3 ){
+ printf( "waiting %is\n", delay );
+ sleep(delay);
+ }
+ }
+ return verifyMultipleWrites();
+}
+
+
+
void runTest( char *path )
{
if ( ( fh = open( path, O_RDWR, S_IRUSR | S_IWUSR ) ) == -1 ) {
@@ -471,10 +513,14 @@ void runTest( char *path )
return;
if ( !interleavedTest() )
return;
+ if ( !multipleWrites() ){
+ return;
+ }
if ( !writeLongNonAlignedPattern() ) {
return;
}
+
printf( "All test's successful.\n" );
}
@@ -488,8 +534,9 @@ void verifyTests( verify_test_t *tests )
tests[2] = ( verify_test_t ){ DNBD3_BLOCK_SIZE * 11 - DNBD3_BLOCK_SIZE / 2, DNBD3_BLOCK_SIZE * 2,
verifyWriteNotOnBlockBorder };
tests[3] = ( verify_test_t ){ 35 * DNBD3_BLOCK_SIZE, DNBD3_BLOCK_SIZE * 10, verifyInterleavedTest };
- tests[4] = ( verify_test_t ){ l2Capacity * 2 - DNBD3_BLOCK_SIZE, DNBD3_BLOCK_SIZE * 2, verifyWriteOverL2 };
- tests[5] = ( verify_test_t ){ l2Capacity * 3 - 1, l2Capacity + 2, verifyLongNonAlignedPattern };
+ tests[4] = ( verify_test_t ){ 100 * DNBD3_BLOCK_SIZE * bitfieldByteSize, DNBD3_BLOCK_SIZE * 10 * bitfieldByteSize, verifyMultipleWrites };
+ tests[5] = ( verify_test_t ){ l2Capacity * 2 - DNBD3_BLOCK_SIZE, DNBD3_BLOCK_SIZE * 2, verifyWriteOverL2 };
+ tests[6] = ( verify_test_t ){ l2Capacity * 3 - 1, l2Capacity + 2, verifyLongNonAlignedPattern };
}
void verifyFinalFile( char *path )
@@ -519,7 +566,7 @@ void verifyFinalFile( char *path )
size_t offset = 0;
- int numberOfTests = 6;
+ int numberOfTests = 7;
verify_test_t tests[numberOfTests];
verifyTests( tests );
@@ -555,60 +602,44 @@ void verifyFinalFile( char *path )
printf( "file verified successful.\n" );
}
-void execCommand( char command, char *parameters )
-{
- switch ( command ) {
- case 'c':
- if ( parameters[0] == '\0' ) {
- printUsage();
- break;
- }
- generateTestFile( parameters, testFileSize );
- break;
- case 't':
- if ( parameters[0] == '\0' ) {
- printUsage();
- break;
- }
- printf( "starting standard test\n" );
- runTest( parameters );
- break;
- case 'v':
- if ( parameters[0] == '\0' ) {
- printUsage();
- break;
- }
- printf( "verifying file \n" );
- verifyFinalFile( parameters );
- break;
- default:
- printf( "Command not Found \n" );
- printUsage();
- break;
- }
-}
int main( int argc, char *argv[] )
{
- if ( argc == 3 ) {
- execCommand( argv[1][0], argv[2] );
- } else {
+ if ( argc < 1 ){
printUsage();
+ return 0;
}
+ while ( 1 )
+ {
+ int result = getopt( argc, argv, "d:c:t:v:" );
+ if ( result == -1 ) break; /* end of list */
+ char * pEnd;
+ switch (result)
+ {
+ case 'd':
+
+ delay =(int) strtol (optarg, &pEnd, 10);
+ printf("Delay set to %i\n", delay);
+ break;
+ case 'c':
+ generateTestFile( optarg, testFileSize );
+ break;
+ case 't':
+ printf( "starting standard test\n" );
+ runTest( optarg );
+ break;
+ case 'v':
+ printf( "verifying file \n" );
+ verifyFinalFile( optarg );
+ break;
+ default:
+ printUsage();
+ return 0;
+ break;
+ }
+ }
return 0;
}
-/*
- method to generate test file.
-*/
-/* 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 increase).
-3. Test truncate file (smaller and lager).
-4. Random read writes.
-5. Read & Writes over data which is partially in cow file
-6. Read & Write single byte
-*/ \ No newline at end of file
diff --git a/src/cowtest/readme.md b/src/cowtest/readme.md
index 16b0e50..b6286d1 100644
--- a/src/cowtest/readme.md
+++ b/src/cowtest/readme.md
@@ -72,6 +72,15 @@ Tests that continuous writes over L2 borders are possible.
| -------| -----|
|l2Capacity * 2 - DNBD3_BLOCK_SIZE | DNBD3_BLOCK_SIZE * 2 |
+
+### MultipleWrites
+Writes multiple times on the same Blocks different data. The separate writes can be delayed with the `-d` parameter. This is useful to test if uploading the same blocks multiple times works as intended.
+
+| offset | size |
+| -------| -----|
+| 100 * DNBD3_BLOCK_SIZE * bitfieldByteSize | DNBD3_BLOCK_SIZE * 10 * bitfieldByteSize |
+
+
### fileSizeChanges
Tests file size changes. First in increases the file size with a truncate by 2 * l2Capacity. It then checks that all the bits in the new allocated space are set to 0. Then it writes data to it to verify writes are possible. After that it truncates it back to the original size. Then it truncates it back to
the original size + 2 * l2Capacity and verifies that the again all bits in the new allocated space are 0 (so that the before written data is set to 0 again).
diff --git a/src/fuse/cowfile.c b/src/fuse/cowfile.c
index 04a5ea6..718de40 100644
--- a/src/fuse/cowfile.c
+++ b/src/fuse/cowfile.c
@@ -5,6 +5,7 @@ extern void image_ll_getattr( fuse_req_t req, fuse_ino_t ino, struct fuse_file_i
static int cowFileVersion = 1;
static int foreground;
static pthread_t tidCowUploader;
+static pthread_t tidStatUpdater;
static char *cowServerAddress;
static CURL *curl;
static cowfile_metadata_header_t *metadata = NULL;
@@ -711,7 +712,7 @@ bool cowfile_init( char *path, const char *image_Name, uint16_t imageVersion, at
createCowStatsFile( path );
pthread_create( &tidCowUploader, NULL, &cowfile_uploader, NULL );
- pthread_create( &tidCowUploader, NULL, &cowfile_statUpdater, NULL );
+ pthread_create( &tidStatUpdater, NULL, &cowfile_statUpdater, NULL );
return true;
}
/**
@@ -818,7 +819,7 @@ bool cowfile_load( char *path, atomic_uint_fast64_t **imageSizePtr, char *server
pthread_mutex_init( &cow.l2CreateLock, NULL );
createCowStatsFile( path );
pthread_create( &tidCowUploader, NULL, &cowfile_uploader, NULL );
- pthread_create( &tidCowUploader, NULL, &cowfile_statUpdater, NULL );
+ pthread_create( &tidStatUpdater, NULL, &cowfile_statUpdater, NULL );
return true;
@@ -1255,7 +1256,9 @@ fail:;
void cowfile_close()
{
uploadLoop = false;
+ pthread_join( tidStatUpdater, NULL );
pthread_join( tidCowUploader, NULL );
+
if ( curl ) {
curl_global_cleanup();
curl_easy_cleanup( curl );