384
uuid_unparse (volinfo->volume_id, buf);
385
385
ret = glusterd_store_save_value (volinfo->shandle,
386
GLUSTERD_STORE_KEY_VOL_ID, buf);
386
GLUSTERD_STORE_KEY_VOL_ID,
387
uuid_utoa (volinfo->volume_id));
640
glusterd_store_handle_retrieve (char *path, glusterd_store_handle_t **handle)
643
struct stat statbuf = {0};
645
ret = stat (path, &statbuf);
647
gf_log ("glusterd", GF_LOG_ERROR, "Unable to retrieve store "
648
"handle for %s, error: %s", path, strerror (errno));
651
ret = glusterd_store_handle_new (path, handle);
653
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
639
658
glusterd_store_handle_destroy (glusterd_store_handle_t *handle)
732
748
if (!priv->handle) {
733
749
snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
734
750
GLUSTERD_INFO_FILE);
735
ret = glusterd_store_handle_new (path, &handle);
751
ret = glusterd_store_handle_retrieve (path, &handle);
738
754
gf_log ("", GF_LOG_ERROR, "Unable to get store "
827
glusterd_store_validate_key_value (char *storepath, char *key, char*val,
828
glusterd_store_op_errno_t *op_errno)
832
GF_ASSERT (op_errno);
833
GF_ASSERT (storepath);
835
if ((key == NULL) && (val == NULL)) {
837
gf_log ("glusterd", GF_LOG_ERROR, "Glusterd store may be "
838
"corrupted, Invalid key and value (null) in %s",
840
*op_errno = GD_STORE_KEY_VALUE_NULL;
841
} else if (key == NULL) {
843
gf_log ("glusterd", GF_LOG_ERROR, "Glusterd store may be "
844
"corrupted, Invalid key (null) in %s", storepath);
845
*op_errno = GD_STORE_KEY_NULL;
846
} else if (val == NULL) {
848
gf_log ("glusterd", GF_LOG_ERROR, "Glusterd store may be "
849
"corrupted, Invalid value (null) for key %s in %s",
851
*op_errno = GD_STORE_VALUE_NULL;
854
*op_errno = GD_STORE_SUCCESS;
810
861
glusterd_store_iter_get_next (glusterd_store_iter_t *iter,
811
char **key, char **value)
862
char **key, char **value,
863
glusterd_store_op_errno_t *op_errno)
813
865
int32_t ret = -1;
814
866
char scan_str[4096] = {0,};
816
868
char *free_str = NULL;
817
869
char *iter_key = NULL;
818
870
char *iter_val = NULL;
871
glusterd_store_op_errno_t store_errno = GD_STORE_SUCCESS;
820
873
GF_ASSERT (iter);
821
874
GF_ASSERT (iter->file);
823
881
ret = fscanf (iter->file, "%s", scan_str);
885
store_errno = GD_STORE_EOF;
830
889
str = gf_strdup (scan_str);
892
store_errno = GD_STORE_ENOMEM;
836
898
iter_key = strtok (str, "=");
837
gf_log ("", GF_LOG_DEBUG, "key %s read", iter_key);
840
899
iter_val = strtok (NULL, "=");
841
gf_log ("", GF_LOG_DEBUG, "value %s read", iter_val);
844
*value = gf_strdup (iter_val);
901
ret = glusterd_store_validate_key_value (iter->filepath, iter_key,
902
iter_val, &store_errno);
906
*value = gf_strdup (iter_val);
845
908
*key = gf_strdup (iter_key);
847
if (!iter_key || !iter_val)
909
if (!iter_key || !iter_val) {
911
store_errno = GD_STORE_ENOMEM;
854
929
GF_FREE (free_str);
931
*op_errno = store_errno;
856
933
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
865
942
char *tmp_key = NULL;
866
943
char *tmp_value = NULL;
868
ret = glusterd_store_iter_get_next (iter, &tmp_key, &tmp_value);
945
ret = glusterd_store_iter_get_next (iter, &tmp_key, &tmp_value,
870
948
if (!strncmp (key, tmp_key, strlen (key))){
872
950
GF_FREE (tmp_key);
875
953
GF_FREE (tmp_key);
876
954
GF_FREE (tmp_value);
877
ret = glusterd_store_iter_get_next (iter, &tmp_key,
955
ret = glusterd_store_iter_get_next (iter, &tmp_key,
983
glusterd_store_strerror (glusterd_store_op_errno_t op_errno)
986
case GD_STORE_SUCCESS:
988
case GD_STORE_KEY_NULL:
989
return "Invalid Key";
990
case GD_STORE_VALUE_NULL:
991
return "Invalid Value";
992
case GD_STORE_KEY_VALUE_NULL:
993
return "Invalid Key and Value";
996
case GD_STORE_ENOMEM:
999
return "Invalid errno";
1001
return "Invalid errno";
905
1005
glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
959
ret = glusterd_store_iter_get_next (iter, &key, &value);
1060
ret = glusterd_store_iter_get_next (iter, &key, &value,
1063
gf_log ("glusterd", GF_LOG_ERROR, "Unable to iterate "
1064
"the store for brick: %s, reason: %s", path,
1065
glusterd_store_strerror (op_errno));
962
1069
if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_HOSTNAME,
963
1070
strlen (GLUSTERD_STORE_KEY_BRICK_HOSTNAME))) {
987
ret = glusterd_store_iter_get_next (iter, &key, &value);
1094
ret = glusterd_store_iter_get_next (iter, &key, &value,
1098
if (op_errno != GD_STORE_EOF)
990
1100
ret = glusterd_store_iter_destroy (iter);
1018
1128
glusterd_conf_t *priv = NULL;
1019
1129
char path[PATH_MAX] = {0,};
1020
1130
int exists = 0;
1131
glusterd_store_op_errno_t op_errno = GD_STORE_SUCCESS;
1022
1133
ret = glusterd_volinfo_new (&volinfo);
1032
1143
snprintf (path, sizeof (path), "%s/%s", volpath,
1033
1144
GLUSTERD_VOLUME_INFO_FILE);
1035
ret = glusterd_store_handle_new (path, &volinfo->shandle);
1146
ret = glusterd_store_handle_retrieve (path, &volinfo->shandle);
1045
ret = glusterd_store_iter_get_next (iter, &key, &value);
1156
ret = glusterd_store_iter_get_next (iter, &key, &value, &op_errno);
1048
1161
if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_TYPE,
1103
ret = glusterd_store_iter_get_next (iter, &key, &value);
1216
ret = glusterd_store_iter_get_next (iter, &key, &value,
1219
if (op_errno != GD_STORE_EOF)
1106
1222
ret = glusterd_store_iter_destroy (iter);
1227
uuid_unparse (volinfo->volume_id, buf);
1228
1343
ret = glusterd_store_save_value (volinfo->shandle,
1229
GLUSTERD_STORE_KEY_VOL_ID, buf);
1344
GLUSTERD_STORE_KEY_VOL_ID,
1345
uuid_utoa (volinfo->volume_id));
1256
1372
glusterd_conf_t *priv = NULL;
1257
1373
char peerdir[PATH_MAX] = {0,};
1258
1374
char filepath[PATH_MAX] = {0,};
1259
char str[512] = {0,};
1260
1375
char hostname_path[PATH_MAX] = {0,};
1283
uuid_unparse (peerinfo->uuid, str);
1285
snprintf (filepath, PATH_MAX, "%s/%s", peerdir, str);
1399
snprintf (filepath, PATH_MAX, "%s/%s", peerdir,
1400
uuid_utoa (peerinfo->uuid));
1286
1401
snprintf (hostname_path, PATH_MAX, "%s/%s",
1287
1402
peerdir, peerinfo->hostname);
1313
1428
glusterd_conf_t *priv = NULL;
1314
1429
char peerdir[PATH_MAX] = {0,};
1315
1430
char filepath[PATH_MAX] = {0,};
1316
char str[512] = {0,};
1317
1431
char buf[4096] = {0,};
1318
1432
char hostname_path[PATH_MAX] = {0,};
1348
uuid_unparse (peerinfo->uuid, str);
1350
snprintf (filepath, PATH_MAX, "%s/%s", peerdir, str);
1463
snprintf (filepath, PATH_MAX, "%s/%s", peerdir,
1464
uuid_utoa (peerinfo->uuid));
1351
1465
snprintf (hostname_path, PATH_MAX, "%s/%s",
1352
1466
peerdir, peerinfo->hostname);
1376
1490
ret = glusterd_store_save_value (peerinfo->shandle,
1377
GLUSTERD_STORE_KEY_PEER_UUID, str);
1491
GLUSTERD_STORE_KEY_PEER_UUID,
1492
uuid_utoa (peerinfo->uuid));
1433
1549
while (entry) {
1434
1550
snprintf (filepath, PATH_MAX, "%s/%s", path, entry->d_name);
1435
ret = glusterd_store_handle_new (filepath, &shandle);
1551
ret = glusterd_store_handle_retrieve (filepath, &shandle);
1443
ret = glusterd_store_iter_get_next (iter, &key, &value);
1445
gf_log (this->name, GF_LOG_ERROR, "key: %p, and value: %p",
1559
ret = glusterd_store_iter_get_next (iter, &key, &value,
1474
ret = glusterd_store_iter_get_next (iter, &key, &value);
1588
ret = glusterd_store_iter_get_next (iter, &key, &value,
1591
if (op_errno != GD_STORE_EOF)
1477
1594
(void) glusterd_store_iter_destroy (iter);