fs: simplify iget & friends

Merge get_new_inode/get_new_inode_fast into iget5_locked/iget_locked
as those were the only callers. Remove the internal ifind/ifind_fast
helpers - ifind_fast only had a single caller, and ifind had two
callers wanting it to do different things. Also clean up the comments
in this area to focus on information important to a developer trying
to use it, instead of overloading them with implementation details.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by Christoph Hellwig and committed by Al Viro 0b2d0724 0f1b1fd8

+86 -182
+86 -182
fs/inode.c
··· 931 } 932 EXPORT_SYMBOL(unlock_new_inode); 933 934 - /* 935 - * This is called without the inode hash lock held.. Be careful. 936 * 937 - * We no longer cache the sb_flags in i_flags - see fs.h 938 - * -- rmk@arm.uk.linux.org 939 */ 940 - static struct inode *get_new_inode(struct super_block *sb, 941 - struct hlist_head *head, 942 - int (*test)(struct inode *, void *), 943 - int (*set)(struct inode *, void *), 944 - void *data) 945 { 946 struct inode *inode; 947 948 inode = alloc_inode(sb); 949 if (inode) { ··· 1008 destroy_inode(inode); 1009 return NULL; 1010 } 1011 1012 - /* 1013 - * get_new_inode_fast is the fast path version of get_new_inode, see the 1014 - * comment at iget_locked for details. 1015 */ 1016 - static struct inode *get_new_inode_fast(struct super_block *sb, 1017 - struct hlist_head *head, unsigned long ino) 1018 { 1019 struct inode *inode; 1020 1021 inode = alloc_inode(sb); 1022 if (inode) { ··· 1070 } 1071 return inode; 1072 } 1073 1074 /* 1075 * search the inode cache for a matching inode number. ··· 1154 EXPORT_SYMBOL(igrab); 1155 1156 /** 1157 - * ifind - internal function, you want ilookup5() or iget5(). 1158 - * @sb: super block of file system to search 1159 - * @head: the head of the list to search 1160 - * @test: callback used for comparisons between inodes 1161 - * @data: opaque data pointer to pass to @test 1162 - * @wait: if true wait for the inode to be unlocked, if false do not 1163 - * 1164 - * ifind() searches for the inode specified by @data in the inode 1165 - * cache. This is a generalized version of ifind_fast() for file systems where 1166 - * the inode number is not sufficient for unique identification of an inode. 1167 - * 1168 - * If the inode is in the cache, the inode is returned with an incremented 1169 - * reference count. 1170 - * 1171 - * Otherwise NULL is returned. 1172 - * 1173 - * Note, @test is called with the inode_hash_lock held, so can't sleep. 1174 - */ 1175 - static struct inode *ifind(struct super_block *sb, 1176 - struct hlist_head *head, int (*test)(struct inode *, void *), 1177 - void *data, const int wait) 1178 - { 1179 - struct inode *inode; 1180 - 1181 - spin_lock(&inode_hash_lock); 1182 - inode = find_inode(sb, head, test, data); 1183 - if (inode) { 1184 - spin_unlock(&inode_hash_lock); 1185 - if (likely(wait)) 1186 - wait_on_inode(inode); 1187 - return inode; 1188 - } 1189 - spin_unlock(&inode_hash_lock); 1190 - return NULL; 1191 - } 1192 - 1193 - /** 1194 - * ifind_fast - internal function, you want ilookup() or iget(). 1195 - * @sb: super block of file system to search 1196 - * @head: head of the list to search 1197 - * @ino: inode number to search for 1198 - * 1199 - * ifind_fast() searches for the inode @ino in the inode cache. This is for 1200 - * file systems where the inode number is sufficient for unique identification 1201 - * of an inode. 1202 - * 1203 - * If the inode is in the cache, the inode is returned with an incremented 1204 - * reference count. 1205 - * 1206 - * Otherwise NULL is returned. 1207 - */ 1208 - static struct inode *ifind_fast(struct super_block *sb, 1209 - struct hlist_head *head, unsigned long ino) 1210 - { 1211 - struct inode *inode; 1212 - 1213 - spin_lock(&inode_hash_lock); 1214 - inode = find_inode_fast(sb, head, ino); 1215 - if (inode) { 1216 - spin_unlock(&inode_hash_lock); 1217 - wait_on_inode(inode); 1218 - return inode; 1219 - } 1220 - spin_unlock(&inode_hash_lock); 1221 - return NULL; 1222 - } 1223 - 1224 - /** 1225 * ilookup5_nowait - search for an inode in the inode cache 1226 * @sb: super block of file system to search 1227 * @hashval: hash value (usually inode number) to search for 1228 * @test: callback used for comparisons between inodes 1229 * @data: opaque data pointer to pass to @test 1230 * 1231 - * ilookup5() uses ifind() to search for the inode specified by @hashval and 1232 - * @data in the inode cache. This is a generalized version of ilookup() for 1233 - * file systems where the inode number is not sufficient for unique 1234 - * identification of an inode. 1235 - * 1236 * If the inode is in the cache, the inode is returned with an incremented 1237 - * reference count. Note, the inode lock is not waited upon so you have to be 1238 - * very careful what you do with the returned inode. You probably should be 1239 - * using ilookup5() instead. 1240 * 1241 - * Otherwise NULL is returned. 1242 * 1243 - * Note, @test is called with the inode_hash_lock held, so can't sleep. 1244 */ 1245 struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval, 1246 int (*test)(struct inode *, void *), void *data) 1247 { 1248 struct hlist_head *head = inode_hashtable + hash(sb, hashval); 1249 1250 - return ifind(sb, head, test, data, 0); 1251 } 1252 EXPORT_SYMBOL(ilookup5_nowait); 1253 ··· 1190 * @test: callback used for comparisons between inodes 1191 * @data: opaque data pointer to pass to @test 1192 * 1193 - * ilookup5() uses ifind() to search for the inode specified by @hashval and 1194 - * @data in the inode cache. This is a generalized version of ilookup() for 1195 - * file systems where the inode number is not sufficient for unique 1196 - * identification of an inode. 1197 - * 1198 - * If the inode is in the cache, the inode lock is waited upon and the inode is 1199 * returned with an incremented reference count. 1200 * 1201 - * Otherwise NULL is returned. 1202 * 1203 - * Note, @test is called with the inode_hash_lock held, so can't sleep. 1204 */ 1205 struct inode *ilookup5(struct super_block *sb, unsigned long hashval, 1206 int (*test)(struct inode *, void *), void *data) 1207 { 1208 - struct hlist_head *head = inode_hashtable + hash(sb, hashval); 1209 1210 - return ifind(sb, head, test, data, 1); 1211 } 1212 EXPORT_SYMBOL(ilookup5); 1213 ··· 1216 * @sb: super block of file system to search 1217 * @ino: inode number to search for 1218 * 1219 - * ilookup() uses ifind_fast() to search for the inode @ino in the inode cache. 1220 - * This is for file systems where the inode number is sufficient for unique 1221 - * identification of an inode. 1222 - * 1223 - * If the inode is in the cache, the inode is returned with an incremented 1224 - * reference count. 1225 - * 1226 - * Otherwise NULL is returned. 1227 */ 1228 struct inode *ilookup(struct super_block *sb, unsigned long ino) 1229 { 1230 struct hlist_head *head = inode_hashtable + hash(sb, ino); 1231 1232 - return ifind_fast(sb, head, ino); 1233 } 1234 EXPORT_SYMBOL(ilookup); 1235 - 1236 - /** 1237 - * iget5_locked - obtain an inode from a mounted file system 1238 - * @sb: super block of file system 1239 - * @hashval: hash value (usually inode number) to get 1240 - * @test: callback used for comparisons between inodes 1241 - * @set: callback used to initialize a new struct inode 1242 - * @data: opaque data pointer to pass to @test and @set 1243 - * 1244 - * iget5_locked() uses ifind() to search for the inode specified by @hashval 1245 - * and @data in the inode cache and if present it is returned with an increased 1246 - * reference count. This is a generalized version of iget_locked() for file 1247 - * systems where the inode number is not sufficient for unique identification 1248 - * of an inode. 1249 - * 1250 - * If the inode is not in cache, get_new_inode() is called to allocate a new 1251 - * inode and this is returned locked, hashed, and with the I_NEW flag set. The 1252 - * file system gets to fill it in before unlocking it via unlock_new_inode(). 1253 - * 1254 - * Note both @test and @set are called with the inode_hash_lock held, so can't 1255 - * sleep. 1256 - */ 1257 - struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, 1258 - int (*test)(struct inode *, void *), 1259 - int (*set)(struct inode *, void *), void *data) 1260 - { 1261 - struct hlist_head *head = inode_hashtable + hash(sb, hashval); 1262 - struct inode *inode; 1263 - 1264 - inode = ifind(sb, head, test, data, 1); 1265 - if (inode) 1266 - return inode; 1267 - /* 1268 - * get_new_inode() will do the right thing, re-trying the search 1269 - * in case it had to block at any point. 1270 - */ 1271 - return get_new_inode(sb, head, test, set, data); 1272 - } 1273 - EXPORT_SYMBOL(iget5_locked); 1274 - 1275 - /** 1276 - * iget_locked - obtain an inode from a mounted file system 1277 - * @sb: super block of file system 1278 - * @ino: inode number to get 1279 - * 1280 - * iget_locked() uses ifind_fast() to search for the inode specified by @ino in 1281 - * the inode cache and if present it is returned with an increased reference 1282 - * count. This is for file systems where the inode number is sufficient for 1283 - * unique identification of an inode. 1284 - * 1285 - * If the inode is not in cache, get_new_inode_fast() is called to allocate a 1286 - * new inode and this is returned locked, hashed, and with the I_NEW flag set. 1287 - * The file system gets to fill it in before unlocking it via 1288 - * unlock_new_inode(). 1289 - */ 1290 - struct inode *iget_locked(struct super_block *sb, unsigned long ino) 1291 - { 1292 - struct hlist_head *head = inode_hashtable + hash(sb, ino); 1293 - struct inode *inode; 1294 - 1295 - inode = ifind_fast(sb, head, ino); 1296 - if (inode) 1297 - return inode; 1298 - /* 1299 - * get_new_inode_fast() will do the right thing, re-trying the search 1300 - * in case it had to block at any point. 1301 - */ 1302 - return get_new_inode_fast(sb, head, ino); 1303 - } 1304 - EXPORT_SYMBOL(iget_locked); 1305 1306 int insert_inode_locked(struct inode *inode) 1307 {
··· 931 } 932 EXPORT_SYMBOL(unlock_new_inode); 933 934 + /** 935 + * iget5_locked - obtain an inode from a mounted file system 936 + * @sb: super block of file system 937 + * @hashval: hash value (usually inode number) to get 938 + * @test: callback used for comparisons between inodes 939 + * @set: callback used to initialize a new struct inode 940 + * @data: opaque data pointer to pass to @test and @set 941 * 942 + * Search for the inode specified by @hashval and @data in the inode cache, 943 + * and if present it is return it with an increased reference count. This is 944 + * a generalized version of iget_locked() for file systems where the inode 945 + * number is not sufficient for unique identification of an inode. 946 + * 947 + * If the inode is not in cache, allocate a new inode and return it locked, 948 + * hashed, and with the I_NEW flag set. The file system gets to fill it in 949 + * before unlocking it via unlock_new_inode(). 950 + * 951 + * Note both @test and @set are called with the inode_hash_lock held, so can't 952 + * sleep. 953 */ 954 + struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, 955 + int (*test)(struct inode *, void *), 956 + int (*set)(struct inode *, void *), void *data) 957 { 958 + struct hlist_head *head = inode_hashtable + hash(sb, hashval); 959 struct inode *inode; 960 + 961 + spin_lock(&inode_hash_lock); 962 + inode = find_inode(sb, head, test, data); 963 + spin_unlock(&inode_hash_lock); 964 + 965 + if (inode) { 966 + wait_on_inode(inode); 967 + return inode; 968 + } 969 970 inode = alloc_inode(sb); 971 if (inode) { ··· 986 destroy_inode(inode); 987 return NULL; 988 } 989 + EXPORT_SYMBOL(iget5_locked); 990 991 + /** 992 + * iget_locked - obtain an inode from a mounted file system 993 + * @sb: super block of file system 994 + * @ino: inode number to get 995 + * 996 + * Search for the inode specified by @ino in the inode cache and if present 997 + * return it with an increased reference count. This is for file systems 998 + * where the inode number is sufficient for unique identification of an inode. 999 + * 1000 + * If the inode is not in cache, allocate a new inode and return it locked, 1001 + * hashed, and with the I_NEW flag set. The file system gets to fill it in 1002 + * before unlocking it via unlock_new_inode(). 1003 */ 1004 + struct inode *iget_locked(struct super_block *sb, unsigned long ino) 1005 { 1006 + struct hlist_head *head = inode_hashtable + hash(sb, ino); 1007 struct inode *inode; 1008 + 1009 + spin_lock(&inode_hash_lock); 1010 + inode = find_inode_fast(sb, head, ino); 1011 + spin_unlock(&inode_hash_lock); 1012 + if (inode) { 1013 + wait_on_inode(inode); 1014 + return inode; 1015 + } 1016 1017 inode = alloc_inode(sb); 1018 if (inode) { ··· 1030 } 1031 return inode; 1032 } 1033 + EXPORT_SYMBOL(iget_locked); 1034 1035 /* 1036 * search the inode cache for a matching inode number. ··· 1113 EXPORT_SYMBOL(igrab); 1114 1115 /** 1116 * ilookup5_nowait - search for an inode in the inode cache 1117 * @sb: super block of file system to search 1118 * @hashval: hash value (usually inode number) to search for 1119 * @test: callback used for comparisons between inodes 1120 * @data: opaque data pointer to pass to @test 1121 * 1122 + * Search for the inode specified by @hashval and @data in the inode cache. 1123 * If the inode is in the cache, the inode is returned with an incremented 1124 + * reference count. 1125 * 1126 + * Note: I_NEW is not waited upon so you have to be very careful what you do 1127 + * with the returned inode. You probably should be using ilookup5() instead. 1128 * 1129 + * Note: @test is called with the inode_hash_lock held, so can't sleep. 1130 */ 1131 struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval, 1132 int (*test)(struct inode *, void *), void *data) 1133 { 1134 struct hlist_head *head = inode_hashtable + hash(sb, hashval); 1135 + struct inode *inode; 1136 1137 + spin_lock(&inode_hash_lock); 1138 + inode = find_inode(sb, head, test, data); 1139 + spin_unlock(&inode_hash_lock); 1140 + 1141 + return inode; 1142 } 1143 EXPORT_SYMBOL(ilookup5_nowait); 1144 ··· 1217 * @test: callback used for comparisons between inodes 1218 * @data: opaque data pointer to pass to @test 1219 * 1220 + * Search for the inode specified by @hashval and @data in the inode cache, 1221 + * and if the inode is in the cache, return the inode with an incremented 1222 + * reference count. Waits on I_NEW before returning the inode. 1223 * returned with an incremented reference count. 1224 * 1225 + * This is a generalized version of ilookup() for file systems where the 1226 + * inode number is not sufficient for unique identification of an inode. 1227 * 1228 + * Note: @test is called with the inode_hash_lock held, so can't sleep. 1229 */ 1230 struct inode *ilookup5(struct super_block *sb, unsigned long hashval, 1231 int (*test)(struct inode *, void *), void *data) 1232 { 1233 + struct inode *inode = ilookup5_nowait(sb, hashval, test, data); 1234 1235 + if (inode) 1236 + wait_on_inode(inode); 1237 + return inode; 1238 } 1239 EXPORT_SYMBOL(ilookup5); 1240 ··· 1243 * @sb: super block of file system to search 1244 * @ino: inode number to search for 1245 * 1246 + * Search for the inode @ino in the inode cache, and if the inode is in the 1247 + * cache, the inode is returned with an incremented reference count. 1248 */ 1249 struct inode *ilookup(struct super_block *sb, unsigned long ino) 1250 { 1251 struct hlist_head *head = inode_hashtable + hash(sb, ino); 1252 + struct inode *inode; 1253 1254 + spin_lock(&inode_hash_lock); 1255 + inode = find_inode_fast(sb, head, ino); 1256 + spin_unlock(&inode_hash_lock); 1257 + 1258 + if (inode) 1259 + wait_on_inode(inode); 1260 + return inode; 1261 } 1262 EXPORT_SYMBOL(ilookup); 1263 1264 int insert_inode_locked(struct inode *inode) 1265 {