1 // SPDX-License-Identifier: GPL-2.0
3 * (C) 2001 Clemson University and The University of Chicago
5 * See COPYING in top-level directory.
9 #include "orangefs-kernel.h"
11 /* tags assigned to kernel upcall operations */
12 static __u64 next_tag_value
;
13 static DEFINE_SPINLOCK(next_tag_value_lock
);
15 /* the orangefs memory caches */
17 /* a cache for orangefs upcall/downcall operations */
18 static struct kmem_cache
*op_cache
;
20 int op_cache_initialize(void)
22 op_cache
= kmem_cache_create("orangefs_op_cache",
23 sizeof(struct orangefs_kernel_op_s
),
25 ORANGEFS_CACHE_CREATE_FLAGS
,
29 gossip_err("Cannot create orangefs_op_cache\n");
33 /* initialize our atomic tag counter */
34 spin_lock(&next_tag_value_lock
);
36 spin_unlock(&next_tag_value_lock
);
40 int op_cache_finalize(void)
42 kmem_cache_destroy(op_cache
);
46 char *get_opname_string(struct orangefs_kernel_op_s
*new_op
)
49 __s32 type
= new_op
->upcall
.type
;
51 if (type
== ORANGEFS_VFS_OP_FILE_IO
)
53 else if (type
== ORANGEFS_VFS_OP_LOOKUP
)
55 else if (type
== ORANGEFS_VFS_OP_CREATE
)
57 else if (type
== ORANGEFS_VFS_OP_GETATTR
)
59 else if (type
== ORANGEFS_VFS_OP_REMOVE
)
61 else if (type
== ORANGEFS_VFS_OP_MKDIR
)
63 else if (type
== ORANGEFS_VFS_OP_READDIR
)
65 else if (type
== ORANGEFS_VFS_OP_READDIRPLUS
)
66 return "OP_READDIRPLUS";
67 else if (type
== ORANGEFS_VFS_OP_SETATTR
)
69 else if (type
== ORANGEFS_VFS_OP_SYMLINK
)
71 else if (type
== ORANGEFS_VFS_OP_RENAME
)
73 else if (type
== ORANGEFS_VFS_OP_STATFS
)
75 else if (type
== ORANGEFS_VFS_OP_TRUNCATE
)
77 else if (type
== ORANGEFS_VFS_OP_RA_FLUSH
)
79 else if (type
== ORANGEFS_VFS_OP_FS_MOUNT
)
81 else if (type
== ORANGEFS_VFS_OP_FS_UMOUNT
)
82 return "OP_FS_UMOUNT";
83 else if (type
== ORANGEFS_VFS_OP_GETXATTR
)
85 else if (type
== ORANGEFS_VFS_OP_SETXATTR
)
87 else if (type
== ORANGEFS_VFS_OP_LISTXATTR
)
88 return "OP_LISTXATTR";
89 else if (type
== ORANGEFS_VFS_OP_REMOVEXATTR
)
90 return "OP_REMOVEXATTR";
91 else if (type
== ORANGEFS_VFS_OP_PARAM
)
93 else if (type
== ORANGEFS_VFS_OP_PERF_COUNT
)
94 return "OP_PERF_COUNT";
95 else if (type
== ORANGEFS_VFS_OP_CANCEL
)
97 else if (type
== ORANGEFS_VFS_OP_FSYNC
)
99 else if (type
== ORANGEFS_VFS_OP_FSKEY
)
101 else if (type
== ORANGEFS_VFS_OP_FEATURES
)
102 return "OP_FEATURES";
104 return "OP_UNKNOWN?";
107 void orangefs_new_tag(struct orangefs_kernel_op_s
*op
)
109 spin_lock(&next_tag_value_lock
);
110 op
->tag
= next_tag_value
++;
111 if (next_tag_value
== 0)
112 next_tag_value
= 100;
113 spin_unlock(&next_tag_value_lock
);
116 struct orangefs_kernel_op_s
*op_alloc(__s32 type
)
118 struct orangefs_kernel_op_s
*new_op
= NULL
;
120 new_op
= kmem_cache_zalloc(op_cache
, GFP_KERNEL
);
122 INIT_LIST_HEAD(&new_op
->list
);
123 spin_lock_init(&new_op
->lock
);
124 init_completion(&new_op
->waitq
);
126 new_op
->upcall
.type
= ORANGEFS_VFS_OP_INVALID
;
127 new_op
->downcall
.type
= ORANGEFS_VFS_OP_INVALID
;
128 new_op
->downcall
.status
= -1;
130 new_op
->op_state
= OP_VFS_STATE_UNKNOWN
;
132 /* initialize the op specific tag and upcall credentials */
133 orangefs_new_tag(new_op
);
134 new_op
->upcall
.type
= type
;
135 new_op
->attempts
= 0;
136 gossip_debug(GOSSIP_CACHE_DEBUG
,
137 "Alloced OP (%p: %llu %s)\n",
140 get_opname_string(new_op
));
142 new_op
->upcall
.uid
= from_kuid(&init_user_ns
,
145 new_op
->upcall
.gid
= from_kgid(&init_user_ns
,
148 gossip_err("op_alloc: kmem_cache_zalloc failed!\n");
153 void op_release(struct orangefs_kernel_op_s
*orangefs_op
)
156 gossip_debug(GOSSIP_CACHE_DEBUG
,
157 "Releasing OP (%p: %llu)\n",
159 llu(orangefs_op
->tag
));
160 kmem_cache_free(op_cache
, orangefs_op
);
162 gossip_err("NULL pointer in op_release\n");