Skip to content

Commit ad512f2

Browse files
ajaysjoshiaxboe
authored andcommitted
scsi: sd_zbc: add zone open, close, and finish support
Implement REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE and REQ_OP_ZONE_FINISH support to allow explicit control of zone states. Contains contributions from Matias Bjorling, Hans Holmberg, Keith Busch and Damien Le Moal. Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ajay Joshi <[email protected]> Signed-off-by: Matias Bjorling <[email protected]> Signed-off-by: Hans Holmberg <[email protected]> Signed-off-by: Keith Busch <[email protected]> Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6d1ec78 commit ad512f2

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

drivers/scsi/sd.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,17 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd)
12911291
case REQ_OP_WRITE:
12921292
return sd_setup_read_write_cmnd(cmd);
12931293
case REQ_OP_ZONE_RESET:
1294-
return sd_zbc_setup_reset_cmnd(cmd, false);
1294+
return sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_RESET_WRITE_POINTER,
1295+
false);
12951296
case REQ_OP_ZONE_RESET_ALL:
1296-
return sd_zbc_setup_reset_cmnd(cmd, true);
1297+
return sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_RESET_WRITE_POINTER,
1298+
true);
1299+
case REQ_OP_ZONE_OPEN:
1300+
return sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_OPEN_ZONE, false);
1301+
case REQ_OP_ZONE_CLOSE:
1302+
return sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_CLOSE_ZONE, false);
1303+
case REQ_OP_ZONE_FINISH:
1304+
return sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_FINISH_ZONE, false);
12971305
default:
12981306
WARN_ON_ONCE(1);
12991307
return BLK_STS_NOTSUPP;
@@ -1961,6 +1969,9 @@ static int sd_done(struct scsi_cmnd *SCpnt)
19611969
case REQ_OP_WRITE_SAME:
19621970
case REQ_OP_ZONE_RESET:
19631971
case REQ_OP_ZONE_RESET_ALL:
1972+
case REQ_OP_ZONE_OPEN:
1973+
case REQ_OP_ZONE_CLOSE:
1974+
case REQ_OP_ZONE_FINISH:
19641975
if (!result) {
19651976
good_bytes = blk_rq_bytes(req);
19661977
scsi_set_resid(SCpnt, 0);

drivers/scsi/sd.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ static inline int sd_is_zoned(struct scsi_disk *sdkp)
209209

210210
extern int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buffer);
211211
extern void sd_zbc_print_zones(struct scsi_disk *sdkp);
212-
extern blk_status_t sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd, bool all);
212+
blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
213+
unsigned char op, bool all);
213214
extern void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
214215
struct scsi_sense_hdr *sshdr);
215216
extern int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
@@ -225,8 +226,9 @@ static inline int sd_zbc_read_zones(struct scsi_disk *sdkp,
225226

226227
static inline void sd_zbc_print_zones(struct scsi_disk *sdkp) {}
227228

228-
static inline blk_status_t sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd,
229-
bool all)
229+
static inline blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
230+
unsigned char op,
231+
bool all)
230232
{
231233
return BLK_STS_TARGET;
232234
}

drivers/scsi/sd_zbc.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,17 @@ static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp)
207207
}
208208

209209
/**
210-
* sd_zbc_setup_reset_cmnd - Prepare a RESET WRITE POINTER scsi command.
210+
* sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations
211+
* can be RESET WRITE POINTER, OPEN, CLOSE or FINISH.
211212
* @cmd: the command to setup
212-
* @all: Reset all zones control.
213+
* @op: Operation to be performed
214+
* @all: All zones control
213215
*
214-
* Called from sd_init_command() for a REQ_OP_ZONE_RESET request.
216+
* Called from sd_init_command() for REQ_OP_ZONE_RESET, REQ_OP_ZONE_RESET_ALL,
217+
* REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE or REQ_OP_ZONE_FINISH requests.
215218
*/
216-
blk_status_t sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd, bool all)
219+
blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
220+
unsigned char op, bool all)
217221
{
218222
struct request *rq = cmd->request;
219223
struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
@@ -234,7 +238,7 @@ blk_status_t sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd, bool all)
234238
cmd->cmd_len = 16;
235239
memset(cmd->cmnd, 0, cmd->cmd_len);
236240
cmd->cmnd[0] = ZBC_OUT;
237-
cmd->cmnd[1] = ZO_RESET_WRITE_POINTER;
241+
cmd->cmnd[1] = op;
238242
if (all)
239243
cmd->cmnd[14] = 0x1;
240244
else
@@ -263,14 +267,14 @@ void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
263267
int result = cmd->result;
264268
struct request *rq = cmd->request;
265269

266-
if (req_op(rq) == REQ_OP_ZONE_RESET &&
270+
if (op_is_zone_mgmt(req_op(rq)) &&
267271
result &&
268272
sshdr->sense_key == ILLEGAL_REQUEST &&
269273
sshdr->asc == 0x24) {
270274
/*
271-
* INVALID FIELD IN CDB error: reset of a conventional
272-
* zone was attempted. Nothing to worry about, so be
273-
* quiet about the error.
275+
* INVALID FIELD IN CDB error: a zone management command was
276+
* attempted on a conventional zone. Nothing to worry about,
277+
* so be quiet about the error.
274278
*/
275279
rq->rq_flags |= RQF_QUIET;
276280
}

0 commit comments

Comments
 (0)