From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxYL4-00025q-My for qemu-devel@nongnu.org; Thu, 19 Jun 2014 05:09:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WxYKs-0007kz-MT for qemu-devel@nongnu.org; Thu, 19 Jun 2014 05:08:58 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:59832) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxYKs-0007kg-GJ for qemu-devel@nongnu.org; Thu, 19 Jun 2014 05:08:46 -0400 Received: by mail-wi0-f175.google.com with SMTP id r20so8991638wiv.8 for ; Thu, 19 Jun 2014 02:08:45 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <53A2A89A.3090505@redhat.com> Date: Thu, 19 Jun 2014 11:08:42 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <3e7848fff9d1ad0a72d43c61a3ddeabd0dc604f0.1403141617.git.peter.crosthwaite@xilinx.com> <78e1e234bb9d30f863bab5be6498bf827f906318.1403141617.git.peter.crosthwaite@xilinx.com> In-Reply-To: <78e1e234bb9d30f863bab5be6498bf827f906318.1403141617.git.peter.crosthwaite@xilinx.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite , qemu-devel@nongnu.org Cc: stefanha@redhat.com > static void bdrv_sync_complete(void *opaque, int ret) > { > /* do nothing. Masters do not directly interact with the backing store, > * only the working copy so no mutexing required. > */ > } > > static void flash_sync_page(Flash *s, int page) > { > if (s->bdrv) { > int bdrv_sector, nb_sectors; > QEMUIOVector iov; > > bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE; > nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE); > qemu_iovec_init(&iov, 1); > qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE, > nb_sectors * BDRV_SECTOR_SIZE); > bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors, > bdrv_sync_complete, NULL); > } > } Using AIO is a good idea, but you could have overlapping writes here if you get close calls to flash_sync_page. It can be bad. Serializing can be done in fancy manners, but it can be as easy as adding bdrv_drain(s->bdrv) before the bdrv_aio_writev. Paolo