summaryrefslogtreecommitdiffstats
path: root/tests/basic/gfapi/gfapi-load-volfile.c
blob: 79502f7a44f6c93d0838a6a58f90be02b1aba880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Create a glfs instance based on a .vol file
 *
 * This is used to measure memory leaks by initializing a graph through a .vol
 * file and destroying it again.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <glusterfs/api/glfs.h>

#define PROGNAME "gfapi-load-volfile"

void
usage(FILE *output)
{
	fprintf(output, "Usage: " PROGNAME " <volfile>\n");
}

void
main(int argc, char **argv)
{
	int ret = 0;
	glfs_t *fs = NULL;

	if (argc != 2) {
		usage(stderr);
		exit(EXIT_FAILURE);
	}

	if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-h")) {
		usage(stdout);
		exit(EXIT_SUCCESS);
	}

	fs = glfs_new(PROGNAME);
	if (!fs) {
		perror("glfs_new failed");
		exit(EXIT_FAILURE);
	}

	glfs_set_logging(fs, PROGNAME ".log", 9);

	ret = glfs_set_volfile(fs, argv[1]);
	if (ret) {
		perror("glfs_set_volfile failed");
		ret = EXIT_FAILURE;
		goto out;
	}

	ret = glfs_init(fs);
	if (ret) {
		perror("glfs_init failed");
		ret = EXIT_FAILURE;
		goto out;
	}

	ret = EXIT_SUCCESS;
out:
	glfs_fini(fs);

	exit(ret);
}