[Pacemaker] getnameinfo() vs uname()

Vladislav Bogdanov bubble at hoster-ok.com
Wed Aug 29 06:57:06 EDT 2012


29.08.2012 13:33, Andrew Beekhof wrote:
> On Wed, Aug 29, 2012 at 4:22 PM, Vladislav Bogdanov
> <bubble at hoster-ok.com> wrote:
>> Hi,
>>
>> It looks like pacemaker (current master)
> 
> "current master" changes quite rapidly, could you be specific?

c72f5ca

> 
>> does not always work nicely on
>> top of corosync2 if one doesn't have /etc/hosts with all cluster nodes
>> in it, where short form of name goes before the long one (so
>> gethostbyaddr() and getnameinfo() return the short one).
> 
> I noticed a different issue related to this, but I need to know
> exactly which version you had before I can answer properly.
> 
>> I tried to run
>> test cluster with stub /etc/hosts but fully functional name server, and
>> I see that pacemaker includes long nodenames (fqdn) into nodelist, while
>> expecting them to be equal to what uname() returns for the local node.
>> After I created needed entries in /etc/hosts everything began to work.
>> From getaddrinfo manpage, NI_NOFQDN flag should help to avoid this
>> behavior. 

s/getaddrinfo/getnameinfo/

Actually it doesn't. At least not always.
Problem is that hostname (nodename) may be either fqdn (like anaconda
tries to set) or contain only host part. And getnameinfo() is not
consistent here (as in EL6), it strips domainname of a local system with
leading dot if local hostname is FQDN, but returns FQDN which
corresponds to address being searched if hostname is host-only.

So, I tried following patch and it works perfectly for me (hosnames are
host-only, and DNS is correctly configured, so hostname -f returns FQDN).

diff -urNp a/lib/cluster/corosync.c b/lib/cluster/corosync.c
--- a/lib/cluster/corosync.c    2012-08-29 07:32:57.000000000 +0000
+++ b/lib/cluster/corosync.c    2012-08-29 07:33:54.730099738 +0000
@@ -207,7 +207,15 @@ static char *corosync_node_name(cmap_han
                 addrlen = sizeof(struct sockaddr_in);
             }

-            if (getnameinfo((struct sockaddr *)addrs[0].address,
addrlen, buf, sizeof(buf), NULL, 0, 0) == 0) {
+            if (getnameinfo((struct sockaddr *)addrs[0].address,
addrlen, buf, sizeof(buf), NULL, 0, NI_NAMEREQD) == 0) {
+                char *p = buf;
+                while (*p) {
+                    if (*p == '.') {
+                        *p = '\0';
+                        break;
+                    }
+                    p++;
+                }
                 crm_notice("Inferred node name '%s' for nodeid %u from
DNS", buf, nodeid);

                 if(corosync_name_is_valid("DNS", buf)) {


Now I do not see FQDNs in nodelist.
Grrr, line wrapping...

>> Additionally, NI_NAMEREQD flag should probably be also used.

This one still applies. Otherwise getnameinfo can return string
representation of IP address if it cannot resolve it.

Btw, NI_MAXHOST should be used instead of INET6_ADDRSTRLEN for buf there.






More information about the Pacemaker mailing list