Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754284AbbDHLak (ORCPT ); Wed, 8 Apr 2015 07:30:40 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:23602 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753804AbbDHL31 (ORCPT ); Wed, 8 Apr 2015 07:29:27 -0400 X-AuditID: cbfee61b-f79536d000000f1f-7e-5525111597c6 From: Krzysztof Opasiak To: balbi@ti.com, gregkh@linuxfoundation.org, jlbec@evilplan.org Cc: andrzej.p@samsung.com, m.szyprowski@samsung.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Krzysztof Opasiak Subject: [PATCH 2/5] fs: configfs: Add unlocked version of configfs_depend_item() Date: Wed, 08 Apr 2015 13:28:45 +0200 Message-id: <1428492528-11993-3-git-send-email-k.opasiak@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1428492528-11993-1-git-send-email-k.opasiak@samsung.com> References: <1428492528-11993-1-git-send-email-k.opasiak@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJLMWRmVeSWpSXmKPExsVy+t9jQV1RQdVQg55FphazXrazWBy8X2/R vHg9m8XJc99YLG5PnMZmsfl7B5vF5V1z2CwWLWtltlh75C67A6fH04tBHvvnrmH36NuyitHj +I3tTB6fN8kFsEZx2aSk5mSWpRbp2yVwZVx6sIy9oF+04tM39wbGt4JdjJwcEgImEjtff2OF sMUkLtxbz9bFyMUhJDCdUeLh4tuMEM4vRonHf7axdDFycLAJ6EvM2yUKYooIOEic2VEEUsIs sI1R4umOGewgg4QFgiVWtu9kA7FZBFQlfm7dwQhi8wq4SmxuOcUI0ishoCAxZ5INSJhTwE3i wd/JYOVCQCXd16ayTWDkXcDIsIpRNLUguaA4KT3XSK84Mbe4NC9dLzk/dxMjOMCeSe9gXNVg cYhRgINRiYdXYLFKqBBrYllxZe4hRgkOZiUR3jNcqqFCvCmJlVWpRfnxRaU5qcWHGKU5WJTE eefoyoUKCaQnlqRmp6YWpBbBZJk4OKUaGFWfsB8UWtvql5fk76X/U+Nbecq9bE1+x/ssfYWr TrPP9M+o9F4ddUt8sdpp1S8pPa4TZL4U8XHeFWbsXLt5a3DIxF6hhgtnp7/NZ75U/f2jW1H8 x8VzrOZOKgxO11L1q2e80B4jJb1u9rm2v+Ez2x8f11jrsdElcMLnnRXKQnePBm0qZvR4qsRS nJFoqMVcVJwIAIw7YBUsAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2870 Lines: 83 Sometimes it might be desirable to prohibit removing a directory in configfs. One example is USB gadget (mass_storage function): when gadget is already bound, if lun directory is removed, the gadget must be thrown away, too. A better solution would be to fail with e.g. -EBUSY. Currently configfs has configfs_depend/undepend_item() methods but they cannot be used in configfs callbacks. This commit adds unlocked version of this methods which can be used only in configfs callbacks. Signed-off-by: Krzysztof Opasiak --- fs/configfs/dir.c | 29 +++++++++++++++++++++++++++++ include/linux/configfs.h | 9 +++++++++ 2 files changed, 38 insertions(+) diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index dee1cb5..ef51594 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -1152,6 +1152,35 @@ void configfs_undepend_item(struct configfs_subsystem *subsys, } EXPORT_SYMBOL(configfs_undepend_item); +int configfs_depend_item_unlocked(struct config_item *target) +{ + struct configfs_dirent *sd; + int ret = -ENOENT; + + spin_lock(&configfs_dirent_lock); + BUG_ON(!target->ci_dentry); + + sd = target->ci_dentry->d_fsdata; + if ((sd->s_type & CONFIGFS_DIR) && + ((sd->s_type & CONFIGFS_USET_DROPPING) || + (sd->s_type & CONFIGFS_USET_CREATING))) + goto out_unlock_dirent_lock; + + sd->s_dependent_count += 1; + ret = 0; + +out_unlock_dirent_lock: + spin_unlock(&configfs_dirent_lock); + return ret; +} +EXPORT_SYMBOL(configfs_depend_item_unlocked); + +void configfs_undepend_item_unlocked(struct config_item *target) +{ + configfs_undepend_item(NULL, target); +} +EXPORT_SYMBOL(configfs_undepend_item_unlocked); + static int configfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) { int ret = 0; diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 34025df..e9dbf01 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -257,4 +257,13 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys); int configfs_depend_item(struct configfs_subsystem *subsys, struct config_item *target); void configfs_undepend_item(struct configfs_subsystem *subsys, struct config_item *target); +/* + * These functions can sleep and can alloc with GFP_KERNEL + * NOTE: These should be called only underneath configfs callbacks. + * WARNING: These cannot be called on newly created item + * (in make_group()/make_item callback) + */ +int configfs_depend_item_unlocked(struct config_item *target); +void configfs_undepend_item_unlocked(struct config_item *target); + #endif /* _CONFIGFS_H_ */ -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/