Skip to content

Commit ff116fc

Browse files
jankaraLinus Torvalds
authored andcommitted
UDF: introduce struct extent_position
Introduce a structure extent_position to store a position of an extent and the corresponding buffer_head in one place. Signed-off-by: Jan Kara <jack@suse.cz> Acked-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 60448b1 commit ff116fc

8 files changed

Lines changed: 434 additions & 445 deletions

File tree

‎fs/udf/balloc.c‎

Lines changed: 83 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ static void udf_table_free_blocks(struct super_block * sb,
427427
{
428428
struct udf_sb_info *sbi = UDF_SB(sb);
429429
uint32_t start, end;
430-
uint32_t nextoffset, oextoffset, elen;
431-
kernel_lb_addr nbloc, obloc, eloc;
432-
struct buffer_head *obh, *nbh;
430+
uint32_t elen;
431+
kernel_lb_addr eloc;
432+
struct extent_position oepos, epos;
433433
int8_t etype;
434434
int i;
435435

@@ -457,14 +457,13 @@ static void udf_table_free_blocks(struct super_block * sb,
457457
start = bloc.logicalBlockNum + offset;
458458
end = bloc.logicalBlockNum + offset + count - 1;
459459

460-
oextoffset = nextoffset = sizeof(struct unallocSpaceEntry);
460+
epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry);
461461
elen = 0;
462-
obloc = nbloc = UDF_I_LOCATION(table);
463-
464-
obh = nbh = NULL;
462+
epos.block = oepos.block = UDF_I_LOCATION(table);
463+
epos.bh = oepos.bh = NULL;
465464

466465
while (count && (etype =
467-
udf_next_aext(table, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) != -1)
466+
udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
468467
{
469468
if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) ==
470469
start))
@@ -482,7 +481,7 @@ static void udf_table_free_blocks(struct super_block * sb,
482481
start += count;
483482
count = 0;
484483
}
485-
udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1);
484+
udf_write_aext(table, &oepos, eloc, elen, 1);
486485
}
487486
else if (eloc.logicalBlockNum == (end + 1))
488487
{
@@ -502,20 +501,20 @@ static void udf_table_free_blocks(struct super_block * sb,
502501
end -= count;
503502
count = 0;
504503
}
505-
udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1);
504+
udf_write_aext(table, &oepos, eloc, elen, 1);
506505
}
507506

508-
if (nbh != obh)
507+
if (epos.bh != oepos.bh)
509508
{
510509
i = -1;
511-
obloc = nbloc;
512-
udf_release_data(obh);
513-
atomic_inc(&nbh->b_count);
514-
obh = nbh;
515-
oextoffset = 0;
510+
oepos.block = epos.block;
511+
udf_release_data(oepos.bh);
512+
atomic_inc(&epos.bh->b_count);
513+
oepos.bh = epos.bh;
514+
oepos.offset = 0;
516515
}
517516
else
518-
oextoffset = nextoffset;
517+
oepos.offset = epos.offset;
519518
}
520519

521520
if (count)
@@ -547,55 +546,53 @@ static void udf_table_free_blocks(struct super_block * sb,
547546
adsize = sizeof(long_ad);
548547
else
549548
{
550-
udf_release_data(obh);
551-
udf_release_data(nbh);
549+
udf_release_data(oepos.bh);
550+
udf_release_data(epos.bh);
552551
goto error_return;
553552
}
554553

555-
if (nextoffset + (2 * adsize) > sb->s_blocksize)
554+
if (epos.offset + (2 * adsize) > sb->s_blocksize)
556555
{
557556
char *sptr, *dptr;
558557
int loffset;
559558

560-
udf_release_data(obh);
561-
obh = nbh;
562-
obloc = nbloc;
563-
oextoffset = nextoffset;
559+
udf_release_data(oepos.bh);
560+
oepos = epos;
564561

565562
/* Steal a block from the extent being free'd */
566-
nbloc.logicalBlockNum = eloc.logicalBlockNum;
563+
epos.block.logicalBlockNum = eloc.logicalBlockNum;
567564
eloc.logicalBlockNum ++;
568565
elen -= sb->s_blocksize;
569566

570-
if (!(nbh = udf_tread(sb,
571-
udf_get_lb_pblock(sb, nbloc, 0))))
567+
if (!(epos.bh = udf_tread(sb,
568+
udf_get_lb_pblock(sb, epos.block, 0))))
572569
{
573-
udf_release_data(obh);
570+
udf_release_data(oepos.bh);
574571
goto error_return;
575572
}
576-
aed = (struct allocExtDesc *)(nbh->b_data);
577-
aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
578-
if (nextoffset + adsize > sb->s_blocksize)
573+
aed = (struct allocExtDesc *)(epos.bh->b_data);
574+
aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum);
575+
if (epos.offset + adsize > sb->s_blocksize)
579576
{
580-
loffset = nextoffset;
577+
loffset = epos.offset;
581578
aed->lengthAllocDescs = cpu_to_le32(adsize);
582-
sptr = UDF_I_DATA(inode) + nextoffset -
579+
sptr = UDF_I_DATA(inode) + epos.offset -
583580
udf_file_entry_alloc_offset(inode) +
584581
UDF_I_LENEATTR(inode) - adsize;
585-
dptr = nbh->b_data + sizeof(struct allocExtDesc);
582+
dptr = epos.bh->b_data + sizeof(struct allocExtDesc);
586583
memcpy(dptr, sptr, adsize);
587-
nextoffset = sizeof(struct allocExtDesc) + adsize;
584+
epos.offset = sizeof(struct allocExtDesc) + adsize;
588585
}
589586
else
590587
{
591-
loffset = nextoffset + adsize;
588+
loffset = epos.offset + adsize;
592589
aed->lengthAllocDescs = cpu_to_le32(0);
593-
sptr = (obh)->b_data + nextoffset;
594-
nextoffset = sizeof(struct allocExtDesc);
590+
sptr = oepos.bh->b_data + epos.offset;
591+
epos.offset = sizeof(struct allocExtDesc);
595592

596-
if (obh)
593+
if (oepos.bh)
597594
{
598-
aed = (struct allocExtDesc *)(obh)->b_data;
595+
aed = (struct allocExtDesc *)oepos.bh->b_data;
599596
aed->lengthAllocDescs =
600597
cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
601598
}
@@ -606,11 +603,11 @@ static void udf_table_free_blocks(struct super_block * sb,
606603
}
607604
}
608605
if (UDF_SB_UDFREV(sb) >= 0x0200)
609-
udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
610-
nbloc.logicalBlockNum, sizeof(tag));
606+
udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1,
607+
epos.block.logicalBlockNum, sizeof(tag));
611608
else
612-
udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
613-
nbloc.logicalBlockNum, sizeof(tag));
609+
udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1,
610+
epos.block.logicalBlockNum, sizeof(tag));
614611
switch (UDF_I_ALLOCTYPE(table))
615612
{
616613
case ICBTAG_FLAG_AD_SHORT:
@@ -619,7 +616,7 @@ static void udf_table_free_blocks(struct super_block * sb,
619616
sad->extLength = cpu_to_le32(
620617
EXT_NEXT_EXTENT_ALLOCDECS |
621618
sb->s_blocksize);
622-
sad->extPosition = cpu_to_le32(nbloc.logicalBlockNum);
619+
sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum);
623620
break;
624621
}
625622
case ICBTAG_FLAG_AD_LONG:
@@ -628,41 +625,41 @@ static void udf_table_free_blocks(struct super_block * sb,
628625
lad->extLength = cpu_to_le32(
629626
EXT_NEXT_EXTENT_ALLOCDECS |
630627
sb->s_blocksize);
631-
lad->extLocation = cpu_to_lelb(nbloc);
628+
lad->extLocation = cpu_to_lelb(epos.block);
632629
break;
633630
}
634631
}
635-
if (obh)
632+
if (oepos.bh)
636633
{
637-
udf_update_tag(obh->b_data, loffset);
638-
mark_buffer_dirty(obh);
634+
udf_update_tag(oepos.bh->b_data, loffset);
635+
mark_buffer_dirty(oepos.bh);
639636
}
640637
else
641638
mark_inode_dirty(table);
642639
}
643640

644641
if (elen) /* It's possible that stealing the block emptied the extent */
645642
{
646-
udf_write_aext(table, nbloc, &nextoffset, eloc, elen, nbh, 1);
643+
udf_write_aext(table, &epos, eloc, elen, 1);
647644

648-
if (!nbh)
645+
if (!epos.bh)
649646
{
650647
UDF_I_LENALLOC(table) += adsize;
651648
mark_inode_dirty(table);
652649
}
653650
else
654651
{
655-
aed = (struct allocExtDesc *)nbh->b_data;
652+
aed = (struct allocExtDesc *)epos.bh->b_data;
656653
aed->lengthAllocDescs =
657654
cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
658-
udf_update_tag(nbh->b_data, nextoffset);
659-
mark_buffer_dirty(nbh);
655+
udf_update_tag(epos.bh->b_data, epos.offset);
656+
mark_buffer_dirty(epos.bh);
660657
}
661658
}
662659
}
663660

664-
udf_release_data(nbh);
665-
udf_release_data(obh);
661+
udf_release_data(epos.bh);
662+
udf_release_data(oepos.bh);
666663

667664
error_return:
668665
sb->s_dirt = 1;
@@ -677,9 +674,9 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
677674
{
678675
struct udf_sb_info *sbi = UDF_SB(sb);
679676
int alloc_count = 0;
680-
uint32_t extoffset, elen, adsize;
681-
kernel_lb_addr bloc, eloc;
682-
struct buffer_head *bh;
677+
uint32_t elen, adsize;
678+
kernel_lb_addr eloc;
679+
struct extent_position epos;
683680
int8_t etype = -1;
684681

685682
if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
@@ -693,14 +690,13 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
693690
return 0;
694691

695692
mutex_lock(&sbi->s_alloc_mutex);
696-
extoffset = sizeof(struct unallocSpaceEntry);
697-
bloc = UDF_I_LOCATION(table);
698-
699-
bh = NULL;
693+
epos.offset = sizeof(struct unallocSpaceEntry);
694+
epos.block = UDF_I_LOCATION(table);
695+
epos.bh = NULL;
700696
eloc.logicalBlockNum = 0xFFFFFFFF;
701697

702698
while (first_block != eloc.logicalBlockNum && (etype =
703-
udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
699+
udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
704700
{
705701
udf_debug("eloc=%d, elen=%d, first_block=%d\n",
706702
eloc.logicalBlockNum, elen, first_block);
@@ -709,7 +705,7 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
709705

710706
if (first_block == eloc.logicalBlockNum)
711707
{
712-
extoffset -= adsize;
708+
epos.offset -= adsize;
713709

714710
alloc_count = (elen >> sb->s_blocksize_bits);
715711
if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count))
@@ -719,15 +715,15 @@ static int udf_table_prealloc_blocks(struct super_block * sb,
719715
alloc_count = block_count;
720716
eloc.logicalBlockNum += alloc_count;
721717
elen -= (alloc_count << sb->s_blocksize_bits);
722-
udf_write_aext(table, bloc, &extoffset, eloc, (etype << 30) | elen, bh, 1);
718+
udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1);
723719
}
724720
else
725-
udf_delete_aext(table, bloc, extoffset, eloc, (etype << 30) | elen, bh);
721+
udf_delete_aext(table, epos, eloc, (etype << 30) | elen);
726722
}
727723
else
728724
alloc_count = 0;
729725

730-
udf_release_data(bh);
726+
udf_release_data(epos.bh);
731727

732728
if (alloc_count && UDF_SB_LVIDBH(sb))
733729
{
@@ -747,9 +743,9 @@ static int udf_table_new_block(struct super_block * sb,
747743
struct udf_sb_info *sbi = UDF_SB(sb);
748744
uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF;
749745
uint32_t newblock = 0, adsize;
750-
uint32_t extoffset, goal_extoffset, elen, goal_elen = 0;
751-
kernel_lb_addr bloc, goal_bloc, eloc, goal_eloc;
752-
struct buffer_head *bh, *goal_bh;
746+
uint32_t elen, goal_elen = 0;
747+
kernel_lb_addr eloc, goal_eloc;
748+
struct extent_position epos, goal_epos;
753749
int8_t etype;
754750

755751
*err = -ENOSPC;
@@ -770,14 +766,12 @@ static int udf_table_new_block(struct super_block * sb,
770766
We store the buffer_head, bloc, and extoffset of the current closest
771767
match and use that when we are done.
772768
*/
773-
774-
extoffset = sizeof(struct unallocSpaceEntry);
775-
bloc = UDF_I_LOCATION(table);
776-
777-
goal_bh = bh = NULL;
769+
epos.offset = sizeof(struct unallocSpaceEntry);
770+
epos.block = UDF_I_LOCATION(table);
771+
epos.bh = goal_epos.bh = NULL;
778772

779773
while (spread && (etype =
780-
udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
774+
udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
781775
{
782776
if (goal >= eloc.logicalBlockNum)
783777
{
@@ -793,24 +787,24 @@ static int udf_table_new_block(struct super_block * sb,
793787
if (nspread < spread)
794788
{
795789
spread = nspread;
796-
if (goal_bh != bh)
790+
if (goal_epos.bh != epos.bh)
797791
{
798-
udf_release_data(goal_bh);
799-
goal_bh = bh;
800-
atomic_inc(&goal_bh->b_count);
792+
udf_release_data(goal_epos.bh);
793+
goal_epos.bh = epos.bh;
794+
atomic_inc(&goal_epos.bh->b_count);
801795
}
802-
goal_bloc = bloc;
803-
goal_extoffset = extoffset - adsize;
796+
goal_epos.block = epos.block;
797+
goal_epos.offset = epos.offset - adsize;
804798
goal_eloc = eloc;
805799
goal_elen = (etype << 30) | elen;
806800
}
807801
}
808802

809-
udf_release_data(bh);
803+
udf_release_data(epos.bh);
810804

811805
if (spread == 0xFFFFFFFF)
812806
{
813-
udf_release_data(goal_bh);
807+
udf_release_data(goal_epos.bh);
814808
mutex_unlock(&sbi->s_alloc_mutex);
815809
return 0;
816810
}
@@ -826,17 +820,17 @@ static int udf_table_new_block(struct super_block * sb,
826820

827821
if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
828822
{
829-
udf_release_data(goal_bh);
823+
udf_release_data(goal_epos.bh);
830824
mutex_unlock(&sbi->s_alloc_mutex);
831825
*err = -EDQUOT;
832826
return 0;
833827
}
834828

835829
if (goal_elen)
836-
udf_write_aext(table, goal_bloc, &goal_extoffset, goal_eloc, goal_elen, goal_bh, 1);
830+
udf_write_aext(table, &goal_epos, goal_eloc, goal_elen, 1);
837831
else
838-
udf_delete_aext(table, goal_bloc, goal_extoffset, goal_eloc, goal_elen, goal_bh);
839-
udf_release_data(goal_bh);
832+
udf_delete_aext(table, goal_epos, goal_eloc, goal_elen);
833+
udf_release_data(goal_epos.bh);
840834

841835
if (UDF_SB_LVIDBH(sb))
842836
{

0 commit comments

Comments
 (0)