Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753943AbbDHMHn (ORCPT ); Wed, 8 Apr 2015 08:07:43 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:27565 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753870AbbDHMHj (ORCPT ); Wed, 8 Apr 2015 08:07:39 -0400 X-AuditID: cbfee61b-f79536d000000f1f-9b-55251a094d86 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 v2 1/4] fs: configfs: Add unlocked version of configfs_depend_item() Date: Wed, 08 Apr 2015 14:06:45 +0200 Message-id: <1428494808-12566-2-git-send-email-k.opasiak@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1428494808-12566-1-git-send-email-k.opasiak@samsung.com> References: <1428494808-12566-1-git-send-email-k.opasiak@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFLMWRmVeSWpSXmKPExsVy+t9jAV1OKdVQg4d39C1mvWxnsTh4v96i efF6NouT576xWNyeOI3NYvP3DjaLy7vmsFksWtbKbLH2yF12B06PpxeDPPbPXcPu0bdlFaPH 8RvbmTw+b5ILYI3isklJzcksSy3St0vgyvi2/DtrQb9oxes5z9kbGN8KdjFyckgImEg8vdjK CGGLSVy4t56ti5GLQ0hgEaPEpiVTWCCcX4wS79f9Yepi5OBgE9CXmLdLFMQUEXCQOLOjCKSE WWAbo8TTHTPYQQYJC4RJHGq8ywZiswioSiw9epYZxOYVcJX48mQKK0ivhICCxJxJNiBhTgE3 iYYPE8BuEAIqOf31DdMERt4FjAyrGEVTC5ILipPSc430ihNzi0vz0vWS83M3MYJD7Jn0DsZV DRaHGAU4GJV4eAUWq4QKsSaWFVfmHmKU4GBWEuE9w6UaKsSbklhZlVqUH19UmpNafIhRmoNF SZx3jq5cqJBAemJJanZqakFqEUyWiYNTqoExcPM9hYqfM+azZSj5TVZXPn5UwkNUUJB51jxV W+1paUIaCc5H6l4dK8th3uA6s+s1K1OW2n75TOW9Sik1nw8yTta8rcq3UsOq03O39Ze9zx/t Xb/JKYPJJe4Wd7rQglOfPu7p1Qqb9Hhfu7HMH52/3hz3q1VS16lpM3/aOnNe8NmMXT1XOt4p sRRnJBpqMRcVJwIAEQMj7S0CAAA= 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 cf0db00..7875a5e 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/