Whamcloud - gitweb
95c2fe289721acb5f7e72218b302f4729b507daa
[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, 2013, 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 static
106 int ll_setxattr_common(struct inode *inode, const char *name,
107                        const void *value, size_t size,
108                        int flags, __u64 valid)
109 {
110         struct ll_sb_info *sbi = ll_i2sbi(inode);
111         struct ptlrpc_request *req = NULL;
112         int xattr_type, rc;
113         struct obd_capa *oc;
114         posix_acl_xattr_header *new_value = NULL;
115         struct rmtacl_ctl_entry *rce = NULL;
116         ext_acl_xattr_header *acl = NULL;
117         const char *pv = value;
118         ENTRY;
119
120         xattr_type = get_xattr_type(name);
121         rc = xattr_type_filter(sbi, xattr_type);
122         if (rc)
123                 RETURN(rc);
124
125         if ((xattr_type == XATTR_ACL_ACCESS_T ||
126              xattr_type == XATTR_ACL_DEFAULT_T) &&
127 #ifdef HAVE_INODE_OWNER_OR_CAPABLE
128             !inode_owner_or_capable(inode))
129 #else
130             !is_owner_or_cap(inode))
131 #endif
132                 return -EPERM;
133
134         /* b10667: ignore lustre special xattr for now */
135         if ((xattr_type == XATTR_TRUSTED_T && strcmp(name, "trusted.lov") == 0) ||
136             (xattr_type == XATTR_LUSTRE_T && strcmp(name, "lustre.lov") == 0))
137                 RETURN(0);
138
139         /* b15587: ignore security.capability xattr for now */
140         if ((xattr_type == XATTR_SECURITY_T &&
141             strcmp(name, "security.capability") == 0))
142                 RETURN(0);
143
144         /* LU-549:  Disable security.selinux when selinux is disabled */
145         if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() &&
146             strcmp(name, "security.selinux") == 0)
147                 RETURN(-EOPNOTSUPP);
148
149 #ifdef CONFIG_FS_POSIX_ACL
150         if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
151             (xattr_type == XATTR_ACL_ACCESS_T ||
152             xattr_type == XATTR_ACL_DEFAULT_T)) {
153                 rce = rct_search(&sbi->ll_rct, current_pid());
154                 if (rce == NULL ||
155                     (rce->rce_ops != RMT_LSETFACL &&
156                     rce->rce_ops != RMT_RSETFACL))
157                         RETURN(-EOPNOTSUPP);
158
159                 if (rce->rce_ops == RMT_LSETFACL) {
160                         struct eacl_entry *ee;
161
162                         ee = et_search_del(&sbi->ll_et, current_pid(),
163                                            ll_inode2fid(inode), xattr_type);
164                         LASSERT(ee != NULL);
165                         if (valid & OBD_MD_FLXATTR) {
166                                 acl = lustre_acl_xattr_merge2ext(
167                                                 (posix_acl_xattr_header *)value,
168                                                 size, ee->ee_acl);
169                                 if (IS_ERR(acl)) {
170                                         ee_free(ee);
171                                         RETURN(PTR_ERR(acl));
172                                 }
173                                 size =  CFS_ACL_XATTR_SIZE(\
174                                                 le32_to_cpu(acl->a_count), \
175                                                 ext_acl_xattr);
176                                 pv = (const char *)acl;
177                         }
178                         ee_free(ee);
179                 } else if (rce->rce_ops == RMT_RSETFACL) {
180                         int acl_size = lustre_posix_acl_xattr_filter(
181                                                 (posix_acl_xattr_header *)value,
182                                                 size, &new_value);
183                         if (unlikely(acl_size < 0))
184                                 RETURN(acl_size);
185                         size = acl_size;
186
187                         pv = (const char *)new_value;
188                 } else
189                         RETURN(-EOPNOTSUPP);
190
191                 valid |= rce_ops2valid(rce->rce_ops);
192         }
193 #endif
194         oc = ll_mdscapa_get(inode);
195         rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
196                         valid, name, pv, size, 0, flags,
197                         ll_i2suppgid(inode), &req);
198         capa_put(oc);
199 #ifdef CONFIG_FS_POSIX_ACL
200         if (new_value != NULL)
201                 lustre_posix_acl_xattr_free(new_value, size);
202         if (acl != NULL)
203                 lustre_ext_acl_xattr_free(acl);
204 #endif
205         if (rc) {
206                 if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) {
207                         LCONSOLE_INFO("Disabling user_xattr feature because "
208                                       "it is not supported on the server\n");
209                         sbi->ll_flags &= ~LL_SBI_USER_XATTR;
210                 }
211                 RETURN(rc);
212         }
213
214         ptlrpc_req_finished(req);
215         RETURN(0);
216 }
217
218 int ll_setxattr(struct dentry *dentry, const char *name,
219                 const void *value, size_t size, int flags)
220 {
221         struct inode *inode = dentry->d_inode;
222
223         LASSERT(inode);
224         LASSERT(name);
225
226         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
227                PFID(ll_inode2fid(inode)), inode, name);
228
229         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1);
230
231         if ((strncmp(name, XATTR_TRUSTED_PREFIX,
232                      sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0 &&
233              strcmp(name + sizeof(XATTR_TRUSTED_PREFIX) - 1, "lov") == 0) ||
234             (strncmp(name, XATTR_LUSTRE_PREFIX,
235                      sizeof(XATTR_LUSTRE_PREFIX) - 1) == 0 &&
236              strcmp(name + sizeof(XATTR_LUSTRE_PREFIX) - 1, "lov") == 0)) {
237                 struct lov_user_md *lump = (struct lov_user_md *)value;
238                 int                 rc = 0;
239
240                 /* Attributes that are saved via getxattr will always have
241                  * the stripe_offset as 0.  Instead, the MDS should be
242                  * allowed to pick the starting OST index.   b=17846 */
243                 if (lump != NULL && lump->lmm_stripe_offset == 0)
244                         lump->lmm_stripe_offset = -1;
245
246                 if (lump != NULL && S_ISREG(inode->i_mode)) {
247                         struct file     f;
248                         __u64           it_flags = FMODE_WRITE;
249                         int             lum_size;
250
251                         lum_size = ll_lov_user_md_size(lump);
252                         if (lum_size < 0 || size < lum_size)
253                                 return 0; /* b=10667: ignore error */
254
255                         memset(&f, 0, sizeof(f)); /* f.f_flags is used below */
256                         f.f_dentry = dentry;
257                         rc = ll_lov_setstripe_ea_info(inode, &f, it_flags, lump,
258                                                       lum_size);
259                         /* b=10667: rc always be 0 here for now */
260                         rc = 0;
261                 } else if (S_ISDIR(inode->i_mode)) {
262                         rc = ll_dir_setstripe(inode, lump, 0);
263                 }
264
265                 return rc;
266
267         } else if (strcmp(name, XATTR_NAME_LMA) == 0 ||
268                    strcmp(name, XATTR_NAME_LINK) == 0)
269                 return 0;
270
271         return ll_setxattr_common(inode, name, value, size, flags,
272                                   OBD_MD_FLXATTR);
273 }
274
275 int ll_removexattr(struct dentry *dentry, const char *name)
276 {
277         struct inode *inode = dentry->d_inode;
278
279         LASSERT(inode);
280         LASSERT(name);
281
282         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
283                PFID(ll_inode2fid(inode)), inode, name);
284
285         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
286         return ll_setxattr_common(inode, name, NULL, 0, 0,
287                                   OBD_MD_FLXATTRRM);
288 }
289
290 static
291 int ll_getxattr_common(struct inode *inode, const char *name,
292                        void *buffer, size_t size, __u64 valid)
293 {
294         struct ll_sb_info *sbi = ll_i2sbi(inode);
295         struct ptlrpc_request *req = NULL;
296         struct mdt_body *body;
297         int xattr_type, rc;
298         void *xdata;
299         struct obd_capa *oc;
300         struct rmtacl_ctl_entry *rce = NULL;
301         struct ll_inode_info *lli = ll_i2info(inode);
302         ENTRY;
303
304         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
305                PFID(ll_inode2fid(inode)), inode);
306
307         /* listxattr have slightly different behavior from of ext3:
308          * without 'user_xattr' ext3 will list all xattr names but
309          * filtered out "^user..*"; we list them all for simplicity.
310          */
311         if (!name) {
312                 xattr_type = XATTR_OTHER_T;
313                 goto do_getxattr;
314         }
315
316         xattr_type = get_xattr_type(name);
317         rc = xattr_type_filter(sbi, xattr_type);
318         if (rc)
319                 RETURN(rc);
320
321         /* b15587: ignore security.capability xattr for now */
322         if ((xattr_type == XATTR_SECURITY_T &&
323             strcmp(name, "security.capability") == 0))
324                 RETURN(-ENODATA);
325
326         /* LU-549:  Disable security.selinux when selinux is disabled */
327         if (xattr_type == XATTR_SECURITY_T && !selinux_is_enabled() &&
328             strcmp(name, "security.selinux") == 0)
329                 RETURN(-EOPNOTSUPP);
330
331 #ifdef CONFIG_FS_POSIX_ACL
332         if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
333             (xattr_type == XATTR_ACL_ACCESS_T ||
334             xattr_type == XATTR_ACL_DEFAULT_T)) {
335                 rce = rct_search(&sbi->ll_rct, current_pid());
336                 if (rce == NULL ||
337                     (rce->rce_ops != RMT_LSETFACL &&
338                     rce->rce_ops != RMT_LGETFACL &&
339                     rce->rce_ops != RMT_RSETFACL &&
340                     rce->rce_ops != RMT_RGETFACL))
341                         RETURN(-EOPNOTSUPP);
342         }
343
344         /* posix acl is under protection of LOOKUP lock. when calling to this,
345          * we just have path resolution to the target inode, so we have great
346          * chance that cached ACL is uptodate.
347          */
348         if (xattr_type == XATTR_ACL_ACCESS_T &&
349             !(sbi->ll_flags & LL_SBI_RMT_CLIENT)) {
350
351                 struct posix_acl *acl;
352
353                 spin_lock(&lli->lli_lock);
354                 acl = posix_acl_dup(lli->lli_posix_acl);
355                 spin_unlock(&lli->lli_lock);
356
357                 if (!acl)
358                         RETURN(-ENODATA);
359
360                 rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
361                 posix_acl_release(acl);
362                 RETURN(rc);
363         }
364         if (xattr_type == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode))
365                 RETURN(-ENODATA);
366 #endif
367
368 do_getxattr:
369         if (sbi->ll_xattr_cache_enabled && xattr_type != XATTR_ACL_ACCESS_T) {
370                 rc = ll_xattr_cache_get(inode, name, buffer, size, valid);
371                 if (rc == -EAGAIN)
372                         goto getxattr_nocache;
373                 if (rc < 0)
374                         GOTO(out_xattr, rc);
375
376                 /* Add "system.posix_acl_access" to the list */
377                 if (lli->lli_posix_acl != NULL && valid & OBD_MD_FLXATTRLS) {
378                         if (size == 0) {
379                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
380                         } else if (size - rc >= sizeof(XATTR_NAME_ACL_ACCESS)) {
381                                 memcpy(buffer + rc, XATTR_NAME_ACL_ACCESS,
382                                        sizeof(XATTR_NAME_ACL_ACCESS));
383                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
384                         } else {
385                                 GOTO(out_xattr, rc = -ERANGE);
386                         }
387                 }
388         } else {
389 getxattr_nocache:
390                 oc = ll_mdscapa_get(inode);
391                 rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
392                                 valid | (rce ? rce_ops2valid(rce->rce_ops) : 0),
393                                 name, NULL, 0, size, 0, &req);
394                 capa_put(oc);
395
396                 if (rc < 0)
397                         GOTO(out_xattr, rc);
398
399                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
400                 LASSERT(body);
401
402                 /* only detect the xattr size */
403                 if (size == 0)
404                         GOTO(out, rc = body->mbo_eadatasize);
405
406                 if (size < body->mbo_eadatasize) {
407                         CERROR("server bug: replied size %u > %u\n",
408                                 body->mbo_eadatasize, (int)size);
409                         GOTO(out, rc = -ERANGE);
410                 }
411
412                 if (body->mbo_eadatasize == 0)
413                         GOTO(out, rc = -ENODATA);
414
415                 /* do not need swab xattr data */
416                 xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
417                                                         body->mbo_eadatasize);
418                 if (!xdata)
419                         GOTO(out, rc = -EFAULT);
420
421                 memcpy(buffer, xdata, body->mbo_eadatasize);
422                 rc = body->mbo_eadatasize;
423         }
424
425 #ifdef CONFIG_FS_POSIX_ACL
426         if (rce != NULL && rce->rce_ops == RMT_LSETFACL) {
427                 ext_acl_xattr_header *acl;
428
429                 acl = lustre_posix_acl_xattr_2ext(buffer, rc);
430                 if (IS_ERR(acl))
431                         GOTO(out, rc = PTR_ERR(acl));
432
433                 rc = ee_add(&sbi->ll_et, current_pid(), ll_inode2fid(inode),
434                             xattr_type, acl);
435                 if (unlikely(rc < 0)) {
436                         lustre_ext_acl_xattr_free(acl);
437                         GOTO(out, rc);
438                 }
439         }
440 #endif
441         EXIT;
442
443 out_xattr:
444         if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) {
445                 LCONSOLE_INFO("%s: disabling user_xattr feature because "
446                                 "it is not supported on the server: rc = %d\n",
447                                 ll_get_fsname(inode->i_sb, NULL, 0), rc);
448                 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
449         }
450 out:
451         ptlrpc_req_finished(req);
452         return rc;
453 }
454
455 ssize_t ll_getxattr(struct dentry *dentry, const char *name,
456                     void *buffer, size_t size)
457 {
458         struct inode *inode = dentry->d_inode;
459
460         LASSERT(inode);
461         LASSERT(name);
462
463         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
464                PFID(ll_inode2fid(inode)), inode, name);
465
466         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
467
468         if ((strncmp(name, XATTR_TRUSTED_PREFIX,
469                      sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0 &&
470              strcmp(name + sizeof(XATTR_TRUSTED_PREFIX) - 1, "lov") == 0) ||
471             (strncmp(name, XATTR_LUSTRE_PREFIX,
472                      sizeof(XATTR_LUSTRE_PREFIX) - 1) == 0 &&
473              strcmp(name + sizeof(XATTR_LUSTRE_PREFIX) - 1, "lov") == 0)) {
474                 struct lov_stripe_md *lsm;
475                 struct lov_user_md *lump;
476                 struct lov_mds_md *lmm = NULL;
477                 struct ptlrpc_request *request = NULL;
478                 int rc = 0, lmmsize = 0;
479
480                 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
481                         return -ENODATA;
482
483                 lsm = ccc_inode_lsm_get(inode);
484                 if (lsm == NULL) {
485                         if (S_ISDIR(inode->i_mode)) {
486                                 rc = ll_dir_getstripe(inode, (void **)&lmm,
487                                                       &lmmsize, &request, 0);
488                         } else {
489                                 rc = -ENODATA;
490                         }
491                 } else {
492                         /* LSM is present already after lookup/getattr call.
493                          * we need to grab layout lock once it is implemented */
494                         rc = obd_packmd(ll_i2dtexp(inode), &lmm, lsm);
495                         lmmsize = rc;
496                 }
497                 ccc_inode_lsm_put(inode, lsm);
498
499                 if (rc < 0)
500                        GOTO(out, rc);
501
502                 if (size == 0) {
503                         /* used to call ll_get_max_mdsize() forward to get
504                          * the maximum buffer size, while some apps (such as
505                          * rsync 3.0.x) care much about the exact xattr value
506                          * size */
507                         rc = lmmsize;
508                         GOTO(out, rc);
509                 }
510
511                 if (size < lmmsize) {
512                         CERROR("server bug: replied size %d > %d for %s (%s)\n",
513                                lmmsize, (int)size, dentry->d_name.name, name);
514                         GOTO(out, rc = -ERANGE);
515                 }
516
517                 lump = (struct lov_user_md *)buffer;
518                 memcpy(lump, lmm, lmmsize);
519                 /* do not return layout gen for getxattr otherwise it would
520                  * confuse tar --xattr by recognizing layout gen as stripe
521                  * offset when the file is restored. See LU-2809. */
522                 lump->lmm_layout_gen = 0;
523
524                 rc = lmmsize;
525 out:
526                 if (request)
527                         ptlrpc_req_finished(request);
528                 else if (lmm)
529                         obd_free_diskmd(ll_i2dtexp(inode), &lmm);
530                 return(rc);
531         }
532
533         return ll_getxattr_common(inode, name, buffer, size, OBD_MD_FLXATTR);
534 }
535
536 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)
537 {
538         struct inode *inode = dentry->d_inode;
539         int rc = 0, rc2 = 0;
540         struct lov_mds_md *lmm = NULL;
541         struct ptlrpc_request *request = NULL;
542         int lmmsize;
543
544         LASSERT(inode);
545
546         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
547                PFID(ll_inode2fid(inode)), inode);
548
549         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_LISTXATTR, 1);
550
551         rc = ll_getxattr_common(inode, NULL, buffer, size, OBD_MD_FLXATTRLS);
552         if (rc < 0)
553                 GOTO(out, rc);
554
555         if (buffer != NULL) {
556                 struct ll_sb_info *sbi = ll_i2sbi(inode);
557                 char *xattr_name = buffer;
558                 int xlen, rem = rc;
559
560                 while (rem > 0) {
561                         xlen = strnlen(xattr_name, rem - 1) + 1;
562                         rem -= xlen;
563                         if (xattr_type_filter(sbi,
564                                         get_xattr_type(xattr_name)) == 0) {
565                                 /* skip OK xattr type
566                                  * leave it in buffer
567                                  */
568                                 xattr_name += xlen;
569                                 continue;
570                         }
571                         /* move up remaining xattrs in buffer
572                          * removing the xattr that is not OK
573                          */
574                         memmove(xattr_name, xattr_name + xlen, rem);
575                         rc -= xlen;
576                 }
577         }
578         if (S_ISREG(inode->i_mode)) {
579                 if (!ll_i2info(inode)->lli_has_smd)
580                         rc2 = -1;
581         } else if (S_ISDIR(inode->i_mode)) {
582                 rc2 = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
583                                        0);
584         }
585
586         if (rc2 < 0) {
587                 GOTO(out, rc2 = 0);
588         } else if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)) {
589                 const int prefix_len = sizeof(XATTR_LUSTRE_PREFIX) - 1;
590                 const size_t name_len   = sizeof("lov") - 1;
591                 const size_t total_len  = prefix_len + name_len + 1;
592
593                 if (((rc + total_len) > size) && (buffer != NULL)) {
594                         ptlrpc_req_finished(request);
595                         return -ERANGE;
596                 }
597
598                 if (buffer != NULL) {
599                         buffer += rc;
600                         memcpy(buffer, XATTR_LUSTRE_PREFIX, prefix_len);
601                         memcpy(buffer + prefix_len, "lov", name_len);
602                         buffer[prefix_len + name_len] = '\0';
603                 }
604                 rc2 = total_len;
605         }
606 out:
607         ptlrpc_req_finished(request);
608         rc = rc + rc2;
609
610         return rc;
611 }