3 #include <linux/malloc.h>
4 #include <linux/vmalloc.h>
9 #define MIN(a,b) (((a)<(b)) ? (a): (b))
10 #define MAX(a,b) (((a)>(b)) ? (a): (b))
15 /* global variables */
16 extern int obd_debug_level;
17 extern int obd_print_entry;
20 #define D_PSDEV 1 /* debug information from psdev.c */
25 #define D_WARNING 32 /* misc warnings */
26 #define D_EXT2 64 /* anything from ext2_debug */
27 #define D_MALLOC 128 /* print malloc, free information */
28 #define D_CACHE 256 /* cache-related items */
29 #define D_INFO 512 /* general information, especially from interface.c */
30 #define D_IOCTL 1024 /* ioctl related information */
31 #define D_BLOCKS 2048 /* ext2 block allocation */
34 #define CDEBUG(mask, format, a...) \
36 if (obd_debug_level & mask) { \
37 printk("(%s,l. %d): ", __FUNCTION__, __LINE__); \
38 printk(format, ## a); } \
42 if (obd_print_entry) \
43 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
46 if (obd_print_entry) \
47 printk("Process %d leaving %s\n", current->pid, __FUNCTION__)
49 #else /* SIM_OBD_DEBUG */
55 #endif /* SIM_OBD_DEBUG */
58 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
60 #define PDEBUG(page,cmd) {if (page){\
61 char *uptodate = (Page_Uptodate(page)) ? "yes" : "no";\
62 char *locked = (PageLocked(page)) ? "yes" : "no";\
63 int count = page->count.counter;\
64 long ino = (page->inode) ? page->inode->i_ino : -1;\
65 long offset = page->offset / PAGE_SIZE;\
67 CDEBUG(D_IOCTL, " ** %s, cmd: %s, ino: %ld, off %ld, uptodate: %s, "\
68 "locked: %s, cnt %d page %p ** \n", __FUNCTION__,\
69 cmd, ino, offset, uptodate, locked, count, page);\
70 } else { CDEBUG(D_IOCTL, "** %s, no page\n", __FUNCTION__); }}
73 #define OBD_ALLOC(ptr, cast, size) \
76 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
77 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n", \
78 (int) size, (int) ptr); \
80 ptr = (cast)vmalloc((unsigned long) size); \
81 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n", \
82 (int) size, (int) ptr); \
85 printk("kernel malloc returns 0 at %s:%d\n", \
86 __FILE__, __LINE__); \
88 memset(ptr, 0, size); \
91 #define OBD_FREE(ptr,size) \
94 kfree_s((ptr), (size)); \
95 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
96 (int) size, (int) ptr); \
99 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
100 (int) size, (int) ptr); \
106 static inline void inode_to_iattr(struct inode *inode, struct iattr *tmp)
108 tmp->ia_mode = inode->i_mode;
109 tmp->ia_uid = inode->i_uid;
110 tmp->ia_gid = inode->i_gid;
111 tmp->ia_size = inode->i_size;
112 tmp->ia_atime = inode->i_atime;
113 tmp->ia_mtime = inode->i_mtime;
114 tmp->ia_ctime = inode->i_ctime;
115 tmp->ia_attr_flags = inode->i_flags;
120 static inline void inode_cpy(struct inode *dest, struct inode *src)
122 dest->i_mode = src->i_mode;
123 dest->i_uid = src->i_uid;
124 dest->i_gid = src->i_gid;
125 dest->i_size = src->i_size;
126 dest->i_atime = src->i_atime;
127 dest->i_mtime = src->i_mtime;
128 dest->i_ctime = src->i_ctime;
129 dest->i_attr_flags = src->i_flags;
130 /* allocation of space */
131 dest->i_blocks = src->i_blocks;
133 if ( !dest->i_blocks)
134 memcpy(&dest->u, &src->u, sizeof(src->u));