Skip to content

Commit

Permalink
Worked on multi-threading support.
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Nov 8, 2015
1 parent 347253d commit e509837
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TODO
* complete thread-safety in open functions
- libvmdk_handle_open_extent_data_files
* add thread-safety in
- extent_descriptor API functions?
* check TODO in libvmdk_handle_open_wide regardin UTF-16

* add support for the change tracking file?
Expand Down
12 changes: 9 additions & 3 deletions include/libvmdk.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ int libvmdk_handle_open(
libvmdk_error_t **error );

#if defined( LIBVMDK_HAVE_WIDE_CHARACTER_TYPE )

/* Opens a set of VMDK file(s)
* Returns 1 if successful or -1 on error
*/
Expand All @@ -231,9 +232,11 @@ int libvmdk_handle_open_wide(
const wchar_t *filename,
int access_flags,
libvmdk_error_t **error );
#endif

#endif /* defined( LIBVMDK_HAVE_WIDE_CHARACTER_TYPE ) */

#if defined( LIBVMDK_HAVE_BFIO )

/* Opens a set of VMDK file(s) using a Basic File IO (bfio) handle
* Returns 1 if successful or -1 on error
*/
Expand All @@ -243,7 +246,8 @@ int libvmdk_handle_open_file_io_handle(
libbfio_handle_t *file_io_handle,
int access_flags,
libvmdk_error_t **error );
#endif

#endif /* defined( LIBVMDK_HAVE_BFIO ) */

/* Opens the extent data files
* If the extent data filenames were not set explicitly this function assumes the extent data files
Expand All @@ -256,6 +260,7 @@ int libvmdk_handle_open_extent_data_files(
libvmdk_error_t **error );

#if defined( LIBVMDK_HAVE_BFIO )

/* Opens the extent data files using a Basic File IO (bfio) pool
* This function assumes the extent data files are in same order as defined by the descriptor file
* Returns 1 if successful or -1 on error
Expand All @@ -265,7 +270,8 @@ int libvmdk_handle_open_extent_data_files_file_io_pool(
libvmdk_handle_t *handle,
libbfio_pool_t *file_io_pool,
libvmdk_error_t **error );
#endif

#endif /* defined( LIBVMDK_HAVE_BFIO ) */

/* Closes the VMDK file(s)
* Returns 0 if successful or -1 on error
Expand Down
81 changes: 77 additions & 4 deletions libvmdk/libvmdk_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,21 @@ int libvmdk_handle_open_extent_data_files(

return( -1 );
}
#if defined( HAVE_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to grab read/write lock for writing.",
function );

return( -1 );
}
#endif
if( libvmdk_descriptor_file_get_number_of_extents(
internal_handle->descriptor_file,
&number_of_extents,
Expand Down Expand Up @@ -1380,23 +1395,38 @@ int libvmdk_handle_open_extent_data_files(
extent_data_file_location = NULL;
}
}
if( libvmdk_handle_open_extent_data_files_file_io_pool(
handle,
if( libvmdk_handle_open_read_grain_table(
internal_handle,
file_io_pool,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to open extent data files using a file IO pool.",
"%s: unable to read grain table.",
function );

goto on_error;
}
internal_handle->extent_data_file_io_pool = file_io_pool;
internal_handle->extent_data_file_io_pool_created_in_library = 1;

#if defined( HAVE_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to release read/write lock for writing.",
function );

return( -1 );
}
#endif
return( 1 );

on_error:
Expand All @@ -1415,6 +1445,11 @@ int libvmdk_handle_open_extent_data_files(
memory_free(
extent_data_file_location );
}
#if defined( HAVE_MULTI_THREAD_SUPPORT )
libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
NULL );
#endif
return( -1 );
}

Expand Down Expand Up @@ -1465,6 +1500,21 @@ int libvmdk_handle_open_extent_data_files_file_io_pool(

return( -1 );
}
#if defined( HAVE_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to grab read/write lock for writing.",
function );

return( -1 );
}
#endif
if( libvmdk_handle_open_read_grain_table(
internal_handle,
file_io_pool,
Expand All @@ -1477,11 +1527,34 @@ int libvmdk_handle_open_extent_data_files_file_io_pool(
"%s: unable to read grain table.",
function );

return( -1 );
goto on_error;
}
internal_handle->extent_data_file_io_pool = file_io_pool;

#if defined( HAVE_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to release read/write lock for writing.",
function );

return( -1 );
}
#endif
return( 1 );

on_error:
#if defined( HAVE_MULTI_THREAD_SUPPORT )
libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
NULL );
#endif
return( -1 );
}

/* Opens a specific extent data file
Expand Down
8 changes: 4 additions & 4 deletions tests/vmdk_test_libcthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/

#if !defined( _VHDI_TEST_LIBCTHREADS_H )
#define _VHDI_TEST_LIBCTHREADS_H
#if !defined( _VMDK_TEST_LIBCTHREADS_H )
#define _VMDK_TEST_LIBCTHREADS_H

#include <common.h>

#if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBVHDI )
#if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBVMDK )

/* Define HAVE_LOCAL_LIBCTHREADS for local use of libcthreads
*/
Expand Down Expand Up @@ -54,7 +54,7 @@

#endif

#endif /* defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBVHDI ) */
#endif /* defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBVMDK ) */

#endif

0 comments on commit e509837

Please sign in to comment.