Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=8975bd6341b2d…
Commit: 8975bd6341b2d94c1f89279b1b00d4360da1f5ff
Parent: 955e85a37c34f2d04980585789c7fe5dbe7d1bf2
Author: Fabio M. Di Nitto <fdinitto(a)redhat.com>
AuthorDate: Wed Jun 27 11:46:01 2012 +0200
Committer: Fabio M. Di Nitto <fdinitto(a)redhat.com>
CommitterDate: Fri Jun 29 11:55:00 2012 +0200
cman-preconfig: allow host aliases as valid cluster nodenames
Resolves: rhbz#786118
Signed-off-by: Fabio M. Di Nitto <fdinitto(a)redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie(a)redhat.com>
---
cman/daemon/cman-preconfig.c | 91 +++++++++++++++++++++++++++++++++++-------
1 files changed, 76 insertions(+), 15 deletions(-)
diff --git a/cman/daemon/cman-preconfig.c b/cman/daemon/cman-preconfig.c
index d88ff3d..68fec22 100644
--- a/cman/daemon/cman-preconfig.c
+++ b/cman/daemon/cman-preconfig.c
@@ -451,7 +451,7 @@ static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
struct sockaddr *sa;
hdb_handle_t nodes_handle;
hdb_handle_t find_handle = 0;
- int error;
+ int found = 0;
/* nodename is either from commandline or from uname */
if (nodelist_byname(objdb, cluster_parent_handle, node))
@@ -497,12 +497,11 @@ static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
}
objdb->object_find_destroy(find_handle);
-
- /* The cluster.conf names may not be related to uname at all,
- they may match a hostname on some network interface.
- NOTE: This is IPv4 only */
- error = getifaddrs(&ifa_list);
- if (error)
+ /*
+ * The cluster.conf names may not be related to uname at all,
+ * they may match a hostname on some network interface.
+ */
+ if (getifaddrs(&ifa_list))
return -1;
for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
@@ -521,12 +520,13 @@ static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
if (sa->sa_family == AF_INET6)
salen = sizeof(struct sockaddr_in6);
- error = getnameinfo(sa, salen, nodename2,
- sizeof(nodename2), NULL, 0, 0);
- if (!error) {
+ if (getnameinfo(sa, salen,
+ nodename2, sizeof(nodename2),
+ NULL, 0, 0) == 0) {
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
strncpy(node, nodename2, sizeof(nodename) - 1);
+ found = 1;
goto out;
}
@@ -537,27 +537,88 @@ static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
strncpy(node, nodename2, sizeof(nodename) - 1);
+ found = 1;
goto out;
}
}
}
/* See if it's the IP address that's in cluster.conf */
- error = getnameinfo(sa, sizeof(*sa), nodename2,
- sizeof(nodename2), NULL, 0, NI_NUMERICHOST);
- if (error)
+ if (getnameinfo(sa, sizeof(*sa),
+ nodename2, sizeof(nodename2),
+ NULL, 0, NI_NUMERICHOST))
continue;
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
strncpy(node, nodename2, sizeof(nodename) - 1);
+ found = 1;
goto out;
}
}
- error = -1;
out:
+ if (found) {
+ freeifaddrs(ifa_list);
+ return 0;
+ }
+
+ /*
+ * This section covers the usecase where the nodename specified in cluster.conf
+ * is an alias specified in /etc/hosts. For example:
+ * <ipaddr> hostname alias1 alias2
+ * and <clusternode name="alias2">
+ * the above calls use uname and getnameinfo does not return aliases.
+ * here we take the name specified in cluster.conf, resolve it to an address
+ * and then compare against all known local ip addresses.
+ * if we have a match, we found our nodename. In theory this chunk of code
+ * could replace all the checks above, but let's avoid any possible regressions
+ * and use it as last.
+ */
+
+ nodes_handle = nodeslist_init(objdb, cluster_parent_handle, &find_handle);
+ while (nodes_handle) {
+ char *dbnodename = NULL;
+ struct addrinfo hints;
+ struct addrinfo *result = NULL, *rp = NULL;
+
+ if (objdb_get_string(objdb, nodes_handle, "name", &dbnodename)) {
+ goto next;
+ }
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_flags = 0;
+ hints.ai_protocol = IPPROTO_UDP;
+
+ if (getaddrinfo(dbnodename, NULL, &hints, &result))
+ goto next;
+
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
+ for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
+ if (ipaddr_equal((struct sockaddr_storage *)rp->ai_addr,
+ (struct sockaddr_storage *)ifa->ifa_addr)) {
+ freeaddrinfo(result);
+ strncpy(node, dbnodename, sizeof(nodename) - 1);
+ found = 1;
+ goto out2;
+ }
+ }
+ }
+
+ freeaddrinfo(result);
+ next:
+ nodes_handle = nodeslist_next(objdb, find_handle);
+ }
+ out2:
+ objdb->object_find_destroy(find_handle);
freeifaddrs(ifa_list);
- return error;
+
+ if (found) {
+ return 0;
+ }
+
+ return -1;
}
/* Get any environment variable overrides */
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=954ccb986b…
Commit: 954ccb986b9a18204e7d3137f4fae97bbcb2be8a
Parent: 9803f25df8f32c8eb4b99957097017df52bdd6fd
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Jun 21 14:14:27 2012 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jun 21 14:14:27 2012 +0100
mkfs.gfs2: Check for symlinks before reporting device contents
When using symlinks with mkfs.gfs2 it reports what the symlink points
to instead of the contents of the device, like so:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
This will destroy any data on /dev/vg/test.
It appears to contain: symbolic link to `../dm-3'
This patch resolves symlinks before checking the device contents to make
the output more informative:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
/dev/vg/test is a symlink to /dev/dm-3
This will destroy any data on /dev/dm-3.
It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_mkfs.c | 35 ++++++++++++++++++++++++++++++++---
1 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e6b00a0..957b144 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -518,19 +518,46 @@ print_results(struct gfs2_sbd *sdp, uint64_t real_device_size,
printf("\n");
}
+
+/**
+ * If path is a symlink, return 1 with *abspath pointing to the absolute path,
+ * otherwise return 0. Exit on errors. The caller must free the memory pointed
+ * to by *abspath.
+ */
+static int is_symlink(char *path, char **abspath)
+{
+ struct stat lnkstat;
+
+ if (lstat(path, &lnkstat) == -1) {
+ perror("Failed to lstat the device");
+ exit(EXIT_FAILURE);
+ }
+ if (!S_ISLNK(lnkstat.st_mode)) {
+ return 0;
+ }
+ *abspath = canonicalize_file_name(path);
+ if (*abspath == NULL) {
+ perror(_("Could not find the absolute path of the device"));
+ exit(EXIT_FAILURE);
+ }
+ printf( _("%s is a symlink to %s\n"), path, *abspath);
+ return 1;
+}
+
/**
* main_mkfs - do everything
* @argc:
* @argv:
*
*/
-
void main_mkfs(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
int error;
int rgsize_specified = 0;
unsigned char uuid[16];
+ char *absname = NULL;
+ int islnk = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = -1;
@@ -561,8 +588,10 @@ void main_mkfs(int argc, char *argv[])
}
if (!sdp->override) {
- printf( _("This will destroy any data on %s.\n"), sdp->device_name);
- check_dev_content(sdp->device_name);
+ islnk = is_symlink(sdp->device_name, &absname);
+ printf(_("This will destroy any data on %s.\n"), islnk ? absname : sdp->device_name);
+ check_dev_content(islnk ? absname : sdp->device_name);
+ free(absname);
are_you_sure();
}