From owner-svn-src-head@freebsd.org Tue May 16 23:31:53 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BF67ED707D5; Tue, 16 May 2017 23:31:53 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8270734F; Tue, 16 May 2017 23:31:53 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4GNVqke090501; Tue, 16 May 2017 23:31:52 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4GNVqRj090497; Tue, 16 May 2017 23:31:52 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201705162331.v4GNVqRj090497@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Tue, 16 May 2017 23:31:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318388 - in head: share/man/man9 sys/kern sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 May 2017 23:31:53 -0000 Author: jhb Date: Tue May 16 23:31:52 2017 New Revision: 318388 URL: https://svnweb.freebsd.org/changeset/base/318388 Log: Add sglist_append_sglist(). This function permits a range of one scatter/gather list to be appended to another sglist. This can be used to construct a scatter/gather list that reorders or duplicates ranges from one or more existing scatter/gather lists. Sponsored by: Chelsio Communications Modified: head/share/man/man9/Makefile head/share/man/man9/sglist.9 head/sys/kern/subr_sglist.c head/sys/sys/sglist.h Modified: head/share/man/man9/Makefile ============================================================================== --- head/share/man/man9/Makefile Tue May 16 23:18:50 2017 (r318387) +++ head/share/man/man9/Makefile Tue May 16 23:31:52 2017 (r318388) @@ -1572,6 +1572,7 @@ MLINKS+=sglist.9 sglist_alloc.9 \ sglist.9 sglist_append_bio.9 \ sglist.9 sglist_append_mbuf.9 \ sglist.9 sglist_append_phys.9 \ + sglist.9 sglist_append_sglist.9 \ sglist.9 sglist_append_uio.9 \ sglist.9 sglist_append_user.9 \ sglist.9 sglist_append_vmpages.9 \ Modified: head/share/man/man9/sglist.9 ============================================================================== --- head/share/man/man9/sglist.9 Tue May 16 23:18:50 2017 (r318387) +++ head/share/man/man9/sglist.9 Tue May 16 23:31:52 2017 (r318388) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 12, 2014 +.Dd May 16, 2017 .Dt SGLIST 9 .Os .Sh NAME @@ -36,6 +36,7 @@ .Nm sglist_append_bio , .Nm sglist_append_mbuf , .Nm sglist_append_phys , +.Nm sglist_append_sglist , .Nm sglist_append_uio , .Nm sglist_append_user , .Nm sglist_append_vmpages , @@ -67,6 +68,8 @@ .Ft int .Fn sglist_append_phys "struct sglist *sg" "vm_paddr_t paddr" "size_t len" .Ft int +.Fn sglist_append_sglist "struct sglist *sg" "struct sglist *source" "size_t offset" "size_t len" +.Ft int .Fn sglist_append_uio "struct sglist *sg" "struct uio *uio" .Ft int .Fn sglist_append_user "struct sglist *sg" "void *buf" "size_t len" "struct thread *td" @@ -252,6 +255,20 @@ and is bytes long. .Pp The +.Nm sglist_append_sglist +function appends physical address ranges described by the scatter/gather list +.Fa source +to the scatter/gather list +.Fa sg . +The physical address ranges start at offset +.Fa offset +within +.Fa source +and continue for +.Fa len +bytes. +.Pp +The .Nm sglist_append_uio function appends the physical address ranges described by a .Xr uio 9 Modified: head/sys/kern/subr_sglist.c ============================================================================== --- head/sys/kern/subr_sglist.c Tue May 16 23:18:50 2017 (r318387) +++ head/sys/kern/subr_sglist.c Tue May 16 23:31:52 2017 (r318388) @@ -413,6 +413,49 @@ sglist_append_user(struct sglist *sg, vo } /* + * Append a subset of an existing scatter/gather list 'source' to a + * the scatter/gather list 'sg'. If there are insufficient segments, + * then this fails with EFBIG. + */ +int +sglist_append_sglist(struct sglist *sg, struct sglist *source, size_t offset, + size_t length) +{ + struct sgsave save; + struct sglist_seg *ss; + size_t seglen; + int error, i; + + if (sg->sg_maxseg == 0 || length == 0) + return (EINVAL); + SGLIST_SAVE(sg, save); + error = EINVAL; + ss = &sg->sg_segs[sg->sg_nseg - 1]; + for (i = 0; i < source->sg_nseg; i++) { + if (offset >= source->sg_segs[i].ss_len) { + offset -= source->sg_segs[i].ss_len; + continue; + } + seglen = source->sg_segs[i].ss_len - offset; + if (seglen > length) + seglen = length; + error = _sglist_append_range(sg, &ss, + source->sg_segs[i].ss_paddr + offset, seglen); + if (error) + break; + offset = 0; + length -= seglen; + if (length == 0) + break; + } + if (length != 0) + error = EINVAL; + if (error) + SGLIST_RESTORE(sg, save); + return (error); +} + +/* * Append the segments that describe a single uio to a scatter/gather * list. If there are insufficient segments, then this fails with * EFBIG. Modified: head/sys/sys/sglist.h ============================================================================== --- head/sys/sys/sglist.h Tue May 16 23:18:50 2017 (r318387) +++ head/sys/sys/sglist.h Tue May 16 23:31:52 2017 (r318388) @@ -88,6 +88,8 @@ int sglist_append_bio(struct sglist *sg, int sglist_append_mbuf(struct sglist *sg, struct mbuf *m0); int sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, size_t len); +int sglist_append_sglist(struct sglist *sg, struct sglist *source, + size_t offset, size_t length); int sglist_append_uio(struct sglist *sg, struct uio *uio); int sglist_append_user(struct sglist *sg, void *buf, size_t len, struct thread *td);