1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * Basic library routines.
25 #ifndef __LIBCFS_LINUX_CFS_MEM_H__
26 #define __LIBCFS_LINUX_CFS_MEM_H__
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
33 # include <linux/mm.h>
34 # include <linux/vmalloc.h>
35 # include <linux/pagemap.h>
36 # include <linux/slab.h>
37 # ifdef HAVE_MM_INLINE
38 # include <linux/mm_inline.h>
41 typedef struct page cfs_page_t;
42 #define CFS_PAGE_SIZE PAGE_CACHE_SIZE
43 #define CFS_PAGE_SHIFT PAGE_CACHE_SHIFT
44 #define CFS_PAGE_MASK PAGE_CACHE_MASK
46 cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order);
47 #define cfs_alloc_page(f) cfs_alloc_pages(f, 0)
48 #define cfs_free_pages(p, o) __free_pages(p, o)
49 #define cfs_free_page(p) __free_pages(p, 0)
51 static inline void *cfs_page_address(cfs_page_t *page)
53 return page_address(page);
56 static inline void *cfs_kmap(cfs_page_t *page)
61 static inline void cfs_kunmap(cfs_page_t *page)
66 static inline void cfs_get_page(cfs_page_t *page)
71 static inline int cfs_page_count(cfs_page_t *page)
73 return page_count(page);
76 static inline void cfs_set_page_count(cfs_page_t *page, int v)
78 set_page_count(page, v);
84 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
85 extern void cfs_free(void *addr);
87 extern void *cfs_alloc_large(size_t nr_bytes);
88 extern void cfs_free_large(void *addr);
93 typedef kmem_cache_t cfs_mem_cache_t;
94 extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long,
95 void (*)(void *, cfs_mem_cache_t *, unsigned long),
96 void (*)(void *, cfs_mem_cache_t *, unsigned long));
97 extern int cfs_mem_cache_destroy ( cfs_mem_cache_t * );
98 extern void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int);
99 extern void cfs_mem_cache_free ( cfs_mem_cache_t *, void *);
103 #define CFS_DECL_MMSPACE mm_segment_t __oldfs
104 #define CFS_MMSPACE_OPEN do { __oldfs = get_fs(); set_fs(get_ds());} while(0)
105 #define CFS_MMSPACE_CLOSE set_fs(__oldfs)
110 #endif /* __LINUX_CFS_MEM_H__ */