Skip to contentSkip to conversation

gfs_controld: Allow mounts entirely via sysfs/uevent interface

Cluster-devel Steven Whitehouse 1 participant 1 message Oct 6, 2010

lore
Share & tools
lore
#0 lore raw

This patch adds the ability for gfs_controld to optionally allow mounts via sysfs/uevents rather than requiring the mount.gfs2 helper. Some kernel support is required to do that, and the support is in recent kernels (2.6.36 and up) so this has to be backwards compatible.

The other change is that when a withdraw occurs, the device is now specified by device number. This number is obtained from sysfs and avoids the issue which would otherwise occur with the new mount sequence for which the device path is not available.

There is a flag added to the mount group which determines whether the mount helper exists or not. The flag is set depending on whether the first notification of the filesystem is from the ADD uevent or from the mount helper.

The plan is that the mount helper will be gradually phased out over time.

group/gfs_controld/cpg-new.c +5 -6
index 23b7a86..a72d0f1 100644
@@ -261,7 +261,6 @@ static int daemon_member_count;
 
 static void apply_changes_recovery(struct mountgroup *mg);
 static void send_withdraw_acks(struct mountgroup *mg);
-static void leave_mountgroup(struct mountgroup *mg, int mnterr);
 
 static void log_config(const struct cpg_name *group_name,
 		       const struct cpg_address *member_list,
@@ -1429,14 +1428,14 @@ static void send_recovery_result(struct mountgroup *mg, int jid, int result)
 	free(buf);
 }
 
-void send_remount(struct mountgroup *mg, struct gfsc_mount_args *ma)
+void send_remount(struct mountgroup *mg, int ro)
 {
 	struct gfs_header h;
 
 	memset(&h, 0, sizeof(h));
 
 	h.type = GFS_MSG_REMOUNT;
-	h.msgdata = strstr(ma->options, "ro") ? 1 : 0;
+	h.msgdata = ro;
 
 	gfs_send_message(mg, (char *)&h, sizeof(h));
 }
@@ -1654,7 +1653,7 @@ static void receive_withdraw(struct mountgroup *mg, struct gfs_header *hd,
 	node->withdraw = 1;
 
 	if (hd->nodeid == our_nodeid)
-		leave_mountgroup(mg, 0);
+		gfs_leave_mountgroup(mg, 0);
 }
 
 /* start message from all nodes shows zero started_count */
@@ -2769,7 +2768,7 @@ int gfs_join_mountgroup(struct mountgroup *mg)
    order.  We can just ignore the second.  The second would either not find
    the mg here, or would see mg->leaving of 1 from the first. */
 
-static void leave_mountgroup(struct mountgroup *mg, int mnterr)
+void gfs_leave_mountgroup(struct mountgroup *mg, int mnterr)
 {
 	cpg_error_t error;
 	struct cpg_name name;
@@ -2806,7 +2805,7 @@ void do_leave(struct mountgroup *mg, int mnterr)
 		return;
 	}
 
-	leave_mountgroup(mg, mnterr);
+	gfs_leave_mountgroup(mg, mnterr);
 }
 
 static void receive_withdraw_ack(struct gfs_header *hd, int len)
group/gfs_controld/gfs_daemon.h +4 -4
index fdfc603..d5ea341 100644
@@ -126,12 +126,12 @@ struct mountgroup {
 	int			our_jid;
 	int			spectator;
 	int			ro;
-	int			rw;
 	int                     joining;
 	int                     leaving;
 	int			kernel_mount_error;
 	int			kernel_mount_done;
 	int			first_mounter;
+	int			no_mount_helper;
 
 	/* cpg-new stuff */
 
@@ -181,7 +181,7 @@ void process_mountgroups(void);
 int gfs_join_mountgroup(struct mountgroup *mg);
 void do_leave(struct mountgroup *mg, int mnterr);
 void gfs_mount_done(struct mountgroup *mg);
-void send_remount(struct mountgroup *mg, struct gfsc_mount_args *ma);
+void send_remount(struct mountgroup *mg, int ro);
 void send_withdraw(struct mountgroup *mg);
 int set_mountgroup_info(struct mountgroup *mg, struct gfsc_mountgroup *out);
 int set_node_info(struct mountgroup *mg, int nodeid, struct gfsc_node *node);
@@ -191,6 +191,7 @@ int set_mountgroup_nodes(struct mountgroup *mg, int option, int *node_count,
 void free_mg(struct mountgroup *mg);
 void node_history_cluster_add(int nodeid);
 void node_history_cluster_remove(int nodeid);
+void gfs_leave_mountgroup(struct mountgroup *mg, int mnterr);
 
 /* main.c */
 int do_read(int fd, void *buf, size_t count);
@@ -200,11 +201,10 @@ int client_add(int fd, void (*workfn)(int ci), void (*deadfn)(int ci));
 int client_fd(int ci);
 void client_ignore(int ci, int fd);
 void client_back(int ci, int fd);
-struct mountgroup *create_mg(char *name);
+struct mountgroup *create_mg(const char *name);
 struct mountgroup *find_mg(char *name);
 struct mountgroup *find_mg_id(uint32_t id);
 void client_reply_remount(struct mountgroup *mg, int ci, int result);
-void client_reply_join(int ci, struct gfsc_mount_args *ma, int result);
 void client_reply_join_full(struct mountgroup *mg, int result);
 void query_lock(void);
 void query_unlock(void);
group/gfs_controld/main.c +168 -16

277 lines not on this page · raw message

group/gfs_controld/util.c +28 -11
index c2cb741..5b2e45d 100644
@@ -68,27 +68,44 @@ int set_sysfs(struct mountgroup *mg, const char *field, int val)
 	sprintf(out, "%d", val);
 
 	rv = write(fd, out, strlen(out));
-
+	if (rv < 0)
+		log_group(mg, "set write %s error %d", fname, errno);
 	close(fd);
 
-	if (rv)
-		rv = 0;
-	return rv;
+	return 0;
 }
 
 int run_dmsetup_suspend(struct mountgroup *mg, char *dev)
 {
 	struct sched_param sched_param;
-	char buf[PATH_MAX];
+	char fname[PATH_MAX];
+	char smajor[16];
+	char sminor[16];
 	pid_t pid;
 	int i, rv;
+	int major, minor;
+	FILE *fp;
 
-	memset(buf, 0, sizeof(buf));
-	rv = readlink(dev, buf, PATH_MAX);
-	if (rv < 0)
-		strncpy(buf, dev, sizeof(buf));
+	snprintf(fname, PATH_MAX, "%s/%s/%s/device/dev",
+		 SYSFS_DIR, mg->mount_args.type, mg->mount_args.table);
+
+	fp = fopen(fname, "r");
+	if (fp == NULL) {
+		log_group(mg, "set open %s error %d", fname, errno);
+		return -1;
+	}
+
+	if (fscanf(fp, "%d:%d", &major, &minor) != 2) {
+		log_group(mg, "cannot read device numbers %d", errno);
+		return -1;
+	}
+
+	fclose(fp);
+
+	log_group(mg, "run_dmsetup_suspend %d:%d", major, minor);
 
-	log_group(mg, "run_dmsetup_suspend %s (orig %s)", buf, dev);
+	snprintf(smajor, 16, "%d", major);
+	snprintf(sminor, 16, "%d", minor);
 
 	pid = fork();
 	if (pid < 0)
@@ -106,7 +123,7 @@ int run_dmsetup_suspend(struct mountgroup *mg, char *dev)
 			close(i);
 
 		execlp("dmsetup", "dmsetup", "suspend",  "--nolockfs",
-		       "--noflush", buf, NULL);
+		       "--noflush", "-j", smajor, "-m", sminor, NULL);
 		exit(EXIT_FAILURE);
 	}
 	return -1;