From patchwork Tue Jun 7 23:34:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haynes X-Patchwork-Id: 9162847 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 181AC60832 for ; Tue, 7 Jun 2016 23:35:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0901328361 for ; Tue, 7 Jun 2016 23:35:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F19F92836E; Tue, 7 Jun 2016 23:35:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55B0C2836D for ; Tue, 7 Jun 2016 23:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476AbcFGXfU (ORCPT ); Tue, 7 Jun 2016 19:35:20 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34371 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753474AbcFGXfT (ORCPT ); Tue, 7 Jun 2016 19:35:19 -0400 Received: by mail-pf0-f175.google.com with SMTP id 62so82344970pfd.1 for ; Tue, 07 Jun 2016 16:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=primarydata-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jt1zAYnh69Aw7ebkkTZbHX2EVOpipyiiLJQ5cle/9tU=; b=UUJQxP5knm7xzG+pzV/GJLqZe1N/T1vk+1zNg5MKJAM0ypujki4aQ8n+PD4FD2qsik 2L3kgMUu3pcN188sYWHVVmzlgbOAkYfxyYdZ9dwoVM9S1n26QMRRrftDuDrALTRVQNmQ 9xBEVVoQjUrLUD+w0h9wvUprQzq5CayXxiRmXMlB7LJCBTYYy9mtmWUZmxbVXp3SDtyf TSH0AnDM4eY2+FnV2jueFbjRwAIbrTxPXC+0Bjslh/Q09bChZOj8xUrv5C30lzSl6qhg HI5AFtVT6BDA6m1R+9ST5p+ZtM2eYKrJ3ZHZDw6vZMPf1KReOPkfsxkh+bWYx/qLAL2i Y03g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jt1zAYnh69Aw7ebkkTZbHX2EVOpipyiiLJQ5cle/9tU=; b=TirvqbMt85w5L+dB+BywunNORqVtayCrGhWojDERjtiI/LeAEEB0f6xA18H5yY/R7h BAWp+OYg1Zq9zmuTXHNC331zGB1PSMNi1h9Y0wgeGwcP20evYkGAdWTiEjVDRif759rQ eZwKBleGlfPRo0/pfwTwGqT3oOiZJMLetKCzpmNK8/UFTnY0O5a4WjSVnMJx5DybBwIb pREuBSOLmdUCnCSMfvnwLX0CsiliZmCZnFiYh9fF2icmg6boLE5sBg/txCjVhUcS61fx BVd2AqYmUH1MobOy5QopJfE/D6SHyWLw6h39sQF0i7TQB0rsAK8hQ/faCvFd2pcP8wce F0bQ== X-Gm-Message-State: ALyK8tLD/PbndZ73fUsS23j4d/TesJ6o3o8jMXS8W47fc93ZqQg0m5uEGxc/TRrnJ2eyfKuY X-Received: by 10.98.204.5 with SMTP id a5mr2108273pfg.37.1465342517717; Tue, 07 Jun 2016 16:35:17 -0700 (PDT) Received: from twank.internal.excfb.com.localdomain (c-50-131-226-197.hsd1.ca.comcast.net. [50.131.226.197]) by smtp.gmail.com with ESMTPSA id u65sm37793013pfa.9.2016.06.07.16.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jun 2016 16:35:17 -0700 (PDT) From: Tom Haynes X-Google-Original-From: Tom Haynes To: Trond Myklebust , Anna Schumaker , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [RFC 1/2] nfs: Encoding a netaddr is common to client and server Date: Tue, 7 Jun 2016 16:34:45 -0700 Message-Id: <1465342486-21750-2-git-send-email-loghyr@primarydata.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465342486-21750-1-git-send-email-loghyr@primarydata.com> References: <1465342486-21750-1-git-send-email-loghyr@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Tom Haynes --- fs/nfs/flexfilelayout/flexfilelayout.c | 93 +------------------------------- fs/nfs/flexfilelayout/flexfilelayout.h | 5 +- include/linux/nfs4_ff.h | 96 ++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 95 deletions(-) create mode 100644 include/linux/nfs4_ff.h diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 0e8018b..1973aea 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -2024,96 +2025,6 @@ ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo, dprintk("%s: Return\n", __func__); } -static int -ff_layout_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen) -{ - const struct sockaddr_in *sin = (struct sockaddr_in *)sap; - - return snprintf(buf, buflen, "%pI4", &sin->sin_addr); -} - -static size_t -ff_layout_ntop6_noscopeid(const struct sockaddr *sap, char *buf, - const int buflen) -{ - const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; - const struct in6_addr *addr = &sin6->sin6_addr; - - /* - * RFC 4291, Section 2.2.2 - * - * Shorthanded ANY address - */ - if (ipv6_addr_any(addr)) - return snprintf(buf, buflen, "::"); - - /* - * RFC 4291, Section 2.2.2 - * - * Shorthanded loopback address - */ - if (ipv6_addr_loopback(addr)) - return snprintf(buf, buflen, "::1"); - - /* - * RFC 4291, Section 2.2.3 - * - * Special presentation address format for mapped v4 - * addresses. - */ - if (ipv6_addr_v4mapped(addr)) - return snprintf(buf, buflen, "::ffff:%pI4", - &addr->s6_addr32[3]); - - /* - * RFC 4291, Section 2.2.1 - */ - return snprintf(buf, buflen, "%pI6c", addr); -} - -/* Derived from rpc_sockaddr2uaddr */ -static void -ff_layout_encode_netaddr(struct xdr_stream *xdr, struct nfs4_pnfs_ds_addr *da) -{ - struct sockaddr *sap = (struct sockaddr *)&da->da_addr; - char portbuf[RPCBIND_MAXUADDRPLEN]; - char addrbuf[RPCBIND_MAXUADDRLEN]; - char *netid; - unsigned short port; - int len, netid_len; - __be32 *p; - - switch (sap->sa_family) { - case AF_INET: - if (ff_layout_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0) - return; - port = ntohs(((struct sockaddr_in *)sap)->sin_port); - netid = "tcp"; - netid_len = 3; - break; - case AF_INET6: - if (ff_layout_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0) - return; - port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); - netid = "tcp6"; - netid_len = 4; - break; - default: - /* we only support tcp and tcp6 */ - WARN_ON_ONCE(1); - return; - } - - snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff); - len = strlcat(addrbuf, portbuf, sizeof(addrbuf)); - - p = xdr_reserve_space(xdr, 4 + netid_len); - xdr_encode_opaque(p, netid, netid_len); - - p = xdr_reserve_space(xdr, 4 + len); - xdr_encode_opaque(p, addrbuf, len); -} - static void ff_layout_encode_nfstime(struct xdr_stream *xdr, ktime_t t) @@ -2160,7 +2071,7 @@ ff_layout_encode_layoutstats(struct xdr_stream *xdr, /* layoutupdate length */ start = xdr_reserve_space(xdr, 4); /* netaddr4 */ - ff_layout_encode_netaddr(xdr, da); + nfs4_encode_netaddr(xdr, (struct sockaddr *)&da->da_addr); /* nfs_fh4 */ p = xdr_reserve_space(xdr, 4 + fh->size); xdr_encode_opaque(p, fh->data, fh->size); diff --git a/fs/nfs/flexfilelayout/flexfilelayout.h b/fs/nfs/flexfilelayout/flexfilelayout.h index 1bcdb15..d71998e 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.h +++ b/fs/nfs/flexfilelayout/flexfilelayout.h @@ -9,10 +9,7 @@ #ifndef FS_NFS_NFS4FLEXFILELAYOUT_H #define FS_NFS_NFS4FLEXFILELAYOUT_H -#define FF_FLAGS_NO_LAYOUTCOMMIT 1 -#define FF_FLAGS_NO_IO_THRU_MDS 2 -#define FF_FLAGS_NO_READ_IO 4 - +#include #include "../pnfs.h" /* XXX: Let's filter out insanely large mirror count for now to avoid oom diff --git a/include/linux/nfs4_ff.h b/include/linux/nfs4_ff.h new file mode 100644 index 0000000..869eb1a --- /dev/null +++ b/include/linux/nfs4_ff.h @@ -0,0 +1,96 @@ +#ifndef _LINUX_NFS4_FF_H +#define _LINUX_NFS4_FF_H + +/* Flex file layout hints on I/O */ +#define FF_FLAGS_NO_LAYOUTCOMMIT 1 +#define FF_FLAGS_NO_IO_THRU_MDS 2 +#define FF_FLAGS_NO_READ_IO 4 + +static inline size_t +nfs4_ntop6_noscopeid(const struct sockaddr *sap, char *buf, const int buflen) +{ + const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; + const struct in6_addr *addr = &sin6->sin6_addr; + + /* + * RFC 4291, Section 2.2.2 + * + * Shorthanded ANY address + */ + if (ipv6_addr_any(addr)) + return snprintf(buf, buflen, "::"); + + /* + * RFC 4291, Section 2.2.2 + * + * Shorthanded loopback address + */ + if (ipv6_addr_loopback(addr)) + return snprintf(buf, buflen, "::1"); + + /* + * RFC 4291, Section 2.2.3 + * + * Special presentation address format for mapped v4 + * addresses. + */ + if (ipv6_addr_v4mapped(addr)) + return snprintf(buf, buflen, "::ffff:%pI4", + &addr->s6_addr32[3]); + + /* + * RFC 4291, Section 2.2.1 + */ + return snprintf(buf, buflen, "%pI6c", addr); +} + +static inline int +nfs4_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen) +{ + const struct sockaddr_in *sin = (struct sockaddr_in *)sap; + + return snprintf(buf, buflen, "%pI4", &sin->sin_addr); +} + +/* Derived from rpc_sockaddr2uaddr */ +static inline void +nfs4_encode_netaddr(struct xdr_stream *xdr, struct sockaddr *sap) +{ + char portbuf[RPCBIND_MAXUADDRPLEN]; + char addrbuf[RPCBIND_MAXUADDRLEN]; + char *netid; + unsigned short port; + int len, netid_len; + __be32 *p; + + switch (sap->sa_family) { + case AF_INET: + if (nfs4_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0) + return; + port = ntohs(((struct sockaddr_in *)sap)->sin_port); + netid = "tcp"; + netid_len = 3; + break; + case AF_INET6: + if (nfs4_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0) + return; + port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); + netid = "tcp6"; + netid_len = 4; + break; + default: + /* we only support tcp and tcp6 */ + WARN_ON_ONCE(1); + return; + } + + snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff); + len = strlcat(addrbuf, portbuf, sizeof(addrbuf)); + + p = xdr_reserve_space(xdr, 4 + netid_len); + xdr_encode_opaque(p, netid, netid_len); + + p = xdr_reserve_space(xdr, 4 + len); + xdr_encode_opaque(p, addrbuf, len); +} +#endif