[PATCH] fs: configfs: add allow_drop() to configfs_item_operations

From: Andrzej Pietrasiewicz
Date: Wed Oct 08 2014 - 06:04:56 EST


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().

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
---
fs/configfs/symlink.c | 11 +++++++++--
include/linux/configfs.h | 1 +
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index cc9f254..52851dc 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -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;
}
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index 34025df..29df5e1 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -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);
};

--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/