summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-store.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c131
1 files changed, 81 insertions, 50 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 6f67a1bfc80..863b70c7ccb 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -52,7 +52,7 @@ glusterd_store_mkdir (char *path)
ret = mkdir (path, 0777);
if ((-1 == ret) && (EEXIST != errno)) {
- gf_log ("", GF_LOG_ERROR, "mkdir() failed on path %s,"
+ gf_log (THIS->name, GF_LOG_ERROR, "mkdir() failed on path %s,"
"errno: %s", path, strerror (errno));
} else {
ret = 0;
@@ -72,8 +72,8 @@ glusterd_store_handle_create_on_absence (glusterd_store_handle_t **shandle,
ret = glusterd_store_handle_new (path, shandle);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to create store"
- " handle for path: %s", path);
+ gf_log (THIS->name, GF_LOG_ERROR, "Unable to create "
+ "store handle for path: %s", path);
}
}
return ret;
@@ -91,7 +91,7 @@ glusterd_store_mkstemp (glusterd_store_handle_t *shandle)
snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path);
fd = open (tmppath, O_RDWR | O_CREAT | O_TRUNC | O_SYNC, 0600);
if (fd <= 0) {
- gf_log ("glusterd", GF_LOG_ERROR, "Failed to open %s, "
+ gf_log (THIS->name, GF_LOG_ERROR, "Failed to open %s, "
"error: %s", tmppath, strerror (errno));
}
@@ -178,7 +178,7 @@ glusterd_store_unlink_tmppath (glusterd_store_handle_t *shandle)
snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path);
ret = unlink (tmppath);
if (ret && (errno != ENOENT)) {
- gf_log ("glusterd", GF_LOG_ERROR, "Failed to mv %s to %s, "
+ gf_log (THIS->name, GF_LOG_ERROR, "Failed to mv %s to %s, "
"error: %s", tmppath, shandle->path, strerror (errno));
} else {
ret = 0;
@@ -275,21 +275,26 @@ glusterd_store_is_valid_brickpath (char *volname, char *brick)
glusterd_volinfo_t *volinfo = NULL;
int32_t ret = 0;
size_t volname_len = strlen (volname);
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
if (ret) {
- gf_log ("", GF_LOG_WARNING, "brick path validation failed");
+ gf_log (this->name, GF_LOG_WARNING, "Failed to create brick "
+ "info for brick %s", brick);
ret = 0;
goto out;
}
ret = glusterd_volinfo_new (&volinfo);
if (ret) {
- gf_log ("", GF_LOG_WARNING, "brick path validation failed");
+ gf_log (this->name, GF_LOG_WARNING, "Failed to create volinfo");
ret = 0;
goto out;
}
if (volname_len >= sizeof (volinfo->volname)) {
- gf_log ("", GF_LOG_WARNING, "volume name too long");
+ gf_log (this->name, GF_LOG_WARNING, "volume name too long");
ret = 0;
goto out;
}
@@ -380,7 +385,7 @@ glusterd_store_brickinfo_write (int fd, glusterd_brickinfo_t *brickinfo)
goto out;
out:
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -406,7 +411,7 @@ out:
glusterd_store_unlink_tmppath (brickinfo->shandle);
if (fd > 0)
close (fd);
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -436,7 +441,7 @@ glusterd_store_brickinfo (glusterd_volinfo_t *volinfo,
ret = glusterd_store_perform_brick_store (brickinfo);
out:
- gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning with %d", ret);
return ret;
}
@@ -507,6 +512,10 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo)
DIR *dir = NULL;
struct dirent *entry = NULL;
char path[PATH_MAX] = {0,};
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
GF_ASSERT (volinfo);
@@ -516,7 +525,7 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo)
goto out;
}
- priv = THIS->private;
+ priv = this->private;
GF_ASSERT (priv);
GLUSTERD_GET_BRICK_DIR (brickdir, volinfo, priv);
@@ -530,7 +539,7 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo)
brickdir, entry->d_name);
ret = unlink (path);
if (ret && errno != ENOENT) {
- gf_log ("", GF_LOG_ERROR, "Unable to unlink %s, "
+ gf_log (this->name, GF_LOG_ERROR, "Unable to unlink %s, "
"reason: %s", path, strerror(errno));
}
glusterd_for_each_entry (entry, dir);
@@ -541,7 +550,7 @@ glusterd_store_remove_bricks (glusterd_volinfo_t *volinfo)
ret = rmdir (brickdir);
out:
- gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ gf_log (this->name, GF_LOG_DEBUG, "Returning with %d", ret);
return ret;
}
@@ -550,6 +559,10 @@ _storeslaves (dict_t *this, char *key, data_t *value, void *data)
{
int32_t ret = 0;
glusterd_store_handle_t *shandle = NULL;
+ xlator_t *xl = NULL;
+
+ xl = THIS;
+ GF_ASSERT (xl);
shandle = (glusterd_store_handle_t*)data;
@@ -567,12 +580,12 @@ _storeslaves (dict_t *this, char *key, data_t *value, void *data)
if (!value || !value->data)
return -1;
- gf_log ("", GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s",
+ gf_log (xl->name, GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s",
key, value->data);
ret = glusterd_store_save_value (shandle->fd, key, (char*)value->data);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to write into store"
+ gf_log (xl->name, GF_LOG_ERROR, "Unable to write into store"
" handle for path: %s", shandle->path);
return -1;
}
@@ -585,6 +598,10 @@ int _storeopts (dict_t *this, char *key, data_t *value, void *data)
int32_t ret = 0;
int32_t exists = 0;
glusterd_store_handle_t *shandle = NULL;
+ xlator_t *xl = NULL;
+
+ xl = THIS;
+ GF_ASSERT (xl);
shandle = (glusterd_store_handle_t*)data;
@@ -610,19 +627,19 @@ int _storeopts (dict_t *this, char *key, data_t *value, void *data)
}
if (1 == exists) {
- gf_log ("", GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s",
- key, value->data);
+ gf_log (xl->name, GF_LOG_DEBUG, "Storing in volinfo:key= %s, "
+ "val=%s", key, value->data);
} else {
- gf_log ("", GF_LOG_DEBUG, "Discarding:key= %s, val=%s",
+ gf_log (xl->name, GF_LOG_DEBUG, "Discarding:key= %s, val=%s",
key, value->data);
return 0;
}
ret = glusterd_store_save_value (shandle->fd, key, (char*)value->data);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to write into store"
- " handle for path: %s", shandle->path);
+ gf_log (xl->name, GF_LOG_ERROR, "Unable to write into store"
+ " handle for path: %s", shandle->path);
return -1;
}
return 0;
@@ -717,8 +734,8 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo)
out:
if (ret)
- gf_log ("", GF_LOG_ERROR, "Unable to write volume values"
- " for %s", volinfo->volname);
+ gf_log (THIS->name, GF_LOG_ERROR, "Unable to write volume "
+ "values for %s", volinfo->volname);
return ret;
}
@@ -747,7 +764,7 @@ glusterd_store_create_volume_dir (glusterd_volinfo_t *volinfo)
glusterd_store_voldirpath_set (volinfo, voldirpath,
sizeof (voldirpath));
ret = glusterd_store_mkdir (voldirpath);
- gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning with %d", ret);
return ret;
}
@@ -771,7 +788,7 @@ glusterd_store_volinfo_write (int fd, glusterd_volinfo_t *volinfo)
dict_foreach (volinfo->gsync_slaves, _storeslaves, shandle);
shandle->fd = 0;
out:
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -881,7 +898,7 @@ glusterd_store_brickinfos (glusterd_volinfo_t *volinfo, int vol_fd)
brick_count++;
}
out:
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -972,7 +989,7 @@ out:
glusterd_store_unlink_tmppath (volinfo->rb_shandle);
if (fd > 0)
close (fd);
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1039,7 +1056,7 @@ out:
glusterd_store_unlink_tmppath (volinfo->node_state_shandle);
if (fd > 0)
close (fd);
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1069,7 +1086,7 @@ out:
glusterd_store_unlink_tmppath (volinfo->shandle);
if (fd > 0)
close (fd);
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1219,7 +1236,7 @@ out:
if (ret)
glusterd_store_volume_cleanup_tmp (volinfo);
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1235,21 +1252,28 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
struct dirent *entry = NULL;
char path[PATH_MAX] = {0,};
struct stat st = {0, };
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
GF_ASSERT (volinfo);
- priv = THIS->private;
+ priv = this->private;
GF_ASSERT (priv);
snprintf (pathname, sizeof (pathname), "%s/vols/%s", priv->workdir,
volinfo->volname);
dir = opendir (pathname);
- if (!dir)
+ if (!dir) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to open directory %s."
+ " Reason : %s", pathname, strerror (errno));
goto out;
+ }
ret = glusterd_store_remove_bricks (volinfo);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Remove bricks failed for %s",
+ gf_log (this->name, GF_LOG_ERROR, "Remove bricks failed for %s",
volinfo->volname);
}
@@ -1259,8 +1283,8 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
snprintf (path, PATH_MAX, "%s/%s", pathname, entry->d_name);
ret = stat (path, &st);
if (ret == -1) {
- gf_log ("", GF_LOG_ERROR, "Failed to stat entry: %s:%s",
- path, strerror (errno));
+ gf_log (this->name, GF_LOG_ERROR, "Failed to stat "
+ "entry %s : %s", path, strerror (errno));
goto stat_failed;
}
@@ -1270,11 +1294,11 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
ret = unlink (path);
if (ret)
- gf_log ("", GF_LOG_INFO, "errno:%d (%s)", errno,
- strerror (errno));
+ gf_log (this->name, GF_LOG_ERROR, " Failed to remove "
+ "%s. Reason : %s", path, strerror (errno));
- gf_log ("", GF_LOG_INFO, "%s %s",
- ret?"Failed to remove":"Removed",
+ gf_log (this->name, ret ? GF_LOG_ERROR : GF_LOG_DEBUG, "%s %s",
+ ret ? "Failed to remove":"Removed",
entry->d_name);
stat_failed:
memset (path, 0, sizeof(path));
@@ -1283,13 +1307,13 @@ stat_failed:
ret = closedir (dir);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Failed to close dir, errno:%d",
- errno);
+ gf_log (this->name, GF_LOG_ERROR, "Failed to close dir %s. "
+ "Reason : %s",pathname, strerror (errno));
}
ret = rmdir (pathname);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Failed to rmdir: %s, err: %s",
+ gf_log (this->name, GF_LOG_ERROR, "Failed to rmdir: %s, err: %s",
pathname, strerror (errno));
}
@@ -1299,7 +1323,7 @@ out:
glusterd_store_handle_destroy (volinfo->shandle);
volinfo->shandle = NULL;
}
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1429,21 +1453,24 @@ glusterd_store_save_value (int fd, char *key, char *value)
{
int32_t ret = -1;
FILE *fp = NULL;
+ xlator_t *this = NULL;
+ this = THIS;
+ GF_ASSERT (this);
GF_ASSERT (fd > 0);
GF_ASSERT (key);
GF_ASSERT (value);
fp = fdopen (fd, "a+");
if (fp == NULL) {
- gf_log ("", GF_LOG_WARNING, "fdopen failed.");
+ gf_log (this->name, GF_LOG_WARNING, "fdopen failed.");
ret = -1;
goto out;
}
ret = fprintf (fp, "%s=%s\n", key, value);
if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "Unable to store key: %s,"
+ gf_log (this->name, GF_LOG_WARNING, "Unable to store key: %s,"
"value: %s, error: %s", key, value,
strerror (errno));
ret = -1;
@@ -1452,7 +1479,7 @@ glusterd_store_save_value (int fd, char *key, char *value)
ret = fflush (fp);
if (feof (fp)) {
- gf_log ("", GF_LOG_WARNING,
+ gf_log (this->name, GF_LOG_WARNING,
"fflush failed, error: %s",
strerror (errno));
ret = -1;
@@ -1462,7 +1489,7 @@ glusterd_store_save_value (int fd, char *key, char *value)
ret = 0;
out:
- gf_log ("", GF_LOG_DEBUG, "returning: %d", ret);
+ gf_log (this->name, GF_LOG_DEBUG, "returning: %d", ret);
return ret;
}
@@ -1473,6 +1500,10 @@ glusterd_store_handle_new (char *path, glusterd_store_handle_t **handle)
glusterd_store_handle_t *shandle = NULL;
int fd = -1;
char *spath = NULL;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
shandle = GF_CALLOC (1, sizeof (*shandle), gf_gld_mt_store_handle_t);
if (!shandle)
@@ -1485,7 +1516,7 @@ glusterd_store_handle_new (char *path, glusterd_store_handle_t **handle)
fd = open (path, O_RDWR | O_CREAT | O_APPEND, 0600);
if (fd <= 0) {
- gf_log ("glusterd", GF_LOG_ERROR, "Failed to open file: %s, "
+ gf_log (this->name, GF_LOG_ERROR, "Failed to open file: %s, "
"error: %s", path, strerror (errno));
goto out;
}
@@ -1507,7 +1538,7 @@ out:
GF_FREE (shandle);
}
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1546,7 +1577,7 @@ glusterd_store_handle_destroy (glusterd_store_handle_t *handle)
ret = 0;
out:
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}