1 789 ahrens /* 2 789 ahrens * CDDL HEADER START 3 789 ahrens * 4 789 ahrens * The contents of this file are subject to the terms of the 5 2856 nd150628 * Common Development and Distribution License (the "License"). 6 2856 nd150628 * You may not use this file except in compliance with the License. 7 789 ahrens * 8 789 ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 789 ahrens * or http://www.opensolaris.org/os/licensing. 10 789 ahrens * See the License for the specific language governing permissions 11 789 ahrens * and limitations under the License. 12 789 ahrens * 13 789 ahrens * When distributing Covered Code, include this CDDL HEADER in each 14 789 ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 789 ahrens * If applicable, add the following below this CDDL HEADER, with the 16 789 ahrens * fields enclosed by brackets "[]" replaced with your own identifying 17 789 ahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18 789 ahrens * 19 789 ahrens * CDDL HEADER END 20 789 ahrens */ 21 789 ahrens /* 22 10265 Krishnendu * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 789 ahrens * Use is subject to license terms. 24 789 ahrens */ 25 789 ahrens 26 789 ahrens #include <errno.h> 27 789 ahrens #include <libgen.h> 28 789 ahrens #include <libintl.h> 29 789 ahrens #include <stdio.h> 30 789 ahrens #include <stdlib.h> 31 789 ahrens #include <strings.h> 32 789 ahrens 33 789 ahrens #include "zpool_util.h" 34 789 ahrens 35 789 ahrens /* 36 789 ahrens * Utility function to guarantee malloc() success. 37 789 ahrens */ 38 789 ahrens void * 39 789 ahrens safe_malloc(size_t size) 40 789 ahrens { 41 789 ahrens void *data; 42 789 ahrens 43 789 ahrens if ((data = calloc(1, size)) == NULL) { 44 789 ahrens (void) fprintf(stderr, "internal error: out of memory\n"); 45 789 ahrens exit(1); 46 789 ahrens } 47 789 ahrens 48 789 ahrens return (data); 49 789 ahrens } 50 789 ahrens 51 789 ahrens /* 52 789 ahrens * Display an out of memory error message and abort the current program. 53 789 ahrens */ 54 789 ahrens void 55 2856 nd150628 zpool_no_memory(void) 56 789 ahrens { 57 789 ahrens assert(errno == ENOMEM); 58 789 ahrens (void) fprintf(stderr, 59 789 ahrens gettext("internal error: out of memory\n")); 60 789 ahrens exit(1); 61 789 ahrens } 62 4527 perrin 63 4527 perrin /* 64 4527 perrin * Return the number of logs in supplied nvlist 65 4527 perrin */ 66 4527 perrin uint_t 67 4527 perrin num_logs(nvlist_t *nv) 68 4527 perrin { 69 4527 perrin uint_t nlogs = 0; 70 4527 perrin uint_t c, children; 71 4527 perrin nvlist_t **child; 72 4527 perrin 73 4527 perrin if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, 74 4527 perrin &child, &children) != 0) 75 4527 perrin return (0); 76 4527 perrin 77 4527 perrin for (c = 0; c < children; c++) { 78 4527 perrin uint64_t is_log = B_FALSE; 79 4527 perrin 80 4527 perrin (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG, 81 4527 perrin &is_log); 82 4527 perrin if (is_log) 83 4527 perrin nlogs++; 84 4527 perrin } 85 4527 perrin return (nlogs); 86 4527 perrin } 87