From patchwork Tue Jan 31 12:17:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 9547047 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 3C56E60425 for ; Tue, 31 Jan 2017 12:20:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BAA8280FC for ; Tue, 31 Jan 2017 12:20:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E34228372; Tue, 31 Jan 2017 12:20:07 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 77FCF280FC for ; Tue, 31 Jan 2017 12:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751864AbdAaMUF (ORCPT ); Tue, 31 Jan 2017 07:20:05 -0500 Received: from mail-bn3nam01on0043.outbound.protection.outlook.com ([104.47.33.43]:32224 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752003AbdAaMSu (ORCPT ); Tue, 31 Jan 2017 07:18:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cnexlabs.onmicrosoft.com; s=selector1-cnexlabs-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=lO0X2VaBLjM1W6QwJDRcb35wrxnmE6dfh7JY2IPQ778=; b=FT7zcG6bzsAAfxBLI8+jPHxcHoNztT9vmIMVOUjEOSevD8ahm6V1/l9SJb7oJGl5e2Z1Mt/kalh6BEkONv0Sa1rGNUQw7OzTjrqSa6urkgJCCMHJb3f6Q1IJekFeVDZvx1bH2N/IGonsGHCKlNiwB2E2rcC8zM1wb3wh0y7skm4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matias@cnexlabs.com; Received: from skyninja.cnexlabs.com (193.106.164.211) by DM5PR06MB2777.namprd06.prod.outlook.com (10.175.107.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.874.12; Tue, 31 Jan 2017 12:18:02 +0000 From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: CC: , , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 12/12] lightnvm: allow targets to use sysfs Date: Tue, 31 Jan 2017 13:17:20 +0100 Message-ID: <20170131121720.10971-13-matias@cnexlabs.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170131121720.10971-1-matias@cnexlabs.com> References: <20170131121720.10971-1-matias@cnexlabs.com> MIME-Version: 1.0 X-Originating-IP: [193.106.164.211] X-ClientProxiedBy: DB6PR0601CA0024.eurprd06.prod.outlook.com (10.168.88.162) To DM5PR06MB2777.namprd06.prod.outlook.com (10.175.107.139) X-MS-Office365-Filtering-Correlation-Id: c57e90e2-67f7-4a93-aca5-08d449d334c1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM5PR06MB2777; X-Microsoft-Exchange-Diagnostics: 1; DM5PR06MB2777; 3:163gQheMYFxR1QLpR7wEcU5bDAsaEfIN68evY8e8ZX/nk16p8RcRnlIlo4ZNM3MXPuVoBoP7gcaFsYEGk/YHxaJ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S/0SIrMzKl35Um1CL2H1vOGByNNvE4551bS0te0qdDUbpTNFtggsFUovwjqNSRcVYwG3hg1sX0YKiKOtGHcsf1nSPrNhoMjzYT9sm6UiG+Zj8qhIz+rNOimEAq8CdxeYpzXoGg47Z3+vSpjM+zP0eoH10ipiAn5BxCIh; 20:BYyqGxoAaPjFYz6sqssWChqF8seRmMwTDXgw8IPBViqE7AdVcsTSMXKyIkWVBGT6iHW1ryhWuBXs1v6V3nFIh0WEbLgQMC6V94e56d0wgvZZMBT0rMG36fT7Ds1PevrVBUPxd3/q+YI5xmjnT2cXuhiAzN9UGBmaMBpO6DvpSyI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:DM5PR06MB2777; BCL:0; PCL:0; RULEID:; SRVR:DM5PR06MB2777; X-Microsoft-Exchange-Diagnostics: 1; DM5PR06MB2777; 4:Rm9YScTzeGLeccAhyqKFDMzGpjsmvY4I76y5FSHjFSXJT9Lgn2RDdQ+hSdknlpj6PpzU1qutG5jQuyUYros0iP44/qR3bie+haa0D+npIYBcONXX3r4/eIxxcw75VhRxc31k516IMYP0XCPeD+I+xgeMVkTYAFwlvUg3s5pNyiUUbgjBX96x2jbLQ+VfvAlmGf6wAuKBEfncz0OaZqtyoR/DAnm++rKlaULjEAUyADRflnaz5doqLpZBhmFnQm4NQfCsGEW8AxV9Eq1itUqYJULhVVhsYdj402D6VcOtf4Mm2+o7ZK83Tqv30sX1rSwhrOhw9vjwofuROY2PdeTz9tosKXuGoXhx+vpzrfX/0Gj2ND/BvP6IEQnz8gsttS3GcYo+havdbVaXmQP2zIiitxycqlPA7ds10a0rpYao/p1Ky9MhT/Tp8mEmBQ/62EzuX9Ehs9HAv2fsv4KazzYxkrG128ZLoBmjRmQ263V+v1eeh33c3XjM6qTDPytfkV6Akgp3ErC1qU+goWmJrMeImrAx7SuMz6LvV8yctMcBkdxza/1R5CrfPRfaq8L2pEjp99aTS+zHz9ZLfLv3nMyIaQ== X-Forefront-PRVS: 0204F0BDE2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39450400003)(189002)(51234002)(199003)(42186005)(66066001)(50466002)(6486002)(47776003)(38730400001)(105586002)(54906002)(25786008)(106356001)(2351001)(36756003)(68736007)(4001430100002)(53416004)(50986999)(107886002)(7736002)(2906002)(305945005)(4326007)(110136003)(23676002)(2870700001)(189998001)(5660300001)(92566002)(86362001)(1076002)(6116002)(3846002)(33646002)(6916009)(97736004)(2950100002)(5820100001)(6666003)(76176999)(101416001)(53936002)(81166006)(81156014)(8676002)(50226002)(69596002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR06MB2777; H:skyninja.cnexlabs.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cnexlabs.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjA2TUIyNzc3OzIzOmI3MUxuc2FpU2RFZCtsK2JNNThQTkdnRG1K?= =?utf-8?B?SFJiU0FCQmw4ZG50d1dQSGdhazRnamFkZk5HSkxvWmVoV0w4MVY2YTJLYWd6?= =?utf-8?B?eFpQTVlsS0ZjOGVHQTg3M080d2JtZG9qdlIyblY0dklreFFZSGlQSzJiQnYy?= =?utf-8?B?VXBHaWRqMUJaWGlBdndBaDQrakp3Q0xRTkIrejJLZDd0UzRjc0dZY0xxTVpn?= =?utf-8?B?aXVkS1NLbmdUd2JSYUFvMnpDa00zWDR5SGtTTVVlOXpNM1dxTFNrUkd5NkNN?= =?utf-8?B?cHlhOWNrbVd0aGpEa0gyUzR2VXdQVGt3OThKc3pkSGNNd2pRcUJLbUZZbWJ2?= =?utf-8?B?QTlSaHUveUhwNmt3ZXpa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/KyUFnJrJFCIJCtDFabFRtiMswIZuLMus2qv6AJCSFPKIXPl5Yl2NfVUYyweVLmyplRpKM+cWjaBqD9TD62leA+Q2rw==; 24:6n+8MWmiseZffkzm659Mv84ruYQmcQ0YSkYnQO3Y1acnclWbyLlZYA8Xg+7gei3zzOs6PV6DeuIAUt82uyy3RkAJeDIGaQHTgZYmxjWtPiQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR06MB2777; 7:DBnf7qHjTZc4rHZ5s76cZwc1LfLerL+KNj6L6AcKWbvd8JLT1ZY2COooRpfWji91cRAhYCkjoqT6zaGiiU8reWjyjQ7uSxG2kJfuo8XsdeMVUpY/VFNWXQakVSBVdPg2qQ31pWSl6ZugVFcpO9QRnCgMZotS2aH7ige0xs6ZnQvZLnrFdDR4lJi7quR09kStQ1/qCYJxfkyqyTrltzpQFzCIH5NRa2UP7VVU2CBiAooyUuvbJA1FCHSToHbCaI4TtzCyEp4WglZa0QckliFNT8qJsGO+TTRUQv/KjyL/CwaZfY8CKUACMnAk4u4pHRo7pZpq+YIpmaL5jLbIRKGH1uwC/isPuaXppQ3bLpm+0xiw3nHyMR0MvymNt1m05QbK3WGGa9EEuixAblu9cpGG5EPbjInhMkYyvdvcTd8cBNLELorrsR+zLxDjdYVLiniMTmf28K08v49gGEomPaqqeZZoVtcjlhzQcrl0hoFBqGgLMOXmSn3wFoRs1UY6t9FTPkKU9kzg1vtbc5xRDh1IdSizQ+KUPPwXyQvI3Z6w10ThhQ+9i2ek6zmmkcFFkDbd X-OriginatorOrg: cnexlabs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2017 12:18:02.7058 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR06MB2777 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 From: Javier González In order to register through the sysfs interface, a driver needs to know its kobject. On a disk structure, this happens when the partition information is added (device_add_disk), which for lightnvm takes place after the target has been initialized. This means that on target initialization, the kboject has not been created yet. This patch adds a target function to let targets initialize their own kboject as a child of the disk kobject. Signed-off-by: Javier González Added exit typedef and passed gendisk instead of void pointer for exit. Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 9 +++++++++ include/linux/lightnvm.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index b2cd3d6..9bfe035 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -289,6 +289,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) set_capacity(tdisk, tt->capacity(targetdata)); add_disk(tdisk); + if (tt->sysfs_init && tt->sysfs_init(tdisk)) + goto err_sysfs; + t->type = tt; t->disk = tdisk; t->dev = tgt_dev; @@ -298,6 +301,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) mutex_unlock(&dev->mlock); return 0; +err_sysfs: + if (tt->exit) + tt->exit(targetdata); err_init: put_disk(tdisk); err_queue: @@ -320,6 +326,9 @@ static void __nvm_remove_target(struct nvm_target *t) del_gendisk(tdisk); blk_cleanup_queue(q); + if (tt->sysfs_exit) + tt->sysfs_exit(tdisk); + if (tt->exit) tt->exit(tdisk->private_data); diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index bc282d2..ca45e4a 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -440,6 +440,8 @@ typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *); typedef sector_t (nvm_tgt_capacity_fn)(void *); typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *); typedef void (nvm_tgt_exit_fn)(void *); +typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *); +typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *); struct nvm_tgt_type { const char *name; @@ -453,6 +455,10 @@ struct nvm_tgt_type { nvm_tgt_init_fn *init; nvm_tgt_exit_fn *exit; + /* sysfs */ + nvm_tgt_sysfs_init_fn *sysfs_init; + nvm_tgt_sysfs_exit_fn *sysfs_exit; + /* For internal use */ struct list_head list; };