From ebdb340e3a3a3a45eecebf8aae0242d282415152 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 28 Feb 2017 20:35:45 -0800 Subject: [PATCH] scst: Port to Linux kernel v4.11 --- scst/include/backport.h | 23 +++++++++++++++++++++++ scst/src/scst_lib.c | 21 +++++++++++---------- scst/src/scst_sysfs.c | 8 +++++++- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index ae047951a..9f5d64499 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -728,4 +728,27 @@ static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) } #endif +/* */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) +static inline struct request *scsi_req(struct request *rq) +{ + return rq; +} + +static inline void scsi_req_init(struct request *rq) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) + rq->cmd_type = REQ_TYPE_BLOCK_PC; + rq->__data_len = 0; + rq->__sector = (sector_t) -1; + rq->bio = rq->biotail = NULL; + memset(rq->__cmd, 0, sizeof(rq->__cmd)); + rq->cmd = rq->__cmd; +#else + return blk_rq_set_block_pc(rq); +#endif +} +#endif + #endif /* _SCST_BACKPORT_H_ */ diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index f8bbdd362..46fc3b46a 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -7938,7 +7938,7 @@ static struct request *blk_make_request(struct request_queue *q, if (IS_ERR(rq)) return rq; - blk_rq_set_block_pc(rq); + scsi_req_init(rq); for_each_bio(bio) { struct bio *bounce_bio = bio; @@ -8140,7 +8140,7 @@ static struct request *blk_map_kern_sg(struct request_queue *q, if (unlikely(!rq)) return ERR_PTR(-ENOMEM); - rq->cmd_type = REQ_TYPE_BLOCK_PC; + scsi_req_init(rq); goto out; } @@ -8345,7 +8345,8 @@ static void scsi_end_async(struct request *req, int error) #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 30) sioc->done(sioc->data, sioc->sense, errors, req->data_len); #else - sioc->done(sioc->data, sioc->sense, errors, req->resid_len); + sioc->done(sioc->data, sioc->sense, errors, + scsi_req(req)->resid_len); #endif kmem_cache_free(scsi_io_context_cache, sioc); @@ -8414,15 +8415,15 @@ int scst_scsi_exec_async(struct scst_cmd *cmd, void *data, sioc->data = data; sioc->done = done; - rq->cmd_len = cmd_len; - if (rq->cmd_len <= BLK_MAX_CDB) { - memset(rq->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */ - memcpy(rq->cmd, cmd->cdb, cmd->cdb_len); + scsi_req(rq)->cmd_len = cmd_len; + if (scsi_req(rq)->cmd_len <= BLK_MAX_CDB) { + memset(scsi_req(rq)->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */ + memcpy(scsi_req(rq)->cmd, cmd->cdb, cmd->cdb_len); } else - rq->cmd = cmd->cdb; + scsi_req(rq)->cmd = cmd->cdb; - rq->sense = sioc->sense; - rq->sense_len = sizeof(sioc->sense); + scsi_req(rq)->sense = sioc->sense; + scsi_req(rq)->sense_len = sizeof(sioc->sense); rq->timeout = cmd->timeout; rq->retries = cmd->retries; rq->end_io_data = sioc; diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 964500859..4b09a25f5 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -1203,7 +1203,13 @@ void scst_kobject_put_and_wait(struct kobject *kobj, const char *category, goto out_free; PRINT_INFO("Waiting for release of sysfs entry for %s %s (%d refs)", - category, name ? : "(?)", atomic_read(&kobj->kref.refcount)); + category, name ? : "(?)", +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) + atomic_read(&kobj->kref.refcount) +#else + atomic_read(&kobj->kref.refcount.refs) +#endif + ); wait_for_completion(c); PRINT_INFO("Finished waiting for release of %s %s sysfs entry", category, name ? : "(?)");