From 909247cb3df6de987cb253f488fb50a02bc4cd6e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 27 Apr 2017 00:17:22 +0000 Subject: [PATCH] scst: Port to Linux kernel v4.11 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7153 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/iser_rdma.c | 4 ++ iscsi-scst/kernel/isert-scst/isert_login.c | 4 ++ scst/src/dev_handlers/scst_user.c | 4 ++ scst/src/dev_handlers/scst_vdisk.c | 3 ++ scst/src/scst_event.c | 4 ++ scst/src/scst_lib.c | 48 +++++++++++++++++----- scst/src/scst_sysfs.c | 8 +++- 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index 2f6752379..e24b5ecdb 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -1400,7 +1400,11 @@ static void isert_kref_free(struct kref *kref) void isert_conn_free(struct isert_connection *isert_conn) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + sBUG_ON(kref_read(&isert_conn->kref) == 0); +#else sBUG_ON(atomic_read(&isert_conn->kref.refcount) == 0); +#endif kref_put(&isert_conn->kref, isert_kref_free); } diff --git a/iscsi-scst/kernel/isert-scst/isert_login.c b/iscsi-scst/kernel/isert-scst/isert_login.c index 3a0028595..f0220e958 100644 --- a/iscsi-scst/kernel/isert-scst/isert_login.c +++ b/iscsi-scst/kernel/isert-scst/isert_login.c @@ -111,7 +111,11 @@ static void isert_kref_release_dev(struct kref *kref) static void isert_dev_release(struct isert_conn_dev *dev) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + sBUG_ON(kref_read(&dev->kref) == 0); +#else sBUG_ON(atomic_read(&dev->kref.refcount) == 0); +#endif mutex_lock(&isert_listen_dev.conn_lock); kref_put(&dev->kref, isert_kref_release_dev); mutex_unlock(&isert_listen_dev.conn_lock); diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index eb6aa6b26..debed3370 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -22,6 +22,10 @@ #include #include #include +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#include +#endif #define LOG_PREFIX DEV_USER_NAME diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 5be651e7c..882904c1e 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -55,6 +55,9 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38) #include #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#include +#endif #define LOG_PREFIX "dev_vdisk" diff --git a/scst/src/scst_event.c b/scst/src/scst_event.c index 70ca038a9..4ec509bf0 100644 --- a/scst/src/scst_event.c +++ b/scst/src/scst_event.c @@ -11,6 +11,10 @@ #include #include #include +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#include +#endif #ifdef INSIDE_KERNEL_TREE #include diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 933ca5a03..1b105209b 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -37,6 +37,9 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) #include #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#include +#endif #include #include @@ -7853,7 +7856,11 @@ static struct request *blk_make_request(struct request_queue *q, if (IS_ERR(rq)) return rq; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + scsi_req_init(rq); +#else blk_rq_set_block_pc(rq); +#endif for_each_bio(bio) { struct bio *bounce_bio = bio; @@ -8063,7 +8070,11 @@ static struct request *blk_map_kern_sg(struct request_queue *q, if (unlikely(!rq)) return ERR_PTR(-ENOMEM); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + scsi_req_init(rq); +#else rq->cmd_type = REQ_TYPE_BLOCK_PC; +#endif goto out; } @@ -8259,10 +8270,14 @@ static void scsi_end_async(struct request *req, int error) #endif if (sioc->done) -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 30) - sioc->done(sioc->data, sioc->sense, req->errors, req->data_len); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + sioc->done(sioc->data, sioc->sense, req->errors, + scsi_req(req)->resid_len); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) + sioc->done(sioc->data, sioc->sense, req->errors, + req->resid_len); #else - sioc->done(sioc->data, sioc->sense, req->errors, req->resid_len); + sioc->done(sioc->data, sioc->sense, req->errors, req->data_len); #endif kmem_cache_free(scsi_io_context_cache, sioc); @@ -8283,6 +8298,11 @@ int scst_scsi_exec_async(struct scst_cmd *cmd, void *data, int res = 0; struct request_queue *q = cmd->dev->scsi_dev->request_queue; struct request *rq; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + struct scsi_request *req; +#else + struct request *req; +#endif struct scsi_io_context *sioc; bool reading = !(cmd->data_direction & SCST_DATA_WRITE); gfp_t gfp = cmd->cmd_gfp_mask; @@ -8331,15 +8351,21 @@ 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); - } else - rq->cmd = cmd->cdb; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) + req = scsi_req(rq); +#else + req = rq; +#endif - rq->sense = sioc->sense; - rq->sense_len = sizeof(sioc->sense); + req->cmd_len = cmd_len; + if (req->cmd_len <= BLK_MAX_CDB) { + memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */ + memcpy(req->cmd, cmd->cdb, cmd->cdb_len); + } else + req->cmd = cmd->cdb; + + req->sense = sioc->sense; + req->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 c89e453c5..10a95a447 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) + kref_read(&kobj->kref) +#else + atomic_read(&kobj->kref.refcount) +#endif + ); wait_for_completion(c); PRINT_INFO("Finished waiting for release of %s %s sysfs entry", category, name ? : "(?)");