From patchwork Mon Aug 10 22:42:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Baluta X-Patchwork-Id: 6986931 Return-Path: X-Original-To: patchwork-linux-fsdevel@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 9FD51C05AC for ; Mon, 10 Aug 2015 22:32:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B771C205D6 for ; Mon, 10 Aug 2015 22:31:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB9EA205D3 for ; Mon, 10 Aug 2015 22:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933326AbbHJWaf (ORCPT ); Mon, 10 Aug 2015 18:30:35 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:38731 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933498AbbHJWad (ORCPT ); Mon, 10 Aug 2015 18:30:33 -0400 Received: by wicja10 with SMTP id ja10so44561491wic.1; Mon, 10 Aug 2015 15:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=yucvBtZuxV5JLVHziymRxdCywcy0PlmqPgrdH4Dp/U0=; b=sf40J4TRzOHxNsZrNmFZjxJybnCM7WZLrGYodakZcmoPLAgmJT6567zkji5fZZQm18 q9N+7Yx6bIErJzI5jOgajJcd9BQtRGgON3IleXRac6jxCHzjm7kEat9kMYyvdOPLVWnt PYT5eeydwe1cBHe7rSrI5wjIbmJIoDoBRI4uU0AzIqsEdS2bRb8hzybzNxMfGDR+LwjU qxMJralcd0XnhGYpQLYYrI3T22s6VuTF3YKTWjGIVm5I/W4k8ebLA3jvd+hXzx3vkKJr nr1yMnDRNe26e2PGjTj/TY8uYIpbuD1eMIjKaEnsAHT1/SqF4n18aoGKAiYJmEWjl0GD wVzA== X-Received: by 10.194.63.42 with SMTP id d10mr53499790wjs.92.1439245831786; Mon, 10 Aug 2015 15:30:31 -0700 (PDT) Received: from ixhome.ixhome ([109.96.190.235]) by smtp.gmail.com with ESMTPSA id bq7sm31485449wjc.31.2015.08.10.15.30.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Aug 2015 15:30:30 -0700 (PDT) From: Daniel Baluta To: jic23@kernel.org, jlbec@evilplan.org, linux-iio@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: lars@metafoo.de, knaack.h@gmx.de, linux-kernel@vger.kernel.org, octavian.purdila@intel.com, pebolle@tiscali.nl, patrick.porlan@intel.com, adriana.reus@intel.com, constantin.musca@intel.com, marten@intuitiveaerial.com, daniel.baluta@intel.com, cristina.opriceana@gmail.com, pmeerw@pmeerw.net, hch@lst.de, viro@zeniv.linux.org.uk, akpm@linux-foundation.org Subject: [PATCH v7 1/5] configfs: Allow dynamic group (un)registration Date: Tue, 11 Aug 2015 01:42:38 +0300 Message-Id: <1439246562-17515-2-git-send-email-daniel.baluta@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439246562-17515-1-git-send-email-daniel.baluta@intel.com> References: <1439246562-17515-1-git-send-email-daniel.baluta@intel.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 We don't want to hardcode default groups at subsystem creation time. Thus, we export: * configfs_register_group * configfs_unregister_group that allows drivers to programatically create/destroy groups. Signed-off-by: Daniel Baluta --- I am not sure about the locking scheme here, Joel can you help? :) fs/configfs/dir.c | 39 +++++++++++++++++++++++++++++++++++++-- include/linux/configfs.h | 4 ++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index c81ce7f..dde3251 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -651,7 +651,8 @@ static void detach_groups(struct config_group *group) * try using vfs_mkdir. Just a thought. */ static int create_default_group(struct config_group *parent_group, - struct config_group *group) + struct config_group *group, + struct dentry **dentry) { int ret; struct configfs_dirent *sd; @@ -671,6 +672,8 @@ static int create_default_group(struct config_group *parent_group, if (!ret) { sd = child->d_fsdata; sd->s_type |= CONFIGFS_USET_DEFAULT; + if (dentry) + *dentry = child; } else { BUG_ON(d_inode(child)); d_drop(child); @@ -691,7 +694,7 @@ static int populate_groups(struct config_group *group) for (i = 0; group->default_groups[i]; i++) { new_group = group->default_groups[i]; - ret = create_default_group(group, new_group); + ret = create_default_group(group, new_group, NULL); if (ret) { detach_groups(group); break; @@ -1636,6 +1639,38 @@ const struct file_operations configfs_dir_operations = { .iterate = configfs_readdir, }; +int configfs_register_group(struct config_group *parent_group, + struct config_group *group) +{ + struct dentry *dentry; + int ret; + + link_group(parent_group, group); + + ret = create_default_group(parent_group, group, &dentry); + if (ret == 0) + configfs_dir_set_ready(dentry->d_fsdata); + + return ret; +} +EXPORT_SYMBOL(configfs_register_group); + +void configfs_unregister_group(struct config_group *group) +{ + struct dentry *dentry = group->cg_item.ci_dentry; + + mutex_lock(&d_inode(dentry)->i_mutex); + configfs_detach_group(&group->cg_item); + d_inode(dentry)->i_flags |= S_DEAD; + dont_mount(dentry); + mutex_unlock(&d_inode(dentry)->i_mutex); + + d_delete(dentry); + dput(dentry); + unlink_group(group); +} +EXPORT_SYMBOL(configfs_unregister_group); + int configfs_register_subsystem(struct configfs_subsystem *subsys) { int err; diff --git a/include/linux/configfs.h b/include/linux/configfs.h index c9e5c57..726980e 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -251,6 +251,10 @@ static inline struct configfs_subsystem *to_configfs_subsystem(struct config_gro int configfs_register_subsystem(struct configfs_subsystem *subsys); void configfs_unregister_subsystem(struct configfs_subsystem *subsys); +int configfs_register_group(struct config_group *parent_group, + struct config_group *group); +void configfs_unregister_group(struct config_group *group); + /* These functions can sleep and can alloc with GFP_KERNEL */ /* WARNING: These cannot be called underneath configfs callbacks!! */ int configfs_depend_item(struct configfs_subsystem *subsys, struct config_item *target);