Skip to contentSkip to conversation

fs: configfs: add allow_drop() to configfs_item_operations

PATCH New Andrzej Pietrasiewicz 1 participant 1 message Oct 8, 2014 configfs

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: configfs: add allow_drop() to configfs_item_operations

Sometimes it might be desirable to prohibit removing a symbolic link in configfs. One example is USB gadget: when a gadget is already bound, if USB function symlink (used to associate USB functions with USB configurations) is removed, the gadget must be thrown away, too. A better solution would be to fail with e.g. -EBUSY.

Why add a new method? Even though (*drop_link)() does have a return value, it is ignored in fs/configfs/symlink.c:configfs_unlink(). It could be tempting to just check the return value, but some users of configfs might already depend on the fact that (*drop_link)() is called _after_ corresponding filesystem entities are torn down. In other words, the semantics of (*drop_link)() is "the final, unconditional cleanup". In order not to break this semantics, a new method is added and its value is checked in fs/configfs/symlink.c:configfs_unlink().

---
 fs/configfs/symlink.c    | 11 +++++++++--
 include/linux/configfs.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)
fs/configfs/symlink.c +9 -2
index cc9f254..52851dc 100644
@@ -198,6 +198,13 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
 
 	parent_item = configfs_get_config_item(dentry->d_parent);
 	type = parent_item->ci_type;
+	if (type && type->ct_item_ops &&
+	    type->ct_item_ops->allow_drop) {
+		ret = type->ct_item_ops->allow_drop(parent_item,
+							sl->sl_target);
+		if (ret)
+			goto out_put;
+	}
 
 	spin_lock(&configfs_dirent_lock);
 	list_del_init(&sd->s_sibling);
@@ -224,10 +231,10 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
 	config_item_put(sl->sl_target);
 	kfree(sl);
 
-	config_item_put(parent_item);
-
 	ret = 0;
 
+out_put:
+	config_item_put(parent_item);
 out:
 	return ret;
 }
include/linux/configfs.h +1 -0
index 34025df..29df5e1 100644
@@ -226,6 +226,7 @@ struct configfs_item_operations {
 	ssize_t	(*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
 	ssize_t	(*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
 	int (*allow_link)(struct config_item *src, struct config_item *target);
+	int (*allow_drop)(struct config_item *src, struct config_item *target);
 	int (*drop_link)(struct config_item *src, struct config_item *target);
 };
 
Signature · 1 line
1.9.1