Mathematica can do it, if you move the term $2 f(x)$ to the RHS !
Clear["Global`*"]
ode = f[x]*(x^2*g''[x] - 2*g[x] + 2) + x*(x*g'[x] - 2*g[x])*f'[x] == 0
lhs = ode[[1]] - 2*f[x]
rhs = ode[[2]] + 2*f[x]
(*make it first order ODE*)
newOde = ApplySides[Integrate[#, x] &, lhs == rhs];
(*Now it can solve it*)
DSolve[newOde, g[x], x]
Mathematica should have been able to do it. btw, I do not see an a
and b
in your ode.