From patchwork Mon May 4 14:46:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6327211 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AFC77BEEE1 for ; Mon, 4 May 2015 14:46:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF6E320351 for ; Mon, 4 May 2015 14:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9AFA9202E6 for ; Mon, 4 May 2015 14:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360AbbEDOqd (ORCPT ); Mon, 4 May 2015 10:46:33 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33958 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750863AbbEDOqb (ORCPT ); Mon, 4 May 2015 10:46:31 -0400 Received: by pacyx8 with SMTP id yx8so162555621pac.1; Mon, 04 May 2015 07:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DvfgwhOzZMSuWGNrDkqTGnjan+AM+hp3+K59wJ4ddNM=; b=tXThAMs0UQb6lMspmWJx/pU4AZEghMW2xK6Hx5jHsOwnOZxm3QPSUi3e1hR02bLXQG B16AC6ZPhZf5CqHvWDBLgfk4D1gGIp0kbauIPrQot1fXWPg6HAgRhtH3dTcAb+L19/pC F2OnuNZDEgJzDKlLT7xfwk56Q52oGcQAqNio4yqPr3Lq0wDkbFISuV1kF1HVfxN/icbu fOsbx8s/HRyJ9NpCpMmAZT+rUk3X2oGn5U/wCeOeF1G71ynL8lXEfaSZRZOMg0Lju3mN g04nr+sNqy1YZBOSnYPPFyJ8JrD381+qJrwoY/JdhJVGj08TxojMenKTN3MELZerI8EB R1Gw== X-Received: by 10.68.167.98 with SMTP id zn2mr42244117pbb.163.1430750790569; Mon, 04 May 2015 07:46:30 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id om10sm13036162pbb.58.2015.05.04.07.46.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 May 2015 07:46:29 -0700 (PDT) From: Akinobu Mita To: linux-scsi@vger.kernel.org Cc: Akinobu Mita , Vinayak Holikatti , Dolev Raviv , Sujit Reddy Thumma , Subhash Jadavani , Christoph Hellwig , "James E.J. Bottomley" , Matthew Dharm , Greg Kroah-Hartman , Alan Stern , "David S. Miller" , Hannes Reinecke , linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net Subject: [PATCH v6 1/4] scsi: add ability to adjust module reference for scsi host Date: Mon, 4 May 2015 23:46:06 +0900 Message-Id: <1430750769-11405-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430750769-11405-1-git-send-email-akinobu.mita@gmail.com> References: <1430750769-11405-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While accessing a scsi_device, the use count of the underlying LLDD module is incremented. The module reference is retrieved through .module field of struct scsi_host_template. This mapping between scsi_device and underlying LLDD module works well except ufs, unusual usb storage drivers, and sub drivers for esp_scsi. These drivers consist with core driver and actual LLDDs, and scsi_host_template is defined in the core driver. So the actual LLDDs can be unloaded even if the scsi_device is being accessed. This adds .module field in struct Scsi_Host and let the module reference be retrieved though it instead of struct scsi_host_template. This allows the actual LLDDs adjust module reference. Signed-off-by: Akinobu Mita Reviewed-by: Hannes Reinecke Cc: Vinayak Holikatti Cc: Dolev Raviv Cc: Sujit Reddy Thumma Cc: Subhash Jadavani Cc: Christoph Hellwig Cc: "James E.J. Bottomley" Cc: Matthew Dharm Cc: Greg Kroah-Hartman Cc: Alan Stern Cc: "David S. Miller" Cc: Hannes Reinecke Cc: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net Cc: linux-scsi@vger.kernel.org --- * Changes from v5 - Rebased as v5 doesn't apply cleanly to the latest tree anymore. drivers/scsi/hosts.c | 1 + drivers/scsi/scsi.c | 4 ++-- include/scsi/scsi_host.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 8bb173e..21f1442 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -411,6 +411,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) */ shost->max_cmd_len = 12; shost->hostt = sht; + shost->module = sht->module; shost->this_id = sht->this_id; shost->can_queue = sht->can_queue; shost->sg_tablesize = sht->sg_tablesize; diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 3833bf5..f7534a9 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -982,7 +982,7 @@ int scsi_device_get(struct scsi_device *sdev) goto fail; if (!get_device(&sdev->sdev_gendev)) goto fail; - if (!try_module_get(sdev->host->hostt->module)) + if (!try_module_get(sdev->host->module)) goto fail_put_device; return 0; @@ -1003,7 +1003,7 @@ EXPORT_SYMBOL(scsi_device_get); */ void scsi_device_put(struct scsi_device *sdev) { - module_put(sdev->host->hostt->module); + module_put(sdev->host->module); put_device(&sdev->sdev_gendev); } EXPORT_SYMBOL(scsi_device_put); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index e113c75..8742bfd 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -620,6 +620,7 @@ struct Scsi_Host { */ unsigned short max_cmd_len; + struct module *module; int this_id; int can_queue; short cmd_per_lun;