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