Whamcloud - gitweb
bz-13541
[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 int obd_alloc_fail(const void *ptr, const char *name, const char *type,
34                    size_t size, const char *file, int line)
35 {
36         if (ptr == NULL ||
37             (ll_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
38                 CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n",
39                        ptr ? "force " :"", type, name, (__u64) size, file,
40                        line);
41                 CERROR("%d total bytes allocated by Lustre, %d by Portals\n",
42                        atomic_read(&obd_memory), atomic_read(&libcfs_kmemory));
43                 return 1;
44         }
45         return 0;
46 }
47 EXPORT_SYMBOL(obd_alloc_fail);