Blame libopeniscsiusr/tests/test_node.c

Packit eace71
/*
Packit eace71
 * Copyright (C) 2017 Red Hat, Inc.
Packit eace71
 *
Packit eace71
 * This program is free software: you can redistribute it and/or modify
Packit eace71
 * it under the terms of the GNU General Public License as published by
Packit eace71
 * the Free Software Foundation, either version 3 of the License, or
Packit eace71
 * (at your option) any later version.
Packit eace71
 *
Packit eace71
 * This program is distributed in the hope that it will be useful,
Packit eace71
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit eace71
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit eace71
 * GNU General Public License for more details.
Packit eace71
 *
Packit eace71
 * You should have received a copy of the GNU General Public License
Packit eace71
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit eace71
 *
Packit eace71
 * Author: Gris Ge <fge@redhat.com>
Packit eace71
 */
Packit eace71
#include <stdlib.h>
Packit eace71
#include <stdio.h>
Packit eace71
#include <assert.h>
Packit eace71
#include <inttypes.h>
Packit eace71
Packit eace71
#include <libopeniscsiusr/libopeniscsiusr.h>
Packit eace71
Packit eace71
int main()
Packit eace71
{
Packit eace71
	struct iscsi_context *ctx = NULL;
Packit eace71
	struct iscsi_node **nodes = NULL;
Packit eace71
	uint32_t node_count = 0;
Packit eace71
	uint32_t i = 0;
Packit eace71
	const char *dump = NULL;
Packit eace71
	int rc = EXIT_SUCCESS;
Packit eace71
Packit eace71
	ctx = iscsi_context_new();
Packit eace71
	iscsi_context_log_priority_set(ctx, LIBISCSI_LOG_PRIORITY_DEBUG);
Packit eace71
Packit eace71
	if (iscsi_nodes_get(ctx, &nodes, &node_count) != LIBISCSI_OK) {
Packit eace71
		printf("FAILED\n");
Packit eace71
		rc = EXIT_FAILURE;
Packit eace71
	} else {
Packit eace71
		printf("\nGot %" PRIu32 " iSCSI nodes\n", node_count);
Packit eace71
		for (i = 0; i < node_count; ++i) {
Packit eace71
			dump = iscsi_node_dump_config(nodes[i], true);
Packit eace71
			assert(dump != NULL);
Packit eace71
			free((void *) dump);
Packit eace71
			iscsi_node_print_config(nodes[i], true);
Packit eace71
		}
Packit eace71
		iscsi_nodes_free(nodes, node_count);
Packit eace71
	}
Packit eace71
	iscsi_context_free(ctx);
Packit eace71
	exit(rc);
Packit eace71
}