1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

test: Use append for journal maintenance instead of rename.

This commit is contained in:
Petr Rockai 2014-06-28 11:15:13 +02:00
parent 23b5a006d4
commit b3caba849d
2 changed files with 22 additions and 18 deletions

View File

@ -61,9 +61,21 @@ struct Journal {
} }
typedef std::map< std::string, R > Status; typedef std::map< std::string, R > Status;
Status status; Status status, written;
std::string location_tmp, location; std::string location, list;
void append( std::string path ) {
std::ofstream of( path.c_str(), std::fstream::app );
Status::iterator writ;
for ( Status::iterator i = status.begin(); i != status.end(); ++i ) {
writ = written.find( i->first );
if ( writ == written.end() || writ->second != i->second )
of << i->first << " " << i->second << std::endl;
}
written = status;
of.close();
}
void write( std::string path ) { void write( std::string path ) {
std::ofstream of( path.c_str() ); std::ofstream of( path.c_str() );
@ -73,9 +85,10 @@ struct Journal {
} }
void sync() { void sync() {
write( location_tmp ); append( location );
fsync_name( location_tmp ); fsync_name( location );
rename( location_tmp.c_str(), location.c_str() ); write ( list );
fsync_name( list );
} }
void started( std::string n ) { void started( std::string n ) {
@ -122,20 +135,11 @@ struct Journal {
std::copy( It( ifs ), It(), std::inserter( status, status.begin() ) ); std::copy( It( ifs ), It(), std::inserter( status, status.begin() ) );
} }
void read() { void read() { read( location ); }
struct stat64 stat;
if ( ::stat64( location.c_str(), &stat ) == 0 )
read( location );
/* on CIFS, rename might fail halfway through, with journal
* already gone but journal.tmp not yet replacing it... in that
* case, pick up journal.tmp */
else if ( ::stat64( location_tmp.c_str(), &stat ) == 0 )
read( location_tmp );
}
Journal( std::string dir ) Journal( std::string dir )
: location( dir + "/journal" ), : location( dir + "/journal" ),
location_tmp( dir + "/journal.tmp" ) list( dir + "/list" )
{} {}
}; };

View File

@ -382,6 +382,8 @@ struct Main {
if ( options.cont ) if ( options.cont )
journal.read(); journal.read();
else
::unlink( journal.location.c_str() );
} }
void run() { void run() {
@ -406,8 +408,6 @@ struct Main {
} }
journal.banner(); journal.banner();
journal.write( options.outdir + "/list" );
fsync_name( options.outdir + "/list" );
if ( die || fatal_signal ) if ( die || fatal_signal )
exit( 1 ); exit( 1 );
} }