Note: "permalinks" may not be as permanent as we would like,
direct links of old sources may well be a few messages off.
On Thu, Mar 18, 2004 at 11:09:36AM +0100, Lars Ellenberg wrote: > I'd like to see such patches ... > AND: don't forget to set minor_count to some more sensible value, > or make it a kernel boot parameter, or you'll end up with only two > minors. Which may or may not be sufficient for your needs... Here are two patches. The first is for the drbd tree itself, which makes the source play nice when trying to do an in-kernel-tree build. Changes: - include path changed to handle moving the shared .h files into include/linux, for compatibility with the kernel build. - moved drbd_init and drbd_cleanup calls around so that there is no difference between a monolithic init and a module init. - dropped unused "errno" definition that conflicted with monolithic builds - commented out sig handler code when building as monolithic The second patch includes the Makefile and Kconfig entries. In this organization, it expects that the "drbd" module directory is in "drivers/block/drbd", and that drbd.h and drbd_config.h are in "include/linux". I left those out of the patch since it would be redundant. My one warning: I haven't fully tested this yet. I only got it to compile and initialize. -- Kees Cook Open Source Development Lab kees at osdl.org -------------- next part -------------- diff -uNrp drbd/drbd/Makefile drbd-0.7_pre2/drbd/Makefile --- drbd/drbd/Makefile 2004-02-08 11:53:19.000000000 -0800 +++ drbd-0.7_pre2/drbd/Makefile 2004-03-17 14:43:38.000000000 -0800 @@ -33,6 +33,8 @@ ifneq ($(KERNELRELEASE),) endif # linux 2.6 style: + CFLAGS_drbd.o = -L../include + obj-m += drbd.o drbd-objs := drbd_fs.o drbd_main.o drbd_proc.o drbd_dsender.o \ drbd_receiver.o drbd_req-2.4.o drbd_actlog.o \ diff -uNrp drbd/drbd/drbd.h drbd-0.7_pre2/drbd/drbd.h --- drbd/drbd/drbd.h 2004-03-03 08:07:59.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd.h 1969-12-31 16:00:00.000000000 -0800 @@ -1,203 +0,0 @@ -/* - drbd.h - Kernel module for 2.4.x Kernels - - This file is part of drbd by Philipp Reisner. - - drbd is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - drbd is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with drbd; see the file COPYING. If not, write to - the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ -#ifndef DRBD_H -#define DRBD_H -#include "../drbd_config.h" - -#include <asm/types.h> - -#ifdef __KERNEL__ -#include <linux/types.h> -#include <linux/ioctl.h> -#else -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/wait.h> -#include <limits.h> -#endif - -#ifdef __KERNEL__ -#define IN const -#define OUT -#define INOUT -#else -#define IN -#define OUT const -#define INOUT -#endif - - -#define MAX_SOCK_ADDR 128 /* 108 for Unix domain - - 16 for IP, 16 for IPX, - 24 for IPv6, - about 80 for AX.25 - must be at least one bigger than - the AF_UNIX size (see net/unix/af_unix.c - :unix_mkname()). - */ - -enum io_error_handler { - PassOn, - Panic, - Detach -}; - - -struct disk_config { - IN int lower_device; - IN unsigned int disk_size; - IN enum io_error_handler on_io_error; - IN int meta_device; - IN int meta_index; -}; - -struct net_config { - IN char my_addr[MAX_SOCK_ADDR]; - IN int my_addr_len; - IN char other_addr[MAX_SOCK_ADDR]; - IN int other_addr_len; - IN int timeout; // deci seconds - IN int wire_protocol; - IN int try_connect_int; /* seconds */ - IN int ping_int; /* seconds */ - IN int max_epoch_size; - IN int max_buffers; - IN int sndbuf_size; /* socket send buffer size */ -}; - -struct syncer_config { - int rate; /* KB/sec */ - int use_csums; /* use checksum based syncing*/ - int skip; - int group; - int al_extents; -}; - -enum ret_codes { - NoError=0, - LAAlreadyInUse, - OAAlreadyInUse, - LDFDInvalid, - MDFDInvalid, - LDAlreadyInUse, - LDNoBlockDev, - MDNoBlockDev, - LDOpenFailed, - MDOpenFailed, - LDDeviceTooSmall, - MDDeviceTooSmall, - LDNoConfig, - LDMounted, - MDMounted, - LDMDInvalid -}; - -struct ioctl_disk_config { - struct disk_config config; - OUT enum ret_codes ret_code; -}; - -struct ioctl_net_config { - struct net_config config; - OUT enum ret_codes ret_code; -}; - -struct ioctl_syncer_config { - struct syncer_config config; - OUT enum ret_codes ret_code; -}; - -struct ioctl_wait { - IN int wfc_timeout; - IN int degr_wfc_timeout; - OUT int ret_code; -}; - -#define DRBD_PROT_A 1 -#define DRBD_PROT_B 2 -#define DRBD_PROT_C 3 - -typedef enum { - Unknown=0, - Primary=1, // role - Secondary=2, // role - Human=4, // flag for set_state - TimeoutExpired=8, // flag for set_state - DontBlameDrbd=16 // flag for set_state -} Drbd_State; - -/* The order of these constants is important. - * The lower ones (<WFReportParams) indicate - * that there is no socket! - * >=WFReportParams ==> There is a socket - */ -typedef enum { - Unconfigured, - StandAlone, - Unconnected, - Timeout, - BrokenPipe, - WFConnection, - WFReportParams, // we have a socket - Connected, // we have introduced each other - SkippedSyncS, // we should have synced, but user said no - SkippedSyncT, - WFBitMapS, - WFBitMapT, - SyncSource, // The distance between original state and pause - SyncTarget, // state must be the same for source and target. (+2) - PausedSyncS, // see _drbd_rs_resume() and _drbd_rs_pause() - PausedSyncT, // is sync target, but higher priority groups first -} Drbd_CState; - -struct ioctl_get_config { - struct net_config nconf; - struct syncer_config sconf; - OUT int lower_device_major; - OUT int lower_device_minor; - OUT unsigned int disk_size_user; - OUT enum io_error_handler on_io_error; - OUT Drbd_CState cstate; - OUT int meta_device_major; - OUT int meta_device_minor; - OUT int meta_index; -}; - -#define DRBD_MAGIC 0x83740267 -#define BE_DRBD_MAGIC __constant_cpu_to_be32(DRBD_MAGIC) - -#define DRBD_IOCTL_GET_VERSION _IOR( 'D', 0x00, int ) -#define DRBD_IOCTL_SET_STATE _IOW( 'D', 0x02, Drbd_State ) -#define DRBD_IOCTL_SET_DISK_CONFIG _IOW( 'D', 0x06, struct ioctl_disk_config ) -#define DRBD_IOCTL_SET_NET_CONFIG _IOW( 'D', 0x07, struct ioctl_net_config ) -#define DRBD_IOCTL_UNCONFIG_NET _IO ( 'D', 0x08 ) -#define DRBD_IOCTL_GET_CONFIG _IOW( 'D', 0x0A, struct ioctl_get_config) -#define DRBD_IOCTL_INVALIDATE _IO ( 'D', 0x0D ) -#define DRBD_IOCTL_INVALIDATE_REM _IO ( 'D', 0x0E ) -#define DRBD_IOCTL_SET_SYNC_CONFIG _IOW( 'D', 0x0F,struct ioctl_syncer_config) -#define DRBD_IOCTL_SET_DISK_SIZE _IOW( 'D', 0x10, unsigned int) -#define DRBD_IOCTL_WAIT_CONNECT _IOR( 'D', 0x11, struct ioctl_wait) -#define DRBD_IOCTL_WAIT_SYNC _IOR( 'D', 0x12, struct ioctl_wait) -#define DRBD_IOCTL_UNCONFIG_DISK _IO ( 'D', 0x13 ) - -#endif - diff -uNrp drbd/drbd/drbd_actlog.c drbd-0.7_pre2/drbd/drbd_actlog.c --- drbd/drbd/drbd_actlog.c 2004-03-15 06:10:36.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_actlog.c 2004-03-17 14:47:10.000000000 -0800 @@ -25,7 +25,7 @@ */ #include <linux/slab.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" #define AL_EXTENTS_PT 61 diff -uNrp drbd/drbd/drbd_dsender.c drbd-0.7_pre2/drbd/drbd_dsender.c --- drbd/drbd/drbd_dsender.c 2004-03-15 09:32:19.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_dsender.c 2004-03-17 14:47:19.000000000 -0800 @@ -41,7 +41,7 @@ #define __KERNEL_SYSCALLS__ #include <linux/slab.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" /* I choose to have all block layer end_io handlers defined here. diff -uNrp drbd/drbd/drbd_fs.c drbd-0.7_pre2/drbd/drbd_fs.c --- drbd/drbd/drbd_fs.c 2004-03-06 01:31:27.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_fs.c 2004-03-17 14:47:30.000000000 -0800 @@ -43,7 +43,7 @@ #include <linux/file.h> #include <linux/slab.h> #include <linux/utsname.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) diff -uNrp drbd/drbd/drbd_int.h drbd-0.7_pre2/drbd/drbd_int.h --- drbd/drbd/drbd_int.h 2004-03-15 09:32:19.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_int.h 2004-03-17 15:34:34.000000000 -0800 @@ -191,10 +191,14 @@ extern void drbd_assert_breakpoint(drbd_ # define LOCK_SIGMASK(task,flags) spin_lock_irqsave(&task->sighand->siglock, flags) # define UNLOCK_SIGMASK(task,flags) spin_unlock_irqrestore(&task->sighand->siglock, flags) # define RECALC_SIGPENDING(TSK) (recalc_sigpending_tsk(TSK)) + +# ifndef MODULE // defined in drbd_main.c, // copied from redhat's kernel-2.4.20-13.9 kernel/signal.c // to avoid a recompile of the redhat kernel inline void recalc_sigpending_tsk(struct task_struct *t); +# endif + #else # define LOCK_SIGMASK(task,flags) spin_lock_irqsave(&task->sigmask_lock, flags) # define UNLOCK_SIGMASK(task,flags) spin_unlock_irqrestore(&task->sigmask_lock, flags) diff -uNrp drbd/drbd/drbd_main.c drbd-0.7_pre2/drbd/drbd_main.c --- drbd/drbd/drbd_main.c 2004-03-11 05:50:16.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_main.c 2004-03-18 08:50:46.000000000 -0800 @@ -67,7 +67,7 @@ extern asmlinkage int sys_ioctl(unsigned #include <linux/unistd.h> #include <linux/vmalloc.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) @@ -98,8 +98,13 @@ MODULE_PARM_DESC(minor_count, "Maximum n MODULE_PARM_DESC(disable_io_hints, "Necessary if loopback devices are used for DRBD" ); // module parameter, defined +#ifdef MODULE int minor_count = 2; int disable_io_hints = 0; +#else +int minor_count = 8; +int disable_io_hints = 0; +#endif // global panic flag volatile int drbd_did_panic = 0; @@ -127,8 +132,6 @@ STATIC struct block_device_operations dr #define ARRY_SIZE(A) (sizeof(A)/sizeof(A[0])) -int errno; - /************************* The transfer log start */ STATIC int tl_init(drbd_dev *mdev) { @@ -1178,10 +1181,26 @@ int drbd_create_mempools(void) return -ENOMEM; } -void drbd_cleanup(void) +static void __exit drbd_cleanup(void) { int i, rr; + if (drbd_conf) { + for (i = 0; i < minor_count; i++) { + drbd_dev *mdev = drbd_conf + i; + + if (mdev) { + down(&mdev->device_mutex); + drbd_set_state(mdev,Secondary); + up(&mdev->device_mutex); + drbd_sync_me(mdev); + set_bit(DO_NOT_INC_CONCNT,&mdev->flags); + drbd_thread_stop(&mdev->worker); + drbd_thread_stop(&mdev->receiver); + drbd_thread_stop(&mdev->asender); + } + } + if (drbd_proc) remove_proc_entry("drbd",&proc_root); i=minor_count; @@ -1239,6 +1258,23 @@ ONLY_IN_26( drbd_destroy_mempools(); } +#if defined(CONFIG_PPC64) || defined(CONFIG_SPARC64) || defined(CONFIG_X86_64) + lock_kernel(); + unregister_ioctl32_conversion(DRBD_IOCTL_GET_VERSION); + unregister_ioctl32_conversion(DRBD_IOCTL_SET_STATE); + unregister_ioctl32_conversion(DRBD_IOCTL_SET_DISK_CONFIG); + unregister_ioctl32_conversion(DRBD_IOCTL_SET_NET_CONFIG); + unregister_ioctl32_conversion(DRBD_IOCTL_UNCONFIG_NET); + unregister_ioctl32_conversion(DRBD_IOCTL_GET_CONFIG); + unregister_ioctl32_conversion(DRBD_IOCTL_INVALIDATE); + unregister_ioctl32_conversion(DRBD_IOCTL_INVALIDATE_REM); + unregister_ioctl32_conversion(DRBD_IOCTL_SET_SYNC_CONFIG); + unregister_ioctl32_conversion(DRBD_IOCTL_SET_DISK_SIZE); + unregister_ioctl32_conversion(DRBD_IOCTL_WAIT_CONNECT); + unregister_ioctl32_conversion(DRBD_IOCTL_WAIT_SYNC); + unregister_ioctl32_conversion(DRBD_IOCTL_UNCONFIG_DISK); + unlock_kernel(); +#endif NOT_IN_26( blksize_size[MAJOR_NR] = NULL; @@ -1249,6 +1285,12 @@ NOT_IN_26( ) kfree(drbd_conf); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) + devfs_unregister(devfs_handle); +#else + devfs_remove(DEVFS_NAME); +#endif + if (unregister_blkdev(MAJOR_NR, DEVICE_NAME) != 0) printk(KERN_ERR DEVICE_NAME": unregister of device failed\n"); @@ -1265,14 +1307,35 @@ void * kcalloc(size_t size, int type) int __init drbd_init(void) { +#if 0 +/* I am too lazy to calculate this by hand -lge + */ +#define SZO(x) printk(KERN_ERR "sizeof(" #x ") = %d\n", sizeof(x)) + SZO(struct Drbd_Conf); + SZO(struct buffer_head); + SZO(Drbd_Polymorph_Packet); + SZO(struct drbd_socket); + SZO(struct semaphore); + SZO(wait_queue_head_t); + SZO(spinlock_t); + return -EBUSY; +#endif int i,err; + if (1 > minor_count||minor_count > 255) { + printk(KERN_ERR DEVICE_NAME + ": invalid minor_count (%d)\n",minor_count); + return -EINVAL; + } err = register_blkdev(MAJOR_NR, DEVICE_NAME NOT_IN_26(, &drbd_ops) ); - if (err) return err; + if (err) { + printk(KERN_ERR DEVICE_NAME": unable to register block device\n"); + return err; + } /* * allocate all necessary structs @@ -1411,88 +1474,21 @@ NOT_IN_26( unlock_kernel(); #endif + printk(KERN_INFO DEVICE_NAME ": initialised. " + "Version: " REL_VERSION " (api:%d/proto:%d)\n", + API_VERSION,PRO_VERSION); + return 0; // Success! Enomem: drbd_cleanup(); if (err == -ENOMEM) // currently always the case printk(KERN_ERR DEVICE_NAME ": ran out of memory\n"); + else + printk(KERN_ERR DEVICE_NAME ": initialization failure\n"); return err; } -int __init init_module(void) -{ -#if 0 -/* I am too lazy to calculate this by hand -lge - */ -#define SZO(x) printk(KERN_ERR "sizeof(" #x ") = %d\n", sizeof(x)) - SZO(struct Drbd_Conf); - SZO(struct buffer_head); - SZO(Drbd_Polymorph_Packet); - SZO(struct drbd_socket); - SZO(struct semaphore); - SZO(wait_queue_head_t); - SZO(spinlock_t); - return -EBUSY; -#endif - - if (1 > minor_count||minor_count > 255) { - printk(KERN_ERR DEVICE_NAME - ": invalid minor_count (%d)\n",minor_count); - return -EINVAL; - } - - printk(KERN_INFO DEVICE_NAME ": initialised. " - "Version: " REL_VERSION " (api:%d/proto:%d)\n", - API_VERSION,PRO_VERSION); - - return drbd_init(); -} - -void cleanup_module(void) -{ - int i; - - for (i = 0; i < minor_count; i++) { - drbd_dev *mdev = drbd_conf + i; - - down(&mdev->device_mutex); - drbd_set_state(mdev,Secondary); - up(&mdev->device_mutex); - drbd_sync_me(mdev); - set_bit(DO_NOT_INC_CONCNT,&mdev->flags); - drbd_thread_stop(&mdev->worker); - drbd_thread_stop(&mdev->receiver); - drbd_thread_stop(&mdev->asender); - } - -#if defined(CONFIG_PPC64) || defined(CONFIG_SPARC64) || defined(CONFIG_X86_64) - lock_kernel(); - unregister_ioctl32_conversion(DRBD_IOCTL_GET_VERSION); - unregister_ioctl32_conversion(DRBD_IOCTL_SET_STATE); - unregister_ioctl32_conversion(DRBD_IOCTL_SET_DISK_CONFIG); - unregister_ioctl32_conversion(DRBD_IOCTL_SET_NET_CONFIG); - unregister_ioctl32_conversion(DRBD_IOCTL_UNCONFIG_NET); - unregister_ioctl32_conversion(DRBD_IOCTL_GET_CONFIG); - unregister_ioctl32_conversion(DRBD_IOCTL_INVALIDATE); - unregister_ioctl32_conversion(DRBD_IOCTL_INVALIDATE_REM); - unregister_ioctl32_conversion(DRBD_IOCTL_SET_SYNC_CONFIG); - unregister_ioctl32_conversion(DRBD_IOCTL_SET_DISK_SIZE); - unregister_ioctl32_conversion(DRBD_IOCTL_WAIT_CONNECT); - unregister_ioctl32_conversion(DRBD_IOCTL_WAIT_SYNC); - unregister_ioctl32_conversion(DRBD_IOCTL_UNCONFIG_DISK); - unlock_kernel(); -#endif - - drbd_cleanup(); - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) - devfs_unregister(devfs_handle); -#else - devfs_remove(DEVFS_NAME); -#endif -} - void drbd_free_ll_dev(drbd_dev *mdev) { struct file *lo_file; @@ -2011,7 +2007,7 @@ void drbd_md_inc(drbd_dev *mdev, enum Me mdev->gen_cnt[order]++; } -#ifdef SIGHAND_HACK +#if defined(SIGHAND_HACK) && defined(MODULE) /* copied from linux-2.6/kernel/signal.c * because recalc_sigpending_tsk is not exported, @@ -2064,3 +2060,6 @@ inline void recalc_sigpending_tsk(struct } #endif + +module_init(drbd_init) +module_exit(drbd_cleanup) diff -uNrp drbd/drbd/drbd_proc.c drbd-0.7_pre2/drbd/drbd_proc.c --- drbd/drbd/drbd_proc.c 2004-02-15 06:40:11.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_proc.c 2004-03-17 14:47:53.000000000 -0800 @@ -39,7 +39,7 @@ #include <linux/file.h> #include <linux/slab.h> #include <linux/proc_fs.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" int drbd_proc_get_info(char *, char **, off_t, int, int *, void *); diff -uNrp drbd/drbd/drbd_receiver.c drbd-0.7_pre2/drbd/drbd_receiver.c --- drbd/drbd/drbd_receiver.c 2004-03-14 11:32:47.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_receiver.c 2004-03-17 14:48:02.000000000 -0800 @@ -51,7 +51,7 @@ #define __KERNEL_SYSCALLS__ #include <linux/unistd.h> #include <linux/vmalloc.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" #define EE_MININUM 32 // @4k pages => 128 KByte diff -uNrp drbd/drbd/drbd_req-2.4.c drbd-0.7_pre2/drbd/drbd_req-2.4.c --- drbd/drbd/drbd_req-2.4.c 2004-03-15 09:32:19.000000000 -0800 +++ drbd-0.7_pre2/drbd/drbd_req-2.4.c 2004-03-17 14:48:14.000000000 -0800 @@ -32,7 +32,7 @@ #endif #include <linux/slab.h> -#include "drbd.h" +#include <linux/drbd.h> #include "drbd_int.h" void drbd_end_req(drbd_request_t *req, int nextstate, int er_flags, diff -uNrp drbd/drbd.spec drbd-0.7_pre2/drbd.spec --- drbd/drbd.spec 2003-10-21 01:58:42.000000000 -0700 +++ drbd-0.7_pre2/drbd.spec 2004-03-17 12:15:12.000000000 -0800 @@ -7,7 +7,7 @@ Vendor: DRBD License: GPL ExclusiveOS: linux Group: System Environment/Kernel -Packager: +Packager: Lars Ellenberg <l.g.e at web.de> Requires: kernel Provides: %{name} URL: http://www.drbd.org/ diff -uNrp drbd/drbd_config.h drbd-0.7_pre2/drbd_config.h --- drbd/drbd_config.h 2004-02-19 08:12:15.000000000 -0800 +++ drbd-0.7_pre2/drbd_config.h 1969-12-31 16:00:00.000000000 -0800 @@ -1,34 +0,0 @@ -/* - drbd_config.h - DRBD's compile time configuration. - - drbd is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - drbd is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with drbd; see the file COPYING. If not, write to - the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef DRBD_CONFIG_H -#define DRBD_CONFIG_H - -#define REL_VERSION "0.7-pre5" -#define API_VERSION 72 -#define PRO_VERSION 72 - -//#define DBG_ALL_SYMBOLS // no static functs, improves quality of OOPS traces -//#define DBG_SPINLOCKS // enables MUST_HOLD macro (assertions for spinlocks) -//#define DBG_ASSERTS // drbd_assert_breakpoint() function - -//#define SIGHAND_HACK // Needed for RH 2.4.20 and later kernels. -//#define REDHAT_HLIST_BACKPORT // Makes DRBD work on RH9 kernels - -#endif diff -uNrp drbd/include/linux/drbd.h drbd-0.7_pre2/include/linux/drbd.h --- drbd/include/linux/drbd.h 1969-12-31 16:00:00.000000000 -0800 +++ drbd-0.7_pre2/include/linux/drbd.h 2004-03-17 14:45:56.000000000 -0800 @@ -0,0 +1,203 @@ +/* + drbd.h + Kernel module for 2.4.x Kernels + + This file is part of drbd by Philipp Reisner. + + drbd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + drbd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with drbd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ +#ifndef DRBD_H +#define DRBD_H +#include <linux/drbd_config.h> + +#include <asm/types.h> + +#ifdef __KERNEL__ +#include <linux/types.h> +#include <linux/ioctl.h> +#else +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/wait.h> +#include <limits.h> +#endif + +#ifdef __KERNEL__ +#define IN const +#define OUT +#define INOUT +#else +#define IN +#define OUT const +#define INOUT +#endif + + +#define MAX_SOCK_ADDR 128 /* 108 for Unix domain - + 16 for IP, 16 for IPX, + 24 for IPv6, + about 80 for AX.25 + must be at least one bigger than + the AF_UNIX size (see net/unix/af_unix.c + :unix_mkname()). + */ + +enum io_error_handler { + PassOn, + Panic, + Detach +}; + + +struct disk_config { + IN int lower_device; + IN unsigned int disk_size; + IN enum io_error_handler on_io_error; + IN int meta_device; + IN int meta_index; +}; + +struct net_config { + IN char my_addr[MAX_SOCK_ADDR]; + IN int my_addr_len; + IN char other_addr[MAX_SOCK_ADDR]; + IN int other_addr_len; + IN int timeout; // deci seconds + IN int wire_protocol; + IN int try_connect_int; /* seconds */ + IN int ping_int; /* seconds */ + IN int max_epoch_size; + IN int max_buffers; + IN int sndbuf_size; /* socket send buffer size */ +}; + +struct syncer_config { + int rate; /* KB/sec */ + int use_csums; /* use checksum based syncing*/ + int skip; + int group; + int al_extents; +}; + +enum ret_codes { + NoError=0, + LAAlreadyInUse, + OAAlreadyInUse, + LDFDInvalid, + MDFDInvalid, + LDAlreadyInUse, + LDNoBlockDev, + MDNoBlockDev, + LDOpenFailed, + MDOpenFailed, + LDDeviceTooSmall, + MDDeviceTooSmall, + LDNoConfig, + LDMounted, + MDMounted, + LDMDInvalid +}; + +struct ioctl_disk_config { + struct disk_config config; + OUT enum ret_codes ret_code; +}; + +struct ioctl_net_config { + struct net_config config; + OUT enum ret_codes ret_code; +}; + +struct ioctl_syncer_config { + struct syncer_config config; + OUT enum ret_codes ret_code; +}; + +struct ioctl_wait { + IN int wfc_timeout; + IN int degr_wfc_timeout; + OUT int ret_code; +}; + +#define DRBD_PROT_A 1 +#define DRBD_PROT_B 2 +#define DRBD_PROT_C 3 + +typedef enum { + Unknown=0, + Primary=1, // role + Secondary=2, // role + Human=4, // flag for set_state + TimeoutExpired=8, // flag for set_state + DontBlameDrbd=16 // flag for set_state +} Drbd_State; + +/* The order of these constants is important. + * The lower ones (<WFReportParams) indicate + * that there is no socket! + * >=WFReportParams ==> There is a socket + */ +typedef enum { + Unconfigured, + StandAlone, + Unconnected, + Timeout, + BrokenPipe, + WFConnection, + WFReportParams, // we have a socket + Connected, // we have introduced each other + SkippedSyncS, // we should have synced, but user said no + SkippedSyncT, + WFBitMapS, + WFBitMapT, + SyncSource, // The distance between original state and pause + SyncTarget, // state must be the same for source and target. (+2) + PausedSyncS, // see _drbd_rs_resume() and _drbd_rs_pause() + PausedSyncT, // is sync target, but higher priority groups first +} Drbd_CState; + +struct ioctl_get_config { + struct net_config nconf; + struct syncer_config sconf; + OUT int lower_device_major; + OUT int lower_device_minor; + OUT unsigned int disk_size_user; + OUT enum io_error_handler on_io_error; + OUT Drbd_CState cstate; + OUT int meta_device_major; + OUT int meta_device_minor; + OUT int meta_index; +}; + +#define DRBD_MAGIC 0x83740267 +#define BE_DRBD_MAGIC __constant_cpu_to_be32(DRBD_MAGIC) + +#define DRBD_IOCTL_GET_VERSION _IOR( 'D', 0x00, int ) +#define DRBD_IOCTL_SET_STATE _IOW( 'D', 0x02, Drbd_State ) +#define DRBD_IOCTL_SET_DISK_CONFIG _IOW( 'D', 0x06, struct ioctl_disk_config ) +#define DRBD_IOCTL_SET_NET_CONFIG _IOW( 'D', 0x07, struct ioctl_net_config ) +#define DRBD_IOCTL_UNCONFIG_NET _IO ( 'D', 0x08 ) +#define DRBD_IOCTL_GET_CONFIG _IOW( 'D', 0x0A, struct ioctl_get_config) +#define DRBD_IOCTL_INVALIDATE _IO ( 'D', 0x0D ) +#define DRBD_IOCTL_INVALIDATE_REM _IO ( 'D', 0x0E ) +#define DRBD_IOCTL_SET_SYNC_CONFIG _IOW( 'D', 0x0F,struct ioctl_syncer_config) +#define DRBD_IOCTL_SET_DISK_SIZE _IOW( 'D', 0x10, unsigned int) +#define DRBD_IOCTL_WAIT_CONNECT _IOR( 'D', 0x11, struct ioctl_wait) +#define DRBD_IOCTL_WAIT_SYNC _IOR( 'D', 0x12, struct ioctl_wait) +#define DRBD_IOCTL_UNCONFIG_DISK _IO ( 'D', 0x13 ) + +#endif + diff -uNrp drbd/include/linux/drbd_config.h drbd-0.7_pre2/include/linux/drbd_config.h --- drbd/include/linux/drbd_config.h 1969-12-31 16:00:00.000000000 -0800 +++ drbd-0.7_pre2/include/linux/drbd_config.h 2004-02-19 08:12:15.000000000 -0800 @@ -0,0 +1,34 @@ +/* + drbd_config.h + DRBD's compile time configuration. + + drbd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + drbd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with drbd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef DRBD_CONFIG_H +#define DRBD_CONFIG_H + +#define REL_VERSION "0.7-pre5" +#define API_VERSION 72 +#define PRO_VERSION 72 + +//#define DBG_ALL_SYMBOLS // no static functs, improves quality of OOPS traces +//#define DBG_SPINLOCKS // enables MUST_HOLD macro (assertions for spinlocks) +//#define DBG_ASSERTS // drbd_assert_breakpoint() function + +//#define SIGHAND_HACK // Needed for RH 2.4.20 and later kernels. +//#define REDHAT_HLIST_BACKPORT // Makes DRBD work on RH9 kernels + +#endif diff -uNrp drbd/user/Makefile drbd-0.7_pre2/user/Makefile --- drbd/user/Makefile 2004-01-12 11:49:41.000000000 -0800 +++ drbd-0.7_pre2/user/Makefile 2004-03-17 14:42:03.000000000 -0800 @@ -17,7 +17,7 @@ # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # -CFLAGS = -c -Wall +CFLAGS = -c -Wall -I../include CC = gcc all: drbdsetup drbdadm diff -uNrp drbd/user/drbdadm.h drbd-0.7_pre2/user/drbdadm.h --- drbd/user/drbdadm.h 2004-02-11 05:25:20.000000000 -0800 +++ drbd-0.7_pre2/user/drbdadm.h 2004-03-17 14:48:33.000000000 -0800 @@ -1,7 +1,7 @@ #ifndef DRBDADM_H #define DRBDADM_H -#include "../drbd_config.h" +#include <linux/drbd_config.h> struct d_globals { diff -uNrp drbd/user/drbdsetup.c drbd-0.7_pre2/user/drbdsetup.c --- drbd/user/drbdsetup.c 2004-03-10 15:54:40.000000000 -0800 +++ drbd-0.7_pre2/user/drbdsetup.c 2004-03-17 14:46:32.000000000 -0800 @@ -38,7 +38,7 @@ #include <fcntl.h> #include <stdio.h> #include <string.h> -#include "../drbd/drbd.h" +#include <linux/drbd.h> #define _GNU_SOURCE #include <getopt.h> #include <stdlib.h> -------------- next part -------------- diff -uNrp linux-2.6.3/drivers/block/drbd/Kconfig linux-drbd/drivers/block/drbd/Kconfig --- linux-2.6.3/drivers/block/drbd/Kconfig 1969-12-31 16:00:00.000000000 -0800 +++ linux-drbd/drivers/block/drbd/Kconfig 2004-03-17 17:20:11.000000000 -0800 @@ -0,0 +1,28 @@ +# +# Block device driver configuration +# + +config BLK_DEV_DRBD + tristate "Distributed redundant block device support" + depends on NET && PROC_FS && !BLK_DEV_NBD + ---help--- + Drbd is a block device which is designed to build high availability + clusters. This is done by mirroring a whole block device via (a + dedicated) network. You could see it as a network RAID 1. + + This device replaces the regular "network block device". + + Each device (drbd provides more than one of these devices) has a + state, which can be 'primary' or 'secondary'. On the node with the + primary device the application is supposed to run and to access the + device (/dev/nbX). Every write is sent to the local 'lower level + block device' and to the node with the device in 'secondary' state. + The secondary device simply writes the data to its lower level block + device. Reads are always carried out locally. + + Drbd management is done through user-space tools. + + http://www.drbd.org/ + + If unsure, say N. + diff -uNrp linux-2.6.3/drivers/block/drbd/Makefile linux-drbd/drivers/block/drbd/Makefile --- linux-2.6.3/drivers/block/drbd/Makefile 1969-12-31 16:00:00.000000000 -0800 +++ linux-drbd/drivers/block/drbd/Makefile 2004-03-17 17:26:39.000000000 -0800 @@ -0,0 +1,9 @@ +# +# DRBD Makefile +# + +obj-$(CONFIG_BLK_DEV_DRBD) += drbd.o +drbd-objs := drbd_fs.o drbd_main.o drbd_proc.o drbd_dsender.o \ + drbd_receiver.o drbd_req-2.4.o drbd_actlog.o \ + lru_cache.o + diff -uNrp linux-2.6.3/drivers/block/Kconfig linux-drbd/drivers/block/Kconfig --- linux-2.6.3/drivers/block/Kconfig 2004-02-17 19:57:20.000000000 -0800 +++ linux-drbd/drivers/block/Kconfig 2004-03-17 17:19:51.000000000 -0800 @@ -284,6 +284,8 @@ config BLK_DEV_NBD If unsure, say N. +source "drivers/block/drbd/Kconfig" + config BLK_DEV_RAM tristate "RAM disk support" ---help--- diff -uNrp linux-2.6.3/drivers/block/Makefile linux-drbd/drivers/block/Makefile --- linux-2.6.3/drivers/block/Makefile 2004-02-17 19:59:12.000000000 -0800 +++ linux-drbd/drivers/block/Makefile 2004-03-17 17:17:57.000000000 -0800 @@ -38,3 +38,5 @@ obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o obj-$(CONFIG_BLK_DEV_UMEM) += umem.o obj-$(CONFIG_BLK_DEV_NBD) += nbd.o obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryptoloop.o + +obj-$(CONFIG_BLK_DEV_DRBD) += drbd/