From patchwork Fri Jan 15 11:13:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1426886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=yccXe6Xz; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHJV61lk4z9sWD for ; Fri, 15 Jan 2021 22:14:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726385AbhAOLOH (ORCPT ); Fri, 15 Jan 2021 06:14:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbhAOLOH (ORCPT ); Fri, 15 Jan 2021 06:14:07 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF82C061796 for ; Fri, 15 Jan 2021 03:13:25 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id q18so8883761wrn.1 for ; Fri, 15 Jan 2021 03:13:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2tAzY7WCaNY6Vvb3iCn3hNcrKN7+M/W71UmthXEquj0=; b=yccXe6XzXp4PeqVy5jE4MDa9Q7zYzWMxG2qUuOLKr5MHfKj8qz/eRR6l/DapGMFh/2 NSIRPoQOfQg6DGgxI9MOtu51DHCgdDkMKtQ8uwH95J8WUcCtaw/l5Bw05MCg8+wzmEkO 7auWaWb4S1pUYIYW7AMkLi1G09ag0IeiqPPXXpLP/V33KkxJ0bxfDXWPNE6tSZHEFg+o OZTAbE6MvM5XfMJM4nshUbeWpAQDEeOJDApjoekDLq0Ly4yp1QRIZClf1Zr2rsVJ+ZqR MsROxnfjceeoCalkPtRbow/EXyGdH/QSRnqbPKlznKCam5y7vlHoTLm5cEDA4PhBU+TY L9YA== 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=2tAzY7WCaNY6Vvb3iCn3hNcrKN7+M/W71UmthXEquj0=; b=eSjiMVA67UgAYvD9CAoEsHlEzNr9ofieAnSCS9IvlmFZyFrJFz85++NoTHSkyGaaKR 4JrOYcYQ/R4W0E+llvna66AwZAoW2gb+q09Wvtwm51FbseZQ8oFFXutB+Nz/oe2fbKoB mOyn+L8zO56FpCBj8NgJD/lHnmgHsM4Tu5nFWDH8Jrr0UT6KNclXnLEEID0ovTe1P38T u4I/qjwLQyCOpQkgpS9y5eSu4+fqqrohR7qdYhFbtMcIQxkrskpHO4WralZktsrV66S7 KyIM+vucadtjGzwFy+Z9+zkJQjDOLNgoVCQwJxEpAcLov+dQ+Sw07dw/V8Qm8bK3nmdn 0Rgg== X-Gm-Message-State: AOAM533QWkud0wyIJuRR4s1OyFeKlIucHElWPESQ1JUsvU4dKSXh3HlT L9yRC1FDWNDDQsAMhrlyUJVwFg== X-Google-Smtp-Source: ABdhPJyb5AthIn+iJs64v8mJJV6h4qlEQLZ0vDmL/7IZZEfzlpBDZuNS8IxFoGmyYnY5FQ+eStCLMw== X-Received: by 2002:adf:8184:: with SMTP id 4mr13102145wra.63.1610709203901; Fri, 15 Jan 2021 03:13:23 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id l1sm15048822wrq.64.2021.01.15.03.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 03:13:23 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, Kent Gibson , Linus Walleij , Andy Shevchenko , linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 1/4] configfs: increase the item name length Date: Fri, 15 Jan 2021 12:13:08 +0100 Message-Id: <20210115111311.31601-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210115111311.31601-1-brgl@bgdev.pl> References: <20210115111311.31601-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski 20 characters limit for item name is relatively small. Let's increase it to 32 to fit '04-committable-children' - a name we'll use in the sample code for committable items. Signed-off-by: Bartosz Golaszewski --- include/linux/configfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 2e8c69b43c64..4f76dcc08134 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -27,7 +27,7 @@ #include /* struct kref */ #include /* struct mutex */ -#define CONFIGFS_ITEM_NAME_LEN 20 +#define CONFIGFS_ITEM_NAME_LEN 32 struct module; From patchwork Fri Jan 15 11:13:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1426887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=XmuU+H9N; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHJV74QpNz9sWY for ; Fri, 15 Jan 2021 22:14:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725831AbhAOLOP (ORCPT ); Fri, 15 Jan 2021 06:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbhAOLOH (ORCPT ); Fri, 15 Jan 2021 06:14:07 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1512C061799 for ; Fri, 15 Jan 2021 03:13:25 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id d26so8846778wrb.12 for ; Fri, 15 Jan 2021 03:13:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dzBIBC0fhIl1XSSH6o1Y94mhuL4g5zkjFrYGUjls+eg=; b=XmuU+H9N42TMrH0RYk4v1pPOa1GXDIBaC9TW9oIfte3ZWUA0fKvDGDvzVZkKcmC7B2 16BEHyCM0urQBL2EoVI+8/X4cxqunmI5xoeu5FIDW8+E5VPaYpk5McxG/3WXl70CTtjT lsjiNon8zP1kD+DQ0zH97oW/Pb0iDjOufeapp1qQe5/aPmGxe/4qj3y5jPITZMsnhh6t wyW6icK8qozixmxs7ENmv9vtW1gf4Ff9uzdAJWyfrVmRBeBcssydx5I3zFO0WgA0IACH Ndri40eE4rIwV05OIXd8ybZbE0wZM6Lhq3p6mQ+xllSJ7UHfE+ckUjQS3zwt6Xtc4CxY ZAXw== 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=dzBIBC0fhIl1XSSH6o1Y94mhuL4g5zkjFrYGUjls+eg=; b=kTa7q6IZ72kWVNoor+P9nEoCcrLTVzGDbd4aRstVVmjvuSyMiKeRPhz1aKwct9OqcA I68OGVGK8EgqkIQh4ux13VOxdqkFiokHgUsLdLzMgr5eh5gaROWHl69DRyAmU61FHQgT xBkk2xtQF5IU/cZX/qbger41C06i5bakqE1wgheZlBJuvzNPK31B26Z5gCbzj8FedcDJ eAsiDzjOHfInyWl7/+UAJiA1SmRcFo1GkyA4oNZbo7IgJD6wGeKvfJan8MM83CwgGWdy m+J5YnSiWImR16JoeYSqKrhylD6uEcUuIbWc7mSkm5m4eUHdKg7AFcfu6I3lAPHSh12w EmqA== X-Gm-Message-State: AOAM533YHIziOflxM6fzPxq3r/ih3ZQZe2OQ/aXdt/dMdwWEp1Dqznoq 8kY34JEGUuVarC04E5BeY8TIkQ== X-Google-Smtp-Source: ABdhPJxfNle5rxjzF83VOUfwUYgoBHOo8P9VI3PSN+mzfrFHdqImR/HGffbJltytsytmJrJcGr+fqw== X-Received: by 2002:adf:eac1:: with SMTP id o1mr12469664wrn.256.1610709204819; Fri, 15 Jan 2021 03:13:24 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id l1sm15048822wrq.64.2021.01.15.03.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 03:13:24 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, Kent Gibson , Linus Walleij , Andy Shevchenko , linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 2/4] configfs: use (1UL << bit) for internal flags Date: Fri, 15 Jan 2021 12:13:09 +0100 Message-Id: <20210115111311.31601-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210115111311.31601-1-brgl@bgdev.pl> References: <20210115111311.31601-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski For better readability and maintenance: use the (1UL << bit) for flag definitions. Signed-off-by: Bartosz Golaszewski --- fs/configfs/configfs_internal.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h index 22dce2d35a4b..2d21bba92acf 100644 --- a/fs/configfs/configfs_internal.h +++ b/fs/configfs/configfs_internal.h @@ -46,16 +46,16 @@ struct configfs_dirent { struct configfs_fragment *s_frag; }; -#define CONFIGFS_ROOT 0x0001 -#define CONFIGFS_DIR 0x0002 -#define CONFIGFS_ITEM_ATTR 0x0004 -#define CONFIGFS_ITEM_BIN_ATTR 0x0008 -#define CONFIGFS_ITEM_LINK 0x0020 -#define CONFIGFS_USET_DIR 0x0040 -#define CONFIGFS_USET_DEFAULT 0x0080 -#define CONFIGFS_USET_DROPPING 0x0100 -#define CONFIGFS_USET_IN_MKDIR 0x0200 -#define CONFIGFS_USET_CREATING 0x0400 +#define CONFIGFS_ROOT (1UL << 0) +#define CONFIGFS_DIR (1UL << 1) +#define CONFIGFS_ITEM_ATTR (1UL << 2) +#define CONFIGFS_ITEM_BIN_ATTR (1UL << 3) +#define CONFIGFS_ITEM_LINK (1UL << 5) +#define CONFIGFS_USET_DIR (1UL << 6) +#define CONFIGFS_USET_DEFAULT (1UL << 7) +#define CONFIGFS_USET_DROPPING (1UL << 8) +#define CONFIGFS_USET_IN_MKDIR (1UL << 9) +#define CONFIGFS_USET_CREATING (1UL << 10) #define CONFIGFS_NOT_PINNED (CONFIGFS_ITEM_ATTR | CONFIGFS_ITEM_BIN_ATTR) extern struct mutex configfs_symlink_mutex; From patchwork Fri Jan 15 11:13:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1426888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Vg4GlWtb; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHJV82Lnjz9sRf for ; Fri, 15 Jan 2021 22:14:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727707AbhAOLOW (ORCPT ); Fri, 15 Jan 2021 06:14:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726046AbhAOLOR (ORCPT ); Fri, 15 Jan 2021 06:14:17 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECC0CC061757 for ; Fri, 15 Jan 2021 03:13:26 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id c5so8864615wrp.6 for ; Fri, 15 Jan 2021 03:13:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m8SFH+NJPWv4YU0duYJ9V6em7qEfdzHzvANB5+9Qh7o=; b=Vg4GlWtbAGFFgRZtAloXFDMDEb5vjZYA5Em8ghTDoFQe1S73O7NQs/lZrPM+0uKMiL 5lIkfF7b0m6xZCKyvTpUFvJVBsQ1RnEeZhgb/NXCBP8y5irQYeTcVniZdE9D9ViiTLyY Ckx7HLk4qRriUaRitJAM50BDPhXaS7mlGYM+8IHqF/ZnQwvw9/P1oIE+ZC7py6hfMREi RvS3RfSp6UCN/XFhuTR4ikmPgQW7Hi571kSGL1swsvYpqAzHjanJw1vDJcQ6CuOfup22 hGbT9dru+nvuSHVkiOCctE0zXJITLdVH2+JKAspXxmzyYFmsJAjIwmn4KBZhF0afczRN mxTQ== 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=m8SFH+NJPWv4YU0duYJ9V6em7qEfdzHzvANB5+9Qh7o=; b=oeiLpNlIfCwl1J9xSMDBD6fZHRzRVE3ObUA2/HCxIKOuUQ/bjqfYxk4FYlklv3M2+z +2lfqpGcrxQ6zmeu3XiukccH/H1gO+IuBFxmmLPxMWsRxmaMkix7it7oDjO8X51cyIg6 c8TEAee3neLMTwPQluu66nYLoHS2lQAZFb0KNqxRABnVxozJX+nbNtb3KnjNgReOd0ML 1h+g6AiX1LSCdi7rYe4KzLv8jdgiAPwUCjAi8eSDe9VOdwPjlo9TBjpDuP8B+KcyGYft yDjzI/SuW1nmt9EhmNLACRhn/l0ZsgOLFINvXtoNCe47WURpd47ZKONQxgmLI9KzXaPs eRfA== X-Gm-Message-State: AOAM5301p6fusl/dzFJvWl8fS95QJlD4wfN5aKpnseZMZiV2avq0D7QH Qgxlmeui8mzwwIpeeFi0BL2Itw== X-Google-Smtp-Source: ABdhPJwEHOwRxdcRqN83FP2bmjr4Rm7LiOh7qglyUi6PqExxGCAhsIoV8olwEDCao1VMGcA+dghc4A== X-Received: by 2002:a5d:54cc:: with SMTP id x12mr12773197wrv.132.1610709205637; Fri, 15 Jan 2021 03:13:25 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id l1sm15048822wrq.64.2021.01.15.03.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 03:13:25 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, Kent Gibson , Linus Walleij , Andy Shevchenko , linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 3/4] configfs: implement committable items Date: Fri, 15 Jan 2021 12:13:10 +0100 Message-Id: <20210115111311.31601-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210115111311.31601-1-brgl@bgdev.pl> References: <20210115111311.31601-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This implements configfs committable items. We mostly follow the documentation except that we extend config_group_ops with uncommit_item() callback for reverting the changes made by commit_item(). Each committable group has two sub-directories: pending and live. New items can only be created in pending/. Attributes can only be modified while the item is in pending/. Once it's ready to be committed, it must be moved over to live/ using the rename() system call. This is when the commit_item() function will be called. Implementation-wise: we reuse the default group mechanism to elegantly plug the new pseude-groups into configfs. The pending group inherits the parent group's operations so that config_items can be seamlesly created in it using the callbacks supplied by the user as part of the committable group itself. Signed-off-by: Bartosz Golaszewski --- Documentation/filesystems/configfs.rst | 6 +- fs/configfs/configfs_internal.h | 2 + fs/configfs/dir.c | 244 ++++++++++++++++++++++++- include/linux/configfs.h | 1 + 4 files changed, 244 insertions(+), 9 deletions(-) diff --git a/Documentation/filesystems/configfs.rst b/Documentation/filesystems/configfs.rst index 1d3d6f4a82a9..7e0e7c356450 100644 --- a/Documentation/filesystems/configfs.rst +++ b/Documentation/filesystems/configfs.rst @@ -290,6 +290,7 @@ config_item_type:: struct config_group *(*make_group)(struct config_group *group, const char *name); int (*commit_item)(struct config_item *item); + int (*uncommit_item)(struct config_item *item); void (*disconnect_notify)(struct config_group *group, struct config_item *item); void (*drop_item)(struct config_group *group, @@ -490,9 +491,6 @@ pass up an error. Committable Items ================= -Note: - Committable items are currently unimplemented. - Some config_items cannot have a valid initial state. That is, no default values can be specified for the item's attributes such that the item can do its work. Userspace must configure one or more attributes, @@ -532,4 +530,4 @@ method returns zero and the item is moved to the "live" directory. As rmdir(2) does not work in the "live" directory, an item must be shutdown, or "uncommitted". Again, this is done via rename(2), this time from the "live" directory back to the "pending" one. The subsystem -is notified by the ct_group_ops->uncommit_object() method. +is notified by the ct_group_ops->uncommit_item() method. diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h index 2d21bba92acf..3e74876c2bd5 100644 --- a/fs/configfs/configfs_internal.h +++ b/fs/configfs/configfs_internal.h @@ -56,6 +56,8 @@ struct configfs_dirent { #define CONFIGFS_USET_DROPPING (1UL << 8) #define CONFIGFS_USET_IN_MKDIR (1UL << 9) #define CONFIGFS_USET_CREATING (1UL << 10) +#define CONFIGFS_GROUP_PENDING (1UL << 11) +#define CONFIGFS_GROUP_LIVE (1UL << 12) #define CONFIGFS_NOT_PINNED (CONFIGFS_ITEM_ATTR | CONFIGFS_ITEM_BIN_ATTR) extern struct mutex configfs_symlink_mutex; diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index b839dd1b459f..491b495ac2ea 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -656,6 +656,13 @@ static void detach_groups(struct config_group *group) inode_unlock(d_inode(child)); + /* + * Free memory allocated for the pending and live directories + * of committable groups. + */ + if (sd->s_type & (CONFIGFS_GROUP_PENDING | CONFIGFS_GROUP_LIVE)) + kfree(sd->s_element); + d_delete(child); dput(child); } @@ -860,6 +867,134 @@ static void configfs_detach_item(struct config_item *item) configfs_remove_dir(item); } +static bool is_committable_group(struct config_item *item) +{ + const struct config_item_type *type = item->ci_type; + + if (type && type->ct_group_ops && + type->ct_group_ops->commit_item && + type->ct_group_ops->uncommit_item) + return true; + + return false; +} + +struct pending_group_data { + struct config_group group; + struct config_item_type type; + struct configfs_group_operations group_ops; +}; + +struct live_group_data { + struct config_group group; + struct config_item_type type; +}; + +static int create_pending_group(struct config_item *parent_item, + struct configfs_fragment *frag) +{ + const struct config_item_type *parent_type = parent_item->ci_type; + struct pending_group_data *pending; + struct configfs_dirent *sd; + int ret; + + pending = kzalloc(sizeof(*pending), GFP_KERNEL); + if (!pending) + return -ENOMEM; + + /* + * Let's inherit the group_ops from the parent except for item + * committing and uncommitting. + */ + memcpy(&pending->group_ops, parent_type->ct_group_ops, + sizeof(struct configfs_group_operations)); + pending->type.ct_group_ops = &pending->group_ops; + pending->type.ct_group_ops->commit_item = NULL; + pending->type.ct_group_ops->uncommit_item = NULL; + + /* Let's directly reuse item_ops. */ + pending->type.ct_item_ops = parent_type->ct_item_ops; + pending->type.ct_owner = parent_type->ct_owner; + + config_group_init_type_name(&pending->group, "pending", &pending->type); + + ret = create_default_group(to_config_group(parent_item), + &pending->group, frag); + if (ret) { + kfree(pending); + return ret; + } + + link_group(to_config_group(parent_item), &pending->group); + + sd = pending->group.cg_item.ci_dentry->d_fsdata; + /* Allow creating config_items in 'pending' group. */ + sd->s_type |= (CONFIGFS_GROUP_PENDING | CONFIGFS_USET_DIR); + + return 0; +} + +static int create_live_group(struct config_item *parent_item, + struct configfs_fragment *frag) +{ + struct live_group_data *live; + struct configfs_dirent *sd; + int ret; + + live = kzalloc(sizeof(*live), GFP_KERNEL); + if (!live) + return -ENOMEM; + + live->type.ct_owner = parent_item->ci_type->ct_owner; + + config_group_init_type_name(&live->group, "live", &live->type); + + ret = create_default_group(to_config_group(parent_item), + &live->group, frag); + if (ret) { + kfree(live); + return ret; + } + + link_group(to_config_group(parent_item), &live->group); + + sd = live->group.cg_item.ci_dentry->d_fsdata; + sd->s_type |= CONFIGFS_GROUP_LIVE; + sd->s_type &= ~CONFIGFS_USET_DIR; + + return 0; +} + +static int create_committable_groups(struct config_item *parent_item, + struct configfs_fragment *frag) +{ + struct configfs_dirent *sd; + int ret; + + ret = create_pending_group(parent_item, frag); + if (ret) + return ret; + + ret = create_live_group(parent_item, frag); + if (ret) { + detach_groups(to_config_group(parent_item)); + return ret; + } + + /* Disallow creating items directly in the committable group. */ + sd = parent_item->ci_dentry->d_fsdata; + sd->s_type &= ~CONFIGFS_USET_DIR; + + return 0; +} + +static void dentry_mark_dead(struct config_item *item, struct dentry *dentry) +{ + configfs_detach_item(item); + d_inode(dentry)->i_flags |= S_DEAD; + dont_mount(dentry); +} + static int configfs_attach_group(struct config_item *parent_item, struct config_item *item, struct dentry *dentry, @@ -885,11 +1020,15 @@ static int configfs_attach_group(struct config_item *parent_item, inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD); configfs_adjust_dir_dirent_depth_before_populate(sd); ret = populate_groups(to_config_group(item), frag); - if (ret) { - configfs_detach_item(item); - d_inode(dentry)->i_flags |= S_DEAD; - dont_mount(dentry); + if (ret) + dentry_mark_dead(item, dentry); + + if (is_committable_group(item)) { + ret = create_committable_groups(item, frag); + if (ret) + dentry_mark_dead(item, dentry); } + configfs_adjust_dir_dirent_depth_after_populate(sd); inode_unlock(d_inode(dentry)); if (ret) @@ -966,6 +1105,8 @@ static void configfs_dump_one(struct configfs_dirent *sd, int level) type_print(CONFIGFS_USET_DIR); type_print(CONFIGFS_USET_DEFAULT); type_print(CONFIGFS_USET_DROPPING); + type_print(CONFIGFS_GROUP_PENDING); + type_print(CONFIGFS_GROUP_LIVE); #undef type_print } @@ -1456,7 +1597,7 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry) struct config_item *parent_item; struct config_item *item; struct configfs_subsystem *subsys; - struct configfs_dirent *sd; + struct configfs_dirent *sd, *parent_sd; struct configfs_fragment *frag; struct module *subsys_owner = NULL, *dead_item_owner = NULL; int ret; @@ -1475,6 +1616,12 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry) return -EINVAL; } + parent_sd = dentry->d_parent->d_fsdata; + if (parent_sd->s_type & CONFIGFS_GROUP_LIVE) { + config_item_put(parent_item); + return -EPERM; + } + /* configfs_mkdir() shouldn't have allowed this */ BUG_ON(!subsys->su_group.cg_item.ci_type); subsys_owner = subsys->su_group.cg_item.ci_type->ct_owner; @@ -1561,9 +1708,96 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry) return 0; } +static int configfs_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) +{ + struct configfs_dirent *sd, *old_parent_sd, *new_parent_sd; + struct dentry *old_parent_dentry, *new_parent_dentry; + struct dentry *committable_group_dentry; + struct config_item *committable_group_item, *item, *new_parent_item; + struct configfs_subsystem *committable_group_subsys; + struct configfs_group_operations *committable_group_ops; + int ret = 0; + + if (flags) + return -EINVAL; + + old_parent_dentry = old_dentry->d_parent; + new_parent_dentry = new_dentry->d_parent; + + sd = old_dentry->d_fsdata; + old_parent_sd = old_dentry->d_parent->d_fsdata; + new_parent_sd = new_dentry->d_parent->d_fsdata; + + if (!old_parent_sd || !new_parent_sd) + return -EPERM; + + /* + * Renaming must always be between a 'pending' and a 'live' group and + * both need to have the same parent. Changing the directory name is + * not allowed. + */ + if (!((old_parent_sd->s_type & CONFIGFS_GROUP_PENDING) && + (new_parent_sd->s_type & CONFIGFS_GROUP_LIVE)) && + !((old_parent_sd->s_type & CONFIGFS_GROUP_LIVE) && + (new_parent_sd->s_type & CONFIGFS_GROUP_PENDING))) + return -EPERM; + + if (old_parent_dentry->d_parent != new_parent_dentry->d_parent) + return -EPERM; + + if (strcmp(old_dentry->d_name.name, new_dentry->d_name.name)) + return -EPERM; + + committable_group_dentry = old_parent_dentry->d_parent; + /* + * Grab a reference to the committable group for the duration of + * this function. + */ + committable_group_item = + configfs_get_config_item(committable_group_dentry); + committable_group_subsys = + to_config_group(committable_group_item)->cg_subsys; + committable_group_ops = committable_group_item->ci_type->ct_group_ops; + + item = sd->s_element; + new_parent_item = new_parent_sd->s_element; + + if (WARN_ON(!is_committable_group(committable_group_item))) { + /* This would be a result of a programming error in configfs. */ + config_item_put(committable_group_item); + return -EPERM; + } + + mutex_lock(&committable_group_subsys->su_mutex); + spin_lock(&configfs_dirent_lock); + + if ((old_parent_sd->s_type & CONFIGFS_GROUP_PENDING) && + (new_parent_sd->s_type & CONFIGFS_GROUP_LIVE)) + ret = committable_group_ops->commit_item(item); + else + ret = committable_group_ops->uncommit_item(item); + if (ret) + goto out; + + new_dentry->d_fsdata = sd; + list_move(&sd->s_sibling, &new_parent_sd->s_children); + item->ci_parent = new_parent_item; + d_move(old_dentry, new_dentry); + +out: + spin_unlock(&configfs_dirent_lock); + mutex_unlock(&committable_group_subsys->su_mutex); + config_item_put(committable_group_item); + + return ret; +} + const struct inode_operations configfs_dir_inode_operations = { .mkdir = configfs_mkdir, .rmdir = configfs_rmdir, + .rename = configfs_rename, .symlink = configfs_symlink, .unlink = configfs_unlink, .lookup = configfs_lookup, diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 4f76dcc08134..ff6b0e408136 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -219,6 +219,7 @@ struct configfs_group_operations { struct config_item *(*make_item)(struct config_group *group, const char *name); struct config_group *(*make_group)(struct config_group *group, const char *name); int (*commit_item)(struct config_item *item); + int (*uncommit_item)(struct config_item *item); void (*disconnect_notify)(struct config_group *group, struct config_item *item); void (*drop_item)(struct config_group *group, struct config_item *item); }; From patchwork Fri Jan 15 11:13:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1426889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=aS8l0JDC; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHJW407fBz9sRf for ; Fri, 15 Jan 2021 22:15:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727700AbhAOLOp (ORCPT ); Fri, 15 Jan 2021 06:14:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbhAOLOp (ORCPT ); Fri, 15 Jan 2021 06:14:45 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF269C06179C for ; Fri, 15 Jan 2021 03:13:27 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id a12so8838845wrv.8 for ; Fri, 15 Jan 2021 03:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TDB5szcqlcCXwZI0QnUXTFV9ZQzED5fqjVoMB5Cr/nI=; b=aS8l0JDCTL2NZRL+TZeWFzLmqoP4h+BZfb0Y4Dw02SQsZ8B1Tj86PaBCBeQQ4jdv+S V5wX+wyRNbkGiZjmvXmrtzYjbb811gAPssqhKGY5jh8AYkZJCFq4/Av+hQVP1BM+uyQx pnJwhwZJoyH+zeQfDmPOJI0Tux9gv715MLyGS02ARsOTUcTlJ+8n6KARYe4GhcI9ojp4 8EmyWvITl08XM0kV8/ycRm3rhHf56cUIhZUFvLMHqU2zG3wagv3UQhwAdKfnSudrzo8N hsjtScB2DgFGt/0g2tpcLg71bLIwOrgiO7ar/2lB6vDtuHXT/SXJNbZ2i6QKb6B+hDDg GrEw== 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=TDB5szcqlcCXwZI0QnUXTFV9ZQzED5fqjVoMB5Cr/nI=; b=darnZ+0cxXPDyCHOUDSL9m1jDEd60nKS99Z7BP0E1dIEaM1R9APSh6Xc8Cep+R8v8k b+xKJu3B4DKpZ33ZdBkXz5SSTKrfsKWhvX3TOe8EboKBdSdkdtjU/Ub+9WNOqiqSwI8J 4n2+C9k/wE9n4zow73xBzRehzg4ywWAuCqIIY8TPF8/0W2AhIOhVNZyqIbuxlD+2SZDF kOkMKkV3M0n3cXzQilk/Ds1k0HWmtQpWjXYkhOzYqn5w36hvlR/sWOdF3p2UitH05G7q JenpHPI7LRfQf34/b4jfpWXCvcNBV8Rsh5TI8bu/m1Fc0YZ8foxxcAlEmK5BatiR8c5n K6Qw== X-Gm-Message-State: AOAM533ghB/AwVeOTmP6guYGmWXfbGDsbCSKXiD9E8o5n2CrfJbPBcu7 JhI35aCuZ5dR6ix9DcYDsM8aWg== X-Google-Smtp-Source: ABdhPJyu5s7qiByOputlrlfGxuBJ9K3excZDYhzaaOZ32OvpjzHa5dShedfu6+qNOiJSlSSvbF0f4w== X-Received: by 2002:a5d:62c8:: with SMTP id o8mr12846525wrv.51.1610709206500; Fri, 15 Jan 2021 03:13:26 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id l1sm15048822wrq.64.2021.01.15.03.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 03:13:26 -0800 (PST) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, Kent Gibson , Linus Walleij , Andy Shevchenko , linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 4/4] samples: configfs: add a committable group Date: Fri, 15 Jan 2021 12:13:11 +0100 Message-Id: <20210115111311.31601-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210115111311.31601-1-brgl@bgdev.pl> References: <20210115111311.31601-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Add an example of using committable items to configfs samples. Each config item has two attributes: read-write 'storeme' which works similarly to other examples in this file and a read-only 'committed' attribute which changes its value between false and true depending on whether it's committed or not at the moment. Signed-off-by: Bartosz Golaszewski --- samples/configfs/configfs_sample.c | 153 +++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/samples/configfs/configfs_sample.c b/samples/configfs/configfs_sample.c index f9008be7a8a1..9bef74e4369d 100644 --- a/samples/configfs/configfs_sample.c +++ b/samples/configfs/configfs_sample.c @@ -315,6 +315,158 @@ static struct configfs_subsystem group_children_subsys = { /* ----------------------------------------------------------------- */ +/* + * 04-committable-children + * + * This is an example of a committable group. It's similar to the simple + * children example but each config_item has an additional 'committed' + * attribute which is read-only and is only modified when the config_item + * is moved from the 'pending' to the 'live' directory. + */ + +struct committable_child { + struct config_item item; + int storeme; + bool committed; +}; + +static inline struct committable_child * +to_committable_child(struct config_item *item) +{ + return container_of(item, struct committable_child, item); +} + +static ssize_t +committable_child_storeme_show(struct config_item *item, char *page) +{ + return sprintf(page, "%d\n", to_committable_child(item)->storeme); +} + +static ssize_t committable_child_storeme_store(struct config_item *item, + const char *page, size_t count) +{ + struct committable_child *child = to_committable_child(item); + int ret; + + if (child->committed) + return -EPERM; + + ret = kstrtoint(page, 10, &child->storeme); + if (ret) + return ret; + + return count; +} + +CONFIGFS_ATTR(committable_child_, storeme); + +static ssize_t +committable_child_committed_show(struct config_item *item, char *page) +{ + return sprintf(page, "%s\n", + to_committable_child(item)->committed ? "true" : "false"); +} + +CONFIGFS_ATTR_RO(committable_child_, committed); + +static struct configfs_attribute *committable_child_attrs[] = { + &committable_child_attr_storeme, + &committable_child_attr_committed, + NULL, +}; + +static void committable_child_release(struct config_item *item) +{ + kfree(to_committable_child(item)); +} + +static struct configfs_item_operations committable_child_item_ops = { + .release = committable_child_release, +}; + +static const struct config_item_type committable_child_type = { + .ct_item_ops = &committable_child_item_ops, + .ct_attrs = committable_child_attrs, + .ct_owner = THIS_MODULE, +}; + +struct committable_children { + struct config_group group; +}; + +static struct config_item * +committable_children_make_item(struct config_group *group, const char *name) +{ + struct committable_child *child; + + child = kzalloc(sizeof(*child), GFP_KERNEL); + if (!child) + return ERR_PTR(-ENOMEM); + + config_item_init_type_name(&child->item, name, &committable_child_type); + + return &child->item; +} + +static ssize_t +committable_children_description_show(struct config_item *item, char *page) +{ + return sprintf(page, +"[04-committable-children]\n" +"\n" +"This subsystem allows creation of committable config_items. The subsystem\n" +"has two subdirectories: pending and live. New config_items can only be\n" +"created in pending/ and they have one writable and readable attribute as\n" +"well as a single read-only attribute. The latter is only changed once the\n" +"item is 'committed'. This is done by moving the config_item (using\n" +"rename()) to the live/ directory. In this example, the storeme attribute\n" +"becomes 'read-only' once committed.\n"); +} + +CONFIGFS_ATTR_RO(committable_children_, description); + +static struct configfs_attribute *committable_children_attrs[] = { + &committable_children_attr_description, + NULL, +}; + +static int committable_children_commit_item(struct config_item *item) +{ + to_committable_child(item)->committed = true; + + return 0; +} + +static int committable_children_uncommit_item(struct config_item *item) +{ + to_committable_child(item)->committed = false; + + return 0; +} + +static struct configfs_group_operations committable_children_group_ops = { + .make_item = committable_children_make_item, + .commit_item = committable_children_commit_item, + .uncommit_item = committable_children_uncommit_item, +}; + +static const struct config_item_type committable_children_type = { + .ct_group_ops = &committable_children_group_ops, + .ct_attrs = committable_children_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem committable_children_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf = "04-committable-children", + .ci_type = &committable_children_type, + }, + }, +}; + +/* ----------------------------------------------------------------- */ + /* * We're now done with our subsystem definitions. * For convenience in this module, here's a list of them all. It @@ -326,6 +478,7 @@ static struct configfs_subsystem *example_subsys[] = { &childless_subsys.subsys, &simple_children_subsys, &group_children_subsys, + &committable_children_subsys, NULL, };