Whamcloud - gitweb
LU-6214 llite: tar restore fails for HSM released files.
[fs/lustre-release.git] / lustre / llite / xattr.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #include <linux/fs.h>
38 #include <linux/sched.h>
39 #include <linux/mm.h>
40 #include <linux/selinux.h>
41
42 #define DEBUG_SUBSYSTEM S_LLITE
43
44 #include <obd_support.h>
45 #include <lustre_dlm.h>
46 #include <lustre_ver.h>
47 #include <lustre_eacl.h>
48
49 #include "llite_internal.h"
50
51 #define XATTR_USER_T            (1)
52 #define XATTR_TRUSTED_T         (2)
53 #define XATTR_SECURITY_T        (3)
54 #define XATTR_ACL_ACCESS_T      (4)
55 #define XATTR_ACL_DEFAULT_T     (5)
56 #define XATTR_LUSTRE_T          (6)
57 #define XATTR_OTHER_T           (7)
58
59 static
60 int get_xattr_type(const char *name)
61 {
62         if (!strcmp(name, POSIX_ACL_XATTR_ACCESS))
63                 return XATTR_ACL_ACCESS_T;
64
65         if (!strcmp(name, POSIX_ACL_XATTR_DEFAULT))
66                 return XATTR_ACL_DEFAULT_T;
67
68         if (!strncmp(name, XATTR_USER_PREFIX,
69                      sizeof(XATTR_USER_PREFIX) - 1))
70                 return XATTR_USER_T;
71
72         if (!strncmp(name, XATTR_TRUSTED_PREFIX,
73                      sizeof(XATTR_TRUSTED_PREFIX) - 1))
74                 return XATTR_TRUSTED_T;
75
76         if (!strncmp(name, XATTR_SECURITY_PREFIX,
77                      sizeof(XATTR_SECURITY_PREFIX) - 1))
78                 return XATTR_SECURITY_T;
79
80         if (!strncmp(name, XATTR_LUSTRE_PREFIX,
81                      sizeof(XATTR_LUSTRE_PREFIX) - 1))
82                 return XATTR_LUSTRE_T;
83
84         return XATTR_OTHER_T;
85 }
86
87 static
88 int xattr_type_filter(struct ll_sb_info *sbi, int xattr_type)
89 {
90         if ((xattr_type == XATTR_ACL_ACCESS_T ||
91              xattr_type == XATTR_ACL_DEFAULT_T) &&
92            !(sbi->ll_flags & LL_SBI_ACL))
93                 return -EOPNOTSUPP;
94
95         if (xattr_type == XATTR_USER_T && !(sbi->ll_flags & LL_SBI_USER_XATTR))
96                 return -EOPNOTSUPP;
97         if (xattr_type == XATTR_TRUSTED_T && !cfs_capable(CFS_CAP_SYS_ADMIN))
98                 return -EPERM;
99         if (xattr_type == XATTR_OTHER_T)
100                 return -EOPNOTSUPP;
101
102         return 0;
103 }
104
105 /* xattr related to IMA(Integrity Measurement Architecture) */
106 #ifndef XATTR_NAME_IMA
107 #define XATTR_NAME_IMA          "security.ima"
108 #define XATTR_NAME_EVM          "security.evm"
109 #endif
110
111 static
112 int ll_setxattr_common(struct inode *inode, const char *name,
113                        const void *value, size_t size,
114                        int flags, __u64 valid)
115 {
116         struct ll_sb_info *sbi = ll_i2sbi(inode);
117         struct ptlrpc_request *req = NULL;
118         int xattr_type, rc;
119         posix_acl_xattr_header *new_value = NULL;
120         struct rmtacl_ctl_entry *rce = NULL;
121         ext_acl_xattr_header *acl = NULL;
122         const char *pv = value;
123         ENTRY;
124
125         /*FIXME: enable IMA when the conditions are ready */
126         if (strncmp(name, XATTR_NAME_IMA,
127                     sizeof(XATTR_NAME_IMA)) == 0 ||
128             strncmp(name, XATTR_NAME_EVM,
129                     sizeof(XATTR_NAME_EVM)) == 0)
130                 return -EOPNOTSUPP;
131
132         xattr_type = get_xattr_type(name);
133         rc = xattr_type_filter(sbi, xattr_type);
134         if (rc)
135                 RETURN(rc);
136
137         if ((xattr_type == XATTR_ACL_ACCESS_T ||
138              xattr_type == XATTR_ACL_DEFAULT_T) &&
139 #ifdef HAVE_INODE_OWNER_OR_CAPABLE
140             !inode_owner_or_capable(inode))
141 #else
142             !is_owner_or_cap(inode))
143 #endif
144                 return -EPERM;
145
146         /* b10667: ignore lustre special xattr for now */
147         if (strcmp(name, XATTR_NAME_HSM) == 0 ||
148                 (xattr_type == XATTR_TRUSTED_T &&
149                 strcmp(name, XATTR_NAME_LOV) == 0) ||
150                 (xattr_type == XATTR_LUSTRE_T &&
151                  strcmp(name, "lustre.lov") == 0))
152                 RETURN(0);
153
154         /* b15587: ignore security.capability xattr for now */
155         if ((xattr_type == XATTR_SECURITY_T &&
156             strcmp(name, "security.capability") == 0))
157                 RETURN(0);
158
159         /* LU-549:  Disable security.selinux when selinux is disabled */
160         if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() &&
161             strcmp(name, "security.selinux") == 0)
162                 RETURN(-EOPNOTSUPP);
163
164 #ifdef CONFIG_FS_POSIX_ACL
165         if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
166             (xattr_type == XATTR_ACL_ACCESS_T ||
167             xattr_type == XATTR_ACL_DEFAULT_T)) {
168                 rce = rct_search(&sbi->ll_rct, current_pid());
169                 if (rce == NULL ||
170                     (rce->rce_ops != RMT_LSETFACL &&
171                     rce->rce_ops != RMT_RSETFACL))
172                         RETURN(-EOPNOTSUPP);
173
174                 if (rce->rce_ops == RMT_LSETFACL) {
175                         struct eacl_entry *ee;
176
177                         ee = et_search_del(&sbi->ll_et, current_pid(),
178                                            ll_inode2fid(inode), xattr_type);
179                         LASSERT(ee != NULL);
180                         if (valid & OBD_MD_FLXATTR) {
181                                 acl = lustre_acl_xattr_merge2ext(
182                                                 (posix_acl_xattr_header *)value,
183                                                 size, ee->ee_acl);
184                                 if (IS_ERR(acl)) {
185                                         ee_free(ee);
186                                         RETURN(PTR_ERR(acl));
187                                 }
188                                 size =  CFS_ACL_XATTR_SIZE(\
189                                                 le32_to_cpu(acl->a_count), \
190                                                 ext_acl_xattr);
191                                 pv = (const char *)acl;
192                         }
193                         ee_free(ee);
194                 } else if (rce->rce_ops == RMT_RSETFACL) {
195                         int acl_size = lustre_posix_acl_xattr_filter(
196                                                 (posix_acl_xattr_header *)value,
197                                                 size, &new_value);
198                         if (unlikely(acl_size < 0))
199                                 RETURN(acl_size);
200                         size = acl_size;
201
202                         pv = (const char *)new_value;
203                 } else
204                         RETURN(-EOPNOTSUPP);
205
206                 valid |= rce_ops2valid(rce->rce_ops);
207         }
208 #endif
209         rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid, name, pv,
210                          size, 0, flags, ll_i2suppgid(inode), &req);
211
212 #ifdef CONFIG_FS_POSIX_ACL
213         if (new_value != NULL)
214                 lustre_posix_acl_xattr_free(new_value, size);
215         if (acl != NULL)
216                 lustre_ext_acl_xattr_free(acl);
217 #endif
218         if (rc) {
219                 if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) {
220                         LCONSOLE_INFO("Disabling user_xattr feature because "
221                                       "it is not supported on the server\n");
222                         sbi->ll_flags &= ~LL_SBI_USER_XATTR;
223                 }
224                 RETURN(rc);
225         }
226
227         ptlrpc_req_finished(req);
228         RETURN(0);
229 }
230
231 static int get_hsm_state(struct inode *inode, __u32 *hus_states)
232 {
233         struct md_op_data *op_data;
234         struct hsm_user_state *hus;
235         int rc;
236
237         OBD_ALLOC_PTR(hus);
238         if (hus == NULL)
239                 return -ENOMEM;
240
241         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
242                                      LUSTRE_OPC_ANY, hus);
243         if (!IS_ERR(op_data)) {
244                 rc = obd_iocontrol(LL_IOC_HSM_STATE_GET, ll_i2mdexp(inode),
245                                    sizeof(*op_data), op_data, NULL);
246                 if (rc == 0)
247                         *hus_states = hus->hus_states;
248                 else
249                         CDEBUG(D_VFSTRACE, "obd_iocontrol failed. rc = %d\n",
250                                rc);
251
252                 ll_finish_md_op_data(op_data);
253         } else {
254                 rc = PTR_ERR(op_data);
255                 CDEBUG(D_VFSTRACE, "Could not prepare the opdata. rc = %d\n",
256                        rc);
257         }
258         OBD_FREE_PTR(hus);
259         return rc;
260 }
261
262 int ll_setxattr(struct dentry *dentry, const char *name,
263                 const void *value, size_t size, int flags)
264 {
265         struct inode *inode = dentry->d_inode;
266
267         LASSERT(inode);
268         LASSERT(name);
269
270         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
271                PFID(ll_inode2fid(inode)), inode, name);
272
273         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1);
274
275         if ((strncmp(name, XATTR_TRUSTED_PREFIX,
276                      sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0 &&
277              strcmp(name + sizeof(XATTR_TRUSTED_PREFIX) - 1, "lov") == 0) ||
278             (strncmp(name, XATTR_LUSTRE_PREFIX,
279                      sizeof(XATTR_LUSTRE_PREFIX) - 1) == 0 &&
280              strcmp(name + sizeof(XATTR_LUSTRE_PREFIX) - 1, "lov") == 0)) {
281                 struct lov_user_md *lump = (struct lov_user_md *)value;
282                 int rc = 0;
283
284                 /* Attributes that are saved via getxattr will always have
285                  * the stripe_offset as 0.  Instead, the MDS should be
286                  * allowed to pick the starting OST index.   b=17846 */
287                 if (lump != NULL && lump->lmm_stripe_offset == 0)
288                         lump->lmm_stripe_offset = -1;
289                 /* Avoid anyone directly setting the RELEASED flag. */
290                 if (lump != NULL &&
291                         (lump->lmm_pattern & LOV_PATTERN_F_RELEASED)) {
292                         /* Only if we have a released flag check if the file
293                         * was indeed archived. */
294                         __u32 state = HS_NONE;
295                         rc = get_hsm_state(inode, &state);
296                         if (rc != 0)
297                                 RETURN(rc);
298                         if (!(state & HS_ARCHIVED)) {
299                                 CDEBUG(D_VFSTRACE,
300                                         "hus_states state = %x, pattern = %x\n",
301                                         state, lump->lmm_pattern);
302                                 /* Here the state is: real file is not
303                                  * archived but user is requesting to set
304                                  * the RELEASED flag so we mask off the
305                                  * released flag from the request */
306                                 lump->lmm_pattern ^= LOV_PATTERN_F_RELEASED;
307                         }
308                 }
309
310                 if (lump != NULL && S_ISREG(inode->i_mode)) {
311                         struct file     f;
312                         __u64           it_flags = FMODE_WRITE;
313                         int             lum_size;
314
315                         lum_size = ll_lov_user_md_size(lump);
316                         if (lum_size < 0 || size < lum_size)
317                                 return 0; /* b=10667: ignore error */
318
319                         memset(&f, 0, sizeof(f)); /* f.f_flags is used below */
320                         f.f_path.dentry = dentry;
321                         rc = ll_lov_setstripe_ea_info(inode, &f, it_flags, lump,
322                                                       lum_size);
323                         /* b=10667: rc always be 0 here for now */
324                         rc = 0;
325                 } else if (S_ISDIR(inode->i_mode)) {
326                         rc = ll_dir_setstripe(inode, lump, 0);
327                 }
328
329                 return rc;
330
331         } else if (strcmp(name, XATTR_NAME_LMA) == 0 ||
332                    strcmp(name, XATTR_NAME_LINK) == 0)
333                 return 0;
334
335         return ll_setxattr_common(inode, name, value, size, flags,
336                                   OBD_MD_FLXATTR);
337 }
338
339 int ll_removexattr(struct dentry *dentry, const char *name)
340 {
341         struct inode *inode = dentry->d_inode;
342
343         LASSERT(inode);
344         LASSERT(name);
345
346         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
347                PFID(ll_inode2fid(inode)), inode, name);
348
349         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
350         return ll_setxattr_common(inode, name, NULL, 0, 0,
351                                   OBD_MD_FLXATTRRM);
352 }
353
354 int ll_getxattr_common(struct inode *inode, const char *name,
355                        void *buffer, size_t size, __u64 valid)
356 {
357         struct ll_sb_info *sbi = ll_i2sbi(inode);
358         struct ptlrpc_request *req = NULL;
359         struct mdt_body *body;
360         int xattr_type, rc;
361         void *xdata;
362         struct rmtacl_ctl_entry *rce = NULL;
363         struct ll_inode_info *lli = ll_i2info(inode);
364         ENTRY;
365
366         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
367                PFID(ll_inode2fid(inode)), inode);
368
369         /* listxattr have slightly different behavior from of ext3:
370          * without 'user_xattr' ext3 will list all xattr names but
371          * filtered out "^user..*"; we list them all for simplicity.
372          */
373         if (!name) {
374                 xattr_type = XATTR_OTHER_T;
375                 goto do_getxattr;
376         }
377
378         xattr_type = get_xattr_type(name);
379         rc = xattr_type_filter(sbi, xattr_type);
380         if (rc)
381                 RETURN(rc);
382
383         /* b15587: ignore security.capability xattr for now */
384         if ((xattr_type == XATTR_SECURITY_T &&
385             strcmp(name, "security.capability") == 0))
386                 RETURN(-ENODATA);
387
388         /* LU-549:  Disable security.selinux when selinux is disabled */
389         if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() &&
390             strcmp(name, "security.selinux") == 0)
391                 RETURN(-EOPNOTSUPP);
392
393 #ifdef CONFIG_FS_POSIX_ACL
394         if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
395             (xattr_type == XATTR_ACL_ACCESS_T ||
396             xattr_type == XATTR_ACL_DEFAULT_T)) {
397                 rce = rct_search(&sbi->ll_rct, current_pid());
398                 if (rce == NULL ||
399                     (rce->rce_ops != RMT_LSETFACL &&
400                     rce->rce_ops != RMT_LGETFACL &&
401                     rce->rce_ops != RMT_RSETFACL &&
402                     rce->rce_ops != RMT_RGETFACL))
403                         RETURN(-EOPNOTSUPP);
404         }
405
406         /* posix acl is under protection of LOOKUP lock. when calling to this,
407          * we just have path resolution to the target inode, so we have great
408          * chance that cached ACL is uptodate.
409          */
410         if (xattr_type == XATTR_ACL_ACCESS_T &&
411             !(sbi->ll_flags & LL_SBI_RMT_CLIENT)) {
412
413                 struct posix_acl *acl;
414
415                 spin_lock(&lli->lli_lock);
416                 acl = posix_acl_dup(lli->lli_posix_acl);
417                 spin_unlock(&lli->lli_lock);
418
419                 if (!acl)
420                         RETURN(-ENODATA);
421
422                 rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
423                 posix_acl_release(acl);
424                 RETURN(rc);
425         }
426         if (xattr_type == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode))
427                 RETURN(-ENODATA);
428 #endif
429
430 do_getxattr:
431         if (sbi->ll_xattr_cache_enabled &&
432             xattr_type != XATTR_ACL_ACCESS_T &&
433             (xattr_type != XATTR_SECURITY_T ||
434                 strcmp(name, "security.selinux") != 0)) {
435                 rc = ll_xattr_cache_get(inode, name, buffer, size, valid);
436                 if (rc == -EAGAIN)
437                         goto getxattr_nocache;
438                 if (rc < 0)
439                         GOTO(out_xattr, rc);
440
441                 /* Add "system.posix_acl_access" to the list */
442                 if (lli->lli_posix_acl != NULL && valid & OBD_MD_FLXATTRLS) {
443                         if (size == 0) {
444                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
445                         } else if (size - rc >= sizeof(XATTR_NAME_ACL_ACCESS)) {
446                                 memcpy(buffer + rc, XATTR_NAME_ACL_ACCESS,
447                                        sizeof(XATTR_NAME_ACL_ACCESS));
448                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
449                         } else {
450                                 GOTO(out_xattr, rc = -ERANGE);
451                         }
452                 }
453         } else {
454 getxattr_nocache:
455                 rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
456                                 valid | (rce ? rce_ops2valid(rce->rce_ops) : 0),
457                                 name, NULL, 0, size, 0, &req);
458
459                 if (rc < 0)
460                         GOTO(out_xattr, rc);
461
462                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
463                 LASSERT(body);
464
465                 /* only detect the xattr size */
466                 if (size == 0)
467                         GOTO(out, rc = body->mbo_eadatasize);
468
469                 if (size < body->mbo_eadatasize) {
470                         CERROR("server bug: replied size %u > %u\n",
471                                 body->mbo_eadatasize, (int)size);
472                         GOTO(out, rc = -ERANGE);
473                 }
474
475                 if (body->mbo_eadatasize == 0)
476                         GOTO(out, rc = -ENODATA);
477
478                 /* do not need swab xattr data */
479                 xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
480                                                         body->mbo_eadatasize);
481                 if (!xdata)
482                         GOTO(out, rc = -EFAULT);
483
484                 memcpy(buffer, xdata, body->mbo_eadatasize);
485                 rc = body->mbo_eadatasize;
486         }
487
488 #ifdef CONFIG_FS_POSIX_ACL
489         if (rce != NULL && rce->rce_ops == RMT_LSETFACL) {
490                 ext_acl_xattr_header *acl;
491
492                 acl = lustre_posix_acl_xattr_2ext(buffer, rc);
493                 if (IS_ERR(acl))
494                         GOTO(out, rc = PTR_ERR(acl));
495
496                 rc = ee_add(&sbi->ll_et, current_pid(), ll_inode2fid(inode),
497                             xattr_type, acl);
498                 if (unlikely(rc < 0)) {
499                         lustre_ext_acl_xattr_free(acl);
500                         GOTO(out, rc);
501                 }
502         }
503 #endif
504         EXIT;
505
506 out_xattr:
507         if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) {
508                 LCONSOLE_INFO("%s: disabling user_xattr feature because "
509                                 "it is not supported on the server: rc = %d\n",
510                                 ll_get_fsname(inode->i_sb, NULL, 0), rc);
511                 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
512         }
513 out:
514         ptlrpc_req_finished(req);
515         return rc;
516 }
517
518 static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
519 {
520         ssize_t rc;
521
522         if (S_ISREG(inode->i_mode)) {
523                 struct cl_object *obj = ll_i2info(inode)->lli_clob;
524                 struct lu_env *env;
525                 struct cl_layout cl = {
526                         .cl_buf.lb_buf = buf,
527                         .cl_buf.lb_len = buf_size,
528                 };
529                 int refcheck;
530
531                 if (obj == NULL)
532                         RETURN(-ENODATA);
533
534                 env = cl_env_get(&refcheck);
535                 if (IS_ERR(env))
536                         RETURN(PTR_ERR(env));
537
538                 rc = cl_object_layout_get(env, obj, &cl);
539                 if (rc < 0)
540                         GOTO(out_env, rc);
541
542                 if (cl.cl_size == 0)
543                         GOTO(out_env, rc = -ENODATA);
544
545                 rc = cl.cl_size;
546
547                 if (buf_size == 0)
548                         GOTO(out_env, rc);
549
550                 LASSERT(buf != NULL && rc <= buf_size);
551
552                 /* Do not return layout gen for getxattr() since
553                  * otherwise it would confuse tar --xattr by
554                  * recognizing layout gen as stripe offset when the
555                  * file is restored. See LU-2809. */
556                 ((struct lov_mds_md *)buf)->lmm_layout_gen = 0;
557 out_env:
558                 cl_env_put(env, &refcheck);
559
560                 RETURN(rc);
561         } else if (S_ISDIR(inode->i_mode)) {
562                 struct lov_mds_md *lmm = NULL;
563                 int lmm_size = 0;
564                 struct ptlrpc_request *req = NULL;
565
566                 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmm_size,
567                                       &req, 0);
568                 if (rc < 0)
569                         GOTO(out_req, rc);
570
571                 if (buf_size == 0)
572                         GOTO(out_req, rc = lmm_size);
573
574                 if (buf_size < lmm_size)
575                         GOTO(out_req, rc = -ERANGE);
576
577                 memcpy(buf, lmm, lmm_size);
578                 GOTO(out_req, rc = lmm_size);
579 out_req:
580                 if (req != NULL)
581                         ptlrpc_req_finished(req);
582
583                 return rc;
584         } else {
585                 RETURN(-ENODATA);
586         }
587 }
588
589 ssize_t ll_getxattr(struct dentry *dentry, const char *name, void *buf,
590                     size_t buf_size)
591 {
592         struct inode *inode = dentry->d_inode;
593
594         LASSERT(inode);
595         LASSERT(name);
596
597         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
598                PFID(ll_inode2fid(inode)), inode, name);
599
600         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
601
602         if (strcmp(name, XATTR_LUSTRE_LOV) == 0 ||
603             strcmp(name, XATTR_NAME_LOV) == 0)
604                 return ll_getxattr_lov(inode, buf, buf_size);
605         else
606                 return ll_getxattr_common(inode, name, buf, buf_size,
607                                           OBD_MD_FLXATTR);
608 }
609
610 ssize_t ll_listxattr(struct dentry *dentry, char *buf, size_t buf_size)
611 {
612         struct inode *inode = dentry->d_inode;
613         struct ll_sb_info *sbi = ll_i2sbi(inode);
614         char *xattr_name;
615         ssize_t rc, rc2;
616         size_t len, rem;
617
618         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
619                PFID(ll_inode2fid(inode)), inode);
620
621         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_LISTXATTR, 1);
622
623         rc = ll_getxattr_common(inode, NULL, buf, buf_size, OBD_MD_FLXATTRLS);
624         if (rc < 0)
625                 RETURN(rc);
626
627         /* If we're being called to get the size of the xattr list
628          * (buf_size == 0) then just assume that a lustre.lov xattr
629          * exists. */
630         if (buf_size == 0)
631                 RETURN(rc + sizeof(XATTR_LUSTRE_LOV));
632
633         xattr_name = buf;
634         rem = rc;
635
636         while (rem > 0) {
637                 len = strnlen(xattr_name, rem - 1) + 1;
638                 rem -= len;
639                 if (xattr_type_filter(sbi, get_xattr_type(xattr_name)) == 0) {
640                         /* Skip OK xattr type, leave it in buffer. */
641                         xattr_name += len;
642                         continue;
643                 }
644
645                 /* Move up remaining xattrs in buffer removing the
646                  * xattr that is not OK. */
647                 memmove(xattr_name, xattr_name + len, rem);
648                 rc -= len;
649         }
650
651         rc2 = ll_getxattr_lov(inode, NULL, 0);
652         if (rc2 == -ENODATA)
653                 RETURN(rc);
654
655         if (rc2 < 0)
656                 RETURN(rc2);
657
658         if (buf_size < rc + sizeof(XATTR_LUSTRE_LOV))
659                 RETURN(-ERANGE);
660
661         memcpy(buf + rc, XATTR_LUSTRE_LOV, sizeof(XATTR_LUSTRE_LOV));
662
663         RETURN(rc + sizeof(XATTR_LUSTRE_LOV));
664 }