Manage LVM locks
It's not possible de take 2 snapshot of the same LVM volume at the same time. This is a problem when using a single file system (backed by a single LVM volume) to store several VM as trying to run 2 backups at the same time will fail (at least, taking the snapshot for one will fail). Add locking before taking a snapshot and wait up to 10 sec for the lock to be released. This should fix concurrent backups
This commit is contained in:
parent
d715a0103e
commit
6d8dd735fa
30
virt-backup
30
virt-backup
|
@ -776,15 +776,33 @@ sub save_xml{
|
||||||
sub create_snapshot{
|
sub create_snapshot{
|
||||||
my ($blk,$suffix) = @_;
|
my ($blk,$suffix) = @_;
|
||||||
my $ret = 0;
|
my $ret = 0;
|
||||||
|
my $lock = $blk;
|
||||||
|
$lock =~ s/\//\-/g;
|
||||||
|
$lock = $opts{backupdir} . '/' . $lock . '.lock';
|
||||||
my $cmd = "$opts{lvcreate} -s -n " . $blk . $suffix .
|
my $cmd = "$opts{lvcreate} -s -n " . $blk . $suffix .
|
||||||
" -L $opts{snapsize} $blk > /dev/null 2>&1 < /dev/null\n";
|
" -L $opts{snapsize} $blk > /dev/null 2>&1 < /dev/null\n";
|
||||||
print "Running: $cmd" if $opts{debug};
|
for ($cnt = 0; $cnt < 10; $cnt++ ){
|
||||||
if ( system("$cmd") == 0 ) {
|
print "Running: $cmd" if $opts{debug};
|
||||||
$ret = 1;
|
if (-e "$lock" . '.lock'){
|
||||||
open SNAPLIST, ">>$backupdir.meta/snapshots" or die "Error, couldn't open snapshot list file\n";
|
print "Volume $blk is locked...\n" if $opts{debug};
|
||||||
print SNAPLIST $blk.$suffix ."\n";
|
sleep(1);
|
||||||
close SNAPLIST;
|
}
|
||||||
|
else{
|
||||||
|
open ( LOCK, ">$lock" );
|
||||||
|
print LOCK "";
|
||||||
|
close LOCK;
|
||||||
|
if ( system("$cmd") == 0 ) {
|
||||||
|
$ret = 1;
|
||||||
|
open SNAPLIST, ">>$backupdir.meta/snapshots" or die "Error, couldn't open snapshot list file\n";
|
||||||
|
print SNAPLIST $blk.$suffix ."\n";
|
||||||
|
close SNAPLIST;
|
||||||
|
# break the loop now
|
||||||
|
$cnt = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
# In any case, failed or not, remove our lock
|
||||||
|
unlink <$lock>;
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user