From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Garry Subject: [PATCH RFC v2 06/24] scsi: add scsi_cmd_from_priv() Date: Wed, 11 Mar 2020 00:25:32 +0800 Message-ID: <1583857550-12049-7-git-send-email-john.garry@huawei.com> References: <1583857550-12049-1-git-send-email-john.garry@huawei.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1583857550-12049-1-git-send-email-john.garry@huawei.com> Sender: linux-kernel-owner@vger.kernel.org To: axboe@kernel.dk, jejb@linux.ibm.com, martin.petersen@oracle.com, hare@suse.de, ming.lei@redhat.com, bvanassche@acm.org, hch@infradead.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, virtualization@lists.linux-foundation.org, esc.storagedev@microsemi.com, chenxiang66@hisilicon.com, Hannes Reinecke List-Id: virtualization@lists.linuxfoundation.org From: Hannes Reinecke Add a functon to retrieve the scsi_cmnd structure from the driver private allocation data. Signed-off-by: Hannes Reinecke --- include/scsi/scsi_cmnd.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 82a4499539b3..c73280b3706d 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -153,6 +153,16 @@ static inline void *scsi_cmd_priv(struct scsi_cmnd *cmd) return cmd + 1; } +/* + * Return the scsi_cmnd structure located before the driver + * private allocation. Only works if cmd_size is set in the + * host template. + */ +static inline struct scsi_cmnd *scsi_cmd_from_priv(void *priv) +{ + return priv - sizeof(struct scsi_cmnd); +} + /* make sure not to use it with passthrough commands */ static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd) { -- 2.17.1