FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * zpool clear <pool> [device]
 *
 * Clear all errors associated with a pool or a particular device.
 */
zpool clear  [device]
Clear all errors associated with a pool or a particular device.
zpool clear [ device ] Clear all errors associated with a pool or a particular device .
int
zpool_do_clear(int argc, char **argv)
{
	int c;
	int ret = 0;
	boolean_t dryrun = B_FALSE;
	boolean_t do_rewind = B_FALSE;
	boolean_t xtreme_rewind = B_FALSE;
	uint32_t rewind_policy = ZPOOL_NO_REWIND;
	nvlist_t *policy = NULL;
	zpool_handle_t *zhp;
	char *pool, *device;
	while ((c = getopt(argc, argv, "FnX")) != -1) {
		switch (c) {
		case 'F':
			do_rewind = B_TRUE;
			break;
		case 'n':
			dryrun = B_TRUE;
			break;
		case 'X':
			xtreme_rewind = 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\n"));
		usage(B_FALSE);
	}
	if (argc > 2) {
		(void) fprintf(stderr, gettext("too many arguments\n"));
		usage(B_FALSE);
	}
	if ((dryrun || xtreme_rewind) && !do_rewind) {
		(void) fprintf(stderr,
		    gettext("-n or -X only meaningful with -F\n"));
		usage(B_FALSE);
	}
	if (dryrun)
		rewind_policy = ZPOOL_TRY_REWIND;
	else if (do_rewind)
		rewind_policy = ZPOOL_DO_REWIND;
	if (xtreme_rewind)
		rewind_policy |= ZPOOL_EXTREME_REWIND;
	if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
	    nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0)
		return (1);
	pool = argv[0];
	device = argc == 2 ? argv[1] : NULL;
	if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
		nvlist_free(policy);
		return (1);
	}
	if (zpool_clear(zhp, device, policy) != 0)
		ret = 1;
	zpool_close(zhp);
	nvlist_free(policy);
	return (ret);
}
int zpool_do_clear ( int argc , char * * argv ) { int c ; int ret = 0 ; boolean_t dryrun = B_FALSE ; boolean_t do_rewind = B_FALSE ; boolean_t xtreme_rewind = B_FALSE ; uint32_t rewind_policy = ZPOOL_NO_REWIND ; nvlist_t * policy = NULL ; zpool_handle_t * zhp ; char * pool , * device ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : do_rewind = B_TRUE ; break ; case ' ' : dryrun = B_TRUE ; break ; case ' ' : xtreme_rewind = 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 ) ; } if ( ( dryrun || xtreme_rewind ) && ! do_rewind ) { ( void ) fprintf ( stderr , gettext ( " \n " ) ) ; usage ( B_FALSE ) ; } if ( dryrun ) rewind_policy = ZPOOL_TRY_REWIND ; else if ( do_rewind ) rewind_policy = ZPOOL_DO_REWIND ; if ( xtreme_rewind ) rewind_policy |= ZPOOL_EXTREME_REWIND ; if ( nvlist_alloc ( & policy , NV_UNIQUE_NAME , 0 ) != 0 || nvlist_add_uint32 ( policy , ZPOOL_REWIND_REQUEST , rewind_policy ) != 0 ) return ( 1 ) ; pool = argv [ 0 ] ; device = argc == 2 ? argv [ 1 ] : NULL ; if ( ( zhp = zpool_open_canfail ( g_zfs , pool ) ) == NULL ) { nvlist_free ( policy ) ; return ( 1 ) ; } if ( zpool_clear ( zhp , device , policy ) != 0 ) ret = 1 ; zpool_close ( zhp ) ; nvlist_free ( policy ) ; return ( ret ) ; }
zpool clear <pool> [device]
 Clear all errors associated with a pool or a particular device.
zpool clear <pool > [ device ] Clear all errors associated with a pool or a particular device .
/* check options */ /* In future, further rewind policy choices can be passed along here */