2 * (C) 2001 Clemson University and The University of Chicago
4 * See COPYING in top-level directory.
8 #include "pvfs2-kernel.h"
10 /* tags assigned to kernel upcall operations */
11 static __u64 next_tag_value
;
12 static DEFINE_SPINLOCK(next_tag_value_lock
);
14 /* the orangefs memory caches */
16 /* a cache for orangefs upcall/downcall operations */
17 static struct kmem_cache
*op_cache
;
19 /* a cache for device (/dev/pvfs2-req) communication */
20 static struct kmem_cache
*dev_req_cache
;
22 /* a cache for orangefs_kiocb objects (i.e orangefs iocb structures ) */
23 static struct kmem_cache
*orangefs_kiocb_cache
;
25 int op_cache_initialize(void)
27 op_cache
= kmem_cache_create("orangefs_op_cache",
28 sizeof(struct orangefs_kernel_op_s
),
30 ORANGEFS_CACHE_CREATE_FLAGS
,
34 gossip_err("Cannot create orangefs_op_cache\n");
38 /* initialize our atomic tag counter */
39 spin_lock(&next_tag_value_lock
);
41 spin_unlock(&next_tag_value_lock
);
45 int op_cache_finalize(void)
47 kmem_cache_destroy(op_cache
);
51 char *get_opname_string(struct orangefs_kernel_op_s
*new_op
)
54 __s32 type
= new_op
->upcall
.type
;
56 if (type
== ORANGEFS_VFS_OP_FILE_IO
)
58 else if (type
== ORANGEFS_VFS_OP_LOOKUP
)
60 else if (type
== ORANGEFS_VFS_OP_CREATE
)
62 else if (type
== ORANGEFS_VFS_OP_GETATTR
)
64 else if (type
== ORANGEFS_VFS_OP_REMOVE
)
66 else if (type
== ORANGEFS_VFS_OP_MKDIR
)
68 else if (type
== ORANGEFS_VFS_OP_READDIR
)
70 else if (type
== ORANGEFS_VFS_OP_READDIRPLUS
)
71 return "OP_READDIRPLUS";
72 else if (type
== ORANGEFS_VFS_OP_SETATTR
)
74 else if (type
== ORANGEFS_VFS_OP_SYMLINK
)
76 else if (type
== ORANGEFS_VFS_OP_RENAME
)
78 else if (type
== ORANGEFS_VFS_OP_STATFS
)
80 else if (type
== ORANGEFS_VFS_OP_TRUNCATE
)
82 else if (type
== ORANGEFS_VFS_OP_MMAP_RA_FLUSH
)
83 return "OP_MMAP_RA_FLUSH";
84 else if (type
== ORANGEFS_VFS_OP_FS_MOUNT
)
86 else if (type
== ORANGEFS_VFS_OP_FS_UMOUNT
)
87 return "OP_FS_UMOUNT";
88 else if (type
== ORANGEFS_VFS_OP_GETXATTR
)
90 else if (type
== ORANGEFS_VFS_OP_SETXATTR
)
92 else if (type
== ORANGEFS_VFS_OP_LISTXATTR
)
93 return "OP_LISTXATTR";
94 else if (type
== ORANGEFS_VFS_OP_REMOVEXATTR
)
95 return "OP_REMOVEXATTR";
96 else if (type
== ORANGEFS_VFS_OP_PARAM
)
98 else if (type
== ORANGEFS_VFS_OP_PERF_COUNT
)
99 return "OP_PERF_COUNT";
100 else if (type
== ORANGEFS_VFS_OP_CANCEL
)
102 else if (type
== ORANGEFS_VFS_OP_FSYNC
)
104 else if (type
== ORANGEFS_VFS_OP_FSKEY
)
107 return "OP_UNKNOWN?";
110 struct orangefs_kernel_op_s
*op_alloc(__s32 type
)
112 struct orangefs_kernel_op_s
*new_op
= NULL
;
114 new_op
= kmem_cache_alloc(op_cache
, ORANGEFS_CACHE_ALLOC_FLAGS
);
116 memset(new_op
, 0, sizeof(struct orangefs_kernel_op_s
));
118 INIT_LIST_HEAD(&new_op
->list
);
119 spin_lock_init(&new_op
->lock
);
120 init_waitqueue_head(&new_op
->waitq
);
122 init_waitqueue_head(&new_op
->io_completion_waitq
);
123 atomic_set(&new_op
->aio_ref_count
, 0);
125 orangefs_op_initialize(new_op
);
127 /* initialize the op specific tag and upcall credentials */
128 spin_lock(&next_tag_value_lock
);
129 new_op
->tag
= next_tag_value
++;
130 if (next_tag_value
== 0)
131 next_tag_value
= 100;
132 spin_unlock(&next_tag_value_lock
);
133 new_op
->upcall
.type
= type
;
134 new_op
->attempts
= 0;
135 gossip_debug(GOSSIP_CACHE_DEBUG
,
136 "Alloced OP (%p: %llu %s)\n",
139 get_opname_string(new_op
));
141 new_op
->upcall
.uid
= from_kuid(current_user_ns(),
144 new_op
->upcall
.gid
= from_kgid(current_user_ns(),
147 gossip_err("op_alloc: kmem_cache_alloc failed!\n");
152 void op_release(struct orangefs_kernel_op_s
*orangefs_op
)
155 gossip_debug(GOSSIP_CACHE_DEBUG
,
156 "Releasing OP (%p: %llu)\n",
158 llu(orangefs_op
->tag
));
159 orangefs_op_initialize(orangefs_op
);
160 kmem_cache_free(op_cache
, orangefs_op
);
162 gossip_err("NULL pointer in op_release\n");
166 int dev_req_cache_initialize(void)
168 dev_req_cache
= kmem_cache_create("orangefs_devreqcache",
169 MAX_ALIGNED_DEV_REQ_DOWNSIZE
,
171 ORANGEFS_CACHE_CREATE_FLAGS
,
174 if (!dev_req_cache
) {
175 gossip_err("Cannot create orangefs_dev_req_cache\n");
181 int dev_req_cache_finalize(void)
183 kmem_cache_destroy(dev_req_cache
);
187 void *dev_req_alloc(void)
191 buffer
= kmem_cache_alloc(dev_req_cache
, ORANGEFS_CACHE_ALLOC_FLAGS
);
193 gossip_err("Failed to allocate from dev_req_cache\n");
195 memset(buffer
, 0, sizeof(MAX_ALIGNED_DEV_REQ_DOWNSIZE
));
199 void dev_req_release(void *buffer
)
202 kmem_cache_free(dev_req_cache
, buffer
);
204 gossip_err("NULL pointer passed to dev_req_release\n");
207 int kiocb_cache_initialize(void)
209 orangefs_kiocb_cache
= kmem_cache_create("orangefs_kiocbcache",
210 sizeof(struct orangefs_kiocb_s
),
212 ORANGEFS_CACHE_CREATE_FLAGS
,
215 if (!orangefs_kiocb_cache
) {
216 gossip_err("Cannot create orangefs_kiocb_cache!\n");
222 int kiocb_cache_finalize(void)
224 kmem_cache_destroy(orangefs_kiocb_cache
);
228 struct orangefs_kiocb_s
*kiocb_alloc(void)
230 struct orangefs_kiocb_s
*x
= NULL
;
232 x
= kmem_cache_alloc(orangefs_kiocb_cache
, ORANGEFS_CACHE_ALLOC_FLAGS
);
234 gossip_err("kiocb_alloc: kmem_cache_alloc failed!\n");
236 memset(x
, 0, sizeof(struct orangefs_kiocb_s
));
240 void kiocb_release(struct orangefs_kiocb_s
*x
)
243 kmem_cache_free(orangefs_kiocb_cache
, x
);
245 gossip_err("kiocb_release: kmem_cache_free NULL pointer!\n");