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