Re: svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
I've updated the g_bio man page with all the info presented here. Please let me know if I missed anything, or if you have suggestions for improvement. Warner On Mon, May 9, 2016 at 12:21 PM, Steven Hartlandwrote: > On 09/05/2016 18:21, Warner Losh wrote: > > On May 9, 2016, at 11:14 AM, Steven Hartland > wrote: > > > > On 09/05/2016 18:04, Alan Somers wrote: > > > On Wed, Feb 17, 2016 at 10:16 AM, Warner Losh > wrote: > Author: imp > Date: Wed Feb 17 17:16:02 2016 > New Revision: 295707 > URL: https://svnweb.freebsd.org/changeset/base/295707 > > Log: > Create an API to reset a struct bio (g_reset_bio). This is mandatory > for all struct bio you get back from g_{new,alloc}_bio. Temporary > bios that you create on the stack or elsewhere should use this before > first use of the bio, and between uses of the bio. At the moment, it > is nothing more than a wrapper around bzero, but that may change in > the future. The wrapper also removes one place where we encode the > size of struct bio in the KBI. > > Modified: > head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c > head/sys/dev/mmc/mmcsd.c > head/sys/dev/virtio/block/virtio_blk.c > head/sys/geom/geom.h > head/sys/geom/geom_io.c > head/sys/geom/journal/g_journal.c > head/sys/geom/mirror/g_mirror.c > head/sys/geom/raid/g_raid.c > head/sys/geom/raid3/g_raid3.c > head/sys/kern/kern_physio.c > > smh noticed that while your commit message says that g_reset_bio is mandatory > after g_{new,alloc}_bio, your diff only replaced existing calls to bzero. > You didn't insert g_reset_bio calls after all g_alloc_bio calls, for example > in vdev_geom_io_start. Do you intend to follow up this change with a > g_reset_bio everywhere that g_alloc_bio is called, or did you mean that > g_reset_bio is optional after all bios returned by g_{new,alloc}_bio? > > > Yer I was just penning this too: > This commit was just referenced in https://reviews.freebsd.org/D6153 > It seems rather odd to require all callers to g_{new,alloc}_bio to also call > g_reset_bio. > > I don’t. Please see my other reply. It’s only when you *RE*use the bio that > you need to call g_reset_bio(), not when you use it in the first place. You > can no longer call bzero() on the bio to reset it. > > > I assume this is because uma can return an existing object instead of fresh > one hence its not guaranteed to be bzeroed? If so why have the caller > responsible, seems petty error prone. A quick look at users of g_alloc_bio it > seems like this is something that's not done currently done in all places, > even some usages of memset still hanging around, are these cases a bug? > > No. That’s not the case at all. There’s going to be contents of the BIO that > cannot be blithely cleared by the users of the memory. Many other structures > in the kernel are like this, but bio wasn’t previously. > > > If the concept of this was to ensure correctly initialised objects from uma > would the callback handers to uma_zcreate not be a better option as that > would guarantee things are correct instead of leaving it to the caller? > > No. It’s to ensure internal state to the bio isn’t blown away by a subsequent > bzero() call before calling g_destroy_bio(). > > > As a side matter, this area really needs some man pages so the its clear to > all what is needed and when. > > Agreed. The whole storage stack, however, is wonderfully under-documented. > I’ve started documenting CAM, but handn’t worked my way back to geom… > > > Thanks for the clarifications Warner, appreciated :) > > Regards > Steve > ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
On 09/05/2016 18:21, Warner Losh wrote: On May 9, 2016, at 11:14 AM, Steven Hartlandwrote: On 09/05/2016 18:04, Alan Somers wrote: On Wed, Feb 17, 2016 at 10:16 AM, Warner Losh wrote: Author: imp Date: Wed Feb 17 17:16:02 2016 New Revision: 295707 URL: https://svnweb.freebsd.org/changeset/base/295707 Log: Create an API to reset a struct bio (g_reset_bio). This is mandatory for all struct bio you get back from g_{new,alloc}_bio. Temporary bios that you create on the stack or elsewhere should use this before first use of the bio, and between uses of the bio. At the moment, it is nothing more than a wrapper around bzero, but that may change in the future. The wrapper also removes one place where we encode the size of struct bio in the KBI. Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c head/sys/dev/mmc/mmcsd.c head/sys/dev/virtio/block/virtio_blk.c head/sys/geom/geom.h head/sys/geom/geom_io.c head/sys/geom/journal/g_journal.c head/sys/geom/mirror/g_mirror.c head/sys/geom/raid/g_raid.c head/sys/geom/raid3/g_raid3.c head/sys/kern/kern_physio.c smh noticed that while your commit message says that g_reset_bio is mandatory after g_{new,alloc}_bio, your diff only replaced existing calls to bzero. You didn't insert g_reset_bio calls after all g_alloc_bio calls, for example in vdev_geom_io_start. Do you intend to follow up this change with a g_reset_bio everywhere that g_alloc_bio is called, or did you mean that g_reset_bio is optional after all bios returned by g_{new,alloc}_bio? Yer I was just penning this too: This commit was just referenced in https://reviews.freebsd.org/D6153 It seems rather odd to require all callers to g_{new,alloc}_bio to also call g_reset_bio. I don’t. Please see my other reply. It’s only when you *RE*use the bio that you need to call g_reset_bio(), not when you use it in the first place. You can no longer call bzero() on the bio to reset it. I assume this is because uma can return an existing object instead of fresh one hence its not guaranteed to be bzeroed? If so why have the caller responsible, seems petty error prone. A quick look at users of g_alloc_bio it seems like this is something that's not done currently done in all places, even some usages of memset still hanging around, are these cases a bug? No. That’s not the case at all. There’s going to be contents of the BIO that cannot be blithely cleared by the users of the memory. Many other structures in the kernel are like this, but bio wasn’t previously. If the concept of this was to ensure correctly initialised objects from uma would the callback handers to uma_zcreate not be a better option as that would guarantee things are correct instead of leaving it to the caller? No. It’s to ensure internal state to the bio isn’t blown away by a subsequent bzero() call before calling g_destroy_bio(). As a side matter, this area really needs some man pages so the its clear to all what is needed and when. Agreed. The whole storage stack, however, is wonderfully under-documented. I’ve started documenting CAM, but handn’t worked my way back to geom… Thanks for the clarifications Warner, appreciated :) Regards Steve ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
> On May 9, 2016, at 11:14 AM, Steven Hartlandwrote: > > > > On 09/05/2016 18:04, Alan Somers wrote: >> >> >> On Wed, Feb 17, 2016 at 10:16 AM, Warner Losh wrote: >> Author: imp >> Date: Wed Feb 17 17:16:02 2016 >> New Revision: 295707 >> URL: https://svnweb.freebsd.org/changeset/base/295707 >> >> Log: >> Create an API to reset a struct bio (g_reset_bio). This is mandatory >> for all struct bio you get back from g_{new,alloc}_bio. Temporary >> bios that you create on the stack or elsewhere should use this before >> first use of the bio, and between uses of the bio. At the moment, it >> is nothing more than a wrapper around bzero, but that may change in >> the future. The wrapper also removes one place where we encode the >> size of struct bio in the KBI. >> >> Modified: >> head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c >> head/sys/dev/mmc/mmcsd.c >> head/sys/dev/virtio/block/virtio_blk.c >> head/sys/geom/geom.h >> head/sys/geom/geom_io.c >> head/sys/geom/journal/g_journal.c >> head/sys/geom/mirror/g_mirror.c >> head/sys/geom/raid/g_raid.c >> head/sys/geom/raid3/g_raid3.c >> head/sys/kern/kern_physio.c >> >> smh noticed that while your commit message says that g_reset_bio is >> mandatory after g_{new,alloc}_bio, your diff only replaced existing calls to >> bzero. You didn't insert g_reset_bio calls after all g_alloc_bio calls, for >> example in vdev_geom_io_start. Do you intend to follow up this change with >> a g_reset_bio everywhere that g_alloc_bio is called, or did you mean that >> g_reset_bio is optional after all bios returned by g_{new,alloc}_bio? >> > Yer I was just penning this too: > This commit was just referenced in https://reviews.freebsd.org/D6153 > It seems rather odd to require all callers to g_{new,alloc}_bio to also call > g_reset_bio. I don’t. Please see my other reply. It’s only when you *RE*use the bio that you need to call g_reset_bio(), not when you use it in the first place. You can no longer call bzero() on the bio to reset it. > I assume this is because uma can return an existing object instead of fresh > one hence its not guaranteed to be bzeroed? If so why have the caller > responsible, seems petty error prone. A quick look at users of g_alloc_bio it > seems like this is something that's not done currently done in all places, > even some usages of memset still hanging around, are these cases a bug? No. That’s not the case at all. There’s going to be contents of the BIO that cannot be blithely cleared by the users of the memory. Many other structures in the kernel are like this, but bio wasn’t previously. > If the concept of this was to ensure correctly initialised objects from uma > would the callback handers to uma_zcreate not be a better option as that > would guarantee things are correct instead of leaving it to the caller? No. It’s to ensure internal state to the bio isn’t blown away by a subsequent bzero() call before calling g_destroy_bio(). > As a side matter, this area really needs some man pages so the its clear to > all what is needed and when. Agreed. The whole storage stack, however, is wonderfully under-documented. I’ve started documenting CAM, but handn’t worked my way back to geom… Warner signature.asc Description: Message signed with OpenPGP using GPGMail
Re: svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
On 09/05/2016 18:04, Alan Somers wrote: On Wed, Feb 17, 2016 at 10:16 AM, Warner Losh> wrote: Author: imp Date: Wed Feb 17 17:16:02 2016 New Revision: 295707 URL: https://svnweb.freebsd.org/changeset/base/295707 Log: Create an API to reset a struct bio (g_reset_bio). This is mandatory for all struct bio you get back from g_{new,alloc}_bio. Temporary bios that you create on the stack or elsewhere should use this before first use of the bio, and between uses of the bio. At the moment, it is nothing more than a wrapper around bzero, but that may change in the future. The wrapper also removes one place where we encode the size of struct bio in the KBI. Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c head/sys/dev/mmc/mmcsd.c head/sys/dev/virtio/block/virtio_blk.c head/sys/geom/geom.h head/sys/geom/geom_io.c head/sys/geom/journal/g_journal.c head/sys/geom/mirror/g_mirror.c head/sys/geom/raid/g_raid.c head/sys/geom/raid3/g_raid3.c head/sys/kern/kern_physio.c smh noticed that while your commit message says that g_reset_bio is mandatory after g_{new,alloc}_bio, your diff only replaced existing calls to bzero. You didn't insert g_reset_bio calls after all g_alloc_bio calls, for example in vdev_geom_io_start. Do you intend to follow up this change with a g_reset_bio everywhere that g_alloc_bio is called, or did you mean that g_reset_bio is optional after all bios returned by g_{new,alloc}_bio? Yer I was just penning this too: This commit was just referenced in https://reviews.freebsd.org/D6153 It seems rather odd to require all callers to g_{new,alloc}_bio to also call g_reset_bio. I assume this is because uma can return an existing object instead of fresh one hence its not guaranteed to be bzeroed? If so why have the caller responsible, seems petty error prone. A quick look at users of g_alloc_bio it seems like this is something that's not done currently done in all places, even some usages of memset still hanging around, are these cases a bug? If the concept of this was to ensure correctly initialised objects from uma would the callback handers to uma_zcreate not be a better option as that would guarantee things are correct instead of leaving it to the caller? As a side matter, this area really needs some man pages so the its clear to all what is needed and when. Regards Steve ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
> On May 9, 2016, at 11:04 AM, Alan Somerswrote: > > > > On Wed, Feb 17, 2016 at 10:16 AM, Warner Losh wrote: > Author: imp > Date: Wed Feb 17 17:16:02 2016 > New Revision: 295707 > URL: https://svnweb.freebsd.org/changeset/base/295707 > > Log: > Create an API to reset a struct bio (g_reset_bio). This is mandatory > for all struct bio you get back from g_{new,alloc}_bio. Temporary > bios that you create on the stack or elsewhere should use this before > first use of the bio, and between uses of the bio. At the moment, it > is nothing more than a wrapper around bzero, but that may change in > the future. The wrapper also removes one place where we encode the > size of struct bio in the KBI. > > Modified: > head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c > head/sys/dev/mmc/mmcsd.c > head/sys/dev/virtio/block/virtio_blk.c > head/sys/geom/geom.h > head/sys/geom/geom_io.c > head/sys/geom/journal/g_journal.c > head/sys/geom/mirror/g_mirror.c > head/sys/geom/raid/g_raid.c > head/sys/geom/raid3/g_raid3.c > head/sys/kern/kern_physio.c > > smh noticed that while your commit message says that g_reset_bio is mandatory > after g_{new,alloc}_bio, your diff only replaced existing calls to bzero. > You didn't insert g_reset_bio calls after all g_alloc_bio calls, for example > in vdev_geom_io_start. Do you intend to follow up this change with a > g_reset_bio everywhere that g_alloc_bio is called, or did you mean that > g_reset_bio is optional after all bios returned by g_{new,alloc}_bio? g_reset_bio is required when you reuse the bio returned from g_{new,alloc}_bio. You don’t need to reset it before using it. Only when reusing it where you used to call bzero(). My commit message is at best ambiguous: g_reset_bio() is required to reuse the bio, not to use it in the first place. So all callers to g_alloc_bio() that just use the bio then return it don’t need to change. Callers to g_alloc_bio() that use the bio for multiple I/Os need to call g_reset_bio() between uses of the bio. That’s why I only changed the bzero’s in the tree: those were the only places where the bio was being re-used. Otherwise you wouldn’t need to reset the bio, since it is returned ‘set’ from g_{new,alloc}_bio. Before some other changes I have, it was safe to assume no fields needed to be preserved when you wanted to reuse the bio for multiple I/Os, so the code just used bzero(). After that change, the code needn’t assume what you need to do to a bio to reuse it, other than call this API. In the future, there may be info about which uma pool the I/O came from so we can have a small reserve of bios for low/out of memory situations to allow them to clear more quickly. Sorry if things were unclear. Hopefully they are clear now. Warner signature.asc Description: Message signed with OpenPGP using GPGMail
Re: svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
On Wed, Feb 17, 2016 at 10:16 AM, Warner Loshwrote: > Author: imp > Date: Wed Feb 17 17:16:02 2016 > New Revision: 295707 > URL: https://svnweb.freebsd.org/changeset/base/295707 > > Log: > Create an API to reset a struct bio (g_reset_bio). This is mandatory > for all struct bio you get back from g_{new,alloc}_bio. Temporary > bios that you create on the stack or elsewhere should use this before > first use of the bio, and between uses of the bio. At the moment, it > is nothing more than a wrapper around bzero, but that may change in > the future. The wrapper also removes one place where we encode the > size of struct bio in the KBI. > > Modified: > head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c > head/sys/dev/mmc/mmcsd.c > head/sys/dev/virtio/block/virtio_blk.c > head/sys/geom/geom.h > head/sys/geom/geom_io.c > head/sys/geom/journal/g_journal.c > head/sys/geom/mirror/g_mirror.c > head/sys/geom/raid/g_raid.c > head/sys/geom/raid3/g_raid3.c > head/sys/kern/kern_physio.c > smh noticed that while your commit message says that g_reset_bio is mandatory after g_{new,alloc}_bio, your diff only replaced existing calls to bzero. You didn't insert g_reset_bio calls after all g_alloc_bio calls, for example in vdev_geom_io_start. Do you intend to follow up this change with a g_reset_bio everywhere that g_alloc_bio is called, or did you mean that g_reset_bio is optional after all bios returned by g_{new,alloc}_bio? ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r295707 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs dev/mmc dev/virtio/block geom geom/journal geom/mirror geom/raid geom/raid3 kern
Author: imp Date: Wed Feb 17 17:16:02 2016 New Revision: 295707 URL: https://svnweb.freebsd.org/changeset/base/295707 Log: Create an API to reset a struct bio (g_reset_bio). This is mandatory for all struct bio you get back from g_{new,alloc}_bio. Temporary bios that you create on the stack or elsewhere should use this before first use of the bio, and between uses of the bio. At the moment, it is nothing more than a wrapper around bzero, but that may change in the future. The wrapper also removes one place where we encode the size of struct bio in the KBI. Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c head/sys/dev/mmc/mmcsd.c head/sys/dev/virtio/block/virtio_blk.c head/sys/geom/geom.h head/sys/geom/geom_io.c head/sys/geom/journal/g_journal.c head/sys/geom/mirror/g_mirror.c head/sys/geom/raid/g_raid.c head/sys/geom/raid3/g_raid3.c head/sys/kern/kern_physio.c Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c == --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Wed Feb 17 16:13:22 2016(r295706) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Wed Feb 17 17:16:02 2016(r295707) @@ -314,7 +314,7 @@ vdev_geom_io(struct g_consumer *cp, int error = 0; for (; off < offset; off += maxio, p += maxio, size -= maxio) { - bzero(bp, sizeof(*bp)); + g_reset_bio(bp); bp->bio_cmd = cmd; bp->bio_done = NULL; bp->bio_offset = off; Modified: head/sys/dev/mmc/mmcsd.c == --- head/sys/dev/mmc/mmcsd.cWed Feb 17 16:13:22 2016(r295706) +++ head/sys/dev/mmc/mmcsd.cWed Feb 17 17:16:02 2016(r295707) @@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -487,7 +488,7 @@ mmcsd_dump(void *arg, void *virtual, vm_ if (!length) return (0); - bzero(, sizeof(struct bio)); + g_reset_bio(); bp.bio_disk = disk; bp.bio_pblkno = offset / disk->d_sectorsize; bp.bio_bcount = length; Modified: head/sys/dev/virtio/block/virtio_blk.c == --- head/sys/dev/virtio/block/virtio_blk.c Wed Feb 17 16:13:22 2016 (r295706) +++ head/sys/dev/virtio/block/virtio_blk.c Wed Feb 17 17:16:02 2016 (r295707) @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -1146,7 +1147,7 @@ vtblk_ident(struct vtblk_softc *sc) req->vbr_hdr.sector = 0; req->vbr_bp = - bzero(, sizeof(struct bio)); + g_reset_bio(); buf.bio_cmd = BIO_READ; buf.bio_data = dp->d_ident; @@ -1278,7 +1279,7 @@ vtblk_dump_write(struct vtblk_softc *sc, req->vbr_hdr.sector = offset / 512; req->vbr_bp = - bzero(, sizeof(struct bio)); + g_reset_bio(); buf.bio_cmd = BIO_WRITE; buf.bio_data = virtual; @@ -1300,7 +1301,7 @@ vtblk_dump_flush(struct vtblk_softc *sc) req->vbr_hdr.sector = 0; req->vbr_bp = - bzero(, sizeof(struct bio)); + g_reset_bio(); buf.bio_cmd = BIO_FLUSH; Modified: head/sys/geom/geom.h == --- head/sys/geom/geom.hWed Feb 17 16:13:22 2016(r295706) +++ head/sys/geom/geom.hWed Feb 17 17:16:02 2016(r295707) @@ -324,6 +324,7 @@ void g_unregister_classifier(struct g_cl void g_io_request(struct bio *bp, struct g_consumer *cp); struct bio *g_new_bio(void); struct bio *g_alloc_bio(void); +void g_reset_bio(struct bio *); void * g_read_data(struct g_consumer *cp, off_t offset, off_t length, int *error); int g_write_data(struct g_consumer *cp, off_t offset, void *ptr, off_t length); int g_delete_data(struct g_consumer *cp, off_t offset, off_t length); Modified: head/sys/geom/geom_io.c == --- head/sys/geom/geom_io.c Wed Feb 17 16:13:22 2016(r295706) +++ head/sys/geom/geom_io.c Wed Feb 17 17:16:02 2016(r295707) @@ -265,6 +265,13 @@ g_duplicate_bio(struct bio *bp) } void +g_reset_bio(struct bio *bp) +{ + + bzero(bp, sizeof(bp)); +} + +void g_io_init() { Modified: head/sys/geom/journal/g_journal.c == --- head/sys/geom/journal/g_journal.c Wed Feb 17 16:13:22 2016 (r295706) +++ head/sys/geom/journal/g_journal.c Wed Feb 17 17:16:02 2016 (r295707) @@ -1296,7 +1296,7 @@ g_journal_flush(struct g_journal_softc * data = bp->bio_data; if