Whamcloud - gitweb
mds/handler.c, mds/mds_reint.c: fixup the ext3 MDS code a bit to build on
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef _OBD_SUPPORT
24 #define _OBD_SUPPORT
25
26 #include <linux/autoconf.h>
27 #include <linux/slab.h>
28 #include <linux/kp30.h>
29
30 /* global variables */
31 extern unsigned long obd_memory;
32 extern unsigned long obd_fail_loc;
33
34 enum {
35         OBD_FAIL_MDS = 0x100,
36         OBD_FAIL_MDS_HANDLE_UNPACK,
37         OBD_FAIL_MDS_GETATTR_NET,
38         OBD_FAIL_MDS_GETATTR_PACK,
39         OBD_FAIL_MDS_READPAGE_NET,
40         OBD_FAIL_MDS_READPAGE_PACK,
41         OBD_FAIL_MDS_READPAGE_BULK_NET,
42         OBD_FAIL_MDS_SENDPAGE,
43         OBD_FAIL_MDS_REINT_NET,
44         OBD_FAIL_MDS_REINT_UNPACK,
45         OBD_FAIL_MDS_REINT_SETATTR,
46         OBD_FAIL_MDS_REINT_SETATTR_WRITE,
47         OBD_FAIL_MDS_REINT_CREATE,
48         OBD_FAIL_MDS_REINT_CREATE_WRITE,
49         OBD_FAIL_MDS_REINT_UNLINK,
50         OBD_FAIL_MDS_REINT_UNLINK_WRITE,
51         OBD_FAIL_MDS_REINT_LINK,
52         OBD_FAIL_MDS_REINT_LINK_WRITE,
53         OBD_FAIL_MDS_REINT_RENAME,
54         OBD_FAIL_MDS_REINT_RENAME_WRITE,
55         OBD_FAIL_MDS_OPEN_NET,
56         OBD_FAIL_MDS_OPEN_PACK,
57         OBD_FAIL_MDS_CLOSE_NET,
58         OBD_FAIL_MDS_CLOSE_PACK,
59
60         OBD_FAIL_OST = 0x200,
61         OBD_FAIL_OST_CONNECT_NET,
62         OBD_FAIL_OST_DISCONNECT_NET,
63         OBD_FAIL_OST_GET_INFO_NET,
64         OBD_FAIL_OST_CREATE_NET,
65         OBD_FAIL_OST_DESTROY_NET,
66         OBD_FAIL_OST_GETATTR_NET,
67         OBD_FAIL_OST_SETATTR_NET,
68         OBD_FAIL_OST_OPEN_NET,
69         OBD_FAIL_OST_CLOSE_NET,
70         OBD_FAIL_OST_BRW_NET,
71         OBD_FAIL_OST_PUNCH_NET,
72 };
73
74 /* preparation for a more advanced failure testbed (not functional yet) */
75 #define OBD_FAIL_MASK_SYS    0x0000FF00
76 #define OBD_FAIL_MASK_LOC    (0x000000FF | OBD_FAIL_MASK_SYS)
77 #define OBD_FAIL_ONCE        0x80000000
78 #define OBD_FAILED           0x40000000
79 #define OBD_FAIL_MDS_ALL_NET 0x01000000
80 #define OBD_FAIL_OST_ALL_NET 0x02000000
81
82 #define OBD_FAIL_CHECK(id)      ((obd_fail_loc & OBD_FAIL_MASK_LOC) == (id))
83
84 #define OBD_FAIL_RETURN(id, ret)                                             \
85 do {                                                                         \
86         if (OBD_FAIL_CHECK(id)) {                                            \
87                 CERROR("obd_fail_loc=%d, fail operation rc=%d\n", id, ret);  \
88                 RETURN(ret);                                                 \
89         }                                                                    \
90 } while(0)
91
92 #define OBD_FAIL_WRITE(id)                                                   \
93 do {                                                                         \
94         if (OBD_FAIL_CHECK(id)) {                                            \
95                 CERROR("obd_fail_loc=%d, fail write operation\n", id);       \
96                 /* FIXME: do something bad here */                           \
97         }                                                                    \
98 } while (0)
99
100 #define OBD_ALLOC(ptr, size)                                    \
101 do {                                                            \
102         long s = (size);                                        \
103         (ptr) = kmalloc(s, GFP_KERNEL);                         \
104         if ((ptr) == NULL) {                                    \
105                 CERROR("kernel malloc of %ld bytes failed at "  \
106                        "%s:%d\n", s, __FILE__, __LINE__);       \
107         } else {                                                \
108                 memset((ptr), 0, s);                            \
109                 obd_memory += s;                                \
110         }                                                       \
111         CDEBUG(D_MALLOC, "kmalloced: %ld at %x (tot %ld).\n",   \
112                s, (int)(ptr), obd_memory);                      \
113 } while (0)
114
115 #define OBD_FREE(ptr, size)                                     \
116 do {                                                            \
117         int s = (size);                                         \
118         kfree((ptr));                                           \
119         CDEBUG(D_MALLOC, "kfreed: %d at %x (tot %ld).\n",       \
120                s, (int)(ptr), obd_memory);                      \
121         obd_memory -= s;                                        \
122 } while (0)
123
124 #endif