From nobody Wed Nov 5 13:32:31 2025 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534485014206593.3045523788029; Thu, 16 Aug 2018 22:50:14 -0700 (PDT) Received: from localhost ([::1]:60093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqXe9-0006Mw-3t for importer@patchew.org; Fri, 17 Aug 2018 01:50:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqXcR-0005Pf-5T for qemu-devel@nongnu.org; Fri, 17 Aug 2018 01:48:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqXcQ-00037j-8w for qemu-devel@nongnu.org; Fri, 17 Aug 2018 01:48:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39886 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fqXcO-00033x-8l; Fri, 17 Aug 2018 01:48:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA1957A7E8; Fri, 17 Aug 2018 05:48:15 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-174.pek2.redhat.com [10.72.12.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id 133AF10EE837; Fri, 17 Aug 2018 05:48:12 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 17 Aug 2018 13:47:57 +0800 Message-Id: <20180817054758.14515-3-famz@redhat.com> In-Reply-To: <20180817054758.14515-1-famz@redhat.com> References: <20180817054758.14515-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 17 Aug 2018 05:48:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 17 Aug 2018 05:48:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 2/3] file-posix: Drop s->lock_fd 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 , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The lock_fd field is not strictly necessary because transferring locked bytes from old fd to the new one shouldn't fail anyway. This spares the user one fd per image. Signed-off-by: Fam Zheng --- block/file-posix.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index f062e477e9..26d4e487d2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -142,7 +142,6 @@ do { \ =20 typedef struct BDRVRawState { int fd; - int lock_fd; bool use_lock; int type; int open_flags; @@ -153,7 +152,7 @@ typedef struct BDRVRawState { uint64_t shared_perm; =20 /* The perms bits whose corresponding bytes are already locked in - * s->lock_fd. */ + * s->fd. */ uint64_t locked_perm; uint64_t locked_shared_perm; =20 @@ -542,18 +541,6 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, } s->fd =3D fd; =20 - s->lock_fd =3D -1; - if (s->use_lock) { - fd =3D qemu_open(filename, s->open_flags); - if (fd < 0) { - ret =3D -errno; - error_setg_errno(errp, errno, "Could not open '%s' for locking= ", - filename); - qemu_close(s->fd); - goto fail; - } - s->lock_fd =3D fd; - } s->perm =3D 0; s->shared_perm =3D BLK_PERM_ALL; =20 @@ -818,15 +805,13 @@ static int raw_handle_perm_lock(BlockDriverState *bs, return 0; } =20 - assert(s->lock_fd > 0); - switch (op) { case RAW_PL_PREPARE: - ret =3D raw_apply_lock_bytes(s, s->lock_fd, s->perm | new_perm, + ret =3D raw_apply_lock_bytes(s, s->fd, s->perm | new_perm, ~s->shared_perm | ~new_shared, false, errp); if (!ret) { - ret =3D raw_check_lock_bytes(s->lock_fd, new_perm, new_shared,= errp); + ret =3D raw_check_lock_bytes(s->fd, new_perm, new_shared, errp= ); if (!ret) { return 0; } @@ -834,7 +819,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs, op =3D RAW_PL_ABORT; /* fall through to unlock bytes. */ case RAW_PL_ABORT: - raw_apply_lock_bytes(s, s->lock_fd, s->perm, ~s->shared_perm, + raw_apply_lock_bytes(s, s->fd, s->perm, ~s->shared_perm, true, &local_err); if (local_err) { /* Theoretically the above call only unlocks bytes and it cann= ot @@ -844,7 +829,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs, } break; case RAW_PL_COMMIT: - raw_apply_lock_bytes(s, s->lock_fd, new_perm, ~new_shared, + raw_apply_lock_bytes(s, s->fd, new_perm, ~new_shared, true, &local_err); if (local_err) { /* Theoretically the above call only unlocks bytes and it cann= ot @@ -956,10 +941,18 @@ static void raw_reopen_commit(BDRVReopenState *state) { BDRVRawReopenState *rs =3D state->opaque; BDRVRawState *s =3D state->bs->opaque; + Error *local_err =3D NULL; =20 s->check_cache_dropped =3D rs->check_cache_dropped; s->open_flags =3D rs->open_flags; =20 + /* Copy locks to the new fd before closing the old one. */ + raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm, + ~s->locked_shared_perm, false, &local_err); + if (local_err) { + /* shouldn't fail in a sane host, but report it just in case. */ + error_report_err(local_err); + } qemu_close(s->fd); s->fd =3D rs->fd; =20 @@ -1952,10 +1945,6 @@ static void raw_close(BlockDriverState *bs) qemu_close(s->fd); s->fd =3D -1; } - if (s->lock_fd >=3D 0) { - qemu_close(s->lock_fd); - s->lock_fd =3D -1; - } } =20 /** --=20 2.17.1