Mercurial > illumos > illumos-gate
comparison usr/src/lib/libdiskmgt/common/inuse_mnt.c @ 4082:2e3825fd8bb5
6372011 libdiskmgt needs to build appropriate .po file
6533990 zpool create in-use check fails on svm swap device
author | mmusante |
---|---|
date | Fri, 20 Apr 2007 17:46:13 -0700 |
parents | 68f95e015346 |
children |
comparison
equal
deleted
inserted
replaced
4081:d68a788b1ca0 | 4082:2e3825fd8bb5 |
---|---|
1 /* | 1 /* |
2 * CDDL HEADER START | 2 * CDDL HEADER START |
3 * | 3 * |
4 * The contents of this file are subject to the terms of the | 4 * The contents of this file are subject to the terms of the |
5 * Common Development and Distribution License, Version 1.0 only | 5 * Common Development and Distribution License (the "License"). |
6 * (the "License"). You may not use this file except in compliance | 6 * You may not use this file except in compliance with the License. |
7 * with the License. | |
8 * | 7 * |
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
10 * or http://www.opensolaris.org/os/licensing. | 9 * or http://www.opensolaris.org/os/licensing. |
11 * See the License for the specific language governing permissions | 10 * See the License for the specific language governing permissions |
12 * and limitations under the License. | 11 * and limitations under the License. |
18 * information: Portions Copyright [yyyy] [name of copyright owner] | 17 * information: Portions Copyright [yyyy] [name of copyright owner] |
19 * | 18 * |
20 * CDDL HEADER END | 19 * CDDL HEADER END |
21 */ | 20 */ |
22 /* | 21 /* |
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. | 23 * Use is subject to license terms. |
25 */ | 24 */ |
26 | 25 |
27 #pragma ident "%Z%%M% %I% %E% SMI" | 26 #pragma ident "%Z%%M% %I% %E% SMI" |
28 | 27 |
205 struct mntpnt_list *currp; | 204 struct mntpnt_list *currp; |
206 FILE *fp; | 205 FILE *fp; |
207 struct mntpnt_list *headp; | 206 struct mntpnt_list *headp; |
208 int num; | 207 int num; |
209 struct mntpnt_list *prevp; | 208 struct mntpnt_list *prevp; |
209 struct swaptable *st; | |
210 struct swapent *swapent; | |
211 int err; | |
212 int i; | |
210 | 213 |
211 headp = NULL; | 214 headp = NULL; |
212 prevp = NULL; | 215 prevp = NULL; |
213 | 216 |
214 /* get the mnttab entries */ | 217 /* get the mnttab entries */ |
274 | 277 |
275 (void) fclose(fp); | 278 (void) fclose(fp); |
276 } | 279 } |
277 | 280 |
278 /* get the swap entries */ | 281 /* get the swap entries */ |
279 if ((num = swapctl(SC_GETNSWP, NULL)) > -1) { | 282 num = dm_get_swapentries(&st, &err); |
280 | 283 if (num < 0) { |
281 struct swaptable *st; | |
282 struct swapent *swapent; | |
283 int i; | |
284 char *path; | |
285 char *pathstart; | |
286 char fullpath[MAXPATHLEN+1]; | |
287 | |
288 st = malloc((size_t)((num * sizeof (swapent_t)) + sizeof (int))); | |
289 if (st == NULL) { | |
290 /* out of memory, free what we have and return */ | |
291 free_mnttab(headp); | 284 free_mnttab(headp); |
292 return (ENOMEM); | 285 return (ENOMEM); |
293 } | 286 } |
294 | 287 |
295 path = malloc(num * MAXPATHLEN); | 288 for (i = 0, swapent = st->swt_ent; i < num; i++, swapent++) { |
296 if (path == NULL) { | 289 char fullpath[MAXPATHLEN+1]; |
297 /* out of memory, free what we have and return */ | 290 |
298 free(st); | 291 currp = (struct mntpnt_list *) |
299 free_mnttab(headp); | 292 calloc((size_t)1, (size_t)sizeof (struct mntpnt_list)); |
300 return (ENOMEM); | 293 |
301 } | 294 if (currp == NULL) { |
302 pathstart = path; | |
303 | |
304 swapent = st->swt_ent; | |
305 for (i = 0; i < num; i++, swapent++) { | |
306 swapent->ste_path = path; | |
307 path += MAXPATHLEN; | |
308 } | |
309 | |
310 st->swt_n = num; | |
311 if ((num = swapctl(SC_LIST, st)) >= 0) { | |
312 swapent = st->swt_ent; | |
313 for (i = 0; i < num; i++, swapent++) { | |
314 | |
315 currp = (struct mntpnt_list *) | |
316 calloc((size_t)1, (size_t)sizeof (struct mntpnt_list)); | |
317 | |
318 if (currp == NULL) { | |
319 /* out of memory, free what we have and return */ | 295 /* out of memory, free what we have and return */ |
320 free((void *)st); | 296 dm_free_swapentries(st); |
321 free((void *)pathstart); | |
322 free_mnttab(headp); | 297 free_mnttab(headp); |
323 return (ENOMEM); | 298 return (ENOMEM); |
324 } | 299 } |
325 | 300 |
326 if (headp == NULL) { | 301 if (headp == NULL) { |
327 headp = currp; | 302 headp = currp; |
328 } else { | 303 } else { |
329 prevp->next = currp; | 304 prevp->next = currp; |
330 } | 305 } |
331 | 306 |
332 currp->next = NULL; | 307 currp->next = NULL; |
333 | 308 |
334 if (*swapent->ste_path != '/') { | 309 if (*swapent->ste_path != '/') { |
335 (void) snprintf(fullpath, sizeof (fullpath), "/dev/%s", | 310 (void) snprintf(fullpath, sizeof (fullpath), "/dev/%s", |
336 swapent->ste_path); | 311 swapent->ste_path); |
337 } else { | 312 } else { |
338 (void) strlcpy(fullpath, swapent->ste_path, | 313 (void) strlcpy(fullpath, swapent->ste_path, |
339 sizeof (fullpath)); | 314 sizeof (fullpath)); |
340 } | 315 } |
341 | 316 |
342 currp->special = strdup(fullpath); | 317 currp->special = strdup(fullpath); |
343 if (currp->special == NULL) { | 318 if (currp->special == NULL) { |
344 /* out of memory, free what we have and return */ | 319 /* out of memory, free what we have and return */ |
345 free(st); | 320 dm_free_swapentries(st); |
346 free(pathstart); | |
347 free_mnttab(headp); | 321 free_mnttab(headp); |
348 return (ENOMEM); | 322 return (ENOMEM); |
349 } | 323 } |
350 | 324 |
351 currp->mountp = strdup("swap"); | 325 currp->mountp = strdup("swap"); |
352 if (currp->mountp == NULL) { | 326 if (currp->mountp == NULL) { |
353 /* out of memory, free what we have and return */ | 327 /* out of memory, free what we have and return */ |
354 free(st); | 328 dm_free_swapentries(st); |
355 free(pathstart); | |
356 free_mnttab(headp); | 329 free_mnttab(headp); |
357 return (ENOMEM); | 330 return (ENOMEM); |
358 } | 331 } |
359 | 332 |
360 prevp = currp; | 333 prevp = currp; |
361 } | 334 } |
362 } | 335 if (num) |
363 | 336 dm_free_swapentries(st); |
364 free(st); | |
365 free(pathstart); | |
366 } | |
367 | 337 |
368 /* note that we unlock the mutex in both paths of this if statement */ | 338 /* note that we unlock the mutex in both paths of this if statement */ |
369 (void) rw_wrlock(&mntpoint_lock); | 339 (void) rw_wrlock(&mntpoint_lock); |
370 if (diff_mnttab(send_event, mntpoint_listp, headp) == B_TRUE) { | 340 if (diff_mnttab(send_event, mntpoint_listp, headp) == B_TRUE) { |
371 struct mntpnt_list *tmpp; | 341 struct mntpnt_list *tmpp; |