Whamcloud - gitweb
Trivial whitespace, struct, etc changes to bring the ldlm_testing branch more in
[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 #define OBD_FAIL_MDS                     0x100
35 #define OBD_FAIL_MDS_HANDLE_UNPACK       0x101
36 #define OBD_FAIL_MDS_GETATTR_NET         0x102
37 #define OBD_FAIL_MDS_GETATTR_PACK        0x103
38 #define OBD_FAIL_MDS_READPAGE_NET        0x104
39 #define OBD_FAIL_MDS_READPAGE_PACK       0x105
40 #define OBD_FAIL_MDS_SENDPAGE            0x106
41 #define OBD_FAIL_MDS_REINT_NET           0x107
42 #define OBD_FAIL_MDS_REINT_UNPACK        0x108
43 #define OBD_FAIL_MDS_REINT_SETATTR       0x109
44 #define OBD_FAIL_MDS_REINT_SETATTR_WRITE 0x10a
45 #define OBD_FAIL_MDS_REINT_CREATE        0x10b
46 #define OBD_FAIL_MDS_REINT_CREATE_WRITE  0x10c
47 #define OBD_FAIL_MDS_REINT_UNLINK        0x10d
48 #define OBD_FAIL_MDS_REINT_UNLINK_WRITE  0x10e
49 #define OBD_FAIL_MDS_REINT_LINK          0x10f
50 #define OBD_FAIL_MDS_REINT_LINK_WRITE    0x110
51 #define OBD_FAIL_MDS_REINT_RENAME        0x111
52 #define OBD_FAIL_MDS_REINT_RENAME_WRITE  0x112
53 #define OBD_FAIL_MDS_OPEN_NET            0x113
54 #define OBD_FAIL_MDS_OPEN_PACK           0x114
55 #define OBD_FAIL_MDS_CLOSE_NET           0x115
56 #define OBD_FAIL_MDS_CLOSE_PACK          0x116
57 #define OBD_FAIL_MDS_CONNECT_NET         0x117
58 #define OBD_FAIL_MDS_CONNECT_PACK       0x118
59
60 #define OBD_FAIL_OST                     0x200
61 #define OBD_FAIL_OST_CONNECT_NET         0x201
62 #define OBD_FAIL_OST_DISCONNECT_NET      0x202
63 #define OBD_FAIL_OST_GET_INFO_NET        0x203
64 #define OBD_FAIL_OST_CREATE_NET          0x204
65 #define OBD_FAIL_OST_DESTROY_NET         0x205
66 #define OBD_FAIL_OST_GETATTR_NET         0x206
67 #define OBD_FAIL_OST_SETATTR_NET         0x207
68 #define OBD_FAIL_OST_OPEN_NET            0x208
69 #define OBD_FAIL_OST_CLOSE_NET           0x209
70 #define OBD_FAIL_OST_BRW_NET             0x20a
71 #define OBD_FAIL_OST_PUNCH_NET           0x20b
72
73 #define OBB_FAIL_LDLM                    0x300
74 #define OBD_FAIL_LDLM_NAMESPACE_NEW      0x301
75 #define OBD_FAIL_LDLM_ENQUEUE            0x302
76 #define OBD_FAIL_LDLM_CONVERT            0x303
77 #define OBD_FAIL_LDLM_CANCEL             0x304
78 #define OBD_FAIL_LDLM_CALLBACK           0x305
79
80 /* preparation for a more advanced failure testbed (not functional yet) */
81 #define OBD_FAIL_MASK_SYS    0x0000FF00
82 #define OBD_FAIL_MASK_LOC    (0x000000FF | OBD_FAIL_MASK_SYS)
83 #define OBD_FAIL_ONCE        0x80000000
84 #define OBD_FAILED           0x40000000
85 #define OBD_FAIL_MDS_ALL_NET 0x01000000
86 #define OBD_FAIL_OST_ALL_NET 0x02000000
87
88 #define OBD_FAIL_CHECK(id)   ((obd_fail_loc & OBD_FAIL_MASK_LOC) == (id) &&  \
89                               ((obd_fail_loc & (OBD_FAILED | OBD_FAIL_ONCE))!=\
90                                 (OBD_FAILED | OBD_FAIL_ONCE)))
91
92 #define OBD_FAIL_RETURN(id, ret)                                             \
93 do {                                                                         \
94         if (OBD_FAIL_CHECK(id)) {                                            \
95                 CERROR("obd_fail_loc=%x, fail operation rc=%d\n", id, ret);  \
96                 obd_fail_loc |= OBD_FAILED;                                  \
97                 if ((id) & OBD_FAIL_ONCE)                                    \
98                         obd_fail_loc |= OBD_FAIL_ONCE;                       \
99                 RETURN(ret);                                                 \
100         }                                                                    \
101 } while(0)
102
103 #include <linux/types.h>
104 #include <linux/blkdev.h>
105
106 static inline void OBD_FAIL_WRITE(int id, kdev_t dev)
107 {
108         if (OBD_FAIL_CHECK(id)) {
109 #ifdef CONFIG_DEV_RDONLY
110                 CERROR("obd_fail_loc=%x, fail write operation on %s\n",
111                        id, bdevname(dev));
112                 dev_set_rdonly(dev, 2);
113 #else
114                 CERROR("obd_fail_loc=%x, can't fail write operation on %s\n",
115                        id, bdevname(dev));
116 #endif
117                 /* We set FAIL_ONCE because we never "un-fail" a device */
118                 obd_fail_loc |= OBD_FAILED | OBD_FAIL_ONCE;
119         }
120 }
121
122 #define OBD_ALLOC(ptr, size)                                            \
123 do {                                                                    \
124         long s = (size);                                                \
125         (ptr) = kmalloc(s, GFP_KERNEL);                                 \
126         if ((ptr) == NULL) {                                            \
127                 CERROR("kmalloc of '" #ptr "' (%ld bytes) failed "      \
128                        "at %s:%d\n", s, __FILE__, __LINE__);            \
129         } else {                                                        \
130                 memset((ptr), 0, s);                                    \
131                 obd_memory += s;                                        \
132                 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %ld at "        \
133                        "%p (tot %ld).\n", s, (ptr), obd_memory);        \
134         }                                                               \
135 } while (0)
136
137 #define OBD_FREE(ptr, size)                                             \
138 do {                                                                    \
139         int s = (size);                                                 \
140         kfree((ptr));                                                   \
141         CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %ld).\n",    \
142                s, (ptr), obd_memory);                                   \
143         obd_memory -= s;                                                \
144 } while (0)
145
146 #endif