From nobody Sat May 4 09:15:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494842861830754.8850316260737; Mon, 15 May 2017 03:07:41 -0700 (PDT) Received: from localhost ([::1]:35781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dACui-0005Wb-Cm for importer@patchew.org; Mon, 15 May 2017 06:07:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dACq5-0001rG-AO for qemu-devel@nongnu.org; Mon, 15 May 2017 06:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dACq2-0006Qa-8X for qemu-devel@nongnu.org; Mon, 15 May 2017 06:02:53 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:49534 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dACq1-0006Q8-Vk for qemu-devel@nongnu.org; Mon, 15 May 2017 06:02:50 -0400 Received: (qmail 1605 invoked by uid 89); 15 May 2017 10:02:47 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23388. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.049747 secs); 15 May 2017 10:02:47 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 15 May 2017 10:02:47 -0000 Received: (qmail 2430 invoked from network); 15 May 2017 10:02:46 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 15 May 2017 10:02:46 -0000 Received: by lieven-pc (Postfix, from userid 1000) id DF06221D2E; Mon, 15 May 2017 12:02:46 +0200 (CEST) X-GL_Whitelist: yes From: Peter Lieven To: qemu-block@nongnu.org Date: Mon, 15 May 2017 12:02:43 +0200 Message-Id: <1494842563-6534-1-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [RFC PATCH] qemu-io: add drain/undrain cmd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Lieven , qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Hi Block developers, I would like to add a feature to Qemu to drain all traffic from a block so = that I can take external snaphosts without the risk to that in the middle of a w= rite operation. Its meant for cases where where QGA freeze/thaw is not available. For me its enough to have this through qemu-io, but Kevin asked me to check if its not worth to have a stable API for it and present it via QMP/HMP. What are your thoughts? Thanks, Peter --- qemu-io-cmds.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 78 insertions(+) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 312fc6d..49d82fe 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1565,6 +1565,82 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 +static const cmdinfo_t drain_cmd; + +static int drain_f(BlockBackend *blk, int argc, char **argv) +{ + BlockDriverState *bs =3D blk_bs(blk); + bool flush =3D false; + int c; + + while ((c =3D getopt(argc, argv, "f")) !=3D -1) { + switch (c) { + case 'f': + flush =3D true; + break; + default: + return qemuio_command_usage(&drain_cmd); + } + } + + if (optind !=3D argc) { + return qemuio_command_usage(&drain_cmd); + } + + + if (bs->quiesce_counter) { + printf("drain failed: device is already drained!\n"); + return 1; + } + + bdrv_drained_begin(bs); /* complete I/O */ + if (flush) { + bdrv_flush(bs); + bdrv_drain(bs); /* in case flush left pending I/O */ + printf("flushed all pending I/O\n"); + } + printf("drain successful\n"); + return 0; +} + +static void drain_help(void) +{ + printf( +"\n" +" Drains all external I/O from the device\n" +"\n" +" -f, -- flush all in-core file state to disk\n" +"\n"); +} + +static const cmdinfo_t drain_cmd =3D { + .name =3D "drain", + .cfunc =3D drain_f, + .args =3D "[-f]", + .argmin =3D 0, + .argmax =3D -1, + .oneline =3D "cease to send I/O to the device", + .help =3D drain_help +}; + +static int undrain_f(BlockBackend *blk, int argc, char **argv) +{ + BlockDriverState *bs =3D blk_bs(blk); + if (!bs->quiesce_counter) { + printf("undrain failed: device is not drained!\n"); + return 1; + } + bdrv_drained_end(bs); + printf("undrain successful\n"); + return 0; +} + +static const cmdinfo_t undrain_cmd =3D { + .name =3D "undrain", + .cfunc =3D undrain_f, + .oneline =3D "continue I/O to a drained device", +}; + static int truncate_f(BlockBackend *blk, int argc, char **argv) { int64_t offset; @@ -2296,6 +2372,8 @@ static void __attribute((constructor)) init_qemuio_co= mmands(void) qemuio_add_command(&aio_write_cmd); qemuio_add_command(&aio_flush_cmd); qemuio_add_command(&flush_cmd); + qemuio_add_command(&drain_cmd); + qemuio_add_command(&undrain_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); --=20 1.9.1