volume/local: Make host resolution backwards compatible

Commit 8ae94cafa5 added a DNS resolution
of the `device` part of the volume option.

The previous way to resolve the passed hostname was to use `addr`
option, which was handled by the same code path as the `nfs` mount type.

The issue is that `addr` is also an SMB module option handled by kernel
and passing a hostname as `addr` produces an invalid argument error.

To fix that, restore the old behavior to handle `addr` the same way as
before, and only perform the new DNS resolution of `device` if there is
no `addr` passed.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit 0d51cf9db8)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2024-01-23 12:32:09 +01:00
parent c7a1d928c0
commit ac76925ff2
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A

View file

@ -127,16 +127,20 @@ func (v *localVolume) mount() error {
mountDevice := v.opts.MountDevice
switch v.opts.MountType {
case "nfs":
case "nfs", "cifs":
if addrValue := getAddress(v.opts.MountOpts); addrValue != "" && net.ParseIP(addrValue).To4() == nil {
ipAddr, err := net.ResolveIPAddr("ip", addrValue)
if err != nil {
return errors.Wrapf(err, "error resolving passed in network volume address")
return errors.Wrap(err, "error resolving passed in network volume address")
}
mountOpts = strings.Replace(mountOpts, "addr="+addrValue, "addr="+ipAddr.String(), 1)
}
case "cifs":
deviceURL, err := url.Parse(v.opts.MountDevice)
if v.opts.MountType != "cifs" {
break
}
deviceURL, err := url.Parse(mountDevice)
if err != nil {
return errors.Wrapf(err, "error parsing mount device url")
}