| @@ -82,6 +82,8 @@ · 81 unmodified lines |
| 82 | | 82 | |
| 83 | #define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) | 83 | #define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) |
| 84 | #define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) | 84 | #define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) |
| | 85 | #define GFS2_HASH_INDEX_MASK 0xffffc000 |
| | 86 | #define GFS2_USE_HASH_FLAG 0x2000 |
| 85 | | 87 | |
| 86 | struct qstr gfs2_qdot __read_mostly; | 88 | struct qstr gfs2_qdot __read_mostly; |
| 87 | struct qstr gfs2_qdotdot __read_mostly; | 89 | struct qstr gfs2_qdotdot __read_mostly; |
| @@ -1223,10 +1225,10 @@ static int compare_dents(const void *a, const void *b) · 1135 unmodified lines |
| 1223 | int ret = 0; | 1225 | int ret = 0; |
| 1224 | | 1226 | |
| 1225 | dent_a = *(const struct gfs2_dirent **)a; | 1227 | dent_a = *(const struct gfs2_dirent **)a; |
| 1226 | hash_a = be32_to_cpu(dent_a->de_hash); | 1228 | hash_a = dent_a->de_cookie; |
| 1227 | | 1229 | |
| 1228 | dent_b = *(const struct gfs2_dirent **)b; | 1230 | dent_b = *(const struct gfs2_dirent **)b; |
| 1229 | hash_b = be32_to_cpu(dent_b->de_hash); | 1231 | hash_b = dent_b->de_cookie; |
| 1230 | | 1232 | |
| 1231 | if (hash_a > hash_b) | 1233 | if (hash_a > hash_b) |
| 1232 | ret = 1; | 1234 | ret = 1; |
| @@ -1264,19 +1266,20 @@ static int compare_dents(const void *a, const void *b) · 31 unmodified lines |
| 1264 | */ | 1266 | */ |
| 1265 | | 1267 | |
| 1266 | static int do_filldir_main(struct gfs2_inode *dip, struct dir_context *ctx, | 1268 | static int do_filldir_main(struct gfs2_inode *dip, struct dir_context *ctx, |
| 1267 | const struct gfs2_dirent **darr, u32 entries, | 1269 | struct gfs2_dirent **darr, u32 entries, |
| 1268 | int *copied) | 1270 | u32 sort_start, int *copied) |
| 1269 | { | 1271 | { |
| 1270 | const struct gfs2_dirent *dent, *dent_next; | 1272 | const struct gfs2_dirent *dent, *dent_next; |
| 1271 | u64 off, off_next; | 1273 | u64 off, off_next; |
| 1272 | unsigned int x, y; | 1274 | unsigned int x, y; |
| 1273 | int run = 0; | 1275 | int run = 0; |
| 1274 | | 1276 | |
| 1275 | sort(darr, entries, sizeof(struct gfs2_dirent *), compare_dents, NULL); | 1277 | if (sort_start < entries) |
| | 1278 | sort(&darr[sort_start], entries - sort_start, |
| | 1279 | sizeof(struct gfs2_dirent *), compare_dents, NULL); |
| 1276 | | 1280 | |
| 1277 | dent_next = darr[0]; | 1281 | dent_next = darr[0]; |
| 1278 | off_next = be32_to_cpu(dent_next->de_hash); | 1282 | off_next = dent_next->de_cookie; |
| 1279 | off_next = gfs2_disk_hash2offset(off_next); | | |
| 1280 | | 1283 | |
| 1281 | for (x = 0, y = 1; x < entries; x++, y++) { | 1284 | for (x = 0, y = 1; x < entries; x++, y++) { |
| 1282 | dent = dent_next; | 1285 | dent = dent_next; |
| @@ -1284,8 +1287,7 @@ static int do_filldir_main(struct gfs2_inode *dip, struct dir_context *ctx, · 1 unmodified line |
| 1284 | | 1287 | |
| 1285 | if (y < entries) { | 1288 | if (y < entries) { |
| 1286 | dent_next = darr[y]; | 1289 | dent_next = darr[y]; |
| 1287 | off_next = be32_to_cpu(dent_next->de_hash); | 1290 | off_next = dent_next->de_cookie; |
| 1288 | off_next = gfs2_disk_hash2offset(off_next); | | |
| 1289 | | 1291 | |
| 1290 | if (off < ctx->pos) | 1292 | if (off < ctx->pos) |
| 1291 | continue; | 1293 | continue; |
| @@ -1332,6 +1334,40 @@ static void *gfs2_alloc_sort_buffer(unsigned size) · 40 unmodified lines |
| 1332 | return ptr; | 1334 | return ptr; |
| 1333 | } | 1335 | } |
| 1334 | | 1336 | |
| | 1337 | |
| | 1338 | static int gfs2_set_cookies(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| | 1339 | unsigned leaf_nr, struct gfs2_dirent **darr, |
| | 1340 | unsigned entries) |
| | 1341 | { |
| | 1342 | int sort_id = -1; |
| | 1343 | int i; |
| | 1344 | |
| | 1345 | for (i = 0; i < entries; i++) { |
| | 1346 | unsigned offset; |
| | 1347 | |
| | 1348 | darr[i]->de_cookie = be32_to_cpu(darr[i]->de_hash); |
| | 1349 | darr[i]->de_cookie = gfs2_disk_hash2offset(darr[i]->de_cookie); |
| | 1350 | |
| | 1351 | if (!sdp->sd_args.ar_loccookie) |
| | 1352 | continue; |
| | 1353 | offset = (char *)(darr[i]) - |
| | 1354 | (bh->b_data + gfs2_dirent_offset(bh->b_data)); |
| | 1355 | offset /= GFS2_MIN_DIRENT_SIZE; |
| | 1356 | offset += leaf_nr * sdp->sd_max_dents_per_leaf; |
| | 1357 | if (offset >= GFS2_USE_HASH_FLAG || |
| | 1358 | leaf_nr >= GFS2_USE_HASH_FLAG) { |
| | 1359 | darr[i]->de_cookie |= GFS2_USE_HASH_FLAG; |
| | 1360 | if (sort_id < 0) |
| | 1361 | sort_id = i; |
| | 1362 | continue; |
| | 1363 | } |
| | 1364 | darr[i]->de_cookie &= GFS2_HASH_INDEX_MASK; |
| | 1365 | darr[i]->de_cookie |= offset; |
| | 1366 | } |
| | 1367 | return sort_id; |
| | 1368 | } |
| | 1369 | |
| | 1370 | |
| 1335 | static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, | 1371 | static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, |
| 1336 | int *copied, unsigned *depth, | 1372 | int *copied, unsigned *depth, |
| 1337 | u64 leaf_no) | 1373 | u64 leaf_no) |
| @@ -1341,12 +1377,11 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, · 3 unmodified lines |
| 1341 | struct buffer_head *bh; | 1377 | struct buffer_head *bh; |
| 1342 | struct gfs2_leaf *lf; | 1378 | struct gfs2_leaf *lf; |
| 1343 | unsigned entries = 0, entries2 = 0; | 1379 | unsigned entries = 0, entries2 = 0; |
| 1344 | unsigned leaves = 0; | 1380 | unsigned leaves = 0, leaf = 0, offset, sort_offset; |
| 1345 | const struct gfs2_dirent **darr, *dent; | 1381 | struct gfs2_dirent **darr, *dent; |
| 1346 | struct dirent_gather g; | 1382 | struct dirent_gather g; |
| 1347 | struct buffer_head **larr; | 1383 | struct buffer_head **larr; |
| 1348 | int leaf = 0; | 1384 | int error, i, need_sort = 0, sort_id; |
| 1349 | int error, i; | | |
| 1350 | u64 lfn = leaf_no; | 1385 | u64 lfn = leaf_no; |
| 1351 | | 1386 | |
| 1352 | do { | 1387 | do { |
| @@ -1362,6 +1397,11 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, · 9 unmodified lines |
| 1362 | brelse(bh); | 1397 | brelse(bh); |
| 1363 | } while(lfn); | 1398 | } while(lfn); |
| 1364 | | 1399 | |
| | 1400 | if (*depth < GFS2_DIR_MAX_DEPTH || !sdp->sd_args.ar_loccookie) { |
| | 1401 | need_sort = 1; |
| | 1402 | sort_offset = 0; |
| | 1403 | } |
| | 1404 | |
| 1365 | if (!entries) | 1405 | if (!entries) |
| 1366 | return 0; | 1406 | return 0; |
| 1367 | | 1407 | |
| @@ -1375,8 +1415,8 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, · 7 unmodified lines |
| 1375 | larr = gfs2_alloc_sort_buffer((leaves + entries + 99) * sizeof(void *)); | 1415 | larr = gfs2_alloc_sort_buffer((leaves + entries + 99) * sizeof(void *)); |
| 1376 | if (!larr) | 1416 | if (!larr) |
| 1377 | goto out; | 1417 | goto out; |
| 1378 | darr = (const struct gfs2_dirent **)(larr + leaves); | 1418 | darr = (struct gfs2_dirent **)(larr + leaves); |
| 1379 | g.pdent = darr; | 1419 | g.pdent = (const struct gfs2_dirent **)darr; |
| 1380 | g.offset = 0; | 1420 | g.offset = 0; |
| 1381 | lfn = leaf_no; | 1421 | lfn = leaf_no; |
| 1382 | | 1422 | |
| @@ -1387,6 +1427,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, · 4 unmodified lines |
| 1387 | lf = (struct gfs2_leaf *)bh->b_data; | 1427 | lf = (struct gfs2_leaf *)bh->b_data; |
| 1388 | lfn = be64_to_cpu(lf->lf_next); | 1428 | lfn = be64_to_cpu(lf->lf_next); |
| 1389 | if (lf->lf_entries) { | 1429 | if (lf->lf_entries) { |
| | 1430 | offset = g.offset; |
| 1390 | entries2 += be16_to_cpu(lf->lf_entries); | 1431 | entries2 += be16_to_cpu(lf->lf_entries); |
| 1391 | dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, | 1432 | dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, |
| 1392 | gfs2_dirent_gather, NULL, &g); | 1433 | gfs2_dirent_gather, NULL, &g); |
| @@ -1404,17 +1445,26 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, · 11 unmodified lines |
| 1404 | goto out_free; | 1445 | goto out_free; |
| 1405 | } | 1446 | } |
| 1406 | error = 0; | 1447 | error = 0; |
| | 1448 | sort_id = gfs2_set_cookies(sdp, bh, leaf, &darr[offset], |
| | 1449 | be16_to_cpu(lf->lf_entries)); |
| | 1450 | if (!need_sort && sort_id >= 0) { |
| | 1451 | need_sort = 1; |
| | 1452 | sort_offset = offset + sort_id; |
| | 1453 | } |
| 1407 | larr[leaf++] = bh; | 1454 | larr[leaf++] = bh; |
| 1408 | } else { | 1455 | } else { |
| | 1456 | larr[leaf++] = NULL; |
| 1409 | brelse(bh); | 1457 | brelse(bh); |
| 1410 | } | 1458 | } |
| 1411 | } while(lfn); | 1459 | } while(lfn); |
| 1412 | | 1460 | |
| 1413 | BUG_ON(entries2 != entries); | 1461 | BUG_ON(entries2 != entries); |
| 1414 | error = do_filldir_main(ip, ctx, darr, entries, copied); | 1462 | error = do_filldir_main(ip, ctx, darr, entries, need_sort ? |
| | 1463 | sort_offset : entries, copied); |
| 1415 | out_free: | 1464 | out_free: |
| 1416 | for(i = 0; i < leaf; i++) | 1465 | for(i = 0; i < leaf; i++) |
| 1417 | brelse(larr[i]); | 1466 | if (larr[i]) |
| | 1467 | brelse(larr[i]); |
| 1418 | kvfree(larr); | 1468 | kvfree(larr); |
| 1419 | out: | 1469 | out: |
| 1420 | return error; | 1470 | return error; |
| @@ -1520,7 +1570,7 @@ int gfs2_dir_read(struct inode *inode, struct dir_context *ctx, · 99 unmodified lines |
| 1520 | struct gfs2_inode *dip = GFS2_I(inode); | 1570 | struct gfs2_inode *dip = GFS2_I(inode); |
| 1521 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 1571 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
| 1522 | struct dirent_gather g; | 1572 | struct dirent_gather g; |
| 1523 | const struct gfs2_dirent **darr, *dent; | 1573 | struct gfs2_dirent **darr, *dent; |
| 1524 | struct buffer_head *dibh; | 1574 | struct buffer_head *dibh; |
| 1525 | int copied = 0; | 1575 | int copied = 0; |
| 1526 | int error; | 1576 | int error; |
| @@ -1544,7 +1594,7 @@ int gfs2_dir_read(struct inode *inode, struct dir_context *ctx, · 17 unmodified lines |
| 1544 | /* 96 is max number of dirents which can be stuffed into an inode */ | 1594 | /* 96 is max number of dirents which can be stuffed into an inode */ |
| 1545 | darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_NOFS); | 1595 | darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_NOFS); |
| 1546 | if (darr) { | 1596 | if (darr) { |
| 1547 | g.pdent = darr; | 1597 | g.pdent = (const struct gfs2_dirent **)darr; |
| 1548 | g.offset = 0; | 1598 | g.offset = 0; |
| 1549 | dent = gfs2_dirent_scan(inode, dibh->b_data, dibh->b_size, | 1599 | dent = gfs2_dirent_scan(inode, dibh->b_data, dibh->b_size, |
| 1550 | gfs2_dirent_gather, NULL, &g); | 1600 | gfs2_dirent_gather, NULL, &g); |
| @@ -1561,8 +1611,9 @@ int gfs2_dir_read(struct inode *inode, struct dir_context *ctx, · 10 unmodified lines |
| 1561 | error = -EIO; | 1611 | error = -EIO; |
| 1562 | goto out; | 1612 | goto out; |
| 1563 | } | 1613 | } |
| | 1614 | gfs2_set_cookies(sdp, dibh, 0, darr, dip->i_entries); |
| 1564 | error = do_filldir_main(dip, ctx, darr, | 1615 | error = do_filldir_main(dip, ctx, darr, |
| 1565 | dip->i_entries, &copied); | 1616 | dip->i_entries, 0, &copied); |
| 1566 | out: | 1617 | out: |
| 1567 | kfree(darr); | 1618 | kfree(darr); |
| 1568 | } | 1619 | } |