If you already have hpv, is the gardasil shot necessary?

Yes. Most of the time women don't know exactly which hpv type they are infected with. In addition, women often clear hpv infection all by themselves! for these reasons, you should be vaccinated regardless of hpv status since you still may derive some benefit from the vaccine.
Yes. Gardasil protects against hpv strains 6, 11, 16, and 18. 6 and 11 cause genital warts and 16 and 18 are the most prevalent cause of abnormal pap smears that can lead to cancer. You may only have been exposed to one of these 4 strains thus far.
Define "have" HPV is a family of viruses. Most adults will eventually be exposed to several strains. The present (2017) Gardasil 9 has material in it to help protect against 7 strains associated with genital cancer and 2 associated with genital warts. It could help anyone not carrying the risky strains. At a listed age of 40 you would beyond the target age where insurers might pay for the vaccines series.