From patchwork Tue Jan 12 06:49:37 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: 8014061 X-Patchwork-Delegate: axboe@kernel.dk Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7930E9F6FA for ; Tue, 12 Jan 2016 06:55:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 968D220379 for ; Tue, 12 Jan 2016 06:55:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA842201F4 for ; Tue, 12 Jan 2016 06:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932851AbcALGv3 (ORCPT ); Tue, 12 Jan 2016 01:51:29 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:38795 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761403AbcALGuY (ORCPT ); Tue, 12 Jan 2016 01:50:24 -0500 Received: by mail-wm0-f51.google.com with SMTP id b14so303602039wmb.1 for ; Mon, 11 Jan 2016 22:50:24 -0800 (PST) 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-type:content-transfer-encoding; bh=ONjJYWKpTs5A6Htn2UvjwtjQAnDG6J32lTkoqatSnWw=; b=eOsmQkST6f1dY0hDOPilo8LxUltIqIN1jtDyqw/ix6thh6tjfO/TrW2nm0QFYrYnmi velr+mCGjZT4wc+oQWivYXG0GxEtKpks55Cg7iATL/H+3ZGaLWIzyvKS4PFs4kW19+l+ dyaUUb4R0Gky47qTfMbRcU+9bnDbJM54Q7FTY= 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-type:content-transfer-encoding; bh=ONjJYWKpTs5A6Htn2UvjwtjQAnDG6J32lTkoqatSnWw=; b=atMI9f5b3Dr+0FM6/Vqdtn/3PVatdF8eKBcEpomyLcdyGrIkfIY+gvogXr/qAlzFwW 4wImxvUKuEeUb0QUAeeur/EJ8o6ocfc2lVO5PjKeXTx1l07t62h5vFUkY7TLfmS7QWPb xHjMoYUzPRfKUpie2mbcb4EIHT13oku8FwISELjOG6jQRfIg0L2TzZ1PdiwZaq6fhUf1 KMhSX/ewHDApN6NQMrZOZ6scmXoQnoDcGU+gQ8aWYGyEQIZ4/gNBb//Nqp286RbJ0Vjt MFeqnrMHtqZLQS838ZqJ5LxqepYYa2KFhmBb633SRikq2/K2ZAgrif+Jtt5YzJBKHI5k MDFQ== X-Gm-Message-State: ALoCoQmsSm83MRKlLGLv6o9KSRqUR5bc04BeGtNfkDRlV9oOKX9ViITkfiOQ9LX1vCKiuCvSoRvv36c5Y/kCxSqfZnjPWf+Lxw== X-Received: by 10.28.187.67 with SMTP id l64mr16869653wmf.39.1452581423672; Mon, 11 Jan 2016 22:50:23 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id yz5sm70776886wjc.36.2016.01.11.22.50.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 22:50:22 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 23/25] lightnvm: introduce ioctl to initialize device Date: Tue, 12 Jan 2016 07:49:37 +0100 Message-Id: <1452581379-18162-24-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452581379-18162-1-git-send-email-m@bjorling.me> References: <1452581379-18162-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable 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 Based on the previous patch, we now introduce an ioctl to initialize the device using nvm_init_sysblock and create the necessary system blocks. The user may specify the media manager that they wish to instantiate on top. Default from user-space will be "gennvm". Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 50 +++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/lightnvm.h | 11 ++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 73b8ae1..ee08fac 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -1019,6 +1019,54 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) return __nvm_configure_remove(&remove); } +static void nvm_setup_nvm_sb_info(struct nvm_sb_info *info) +{ + info->seqnr = 1; + info->erase_cnt = 0; + info->version = 1; +} + +static long __nvm_ioctl_dev_init(struct nvm_ioctl_dev_init *init) +{ + struct nvm_dev *dev; + struct nvm_sb_info info; + + down_write(&nvm_lock); + dev = nvm_find_nvm_dev(init->dev); + up_write(&nvm_lock); + if (!dev) { + pr_err("nvm: device not found\n"); + return -EINVAL; + } + + nvm_setup_nvm_sb_info(&info); + + strncpy(info.mmtype, init->mmtype, NVM_MMTYPE_LEN); + info.fs_ppa.ppa = -1; + + return nvm_init_sysblock(dev, &info); +} + +static long nvm_ioctl_dev_init(struct file *file, void __user *arg) +{ + struct nvm_ioctl_dev_init init; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init))) + return -EFAULT; + + if (init.flags != 0) { + pr_err("nvm: no flags supported\n"); + return -EINVAL; + } + + init.dev[DISK_NAME_LEN - 1] = '\0'; + + return __nvm_ioctl_dev_init(&init); +} + static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) { void __user *argp = (void __user *)arg; @@ -1032,6 +1080,8 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) return nvm_ioctl_dev_create(file, argp); case NVM_DEV_REMOVE: return nvm_ioctl_dev_remove(file, argp); + case NVM_DEV_INIT: + return nvm_ioctl_dev_init(file, argp); } return 0; } diff --git a/include/uapi/linux/lightnvm.h b/include/uapi/linux/lightnvm.h index 0171b85..56339e2 100644 --- a/include/uapi/linux/lightnvm.h +++ b/include/uapi/linux/lightnvm.h @@ -101,6 +101,12 @@ struct nvm_ioctl_remove { __u32 flags; }; +struct nvm_ioctl_dev_init { + char dev[DISK_NAME_LEN]; /* open-channel SSD device */ + char mmtype[NVM_MMTYPE_LEN]; /* register to media manager */ + + __u32 flags; +}; /* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */ enum { @@ -111,6 +117,9 @@ enum { /* device level cmds */ NVM_DEV_CREATE_CMD, NVM_DEV_REMOVE_CMD, + + /* Init a device to support LightNVM media managers */ + NVM_DEV_INIT_CMD, }; #define NVM_IOCTL 'L' /* 0x4c */ @@ -123,6 +132,8 @@ enum { struct nvm_ioctl_create) #define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \ struct nvm_ioctl_remove) +#define NVM_DEV_INIT _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \ + struct nvm_ioctl_dev_init) #define NVM_VERSION_MAJOR 1 #define NVM_VERSION_MINOR 0