From nobody Mon May 25 20:33:42 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1778304234; cv=none; d=zohomail.com; s=zohoarc; b=M019ErlFfAd5oOjRiM8JjOFEyI4Iantkx8TZkAE/jPmK9O0Y+KAohHLPfb6OfLTQJyAtDcv0sv2kHsLYEoUnTFmyE9K4pNdP313hJR3aPi2ajTMr5/ok4L+z9NSrG2bppYtkoemdhbo1FTbLVLOKKxAFTv2FRDlK94oI3LeuPDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778304234; 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=plpHRHrl9ewbt9bmKWd1qyedvODHuUTpEffj852qVy0=; b=Fh8bZUX3hn9xNGydMvsGTnk84axAGHj7OVeOxZUr5yyXB97kP0uz2uRJqgqe0p7N6+cCAZTUZVEQyiADTcK2ni4SXShy2L7ZL6KiEDu4ey672WshHD4w0oNW6Wv22B/z1plgViX4bdTKy3theUsRRMlSH755emRt8HoQ2O6N2P0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778304234405535.9377006845606; Fri, 8 May 2026 22:23:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLa9l-0000gK-PN; Sat, 09 May 2026 01:23:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9j-0000fU-Jt for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9h-0007HN-Q0 for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:15 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-244-CjJijHhsOnKVG_RCNvu73A-1; Sat, 09 May 2026 01:23:11 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-488c0120047so16403255e9.0 for ; Fri, 08 May 2026 22:23:10 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e7040a9a9sm38603875e9.9.2026.05.08.22.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 22:23:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778304192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=plpHRHrl9ewbt9bmKWd1qyedvODHuUTpEffj852qVy0=; b=ZgY1KimS0QYJoMdyqCEgtZm07VTGC4zy9WpLcTZzhseITJANuO6EmfgyqA+sZqFrmOXP1H ndTjZp92VCuiljdd07p88eMnzsJhUTwvpX18TH1tw48z/SYahS2Gmcn8QWGWLIn7ZQcvJd lUqz0PR1wHqgXksuCnJSd2UrG68Au9k= X-MC-Unique: CjJijHhsOnKVG_RCNvu73A-1 X-Mimecast-MFC-AGG-ID: CjJijHhsOnKVG_RCNvu73A_1778304190 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778304189; x=1778908989; 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=plpHRHrl9ewbt9bmKWd1qyedvODHuUTpEffj852qVy0=; b=FGORE3F2lqJqS2jSPKyiTMRSh7ozuyMwGl0cDIVOaiuoBnJ2WKz/1CsDCBXMB1EMU+ 5VqPevP8J4xfLlU91JYiz/P4FA6FHPcgxiuKkNSuHrTSqgouPHZ2rVBwg56c4sDqaB5G yn/Lap+VPBOcsJvmKpvU272e2J6+Y2a9tfkgGF7Uiu3h+DMzVoTbOqGGUw3EE9Fa8OkE KnnJdf19A6T7WMh/lvlkFimkam7Eyfh9XVF5hpo3nUJx/jYwMWmQ308xnJU9QNLTVfk0 chqhOEZyM/Y2CxU7FSBELVAj4sqFooJTYk/5EyfLZf5pmfG+YpYAMewTbWvsvyW4sLpF TO8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778304189; x=1778908989; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=plpHRHrl9ewbt9bmKWd1qyedvODHuUTpEffj852qVy0=; b=Et4SdqWqG9FdhPNhs+pNdLr84xE2bb5qNNU5p2BmXjoLIYjrU5NoE5XQkiGAWzglT9 fUZNYVYsJjU3DcA+psLAs9lBnbPXmRpK3rqEoQNjL9vRuDCFunYunyr8OKgeBmLwQDv/ q6TVX4/zHd6+nMu+QvRnsdeKwW8Zi79FX3qmsex9SUCgh1bId6Q4rHcXDx5XOA7TYFu/ g3wEXhWQHRvibLbIx9ux6kaXzhzqXcCzKxq4cER6k11KgK1Trjk2j4ZaLh4KAEGX3R9d C74fhIMPHI8e66yriWKHb//WoweNLS2MwrK8XFzS4M0eg05uuPBCgVhZFeoLBmcilCR1 xYpg== X-Gm-Message-State: AOJu0Ywtg2Xpvd+auDpqWf4oPcww/g+FXnuoJlMOjueWwfWVZb7A3Pgk HLaNqfm9J3JYO4+aQxX1oPDvlLw6EudQb1i0KNNsaYJzrtvQTkExwzWtrjBw6tYS5JzT1qY24bs qMjdzZpudTzFIkhB9epnd3hPLPcmKSHwA2CNPClveB4iLHtaJiowPfNI9WpJHmhAvVwCdmxGmrM KvAM9ZfowT/FBBHHP1me59RItpPbRBBSL++GVk5b2X X-Gm-Gg: Acq92OE10/+epoQ61DymM3psPUjj0iIn4XztROLUypwXjcrko06pSy5Ry3/TAKn8RxZ +GvOz3ng2W2my6VFzzGoE5YP4nywMaa/EtFmhS3Uq1KywtvjVuMt5oAR1vhkWgzaBfWWpvD4p9R FS7vxrSUYvZA56ItP/JPuhmmJwy/PvU+M5qeq0pt5a9TGGK9Hf7n1qJ91j9smszjZeus5sXTk1L 2/zPNMiY+PDr36jPjv60uh+LsTA+5kpsuUh57GuSFfE7tTTHu4J914uL2yglSTLym6muvbIs3fh DigpiPs/a34H+1jeb16qUj7x42OvTsQxIZ8hoacvh5uiYujQOAOkySOK31nsKEJkKJEIctGMfP3 iux0a8Qvz6wf/9o2EYc7Ku46QLpIAHkwoCU71cnlufBdPeHWPMLHaGSG8iUVaXqCaofpKEUNlJO PO5Ik/I1yaoBAmTCRxip/MvdhWa9xA X-Received: by 2002:a05:600c:3548:b0:487:1108:48b8 with SMTP id 5b1f17b1804b1-48e51e0a60fmr231291425e9.2.1778304189157; Fri, 08 May 2026 22:23:09 -0700 (PDT) X-Received: by 2002:a05:600c:3548:b0:487:1108:48b8 with SMTP id 5b1f17b1804b1-48e51e0a60fmr231291145e9.2.1778304188648; Fri, 08 May 2026 22:23:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Subject: [PULL 1/5] scsi: change buf_size to unsigned int in scsi_SG_IO() Date: Sat, 9 May 2026 07:23:00 +0200 Message-ID: <20260509052304.2159829-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260509052304.2159829-1-pbonzini@redhat.com> References: <20260509052304.2159829-1-pbonzini@redhat.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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.44, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1778304236678158500 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi SG_IO supports an unsigned int dxfer_len value. Existing callers use less than 256 bytes, so scsi_SG_IO()'s uint8_t buf_size type was sufficient. The next patch will use a larger value, so update the type. Signed-off-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20260415232906.212349-2-stefanha@redhat.com Signed-off-by: Paolo Bonzini --- include/hw/scsi/scsi.h | 3 ++- hw/scsi/scsi-generic.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index a3e246dbd92..5f83e58d1d0 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -247,7 +247,8 @@ void scsi_device_unit_attention_reported(SCSIDevice *de= v); void scsi_generic_read_device_inquiry(SCSIDevice *dev); int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fix= ed); int scsi_SG_IO(BlockBackend *blk, int direction, uint8_t *cmd, uint8_t cmd= _size, - uint8_t *buf, uint8_t buf_size, uint32_t timeout, Error **e= rrp); + uint8_t *buf, unsigned int buf_size, uint32_t timeout, + Error **errp); SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lu= n); SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int target, int lun= ); =20 diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index a2316a5266e..e629b1756b0 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -774,7 +774,7 @@ static int read_naa_id(const uint8_t *p, uint64_t *p_ww= n) } =20 int scsi_SG_IO(BlockBackend *blk, int direction, uint8_t *cmd, - uint8_t cmd_size, uint8_t *buf, uint8_t buf_size, + uint8_t cmd_size, uint8_t *buf, unsigned int buf_size, uint32_t timeout, Error **errp) { sg_io_hdr_t io_header; --=20 2.54.0 From nobody Mon May 25 20:33:42 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1778304266; cv=none; d=zohomail.com; s=zohoarc; b=i8K27brKwVuhzByTFbpL+Xq4UDZ7sLwDcQFwLeNkKtIpY/5eShvxnkjZd2tYpZIjXb3k2jcfnIbrzyGgshK27NP1Du+bY9bmgb4cEpgPycb9kOE7eI95deL03oET2AqiabR9JdeYA2ypjcrcQpD0i3df2YfSouM36wg0LsIat94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778304266; 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=nNkszS3JD+hctSC8f4FoyRu8v9EIlOM/MNYQI7jR03Q=; b=DEMug2F3Gwu2mNsy9Ofk2FgjnFWj7HilYU2HEsv9pJCBD/HRTPTAWAzoG4Cu/664ehOsmmtv3COKRmOlKSI7Bpi3BenkAT0ulSIR+7onet4R98It8C2daINgJOhOC4O/D2c2v7oFQgafZYq7gTgMiSDo2CCeHDqGECncflNeQZI= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778304266524386.3662956861948; Fri, 8 May 2026 22:24:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLa9n-0000go-6k; Sat, 09 May 2026 01:23:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9m-0000ge-8i for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9k-0007I6-TP for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:18 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-oAzG_JpTNxC7uRCDuJEsuQ-1; Sat, 09 May 2026 01:23:14 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48d144d3428so15090785e9.3 for ; Fri, 08 May 2026 22:23:14 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e7040a9a9sm38609605e9.9.2026.05.08.22.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 22:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778304196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nNkszS3JD+hctSC8f4FoyRu8v9EIlOM/MNYQI7jR03Q=; b=BCXpY5MOLnnFIHDWSQQ50u7Qapu8T8RGhyR8LzhS6rlRNMh+9DUDA0dd64olEvxezpORKj iyMS0V6PLFVVmIoghoK+7Y9TwN5KGy8C7ElS3gO2YAxhCUb6zWaE4mgEQPAJe4nr7l2Mzn 2Vs2y2rNGk8rQSAjkRTavx1oaFoMNwM= X-MC-Unique: oAzG_JpTNxC7uRCDuJEsuQ-1 X-Mimecast-MFC-AGG-ID: oAzG_JpTNxC7uRCDuJEsuQ_1778304193 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778304191; x=1778908991; 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=nNkszS3JD+hctSC8f4FoyRu8v9EIlOM/MNYQI7jR03Q=; b=ISet4cKQA078qZ7Tzw/ceI7B38msnhfINMbC9k54sIDSmRbUkAco4oQQPVPAHh2L3z N/k5dsKD62N8dMAK6EbIFhAA++X/wVlUSTwYGhzRM8EfgspV1fohXOWCtTkyT0wl7u2A XbiyxkaUkulYm+NUKYdok2eP1e80sWZqFwz4N1ib19Ek3T+VmS4YrxhkdV+o4tC5qcNG z3wcYMIrLWbw6P2nLWxKrJYpvmnFRnOPWFUVAZ/2K7sZbAfFHzKOpgtNvXgT3x6u2nDX eq3ja5jSpENsmEenyNhxGTe+zH5Sn2rmr/oJ00eEpFmAENnfeH0IOg+uRY5YWUhifnyE PBAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778304191; x=1778908991; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nNkszS3JD+hctSC8f4FoyRu8v9EIlOM/MNYQI7jR03Q=; b=ia7IXRKIP+EaZZj3CFUaANMb2Cp6p0fEt35AucrU4iwiCB4nuPAicfBS0gMgKmCGO/ FjZoGFMZTxFzI7827rYqmtxgrVF1kOZ9tE51KfR2p/wjiA3Rg6DwONZC7YNR2W/7rvNG VeY57oXW0o7AIQoqic3HBxm73dGMWCDQ1svN7m1CvOiyGlJKldjWf8N1L9Ar/fqNLikc gtA5sxvgLNdnUB7WY/IZ/xgOdxdK3mjyoQHnDqT23rJewd3/gcG1+g70UkDcYYkotPG1 IczYIxxDyzenVvdE4r3UCSxLhnca4GlJ/Ts4lCbuKHjO8229keVG5GNqG2gZU7hx41Yt pW2w== X-Gm-Message-State: AOJu0YymuoHd/jvH5EfLdXfBo3Q76C2rEHbJ7vmKNsqP8tAlMxwVHPsh CpCmoJQUoTaAW9eDfm+tzBbk5lfnNUTPzu05wNrF7TJMVaASNxDR7NEfSigu79SG+Vlv3ZXuXCO IYholOeyYnlJUyqGXXcA4WBiya9wSVJgDvGZUvwGdp9uZYjqbBLm4zXWPzBFVIod1zYJzCx+Ig5 I5Rxz1l63Siojh87L+QIuexPjMMY2lB0fjDZktzXdJ X-Gm-Gg: Acq92OEWFlbq7yPKXvNIuipOXpuDZv/SwvVr0TQiJSzukzePu1YcmZEveDweDTx7Lis +A7Uc8sA7mwxdfGuesWkUNDYcJO6pGSx4Up2r02zYuXG3DNbpa2+KUE+T9BqrkFonj7FluajjjM Gt0uBMPUnaFdN3s/iIj3iT5HseYCfkwy0Pt+aORjlvgTcrA1moawgbGwRMZEHfcZ7Rmf91qRbQw oC9m6mVWaan5xPSi0qtSQOJKwpgod4DCS3sxjZumVU+BJGI45BP76n3JVvPcB/FDuotqUxgeAhM tuA0stbDqsy7C7WAgy16v104NMNUxCE5FHopV+5qOv3LhKIgVXTxMqUlTfz1HZOlYJ+SIh6bNM8 eVBpkN3N/7RfYZ7ruSgMqchq8TDiY/P+IL68dFzvj7oy0YKvDesiglcXf/wX/2CiJSuzWvJH8eJ I1+vVfgQO2BgfaLC0qB3ux6VkGWPoS X-Received: by 2002:a05:600d:e:b0:489:ad:7b5b with SMTP id 5b1f17b1804b1-48e706d24e3mr13945805e9.24.1778304191259; Fri, 08 May 2026 22:23:11 -0700 (PDT) X-Received: by 2002:a05:600d:e:b0:489:ad:7b5b with SMTP id 5b1f17b1804b1-48e706d24e3mr13945545e9.24.1778304190891; Fri, 08 May 2026 22:23:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Subject: [PULL 2/5] scsi: adjust error_prepend() formatting Date: Sat, 9 May 2026 07:23:01 +0200 Message-ID: <20260509052304.2159829-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260509052304.2159829-1-pbonzini@redhat.com> References: <20260509052304.2159829-1-pbonzini@redhat.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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.44, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1778304267985154100 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The error strings will be concatenated so add a separator to make the combined error message easy to read. Signed-off-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20260401171927.396672-2-stefanha@redhat.com Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-generic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index e629b1756b0..d0086d86d94 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -439,7 +439,7 @@ static bool scsi_generic_pr_register(SCSIDevice *s, uin= t64_t key, Error **errp) ret =3D scsi_SG_IO(s->conf.blk, SG_DXFER_TO_DEV, cmd, sizeof(cmd), buf, sizeof(buf), s->io_timeout, errp); if (ret < 0) { - error_prepend(errp, "PERSISTENT RESERVE OUT with REGISTER"); + error_prepend(errp, "PERSISTENT RESERVE OUT with REGISTER: "); return false; } return true; @@ -463,7 +463,7 @@ static bool scsi_generic_pr_preempt(SCSIDevice *s, uint= 64_t key, ret =3D scsi_SG_IO(s->conf.blk, SG_DXFER_TO_DEV, cmd, sizeof(cmd), buf, sizeof(buf), s->io_timeout, errp); if (ret < 0) { - error_prepend(errp, "PERSISTENT RESERVE OUT with PREEMPT"); + error_prepend(errp, "PERSISTENT RESERVE OUT with PREEMPT: "); return false; } return true; --=20 2.54.0 From nobody Mon May 25 20:33:42 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1778304273; cv=none; d=zohomail.com; s=zohoarc; b=Hz+5uMuOtV9wP96LJuOtoq1ygUhq5/Cf90kiN1Wl3f3Xvd/sQuTaTuQ/hTr1Sai+AGg6MN/XHARWjrl7I6CwHkL2SNG5fq7jNA9Bt8lE61UMIPe5B418hKjUzDL+ZjfrbyYO/rWqXah2/WM+ThrZ09YBq8ijBATskTpNh3DpyXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778304273; 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=OPqRifcNBcx2spNpK0C/rcHXsgRllLbXT2mzGwKdmyM=; b=KaCViOrT4zifMUqZUcSTRRWF5Y6SwpcW457lfBqzBHoHitD1NgPMLL5Q6w4TI/ku3TcSlxCf0s9iyim6g8UeWu4kAkX0PZbT3MXGQlYThOAlVTK987n3F8kvPOYi+KtLIkOesH47FvmUSaHfco0plTqMKlG7aWS2aZVaR4ePwzw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778304273153793.4013466341996; Fri, 8 May 2026 22:24:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLa9t-0000hw-8q; Sat, 09 May 2026 01:23:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9r-0000hQ-Lm for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9q-0007Mb-6O for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:23 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-cvBouv0jNSm999H8zbPfvg-1; Sat, 09 May 2026 01:23:18 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-44f56d5523eso2210987f8f.1 for ; Fri, 08 May 2026 22:23:18 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4548e6a5b65sm9568740f8f.8.2026.05.08.22.23.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 22:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778304201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OPqRifcNBcx2spNpK0C/rcHXsgRllLbXT2mzGwKdmyM=; b=iycDgZFFXGMe+27Y9+LpVoEH5NHyfQWxLUy73wva8dPRWkGYjruBf5tMQw/ngbJsbkCizp Xm8482CXMykieYJGys0NWw0au5TycZR10gYEB0WBaZm0IyXygZ2CKskPPN9h5uk+MkumXu FuGKVdXg9F4j/nDZTy2mEMY2BkhRvw0= X-MC-Unique: cvBouv0jNSm999H8zbPfvg-1 X-Mimecast-MFC-AGG-ID: cvBouv0jNSm999H8zbPfvg_1778304196 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778304195; x=1778908995; 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=OPqRifcNBcx2spNpK0C/rcHXsgRllLbXT2mzGwKdmyM=; b=atzMxLQz8+hPj8ZZBSxEbjdtM2BZu3nSkFZsdjujLOIexNMs2xg7HkqWTmD8AyYIHD RUZHnR1wKNb1Yr+2SGV7khueKru++zdHPnCCTtFjFrDUF1PLStkkGoPaUraZ992qxn6Q qrHyEvg1dby/xetytlUIsPcVLR2+kbY/TKvCzNQZoUJLLwJdwrM3y/yP7pItQX4x3Tno 3YuZXQ3gD8pqsV6G8Wdy4ypoQVePN7UwmZ7kQuYvtlguRGgaykdxCfRVAb3sAHExvXDQ HI8WBSUv1EGOlPHu+MFW08l5+4n8na1w1DRznRCPtUGVDVsogJdeAg+AMcBUAnYr3bhy rDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778304195; x=1778908995; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OPqRifcNBcx2spNpK0C/rcHXsgRllLbXT2mzGwKdmyM=; b=m8sbOrAqNVdgt6MNPuNWXEfg34/lYffPVPlME1teNDh2zv0S+LVvF4Rsns3dmnAlk0 EwkgE88aqvxtDGLT+KLHqAFmBXKTWxH05gQQ+9S5MWbegICWUfmQN9kDYLUcpviRw9fb +Tr8QSd12l+e72AcocHBR+7/ec3ZFZQM+JsFvsPhaoywfogtI+fQwX+aSMC4K1kLa9GF lWghWEF4QwdTk6ijiO6DAlO8DSOG12J0m0TC8TtU3TijXzXfzWIBgW4ly/0oT7DrCSd4 95Ek2SdDm3jPcXBJfW0bfT2bu1vBlzF82GtNyrc5d08//27NhEwLnfZvwcInblBGVf4/ pLDw== X-Gm-Message-State: AOJu0YwNcUnuGheK5WNa1RrRPCRvxJ8wtsqxVer7PsNFcvSAgUOPYizQ Gz98KOoScalObkAGSUeDohwz9MLUFWonSRpro0FKq0bMVcqfVRRfnGH0wapNjWd+PIC3vDe94A8 yckN6Na2bTajJiQ3KbrZkNuQtU2kG0/a/l5xsspZUykHW1Pi/sUVueGsosw194HFb7oZQXiI4ek F9sSwBX8x/IHNKuhGL8F2Rv5gJT17xk3LK8fpQAZkg X-Gm-Gg: Acq92OFE4SJe7ge2yR0s2e8UkFUY+S/64lfkI4rwbMw+nb6MaYOOYvbpSj9kgEXeozy WH39XDZa/rTvcd4czh3TAEjqlrovqQYgnB2omPy/8dD1LFKN1LMsJBSN6KS2Th1dTkQgT33RLDB E+6w7xM8ElhLsZFpPrAdmXOFhNTrshXK55+nJxGY+0vnTtCzMKNa3YCUWvA90TdNhNSic2HZP17 QrylQalJguzBoofuETjWg+sx6MlxGfFls6Mbyl92PCt3BVCNeZ8JheVLkktkNbwt34BSkrvvrOp w237HwQFq06HiV1Y2M2GhHrNPLBFmYpxpUpHy8Ki2qL67skEyWmXe+hCDlbNMc2TUKNu6IJhHMI QuLYVHKlUmTi/tTVnWtLinKK6csmb/ukoIkhZvGnIDBeNOqYzbKnTkmgFDvFiuuBVmSqvLJNRno nSP9peiqREc0xin/ZsgHL07lFGgYDW X-Received: by 2002:a05:6000:400d:b0:43d:69ff:6898 with SMTP id ffacd0b85a97d-4515b0571d2mr22313092f8f.9.1778304195581; Fri, 08 May 2026 22:23:15 -0700 (PDT) X-Received: by 2002:a05:6000:400d:b0:43d:69ff:6898 with SMTP id ffacd0b85a97d-4515b0571d2mr22313062f8f.9.1778304195146; Fri, 08 May 2026 22:23:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Qing Wang Subject: [PULL 3/5] scsi: always send valid PREEMPT TYPE field Date: Sat, 9 May 2026 07:23:02 +0200 Message-ID: <20260509052304.2159829-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260509052304.2159829-1-pbonzini@redhat.com> References: <20260509052304.2159829-1-pbonzini@redhat.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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.44, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1778304274262158500 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The SPC-6 specification says that the PREEMPT service action ignores the TYPE field when there is no reservation. However, the LIO Linux iSCSI target rejects commands with a zero TYPE field. The field never ends up being used in this case, so replace it with a "valid" value to work around the issue. Reported-by: Qing Wang Buglink: https://redhat.atlassian.net/browse/RHEL-155807 Signed-off-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20260401171927.396672-3-stefanha@redhat.com Signed-off-by: Paolo Bonzini --- include/scsi/constants.h | 10 ++++++++++ hw/scsi/scsi-generic.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/scsi/constants.h b/include/scsi/constants.h index cb97bdb6362..717e470a5d4 100644 --- a/include/scsi/constants.h +++ b/include/scsi/constants.h @@ -340,4 +340,14 @@ #define PRO_REGISTER_AND_MOVE 0x07 #define PRO_REPLACE_LOST_RESERVATION 0x08 =20 +/* + * Persistent reservation types + */ +#define PR_TYPE_WRITE_EXCLUSIVE 0x1 +#define PR_TYPE_EXCLUSIVE_ACCESS 0x3 +#define PR_TYPE_WRITE_EXCLUSIVE_REG_ONLY 0x5 +#define PR_TYPE_EXCLUSIVE_ACCESS_REG_ONLY 0x6 +#define PR_TYPE_WRITE_EXCLUSIVE_ALL_REGS 0x7 +#define PR_TYPE_EXCLUSIVE_ACCESS_ALL_REGS 0x8 + #endif diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index d0086d86d94..f1c328e6da6 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -453,6 +453,16 @@ static bool scsi_generic_pr_preempt(SCSIDevice *s, uin= t64_t key, uint64_t key_be =3D cpu_to_be64(key); int ret; =20 + /* + * The LIO iSCSI target in Linux up to at least version 7.0 rejects PR= EEMPT + * commands with a zero TYPE field although the SPC-6 specification sa= ys + * the field should be ignored when there is no persistent reservation. + * Work around this by choosing an arbitrary valid PR type value. + */ + if (resv_type =3D=3D 0) { + resv_type =3D PR_TYPE_WRITE_EXCLUSIVE; + } + cmd[0] =3D PERSISTENT_RESERVE_OUT; cmd[1] =3D PRO_PREEMPT; cmd[2] =3D resv_type & 0xf; --=20 2.54.0 From nobody Mon May 25 20:33:42 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1778304277; cv=none; d=zohomail.com; s=zohoarc; b=RI0jjue8GG445NOTap1R4EcmxLadWs0a2rj0JkdKH04hgT7h1dKsvJ2wNQlecWh5VQ7UeH116EeDviBkXfzapwKdWDOcCAzWwX3oYtE/6IJw7KdZNKSeoP1AhmS6xRL8N7MYWnEDDeoxD112CpkPUIvgu4DNAsU3z7sGbJGrfU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778304277; 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=rmcvllseInYN32LRwlJ5uUOWOG56WIpWVcOlOni/BfM=; b=G0P0rpe46KL185E9FFUJsDc3eOKvR15sZCxB45hycn2ofrN99/QOe+Ep2cPw+l9zwK1H3DH7enjIE2wVNV0ssd6wZY0GyWVNQcGUzLlwAlOa5o5Fft9CrVAQ9fPhyCOxxvg0wanhlqPHBv6ELRBvIqCazNAvjeO+XS4HmZ6tIak= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778304277856360.143257393108; Fri, 8 May 2026 22:24:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLa9t-0000hz-Go; Sat, 09 May 2026 01:23:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9r-0000hX-Us for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9q-0007Mg-JO for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:23 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-k_hXZmF7N-O3itZJIESlmg-1; Sat, 09 May 2026 01:23:20 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48e60b55de2so21798215e9.3 for ; Fri, 08 May 2026 22:23:19 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6fff9c91sm23821715e9.1.2026.05.08.22.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 22:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778304201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rmcvllseInYN32LRwlJ5uUOWOG56WIpWVcOlOni/BfM=; b=eMSpaJbitmwaPM4fZjACOd6ENM4zU2ZGlqoQUuLHsazdiiPYyyz5Si4lB558TVirBdyBVY u/rBhiY52pjLx2+XAeD8otn2U0/eg7ML4Lvz5WBEf+66iuvbMf1N7GXCfpFeGHPn54Xcvs uWwFyMUCd+Yv9EynIPEQFuq2BDHpCUQ= X-MC-Unique: k_hXZmF7N-O3itZJIESlmg-1 X-Mimecast-MFC-AGG-ID: k_hXZmF7N-O3itZJIESlmg_1778304199 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778304198; x=1778908998; 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=rmcvllseInYN32LRwlJ5uUOWOG56WIpWVcOlOni/BfM=; b=C6VXP+Iwdhso8s74xxnq0bo0Rpb8OsQ8a5wqOIMTbvIjp0fhpeR9ZPbStaGhE+aGE1 /LMC7pHZiw/kTUZhaqhWqXcxzbAFtflCDhyTp4YM0s+o9S+5qTicW9zoQnzP0eKfVnfN gl8VmDoOQaoghm5Xqsf1bpPFxKgvgea+jTLn9v19aYEyUm/IPKUGfGfeFZMpKNENfIOe /SJgHhFm7exlu9hDCQxWmaWl+dmaX/L2ZWqEl/F3rsag9i8W5h5pQ2G13NpkSia2DiS2 H7DZscQOVMxuJtjFYssYv6qPeYI7ZkFzOiX1GBTsYzBJAyJfqGxJ1hSguGnFIsIIU5Lj KG3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778304198; x=1778908998; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rmcvllseInYN32LRwlJ5uUOWOG56WIpWVcOlOni/BfM=; b=Jk32HkUHyQeCUgG8DljuDIpPz2eNahlbC5uvFZ9uSaHFLdzrpn2eVJqK/Zw1JgIrpf HKdQ7tg6wmufZj1Laa39KyWrcLFMvfpqbLFbJElfR4CI5t24vGLEsEV0bw+8AlqyTwQD lG1EBcNhcvzr+xU7q7rG7XCSAOXqHgu7ahH1Jpuyf22o7woVEr5ffgjUaQSYJxTS8FmN sIFow81HsHGf/SGNOI35pl21dgSFVlLVt6B+CjCYHBmorJFkQYTvmLS1HD45LhYHv7up EONZ/L9RY96yweUXMfgqyVlDYiYUK1CKhXCKF4qIZN5R9Vt97h2PDCW/N/V66NyLWaED vAJQ== X-Gm-Message-State: AOJu0YzHxIDtNjTlwazMnKU/KIEQukFGhgewnR/dn59PqNKtS3aW+02/ Z1A75N5ryG4tRaaut9lfJOw18SC/CxfjSQFjvZN/JsxGVBZKMejaQTopSn2Vo5xtRtPreTxSix5 S2onveERbOTCEamDpKd9+uU9UFJ5PrFxUY+21K8W136lgTkte+dks6dcVSisrGBdR7734MaNav6 J/8E3eqUzcNyYtolX1omG6ql0IYMowyFyQHRa/l8+k X-Gm-Gg: Acq92OGqVYETG24hFqG157rfC5zk7B8hCWFiFKJiDG9fex3KwuGMhg4cQt7MQ0On55y 7+bGoxQR8pB6wmt9h+HFJ/T5vpHyi4PoIy9K0tG6/8MobiotBm052/yaiAGE40kpQnfLe5lS2Ll +keYPck2tjy2wC6kGDNebGFXMtUlrKsjnc9nntLDpIvuryMWMJ8jblZvSm7T1VAaLA/mDdWhsCj jBE8mZpwY7Lb6GvPBPvVGOV/072aYU0c1HMJUKmcJMJNi1IpzBZlLDe5Yij/QlR4+E6DM9p6u3B 7FAK34+caB++1upYPiLRmMNckGT0sW7HzUGX11uOOxOT3sBYPsalof/bAHmNX59el8aEWa4WtK4 e1vjj9mY4MWicT6NkFLUNCL8YJhsJDHAxfJo82hoxo8LEacL5amWw0xPxoRmSULPUk6o/WNfEzB SdI0F/dE5nj25Wy10Ys9A4AfSaNA7/ X-Received: by 2002:a05:600c:8485:b0:489:1f3e:5f6f with SMTP id 5b1f17b1804b1-48e51f327f0mr248797865e9.12.1778304197856; Fri, 08 May 2026 22:23:17 -0700 (PDT) X-Received: by 2002:a05:600c:8485:b0:489:1f3e:5f6f with SMTP id 5b1f17b1804b1-48e51f327f0mr248797475e9.12.1778304197449; Fri, 08 May 2026 22:23:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Subject: [PULL 4/5] scsi: register again after PREEMPT without reservation Date: Sat, 9 May 2026 07:23:03 +0200 Message-ID: <20260509052304.2159829-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260509052304.2159829-1-pbonzini@redhat.com> References: <20260509052304.2159829-1-pbonzini@redhat.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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.44, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1778304278252158500 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The SCSI specification says PREEMPT without a reservation removes all registrations with the given key. Try to register again after PREEMPT since our key will have been removed. In practice some SCSI targets keep the calling I_T nexus' registration instead of removing it. Therefore we need to handle both the spec-compliant and the non-compliant behavior. Signed-off-by: Stefan Hajnoczi Reviewed-by: Paolo Bonzini Link: https://lore.kernel.org/r/20260401171927.396672-4-stefanha@redhat.com Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-generic.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index f1c328e6da6..29bc952af5d 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -513,6 +513,16 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Erro= r **errp) if (!scsi_generic_pr_preempt(s, key, resv_type, errp)) { return false; } + + /* + * Some SCSI targets, like the Linux LIO target, remove our + * registration when preempting without a reservation (resv_type i= s 0). + * Try to register again but ignore the error since a RESERVATION + * CONFLICT is expected if our registration remained in place. + */ + if (resv_type =3D=3D 0) { + scsi_generic_pr_register(s, key, NULL); + } } return true; } --=20 2.54.0 From nobody Mon May 25 20:33:42 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1778304234; cv=none; d=zohomail.com; s=zohoarc; b=Y6FATU7YCKYkD6HuyrgOhUsxvDQC69NbsbB6y9Vweoahxzej94qi/e33zgVUKuq0o3iMxkDk80Ai52JzPbay5xnUEONlGnRXh55MKyp4oZofnE8ait53Z1pQA8A6zad+t+Iy6wMauZ3CUqlNczeIQ4Z1bduik/IzmId5oQT4dfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778304234; 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=WHAANPw3hoVZMvfFza2Z/uOEAoSMVMaGiu2b+FC5QMc=; b=kNA6hfMUXTsKBucFLcadFflqYr8ncT53nZSuBXXpP6kfQxU8sZmWu2lfRvnP9r1KrOl9s4XborXdJ5AVcok8iVDi5tQZOIfIcfCfrVEpXnWAU/HRtikJuxrpodDZFovrWHHawKRQDBaMWX58pOfqNQNQGInbeJdFchudpMLguz0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1778304234848148.62629825289866; Fri, 8 May 2026 22:23:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wLa9w-0000jH-Mq; Sat, 09 May 2026 01:23:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9v-0000id-A0 for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wLa9t-0007N5-DG for qemu-devel@nongnu.org; Sat, 09 May 2026 01:23:27 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-EkUzxY_PMK2EU96XbbU-IA-1; Sat, 09 May 2026 01:23:23 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-43d7a5b9678so1758927f8f.2 for ; Fri, 08 May 2026 22:23:22 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e701e9585sm24194945e9.5.2026.05.08.22.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 22:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778304204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WHAANPw3hoVZMvfFza2Z/uOEAoSMVMaGiu2b+FC5QMc=; b=MfvNN9I3u8KIlwlw9BZOE/gt6/nBsbq7dMV5ARWaYMqNR96qZ6by396tSc4ZWNu2sm83b8 gQ2aA46Yjo91GVdKfwYUfgukHQoJ4+T9KcbMpT9xMh3fjTXDMwZ4GHuDCDIirpB9k2vQZr 1nW/bzzLmPINqmTTCHnuP1JIZgInn/g= X-MC-Unique: EkUzxY_PMK2EU96XbbU-IA-1 X-Mimecast-MFC-AGG-ID: EkUzxY_PMK2EU96XbbU-IA_1778304202 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778304201; x=1778909001; 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=WHAANPw3hoVZMvfFza2Z/uOEAoSMVMaGiu2b+FC5QMc=; b=JoDPhNtBBWe/rfRhBA15TDogzGloDHGs1XzMFrFMTBBD0K2MFaFaiBNIQ3HE2aTCxJ 7W6oLLEr3iSG3v8hOFubbFLi275suXzf75RcPN6Fb2lwYwDEvZ6FkyBjRs7fYLESgp2d sQgQSqMwul+kL26GWQPbmm8CkWQnE0YT+urDoNDFRJBgQk5fdvMxlRgE2E5rUsIZ9saD +znwJe52bx6lWW0BbfrJpA8MN3v2dHum17qc9XW6HBfdXvnxiMiFBE+jKG2bPlvZL5I4 32jL2TIaSV/D80kYOZc2YZM6CxvbcXlFKYbKehWzhy46GceaHYXrybuD71ZNB/o7hMs2 4uiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778304201; x=1778909001; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WHAANPw3hoVZMvfFza2Z/uOEAoSMVMaGiu2b+FC5QMc=; b=oiS2pv7kwgVbB8qQqYR1R+XX2shmd0rv/7z8s3fZ5BidQ6pZnn0/Er9LhZHU2lBUcc c+Lx/56hnHa3fhtAehDMeG+J/sPsVNOenKUbIXI9QLvEPAvZtCPJ8XCib/i0eGIqvZIf MN5mgSVVDFqgIPUu1/2wClLvKPcUpTBfM2ru+NXEdWDZEXKmk9GOIP/mPLVPuXlXmwON QAVtvd2iAmjb3ZBbFiKikzUwblhioa2w6me255pd10olXQJ3nQVyZk/MhKE4i6ToRghD LE+VXvBpHI5kmawLqYqmvfqowbLVefeu9RaLA9jOw+fFjxQnGA0zjDqMNAea4+pFu3oC ocag== X-Gm-Message-State: AOJu0YzkCVnSPwxhj+/fK0pvdaEsabRTPmU8ijHcjf+gDo+DaNfIbUdO UD5em2hbA34gRiCsngS1Hn6mr0Gim9RVJVr2L4lUn1fmV+BoufVwMA7/txQeSKnCPkMG/bdAUhm y0o4uHxrVnv96/vZ806g4sUxk/7BzAez4jMjIQ1yVR+PvtnuCJ+ERhD3U7jankbh7MKA7KiYul/ m8ZlH0Ee1a6jh046U9gOZsKKuqt5bS/LNbm1RXrXxq X-Gm-Gg: Acq92OEekvwGizaX29ost5oO9j+PoLJHSSk31dV43GOhqp0vetFNpOzGdkfNYmyjaLd FnAHqaosc5+2Lqnv4G5yT0sOHlQ3qF9XRJ0zdTs32iQVc36bgyzYDPrfE0/nPxX9NP+8IUDKczp KpPpLcsElW9Hrxjt0qXMb3oob5nyWna7lQDd3Z/zI6QP7tlJtqFXPxeNqc2DWrtTck9tJNbBpPo nW+5uM2JOSnVaVgRgHrJIyy9ilzkUNf75AZe7eRiEwlZdPC3heFVd3gGMr5/RP+sLqr5HcFsBHP BHW1hCLRQFvVKE+HkLi+2j5Ld6ujPg3jKpShOaha73KJf1MtUDczQOc0MKk25so3m5hX+V74LPn j3vwleVV8Vhds2XnWiYaYFpWXKmhpllvELj5E6Zfyc49Z5rIMm2PIM8M8qENrBqvGeuHdw+0b1b R0BxNaNrEs10Pn2usicI53PnEJilFL X-Received: by 2002:a05:600c:8486:b0:48a:6fd4:d3d3 with SMTP id 5b1f17b1804b1-48e706be062mr15119355e9.20.1778304201043; Fri, 08 May 2026 22:23:21 -0700 (PDT) X-Received: by 2002:a05:600c:8486:b0:48a:6fd4:d3d3 with SMTP id 5b1f17b1804b1-48e706be062mr15118915e9.20.1778304200442; Fri, 08 May 2026 22:23:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Subject: [PULL 5/5] scsi: handle reservation changes across migration Date: Sat, 9 May 2026 07:23:04 +0200 Message-ID: <20260509052304.2159829-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260509052304.2159829-1-pbonzini@redhat.com> References: <20260509052304.2159829-1-pbonzini@redhat.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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.44, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1778304236757158500 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Other nodes in the cluster can preempt or clear SCSI Persistent Reservations at any time. When this happens across live migration, the reservation state transferred with the guest might be outdated. Attempt to handle such cases gracefully by checking the current reservation or registered keys to detect stale state before restoring. If the actual state of the disk has changed, do not modify it and accept that as the most up-to-date state. Do this using READ RESERVATION when the guest holds a reservation or READ KEYS when the guest has registered a key but does not hold a reservation. There is still a race condition between checking and restoring state, but it seems unavoidable and is no worse than before. Buglink: https://redhat.atlassian.net/browse/RHEL-153123 Fixes: ab57b51f1375b6a6f098a74c6f79207a9630948d ("scsi: save/load SCSI rese= rvation state") Reported-by: Qing Wang Signed-off-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20260415232906.212349-3-stefanha@redhat.com Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-generic.c | 173 +++++++++++++++++++++++++++++++++++------ 1 file changed, 149 insertions(+), 24 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 29bc952af5d..8999f3b7200 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -479,13 +479,84 @@ static bool scsi_generic_pr_preempt(SCSIDevice *s, ui= nt64_t key, return true; } =20 +/* + * Returns true if the given key is registered or false otherwise (includi= ng + * errors). + */ +static bool scsi_generic_pr_key_registered(SCSIDevice *s, uint64_t key, + Error **errp) +{ + const size_t key_list_offset =3D 8; /* in READ KEYS parameter data */ + uint64_t key_be =3D cpu_to_be64(key); + uint8_t cmd[10] =3D {}; + size_t buf_len; + g_autofree uint8_t *buf =3D NULL; + uint32_t additional_length =3D 16 * 8; /* initial key list size */ + + /* + * Loop to resize parameter data buffer when there are many keys. It w= ould + * be simpler to hardcode the maximum buffer size (it's only 64 KB), b= ut + * SG_IO can fail with EINVAL if the host kernel blkdev queue limits a= re + * too low. + */ + do { + uint16_t allocation_length_be; + int ret; + + buf_len =3D key_list_offset + additional_length; + buf =3D g_realloc(buf, buf_len); + memset(buf, 0, buf_len); + + cmd[0] =3D PERSISTENT_RESERVE_IN; + cmd[1] =3D PRI_READ_KEYS; + allocation_length_be =3D cpu_to_be16(buf_len); + memcpy(&cmd[7], &allocation_length_be, sizeof(allocation_length_be= )); + + ret =3D scsi_SG_IO(s->conf.blk, SG_DXFER_FROM_DEV, cmd, sizeof(cmd= ), + buf, buf_len, s->io_timeout, errp); + if (ret < 0) { + error_prepend(errp, "PERSISTENT RESERVE IN with READ KEYS: "); + return false; + } + + memcpy(&additional_length, &buf[4], sizeof(additional_length)); + be32_to_cpus(&additional_length); + + /* + * The parameter data's ADDITIONAL LENGTH must not overflow the CD= B's + * 16-bit ALLOCATION LENGTH field since the next loop iteration wi= ll + * compute ALLOCATION LENGTH based on ADDITIONAL LENGTH. + */ + if (additional_length > UINT16_MAX - key_list_offset) { + error_setg(errp, "got invalid ADDITIONAL LENGTH %" PRIu32 + " from READ KEYS", additional_length); + return false; + } + + for (size_t i =3D key_list_offset; i < buf_len; i +=3D sizeof(key_= be)) { + if (i - key_list_offset >=3D additional_length) { + break; /* end of parameter list */ + } + + if (memcmp(&key_be, &buf[i], sizeof(key_be)) =3D=3D 0) { + return true; /* key found */ + } + } + } while (additional_length > buf_len - key_list_offset); + + return false; /* key not found */ +} + /* Register keys and preempt reservations after live migration */ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error **errp) { SCSIPRState *pr_state =3D &s->pr_state; + Error *local_err =3D NULL; + bool check_stale_key =3D true; uint64_t key; uint8_t resv_type; =20 + /* Get the migrated PR state */ WITH_QEMU_LOCK_GUARD(&pr_state->mutex) { key =3D pr_state->key; resv_type =3D pr_state->resv_type; @@ -493,36 +564,90 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Err= or **errp) =20 trace_scsi_generic_pr_state_preempt(key, resv_type); =20 - if (key) { - if (!scsi_generic_pr_register(s, key, errp)) { + /* Handle stale PR state (e.g. another node preempted) */ + if (resv_type) { + uint64_t dev_key; + uint8_t dev_resv_type; + + if (scsi_generic_read_reservation(s, &dev_key, &dev_resv_type, + errp) < 0) { return false; } =20 - /* - * Two cases: - * - * 1. There is no reservation (resv_type is 0) and the other I_T n= exus - * will be unregistered. This is important so the source host d= oes - * not leak registered keys across live migration. - * - * 2. There is a reservation (resv_type is not 0) and the other I_T - * nexus will be unregistered and its reservation is atomically - * taken over by us. This is the scenario where a reservation is - * migrated along with the guest. - */ - if (!scsi_generic_pr_preempt(s, key, resv_type, errp)) { + if (dev_resv_type !=3D resv_type) { + /* vmstate had a stale reservation type */ + g_autofree char *name =3D qdev_get_human_name(&s->qdev); + warn_report("Expected SCSI reservation type 0x%x on device '%s= ', " + "got 0x%x, using new type", + resv_type, name, dev_resv_type); + resv_type =3D dev_resv_type; + } + + if (dev_key =3D=3D key) { + /* The reservation exists, no need to check for a stale key */ + check_stale_key =3D false; + } else { + g_autofree char *name =3D qdev_get_human_name(&s->qdev); + warn_report("Expected SCSI reservation with key 0x%" PRIx64 + " on device '%s', got 0x%" PRIx64 ", ignoring " + "reservation", + key, name, dev_key); + resv_type =3D 0; /* vmstate had a stale reservation */ + } + } + + if (key !=3D 0 && check_stale_key && + !scsi_generic_pr_key_registered(s, key, &local_err)) { + if (local_err) { + error_propagate(errp, local_err); return false; } =20 - /* - * Some SCSI targets, like the Linux LIO target, remove our - * registration when preempting without a reservation (resv_type i= s 0). - * Try to register again but ignore the error since a RESERVATION - * CONFLICT is expected if our registration remained in place. - */ - if (resv_type =3D=3D 0) { - scsi_generic_pr_register(s, key, NULL); - } + g_autofree char *name =3D qdev_get_human_name(&s->qdev); + warn_report("SCSI reservation key 0x%" PRIx64 " on device '%s' not= " + "registered after migration, ignoring", + key, name); + key =3D 0; /* vmstate had a stale key */ + } + + /* Stale PR state may have been updated */ + WITH_QEMU_LOCK_GUARD(&pr_state->mutex) { + pr_state->key =3D key; + pr_state->resv_type =3D resv_type; + } + + if (key =3D=3D 0) { + return true; /* no PR state, do nothing */ + } + + if (!scsi_generic_pr_register(s, key, errp)) { + return false; + } + + /* + * Two cases: + * + * 1. There is no reservation (resv_type is 0) and the other I_T nexus + * will be unregistered. This is important so the source host does + * not leak registered keys across live migration. + * + * 2. There is a reservation (resv_type is not 0) and the other I_T + * nexus will be unregistered and its reservation is atomically + * taken over by us. This is the scenario where a reservation is + * migrated along with the guest. + */ + if (!scsi_generic_pr_preempt(s, key, resv_type, errp)) { + return false; + } + + /* + * Some SCSI targets, like the Linux LIO target, remove our + * registration when preempting without a reservation (resv_type is 0). + * Try to register again but ignore the error since a RESERVATION + * CONFLICT is expected if our registration remained in place. + */ + if (resv_type =3D=3D 0) { + scsi_generic_pr_register(s, key, NULL); } return true; } --=20 2.54.0