From owner-svn-src-projects@FreeBSD.ORG Thu Jan 5 02:16:56 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 190421065670; Thu, 5 Jan 2012 02:16:56 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F05FD8FC12; Thu, 5 Jan 2012 02:16:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q052GtOw009955; Thu, 5 Jan 2012 02:16:55 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q052GtW6009952; Thu, 5 Jan 2012 02:16:55 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201201050216.q052GtW6009952@svn.freebsd.org> From: Rick Macklem Date: Thu, 5 Jan 2012 02:16:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r229553 - in projects/nfsv4.1-client/sys/fs: nfs nfsclient X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jan 2012 02:16:56 -0000 Author: rmacklem Date: Thu Jan 5 02:16:55 2012 New Revision: 229553 URL: http://svn.freebsd.org/changeset/base/229553 Log: Fix up "struct nfsclfldevinfo" and the inline functions that use it. Basically, redefine nfsdi_data[] as an array of "struct sockaddr_storage" to avoid alignment/packing issues. Modified: projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c Modified: projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h ============================================================================== --- projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h Thu Jan 5 02:05:15 2012 (r229552) +++ projects/nfsv4.1-client/sys/fs/nfs/nfsclstate.h Thu Jan 5 02:16:55 2012 (r229553) @@ -233,13 +233,12 @@ struct nfsclflayout { /* * Stores the NFSv4.1 Device Info. Malloc'd to the correct length to - * store the list of indices and list of network addresses. + * store the list of network addresses and list of indices. * nfsdi_data[] is allocated the following way: * - nfsdi_addrcnt * struct sockaddr_storage * - stripe indices, each stored as one byte, since there can be many * of them. (This implies a limit of 256 on nfsdi_addrcnt, since the - * indices select which address. It is defined as uint64_t to ensure proper - * alignment.) + * indices select which address.) */ struct nfsclfldevinfo { TAILQ_ENTRY(nfsclfldevinfo) nfsdi_list; @@ -247,21 +246,21 @@ struct nfsclfldevinfo { uint8_t nfsdi_deviceid[NFSX_V4DEVICEID]; struct nfsclclient *nfsdi_clp; uint16_t nfsdi_stripecnt; - uint64_t nfsdi_addrcnt; - uint8_t nfsdi_data[1]; + uint16_t nfsdi_addrcnt; + struct sockaddr_storage nfsdi_data[1]; }; /* These inline functions return values from nfsdi_data[]. */ /* * Return a pointer to the address at "pos". */ -static __inline void * +static __inline struct sockaddr_storage * nfsfldi_addr(struct nfsclfldevinfo *ndi, int pos) { - if (pos > ndi->nfsdi_addrcnt) + if (pos >= ndi->nfsdi_addrcnt) return (NULL); - return (&ndi->nfsdi_data[pos * sizeof(struct sockaddr_storage)]); + return (&ndi->nfsdi_data[pos]); } /* @@ -270,11 +269,13 @@ nfsfldi_addr(struct nfsclfldevinfo *ndi, static __inline int nfsfldi_stripeindex(struct nfsclfldevinfo *ndi, int pos) { + uint8_t *valp; - if (pos > ndi->nfsdi_stripecnt) + if (pos >= ndi->nfsdi_stripecnt) return (-1); - return ((int)ndi->nfsdi_data[pos + ndi->nfsdi_addrcnt * - sizeof(struct sockaddr_storage)]); + valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt]; + valp += pos; + return ((int)*valp); } /* @@ -283,25 +284,13 @@ nfsfldi_stripeindex(struct nfsclfldevinf static __inline void nfsfldi_setstripeindex(struct nfsclfldevinfo *ndi, int pos, uint8_t val) { + uint8_t *valp; - if (pos > ndi->nfsdi_stripecnt) + if (pos >= ndi->nfsdi_stripecnt) return; - ndi->nfsdi_data[pos + ndi->nfsdi_addrcnt * - sizeof(struct sockaddr_storage)] = val; -} - -/* - * Return a pointer to the address referred to by stripe index "pos". - */ -static __inline void * -nfsfldi_stripeaddr(struct nfsclfldevinfo *ndi, int pos) -{ - int i; - - i = nfsfldi_stripeindex(ndi, pos); - if (i < 0) - return (NULL); - return (nfsfldi_addr(ndi, i)); + valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt]; + valp += pos; + *valp = val; } /* Modified: projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c ============================================================================== --- projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c Thu Jan 5 02:05:15 2012 (r229552) +++ projects/nfsv4.1-client/sys/fs/nfsclient/nfs_clrpcops.c Thu Jan 5 02:16:55 2012 (r229553) @@ -4652,8 +4652,9 @@ nfsrpc_getdeviceinfo(struct nfsmount *nm * Now we know how many stripe indices and addresses, so * we can allocate the structure the correct size. */ - ndi = malloc(sizeof(*ndi) + addrcnt * - sizeof(struct sockaddr_storage) + stripecnt - 1, + i = stripecnt / sizeof(struct sockaddr_storage) + 1; + ndi = malloc(sizeof(*ndi) + (addrcnt + i - 1) * + sizeof(struct sockaddr_storage), M_NFSDEVINFO, M_WAITOK); NFSBCOPY(deviceid, ndi->nfsdi_deviceid, NFSX_V4DEVICEID); ndi->nfsdi_stripecnt = stripecnt;