[Ocfs2-test-devel] [PATCH 2/2] Ocfs2-test: Add semaphore to protect file_writes and log_writes.

Tao Ma tao.ma at oracle.com
Wed Dec 2 22:49:59 PST 2009



Tristan Ye wrote:
> File writes and log writes together should be finished like a transaction,
> we therefore use sem to guarantee the atomicity of such ops.
> 
> Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
> ---
>  programs/reflink_tests/reflink_test.c       |   33 ++++++++++++++-
>  programs/reflink_tests/reflink_test.h       |   15 +++++++
>  programs/reflink_tests/reflink_test_utils.c |   57 +++++++++++++++++++++++++++
>  3 files changed, 102 insertions(+), 3 deletions(-)
> 
> diff --git a/programs/reflink_tests/reflink_test.c b/programs/reflink_tests/reflink_test.c
> index 41bd544..a235382 100755
> --- a/programs/reflink_tests/reflink_test.c
> +++ b/programs/reflink_tests/reflink_test.c
> @@ -1807,6 +1807,23 @@ static int destructive_test(void)
>  
>  	pid_t pid;
>  
> +	int sem_id;
> +	key_t sem_key = IPC_PRIVATE;
> +
> +	/*get and init semaphore*/
> +	sem_id = semget(sem_key, 1, 0766 | IPC_CREAT);
> +	if (sem_id < 0) {
> +		sem_id = errno;
> +		fprintf(stderr, "semget failed, %s.\n", strerror(sem_id));
> +		return -1;
> +	}
> +
> +	ret = set_semvalue(sem_id);
> +	if (ret < 0) {
> +		fprintf(stderr, "Set semaphore value failed!\n");
> +		return ret;
> +	}
> +
>  	while (align_filesz < file_size)
>  		align_filesz += CHUNK_SIZE;
>  
> @@ -1884,24 +1901,31 @@ static int destructive_test(void)
>  					 dwu.d_timestamp, dwu.d_checksum,
>  					 dwu.d_char);
>  
> +				if (semaphore_p(sem_id) < 0)
> +					exit(-1);
>  				ret = do_write_chunk(fd, &dwu);
>  				if (ret)
>  					return -1;
if we add sem, here we may need to go to the semaphore_close below I 
guess? The same goes with other returns.

Regards,
Tao



More information about the Ocfs2-test-devel mailing list