Skip to content

Commit fceb5d1

Browse files
ChaitanayaKulkarniaxboe
authored andcommitted
null_blk: create a helper for zoned devices
This patch creates a helper function for handling zoned block device operations. This patch also restructured the code for null_blk_zoned.c and uses the pattern to return blk_status_t and catch the error in the function null_handle_cmd() into cmd->error variable instead of setting it up in the deeper layer just like the way it is done for flush, badblocks and memory backed case in the null_handle_cmd(). We also move null_handle_zoned() to the null_blk_zoned.c to keep the zoned code separate. Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7ea88e2 commit fceb5d1

3 files changed

Lines changed: 35 additions & 27 deletions

File tree

‎drivers/block/null_blk.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ int null_zone_init(struct nullb_device *dev);
9090
void null_zone_exit(struct nullb_device *dev);
9191
int null_zone_report(struct gendisk *disk, sector_t sector,
9292
struct blk_zone *zones, unsigned int *nr_zones);
93-
void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
94-
unsigned int nr_sectors);
95-
void null_zone_reset(struct nullb_cmd *cmd, sector_t sector);
93+
inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
94+
enum req_opf op, sector_t sector,
95+
sector_t nr_sectors);
9696
#else
9797
static inline int null_zone_init(struct nullb_device *dev)
9898
{
@@ -106,10 +106,11 @@ static inline int null_zone_report(struct gendisk *disk, sector_t sector,
106106
{
107107
return -EOPNOTSUPP;
108108
}
109-
static inline void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
110-
unsigned int nr_sectors)
109+
static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
110+
enum req_opf op, sector_t sector,
111+
sector_t nr_sectors)
111112
{
113+
return BLK_STS_NOTSUPP;
112114
}
113-
static inline void null_zone_reset(struct nullb_cmd *cmd, sector_t sector) {}
114115
#endif /* CONFIG_BLK_DEV_ZONED */
115116
#endif /* __NULL_BLK_H */

‎drivers/block/null_blk_main.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,14 +1209,9 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
12091209
if (dev->memory_backed)
12101210
cmd->error = null_handle_memory_backed(cmd, op);
12111211

1212-
if (!cmd->error && dev->zoned) {
1213-
if (op == REQ_OP_WRITE)
1214-
null_zone_write(cmd, sector, nr_sectors);
1215-
else if (op == REQ_OP_ZONE_RESET)
1216-
null_zone_reset(cmd, sector);
1217-
else if (op == REQ_OP_ZONE_RESET_ALL)
1218-
null_zone_reset(cmd, 0);
1219-
}
1212+
if (!cmd->error && dev->zoned)
1213+
cmd->error = null_handle_zoned(cmd, op, sector, nr_sectors);
1214+
12201215
out:
12211216
/* Complete IO by inline, softirq or timer */
12221217
switch (dev->irqmode) {

‎drivers/block/null_blk_zoned.c‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int null_zone_report(struct gendisk *disk, sector_t sector,
8484
return 0;
8585
}
8686

87-
void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
87+
static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
8888
unsigned int nr_sectors)
8989
{
9090
struct nullb_device *dev = cmd->nq->dev;
@@ -95,14 +95,12 @@ void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
9595
case BLK_ZONE_COND_FULL:
9696
/* Cannot write to a full zone */
9797
cmd->error = BLK_STS_IOERR;
98-
break;
98+
return BLK_STS_IOERR;
9999
case BLK_ZONE_COND_EMPTY:
100100
case BLK_ZONE_COND_IMP_OPEN:
101101
/* Writes must be at the write pointer position */
102-
if (sector != zone->wp) {
103-
cmd->error = BLK_STS_IOERR;
104-
break;
105-
}
102+
if (sector != zone->wp)
103+
return BLK_STS_IOERR;
106104

107105
if (zone->cond == BLK_ZONE_COND_EMPTY)
108106
zone->cond = BLK_ZONE_COND_IMP_OPEN;
@@ -115,12 +113,12 @@ void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
115113
break;
116114
default:
117115
/* Invalid zone condition */
118-
cmd->error = BLK_STS_IOERR;
119-
break;
116+
return BLK_STS_IOERR;
120117
}
118+
return BLK_STS_OK;
121119
}
122120

123-
void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
121+
static blk_status_t null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
124122
{
125123
struct nullb_device *dev = cmd->nq->dev;
126124
unsigned int zno = null_zone_no(dev, sector);
@@ -137,10 +135,8 @@ void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
137135
}
138136
break;
139137
case REQ_OP_ZONE_RESET:
140-
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
141-
cmd->error = BLK_STS_IOERR;
142-
return;
143-
}
138+
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL)
139+
return BLK_STS_IOERR;
144140

145141
zone->cond = BLK_ZONE_COND_EMPTY;
146142
zone->wp = zone->start;
@@ -149,4 +145,20 @@ void null_zone_reset(struct nullb_cmd *cmd, sector_t sector)
149145
cmd->error = BLK_STS_NOTSUPP;
150146
break;
151147
}
148+
return BLK_STS_OK;
149+
}
150+
151+
inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
152+
enum req_opf op, sector_t sector,
153+
sector_t nr_sectors)
154+
{
155+
switch (op) {
156+
case REQ_OP_WRITE:
157+
return null_zone_write(cmd, sector, nr_sectors);
158+
case REQ_OP_ZONE_RESET:
159+
case REQ_OP_ZONE_RESET_ALL:
160+
return null_zone_reset(cmd, sector);
161+
default:
162+
return BLK_STS_OK;
163+
}
152164
}

0 commit comments

Comments
 (0)