From patchwork Wed Jun 29 14:51:41 2016 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: 9205555 X-Patchwork-Delegate: snitzer@redhat.com 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 B01356089F for ; Wed, 29 Jun 2016 14:55:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0C3128669 for ; Wed, 29 Jun 2016 14:55:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 952E72866B; Wed, 29 Jun 2016 14:55:55 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63BD52866A for ; Wed, 29 Jun 2016 14:55:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5TEqMIQ001125; Wed, 29 Jun 2016 10:52:22 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u5TEq808009827 for ; Wed, 29 Jun 2016 10:52:08 -0400 Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5TEq8WV031615 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 29 Jun 2016 10:52:08 -0400 Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D30EC65422 for ; Wed, 29 Jun 2016 14:52:06 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id r201so14943897wme.0 for ; Wed, 29 Jun 2016 07:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uZtcRuRJTEL2uRqGqEBe1FDfTVvfwLDOM9tkpNIkNXo=; b=iZf5r0uTmEydgrD2yJALw6TPW5xjsz22VAlUGfIXvmxEumlsY57K72KVZJYyHHETum 34G8yiRoi7pgmEunESjF9qYMRpnfNfSaFiiwJrdCyh2EpRpxZOg+ISCRu7V2kkGj9F4q tBNPeOrdUyySxL6nooJ+UK1LDO6baPyznd460= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uZtcRuRJTEL2uRqGqEBe1FDfTVvfwLDOM9tkpNIkNXo=; b=VS9WVZtgTRKU3pKxCBKREUty197LKoQ152SQqF66DxCo3rxu55zjWkymIIJKLePgI0 FkOVGAZ0qioHgvqxBjFptI0uFts4wiaV2miUj7CiRd/546F7zFrujTQ4QP6Kb/p4mLLa mj7UKA1+JM4Dgb3lr5LsQwULC0paz8IZdGkrhIfFTkqr/d87C0LxEjm1aNtqy5mzvJY+ /lvIuJeQW7xST5JyO7GTp826ygWxELJyQFSZRTrLSHw3ABN5ZvYrlsBWND3gqAhEX+6O dgzMyk3npzKmP8j1+pYVtwNNgCq4vijsDVcFgRI5PJJ7NTWZv7P4n7EgWm9e7FmDkxk6 j3hg== X-Gm-Message-State: ALyK8tLa/JAxUbeoE6my0pN2isurwYNh/oB73DVgiYidebBZ0RnbEy+TfBaMo77iXEflxg== X-Received: by 10.28.136.195 with SMTP id k186mr21765056wmd.13.1467211924322; Wed, 29 Jun 2016 07:52:04 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id t1sm4112703wjy.3.2016.06.29.07.52.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jun 2016 07:52:03 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com, keith.busch@intel.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com Date: Wed, 29 Jun 2016 16:51:41 +0200 Message-Id: <1467211901-26707-7-git-send-email-m@bjorling.me> In-Reply-To: <1467211901-26707-1-git-send-email-m@bjorling.me> References: <1467211901-26707-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 29 Jun 2016 14:52:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 29 Jun 2016 14:52:07 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.google.com' FROM:'m@bjorling.me' RCPT:'' X-RedHat-Spam-Score: -0.121 (BAYES_50, DCC_REPUT_13_19, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-loop: dm-devel@redhat.com Cc: "Simon A. F. Lund" , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [dm-devel] [PATCH 6/6] lightnvm: expose gennvm target type through sysfs X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP From: "Simon A. F. Lund" Create a sysfs directory for targets to expose their internal statistics and knobs. The entries is exposed through the /sys/block//lightnvm/* directory. It currently holds a single sysfs entry "type", which exports the target type name. Signed-off-by: Simon A. F. Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/gennvm.c | 112 ++++++++++++++++++++++++++++++++++++++-------- include/linux/lightnvm.h | 10 +++++ 2 files changed, 104 insertions(+), 18 deletions(-) diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c index b74174c..bfdad3c 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -20,6 +20,87 @@ #include "gennvm.h" +static struct attribute gen_type_attr = { + .name = "type", + .mode = S_IRUGO +}; + +static struct attribute *gen_target_attrs[] = { + &gen_type_attr, + NULL, +}; + +static ssize_t gen_target_attr_show(struct kobject *kobj, + struct attribute *attr, + char *page) +{ + struct nvm_target *t = container_of(kobj, struct nvm_target, kobj); + + if (strcmp(attr->name, "type") == 0) + return scnprintf(page, PAGE_SIZE, "%s\n", t->type->name); + + if (t->type->sysfs_show) + return t->type->sysfs_show(t, attr, page); + + return scnprintf(page, PAGE_SIZE, + "Unhandled attr(%s) in `nvm_target_attr_show`\n", + attr->name); +} + +static const struct sysfs_ops target_sysfs_ops = { + .show = gen_target_attr_show, +}; + +static void gen_target_release(struct kobject *kobj) +{ + struct nvm_target *t = container_of(kobj, struct nvm_target, kobj); + struct nvm_tgt_type *tt = t->type; + struct gendisk *tdisk = t->disk; + struct request_queue *q = tdisk->queue; + + pr_debug("gen: `gen_target_release`\n"); + + del_gendisk(tdisk); + blk_cleanup_queue(q); + put_disk(tdisk); + + if (tt->exit) + tt->exit(tdisk->private_data); + + kfree(t); +} + +static struct kobj_type nvm_target_type = { + .sysfs_ops = &target_sysfs_ops, + .default_attrs = gen_target_attrs, + .release = gen_target_release +}; + +void gen_unregister_target(struct nvm_target *t) +{ + kobject_uevent(&t->kobj, KOBJ_REMOVE); + kobject_del(&t->kobj); + kobject_put(&t->kobj); +} + +int gen_register_target(struct nvm_target *t) +{ + struct gendisk *disk = t->disk; + struct device *dev = disk_to_dev(disk); + int ret; + + ret = kobject_init_and_add(&t->kobj, &nvm_target_type, + kobject_get(&dev->kobj), "%s", "lightnvm"); + if (ret < 0) { + pr_err("gen: `_register_target` failed.\n"); + kobject_put(&t->kobj); + return ret; + } + + kobject_uevent(&t->kobj, KOBJ_ADD); + return 0; +} + static struct nvm_target *gen_find_target(struct gen_dev *gn, const char *name) { struct nvm_target *tgt; @@ -60,7 +141,7 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) } mutex_unlock(&gn->lock); - t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL); + t = kzalloc(sizeof(struct nvm_target), GFP_KERNEL); if (!t) return -ENOMEM; @@ -89,13 +170,19 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) blk_queue_max_hw_sectors(tqueue, 8 * dev->ops->max_phys_sect); - set_capacity(tdisk, tt->capacity(targetdata)); - add_disk(tdisk); - t->type = tt; t->disk = tdisk; t->dev = dev; + set_capacity(tdisk, tt->capacity(targetdata)); + add_disk(tdisk); + + if (gen_register_target(t)) + goto err_init; + + if (tt->sysfs_init) + tt->sysfs_init(t); + mutex_lock(&gn->lock); list_add_tail(&t->list, &gn->targets); mutex_unlock(&gn->lock); @@ -112,20 +199,10 @@ err_t: static void __gen_remove_target(struct nvm_target *t) { - struct nvm_tgt_type *tt = t->type; - struct gendisk *tdisk = t->disk; - struct request_queue *q = tdisk->queue; - - del_gendisk(tdisk); - blk_cleanup_queue(q); - - if (tt->exit) - tt->exit(tdisk->private_data); - - put_disk(tdisk); - list_del(&t->list); - kfree(t); + if (t->type->sysfs_exit) + t->type->sysfs_exit(t); + gen_unregister_target(t); } /** @@ -627,7 +704,6 @@ static void gen_lun_info_print(struct nvm_dev *dev) struct gen_lun *lun; unsigned int i; - gen_for_each_lun(gn, lun, i) { spin_lock(&lun->vlun.lock); diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index d190786..3823891 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -211,6 +211,8 @@ struct nvm_target { struct nvm_dev *dev; struct nvm_tgt_type *type; struct gendisk *disk; + + struct kobject kobj; }; struct nvm_tgt_instance { @@ -434,6 +436,10 @@ 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_dev *, struct gendisk *, int, int); typedef void (nvm_tgt_exit_fn)(void *); +typedef void (nvm_tgt_sysfs_init_fn)(struct nvm_target *); +typedef void (nvm_tgt_sysfs_exit_fn)(struct nvm_target *); +typedef ssize_t(nvm_tgt_sysfs_show_fn)(struct nvm_target *, + struct attribute *, char *); struct nvm_tgt_type { const char *name; @@ -448,6 +454,10 @@ struct nvm_tgt_type { nvm_tgt_init_fn *init; nvm_tgt_exit_fn *exit; + nvm_tgt_sysfs_init_fn *sysfs_init; + nvm_tgt_sysfs_exit_fn *sysfs_exit; + nvm_tgt_sysfs_show_fn *sysfs_show; + /* For internal use */ struct list_head list; };