Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752743AbcCVWEI (ORCPT ); Tue, 22 Mar 2016 18:04:08 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:53646 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752628AbcCVWEE (ORCPT ); Tue, 22 Mar 2016 18:04:04 -0400 X-AuditID: cbfee61a-f79266d000003652-6d-56f1c152e515 From: Ming Lin To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH v2 1/5] scsi: replace "scsi_data_buffer" with "sg_table" in SG functions Date: Tue, 22 Mar 2016 15:03:12 -0700 Message-id: <1458684196-15923-2-git-send-email-mlin@kernel.org> X-Mailer: git-send-email 1.9.1 In-reply-to: <1458684196-15923-1-git-send-email-mlin@kernel.org> References: <1458684196-15923-1-git-send-email-mlin@kernel.org> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMJMWRmVeSWpSXmKPExsVy+t9jQd2ggx/DDOZ2SVusXH2UyeLyrjls Ft3Xd7A5MHvsvtnA5vF5k1wAUxSXTUpqTmZZapG+XQJXxqL270wFTxQqLh/9zNTAuEu6i5GT Q0LAROJW6z9mCFtM4sK99WxdjFwcQgKzGCXaul+wQzi/GCUar7wCq2ITUJA4uG4DUxcjB4eI gI1E0zcmkDCzgJLEgrV32UFsYYEoiebblxhBbBYBVYmOjp9grbwC9hJHHjxlhVgmJ3Hy2GQw m1PAQeLjhNksILYQUE3T75OsExh5FzAyrGKUSC1ILihOSs81zEst1ytOzC0uzUvXS87P3cQI DopnUjsYD+5yP8QowMGoxMPbsOFDmBBrYllxZe4hRgkOZiUR3lV9H8OEeFMSK6tSi/Lji0pz UosPMUpzsCiJ8z7+vy5MSCA9sSQ1OzW1ILUIJsvEwSnVwLh2RWPKPtHv7uzT55bOUQjzPLp6 773Mfd/sft+PZyo/aBP5V+hhp41XfMJNuyf3j+cFK/T51t7U3SfOu1Mop0royS77XfZxn9f0 bInVUvnmcqV2mpDapRb/6xPqUuvPTLae9HXLpF1mTmrRRT84Jy+v8pbe2Pqokl/+zwyNfvlX L1/rtPnZyiqxFGckGmoxFxUnAgAreh5oBgIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4073 Lines: 121 From: Ming Lin Replace parameter "struct scsi_data_buffer" with "struct sg_table" in SG alloc/free functions to make them generic. Signed-off-by: Ming Lin --- drivers/scsi/scsi_lib.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8c6e318..5eaddc7 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -583,14 +583,14 @@ static struct scatterlist *scsi_sg_alloc(unsigned int nents, gfp_t gfp_mask) return mempool_alloc(sgp->pool, gfp_mask); } -static void scsi_free_sgtable(struct scsi_data_buffer *sdb, bool mq) +static void scsi_free_sgtable(struct sg_table *table, bool mq) { - if (mq && sdb->table.orig_nents <= SCSI_MAX_SG_SEGMENTS) + if (mq && table->orig_nents <= SCSI_MAX_SG_SEGMENTS) return; - __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free); + __sg_free_table(table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free); } -static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, bool mq) +static int scsi_alloc_sgtable(struct sg_table *table, int nents, bool mq) { struct scatterlist *first_chunk = NULL; int ret; @@ -599,17 +599,17 @@ static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, bool mq) if (mq) { if (nents <= SCSI_MAX_SG_SEGMENTS) { - sdb->table.nents = sdb->table.orig_nents = nents; - sg_init_table(sdb->table.sgl, nents); + table->nents = table->orig_nents = nents; + sg_init_table(table->sgl, nents); return 0; } - first_chunk = sdb->table.sgl; + first_chunk = table->sgl; } - ret = __sg_alloc_table(&sdb->table, nents, SCSI_MAX_SG_SEGMENTS, + ret = __sg_alloc_table(table, nents, SCSI_MAX_SG_SEGMENTS, first_chunk, GFP_ATOMIC, scsi_sg_alloc); if (unlikely(ret)) - scsi_free_sgtable(sdb, mq); + scsi_free_sgtable(table, mq); return ret; } @@ -625,12 +625,17 @@ static void scsi_uninit_cmd(struct scsi_cmnd *cmd) static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) { + struct scsi_data_buffer *sdb; + if (cmd->sdb.table.nents) - scsi_free_sgtable(&cmd->sdb, true); - if (cmd->request->next_rq && cmd->request->next_rq->special) - scsi_free_sgtable(cmd->request->next_rq->special, true); + scsi_free_sgtable(&cmd->sdb.table, true); + if (cmd->request->next_rq) { + sdb = cmd->request->next_rq->special; + if (sdb) + scsi_free_sgtable(&sdb->table, true); + } if (scsi_prot_sg_count(cmd)) - scsi_free_sgtable(cmd->prot_sdb, true); + scsi_free_sgtable(&cmd->prot_sdb->table, true); } static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) @@ -669,19 +674,19 @@ static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) static void scsi_release_buffers(struct scsi_cmnd *cmd) { if (cmd->sdb.table.nents) - scsi_free_sgtable(&cmd->sdb, false); + scsi_free_sgtable(&cmd->sdb.table, false); memset(&cmd->sdb, 0, sizeof(cmd->sdb)); if (scsi_prot_sg_count(cmd)) - scsi_free_sgtable(cmd->prot_sdb, false); + scsi_free_sgtable(&cmd->prot_sdb->table, false); } static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd) { struct scsi_data_buffer *bidi_sdb = cmd->request->next_rq->special; - scsi_free_sgtable(bidi_sdb, false); + scsi_free_sgtable(&bidi_sdb->table, false); kmem_cache_free(scsi_sdb_cache, bidi_sdb); cmd->request->next_rq->special = NULL; } @@ -1085,7 +1090,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb) /* * If sg table allocation fails, requeue request later. */ - if (unlikely(scsi_alloc_sgtable(sdb, req->nr_phys_segments, + if (unlikely(scsi_alloc_sgtable(&sdb->table, req->nr_phys_segments, req->mq_ctx != NULL))) return BLKPREP_DEFER; @@ -1158,7 +1163,7 @@ int scsi_init_io(struct scsi_cmnd *cmd) ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); - if (scsi_alloc_sgtable(prot_sdb, ivecs, is_mq)) { + if (scsi_alloc_sgtable(&prot_sdb->table, ivecs, is_mq)) { error = BLKPREP_DEFER; goto err_exit; } -- 1.9.1