FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * zpool add [-fn] <pool> <vdev> ...
 *
 *	-f	Force addition of devices, even if they appear in use
 *	-n	Do not add the devices, but display the resulting layout if
 *		they were to be added.
 *
 * Adds the given vdevs to 'pool'.  As with create, the bulk of this work is
 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
 * libzfs.
 */
zpool add [-fn]  
-f      Force addition of devices, even if they appear in use
-n      Do not add the devices, but display the resulting layout if
they were to be added.

Adds the given vdevs to 'pool'.  As with create, the bulk of this work is
handled by get_vdev_spec(), which constructs the nvlist needed to pass to
libzfs.
zpool add [ - fn ] - f Force addition of devices even if they appear in use - n Do not add the devices but display the resulting layout if they were to be added . Adds the given vdevs to ' pool ' . As with create the bulk of this work is handled by get_vdev_spec () which constructs the nvlist needed to pass to libzfs .
int
zpool_do_add(int argc, char **argv)
{
	boolean_t force = B_FALSE;
	boolean_t dryrun = B_FALSE;
	int c;
	nvlist_t *nvroot;
	char *poolname;
	int ret;
	zpool_handle_t *zhp;
	nvlist_t *config;
	while ((c = getopt(argc, argv, "fn")) != -1) {
		switch (c) {
		case 'f':
			force = B_TRUE;
			break;
		case 'n':
			dryrun = B_TRUE;
			break;
		case '?':
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
			    optopt);
			usage(B_FALSE);
		}
	}
	argc -= optind;
	argv += optind;
	if (argc < 1) {
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
		usage(B_FALSE);
	}
	if (argc < 2) {
		(void) fprintf(stderr, gettext("missing vdev specification\n"));
		usage(B_FALSE);
	}
	poolname = argv[0];
	argc--;
	argv++;
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
		return (1);
	if ((config = zpool_get_config(zhp, NULL)) == NULL) {
		(void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
		    poolname);
		zpool_close(zhp);
		return (1);
	}
	nvroot = make_root_vdev(zhp, force, !force, B_FALSE, dryrun,
	    argc, argv);
	if (nvroot == NULL) {
		zpool_close(zhp);
		return (1);
	}
	if (dryrun) {
		nvlist_t *poolnvroot;
		verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
		    &poolnvroot) == 0);
		(void) printf(gettext("would update '%s' to the following "
		    "configuration:\n"), zpool_get_name(zhp));
		print_vdev_tree(zhp, poolname, poolnvroot, 0, B_FALSE);
		print_vdev_tree(zhp, NULL, nvroot, 0, B_FALSE);
		if (num_logs(poolnvroot) > 0) {
			print_vdev_tree(zhp, "logs", poolnvroot, 0, B_TRUE);
			print_vdev_tree(zhp, NULL, nvroot, 0, B_TRUE);
		} else if (num_logs(nvroot) > 0) {
			print_vdev_tree(zhp, "logs", nvroot, 0, B_TRUE);
		}
		ret = 0;
	} else {
		ret = (zpool_add(zhp, nvroot) != 0);
	}
	nvlist_free(nvroot);
	zpool_close(zhp);
	return (ret);
}
int zpool_do_add ( int argc , char * * argv ) { boolean_t force = B_FALSE ; boolean_t dryrun = B_FALSE ; int c ; nvlist_t * nvroot ; char * poolname ; int ret ; zpool_handle_t * zhp ; nvlist_t * config ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : force = B_TRUE ; break ; case ' ' : dryrun = B_TRUE ; break ; case ' ' : ( void ) fprintf ( stderr , gettext ( " \n " ) , optopt ) ; usage ( B_FALSE ) ; } } argc -= optind ; argv += optind ; if ( argc < 1 ) { ( void ) fprintf ( stderr , gettext ( " \n " ) ) ; usage ( B_FALSE ) ; } if ( argc < 2 ) { ( void ) fprintf ( stderr , gettext ( " \n " ) ) ; usage ( B_FALSE ) ; } poolname = argv [ 0 ] ; argc -- ; argv ++ ; if ( ( zhp = zpool_open ( g_zfs , poolname ) ) == NULL ) return ( 1 ) ; if ( ( config = zpool_get_config ( zhp , NULL ) ) == NULL ) { ( void ) fprintf ( stderr , gettext ( " \n " ) , poolname ) ; zpool_close ( zhp ) ; return ( 1 ) ; } nvroot = make_root_vdev ( zhp , force , ! force , B_FALSE , dryrun , argc , argv ) ; if ( nvroot == NULL ) { zpool_close ( zhp ) ; return ( 1 ) ; } if ( dryrun ) { nvlist_t * poolnvroot ; verify ( nvlist_lookup_nvlist ( config , ZPOOL_CONFIG_VDEV_TREE , & poolnvroot ) == 0 ) ; ( void ) printf ( gettext ( " " " \n " ) , zpool_get_name ( zhp ) ) ; print_vdev_tree ( zhp , poolname , poolnvroot , 0 , B_FALSE ) ; print_vdev_tree ( zhp , NULL , nvroot , 0 , B_FALSE ) ; if ( num_logs ( poolnvroot ) > 0 ) { print_vdev_tree ( zhp , " " , poolnvroot , 0 , B_TRUE ) ; print_vdev_tree ( zhp , NULL , nvroot , 0 , B_TRUE ) ; } else if ( num_logs ( nvroot ) > 0 ) { print_vdev_tree ( zhp , " " , nvroot , 0 , B_TRUE ) ; } ret = 0 ; } else { ret = ( zpool_add ( zhp , nvroot ) != 0 ) ; } nvlist_free ( nvroot ) ; zpool_close ( zhp ) ; return ( ret ) ; }
zpool add [-fn] <pool> <vdev> ...
      -f      Force addition of devices, even if they appear in use
      -n      Do not add the devices, but display the resulting layout if
              they were to be added.
zpool add [ - fn ] <pool > <vdev > ... - f Force addition of devices even if they appear in use - n Do not add the devices but display the resulting layout if they were to be added .
/* check options */ /* get pool name and check number of arguments */ /* pass off to get_vdev_spec for processing */ /* print original main pool and new tree */ /* Do the same for the logs */