13
#include <glusterfs/glusterfs.h>
14
#include <glusterfs/compat.h>
15
#include <glusterfs/dict.h>
16
#include <glusterfs/logging.h>
17
#include <glusterfs/timer.h>
18
#include <glusterfs/syscall.h>
19
#include <glusterfs/compat.h>
20
#include <glusterfs/compat-errno.h>
21
#include <glusterfs/statedump.h>
22
#include "glusterd-mem-types.h"
24
#include "glusterd-sm.h"
25
#include "glusterd-op-sm.h"
26
#include "glusterd-utils.h"
27
#include "glusterd-hooks.h"
28
#include "glusterd-store.h"
29
#include "glusterd-snapshot-utils.h"
30
#include "glusterd-messages.h"
33
#include <glusterfs/common-utils.h>
34
#include <glusterfs/quota-common-utils.h>
39
#if defined(GF_LINUX_HOST_OS)
42
#include "mntent_compat.h"
45
#define GLUSTERD_GET_BRICK_DIR(path, volinfo, priv) \
48
if (volinfo->is_snap_volume) { \
49
_brick_len = snprintf(path, PATH_MAX, "%s/snaps/%s/%s/%s", \
50
priv->workdir, volinfo->snapshot->snapname, \
51
volinfo->volname, GLUSTERD_BRICK_INFO_DIR); \
53
_brick_len = snprintf(path, PATH_MAX, "%s/%s/%s/%s", \
54
priv->workdir, GLUSTERD_VOLUME_DIR_PREFIX, \
55
volinfo->volname, GLUSTERD_BRICK_INFO_DIR); \
57
if ((_brick_len < 0) || (_brick_len >= PATH_MAX)) { \
63
glusterd_replace_slash_with_hyphen(char *str)
67
ptr = strchr(str, '/');
71
ptr = strchr(ptr, '/');
76
glusterd_store_create_brick_dir(glusterd_volinfo_t *volinfo)
79
char brickdirpath[PATH_MAX] = {
82
glusterd_conf_t *priv = NULL;
89
GLUSTERD_GET_BRICK_DIR(brickdirpath, volinfo, priv);
90
ret = gf_store_mkdir(brickdirpath);
96
glusterd_store_key_vol_brick_set(glusterd_brickinfo_t *brickinfo,
97
char *key_vol_brick, size_t len)
100
GF_ASSERT(key_vol_brick);
101
GF_ASSERT(len >= PATH_MAX);
103
snprintf(key_vol_brick, len, "%s", brickinfo->path);
104
glusterd_replace_slash_with_hyphen(key_vol_brick);
108
glusterd_store_brickinfofname_set(glusterd_brickinfo_t *brickinfo,
109
char *brickfname, size_t len)
111
char key_vol_brick[PATH_MAX] = {0};
113
GF_ASSERT(brickfname);
114
GF_ASSERT(brickinfo);
115
GF_ASSERT(len >= PATH_MAX);
117
glusterd_store_key_vol_brick_set(brickinfo, key_vol_brick,
118
sizeof(key_vol_brick));
119
ret = snprintf(brickfname, len, "%s:%s", brickinfo->hostname,
121
if (ret < 0 || ret >= len)
127
glusterd_store_brickinfopath_set(glusterd_volinfo_t *volinfo,
128
glusterd_brickinfo_t *brickinfo,
129
char *brickpath, size_t len)
131
char brickfname[PATH_MAX] = {0};
132
char brickdirpath[PATH_MAX] = {
135
glusterd_conf_t *priv = NULL;
137
GF_ASSERT(brickpath);
138
GF_ASSERT(brickinfo);
139
GF_ASSERT(len >= PATH_MAX);
141
priv = THIS->private;
144
GLUSTERD_GET_BRICK_DIR(brickdirpath, volinfo, priv);
145
ret = glusterd_store_brickinfofname_set(brickinfo, brickfname,
149
ret = snprintf(brickpath, len, "%s/%s", brickdirpath, brickfname);
150
if (ret < 0 || ret >= len)
156
glusterd_store_snapd_path_set(glusterd_volinfo_t *volinfo, char *snapd_path,
159
char volpath[PATH_MAX] = {
162
glusterd_conf_t *priv = NULL;
165
GF_ASSERT(len >= PATH_MAX);
167
priv = THIS->private;
170
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv);
172
ret = snprintf(snapd_path, len, "%s/snapd.info", volpath);
173
if (ret < 0 || ret >= len)
179
glusterd_store_is_valid_brickpath(char *volname, char *brick)
181
glusterd_brickinfo_t *brickinfo = NULL;
182
glusterd_volinfo_t *volinfo = NULL;
184
size_t volname_len = strlen(volname);
186
const char delim[2] = "/";
187
char *sub_dir = NULL;
188
char *saveptr = NULL;
189
char *brickpath_ptr = NULL;
191
ret = glusterd_brickinfo_new_from_brick(brick, &brickinfo, _gf_false, NULL);
193
gf_msg(THIS->name, GF_LOG_WARNING, 0, GD_MSG_BRICK_CREATION_FAIL,
194
"Failed to create brick "
200
ret = glusterd_volinfo_new(&volinfo);
202
gf_msg(THIS->name, GF_LOG_WARNING, 0, GD_MSG_VOLFILE_CREATE_FAIL,
203
"Failed to create volinfo");
207
if (volname_len >= sizeof(volinfo->volname)) {
208
gf_msg(THIS->name, GF_LOG_WARNING, 0, GD_MSG_NAME_TOO_LONG,
209
"volume name too long");
213
memcpy(volinfo->volname, volname, volname_len + 1);
217
bpath_len = strlen(brickinfo->path);
219
if (brickinfo->path[bpath_len - 1] != '/') {
220
if (bpath_len >= PATH_MAX) {
228
if (bpath_len >= PATH_MAX + 1) {
238
brickpath_ptr = brickinfo->path;
239
sub_dir = strtok_r(brickpath_ptr, delim, &saveptr);
241
while (sub_dir != NULL) {
242
if (strlen(sub_dir) >= _POSIX_PATH_MAX) {
246
sub_dir = strtok_r(NULL, delim, &saveptr);
251
glusterd_brickinfo_delete(brickinfo);
253
glusterd_volinfo_unref(volinfo);
259
glusterd_store_volinfo_brick_fname_write(int vol_fd,
260
glusterd_brickinfo_t *brickinfo,
267
char brickfname[PATH_MAX] = {
272
if (!is_thin_arbiter) {
273
snprintf(key, sizeof(key), "%s-%d", GLUSTERD_STORE_KEY_VOL_BRICK,
276
snprintf(key, sizeof(key), "%s-%d", GLUSTERD_STORE_KEY_VOL_TA_BRICK,
279
ret = glusterd_store_brickinfofname_set(brickinfo, brickfname,
283
ret = gf_store_save_value(vol_fd, key, brickfname);
288
glusterd_store_create_brick_shandle_on_absence(glusterd_volinfo_t *volinfo,
289
glusterd_brickinfo_t *brickinfo)
291
char brickpath[PATH_MAX] = {
297
GF_ASSERT(brickinfo);
299
ret = glusterd_store_brickinfopath_set(volinfo, brickinfo, brickpath,
303
ret = gf_store_handle_create_on_absence(&brickinfo->shandle, brickpath);
308
glusterd_store_create_snapd_shandle_on_absence(glusterd_volinfo_t *volinfo)
310
char snapd_path[PATH_MAX] = {
317
ret = glusterd_store_snapd_path_set(volinfo, snapd_path,
321
ret = gf_store_handle_create_on_absence(&volinfo->snapd.handle, snapd_path);
331
gd_store_brick_snap_details_write(int fd, glusterd_brickinfo_t *brickinfo)
334
xlator_t *this = THIS;
335
char value[5 * PATH_MAX];
338
GF_VALIDATE_OR_GOTO(this->name, (fd > 0), out);
339
GF_VALIDATE_OR_GOTO(this->name, (brickinfo != NULL), out);
341
if (brickinfo->origin_path[0] != '\0') {
342
ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n",
343
GLUSTERD_STORE_KEY_BRICK_ORIGIN_PATH,
344
brickinfo->origin_path);
345
if (ret < 0 || ret >= sizeof(value) - total_len) {
352
if (brickinfo->mount_dir[0] != '\0') {
353
ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n",
354
GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR,
355
brickinfo->mount_dir);
356
if (ret < 0 || ret >= sizeof(value) - total_len) {
363
if (brickinfo->fstype[0] != '\0') {
364
ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n",
365
GLUSTERD_STORE_KEY_BRICK_FSTYPE, brickinfo->fstype);
366
if (ret < 0 || ret >= sizeof(value) - total_len) {
373
if (strlen(brickinfo->snap_type) > 0) {
374
ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n",
375
GLUSTERD_STORE_KEY_BRICK_SNAPTYPE, brickinfo->snap_type);
376
if (ret < 0 || ret >= sizeof(value) - total_len) {
383
if (brickinfo->mnt_opts[0] != '\0') {
384
ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n",
385
GLUSTERD_STORE_KEY_BRICK_MNTOPTS, brickinfo->mnt_opts);
386
if (ret < 0 || ret >= sizeof(value) - total_len) {
393
ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%d\n",
394
GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS,
395
brickinfo->snap_status);
396
if (ret < 0 || ret >= sizeof(value) - total_len) {
402
ret = snprintf(value + total_len, sizeof(value) - total_len,
403
"%s=%" PRIu64 "\n", GLUSTERD_STORE_KEY_BRICK_FSID,
404
brickinfo->statfs_fsid);
405
if (ret < 0 || ret >= sizeof(value) - total_len) {
410
ret = gf_store_save_items(fd, value);
413
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_FS_LABEL_UPDATE_FAIL,
415
"snap detils of brick %s",
423
glusterd_store_brickinfo_write(int fd, glusterd_brickinfo_t *brickinfo)
425
char value[5 * PATH_MAX];
428
GF_ASSERT(brickinfo);
431
ret = snprintf(value, sizeof(value),
432
"%s=%s\n%s=%s\n%s=%s\n%s=%s\n%s=%d\n%s=%d\n%s=%d\n%s=%s\n",
433
GLUSTERD_STORE_KEY_BRICK_UUID, uuid_utoa(brickinfo->uuid),
434
GLUSTERD_STORE_KEY_BRICK_HOSTNAME, brickinfo->hostname,
435
GLUSTERD_STORE_KEY_BRICK_PATH, brickinfo->path,
436
GLUSTERD_STORE_KEY_BRICK_REAL_PATH, brickinfo->path,
437
GLUSTERD_STORE_KEY_BRICK_PORT, brickinfo->port,
438
GLUSTERD_STORE_KEY_BRICK_RDMA_PORT, brickinfo->rdma_port,
439
GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED,
440
brickinfo->decommissioned, GLUSTERD_STORE_KEY_BRICK_ID,
441
brickinfo->brick_id);
443
if (ret < 0 || ret >= sizeof(value)) {
448
ret = gf_store_save_items(fd, value);
452
ret = gd_store_brick_snap_details_write(fd, brickinfo);
456
if (!brickinfo->vg[0])
459
ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_VGNAME,
462
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
467
glusterd_store_snapd_write(int fd, glusterd_volinfo_t *volinfo)
473
xlator_t *this = THIS;
478
snprintf(value, sizeof(value), "%d", volinfo->snapd.port);
479
ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAPD_PORT, value);
481
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_PORT_STORE_FAIL,
482
"failed to store the snapd "
486
gf_msg_debug(this->name, 0, "Returning %d", ret);
491
glusterd_store_perform_brick_store(glusterd_brickinfo_t *brickinfo)
495
GF_ASSERT(brickinfo);
497
fd = gf_store_mkstemp(brickinfo->shandle);
502
ret = glusterd_store_brickinfo_write(fd, brickinfo);
507
if (ret && (fd > 0)) {
508
gf_store_unlink_tmppath(brickinfo->shandle);
510
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
515
glusterd_store_perform_snapd_store(glusterd_volinfo_t *volinfo)
519
xlator_t *this = THIS;
523
fd = gf_store_mkstemp(volinfo->snapd.handle);
525
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
526
"failed to create the "
527
"temporary file for the snapd store handle of volume "
533
ret = glusterd_store_snapd_write(fd, volinfo);
535
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_PORT_STORE_FAIL,
536
"failed to write snapd port "
537
"info to store handle (volume: %s",
542
ret = gf_store_rename_tmppath(volinfo->snapd.handle);
546
gf_store_unlink_tmppath(volinfo->snapd.handle);
547
gf_msg_debug(this->name, 0, "Returning %d", ret);
552
glusterd_store_brickinfo(glusterd_volinfo_t *volinfo,
553
glusterd_brickinfo_t *brickinfo, int32_t brick_count,
554
int vol_fd, int is_thin_arbiter)
559
GF_ASSERT(brickinfo);
561
ret = glusterd_store_volinfo_brick_fname_write(
562
vol_fd, brickinfo, brick_count, is_thin_arbiter);
566
ret = glusterd_store_create_brick_shandle_on_absence(volinfo, brickinfo);
570
ret = glusterd_store_perform_brick_store(brickinfo);
572
gf_msg_debug(THIS->name, 0, "Returning with %d", ret);
577
glusterd_store_snapd_info(glusterd_volinfo_t *volinfo)
580
xlator_t *this = THIS;
584
ret = glusterd_store_create_snapd_shandle_on_absence(volinfo);
586
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_CREATE_FAIL,
587
"failed to create store "
588
"handle for snapd (volume: %s)",
593
ret = glusterd_store_perform_snapd_store(volinfo);
595
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_INFO_STORE_FAIL,
596
"failed to store snapd info "
602
gf_store_unlink_tmppath(volinfo->snapd.handle);
604
gf_msg_debug(this->name, 0, "Returning with %d", ret);
609
glusterd_store_delete_brick(glusterd_brickinfo_t *brickinfo, char *delete_path)
612
glusterd_conf_t *priv = NULL;
613
char brickpath[PATH_MAX] = {
617
char *tmppath = NULL;
618
xlator_t *this = THIS;
620
GF_ASSERT(brickinfo);
622
priv = this->private;
625
tmppath = gf_strdup(brickinfo->path);
627
ptr = strchr(tmppath, '/');
631
ptr = strchr(tmppath, '/');
634
snprintf(brickpath, sizeof(brickpath),
635
"%s/" GLUSTERD_BRICK_INFO_DIR "/%s:%s", delete_path,
636
brickinfo->hostname, tmppath);
640
ret = gf_unlink(brickpath) ? 0 : -1;
642
if (brickinfo->shandle) {
643
gf_store_handle_destroy(brickinfo->shandle);
644
brickinfo->shandle = NULL;
646
gf_msg_debug(this->name, 0, "Returning with %d", ret);
651
_storeopts(dict_t *dict_value, char *key, data_t *value, void *data)
655
int32_t option_len = 0;
656
gf_store_handle_t *shandle = NULL;
657
glusterd_volinfo_data_store_t *dict_data = NULL;
658
xlator_t *this = THIS;
660
dict_data = (glusterd_volinfo_data_store_t *)data;
661
shandle = dict_data->shandle;
664
GF_ASSERT(shandle->fd > 0);
667
GF_ASSERT(value->data);
669
if (dict_data->key_check == 1) {
670
if (is_key_glusterd_hooks_friendly(key)) {
674
exists = glusterd_check_option_exists(key, NULL);
677
if (exists == 1 || dict_data->key_check == 0) {
678
gf_msg_debug(this->name, 0,
679
"Storing in buffer for volinfo:key= %s, "
683
gf_msg_debug(this->name, 0, "Discarding:key= %s, val=%s", key,
694
option_len = strlen(key) + value->len + 1;
696
if ((VOLINFO_BUFFER_SIZE - dict_data->buffer_len - 1) < option_len) {
697
ret = gf_store_save_items(shandle->fd, dict_data->buffer);
699
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, NULL);
702
dict_data->buffer_len = 0;
703
dict_data->buffer[0] = '\0';
705
ret = snprintf(dict_data->buffer + dict_data->buffer_len, option_len + 1,
706
"%s=%s\n", key, value->data);
707
if (ret < 0 || ret > option_len + 1) {
708
gf_smsg(this->name, GF_LOG_ERROR, EINVAL, GD_MSG_COPY_FAIL, NULL);
712
dict_data->buffer_len += ret;
723
glusterd_volume_write_snap_details(int fd, glusterd_volinfo_t *volinfo)
726
xlator_t *this = THIS;
727
char buf[PATH_MAX] = {
732
GF_VALIDATE_OR_GOTO(this->name, (fd > 0), out);
733
GF_VALIDATE_OR_GOTO(this->name, (volinfo != NULL), out);
735
ret = snprintf(buf, sizeof(buf), "%s=%s\n%s=%s\n%s=%" PRIu64 "\n",
736
GLUSTERD_STORE_KEY_PARENT_VOLNAME, volinfo->parent_volname,
737
GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP,
738
uuid_utoa(volinfo->restored_from_snap),
739
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
740
volinfo->snap_max_hard_limit);
741
if (ret < 0 || ret >= sizeof(buf)) {
747
if (volinfo->restored_from_snapname_id[0] != '\0') {
748
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n",
749
GLUSTERD_STORE_KEY_VOL_RESTORED_SNAPNAME_ID,
750
volinfo->restored_from_snapname_id);
751
if (ret < 0 || ret >= sizeof(buf) - total_len) {
758
if (volinfo->snap_plugin[0] != '\0') {
759
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n",
760
GLUSTERD_STORE_KEY_VOL_SNAP_PLUGIN,
761
volinfo->snap_plugin);
762
if (ret < 0 || ret >= sizeof(buf) - total_len) {
769
if (volinfo->restored_from_snapname[0] != '\0') {
770
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n",
771
GLUSTERD_STORE_KEY_VOL_RESTORED_SNAPNAME,
772
volinfo->restored_from_snapname);
773
if (ret < 0 || ret >= sizeof(buf) - total_len) {
780
ret = gf_store_save_items(fd, buf);
784
ret = glusterd_store_snapd_info(volinfo);
787
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPINFO_WRITE_FAIL,
788
"Failed to write snap details"
796
glusterd_volume_exclude_options_write(int fd, glusterd_volinfo_t *volinfo)
802
xlator_t *this = THIS;
803
glusterd_conf_t *conf = NULL;
807
conf = this->private;
808
GF_VALIDATE_OR_GOTO(this->name, (conf != NULL), out);
810
ret = snprintf(buf + total_len, sizeof(buf) - total_len,
811
"%s=%d\n%s=%d\n%s=%d\n%s=%d\n%s=%d\n",
812
GLUSTERD_STORE_KEY_VOL_TYPE, volinfo->type,
813
GLUSTERD_STORE_KEY_VOL_COUNT, volinfo->brick_count,
814
GLUSTERD_STORE_KEY_VOL_STATUS, volinfo->status,
815
GLUSTERD_STORE_KEY_VOL_SUB_COUNT, volinfo->sub_count,
816
GLUSTERD_STORE_KEY_VOL_REPLICA_CNT, volinfo->replica_count);
817
if (ret < 0 || ret >= sizeof(buf) - total_len) {
823
if (conf->op_version < GD_OP_VERSION_10_0) {
824
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n",
825
GLUSTERD_STORE_KEY_VOL_STRIPE_CNT, STRIPE_COUNT);
826
if (ret < 0 || ret >= sizeof(buf) - total_len) {
833
if (volinfo->arbiter_count) {
834
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n",
835
GLUSTERD_STORE_KEY_VOL_ARBITER_CNT,
836
volinfo->arbiter_count);
837
if (ret < 0 || ret >= sizeof(buf) - total_len) {
844
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n%s=%d\n",
845
GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT, volinfo->disperse_count,
846
GLUSTERD_STORE_KEY_VOL_REDUNDANCY_CNT,
847
volinfo->redundancy_count);
848
if (ret < 0 || ret >= sizeof(buf) - total_len) {
854
ret = snprintf(buf + total_len, sizeof(buf) - total_len,
855
"%s=%d\n%s=%d\n%s=%s\n", GLUSTERD_STORE_KEY_VOL_VERSION,
856
volinfo->version, GLUSTERD_STORE_KEY_VOL_TRANSPORT,
857
volinfo->transport_type, GLUSTERD_STORE_KEY_VOL_ID,
858
uuid_utoa(volinfo->volume_id));
859
if (ret < 0 || ret >= sizeof(buf) - total_len) {
865
str = glusterd_auth_get_username(volinfo);
867
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n",
868
GLUSTERD_STORE_KEY_USERNAME, str);
869
if (ret < 0 || ret >= sizeof(buf) - total_len) {
876
str = glusterd_auth_get_password(volinfo);
878
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n",
879
GLUSTERD_STORE_KEY_PASSWORD, str);
880
if (ret < 0 || ret >= sizeof(buf) - total_len) {
887
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n%s=%d\n",
888
GLUSTERD_STORE_KEY_VOL_OP_VERSION, volinfo->op_version,
889
GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION,
890
volinfo->client_op_version);
891
if (ret < 0 || ret >= sizeof(buf) - total_len) {
897
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n",
898
GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION,
899
volinfo->quota_xattr_version);
900
if (ret < 0 || ret >= sizeof(buf) - total_len) {
906
if (conf->op_version >= GD_OP_VERSION_3_10_0) {
907
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=0\n",
909
if (ret < 0 || ret >= sizeof(buf) - total_len) {
916
if ((conf->op_version >= GD_OP_VERSION_7_0) &&
917
volinfo->thin_arbiter_count) {
918
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n",
919
GLUSTERD_STORE_KEY_VOL_THIN_ARBITER_CNT,
920
volinfo->thin_arbiter_count);
921
if (ret < 0 || ret >= sizeof(buf) - total_len) {
928
ret = gf_store_save_items(fd, buf);
932
ret = glusterd_volume_write_snap_details(fd, volinfo);
936
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOL_VALS_WRITE_FAIL,
937
"Unable to write volume "
944
glusterd_store_voldirpath_set(glusterd_volinfo_t *volinfo, char *voldirpath)
946
glusterd_conf_t *priv = NULL;
949
priv = THIS->private;
952
GLUSTERD_GET_VOLUME_DIR(voldirpath, volinfo, priv);
956
glusterd_store_piddirpath_set(glusterd_volinfo_t *volinfo, char *piddirpath)
958
glusterd_conf_t *priv = NULL;
961
priv = THIS->private;
964
GLUSTERD_GET_VOLUME_PID_DIR(piddirpath, volinfo, priv);
968
glusterd_store_create_volume_dirs(glusterd_volinfo_t *volinfo)
971
char dirpath[PATH_MAX] = {
977
glusterd_store_voldirpath_set(volinfo, dirpath);
978
ret = gf_store_mkdir(dirpath);
982
glusterd_store_piddirpath_set(volinfo, dirpath);
983
ret = gf_store_mkdir(dirpath);
988
gf_msg_debug(THIS->name, 0, "Returning with %d", ret);
993
glusterd_store_create_snap_dir(glusterd_snap_t *snap)
996
char snapdirpath[PATH_MAX] = {
999
glusterd_conf_t *priv = NULL;
1001
priv = THIS->private;
1005
GLUSTERD_GET_SNAP_DIR(snapdirpath, snap, priv);
1007
ret = mkdir_p(snapdirpath, 0755, _gf_true);
1009
gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
1010
"Failed to create snaps dir "
1018
glusterd_store_volinfo_write(int fd, glusterd_volinfo_t *volinfo)
1021
gf_store_handle_t *shandle = NULL;
1024
GF_ASSERT(volinfo->shandle);
1025
xlator_t *this = THIS;
1026
glusterd_volinfo_data_store_t *dict_data = NULL;
1028
shandle = volinfo->shandle;
1030
dict_data = GF_CALLOC(1, sizeof(glusterd_volinfo_data_store_t),
1031
gf_gld_mt_volinfo_dict_data_t);
1032
if (dict_data == NULL) {
1033
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, NULL);
1037
ret = glusterd_volume_exclude_options_write(fd, volinfo);
1042
dict_data->shandle = shandle;
1043
dict_data->key_check = 1;
1046
dict_foreach(volinfo->dict, _storeopts, (void *)dict_data);
1048
dict_data->key_check = 0;
1049
dict_foreach(volinfo->gsync_secondaries, _storeopts, (void *)dict_data);
1051
if (dict_data->buffer_len > 0) {
1052
ret = gf_store_save_items(fd, dict_data->buffer);
1054
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, NULL);
1062
gf_msg_debug(this->name, 0, "Returning %d", ret);
1067
glusterd_store_snapinfo_write(glusterd_snap_t *snap)
1076
fd = gf_store_mkstemp(snap->shandle);
1080
ret = snprintf(buf + total_len, sizeof(buf) - total_len,
1081
"%s=%s\n%s=%d\n%s=%d\n", GLUSTERD_STORE_KEY_SNAP_ID,
1082
uuid_utoa(snap->snap_id), GLUSTERD_STORE_KEY_SNAP_STATUS,
1083
snap->snap_status, GLUSTERD_STORE_KEY_SNAP_RESTORED,
1084
snap->snap_restored);
1085
if (ret < 0 || ret >= sizeof(buf) - total_len) {
1091
if (snap->description) {
1092
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n",
1093
GLUSTERD_STORE_KEY_SNAP_DESC, snap->description);
1094
if (ret < 0 || ret >= sizeof(buf) - total_len) {
1101
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%ld\n",
1102
GLUSTERD_STORE_KEY_SNAP_TIMESTAMP, snap->time_stamp);
1103
if (ret < 0 || ret >= sizeof(buf) - total_len) {
1107
ret = gf_store_save_items(fd, buf);
1110
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
1115
glusterd_store_volfpath_set(glusterd_volinfo_t *volinfo, char *volfpath,
1118
char voldirpath[PATH_MAX] = {
1122
GF_ASSERT(volfpath);
1123
GF_ASSERT(len <= PATH_MAX);
1125
glusterd_store_voldirpath_set(volinfo, voldirpath);
1126
ret = snprintf(volfpath, len, "%s/%s", voldirpath,
1127
GLUSTERD_VOLUME_INFO_FILE);
1128
if (ret < 0 || ret >= len)
1134
glusterd_store_node_state_path_set(glusterd_volinfo_t *volinfo,
1135
char *node_statepath, size_t len)
1137
char voldirpath[PATH_MAX] = {
1141
GF_ASSERT(node_statepath);
1142
GF_ASSERT(len <= PATH_MAX);
1144
glusterd_store_voldirpath_set(volinfo, voldirpath);
1145
ret = snprintf(node_statepath, len, "%s/%s", voldirpath,
1146
GLUSTERD_NODE_STATE_FILE);
1147
if (ret < 0 || ret >= len)
1153
glusterd_store_quota_conf_path_set(glusterd_volinfo_t *volinfo,
1154
char *quota_conf_path, size_t len)
1156
char voldirpath[PATH_MAX] = {
1160
GF_ASSERT(quota_conf_path);
1161
GF_ASSERT(len <= PATH_MAX);
1163
glusterd_store_voldirpath_set(volinfo, voldirpath);
1164
ret = snprintf(quota_conf_path, len, "%s/%s", voldirpath,
1165
GLUSTERD_VOLUME_QUOTA_CONFIG);
1166
if (ret < 0 || ret >= len)
1172
glusterd_store_missed_snaps_list_path_set(char *missed_snaps_list, size_t len)
1174
glusterd_conf_t *priv = NULL;
1176
priv = THIS->private;
1178
GF_ASSERT(missed_snaps_list);
1179
GF_ASSERT(len <= PATH_MAX);
1181
snprintf(missed_snaps_list, len,
1182
"%s/snaps/" GLUSTERD_MISSED_SNAPS_LIST_FILE, priv->workdir);
1186
glusterd_store_snapfpath_set(glusterd_snap_t *snap, char *snap_fpath,
1189
glusterd_conf_t *priv = NULL;
1190
priv = THIS->private;
1193
GF_ASSERT(snap_fpath);
1194
GF_ASSERT(len <= PATH_MAX);
1196
snprintf(snap_fpath, len, "%s/snaps/%s/%s", priv->workdir, snap->snapname,
1197
GLUSTERD_SNAP_INFO_FILE);
1201
glusterd_store_create_vol_shandle_on_absence(glusterd_volinfo_t *volinfo)
1203
char volfpath[PATH_MAX] = {0};
1208
ret = glusterd_store_volfpath_set(volinfo, volfpath, sizeof(volfpath));
1211
ret = gf_store_handle_create_on_absence(&volinfo->shandle, volfpath);
1216
glusterd_store_create_nodestate_sh_on_absence(glusterd_volinfo_t *volinfo)
1218
char node_state_path[PATH_MAX] = {0};
1223
ret = glusterd_store_node_state_path_set(volinfo, node_state_path,
1224
sizeof(node_state_path));
1227
ret = gf_store_handle_create_on_absence(&volinfo->node_state_shandle,
1234
glusterd_store_create_quota_conf_sh_on_absence(glusterd_volinfo_t *volinfo)
1236
char quota_conf_path[PATH_MAX] = {0};
1241
ret = glusterd_store_quota_conf_path_set(volinfo, quota_conf_path,
1242
sizeof(quota_conf_path));
1245
ret = gf_store_handle_create_on_absence(&volinfo->quota_conf_shandle,
1252
glusterd_store_create_missed_snaps_list_shandle_on_absence(void)
1254
char missed_snaps_list[PATH_MAX] = "";
1256
glusterd_conf_t *priv = NULL;
1257
xlator_t *this = THIS;
1259
priv = this->private;
1262
glusterd_store_missed_snaps_list_path_set(missed_snaps_list,
1263
sizeof(missed_snaps_list));
1265
ret = gf_store_handle_create_on_absence(&priv->missed_snaps_list_shandle,
1271
glusterd_store_create_snap_shandle_on_absence(glusterd_snap_t *snap)
1273
char snapfpath[PATH_MAX] = {0};
1278
glusterd_store_snapfpath_set(snap, snapfpath, sizeof(snapfpath));
1279
ret = gf_store_handle_create_on_absence(&snap->shandle, snapfpath);
1284
glusterd_store_brickinfos(glusterd_volinfo_t *volinfo, int vol_fd)
1287
glusterd_brickinfo_t *brickinfo = NULL;
1288
glusterd_brickinfo_t *ta_brickinfo = NULL;
1289
int32_t brick_count = 0;
1290
int32_t ta_brick_count = 0;
1294
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
1296
ret = glusterd_store_brickinfo(volinfo, brickinfo, brick_count, vol_fd,
1302
if (volinfo->thin_arbiter_count == 1) {
1303
ta_brickinfo = list_first_entry(&volinfo->ta_bricks,
1304
glusterd_brickinfo_t, brick_list);
1305
ret = glusterd_store_brickinfo(volinfo, ta_brickinfo, ta_brick_count,
1312
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
1317
glusterd_store_node_state_write(int fd, glusterd_volinfo_t *volinfo)
1321
char uuid[GF_UUID_BUF_SIZE];
1323
glusterd_volinfo_data_store_t *dict_data = NULL;
1324
gf_store_handle_t shandle;
1325
xlator_t *this = THIS;
1330
if (volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_STATUS) {
1335
gf_uuid_unparse(volinfo->rebal.rebalance_id, uuid);
1336
ret = snprintf(buf + total_len, sizeof(buf) - total_len,
1337
"%s=%d\n%s=%d\n%s=%d\n%s=%s\n",
1338
GLUSTERD_STORE_KEY_VOL_DEFRAG, volinfo->rebal.defrag_cmd,
1339
GLUSTERD_STORE_KEY_VOL_DEFRAG_STATUS,
1340
volinfo->rebal.defrag_status, GLUSTERD_STORE_KEY_DEFRAG_OP,
1341
volinfo->rebal.op, GF_REBALANCE_TID_KEY, uuid);
1342
if (ret < 0 || ret >= sizeof(buf) - total_len) {
1349
buf + total_len, sizeof(buf) - total_len,
1350
"%s=%" PRIu64 "\n%s=%" PRIu64 "\n%s=%" PRIu64 "\n%s=%" PRIu64
1351
"\n%s=%" PRIu64 "\n%s=%lf\n",
1352
GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES, volinfo->rebal.rebalance_files,
1353
GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE, volinfo->rebal.rebalance_data,
1354
GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED, volinfo->rebal.lookedup_files,
1355
GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES,
1356
volinfo->rebal.rebalance_failures,
1357
GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED, volinfo->rebal.skipped_files,
1358
GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME, volinfo->rebal.rebalance_time);
1359
if (ret < 0 || ret >= sizeof(buf) - total_len) {
1364
ret = gf_store_save_items(fd, buf);
1369
if (volinfo->rebal.dict) {
1370
dict_data = GF_CALLOC(1, sizeof(glusterd_volinfo_data_store_t),
1371
gf_gld_mt_volinfo_dict_data_t);
1372
if (dict_data == NULL) {
1373
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, NULL);
1376
dict_data->shandle = &shandle;
1378
dict_foreach(volinfo->rebal.dict, _storeopts, (void *)dict_data);
1379
if (dict_data->buffer_len > 0) {
1380
ret = gf_store_save_items(fd, dict_data->buffer);
1382
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED,
1391
gf_msg_debug(this->name, 0, "Returning %d", ret);
1396
glusterd_store_perform_node_state_store(glusterd_volinfo_t *volinfo)
1402
fd = gf_store_mkstemp(volinfo->node_state_shandle);
1408
ret = glusterd_store_node_state_write(fd, volinfo);
1412
ret = gf_store_rename_tmppath(volinfo->node_state_shandle);
1417
if (ret && (fd > 0))
1418
gf_store_unlink_tmppath(volinfo->node_state_shandle);
1419
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
1424
glusterd_store_perform_volume_store(glusterd_volinfo_t *volinfo)
1430
fd = gf_store_mkstemp(volinfo->shandle);
1436
ret = glusterd_store_volinfo_write(fd, volinfo);
1440
ret = glusterd_store_create_brick_dir(volinfo);
1444
ret = glusterd_store_brickinfos(volinfo, fd);
1449
if (ret && (fd > 0))
1450
gf_store_unlink_tmppath(volinfo->shandle);
1451
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
1456
glusterd_perform_volinfo_version_action(glusterd_volinfo_t *volinfo,
1457
glusterd_volinfo_ver_ac_t ac)
1462
case GLUSTERD_VOLINFO_VER_AC_NONE:
1464
case GLUSTERD_VOLINFO_VER_AC_INCREMENT:
1467
case GLUSTERD_VOLINFO_VER_AC_DECREMENT:
1474
glusterd_store_bricks_cleanup_tmp(glusterd_volinfo_t *volinfo)
1476
glusterd_brickinfo_t *brickinfo = NULL;
1480
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
1482
gf_store_unlink_tmppath(brickinfo->shandle);
1487
glusterd_store_volume_cleanup_tmp(glusterd_volinfo_t *volinfo)
1491
glusterd_store_bricks_cleanup_tmp(volinfo);
1493
gf_store_unlink_tmppath(volinfo->shandle);
1495
gf_store_unlink_tmppath(volinfo->node_state_shandle);
1497
gf_store_unlink_tmppath(volinfo->snapd.handle);
1501
glusterd_store_brickinfos_atomic_update(glusterd_volinfo_t *volinfo)
1504
glusterd_brickinfo_t *brickinfo = NULL;
1505
glusterd_brickinfo_t *ta_brickinfo = NULL;
1509
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
1511
ret = gf_store_rename_tmppath(brickinfo->shandle);
1516
if (volinfo->thin_arbiter_count == 1) {
1517
ta_brickinfo = list_first_entry(&volinfo->ta_bricks,
1518
glusterd_brickinfo_t, brick_list);
1519
ret = gf_store_rename_tmppath(ta_brickinfo->shandle);
1529
glusterd_store_volinfo_atomic_update(glusterd_volinfo_t *volinfo)
1534
ret = gf_store_rename_tmppath(volinfo->shandle);
1540
gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
1542
"temporary file(s)");
1547
glusterd_store_volume_atomic_update(glusterd_volinfo_t *volinfo)
1552
ret = glusterd_store_brickinfos_atomic_update(volinfo);
1556
ret = glusterd_store_volinfo_atomic_update(volinfo);
1563
glusterd_store_snap_atomic_update(glusterd_snap_t *snap)
1568
ret = gf_store_rename_tmppath(snap->shandle);
1570
gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
1572
"temporary file(s)");
1578
glusterd_store_snap(glusterd_snap_t *snap)
1584
ret = glusterd_store_create_snap_dir(snap);
1586
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SNAPDIR_CREATE_FAIL,
1587
"Failed to create snap dir");
1591
ret = glusterd_store_create_snap_shandle_on_absence(snap);
1593
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SNAPINFO_CREATE_FAIL,
1594
"Failed to create snap info "
1599
ret = glusterd_store_snapinfo_write(snap);
1601
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SNAPINFO_WRITE_FAIL,
1602
"Failed to write snap info");
1606
ret = glusterd_store_snap_atomic_update(snap);
1608
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_AUTOMIC_UPDATE_FAIL,
1609
"Failed to do automic update");
1614
if (ret && snap->shandle)
1615
gf_store_unlink_tmppath(snap->shandle);
1617
gf_msg_trace(THIS->name, 0, "Returning %d", ret);
1622
glusterd_store_volinfo(glusterd_volinfo_t *volinfo,
1623
glusterd_volinfo_ver_ac_t ac)
1626
glusterfs_ctx_t *ctx = NULL;
1627
xlator_t *this = THIS;
1633
pthread_mutex_lock(&ctx->cleanup_lock);
1634
pthread_mutex_lock(&volinfo->store_volinfo_lock);
1636
glusterd_perform_volinfo_version_action(volinfo, ac);
1638
ret = glusterd_store_create_volume_dirs(volinfo);
1642
ret = glusterd_store_create_vol_shandle_on_absence(volinfo);
1646
ret = glusterd_store_create_nodestate_sh_on_absence(volinfo);
1650
ret = glusterd_store_perform_volume_store(volinfo);
1654
ret = glusterd_store_volume_atomic_update(volinfo);
1656
glusterd_perform_volinfo_version_action(
1657
volinfo, GLUSTERD_VOLINFO_VER_AC_DECREMENT);
1661
ret = glusterd_store_perform_node_state_store(volinfo);
1666
ret = glusterd_compute_cksum(volinfo, _gf_false);
1671
pthread_mutex_unlock(&volinfo->store_volinfo_lock);
1672
pthread_mutex_unlock(&ctx->cleanup_lock);
1675
glusterd_store_volume_cleanup_tmp(volinfo);
1677
gf_msg_debug(this->name, 0, "Returning %d", ret);
1683
glusterd_store_delete_volume(glusterd_volinfo_t *volinfo)
1685
char pathname[PATH_MAX] = {
1689
glusterd_conf_t *priv = NULL;
1690
char delete_path[PATH_MAX] = {
1693
char trashdir[PATH_MAX] = {
1696
xlator_t *this = THIS;
1697
gf_boolean_t rename_fail = _gf_false;
1701
priv = this->private;
1705
GLUSTERD_GET_VOLUME_DIR(pathname, volinfo, priv);
1707
len = snprintf(delete_path, sizeof(delete_path),
1708
"%s/" GLUSTERD_TRASH "/%s.deleted", priv->workdir,
1709
uuid_utoa(volinfo->volume_id));
1710
if ((len < 0) || (len >= sizeof(delete_path))) {
1714
len = snprintf(trashdir, sizeof(trashdir), "%s/" GLUSTERD_TRASH,
1716
if ((len < 0) || (len >= sizeof(trashdir))) {
1720
ret = sys_mkdir(trashdir, 0755);
1721
if (ret && errno != EEXIST) {
1722
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
1723
"Failed to create trash "
1728
ret = sys_rename(pathname, delete_path);
1730
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
1731
"Failed to rename volume "
1732
"directory for volume %s",
1734
rename_fail = _gf_true;
1738
ret = recursive_rmdir(trashdir);
1740
gf_msg_debug(this->name, 0, "Failed to rmdir: %s", trashdir);
1744
if (volinfo->shandle) {
1745
gf_store_handle_destroy(volinfo->shandle);
1746
volinfo->shandle = NULL;
1748
ret = (rename_fail == _gf_true) ? -1 : 0;
1750
gf_msg_debug(this->name, 0, "Returning %d", ret);
1757
glusterd_store_delete_snap(glusterd_snap_t *snap)
1759
char pathname[PATH_MAX] = {
1763
glusterd_conf_t *priv = NULL;
1765
struct dirent *entry = NULL;
1766
struct dirent scratch[2] = {
1771
char path[PATH_MAX] = {
1774
char delete_path[PATH_MAX] = {
1777
char trashdir[PATH_MAX] = {
1783
xlator_t *this = THIS;
1784
gf_boolean_t rename_fail = _gf_false;
1787
priv = this->private;
1791
GLUSTERD_GET_SNAP_DIR(pathname, snap, priv);
1793
len = snprintf(delete_path, sizeof(delete_path),
1794
"%s/" GLUSTERD_TRASH "/snap-%s.deleted", priv->workdir,
1795
uuid_utoa(snap->snap_id));
1796
if ((len < 0) || (len >= sizeof(delete_path))) {
1800
len = snprintf(trashdir, sizeof(trashdir), "%s/" GLUSTERD_TRASH,
1802
if ((len < 0) || (len >= sizeof(trashdir))) {
1806
ret = sys_mkdir(trashdir, 0755);
1807
if (ret && errno != EEXIST) {
1808
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
1809
"Failed to create trash "
1814
ret = sys_rename(pathname, delete_path);
1816
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
1817
"Failed to rename snap "
1818
"directory %s to %s",
1819
pathname, delete_path);
1820
rename_fail = _gf_true;
1824
dir = sys_opendir(delete_path);
1826
gf_msg_debug(this->name, 0, "Failed to open directory %s.",
1831
while ((entry = sys_readdir(dir, scratch))) {
1832
if (gf_irrelevant_entry(entry))
1834
len = snprintf(path, PATH_MAX, "%s/%s", delete_path, entry->d_name);
1835
if ((len < 0) || (len >= PATH_MAX)) {
1838
ret = sys_stat(path, &st);
1840
gf_msg_debug(this->name, 0,
1847
if (S_ISDIR(st.st_mode))
1848
ret = sys_rmdir(path);
1850
ret = sys_unlink(path);
1853
gf_msg_debug(this->name, 0,
1854
" Failed to remove "
1859
gf_msg_debug(this->name, 0, "%s %s",
1860
ret ? "Failed to remove" : "Removed", entry->d_name);
1862
memset(path, 0, sizeof(path));
1865
ret = sys_closedir(dir);
1867
gf_msg_debug(this->name, 0, "Failed to close dir %s.", delete_path);
1870
ret = sys_rmdir(delete_path);
1872
gf_msg_debug(this->name, 0, "Failed to rmdir: %s", delete_path);
1874
ret = sys_rmdir(trashdir);
1876
gf_msg_debug(this->name, 0, "Failed to rmdir: %s", trashdir);
1880
if (snap->shandle) {
1881
gf_store_handle_destroy(snap->shandle);
1882
snap->shandle = NULL;
1884
ret = (rename_fail == _gf_true) ? -1 : 0;
1886
gf_msg_debug(this->name, 0, "Returning %d", ret);
1891
glusterd_store_global_info(xlator_t *this)
1894
glusterd_conf_t *conf = NULL;
1897
gf_store_handle_t *handle = NULL;
1898
char *uuid_str = NULL;
1900
conf = this->private;
1902
uuid_str = gf_strdup(uuid_utoa(MY_UUID));
1906
if (!conf->handle) {
1907
ret = snprintf(buf, sizeof(buf), "%s/%s", conf->workdir,
1908
GLUSTERD_INFO_FILE);
1909
if ((ret < 0) || (ret >= sizeof(buf))) {
1913
ret = gf_store_handle_new(buf, &handle);
1915
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_GET_FAIL,
1916
"Unable to get store handle");
1920
conf->handle = handle;
1922
handle = conf->handle;
1925
ret = sys_chmod(handle->path, 0644);
1927
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
1928
"chmod error for %s", GLUSTERD_INFO_FILE);
1932
handle->fd = gf_store_mkstemp(handle);
1933
if (handle->fd < 0) {
1938
ret = snprintf(buf, sizeof(buf), "%s=%s\n", GLUSTERD_STORE_UUID_KEY,
1940
if (ret < 0 || ret >= sizeof(buf)) {
1946
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n",
1947
GD_OP_VERSION_KEY, conf->op_version);
1948
if (ret < 0 || ret >= sizeof(buf) - total_len) {
1953
ret = gf_store_save_items(handle->fd, buf);
1955
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_OP_VERS_STORE_FAIL,
1956
"Storing glusterd global-info failed ret = %d", ret);
1960
ret = gf_store_rename_tmppath(handle);
1963
if (ret && (handle->fd >= 0))
1964
gf_store_unlink_tmppath(handle);
1971
gf_msg(this->name, GF_LOG_ERROR, 0,
1972
GD_MSG_GLUSTERD_GLOBAL_INFO_STORE_FAIL,
1973
"Failed to store glusterd global-info");
1979
glusterd_store_max_op_version(xlator_t *this)
1982
glusterd_conf_t *conf = NULL;
1983
char op_version_str[15] = {
1986
char path[PATH_MAX] = {
1989
gf_store_handle_t *handle = NULL;
1992
conf = this->private;
1994
len = snprintf(path, PATH_MAX, "%s/%s", conf->workdir,
1995
GLUSTERD_UPGRADE_FILE);
1996
if ((len < 0) || (len >= PATH_MAX)) {
1999
ret = gf_store_handle_new(path, &handle);
2001
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_GET_FAIL,
2002
"Unable to get store handle");
2007
ret = sys_chmod(handle->path, 0644);
2009
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
2010
"chmod error for %s", GLUSTERD_UPGRADE_FILE);
2014
handle->fd = gf_store_mkstemp(handle);
2015
if (handle->fd < 0) {
2020
snprintf(op_version_str, sizeof(op_version_str), "%d", GD_OP_VERSION_MAX);
2021
ret = gf_store_save_value(handle->fd, GD_MAX_OP_VERSION_KEY,
2024
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OP_VERS_STORE_FAIL,
2025
"Storing op-version failed ret = %d", ret);
2029
ret = gf_store_rename_tmppath(handle);
2032
if (ret && (handle->fd >= 0))
2033
gf_store_unlink_tmppath(handle);
2037
gf_msg(this->name, GF_LOG_ERROR, 0,
2038
GD_MSG_GLUSTERD_GLOBAL_INFO_STORE_FAIL,
2039
"Failed to store max op-version");
2041
gf_store_handle_destroy(handle);
2046
glusterd_retrieve_max_op_version(xlator_t *this, int *op_version)
2048
char *op_version_str = NULL;
2049
glusterd_conf_t *priv = NULL;
2051
int tmp_version = 0;
2053
char path[PATH_MAX] = {
2056
gf_store_handle_t *handle = NULL;
2059
priv = this->private;
2061
len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir,
2062
GLUSTERD_UPGRADE_FILE);
2063
if ((len < 0) || (len >= PATH_MAX)) {
2066
ret = gf_store_handle_retrieve(path, &handle);
2069
gf_msg_debug(this->name, 0,
2070
"Unable to get store "
2075
ret = gf_store_retrieve_value(handle, GD_MAX_OP_VERSION_KEY,
2078
gf_msg_debug(this->name, 0, "No previous op_version present");
2082
tmp_version = strtol(op_version_str, &tmp, 10);
2083
if ((tmp_version <= 0) || (tmp && strlen(tmp) > 1)) {
2084
gf_msg(this->name, GF_LOG_WARNING, EINVAL, GD_MSG_UNSUPPORTED_VERSION,
2085
"invalid version number");
2089
*op_version = tmp_version;
2094
GF_FREE(op_version_str);
2096
gf_store_handle_destroy(handle);
2101
glusterd_retrieve_op_version(xlator_t *this, int *op_version)
2103
char *op_version_str = NULL;
2104
glusterd_conf_t *priv = NULL;
2106
int tmp_version = 0;
2108
char path[PATH_MAX] = {
2111
gf_store_handle_t *handle = NULL;
2114
priv = this->private;
2116
if (!priv->handle) {
2117
len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir,
2118
GLUSTERD_INFO_FILE);
2119
if ((len < 0) || (len >= PATH_MAX)) {
2122
ret = gf_store_handle_retrieve(path, &handle);
2125
gf_msg_debug(this->name, 0,
2126
"Unable to get store "
2131
priv->handle = handle;
2134
ret = gf_store_retrieve_value(priv->handle, GD_OP_VERSION_KEY,
2137
gf_msg_debug(this->name, 0, "No previous op_version present");
2141
tmp_version = strtol(op_version_str, &tmp, 10);
2142
if ((tmp_version <= 0) || (tmp && strlen(tmp) > 1)) {
2143
gf_msg(this->name, GF_LOG_WARNING, EINVAL, GD_MSG_UNSUPPORTED_VERSION,
2144
"invalid version number");
2148
*op_version = tmp_version;
2153
GF_FREE(op_version_str);
2159
glusterd_restore_op_version(xlator_t *this)
2161
glusterd_conf_t *conf = NULL;
2165
conf = this->private;
2167
ret = glusterd_retrieve_op_version(this, &op_version);
2169
if ((op_version < GD_OP_VERSION_MIN) ||
2170
(op_version > GD_OP_VERSION_MAX)) {
2171
gf_msg(this->name, GF_LOG_ERROR, EINVAL, GD_MSG_UNSUPPORTED_VERSION,
2172
"wrong op-version (%d) retrieved", op_version);
2176
conf->op_version = op_version;
2177
gf_msg("glusterd", GF_LOG_INFO, 0, GD_MSG_OP_VERS_INFO,
2178
"retrieved op-version: %d", conf->op_version);
2195
ret = glusterd_retrieve_uuid();
2197
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_OP_VERS_SET_INFO,
2198
"Detected new install. Setting"
2199
" op-version to maximum : %d",
2201
conf->op_version = GD_OP_VERSION_MAX;
2203
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_OP_VERS_SET_INFO,
2204
"Upgrade detected. Setting"
2205
" op-version to minimum : %d",
2207
conf->op_version = GD_OP_VERSION_MIN;
2215
glusterd_retrieve_uuid(void)
2217
char *uuid_str = NULL;
2219
gf_store_handle_t *handle = NULL;
2220
glusterd_conf_t *priv = NULL;
2221
xlator_t *this = THIS;
2222
char path[PATH_MAX] = {
2227
priv = this->private;
2229
if (!priv->handle) {
2230
len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir,
2231
GLUSTERD_INFO_FILE);
2232
if ((len < 0) || (len >= PATH_MAX)) {
2235
ret = gf_store_handle_retrieve(path, &handle);
2238
gf_msg_debug(this->name, 0,
2239
"Unable to get store"
2244
priv->handle = handle;
2246
pthread_mutex_lock(&priv->mutex);
2248
ret = gf_store_retrieve_value(priv->handle, GLUSTERD_STORE_UUID_KEY,
2251
pthread_mutex_unlock(&priv->mutex);
2253
gf_msg_debug(this->name, 0, "No previous uuid is present");
2257
gf_uuid_parse(uuid_str, priv->uuid);
2261
gf_msg_debug(this->name, 0, "Returning %d", ret);
2266
glusterd_store_retrieve_snapd(glusterd_volinfo_t *volinfo)
2271
char volpath[PATH_MAX] = {
2274
char path[PATH_MAX] = {
2277
xlator_t *this = THIS;
2278
glusterd_conf_t *conf = NULL;
2279
gf_store_iter_t *iter = NULL;
2280
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
2283
conf = this->private;
2300
if (!dict_get_str_boolean(volinfo->dict, "features.uss", _gf_false)) {
2305
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, conf);
2307
len = snprintf(path, sizeof(path), "%s/%s", volpath,
2308
GLUSTERD_VOLUME_SNAPD_INFO_FILE);
2309
if ((len < 0) || (len >= sizeof(path))) {
2313
ret = gf_store_handle_retrieve(path, &volinfo->snapd.handle);
2315
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HANDLE_NULL,
2316
"volinfo handle is NULL");
2320
ret = gf_store_iter_new(volinfo->snapd.handle, &iter);
2322
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_GET_FAIL,
2323
"Failed to get new store "
2328
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2330
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_GET_FAIL,
2331
"Failed to get next store "
2337
if (!strncmp(key, GLUSTERD_STORE_KEY_SNAPD_PORT,
2338
SLEN(GLUSTERD_STORE_KEY_SNAPD_PORT))) {
2339
volinfo->snapd.port = atoi(value);
2346
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2349
if (op_errno != GD_STORE_EOF)
2355
if (gf_store_iter_destroy(&iter)) {
2356
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
2357
"Failed to destroy store iter");
2365
glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo)
2368
glusterd_brickinfo_t *brickinfo = NULL;
2369
glusterd_brickinfo_t *ta_brickinfo = NULL;
2370
gf_store_iter_t *iter = NULL;
2373
char brickdir[PATH_MAX] = {
2376
char path[PATH_MAX] = {
2379
glusterd_conf_t *priv = NULL;
2380
int32_t brick_count = 0;
2381
int32_t ta_brick_count = 0;
2385
gf_store_iter_t *tmpiter = NULL;
2386
char *tmpvalue = NULL;
2387
char abspath[PATH_MAX] = {0};
2388
xlator_t *this = THIS;
2393
int ta_brick_id = 2;
2394
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
2398
GF_ASSERT(volinfo->volname);
2400
priv = this->private;
2402
GLUSTERD_GET_BRICK_DIR(brickdir, volinfo, priv);
2404
ret = gf_store_iter_new(volinfo->shandle, &tmpiter);
2409
while (brick_count < volinfo->brick_count) {
2410
ret = glusterd_brickinfo_new(&brickinfo);
2414
snprintf(tmpkey, sizeof(tmpkey), "%s-%d", GLUSTERD_STORE_KEY_VOL_BRICK,
2416
ret = gf_store_iter_get_matching(tmpiter, tmpkey, &tmpvalue);
2417
len = snprintf(path, sizeof(path), "%s/%s", brickdir, tmpvalue);
2420
if ((len < 0) || (len >= sizeof(path))) {
2425
ret = gf_store_handle_retrieve(path, &brickinfo->shandle);
2430
ret = gf_store_iter_new(brickinfo->shandle, &iter);
2435
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2437
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2438
GD_MSG_STORE_ITER_GET_FAIL,
2439
"Unable to iterate "
2440
"the store for brick: %s",
2445
if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_HOSTNAME,
2446
SLEN(GLUSTERD_STORE_KEY_BRICK_HOSTNAME))) {
2447
if (snprintf(brickinfo->hostname, sizeof(brickinfo->hostname),
2448
"%s", value) >= sizeof(brickinfo->hostname)) {
2449
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2450
GD_MSG_PARSE_BRICKINFO_FAIL,
2451
"brick hostname truncated: %s", brickinfo->hostname);
2454
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PATH,
2455
SLEN(GLUSTERD_STORE_KEY_BRICK_PATH))) {
2456
if (snprintf(brickinfo->path, sizeof(brickinfo->path), "%s",
2457
value) >= sizeof(brickinfo->path)) {
2458
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2459
GD_MSG_PARSE_BRICKINFO_FAIL,
2460
"brick path truncated: %s", brickinfo->path);
2463
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_REAL_PATH,
2464
SLEN(GLUSTERD_STORE_KEY_BRICK_REAL_PATH))) {
2465
if (snprintf(brickinfo->real_path, sizeof(brickinfo->real_path),
2466
"%s", value) >= sizeof(brickinfo->real_path)) {
2467
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2468
GD_MSG_PARSE_BRICKINFO_FAIL,
2469
"real_path truncated: %s", brickinfo->real_path);
2472
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PORT,
2473
SLEN(GLUSTERD_STORE_KEY_BRICK_PORT))) {
2474
ret = gf_string2int(value, &brickinfo->port);
2476
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2477
GD_MSG_INCOMPATIBLE_VALUE,
2478
"Failed to convert "
2479
"string to integer");
2482
if (brickinfo->port < priv->base_port) {
2485
brickinfo->port = 0;
2487
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT,
2488
SLEN(GLUSTERD_STORE_KEY_BRICK_RDMA_PORT))) {
2489
ret = gf_string2int(value, &brickinfo->rdma_port);
2491
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2492
GD_MSG_INCOMPATIBLE_VALUE,
2493
"Failed to convert "
2494
"string to integer");
2497
if (brickinfo->rdma_port < priv->base_port) {
2500
brickinfo->rdma_port = 0;
2503
} else if (!strncmp(
2504
key, GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED,
2505
SLEN(GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED))) {
2506
ret = gf_string2int(value, &brickinfo->decommissioned);
2508
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2509
GD_MSG_INCOMPATIBLE_VALUE,
2510
"Failed to convert "
2511
"string to integer");
2514
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_ORIGIN_PATH,
2515
SLEN(GLUSTERD_STORE_KEY_BRICK_ORIGIN_PATH))) {
2516
if (snprintf(brickinfo->origin_path,
2517
sizeof(brickinfo->origin_path), "%s",
2518
value) >= sizeof(brickinfo->origin_path)) {
2519
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2520
GD_MSG_PARSE_BRICKINFO_FAIL,
2521
"origin_path truncated: %s", brickinfo->origin_path);
2524
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR,
2525
SLEN(GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR))) {
2526
if (snprintf(brickinfo->mount_dir, sizeof(brickinfo->mount_dir),
2527
"%s", value) >= sizeof(brickinfo->mount_dir)) {
2528
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2529
GD_MSG_PARSE_BRICKINFO_FAIL,
2530
"mount_dir truncated: %s", brickinfo->mount_dir);
2533
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS,
2534
SLEN(GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS))) {
2535
ret = gf_string2int(value, &brickinfo->snap_status);
2537
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2538
GD_MSG_INCOMPATIBLE_VALUE,
2539
"Failed to convert "
2540
"string to integer");
2543
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_FSTYPE,
2544
SLEN(GLUSTERD_STORE_KEY_BRICK_FSTYPE))) {
2545
if (snprintf(brickinfo->fstype, sizeof(brickinfo->fstype), "%s",
2546
value) >= sizeof(brickinfo->fstype)) {
2547
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2548
GD_MSG_PARSE_BRICKINFO_FAIL, "fstype truncated: %s",
2552
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_SNAPTYPE,
2553
SLEN(GLUSTERD_STORE_KEY_BRICK_SNAPTYPE))) {
2554
if (snprintf(brickinfo->snap_type, sizeof(brickinfo->snap_type),
2555
"%s", value) >= sizeof(brickinfo->snap_type)) {
2556
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2557
GD_MSG_PARSE_BRICKINFO_FAIL,
2558
"snap_type truncated: %s", brickinfo->snap_type);
2561
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_MNTOPTS,
2562
SLEN(GLUSTERD_STORE_KEY_BRICK_MNTOPTS))) {
2563
if (snprintf(brickinfo->mnt_opts, sizeof(brickinfo->mnt_opts),
2564
"%s", value) >= sizeof(brickinfo->mnt_opts)) {
2565
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2566
GD_MSG_PARSE_BRICKINFO_FAIL,
2567
"mnt_opts truncated: %s", brickinfo->mnt_opts);
2570
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_VGNAME,
2571
SLEN(GLUSTERD_STORE_KEY_BRICK_VGNAME))) {
2572
if (snprintf(brickinfo->vg, sizeof(brickinfo->vg), "%s",
2573
value) >= sizeof(brickinfo->vg)) {
2574
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2575
GD_MSG_PARSE_BRICKINFO_FAIL,
2576
"brickinfo->vg truncated: %s", brickinfo->vg);
2579
} else if (!strcmp(key, GLUSTERD_STORE_KEY_BRICK_ID)) {
2580
if (snprintf(brickinfo->brick_id, sizeof(brickinfo->brick_id),
2581
"%s", value) >= sizeof(brickinfo->brick_id)) {
2582
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2583
GD_MSG_PARSE_BRICKINFO_FAIL,
2584
"brick_id truncated: %s", brickinfo->brick_id);
2587
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_FSID,
2588
SLEN(GLUSTERD_STORE_KEY_BRICK_FSID))) {
2589
ret = gf_string2uint64(value, &brickinfo->statfs_fsid);
2591
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY,
2593
"is not a valid uint64_t value",
2597
} else if (!strcmp(key, GLUSTERD_STORE_KEY_BRICK_UUID)) {
2598
gf_uuid_parse(value, brickinfo->uuid);
2600
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_UNKNOWN_KEY,
2601
"Unknown key: %s", key);
2609
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2612
if (op_errno != GD_STORE_EOF) {
2613
gf_msg(this->name, GF_LOG_ERROR, op_errno,
2614
GD_MSG_PARSE_BRICKINFO_FAIL,
2615
"Error parsing brickinfo: "
2621
if (brickinfo->brick_id[0] == '\0') {
2623
GLUSTERD_ASSIGN_BRICKID_TO_BRICKINFO(brickinfo, volinfo, brickid++);
2629
if (gf_uuid_is_null(brickinfo->uuid))
2630
(void)glusterd_resolve_brick(brickinfo);
2631
if (brickinfo->real_path[0] == '\0' && !volinfo->is_snap_volume &&
2632
gf_uuid_is_null(volinfo->restored_from_snap)) {
2639
if (!gf_uuid_compare(brickinfo->uuid, MY_UUID)) {
2640
if (!realpath(brickinfo->path, abspath)) {
2641
gf_msg(this->name, GF_LOG_CRITICAL, errno,
2642
GD_MSG_BRICKINFO_CREATE_FAIL,
2643
"realpath() failed for brick %s"
2644
". The underlying file system "
2645
"may be in bad state",
2650
if (strlen(abspath) >= sizeof(brickinfo->real_path)) {
2654
(void)strncpy(brickinfo->real_path, abspath,
2655
sizeof(brickinfo->real_path));
2661
if (!gf_uuid_compare(brickinfo->uuid, MY_UUID) &&
2662
brickinfo->statfs_fsid == 0) {
2663
struct statvfs brickstat = {
2666
ret = sys_statvfs(brickinfo->path, &brickstat);
2668
gf_msg(this->name, GF_LOG_WARNING, errno,
2669
GD_MSG_BRICKINFO_CREATE_FAIL,
2670
"failed to get statfs() call on brick %s",
2675
brickinfo->statfs_fsid = brickstat.f_fsid;
2679
cds_list_add_tail(&brickinfo->brick_list, &volinfo->bricks);
2681
if (gf_store_iter_destroy(&iter)) {
2682
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
2683
"Failed to destroy store iter");
2689
if (gf_store_iter_destroy(&tmpiter)) {
2690
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
2691
"Failed to destroy store iter");
2696
ret = gf_store_iter_new(volinfo->shandle, &tmpiter);
2701
if (volinfo->thin_arbiter_count == 1) {
2702
snprintf(tmpkey, sizeof(tmpkey), "%s-%d",
2703
GLUSTERD_STORE_KEY_VOL_TA_BRICK, 0);
2704
while (ta_brick_count < volinfo->subvol_count) {
2705
ret = glusterd_brickinfo_new(&ta_brickinfo);
2709
ret = gf_store_iter_get_matching(tmpiter, tmpkey, &tmpvalue);
2711
len = snprintf(path, sizeof(path), "%s/%s", brickdir, tmpvalue);
2714
if ((len < 0) || (len >= sizeof(path))) {
2719
ret = gf_store_handle_retrieve(path, &ta_brickinfo->shandle);
2724
ret = gf_store_iter_new(ta_brickinfo->shandle, &iter);
2729
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2731
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2732
GD_MSG_STORE_ITER_GET_FAIL,
2733
"Unable to iterate "
2734
"the store for brick: %s",
2740
if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_HOSTNAME,
2741
SLEN(GLUSTERD_STORE_KEY_BRICK_HOSTNAME))) {
2742
if (snprintf(ta_brickinfo->hostname,
2743
sizeof(ta_brickinfo->hostname), "%s",
2744
value) >= sizeof(ta_brickinfo->hostname)) {
2745
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2746
GD_MSG_PARSE_BRICKINFO_FAIL,
2747
"brick hostname truncated: %s",
2748
ta_brickinfo->hostname);
2751
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PATH,
2752
SLEN(GLUSTERD_STORE_KEY_BRICK_PATH))) {
2753
if (snprintf(ta_brickinfo->path, sizeof(ta_brickinfo->path),
2754
"%s", value) >= sizeof(ta_brickinfo->path)) {
2755
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2756
GD_MSG_PARSE_BRICKINFO_FAIL,
2757
"brick path truncated: %s", ta_brickinfo->path);
2760
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_REAL_PATH,
2761
SLEN(GLUSTERD_STORE_KEY_BRICK_REAL_PATH))) {
2762
if (snprintf(ta_brickinfo->real_path,
2763
sizeof(ta_brickinfo->real_path), "%s",
2764
value) >= sizeof(ta_brickinfo->real_path)) {
2765
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2766
GD_MSG_PARSE_BRICKINFO_FAIL,
2767
"real_path truncated: %s",
2768
ta_brickinfo->real_path);
2771
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PORT,
2772
SLEN(GLUSTERD_STORE_KEY_BRICK_PORT))) {
2773
ret = gf_string2int(value, &ta_brickinfo->port);
2775
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2776
GD_MSG_INCOMPATIBLE_VALUE,
2777
"Failed to convert "
2778
"string to integer");
2781
if (ta_brickinfo->port < priv->base_port) {
2784
ta_brickinfo->port = 0;
2786
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT,
2787
SLEN(GLUSTERD_STORE_KEY_BRICK_RDMA_PORT))) {
2788
ret = gf_string2int(value, &ta_brickinfo->rdma_port);
2790
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2791
GD_MSG_INCOMPATIBLE_VALUE,
2792
"Failed to convert "
2793
"string to integer");
2796
if (ta_brickinfo->rdma_port < priv->base_port) {
2799
ta_brickinfo->rdma_port = 0;
2801
} else if (!strncmp(
2802
key, GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED,
2803
SLEN(GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED))) {
2804
ret = gf_string2int(value, &ta_brickinfo->decommissioned);
2806
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2807
GD_MSG_INCOMPATIBLE_VALUE,
2808
"Failed to convert "
2809
"string to integer");
2812
} else if (!strcmp(key, GLUSTERD_STORE_KEY_BRICK_ID)) {
2813
if (snprintf(ta_brickinfo->brick_id,
2814
sizeof(ta_brickinfo->brick_id), "%s",
2815
value) >= sizeof(ta_brickinfo->brick_id)) {
2816
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
2817
GD_MSG_PARSE_BRICKINFO_FAIL,
2818
"brick_id truncated: %s",
2819
ta_brickinfo->brick_id);
2822
} else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_FSID,
2823
SLEN(GLUSTERD_STORE_KEY_BRICK_FSID))) {
2824
ret = gf_string2uint64(value, &ta_brickinfo->statfs_fsid);
2826
gf_msg(this->name, GF_LOG_ERROR, 0,
2827
GD_MSG_INVALID_ENTRY,
2829
"is not a valid uint64_t value",
2832
} else if (!strcmp(key, GLUSTERD_STORE_KEY_BRICK_UUID)) {
2833
gf_uuid_parse(value, brickinfo->uuid);
2834
} else if (!strncmp(
2835
key, GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS,
2836
SLEN(GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS))) {
2837
ret = gf_string2int(value, &ta_brickinfo->snap_status);
2839
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
2840
GD_MSG_INCOMPATIBLE_VALUE,
2841
"Failed to convert "
2842
"string to integer");
2846
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_UNKNOWN_KEY,
2847
"Unknown key: %s", key);
2854
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2857
GLUSTERD_ASSIGN_BRICKID_TO_TA_BRICKINFO(ta_brickinfo, volinfo,
2861
cds_list_add_tail(&ta_brickinfo->brick_list, &volinfo->ta_bricks);
2863
if (gf_store_iter_destroy(&iter)) {
2864
gf_msg(this->name, GF_LOG_ERROR, 0,
2865
GD_MSG_STORE_ITER_DESTROY_FAIL,
2866
"Failed to destroy store iter");
2873
assign_brick_groups(volinfo);
2881
if (gf_store_iter_destroy(&tmpiter)) {
2882
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
2883
"Failed to destroy store iter");
2887
if (gf_store_iter_destroy(&iter)) {
2888
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
2889
"Failed to destroy store iter");
2893
gf_msg_debug(this->name, 0, "Returning with %d", ret);
2899
glusterd_store_retrieve_node_state(glusterd_volinfo_t *volinfo)
2902
gf_store_iter_t *iter = NULL;
2905
char *dup_value = NULL;
2906
char volpath[PATH_MAX] = {
2909
glusterd_conf_t *priv = NULL;
2910
char path[PATH_MAX] = {
2913
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
2914
dict_t *tmp_dict = NULL;
2915
xlator_t *this = THIS;
2918
priv = this->private;
2922
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv);
2923
len = snprintf(path, sizeof(path), "%s/%s", volpath,
2924
GLUSTERD_NODE_STATE_FILE);
2925
if ((len < 0) || (len >= PATH_MAX)) {
2929
ret = gf_store_handle_retrieve(path, &volinfo->node_state_shandle);
2933
ret = gf_store_iter_new(volinfo->node_state_shandle, &iter);
2938
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
2944
if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG,
2945
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG))) {
2946
volinfo->rebal.defrag_cmd = atoi(value);
2947
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_STATUS,
2948
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_STATUS))) {
2949
volinfo->rebal.defrag_status = atoi(value);
2950
} else if (!strncmp(key, GF_REBALANCE_TID_KEY,
2951
SLEN(GF_REBALANCE_TID_KEY))) {
2952
gf_uuid_parse(value, volinfo->rebal.rebalance_id);
2953
} else if (!strncmp(key, GLUSTERD_STORE_KEY_DEFRAG_OP,
2954
SLEN(GLUSTERD_STORE_KEY_DEFRAG_OP))) {
2955
volinfo->rebal.op = atoi(value);
2956
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES,
2957
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES))) {
2958
sscanf(value, "%" PRIu64, &volinfo->rebal.rebalance_files);
2959
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE,
2960
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE))) {
2961
sscanf(value, "%" PRIu64, &volinfo->rebal.rebalance_data);
2962
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED,
2963
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED))) {
2964
sscanf(value, "%" PRIu64, &volinfo->rebal.lookedup_files);
2965
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES,
2966
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES))) {
2967
sscanf(value, "%" PRIu64, &volinfo->rebal.rebalance_failures);
2968
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED,
2969
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED))) {
2970
sscanf(value, "%" PRIu64, &volinfo->rebal.skipped_files);
2971
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME,
2972
SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME))) {
2973
volinfo->rebal.rebalance_time = atoi(value);
2976
tmp_dict = dict_new();
2982
dup_value = gf_strdup(value);
2985
gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY,
2986
"Failed to strdup value string");
2989
ret = dict_set_str(tmp_dict, key, dup_value);
2991
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
2992
"Error setting data in rebal "
3004
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3007
volinfo->rebal.dict = dict_ref(tmp_dict);
3010
if (op_errno != GD_STORE_EOF) {
3018
if (gf_store_iter_destroy(&iter)) {
3019
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
3020
"Failed to destroy store iter");
3031
if (volinfo->rebal.dict)
3032
dict_unref(volinfo->rebal.dict);
3035
dict_unref(tmp_dict);
3037
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3044
glusterd_chk_update_geo_rep_key_name(char **key)
3046
char *new_key = NULL;
3048
int slen_secondary = 9;
3050
if (strncmp(*key, "slave", slen_slave) != 0)
3053
int new_key_len = slen_secondary + (strlen(*key) - slen_slave);
3055
new_key = GF_MALLOC(new_key_len + 1, gf_common_mt_char);
3059
strcpy(new_key, "secondary");
3060
strcat(new_key, *key + slen_slave);
3066
glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo)
3072
char volpath[PATH_MAX] = {
3075
char path[PATH_MAX] = {
3078
xlator_t *this = THIS;
3079
glusterd_conf_t *conf = NULL;
3080
gf_store_iter_t *iter = NULL;
3081
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
3084
conf = this->private;
3087
GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, conf);
3089
len = snprintf(path, sizeof(path), "%s/%s", volpath,
3090
GLUSTERD_VOLUME_INFO_FILE);
3091
if ((len < 0) || (len >= sizeof(path))) {
3095
ret = gf_store_handle_retrieve(path, &volinfo->shandle);
3097
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HANDLE_NULL,
3098
"volinfo handle is NULL");
3102
ret = gf_store_iter_new(volinfo->shandle, &iter);
3104
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_GET_FAIL,
3105
"Failed to get new store "
3110
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3112
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_GET_FAIL,
3113
"Failed to get next store "
3119
gf_msg_debug(this->name, 0, "key = %s value = %s", key, value);
3120
if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_TYPE,
3121
SLEN(GLUSTERD_STORE_KEY_VOL_TYPE))) {
3122
volinfo->type = atoi(value);
3123
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_COUNT,
3124
SLEN(GLUSTERD_STORE_KEY_VOL_COUNT))) {
3125
volinfo->brick_count = atoi(value);
3126
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_STATUS,
3127
SLEN(GLUSTERD_STORE_KEY_VOL_STATUS))) {
3128
volinfo->status = atoi(value);
3129
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_VERSION,
3130
SLEN(GLUSTERD_STORE_KEY_VOL_VERSION))) {
3131
volinfo->version = atoi(value);
3132
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_PORT,
3133
SLEN(GLUSTERD_STORE_KEY_VOL_PORT))) {
3134
volinfo->port = atoi(value);
3135
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_SUB_COUNT,
3136
SLEN(GLUSTERD_STORE_KEY_VOL_SUB_COUNT))) {
3137
volinfo->sub_count = atoi(value);
3138
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_REPLICA_CNT,
3139
SLEN(GLUSTERD_STORE_KEY_VOL_REPLICA_CNT))) {
3140
volinfo->replica_count = atoi(value);
3141
} else if (!strcmp(key, GLUSTERD_STORE_KEY_VOL_ARBITER_CNT)) {
3142
volinfo->arbiter_count = atoi(value);
3143
} else if (!strcmp(key, GLUSTERD_STORE_KEY_VOL_THIN_ARBITER_CNT)) {
3144
volinfo->thin_arbiter_count = atoi(value);
3145
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT,
3146
SLEN(GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT))) {
3147
volinfo->disperse_count = atoi(value);
3148
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_REDUNDANCY_CNT,
3149
SLEN(GLUSTERD_STORE_KEY_VOL_REDUNDANCY_CNT))) {
3150
volinfo->redundancy_count = atoi(value);
3151
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_TRANSPORT,
3152
SLEN(GLUSTERD_STORE_KEY_VOL_TRANSPORT))) {
3153
volinfo->transport_type = atoi(value);
3154
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_ID,
3155
SLEN(GLUSTERD_STORE_KEY_VOL_ID))) {
3156
ret = gf_uuid_parse(value, volinfo->volume_id);
3158
gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_UUID_PARSE_FAIL,
3159
"failed to parse uuid");
3161
} else if (!strncmp(key, GLUSTERD_STORE_KEY_USERNAME,
3162
SLEN(GLUSTERD_STORE_KEY_USERNAME))) {
3163
glusterd_auth_set_username(volinfo, value);
3165
} else if (!strncmp(key, GLUSTERD_STORE_KEY_PASSWORD,
3166
SLEN(GLUSTERD_STORE_KEY_PASSWORD))) {
3167
glusterd_auth_set_password(volinfo, value);
3169
} else if (strstr(key, "secondary") || strstr(key, "slave")) {
3170
glusterd_chk_update_geo_rep_key_name(&key);
3171
ret = dict_set_dynstr(volinfo->gsync_secondaries, key,
3174
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
3179
gf_msg_debug(this->name, 0,
3182
" secondary:key=%s,value:%s",
3185
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_OP_VERSION,
3186
SLEN(GLUSTERD_STORE_KEY_VOL_OP_VERSION))) {
3187
volinfo->op_version = atoi(value);
3188
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION,
3189
SLEN(GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION))) {
3190
volinfo->client_op_version = atoi(value);
3191
} else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
3192
SLEN(GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT))) {
3193
volinfo->snap_max_hard_limit = (uint64_t)atoll(value);
3194
} else if (!strncmp(
3195
key, GLUSTERD_STORE_KEY_VOL_RESTORED_SNAPNAME_ID,
3196
SLEN(GLUSTERD_STORE_KEY_VOL_RESTORED_SNAPNAME_ID))) {
3197
if (snprintf(volinfo->restored_from_snapname_id,
3198
sizeof(volinfo->restored_from_snapname_id), "%s",
3199
value) >= sizeof(volinfo->restored_from_snapname_id)) {
3200
gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_UUID_PARSE_FAIL,
3201
"failed to parse restored_from_snapname_id");
3203
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_RESTORED_SNAPNAME,
3204
SLEN(GLUSTERD_STORE_KEY_VOL_RESTORED_SNAPNAME))) {
3205
if (snprintf(volinfo->restored_from_snapname,
3206
sizeof(volinfo->restored_from_snapname), "%s",
3207
value) >= sizeof(volinfo->restored_from_snapname)) {
3208
gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_SET_FAILED,
3209
"failed to parse restored_from_snapname");
3211
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP,
3212
SLEN(GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP))) {
3213
ret = gf_uuid_parse(value, volinfo->restored_from_snap);
3215
gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_UUID_PARSE_FAIL,
3216
"failed to parse restored snap's uuid");
3217
} else if (!strncmp(key, GLUSTERD_STORE_KEY_PARENT_VOLNAME,
3218
SLEN(GLUSTERD_STORE_KEY_PARENT_VOLNAME))) {
3219
if (snprintf(volinfo->parent_volname,
3220
sizeof(volinfo->parent_volname), "%s",
3221
value) >= sizeof(volinfo->parent_volname)) {
3222
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
3223
GD_MSG_PARSE_BRICKINFO_FAIL,
3224
"parent_volname truncated: %s", volinfo->parent_volname);
3227
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_SNAP_PLUGIN,
3228
SLEN(GLUSTERD_STORE_KEY_VOL_SNAP_PLUGIN))) {
3229
if (snprintf(volinfo->snap_plugin, sizeof(volinfo->snap_plugin),
3230
"%s", value) >= sizeof(volinfo->snap_plugin)) {
3231
gf_msg("glusterd", GF_LOG_ERROR, op_errno,
3232
GD_MSG_PARSE_BRICKINFO_FAIL, "snap_plugin truncated: %s",
3233
volinfo->snap_plugin);
3236
} else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION,
3237
SLEN(GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION))) {
3238
volinfo->quota_xattr_version = atoi(value);
3240
if (is_key_glusterd_hooks_friendly(key)) {
3244
exists = glusterd_check_option_exists(key, NULL);
3257
if (!strstr(key, GLUSTERD_STORE_KEY_VOL_BRICK) ||
3258
!strstr(key, GF_TIER_ENABLED))
3259
gf_msg(this->name, GF_LOG_WARNING, 0,
3260
GD_MSG_UNKNOWN_KEY, "Unknown key: %s", key);
3270
if (!strcmp(key, "features.limit-usage"))
3272
ret = dict_set_dynstr(volinfo->dict, key, gf_strdup(value));
3274
gf_msg(this->name, GF_LOG_ERROR, 0,
3275
GD_MSG_DICT_SET_FAILED,
3280
gf_msg_debug(this->name, 0,
3282
"set:key=%s,value:%s",
3293
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3298
switch (volinfo->type) {
3299
case GF_CLUSTER_TYPE_NONE:
3300
volinfo->replica_count = 1;
3303
case GF_CLUSTER_TYPE_REPLICATE:
3304
volinfo->replica_count = volinfo->sub_count;
3307
case GF_CLUSTER_TYPE_DISPERSE:
3308
GF_ASSERT(volinfo->disperse_count > 0);
3309
GF_ASSERT(volinfo->redundancy_count > 0);
3317
volinfo->dist_leaf_count = glusterd_get_dist_leaf_count(volinfo);
3319
volinfo->subvol_count = (volinfo->brick_count /
3320
volinfo->dist_leaf_count);
3323
if (!volinfo->op_version && !volinfo->client_op_version)
3324
gd_update_volume_op_versions(volinfo);
3327
if (op_errno != GD_STORE_EOF)
3333
if (gf_store_iter_destroy(&iter)) {
3334
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
3335
"Failed to destroy store iter");
3347
glusterd_store_retrieve_volume(char *volname, glusterd_snap_t *snap)
3350
glusterd_volinfo_t *volinfo = NULL;
3351
glusterd_volinfo_t *origin_volinfo = NULL;
3352
glusterd_conf_t *priv = NULL;
3353
xlator_t *this = THIS;
3355
priv = this->private;
3359
ret = glusterd_volinfo_new(&volinfo);
3363
if (snprintf(volinfo->volname, NAME_MAX + 1, "%s", volname) >= NAME_MAX + 1)
3365
volinfo->snapshot = snap;
3367
volinfo->is_snap_volume = _gf_true;
3369
ret = glusterd_store_update_volinfo(volinfo);
3371
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_UPDATE_FAIL,
3372
"Failed to update volinfo "
3378
ret = glusterd_store_retrieve_bricks(volinfo);
3382
ret = glusterd_store_retrieve_snapd(volinfo);
3386
ret = glusterd_compute_cksum(volinfo, _gf_false);
3390
ret = glusterd_store_retrieve_quota_version(volinfo);
3394
ret = glusterd_store_create_quota_conf_sh_on_absence(volinfo);
3398
ret = glusterd_compute_cksum(volinfo, _gf_true);
3402
ret = glusterd_store_save_quota_version_and_cksum(volinfo);
3407
glusterd_list_add_order(&volinfo->vol_list, &priv->volumes,
3408
glusterd_compare_volume_name);
3411
ret = glusterd_volinfo_find(volinfo->parent_volname, &origin_volinfo);
3413
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
3415
"not found for %s volume",
3419
glusterd_list_add_snapvol(origin_volinfo, volinfo);
3425
glusterd_volinfo_unref(volinfo);
3429
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3435
glusterd_store_set_options_path(glusterd_conf_t *conf, char *path, size_t len)
3437
snprintf(path, len, "%s/options", conf->workdir);
3441
glusterd_store_options(xlator_t *this, dict_t *opts)
3443
gf_store_handle_t *shandle = NULL;
3444
glusterd_conf_t *conf = NULL;
3445
char path[PATH_MAX] = {0};
3448
glusterd_volinfo_data_store_t *dict_data = NULL;
3450
conf = this->private;
3451
glusterd_store_set_options_path(conf, path, sizeof(path));
3453
ret = gf_store_handle_new(path, &shandle);
3458
fd = gf_store_mkstemp(shandle);
3464
dict_data = GF_CALLOC(1, sizeof(glusterd_volinfo_data_store_t),
3465
gf_gld_mt_volinfo_dict_data_t);
3466
if (dict_data == NULL) {
3467
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, NULL);
3470
dict_data->shandle = shandle;
3472
dict_foreach(opts, _storeopts, (void *)dict_data);
3473
if (dict_data->buffer_len > 0) {
3474
ret = gf_store_save_items(fd, dict_data->buffer);
3476
gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, NULL);
3481
ret = gf_store_rename_tmppath(shandle);
3485
if ((ret < 0) && (fd > 0)) {
3486
gf_store_unlink_tmppath(shandle);
3488
gf_store_handle_destroy(shandle);
3493
glusterd_store_retrieve_options(xlator_t *this)
3495
char path[PATH_MAX] = {0};
3496
glusterd_conf_t *conf = NULL;
3497
gf_store_handle_t *shandle = NULL;
3498
gf_store_iter_t *iter = NULL;
3501
gf_store_op_errno_t op_errno = 0;
3504
conf = this->private;
3505
glusterd_store_set_options_path(conf, path, sizeof(path));
3507
ret = gf_store_handle_retrieve(path, &shandle);
3511
ret = gf_store_iter_new(shandle, &iter);
3515
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3517
ret = dict_set_dynstr(conf->opts, key, value);
3527
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3529
if (op_errno != GD_STORE_EOF)
3533
(void)gf_store_iter_destroy(&iter);
3534
gf_store_handle_destroy(shandle);
3539
glusterd_store_retrieve_volumes(xlator_t *this, glusterd_snap_t *snap)
3542
char path[PATH_MAX] = {
3545
glusterd_conf_t *priv = NULL;
3547
struct dirent *entry = NULL;
3548
struct dirent scratch[2] = {
3553
glusterd_volinfo_t *volinfo = NULL;
3557
char entry_path[PATH_MAX] = {
3562
priv = this->private;
3567
len = snprintf(path, PATH_MAX, "%s/snaps/%s", priv->workdir,
3570
len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir,
3571
GLUSTERD_VOLUME_DIR_PREFIX);
3572
if ((len < 0) || (len >= PATH_MAX)) {
3576
dir = sys_opendir(path);
3579
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
3580
"Unable to open dir %s", path);
3584
while ((entry = sys_readdir(dir, scratch))) {
3585
if (gf_irrelevant_entry(entry))
3587
if (snap && ((!strcmp(entry->d_name, "geo-replication")) ||
3588
(!strcmp(entry->d_name, "info"))))
3591
len = snprintf(entry_path, PATH_MAX, "%s/%s", path, entry->d_name);
3592
if ((len < 0) || (len >= PATH_MAX))
3595
ret = sys_lstat(entry_path, &st);
3597
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY,
3598
"Failed to stat entry %s : %s", path, strerror(errno));
3602
if (!S_ISDIR(st.st_mode)) {
3603
gf_msg_debug(this->name, 0, "%s is not a valid volume",
3608
volinfo = glusterd_store_retrieve_volume(entry->d_name, snap);
3610
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOL_RESTORE_FAIL,
3611
"Unable to restore "
3618
ret = glusterd_store_retrieve_node_state(volinfo);
3621
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_NEW_NODE_STATE_CREATION,
3622
"Creating a new node_state "
3625
glusterd_store_create_nodestate_sh_on_absence(volinfo);
3626
glusterd_store_perform_node_state_store(volinfo);
3635
gf_msg_debug(this->name, 0, "Returning with %d", ret);
3642
glusterd_find_brick_mount_path(char *brick_path, char **brick_mount_path)
3646
xlator_t *this = THIS;
3648
GF_ASSERT(brick_path);
3649
GF_ASSERT(brick_mount_path);
3651
*brick_mount_path = gf_strdup(brick_path);
3652
if (!*brick_mount_path) {
3660
ptr = strstr(*brick_mount_path, "brick");
3665
gf_msg(this->name, GF_LOG_ERROR, EINVAL, GD_MSG_INVALID_ENTRY,
3666
"Invalid brick path(%s)", brick_path);
3675
while ((*ptr != '\0') && (*ptr != '/'))
3684
if (ret && *brick_mount_path) {
3685
GF_FREE(*brick_mount_path);
3686
*brick_mount_path = NULL;
3688
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3696
glusterd_mount_brick_paths(glusterd_volinfo_t *volinfo,
3697
glusterd_brickinfo_t *brickinfo, int32_t brick_num)
3700
xlator_t *this = THIS;
3701
glusterd_conf_t *priv = NULL;
3702
struct glusterd_snap_ops *snap_ops = NULL;
3703
char snap_volume_id[GD_VOLUME_NAME_MAX] = "";
3704
char snapname[NAME_MAX] = "";
3706
GF_ASSERT(brickinfo);
3708
priv = this->private;
3711
glusterd_snapshot_plugin_by_name(volinfo->snap_plugin, &snap_ops);
3714
if (volinfo->snapshot) {
3715
strcpy(snap_volume_id, volinfo->volname);
3716
strcpy(snapname, volinfo->snapshot->snapname);
3717
} else if (strlen(volinfo->restored_from_snapname) == 0) {
3720
GLUSTERD_GET_UUID_NOHYPHEN(snap_volume_id, volinfo->volume_id);
3721
strcpy(snapname, volinfo->volname);
3723
strcpy(snap_volume_id, volinfo->restored_from_snapname_id);
3724
strcpy(snapname, volinfo->restored_from_snapname);
3726
ret = snap_ops->activate(brickinfo, snapname, snap_volume_id, brick_num);
3728
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_MOUNT_FAIL,
3729
"Failed to mount snapshot.");
3734
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3739
glusterd_recreate_vol_brick_mounts(xlator_t *this, glusterd_volinfo_t *volinfo)
3741
glusterd_brickinfo_t *brickinfo = NULL;
3743
struct stat st_buf = {
3746
char abspath[PATH_MAX] = {0};
3747
int brick_count = -1;
3751
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
3759
if ((gf_uuid_compare(brickinfo->uuid, MY_UUID)) ||
3760
(brickinfo->snap_status == -1))
3765
ret = sys_lstat(brickinfo->path, &st_buf);
3767
if (errno == ENOENT) {
3770
ret = glusterd_mount_brick_paths(volinfo, brickinfo,
3773
gf_msg(this->name, GF_LOG_ERROR, 0,
3774
GD_MSG_BRK_MNTPATH_MOUNT_FAIL,
3775
"Failed to mount brick_mount_path");
3779
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
3780
"Brick Path(%s) not valid. ", brickinfo->path);
3785
if (!gf_uuid_compare(brickinfo->uuid, MY_UUID)) {
3786
if (brickinfo->real_path[0] == '\0') {
3787
if (!realpath(brickinfo->path, abspath)) {
3788
gf_msg(this->name, GF_LOG_CRITICAL, errno,
3789
GD_MSG_BRICKINFO_CREATE_FAIL,
3790
"realpath() failed for brick %s"
3791
". The underlying file system "
3792
"may be in bad state",
3797
if (strlen(abspath) >= sizeof(brickinfo->real_path)) {
3801
(void)strncpy(brickinfo->real_path, abspath,
3802
sizeof(brickinfo->real_path));
3809
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3814
glusterd_resolve_snap_bricks(xlator_t *this, glusterd_snap_t *snap)
3817
glusterd_volinfo_t *volinfo = NULL;
3818
glusterd_brickinfo_t *brickinfo = NULL;
3820
GF_VALIDATE_OR_GOTO(this->name, snap, out);
3822
cds_list_for_each_entry(volinfo, &snap->volumes, vol_list)
3824
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
3826
ret = glusterd_resolve_brick(brickinfo);
3828
gf_event(EVENT_BRICKPATH_RESOLVE_FAILED,
3829
"peer=%s;volume=%s;brick=%s", brickinfo->hostname,
3830
volinfo->volname, brickinfo->path);
3831
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RESOLVE_BRICK_FAIL,
3832
"resolve brick failed in restore");
3841
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3847
glusterd_store_update_snap(glusterd_snap_t *snap)
3852
char snappath[PATH_MAX] = {
3855
char path[PATH_MAX] = {
3858
xlator_t *this = THIS;
3859
glusterd_conf_t *conf = NULL;
3860
gf_store_iter_t *iter = NULL;
3861
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
3864
conf = this->private;
3867
GLUSTERD_GET_SNAP_DIR(snappath, snap, conf);
3869
len = snprintf(path, sizeof(path), "%s/%s", snappath,
3870
GLUSTERD_SNAP_INFO_FILE);
3871
if ((len < 0) || (len >= sizeof(path))) {
3875
ret = gf_store_handle_retrieve(path, &snap->shandle);
3877
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HANDLE_NULL,
3878
"snap handle is NULL");
3882
ret = gf_store_iter_new(snap->shandle, &iter);
3884
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_GET_FAIL,
3885
"Failed to get new store "
3890
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3892
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_GET_FAIL,
3893
"Failed to get next store "
3899
gf_msg_debug(this->name, 0, "key = %s value = %s", key, value);
3901
if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_ID,
3902
SLEN(GLUSTERD_STORE_KEY_SNAP_ID))) {
3903
ret = gf_uuid_parse(value, snap->snap_id);
3905
gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_UUID_PARSE_FAIL,
3906
"Failed to parse uuid");
3907
} else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_RESTORED,
3908
SLEN(GLUSTERD_STORE_KEY_SNAP_RESTORED))) {
3909
snap->snap_restored = atoi(value);
3910
} else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_STATUS,
3911
SLEN(GLUSTERD_STORE_KEY_SNAP_STATUS))) {
3912
snap->snap_status = atoi(value);
3913
} else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_DESC,
3914
SLEN(GLUSTERD_STORE_KEY_SNAP_DESC))) {
3915
snap->description = gf_strdup(value);
3916
} else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_TIMESTAMP,
3917
SLEN(GLUSTERD_STORE_KEY_SNAP_TIMESTAMP))) {
3918
snap->time_stamp = atoi(value);
3926
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
3929
if (op_errno != GD_STORE_EOF)
3935
if (gf_store_iter_destroy(&iter)) {
3936
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL,
3937
"Failed to destroy store iter");
3945
glusterd_store_retrieve_snap(char *snapname)
3948
glusterd_snap_t *snap = NULL;
3949
glusterd_conf_t *priv = NULL;
3950
xlator_t *this = THIS;
3952
priv = this->private;
3954
GF_ASSERT(snapname);
3956
snap = glusterd_new_snap_object();
3958
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_OBJECT_STORE_FAIL,
3964
if (snprintf(snap->snapname, sizeof(snap->snapname), "%s", snapname) >=
3965
sizeof(snap->snapname))
3967
ret = glusterd_store_update_snap(snap);
3969
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPSHOT_UPDATE_FAIL,
3970
"Failed to update snapshot "
3976
ret = glusterd_store_retrieve_volumes(this, snap);
3978
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_VOL_RETRIEVE_FAIL,
3979
"Failed to retrieve "
3980
"snap volumes for snap %s",
3988
glusterd_list_add_order(&snap->snap_list, &priv->snapshots,
3989
glusterd_compare_snap_time);
3992
gf_msg_trace(this->name, 0, "Returning with %d", ret);
3998
glusterd_store_retrieve_missed_snaps_list(xlator_t *this)
4000
char path[PATH_MAX] = "";
4001
char *snap_vol_id = NULL;
4002
char *missed_node_info = NULL;
4003
char *brick_path = NULL;
4005
char *save_ptr = NULL;
4007
int32_t brick_num = -1;
4008
int32_t snap_op = -1;
4009
int32_t snap_status = -1;
4011
glusterd_conf_t *priv = NULL;
4012
gf_store_op_errno_t store_errno = GD_STORE_SUCCESS;
4014
priv = this->private;
4018
glusterd_store_missed_snaps_list_path_set(path, sizeof(path));
4020
fp = fopen(path, "r");
4023
if (errno != ENOENT) {
4024
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
4025
"Failed to open %s. ", path);
4027
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_MISSED_SNAP_LIST_EMPTY,
4028
"No missed snaps list.");
4036
ret = gf_store_read_and_tokenize(fp, &missed_node_info, &value,
4037
&store_errno, buf, 8192);
4039
if (store_errno == GD_STORE_EOF) {
4040
gf_msg_debug(this->name, 0, "EOF for missed_snap_list");
4044
gf_msg(this->name, GF_LOG_ERROR, store_errno,
4045
GD_MSG_MISSED_SNAP_GET_FAIL,
4046
"Failed to fetch data from "
4047
"missed_snaps_list.");
4052
snap_vol_id = strtok_r(value, ":", &save_ptr);
4053
brick_num = atoi(strtok_r(NULL, ":", &save_ptr));
4054
brick_path = strtok_r(NULL, ":", &save_ptr);
4055
snap_op = atoi(strtok_r(NULL, ":", &save_ptr));
4056
snap_status = atoi(strtok_r(NULL, ":", &save_ptr));
4058
if (!missed_node_info || !brick_path || !snap_vol_id || brick_num < 1 ||
4059
snap_op < 1 || snap_status < 1) {
4060
gf_msg(this->name, GF_LOG_ERROR, EINVAL,
4061
GD_MSG_INVALID_MISSED_SNAP_ENTRY,
4062
"Invalid missed_snap_entry");
4067
ret = glusterd_add_new_entry_to_list(missed_node_info, snap_vol_id,
4068
brick_num, brick_path, snap_op,
4071
gf_msg(this->name, GF_LOG_ERROR, 0,
4072
GD_MSG_MISSED_SNAP_LIST_STORE_FAIL,
4073
"Failed to store missed snaps_list");
4077
} while (store_errno == GD_STORE_SUCCESS);
4084
gf_msg_trace(this->name, 0, "Returning with %d", ret);
4089
glusterd_store_retrieve_snaps(xlator_t *this)
4092
char path[PATH_MAX] = {
4095
glusterd_conf_t *priv = NULL;
4097
struct dirent *entry = NULL;
4098
struct dirent scratch[2] = {
4105
priv = this->private;
4109
len = snprintf(path, PATH_MAX, "%s/snaps", priv->workdir);
4110
if ((len < 0) || (len >= PATH_MAX)) {
4115
dir = sys_opendir(path);
4120
if (errno != ENOENT) {
4122
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
4123
"Unable to open dir %s", path);
4128
while ((entry = sys_readdir(dir, scratch))) {
4129
if (gf_irrelevant_entry(entry))
4131
if (strcmp(entry->d_name, GLUSTERD_MISSED_SNAPS_LIST_FILE)) {
4132
ret = glusterd_store_retrieve_snap(entry->d_name);
4134
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_RESTORE_FAIL,
4135
"Unable to restore snapshot: %s", entry->d_name);
4142
ret = glusterd_store_retrieve_missed_snaps_list(this);
4144
gf_msg_debug(this->name, 0, "Failed to retrieve missed_snaps_list");
4151
gf_msg_debug(this->name, 0, "Returning with %d", ret);
4158
glusterd_store_write_missed_snapinfo(int32_t fd)
4160
char key[GF_UUID_BUF_SIZE * 2];
4161
char value[PATH_MAX];
4163
glusterd_conf_t *priv = NULL;
4164
glusterd_missed_snap_info *missed_snapinfo = NULL;
4165
glusterd_snap_op_t *snap_opinfo = NULL;
4166
xlator_t *this = THIS;
4168
priv = this->private;
4172
cds_list_for_each_entry(missed_snapinfo, &priv->missed_snaps_list,
4175
cds_list_for_each_entry(snap_opinfo, &missed_snapinfo->snap_ops,
4178
snprintf(key, sizeof(key), "%s:%s", missed_snapinfo->node_uuid,
4179
missed_snapinfo->snap_uuid);
4180
snprintf(value, sizeof(value), "%s:%d:%s:%d:%d",
4181
snap_opinfo->snap_vol_id, snap_opinfo->brick_num,
4182
snap_opinfo->brick_path, snap_opinfo->op,
4183
snap_opinfo->status);
4184
ret = gf_store_save_value(fd, key, value);
4186
gf_msg(this->name, GF_LOG_ERROR, 0,
4187
GD_MSG_MISSEDSNAP_INFO_SET_FAIL,
4188
"Failed to write missed snapinfo");
4196
gf_msg_trace(this->name, 0, "Returning %d", ret);
4203
glusterd_store_update_missed_snaps(void)
4207
glusterd_conf_t *priv = NULL;
4208
xlator_t *this = THIS;
4210
priv = this->private;
4213
ret = glusterd_store_create_missed_snaps_list_shandle_on_absence();
4215
gf_msg(this->name, GF_LOG_ERROR, 0,
4216
GD_MSG_MISSED_SNAP_LIST_STORE_HANDLE_GET_FAIL,
4218
"missed_snaps_list store handle.");
4222
fd = gf_store_mkstemp(priv->missed_snaps_list_shandle);
4224
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
4225
"Failed to create tmp file");
4230
ret = glusterd_store_write_missed_snapinfo(fd);
4232
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_MISSED_SNAP_CREATE_FAIL,
4233
"Failed to write missed snaps to disk");
4237
ret = gf_store_rename_tmppath(priv->missed_snaps_list_shandle);
4239
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
4240
"Failed to rename the tmp file");
4244
if (ret && (fd > 0)) {
4245
ret = gf_store_unlink_tmppath(priv->missed_snaps_list_shandle);
4247
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_TMP_FILE_UNLINK_FAIL,
4248
"Failed to unlink the tmp file");
4253
gf_msg_trace(this->name, 0, "Returning %d", ret);
4258
glusterd_store_delete_peerinfo(glusterd_peerinfo_t *peerinfo)
4261
glusterd_conf_t *priv = NULL;
4262
xlator_t *this = THIS;
4263
char peerdir[PATH_MAX] = {
4266
char filepath[PATH_MAX] = {
4269
char hostname_path[PATH_MAX] = {
4279
priv = this->private;
4281
len = snprintf(peerdir, PATH_MAX, "%s/peers", priv->workdir);
4282
if ((len < 0) || (len >= PATH_MAX)) {
4286
if (gf_uuid_is_null(peerinfo->uuid)) {
4287
if (peerinfo->hostname) {
4288
len = snprintf(filepath, PATH_MAX, "%s/%s", peerdir,
4289
peerinfo->hostname);
4290
if ((len < 0) || (len >= PATH_MAX)) {
4298
len = snprintf(filepath, PATH_MAX, "%s/%s", peerdir,
4299
uuid_utoa(peerinfo->uuid));
4300
if ((len < 0) || (len >= PATH_MAX)) {
4303
len = snprintf(hostname_path, PATH_MAX, "%s/%s", peerdir,
4304
peerinfo->hostname);
4305
if ((len < 0) || (len >= PATH_MAX)) {
4309
ret = sys_unlink(hostname_path);
4315
ret = gf_unlink(filepath) ? 0 : -1;
4318
if (peerinfo && peerinfo->shandle) {
4319
gf_store_handle_destroy(peerinfo->shandle);
4320
peerinfo->shandle = NULL;
4322
gf_msg_debug(this->name, 0, "Returning with %d", ret);
4328
glusterd_store_peerinfo_dirpath_set(char *path, size_t len)
4330
glusterd_conf_t *priv = NULL;
4332
GF_ASSERT(len >= PATH_MAX);
4334
priv = THIS->private;
4335
snprintf(path, len, "%s/peers", priv->workdir);
4339
glusterd_store_create_peer_dir(void)
4342
char path[PATH_MAX];
4344
glusterd_store_peerinfo_dirpath_set(path, sizeof(path));
4345
ret = gf_store_mkdir(path);
4347
gf_msg_debug("glusterd", 0, "Returning with %d", ret);
4352
glusterd_store_uuid_peerpath_set(glusterd_peerinfo_t *peerinfo, char *peerfpath,
4355
char peerdir[PATH_MAX];
4359
GF_ASSERT(peerinfo);
4360
GF_ASSERT(peerfpath);
4361
GF_ASSERT(len >= PATH_MAX);
4363
glusterd_store_peerinfo_dirpath_set(peerdir, sizeof(peerdir));
4364
gf_uuid_unparse(peerinfo->uuid, str);
4365
ret = snprintf(peerfpath, len, "%s/%s", peerdir, str);
4366
if (ret < 0 || ret >= len)
4372
glusterd_store_hostname_peerpath_set(glusterd_peerinfo_t *peerinfo,
4373
char *peerfpath, size_t len)
4375
char peerdir[PATH_MAX];
4377
GF_ASSERT(peerinfo);
4378
GF_ASSERT(peerfpath);
4379
GF_ASSERT(len >= PATH_MAX);
4381
glusterd_store_peerinfo_dirpath_set(peerdir, sizeof(peerdir));
4382
ret = snprintf(peerfpath, len, "%s/%s", peerdir, peerinfo->hostname);
4383
if (ret < 0 || ret >= len)
4389
glusterd_store_peerinfo_hostname_shandle_create(glusterd_peerinfo_t *peerinfo)
4391
char peerfpath[PATH_MAX];
4394
ret = glusterd_store_hostname_peerpath_set(peerinfo, peerfpath,
4398
ret = gf_store_handle_create_on_absence(&peerinfo->shandle, peerfpath);
4403
glusterd_store_peerinfo_uuid_shandle_create(glusterd_peerinfo_t *peerinfo)
4405
char peerfpath[PATH_MAX];
4408
ret = glusterd_store_uuid_peerpath_set(peerinfo, peerfpath,
4413
ret = gf_store_handle_create_on_absence(&peerinfo->shandle, peerfpath);
4418
glusterd_peerinfo_hostname_shandle_check_destroy(glusterd_peerinfo_t *peerinfo)
4420
char peerfpath[PATH_MAX];
4422
struct stat stbuf = {
4426
ret = glusterd_store_hostname_peerpath_set(peerinfo, peerfpath,
4430
ret = sys_stat(peerfpath, &stbuf);
4432
if (peerinfo->shandle)
4433
gf_store_handle_destroy(peerinfo->shandle);
4434
peerinfo->shandle = NULL;
4435
ret = sys_unlink(peerfpath);
4441
glusterd_store_create_peer_shandle(glusterd_peerinfo_t *peerinfo)
4445
GF_ASSERT(peerinfo);
4447
if (gf_uuid_is_null(peerinfo->uuid)) {
4448
ret = glusterd_store_peerinfo_hostname_shandle_create(peerinfo);
4450
ret = glusterd_peerinfo_hostname_shandle_check_destroy(peerinfo);
4451
ret = glusterd_store_peerinfo_uuid_shandle_create(peerinfo);
4457
glusterd_store_peer_write(int fd, glusterd_peerinfo_t *peerinfo)
4463
glusterd_peer_hostname_t *hostname = NULL;
4465
ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n%s=%d\n",
4466
GLUSTERD_STORE_KEY_PEER_UUID, uuid_utoa(peerinfo->uuid),
4467
GLUSTERD_STORE_KEY_PEER_STATE, peerinfo->state);
4468
if (ret < 0 || ret >= sizeof(buf) - total_len) {
4474
cds_list_for_each_entry(hostname, &peerinfo->hostnames, hostname_list)
4476
ret = snprintf(buf + total_len, sizeof(buf) - total_len,
4477
GLUSTERD_STORE_KEY_PEER_HOSTNAME "%d=%s\n", i,
4478
hostname->hostname);
4479
if (ret < 0 || ret >= sizeof(buf) - total_len) {
4487
ret = gf_store_save_items(fd, buf);
4489
gf_msg_debug("glusterd", 0, "Returning with %d", ret);
4494
glusterd_store_perform_peer_store(glusterd_peerinfo_t *peerinfo)
4499
GF_ASSERT(peerinfo);
4501
fd = gf_store_mkstemp(peerinfo->shandle);
4507
ret = glusterd_store_peer_write(fd, peerinfo);
4511
ret = gf_store_rename_tmppath(peerinfo->shandle);
4513
if (ret && (fd > 0))
4514
gf_store_unlink_tmppath(peerinfo->shandle);
4515
gf_msg_debug("glusterd", 0, "Returning %d", ret);
4520
glusterd_store_peerinfo(glusterd_peerinfo_t *peerinfo)
4524
GF_ASSERT(peerinfo);
4526
ret = glusterd_store_create_peer_dir();
4530
ret = glusterd_store_create_peer_shandle(peerinfo);
4534
ret = glusterd_store_perform_peer_store(peerinfo);
4536
gf_msg_debug("glusterd", 0, "Returning with %d", ret);
4541
glusterd_store_retrieve_peers(xlator_t *this)
4544
glusterd_conf_t *priv = NULL;
4546
struct dirent *entry = NULL;
4547
struct dirent scratch[2] = {
4552
char path[PATH_MAX] = {
4555
glusterd_peerinfo_t *peerinfo = NULL;
4556
gf_store_handle_t *shandle = NULL;
4557
char filepath[PATH_MAX] = {
4560
gf_store_iter_t *iter = NULL;
4563
glusterd_peerctx_args_t args = {0};
4564
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
4565
glusterd_peer_hostname_t *address = NULL;
4570
priv = this->private;
4574
len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir,
4575
GLUSTERD_PEER_DIR_PREFIX);
4576
if ((len < 0) || (len >= PATH_MAX)) {
4581
dir = sys_opendir(path);
4584
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
4585
"Unable to open dir %s", path);
4590
while ((entry = sys_readdir(dir, scratch))) {
4591
if (gf_irrelevant_entry(entry))
4593
if (gf_uuid_parse(entry->d_name, tmp_uuid) != 0) {
4594
gf_log(this->name, GF_LOG_WARNING, "skipping non-peer file %s",
4599
len = snprintf(filepath, PATH_MAX, "%s/%s", path, entry->d_name);
4600
if ((len < 0) || (len >= PATH_MAX)) {
4603
ret = gf_store_handle_retrieve(filepath, &shandle);
4607
ret = gf_store_iter_new(shandle, &iter);
4611
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
4619
peerinfo = glusterd_peerinfo_new(GD_FRIEND_STATE_DEFAULT, NULL, NULL,
4621
if (peerinfo == NULL) {
4631
if (!strncmp(GLUSTERD_STORE_KEY_PEER_UUID, key,
4632
SLEN(GLUSTERD_STORE_KEY_PEER_UUID))) {
4634
gf_uuid_parse(value, peerinfo->uuid);
4635
} else if (!strncmp(GLUSTERD_STORE_KEY_PEER_STATE, key,
4636
SLEN(GLUSTERD_STORE_KEY_PEER_STATE))) {
4637
peerinfo->state = atoi(value);
4638
} else if (!strncmp(GLUSTERD_STORE_KEY_PEER_HOSTNAME, key,
4639
SLEN(GLUSTERD_STORE_KEY_PEER_HOSTNAME))) {
4640
ret = gd_add_address_to_peer(peerinfo, value, _gf_false);
4642
gf_msg(this->name, GF_LOG_ERROR, 0,
4643
GD_MSG_ADD_ADDRESS_TO_PEER_FAIL,
4644
"Could not add address to peer");
4647
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_UNKNOWN_KEY,
4648
"Unknown key: %s", key);
4656
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
4658
if (op_errno != GD_STORE_EOF) {
4662
if (gf_uuid_is_null(peerinfo->uuid)) {
4663
gf_log("", GF_LOG_ERROR,
4664
"Null UUID while attempting to read peer from '%s'",
4672
address = cds_list_entry(peerinfo->hostnames.next,
4673
glusterd_peer_hostname_t, hostname_list);
4674
peerinfo->hostname = gf_strdup(address->hostname);
4676
ret = glusterd_friend_add_from_peerinfo(peerinfo, 1, NULL);
4680
peerinfo->shandle = shandle;
4684
(void)gf_store_iter_destroy(&iter);
4687
gf_log(this->name, GF_LOG_WARNING,
4688
"skipping malformed peer file %s", entry->d_name);
4690
glusterd_peerinfo_cleanup(peerinfo);
4696
args.mode = GD_MODE_ON;
4699
cds_list_for_each_entry_rcu(peerinfo, &priv->peers, uuid_list)
4701
ret = glusterd_friend_rpc_create(this, peerinfo, &args);
4712
gf_msg_debug(this->name, 0, "Returning with %d", ret);
4723
glusterd_recreate_all_snap_brick_mounts(xlator_t *this)
4726
glusterd_conf_t *priv = NULL;
4727
glusterd_volinfo_t *volinfo = NULL;
4728
glusterd_snap_t *snap = NULL;
4730
priv = this->private;
4734
cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
4737
if (gf_uuid_is_null(volinfo->restored_from_snap))
4740
ret = glusterd_recreate_vol_brick_mounts(this, volinfo);
4742
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BRK_MNT_RECREATE_FAIL,
4743
"Failed to recreate brick mounts "
4753
cds_list_for_each_entry(snap, &priv->snapshots, snap_list)
4755
cds_list_for_each_entry(volinfo, &snap->volumes, vol_list)
4757
if (volinfo->status != GLUSTERD_STATUS_STOPPED) {
4758
ret = glusterd_recreate_vol_brick_mounts(this, volinfo);
4760
gf_msg(this->name, GF_LOG_ERROR, 0,
4761
GD_MSG_BRK_MNT_RECREATE_FAIL,
4762
"Failed to recreate brick "
4772
gf_msg_trace(this->name, 0, "Returning with %d", ret);
4790
glusterd_snap_cleanup(xlator_t *this)
4792
dict_t *dict = NULL;
4794
glusterd_conf_t *priv = NULL;
4795
glusterd_snap_t *snap = NULL;
4796
glusterd_snap_t *tmp_snap = NULL;
4798
priv = this->private;
4803
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_CREATE_FAIL,
4804
"Failed to create dict");
4809
cds_list_for_each_entry_safe(snap, tmp_snap, &priv->snapshots, snap_list)
4811
if (snap->snap_status == GD_SNAP_STATUS_RESTORED) {
4812
ret = glusterd_snapshot_revert_restore_from_snap(snap);
4814
gf_msg(this->name, GF_LOG_WARNING, 0,
4815
GD_MSG_SNAP_RESTORE_REVERT_FAIL,
4817
"revert partially restored snapshot "
4822
} else if (snap->snap_status != GD_SNAP_STATUS_IN_USE) {
4823
ret = glusterd_snap_remove(dict, snap, _gf_true, _gf_true,
4826
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_REMOVE_FAIL,
4827
"Failed to remove the snapshot %s", snap->snapname);
4836
gf_msg_trace(this->name, 0, "Returning with %d", ret);
4841
glusterd_resolve_all_bricks(xlator_t *this)
4844
glusterd_conf_t *priv = NULL;
4845
glusterd_volinfo_t *volinfo = NULL;
4846
glusterd_brickinfo_t *brickinfo = NULL;
4847
glusterd_snap_t *snap = NULL;
4849
priv = this->private;
4854
cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
4856
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
4858
ret = glusterd_resolve_brick(brickinfo);
4860
gf_event(EVENT_BRICKPATH_RESOLVE_FAILED,
4861
"peer=%s;volume=%s;brick=%s", brickinfo->hostname,
4862
volinfo->volname, brickinfo->path);
4863
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_RESOLVE_BRICK_FAIL,
4864
"Failed to resolve brick %s with host %s of volume %s"
4866
brickinfo->path, brickinfo->hostname, volinfo->volname);
4873
cds_list_for_each_entry(snap, &priv->snapshots, snap_list)
4875
ret = glusterd_resolve_snap_bricks(this, snap);
4877
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_RESOLVE_BRICK_FAIL,
4878
"resolving the snap bricks"
4879
" failed for snap: %s",
4886
gf_msg_trace(this->name, 0, "Returning with %d", ret);
4891
glusterd_restore(void)
4894
xlator_t *this = THIS;
4896
ret = glusterd_options_init(this);
4900
ret = glusterd_store_retrieve_volumes(this, NULL);
4904
ret = glusterd_store_retrieve_peers(this);
4916
ret = glusterd_store_retrieve_snaps(this);
4920
ret = glusterd_resolve_all_bricks(this);
4924
ret = glusterd_snap_cleanup(this);
4926
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_CLEANUP_FAIL,
4927
"Failed to perform "
4928
"a cleanup of the snapshots");
4932
ret = glusterd_recreate_all_snap_brick_mounts(this);
4934
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAP_BRK_MNT_RECREATE_FAIL,
4935
"Failed to recreate "
4936
"all snap brick mounts");
4941
gf_msg_debug(this->name, 0, "Returning %d", ret);
4946
glusterd_store_retrieve_quota_version(glusterd_volinfo_t *volinfo)
4949
uint32_t version = 0;
4950
char cksum_path[PATH_MAX] = {
4953
char path[PATH_MAX] = {
4956
char *version_str = NULL;
4958
xlator_t *this = THIS;
4959
glusterd_conf_t *conf = NULL;
4960
gf_store_handle_t *handle = NULL;
4963
conf = this->private;
4966
GLUSTERD_GET_VOLUME_DIR(path, volinfo, conf);
4967
len = snprintf(cksum_path, sizeof(cksum_path), "%s/%s", path,
4968
GLUSTERD_VOL_QUOTA_CKSUM_FILE);
4969
if ((len < 0) || (len >= sizeof(cksum_path))) {
4973
ret = gf_store_handle_new(cksum_path, &handle);
4975
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_GET_FAIL,
4976
"Unable to get store handle "
4982
ret = gf_store_retrieve_value(handle, "version", &version_str);
4984
gf_msg_debug(this->name, 0, "Version absent");
4989
version = strtoul(version_str, &tmp, 10);
4990
if ((errno == ERANGE) || (errno == EINVAL)) {
4991
gf_msg_debug(this->name, 0, "Invalid version number");
4994
volinfo->quota_conf_version = version;
4999
GF_FREE(version_str);
5000
gf_store_handle_destroy(handle);
5005
glusterd_store_save_quota_version_and_cksum(glusterd_volinfo_t *volinfo)
5007
gf_store_handle_t *shandle = NULL;
5008
glusterd_conf_t *conf = NULL;
5009
xlator_t *this = THIS;
5010
char path[PATH_MAX] = {0};
5011
char cksum_path[PATH_MAX + 32] = {
5019
conf = this->private;
5021
GLUSTERD_GET_VOLUME_DIR(path, volinfo, conf);
5022
len = snprintf(cksum_path, sizeof(cksum_path), "%s/%s", path,
5023
GLUSTERD_VOL_QUOTA_CKSUM_FILE);
5024
if ((len < 0) || (len >= sizeof(cksum_path))) {
5028
ret = gf_store_handle_new(cksum_path, &shandle);
5032
fd = gf_store_mkstemp(shandle);
5038
ret = snprintf(buf, sizeof(buf), "cksum=%u\nversion=%u\n",
5039
volinfo->quota_conf_cksum, volinfo->quota_conf_version);
5040
if (ret < 0 || ret >= sizeof(buf)) {
5045
ret = gf_store_save_items(fd, buf);
5047
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_STORE_FAIL,
5048
"Failed to store quota cksum and version");
5052
ret = gf_store_rename_tmppath(shandle);
5057
if ((ret < 0) && (fd > 0))
5058
gf_store_unlink_tmppath(shandle);
5059
gf_store_handle_destroy(shandle);
5064
glusterd_quota_conf_write_header(int fd)
5066
int header_len = SLEN(QUOTA_CONF_HEADER);
5069
ret = gf_nwrite(fd, QUOTA_CONF_HEADER, header_len);
5071
if (ret != header_len) {
5072
gf_msg_callingfn("quota", GF_LOG_ERROR, 0, GD_MSG_QUOTA_CONF_WRITE_FAIL,
5074
"header to a quota conf");
5082
glusterd_quota_conf_write_gfid(int fd, void *buf, char type)
5086
ret = gf_nwrite(fd, buf, 16);
5092
ret = gf_nwrite(fd, &type, 1);
5102
gf_msg_callingfn("quota", GF_LOG_ERROR, 0, GD_MSG_QUOTA_CONF_WRITE_FAIL,
5104
"gfid %s to a quota conf",