summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c109
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h11
3 files changed, 79 insertions, 47 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 7bfede0..116dd51 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -44,6 +44,8 @@
#include <mntent.h>
#endif
+char snap_mount_folder[PATH_MAX];
+
/* This function will restore a snapshot for the entire
* volume or the entire CG (Consistency Group)
*
@@ -717,7 +719,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
ret = snprintf (snap_mount, sizeof(snap_mount) - 1,
"%s/%s%s-brick",
- GLUSTERD_DEFAULT_SNAPS_BRICK_DIR,
+ snap_mount_folder,
snap_volname, device);
snap_mount[ret] = '\0';
@@ -2772,7 +2774,7 @@ glusterd_snap_brick_create (char *device, glusterd_volinfo_t *snap_volinfo,
snap_brick_dir++;
snprintf (snap_brick_mount_path, sizeof (snap_brick_mount_path),
- "%s/%s%s-brick", GLUSTERD_DEFAULT_SNAPS_BRICK_DIR,
+ "%s/%s%s-brick", snap_mount_folder,
snap_volinfo->volname, tmp);
snprintf (snap_brick_path, sizeof (snap_brick_path), "%s/%s",
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index edb36b7..4d5e631 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -56,6 +56,8 @@ extern struct rpcsvc_program gd_svc_cli_prog_ro;
extern struct rpc_clnt_program gd_brick_prog;
extern struct rpcsvc_program glusterd_mgmt_hndsk_prog;
+extern char snap_mount_folder[PATH_MAX];
+
rpcsvc_cbk_program_t glusterd_cbk_prog = {
.progname = "Gluster Callback",
.prognum = GLUSTER_CBK_PROGRAM,
@@ -1068,6 +1070,70 @@ glusterd_stop_uds_listener (xlator_t *this)
return;
}
+static int
+glusterd_init_snap_folder (xlator_t *this)
+{
+ int ret = -1;
+ struct stat buf = {0,};
+
+ GF_ASSERT (this);
+
+ /* Snapshot volumes are mounted under /var/run/gluster/snaps folder.
+ * But /var/run is normally a symbolic link to /run folder, which
+ * creates problems as the entry point in the mtab for the mount point
+ * and glusterd maintained entry point will be different. Therefore
+ * identify the correct run folder and use it for snap volume mounting.
+ */
+ ret = lstat (GLUSTERD_VAR_RUN_DIR, &buf);
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "stat fails on %s, exiting. (errno = %d)",
+ GLUSTERD_VAR_RUN_DIR, errno);
+ goto out;
+ }
+
+ /* If /var/run is symlink then use /run folder */
+ if (S_ISLNK (buf.st_mode)) {
+ strcpy (snap_mount_folder, GLUSTERD_RUN_DIR);
+ } else {
+ strcpy (snap_mount_folder, GLUSTERD_VAR_RUN_DIR);
+ }
+
+ strcat (snap_mount_folder, GLUSTERD_DEFAULT_SNAPS_BRICK_DIR);
+
+ ret = stat (snap_mount_folder, &buf);
+ if ((ret != 0) && (ENOENT != errno)) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "stat fails on %s, exiting. (errno = %d)",
+ snap_mount_folder, errno);
+ ret = -1;
+ goto out;
+ }
+
+ if ((!ret) && (!S_ISDIR(buf.st_mode))) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "Provided snap path %s is not a directory,"
+ "exiting", snap_mount_folder);
+ ret = -1;
+ goto out;
+ }
+
+ if ((-1 == ret) && (ENOENT == errno)) {
+ /* Create missing folders */
+ ret = mkdir_p (snap_mount_folder, 0777, _gf_false);
+
+ if (-1 == ret) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "Unable to create directory %s"
+ " ,errno = %d", snap_mount_folder, errno);
+ goto out;
+ }
+ }
+
+out:
+ return ret;
+}
+
/*
* init - called during glusterd initialization
*
@@ -1085,7 +1151,6 @@ init (xlator_t *this)
struct stat buf = {0,};
char storedir [PATH_MAX] = {0,};
char workdir [PATH_MAX] = {0,};
- char snap_brick_dir[PATH_MAX] = {0, };
char hooks_dir [PATH_MAX] = {0,};
char cmd_log_filename [PATH_MAX] = {0,};
int first_time = 0;
@@ -1135,42 +1200,12 @@ init (xlator_t *this)
gf_log (this->name, GF_LOG_INFO, "Using %s as working directory",
workdir);
- dir_data = dict_get (this->options, "snap-bricks-path");
- if (!dir_data) {
- //Use default working dir
- strncpy (snap_brick_dir, GLUSTERD_DEFAULT_SNAPS_BRICK_DIR, PATH_MAX);
- } else {
- strncpy (snap_brick_dir, dir_data->data, PATH_MAX);
- }
-
- ret = stat (snap_brick_dir, &buf);
- if ((ret != 0) && (ENOENT != errno)) {
- gf_log (this->name, GF_LOG_ERROR,
- "stat fails on %s, exiting. (errno = %d)",
- workdir, errno);
- exit (1);
- }
-
- if ((!ret) && (!S_ISDIR(buf.st_mode))) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "Provided working area %s is not a directory,"
- "exiting", workdir);
- exit (1);
- }
-
-
- if ((-1 == ret) && (ENOENT == errno)) {
- ret = mkdir (snap_brick_dir, 0777);
-
- if (-1 == ret) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "Unable to create directory %s"
- " ,errno = %d", snap_brick_dir, errno);
- exit (1);
- }
-
- first_time = 1;
- }
+ ret = glusterd_init_snap_folder (this);
+ if (ret) {
+ gf_log (this->name, GF_LOG_CRITICAL, "Unable to create "
+ "snap backend folder");
+ exit (1);
+ }
snprintf (cmd_log_filename, PATH_MAX,"%s/.cmd_log_history",
DEFAULT_LOG_FILE_DIRECTORY);
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index bd76534..8ba6261 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -437,14 +437,9 @@ enum glusterd_vol_comp_status_ {
#define GLUSTERD_VOL_SNAP_DIR_PREFIX "snaps"
#define GLUSTERD_VOL_SNAP_CG_DIR_PREFIX "cgs"
-/* TODO: It was supposed to be /var/run/gluster. But /var/run seems
- to be a symbolic link to /run/gluster which creates problems
- as the entry point in the mtab for the mount point and
- glusterd maintained entry point will be different. Verify
- properly on which path should be used for creating the
- brick directories of snap volumes
-*/
-#define GLUSTERD_DEFAULT_SNAPS_BRICK_DIR "/run/gluster/snaps"
+#define GLUSTERD_DEFAULT_SNAPS_BRICK_DIR "/gluster/snaps"
+#define GLUSTERD_VAR_RUN_DIR "/var/run"
+#define GLUSTERD_RUN_DIR "/run"
/* definitions related to replace brick */
#define RB_CLIENT_MOUNTPOINT "rb_mount"