Back in the day, FBI Director J. Edgar Hoover was believed to keep extensive files on the peccadilloes of various senators and other government officials, including presidents. It is alleged these files were used by Hoover to influence official decisions.
One wonders if early FBI knowledge of the Petraeus affair was being used in the same way, as this Investors' Business Daily article hints. Questions about the CIA's role in the Benghazi consulate attack still pend.
Petraeus may have gone public about the affair and resigned in order to eliminate leverage against him prior to testifying to Congress. Or to make his testimony not useful.
Perhaps it was a bureaucrat's version of "falling on a grenade" - taking one for his Agency. For another view, see this political/analytical article from The New Yorker.