From owner-svn-src-projects@FreeBSD.ORG Sat Feb 12 21:06:12 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D04FC106566B; Sat, 12 Feb 2011 21:06:12 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BFE698FC08; Sat, 12 Feb 2011 21:06:12 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p1CL6CTn014971; Sat, 12 Feb 2011 21:06:12 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p1CL6CXF014969; Sat, 12 Feb 2011 21:06:12 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201102122106.p1CL6CXF014969@svn.freebsd.org> From: Alexander Motin Date: Sat, 12 Feb 2011 21:06:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218622 - projects/graid/head/sys/geom/raid X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 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 Feb 2011 21:06:12 -0000 Author: mav Date: Sat Feb 12 21:06:12 2011 New Revision: 218622 URL: http://svn.freebsd.org/changeset/base/218622 Log: Refactor striping code. No need to unroll first loop iteration. It could be easily handled in common way. Modified: projects/graid/head/sys/geom/raid/tr_raid0.c Modified: projects/graid/head/sys/geom/raid/tr_raid0.c ============================================================================== --- projects/graid/head/sys/geom/raid/tr_raid0.c Sat Feb 12 20:58:59 2011 (r218621) +++ projects/graid/head/sys/geom/raid/tr_raid0.c Sat Feb 12 21:06:12 2011 (r218622) @@ -185,13 +185,12 @@ g_raid_tr_stop_raid0(struct g_raid_tr_ob static void g_raid_tr_iostart_raid0(struct g_raid_tr_object *tr, struct bio *bp) { - struct g_raid_softc *sc; struct g_raid_volume *vol; struct g_raid_subdisk *sd; struct bio_queue_head queue; struct bio *cbp; char *addr; - off_t offset, start, length, nstripe; + off_t offset, start, length, nstripe, remain; u_int no, strip_size; vol = tr->tro_volume; @@ -204,8 +203,6 @@ g_raid_tr_iostart_raid0(struct g_raid_tr g_raid_tr_flush_common(tr, bp); return; } - sc = vol->v_softc; - addr = bp->bio_data; strip_size = vol->v_strip_size; @@ -215,55 +212,30 @@ g_raid_tr_iostart_raid0(struct g_raid_tr start = bp->bio_offset % strip_size; /* Disk number. */ no = nstripe % vol->v_disks_count; - /* Start position in disk. */ - offset = (nstripe / vol->v_disks_count) * strip_size + start; + /* Stripe start position in disk. */ + offset = (nstripe / vol->v_disks_count) * strip_size; /* Length of data to operate. */ - length = MIN(bp->bio_length, strip_size - start); + remain = bp->bio_length; - /* - * Allocate all bios before sending any request, so we can - * return ENOMEM in nice and clean way. - */ bioq_init(&queue); - cbp = g_clone_bio(bp); - if (cbp == NULL) - goto failure; - /* - * Fill in the component buf structure. - */ - cbp->bio_offset = offset; - cbp->bio_data = addr; - cbp->bio_length = length; - cbp->bio_caller1 = &vol->v_subdisks[no]; - bioq_insert_tail(&queue, cbp); - - offset -= offset % strip_size; - addr += length; - length = bp->bio_length - length; - for (no++; length > 0; - no++, length -= strip_size, addr += strip_size) { - if (no > vol->v_disks_count - 1) { - no = 0; - offset += strip_size; - } + do { + length = MIN(strip_size - start, remain); cbp = g_clone_bio(bp); if (cbp == NULL) goto failure; - - /* - * Fill in the component buf structure. - */ - cbp->bio_offset = offset; + cbp->bio_offset = offset + start; cbp->bio_data = addr; - /* - * MIN() is in case when - * (bp->bio_length % sc->sc_stripesize) != 0. - */ - cbp->bio_length = MIN(strip_size, length); - + cbp->bio_length = length; cbp->bio_caller1 = &vol->v_subdisks[no]; bioq_insert_tail(&queue, cbp); - } + if (++no >= vol->v_disks_count) { + no = 0; + offset += strip_size; + } + remain -= length; + addr += length; + start = 0; + } while (remain > 0); for (cbp = bioq_first(&queue); cbp != NULL; cbp = bioq_first(&queue)) { bioq_remove(&queue, cbp); @@ -287,50 +259,43 @@ int g_raid_tr_kerneldump_raid0(struct g_raid_tr_object *tr, void *virtual, vm_offset_t physical, off_t boffset, size_t blength) { - struct g_raid_softc *sc; struct g_raid_volume *vol; char *addr; - off_t offset, start, length, nstripe; + off_t offset, start, length, nstripe, remain; u_int no, strip_size; int error; vol = tr->tro_volume; if (vol->v_state != G_RAID_VOLUME_S_OPTIMAL) return (ENXIO); - sc = vol->v_softc; - addr = virtual; strip_size = vol->v_strip_size; + /* Stripe number. */ nstripe = boffset / strip_size; /* Start position in stripe. */ start = boffset % strip_size; /* Disk number. */ no = nstripe % vol->v_disks_count; - /* Start position in disk. */ - offset = (nstripe / vol->v_disks_count) * strip_size + start; + /* Stripe tart position in disk. */ + offset = (nstripe / vol->v_disks_count) * strip_size; /* Length of data to operate. */ - length = MIN(blength, strip_size - start); + remain = blength; - error = g_raid_subdisk_kerneldump(&vol->v_subdisks[no], - addr, 0, offset, length); - if (error != 0) - return (error); - - offset -= offset % strip_size; - addr += length; - length = blength - length; - for (no++; length > 0; - no++, length -= strip_size, addr += strip_size) { - if (no > vol->v_disks_count - 1) { - no = 0; - offset += strip_size; - } + do { + length = MIN(strip_size - start, remain); error = g_raid_subdisk_kerneldump(&vol->v_subdisks[no], - addr, 0, offset, MIN(strip_size, length)); + addr, 0, offset + start, length); if (error != 0) return (error); - } + if (++no >= vol->v_disks_count) { + no = 0; + offset += strip_size; + } + remain -= length; + addr += length; + start = 0; + } while (remain > 0); return (0); }