Commit b6520c81934848cef126d93951f7ce242e0f656d
Committed by
Al Viro
1 parent
2b1c6bd77d
Exists in
master
and in
7 other branches
cleanup d_add_ci
Make sure that comments describe what's going on and not how, and always use __d_instantiate instead of two separate branches, one with d_instantiate and one with __d_instantiate. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 1 changed file with 18 additions and 30 deletions Side-by-side Diff
fs/dcache.c
... | ... | @@ -1247,15 +1247,18 @@ |
1247 | 1247 | struct dentry *found; |
1248 | 1248 | struct dentry *new; |
1249 | 1249 | |
1250 | - /* Does a dentry matching the name exist already? */ | |
1250 | + /* | |
1251 | + * First check if a dentry matching the name already exists, | |
1252 | + * if not go ahead and create it now. | |
1253 | + */ | |
1251 | 1254 | found = d_hash_and_lookup(dentry->d_parent, name); |
1252 | - /* If not, create it now and return */ | |
1253 | 1255 | if (!found) { |
1254 | 1256 | new = d_alloc(dentry->d_parent, name); |
1255 | 1257 | if (!new) { |
1256 | 1258 | error = -ENOMEM; |
1257 | 1259 | goto err_out; |
1258 | 1260 | } |
1261 | + | |
1259 | 1262 | found = d_splice_alias(inode, new); |
1260 | 1263 | if (found) { |
1261 | 1264 | dput(new); |
1262 | 1265 | |
1263 | 1266 | |
1264 | 1267 | |
1265 | 1268 | |
1266 | 1269 | |
1267 | 1270 | |
1268 | 1271 | |
1269 | 1272 | |
1270 | 1273 | |
1271 | 1274 | |
1272 | 1275 | |
1273 | 1276 | |
... | ... | @@ -1263,61 +1266,46 @@ |
1263 | 1266 | } |
1264 | 1267 | return new; |
1265 | 1268 | } |
1266 | - /* Matching dentry exists, check if it is negative. */ | |
1269 | + | |
1270 | + /* | |
1271 | + * If a matching dentry exists, and it's not negative use it. | |
1272 | + * | |
1273 | + * Decrement the reference count to balance the iget() done | |
1274 | + * earlier on. | |
1275 | + */ | |
1267 | 1276 | if (found->d_inode) { |
1268 | 1277 | if (unlikely(found->d_inode != inode)) { |
1269 | 1278 | /* This can't happen because bad inodes are unhashed. */ |
1270 | 1279 | BUG_ON(!is_bad_inode(inode)); |
1271 | 1280 | BUG_ON(!is_bad_inode(found->d_inode)); |
1272 | 1281 | } |
1273 | - /* | |
1274 | - * Already have the inode and the dentry attached, decrement | |
1275 | - * the reference count to balance the iget() done | |
1276 | - * earlier on. We found the dentry using d_lookup() so it | |
1277 | - * cannot be disconnected and thus we do not need to worry | |
1278 | - * about any NFS/disconnectedness issues here. | |
1279 | - */ | |
1280 | 1282 | iput(inode); |
1281 | 1283 | return found; |
1282 | 1284 | } |
1285 | + | |
1283 | 1286 | /* |
1284 | 1287 | * Negative dentry: instantiate it unless the inode is a directory and |
1285 | - * has a 'disconnected' dentry (i.e. IS_ROOT and DCACHE_DISCONNECTED), | |
1286 | - * in which case d_move() that in place of the found dentry. | |
1288 | + * already has a dentry. | |
1287 | 1289 | */ |
1288 | - if (!S_ISDIR(inode->i_mode)) { | |
1289 | - /* Not a directory; everything is easy. */ | |
1290 | - d_instantiate(found, inode); | |
1291 | - return found; | |
1292 | - } | |
1293 | 1290 | spin_lock(&dcache_lock); |
1294 | - if (list_empty(&inode->i_dentry)) { | |
1295 | - /* | |
1296 | - * Directory without a 'disconnected' dentry; we need to do | |
1297 | - * d_instantiate() by hand because it takes dcache_lock which | |
1298 | - * we already hold. | |
1299 | - */ | |
1291 | + if (!S_ISDIR(inode->i_mode) || list_empty(&inode->i_dentry)) { | |
1300 | 1292 | __d_instantiate(found, inode); |
1301 | 1293 | spin_unlock(&dcache_lock); |
1302 | 1294 | security_d_instantiate(found, inode); |
1303 | 1295 | return found; |
1304 | 1296 | } |
1297 | + | |
1305 | 1298 | /* |
1306 | - * Directory with a 'disconnected' dentry; get a reference to the | |
1307 | - * 'disconnected' dentry. | |
1299 | + * In case a directory already has a (disconnected) entry grab a | |
1300 | + * reference to it, move it in place and use it. | |
1308 | 1301 | */ |
1309 | 1302 | new = list_entry(inode->i_dentry.next, struct dentry, d_alias); |
1310 | 1303 | dget_locked(new); |
1311 | 1304 | spin_unlock(&dcache_lock); |
1312 | - /* Do security vodoo. */ | |
1313 | 1305 | security_d_instantiate(found, inode); |
1314 | - /* Move new in place of found. */ | |
1315 | 1306 | d_move(new, found); |
1316 | - /* Balance the iget() we did above. */ | |
1317 | 1307 | iput(inode); |
1318 | - /* Throw away found. */ | |
1319 | 1308 | dput(found); |
1320 | - /* Use new as the actual dentry. */ | |
1321 | 1309 | return new; |
1322 | 1310 | |
1323 | 1311 | err_out: |