From patchwork Mon May 15 10:02:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 9726639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C53B60231 for ; Mon, 15 May 2017 10:07:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDF6628979 for ; Mon, 15 May 2017 10:07:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E065D28980; Mon, 15 May 2017 10:07:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 42B4128979 for ; Mon, 15 May 2017 10:07:13 +0000 (UTC) Received: from localhost ([::1]:35772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dACuG-0004ZI-Ev for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 May 2017 06:07:12 -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 X-GL_Whitelist: yes 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 write 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 = { .oneline = "flush all in-core file state to disk", }; +static const cmdinfo_t drain_cmd; + +static int drain_f(BlockBackend *blk, int argc, char **argv) +{ + BlockDriverState *bs = blk_bs(blk); + bool flush = false; + int c; + + while ((c = getopt(argc, argv, "f")) != -1) { + switch (c) { + case 'f': + flush = true; + break; + default: + return qemuio_command_usage(&drain_cmd); + } + } + + if (optind != 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 = { + .name = "drain", + .cfunc = drain_f, + .args = "[-f]", + .argmin = 0, + .argmax = -1, + .oneline = "cease to send I/O to the device", + .help = drain_help +}; + +static int undrain_f(BlockBackend *blk, int argc, char **argv) +{ + BlockDriverState *bs = 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 = { + .name = "undrain", + .cfunc = undrain_f, + .oneline = "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_commands(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);