From nobody Wed Apr 16 08:01:17 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727324288670.9440451004546; Mon, 11 Jun 2018 07:28:44 -0700 (PDT) Received: from localhost ([::1]:49152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNoJ-0005qb-Dt for importer@patchew.org; Mon, 11 Jun 2018 10:28:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNm0-0004AC-8u for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNlz-0001XM-3v for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54472 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 1fSNlv-0001WB-S4; Mon, 11 Jun 2018 10:26:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7124B4022905; Mon, 11 Jun 2018 14:26:15 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19FF42028672; Mon, 11 Jun 2018 14:26:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:43 +0200 Message-Id: <20180611142611.6609-2-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 01/29] block/file-posix: Pass FD to locking helpers 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 , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" raw_apply_lock_bytes() and raw_check_lock_bytes() currently take a BDRVRawState *, but they only use the lock_fd field. During image creation, we do not have a BDRVRawState, but we do have an FD; so if we want to reuse the functions there, we should modify them to receive only the FD. Signed-off-by: Max Reitz Reviewed-by: Fam Zheng Message-id: 20180509215336.31304-2-mreitz@redhat.com Signed-off-by: Max Reitz --- block/file-posix.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 513d371bb1..7583bbfbb3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -643,7 +643,7 @@ typedef enum { * file; if @unlock =3D=3D true, also unlock the unneeded bytes. * @shared_perm_lock_bits is the mask of all permissions that are NOT shar= ed. */ -static int raw_apply_lock_bytes(BDRVRawState *s, +static int raw_apply_lock_bytes(int fd, uint64_t perm_lock_bits, uint64_t shared_perm_lock_bits, bool unlock, Error **errp) @@ -654,13 +654,13 @@ static int raw_apply_lock_bytes(BDRVRawState *s, PERM_FOREACH(i) { int off =3D RAW_LOCK_PERM_BASE + i; if (perm_lock_bits & (1ULL << i)) { - ret =3D qemu_lock_fd(s->lock_fd, off, 1, false); + ret =3D qemu_lock_fd(fd, off, 1, false); if (ret) { error_setg(errp, "Failed to lock byte %d", off); return ret; } } else if (unlock) { - ret =3D qemu_unlock_fd(s->lock_fd, off, 1); + ret =3D qemu_unlock_fd(fd, off, 1); if (ret) { error_setg(errp, "Failed to unlock byte %d", off); return ret; @@ -670,13 +670,13 @@ static int raw_apply_lock_bytes(BDRVRawState *s, PERM_FOREACH(i) { int off =3D RAW_LOCK_SHARED_BASE + i; if (shared_perm_lock_bits & (1ULL << i)) { - ret =3D qemu_lock_fd(s->lock_fd, off, 1, false); + ret =3D qemu_lock_fd(fd, off, 1, false); if (ret) { error_setg(errp, "Failed to lock byte %d", off); return ret; } } else if (unlock) { - ret =3D qemu_unlock_fd(s->lock_fd, off, 1); + ret =3D qemu_unlock_fd(fd, off, 1); if (ret) { error_setg(errp, "Failed to unlock byte %d", off); return ret; @@ -687,8 +687,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, } =20 /* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. = */ -static int raw_check_lock_bytes(BDRVRawState *s, - uint64_t perm, uint64_t shared_perm, +static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_per= m, Error **errp) { int ret; @@ -698,7 +697,7 @@ static int raw_check_lock_bytes(BDRVRawState *s, int off =3D RAW_LOCK_SHARED_BASE + i; uint64_t p =3D 1ULL << i; if (perm & p) { - ret =3D qemu_lock_fd_test(s->lock_fd, off, 1, true); + ret =3D qemu_lock_fd_test(fd, off, 1, true); if (ret) { char *perm_name =3D bdrv_perm_names(p); error_setg(errp, @@ -715,7 +714,7 @@ static int raw_check_lock_bytes(BDRVRawState *s, int off =3D RAW_LOCK_PERM_BASE + i; uint64_t p =3D 1ULL << i; if (!(shared_perm & p)) { - ret =3D qemu_lock_fd_test(s->lock_fd, off, 1, true); + ret =3D qemu_lock_fd_test(fd, off, 1, true); if (ret) { char *perm_name =3D bdrv_perm_names(p); error_setg(errp, @@ -752,11 +751,11 @@ static int raw_handle_perm_lock(BlockDriverState *bs, =20 switch (op) { case RAW_PL_PREPARE: - ret =3D raw_apply_lock_bytes(s, s->perm | new_perm, + ret =3D raw_apply_lock_bytes(s->lock_fd, s->perm | new_perm, ~s->shared_perm | ~new_shared, false, errp); if (!ret) { - ret =3D raw_check_lock_bytes(s, new_perm, new_shared, errp); + ret =3D raw_check_lock_bytes(s->lock_fd, new_perm, new_shared,= errp); if (!ret) { return 0; } @@ -764,7 +763,8 @@ 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->perm, ~s->shared_perm, true, &local_err= ); + raw_apply_lock_bytes(s->lock_fd, s->perm, ~s->shared_perm, + true, &local_err); if (local_err) { /* Theoretically the above call only unlocks bytes and it cann= ot * fail. Something weird happened, report it. @@ -773,7 +773,8 @@ static int raw_handle_perm_lock(BlockDriverState *bs, } break; case RAW_PL_COMMIT: - raw_apply_lock_bytes(s, new_perm, ~new_shared, true, &local_err); + raw_apply_lock_bytes(s->lock_fd, new_perm, ~new_shared, + true, &local_err); if (local_err) { /* Theoretically the above call only unlocks bytes and it cann= ot * fail. Something weird happened, report it. --=20 2.17.1