Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / lvfs / lvfs_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/lvfs/lvfs_lib.c
5  *  Lustre filesystem abstraction routines
6  *
7  *  Copyright (C) 2007 Cluster File Systems, Inc.
8  *   Author: Andreas Dilger <adilger@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 #ifdef __KERNEL__
26 #include <linux/module.h>
27 #include <linux/random.h>
28 #else
29 #include <liblustre.h>
30 #endif
31 #include <lustre_lib.h>
32
33 unsigned int obd_fail_val = 0;
34 unsigned int obd_fail_loc = 0;
35 unsigned int obd_alloc_fail_rate = 0;
36
37 int obd_alloc_fail(const void *ptr, const char *name, const char *type,
38                    size_t size, const char *file, int line)
39 {
40         if (ptr == NULL ||
41             (ll_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
42                 CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n",
43                        ptr ? "force " :"", type, name, (__u64)size, file,
44                        line);
45                 CERROR(LPU64" total bytes and "LPU64" total pages "
46                        "("LPU64" bytes) allocated by Lustre, "
47                        "%d total bytes by LNET\n",
48                        obd_memory_sum(),
49                        obd_pages_sum() << CFS_PAGE_SHIFT,
50                        obd_pages_sum(),
51                        atomic_read(&libcfs_kmemory));                
52                 return 1;
53         }
54         return 0;
55 }
56 EXPORT_SYMBOL(obd_alloc_fail);
57
58 EXPORT_SYMBOL(obd_fail_loc);
59 EXPORT_SYMBOL(obd_alloc_fail_rate);
60 EXPORT_SYMBOL(obd_fail_val);