From owner-svn-src-projects@FreeBSD.ORG Tue Jan 29 07:35:25 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D677677F; Tue, 29 Jan 2013 07:35:25 +0000 (UTC) (envelope-from bryanv@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id B18FFCF7; Tue, 29 Jan 2013 07:35:25 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r0T7ZPlC007819; Tue, 29 Jan 2013 07:35:25 GMT (envelope-from bryanv@svn.freebsd.org) Received: (from bryanv@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r0T7ZPn5007818; Tue, 29 Jan 2013 07:35:25 GMT (envelope-from bryanv@svn.freebsd.org) Message-Id: <201301290735.r0T7ZPn5007818@svn.freebsd.org> From: Bryan Venteicher Date: Tue, 29 Jan 2013 07:35:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r246061 - projects/virtio/sys/dev/virtio/block X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 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: Tue, 29 Jan 2013 07:35:25 -0000 Author: bryanv Date: Tue Jan 29 07:35:25 2013 New Revision: 246061 URL: http://svnweb.freebsd.org/changeset/base/246061 Log: virtio_blk: Do not always read entire config Only the capacity is guaranteed to be available. The other fields in the device config should only be read if their corresponding feature was negotiated. Approved by: grehan (implicit) Modified: projects/virtio/sys/dev/virtio/block/virtio_blk.c Modified: projects/virtio/sys/dev/virtio/block/virtio_blk.c ============================================================================== --- projects/virtio/sys/dev/virtio/block/virtio_blk.c Tue Jan 29 07:33:40 2013 (r246060) +++ projects/virtio/sys/dev/virtio/block/virtio_blk.c Tue Jan 29 07:35:25 2013 (r246061) @@ -138,6 +138,8 @@ static void vtblk_vq_intr(void *); static void vtblk_stop(struct vtblk_softc *); +static void vtblk_read_config(struct vtblk_softc *, + struct virtio_blk_config *); static void vtblk_get_ident(struct vtblk_softc *); static void vtblk_prepare_dump(struct vtblk_softc *); static int vtblk_write_dump(struct vtblk_softc *, void *, off_t, size_t); @@ -283,8 +285,7 @@ vtblk_attach(device_t dev) sc->vtblk_flags |= VTBLK_FLAG_READONLY; /* Get local copy of config. */ - virtio_read_device_config(dev, 0, &blkcfg, - sizeof(struct virtio_blk_config)); + vtblk_read_config(sc, &blkcfg); /* * With the current sglist(9) implementation, it is not easy @@ -428,8 +429,7 @@ vtblk_config_change(device_t dev) sc = device_get_softc(dev); - virtio_read_device_config(dev, 0, &blkcfg, - sizeof(struct virtio_blk_config)); + vtblk_read_config(sc, &blkcfg); /* Capacity is always in 512-byte units. */ capacity = blkcfg.capacity * 512; @@ -878,6 +878,36 @@ vtblk_stop(struct vtblk_softc *sc) virtio_stop(sc->vtblk_dev); } +#define VTBLK_GET_CONFIG(_dev, _feature, _field, _cfg) \ + if (virtio_with_feature(_dev, _feature)) { \ + virtio_read_device_config(_dev, \ + offsetof(struct virtio_blk_config, _field), \ + &(_cfg)->_field, sizeof((_cfg)->_field)); \ + } + +static void +vtblk_read_config(struct vtblk_softc *sc, struct virtio_blk_config *blkcfg) +{ + device_t dev; + + dev = sc->vtblk_dev; + + bzero(blkcfg, sizeof(struct virtio_blk_config)); + + /* The capacity is always available. */ + virtio_read_device_config(dev, offsetof(struct virtio_blk_config, + capacity), &blkcfg->capacity, 8); + + /* Read the configuration if the feature was negotiated. */ + VTBLK_GET_CONFIG(dev, VIRTIO_BLK_F_SIZE_MAX, size_max, blkcfg); + VTBLK_GET_CONFIG(dev, VIRTIO_BLK_F_SEG_MAX, seg_max, blkcfg); + VTBLK_GET_CONFIG(dev, VIRTIO_BLK_F_GEOMETRY, geometry, blkcfg); + VTBLK_GET_CONFIG(dev, VIRTIO_BLK_F_BLK_SIZE, blk_size, blkcfg); + VTBLK_GET_CONFIG(dev, VIRTIO_BLK_F_TOPOLOGY, topology, blkcfg); +} + +#undef VTBLK_GET_CONFIG + static void vtblk_get_ident(struct vtblk_softc *sc) {