Whamcloud - gitweb
Branch HEAD
[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 _LINUX_OBD_SUPPORT
24 #define _LINUX_OBD_SUPPORT
25
26 #ifndef _OBD_SUPPORT
27 #error Do not #include this file directly. #include <obd_support.h> instead
28 #endif
29
30 #ifdef __KERNEL__
31 #ifndef AUTOCONF_INCLUDED
32 #include <linux/config.h>
33 #endif
34 #include <linux/autoconf.h>
35 #include <linux/slab.h>
36 #include <linux/highmem.h>
37 #endif
38 #include <libcfs/kp30.h>
39 #include <linux/lustre_compat25.h>
40
41 /* Prefer the kernel's version, if it exports it, because it might be
42  * optimized for this CPU. */
43 #if defined(__KERNEL__) && (defined(CONFIG_CRC32) || defined(CONFIG_CRC32_MODULE))
44 # include <linux/crc32.h>
45 #else
46 /* crc32_le lifted from the Linux kernel, which had the following to say:
47  *
48  * This code is in the public domain; copyright abandoned.
49  * Liability for non-performance of this code is limited to the amount
50  * you paid for it.  Since it is distributed for free, your refund will
51  * be very very small.  If it breaks, you get to keep both pieces.
52  */
53 #define CRCPOLY_LE 0xedb88320
54 /**
55  * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
56  * @crc - seed value for computation.  ~0 for Ethernet, sometimes 0 for
57  *        other uses, or the previous crc32 value if computing incrementally.
58  * @p   - pointer to buffer over which CRC is run
59  * @len - length of buffer @p
60  */
61 static inline __u32 crc32_le(__u32 crc, unsigned char const *p, size_t len)
62 {
63         int i;
64         while (len--) {
65                 crc ^= *p++;
66                 for (i = 0; i < 8; i++)
67                         crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
68         }
69         return crc;
70 }
71 #endif
72
73 #ifdef __KERNEL__
74 # include <linux/types.h>
75 # include <linux/blkdev.h>
76 # include <lvfs.h>
77
78 static inline void OBD_FAIL_WRITE(int id, struct super_block *sb)
79 {
80         if (OBD_FAIL_CHECK(id)) {
81 #ifdef LIBCFS_DEBUG
82                 BDEVNAME_DECLARE_STORAGE(tmp);
83                 CERROR("obd_fail_loc=%x, fail write operation on %s\n",
84                        id, ll_bdevname(sb, tmp));
85 #endif
86                 /* TODO-CMD: fix getting jdev */
87                 __lvfs_set_rdonly(lvfs_sbdev(sb), (lvfs_sbdev_type)0);
88                 /* We set FAIL_ONCE because we never "un-fail" a device */
89                 obd_fail_loc |= OBD_FAILED | OBD_FAIL_ONCE;
90         }
91 }
92
93 #define OBD_SLEEP_ON(wq, state)  wait_event_interruptible(wq, state)
94
95
96 #else /* !__KERNEL__ */
97 # define LTIME_S(time) (time)
98 /* for obd_class.h */
99 # ifndef ERR_PTR
100 #  define ERR_PTR(a) ((void *)(a))
101 # endif
102 #endif  /* __KERNEL__ */
103
104 #endif