Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756114AbbDIQSu (ORCPT ); Thu, 9 Apr 2015 12:18:50 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:60551 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753196AbbDIQSo (ORCPT ); Thu, 9 Apr 2015 12:18:44 -0400 X-AuditID: cbfee61a-f79516d000006302-2f-5526a66278ed 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 v3 1/4] fs: configfs: Add unlocked version of configfs_depend_item() Date: Thu, 09 Apr 2015 18:18:07 +0200 Message-id: <1428596290-23637-2-git-send-email-k.opasiak@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1428596290-23637-1-git-send-email-k.opasiak@samsung.com> References: <1428596290-23637-1-git-send-email-k.opasiak@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJLMWRmVeSWpSXmKPExsVy+t9jAd2kZWqhBvOX2FjMetnOYnHwfr1F 8+L1bBYnz31jsbg9cRqbxebvHWwWl3fNYbNYtKyV2WLtkbvsDpweTy8Geeyfu4bdo2/LKkaP 4ze2M3l83iQXwBrFZZOSmpNZllqkb5fAlfFt+XfWgn7RitdznrM3ML4V7GLk5JAQMJHoOH6E DcIWk7hwbz2QzcUhJLCIUWLv709Qzi9Gied7XjB3MXJwsAnoS8zbJQpiigg4SJzZUQRSwiyw jVHi6Y4Z7CCDhAXCJOY2HWAFsVkEVCXeT2tkAbF5BVyB6ieyg/RKCChIzJlkA2JyCrhJ9PVI g1QIAVXsOPaMcQIj7wJGhlWMoqkFyQXFSem5hnrFibnFpXnpesn5uZsYwQH2TGoH48oGi0OM AhyMSjy8L76phgqxJpYVV+YeYpTgYFYS4f24UC1UiDclsbIqtSg/vqg0J7X4EKM0B4uSOO8c XblQIYH0xJLU7NTUgtQimCwTB6dUA6Nki46XTV94Y8eh94ILLBkrY5T89me2OAf+vu20+ENH Z19I4JoNO9kuxtjXm8VrTfn47l2pRnnG3UvKQdEcf3p3njT0fdR/RtL2T+J6me51Nw5NYNM8 Yiv4PkVS433xvlLp8h0Gyu+Ysn+wzcywj4irDC3XTg66usDYm1E2y696Qrlqnuw+JZbijERD Leai4kQAGoE+ASwCAAA= 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/