From patchwork Thu Nov 17 09:31:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 9433755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6AD760471 for ; Thu, 17 Nov 2016 09:37:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A746F29309 for ; Thu, 17 Nov 2016 09:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BF7B2939C; Thu, 17 Nov 2016 09:37:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4341229309 for ; Thu, 17 Nov 2016 09:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932716AbcKQJcp (ORCPT ); Thu, 17 Nov 2016 04:32:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:55670 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753268AbcKQJbu (ORCPT ); Thu, 17 Nov 2016 04:31:50 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A8E4BACE6; Thu, 17 Nov 2016 09:31:47 +0000 (UTC) From: Johannes Thumshirn To: James Bottomley , "Martin K . Petersen" Cc: Hannes Reinecke , Christoph Hellwig , Johannes Thumshirn , Jens Axboe , Hannes Reinecke , linux-block@vger.kernel.org (open list:BLOCK LAYER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 08/15] block: add reference counting for struct bsg_job Date: Thu, 17 Nov 2016 10:31:18 +0100 Message-Id: <07ed1ca26f9ab85bdc32cb9b582c8f36e9424d49.1479374720.git.jthumshirn@suse.de> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add reference counting to 'struct bsg_job' so we can implement a reuqest timeout handler for bsg_jobs, which is needed for Fibre Channel. Signed-off-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke --- block/bsg-lib.c | 7 +++++-- include/linux/bsg-lib.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 650f427..632fb40 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -32,8 +32,10 @@ * bsg_destroy_job - routine to teardown/delete a bsg job * @job: bsg_job that is to be torn down */ -static void bsg_destroy_job(struct bsg_job *job) +static void bsg_destroy_job(struct kref *kref) { + struct bsg_job *job = container_of(kref, struct bsg_job, kref); + put_device(job->dev); /* release reference for the request */ kfree(job->request_payload.sg_list); @@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq) struct bsg_job *job = rq->special; blk_end_request_all(rq, rq->errors); - bsg_destroy_job(job); + kref_put(&job->kref, bsg_destroy_job); } static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req) @@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct request *req) job->dev = dev; /* take a reference for the request */ get_device(job->dev); + kref_init(&job->kref); return 0; failjob_rls_rqst_payload: diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h index a226652..58e0717 100644 --- a/include/linux/bsg-lib.h +++ b/include/linux/bsg-lib.h @@ -40,6 +40,8 @@ struct bsg_job { struct device *dev; struct request *req; + struct kref kref; + /* Transport/driver specific request/reply structs */ void *request; void *reply;