Qatar has passed a law to allow some of the foreigners who make up most of its population to get permanent residency.