FreeBSD/cddl/contrib/opensolaris/cmd/zinject/zinject.c
/*
 * Register a new fault injection handler.
 */
Register a new fault injection handler.
Register a new fault injection handler .
static int
register_handler(const char *pool, int flags, zinject_record_t *record,
    int quiet)
{
	zfs_cmd_t zc = { 0 };
	(void) strcpy(zc.zc_name, pool);
	zc.zc_inject_record = *record;
	zc.zc_guid = flags;
	if (ioctl(zfs_fd, ZFS_IOC_INJECT_FAULT, &zc) != 0) {
		(void) fprintf(stderr, "failed to add handler: %s\n",
		    strerror(errno));
		return (1);
	}
	if (flags & ZINJECT_NULL)
		return (0);
	if (quiet) {
		(void) printf("%llu\n", (u_longlong_t)zc.zc_guid);
	} else {
		(void) printf("Added handler %llu with the following "
		    "properties:\n", (u_longlong_t)zc.zc_guid);
		(void) printf("  pool: %s\n", pool);
		if (record->zi_guid) {
			(void) printf("  vdev: %llx\n",
			    (u_longlong_t)record->zi_guid);
		} else if (record->zi_func[0] != '\0') {
			(void) printf("  panic function: %s\n",
			    record->zi_func);
		} else if (record->zi_duration > 0) {
			(void) printf(" time: %lld seconds\n",
			    (u_longlong_t)record->zi_duration);
		} else if (record->zi_duration < 0) {
			(void) printf(" txgs: %lld \n",
			    (u_longlong_t)-record->zi_duration);
		} else {
			(void) printf("objset: %llu\n",
			    (u_longlong_t)record->zi_objset);
			(void) printf("object: %llu\n",
			    (u_longlong_t)record->zi_object);
			(void) printf("  type: %llu\n",
			    (u_longlong_t)record->zi_type);
			(void) printf(" level: %d\n", record->zi_level);
			if (record->zi_start == 0 &&
			    record->zi_end == -1ULL)
				(void) printf(" range: all\n");
			else
				(void) printf(" range: [%llu, %llu)\n",
				    (u_longlong_t)record->zi_start,
				    (u_longlong_t)record->zi_end);
		}
	}
	return (0);
}
static int register_handler ( const char * pool , int flags , zinject_record_t * record , int quiet ) { zfs_cmd_t zc = { 0 } ; ( void ) strcpy ( zc . zc_name , pool ) ; zc . zc_inject_record = * record ; zc . zc_guid = flags ; if ( ioctl ( zfs_fd , ZFS_IOC_INJECT_FAULT , & zc ) != 0 ) { ( void ) fprintf ( stderr , " \n " , strerror ( errno ) ) ; return ( 1 ) ; } if ( flags & ZINJECT_NULL ) return ( 0 ) ; if ( quiet ) { ( void ) printf ( " \n " , ( u_longlong_t ) zc . zc_guid ) ; } else { ( void ) printf ( " " " \n " , ( u_longlong_t ) zc . zc_guid ) ; ( void ) printf ( " \n " , pool ) ; if ( record -> zi_guid ) { ( void ) printf ( " \n " , ( u_longlong_t ) record -> zi_guid ) ; } else if ( record -> zi_func [ 0 ] != ' \0 ' ) { ( void ) printf ( " \n " , record -> zi_func ) ; } else if ( record -> zi_duration > 0 ) { ( void ) printf ( " \n " , ( u_longlong_t ) record -> zi_duration ) ; } else if ( record -> zi_duration < 0 ) { ( void ) printf ( " \n " , ( u_longlong_t ) - record -> zi_duration ) ; } else { ( void ) printf ( " \n " , ( u_longlong_t ) record -> zi_objset ) ; ( void ) printf ( " \n " , ( u_longlong_t ) record -> zi_object ) ; ( void ) printf ( " \n " , ( u_longlong_t ) record -> zi_type ) ; ( void ) printf ( " \n " , record -> zi_level ) ; if ( record -> zi_start == 0 && record -> zi_end == -1ULL ) ( void ) printf ( " \n " ) ; else ( void ) printf ( " \n " , ( u_longlong_t ) record -> zi_start , ( u_longlong_t ) record -> zi_end ) ; } } return ( 0 ) ; }
Register a new fault injection handler.
Register a new fault injection handler .