summaryrefslogtreecommitdiffstats
path: root/tests/bugs/posix/disallow-gfid-volumeid-fremovexattr.c
blob: 4ed3181d48f211e449a2b4e3345d61595993b38c (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <glusterfs/api/glfs.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
    glfs_t *fs = NULL;
    int ret = 0;
    int i = 0;
    glfs_fd_t *fd = NULL;
    char *logfile = NULL;
    char *hostname = NULL;

    if (argc != 4) {
        fprintf(stderr,
                "Expect following args %s <hostname> <Vol> <log file>\n",
                argv[0]);
        return -1;
    }

    hostname = argv[1];
    logfile = argv[3];

    fs = glfs_new(argv[2]);
    if (!fs) {
        fprintf(stderr, "glfs_new: returned NULL (%s)\n", strerror(errno));
        return -1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
    if (ret < 0) {
        fprintf(stderr, "glfs_set_volfile_server failed ret:%d (%s)\n", ret,
                strerror(errno));
        return -1;
    }

    ret = glfs_set_logging(fs, logfile, 7);
    if (ret < 0) {
        fprintf(stderr, "glfs_set_logging failed with ret: %d (%s)\n", ret,
                strerror(errno));
        return -1;
    }

    ret = glfs_init(fs);
    if (ret < 0) {
        fprintf(stderr, "glfs_init failed with ret: %d (%s)\n", ret,
                strerror(errno));
        return -1;
    }

    fd = glfs_opendir(fs, "/");
    if (!fd) {
        fprintf(stderr, "glfs_opendir failed with (%s)\n", strerror(errno));
        return -1;
    }

    ret = glfs_fremovexattr(fd, "trusted.gfid");
    if (ret == 0 || errno != EPERM) {
        fprintf(stderr,
                "glfs_fremovexattr gfid exited with ret: "
                "%d (%s)\n",
                ret, strerror(errno));
        return -1;
    }

    ret = glfs_fremovexattr(fd, "trusted.glusterfs.volume-id");
    if (ret == 0 || errno != EPERM) {
        fprintf(stderr,
                "glfs_fremovexattr volume-id exited with ret: "
                "%d (%s)\n",
                ret, strerror(errno));
        return -1;
    }

    ret = glfs_fsetxattr(fd, "trusted.abc", "abc", 3, 0);
    if (ret < 0) {
        fprintf(stderr,
                "glfs_fsetxattr trusted.abc exited with ret: "
                "%d (%s)\n",
                ret, strerror(errno));
        return -1;
    }

    ret = glfs_fremovexattr(fd, "trusted.abc");
    if (ret < 0) {
        fprintf(stderr,
                "glfs_fremovexattr trusted.abc exited with "
                "ret: %d (%s)\n",
                ret, strerror(errno));
        return -1;
    }

    (void)glfs_closedir(fd);
    ret = glfs_fini(fs);
    if (ret < 0) {
        fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
                strerror(errno));
        return -1;
    }
    return 0;
}