[sheepdog] [PATCH] sheep: read journal head first in journal_recover

levin li levin108 at gmail.com
Thu Jul 5 08:18:10 CEST 2012


On 2012年07月05日 14:11, Liu Yuan wrote:
> On 07/05/2012 02:06 PM, levin li wrote:
>> From: levin li <xingke.lwp at taobao.com>
>>
>> Sheep doesn't read the journal head in journal_recover which
>> always leaves all the fields of journal head uninitialized,
>> so the target_path is something random.
>>
>> Signed-off-by: levin li <xingke.lwp at taobao.com>
>> ---
>>  sheep/journal.c |    6 ++++++
>>  1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/sheep/journal.c b/sheep/journal.c
>> index d082aa2..74384b2 100644
>> --- a/sheep/journal.c
>> +++ b/sheep/journal.c
>> @@ -257,6 +257,12 @@ int jrnl_recover(const char *jrnl_dir)
>>  			goto end_while_3;
>>  		}
>>  
>> +		ret = pread64(jd.fd, &jd.head, sizeof(jd.head), 0);
> 
> why not use xpread which handles short read? I think all pread64 should
> be changed into xpread
> 
> Thanks,
> Yuan

I think pread64 is OK for regular files, as the manual says only in
the following conditions the number of bytes read may be less than
the number of bytes requested:

1. The number of bytes left in the file is less than the requested length.
2. The read() was interrupted by a signal.
3. The file is a pipe or FIFO or special device and has fewer bytes than requested immediately available for reading.

thanks,

levin

>> +		if (ret != sizeof(jd.head)) {
>> +			eprintf("can't read journal head\n");
>> +			goto end_while_2;
>> +		}
>> +
>>  		ret = pread64(jd.fd, &end_mark, sizeof(end_mark),
>>  				sizeof(jd.head) + jd.head.size);
>>  		if (ret != sizeof(end_mark)) {
>>
> 
> 





More information about the sheepdog mailing list