From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W00Cl-0002Ya-TM for qemu-devel@nongnu.org; Sun, 05 Jan 2014 21:46:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W00Ce-0003dS-Jo for qemu-devel@nongnu.org; Sun, 05 Jan 2014 21:46:15 -0500 Received: from mail-ee0-f54.google.com ([74.125.83.54]:35952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W00Ce-0003dO-CY for qemu-devel@nongnu.org; Sun, 05 Jan 2014 21:46:08 -0500 Received: by mail-ee0-f54.google.com with SMTP id e51so6556328eek.13 for ; Sun, 05 Jan 2014 18:45:32 -0800 (PST) Date: Mon, 6 Jan 2014 10:45:24 +0800 From: Stefan Hajnoczi Message-ID: <20140106024524.GD9790@stefanha-thinkpad.redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] TRIM/DISCARD/UNMAP support on qemu-nbd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Teng-Feng Yang Cc: qemu-devel@nongnu.org On Mon, Dec 30, 2013 at 07:58:29PM +0800, Teng-Feng Yang wrote: > I have been studying QCOW2 file format for a couple of days, and I am > a little bit confused about whether QCOW2 supports UNMAP or not. Discard is an area that has seen a lot of development activity over the past year or two. That means it's still relatively new, you may find outdated information online, etc. > As I surf through internet, some mailing list discussion had mentioned > that qemu-nbd and nbd module both support UNMAP command. Yes: * qemu-nbd since QEMU 1.1 supports TRIM * nbd.ko since Linux 3.7 supports discard > So I follow the steps below on my machine (Ubuntu 13.10 with linux > kernel 3.12) to test if qemu-nbd and QCOW2 do support UNMAP. > > 1. Create a qcow2 file via qemu-img > > sudo qemu-img create -f qcow2 -o cluster_size=524288 base.qcow2 1G > > 2. Connect this qcow2 file with qemu-nbd > > sudo qemu-nbd -c /dev/nbd0 base.qcow2 --discard=unmap > > 3. Use sg_unmap command to issue UNMAP command to this NBD > > sudo sg_unmap --lba=0 --num=1 /dev/nbd0 > > Everytime I get the following error message: > > unmap cdb: 42 00 00 00 00 00 00 00 18 00 > unmap: pass through os error: Inappropriate ioctl for device > UNMAP failed (use '-v' to get more information) > > I also try to format this nbd device with EXT4 and mount it, but still > cannot perform fstrim on the mount point. NBD isn't a SCSI device so sending UNMAP commands doesn't work. I think you need to issue ioctl(BLKDISCARD) instead. See blkdiscard(8). Also, make sure to use qemu.git/master if you want qcow2 discard support. I didn't check the details but the unmap implementation for qcow2 has recently been added/modified. Stefan