Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / llite / xattr_cache.c
1 /* GPL HEADER START
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 only,
7  * as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License version 2 for more details (a copy is included
13  * in the LICENSE file that accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License
16  * version 2 along with this program; If not, see http://www.gnu.org/licenses
17  *
18  * Please  visit http://www.xyratex.com/contact if you need additional
19  * information or have any questions.
20  *
21  * GPL HEADER END
22  */
23
24 /*
25  * Copyright 2012 Xyratex Technology Limited
26  *
27  * Copyright (c) 2013, 2017, Intel Corporation.
28  *
29  * Author: Andrew Perepechko <Andrew_Perepechko@xyratex.com>
30  *
31  */
32
33 #define DEBUG_SUBSYSTEM S_LLITE
34
35 #include <linux/fs.h>
36 #include <linux/sched.h>
37 #include <linux/mm.h>
38 #include <obd_support.h>
39 #include <lustre_dlm.h>
40 #include "llite_internal.h"
41
42 /* If we ever have hundreds of extended attributes, we might want to consider
43  * using a hash or a tree structure instead of list for faster lookups.
44  */
45 struct ll_xattr_entry {
46         struct list_head xe_list; /* protected by lli_xattrs_list_rwsem */
47         char *xe_name;            /* xattr name, \0-terminated */
48         char *xe_value;           /* xattr value */
49         unsigned int xe_namelen;  /* strlen(xe_name) + 1 */
50         unsigned int xe_vallen;   /* xattr value length */
51 };
52
53 static struct kmem_cache *xattr_kmem;
54 static struct lu_kmem_descr xattr_caches[] = {
55         {
56                 .ckd_cache = &xattr_kmem,
57                 .ckd_name  = "xattr_kmem",
58                 .ckd_size  = sizeof(struct ll_xattr_entry)
59         },
60         {
61                 .ckd_cache = NULL
62         }
63 };
64
65 int ll_xattr_init(void)
66 {
67         return lu_kmem_init(xattr_caches);
68 }
69
70 void ll_xattr_fini(void)
71 {
72         lu_kmem_fini(xattr_caches);
73 }
74
75 /*
76  * Initializes xattr cache for an inode.
77  *
78  * This initializes the xattr list and marks cache presence.
79  */
80 static void ll_xattr_cache_init(struct ll_inode_info *lli)
81 {
82         ENTRY;
83
84         LASSERT(lli != NULL);
85
86         INIT_LIST_HEAD(&lli->lli_xattrs);
87         set_bit(LLIF_XATTR_CACHE, &lli->lli_flags);
88 }
89
90 /**
91  *  This looks for a specific extended attribute.
92  *
93  *  Find in @cache and return @xattr_name attribute in @xattr,
94  *  for the NULL @xattr_name return the first cached @xattr.
95  *
96  *  \retval 0        success
97  *  \retval -ENODATA if not found
98  */
99 static int ll_xattr_cache_find(struct list_head *cache,
100                                const char *xattr_name,
101                                struct ll_xattr_entry **xattr)
102 {
103         struct ll_xattr_entry *entry;
104
105         ENTRY;
106
107         list_for_each_entry(entry, cache, xe_list) {
108                 /* xattr_name == NULL means look for any entry */
109                 if (xattr_name == NULL ||
110                     strcmp(xattr_name, entry->xe_name) == 0) {
111                         *xattr = entry;
112                         CDEBUG(D_CACHE, "find: [%s]=%.*s\n",
113                                entry->xe_name, entry->xe_vallen,
114                                entry->xe_value);
115                         RETURN(0);
116                 }
117         }
118
119         RETURN(-ENODATA);
120 }
121
122 /**
123  * This adds an xattr.
124  *
125  * Add @xattr_name attr with @xattr_val value and @xattr_val_len length,
126  *
127  * \retval 0       success
128  * \retval -ENOMEM if no memory could be allocated for the cached attr
129  * \retval -EPROTO if duplicate xattr is being added
130  */
131 static int ll_xattr_cache_add(struct list_head *cache,
132                               const char *xattr_name,
133                               const char *xattr_val,
134                               unsigned int xattr_val_len)
135 {
136         struct ll_xattr_entry *xattr;
137
138         ENTRY;
139
140         if (ll_xattr_cache_find(cache, xattr_name, &xattr) == 0) {
141                 if (!strcmp(xattr_name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) ||
142                     !strcmp(xattr_name, LL_XATTR_NAME_ENCRYPTION_CONTEXT_OLD))
143                         /* it means enc ctx was already in cache,
144                          * ignore error as it cannot be modified
145                          */
146                         RETURN(0);
147
148                 CDEBUG(D_CACHE, "duplicate xattr: [%s]\n", xattr_name);
149                 RETURN(-EPROTO);
150         }
151
152         OBD_SLAB_ALLOC_PTR_GFP(xattr, xattr_kmem, GFP_NOFS);
153         if (xattr == NULL) {
154                 CDEBUG(D_CACHE, "failed to allocate xattr\n");
155                 RETURN(-ENOMEM);
156         }
157
158         xattr->xe_namelen = strlen(xattr_name) + 1;
159
160         OBD_ALLOC(xattr->xe_name, xattr->xe_namelen);
161         if (!xattr->xe_name) {
162                 CDEBUG(D_CACHE, "failed to alloc xattr name %u\n",
163                        xattr->xe_namelen);
164                 goto err_name;
165         }
166         OBD_ALLOC(xattr->xe_value, xattr_val_len);
167         if (!xattr->xe_value) {
168                 CDEBUG(D_CACHE, "failed to alloc xattr value %d\n",
169                        xattr_val_len);
170                 goto err_value;
171         }
172
173         memcpy(xattr->xe_name, xattr_name, xattr->xe_namelen);
174         memcpy(xattr->xe_value, xattr_val, xattr_val_len);
175         xattr->xe_vallen = xattr_val_len;
176         list_add(&xattr->xe_list, cache);
177
178         CDEBUG(D_CACHE, "set: [%s]=%.*s\n", xattr_name,
179                 xattr_val_len, xattr_val);
180
181         RETURN(0);
182 err_value:
183         OBD_FREE(xattr->xe_name, xattr->xe_namelen);
184 err_name:
185         OBD_SLAB_FREE_PTR(xattr, xattr_kmem);
186
187         RETURN(-ENOMEM);
188 }
189
190 /**
191  * This removes an extended attribute from cache.
192  *
193  * Remove @xattr_name attribute from @cache.
194  *
195  * \retval 0        success
196  * \retval -ENODATA if @xattr_name is not cached
197  */
198 static int ll_xattr_cache_del(struct list_head *cache,
199                               const char *xattr_name)
200 {
201         struct ll_xattr_entry *xattr;
202
203         ENTRY;
204
205         CDEBUG(D_CACHE, "del xattr: %s\n", xattr_name);
206
207         if (ll_xattr_cache_find(cache, xattr_name, &xattr) == 0) {
208                 list_del(&xattr->xe_list);
209                 OBD_FREE(xattr->xe_name, xattr->xe_namelen);
210                 OBD_FREE(xattr->xe_value, xattr->xe_vallen);
211                 OBD_SLAB_FREE_PTR(xattr, xattr_kmem);
212
213                 RETURN(0);
214         }
215
216         RETURN(-ENODATA);
217 }
218
219 /**
220  * This iterates cached extended attributes.
221  *
222  * Walk over cached attributes in @cache and
223  * fill in @xld_buffer or only calculate buffer
224  * size if @xld_buffer is NULL.
225  *
226  * \retval >= 0     buffer list size
227  * \retval -ENODATA if the list cannot fit @xld_size buffer
228  */
229 static int ll_xattr_cache_list(struct list_head *cache,
230                                char *xld_buffer,
231                                int xld_size)
232 {
233         struct ll_xattr_entry *xattr, *tmp;
234         int xld_tail = 0;
235
236         ENTRY;
237
238         list_for_each_entry_safe(xattr, tmp, cache, xe_list) {
239                 CDEBUG(D_CACHE, "list: buffer=%p[%d] name=%s\n",
240                         xld_buffer, xld_tail, xattr->xe_name);
241
242                 if (xld_buffer) {
243                         xld_size -= xattr->xe_namelen;
244                         if (xld_size < 0)
245                                 break;
246                         memcpy(&xld_buffer[xld_tail],
247                                xattr->xe_name, xattr->xe_namelen);
248                 }
249                 xld_tail += xattr->xe_namelen;
250         }
251
252         if (xld_size < 0)
253                 RETURN(-ERANGE);
254
255         RETURN(xld_tail);
256 }
257
258 /**
259  * Check if the xattr cache is initialized.
260  *
261  * \retval 0 @cache is not initialized
262  * \retval 1 @cache is initialized
263  */
264 static int ll_xattr_cache_valid(struct ll_inode_info *lli)
265 {
266         return test_bit(LLIF_XATTR_CACHE, &lli->lli_flags);
267 }
268
269 /**
270  * Check if the xattr cache is filled.
271  *
272  * \retval 0 @cache is not filled
273  * \retval 1 @cache is filled
274  */
275 static int ll_xattr_cache_filled(struct ll_inode_info *lli)
276 {
277         return test_bit(LLIF_XATTR_CACHE_FILLED, &lli->lli_flags);
278 }
279
280 /**
281  * This finalizes the xattr cache.
282  *
283  * Free all xattr memory. @lli is the inode info pointer.
284  *
285  * \retval 0 no error occured
286  */
287 static int ll_xattr_cache_destroy_locked(struct ll_inode_info *lli)
288 {
289         ENTRY;
290
291         if (!ll_xattr_cache_valid(lli))
292                 RETURN(0);
293
294         while (ll_xattr_cache_del(&lli->lli_xattrs, NULL) == 0)
295                 ; /* empty loop */
296
297         clear_bit(LLIF_XATTR_CACHE_FILLED, &lli->lli_flags);
298         clear_bit(LLIF_XATTR_CACHE, &lli->lli_flags);
299
300         RETURN(0);
301 }
302
303 int ll_xattr_cache_destroy(struct inode *inode)
304 {
305         struct ll_inode_info *lli = ll_i2info(inode);
306         int rc;
307
308         ENTRY;
309
310         down_write(&lli->lli_xattrs_list_rwsem);
311         rc = ll_xattr_cache_destroy_locked(lli);
312         up_write(&lli->lli_xattrs_list_rwsem);
313
314         RETURN(rc);
315 }
316
317 /*
318  * ll_xattr_cache_empty - empty xattr cache for @ino
319  *
320  * Similar to ll_xattr_cache_destroy(), but preserves encryption context.
321  * So only LLIF_XATTR_CACHE_FILLED flag is cleared, but not LLIF_XATTR_CACHE.
322  */
323 int ll_xattr_cache_empty(struct inode *inode)
324 {
325         struct ll_inode_info *lli = ll_i2info(inode);
326         struct ll_xattr_entry *entry, *n;
327
328         ENTRY;
329
330         down_write(&lli->lli_xattrs_list_rwsem);
331         if (!ll_xattr_cache_valid(lli) ||
332             !ll_xattr_cache_filled(lli))
333                 GOTO(out_empty, 0);
334
335         list_for_each_entry_safe(entry, n, &lli->lli_xattrs, xe_list) {
336                 if (strcmp(entry->xe_name, xattr_for_enc(inode)) == 0)
337                         continue;
338
339                 CDEBUG(D_CACHE, "delete: %s\n", entry->xe_name);
340                 list_del(&entry->xe_list);
341                 OBD_FREE(entry->xe_name, entry->xe_namelen);
342                 OBD_FREE(entry->xe_value, entry->xe_vallen);
343                 OBD_SLAB_FREE_PTR(entry, xattr_kmem);
344         }
345         clear_bit(LLIF_XATTR_CACHE_FILLED, &lli->lli_flags);
346
347 out_empty:
348         up_write(&lli->lli_xattrs_list_rwsem);
349         RETURN(0);
350 }
351
352 /**
353  * Match or enqueue a PR lock.
354  *
355  * Find or request an LDLM lock with xattr data.
356  * Since LDLM does not provide API for atomic match_or_enqueue,
357  * the function handles it with a separate enq lock.
358  * If successful, the function exits with a write lock held
359  * on lli_xattrs_list_rwsem.
360  *
361  * \retval 0       no error occured
362  * \retval -ENOMEM not enough memory
363  */
364 static int ll_xattr_find_get_lock(struct inode *inode,
365                                   struct lookup_intent *oit,
366                                   struct ptlrpc_request **req)
367 {
368         enum ldlm_mode mode;
369         struct lustre_handle lockh = { 0 };
370         struct md_op_data *op_data;
371         struct ll_inode_info *lli = ll_i2info(inode);
372         struct ll_sb_info *sbi = ll_i2sbi(inode);
373         struct obd_export *exp = sbi->ll_md_exp;
374         int rc;
375
376         ENTRY;
377
378         mutex_lock(&lli->lli_xattrs_enq_lock);
379         /* inode may have been shrunk and recreated, so data is gone, match lock
380          * only when data exists.
381          */
382         if (ll_xattr_cache_filled(lli)) {
383                 /* Try matching first. */
384                 mode = ll_take_md_lock(inode, MDS_INODELOCK_XATTR, &lockh, 0,
385                                         LCK_PR);
386                 if (mode != 0) {
387                         /* fake oit in mdc_revalidate_lock() manner */
388                         oit->it_lock_handle = lockh.cookie;
389                         oit->it_lock_mode = mode;
390                         goto out;
391                 }
392         }
393
394         /* Enqueue if the lock isn't cached locally. */
395         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
396                                      LUSTRE_OPC_ANY, NULL);
397         if (IS_ERR(op_data)) {
398                 mutex_unlock(&lli->lli_xattrs_enq_lock);
399                 RETURN(PTR_ERR(op_data));
400         }
401
402         op_data->op_valid = OBD_MD_FLXATTR | OBD_MD_FLXATTRLS;
403
404         rc = md_intent_lock(exp, op_data, oit, req, &ll_md_blocking_ast, 0);
405         ll_finish_md_op_data(op_data);
406         *req = oit->it_request;
407
408         if (rc < 0) {
409                 CDEBUG(D_CACHE,
410                        "md_intent_lock failed with %d for fid "DFID"\n", rc,
411                        PFID(ll_inode2fid(inode)));
412                 mutex_unlock(&lli->lli_xattrs_enq_lock);
413                 RETURN(rc);
414         }
415
416 out:
417         down_write(&lli->lli_xattrs_list_rwsem);
418         mutex_unlock(&lli->lli_xattrs_enq_lock);
419
420         RETURN(0);
421 }
422
423 /**
424  * Refill the xattr cache.
425  *
426  * Fetch and cache the whole of xattrs for @inode, thanks to the write lock
427  * on lli_xattrs_list_rwsem obtained from ll_xattr_find_get_lock().
428  * If successful, this write lock is kept.
429  *
430  * \retval 0       no error occured
431  * \retval -EPROTO network protocol error
432  * \retval -ENOMEM not enough memory for the cache
433  */
434 static int ll_xattr_cache_refill(struct inode *inode)
435 {
436         struct lookup_intent oit = { .it_op = IT_GETXATTR };
437         struct ll_sb_info *sbi = ll_i2sbi(inode);
438         struct ptlrpc_request *req = NULL;
439         const char *xdata, *xval, *xtail, *xvtail;
440         struct ll_inode_info *lli = ll_i2info(inode);
441         struct mdt_body *body;
442         __u32 *xsizes;
443         int rc = 0, i;
444
445         ENTRY;
446
447         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_XATTR_PAUSE, cfs_fail_val ?: 2);
448
449         rc = ll_xattr_find_get_lock(inode, &oit, &req);
450         if (rc)
451                 GOTO(err_req, rc);
452
453         /* Do we have the data at this point? */
454         if (ll_xattr_cache_filled(lli)) {
455                 ll_stats_ops_tally(sbi, LPROC_LL_GETXATTR_HITS, 1);
456                 ll_intent_drop_lock(&oit);
457                 GOTO(err_req, rc = 0);
458         }
459
460         /* Matched but no cache? Cancelled on error by a parallel refill. */
461         if (unlikely(req == NULL)) {
462                 CDEBUG(D_CACHE, "cancelled by a parallel getxattr\n");
463                 ll_intent_drop_lock(&oit);
464                 GOTO(err_unlock, rc = -EAGAIN);
465         }
466
467         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
468         if (body == NULL) {
469                 CERROR("no MDT BODY in the refill xattr reply\n");
470                 GOTO(err_cancel, rc = -EPROTO);
471         }
472         /* do not need swab xattr data */
473         xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
474                                                 body->mbo_eadatasize);
475         xval = req_capsule_server_sized_get(&req->rq_pill, &RMF_EAVALS,
476                                                 body->mbo_aclsize);
477         xsizes = req_capsule_server_sized_get(&req->rq_pill, &RMF_EAVALS_LENS,
478                                               body->mbo_max_mdsize *
479                                               sizeof(__u32));
480         if (xdata == NULL || xval == NULL || xsizes == NULL) {
481                 CERROR("wrong setxattr reply\n");
482                 GOTO(err_cancel, rc = -EPROTO);
483         }
484
485         xtail = xdata + body->mbo_eadatasize;
486         xvtail = xval + body->mbo_aclsize;
487
488         CDEBUG(D_CACHE, "caching: xdata=%p xtail=%p\n", xdata, xtail);
489
490         if (!ll_xattr_cache_valid(lli))
491                 ll_xattr_cache_init(lli);
492
493         for (i = 0; i < body->mbo_max_mdsize; i++) {
494                 CDEBUG(D_CACHE, "caching [%s]=%.*s\n", xdata, *xsizes, xval);
495                 /* Perform consistency checks: attr names and vals in pill */
496                 if (memchr(xdata, 0, xtail - xdata) == NULL) {
497                         CERROR("xattr protocol violation (names are broken)\n");
498                         rc = -EPROTO;
499                 } else if (xval + *xsizes > xvtail) {
500                         CERROR("xattr protocol violation (vals are broken)\n");
501                         rc = -EPROTO;
502                 } else if (CFS_FAIL_CHECK(OBD_FAIL_LLITE_XATTR_ENOMEM)) {
503                         rc = -ENOMEM;
504                 } else if (!strcmp(xdata, XATTR_NAME_ACL_ACCESS)) {
505                         /* Filter out ACL ACCESS since it's cached separately */
506                         CDEBUG(D_CACHE, "not caching %s\n",
507                                XATTR_NAME_ACL_ACCESS);
508                         rc = 0;
509                 } else if (ll_xattr_is_seclabel(xdata)) {
510                         /* Filter out security label, it is cached in slab */
511                         CDEBUG(D_CACHE, "not caching %s\n", xdata);
512                         rc = 0;
513                 } else if (!strcmp(xdata, XATTR_NAME_SOM)) {
514                         /* Filter out trusted.som, it is not cached on client */
515                         CDEBUG(D_CACHE, "not caching trusted.som\n");
516                         rc = 0;
517                 } else {
518                         rc = ll_xattr_cache_add(&lli->lli_xattrs, xdata, xval,
519                                                 *xsizes);
520                 }
521                 if (rc < 0) {
522                         ll_xattr_cache_destroy_locked(lli);
523                         GOTO(err_cancel, rc);
524                 }
525                 xdata += strlen(xdata) + 1;
526                 xval  += *xsizes;
527                 xsizes++;
528         }
529
530         if (xdata != xtail || xval != xvtail)
531                 CERROR("a hole in xattr data\n");
532         else
533                 set_bit(LLIF_XATTR_CACHE_FILLED, &lli->lli_flags);
534
535         ll_set_lock_data(sbi->ll_md_exp, inode, &oit, NULL);
536         ll_intent_drop_lock(&oit);
537
538         ptlrpc_req_finished(req);
539         RETURN(0);
540
541 err_cancel:
542         ldlm_lock_decref_and_cancel((struct lustre_handle *)
543                                     &oit.it_lock_handle,
544                                     oit.it_lock_mode);
545 err_unlock:
546         up_write(&lli->lli_xattrs_list_rwsem);
547 err_req:
548         if (rc == -ERANGE)
549                 rc = -EAGAIN;
550
551         ptlrpc_req_finished(req);
552         RETURN(rc);
553 }
554
555 /**
556  * Get an xattr value or list xattrs using the write-through cache.
557  *
558  * Get the xattr value (@valid has OBD_MD_FLXATTR set) of @name or
559  * list xattr names (@valid has OBD_MD_FLXATTRLS set) for @inode.
560  * The resulting value/list is stored in @buffer if the former
561  * is not larger than @size.
562  *
563  * \retval 0        no error occured
564  * \retval -EPROTO  network protocol error
565  * \retval -ENOMEM  not enough memory for the cache
566  * \retval -ERANGE  the buffer is not large enough
567  * \retval -ENODATA no such attr or the list is empty
568  */
569 int ll_xattr_cache_get(struct inode *inode,
570                         const char *name,
571                         char *buffer,
572                         size_t size,
573                         __u64 valid)
574 {
575         struct ll_inode_info *lli = ll_i2info(inode);
576         int rc = 0;
577
578         ENTRY;
579
580         LASSERT(!!(valid & OBD_MD_FLXATTR) ^ !!(valid & OBD_MD_FLXATTRLS));
581
582         down_read(&lli->lli_xattrs_list_rwsem);
583         /* For performance reasons, we do not want to refill complete xattr
584          * cache if we are just interested in encryption context.
585          */
586         if ((valid & OBD_MD_FLXATTRLS ||
587              strcmp(name, xattr_for_enc(inode)) != 0) &&
588             !ll_xattr_cache_filled(lli)) {
589                 up_read(&lli->lli_xattrs_list_rwsem);
590                 rc = ll_xattr_cache_refill(inode);
591                 if (rc)
592                         RETURN(rc);
593                 /* Turn the write lock obtained in ll_xattr_cache_refill()
594                  * into a read lock.
595                  */
596                 downgrade_write(&lli->lli_xattrs_list_rwsem);
597         } else {
598                 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR_HITS, 1);
599         }
600
601         if (!ll_xattr_cache_valid(lli))
602                 GOTO(out, rc = -ENODATA);
603
604         if (valid & OBD_MD_FLXATTR) {
605                 struct ll_xattr_entry *xattr;
606
607                 rc = ll_xattr_cache_find(&lli->lli_xattrs, name, &xattr);
608                 if (rc == 0) {
609                         rc = xattr->xe_vallen;
610                         /* zero size means we are only requested size in rc */
611                         if (size != 0) {
612                                 if (size >= xattr->xe_vallen)
613                                         memcpy(buffer, xattr->xe_value,
614                                                 xattr->xe_vallen);
615                                 else
616                                         rc = -ERANGE;
617                         }
618                 /* Return the project id when the virtual project id xattr
619                  * is explicitly asked.
620                  */
621                 } else if (strcmp(name, XATTR_NAME_PROJID) == 0) {
622                         /* 10 chars to hold u32 in decimal, plus ending \0 */
623                         char projid[11];
624
625                         rc = snprintf(projid, sizeof(projid),
626                                       "%u", lli->lli_projid);
627                         if (size != 0) {
628                                 if (rc <= size)
629                                         memcpy(buffer, projid, rc);
630                                 else
631                                         rc = -ERANGE;
632                         }
633                 }
634         } else if (valid & OBD_MD_FLXATTRLS) {
635                 rc = ll_xattr_cache_list(&lli->lli_xattrs,
636                                          size ? buffer : NULL, size);
637         }
638
639         GOTO(out, rc);
640 out:
641         up_read(&lli->lli_xattrs_list_rwsem);
642
643         RETURN(rc);
644 }
645
646 /**
647  * Insert an xattr value into the cache.
648  *
649  * Add @name xattr with @buffer value and @size length for @inode.
650  * Init cache for @inode if necessary.
651  *
652  * \retval 0       success
653  * \retval < 0     from ll_xattr_cache_add(), except -EPROTO is ignored for
654  *                 LL_XATTR_NAME_ENCRYPTION_CONTEXT xattr
655  */
656 int ll_xattr_cache_insert(struct inode *inode,
657                           const char *name,
658                           char *buffer,
659                           size_t size)
660 {
661         struct ll_inode_info *lli = ll_i2info(inode);
662         int rc;
663
664         ENTRY;
665
666         down_write(&lli->lli_xattrs_list_rwsem);
667         if (!ll_xattr_cache_valid(lli))
668                 ll_xattr_cache_init(lli);
669         rc = ll_xattr_cache_add(&lli->lli_xattrs, name, buffer, size);
670         up_write(&lli->lli_xattrs_list_rwsem);
671         RETURN(rc);
672 }