[pve-devel] [PATCH common 2/2] (maybe) fixes #1229: fix port reservation

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Feb 16 09:15:03 CET 2017


On Wed, Feb 15, 2017 at 05:09:38PM +0100, Dominik Csapak wrote:
> when reserving ports, we use lock_file to lock the
> reservation file, but then use file_set_content which
> writes a new file and renames it, making the lock invalid
> and different processes waiting for the lock get inconsistent
> data
> 
> instead we use a ".flock" file for the lock, so that we don't
> lose the lock when writing the reservation file

Seems we have a few files in /var/lock with the usual *.lck naming
convention. For consistency it would make sense to follow the same
pattern here as well.

> 
> this should fix the problem that sometimes multiple vms get the
> same vnc/spice port
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  src/PVE/Tools.pm | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
> index 82d598e..e4afa93 100644
> --- a/src/PVE/Tools.pm
> +++ b/src/PVE/Tools.pm
> @@ -799,7 +799,7 @@ sub next_unused_port {
>  	return $newport;
>      };
>  
> -    my $p = lock_file($filename, 10, $code);
> +    my $p = lock_file($filename.".flock", 10, $code);
>      die $@ if $@;
>  
>      die "unable to find free port (${range_start}-${range_end})\n" if !$p;
> -- 
> 2.1.4




More information about the pve-devel mailing list