From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W45Eb-0007pl-N0 for qemu-devel@nongnu.org; Fri, 17 Jan 2014 03:57:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W45ET-0006sq-Al for qemu-devel@nongnu.org; Fri, 17 Jan 2014 03:57:01 -0500 Received: from mail-ea0-x235.google.com ([2a00:1450:4013:c01::235]:45729) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W45ET-0006sD-3s for qemu-devel@nongnu.org; Fri, 17 Jan 2014 03:56:53 -0500 Received: by mail-ea0-f181.google.com with SMTP id m10so1617652eaj.12 for ; Fri, 17 Jan 2014 00:56:52 -0800 (PST) Date: Fri, 17 Jan 2014 16:56:42 +0800 From: Stefan Hajnoczi Message-ID: <20140117085642.GD31039@stefanha-thinkpad.redhat.com> References: <8ff0f6493e8ad300948cb1e2c8fd45f82e265ac4.1388112645.git.hutao@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8ff0f6493e8ad300948cb1e2c8fd45f82e265ac4.1388112645.git.hutao@cn.fujitsu.com> Subject: Re: [Qemu-devel] [RFC PATCH v4 3/4] raw-posix: Add full image preallocation option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao Cc: Kevin Wolf , Fam Zheng , Peter Lieven , qemu-devel@nongnu.org On Fri, Dec 27, 2013 at 11:05:53AM +0800, Hu Tao wrote: > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 6f6b8c1..a722d27 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -1160,17 +1160,52 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs) > return (int64_t)st.st_blocks * 512; > } > > +#ifdef __linux__ > +static int raw_preallocate2(int fd, int64_t offset, int64_t length) > +{ > + int ret = -1; > + > + ret = fallocate(fd, 0, offset, length); > + if (ret < 0) { > + ret = -errno; > + } > + > + /* fallback to posix_fallocate() if fallocate() is not supported */ > + if (ret == -ENOSYS || ret == -EOPNOTSUPP) { > + ret = posix_fallocate(fd, offset, length); > + } > + > + return ret; > +} Why is this Linux-specific #ifdef necessary? glibc will try to use the fallocate(2) system call, if possible. Stefan