forked from vbellur/gfid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgfid-unlink.c
81 lines (61 loc) · 2.31 KB
/
gfid-unlink.c
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
/*
* Author: Thong Nguyen ([email protected])
*
*
* gfid-unlink: Take a text file with a list of gfids and deletes the links from the
* hidden .glusterfs directory
*
* This program also logs the success or failure of deleting on each
* file to stderr.
*/
#include <sys/xattr.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <ftw.h>
#define GLUSTER_GFID_KEY "trusted.gfid"
#define GLUSTER_GFID_SIZE 16
#define PATH_FORMAT_STR "./%c%c/%c%c/%c%c%c%c%c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c%c%c%c%c%c%c%c%c"
#define PATH_VALUE_STR(v) v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16], v[17], v[18], v[19], v[20], v[21], v[22], v[23], v[24], v[25], v[26], v[27], v[28], v[29], v[30], v[31]
void usage (char *str)
{
fprintf (stderr, "Usage: %s /path/to/brick_mismatch_gfid_list\n", str);
fprintf (stderr, "\nMake sure you cd into the .glusterfs directory first and then run:\n\n# %s /path/to/brick_mismatch_gfid_list\n\n", str);
}
void gfid_unlink (FILE *master_list)
{
char line[4096];
char path[4096];
unsigned char gfid[GLUSTER_GFID_SIZE];
int ret = -1;
while ((fgets (line, 4096, master_list)) != NULL) {
int error = 0;
char *error_str = NULL;
if (!((line[0] >= 'a' && line[0] <= 'f') || (line[0] >= '0' && line[0] <= '9'))) continue;
line[32] = '\0';
sprintf(path, PATH_FORMAT_STR, line[0], line[1], line[2], line[3], PATH_VALUE_STR(line));
ret = unlink(path);
if (ret == -1) {
fprintf (stderr, "%s: %s\n", path, strerror(errno));
} else {
fprintf (stderr, "%s: unlinked OK\n", path);
}
}
}
int main (int argc, char **argv)
{
FILE *master_list = NULL;
if (argc != 2) {
usage (argv[0]);
return 1;
}
master_list = fopen (argv[1], "r");
if (master_list == NULL) {
fprintf (stderr, "Could not open brick mismatched gfid list: %s\n", strerror (errno));
return 1;
}
gfid_unlink (master_list);
return 0;
}