164 * Devpolicy reference counting/allocation routines.
165 * cf. crget()/crhold()/crfree().
166 */
167 devplcy_t *
168 dpget(void)
169 {
170 devplcy_t *dp = kmem_zalloc(sizeof (*dp), KM_SLEEP);
171
172 ASSERT(MUTEX_HELD(&policymutex));
173
174 dp->dp_ref = 1;
175 /* New ones belong to the next generation */
176 dp->dp_gen = devplcy_gen + 1;
177 return (dp);
178 }
179
180 void
181 dphold(devplcy_t *dp)
182 {
183 ASSERT(dp->dp_ref != 0xdeadbeef && dp->dp_ref != 0);
184 atomic_add_32(&dp->dp_ref, 1);
185 }
186
187 void
188 dpfree(devplcy_t *dp)
189 {
190 ASSERT(dp->dp_ref != 0xdeadbeef && dp->dp_ref != 0);
191 if (atomic_add_32_nv(&dp->dp_ref, -1) == 0)
192 kmem_free(dp, sizeof (*dp));
193 }
194
195 /*
196 * Find the policy that matches this device.
197 */
198 static devplcy_t *
199 match_policy(devplcyent_t *de, dev_t dev, vtype_t spec)
200 {
201 char *mname = NULL;
202 minor_t min = getminor(dev);
203
204 for (; de != NULL; de = de->dpe_next) {
205 if (de->dpe_flags & DPE_ALLMINOR)
206 break;
207
208 if (de->dpe_flags & DPE_EXPANDED) {
209 if (min >= de->dpe_lomin && min <= de->dpe_himin &&
210 spec == de->dpe_spec) {
211 break;
|
164 * Devpolicy reference counting/allocation routines.
165 * cf. crget()/crhold()/crfree().
166 */
167 devplcy_t *
168 dpget(void)
169 {
170 devplcy_t *dp = kmem_zalloc(sizeof (*dp), KM_SLEEP);
171
172 ASSERT(MUTEX_HELD(&policymutex));
173
174 dp->dp_ref = 1;
175 /* New ones belong to the next generation */
176 dp->dp_gen = devplcy_gen + 1;
177 return (dp);
178 }
179
180 void
181 dphold(devplcy_t *dp)
182 {
183 ASSERT(dp->dp_ref != 0xdeadbeef && dp->dp_ref != 0);
184 atomic_inc_32(&dp->dp_ref);
185 }
186
187 void
188 dpfree(devplcy_t *dp)
189 {
190 ASSERT(dp->dp_ref != 0xdeadbeef && dp->dp_ref != 0);
191 if (atomic_dec_32_nv(&dp->dp_ref) == 0)
192 kmem_free(dp, sizeof (*dp));
193 }
194
195 /*
196 * Find the policy that matches this device.
197 */
198 static devplcy_t *
199 match_policy(devplcyent_t *de, dev_t dev, vtype_t spec)
200 {
201 char *mname = NULL;
202 minor_t min = getminor(dev);
203
204 for (; de != NULL; de = de->dpe_next) {
205 if (de->dpe_flags & DPE_ALLMINOR)
206 break;
207
208 if (de->dpe_flags & DPE_EXPANDED) {
209 if (min >= de->dpe_lomin && min <= de->dpe_himin &&
210 spec == de->dpe_spec) {
211 break;
|