Skip to contentSkip to conversation

Device Mapper Mirror

PATCH New Jonathan Brassow 1 participant 1 message Nov 7, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Device Mapper Mirror

This patch is not yet finish and should not be pushed upstream in its current form. I provide it here so people can look at it and give me feedback.

brassow

drivers/md/dm-clog-tfr.c new file +216 -0
Index: linux-2.6.18.1/drivers/md/dm-clog-tfr.c
===================================================================
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2006 Red Hat, Inc.
+ *
+ * This file is released under the LGPL.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <net/sock.h>
+#include <linux/workqueue.h>
+#include <linux/dm-clog-tfr.h>
+#include "dm.h"
+
+/*
+ * Pre-allocated nominal request area for speed
+ */
+#define DM_CLOG_NOMINAL_REQUEST_SIZE 512
+static char nominal_request[DM_CLOG_NOMINAL_REQUEST_SIZE];
+
+static struct sock *nl_sk = NULL;
+static DEFINE_MUTEX(_lock);
+static int users = 0;
+//static int server_pid = 0;
+
+static void nl_data_ready (struct sock *sk, int len)
+{
+        wake_up_interruptible(sk->sk_sleep);
+}
+
+static int find_server_process(void)
+{
+	int r = -ENOSYS;
+	struct sk_buff *skb = NULL;
+	struct nlmsghdr *nlh = NULL;
+
+	BUG_ON(!nl_sk);
+
+	skb = alloc_skb(NLMSG_SPACE(0), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
+	nlh = (struct nlmsghdr *)skb->data;
+	nlh->nlmsg_len = NLMSG_SPACE(0);
+	nlh->nlmsg_pid = 0;
+	nlh->nlmsg_flags = 0;
+
+/* Not in newer kernels
+	NETLINK_CB(skb).groups = 1;
+	NETLINK_CB(skb).dst_groups = 1;
+*/
+	NETLINK_CB(skb).pid = 0;
+	NETLINK_CB(skb).dst_pid = 0;
+	NETLINK_CB(skb).dst_group = 1;
+
+	netlink_broadcast(nl_sk, skb, 0, 1, GFP_KERNEL);
+
+	/* Get reply to find out server pid */
+	return r;
+}
+
+static int dm_clog_sendto_server(struct clog_tfr *tfr)
+{
+	BUG_ON(!nl_sk);
+	return -ENOSYS;
+}
+
+static int dm_clog_recvfrom_server(char *rdata, int *rdata_size)
+{
+        struct sk_buff *skb = NULL;
+	struct clog_tfr *tfr = NULL;
+	int r;
+
+	BUG_ON(!nl_sk);
+	skb = skb_recv_datagram(nl_sk, 0, 0, &r);
+	if (r)
+		return r;
+
+	tfr = NLMSG_DATA((struct nlmsghdr *)skb->data);
+
+	if (tfr->error) {
+		r = tfr->error;
+	} else if (tfr->data_size > *rdata_size) {
+		r = -ENOSPC;
+	} else {
+		*rdata_size = tfr->data_size;
+		memcpy(rdata, tfr->data, tfr->data_size);
+	}
+
+	return r;
+}
+
+/*
+ * dm_clog_consult_server
+ * @uuid: log's uuid (must be DM_UUID_LEN in size)
+ * @request_type:
+ * @data: data to tx to the server
+ * @data_size: size of data in bytes
+ * @rdata: place to put return data from server
+ * @rdata_size: value-result (amount of space given/amount of space used)
+ *
+ * Only one process at a time can communicate with the server.
+ * rdata_size is undefined on failure.
+ *
+ * Returns: 0 on success, -EXXX on failure
+ */
+int dm_clog_consult_server(const char *uuid, int request_type,
+			   char *data, int data_size,
+			   char *rdata, int *rdata_size)
+{
+	int r = 0;
+	struct clog_tfr *tfr = (struct clog_tfr *)nominal_request;
+
+	if (data_size > (DM_CLOG_NOMINAL_REQUEST_SIZE - sizeof(*tfr)))
+		/* FIXME: is kmalloc sufficient if we need this much space? */
+		tfr = kmalloc(data_size + sizeof(*tfr), GFP_KERNEL);
+
+	if (!tfr)
+		return -ENOMEM;
+
+	mutex_lock(&_lock);
+
+	memcpy(tfr->uuid, uuid, DM_UUID_LEN);
+	tfr->request_type = request_type;
+	tfr->data_size = data_size;
+
+	r = dm_clog_sendto_server(tfr);
+	if (r < 0) {
+//		DMERR("Unable to send cluster log request to server: %d", r);
+		goto fail;
+	}
+
+	if (rdata) {
+		r = dm_clog_recvfrom_server(rdata, rdata_size);
+
+		if (r < 0)
+			goto fail;
+	} else {
+		/*
+		 * FIXME: If we are using netlink, we may want an
+		 * ack from the server to know that it got the
+		 * request.  (Ack is implicit if we are receiving
+		 * data.)
+		 */
+		r = -ENOSYS;
+	}
+
+fail:
+	if (tfr && (tfr != (struct clog_tfr *)nominal_request))
+		kfree(tfr);
+
+	mutex_unlock(&_lock);
+	return r;
+}
+
+/*
+ * dm_clog_tfr_get
+ *
+ * Set-up or increment reference count on the
+ * netlink used to communicate with the user-space
+ * server.
+ *
+ * Returns: 0 on success, -EXXX on failure
+ */
+int dm_clog_tfr_get(void)
+{
+	int r = 0;
+
+	mutex_lock(&_lock);
+	if (!users) {
+
+		BUG_ON(nl_sk); /* no socket should be present */
+
+		nl_sk = netlink_kernel_create(NETLINK_DMCLOG, 1,
+					      nl_data_ready, THIS_MODULE);
+
+		if (!nl_sk) {
+			r = -ENOMEM;
+			goto fail;
+		}
+
+		r = find_server_process();
+		if (r)
+			goto fail;
+	}
+	users++;
+fail:
+	if (r && nl_sk) {
+		sock_release(nl_sk->sk_socket);
+		nl_sk = NULL;
+	}
+	mutex_unlock(&_lock);
+
+	return r;
+}
+
+/*
+ * dm_clog_tfr_put
+ *
+ * Decrement reference count on the netlink used to
+ * communicate with the user-space server - releasing
+ * the socket if no references remain.
+ *
+ * Returns: 0 on success, -EXXX on failure
+ */
+int dm_clog_tfr_put(void)
+{
+	mutex_lock(&_lock);
+	if (!--users) {
+		sock_release(nl_sk->sk_socket);
+
+		nl_sk = NULL;
+	}
+	mutex_unlock(&_lock);
+
+	return 0;
+}
drivers/md/dm-clog.c new file +596 -0

596 lines not on this page · raw message

drivers/md/Kconfig +9 -0
Index: linux-2.6.18.1/drivers/md/Kconfig
===================================================================
@@ -230,6 +230,15 @@ config DM_MIRROR
          Allow volume managers to mirror logical volumes, also
          needed for live data migration tools such as 'pvmove'.
 
+config DM_CLOG
+	tristate "Mirror cluster logging (EXPERIMENTAL)"
+	depends on DM_MIRROR && EXPERIMENTAL
+	---help---
+	Cluster logging allows mirroring to become cluster-aware.
+	Mirror devices can be used by multiple machines at the
+	same time.  Note: this will not make your applications
+	cluster-aware.
+
 config DM_ZERO
 	tristate "Zero target (EXPERIMENTAL)"
 	depends on BLK_DEV_DM && EXPERIMENTAL
drivers/md/Makefile +2 -0
Index: linux-2.6.18.1/drivers/md/Makefile
===================================================================
@@ -7,6 +7,7 @@ dm-mod-objs	:= dm.o dm-table.o dm-target
 dm-multipath-objs := dm-hw-handler.o dm-path-selector.o dm-mpath.o
 dm-snapshot-objs := dm-snap.o dm-exception-store.o
 dm-mirror-objs	:= dm-log.o dm-raid1.o
+dm-clulog-objs  := dm-clog.o dm-clog-tfr.o
 md-mod-objs     := md.o bitmap.o
 raid456-objs	:= raid5.o raid6algos.o raid6recov.o raid6tables.o \
 		   raid6int1.o raid6int2.o raid6int4.o \
@@ -35,6 +36,7 @@ obj-$(CONFIG_DM_MULTIPATH)	+= dm-multipa
 obj-$(CONFIG_DM_MULTIPATH_EMC)	+= dm-emc.o
 obj-$(CONFIG_DM_SNAPSHOT)	+= dm-snapshot.o
 obj-$(CONFIG_DM_MIRROR)		+= dm-mirror.o
+obj-$(CONFIG_DM_CLOG)		+= dm-clulog.o
 obj-$(CONFIG_DM_ZERO)		+= dm-zero.o
 
 quiet_cmd_unroll = UNROLL  $@
include/linux/dm-clog-tfr.h new file +50 -0

50 lines not on this page · raw message