From patchwork Tue Jun 7 23:34:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haynes X-Patchwork-Id: 9162849 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 8B78B60831 for ; Tue, 7 Jun 2016 23:35:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C71F28361 for ; Tue, 7 Jun 2016 23:35:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 716B22836E; Tue, 7 Jun 2016 23:35:34 +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 F017028361 for ; Tue, 7 Jun 2016 23:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753471AbcFGXf1 (ORCPT ); Tue, 7 Jun 2016 19:35:27 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35552 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753475AbcFGXfT (ORCPT ); Tue, 7 Jun 2016 19:35:19 -0400 Received: by mail-pf0-f182.google.com with SMTP id c2so9624628pfa.2 for ; Tue, 07 Jun 2016 16:35:19 -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=bYLeHpM6Misl8dltnWhMHLZ+TpsNc5Sp2hHlUvHWsUA=; b=W2RXQ/GEH+YQIEWV8/1tSrTtoKYIKNBXERfaB3Ytl15V1+INZZS6VKOFgzHWI25Sgs BHMSo5dHvYuZ8fHHiRn3xeJV/DIBchpNjkVr4l5SeZEzF2/h9PxHT+THHN9yg9P8bGs9 +hYo/gpZ992Zj5hYEWluFerGZLwff+sPfJvG1rZ/wje/PA85aXuwY+DcnkbH04C9WWUo dVtt6rHKwNmr8OG3R190iiqgY4pOsyV9aATsgiN6vGpLnqBAp+83ghpwvrMBgAFX8vb+ aGL2/7nsbU7ZANsyR0ilLRRnEJncxyoTcw//ZaJCVT26CZqIgZBMmiFeXpA4bigMSRVj XbyA== 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=bYLeHpM6Misl8dltnWhMHLZ+TpsNc5Sp2hHlUvHWsUA=; b=mWRoyIJLruokwMBTkMwzC9F2bOL4u/2bhXjdaS4OSAtnlNlYMuaL9NG1YIi30SXHBO wkNpCeeNvCtRv2kpQ3YSdzlVvxH9PFUYuBiIaXRrMobFuIYRC2WiwDQffu6+BbXnme3a DjRN3AVb5+zKHLAa5zgbvABGCjICrGQsS7ksvJ/RjuREOTblKTBwIK9WZTafHfM4CwTK nAx2aayaulCtgwCeVFSjvVpNIrBF9y4kiEL0hdSuUV4aT2jrUQ3VoM97ybQpoBZ7mGu6 ImOTKMVU7XuATy7Pz5zGvLCe3QxcaDk4BZ5alOABZJrT6z0IDIYi1EgcfHzEyDdD5Csx Bw/w== X-Gm-Message-State: ALyK8tK4/g0BZsHXNBtPt1+0JglD76yG/m+gy6a0dX/okGRyOi6SG+oWA1yXftSNfpDnytll X-Received: by 10.98.66.142 with SMTP id h14mr2135171pfd.11.1465342518584; Tue, 07 Jun 2016 16:35:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jun 2016 16:35:18 -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 2/2] nfsd: Encode a netaddr correctly Date: Tue, 7 Jun 2016 16:34:46 -0700 Message-Id: <1465342486-21750-3-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/nfsd/flexfilelayout.c | 26 ++------------------------ fs/nfsd/flexfilelayoutxdr.c | 34 ++++++++++++++-------------------- fs/nfsd/flexfilelayoutxdr.h | 15 +-------------- include/linux/nfs4_ff.h | 4 ++++ 4 files changed, 21 insertions(+), 58 deletions(-) diff --git a/fs/nfsd/flexfilelayout.c b/fs/nfsd/flexfilelayout.c index df880e9..9ba4d4f 100644 --- a/fs/nfsd/flexfilelayout.c +++ b/fs/nfsd/flexfilelayout.c @@ -11,6 +11,7 @@ #include #include +#include #include "flexfilelayoutxdr.h" #include "pnfs.h" @@ -81,9 +82,6 @@ nfsd4_ff_proc_getdeviceinfo(struct super_block *sb, struct svc_rqst *rqstp, { struct pnfs_ff_device_addr *da; - u16 port; - char addr[INET6_ADDRSTRLEN]; - da = kzalloc(sizeof(struct pnfs_ff_device_addr), GFP_KERNEL); if (!da) return nfserrno(-ENOMEM); @@ -96,27 +94,7 @@ nfsd4_ff_proc_getdeviceinfo(struct super_block *sb, struct svc_rqst *rqstp, da->rsize = svc_max_payload(rqstp); da->wsize = da->rsize; - rpc_ntop((struct sockaddr *)&rqstp->rq_daddr, - addr, INET6_ADDRSTRLEN); - if (rqstp->rq_daddr.ss_family == AF_INET) { - struct sockaddr_in *sin; - - sin = (struct sockaddr_in *)&rqstp->rq_daddr; - port = ntohs(sin->sin_port); - snprintf(da->netaddr.netid, FF_NETID_LEN + 1, "tcp"); - da->netaddr.netid_len = 3; - } else { - struct sockaddr_in6 *sin6; - - sin6 = (struct sockaddr_in6 *)&rqstp->rq_daddr; - port = ntohs(sin6->sin6_port); - snprintf(da->netaddr.netid, FF_NETID_LEN + 1, "tcp6"); - da->netaddr.netid_len = 4; - } - - da->netaddr.addr_len = - snprintf(da->netaddr.addr, FF_ADDR_LEN + 1, - "%s.%hhu.%hhu", addr, port >> 8, port & 0xff); + memcpy(&da->daddr, &rqstp->rq_daddr, rqstp->rq_daddrlen); da->tightly_coupled = false; diff --git a/fs/nfsd/flexfilelayoutxdr.c b/fs/nfsd/flexfilelayoutxdr.c index a241f29..83a1a56 100644 --- a/fs/nfsd/flexfilelayoutxdr.c +++ b/fs/nfsd/flexfilelayoutxdr.c @@ -3,6 +3,7 @@ */ #include #include +#include #include "nfsd.h" #include "flexfilelayoutxdr.h" @@ -79,37 +80,30 @@ nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr, struct nfsd4_getdeviceinfo *gdp) { struct pnfs_ff_device_addr *da = gdp->gd_device; - int len; - int ver_len; - int addr_len; - __be32 *p; - - /* len + padding for two strings */ - addr_len = 16 + da->netaddr.netid_len + da->netaddr.addr_len; - ver_len = 20; + __be32 *p, *start; - len = 4 + ver_len + 4 + addr_len; + start = xdr_reserve_space(xdr, 4); + if (!start) + return nfserr_resource; - p = xdr_reserve_space(xdr, len + sizeof(__be32)); + p = xdr_reserve_space(xdr, 4); if (!p) return nfserr_resource; - /* - * Fill in the overall length and number of volumes at the beginning - * of the layout. - */ - *p++ = cpu_to_be32(len); - *p++ = cpu_to_be32(1); /* 1 netaddr */ - p = xdr_encode_opaque(p, da->netaddr.netid, da->netaddr.netid_len); - p = xdr_encode_opaque(p, da->netaddr.addr, da->netaddr.addr_len); - - *p++ = cpu_to_be32(1); /* 1 versions */ + /* We only send 1 netaddr */ + *p++ = cpu_to_be32(1); + nfs4_encode_netaddr(xdr, (struct sockaddr *)&da->daddr); + /* We only send 1 version */ + p = xdr_reserve_space(xdr, 24); + *p++ = cpu_to_be32(1); *p++ = cpu_to_be32(da->version); *p++ = cpu_to_be32(da->minor_version); *p++ = cpu_to_be32(da->rsize); *p++ = cpu_to_be32(da->wsize); *p++ = cpu_to_be32(da->tightly_coupled); + *start = cpu_to_be32((xdr->p - start - 1) * 4); + return 0; } diff --git a/fs/nfsd/flexfilelayoutxdr.h b/fs/nfsd/flexfilelayoutxdr.h index 467defd..1fe2bb8 100644 --- a/fs/nfsd/flexfilelayoutxdr.h +++ b/fs/nfsd/flexfilelayoutxdr.h @@ -7,23 +7,10 @@ #include #include "xdr4.h" -#define FF_FLAGS_NO_LAYOUTCOMMIT 1 -#define FF_FLAGS_NO_IO_THRU_MDS 2 -#define FF_FLAGS_NO_READ_IO 4 - struct xdr_stream; -#define FF_NETID_LEN (4) -#define FF_ADDR_LEN (INET6_ADDRSTRLEN + 8) -struct pnfs_ff_netaddr { - char netid[FF_NETID_LEN + 1]; - char addr[FF_ADDR_LEN + 1]; - u32 netid_len; - u32 addr_len; -}; - struct pnfs_ff_device_addr { - struct pnfs_ff_netaddr netaddr; + struct sockaddr_storage daddr; u32 version; u32 minor_version; u32 rsize; diff --git a/include/linux/nfs4_ff.h b/include/linux/nfs4_ff.h index 869eb1a..634fbfa1 100644 --- a/include/linux/nfs4_ff.h +++ b/include/linux/nfs4_ff.h @@ -1,6 +1,10 @@ #ifndef _LINUX_NFS4_FF_H #define _LINUX_NFS4_FF_H +#include +#include +#include + /* Flex file layout hints on I/O */ #define FF_FLAGS_NO_LAYOUTCOMMIT 1 #define FF_FLAGS_NO_IO_THRU_MDS 2