Skip to contentSkip to conversation

check for running cluster log daemon, not just log module

PATCH New Jonathan Brassow 2 participants 5 messages Jul 16, 2010 – Jul 20, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check for running cluster log daemon, not just log module

brassow

It's not enough to check for the kernel module in the case of cluster mirrors, we must also check that the log daemon (cmirrord) is running. The log module can be auto-loaded, but the daemon cannot be "auto-started". Failing to check for the daemon produces cryptic messages that customers have a hard time deciphering. (The system messages do report that the log daemon is not running, but people don't seem to find this message easily.)

Here are examples of what is printed when the module is available, but the log daemon has not been started.

[root at bp-01 LVM2]# lvcreate -m1 -l1 -n lv vg
Shared cluster mirrors are not available.

[root at bp-01 LVM2]# lvcreate -m1 -l1 -n lv vg -v
Setting logging type to disk
Finding volume group "vg"
Archiving volume group "vg" metadata (seqno 3). Creating logical volume lv
Executing: /sbin/modprobe dm-log-userspace
Cluster mirror log daemon is not running
Shared cluster mirrors are not available.
Creating volume group backup "/etc/lvm/backup/vg" (seqno 4).

TODO:
1. check that lvconvert is also covered
2. check pvmove is not negatively affected (should improve pvmove too)

libdm/libdevmapper.h +7 -0
Index: LVM2/libdm/libdevmapper.h
===================================================================
@@ -988,6 +988,13 @@ int dm_asprintf(char **buf, const char *
  */
 int dm_create_lockfile(const char* lockfile);
 
+/*
+ * Query whether a daemon is running based on its lockfile
+ *
+ * Returns: 1 if running, 0 if not
+ */
+int dm_daemon_is_running(const char* lockfile);
+
 /*********************
  * regular expressions
  *********************/
libdm/libdm-file.c +27 -0
Index: LVM2/libdm/libdm-file.c
===================================================================
@@ -166,3 +166,30 @@ fail:
 
 	return 0;
 }
+
+int dm_daemon_is_running(const char* lockfile)
+{
+	int fd;
+	struct flock lock;
+
+	if((fd = open(lockfile, O_RDONLY)) < 0)
+		return 0;
+
+	lock.l_type = F_WRLCK;
+	lock.l_start = 0;
+	lock.l_whence = SEEK_SET;
+	lock.l_len = 0;
+	if (fcntl(fd, F_GETLK, &lock) < 0) {
+		log_error("Cannot check lock status of lockfile [%s], error was [%s]",
+			  lockfile, strerror(errno));
+		if (close(fd))
+			stack;
+		return 0;
+	}
+
+	/* Should we also read and check pid? */
+	if (close(fd))
+		stack;
+
+	return (lock.l_type == F_UNLCK) ? 0 : 1;
+}
lib/metadata/mirror.c +36 -0
Index: LVM2/lib/metadata/mirror.c
===================================================================
@@ -81,6 +81,36 @@ int lv_is_mirrored(const struct logical_
 }
 
 /*
+ * cluster_mirror_is_available
+ *
+ * Check if the proper kernel module and log daemon are running.
+ * Caller should check for 'vg_is_clustered(lv->vg)' before making
+ * this call.
+ *
+ * Returns: 1 if available, 0 otherwise
+ */
+static int cluster_mirror_is_available(struct logical_volume *lv)
+{
+	unsigned attr = 0;
+	struct cmd_context *cmd = lv->vg->cmd;
+	const struct segment_type *segtype;
+
+	if (!(segtype = get_segtype_from_string(cmd, "mirror")))
+		return_0;
+
+	if (!segtype->ops->target_present)
+		return_0;
+
+	if (!segtype->ops->target_present(lv->vg->cmd, NULL, &attr))
+		return_0;
+
+	if (!(attr & MIRROR_LOG_CLUSTERED))
+		return 0;
+
+	return 1;
+}
+
+/*
  * Returns the number of mirrors of the LV
  */
 uint32_t lv_mirror_count(const struct logical_volume *lv)
@@ -1940,6 +1970,12 @@ int lv_add_mirrors(struct cmd_context *c
 		return 0;
 	}
 
+	if (vg_is_clustered(lv->vg) &&  !(lv->status & ACTIVATE_EXCL) &&
+	    !cluster_mirror_is_available(lv)) {
+		log_error("Shared cluster mirrors are not available.");
+		return 0;
+	}
+
 	/* For corelog mirror, activation code depends on
 	 * the global mirror_in_sync status. As we are adding
 	 * a new mirror, it should be set as 'out-of-sync'
lib/mirror/mirrored.c +13 -0
Index: LVM2/lib/mirror/mirrored.c
===================================================================
@@ -519,6 +519,19 @@ static int _mirrored_target_present(stru
 					_mirror_attributes |= MIRROR_LOG_CLUSTERED;
 			} else if (module_present(cmd, "log-userspace"))
 				_mirror_attributes |= MIRROR_LOG_CLUSTERED;
+
+			if (!(_mirror_attributes & MIRROR_LOG_CLUSTERED))
+				log_verbose("Cluster mirror log module is not available");
+
+			/*
+			 * The cluster mirror log daemon must be running,
+			 * otherwise, the kernel module will fail to make
+			 * contact.
+			 */
+			if (!dm_daemon_is_running(CMIRRORD_PIDFILE)) {
+				log_verbose("Cluster mirror log daemon is not running");
+				_mirror_attributes &= ~MIRROR_LOG_CLUSTERED;
+			}
 		}
 		*attributes = _mirror_attributes;
 	}
#1 lore raw

PATCH 1/1 check for running cluster log daemon, not just log module

libdm/libdm-file.c fail: · line 190

Quoted 3 lines · Jon Brassow
libdm/libdm-file.c +2 -0
+int dm_daemon_is_running(const char* lockfile)
 
+	/* Should we also read and check pid? */

Yes - check /proc/<pid>/fd/* if available?

(cf. _get_filename in tools/lvmcmdline.c)

Alasdair

#2 lore raw

PATCH 1/1 check for running cluster log daemon, not just log module

Quoted 8 lines · Alasdair G Kergon

libdm/libdm-file.c fail: · line 190

Quoted 3 lines · Jon Brassow
libdm/libdm-file.c +2 -0
+int dm_daemon_is_running(const char* lockfile)
 
+	/* Should we also read and check pid? */

Yes - check /proc/<pid>/fd/* if available?

(cf. _get_filename in tools/lvmcmdline.c)

I'm not certain how best to go about this, because the function takes a generic argument - it doesn't specifically look for 'cmirrord'. So, unless the PID filename is guaranteed to follow a convention that includes the executable name, I'm not sure how to do more than just validate that /a/ process is running and has the appropriate lock. Sure, I could look-up a pid to see the cmdline and check that against the name of a daemon, but that isn't what we have available. I could check that at least the pid in the file is in the system, but that doesn't gain us anything.

One possible solution is to be less generic and simply make a function called 'dm_cmirrord_is_running', or something. Then I could correlate pid, cmdline, and executable name.

I am considering checking in the patch 'as is' and adding any additional testing in a separate commit if it proves useful.

brassow

#3 lore raw

PATCH 1/1 check for running cluster log daemon, not just log module

The function is named 'daemon_is_running', so it really should still give the correct answer if the daemon is *not* running but a previous instance left the file behind for any reason. I.e. validate that the PID in the file does in fact still exist and have that lockfile open.

Quoted 1 line
Quoted 1 line

Yes - check /proc/<pid>/fd/* if available?

Read pidfile to get PID.

List /proc/<pid>/fd/* and check that one of them (a quick code audit might even enable you to guarantee which one and pass it in as another parameter) points back at the file.

The daemon name doesn't really matter in this: if someone creates other software that uses *our* lockfile then they've got bigger problems, but yes, you could pass that in and check that too.

Alasdair

#4 lore raw

PATCH 1/1 check for running cluster log daemon, not just log module

The lock gets dropped if the process holding it dies, as I remember it. This obviates the need to validate the PID. Sure, a previous instance may have died and left the file in place, but the locks would have been release too - and this is what we are checking for. I'm still not seeing what we gain - unless we can have the name of the executable to validate. This would be the only thing - from my perspective - that would gain us anything. However, you point out that this doesn't really matter, and I agree with you.

brassow

Quoted 22 lines · Alasdair G Kergon

The function is named 'daemon_is_running', so it really should still give the correct answer if the daemon is *not* running but a previous instance left the file behind for any reason. I.e. validate that the PID in the file does in fact still exist and have that lockfile open.

Quoted 1 line
Quoted 1 line

Yes - check /proc/<pid>/fd/* if available?

Read pidfile to get PID.

List /proc/<pid>/fd/* and check that one of them (a quick code audit might even enable you to guarantee which one and pass it in as another parameter) points back at the file.

The daemon name doesn't really matter in this: if someone creates other
software that uses *our* lockfile then they've got bigger problems, but yes,
you could pass that in and check that too.

Alasdair