@@ -277,34 +277,30 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(
static void iblock_complete_cmd(struct target_iostate *ios)
{
- struct iblock_req *ibr = ios->priv;
u8 status;
- if (!atomic_dec_and_test(&ibr->pending))
+ if (!atomic_dec_and_test(&ios->backend_pending))
return;
- if (atomic_read(&ibr->ib_bio_err_cnt))
+ if (atomic_read(&ios->backend_err_cnt))
status = SAM_STAT_CHECK_CONDITION;
else
status = SAM_STAT_GOOD;
// XXX: ios status SAM completion translation
ios->t_comp_func(ios, status);
-
- kfree(ibr);
}
static void iblock_bio_done(struct bio *bio)
{
struct target_iostate *ios = bio->bi_private;
- struct iblock_req *ibr = ios->priv;
if (bio->bi_error) {
pr_err("bio error: %p, err: %d\n", bio, bio->bi_error);
/*
* Bump the ib_bio_err_cnt and release bio.
*/
- atomic_inc(&ibr->ib_bio_err_cnt);
+ atomic_inc(&ios->backend_err_cnt);
smp_mb__after_atomic();
}
@@ -453,7 +449,6 @@ iblock_execute_write_same(struct se_cmd *cmd)
{
struct target_iostate *ios = &cmd->t_iostate;
struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd;
- struct iblock_req *ibr;
struct scatterlist *sg;
struct bio *bio;
struct bio_list list;
@@ -480,19 +475,14 @@ iblock_execute_write_same(struct se_cmd *cmd)
if (bdev_write_same(bdev))
return iblock_execute_write_same_direct(bdev, cmd);
- ibr = kzalloc(sizeof(struct iblock_req), GFP_KERNEL);
- if (!ibr)
- goto fail;
- ios->priv = ibr;
-
bio = iblock_get_bio(ios, block_lba, 1);
if (!bio)
- goto fail_free_ibr;
+ goto fail;
bio_list_init(&list);
bio_list_add(&list, bio);
- atomic_set(&ibr->pending, 1);
+ atomic_set(&ios->backend_pending, 1);
while (sectors) {
while (bio_add_page(bio, sg_page(sg), sg->length, sg->offset)
@@ -502,7 +492,7 @@ iblock_execute_write_same(struct se_cmd *cmd)
if (!bio)
goto fail_put_bios;
- atomic_inc(&ibr->pending);
+ atomic_inc(&ios->backend_pending);
bio_list_add(&list, bio);
}
@@ -517,8 +507,6 @@ iblock_execute_write_same(struct se_cmd *cmd)
fail_put_bios:
while ((bio = bio_list_pop(&list)))
bio_put(bio);
-fail_free_ibr:
- kfree(ibr);
fail:
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}
@@ -680,7 +668,6 @@ iblock_execute_rw(struct target_iostate *ios, struct scatterlist *sgl, u32 sgl_n
{
struct se_device *dev = ios->se_dev;
sector_t block_lba = target_to_linux_sector(dev, ios->t_task_lba);
- struct iblock_req *ibr;
struct bio *bio, *bio_start;
struct bio_list list;
struct scatterlist *sg;
@@ -710,26 +697,21 @@ iblock_execute_rw(struct target_iostate *ios, struct scatterlist *sgl, u32 sgl_n
rw = READ;
}
- ibr = kzalloc(sizeof(struct iblock_req), GFP_KERNEL);
- if (!ibr)
- goto fail;
- ios->priv = ibr;
-
if (!sgl_nents) {
- atomic_set(&ibr->pending, 1);
+ atomic_set(&ios->backend_pending, 1);
iblock_complete_cmd(ios);
return 0;
}
bio = iblock_get_bio(ios, block_lba, sgl_nents);
if (!bio)
- goto fail_free_ibr;
+ goto fail;
bio_start = bio;
bio_list_init(&list);
bio_list_add(&list, bio);
- atomic_set(&ibr->pending, 2);
+ atomic_set(&ios->backend_pending, 2);
bio_cnt = 1;
for_each_sg(sgl, sg, sgl_nents, i) {
@@ -749,7 +731,7 @@ iblock_execute_rw(struct target_iostate *ios, struct scatterlist *sgl, u32 sgl_n
if (!bio)
goto fail_put_bios;
- atomic_inc(&ibr->pending);
+ atomic_inc(&ios->backend_pending);
bio_list_add(&list, bio);
bio_cnt++;
}
@@ -772,8 +754,6 @@ iblock_execute_rw(struct target_iostate *ios, struct scatterlist *sgl, u32 sgl_n
fail_put_bios:
while ((bio = bio_list_pop(&list)))
bio_put(bio);
-fail_free_ibr:
- kfree(ibr);
fail:
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}
@@ -6,11 +6,6 @@
#define IBLOCK_MAX_CDBS 16
#define IBLOCK_LBA_SHIFT 9
-struct iblock_req {
- atomic_t pending;
- atomic_t ib_bio_err_cnt;
-} ____cacheline_aligned;
-
#define IBDF_HAS_UDEV_PATH 0x01
struct iblock_dev {
@@ -469,7 +469,10 @@ struct target_iostate {
struct target_iomem *iomem;
struct se_device *se_dev;
void (*t_comp_func)(struct target_iostate *, u16);
- void *priv;
+
+ /* Used by IBLOCK for BIO submission + completion */
+ atomic_t backend_pending;
+ atomic_t backend_err_cnt;
};
struct se_cmd {