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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
GlusterFS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include <inttypes.h>
#include "globals.h"
#include "glusterfs.h"
#include "compat.h"
#include "dict.h"
#include "protocol-common.h"
#include "xlator.h"
#include "logging.h"
#include "timer.h"
#include "defaults.h"
#include "compat.h"
#include "compat-errno.h"
#include "statedump.h"
#include "glusterd-mem-types.h"
#include "glusterd.h"
#include "glusterd-sm.h"
#include "glusterd-op-sm.h"
#include "glusterd-utils.h"
#include "glusterd-ha.h"
#include "glusterd1.h"
#include "cli1.h"
#include "rpc-clnt.h"
#include <sys/resource.h>
#include <inttypes.h>
#include <dirent.h>
int32_t
glusterd_ha_create_volume (glusterd_volinfo_t *volinfo)
{
char pathname[PATH_MAX] = {0,};
int32_t ret = -1;
char filepath[PATH_MAX] = {0,};
char buf[4096] = {0,};
int fd = -1;
glusterd_conf_t *priv = NULL;
GF_ASSERT (volinfo);
priv = THIS->private;
GF_ASSERT (priv);
snprintf (pathname, 1024, "%s/vols/%s", priv->workdir,
volinfo->volname);
ret = mkdir (pathname, 0x777);
if (-1 == ret) {
gf_log ("", GF_LOG_ERROR, "mkdir() failed on path %s,"
"errno: %d", pathname, errno);
goto out;
}
snprintf (filepath, 1024, "%s/info", pathname);
fd = open (filepath, O_RDWR | O_CREAT | O_APPEND, 0644);
if (-1 == fd) {
gf_log ("", GF_LOG_ERROR, "open() failed on path %s,"
"errno: %d", filepath, errno);
ret = -1;
goto out;
}
snprintf (buf, 4096, "type=%d\n", volinfo->type);
ret = write (fd, buf, strlen (buf));
snprintf (buf, 4096, "count=%d\n", volinfo->brick_count);
ret = write (fd, buf, strlen (buf));
close (fd);
ret = 0;
out:
if (ret) {
glusterd_ha_delete_volume (volinfo);
}
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
int32_t
glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo)
{
char pathname[PATH_MAX] = {0,};
int32_t ret = -1;
glusterd_conf_t *priv = NULL;
DIR *dir = NULL;
struct dirent *entry = NULL;
char path[PATH_MAX] = {0,};
GF_ASSERT (volinfo);
priv = THIS->private;
GF_ASSERT (priv);
snprintf (pathname, 1024, "%s/vols/%s", priv->workdir,
volinfo->volname);
dir = opendir (pathname);
if (!dir)
goto out;
entry = readdir (dir);
while (entry != NULL) {
if (!strcmp (entry->d_name, ".") ||
!strcmp (entry->d_name, "..")) {
entry = readdir (dir);
continue;
}
snprintf (path, PATH_MAX, "%s/%s", pathname, entry->d_name);
if (DT_DIR == entry->d_type)
ret = rmdir (path);
else
ret = unlink (path);
gf_log ("", GF_LOG_NORMAL, "%s %s",
ret?"Failed to remove":"Removed",
entry->d_name);
if (ret)
gf_log ("", GF_LOG_NORMAL, "errno:%d", errno);
entry = readdir (dir);
memset (path, 0, sizeof(path));
}
ret = closedir (dir);
if (ret) {
gf_log ("", GF_LOG_NORMAL, "Failed to close dir, errno:%d",
errno);
}
ret = rmdir (pathname);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Failed to rmdir: %s, errno: %d",
pathname, errno);
}
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
|