Changeset 739 for trunk/cgi-bin


Ignore:
Timestamp:
05/29/15 18:06:09 (9 years ago)
Author:
Kris Deugau
Message:

/dev

Fix a lurking bug before I forget; splitting a largish container with
mostly free space would result in mangled free blocks. Any block larger
than the split size needs to be split as well and distributed between the
appropriate containers. See #7.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r738 r739  
    19081908    }
    19091909
     1910    # Holder for freeblocks-to-delete.  Should be impossible to have more than one...
     1911    my %fbdel;
     1912
    19101913    # Loop over the new blocks that are not the base block
    19111914    for (my $i = 1; $i <= $#newblocks; $i++) {
     
    19291932        $nbsth->execute($args{id}, $newblocks[$i]->addr);
    19301933        $newblocks[$i]++;
    1931       }
     1934      } # $binfo->{type} =~ /.d/
     1935
     1936      # Check for free blocks larger than the new mask length, and split those as needed.
     1937      if ($binfo->{type} =~ /.[cm]/) {
     1938        # get a "list" of freeblocks bigger than the allocation in the parent.  there's only one, right?
     1939        my $fblist = $dbh->selectall_arrayref("SELECT id FROM freeblocks WHERE cidr >> ? AND parent_id = ? ",
     1940            {Slice=>{}}, $newblocks[$i], $args{id});
     1941        if (@$fblist) {
     1942          # create a new freeblock for the new block we created earlier
     1943          $dbh->do(q{
     1944            INSERT INTO freeblocks (cidr, parent_id, master_id, city, routed,vrf)
     1945                SELECT ? AS cidr, ? AS parent_id, master_id, city, routed, vrf FROM freeblocks
     1946                WHERE id = ?
     1947            }, undef, ($newblocks[$i], $nid, $fblist->[0]->{id}) );
     1948          $fbdel{$fblist->[0]->{id}}++;
     1949        }
     1950      } # $binfo->{type} =~ /.[cm]/
    19321951
    19331952      # Reparent allocations, freeblocks, and pool IPs. 
     
    19431962      }
    19441963
     1964##fixme:
     1965# Still missing one edge case - megasplitting a large block such that "many" children also need to be split.
     1966# I'm going to call this "unsupported" because I really can't imagine a sane reason for doing this.
     1967# Should probably check and error out at least
     1968
    19451969    } # for (... @newblocks)
     1970
     1971    $dbh->do("DELETE FROM freeblocks WHERE id IN (".join(',', keys %fbdel).")");
    19461972
    19471973    $dbh->commit;
Note: See TracChangeset for help on using the changeset viewer.