From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174032; cv=none; d=zohomail.com; s=zohoarc; b=X7u7PosIId8FUG0E09QIVJ+YMz3ndaRBK/bUp3cxvUJHqDIjBiyEwIKHMKW7IG+ogdCu5GZu8i95JVqX3HgPSKMIkLmVus9u0+eUNDlyVjrgYXANxWZ1/uWrzygJ9SHBnKj3oHBsdPIvQL/2ZV6o3km3qT0rsMkV3BMSO+RzZ0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174032; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/qu8+iAK0K9N+HN9c0K7jCKPaWH/4uiuQLwNM1E1UA8=; b=Zdd/3BHRW/gi8FFUFK7llW6dA1SNANa2TD9evtG09cTftLSIFNhiZSGqSXbA1O6KRQEkLk80SpNZN4tmIt7NN9kJSLxTchTOYq2Ec3+UvCMJmYTCyQkwrUkidmQJlNbRAXqmeXcUiTb9svSQ7VMJC2/BtFwTa9xcNDKPRB7s4hE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174032689627.9761888603574; Wed, 8 May 2024 06:13:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5r-0005DD-G8; Wed, 08 May 2024 09:12:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dke-0007QX-Dv for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:16 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dka-0000Wa-4V for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:15 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ec486198b6so34622715ad.1 for ; Wed, 08 May 2024 02:38:11 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161091; x=1715765891; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/qu8+iAK0K9N+HN9c0K7jCKPaWH/4uiuQLwNM1E1UA8=; b=FUPtMDGNKhjLO+C8IlQDhW5qfL//8P0HzsLL8iWDysA1FwYmgoOSwZTsxr/yQGmpY3 0ZKDp5nJmlXlJAg2xWj4nWqVKt3BVEFMvCARrnk+EOpOA5L4u60myuniLl+iiwTiVZer 1V7Yto2NvBJmlsaOWY4IvkrSrGPTvss4WOYGbsfaeHZtQBiszcwHXec2mjw5ms3MduYE 5LKbfxKc4btanmrVcS1+wtvT6MPQVqwLz05LfZ8ZGE9ACwgHFNmU4kW2VV0Q2j7ereuJ nTSUU52NkxtZpcnw52k0uuh1fJ43ZS3uasmd1H+iyoK1kcdIImrlu4Ok0BPf96LLJ0KC NhFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161091; x=1715765891; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/qu8+iAK0K9N+HN9c0K7jCKPaWH/4uiuQLwNM1E1UA8=; b=qYp0yf5LMqj+8PKwBieORJZ1qa1/zNErp1Son3jJrYrQehQCVlu1qobbJTPGVCdCtS goHfZRGuCD7vKv90M1oj4zz5yVdC1Ycw8XxAjvYOUyLMZI4aw/u8gsLP1WDwoxwD/uoE paUz5ZaSOR5PzkOU3h4nyZkOP9O07lB9n2zXdTHPVsVU6pSSK9r+boSdCzJ1XUb1n0Tb wJ4/QHkNeTzk4xtJ+S36VzIM41cySxqaxgs5pm6PCc4asz/IHn2nvLRf+C5tXMeCMpio gv9ZtWVxsnBlfo/qZiVA/i4csQNSn1lYgK/jmMsv7hhqakqv1KXd7YxcWwq+ryc6n4Ob BVCw== X-Forwarded-Encrypted: i=1; AJvYcCX9IMRdF6I8RHL7MORoXmkMlg++cqldPgr02vkaH7DEqrV4O7CnGnDVsT6P0jXAuIXXGbAE/+8AjsaKKozFtFmsrnUqHMk= X-Gm-Message-State: AOJu0YyA0f/+0kK7H832fkRq4czaBJGUzwJmFyDUEDxtAiN8w+w2qp/m /muEe7Uua96Sz/aRLUJpWCCeR989KDjz9IlXrZ1JfbYrjIKipRbBiaesYRTO4ME= X-Google-Smtp-Source: AGHT+IFEoRWrvLo1mPs+qu5kn151AA2H/k6dHAqweRFFn23DBgvySsCEjxU02FE5dF+FUE2gda2ZMw== X-Received: by 2002:a17:903:2301:b0:1eb:63d9:8d85 with SMTP id d9443c01a7336-1eeb03a5643mr25134625ad.14.1715161090714; Wed, 08 May 2024 02:38:10 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 1/9] block: add persistent reservation in/out api Date: Wed, 8 May 2024 17:36:21 +0800 Message-Id: <20240508093629.441057-2-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=luchangqi.123@bytedance.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174034856100003 Content-Type: text/plain; charset="utf-8" Add persistent reservation in/out operations at the block level. The following operations are included: - read_keys: retrieves the list of registered keys. - read_reservation: retrieves the current reservation status. - register: registers a new reservation key. - reserve: initiates a reservation for a specific key. - release: releases a reservation for a specific key. - clear: clears all existing reservations. - preempt: preempts a reservation held by another key. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi --- block/block-backend.c | 386 ++++++++++++++++++++++++++++++ block/io.c | 161 +++++++++++++ include/block/block-common.h | 9 + include/block/block-io.h | 19 ++ include/block/block_int-common.h | 31 +++ include/sysemu/block-backend-io.h | 22 ++ 6 files changed, 628 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index db6f9b92a3..ec67937d28 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1770,6 +1770,392 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsign= ed long int req, void *buf, return blk_aio_prwv(blk, req, 0, buf, blk_aio_ioctl_entry, 0, cb, opaq= ue); } =20 +typedef struct BlkPrInCo { + BlockBackend *blk; + uint32_t *generation; + uint32_t num_keys; + BlockPrType *type; + uint64_t *keys; + int ret; +} BlkPrInCo; + +typedef struct BlkPrInCB { + BlockAIOCB common; + BlkPrInCo prco; + bool has_returned; +} BlkPrInCB; + +static const AIOCBInfo blk_pr_in_aiocb_info =3D { + .aiocb_size =3D sizeof(BlkPrInCB), +}; + +static void blk_pr_in_complete(BlkPrInCB *acb) +{ + if (acb->has_returned) { + acb->common.cb(acb->common.opaque, acb->prco.ret); + blk_dec_in_flight(acb->prco.blk); + qemu_aio_unref(acb); + } +} + +static void blk_pr_in_complete_bh(void *opaque) +{ + BlkPrInCB *acb =3D opaque; + assert(acb->has_returned); + blk_pr_in_complete(acb); +} + +static BlockAIOCB *blk_aio_pr_in(BlockBackend *blk, uint32_t *generation, + uint32_t num_keys, BlockPrType *type, + uint64_t *keys, CoroutineEntry co_entry, + BlockCompletionFunc *cb, void *opaque) +{ + BlkPrInCB *acb; + Coroutine *co; + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_pr_in_aiocb_info, blk, cb, opaque); + acb->prco =3D (BlkPrInCo) { + .blk =3D blk, + .generation =3D generation, + .num_keys =3D num_keys, + .type =3D type, + .ret =3D NOT_DONE, + .keys =3D keys, + }; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(co_entry, acb); + aio_co_enter(qemu_get_current_aio_context(), co); + + acb->has_returned =3D true; + if (acb->prco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), + blk_pr_in_complete_bh, acb); + } + + return &acb->common; +} + + +static int coroutine_fn +blk_aio_pr_do_read_keys(BlockBackend *blk, uint32_t *generation, + uint32_t num_keys, uint64_t *keys) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_read_keys(blk_bs(blk), generation, num_keys, keys); +} + +static void coroutine_fn blk_aio_pr_read_keys_entry(void *opaque) +{ + BlkPrInCB *acb =3D opaque; + BlkPrInCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_read_keys(prco->blk, prco->generation, + prco->num_keys, prco->keys); + blk_pr_in_complete(acb); +} + +BlockAIOCB *blk_aio_pr_read_keys(BlockBackend *blk, uint32_t *generation, + uint32_t num_keys, uint64_t *keys, + BlockCompletionFunc *cb, void *opaque) +{ + IO_CODE(); + return blk_aio_pr_in(blk, generation, num_keys, NULL, keys, + blk_aio_pr_read_keys_entry, cb, opaque); +} + + +static int coroutine_fn +blk_aio_pr_do_read_reservation(BlockBackend *blk, uint32_t *generation, + uint64_t *key, BlockPrType *type) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_read_reservation(blk_bs(blk), generation, key, type); +} + +static void coroutine_fn blk_aio_pr_read_reservation_entry(void *opaque) +{ + BlkPrInCB *acb =3D opaque; + BlkPrInCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_read_reservation(prco->blk, prco->generati= on, + prco->keys, prco->type); + blk_pr_in_complete(acb); +} + +BlockAIOCB *blk_aio_pr_read_reservation(BlockBackend *blk, uint32_t *gener= ation, + uint64_t *key, BlockPrType *type, + BlockCompletionFunc *cb, void *opa= que) +{ + IO_CODE(); + return blk_aio_pr_in(blk, generation, 0, type, key, + blk_aio_pr_read_reservation_entry, cb, opaque); +} + + +typedef struct BlkPrOutCo { + BlockBackend *blk; + uint64_t old_key; + uint64_t new_key; + BlockPrType type; + bool ignore_key; + bool abort; + int ret; +} BlkPrOutCo; + +typedef struct BlkPrOutCB { + BlockAIOCB common; + BlkPrOutCo prco; + bool has_returned; +} BlkPrOutCB; + +static const AIOCBInfo blk_pr_out_aiocb_info =3D { + .aiocb_size =3D sizeof(BlkPrOutCB), +}; + +static void blk_pr_out_complete(BlkPrOutCB *acb) +{ + if (acb->has_returned) { + acb->common.cb(acb->common.opaque, acb->prco.ret); + blk_dec_in_flight(acb->prco.blk); + qemu_aio_unref(acb); + } +} + +static void blk_pr_out_complete_bh(void *opaque) +{ + BlkPrOutCB *acb =3D opaque; + assert(acb->has_returned); + blk_pr_out_complete(acb); +} + +static BlockAIOCB *blk_aio_pr_out(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, + bool ignore_key, bool abort, + CoroutineEntry co_entry, + BlockCompletionFunc *cb, void *opaque) +{ + BlkPrOutCB *acb; + Coroutine *co; + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_pr_out_aiocb_info, blk, cb, opaque); + acb->prco =3D (BlkPrOutCo) { + .blk =3D blk, + .old_key =3D old_key, + .new_key =3D new_key, + .type =3D type, + .ignore_key =3D ignore_key, + .abort =3D abort, + .ret =3D NOT_DONE, + }; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(co_entry, acb); + aio_co_enter(qemu_get_current_aio_context(), co); + + acb->has_returned =3D true; + if (acb->prco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), + blk_pr_out_complete_bh, acb); + } + + return &acb->common; +} + +static int coroutine_fn +blk_aio_pr_do_register(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, + bool ignore_key) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_register(blk_bs(blk), old_key, new_key, type, ignore= _key); +} + +static void coroutine_fn blk_aio_pr_register_entry(void *opaque) +{ + BlkPrOutCB *acb =3D opaque; + BlkPrOutCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_register(prco->blk, prco->old_key, prco->n= ew_key, + prco->type, prco->ignore_key); + blk_pr_out_complete(acb); +} + +BlockAIOCB *blk_aio_pr_register(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, + bool ignore_key, BlockCompletionFunc *cb, + void *opaque) +{ + IO_CODE(); + return blk_aio_pr_out(blk, old_key, new_key, type, ignore_key, false, + blk_aio_pr_register_entry, cb, opaque); +} + +static int coroutine_fn +blk_aio_pr_do_reserve(BlockBackend *blk, uint64_t key, BlockPrType type) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_reserve(blk_bs(blk), key, type); +} + +static void coroutine_fn blk_aio_pr_reserve_entry(void *opaque) +{ + BlkPrOutCB *acb =3D opaque; + BlkPrOutCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_reserve(prco->blk, prco->old_key, prco->ty= pe); + blk_pr_out_complete(acb); +} + + +BlockAIOCB *blk_aio_pr_reserve(BlockBackend *blk, uint64_t key, + BlockPrType type, BlockCompletionFunc *cb, + void *opaque) +{ + IO_CODE(); + return blk_aio_pr_out(blk, key, 0, type, false, false, + blk_aio_pr_reserve_entry, cb, opaque); +} + +static int coroutine_fn +blk_aio_pr_do_release(BlockBackend *blk, uint64_t key, BlockPrType type) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_release(blk_bs(blk), key, type); +} + +static void coroutine_fn blk_aio_pr_release_entry(void *opaque) +{ + BlkPrOutCB *acb =3D opaque; + BlkPrOutCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_release(prco->blk, prco->old_key, prco->ty= pe); + blk_pr_out_complete(acb); +} + + +BlockAIOCB *blk_aio_pr_release(BlockBackend *blk, uint64_t key, + BlockPrType type, BlockCompletionFunc *cb, + void *opaque) +{ + IO_CODE(); + return blk_aio_pr_out(blk, key, 0, type, false, false, + blk_aio_pr_release_entry, cb, opaque); +} + +static int coroutine_fn +blk_aio_pr_do_clear(BlockBackend *blk, uint64_t key) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_clear(blk_bs(blk), key); +} + +static void coroutine_fn blk_aio_pr_clear_entry(void *opaque) +{ + BlkPrOutCB *acb =3D opaque; + BlkPrOutCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_clear(prco->blk, prco->old_key); + blk_pr_out_complete(acb); +} + + +BlockAIOCB *blk_aio_pr_clear(BlockBackend *blk, uint64_t key, + BlockCompletionFunc *cb, void *opaque) +{ + IO_CODE(); + return blk_aio_pr_out(blk, key, 0, 0, false, false, + blk_aio_pr_clear_entry, cb, opaque); +} + +static int coroutine_fn +blk_aio_pr_do_preempt(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool abort) +{ + IO_CODE(); + + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + if (!blk_co_is_available(blk)) { + return -ENOMEDIUM; + } + + return bdrv_co_pr_preempt(blk_bs(blk), old_key, new_key, type, abort); +} + +static void coroutine_fn blk_aio_pr_preempt_entry(void *opaque) +{ + BlkPrOutCB *acb =3D opaque; + BlkPrOutCo *prco =3D &acb->prco; + + prco->ret =3D blk_aio_pr_do_preempt(prco->blk, prco->old_key, + prco->new_key, prco->type, + prco->abort); + blk_pr_out_complete(acb); +} + + +BlockAIOCB *blk_aio_pr_preempt(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, + bool abort, BlockCompletionFunc *cb, + void *opaque) +{ + IO_CODE(); + return blk_aio_pr_out(blk, old_key, new_key, type, false, abort, + blk_aio_pr_preempt_entry, cb, opaque); +} + /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes) diff --git a/block/io.c b/block/io.c index 7217cf811b..98a358c6b2 100644 --- a/block/io.c +++ b/block/io.c @@ -3220,6 +3220,167 @@ out: return co.ret; } =20 +int coroutine_fn bdrv_co_pr_read_keys(BlockDriverState *bs, + uint32_t *generation, uint32_t num_keys, + uint64_t *keys) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_read_keys) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_read_keys(bs, generation, num_keys, keys); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_pr_read_reservation(BlockDriverState *bs, + uint32_t *generation, uint64_t *key, BlockPrType *type) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_read_reservation) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_read_reservation(bs, generation, key, type); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_pr_register(BlockDriverState *bs, uint64_t old_ke= y, + uint64_t new_key, BlockPrType type, bool ignore_key) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_register) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_register(bs, old_key, new_key, type, ignore= _key); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_pr_reserve(BlockDriverState *bs, uint64_t key, + BlockPrType type) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_reserve) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_reserve(bs, key, type); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_pr_release(BlockDriverState *bs, uint64_t key, + BlockPrType type) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_release) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_release(bs, key, type); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_pr_clear(BlockDriverState *bs, uint64_t key) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_clear) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_clear(bs, key); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_pr_preempt(BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool abort) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + IO_CODE(); + assert_bdrv_graph_readable(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_pr_preempt) { + co.ret =3D -ENOTSUP; + goto out; + } + + co.ret =3D drv->bdrv_co_pr_preempt(bs, old_key, new_key, type, abort); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, unsigned int *nr_zones, BlockZoneDescriptor *zones) diff --git a/include/block/block-common.h b/include/block/block-common.h index a846023a09..c078d69f79 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -524,6 +524,15 @@ typedef enum { BDRV_FIX_ERRORS =3D 2, } BdrvCheckMode; =20 +typedef enum { + BLK_PR_WRITE_EXCLUSIVE =3D 0x1, + BLK_PR_EXCLUSIVE_ACCESS =3D 0x2, + BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY =3D 0x3, + BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY =3D 0x4, + BLK_PR_WRITE_EXCLUSIVE_ALL_REGS =3D 0x5, + BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS =3D 0x6, +} BlockPrType; + typedef struct BlockSizes { uint32_t phys; uint32_t log; diff --git a/include/block/block-io.h b/include/block/block-io.h index b49e0537dd..f2827cd74e 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -106,6 +106,25 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int coroutine_fn GRAPH_RDLOCK bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_read_keys(BlockDriverState *bs, uint32_t *generation, + uint32_t num_keys, uint64_t *keys); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_read_reservation(BlockDriverState *bs, uint32_t *generation, + uint64_t *key, BlockPrType *type); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_register(BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool ignore_key); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_reserve(BlockDriverState *bs, uint64_t key, BlockPrType type); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_release(BlockDriverState *bs, uint64_t key, BlockPrType type); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_clear(BlockDriverState *bs, uint64_t key); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pr_preempt(BlockDriverState *bs, uint64_t old_key, uint64_t new_ke= y, + BlockPrType type, bool abort); + /* Ensure contents are flushed to disk. */ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 761276127e..e5526f1d04 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -766,6 +766,37 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_ioctl)( BlockDriverState *bs, unsigned long int req, void *buf); =20 + /** + * bdrv_co_pr_read_keys is called to read the registered keys, + * @num_keys is the maximum number of keys that can be transmitted. + * On success, store generation in @generation and store keys @keys + * and return the number of @keys. + * On failure return -errno. + */ + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_read_keys)( + BlockDriverState *bs, uint32_t *generation, + uint32_t num_keys, uint64_t *keys); + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_read_reservation)( + BlockDriverState *bs, uint32_t *generation, + uint64_t *key, BlockPrType *type); + + /** + * Persist Through Power Loss(PTPL) is considered as required in QEMU + * block layer, the block driver need always enable PTPL. + */ + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_register)( + BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool ignore_key); + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_reserve)( + BlockDriverState *bs, uint64_t key, BlockPrType type); + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_release)( + BlockDriverState *bs, uint64_t key, BlockPrType type); + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_clear)( + BlockDriverState *bs, uint64_t key); + int coroutine_fn GRAPH_RDLOCK_PTR(*bdrv_co_pr_preempt)( + BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool abort); + /* * Returns 0 for completed check, -errno for internal errors. * The check results are stored in result. diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index d174275a5c..f87c61c06e 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -62,6 +62,28 @@ void blk_aio_cancel_async(BlockAIOCB *acb); BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *= buf, BlockCompletionFunc *cb, void *opaque); =20 +BlockAIOCB *blk_aio_pr_read_keys(BlockBackend *blk, uint32_t *generation, + uint32_t num_keys, uint64_t *keys, + BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_pr_read_reservation(BlockBackend *blk, uint32_t *gener= ation, + uint64_t *key, BlockPrType *type, + BlockCompletionFunc *cb, void *opa= que); +BlockAIOCB *blk_aio_pr_register(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, + bool ignore_key, BlockCompletionFunc *cb, + void *opaque); +BlockAIOCB *blk_aio_pr_reserve(BlockBackend *blk, uint64_t key, + BlockPrType type, BlockCompletionFunc *cb, + void *opaque); +BlockAIOCB *blk_aio_pr_release(BlockBackend *blk, uint64_t key, + BlockPrType type, BlockCompletionFunc *cb, + void *opaque); +BlockAIOCB *blk_aio_pr_clear(BlockBackend *blk, uint64_t key, + BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_pr_preempt(BlockBackend *blk, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool ab= ort, + BlockCompletionFunc *cb, void *opaque); + void blk_inc_in_flight(BlockBackend *blk); void blk_dec_in_flight(BlockBackend *blk); =20 --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174065; cv=none; d=zohomail.com; s=zohoarc; b=jnRDPxknoj5kh7JYnLmNO+djEDIENrw2m77vvuzzqMPI5AKmeJSugLUXXZzhrz2LFR/SF0RGSa+0U/VuLT/57axFepMyz2EsKAYZuN9Y5nbU/kcBI258VFqxE06mXQ++Z/Cm22BLpcb87MjzGoqguFLZmfF48VJJ8uHXoSQWagM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174065; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=REjV3MNcFfq7gH+69GQ9Wyw9SNuTcZ130RuiQhIkTss=; b=fPM9PLvKT03ZE1su3N84gJmfCcRqzddwGDIT1GlxLZuZIQGxj5Un5IETAmWUO+0qrgRfemV9rj+/ZlOLh4QBFQ0TWQeJVhPqiEl6kj3euqEjTuEMTOig9lZHBdevDqwV2tWa8IkLRbhSIt1+luedK7eeiFGdDNgo0D6fIhzcGoA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174065520171.6418430930877; Wed, 8 May 2024 06:14:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5t-0005EI-2S; Wed, 08 May 2024 09:12:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dkf-0007V6-UV for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:17 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dke-0000XJ-68 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:17 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ed0abbf706so28848015ad.2 for ; Wed, 08 May 2024 02:38:15 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161095; x=1715765895; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=REjV3MNcFfq7gH+69GQ9Wyw9SNuTcZ130RuiQhIkTss=; b=Bq3jyy65s6OIXByBJPOjqkdPcuLCiSw2t5sMF6q4tpU9nrM6HCG/PzN/V49x9sjuhn iD1S3LJIB2Fs/8C1Rv8eoDm9p+o4mrVXPUUfxqr3cY6xlUsOpzCivfeDGWLUHoYIXBlb lSo+UWmVxxuHzyz74h5NN6TwSGW0Ir8TYjiATkvuShZ+cBruvdBID2R04XMcxMsN78fD fTHRwA55kUHVzhutkIpKhtQhFG1uSpLiz+jCcigA87ysd822PH8F5mihOpZ24dLe0PbH w+1InPaFx2vzXmvt+OXSA2onRmVfV+r2oH2dZoVF2giYj3GFTOgKDkWJH41eIeRL1L8C KW4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161095; x=1715765895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=REjV3MNcFfq7gH+69GQ9Wyw9SNuTcZ130RuiQhIkTss=; b=jlhl6R+igzjMatQIFdaIWQqxAdMDG8F1l3kgmtWudJgw6BQFf0sDK2TyYaGsT/S9ir Xosi50I7+RQoQXUBkImpInrAdcTWQwrXov0iFS86xEUq0JXJnmW9KWovo2tRx3+3kXtf af+/QdnrV3S8fxbh58ibmn1QNP5TyeIaL5Q3lDeelAbW5O7Kl/IsWfZUMMUqPbxWaDbX XBUFlX6SDKO6S3kaF+4DjAs1EAXQnz1bSK8W11pWwUVQEIxq2fFEmd9TEjj4WduUDeOZ 0F1v6dddWec0aD2hTtw4pewlC/TcjqZovQ9/OpkOG1AtPb8TYXQPZkO3p2LfoMqSDuen husQ== X-Forwarded-Encrypted: i=1; AJvYcCUIuKKTiooF64zwyNgkcslRzd58nbjvSYBJpuvhZSemebQ+2sw61i1rt10F1nLMTsu2Eiqs2X/s21FCkWDq4cLTHXdnxqI= X-Gm-Message-State: AOJu0YxfpSxRIp6yG0FFJGZtzks3xpU3uXrXa/X3SEEOs8lQoYECKwN7 24kAz4aTU/Wy/X6PCGHlfl+pLUY429kIVxjLEsLwQw/a0wjiMmGPCDPOi9mHhUU= X-Google-Smtp-Source: AGHT+IGM3+Ubylkt9hhSsVGlCd72RXz03xCMm80BRI+tojF1H57vkTR76YzdGhOLEE0uMhtdjvNo2g== X-Received: by 2002:a17:902:e74a:b0:1e2:3e1e:3d9 with SMTP id d9443c01a7336-1eeb0899ae1mr27124525ad.63.1715161094778; Wed, 08 May 2024 02:38:14 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 2/9] block/raw: add persistent reservation in/out driver Date: Wed, 8 May 2024 17:36:22 +0800 Message-Id: <20240508093629.441057-3-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=luchangqi.123@bytedance.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174067105100001 Content-Type: text/plain; charset="utf-8" Add persistent reservation in/out operations for raw driver. The following methods are implemented: bdrv_co_pr_read_keys, bdrv_co_pr_read_reservation, bdrv_co_pr_register, bdrv_co_pr_reserve, bdrv_co_pr_release, bdrv_co_pr_clear and bdrv_co_pr_preempt. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Reviewed-by: Stefan Hajnoczi --- block/raw-format.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index ac7e8495f6..7ba5b12101 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -454,6 +454,54 @@ raw_co_ioctl(BlockDriverState *bs, unsigned long int r= eq, void *buf) return bdrv_co_ioctl(bs->file->bs, req, buf); } =20 +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_read_keys(BlockDriverState *bs, uint32_t *generation, + uint32_t num_keys, uint64_t *keys) +{ + + return bdrv_co_pr_read_keys(bs->file->bs, generation, num_keys, keys); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_read_reservation(BlockDriverState *bs, uint32_t *generation, + uint64_t *key, BlockPrType *type) +{ + return bdrv_co_pr_read_reservation(bs->file->bs, generation, key, type= ); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_register(BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool ignore_key) +{ + return bdrv_co_pr_register(bs->file->bs, old_key, new_key, + type, ignore_key); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_reserve(BlockDriverState *bs, uint64_t key, BlockPrType type) +{ + return bdrv_co_pr_reserve(bs->file->bs, key, type); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_release(BlockDriverState *bs, uint64_t key, BlockPrType type) +{ + return bdrv_co_pr_release(bs->file->bs, key, type); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_clear(BlockDriverState *bs, uint64_t key) +{ + return bdrv_co_pr_clear(bs->file->bs, key); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_pr_preempt(BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool abort) +{ + return bdrv_co_pr_preempt(bs->file->bs, old_key, new_key, type, abort); +} + static int GRAPH_RDLOCK raw_has_zero_init(BlockDriverState *bs) { return bdrv_has_zero_init(bs->file->bs); @@ -672,6 +720,13 @@ BlockDriver bdrv_raw =3D { .strong_runtime_opts =3D raw_strong_runtime_opts, .mutable_opts =3D mutable_opts, .bdrv_cancel_in_flight =3D raw_cancel_in_flight, + .bdrv_co_pr_read_keys =3D raw_co_pr_read_keys, + .bdrv_co_pr_read_reservation =3D raw_co_pr_read_reservation, + .bdrv_co_pr_register =3D raw_co_pr_register, + .bdrv_co_pr_reserve =3D raw_co_pr_reserve, + .bdrv_co_pr_release =3D raw_co_pr_release, + .bdrv_co_pr_clear =3D raw_co_pr_clear, + .bdrv_co_pr_preempt =3D raw_co_pr_preempt, }; =20 static void bdrv_raw_init(void) --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715173983; cv=none; d=zohomail.com; s=zohoarc; b=NWyZzHTuu0w4Hknx3SyqLe76NP8DTjnN3zsFGVAtpOal3Jnl0HcCcF6TBuaddLh0LU5ocnbgKwHl+m9SUB2L9np1PZo+3BYDa1ZBk7D9s5HAFrl++2JjCZ54fIX7DPja8sm0e/X4cTYJCg3Nh9QivQVz6p63//ulNMn3KW44qTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715173983; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mhrpNoHqPwXJhHSVuGspRrhBd9WnIeflRDPD7nuJ1Zo=; b=eTaTR3kaMyeWGLWZOokxEpyd5uHqPjtuFP5bzMvnH8KuhumII4hZPprSROX9619xhDUh/dH3JBOLZy3MdufB5zeBcl6FAnYj+qAtQ69yYJy61AnVYIF98xC7FvSGmKFx7N59ujyq53M5j9lR5GILcz30RZCp+46JNkl+n9Mziu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171517398344329.170517348223825; Wed, 8 May 2024 06:13:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5u-0005Ek-Iw; Wed, 08 May 2024 09:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dkq-0007ah-8T for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:28 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dki-0000Y6-11 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:27 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ec4b2400b6so35623515ad.3 for ; Wed, 08 May 2024 02:38:19 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161099; x=1715765899; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mhrpNoHqPwXJhHSVuGspRrhBd9WnIeflRDPD7nuJ1Zo=; b=exp6Dl0IDz2RWJEePf1/KcH4nKmJLDLtStACvtU8rQdsI2zAil1WRapLCIsmGDmweo FiypOIf7oX5gnsHMefaqfx6zFL6tIugh60c2JPATazJGKJA0i53ke43ZaTbjHz3m/Fn/ oPXwyiKCUg8xFaeKHBzhpKCVTf0/WS925xoZK3W6Zrf5vvRe4jLopBzY0accBXCrPbQB /pxdgu1oshEERHfS1oNnwlfUJhy/8stnuagdOzTV6AC2+PK9L/PrH07c99iWi+k3OIiy +az3rJunWKyPKDOXYy2NtfUMNeR48jRGKm1lGrHjK+iM2yEWn7iDAOT7cAo10XF1pi09 ppKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161099; x=1715765899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mhrpNoHqPwXJhHSVuGspRrhBd9WnIeflRDPD7nuJ1Zo=; b=Q41GC+e+LXSkhw9LSVknliIdyBWlJXYusKvOQLbBNGLzLx+NK9tlDpVonekNbB0ec+ fI/xKqn9EG7bfMFr9R7dLSd8huJfrGqL+p7V9JiWsRvm8mqhDW7JTv0LRkqmcy2/jy19 oFwz92/r9Ou2mVUcGnbF35pzZ2zlahSx74J4Q4U6VUns/Srmoa8ia/2ny6i7qwHiJuqZ coH0TDUYu1ENwe3IFTlOX1xWSiQlxMELcuIC0a5S/x9EaUq0P7jXP/8wjNIClB/OAcPL 90Y12HxWBGDylxOqZQSDaH2iepknlKjPujoO6RDsAGd2jb1S9YByEUGgmklX6QHrgbBE V55Q== X-Forwarded-Encrypted: i=1; AJvYcCVXa7GBkhZ09xyBkpraFcr44qq3t2SRHDvEVRTQs4M0rEQ6j5XVyd8ZxO2OdXr7LDNCFAbj/AF13qK4q7vHaQ9hXxdok+0= X-Gm-Message-State: AOJu0YwsuHOmjZRuCXlzhRMGoXJoetcicqG3QXzZXdAyXYGrIrfkA2Tt 1ZaSVsbk7DSFSvLxEUmnXFBA8Cg9gks49Dv6xT+SUnk3Lkdw2Xi0A1pNU3nh8dJQfQglrYUI/R+ X2MhPPA== X-Google-Smtp-Source: AGHT+IHuv82rlHUqmBIPjbAKlsSpJcJLczPqPyT0rZphivePCLpG7UW77iGG4TP6LmFX8wyD3F/71w== X-Received: by 2002:a17:902:988c:b0:1e2:6bcd:e64e with SMTP id d9443c01a7336-1eeb059326emr18545125ad.16.1715161098788; Wed, 08 May 2024 02:38:18 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 3/9] scsi/constant: add persistent reservation in/out protocol constants Date: Wed, 8 May 2024 17:36:23 +0800 Message-Id: <20240508093629.441057-4-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=luchangqi.123@bytedance.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715173985267100001 Content-Type: text/plain; charset="utf-8" Add constants for the persistent reservation in/out protocol in the scsi/constant module. The constants include the persistent reservation command, type, and scope values defined in sections 6.13 and 6.14 of the SCSI Primary Commands-4 (SPC-4) specification. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Reviewed-by: Stefan Hajnoczi --- include/scsi/constants.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/scsi/constants.h b/include/scsi/constants.h index 9b98451912..511cb3d03e 100644 --- a/include/scsi/constants.h +++ b/include/scsi/constants.h @@ -319,4 +319,33 @@ #define IDENT_DESCR_TGT_DESCR_SIZE 32 #define XCOPY_BLK2BLK_SEG_DESC_SIZE 28 =20 +typedef enum { + SCSI_PR_WRITE_EXCLUSIVE =3D 0x01, + SCSI_PR_EXCLUSIVE_ACCESS =3D 0x03, + SCSI_PR_WRITE_EXCLUSIVE_REGS_ONLY =3D 0x05, + SCSI_PR_EXCLUSIVE_ACCESS_REGS_ONLY =3D 0x06, + SCSI_PR_WRITE_EXCLUSIVE_ALL_REGS =3D 0x07, + SCSI_PR_EXCLUSIVE_ACCESS_ALL_REGS =3D 0x08, +} SCSIPrType; + +typedef enum { + SCSI_PR_LU_SCOPE =3D 0x00, +} SCSIPrScope; + +typedef enum { + SCSI_PR_OUT_REGISTER =3D 0x0, + SCSI_PR_OUT_RESERVE =3D 0x1, + SCSI_PR_OUT_RELEASE =3D 0x2, + SCSI_PR_OUT_CLEAR =3D 0x3, + SCSI_PR_OUT_PREEMPT =3D 0x4, + SCSI_PR_OUT_PREEMPT_AND_ABORT =3D 0x5, + SCSI_PR_OUT_REG_AND_IGNORE_KEY =3D 0x6, + SCSI_PR_OUT_REG_AND_MOVE =3D 0x7, +} SCSIPrOutAction; + +typedef enum { + SCSI_PR_IN_READ_KEYS =3D 0x0, + SCSI_PR_IN_READ_RESERVATION =3D 0x1, +} SCSIPrInAction; + #endif --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174197; cv=none; d=zohomail.com; s=zohoarc; b=E20YlzjCYmK7YM0rE4WQ4Nz7G9scTSpdDgeTv6+JYwFLTlSKaY+I6Mm+diD4AR2Yi0EvLHqdc8H454ONH3pi0Is4BmH3xoyTEXU1ELnC5z0SZnQXpnbd2KMxT9sKK5tI654F9PKDIycVX7u4BY7kiq5YcFndV/sTtrhL3BA0MnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174197; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=t8zABI1BTj8XZR99oMhp56K6CNAOT5mRJrRHjuL0Qm8=; b=hfnqvW/4kyIqKtso/L+rBcxh+SKw9FwMoX2AaxEeaxUaFeNScw8J7n2zUoJegDyEhvF5ynxclZJ5zjAPVMgn3mq8/uVcOLSWTefX6WRqm3jO61m7o/lKcXmFiiHccleEpXnhAi1LL9x4O2bhQwr/hWISe3q7N5k3RtBHWddBsaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174197109937.3222195036693; Wed, 8 May 2024 06:16:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5u-0005F5-Q7; Wed, 08 May 2024 09:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dko-0007Y6-Fx for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:26 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dkm-0000YO-ML for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:26 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ed96772f92so29859035ad.0 for ; Wed, 08 May 2024 02:38:23 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161103; x=1715765903; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t8zABI1BTj8XZR99oMhp56K6CNAOT5mRJrRHjuL0Qm8=; b=OuJnLGBSxAH2AnVAwizTKS9JfDe2ZhfyvedCpIe+vg7BHWMA4hV7pTtoYF97qUO+pa Dy/7I0nGEZgp7ZqRiTpTQUfqhGjl3czSAY5wYDgREpIo+xZ8bJAPb5eqR4VF8eBmXuzD UWunbFWj9cmu/Ovnw397IIU8vvTSusRqZJswWpH210B2ViBBeuOk/XcEQCHt1b7qbbwV Uf3AFEN3Xpj4hfUF8shpK5I+aW3m6BD7guDDmWAxKRcszE5XzJ/Xvxru4aw1+m7nwPPd yRNt+20/Yqakodfxg+CDukwLTsFD9crw9yrNQfTLAtIo+eu57jcJQd9xwKRBkau8r6kR Jmhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161103; x=1715765903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t8zABI1BTj8XZR99oMhp56K6CNAOT5mRJrRHjuL0Qm8=; b=qNrsFIjhbE0ZZx0yDIS6iLpqa5Z++RKiUyvDtT73605yLYJAZt2ftCTu3zlnHJstGX 2NxHGeYZ/H4qS47m8wmJ+pi0RyecOtFYVQEk+61HxOwgb6DKCrzHNQb9BFltRrH9K6KZ XnIvzXDqpp15ldeefz3m+9wgK91VpedsMId1w0O7jff6bkt8VMBHoOGGGxB3lbNWTLrg o3JgOZQG4Og6EuR+2GT3Gp5YvGgIZN7zZdX/WbS48LrNAQ9CbEf/pSgK5KSTUyNezuXt Z7wTGXV4cx0Eh/s42Zc5tagiivcqd+ETsjOhRNP603z48o7P8Zdie9WGnDpk1phTEylu D/mQ== X-Forwarded-Encrypted: i=1; AJvYcCVuMkoSYqaef/01LQ4EaqbQKe+BEfFPYkWg2BPuLLRiOGn3rjIKS8YSSPyed5wap1gLQWA6n3W7qiGPOjvrtC7nytiWxrs= X-Gm-Message-State: AOJu0YzWVEF79Y2e+GEyk7Ro5qWCn/PsxAQiippYOmXppENSRYg5U+0E lGgDC+fGT+Jp/K1g9REIuur0smndYa9qgZ3mD1npRcUvpB0fD3foxOzrDGdT0jE= X-Google-Smtp-Source: AGHT+IGLfOb2/pZZLUKFCv/PRWqHkuHM2tIc7DrP6Rko5KabxplsHKrKo/yrfHJCHgZUh6pyRHSj5A== X-Received: by 2002:a17:902:ef52:b0:1ec:c6bd:4157 with SMTP id d9443c01a7336-1eeb078eca4mr27541745ad.59.1715161102715; Wed, 08 May 2024 02:38:22 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 4/9] scsi/util: add helper functions for persistent reservation types conversion Date: Wed, 8 May 2024 17:36:24 +0800 Message-Id: <20240508093629.441057-5-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=luchangqi.123@bytedance.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174197847100001 Content-Type: text/plain; charset="utf-8" This commit introduces two helper functions that facilitate the conversion between the persistent reservation types used in the SCSI protocol and those used in the block layer. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Reviewed-by: Stefan Hajnoczi --- include/scsi/utils.h | 5 +++++ scsi/utils.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/scsi/utils.h b/include/scsi/utils.h index d5c8efa16e..8212860231 100644 --- a/include/scsi/utils.h +++ b/include/scsi/utils.h @@ -1,6 +1,8 @@ #ifndef SCSI_UTILS_H #define SCSI_UTILS_H =20 +#include "block/block-common.h" +#include "scsi/constants.h" #ifdef CONFIG_LINUX #include #endif @@ -135,6 +137,9 @@ uint32_t scsi_data_cdb_xfer(uint8_t *buf); uint32_t scsi_cdb_xfer(uint8_t *buf); int scsi_cdb_length(uint8_t *buf); =20 +BlockPrType scsi_pr_type_to_block(SCSIPrType type); +SCSIPrType block_pr_type_to_scsi(BlockPrType type); + /* Linux SG_IO interface. */ #ifdef CONFIG_LINUX #define SG_ERR_DRIVER_TIMEOUT 0x06 diff --git a/scsi/utils.c b/scsi/utils.c index 357b036671..381803c81c 100644 --- a/scsi/utils.c +++ b/scsi/utils.c @@ -658,3 +658,43 @@ int scsi_sense_from_host_status(uint8_t host_status, } return GOOD; } + +BlockPrType scsi_pr_type_to_block(SCSIPrType type) +{ + switch (type) { + case SCSI_PR_WRITE_EXCLUSIVE: + return BLK_PR_WRITE_EXCLUSIVE; + case SCSI_PR_EXCLUSIVE_ACCESS: + return BLK_PR_EXCLUSIVE_ACCESS; + case SCSI_PR_WRITE_EXCLUSIVE_REGS_ONLY: + return BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY; + case SCSI_PR_EXCLUSIVE_ACCESS_REGS_ONLY: + return BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY; + case SCSI_PR_WRITE_EXCLUSIVE_ALL_REGS: + return BLK_PR_WRITE_EXCLUSIVE_ALL_REGS; + case SCSI_PR_EXCLUSIVE_ACCESS_ALL_REGS: + return BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS; + } + + return 0; +} + +SCSIPrType block_pr_type_to_scsi(BlockPrType type) +{ + switch (type) { + case BLK_PR_WRITE_EXCLUSIVE: + return SCSI_PR_WRITE_EXCLUSIVE; + case BLK_PR_EXCLUSIVE_ACCESS: + return SCSI_PR_EXCLUSIVE_ACCESS; + case BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY: + return SCSI_PR_WRITE_EXCLUSIVE_REGS_ONLY; + case BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY: + return SCSI_PR_EXCLUSIVE_ACCESS_REGS_ONLY; + case BLK_PR_WRITE_EXCLUSIVE_ALL_REGS: + return SCSI_PR_WRITE_EXCLUSIVE_ALL_REGS; + case BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS: + return SCSI_PR_EXCLUSIVE_ACCESS_ALL_REGS; + } + + return 0; +} --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174073; cv=none; d=zohomail.com; s=zohoarc; b=nqs/0yrTukDg24B8obmGbdmtPlgSpZnGRoyg8dmJ+Fsb1gRRDl7PitZPMeD9ag5i+kAA4gMs2T3vXEnelt9BOMWg70/x2Jl+6kX92vhmeCyj8eQrYE5ro1sCcgQWW3AuXRjBVQgq5zusxfH5molPdeiAEkJTyAEJp7bb7S7ET3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174073; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AbH5d8nS0+8RiFpo1WcBikzFAHCe+8opa1Qcgy0NVCI=; b=byPi+ZBXZJqREhQZjG7tVvOdPSS4j9OBV8Dz5zcEm8BH1bmcPbcK4n868Qu6h5Zn0GGqBj8j/pl5ZP8FOVjSKQcdB5Ufm7dWLA1nDonf+/MxeMhlxWsQKK+mY+uIPcE0mNc21COvNZX6LWcKvF86rSojYDONNudsuQRhGPBfODc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174073450152.5774280662945; Wed, 8 May 2024 06:14:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5s-0005DY-5i; Wed, 08 May 2024 09:12:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dks-0007c2-GN for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:30 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dkq-0000ZR-D0 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:30 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5d4d15ec7c5so3653242a12.1 for ; Wed, 08 May 2024 02:38:28 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161107; x=1715765907; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AbH5d8nS0+8RiFpo1WcBikzFAHCe+8opa1Qcgy0NVCI=; b=Dj+5MBffk+eSkQj5nbGEx7LxHYR+EVwpzilYKWxxE+zHJcMF8GYJ78rDxNnufoIxkF CSALNhGSj3GXWKRu77XKnot3JvC2yakp5EbJxpuTZFTX0wdPAbmA0EBv+SCLd2d2PjFZ Sg+/7xQDCRoZUA3iIomltIiN+Zs6kcwXM1SIgkkx2PBRnhvPBaW2gBczm00FDWAcVG2H hN2gpO9dCT6EBcCKWgkjhjdxJFBwPCG3AA6HyG5ur5Bk8pshFoHjdMFn79Nr98pEN4Nl 5KUf6gMyS3H4sMDegWWpoaSl6qc4pirVwqz2laFtALLV/Fj+uRy0opOCJ5ofjKw8Zx8H jQMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161107; x=1715765907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AbH5d8nS0+8RiFpo1WcBikzFAHCe+8opa1Qcgy0NVCI=; b=nZ10IqqPgWYSeKiUsggQ5sgGepWa7qUdJ8PuNJiOyvHynCnIbS0vACIkV4VfPEOHuU x8/S8eX42ms9qlmQdI68zgF40krbqecDrKCFAxA1NiQfUcm6kYsVw4aC1mv+ni79mETe IfdBsEhXAnVsm8JTQ9T6yzp1w/8aYF3jC7+szvAYvvzoe8LkGx6Cbkc6Vydxfg5Q0FWl k6nthVIXUmJ9dmYxgjNtkVnA11hucqkbjfBIi+v0+cSJZuladxnkNTNxteCRqZsXj0uW LjhPW9PlvMSoF9Nif3EL47Lgh6MtTQaF2CuXz0vNXSp2GJ6VekmK+hCPTi2Q+/SXmFLC LxSQ== X-Forwarded-Encrypted: i=1; AJvYcCX11fygj/sMCcIOo/dpweWMdKt1zYEOW6+xhCraw7IXUdrrNbWb4VAfJSX9gRy9O/cqSCWWl5eCp+QCRNWRE9nr2ZFL3hU= X-Gm-Message-State: AOJu0YzN14vcfMLHzo4aMVAz9IuduOAjKEO8O3i2PSt1KeN87Xj/BlfK LXjHJAjYi17NAoF53g8dlYn2mRuNcLXysGkrOwgTYlNkKnF01PGvvMC8bo1FI4s= X-Google-Smtp-Source: AGHT+IE8JgTSnzTmrzUAD6JKxEV2KtwCPZ1Xb9QEBHEYQNVRf1bSp7v2AEzEqnBBIcDe0+aheZhNOQ== X-Received: by 2002:a05:6a20:3d8d:b0:1a7:5780:1f4b with SMTP id adf61e73a8af0-1afc8d3a125mr2776356637.24.1715161106828; Wed, 08 May 2024 02:38:26 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 5/9] hw/scsi: add persistent reservation in/out api for scsi device Date: Wed, 8 May 2024 17:36:25 +0800 Message-Id: <20240508093629.441057-6-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=luchangqi.123@bytedance.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174075091100003 Content-Type: text/plain; charset="utf-8" Add persistent reservation in/out operations in the SCSI device layer. By introducing the persistent reservation in/out api, this enables the SCSI device to perform reservation-related tasks, including querying keys, querying reservation status, registering reservation keys, initiating and releasing reservations, as well as clearing and preempting reservations held by other keys. These operations are crucial for management and control of shared storage resources in a persistent manner. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi --- hw/scsi/scsi-disk.c | 302 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 4bd7af9d0c..bdd66c4026 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -32,6 +32,7 @@ #include "migration/vmstate.h" #include "hw/scsi/emulation.h" #include "scsi/constants.h" +#include "scsi/utils.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/block/block.h" @@ -1474,6 +1475,296 @@ static void scsi_disk_emulate_read_data(SCSIRequest= *req) scsi_req_complete(&r->req, GOOD); } =20 +typedef struct SCSIPrReadKeys { + uint32_t generation; + uint32_t num_keys; + uint64_t *keys; + void *req; +} SCSIPrReadKeys; + +typedef struct SCSIPrReadReservation { + uint32_t generation; + uint64_t key; + BlockPrType type; + void *req; +} SCSIPrReadReservation; + +static void scsi_pr_read_keys_complete(void *opaque, int ret) +{ + int num_keys; + uint8_t *buf; + SCSIPrReadKeys *blk_keys =3D (SCSIPrReadKeys *)opaque; + SCSIDiskReq *r =3D (SCSIDiskReq *)blk_keys->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + + assert(blk_get_aio_context(s->qdev.conf.blk) =3D=3D + qemu_get_current_aio_context()); + + assert(r->req.aiocb !=3D NULL); + r->req.aiocb =3D NULL; + + if (scsi_disk_req_check_error(r, ret, true)) { + goto done; + } + + buf =3D scsi_req_get_buf(&r->req); + num_keys =3D MIN(blk_keys->num_keys, ret); + blk_keys->generation =3D cpu_to_be32(blk_keys->generation); + memcpy(&buf[0], &blk_keys->generation, 4); + for (int i =3D 0; i < num_keys; i++) { + blk_keys->keys[i] =3D cpu_to_be64(blk_keys->keys[i]); + memcpy(&buf[8 + i * 8], &blk_keys->keys[i], 8); + } + num_keys =3D cpu_to_be32(num_keys * 8); + memcpy(&buf[4], &num_keys, 4); + + scsi_req_data(&r->req, r->buflen); +done: + scsi_req_unref(&r->req); + g_free(blk_keys->keys); + g_free(blk_keys); +} + +static int scsi_disk_emulate_pr_read_keys(SCSIRequest *req) +{ + SCSIPrReadKeys *blk_keys; + SCSIDiskReq *r =3D DO_UPCAST(SCSIDiskReq, req, req); + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + int buflen =3D MIN(r->req.cmd.xfer, r->buflen); + int num_keys =3D (buflen - sizeof(uint32_t) * 2) / sizeof(uint64_t); + + blk_keys =3D g_new0(SCSIPrReadKeys, 1); + blk_keys->generation =3D 0; + /* num_keys is the maximum number of keys that can be transmitted */ + blk_keys->num_keys =3D num_keys; + blk_keys->keys =3D g_malloc(sizeof(uint64_t) * num_keys); + blk_keys->req =3D r; + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_read_keys(s->qdev.conf.blk, &blk_keys->gen= eration, + blk_keys->num_keys, blk_keys->keys, + scsi_pr_read_keys_complete, blk_ke= ys); + return 0; +} + +static void scsi_pr_read_reservation_complete(void *opaque, int ret) +{ + uint8_t *buf; + uint32_t num_keys =3D 0; + SCSIPrReadReservation *blk_rsv =3D (SCSIPrReadReservation *)opaque; + SCSIDiskReq *r =3D (SCSIDiskReq *)blk_rsv->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + + assert(blk_get_aio_context(s->qdev.conf.blk) =3D=3D + qemu_get_current_aio_context()); + + assert(r->req.aiocb !=3D NULL); + r->req.aiocb =3D NULL; + + if (scsi_disk_req_check_error(r, ret, true)) { + goto done; + } + + buf =3D scsi_req_get_buf(&r->req); + blk_rsv->generation =3D cpu_to_be32(blk_rsv->generation); + memcpy(&buf[0], &blk_rsv->generation, 4); + if (ret) { + num_keys =3D cpu_to_be32(16); + blk_rsv->key =3D cpu_to_be64(blk_rsv->key); + memcpy(&buf[8], &blk_rsv->key, 8); + buf[21] =3D block_pr_type_to_scsi(blk_rsv->type) & 0xf; + } else { + num_keys =3D cpu_to_be32(0); + } + + memcpy(&buf[4], &num_keys, 4); + scsi_req_data(&r->req, r->buflen); + +done: + scsi_req_unref(&r->req); + g_free(blk_rsv); +} + +static int scsi_disk_emulate_pr_read_reservation(SCSIRequest *req) +{ + SCSIPrReadReservation *blk_rsv; + SCSIDiskReq *r =3D DO_UPCAST(SCSIDiskReq, req, req); + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + + blk_rsv =3D g_malloc(sizeof(*blk_rsv)); + blk_rsv->generation =3D 0; + blk_rsv->key =3D 0; + blk_rsv->type =3D 0; + blk_rsv->req =3D r; + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_read_reservation(s->qdev.conf.blk, + &blk_rsv->generation, &blk_rsv->key, &blk_rsv->type, + scsi_pr_read_reservation_complete, blk_rsv); + return 0; +} + +static void scsi_aio_pr_complete(void *opaque, int ret) +{ + SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + + /* The request must only run in the BlockBackend's AioContext */ + assert(blk_get_aio_context(s->qdev.conf.blk) =3D=3D + qemu_get_current_aio_context()); + + assert(r->req.aiocb !=3D NULL); + r->req.aiocb =3D NULL; + + if (scsi_disk_req_check_error(r, ret, true)) { + goto done; + } + + scsi_req_complete(&r->req, GOOD); + +done: + scsi_req_unref(&r->req); +} + +static int scsi_disk_emulate_pr_register(SCSIDiskReq *r, uint64_t old_key, + uint64_t new_key, SCSIPrType type, + bool ignore_key) +{ + SCSIRequest *req =3D &r->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_register(s->qdev.conf.blk, old_key, new_ke= y, + scsi_pr_type_to_block(type), + ignore_key, scsi_aio_pr_complete, r= ); + + return 0; +} + +static int scsi_disk_emulate_pr_reserve(SCSIDiskReq *r, uint64_t key, + SCSIPrType type) +{ + SCSIRequest *req =3D &r->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_reserve(s->qdev.conf.blk, key, + scsi_pr_type_to_block(type), + scsi_aio_pr_complete, r); + + return 0; +} + +static int scsi_disk_emulate_pr_release(SCSIDiskReq *r, uint64_t key, + SCSIPrType type) +{ + SCSIRequest *req =3D &r->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_release(s->qdev.conf.blk, key, + scsi_pr_type_to_block(type), + scsi_aio_pr_complete, r); + + return 0; +} + +static int scsi_disk_emulate_pr_clear(SCSIDiskReq *r, uint64_t key) +{ + SCSIRequest *req =3D &r->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_clear(s->qdev.conf.blk, key, + scsi_aio_pr_complete, r); + + return 0; +} + +static int scsi_disk_emulate_pr_preempt(SCSIDiskReq *r, uint64_t new_key, + uint64_t old_key, SCSIPrType type, + bool abort) +{ + SCSIRequest *req =3D &r->req; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); + + scsi_req_ref(&r->req); + r->req.aiocb =3D blk_aio_pr_preempt(s->qdev.conf.blk, new_key, old_key, + scsi_pr_type_to_block(type), abort, + scsi_aio_pr_complete, r); + + return 0; +} + +static int scsi_disk_emulate_pr_in(SCSIRequest *req) +{ + int rc; + SCSIPrInAction action =3D req->cmd.buf[1] & 0x1f; + + switch (action) { + case SCSI_PR_IN_READ_KEYS: + rc =3D scsi_disk_emulate_pr_read_keys(req); + break; + case SCSI_PR_IN_READ_RESERVATION: + rc =3D scsi_disk_emulate_pr_read_reservation(req); + break; + default: + return -ENOTSUP; + } + + return rc; +} + +static int scsi_disk_emulate_pr_out(SCSIDiskReq *r, uint8_t *inbuf) +{ + int rc; + uint64_t old_key, new_key; + SCSIPrOutAction action; + SCSIPrScope scope; + SCSIPrType type; + SCSIRequest *req =3D &r->req; + + memcpy(&old_key, &inbuf[0], 8); + old_key =3D be64_to_cpu(old_key); + memcpy(&new_key, &inbuf[8], 8); + new_key =3D be64_to_cpu(new_key); + action =3D req->cmd.buf[1] & 0x1f; + scope =3D (req->cmd.buf[2] >> 4) & 0x0f; + type =3D req->cmd.buf[2] & 0x0f; + + if (scope !=3D SCSI_PR_LU_SCOPE) { + return -ENOTSUP; + } + + switch (action) { + case SCSI_PR_OUT_REGISTER: + rc =3D scsi_disk_emulate_pr_register(r, old_key, new_key, type, fa= lse); + break; + case SCSI_PR_OUT_REG_AND_IGNORE_KEY: + rc =3D scsi_disk_emulate_pr_register(r, old_key, new_key, type, tr= ue); + break; + case SCSI_PR_OUT_RESERVE: + rc =3D scsi_disk_emulate_pr_reserve(r, old_key, type); + break; + case SCSI_PR_OUT_RELEASE: + rc =3D scsi_disk_emulate_pr_release(r, old_key, type); + break; + case SCSI_PR_OUT_CLEAR: + rc =3D scsi_disk_emulate_pr_clear(r, old_key); + break; + case SCSI_PR_OUT_PREEMPT: + rc =3D scsi_disk_emulate_pr_preempt(r, old_key, new_key, type, fal= se); + break; + case SCSI_PR_OUT_PREEMPT_AND_ABORT: + rc =3D scsi_disk_emulate_pr_preempt(r, old_key, new_key, type, tru= e); + break; + default: + return -ENOTSUP; + } + + return rc; +} + static int scsi_disk_check_mode_select(SCSIDiskState *s, int page, uint8_t *inbuf, int inlen) { @@ -1957,6 +2248,9 @@ static void scsi_disk_emulate_write_data(SCSIRequest = *req) scsi_req_complete(&r->req, GOOD); break; =20 + case PERSISTENT_RESERVE_OUT: + scsi_disk_emulate_pr_out(r, r->iov.iov_base); + break; default: abort(); } @@ -2213,6 +2507,12 @@ static int32_t scsi_disk_emulate_command(SCSIRequest= *req, uint8_t *buf) case FORMAT_UNIT: trace_scsi_disk_emulate_command_FORMAT_UNIT(r->req.cmd.xfer); break; + case PERSISTENT_RESERVE_OUT: + break; + case PERSISTENT_RESERVE_IN: + scsi_req_ref(&r->req); + scsi_disk_emulate_pr_in(req); + return 0; default: trace_scsi_disk_emulate_command_UNKNOWN(buf[0], scsi_command_name(buf[0])); @@ -2632,6 +2932,8 @@ static const SCSIReqOps *const scsi_disk_reqops_dispa= tch[256] =3D { [VERIFY_12] =3D &scsi_disk_emulate_reqops, [VERIFY_16] =3D &scsi_disk_emulate_reqops, [FORMAT_UNIT] =3D &scsi_disk_emulate_reqops, + [PERSISTENT_RESERVE_IN] =3D &scsi_disk_emulate_reqops, + [PERSISTENT_RESERVE_OUT] =3D &scsi_disk_emulate_reqops, =20 [READ_6] =3D &scsi_disk_dma_reqops, [READ_10] =3D &scsi_disk_dma_reqops, --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174051; cv=none; d=zohomail.com; s=zohoarc; b=jvbU411fPk9UyDatXrvc/a+IOL9cmJC2V4+o1rtAkcDXUZWexAt7NawIVqZW+0CcDtYRgbS+yfYSExBWoItYm7Y0i5UKEjlgeUKwu/XMtzC74cmx785ufyVjpikYBoBzlc+JTjqu9LJhb9iOewdbUq2ZDy0EyB9mkleSGCROl7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174051; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gFPFIrQSwbonOV1Lxc6f0KhdGy2FCqSxIxef8n97aRY=; b=ACA5DeAbOVfY7z11ErySl3yQpbkFTnEIadm1RfHe6MZYN9ZRwXYGBsr7bbjF5LGcb+JLU+h6lNjzESB4q0j2HblOQ3Wi/fbcOCxReCvxPusAzGpufCsFjuM2TC76Ntgq5cjEmUPzhkEFW5vj6gZ3+WYvkispyjk+uFULgEOnBQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174050989641.4120017762724; Wed, 8 May 2024 06:14:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5u-0005FA-UC; Wed, 08 May 2024 09:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dkv-0007f0-GH for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:33 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dkt-0000aE-TU for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:33 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5ff57410ebbso3329570a12.1 for ; Wed, 08 May 2024 02:38:31 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161110; x=1715765910; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gFPFIrQSwbonOV1Lxc6f0KhdGy2FCqSxIxef8n97aRY=; b=D/uBsBmkWjLRrY/iME4smJluXXkpSMzSb4fprqPvDWpbb0h7T4ZERihkmB+VLtRH2d uLrSq/lzeFXDZLMs475ICN13OIKtb4O4jlxUuPuADskSH0c7jWWgcHiPecGQYAM6RN1q GcxdjFiDFbSOMHG36Fdsd/mOf1JVBBdXxxoXG70egBRgyk0uV6TDctDvyi/VqdDML6O7 UMSDGTPgbyX7PC5+7Xk4jhmr6PArO4OJ7eKmo2rgpcVjoMdY2/V1KnKWXGZWsMpgn+8r IjGmp95+Gmn7dZO9Ao7CHS0S+LbBuekNkE5unQ/5x1pOXz6rmXtrXJqHUrwg+zYgUMZK yY4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161110; x=1715765910; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gFPFIrQSwbonOV1Lxc6f0KhdGy2FCqSxIxef8n97aRY=; b=ajXwAnhyBKggDgUDdHA5/ykQyb7ZZyBBz5EUGJAXcBHKIkYFj/sMbHN9+znV3I/yaO 6VzYBGuTdUuSmnfqmetyxSM3bctN3Qo6oJzw01vD33i7waq7jwNKAKiSbY1M28sWIqYn HaKFDq9BHr5kzmo29QGTz4lUo3kdqjjDHleKQBQtnRsYfgscKkhmU72hzYnvb5AE9c5j ny8wsgS/a5exDYUM9ya0KVcOEpMTnJK1SLwh7e+T6dOexMLJyFf6hsvxAauKenTIyIFj uXYPJNj0S0pxJ+mJ7q7OUqOOwspiMKjlL0xzeqMCAa4qbX0T2BeB69C88cA+A4RTF0Fz A7KA== X-Forwarded-Encrypted: i=1; AJvYcCWqXLQ0iW6QnEDCp8IK2WB+z2HBOaYIl+YjzFxoem2IZ1CQ4QnbeYFoOen4OmMcjMqd3C4Y7FTseQpYqfD7enUBWX05pqg= X-Gm-Message-State: AOJu0YyABDR5qVCBe3XvAZTMPuuQhjWyR0jqoCMf8zl8zktzRoP+ihQ0 3Wr/PUQ+aztCiIbjjVFgp904h9xA6j9x59kj8m7ltLQsKJv3W8pUtjsWNELqNrA= X-Google-Smtp-Source: AGHT+IHVkAh3WR5P0kjIKVVEosIeAvI3hhDd1eD4VvY/gSFtVxjx9dZbAysNNXqL9FWwiXwOSv9HfA== X-Received: by 2002:a17:902:b48f:b0:1e4:4000:a576 with SMTP id d9443c01a7336-1eeb0795f3emr19156935ad.43.1715161110685; Wed, 08 May 2024 02:38:30 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 6/9] block/nvme: add reservation command protocol constants Date: Wed, 8 May 2024 17:36:26 +0800 Message-Id: <20240508093629.441057-7-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=luchangqi.123@bytedance.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_50_75=0.008 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174053100100003 Content-Type: text/plain; charset="utf-8" Add constants for the NVMe persistent command protocol. The constants include the reservation command opcode and reservation type values defined in section 7 of the NVMe 2.0 specification. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Reviewed-by: Stefan Hajnoczi --- include/block/nvme.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/block/nvme.h b/include/block/nvme.h index bb231d0b9a..3409fba762 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -633,6 +633,10 @@ enum NvmeIoCommands { NVME_CMD_WRITE_ZEROES =3D 0x08, NVME_CMD_DSM =3D 0x09, NVME_CMD_VERIFY =3D 0x0c, + NVME_CMD_RESV_REGISTER =3D 0x0d, + NVME_CMD_RESV_REPORT =3D 0x0e, + NVME_CMD_RESV_ACQUIRE =3D 0x11, + NVME_CMD_RESV_RELEASE =3D 0x15, NVME_CMD_IO_MGMT_RECV =3D 0x12, NVME_CMD_COPY =3D 0x19, NVME_CMD_IO_MGMT_SEND =3D 0x1d, @@ -641,6 +645,32 @@ enum NvmeIoCommands { NVME_CMD_ZONE_APPEND =3D 0x7d, }; =20 +typedef enum { + NVME_RESV_REGISTER_ACTION_REGISTER =3D 0x00, + NVME_RESV_REGISTER_ACTION_UNREGISTER =3D 0x01, + NVME_RESV_REGISTER_ACTION_REPLACE =3D 0x02, +} NVME_RESV_REGISTER_ACTION; + +typedef enum { + NVME_RESV_RELEASE_ACTION_RELEASE =3D 0x00, + NVME_RESV_RELEASE_ACTION_CLEAR =3D 0x01, +} NVME_RESV_RELEASE_ACTION; + +typedef enum { + NVME_RESV_ACQUIRE_ACTION_ACQUIRE =3D 0x00, + NVME_RESV_ACQUIRE_ACTION_PREEMPT =3D 0x01, + NVME_RESV_ACQUIRE_ACTION_PREEMPT_AND_ABORT =3D 0x02, +} NVME_RESV_ACQUIRE_ACTION; + +typedef enum { + NVME_RESV_WRITE_EXCLUSIVE =3D 0x01, + NVME_RESV_EXCLUSIVE_ACCESS =3D 0x02, + NVME_RESV_WRITE_EXCLUSIVE_REGS_ONLY =3D 0x03, + NVME_RESV_EXCLUSIVE_ACCESS_REGS_ONLY =3D 0x04, + NVME_RESV_WRITE_EXCLUSIVE_ALL_REGS =3D 0x05, + NVME_RESV_EXCLUSIVE_ACCESS_ALL_REGS =3D 0x06, +} NVMEResvType; + typedef struct QEMU_PACKED NvmeDeleteQ { uint8_t opcode; uint8_t flags; --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174117; cv=none; d=zohomail.com; s=zohoarc; b=dzNGzUjdwY2jYPbp0ZnbF1AOm62+0+6/CsgGXQcnu2D59+pEA46qZ6SWvLRYMBGsmHjOmf2u7xBkpmTMq7rXRn80ZHnOlbt/ZCI5IYeAq2KP3TCmmjAsZOig+o6QbYwm07xViE2W/7vbCvHhFlFvcnr5SbqAj/olvDcyX87fBk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174117; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RLmdC7xgHK3n63q1edNAVO95cmP2mjRHETTCOF2flbQ=; b=BUETf6FfALQM9SH5kjWIGH7fl9ptAO2a4XeWTYBXsbIK10SwTrrqk21J0YnWpdYjF5BMCtKd/1nequu8Vl1mJkt7Ya1Om5dffay3Pd2ugTecOXv5xxHJuw+I5Ge7kxb7jg/4TaPa9yW9a6ehVxB/YzeTcwAurWzzMtHf+U4yyHI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174117145502.7142939770471; Wed, 8 May 2024 06:15:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5t-0005EJ-3Z; Wed, 08 May 2024 09:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dl0-0007mw-P0 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:38 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dky-0000bA-4S for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:37 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ee0132a6f3so27414645ad.0 for ; Wed, 08 May 2024 02:38:35 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161115; x=1715765915; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RLmdC7xgHK3n63q1edNAVO95cmP2mjRHETTCOF2flbQ=; b=CfKjj8WRWhC6XVOLeoMcv1G01FLEE1qwRpvxtv8aQ3EUM/+4qnh39RJNZmxwsrbUhH vfQ+TaWk4Bky2RnEifaIOOt0cFFBTD0BS7q7FD/0OK5MjL+HVUboiHK2DIi6PqKMpbI/ snTlWBXfWXyMB+z7FxzJdmaIpM9J1FwT1QC/l9XyvYzfmLFrl2gXLkdnv9RKX5Dz/PbZ XF8YE/K3jHCIv4jhH88LTYZBcTj+IQ/iKMpYO4YVKbPJrP1hEtTJ+eXiK7aGpHW9fT1y IM35ZMLRvNBiQvfQqWkaHN8o1ENdKU0aHZENSdkPq4wZqUz/zaqCyk1ZURhVS9fTTktU oHvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161115; x=1715765915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLmdC7xgHK3n63q1edNAVO95cmP2mjRHETTCOF2flbQ=; b=VBzweRjOpF2yY190vY68ZCNw76/7VbuKlwJcRbs6CC7Nbb3+oKPytqmXAxEI0+5enK zZKD07BOdqOeR5bE8qK1MPxmBlQ71SO10sCfw0UTpF8VjcDLerHyeyVs4o0+BtTKdq1R GzpPWXqihEbWhZstL11E7QH3/05J9gznNO7M8jaesoN21KcMztdWyZ4Se37OfAubqHkq NLr663bBdYxYnVYvBw9t4wELBn8q/8DDlBYLPAJA4jcpK9/g7BIQhrA/Xbu0FdPkj8WE o9YhXGJ6g6S7rUTIzUjN1ccomKaPDbDjL7h8N5YgkmDR5aULQljw9cDxzdK/8FmvbDZ+ RuRg== X-Forwarded-Encrypted: i=1; AJvYcCXQwzswGchIWYMbhIT6sbI+2bAZILDotnCHUnh0SgQEyzYUe7PA1dRgf38XyMwFf9FuDKnti4Ot0bYo/IdHPTTJPdZtX4A= X-Gm-Message-State: AOJu0Yw/pSqJPAw8wCsYRA7ZhYP3nGqQDUJqYhRaQdbln7mlM0FtYbVJ vf002Aczc7e6YhFyoPlVqWWRj1zfbqSzsJhXOaFyA+gI7d9O+9n52gwfgnd1VMc= X-Google-Smtp-Source: AGHT+IGiQVmoghL6gesnyA9ypkJn2wokeKSw7nKcC10NA6sZ5iYgjXdmtulOk9J+mfI71azCJd/shw== X-Received: by 2002:a17:902:eb55:b0:1eb:704c:43b3 with SMTP id d9443c01a7336-1eeb039e93fmr20501085ad.24.1715161114721; Wed, 08 May 2024 02:38:34 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 7/9] hw/nvme: add helper functions for converting reservation types Date: Wed, 8 May 2024 17:36:27 +0800 Message-Id: <20240508093629.441057-8-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=luchangqi.123@bytedance.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174119276100003 Content-Type: text/plain; charset="utf-8" This commit introduces two helper functions that facilitate the conversion between the reservation types used in the NVME protocol and those used in the block layer. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Reviewed-by: Stefan Hajnoczi --- hw/nvme/nvme.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index bed8191bd5..6abe479410 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -474,6 +474,46 @@ static inline const char *nvme_io_opc_str(uint8_t opc) } } =20 +static inline NVMEResvType block_pr_type_to_nvme(BlockPrType type) +{ + switch (type) { + case BLK_PR_WRITE_EXCLUSIVE: + return NVME_RESV_WRITE_EXCLUSIVE; + case BLK_PR_EXCLUSIVE_ACCESS: + return NVME_RESV_EXCLUSIVE_ACCESS; + case BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY: + return NVME_RESV_WRITE_EXCLUSIVE_REGS_ONLY; + case BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY: + return NVME_RESV_EXCLUSIVE_ACCESS_REGS_ONLY; + case BLK_PR_WRITE_EXCLUSIVE_ALL_REGS: + return NVME_RESV_WRITE_EXCLUSIVE_ALL_REGS; + case BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS: + return NVME_RESV_EXCLUSIVE_ACCESS_ALL_REGS; + } + + return 0; +} + +static inline BlockPrType nvme_pr_type_to_block(NVMEResvType type) +{ + switch (type) { + case NVME_RESV_WRITE_EXCLUSIVE: + return BLK_PR_WRITE_EXCLUSIVE; + case NVME_RESV_EXCLUSIVE_ACCESS: + return BLK_PR_EXCLUSIVE_ACCESS; + case NVME_RESV_WRITE_EXCLUSIVE_REGS_ONLY: + return BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY; + case NVME_RESV_EXCLUSIVE_ACCESS_REGS_ONLY: + return BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY; + case NVME_RESV_WRITE_EXCLUSIVE_ALL_REGS: + return BLK_PR_WRITE_EXCLUSIVE_ALL_REGS; + case NVME_RESV_EXCLUSIVE_ACCESS_ALL_REGS: + return BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS; + } + + return 0; +} + typedef struct NvmeSQueue { struct NvmeCtrl *ctrl; uint16_t sqid; --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174168; cv=none; d=zohomail.com; s=zohoarc; b=RXXsk1Xxemr3QT7oW9pBRdBa+8YvIe/BcEpfiv6OFNdfUFnzIp/b2vbOH/xlb9pNxXPL9rPJLOR/ocfhRboC8bG+0t6/EtjyfOSr6ne6w6T04yiRk9cU2w1bqhoRGl7DFoZcYqF73fjkyfQ8LPHkA2RBv9EvKkzc1ffap9cafsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174168; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OjCVH7Yj9aox6J3j8ChzMwHPaTg5EjxvcQ5KtDcpmXc=; b=d1guyzhrJiN54IGoV34ilN2uvGdjRa/6wxCPx5CXikoQ/g8xpfOv8L3y2hdRF+tem0CTLxztTDDMiGHrr1VEq5++2XBj0yel9qGAwjhT7j4DFlXUKWYR4hln9aSDgJ1R8zPemb1Egi2dnnllEPHDLjjUavdnqup3PCzz56h/5S8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174168312200.76021933216862; Wed, 8 May 2024 06:16:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5t-0005Ee-Vh; Wed, 08 May 2024 09:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dl4-0007nx-DB for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:42 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dl2-0000bl-3E for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:42 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6f44bcbaae7so3159115b3a.2 for ; Wed, 08 May 2024 02:38:39 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161118; x=1715765918; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OjCVH7Yj9aox6J3j8ChzMwHPaTg5EjxvcQ5KtDcpmXc=; b=LCg/JVK1rxkfzNfglL0JkB5gvsd1Gj3iL1/JQ9qK8zaTkUwLtJzVj5gUEs03ri5coR SqPJrStdBkel2rM5rbhNuNR9JE019edYyqPUk6p3d0DQnhLjIUvKjMhfDrQkliPWRjrD GqgL7J+npO8bKVTQy9Lsj/zGKXVACR0fikfRyHeKNM0RoVXrOSAzYh/avkQnyWlyik0u kAqYNjVP7ucrYvfj9b5UUHfPo4HVtIB5cKXMt+RLTcL7LUpZyrQaSSuNxeWDukJITrYg lYm57fFp8J/lpRy1XFKsiwzvFqVn52Sk12g7odHJMoIm8HcgRHKo+hsVB6KceQRN4TdX 6qvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161118; x=1715765918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OjCVH7Yj9aox6J3j8ChzMwHPaTg5EjxvcQ5KtDcpmXc=; b=xS2O0QnJYrZlcCyLYib3iSQP1gDOeil0OZt7ixTbCZyvQzyMo+rGzlgJbVhtFeCJyt McTsscKuZIsnM7cNwOCWlyTwe4F9Ip/yBFtuK7Wa6QCUz641sLk6SLU+GQcgnH539AUJ f5oa4gEmhc5cbIJkvUtcOfuZh5jfQq/AHodj9YSECkhzlSGflYMekFnebNSnOAo6lFrC b1E6qGdMF6BjnbP6GQ6AAtdxvPQ8Ny+ox7OfZabwcyDjCmmpqXIqY8Hv00F0KEDA/WOh 152eC5J8ilfa/oaY18Ex03jEuqJu1c11vPq6KscZIjRC5AACZ4DK7WT5uQwJ+PqlBkJ+ zlog== X-Forwarded-Encrypted: i=1; AJvYcCUNbEbyHwHEXXxrbEdZs1TiJkKraq8m3FwAyo7D5h4b7z2ptXvRyTdTcH18WaIpGbof0XrFVzgxjqojeAw7Zi8PrifL2V4= X-Gm-Message-State: AOJu0YwaVXVywlRMQYsg0BMAeJD17cpm7SQGARUOE9tlMf/JRoMWr4Sv N+OjkpmwIzJfg9XzGxv+y7lI3X+WmBrMM82hNu2yzsP4CReGqaUlsuOnTUAAif8= X-Google-Smtp-Source: AGHT+IF48gn+l3a59VPB4PIAwCekZ24Ta/y92rkdHYskSYCSRNiWOnjf+CY576Uhuc1sWi7C5aHtZQ== X-Received: by 2002:a05:6a21:604:b0:1a9:694b:5b0 with SMTP id adf61e73a8af0-1afc8d3ca45mr2135863637.21.1715161118597; Wed, 08 May 2024 02:38:38 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 8/9] hw/nvme: add reservation protocal command Date: Wed, 8 May 2024 17:36:28 +0800 Message-Id: <20240508093629.441057-9-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=luchangqi.123@bytedance.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174169705100001 Content-Type: text/plain; charset="utf-8" Add reservation acquire, reservation register, reservation release and reservation report commands in the nvme device layer. By introducing these commands, this enables the nvme device to perform reservation-related tasks, including querying keys, querying reservation status, registering reservation keys, initiating and releasing reservations, as well as clearing and preempting reservations held by other keys. These commands are crucial for management and control of shared storage resources in a persistent manner. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi --- hw/nvme/ctrl.c | 304 ++++++++++++++++++++++++++++++++++++++++++- hw/nvme/nvme.h | 4 + include/block/nvme.h | 37 ++++++ 3 files changed, 344 insertions(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 127c3d2383..1f881fc44c 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -294,6 +294,10 @@ static const uint32_t nvme_cse_iocs_nvm[256] =3D { [NVME_CMD_COMPARE] =3D NVME_CMD_EFF_CSUPP, [NVME_CMD_IO_MGMT_RECV] =3D NVME_CMD_EFF_CSUPP, [NVME_CMD_IO_MGMT_SEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_RESV_REGISTER] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_REPORT] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_ACQUIRE] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_RELEASE] =3D NVME_CMD_EFF_CSUPP, }; =20 static const uint32_t nvme_cse_iocs_zoned[256] =3D { @@ -308,6 +312,10 @@ static const uint32_t nvme_cse_iocs_zoned[256] =3D { [NVME_CMD_ZONE_APPEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, [NVME_CMD_ZONE_MGMT_SEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, [NVME_CMD_ZONE_MGMT_RECV] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_REGISTER] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_REPORT] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_ACQUIRE] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_RELEASE] =3D NVME_CMD_EFF_CSUPP, }; =20 static void nvme_process_sq(void *opaque); @@ -1745,6 +1753,7 @@ static void nvme_aio_err(NvmeRequest *req, int ret) =20 switch (req->cmd.opcode) { case NVME_CMD_READ: + case NVME_CMD_RESV_REPORT: status =3D NVME_UNRECOVERED_READ; break; case NVME_CMD_FLUSH: @@ -1752,6 +1761,9 @@ static void nvme_aio_err(NvmeRequest *req, int ret) case NVME_CMD_WRITE_ZEROES: case NVME_CMD_ZONE_APPEND: case NVME_CMD_COPY: + case NVME_CMD_RESV_REGISTER: + case NVME_CMD_RESV_ACQUIRE: + case NVME_CMD_RESV_RELEASE: status =3D NVME_WRITE_FAULT; break; default: @@ -2127,7 +2139,10 @@ static inline bool nvme_is_write(NvmeRequest *req) =20 return rw->opcode =3D=3D NVME_CMD_WRITE || rw->opcode =3D=3D NVME_CMD_ZONE_APPEND || - rw->opcode =3D=3D NVME_CMD_WRITE_ZEROES; + rw->opcode =3D=3D NVME_CMD_WRITE_ZEROES || + rw->opcode =3D=3D NVME_CMD_RESV_REGISTER || + rw->opcode =3D=3D NVME_CMD_RESV_ACQUIRE || + rw->opcode =3D=3D NVME_CMD_RESV_RELEASE; } =20 static void nvme_misc_cb(void *opaque, int ret) @@ -2692,6 +2707,285 @@ static uint16_t nvme_verify(NvmeCtrl *n, NvmeReques= t *req) return NVME_NO_COMPLETE; } =20 +typedef struct NvmeKeyInfo { + uint64_t cr_key; + uint64_t nr_key; +} NvmeKeyInfo; + +static uint16_t nvme_resv_register(NvmeCtrl *n, NvmeRequest *req) +{ + int ret; + NvmeKeyInfo key_info; + NvmeNamespace *ns =3D req->ns; + uint32_t cdw10 =3D le32_to_cpu(req->cmd.cdw10); + bool ignore_key =3D cdw10 >> 3 & 0x1; + uint8_t action =3D cdw10 & 0x7; + + ret =3D nvme_h2c(n, (uint8_t *)&key_info, sizeof(NvmeKeyInfo), req); + if (ret) { + return ret; + } + + switch (action) { + case NVME_RESV_REGISTER_ACTION_REGISTER: + req->aiocb =3D blk_aio_pr_register(ns->blkconf.blk, 0, + key_info.nr_key, 0, + ignore_key, nvme_misc_cb, + req); + break; + case NVME_RESV_REGISTER_ACTION_UNREGISTER: + req->aiocb =3D blk_aio_pr_register(ns->blkconf.blk, key_info.cr_ke= y, 0, + 0, ignore_key, nvme_misc_cb, r= eq); + break; + case NVME_RESV_REGISTER_ACTION_REPLACE: + req->aiocb =3D blk_aio_pr_register(ns->blkconf.blk, key_info.cr_ke= y, + key_info.nr_key, 0, ignore_key, + nvme_misc_cb, req); + break; + default: + return NVME_INVALID_FIELD; + } + + return NVME_NO_COMPLETE; +} + +static uint16_t nvme_resv_release(NvmeCtrl *n, NvmeRequest *req) +{ + int ret; + uint64_t cr_key; + NvmeNamespace *ns =3D req->ns; + uint32_t cdw10 =3D le32_to_cpu(req->cmd.cdw10); + uint8_t action =3D cdw10 & 0x7; + NVMEResvType type =3D cdw10 >> 8 & 0xff; + + ret =3D nvme_h2c(n, (uint8_t *)&cr_key, sizeof(cr_key), req); + if (ret) { + return ret; + } + + switch (action) { + case NVME_RESV_RELEASE_ACTION_RELEASE: + req->aiocb =3D blk_aio_pr_release(ns->blkconf.blk, cr_key, + nvme_pr_type_to_block(type), + nvme_misc_cb, req); + break; + case NVME_RESV_RELEASE_ACTION_CLEAR: + req->aiocb =3D blk_aio_pr_clear(ns->blkconf.blk, cr_key, + nvme_misc_cb, req); + break; + default: + return NVME_INVALID_FIELD; + } + + return NVME_NO_COMPLETE; +} + +static uint16_t nvme_resv_acquire(NvmeCtrl *n, NvmeRequest *req) +{ + int ret; + NvmeKeyInfo key_info; + NvmeNamespace *ns =3D req->ns; + uint32_t cdw10 =3D le32_to_cpu(req->cmd.cdw10); + uint8_t action =3D cdw10 & 0x7; + NVMEResvType type =3D cdw10 >> 8 & 0xff; + + ret =3D nvme_h2c(n, (uint8_t *)&key_info, sizeof(NvmeKeyInfo), req); + if (ret) { + return ret; + } + + switch (action) { + case NVME_RESV_ACQUIRE_ACTION_ACQUIRE: + req->aiocb =3D blk_aio_pr_reserve(ns->blkconf.blk, key_info.cr_key, + nvme_pr_type_to_block(type), + nvme_misc_cb, req); + break; + case NVME_RESV_ACQUIRE_ACTION_PREEMPT: + req->aiocb =3D blk_aio_pr_preempt(ns->blkconf.blk, + key_info.cr_key, key_info.nr_key, + nvme_pr_type_to_block(type), + false, nvme_misc_cb, req); + break; + case NVME_RESV_ACQUIRE_ACTION_PREEMPT_AND_ABORT: + req->aiocb =3D blk_aio_pr_preempt(ns->blkconf.blk, key_info.cr_key, + key_info.nr_key, type, true, + nvme_misc_cb, req); + break; + default: + return NVME_INVALID_FIELD; + } + + return NVME_NO_COMPLETE; +} + +typedef struct NvmeResvKeys { + uint32_t generation; + uint32_t num_keys; + uint64_t *keys; + NvmeRequest *req; +} NvmeResvKeys; + +typedef struct NvmeReadReservation { + uint32_t generation; + uint64_t key; + BlockPrType type; + NvmeRequest *req; + NvmeResvKeys *keys_info; +} NvmeReadReservation; + +static int _nvme_resv_read_reservation_cb(NvmeReadReservation *reservation) +{ + int rc; + NvmeReservationStatus *nvme_status; + NvmeRequest *req =3D reservation->req; + NvmeCtrl *n =3D req->sq->ctrl; + NvmeResvKeys *keys_info =3D reservation->keys_info; + int len =3D sizeof(NvmeReservationStatusHeader) + + sizeof(NvmeRegisteredCtrl) * keys_info->num_keys; + + nvme_status =3D g_malloc(len); + nvme_status->header.gen =3D reservation->generation; + nvme_status->header.rtype =3D block_pr_type_to_nvme(reservation->type); + nvme_status->header.regctl =3D keys_info->num_keys; + for (int i =3D 0; i < keys_info->num_keys; i++) { + nvme_status->regctl_ds[i].cntlid =3D nvme_ctrl(req)->cntlid; + nvme_status->regctl_ds[i].rkey =3D keys_info->keys[i]; + nvme_status->regctl_ds[i].rcsts =3D keys_info->keys[i] =3D=3D + reservation->key ? 1 : 0; + /* hostid is not supported currently */ + memset(&nvme_status->regctl_ds[i].hostid, 0, 8); + } + + rc =3D nvme_c2h(n, (uint8_t *)nvme_status, len, req); + g_free(nvme_status); + return rc; +} + +static int _nvme_resv_read_reservation_ext_cb(NvmeReadReservation *reserva= tion) +{ + int rc; + NvmeReservationStatusExt *nvme_status_ext; + NvmeRequest *req =3D reservation->req; + NvmeCtrl *n =3D req->sq->ctrl; + NvmeResvKeys *keys_info =3D reservation->keys_info; + int len =3D sizeof(NvmeReservationStatusHeader) + + sizeof(uint8_t) * 40 + + sizeof(NvmeRegisteredCtrlExt) * keys_info->num_keys; + + nvme_status_ext =3D g_malloc(len); + nvme_status_ext->header.gen =3D cpu_to_be32(reservation->generation); + nvme_status_ext->header.rtype =3D block_pr_type_to_nvme(reservation->t= ype); + nvme_status_ext->header.regctl =3D cpu_to_be16(keys_info->num_keys); + + for (int i =3D 0; i < keys_info->num_keys; i++) { + uint16_t ctnlid =3D nvme_ctrl(req)->cntlid; + nvme_status_ext->regctl_eds[i].cntlid =3D cpu_to_be16(ctnlid); + nvme_status_ext->regctl_eds[i].rkey =3D cpu_to_be64(keys_info->key= s[i]); + nvme_status_ext->regctl_eds[i].rcsts =3D keys_info->keys[i] =3D=3D + reservation->key ? 1 : 0; + /* hostid is not supported currently */ + memset(&nvme_status_ext->regctl_eds[i].hostid, 0, 16); + } + + rc =3D nvme_c2h(n, (uint8_t *)nvme_status_ext, len, req); + g_free(nvme_status_ext); + return rc; +} + +static void nvme_resv_read_reservation_cb(void *opaque, int ret) +{ + NvmeReadReservation *reservation =3D opaque; + NvmeRequest *req =3D reservation->req; + bool eds =3D req->cmd.cdw11 & 0x1; + NvmeResvKeys *keys_info =3D reservation->keys_info; + + if (ret < 0) { + goto out; + } + + if (eds) { + ret =3D _nvme_resv_read_reservation_ext_cb(reservation); + } else { + ret =3D _nvme_resv_read_reservation_cb(reservation); + } + +out: + g_free(keys_info); + g_free(reservation); + nvme_misc_cb(req, ret); +} + +static void nvme_resv_read_keys_cb(void *opaque, int ret) +{ + NvmeResvKeys *keys_info =3D opaque; + NvmeRequest *req =3D keys_info->req; + NvmeNamespace *ns =3D req->ns; + NvmeReadReservation *reservation; + + if (ret < 0) { + goto out; + } + + keys_info->num_keys =3D MIN(ret, keys_info->num_keys); + reservation =3D g_new0(NvmeReadReservation, 1); + memset(reservation, 0, sizeof(*reservation)); + reservation->req =3D req; + reservation->keys_info =3D keys_info; + + req->aiocb =3D blk_aio_pr_read_reservation(ns->blkconf.blk, + &reservation->generation, &reservation->key, + &reservation->type, nvme_resv_read_reservation_cb, + reservation); + return; + +out: + g_free(keys_info); + nvme_misc_cb(req, ret); +} + + +static uint16_t nvme_resv_report(NvmeCtrl *n, NvmeRequest *req) +{ + int num_keys; + uint32_t cdw10 =3D req->cmd.cdw10; + uint32_t cdw11 =3D req->cmd.cdw11; + int buflen =3D (cdw10 + 1) * sizeof(uint32_t); + bool eds =3D cdw11 & 0x1; + NvmeNamespace *ns =3D req->ns; + NvmeResvKeys *keys_info; + + if (eds) { + if (buflen < sizeof(NvmeReservationStatusHeader) + + sizeof(uint8_t) * 40) { + return NVME_INVALID_FIELD; + } + + num_keys =3D (buflen - sizeof(NvmeReservationStatusHeader) - + sizeof(uint8_t) * 40) / + sizeof(struct NvmeRegisteredCtrlExt); + } else { + if (buflen < sizeof(NvmeReservationStatusHeader)) { + return NVME_INVALID_FIELD; + } + + num_keys =3D (buflen - sizeof(NvmeReservationStatusHeader)) / + sizeof(struct NvmeRegisteredCtrl); + } + + keys_info =3D g_new0(NvmeResvKeys, 1); + keys_info->generation =3D 0; + /* num_keys is the maximum number of keys that can be transmitted */ + keys_info->num_keys =3D num_keys; + keys_info->keys =3D g_malloc(sizeof(uint64_t) * num_keys); + keys_info->req =3D req; + + req->aiocb =3D blk_aio_pr_read_keys(ns->blkconf.blk, &keys_info->gener= ation, + keys_info->num_keys, keys_info->keys, + nvme_resv_read_keys_cb, keys_info); + + return NVME_NO_COMPLETE; +} + typedef struct NvmeCopyAIOCB { BlockAIOCB common; BlockAIOCB *aiocb; @@ -4469,6 +4763,14 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest= *req) return nvme_dsm(n, req); case NVME_CMD_VERIFY: return nvme_verify(n, req); + case NVME_CMD_RESV_REGISTER: + return nvme_resv_register(n, req); + case NVME_CMD_RESV_REPORT: + return nvme_resv_report(n, req); + case NVME_CMD_RESV_ACQUIRE: + return nvme_resv_acquire(n, req); + case NVME_CMD_RESV_RELEASE: + return nvme_resv_release(n, req); case NVME_CMD_COPY: return nvme_copy(n, req); case NVME_CMD_ZONE_MGMT_SEND: diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 6abe479410..c18f17a332 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -470,6 +470,10 @@ static inline const char *nvme_io_opc_str(uint8_t opc) case NVME_CMD_ZONE_MGMT_SEND: return "NVME_ZONED_CMD_MGMT_SEND"; case NVME_CMD_ZONE_MGMT_RECV: return "NVME_ZONED_CMD_MGMT_RECV"; case NVME_CMD_ZONE_APPEND: return "NVME_ZONED_CMD_ZONE_APPEND"; + case NVME_CMD_RESV_REGISTER: return "NVME_CMD_RESV_REGISTER"; + case NVME_CMD_RESV_REPORT: return "NVME_CMD_RESV_REPORT"; + case NVME_CMD_RESV_ACQUIRE: return "NVME_CMD_RESV_ACQUIRE"; + case NVME_CMD_RESV_RELEASE: return "NVME_CMD_RESV_RELEASE"; default: return "NVME_NVM_CMD_UNKNOWN"; } } diff --git a/include/block/nvme.h b/include/block/nvme.h index 3409fba762..33503b9ba9 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -671,6 +671,43 @@ typedef enum { NVME_RESV_EXCLUSIVE_ACCESS_ALL_REGS =3D 0x06, } NVMEResvType; =20 +typedef struct QEMU_PACKED NvmeRegisteredCtrl { + uint16_t cntlid; + uint8_t rcsts; + uint8_t rsvd3[5]; + uint8_t hostid[8]; + uint64_t rkey; +} NvmeRegisteredCtrl; + +typedef struct QEMU_PACKED NvmeRegisteredCtrlExt { + uint16_t cntlid; + uint8_t rcsts; + uint8_t rsvd3[5]; + uint64_t rkey; + uint8_t hostid[16]; + uint8_t rsvd32[32]; +} NvmeRegisteredCtrlExt; + +typedef struct QEMU_PACKED NvmeReservationStatusHeader { + uint32_t gen; + uint8_t rtype; + uint16_t regctl; + uint16_t resv5; + uint8_t ptpls; + uint8_t resv10[14]; +} NvmeReservationStatusHeader; + +typedef struct QEMU_PACKED NvmeReservationStatus { + struct NvmeReservationStatusHeader header; + struct NvmeRegisteredCtrl regctl_ds[]; +} NvmeReservationStatus; + +typedef struct QEMU_PACKED NvmeReservationStatusExt { + struct NvmeReservationStatusHeader header; + uint8_t rsvd24[40]; + struct NvmeRegisteredCtrlExt regctl_eds[]; +} NvmeReservationStatusExt; + typedef struct QEMU_PACKED NvmeDeleteQ { uint8_t opcode; uint8_t flags; --=20 2.20.1 From nobody Mon Nov 25 09:33:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1715174006; cv=none; d=zohomail.com; s=zohoarc; b=kEOBheJ90U+2apZLJpBkqTLG8mWRftQ5j1SHlseDITCR/hXP6II2BKHg247Bw3qftVhv2QvcdV7yPOqmEuBibgPKFUbsfnETqv4x2apvT4igDF2R27QJvlS2nk1A1AYso1YMBSP5yD9ZLzzvF3bxBeABEFeZ14IDWnHNhWMAlgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715174006; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YzUXiaM2rF7jrfvYaToKOL09mhX+9O3YqGRC0KLKQCU=; b=i8hPUij//YlnkV0P+2mPbkF0H37IBoaYYI+thg1nsvTHDveI7cH/uF4vvR8JGbhz/faZk9QnVW8SxYE0FSlsMVEz8MUlo+dzhmfBD5H3YurLssX2vXWWIr+rLLrupFYQ+ZkUm2jgwnrCxy2ML2fQRK7iOSBVn0p8J82245D6Cv0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715174006036919.1047766895442; Wed, 8 May 2024 06:13:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4h5w-0005GB-46; Wed, 08 May 2024 09:12:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dl7-0007p3-PR for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:46 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4dl5-0000cK-NG for qemu-devel@nongnu.org; Wed, 08 May 2024 05:38:45 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1ed012c1afbso5437905ad.1 for ; Wed, 08 May 2024 02:38:43 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id p16-20020a1709027ed000b001ee13eb2bedsm4992178plb.98.2024.05.08.02.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 02:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1715161122; x=1715765922; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YzUXiaM2rF7jrfvYaToKOL09mhX+9O3YqGRC0KLKQCU=; b=N5wBxn+xXLp05eWpv7OrdY+rzi2bcuBEKStX5e3ICJAdXOqPr0biEXRDKhK/mQAJhA HG+d3a2qNXFyWnP9hQOhjRU8jlPkmaAFbHaundPMVF1/KSFzG6WTA2Yd6yrPxU65GjS4 c92FEmBBXxmPy0xjGQ5rRiBVDZdaPXmyFyPA3KFD7lIcB0Tbr3mx/NxIazT0Wt4Njy8U 29Qza7ebwbGHQb72XWJTe5BcrjZ1RmqpBhplef4gNGcV1smh4AX52+JCmUBcXg8lbplF MW7mLKI3ZllynHQ3gH5TuaAlkAmzucossqS7jDgHO9olVMOv4X/1kEtNvvhB45fHodcm RMfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715161122; x=1715765922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YzUXiaM2rF7jrfvYaToKOL09mhX+9O3YqGRC0KLKQCU=; b=sQs4G9Yunq4jy6ikeudhql+uE+niuvEf/BvIQeJpKCP2ijDdQBNnGCAP0QJQ+c3iJB zvAtzQpVt8Dv8eTARlbueSteboECVmIVr/9rpRvPUMTDyMv0NaC2cSBJ599JCAIvfNg4 yYyUxdbZZMqQ7rW+bWydtZTx4Lg6EbpT95BS36UvCnH+58AEdECkEbvjqYKSJPF8u6cU +J+7udSDQXTiOGBZxYTWvMdxfou1em9bGYHOBhCnDtHKOaqow9s/IrPOxUrECbXtWn3g x9/nl3KUFyyWfNbyg2JaG6u3n1brk9LKuln83kMFaCXNEvq3a/zvZRHe9+cxBbsmtp2x 1FPQ== X-Forwarded-Encrypted: i=1; AJvYcCV0kRAT/+VNa9d6Xr19sZYIZBAey2J9Muoa2czTeYRCdd6ABrgkcOj217+1NRUN50iYLSfsvPG6IRvoK4rn6G8K7v1ZFtg= X-Gm-Message-State: AOJu0Yxcy0RcdjLA9dEFOAv/GXeuopR0AK3qP+OO8MOyhs7b8n27vsYi JmwP5dA4idd2pFOI+9sG0fVyPTXKauDvEYSf+FU1kkEX6hljTvJMw6QIonIfSYs= X-Google-Smtp-Source: AGHT+IEO7jIQCm0v2ZcSn30JiFDREb6feNyGHvVZcsweJZrubutWiazXJxq7E8kHYJUe3kEGa8DzNQ== X-Received: by 2002:a17:902:650a:b0:1ec:c6ba:f2c3 with SMTP id d9443c01a7336-1eeab69ebc2mr26315975ad.2.1715161122488; Wed, 08 May 2024 02:38:42 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, Changqi Lu , zhenwei pi Subject: [PATCH 9/9] block/iscsi: add persistent reservation in/out driver Date: Wed, 8 May 2024 17:36:29 +0800 Message-Id: <20240508093629.441057-10-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240508093629.441057-1-luchangqi.123@bytedance.com> References: <20240508093629.441057-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=luchangqi.123@bytedance.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 May 2024 09:12:22 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1715174006713100001 Content-Type: text/plain; charset="utf-8" Add persistent reservation in/out operations for iscsi driver. The following methods are implemented: bdrv_co_pr_read_keys, bdrv_co_pr_read_reservation, bdrv_co_pr_register, bdrv_co_pr_reserve, bdrv_co_pr_release, bdrv_co_pr_clear and bdrv_co_pr_preempt. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi --- block/iscsi.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) diff --git a/block/iscsi.c b/block/iscsi.c index 2ff14b7472..212fab53ad 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -280,6 +280,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int st= atus, iTask->err_code =3D -error; iTask->err_str =3D g_strdup(iscsi_get_error(iscsi)); } + } else if (status =3D=3D SCSI_STATUS_RESERVATION_CONFLICT) { + iTask->err_code =3D -EBADE; } } } @@ -2408,6 +2410,386 @@ out_unlock: return r; } =20 +static int coroutine_fn +iscsi_co_pr_read_keys(BlockDriverState *bs, uint32_t *generation, + uint32_t num_keys, uint64_t *keys) +{ + IscsiLun *iscsilun =3D bs->opaque; + QEMUIOVector qiov; + struct IscsiTask iTask; + int xferlen =3D sizeof(struct scsi_persistent_reserve_in_read_keys) + + sizeof(uint64_t) * num_keys; + uint8_t *buf =3D g_malloc0(xferlen); + int32_t num_collect_keys =3D 0; + int r =3D 0; + + qemu_iovec_init_buf(&qiov, buf, xferlen); + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_in_task(iscsilun->iscsi, + iscsilun->lun, SCSI_PR_IN_READ_KEYS, xferlen, + iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + scsi_task_set_iov_in(iTask.task, (struct scsi_iovec *)qiov.iov, qiov.n= iov); + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_IN failed: %s", iTask.err_s= tr); + r =3D iTask.err_code; + goto out; + } + + memcpy(generation, &buf[0], 4); + *generation =3D be32_to_cpu(*generation); + memcpy(&num_collect_keys, &buf[4], 4); + if (num_collect_keys > num_keys) { + r =3D -EINVAL; + goto out; + } + + for (int i =3D 0; i < num_collect_keys; i++) { + memcpy(&keys[i], &buf[8 + i * 8], 8); + keys[i] =3D be64_to_cpu(keys[i]); + } + +out: + qemu_mutex_unlock(&iscsilun->mutex); + g_free(iTask.err_str); + g_free(buf); + return r; +} + +static int coroutine_fn +iscsi_co_pr_read_reservation(BlockDriverState *bs, uint32_t *generation, + uint64_t *key, BlockPrType *type) +{ + IscsiLun *iscsilun =3D bs->opaque; + QEMUIOVector qiov; + struct IscsiTask iTask; + int xferlen =3D sizeof(struct scsi_persistent_reserve_in_read_reservat= ion); + uint8_t *buf =3D g_malloc0(xferlen); + uint8_t scope_type =3D 0; + int32_t num_collect_keys =3D 0; + int r =3D 0; + + qemu_iovec_init_buf(&qiov, buf, xferlen); + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_in_task(iscsilun->iscsi, + iscsilun->lun, SCSI_PR_IN_READ_RESERVATION, + xferlen, iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + scsi_task_set_iov_in(iTask.task, (struct scsi_iovec *)qiov.iov, qiov.n= iov); + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_IN failed: %s", iTask.err_s= tr); + r =3D iTask.err_code; + goto out; + } + + memcpy(generation, &buf[0], 4); + *generation =3D be32_to_cpu(*generation); + memcpy(key, &buf[8], 8); + *key =3D be64_to_cpu(*key); + memcpy(&scope_type, &buf[21], 1); + *type =3D scsi_pr_type_to_block(scope_type & 0xf); + memcpy(&num_collect_keys, &buf[4], 4); + r =3D be32_to_cpu(num_collect_keys) / sizeof(uint64_t); +out: + qemu_mutex_unlock(&iscsilun->mutex); + g_free(iTask.err_str); + g_free(buf); + return r; +} + +static int coroutine_fn +iscsi_co_pr_register(BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, + bool ignore_key) +{ + IscsiLun *iscsilun =3D bs->opaque; + struct IscsiTask iTask; + struct scsi_persistent_reserve_out_basic *basic; + SCSIPrOutAction action =3D ignore_key ? SCSI_PR_OUT_REG_AND_IGNORE_KEY= : + SCSI_PR_OUT_REGISTER; + int r =3D 0; + + basic =3D g_new0(struct scsi_persistent_reserve_out_basic, 1); + /** + * spec_i_pt/all_tg_pt is currently not supported, + * aptpl is enable by default. + */ + basic->reservation_key =3D old_key; + basic->service_action_reservation_key =3D new_key; + basic->aptpl =3D 1; + + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_out_task(iscsilun->iscsi, + iscsilun->lun, action, 0, block_pr_type_to_scsi(type), + basic, iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_OUT failed: %s", iTask.err_= str); + r =3D iTask.err_code; + } + + qemu_mutex_unlock(&iscsilun->mutex); + + g_free(iTask.err_str); + g_free(basic); + return r; +} + +static int coroutine_fn +iscsi_co_pr_reserve(BlockDriverState *bs, uint64_t key, BlockPrType type) +{ + IscsiLun *iscsilun =3D bs->opaque; + struct IscsiTask iTask; + struct scsi_persistent_reserve_out_basic *basic; + int r =3D 0; + + basic =3D g_new0(struct scsi_persistent_reserve_out_basic, 1); + basic->reservation_key =3D key; + + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_out_task(iscsilun->iscsi, + iscsilun->lun, SCSI_PR_OUT_RESERVE, 0, + block_pr_type_to_scsi(type), basic, + iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_OUT failed: %s", iTask.err_= str); + r =3D iTask.err_code; + } + + qemu_mutex_unlock(&iscsilun->mutex); + + g_free(iTask.err_str); + g_free(basic); + return r; +} + +static int coroutine_fn +iscsi_co_pr_release(BlockDriverState *bs, uint64_t key, BlockPrType type) +{ + IscsiLun *iscsilun =3D bs->opaque; + struct IscsiTask iTask; + struct scsi_persistent_reserve_out_basic *basic; + int r =3D 0; + + basic =3D g_new0(struct scsi_persistent_reserve_out_basic, 1); + basic->reservation_key =3D key; + + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_out_task(iscsilun->iscsi, + iscsilun->lun, SCSI_PR_OUT_RELEASE, 0, + block_pr_type_to_scsi(type), basic, + iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_OUT failed: %s", iTask.err_= str); + r =3D iTask.err_code; + } + + qemu_mutex_unlock(&iscsilun->mutex); + + g_free(iTask.err_str); + g_free(basic); + return r; +} + +static int coroutine_fn +iscsi_co_pr_clear(BlockDriverState *bs, uint64_t key) +{ + IscsiLun *iscsilun =3D bs->opaque; + struct IscsiTask iTask; + struct scsi_persistent_reserve_out_basic *basic; + int r =3D 0; + + basic =3D g_new0(struct scsi_persistent_reserve_out_basic, 1); + basic->reservation_key =3D key; + + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_out_task(iscsilun->iscsi, + iscsilun->lun, SCSI_PR_OUT_CLEAR, 0, 0, basic, + iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_OUT failed: %s", iTask.err_= str); + r =3D iTask.err_code; + } + + qemu_mutex_unlock(&iscsilun->mutex); + + g_free(iTask.err_str); + g_free(basic); + return r; +} + +static int coroutine_fn +iscsi_co_pr_preempt(BlockDriverState *bs, uint64_t old_key, + uint64_t new_key, BlockPrType type, bool abort) +{ + IscsiLun *iscsilun =3D bs->opaque; + struct IscsiTask iTask; + struct scsi_persistent_reserve_out_basic *basic; + SCSIPrOutAction action =3D abort ? SCSI_PR_OUT_PREEMPT_AND_ABORT : + SCSI_PR_OUT_PREEMPT; + int r =3D 0; + + basic =3D g_new0(struct scsi_persistent_reserve_out_basic, 1); + basic->reservation_key =3D old_key; + basic->service_action_reservation_key =3D new_key; + + iscsi_co_init_iscsitask(iscsilun, &iTask); + qemu_mutex_lock(&iscsilun->mutex); +retry: + iTask.task =3D iscsi_persistent_reserve_out_task(iscsilun->iscsi, + iscsilun->lun, action, 0, block_pr_type_to_scsi(type), + basic, iscsi_co_generic_cb, &iTask); + + if (iTask.task =3D=3D NULL) { + qemu_mutex_unlock(&iscsilun->mutex); + return -ENOMEM; + } + + + iscsi_co_wait_for_task(&iTask, iscsilun); + + if (iTask.task !=3D NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task =3D NULL; + } + + if (iTask.do_retry) { + iTask.complete =3D 0; + goto retry; + } + + if (iTask.status !=3D SCSI_STATUS_GOOD) { + error_report("iSCSI PERSISTENT_RESERVE_OUT failed: %s", iTask.err_= str); + r =3D iTask.err_code; + } + + qemu_mutex_unlock(&iscsilun->mutex); + + + g_free(iTask.err_str); + g_free(basic); + return r; +} =20 static const char *const iscsi_strong_runtime_opts[] =3D { "transport", @@ -2451,6 +2833,14 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_co_writev =3D iscsi_co_writev, .bdrv_co_flush_to_disk =3D iscsi_co_flush, =20 + .bdrv_co_pr_read_keys =3D iscsi_co_pr_read_keys, + .bdrv_co_pr_read_reservation =3D iscsi_co_pr_read_reservation, + .bdrv_co_pr_register =3D iscsi_co_pr_register, + .bdrv_co_pr_reserve =3D iscsi_co_pr_reserve, + .bdrv_co_pr_release =3D iscsi_co_pr_release, + .bdrv_co_pr_clear =3D iscsi_co_pr_clear, + .bdrv_co_pr_preempt =3D iscsi_co_pr_preempt, + #ifdef __linux__ .bdrv_aio_ioctl =3D iscsi_aio_ioctl, #endif --=20 2.20.1