From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jevon Qiao Subject: [PATCH 2/2] hw/9pfs: fix alignment issue when host filesystem block size is larger than client msize Date: Sun, 14 Feb 2016 15:35:43 +0800 Message-ID: <56C02E4F.6030303@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org To: qemu-devel@nongnu.org, "ceph-devel@vger.kernel.org" Cc: haomaiwang@gmail.com, mst@redhat.com, aneesh.kumar@linux.vnet.ibm.com, sage@newdream.net, gfarnum@redhat.com, gkurz@linux.vnet.ibm.com List-Id: ceph-devel.vger.kernel.org The following patch is to fix alignment issue when host filesystem block size is larger than client msize. Thanks, Jevon From: Jevon Qiao Date: Sun, 14 Feb 2016 15:11:08 +0800 Subject: [PATCH] hw/9pfs: fix alignment issue when host filesystem block size is larger than client msize. Per the previous implementation, iounit will be assigned to be 0 after the first if statement as (s->msize - P9_IOHDRSZ)/stbuf.f_bsize will be zero when host filesystem block size is larger than msize. Finally, iounit will be equal to s->msize - P9_IOHDRSZ, which is usually not aligned. Signed-off-by: Jevon Qiao --- hw/9pfs/virtio-9p.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index f972731..005d3a8 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -1326,7 +1326,7 @@ out_nofid: static int32_t get_iounit(V9fsPDU *pdu, V9fsPath *path) { struct statfs stbuf; - int32_t iounit = 0; + int32_t iounit = 0, unit = 0; V9fsState *s = pdu->s; /* @@ -1334,8 +1334,21 @@ static int32_t get_iounit(V9fsPDU *pdu, V9fsPath *path) * and as well as less than (client msize - P9_IOHDRSZ)) */ if (!v9fs_co_statfs(pdu, path, &stbuf)) { - iounit = stbuf.f_bsize; - iounit *= (s->msize - P9_IOHDRSZ)/stbuf.f_bsize; + /* + * If host filesystem block size is larger than client msize, + * we will use PAGESIZE as the unit. The reason why we choose + * PAGESIZE is because the data will be splitted in terms of + * PAGESIZE in the virtio layer. In this case, the final + * iounit is equal to the value of ((msize/unit) - 1) * unit. + */ + if (stbuf.f_bsize > s->msize) { + iounit = 4096; + unit = 4096; + } else { + iounit = stbuf.f_bsize; + unit = stbuf.f_bsize; + } + iounit *= (s->msize - P9_IOHDRSZ)/unit; } if (!iounit) { iounit = s->msize - P9_IOHDRSZ; -- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUrDx-0000NI-A8 for qemu-devel@nongnu.org; Sun, 14 Feb 2016 02:36:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUrDu-0001Pq-4G for qemu-devel@nongnu.org; Sun, 14 Feb 2016 02:36:05 -0500 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]:35922) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUrDt-0001Pm-Sr for qemu-devel@nongnu.org; Sun, 14 Feb 2016 02:36:02 -0500 Received: by mail-pa0-x241.google.com with SMTP id y7so962044paa.3 for ; Sat, 13 Feb 2016 23:36:01 -0800 (PST) From: Jevon Qiao Message-ID: <56C02E4F.6030303@gmail.com> Date: Sun, 14 Feb 2016 15:35:43 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 2/2] hw/9pfs: fix alignment issue when host filesystem block size is larger than client msize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, "ceph-devel@vger.kernel.org" Cc: haomaiwang@gmail.com, mst@redhat.com, aneesh.kumar@linux.vnet.ibm.com, sage@newdream.net, gfarnum@redhat.com, gkurz@linux.vnet.ibm.com The following patch is to fix alignment issue when host filesystem block size is larger than client msize. Thanks, Jevon From: Jevon Qiao Date: Sun, 14 Feb 2016 15:11:08 +0800 Subject: [PATCH] hw/9pfs: fix alignment issue when host filesystem block size is larger than client msize. Per the previous implementation, iounit will be assigned to be 0 after the first if statement as (s->msize - P9_IOHDRSZ)/stbuf.f_bsize will be zero when host filesystem block size is larger than msize. Finally, iounit will be equal to s->msize - P9_IOHDRSZ, which is usually not aligned. Signed-off-by: Jevon Qiao --- hw/9pfs/virtio-9p.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index f972731..005d3a8 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -1326,7 +1326,7 @@ out_nofid: static int32_t get_iounit(V9fsPDU *pdu, V9fsPath *path) { struct statfs stbuf; - int32_t iounit = 0; + int32_t iounit = 0, unit = 0; V9fsState *s = pdu->s; /* @@ -1334,8 +1334,21 @@ static int32_t get_iounit(V9fsPDU *pdu, V9fsPath *path) * and as well as less than (client msize - P9_IOHDRSZ)) */ if (!v9fs_co_statfs(pdu, path, &stbuf)) { - iounit = stbuf.f_bsize; - iounit *= (s->msize - P9_IOHDRSZ)/stbuf.f_bsize; + /* + * If host filesystem block size is larger than client msize, + * we will use PAGESIZE as the unit. The reason why we choose + * PAGESIZE is because the data will be splitted in terms of + * PAGESIZE in the virtio layer. In this case, the final + * iounit is equal to the value of ((msize/unit) - 1) * unit. + */ + if (stbuf.f_bsize > s->msize) { + iounit = 4096; + unit = 4096; + } else { + iounit = stbuf.f_bsize; + unit = stbuf.f_bsize; + } + iounit *= (s->msize - P9_IOHDRSZ)/unit; } if (!iounit) { iounit = s->msize - P9_IOHDRSZ; --