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