From patchwork Wed May 8 18:25:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 10936411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25C5813AD for ; Wed, 8 May 2019 18:27:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B5AF28734 for ; Wed, 8 May 2019 18:27:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FB1A28737; Wed, 8 May 2019 18:27:29 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B5CCE28734 for ; Wed, 8 May 2019 18:27:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:41456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hORHs-00061d-1l for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 May 2019 14:27:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hORGQ-0004N5-8z for qemu-devel@nongnu.org; Wed, 08 May 2019 14:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hORGP-0002yg-9A for qemu-devel@nongnu.org; Wed, 08 May 2019 14:25:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31579) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hORGM-0002sR-J2; Wed, 08 May 2019 14:25:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5D46301EA90; Wed, 8 May 2019 18:25:53 +0000 (UTC) Received: from localhost (ovpn-204-94.brq.redhat.com [10.40.204.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6283362672; Wed, 8 May 2019 18:25:53 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 8 May 2019 20:25:40 +0200 Message-Id: <20190508182546.2239-2-mreitz@redhat.com> In-Reply-To: <20190508182546.2239-1-mreitz@redhat.com> References: <20190508182546.2239-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 May 2019 18:25:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/7] file-posix: Update open_flags in raw_set_perm() 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: Kevin Wolf , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP raw_check_perm() + raw_set_perm() can change the flags associated with the current FD. If so, we have to update BDRVRawState.open_flags accordingly. Otherwise, we may keep reopening the FD even though the current one already has the correct flags. Signed-off-by: Max Reitz Reviewed-by: Kevin Wolf --- block/file-posix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 1cf4ee49eb..3e859c4b9f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -145,6 +145,7 @@ typedef struct BDRVRawState { uint64_t locked_shared_perm; int perm_change_fd; + int perm_change_flags; BDRVReopenState *reopen_state; #ifdef CONFIG_XFS @@ -2754,6 +2755,7 @@ static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared, assert(s->reopen_state->shared_perm == shared); rs = s->reopen_state->opaque; s->perm_change_fd = rs->fd; + s->perm_change_flags = rs->open_flags; } else { /* We may need a new fd if auto-read-only switches the mode */ ret = raw_reconfigure_getfd(bs, bs->open_flags, &open_flags, perm, @@ -2762,6 +2764,7 @@ static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared, return ret; } else if (ret != s->fd) { s->perm_change_fd = ret; + s->perm_change_flags = open_flags; } } @@ -2800,6 +2803,7 @@ static void raw_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared) if (s->perm_change_fd && s->fd != s->perm_change_fd) { qemu_close(s->fd); s->fd = s->perm_change_fd; + s->open_flags = s->perm_change_flags; } s->perm_change_fd = 0;