aboutsummaryrefslogtreecommitdiffstats
path: root/fs/configfs/symlink.c
diff options
context:
space:
mode:
authorLouis Rilling <louis.rilling@kerlabs.com>2008-06-20 08:09:22 -0400
committerMark Fasheh <mfasheh@suse.com>2008-07-31 19:21:13 -0400
commit9a73d78cda750f12e25eb811878f2d9dbab1bc6e (patch)
treeabdc6537d51ee4faeb41c452428f2bde72abc9c8 /fs/configfs/symlink.c
parent4768e9b18dc63719209c68920d4ae52dc49b6161 (diff)
[PATCH] configfs: Fix failing symlink() making rmdir() fail
On a similar pattern as mkdir() vs rmdir(), a failing symlink() may make rmdir() fail for the symlink's parent and the symlink's target as well. failing symlink() making target's rmdir() fail: process 1: process 2: symlink("A/S" -> "B") allow_link() create_link() attach to "B" links list rmdir("B") detach_prep("B") error because of new link configfs_create_link("A", "S") error (eg -ENOMEM) failing symlink() making parent's rmdir() fail: process 1: process 2: symlink("A/D/S" -> "B") allow_link() create_link() attach to "B" links list configfs_create_link("A/D", "S") make_dirent("A/D", "S") rmdir("A") detach_prep("A") detach_prep("A/D") error because of "S" create("S") error (eg -ENOMEM) We cannot use the same solution as for mkdir() vs rmdir(), since rmdir() on the target cannot wait on the i_mutex of the new symlink's parent without risking a deadlock (with other symlink() or sys_rename()). Instead we define a global mutex protecting all configfs symlinks attachment, so that rmdir() can avoid the races above. Signed-off-by: Louis Rilling <louis.rilling@kerlabs.com> Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/configfs/symlink.c')
-rw-r--r--fs/configfs/symlink.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index c12801a12c3..61a886dbd60 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -31,6 +31,9 @@
31#include <linux/configfs.h> 31#include <linux/configfs.h>
32#include "configfs_internal.h" 32#include "configfs_internal.h"
33 33
34/* Protects attachments of new symlinks */
35DEFINE_MUTEX(configfs_symlink_mutex);
36
34static int item_depth(struct config_item * item) 37static int item_depth(struct config_item * item)
35{ 38{
36 struct config_item * p = item; 39 struct config_item * p = item;
@@ -147,7 +150,9 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symna
147 150
148 ret = type->ct_item_ops->allow_link(parent_item, target_item); 151 ret = type->ct_item_ops->allow_link(parent_item, target_item);
149 if (!ret) { 152 if (!ret) {
153 mutex_lock(&configfs_symlink_mutex);
150 ret = create_link(parent_item, target_item, dentry); 154 ret = create_link(parent_item, target_item, dentry);
155 mutex_unlock(&configfs_symlink_mutex);
151 if (ret && type->ct_item_ops->drop_link) 156 if (ret && type->ct_item_ops->drop_link)
152 type->ct_item_ops->drop_link(parent_item, 157 type->ct_item_ops->drop_link(parent_item,
153 target_item); 158 target_item);