From patchwork Thu Jan 26 11:47:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= X-Patchwork-Id: 9538925 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 E80D0604A0 for ; Thu, 26 Jan 2017 11:48:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9EBC280D0 for ; Thu, 26 Jan 2017 11:48:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CED1E2818E; Thu, 26 Jan 2017 11:48:04 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 775F9280D0 for ; Thu, 26 Jan 2017 11:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752205AbdAZLry (ORCPT ); Thu, 26 Jan 2017 06:47:54 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:37700 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751986AbdAZLrw (ORCPT ); Thu, 26 Jan 2017 06:47:52 -0500 Received: by mail-wm0-f46.google.com with SMTP id c206so79675093wme.0 for ; Thu, 26 Jan 2017 03:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4RQC3dWG1gTbqnKTSh3zlqanM3zgj+JAkeuAUpJdnnY=; b=0+rr3cC0/ZcuHBcODI0mXxVu31Y3LpDm55DHQ5f4vmDnjQu+y93Rvie/2f0B3e0+1L KYrJE0XW0yQaxuZHnwJ4bhI0FUhb830fLtshf3tPiGrAu3kRk1kUmJWDOAtBWtArnu2r rxJefrdq9kaPWuf7PqP/cXoxZ1KX0ASioGl2bsg4FdbTPwel/9Ow6Nt7jUbQFtIVLYyL fU2lJk+8AGTQ8aFzvTGg4IpkfntanX+lpt+c9ppCZYw3S3Im4mFalDSATkKsMKYTkkqT W5qbUj5LpslIGEJ/Ak6U4+6d7FbQE4NToT6xytnHoq3SJuvXRqoItPkxFzgTEtruCY8q 0dlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4RQC3dWG1gTbqnKTSh3zlqanM3zgj+JAkeuAUpJdnnY=; b=EQmbdK6MagQ0996wim7X1e/hjqZBm+Z19HStf5nuDcMLekbjLtUS63luXnsBDEGJjv HBdzzzhEjOWabj3faWfz98+gWjev//urg3/b80GFHi3bxK+lX26mcgIpLvLAHj+tbisx KySWXnjDILHOLppRKwvpuulZe9feyR62VcLGarGs0FYRqKj12pUhv+ValRkZICdMqmkx WZWk3sBWWpPlfwLvkPijkCClRwCGQHAbIAEu+HyMUXY/knUBb/AgumvsTFhfeX2oLT8o 09QnwTSICxPf35YPM7WrmsPfVEjHJLEqbGlAXbFawRC3tieiijAa+nVBAsmCWHUZl3JR tq3A== X-Gm-Message-State: AIkVDXKFGUg4sp+OOom5lENXdnLM1miRRSeAK1d5QuN/F7lTMsDufca9g+gUP863tR5nBw== X-Received: by 10.223.130.118 with SMTP id 109mr2705156wrb.10.1485431270850; Thu, 26 Jan 2017 03:47:50 -0800 (PST) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id y1sm3282750wme.15.2017.01.26.03.47.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Jan 2017 03:47:49 -0800 (PST) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH 2/3] lightnvm: allow targets to use sysfs Date: Thu, 26 Jan 2017 12:47:39 +0100 Message-Id: <1485431260-20268-2-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485431260-20268-1-git-send-email-javier@cnexlabs.com> References: <1485431260-20268-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 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 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 --- drivers/lightnvm/core.c | 9 +++++++++ include/linux/lightnvm.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 3a3e91d..8baae61 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->private_data); + if (tt->exit) tt->exit(tdisk->private_data); diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index a75d8c0..11c318e 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -440,6 +440,7 @@ 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 *); struct nvm_tgt_type { const char *name; @@ -453,6 +454,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_exit_fn *sysfs_exit; + /* For internal use */ struct list_head list; };