From: Hannes Reinecke <hare@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
James Bottomley <james.bottomley@hansenpartnership.com>,
Hannes Reinecke <hare@kernel.org>
Subject: [PATCH 3/3] scsi: return PR generation if no reservation is held
Date: Tue, 3 Jun 2025 12:04:16 +0200 [thread overview]
Message-ID: <20250603100416.131490-4-hare@kernel.org> (raw)
In-Reply-To: <20250603100416.131490-1-hare@kernel.org>
For READ RESERVATION the PRgeneration value is always present, even
if no reservations are held.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/scsi/sd.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 950d8c9fb884..daa61feaf441 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2008,9 +2008,13 @@ static int sd_pr_read_reservation(struct block_device *bdev,
if (result)
return result;
+ rsv->generation = get_unaligned_be32(&data[0]);
+ rsv->type = 0;
len = get_unaligned_be32(&data[4]);
- if (!len)
+ if (!len) {
+ rsv->key = 0;
return 0;
+ }
/* Make sure we have at least the key and type */
if (len < 14) {
@@ -2020,9 +2024,9 @@ static int sd_pr_read_reservation(struct block_device *bdev,
return -EINVAL;
}
- rsv->generation = get_unaligned_be32(&data[0]);
rsv->key = get_unaligned_be64(&data[8]);
- rsv->type = scsi_pr_type_to_block(data[21] & 0x0f);
+ if (len == 16)
+ rsv->type = scsi_pr_type_to_block(data[21] & 0x0f);
return 0;
}
--
2.35.3
prev parent reply other threads:[~2025-06-03 10:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 10:04 [PATCH 0/3] block: expose 'read_keys' and 'read_reservation' PR callbacks Hannes Reinecke
2025-06-03 10:04 ` [PATCH 1/3] block: add 'read_keys' persistent reservation ioctl Hannes Reinecke
2025-06-03 10:04 ` [PATCH 2/3] block: add 'read_reservation' " Hannes Reinecke
2025-06-03 10:04 ` Hannes Reinecke [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250603100416.131490-4-hare@kernel.org \
--to=hare@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox