@@ -55,41 +55,63 @@ static void fill_item_path(struct config_item * item, char * buffer, int length)
5555 }
5656}
5757
58+ static int configfs_get_target_path (struct config_item * item ,
59+ struct config_item * target , char * path )
60+ {
61+ int depth , size ;
62+ char * s ;
63+
64+ depth = item_depth (item );
65+ size = item_path_length (target ) + depth * 3 - 1 ;
66+ if (size > PATH_MAX )
67+ return - ENAMETOOLONG ;
68+
69+ pr_debug ("%s: depth = %d, size = %d\n" , __func__ , depth , size );
70+
71+ for (s = path ; depth -- ; s += 3 )
72+ strcpy (s ,"../" );
73+
74+ fill_item_path (target , path , size );
75+ pr_debug ("%s: path = '%s'\n" , __func__ , path );
76+ return 0 ;
77+ }
78+
5879static int create_link (struct config_item * parent_item ,
5980 struct config_item * item ,
6081 struct dentry * dentry )
6182{
6283 struct configfs_dirent * target_sd = item -> ci_dentry -> d_fsdata ;
63- struct configfs_symlink * sl ;
84+ char * body ;
6485 int ret ;
6586
66- ret = - ENOENT ;
6787 if (!configfs_dirent_is_ready (target_sd ))
68- goto out ;
69- ret = - ENOMEM ;
70- sl = kmalloc (sizeof (struct configfs_symlink ), GFP_KERNEL );
71- if (sl ) {
88+ return - ENOENT ;
89+
90+ body = kzalloc (PAGE_SIZE , GFP_KERNEL );
91+ if (!body )
92+ return - ENOMEM ;
93+
94+ configfs_get (target_sd );
95+ spin_lock (& configfs_dirent_lock );
96+ if (target_sd -> s_type & CONFIGFS_USET_DROPPING ) {
97+ spin_unlock (& configfs_dirent_lock );
98+ configfs_put (target_sd );
99+ kfree (body );
100+ return - ENOENT ;
101+ }
102+ target_sd -> s_links ++ ;
103+ spin_unlock (& configfs_dirent_lock );
104+ ret = configfs_get_target_path (item , item , body );
105+ if (!ret )
106+ ret = configfs_create_link (target_sd , parent_item -> ci_dentry ,
107+ dentry , body );
108+ if (ret ) {
72109 spin_lock (& configfs_dirent_lock );
73- if (target_sd -> s_type & CONFIGFS_USET_DROPPING ) {
74- spin_unlock (& configfs_dirent_lock );
75- kfree (sl );
76- return - ENOENT ;
77- }
78- sl -> sl_target = config_item_get (item );
79- list_add (& sl -> sl_list , & target_sd -> s_links );
110+ target_sd -> s_links -- ;
80111 spin_unlock (& configfs_dirent_lock );
81- ret = configfs_create_link (sl , parent_item -> ci_dentry ,
82- dentry );
83- if (ret ) {
84- spin_lock (& configfs_dirent_lock );
85- list_del_init (& sl -> sl_list );
86- spin_unlock (& configfs_dirent_lock );
87- config_item_put (item );
88- kfree (sl );
89- }
112+ configfs_put (target_sd );
113+ kfree (body );
90114 }
91-
92- out :
93115 return ret ;
94116}
95117
@@ -131,9 +153,8 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symna
131153 * Fake invisibility if dir belongs to a group/default groups hierarchy
132154 * being attached
133155 */
134- ret = - ENOENT ;
135156 if (!configfs_dirent_is_ready (sd ))
136- goto out ;
157+ return - ENOENT ;
137158
138159 parent_item = configfs_get_config_item (dentry -> d_parent );
139160 type = parent_item -> ci_type ;
@@ -193,15 +214,12 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symna
193214
194215out_put :
195216 config_item_put (parent_item );
196-
197- out :
198217 return ret ;
199218}
200219
201220int configfs_unlink (struct inode * dir , struct dentry * dentry )
202221{
203- struct configfs_dirent * sd = dentry -> d_fsdata ;
204- struct configfs_symlink * sl ;
222+ struct configfs_dirent * sd = dentry -> d_fsdata , * target_sd ;
205223 struct config_item * parent_item ;
206224 const struct config_item_type * type ;
207225 int ret ;
@@ -210,7 +228,7 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
210228 if (!(sd -> s_type & CONFIGFS_ITEM_LINK ))
211229 goto out ;
212230
213- sl = sd -> s_element ;
231+ target_sd = sd -> s_element ;
214232
215233 parent_item = configfs_get_config_item (dentry -> d_parent );
216234 type = parent_item -> ci_type ;
@@ -224,21 +242,18 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
224242
225243 /*
226244 * drop_link() must be called before
227- * list_del_init(&sl->sl_list) , so that the order of
245+ * decrementing target's ->s_links , so that the order of
228246 * drop_link(this, target) and drop_item(target) is preserved.
229247 */
230248 if (type && type -> ct_item_ops &&
231249 type -> ct_item_ops -> drop_link )
232250 type -> ct_item_ops -> drop_link (parent_item ,
233- sl -> sl_target );
251+ target_sd -> s_element );
234252
235253 spin_lock (& configfs_dirent_lock );
236- list_del_init ( & sl -> sl_list ) ;
254+ target_sd -> s_links -- ;
237255 spin_unlock (& configfs_dirent_lock );
238-
239- /* Put reference from create_link() */
240- config_item_put (sl -> sl_target );
241- kfree (sl );
256+ configfs_put (target_sd );
242257
243258 config_item_put (parent_item );
244259
@@ -248,79 +263,8 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
248263 return ret ;
249264}
250265
251- static int configfs_get_target_path (struct config_item * item , struct config_item * target ,
252- char * path )
253- {
254- char * s ;
255- int depth , size ;
256-
257- depth = item_depth (item );
258- size = item_path_length (target ) + depth * 3 - 1 ;
259- if (size > PATH_MAX )
260- return - ENAMETOOLONG ;
261-
262- pr_debug ("%s: depth = %d, size = %d\n" , __func__ , depth , size );
263-
264- for (s = path ; depth -- ; s += 3 )
265- strcpy (s ,"../" );
266-
267- fill_item_path (target , path , size );
268- pr_debug ("%s: path = '%s'\n" , __func__ , path );
269-
270- return 0 ;
271- }
272-
273- static int configfs_getlink (struct dentry * dentry , char * path )
274- {
275- struct config_item * item , * target_item ;
276- int error = 0 ;
277-
278- item = configfs_get_config_item (dentry -> d_parent );
279- if (!item )
280- return - EINVAL ;
281-
282- target_item = configfs_get_config_item (dentry );
283- if (!target_item ) {
284- config_item_put (item );
285- return - EINVAL ;
286- }
287-
288- down_read (& configfs_rename_sem );
289- error = configfs_get_target_path (item , target_item , path );
290- up_read (& configfs_rename_sem );
291-
292- config_item_put (item );
293- config_item_put (target_item );
294- return error ;
295-
296- }
297-
298- static const char * configfs_get_link (struct dentry * dentry ,
299- struct inode * inode ,
300- struct delayed_call * done )
301- {
302- char * body ;
303- int error ;
304-
305- if (!dentry )
306- return ERR_PTR (- ECHILD );
307-
308- body = kzalloc (PAGE_SIZE , GFP_KERNEL );
309- if (!body )
310- return ERR_PTR (- ENOMEM );
311-
312- error = configfs_getlink (dentry , body );
313- if (!error ) {
314- set_delayed_call (done , kfree_link , body );
315- return body ;
316- }
317-
318- kfree (body );
319- return ERR_PTR (error );
320- }
321-
322266const struct inode_operations configfs_symlink_inode_operations = {
323- .get_link = configfs_get_link ,
267+ .get_link = simple_get_link ,
324268 .setattr = configfs_setattr ,
325269};
326270
0 commit comments