Date: Sun, 15 Jun 2014 18:16:52 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267515 - head/sys/cam/ctl Message-ID: <201406151816.s5FIGqnc077872@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Sun Jun 15 18:16:51 2014 New Revision: 267515 URL: http://svnweb.freebsd.org/changeset/base/267515 Log: Remove memcpy() from ctl_private[] accesses. That union is aligned enough to access data directly. Modified: head/sys/cam/ctl/ctl.c head/sys/cam/ctl/ctl_backend_block.c Modified: head/sys/cam/ctl/ctl.c ============================================================================== --- head/sys/cam/ctl/ctl.c Sun Jun 15 17:14:52 2014 (r267514) +++ head/sys/cam/ctl/ctl.c Sun Jun 15 18:16:51 2014 (r267515) @@ -5779,7 +5779,7 @@ int ctl_write_same(struct ctl_scsiio *ctsio) { struct ctl_lun *lun; - struct ctl_lba_len_flags lbalen; + struct ctl_lba_len_flags *lbalen; uint64_t lba; uint32_t num_blocks; int len, retval; @@ -5872,11 +5872,10 @@ ctl_write_same(struct ctl_scsiio *ctsio) return (CTL_RETVAL_COMPLETE); } - lbalen.lba = lba; - lbalen.len = num_blocks; - lbalen.flags = byte2; - memcpy(ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, &lbalen, - sizeof(lbalen)); + lbalen = (struct ctl_lba_len_flags *)&ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + lbalen->lba = lba; + lbalen->len = num_blocks; + lbalen->flags = byte2; retval = lun->backend->config_write((union ctl_io *)ctsio); return (retval); @@ -5887,7 +5886,7 @@ ctl_unmap(struct ctl_scsiio *ctsio) { struct ctl_lun *lun; struct scsi_unmap *cdb; - struct ctl_ptr_len_flags ptrlen; + struct ctl_ptr_len_flags *ptrlen; struct scsi_unmap_header *hdr; struct scsi_unmap_desc *buf, *end; uint64_t lba; @@ -5942,11 +5941,10 @@ ctl_unmap(struct ctl_scsiio *ctsio) buf = (struct scsi_unmap_desc *)(hdr + 1); end = buf + len / sizeof(*buf); - ptrlen.ptr = (void *)buf; - ptrlen.len = len; - ptrlen.flags = byte2; - memcpy(ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, &ptrlen, - sizeof(ptrlen)); + ptrlen = (struct ctl_ptr_len_flags *)&ctsio->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + ptrlen->ptr = (void *)buf; + ptrlen->len = len; + ptrlen->flags = byte2; for (; buf < end; buf++) { lba = scsi_8btou64(buf->lba); @@ -12755,7 +12753,7 @@ ctl_process_done(union ctl_io *io, int h switch (io->io_hdr.io_type) { case CTL_IO_SCSI: { int isread; - struct ctl_lba_len lbalen; + struct ctl_lba_len *lbalen; isread = 0; switch (io->scsiio.cdb[0]) { @@ -12772,12 +12770,12 @@ ctl_process_done(union ctl_io *io, int h case WRITE_VERIFY_10: case WRITE_VERIFY_12: case WRITE_VERIFY_16: - memcpy(&lbalen, io->io_hdr.ctl_private[ - CTL_PRIV_LBA_LEN].bytes, sizeof(lbalen)); + lbalen = (struct ctl_lba_len *) + &io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; if (isread) { lun->stats.ports[targ_port].bytes[CTL_STATS_READ] += - lbalen.len * blocksize; + lbalen->len * blocksize; lun->stats.ports[targ_port].operations[CTL_STATS_READ]++; #ifdef CTL_TIME_IO @@ -12807,7 +12805,7 @@ ctl_process_done(union ctl_io *io, int h #endif /* CTL_TIME_IO */ } else { lun->stats.ports[targ_port].bytes[CTL_STATS_WRITE] += - lbalen.len * blocksize; + lbalen->len * blocksize; lun->stats.ports[targ_port].operations[ CTL_STATS_WRITE]++; Modified: head/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- head/sys/cam/ctl/ctl_backend_block.c Sun Jun 15 17:14:52 2014 (r267514) +++ head/sys/cam/ctl/ctl_backend_block.c Sun Jun 15 18:16:51 2014 (r267515) @@ -786,7 +786,7 @@ ctl_be_block_unmap_dev(struct ctl_be_blo { union ctl_io *io; struct ctl_be_block_devdata *dev_data; - struct ctl_ptr_len_flags ptrlen; + struct ctl_ptr_len_flags *ptrlen; struct scsi_unmap_desc *buf, *end; uint64_t len; @@ -800,10 +800,9 @@ ctl_be_block_unmap_dev(struct ctl_be_blo if (beio->io_offset == -1) { beio->io_len = 0; - memcpy(&ptrlen, io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, - sizeof(ptrlen)); - buf = (struct scsi_unmap_desc *)ptrlen.ptr; - end = buf + ptrlen.len / sizeof(*buf); + ptrlen = (struct ctl_ptr_len_flags *)&io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; + buf = (struct scsi_unmap_desc *)ptrlen->ptr; + end = buf + ptrlen->len / sizeof(*buf); for (; buf < end; buf++) { len = (uint64_t)scsi_4btoul(buf->length) * be_lun->blocksize; @@ -926,7 +925,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_b { struct ctl_be_block_io *beio; struct ctl_be_block_softc *softc; - struct ctl_lba_len_flags lbalen; + struct ctl_lba_len_flags *lbalen; uint64_t len_left, lba; int i, seglen; uint8_t *buf, *end; @@ -935,11 +934,10 @@ ctl_be_block_cw_dispatch_ws(struct ctl_b beio = io->io_hdr.ctl_private[CTL_PRIV_BACKEND].ptr; softc = be_lun->softc; - memcpy(&lbalen, io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, - sizeof(lbalen)); + lbalen = (struct ctl_lba_len_flags *)&io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; - if (lbalen.flags & ~(SWS_LBDATA | SWS_UNMAP) || - (lbalen.flags & SWS_UNMAP && be_lun->unmap == NULL)) { + if (lbalen->flags & ~(SWS_LBDATA | SWS_UNMAP) || + (lbalen->flags & SWS_UNMAP && be_lun->unmap == NULL)) { ctl_free_beio(beio); ctl_set_invalid_field(&io->scsiio, /*sks_valid*/ 1, @@ -975,9 +973,9 @@ ctl_be_block_cw_dispatch_ws(struct ctl_b break; } - if (lbalen.flags & SWS_UNMAP) { - beio->io_offset = lbalen.lba * be_lun->blocksize; - beio->io_len = (uint64_t)lbalen.len * be_lun->blocksize; + if (lbalen->flags & SWS_UNMAP) { + beio->io_offset = lbalen->lba * be_lun->blocksize; + beio->io_len = (uint64_t)lbalen->len * be_lun->blocksize; beio->bio_cmd = BIO_DELETE; beio->ds_trans_type = DEVSTAT_FREE; @@ -989,9 +987,9 @@ ctl_be_block_cw_dispatch_ws(struct ctl_b beio->ds_trans_type = DEVSTAT_WRITE; DPRINTF("WRITE SAME at LBA %jx len %u\n", - (uintmax_t)lbalen.lba, lbalen.len); + (uintmax_t)lbalen->lba, lbalen->len); - len_left = (uint64_t)lbalen.len * be_lun->blocksize; + len_left = (uint64_t)lbalen->len * be_lun->blocksize; for (i = 0, lba = 0; i < CTLBLK_MAX_SEGS && len_left > 0; i++) { /* @@ -1012,21 +1010,19 @@ ctl_be_block_cw_dispatch_ws(struct ctl_b end = buf + seglen; for (; buf < end; buf += be_lun->blocksize) { memcpy(buf, io->scsiio.kern_data_ptr, be_lun->blocksize); - if (lbalen.flags & SWS_LBDATA) - scsi_ulto4b(lbalen.lba + lba, buf); + if (lbalen->flags & SWS_LBDATA) + scsi_ulto4b(lbalen->lba + lba, buf); lba++; } } - beio->io_offset = lbalen.lba * be_lun->blocksize; + beio->io_offset = lbalen->lba * be_lun->blocksize; beio->io_len = lba * be_lun->blocksize; /* We can not do all in one run. Correct and schedule rerun. */ if (len_left > 0) { - lbalen.lba += lba; - lbalen.len -= lba; - memcpy(io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, &lbalen, - sizeof(lbalen)); + lbalen->lba += lba; + lbalen->len -= lba; beio->beio_cont = ctl_be_block_cw_done_ws; } @@ -1039,16 +1035,15 @@ ctl_be_block_cw_dispatch_unmap(struct ct { struct ctl_be_block_io *beio; struct ctl_be_block_softc *softc; - struct ctl_ptr_len_flags ptrlen; + struct ctl_ptr_len_flags *ptrlen; DPRINTF("entered\n"); beio = io->io_hdr.ctl_private[CTL_PRIV_BACKEND].ptr; softc = be_lun->softc; - memcpy(&ptrlen, io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, - sizeof(ptrlen)); + ptrlen = (struct ctl_ptr_len_flags *)&io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; - if (ptrlen.flags != 0 || be_lun->unmap == NULL) { + if (ptrlen->flags != 0 || be_lun->unmap == NULL) { ctl_free_beio(beio); ctl_set_invalid_field(&io->scsiio, /*sks_valid*/ 0, @@ -1090,8 +1085,7 @@ ctl_be_block_cw_dispatch_unmap(struct ct beio->bio_cmd = BIO_DELETE; beio->ds_trans_type = DEVSTAT_FREE; - DPRINTF("WRITE SAME at LBA %jx len %u\n", - (uintmax_t)lbalen.lba, lbalen.len); + DPRINTF("UNMAP\n"); be_lun->unmap(be_lun, beio); } @@ -1186,7 +1180,7 @@ ctl_be_block_dispatch(struct ctl_be_bloc { struct ctl_be_block_io *beio; struct ctl_be_block_softc *softc; - struct ctl_lba_len lbalen; + struct ctl_lba_len *lbalen; uint64_t len_left, lbaoff; int i; @@ -1246,14 +1240,13 @@ ctl_be_block_dispatch(struct ctl_be_bloc beio->ds_trans_type = DEVSTAT_WRITE; } - memcpy(&lbalen, io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes, - sizeof(lbalen)); + lbalen = (struct ctl_lba_len *)&io->io_hdr.ctl_private[CTL_PRIV_LBA_LEN]; DPRINTF("%s at LBA %jx len %u @%ju\n", (beio->bio_cmd == BIO_READ) ? "READ" : "WRITE", - (uintmax_t)lbalen.lba, lbalen.len, lbaoff); + (uintmax_t)lbalen->lba, lbalen->len, lbaoff); lbaoff = io->scsiio.kern_rel_offset / be_lun->blocksize; - beio->io_offset = (lbalen.lba + lbaoff) * be_lun->blocksize; - beio->io_len = MIN((lbalen.len - lbaoff) * be_lun->blocksize, + beio->io_offset = (lbalen->lba + lbaoff) * be_lun->blocksize; + beio->io_len = MIN((lbalen->len - lbaoff) * be_lun->blocksize, CTLBLK_MAX_IO_SIZE); beio->io_len -= beio->io_len % be_lun->blocksize;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406151816.s5FIGqnc077872>