@@ -28,14 +28,18 @@ static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid)
28
28
/**
29
29
* v9fs_fid_add - add a fid to a dentry
30
30
* @dentry: dentry that the fid is being added to
31
- * @fid : fid to add
31
+ * @pfid : fid to add, NULLed out
32
32
*
33
33
*/
34
- void v9fs_fid_add (struct dentry * dentry , struct p9_fid * fid )
34
+ void v9fs_fid_add (struct dentry * dentry , struct p9_fid * * pfid )
35
35
{
36
+ struct p9_fid * fid = * pfid ;
37
+
36
38
spin_lock (& dentry -> d_lock );
37
39
__add_fid (dentry , fid );
38
40
spin_unlock (& dentry -> d_lock );
41
+
42
+ * pfid = NULL ;
39
43
}
40
44
41
45
/**
@@ -56,7 +60,7 @@ static struct p9_fid *v9fs_fid_find_inode(struct inode *inode, kuid_t uid)
56
60
h = (struct hlist_head * )& inode -> i_private ;
57
61
hlist_for_each_entry (fid , h , ilist ) {
58
62
if (uid_eq (fid -> uid , uid )) {
59
- refcount_inc ( & fid -> count );
63
+ p9_fid_get ( fid );
60
64
ret = fid ;
61
65
break ;
62
66
}
@@ -68,15 +72,19 @@ static struct p9_fid *v9fs_fid_find_inode(struct inode *inode, kuid_t uid)
68
72
/**
69
73
* v9fs_open_fid_add - add an open fid to an inode
70
74
* @inode: inode that the fid is being added to
71
- * @fid : fid to add
75
+ * @pfid : fid to add, NULLed out
72
76
*
73
77
*/
74
78
75
- void v9fs_open_fid_add (struct inode * inode , struct p9_fid * fid )
79
+ void v9fs_open_fid_add (struct inode * inode , struct p9_fid * * pfid )
76
80
{
81
+ struct p9_fid * fid = * pfid ;
82
+
77
83
spin_lock (& inode -> i_lock );
78
84
hlist_add_head (& fid -> ilist , (struct hlist_head * )& inode -> i_private );
79
85
spin_unlock (& inode -> i_lock );
86
+
87
+ * pfid = NULL ;
80
88
}
81
89
82
90
@@ -104,7 +112,7 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
104
112
hlist_for_each_entry (fid , h , dlist ) {
105
113
if (any || uid_eq (fid -> uid , uid )) {
106
114
ret = fid ;
107
- refcount_inc ( & ret -> count );
115
+ p9_fid_get ( ret );
108
116
break ;
109
117
}
110
118
}
@@ -150,9 +158,9 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
150
158
{
151
159
struct dentry * ds ;
152
160
const unsigned char * * wnames , * uname ;
153
- int i , n , l , clone , access ;
161
+ int i , n , l , access ;
154
162
struct v9fs_session_info * v9ses ;
155
- struct p9_fid * fid , * old_fid ;
163
+ struct p9_fid * fid , * root_fid , * old_fid ;
156
164
157
165
v9ses = v9fs_dentry2v9ses (dentry );
158
166
access = v9ses -> flags & V9FS_ACCESS_MASK ;
@@ -169,17 +177,17 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
169
177
fid = v9fs_fid_find (ds , uid , any );
170
178
if (fid ) {
171
179
/* Found the parent fid do a lookup with that */
172
- struct p9_fid * ofid = fid ;
180
+ old_fid = fid ;
173
181
174
- fid = p9_client_walk (ofid , 1 , & dentry -> d_name .name , 1 );
175
- p9_client_clunk ( ofid );
182
+ fid = p9_client_walk (old_fid , 1 , & dentry -> d_name .name , 1 );
183
+ p9_fid_put ( old_fid );
176
184
goto fid_out ;
177
185
}
178
186
up_read (& v9ses -> rename_sem );
179
187
180
188
/* start from the root and try to do a lookup */
181
- fid = v9fs_fid_find (dentry -> d_sb -> s_root , uid , any );
182
- if (!fid ) {
189
+ root_fid = v9fs_fid_find (dentry -> d_sb -> s_root , uid , any );
190
+ if (!root_fid ) {
183
191
/* the user is not attached to the fs yet */
184
192
if (access == V9FS_ACCESS_SINGLE )
185
193
return ERR_PTR (- EPERM );
@@ -194,12 +202,13 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
194
202
if (IS_ERR (fid ))
195
203
return fid ;
196
204
197
- refcount_inc ( & fid -> count );
198
- v9fs_fid_add (dentry -> d_sb -> s_root , fid );
205
+ root_fid = p9_fid_get ( fid );
206
+ v9fs_fid_add (dentry -> d_sb -> s_root , & fid );
199
207
}
200
208
/* If we are root ourself just return that */
201
209
if (dentry -> d_sb -> s_root == dentry )
202
- return fid ;
210
+ return root_fid ;
211
+
203
212
/*
204
213
* Do a multipath walk with attached root.
205
214
* When walking parent we need to make sure we
@@ -211,39 +220,39 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
211
220
fid = ERR_PTR (n );
212
221
goto err_out ;
213
222
}
214
- old_fid = fid ;
215
- clone = 1 ;
223
+ fid = root_fid ;
224
+ old_fid = root_fid ;
216
225
i = 0 ;
217
226
while (i < n ) {
218
227
l = min (n - i , P9_MAXWELEM );
219
228
/*
220
229
* We need to hold rename lock when doing a multipath
221
- * walk to ensure none of the patch component change
230
+ * walk to ensure none of the path components change
222
231
*/
223
- fid = p9_client_walk (fid , l , & wnames [i ], clone );
232
+ fid = p9_client_walk (old_fid , l , & wnames [i ],
233
+ old_fid == root_fid /* clone */ );
224
234
/* non-cloning walk will return the same fid */
225
235
if (fid != old_fid ) {
226
- p9_client_clunk (old_fid );
236
+ p9_fid_put (old_fid );
227
237
old_fid = fid ;
228
238
}
229
239
if (IS_ERR (fid )) {
230
240
kfree (wnames );
231
241
goto err_out ;
232
242
}
233
243
i += l ;
234
- clone = 0 ;
235
244
}
236
245
kfree (wnames );
237
246
fid_out :
238
247
if (!IS_ERR (fid )) {
239
248
spin_lock (& dentry -> d_lock );
240
249
if (d_unhashed (dentry )) {
241
250
spin_unlock (& dentry -> d_lock );
242
- p9_client_clunk (fid );
251
+ p9_fid_put (fid );
243
252
fid = ERR_PTR (- ENOENT );
244
253
} else {
245
254
__add_fid (dentry , fid );
246
- refcount_inc ( & fid -> count );
255
+ p9_fid_get ( fid );
247
256
spin_unlock (& dentry -> d_lock );
248
257
}
249
258
}
@@ -300,7 +309,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)
300
309
fid = clone_fid (ofid );
301
310
if (IS_ERR (fid ))
302
311
goto error_out ;
303
- p9_client_clunk (ofid );
312
+ p9_fid_put (ofid );
304
313
/*
305
314
* writeback fid will only be used to write back the
306
315
* dirty pages. We always request for the open fid in read-write
@@ -309,7 +318,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)
309
318
*/
310
319
err = p9_client_open (fid , O_RDWR );
311
320
if (err < 0 ) {
312
- p9_client_clunk (fid );
321
+ p9_fid_put (fid );
313
322
fid = ERR_PTR (err );
314
323
goto error_out ;
315
324
}
0 commit comments