From patchwork Thu Jun 21 22:21:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10480795 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 0A0C9604D3 for ; Thu, 21 Jun 2018 22:22:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE60628F92 for ; Thu, 21 Jun 2018 22:22:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1D5628F95; Thu, 21 Jun 2018 22:22:57 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 6A05328F92 for ; Thu, 21 Jun 2018 22:22:57 +0000 (UTC) Received: from localhost ([::1]:57810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fW7yi-0005Zs-3P for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jun 2018 18:22:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fW7xs-00056E-DB for qemu-devel@nongnu.org; Thu, 21 Jun 2018 18:22:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fW7xr-0008KG-2A for qemu-devel@nongnu.org; Thu, 21 Jun 2018 18:22:04 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:43278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fW7xq-0008J1-Ru for qemu-devel@nongnu.org; Thu, 21 Jun 2018 18:22:02 -0400 Received: by mail-pg0-x241.google.com with SMTP id a14-v6so2030825pgw.10 for ; Thu, 21 Jun 2018 15:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digitalocean.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Lm1SmP0GWAb8RzHozgxUy/zrAvWndyRRpbgBBsOetMk=; b=PaRpDiJV+RsAPD1zh7OFtGUGpMF0gtxmELHZ029nNOsoQ/vItYiSiSJLuCkalhwzyO 7RCRJUy62bx1J9CmrCb0LeNtCOrnxZV94aDLOpUeAEOsMyHR1fReRmoXbHespo0fDVqx A/lCiliMdHXyj5rcuzqkPl3mrYLF2kPFWNqVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Lm1SmP0GWAb8RzHozgxUy/zrAvWndyRRpbgBBsOetMk=; b=d9M38RQz+qJsCy4mxo5+FhKoH3EkY3szyETjA/9jeH5NlKDjh8Yl/lDPH2FswixJi0 tY0JhPHu4Mep5Lyetq2sJNlSc5qyRj4dQgfykwv+vkAbDACbmjNmv6yn0BZBhfu5vfu0 pdS0+Nr/8IHdoE6Cvkge38WOBiPcSC4m/F+Fep6nsiWQFW8fA/BHhI4c6y+Bmvl2kTwV v0/cqdmEvZIgWEMbvuRSrJtn7vfUEYrfAKZ5BxYlZGgSaeitAhasB27wrFmWPeE1nF6l dasO5AqTgG+6Q4FUi/U6/Gph82k2Krlj9mjC+mhGN++gBvdlgygHKmUgnPgrXjp848+Y ST1Q== X-Gm-Message-State: APt69E2s1J9S0x14f0Zt3X+6fZdYxynlGbGWouwEfE+RSgCzPhNpiyGM xxy+/gga1MNN+aA71ti2Gwnatg== X-Google-Smtp-Source: ADUXVKIS2jHscz8/Unz1mXK1tWvWOSkxyTptxv5c8qexxnIWoZ7Fh9esHeEza4BPB/tC5n821HZw5g== X-Received: by 2002:a62:c809:: with SMTP id z9-v6mr28885484pff.5.1529619721979; Thu, 21 Jun 2018 15:22:01 -0700 (PDT) Received: from breakout.internal.digitalocean.com (97-120-190-204.ptld.qwest.net. [97.120.190.204]) by smtp.gmail.com with ESMTPSA id l8-v6sm12790096pfb.102.2018.06.21.15.22.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Jun 2018 15:22:01 -0700 (PDT) Received: by breakout.internal.digitalocean.com (Postfix, from userid 1000) id D0A008A2A84; Thu, 21 Jun 2018 15:22:00 -0700 (PDT) To: naravamudan@digitalocean.com Date: Thu, 21 Jun 2018 15:21:43 -0700 Message-Id: <20180621222143.27266-3-naravamudan@digitalocean.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180621222143.27266-1-naravamudan@digitalocean.com> References: <20180621222143.27266-1-naravamudan@digitalocean.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH v3 2/2] block/file-posix: reconfigure aio on iothread start 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: , X-Patchwork-Original-From: Nishanth Aravamudan via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: Nishanth Aravamudan Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When the AioContext changes, we need to associate a LinuxAioState with the new AioContext. Use the bdrv_attach_aio_context callback and call the new aio_setup_linux_aio(), which will allocate a new AioContext if needed, and return errors on failures. If it fails for any reason, fallback to threaded AIO with an error message, as the device is already in-use by the guest. Signed-off-by: Nishanth Aravamudan --- Note this patch didn't exist in v2, but is a result of feedback to that posting. block/file-posix.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 6a1714d4a8..ce24950acf 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1730,6 +1730,21 @@ static BlockAIOCB *raw_aio_flush(BlockDriverState *bs, return paio_submit(bs, s->fd, 0, NULL, 0, cb, opaque, QEMU_AIO_FLUSH); } +static void raw_aio_attach_aio_context(BlockDriverState *bs, + AioContext *new_context) +{ +#ifdef CONFIG_LINUX_AIO + BDRVRawState *s = bs->opaque; + if (s->use_linux_aio) { + if (aio_setup_linux_aio(new_context) != 0) { + error_report("Unable to use native AIO, falling back to " + "thread pool"); + s->use_linux_aio = false; + } + } +#endif +} + static void raw_close(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -2608,6 +2623,7 @@ BlockDriver bdrv_file = { .bdrv_refresh_limits = raw_refresh_limits, .bdrv_io_plug = raw_aio_plug, .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength,