Cluster-aware logging module
Subsystems (2)
PATCH 1/1 Cluster-aware logging module
I have removed the last complaint that I know of (the hard-coded values for 'cn_clog_id'). I have created macros for (reserved us a spot in) include/linux/connector.h. I created a channel for DM to multiplex on. (The cluster log is the first user, the cluster exception store will likely be the second, uevent could be the third, etc.) I did not receive feedback on the RQ_TYPE macro.
Code for the userspace server is currently being housed in LVM2/daemons/clogd. This is a temporary home for the code that will become permanent after review. Currently, to compile the code, you will need to 'cd LVM2/daemons/clogd; make'.
Please review. Please push upstream. Please remember that this patch depends on "dm-raid1-add-is_remote_recovering-hook-for-clusters.patch".
brassow
This patch contains a cluster-aware log module. When used by dm-raid1, device-mapper mirroring can be cluster-aware.
There is a kernel component (provided in this patch) and a user space component. The kernel component implements the logging interface and passes all requests to userspace via 'connector' (a netlink wrapper). The userspace daemon is built upon OpenAIS for cluster communication and is fault tolerant.
drivers/md/dm-clog-tfr.c new file +272 -0
@@ -0,0 +1,272 @@ +/* +* Copyright (C) 2006-2008 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/connector.h> +#include <linux/device-mapper.h> + +#include <linux/dm-cluster-log.h> +#include "dm-clog-tfr.h" + +#include <asm/div64.h> /* Unnecessary */ + +#define SHORT_UUID (x) (strlen(x) > 8) ? ((x) + (strlen(x) - 8)) : (x) + +static uint32_t seq =0 ; + +/* +* Pre-allocated space for speed +*/ +#define DM_CLOG_PREALLOCED_SIZE 512 +static struct cn_msg *prealloced_cn_msg =NULL ; +static struct clog_tfr *prealloced_clog_tfr =NULL ; + +static struct cb_id cn_clog_id = {CN_IDX_DM ,CN_VAL_DM_CLUSTER_LOG }; +static DEFINE_MUTEX (_lock); + +struct receiving_pkg { +struct list_head list; +struct completion complete; + +uint32_t seq; + +int error; +int *data_size; +char *data; +}; + +static spinlock_t receiving_list_lock =SPIN_LOCK_UNLOCKED ; +static struct list_head receiving_list; + +static int dm_clog_sendto_server (struct clog_tfr *tfr) +{ +int r; +int size; +struct cn_msg *msg = prealloced_cn_msg; + +if (tfr != prealloced_clog_tfr) { + size =sizeof (struct cn_msg ) + +sizeof (struct clog_tfr ) + tfr->data_size; + msg =kmalloc (size,GFP_NOIO ); +if (!msg) +return -ENOMEM ; +memcpy ((msg +1 ), tfr, +sizeof (struct clog_tfr ) + tfr->data_size); + } + +memset (msg,0 ,sizeof (struct cn_msg )); + + msg->id.idx = cn_clog_id.idx; + msg->id.val = cn_clog_id.val; + msg->ack =0 ; + msg->seq = tfr->seq; + msg->len =sizeof (struct clog_tfr ) + tfr->data_size; + + r =cn_netlink_send (msg,0 ,gfp_any ()); + +if (msg != prealloced_cn_msg) +kfree (msg); + +return r; +} + +/* +* fill_pkg +* @msg +* @tfr +* +* Parameters can be either msg or tfr, but not both. This +* function fills in the reply for a waiting request. If just +* msg is given, then the reply is simply an ACK from userspace +* that the request was received. +* +* Returns: 0 on success, -ENOENT on failure +*/ +static int fill_pkg (struct cn_msg *msg,struct clog_tfr *tfr) +{ +uint32_t rtn_seq = (msg) ? msg->seq : (tfr) ? tfr->seq :0 ; +struct receiving_pkg *pkg; + +list_for_each_entry (pkg, &receiving_list, list) { +if (rtn_seq != pkg->seq) +continue ; + +if (msg) { + pkg->error = -msg->ack; +/* +* If we are trying again, we will need to know our +* storage capacity. Otherwise, along with the +* error code, we make explicit that we have no data. +*/ +if (pkg->error != -EAGAIN ) + *(pkg->data_size) =0 ; + }else if (tfr->data_size > *(pkg->data_size)) { +DMERR ("Insufficient space to receive package [%s]::" , +RQ_TYPE (tfr->request_type)); +DMERR (" tfr->data_size = %u" , tfr->data_size); +DMERR (" *(pkg->data_size) = %u" , *(pkg->data_size)); + + *(pkg->data_size) =0 ; + pkg->error = -ENOSPC ; + }else { + pkg->error = tfr->error; +memcpy (pkg->data, tfr->data, tfr->data_size); + *(pkg->data_size) = tfr->data_size; + } +complete (&pkg->complete); +return 0 ; + } + +return -ENOENT ; +} + +/* +* cn_clog_callback +* @data +* +* This is the connector callback that delivers data +* that was sent from userspace. +*/ +static void cn_clog_callback (void *data) +{ +struct cn_msg *msg = (struct cn_msg *)data; +struct clog_tfr *tfr = (struct clog_tfr *)(msg +1 ); + +spin_lock (&receiving_list_lock); +if (msg->len ==0 ) +fill_pkg (msg,NULL ); +else if (msg->len <sizeof (*tfr)) +DMERR ("Incomplete message received: [%u]" , msg->seq); +else +fill_pkg (NULL , tfr); +spin_unlock (&receiving_list_lock); +} + +/* +* 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 ; +int dummy =0 ; +int overhead_size =sizeof (struct clog_tfr *) +sizeof (struct cn_msg ); +struct clog_tfr *tfr = prealloced_clog_tfr; +struct receiving_pkg pkg; + +if (data_size > (DM_CLOG_PREALLOCED_SIZE - overhead_size)) { +DMINFO ("Size of tfr exceeds preallocated size" ); +/* FIXME: is kmalloc sufficient if we need this much space? */ + tfr =kzalloc (data_size +sizeof (*tfr),GFP_NOIO ); + } + +if (!tfr) +return -ENOMEM ; + +if (!rdata_size) + rdata_size = &dummy; +resend: +/* +* We serialize the sending of requests so we can +* use the preallocated space. +*/ +mutex_lock (&_lock); + +memset (tfr,0 ,DM_CLOG_PREALLOCED_SIZE - overhead_size); +memcpy (tfr->uuid, uuid,DM_UUID_LEN ); + tfr->seq = seq++; + tfr->request_type = request_type; + tfr->data_size = data_size; +if (data && data_size) +memcpy (tfr->data, data, data_size); + +memset (&pkg,0 ,sizeof (pkg)); +init_completion (&pkg.complete); + pkg.seq = tfr->seq; + pkg.data_size = rdata_size; + pkg.data = rdata; +spin_lock (&receiving_list_lock); +list_add (&(pkg.list), &receiving_list); +spin_unlock (&receiving_list_lock); + + r =dm_clog_sendto_server (tfr); + +mutex_unlock (&_lock); + +if (r) { +DMERR ("Unable to send cluster log request [%s] to server: %d" , +RQ_TYPE (request_type), r); +spin_lock (&receiving_list_lock); +list_del_init (&(pkg.list)); +spin_unlock (&receiving_list_lock); + + goto out; + } + + r =wait_for_completion_timeout (&(pkg.complete),15 *HZ ); +spin_lock (&receiving_list_lock); +list_del_init (&(pkg.list)); +spin_unlock (&receiving_list_lock); +if (!r) { +DMWARN ("[%s] Request timed out: [%s/%u] - retrying" , +SHORT_UUID (uuid),RQ_TYPE (request_type), pkg.seq); + goto resend; + } + + r = pkg.error; +if (r == -EAGAIN ) + goto resend; + +out: +if (tfr != (struct clog_tfr *)prealloced_clog_tfr) +kfree (tfr); + +return r; +} + +int dm_clog_tfr_init (void ) +{ +int r; +void *prealloced; + +INIT_LIST_HEAD (&receiving_list); + + prealloced =kmalloc (DM_CLOG_PREALLOCED_SIZE ,GFP_KERNEL ); +if (!prealloced) +return -ENOMEM ; + + prealloced_cn_msg = prealloced; + prealloced_clog_tfr = prealloced +sizeof (struct cn_msg ); + + r =cn_add_callback (&cn_clog_id,"clulog" , cn_clog_callback); +if (r) { +cn_del_callback (&cn_clog_id); +return r; + } + +return 0 ; +} + +void dm_clog_tfr_exit (void ) +{ +cn_del_callback (&cn_clog_id); +kfree (prealloced_cn_msg); +}
drivers/md/dm-clog-tfr.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (C) 2006-2008 Red Hat, Inc. +* +* This file is released under the LGPL. +*/ + +#ifndef __DM_CLOG_TFR_H__ +#define __DM_CLOG_TFR_H__ + +#define DM_MSG_PREFIX "dm-log-clustered" + +int dm_clog_tfr_init (void ); +void dm_clog_tfr_exit (void ); +int dm_clog_consult_server (const char *uuid,int request_type, +char *data,int data_size, +char *rdata,int *rdata_size); + +#endif /* __DM_CLOG_TFR_H__ */
drivers/md/dm-clog.c new file +786 -0
786 lines not on this page · raw message
drivers/md/Kconfig +9 -0
@@ -256,6 +256,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 device-mapper mirroring to be + 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" depends on BLK_DEV_DM
drivers/md/Makefile +2 -0
@@ -8,6 +8,7 @@ dm-multipath-objs := dm-path-selector.o dm-snapshot-objs := dm-snap.o dm-exception-store.o dm-snap-transient.o \ dm-snap-persistent.o dm-mirror-objs := dm-raid1.o +dm-log-clustered-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 \
@@ -36,6 +37,7 @@ obj-$(CONFIG_DM_DELAY) += dm-delay.o obj-$(CONFIG_DM_MULTIPATH) += dm-multipath.o dm-round-robin.o obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o obj-$(CONFIG_DM_MIRROR) += dm-mirror.o dm-log.o dm-region-hash.o +obj-$(CONFIG_DM_CLOG) += dm-log-clustered.o obj-$(CONFIG_DM_ZERO) += dm-zero.o quiet_cmd_unroll = UNROLL $@
include/linux/dm-cluster-log.h new file +66 -0
66 lines not on this page · raw message
include/linux/connector.h +3 -1
@@ -39,8 +39,10 @@#define CN_IDX_V86D 0x4#define CN_VAL_V86D_UVESAFB 0x1#define CN_IDX_BB 0x5/* BlackBoard, from the TSP GPL sampling framework */ +#define CN_IDX_DM 0x6/* Device Mapper */ +#define CN_VAL_DM_CLUSTER_LOG 0x1 -#define CN_NETLINK_USERS 6 +#define CN_NETLINK_USERS 7/* * Maximum connector's message size.
Quoted 12 lines · Jonathan Brassow
I have removed the last complaint that I know of (the hard-coded values for '
cn_clog_id'). I have created macros for (reserved us a spot in)include/linux/connector.h. I created a channel for DM to multiplex on. (The cluster log is the first user, the cluster exception store will likely be the second, uevent could be the third, etc.) I did not receive feedback on theRQ_TYPEmacro.Code for the userspace server is currently being housed in LVM2/daemons/clogd. This is a temporary home for the code that will become permanent after review. Currently, to compile the code, you will need to 'cd LVM2/daemons/clogd; make'.
Quoted 4 lines
Please review. Please push upstream. Please remember that this patch depends on "dm-raid1-add-is_remote_recovering-hook-for-clusters.patch".
brassow
With a bit more input, I've made a couple more changes to the patch:
- changed file names
- a couple minor formatting corrections
- remove the RQ_TYPE macro in favor of a list of strings that can be used later in indexed arrays (avoids nested conditionals)
I'm not sure how "Patchwork" will handle the repost of this patch, but the following should 'supersede' the previous patch.
brassow
This patch contains a cluster-aware log module. When used by dm-raid1, device-mapper mirroring can be cluster-aware.
There is a kernel component (provided in this patch) and a user space component. The kernel component implements the logging interface and passes all requests to userspace via 'connector' (a netlink wrapper). The userspace daemon is built upon OpenAIS for cluster communication and is fault tolerant.
drivers/md/Kconfig +9 -0
@@ -256,6 +256,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 device-mapper mirroring to be + 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" depends on BLK_DEV_DM
drivers/md/Makefile +2 -0
@@ -8,6 +8,7 @@ dm-multipath-objs := dm-path-selector.o dm-snapshot-objs := dm-snap.o dm-exception-store.o dm-snap-transient.o \ dm-snap-persistent.o dm-mirror-objs := dm-raid1.o +dm-log-clustered-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 \
@@ -36,6 +37,7 @@ obj-$(CONFIG_DM_DELAY) += dm-delay.o obj-$(CONFIG_DM_MULTIPATH) += dm-multipath.o dm-round-robin.o obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o obj-$(CONFIG_DM_MIRROR) += dm-mirror.o dm-log.o dm-region-hash.o +obj-$(CONFIG_DM_CLOG) += dm-log-clustered.o obj-$(CONFIG_DM_ZERO) += dm-zero.o quiet_cmd_unroll = UNROLL $@
include/linux/connector.h +3 -1
@@ -39,8 +39,10 @@#define CN_IDX_V86D 0x4#define CN_VAL_V86D_UVESAFB 0x1#define CN_IDX_BB 0x5/* BlackBoard, from the TSP GPL sampling framework */ +#define CN_IDX_DM 0x6/* Device Mapper */ +#define CN_VAL_DM_CLUSTER_LOG 0x1 -#define CN_NETLINK_USERS 6 +#define CN_NETLINK_USERS 7/* * Maximum connector's message size.
include/linux/dm-log-cluster.h new file +66 -0
66 lines not on this page · raw message
drivers/md/dm-log-cluster-transfer.c new file +279 -0
279 lines not on this page · raw message
drivers/md/dm-log-cluster-transfer.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (C) 2006-2008 Red Hat, Inc. +* +* This file is released under the LGPL. +*/ + +#ifndef __DM_CLOG_TFR_H__ +#define __DM_CLOG_TFR_H__ + +#define DM_MSG_PREFIX "dm-log-clustered" + +int dm_clog_tfr_init (void ); +void dm_clog_tfr_exit (void ); +int dm_clog_consult_server (const char *uuid,int request_type, +char *data,int data_size, +char *rdata,int *rdata_size); + +#endif /* __DM_CLOG_TFR_H__ */
drivers/md/dm-log-cluster.c new file +795 -0
795 lines not on this page · raw message