Whamcloud - gitweb
93863958b92d0053e8b3a226d2087b08afd346e1
[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_drop_packet;
33
34 enum {
35         OBD_INST_MDS_GETATTR = 1,
36         OBD_INST_MDS_READPAGE,
37         OBD_INST_MDS_READPAGE_BULK,
38         OBD_INST_MDS_REINT,
39         OBD_INST_MDS_OPEN,
40         OBD_INST_MDS_CLOSE,
41         OBD_INST_OST_CONNECT,
42         OBD_INST_OST_DISCONNECT,
43         OBD_INST_OST_GET_INFO,
44         OBD_INST_OST_CREATE,
45         OBD_INST_OST_DESTROY,
46         OBD_INST_OST_GETATTR,
47         OBD_INST_OST_SETATTR,
48         OBD_INST_OST_OPEN,
49         OBD_INST_OST_CLOSE,
50         OBD_INST_OST_BRW,
51         OBD_INST_OST_PUNCH
52 };
53
54 #define OBD_CHECK_DROP_PACKET(req, id)                                  \
55 do {                                                                    \
56         if (obd_drop_packet != id)                                      \
57                 break;                                                  \
58                                                                         \
59         CDEBUG(D_OTHER, "obd_drop_packet=%d, dropping packet.\n", id);  \
60         RETURN(0);                                                      \
61 } while(0)
62
63 #define OBD_ALLOC(ptr, size)                                    \
64 do {                                                            \
65         long s = (size);                                        \
66         (ptr) = kmalloc(s, GFP_KERNEL);                         \
67         if ((ptr) == NULL) {                                    \
68                 CERROR("kernel malloc of %ld bytes failed at "  \
69                        "%s:%d\n", s, __FILE__, __LINE__);       \
70         } else {                                                \
71                 memset((ptr), 0, s);                            \
72                 obd_memory += s;                                \
73         }                                                       \
74         CDEBUG(D_MALLOC, "kmalloced: %ld at %x (tot %ld).\n",   \
75                s, (int)(ptr), obd_memory);                      \
76 } while (0)
77
78 #define OBD_FREE(ptr, size)                                     \
79 do {                                                            \
80         int s = (size);                                         \
81         kfree((ptr));                                           \
82         CDEBUG(D_MALLOC, "kfreed: %d at %x (tot %ld).\n",       \
83                s, (int)(ptr), obd_memory);                      \
84         obd_memory -= s;                                        \
85 } while (0)
86
87 #endif