From owner-svn-src-projects@FreeBSD.ORG Sat Oct 12 22:39:35 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 8FA1543A; Sat, 12 Oct 2013 22:39:35 +0000 (UTC) (envelope-from bryanv@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7AACB247B; Sat, 12 Oct 2013 22:39:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9CMdZ7c009739; Sat, 12 Oct 2013 22:39:35 GMT (envelope-from bryanv@svn.freebsd.org) Received: (from bryanv@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9CMdY7B009736; Sat, 12 Oct 2013 22:39:34 GMT (envelope-from bryanv@svn.freebsd.org) Message-Id: <201310122239.r9CMdY7B009736@svn.freebsd.org> From: Bryan Venteicher Date: Sat, 12 Oct 2013 22:39:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r256395 - in projects/virtio: share/man/man9 sys/kern sys/sys X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 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: Sat, 12 Oct 2013 22:39:35 -0000 Author: bryanv Date: Sat Oct 12 22:39:34 2013 New Revision: 256395 URL: http://svnweb.freebsd.org/changeset/base/256395 Log: Add sglist_append_bio(9) to append a struct bio's data Modified: projects/virtio/share/man/man9/sglist.9 projects/virtio/sys/kern/subr_sglist.c projects/virtio/sys/sys/sglist.h Modified: projects/virtio/share/man/man9/sglist.9 ============================================================================== --- projects/virtio/share/man/man9/sglist.9 Sat Oct 12 22:36:01 2013 (r256394) +++ projects/virtio/share/man/man9/sglist.9 Sat Oct 12 22:39:34 2013 (r256395) @@ -33,6 +33,7 @@ .Nm sglist , .Nm sglist_alloc , .Nm sglist_append , +.Nm sglist_append_bio , .Nm sglist_append_mbuf , .Nm sglist_append_phys , .Nm sglist_append_uio , @@ -58,6 +59,8 @@ .Ft int .Fn sglist_append "struct sglist *sg" "void *buf" "size_t len" .Ft int +.Fn sglist_append_bio "struct sglist *sg" "struct bio *bp" +.Ft int .Fn sglist_append_mbuf "struct sglist *sg" "struct mbuf *m" .Ft int .Fn sglist_append_phys "struct sglist *sg" "vm_paddr_t paddr" "size_t len" @@ -206,6 +209,13 @@ and is bytes long. .Pp The +.Nm sglist_append_bio +function appends the physical address ranges described by a single bio +.Fa bp +to the scatter/gather list +.Fa sg . +.Pp +The .Nm sglist_append_mbuf function appends the physical address ranges described by an entire mbuf chain Modified: projects/virtio/sys/kern/subr_sglist.c ============================================================================== --- projects/virtio/sys/kern/subr_sglist.c Sat Oct 12 22:36:01 2013 (r256394) +++ projects/virtio/sys/kern/subr_sglist.c Sat Oct 12 22:39:34 2013 (r256395) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -40,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -239,6 +241,42 @@ sglist_append(struct sglist *sg, void *b } /* + * Append the segments to describe a bio's data to a scatter/gather list. + * If there are insufficient segments, then this fails with EFBIG. + */ +int +sglist_append_bio(struct sglist *sg, struct bio *bp) +{ + struct sgsave save; + vm_paddr_t paddr; + size_t len, tlen; + int error, i, ma_offs; + + if ((bp->bio_flags & BIO_UNMAPPED) == 0) { + error = sglist_append(sg, bp->bio_data, bp->bio_bcount); + return (error); + } + + if (sg->sg_maxseg == 0) + return (EINVAL); + + SGLIST_SAVE(sg, save); + tlen = bp->bio_bcount; + ma_offs = bp->bio_ma_offset; + for (i = 0; tlen > 0; i++, tlen -= len) { + len = min(PAGE_SIZE - ma_offs, tlen); + paddr = VM_PAGE_TO_PHYS(bp->bio_ma[i]) + ma_offs; + error = sglist_append_phys(sg, paddr, len); + if (error) { + SGLIST_RESTORE(sg, save); + return (error); + } + ma_offs = 0; + } + return (0); +} + +/* * Append a single physical address range to a scatter/gather list. * If there are insufficient segments, then this fails with EFBIG. */ Modified: projects/virtio/sys/sys/sglist.h ============================================================================== --- projects/virtio/sys/sys/sglist.h Sat Oct 12 22:36:01 2013 (r256394) +++ projects/virtio/sys/sys/sglist.h Sat Oct 12 22:39:34 2013 (r256395) @@ -53,6 +53,7 @@ struct sglist { u_short sg_maxseg; }; +struct bio; struct mbuf; struct uio; @@ -83,6 +84,7 @@ sglist_hold(struct sglist *sg) struct sglist *sglist_alloc(int nsegs, int mflags); int sglist_append(struct sglist *sg, void *buf, size_t len); +int sglist_append_bio(struct sglist *sg, struct bio *bp); int sglist_append_mbuf(struct sglist *sg, struct mbuf *m0); int sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, size_t len);