]>
Commit | Line | Data |
---|---|---|
274dcf55 MM |
1 | /* |
2 | * (C) 2001 Clemson University and The University of Chicago | |
3 | * | |
4 | * See COPYING in top-level directory. | |
5 | */ | |
6 | ||
7 | #include "protocol.h" | |
575e9461 | 8 | #include "orangefs-kernel.h" |
274dcf55 MM |
9 | |
10 | /* tags assigned to kernel upcall operations */ | |
11 | static __u64 next_tag_value; | |
12 | static DEFINE_SPINLOCK(next_tag_value_lock); | |
13 | ||
8bb8aefd | 14 | /* the orangefs memory caches */ |
274dcf55 | 15 | |
8bb8aefd | 16 | /* a cache for orangefs upcall/downcall operations */ |
274dcf55 MM |
17 | static struct kmem_cache *op_cache; |
18 | ||
274dcf55 MM |
19 | int op_cache_initialize(void) |
20 | { | |
8bb8aefd YL |
21 | op_cache = kmem_cache_create("orangefs_op_cache", |
22 | sizeof(struct orangefs_kernel_op_s), | |
274dcf55 | 23 | 0, |
8bb8aefd | 24 | ORANGEFS_CACHE_CREATE_FLAGS, |
274dcf55 MM |
25 | NULL); |
26 | ||
27 | if (!op_cache) { | |
8bb8aefd | 28 | gossip_err("Cannot create orangefs_op_cache\n"); |
274dcf55 MM |
29 | return -ENOMEM; |
30 | } | |
31 | ||
32 | /* initialize our atomic tag counter */ | |
33 | spin_lock(&next_tag_value_lock); | |
34 | next_tag_value = 100; | |
35 | spin_unlock(&next_tag_value_lock); | |
36 | return 0; | |
37 | } | |
38 | ||
39 | int op_cache_finalize(void) | |
40 | { | |
41 | kmem_cache_destroy(op_cache); | |
42 | return 0; | |
43 | } | |
44 | ||
8bb8aefd | 45 | char *get_opname_string(struct orangefs_kernel_op_s *new_op) |
274dcf55 MM |
46 | { |
47 | if (new_op) { | |
48 | __s32 type = new_op->upcall.type; | |
49 | ||
8bb8aefd | 50 | if (type == ORANGEFS_VFS_OP_FILE_IO) |
274dcf55 | 51 | return "OP_FILE_IO"; |
8bb8aefd | 52 | else if (type == ORANGEFS_VFS_OP_LOOKUP) |
274dcf55 | 53 | return "OP_LOOKUP"; |
8bb8aefd | 54 | else if (type == ORANGEFS_VFS_OP_CREATE) |
274dcf55 | 55 | return "OP_CREATE"; |
8bb8aefd | 56 | else if (type == ORANGEFS_VFS_OP_GETATTR) |
274dcf55 | 57 | return "OP_GETATTR"; |
8bb8aefd | 58 | else if (type == ORANGEFS_VFS_OP_REMOVE) |
274dcf55 | 59 | return "OP_REMOVE"; |
8bb8aefd | 60 | else if (type == ORANGEFS_VFS_OP_MKDIR) |
274dcf55 | 61 | return "OP_MKDIR"; |
8bb8aefd | 62 | else if (type == ORANGEFS_VFS_OP_READDIR) |
274dcf55 | 63 | return "OP_READDIR"; |
8bb8aefd | 64 | else if (type == ORANGEFS_VFS_OP_READDIRPLUS) |
274dcf55 | 65 | return "OP_READDIRPLUS"; |
8bb8aefd | 66 | else if (type == ORANGEFS_VFS_OP_SETATTR) |
274dcf55 | 67 | return "OP_SETATTR"; |
8bb8aefd | 68 | else if (type == ORANGEFS_VFS_OP_SYMLINK) |
274dcf55 | 69 | return "OP_SYMLINK"; |
8bb8aefd | 70 | else if (type == ORANGEFS_VFS_OP_RENAME) |
274dcf55 | 71 | return "OP_RENAME"; |
8bb8aefd | 72 | else if (type == ORANGEFS_VFS_OP_STATFS) |
274dcf55 | 73 | return "OP_STATFS"; |
8bb8aefd | 74 | else if (type == ORANGEFS_VFS_OP_TRUNCATE) |
274dcf55 | 75 | return "OP_TRUNCATE"; |
8bb8aefd | 76 | else if (type == ORANGEFS_VFS_OP_MMAP_RA_FLUSH) |
274dcf55 | 77 | return "OP_MMAP_RA_FLUSH"; |
8bb8aefd | 78 | else if (type == ORANGEFS_VFS_OP_FS_MOUNT) |
274dcf55 | 79 | return "OP_FS_MOUNT"; |
8bb8aefd | 80 | else if (type == ORANGEFS_VFS_OP_FS_UMOUNT) |
274dcf55 | 81 | return "OP_FS_UMOUNT"; |
8bb8aefd | 82 | else if (type == ORANGEFS_VFS_OP_GETXATTR) |
274dcf55 | 83 | return "OP_GETXATTR"; |
8bb8aefd | 84 | else if (type == ORANGEFS_VFS_OP_SETXATTR) |
274dcf55 | 85 | return "OP_SETXATTR"; |
8bb8aefd | 86 | else if (type == ORANGEFS_VFS_OP_LISTXATTR) |
274dcf55 | 87 | return "OP_LISTXATTR"; |
8bb8aefd | 88 | else if (type == ORANGEFS_VFS_OP_REMOVEXATTR) |
274dcf55 | 89 | return "OP_REMOVEXATTR"; |
8bb8aefd | 90 | else if (type == ORANGEFS_VFS_OP_PARAM) |
274dcf55 | 91 | return "OP_PARAM"; |
8bb8aefd | 92 | else if (type == ORANGEFS_VFS_OP_PERF_COUNT) |
274dcf55 | 93 | return "OP_PERF_COUNT"; |
8bb8aefd | 94 | else if (type == ORANGEFS_VFS_OP_CANCEL) |
274dcf55 | 95 | return "OP_CANCEL"; |
8bb8aefd | 96 | else if (type == ORANGEFS_VFS_OP_FSYNC) |
274dcf55 | 97 | return "OP_FSYNC"; |
8bb8aefd | 98 | else if (type == ORANGEFS_VFS_OP_FSKEY) |
274dcf55 | 99 | return "OP_FSKEY"; |
274dcf55 MM |
100 | } |
101 | return "OP_UNKNOWN?"; | |
102 | } | |
103 | ||
8bb8aefd | 104 | struct orangefs_kernel_op_s *op_alloc(__s32 type) |
274dcf55 | 105 | { |
8bb8aefd | 106 | struct orangefs_kernel_op_s *new_op = NULL; |
274dcf55 | 107 | |
2d4cae0d | 108 | new_op = kmem_cache_zalloc(op_cache, GFP_KERNEL); |
274dcf55 | 109 | if (new_op) { |
274dcf55 MM |
110 | INIT_LIST_HEAD(&new_op->list); |
111 | spin_lock_init(&new_op->lock); | |
112 | init_waitqueue_head(&new_op->waitq); | |
113 | ||
ed42fe05 | 114 | atomic_set(&new_op->ref_count, 1); |
274dcf55 | 115 | |
115b93a8 AV |
116 | init_completion(&new_op->done); |
117 | ||
118 | new_op->upcall.type = ORANGEFS_VFS_OP_INVALID; | |
119 | new_op->downcall.type = ORANGEFS_VFS_OP_INVALID; | |
120 | new_op->downcall.status = -1; | |
121 | ||
122 | new_op->op_state = OP_VFS_STATE_UNKNOWN; | |
123 | new_op->tag = 0; | |
274dcf55 MM |
124 | |
125 | /* initialize the op specific tag and upcall credentials */ | |
126 | spin_lock(&next_tag_value_lock); | |
127 | new_op->tag = next_tag_value++; | |
128 | if (next_tag_value == 0) | |
129 | next_tag_value = 100; | |
130 | spin_unlock(&next_tag_value_lock); | |
131 | new_op->upcall.type = type; | |
132 | new_op->attempts = 0; | |
133 | gossip_debug(GOSSIP_CACHE_DEBUG, | |
134 | "Alloced OP (%p: %llu %s)\n", | |
135 | new_op, | |
136 | llu(new_op->tag), | |
137 | get_opname_string(new_op)); | |
138 | ||
139 | new_op->upcall.uid = from_kuid(current_user_ns(), | |
140 | current_fsuid()); | |
141 | ||
142 | new_op->upcall.gid = from_kgid(current_user_ns(), | |
143 | current_fsgid()); | |
274dcf55 | 144 | } else { |
2d4cae0d | 145 | gossip_err("op_alloc: kmem_cache_zalloc failed!\n"); |
274dcf55 MM |
146 | } |
147 | return new_op; | |
148 | } | |
149 | ||
ed42fe05 | 150 | void __op_release(struct orangefs_kernel_op_s *orangefs_op) |
274dcf55 | 151 | { |
8bb8aefd | 152 | if (orangefs_op) { |
274dcf55 MM |
153 | gossip_debug(GOSSIP_CACHE_DEBUG, |
154 | "Releasing OP (%p: %llu)\n", | |
8bb8aefd YL |
155 | orangefs_op, |
156 | llu(orangefs_op->tag)); | |
8bb8aefd | 157 | kmem_cache_free(op_cache, orangefs_op); |
274dcf55 MM |
158 | } else { |
159 | gossip_err("NULL pointer in op_release\n"); | |
160 | } | |
161 | } |