Medium: exportfs: Use canonical hostname for monitor op #1225
+9
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
If the hostname specified in
clientspec
does not match the canonicalhostname, the monitor operation fails even though the export exists.
This is caused by the exportfs command's name resolution process. It
queries the hosts DB as configured in /etc/nsswitch.conf (usually
/etc/hosts and/or DNS) to ensure that the given hostname resolves.
If the lookup returns the FQDN and the clientspec uses the short name,
the monitor operation fails. This also occurs in reverse. If the lookup
returns the short name and the clientspec uses the FQDN, the monitor
operation fails.
Reproducer
For example:
ocf:heartbeat:exportfs
resource using the short name in theclientspec
attribute.Resolution
This patch resolves the issue by querying the ahosts database to fetch
the canonical hostname. We use the canonical hostname as the spec. If
the clientspec is an IP address, the fetch simply returns the same IP
address. If the clientspec is of some other format, the fetch returns
nothing and we continue to use the spec as-is.
Using
getent ahosts
rather thangetent hosts
eliminates the need tohandle IP addresses specially, thanks to its output formatting. It uses
getaddrinfo
rather thangethostbyname2
.Notes
I added the
NF == 3
awk filter to match only lines that included a canonical name/address, which will be in the third field. I exited after the first match in case there are multiple. In my testing, the line with the canonical name/address was always the first line, and there was never more than one match. So this may not be necessary. Better safe than sorry.I added the
'$NF != "localhost"'
awk filter because of an edge case. An otherwise unrecognized hostname ending in".localdomain"
matches against the localhost record.This broke monitoring for clientspecs with wildcard characters in my testing.