Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Jan 2014 18:36:42 +0000 (UTC)
From:      Bryan Venteicher <bryanv@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r260856 - in stable/10: share/man/man9 sys/kern sys/sys
Message-ID:  <201401181836.s0IIagxa082851@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bryanv
Date: Sat Jan 18 18:36:41 2014
New Revision: 260856
URL: http://svnweb.freebsd.org/changeset/base/260856

Log:
  MFC r260581: Add sglist_append_bio(9) to append a struct bio's data to
  a sglist

Modified:
  stable/10/share/man/man9/Makefile
  stable/10/share/man/man9/sglist.9
  stable/10/sys/kern/subr_sglist.c
  stable/10/sys/sys/sglist.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/share/man/man9/Makefile
==============================================================================
--- stable/10/share/man/man9/Makefile	Sat Jan 18 17:59:22 2014	(r260855)
+++ stable/10/share/man/man9/Makefile	Sat Jan 18 18:36:41 2014	(r260856)
@@ -1172,6 +1172,7 @@ MLINKS+=sf_buf.9 sf_buf_alloc.9 \
 	sf_buf.9 sf_buf_page.9
 MLINKS+=sglist.9 sglist_alloc.9 \
 	sglist.9 sglist_append.9 \
+	sglist.9 sglist_append_bio.9 \
 	sglist.9 sglist_append_mbuf.9 \
 	sglist.9 sglist_append_phys.9 \
 	sglist.9 sglist_append_uio.9 \

Modified: stable/10/share/man/man9/sglist.9
==============================================================================
--- stable/10/share/man/man9/sglist.9	Sat Jan 18 17:59:22 2014	(r260855)
+++ stable/10/share/man/man9/sglist.9	Sat Jan 18 18:36:41 2014	(r260856)
@@ -26,13 +26,14 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 15, 2009
+.Dd January 12, 2014
 .Dt SGLIST 9
 .Os
 .Sh NAME
 .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
@@ -499,6 +509,7 @@ list in
 to describe the requested physical address ranges.
 .El
 .Sh SEE ALSO
+.Xr g_bio 9 ,
 .Xr malloc 9 ,
 .Xr mbuf 9 ,
 .Xr uio 9

Modified: stable/10/sys/kern/subr_sglist.c
==============================================================================
--- stable/10/sys/kern/subr_sglist.c	Sat Jan 18 17:59:22 2014	(r260855)
+++ stable/10/sys/kern/subr_sglist.c	Sat Jan 18 18:36:41 2014	(r260856)
@@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
+#include <sys/bio.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/proc.h>
@@ -40,6 +41,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/uio.h>
 
 #include <vm/vm.h>
+#include <vm/vm_page.h>
 #include <vm/pmap.h>
 #include <vm/vm_map.h>
 
@@ -239,6 +241,44 @@ 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.
+ *
+ * NOTE: This function expects bio_bcount to be initialized.
+ */
+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: stable/10/sys/sys/sglist.h
==============================================================================
--- stable/10/sys/sys/sglist.h	Sat Jan 18 17:59:22 2014	(r260855)
+++ stable/10/sys/sys/sglist.h	Sat Jan 18 18:36:41 2014	(r260856)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401181836.s0IIagxa082851>