Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796136586; b=QS25N0cWPnMc7//IePKX0ztwmu1E/vrX0TYNDTMGaR//t4FBcVTOjUnBBe2czGNlQTaK Cy6BHCOlGnhriS8LxkoZKtq7FsQLQEb2frL49Cbx1UMIyH9gnznm+U8/jXtcYt/Lu8hXy 5nxgWBrWJry7/YPPyU93tUAkqalOegfqhSAENkJULMfMiWLvrK3Mgkzt79i08ZACDHp10 nKUxWyoEOZCkokNVpSQsFTk1O2yN/JzWxss/nkIjDyr/PKmV8vSE5WgQsmo4RHBEIYbKu ByZwRTQB1T/ZIzRdJliG60xj+fKvwiP7FntQVKc7m5nNdtYEL8mGuflIcYWNQXov4fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796136586; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Received:From:To:Cc:Subject: Date:Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=Rzi67CFV+MLfF/VWM7DsMmyAGBcTn2q+U4MkS4qq9lY=; b=TX242GpkjsLMzrOBflVTBeacrF3H86fqkPfYMFuvOntLmpzfDy5KJPa9ago09KlC+/cj yoEBsED0EBZSdNcZRSH8eFEVoPQ43xqKZoqSr73jy3YmrBRU5tRQW7C7TKaUbVqsXk+WA BlK0RyyDr18k4bpcC1gj5qRaSUJXITQY+MFPyvL8J74TkldKkarGiIkInzhI8jcdDB1kr zySqwtTwMYUZdJsKVmjwNKyDsDP3EWMRz4ARQlnFjlI/8xZitELn8qpoK8y5BCza+ceFe +h7JvkyN9L06SCyFU38eLNDb//HLWm9ZE9QQGh+HpJDLHlB60Nf8qnqZvsbZNOdb5eQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OIbsRgW8; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCE19606A332 for ; Tue, 1 Dec 2026 14:49:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCE19606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OIbsRgW8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796136585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rzi67CFV+MLfF/VWM7DsMmyAGBcTn2q+U4MkS4qq9lY=; b=OIbsRgW8nh2oHXaAuS7YTBSz/SGPr9oLyMdetMNoHfXqSWX2FhLG73ZSpcBWvMkrG8op7v mhdEMqBpYA/TMxcWIAJvsndVU7FQIOF+2l/NTSRt1QuKDTJ16Qo192MXv6OxXdUbjNu4WB A3Z1Q54myRuvTPriRLjLQA3rGIZdTF4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-cWDzDO97OVewBfF6ehVbTg-1; Tue, 1 Dec 2026 14:49:40 +0000 X-MC-Unique: cWDzDO97OVewBfF6ehVbTg-1 X-Mimecast-MFC-AGG-ID: cWDzDO97OVewBfF6ehVbTg_1796136578 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 767961933FA6; Tue, 1 Dec 2026 14:49:38 +0000 (UTC) Received: from smayhew-thinkpadp1gen4i.remote.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5E6DA1955DA5; Tue, 1 Dec 2026 14:49:35 +0000 (UTC) Received: from smayhew-thinkpadp1gen4i.redhat.corp (localhost [IPv6:::1]) by smayhew-thinkpadp1gen4i.remote.csb (Postfix) with ESMTP id F0F855D1DBBE; Tue, 01 Dec 2026 09:49:30 -0500 (EST) From: Scott Mayhew To: steved@redhat.com Cc: jlayton@kernel.org, linux-nfs@vger.kernel.org Subject: [nfs-utils PATCH 2/6] Revert "sm-notify: use a separate socket per address family" Date: Tue, 1 Dec 2026 09:49:26 -0500 Message-ID: <20261201144930.369297-3-smayhew@redhat.com> In-Reply-To: <20261201144930.369297-1-smayhew@redhat.com> References: <20261201144930.369297-1-smayhew@redhat.com> X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 This reverts commit ba96fb357f748e8f301ca6a44f16ce5198bab284. This revert is necessary for the revert of 62ece1e9f935bf8d96d00d3bd0d35b02a4ed82ce which follows. Signed-off-by: Scott Mayhew --- utils/statd/sm-notify.c | 253 ++++++++++++++-------------------------- 1 file changed, 90 insertions(+), 163 deletions(-) diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c index 89e67c49..affaea28 100644 --- a/utils/statd/sm-notify.c +++ b/utils/statd/sm-notify.c @@ -68,26 +68,15 @@ struct nsm_host { static char nsm_hostname[SM_MAXSTRLEN + 1]; static int nsm_state; +static int nsm_family = AF_INET; static int opt_debug = 0; static _Bool opt_update_state = true; static unsigned int opt_max_retry = 15 * 60; static char * opt_srcaddr = NULL; static char * opt_srcport = NULL; -/* - * sm-notify uses one datagram socket per address family so that it can - * reach both IPv4 and IPv6 peers without relying on IPv4-mapped IPv6 - * addresses. Either descriptor may be -1 when that family is - * unavailable (eg. IPv6 is disabled, or a source address was requested - * for one family only). - */ -struct nsm_sockets { - int v4; - int v6; -}; - -static void notify(const struct nsm_sockets *socks); -static int notify_host(const struct nsm_sockets *, struct nsm_host *); +static void notify(const int sock); +static int notify_host(int, struct nsm_host *); static void recv_reply(int); static void insert_host(struct nsm_host *); static struct nsm_host *find_host(uint32_t); @@ -101,11 +90,7 @@ smn_lookup(const char *name) { struct addrinfo *ai = NULL; struct addrinfo hint = { -#ifdef IPV6_SUPPORTED - .ai_family = AF_UNSPEC, -#else /* !IPV6_SUPPORTED */ - .ai_family = AF_INET, -#endif /* !IPV6_SUPPORTED */ + .ai_family = (nsm_family == AF_INET ? AF_INET: AF_UNSPEC), .ai_protocol = (int)IPPROTO_UDP, }; int error; @@ -291,53 +276,78 @@ smn_get_host(const char *hostname, return 1; } -/* - * Create a non-blocking datagram socket of the given address family. - * - * Returns the socket descriptor, or -1 if the family is unavailable - * or an error occurs. - */ -static int -smn_socket(const int family) +#ifdef IPV6_SUPPORTED +static int smn_socket(void) { int sock; - sock = socket(family, SOCK_DGRAM, 0); + /* + * Use an AF_INET socket if IPv6 is disabled on the + * local system. + */ + sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock == -1) { - /* The family being unsupported is not an error: the - * caller simply won't use a socket for it. */ - if (errno == EAFNOSUPPORT) + if (errno != EAFNOSUPPORT) { + xlog(L_ERROR, "Failed to create RPC socket: %m"); return -1; - xlog(L_ERROR, "Failed to create RPC socket: %m"); - return -1; - } + } + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + xlog(L_ERROR, "Failed to create RPC socket: %m"); + return -1; + } + } else + nsm_family = AF_INET6; if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) { xlog(L_ERROR, "fcntl(3) on RPC socket failed: %m"); - (void)close(sock); - return -1; + goto out_close; } -#ifdef IPV6_SUPPORTED /* - * Keep the IPv6 socket strictly IPv6; the AF_INET socket is used - * to reach IPv4 peers. This avoids any dependence on IPv4-mapped - * IPv6 addresses, which are not usable on all configurations. + * TI-RPC over IPv6 (udp6/tcp6) does not handle IPv4. However, + * since sm-notify open-codes all of its RPC support, it can + * use a single socket and let the local network stack provide + * the correct mapping between address families automatically. + * This is the same thing that is done in the kernel. */ - if (family == AF_INET6) { - const int one = 1; + if (nsm_family == AF_INET6) { + const int zero = 0; + socklen_t zerolen = (socklen_t)sizeof(zero); if (setsockopt(sock, SOL_IPV6, IPV6_V6ONLY, - (char *)&one, (socklen_t)sizeof(one)) == -1) { + (char *)&zero, zerolen) == -1) { xlog(L_ERROR, "setsockopt(3) on RPC socket failed: %m"); - (void)close(sock); - return -1; + goto out_close; } } -#endif /* IPV6_SUPPORTED */ return sock; + +out_close: + (void)close(sock); + return -1; } +#else /* !IPV6_SUPPORTED */ +static int smn_socket(void) +{ + int sock; + + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock == -1) { + xlog(L_ERROR, "Failed to create RPC socket: %m"); + return -1; + } + + if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) { + xlog(L_ERROR, "fcntl(3) on RPC socket failed: %m"); + (void)close(sock); + return -1; + } + + return sock; +} +#endif /* !IPV6_SUPPORTED */ /* * If admin specified a source address or srcport, then convert those @@ -345,12 +355,12 @@ smn_socket(const int family) */ __attribute__((__malloc__)) static struct addrinfo * -smn_bind_address(const char *srcaddr, const char *srcport, const int family) +smn_bind_address(const char *srcaddr, const char *srcport) { struct addrinfo *ai = NULL; struct addrinfo hint = { - .ai_flags = AI_NUMERICSERV, - .ai_family = family, + .ai_flags = AI_NUMERICSERV | AI_V4MAPPED, + .ai_family = nsm_family, .ai_protocol = (int)IPPROTO_UDP, }; int error; @@ -364,17 +374,6 @@ smn_bind_address(const char *srcaddr, const char *srcport, const int family) else error = getaddrinfo(srcaddr, srcport, &hint, &ai); if (error != 0) { - /* - * When a specific source address was requested, it is normal - * for it to have no address in one of the families; that - * family is simply not served by this invocation. - */ - if (srcaddr != NULL) { - xlog(D_GENERAL, "No %s source address for '%s': %s", - family == AF_INET ? "IPv4" : "IPv6", - srcaddr, gai_strerror(error)); - return NULL; - } xlog(L_ERROR, "Invalid bind address or port for RPC socket: %s", gai_strerror(error)); @@ -411,17 +410,17 @@ smn_bindresvport(int sock, struct sockaddr *sap) * an error occurs. */ static int -smn_create_socket(const int family, const char *srcaddr, const char *srcport) +smn_create_socket(const char *srcaddr, const char *srcport) { int sock, retry_cnt = 0; struct addrinfo *ai; retry: - sock = smn_socket(family); + sock = smn_socket(); if (sock == -1) return -1; - ai = smn_bind_address(srcaddr, srcport, family); + ai = smn_bind_address(srcaddr, srcport); if (ai == NULL) { (void)close(sock); return -1; @@ -504,9 +503,8 @@ read_smnotify_conf(char **argv) int main(int argc, char **argv) { - int c; + int c, sock; char * progname; - struct nsm_sockets socks; progname = strrchr(argv[0], '/'); if (progname != NULL) @@ -612,21 +610,14 @@ usage: fprintf(stderr, close(2); } - socks.v4 = smn_create_socket(AF_INET, opt_srcaddr, opt_srcport); -#ifdef IPV6_SUPPORTED - socks.v6 = smn_create_socket(AF_INET6, opt_srcaddr, opt_srcport); -#else /* !IPV6_SUPPORTED */ - socks.v6 = -1; -#endif /* !IPV6_SUPPORTED */ - if (socks.v4 == -1 && socks.v6 == -1) { - xlog(L_ERROR, "Failed to create an RPC socket"); + sock = smn_create_socket(opt_srcaddr, opt_srcport); + if (sock == -1) exit(1); - } if (!nsm_drop_privileges(-1)) exit(1); - notify(&socks); + notify(sock); if (hosts) { struct nsm_host *hp; @@ -642,50 +633,11 @@ usage: fprintf(stderr, exit(0); } -/* - * Return the socket descriptor to use for the given address family, - * or -1 if no socket is available for it. - */ -static int -smn_sock_for_family(const struct nsm_sockets *socks, const int family) -{ - switch (family) { - case AF_INET: - return socks->v4; - case AF_INET6: - return socks->v6; - } - return -1; -} - -/* - * Move the first address on a host's list to the end, so the next - * attempt uses a different address. A no-op if there is only one. - */ -static void -smn_rotate_address(struct nsm_host *host) -{ - if (host->ai->ai_next != NULL) { - struct addrinfo *first = host->ai; - struct addrinfo **next; - - /* remove the first entry from the list */ - host->ai = first->ai_next; - first->ai_next = NULL; - /* find the end of the (new) list */ - next = &host->ai; - while ( *next ) - next = & (*next)->ai_next; - /* put first entry at end */ - *next = first; - } -} - /* * Notify hosts */ static void -notify(const struct nsm_sockets *socks) +notify(const int sock) { time_t failtime = 0; @@ -693,8 +645,7 @@ notify(const struct nsm_sockets *socks) failtime = time(NULL) + opt_max_retry; while (hosts) { - struct pollfd pfd[2]; - int nfds, i; + struct pollfd pfd; time_t now = time(NULL); unsigned int sent = 0; struct nsm_host *hp; @@ -712,7 +663,7 @@ notify(const struct nsm_sockets *socks) hp = hosts; hosts = hp->next; - if (notify_host(socks, hp)) + if (notify_host(sock, hp)) continue; /* Set the timeout for this call, using an @@ -731,27 +682,16 @@ notify(const struct nsm_sockets *socks) xlog(D_GENERAL, "Host %s due in %ld seconds", hosts->name, wait); - nfds = 0; - if (socks->v4 != -1) { - pfd[nfds].fd = socks->v4; - pfd[nfds].events = POLLIN; - nfds++; - } - if (socks->v6 != -1) { - pfd[nfds].fd = socks->v6; - pfd[nfds].events = POLLIN; - nfds++; - } + pfd.fd = sock; + pfd.events = POLLIN; wait *= 1000; if (wait < 100) wait = 100; - if (poll(pfd, (nfds_t)nfds, wait) <= 0) + if (poll(&pfd, 1, wait) != 1) continue; - for (i = 0; i < nfds; i++) - if (pfd[i].revents & POLLIN) - recv_reply(pfd[i].fd); + recv_reply(sock); } } @@ -759,13 +699,10 @@ notify(const struct nsm_sockets *socks) * Send notification to a single host */ static int -notify_host(const struct nsm_sockets *socks, struct nsm_host *host) +notify_host(int sock, struct nsm_host *host) { struct sockaddr *sap; socklen_t salen; - unsigned int naddr, tried; - struct addrinfo *a; - int sock; if (host->ai == NULL) { host->ai = smn_lookup(host->name); @@ -782,34 +719,24 @@ notify_host(const struct nsm_sockets *socks, struct nsm_host *host) * point. */ if (host->retries >= 4) { - smn_rotate_address(host); - nfs_set_port(host->ai->ai_addr, 0); - host->retries = 0; - } - - /* - * Select the socket matching the address family of the current - * address. If we have no socket for that family (eg. a source - * address was requested for the other family only), rotate through - * the remaining addresses looking for one we can send from. If - * none is usable, give up on this host, leaving its on-disk record - * so a later run can retry. - */ - naddr = 0; - for (a = host->ai; a != NULL; a = a->ai_next) - naddr++; - - for (tried = 0; ; tried++) { - sock = smn_sock_for_family(socks, host->ai->ai_addr->sa_family); - if (sock != -1) - break; - if (tried + 1 >= naddr) { - xlog_warn("No usable source address to notify %s; " - "giving up", host->name); - return 1; + /* don't rotate if there is only one addrinfo */ + if (host->ai->ai_next != NULL) { + struct addrinfo *first = host->ai; + struct addrinfo **next; + + /* remove the first entry from the list */ + host->ai = first->ai_next; + first->ai_next = NULL; + /* find the end of the (new) list */ + next = &host->ai; + while ( *next ) + next = & (*next)->ai_next; + /* put first entry at end */ + *next = first; } - smn_rotate_address(host); + nfs_set_port(host->ai->ai_addr, 0); + host->retries = 0; } sap = host->ai->ai_addr; -- 2.56.1