.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | 2 | /* |
---|
3 | 3 | * (C) 2001 Clemson University and The University of Chicago |
---|
| 4 | + * Copyright 2018 Omnibond Systems, L.L.C. |
---|
4 | 5 | * |
---|
5 | 6 | * See COPYING in top-level directory. |
---|
6 | 7 | */ |
---|
.. | .. |
---|
14 | 15 | #include "orangefs-bufmap.h" |
---|
15 | 16 | #include <linux/posix_acl_xattr.h> |
---|
16 | 17 | #include <linux/xattr.h> |
---|
17 | | - |
---|
| 18 | +#include <linux/hashtable.h> |
---|
18 | 19 | |
---|
19 | 20 | #define SYSTEM_ORANGEFS_KEY "system.pvfs2." |
---|
20 | 21 | #define SYSTEM_ORANGEFS_KEY_LEN 13 |
---|
.. | .. |
---|
50 | 51 | return internal_flag; |
---|
51 | 52 | } |
---|
52 | 53 | |
---|
| 54 | +static unsigned int xattr_key(const char *key) |
---|
| 55 | +{ |
---|
| 56 | + unsigned int i = 0; |
---|
| 57 | + while (key) |
---|
| 58 | + i += *key++; |
---|
| 59 | + return i % 16; |
---|
| 60 | +} |
---|
| 61 | + |
---|
| 62 | +static struct orangefs_cached_xattr *find_cached_xattr(struct inode *inode, |
---|
| 63 | + const char *key) |
---|
| 64 | +{ |
---|
| 65 | + struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
---|
| 66 | + struct orangefs_cached_xattr *cx; |
---|
| 67 | + struct hlist_head *h; |
---|
| 68 | + struct hlist_node *tmp; |
---|
| 69 | + h = &orangefs_inode->xattr_cache[xattr_key(key)]; |
---|
| 70 | + if (hlist_empty(h)) |
---|
| 71 | + return NULL; |
---|
| 72 | + hlist_for_each_entry_safe(cx, tmp, h, node) { |
---|
| 73 | +/* if (!time_before(jiffies, cx->timeout)) { |
---|
| 74 | + hlist_del(&cx->node); |
---|
| 75 | + kfree(cx); |
---|
| 76 | + continue; |
---|
| 77 | + }*/ |
---|
| 78 | + if (!strcmp(cx->key, key)) |
---|
| 79 | + return cx; |
---|
| 80 | + } |
---|
| 81 | + return NULL; |
---|
| 82 | +} |
---|
53 | 83 | |
---|
54 | 84 | /* |
---|
55 | 85 | * Tries to get a specified key's attributes of a given |
---|
.. | .. |
---|
65 | 95 | { |
---|
66 | 96 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
---|
67 | 97 | struct orangefs_kernel_op_s *new_op = NULL; |
---|
| 98 | + struct orangefs_cached_xattr *cx; |
---|
68 | 99 | ssize_t ret = -ENOMEM; |
---|
69 | 100 | ssize_t length = 0; |
---|
70 | 101 | int fsuid; |
---|
.. | .. |
---|
93 | 124 | |
---|
94 | 125 | down_read(&orangefs_inode->xattr_sem); |
---|
95 | 126 | |
---|
| 127 | + cx = find_cached_xattr(inode, name); |
---|
| 128 | + if (cx && time_before(jiffies, cx->timeout)) { |
---|
| 129 | + if (cx->length == -1) { |
---|
| 130 | + ret = -ENODATA; |
---|
| 131 | + goto out_unlock; |
---|
| 132 | + } else { |
---|
| 133 | + if (size == 0) { |
---|
| 134 | + ret = cx->length; |
---|
| 135 | + goto out_unlock; |
---|
| 136 | + } |
---|
| 137 | + if (cx->length > size) { |
---|
| 138 | + ret = -ERANGE; |
---|
| 139 | + goto out_unlock; |
---|
| 140 | + } |
---|
| 141 | + memcpy(buffer, cx->val, cx->length); |
---|
| 142 | + memset(buffer + cx->length, 0, size - cx->length); |
---|
| 143 | + ret = cx->length; |
---|
| 144 | + goto out_unlock; |
---|
| 145 | + } |
---|
| 146 | + } |
---|
| 147 | + |
---|
96 | 148 | new_op = op_alloc(ORANGEFS_VFS_OP_GETXATTR); |
---|
97 | 149 | if (!new_op) |
---|
98 | 150 | goto out_unlock; |
---|
.. | .. |
---|
117 | 169 | " does not exist!\n", |
---|
118 | 170 | get_khandle_from_ino(inode), |
---|
119 | 171 | (char *)new_op->upcall.req.getxattr.key); |
---|
| 172 | + cx = kmalloc(sizeof *cx, GFP_KERNEL); |
---|
| 173 | + if (cx) { |
---|
| 174 | + strcpy(cx->key, name); |
---|
| 175 | + cx->length = -1; |
---|
| 176 | + cx->timeout = jiffies + |
---|
| 177 | + orangefs_getattr_timeout_msecs*HZ/1000; |
---|
| 178 | + hash_add(orangefs_inode->xattr_cache, &cx->node, |
---|
| 179 | + xattr_key(cx->key)); |
---|
| 180 | + } |
---|
120 | 181 | } |
---|
121 | 182 | goto out_release_op; |
---|
122 | 183 | } |
---|
.. | .. |
---|
156 | 217 | |
---|
157 | 218 | ret = length; |
---|
158 | 219 | |
---|
| 220 | + if (cx) { |
---|
| 221 | + strcpy(cx->key, name); |
---|
| 222 | + memcpy(cx->val, buffer, length); |
---|
| 223 | + cx->length = length; |
---|
| 224 | + cx->timeout = jiffies + HZ; |
---|
| 225 | + } else { |
---|
| 226 | + cx = kmalloc(sizeof *cx, GFP_KERNEL); |
---|
| 227 | + if (cx) { |
---|
| 228 | + strcpy(cx->key, name); |
---|
| 229 | + memcpy(cx->val, buffer, length); |
---|
| 230 | + cx->length = length; |
---|
| 231 | + cx->timeout = jiffies + HZ; |
---|
| 232 | + hash_add(orangefs_inode->xattr_cache, &cx->node, |
---|
| 233 | + xattr_key(cx->key)); |
---|
| 234 | + } |
---|
| 235 | + } |
---|
| 236 | + |
---|
159 | 237 | out_release_op: |
---|
160 | 238 | op_release(new_op); |
---|
161 | 239 | out_unlock: |
---|
.. | .. |
---|
168 | 246 | { |
---|
169 | 247 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
---|
170 | 248 | struct orangefs_kernel_op_s *new_op = NULL; |
---|
| 249 | + struct orangefs_cached_xattr *cx; |
---|
| 250 | + struct hlist_head *h; |
---|
| 251 | + struct hlist_node *tmp; |
---|
171 | 252 | int ret = -ENOMEM; |
---|
172 | 253 | |
---|
173 | 254 | if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN) |
---|
.. | .. |
---|
209 | 290 | "orangefs_inode_removexattr: returning %d\n", ret); |
---|
210 | 291 | |
---|
211 | 292 | op_release(new_op); |
---|
| 293 | + |
---|
| 294 | + h = &orangefs_inode->xattr_cache[xattr_key(name)]; |
---|
| 295 | + hlist_for_each_entry_safe(cx, tmp, h, node) { |
---|
| 296 | + if (!strcmp(cx->key, name)) { |
---|
| 297 | + hlist_del(&cx->node); |
---|
| 298 | + kfree(cx); |
---|
| 299 | + break; |
---|
| 300 | + } |
---|
| 301 | + } |
---|
| 302 | + |
---|
212 | 303 | out_unlock: |
---|
213 | 304 | up_write(&orangefs_inode->xattr_sem); |
---|
214 | 305 | return ret; |
---|
.. | .. |
---|
226 | 317 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
---|
227 | 318 | struct orangefs_kernel_op_s *new_op; |
---|
228 | 319 | int internal_flag = 0; |
---|
| 320 | + struct orangefs_cached_xattr *cx; |
---|
| 321 | + struct hlist_head *h; |
---|
| 322 | + struct hlist_node *tmp; |
---|
229 | 323 | int ret = -ENOMEM; |
---|
230 | 324 | |
---|
231 | 325 | gossip_debug(GOSSIP_XATTR_DEBUG, |
---|
.. | .. |
---|
287 | 381 | |
---|
288 | 382 | /* when request is serviced properly, free req op struct */ |
---|
289 | 383 | op_release(new_op); |
---|
| 384 | + |
---|
| 385 | + h = &orangefs_inode->xattr_cache[xattr_key(name)]; |
---|
| 386 | + hlist_for_each_entry_safe(cx, tmp, h, node) { |
---|
| 387 | + if (!strcmp(cx->key, name)) { |
---|
| 388 | + hlist_del(&cx->node); |
---|
| 389 | + kfree(cx); |
---|
| 390 | + break; |
---|
| 391 | + } |
---|
| 392 | + } |
---|
| 393 | + |
---|
290 | 394 | out_unlock: |
---|
291 | 395 | up_write(&orangefs_inode->xattr_sem); |
---|
292 | 396 | return ret; |
---|
.. | .. |
---|
437 | 541 | struct inode *inode, |
---|
438 | 542 | const char *name, |
---|
439 | 543 | void *buffer, |
---|
440 | | - size_t size) |
---|
| 544 | + size_t size, |
---|
| 545 | + int flags) |
---|
441 | 546 | { |
---|
442 | 547 | return orangefs_inode_getxattr(inode, name, buffer, size); |
---|
443 | 548 | |
---|