aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2011-03-23 15:03:28 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2011-03-24 21:17:52 -0400
commit0b2d0724e26a335cd326eb7ad552c109116a8795 (patch)
treefabd651e35f3fbc60d4ca9ca7fbdad0a04596d43
parent0f1b1fd86f6fd662e04da3e82a6780b226fcd0d1 (diff)
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>
-rw-r--r--fs/inode.c262
1 files changed, 83 insertions, 179 deletions
diff --git a/fs/inode.c b/fs/inode.c
index f9ee4928358f..05a1f75ae791 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -931,20 +931,42 @@ void unlock_new_inode(struct inode *inode)
931} 931}
932EXPORT_SYMBOL(unlock_new_inode); 932EXPORT_SYMBOL(unlock_new_inode);
933 933
934/* 934/**
935 * This is called without the inode hash lock held.. Be careful. 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().
936 * 950 *
937 * We no longer cache the sb_flags in i_flags - see fs.h 951 * Note both @test and @set are called with the inode_hash_lock held, so can't
938 * -- rmk@arm.uk.linux.org 952 * sleep.
939 */ 953 */
940static struct inode *get_new_inode(struct super_block *sb, 954struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
941 struct hlist_head *head, 955 int (*test)(struct inode *, void *),
942 int (*test)(struct inode *, void *), 956 int (*set)(struct inode *, void *), void *data)
943 int (*set)(struct inode *, void *),
944 void *data)
945{ 957{
958 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
946 struct inode *inode; 959 struct inode *inode;
947 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
948 inode = alloc_inode(sb); 970 inode = alloc_inode(sb);
949 if (inode) { 971 if (inode) {
950 struct inode *old; 972 struct inode *old;
@@ -986,16 +1008,34 @@ set_failed:
986 destroy_inode(inode); 1008 destroy_inode(inode);
987 return NULL; 1009 return NULL;
988} 1010}
1011EXPORT_SYMBOL(iget5_locked);
989 1012
990/* 1013/**
991 * get_new_inode_fast is the fast path version of get_new_inode, see the 1014 * iget_locked - obtain an inode from a mounted file system
992 * comment at iget_locked for details. 1015 * @sb: super block of file system
1016 * @ino: inode number to get
1017 *
1018 * Search for the inode specified by @ino in the inode cache and if present
1019 * return it with an increased reference count. This is for file systems
1020 * where the inode number is sufficient for unique identification of an inode.
1021 *
1022 * If the inode is not in cache, allocate a new inode and return it locked,
1023 * hashed, and with the I_NEW flag set. The file system gets to fill it in
1024 * before unlocking it via unlock_new_inode().
993 */ 1025 */
994static struct inode *get_new_inode_fast(struct super_block *sb, 1026struct inode *iget_locked(struct super_block *sb, unsigned long ino)
995 struct hlist_head *head, unsigned long ino)
996{ 1027{
1028 struct hlist_head *head = inode_hashtable + hash(sb, ino);
997 struct inode *inode; 1029 struct inode *inode;
998 1030
1031 spin_lock(&inode_hash_lock);
1032 inode = find_inode_fast(sb, head, ino);
1033 spin_unlock(&inode_hash_lock);
1034 if (inode) {
1035 wait_on_inode(inode);
1036 return inode;
1037 }
1038
999 inode = alloc_inode(sb); 1039 inode = alloc_inode(sb);
1000 if (inode) { 1040 if (inode) {
1001 struct inode *old; 1041 struct inode *old;
@@ -1030,6 +1070,7 @@ static struct inode *get_new_inode_fast(struct super_block *sb,
1030 } 1070 }
1031 return inode; 1071 return inode;
1032} 1072}
1073EXPORT_SYMBOL(iget_locked);
1033 1074
1034/* 1075/*
1035 * search the inode cache for a matching inode number. 1076 * search the inode cache for a matching inode number.
@@ -1113,100 +1154,32 @@ struct inode *igrab(struct inode *inode)
1113EXPORT_SYMBOL(igrab); 1154EXPORT_SYMBOL(igrab);
1114 1155
1115/** 1156/**
1116 * ifind - internal function, you want ilookup5() or iget5(). 1157 * ilookup5_nowait - search for an inode in the inode cache
1117 * @sb: super block of file system to search 1158 * @sb: super block of file system to search
1118 * @head: the head of the list to search 1159 * @hashval: hash value (usually inode number) to search for
1119 * @test: callback used for comparisons between inodes 1160 * @test: callback used for comparisons between inodes
1120 * @data: opaque data pointer to pass to @test 1161 * @data: opaque data pointer to pass to @test
1121 * @wait: if true wait for the inode to be unlocked, if false do not
1122 *
1123 * ifind() searches for the inode specified by @data in the inode
1124 * cache. This is a generalized version of ifind_fast() for file systems where
1125 * the inode number is not sufficient for unique identification of an inode.
1126 * 1162 *
1163 * Search for the inode specified by @hashval and @data in the inode cache.
1127 * If the inode is in the cache, the inode is returned with an incremented 1164 * If the inode is in the cache, the inode is returned with an incremented
1128 * reference count. 1165 * reference count.
1129 * 1166 *
1130 * Otherwise NULL is returned. 1167 * Note: I_NEW is not waited upon so you have to be very careful what you do
1168 * with the returned inode. You probably should be using ilookup5() instead.
1131 * 1169 *
1132 * Note, @test is called with the inode_hash_lock held, so can't sleep. 1170 * Note: @test is called with the inode_hash_lock held, so can't sleep.
1133 */ 1171 */
1134static struct inode *ifind(struct super_block *sb, 1172struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
1135 struct hlist_head *head, int (*test)(struct inode *, void *), 1173 int (*test)(struct inode *, void *), void *data)
1136 void *data, const int wait)
1137{ 1174{
1175 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
1138 struct inode *inode; 1176 struct inode *inode;
1139 1177
1140 spin_lock(&inode_hash_lock); 1178 spin_lock(&inode_hash_lock);
1141 inode = find_inode(sb, head, test, data); 1179 inode = find_inode(sb, head, test, data);
1142 if (inode) {
1143 spin_unlock(&inode_hash_lock);
1144 if (likely(wait))
1145 wait_on_inode(inode);
1146 return inode;
1147 }
1148 spin_unlock(&inode_hash_lock);
1149 return NULL;
1150}
1151
1152/**
1153 * ifind_fast - internal function, you want ilookup() or iget().
1154 * @sb: super block of file system to search
1155 * @head: head of the list to search
1156 * @ino: inode number to search for
1157 *
1158 * ifind_fast() searches for the inode @ino in the inode cache. This is for
1159 * file systems where the inode number is sufficient for unique identification
1160 * of an inode.
1161 *
1162 * If the inode is in the cache, the inode is returned with an incremented
1163 * reference count.
1164 *
1165 * Otherwise NULL is returned.
1166 */
1167static struct inode *ifind_fast(struct super_block *sb,
1168 struct hlist_head *head, unsigned long ino)
1169{
1170 struct inode *inode;
1171
1172 spin_lock(&inode_hash_lock);
1173 inode = find_inode_fast(sb, head, ino);
1174 if (inode) {
1175 spin_unlock(&inode_hash_lock);
1176 wait_on_inode(inode);
1177 return inode;
1178 }
1179 spin_unlock(&inode_hash_lock); 1180 spin_unlock(&inode_hash_lock);
1180 return NULL;
1181}
1182
1183/**
1184 * ilookup5_nowait - search for an inode in the inode cache
1185 * @sb: super block of file system to search
1186 * @hashval: hash value (usually inode number) to search for
1187 * @test: callback used for comparisons between inodes
1188 * @data: opaque data pointer to pass to @test
1189 *
1190 * ilookup5() uses ifind() to search for the inode specified by @hashval and
1191 * @data in the inode cache. This is a generalized version of ilookup() for
1192 * file systems where the inode number is not sufficient for unique
1193 * identification of an inode.
1194 *
1195 * If the inode is in the cache, the inode is returned with an incremented
1196 * reference count. Note, the inode lock is not waited upon so you have to be
1197 * very careful what you do with the returned inode. You probably should be
1198 * using ilookup5() instead.
1199 *
1200 * Otherwise NULL is returned.
1201 *
1202 * Note, @test is called with the inode_hash_lock held, so can't sleep.
1203 */
1204struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
1205 int (*test)(struct inode *, void *), void *data)
1206{
1207 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
1208 1181
1209 return ifind(sb, head, test, data, 0); 1182 return inode;
1210} 1183}
1211EXPORT_SYMBOL(ilookup5_nowait); 1184EXPORT_SYMBOL(ilookup5_nowait);
1212 1185
@@ -1217,24 +1190,24 @@ EXPORT_SYMBOL(ilookup5_nowait);
1217 * @test: callback used for comparisons between inodes 1190 * @test: callback used for comparisons between inodes
1218 * @data: opaque data pointer to pass to @test 1191 * @data: opaque data pointer to pass to @test
1219 * 1192 *
1220 * ilookup5() uses ifind() to search for the inode specified by @hashval and 1193 * Search for the inode specified by @hashval and @data in the inode cache,
1221 * @data in the inode cache. This is a generalized version of ilookup() for 1194 * and if the inode is in the cache, return the inode with an incremented
1222 * file systems where the inode number is not sufficient for unique 1195 * reference count. Waits on I_NEW before returning the inode.
1223 * identification of an inode.
1224 *
1225 * If the inode is in the cache, the inode lock is waited upon and the inode is
1226 * returned with an incremented reference count. 1196 * returned with an incremented reference count.
1227 * 1197 *
1228 * Otherwise NULL is returned. 1198 * This is a generalized version of ilookup() for file systems where the
1199 * inode number is not sufficient for unique identification of an inode.
1229 * 1200 *
1230 * Note, @test is called with the inode_hash_lock held, so can't sleep. 1201 * Note: @test is called with the inode_hash_lock held, so can't sleep.
1231 */ 1202 */
1232struct inode *ilookup5(struct super_block *sb, unsigned long hashval, 1203struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
1233 int (*test)(struct inode *, void *), void *data) 1204 int (*test)(struct inode *, void *), void *data)
1234{ 1205{
1235 struct hlist_head *head = inode_hashtable + hash(sb, hashval); 1206 struct inode *inode = ilookup5_nowait(sb, hashval, test, data);
1236 1207
1237 return ifind(sb, head, test, data, 1); 1208 if (inode)
1209 wait_on_inode(inode);
1210 return inode;
1238} 1211}
1239EXPORT_SYMBOL(ilookup5); 1212EXPORT_SYMBOL(ilookup5);
1240 1213
@@ -1243,92 +1216,23 @@ EXPORT_SYMBOL(ilookup5);
1243 * @sb: super block of file system to search 1216 * @sb: super block of file system to search
1244 * @ino: inode number to search for 1217 * @ino: inode number to search for
1245 * 1218 *
1246 * ilookup() uses ifind_fast() to search for the inode @ino in the inode cache. 1219 * Search for the inode @ino in the inode cache, and if the inode is in the
1247 * This is for file systems where the inode number is sufficient for unique 1220 * cache, the inode is returned with an incremented reference count.
1248 * identification of an inode.
1249 *
1250 * If the inode is in the cache, the inode is returned with an incremented
1251 * reference count.
1252 *
1253 * Otherwise NULL is returned.
1254 */ 1221 */
1255struct inode *ilookup(struct super_block *sb, unsigned long ino) 1222struct inode *ilookup(struct super_block *sb, unsigned long ino)
1256{ 1223{
1257 struct hlist_head *head = inode_hashtable + hash(sb, ino); 1224 struct hlist_head *head = inode_hashtable + hash(sb, ino);
1258
1259 return ifind_fast(sb, head, ino);
1260}
1261EXPORT_SYMBOL(ilookup);
1262
1263/**
1264 * iget5_locked - obtain an inode from a mounted file system
1265 * @sb: super block of file system
1266 * @hashval: hash value (usually inode number) to get
1267 * @test: callback used for comparisons between inodes
1268 * @set: callback used to initialize a new struct inode
1269 * @data: opaque data pointer to pass to @test and @set
1270 *
1271 * iget5_locked() uses ifind() to search for the inode specified by @hashval
1272 * and @data in the inode cache and if present it is returned with an increased
1273 * reference count. This is a generalized version of iget_locked() for file
1274 * systems where the inode number is not sufficient for unique identification
1275 * of an inode.
1276 *
1277 * If the inode is not in cache, get_new_inode() is called to allocate a new
1278 * inode and this is returned locked, hashed, and with the I_NEW flag set. The
1279 * file system gets to fill it in before unlocking it via unlock_new_inode().
1280 *
1281 * Note both @test and @set are called with the inode_hash_lock held, so can't
1282 * sleep.
1283 */
1284struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
1285 int (*test)(struct inode *, void *),
1286 int (*set)(struct inode *, void *), void *data)
1287{
1288 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
1289 struct inode *inode; 1225 struct inode *inode;
1290 1226
1291 inode = ifind(sb, head, test, data, 1); 1227 spin_lock(&inode_hash_lock);
1292 if (inode) 1228 inode = find_inode_fast(sb, head, ino);
1293 return inode; 1229 spin_unlock(&inode_hash_lock);
1294 /*
1295 * get_new_inode() will do the right thing, re-trying the search
1296 * in case it had to block at any point.
1297 */
1298 return get_new_inode(sb, head, test, set, data);
1299}
1300EXPORT_SYMBOL(iget5_locked);
1301
1302/**
1303 * iget_locked - obtain an inode from a mounted file system
1304 * @sb: super block of file system
1305 * @ino: inode number to get
1306 *
1307 * iget_locked() uses ifind_fast() to search for the inode specified by @ino in
1308 * the inode cache and if present it is returned with an increased reference
1309 * count. This is for file systems where the inode number is sufficient for
1310 * unique identification of an inode.
1311 *
1312 * If the inode is not in cache, get_new_inode_fast() is called to allocate a
1313 * new inode and this is returned locked, hashed, and with the I_NEW flag set.
1314 * The file system gets to fill it in before unlocking it via
1315 * unlock_new_inode().
1316 */
1317struct inode *iget_locked(struct super_block *sb, unsigned long ino)
1318{
1319 struct hlist_head *head = inode_hashtable + hash(sb, ino);
1320 struct inode *inode;
1321 1230
1322 inode = ifind_fast(sb, head, ino);
1323 if (inode) 1231 if (inode)
1324 return inode; 1232 wait_on_inode(inode);
1325 /* 1233 return inode;
1326 * get_new_inode_fast() will do the right thing, re-trying the search
1327 * in case it had to block at any point.
1328 */
1329 return get_new_inode_fast(sb, head, ino);
1330} 1234}
1331EXPORT_SYMBOL(iget_locked); 1235EXPORT_SYMBOL(ilookup);
1332 1236
1333int insert_inode_locked(struct inode *inode) 1237int insert_inode_locked(struct inode *inode)
1334{ 1238{