From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41624 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PaCUO-0002Au-EW for qemu-devel@nongnu.org; Tue, 04 Jan 2011 14:24:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PaCUM-00028X-7U for qemu-devel@nongnu.org; Tue, 04 Jan 2011 14:24:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PaCUL-00028O-Vn for qemu-devel@nongnu.org; Tue, 04 Jan 2011 14:24:10 -0500 From: Juan Quintela In-Reply-To: (Blue Swirl's message of "Tue, 4 Jan 2011 19:06:54 +0000") References: <95fe2a778152f50d942dcb17872927247195d0b1.1294150511.git.quintela@redhat.com> Date: Tue, 04 Jan 2011 20:23:11 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH 5/5] drive_open: Add invalidate option for block devices Reply-To: quintela@redhat.com List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org Blue Swirl wrote: > On Tue, Jan 4, 2011 at 2:33 PM, Juan Quintela wrote: >> Linux allows to invalidate block devices. =C2=A0This is needed for the i= ncoming >> migration part. >> >> Signed-off-by: Juan Quintela >> --- >> =C2=A0block.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A02 ++ >> =C2=A0block/raw-posix.c | =C2=A0 24 ++++++++++++++++++++++++ >> =C2=A0blockdev.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A09 +++++---- >> =C2=A03 files changed, 31 insertions(+), 4 deletions(-) >> >> diff --git a/block.h b/block.h >> index f923add..5ac96a5 100644 >> --- a/block.h >> +++ b/block.h >> @@ -34,6 +34,8 @@ typedef struct QEMUSnapshotInfo { >> =C2=A0#define BDRV_O_NATIVE_AIO =C2=A00x0080 /* use native AIO instead o= f the thread pool */ >> =C2=A0#define BDRV_O_NO_BACKING =C2=A00x0100 /* don't open the backing f= ile */ >> =C2=A0#define BDRV_O_NO_FLUSH =C2=A0 =C2=A00x0200 /* disable flushing on= this disk */ >> +#define BDRV_O_INVALIDATE =C2=A00x0400 /* invalidate buffer cache for t= his device. >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 re-read things from= server */ >> >> =C2=A0#define BDRV_O_CACHE_MASK =C2=A0(BDRV_O_NOCACHE | BDRV_O_CACHE_WB = | BDRV_O_NO_FLUSH) >> >> diff --git a/block/raw-posix.c b/block/raw-posix.c >> index 6b72470..9439cf1 100644 >> --- a/block/raw-posix.c >> +++ b/block/raw-posix.c >> @@ -51,6 +51,7 @@ >> =C2=A0#include >> =C2=A0#include >> =C2=A0#include >> +#include >> =C2=A0#endif >> =C2=A0#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) >> =C2=A0#include >> @@ -168,6 +169,29 @@ static int raw_open_common(BlockDriverState *bs, co= nst char *filename, >> =C2=A0 =C2=A0 s->fd =3D fd; >> =C2=A0 =C2=A0 s->aligned_buf =3D NULL; >> >> +#ifdef __linux__ >> + =C2=A0 =C2=A0if ((bdrv_flags & BDRV_O_INVALIDATE)) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0struct stat buf; >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0int res; >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0res =3D fstat(fd, &buf); >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (res < 0) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -errno; >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (S_ISBLK(buf.st_mode)) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("we are in a block dev= ice: %s\n", filename); > > Leftover debugging? ouch, yes. thanks for the spotting. Later, Juan.