From 2e58513506919899115935c2ca6b2359fdeff7b8 Mon Sep 17 00:00:00 2001 From: Rajesh Joseph Date: Thu, 20 Feb 2014 19:22:23 +0530 Subject: gluster/snapshot: Create missing backend snapshot folder Snapshot volume bricks are mounted under /var/run/gluster/snaps folder. In the latest machines /var/run is a symbolic link to /run folder. In such cases if we use /var/run then there would be mismatch between mtab entry for the mount and the folder where we actually mount. Therefore this patch will get the correct folder and also create it if the folder is missing. Change-Id: I267aa7f3e171b486c5b3bb2a9f88cbd4be0e47ea BUG: 1072253 Signed-off-by: Rajesh Joseph Reviewed-on: http://review.gluster.org/7140 --- xlators/mgmt/glusterd/src/glusterd.c | 109 +++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 37 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd.c') diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index edb36b7d8..4d5e6310f 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); -- cgit