aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_node.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_dir2_node.c')
-rw-r--r--fs/xfs/xfs_dir2_node.c84
1 files changed, 4 insertions, 80 deletions
diff --git a/fs/xfs/xfs_dir2_node.c b/fs/xfs/xfs_dir2_node.c
index a0aab7d3294f..02da7b7a005a 100644
--- a/fs/xfs/xfs_dir2_node.c
+++ b/fs/xfs/xfs_dir2_node.c
@@ -244,89 +244,13 @@ xfs_dir2_leafn_add(
244 lfloglow = be16_to_cpu(leaf->hdr.count); 244 lfloglow = be16_to_cpu(leaf->hdr.count);
245 lfloghigh = -1; 245 lfloghigh = -1;
246 } 246 }
247 /* 247
248 * No stale entries, just insert a space for the new entry.
249 */
250 if (!leaf->hdr.stale) {
251 lep = &leaf->ents[index];
252 if (index < be16_to_cpu(leaf->hdr.count))
253 memmove(lep + 1, lep,
254 (be16_to_cpu(leaf->hdr.count) - index) * sizeof(*lep));
255 lfloglow = index;
256 lfloghigh = be16_to_cpu(leaf->hdr.count);
257 be16_add_cpu(&leaf->hdr.count, 1);
258 }
259 /*
260 * There are stale entries. We'll use one for the new entry.
261 */
262 else {
263 /*
264 * If we didn't do a compact then we need to figure out
265 * which stale entry will be used.
266 */
267 if (compact == 0) {
268 /*
269 * Find first stale entry before our insertion point.
270 */
271 for (lowstale = index - 1;
272 lowstale >= 0 &&
273 be32_to_cpu(leaf->ents[lowstale].address) !=
274 XFS_DIR2_NULL_DATAPTR;
275 lowstale--)
276 continue;
277 /*
278 * Find next stale entry after insertion point.
279 * Stop looking if the answer would be worse than
280 * lowstale already found.
281 */
282 for (highstale = index;
283 highstale < be16_to_cpu(leaf->hdr.count) &&
284 be32_to_cpu(leaf->ents[highstale].address) !=
285 XFS_DIR2_NULL_DATAPTR &&
286 (lowstale < 0 ||
287 index - lowstale - 1 >= highstale - index);
288 highstale++)
289 continue;
290 }
291 /*
292 * Using the low stale entry.
293 * Shift entries up toward the stale slot.
294 */
295 if (lowstale >= 0 &&
296 (highstale == be16_to_cpu(leaf->hdr.count) ||
297 index - lowstale - 1 < highstale - index)) {
298 ASSERT(be32_to_cpu(leaf->ents[lowstale].address) ==
299 XFS_DIR2_NULL_DATAPTR);
300 ASSERT(index - lowstale - 1 >= 0);
301 if (index - lowstale - 1 > 0)
302 memmove(&leaf->ents[lowstale],
303 &leaf->ents[lowstale + 1],
304 (index - lowstale - 1) * sizeof(*lep));
305 lep = &leaf->ents[index - 1];
306 lfloglow = MIN(lowstale, lfloglow);
307 lfloghigh = MAX(index - 1, lfloghigh);
308 }
309 /*
310 * Using the high stale entry.
311 * Shift entries down toward the stale slot.
312 */
313 else {
314 ASSERT(be32_to_cpu(leaf->ents[highstale].address) ==
315 XFS_DIR2_NULL_DATAPTR);
316 ASSERT(highstale - index >= 0);
317 if (highstale - index > 0)
318 memmove(&leaf->ents[index + 1],
319 &leaf->ents[index],
320 (highstale - index) * sizeof(*lep));
321 lep = &leaf->ents[index];
322 lfloglow = MIN(index, lfloglow);
323 lfloghigh = MAX(highstale, lfloghigh);
324 }
325 be16_add_cpu(&leaf->hdr.stale, -1);
326 }
327 /* 248 /*
328 * Insert the new entry, log everything. 249 * Insert the new entry, log everything.
329 */ 250 */
251 lep = xfs_dir2_leaf_find_entry(leaf, index, compact, lowstale,
252 highstale, &lfloglow, &lfloghigh);
253
330 lep->hashval = cpu_to_be32(args->hashval); 254 lep->hashval = cpu_to_be32(args->hashval);
331 lep->address = cpu_to_be32(xfs_dir2_db_off_to_dataptr(mp, 255 lep->address = cpu_to_be32(xfs_dir2_db_off_to_dataptr(mp,
332 args->blkno, args->index)); 256 args->blkno, args->index));