Whamcloud - gitweb
LU-6401 uapi: migrate remaining uapi headers to uapi directory
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #include <linux/fs.h>
34 #include <linux/sched.h>
35 #include <linux/mm.h>
36 #include <linux/xattr.h>
37 #include <linux/selinux.h>
38
39 #define DEBUG_SUBSYSTEM S_LLITE
40
41 #include <obd_support.h>
42 #include <lustre_dlm.h>
43 #include <lustre_eacl.h>
44
45 #include "llite_internal.h"
46
47 const struct xattr_handler *get_xattr_type(const char *name)
48 {
49         int i = 0;
50
51         while (ll_xattr_handlers[i]) {
52                 size_t len = strlen(ll_xattr_handlers[i]->prefix);
53
54                 if (!strncmp(ll_xattr_handlers[i]->prefix, name, len))
55                         return ll_xattr_handlers[i];
56                 i++;
57         }
58         return NULL;
59 }
60
61 static int xattr_type_filter(struct ll_sb_info *sbi,
62                              const struct xattr_handler *handler)
63 {
64         /* No handler means XATTR_OTHER_T */
65         if (!handler)
66                 return -EOPNOTSUPP;
67
68         if ((handler->flags == XATTR_ACL_ACCESS_T ||
69              handler->flags == XATTR_ACL_DEFAULT_T) &&
70             !(sbi->ll_flags & LL_SBI_ACL))
71                 return -EOPNOTSUPP;
72
73         if (handler->flags == XATTR_USER_T &&
74             !(sbi->ll_flags & LL_SBI_USER_XATTR))
75                 return -EOPNOTSUPP;
76
77         if (handler->flags == XATTR_TRUSTED_T &&
78             !capable(CFS_CAP_SYS_ADMIN))
79                 return -EPERM;
80
81         return 0;
82 }
83
84 static int ll_xattr_set_common(const struct xattr_handler *handler,
85                                struct dentry *dentry, struct inode *inode,
86                                const char *name, const void *value, size_t size,
87                                int flags)
88 {
89         struct ll_sb_info *sbi = ll_i2sbi(inode);
90         struct ptlrpc_request *req = NULL;
91         const char *pv = value;
92         char *fullname;
93         u64 valid;
94         int rc;
95         ENTRY;
96
97         if (flags == XATTR_REPLACE) {
98                 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
99                 valid = OBD_MD_FLXATTRRM;
100         } else {
101                 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1);
102                 valid = OBD_MD_FLXATTR;
103         }
104
105         /* FIXME: enable IMA when the conditions are ready */
106         if (handler->flags == XATTR_SECURITY_T &&
107             (!strcmp(name, "ima") || !strcmp(name, "evm")))
108                 RETURN(-EOPNOTSUPP);
109
110         rc = xattr_type_filter(sbi, handler);
111         if (rc)
112                 RETURN(rc);
113
114         if ((handler->flags == XATTR_ACL_ACCESS_T ||
115              handler->flags == XATTR_ACL_DEFAULT_T) &&
116 #ifdef HAVE_INODE_OWNER_OR_CAPABLE
117             !inode_owner_or_capable(inode))
118 #else
119             !is_owner_or_cap(inode))
120 #endif
121                 RETURN(-EPERM);
122
123         /* b10667: ignore lustre special xattr for now */
124         if (!strcmp(name, "hsm") ||
125             ((handler->flags == XATTR_TRUSTED_T && !strcmp(name, "lov")) ||
126              (handler->flags == XATTR_LUSTRE_T && !strcmp(name, "lov"))))
127                 RETURN(0);
128
129         /* LU-549:  Disable security.selinux when selinux is disabled */
130         if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() &&
131             strcmp(name, "selinux") == 0)
132                 RETURN(-EOPNOTSUPP);
133
134         /*
135          * In user.* namespace, only regular files and directories can have
136          * extended attributes.
137          */
138         if (handler->flags == XATTR_USER_T) {
139                 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
140                         RETURN(-EPERM);
141         }
142
143         fullname = kasprintf(GFP_KERNEL, "%s%s", handler->prefix, name);
144         if (!fullname)
145                 RETURN(-ENOMEM);
146
147         rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid, fullname,
148                          pv, size, 0, flags, ll_i2suppgid(inode), &req);
149         kfree(fullname);
150         if (rc) {
151                 if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) {
152                         LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
153                         sbi->ll_flags &= ~LL_SBI_USER_XATTR;
154                 }
155                 RETURN(rc);
156         }
157
158         ptlrpc_req_finished(req);
159         RETURN(0);
160 }
161
162 static int get_hsm_state(struct inode *inode, u32 *hus_states)
163 {
164         struct md_op_data *op_data;
165         struct hsm_user_state *hus;
166         int rc;
167
168         OBD_ALLOC_PTR(hus);
169         if (!hus)
170                 return -ENOMEM;
171
172         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
173                                      LUSTRE_OPC_ANY, hus);
174         if (!IS_ERR(op_data)) {
175                 rc = obd_iocontrol(LL_IOC_HSM_STATE_GET, ll_i2mdexp(inode),
176                                    sizeof(*op_data), op_data, NULL);
177                 if (!rc)
178                         *hus_states = hus->hus_states;
179                 else
180                         CDEBUG(D_VFSTRACE, "obd_iocontrol failed. rc = %d\n",
181                                rc);
182
183                 ll_finish_md_op_data(op_data);
184         } else {
185                 rc = PTR_ERR(op_data);
186                 CDEBUG(D_VFSTRACE, "Could not prepare the opdata. rc = %d\n",
187                        rc);
188         }
189         OBD_FREE_PTR(hus);
190         return rc;
191 }
192
193 static int ll_adjust_lum(struct inode *inode, struct lov_user_md *lump)
194 {
195         struct lov_comp_md_v1 *comp_v1 = (struct lov_comp_md_v1 *)lump;
196         struct lov_user_md *v1 = lump;
197         bool need_clear_release = false;
198         bool release_checked = false;
199         bool is_composite = false;
200         u16 entry_count = 1;
201         int rc = 0;
202         int i;
203
204         if (!lump)
205                 return 0;
206
207         if (lump->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
208                 entry_count = comp_v1->lcm_entry_count;
209                 is_composite = true;
210         }
211
212         for (i = 0; i < entry_count; i++) {
213                 if (lump->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
214                         void *ptr = comp_v1;
215
216                         ptr += comp_v1->lcm_entries[i].lcme_offset;
217                         v1 = (struct lov_user_md *)ptr;
218                 }
219
220                 /*
221                  * Attributes that are saved via getxattr will always
222                  * have the stripe_offset as 0. Instead, the MDS
223                  * should be allowed to pick the starting OST index.
224                  * b=17846
225                  */
226                 if (!is_composite && v1->lmm_stripe_offset == 0)
227                         v1->lmm_stripe_offset = -1;
228
229                 /* Avoid anyone directly setting the RELEASED flag. */
230                 if (v1->lmm_pattern & LOV_PATTERN_F_RELEASED) {
231                         if (!release_checked) {
232                                 u32 state = HS_NONE;
233
234                                 rc = get_hsm_state(inode, &state);
235                                 if (rc)
236                                         return rc;
237
238                                 if (!(state & HS_ARCHIVED))
239                                         need_clear_release = true;
240                                 release_checked = true;
241                         }
242                         if (need_clear_release)
243                                 v1->lmm_pattern ^= LOV_PATTERN_F_RELEASED;
244                 }
245         }
246
247         return rc;
248 }
249
250 static int ll_setstripe_ea(struct dentry *dentry, struct lov_user_md *lump,
251                            size_t size)
252 {
253         struct inode *inode = dentry->d_inode;
254         int rc = 0;
255
256         /*
257          * It is possible to set an xattr to a "" value of zero size.
258          * For this case we are going to treat it as a removal.
259          */
260         if (!size && lump)
261                 lump = NULL;
262
263         rc = ll_adjust_lum(inode, lump);
264         if (rc)
265                 return rc;
266
267         if (lump && S_ISREG(inode->i_mode)) {
268                 u64 it_flags = FMODE_WRITE;
269                 ssize_t lum_size;
270
271                 lum_size = ll_lov_user_md_size(lump);
272                 if (lum_size < 0 || size < lum_size)
273                         return -ERANGE;
274
275                 rc = ll_lov_setstripe_ea_info(inode, dentry, it_flags, lump,
276                                               lum_size);
277                 /**
278                  * b=10667: ignore -EEXIST.
279                  * Silently eat error on setting trusted.lov/lustre.lov
280                  * attribute for platforms that added the default option
281                  * to copy all attributes in 'cp' command. Both rsync and
282                  * tar --xattrs also will try to set LOVEA for existing
283                  * files.
284                  */
285                 if (rc == -EEXIST)
286                         rc = 0;
287         } else if (S_ISDIR(inode->i_mode)) {
288                 if (size != 0 && size < sizeof(struct lov_user_md))
289                         return -EINVAL;
290
291                 rc = ll_dir_setstripe(inode, lump, 0);
292         }
293
294         return rc;
295 }
296
297 static int ll_xattr_set(const struct xattr_handler *handler,
298                         struct dentry *dentry, struct inode *inode,
299                         const char *name, const void *value, size_t size,
300                         int flags)
301 {
302         LASSERT(inode);
303         LASSERT(name);
304
305         CDEBUG(D_VFSTRACE, "VFS Op:inode=" DFID "(%p), xattr %s\n",
306                PFID(ll_inode2fid(inode)), inode, name);
307
308         /* lustre/trusted.lov.xxx would be passed through xattr API */
309         if (!strcmp(name, "lov")) {
310                 int op_type = flags == XATTR_REPLACE ? LPROC_LL_REMOVEXATTR :
311                                                        LPROC_LL_SETXATTR;
312
313                 ll_stats_ops_tally(ll_i2sbi(inode), op_type, 1);
314
315                 return ll_setstripe_ea(dentry, (struct lov_user_md *)value,
316                                        size);
317         } else if (!strcmp(name, "lma") || !strcmp(name, "link")) {
318                 int op_type = flags == XATTR_REPLACE ? LPROC_LL_REMOVEXATTR :
319                                                        LPROC_LL_SETXATTR;
320
321                 ll_stats_ops_tally(ll_i2sbi(inode), op_type, 1);
322                 return 0;
323         }
324
325         return ll_xattr_set_common(handler, dentry, inode, name, value, size,
326                                    flags);
327 }
328
329 int ll_xattr_list(struct inode *inode, const char *name, int type, void *buffer,
330                   size_t size, u64 valid)
331 {
332         struct ll_inode_info *lli = ll_i2info(inode);
333         struct ll_sb_info *sbi = ll_i2sbi(inode);
334         struct ptlrpc_request *req = NULL;
335         struct mdt_body *body;
336         void *xdata;
337         int rc;
338         ENTRY;
339
340         if (sbi->ll_xattr_cache_enabled && type != XATTR_ACL_ACCESS_T &&
341             (type != XATTR_SECURITY_T || strcmp(name, "security.selinux"))) {
342                 rc = ll_xattr_cache_get(inode, name, buffer, size, valid);
343                 if (rc == -EAGAIN)
344                         goto getxattr_nocache;
345                 if (rc < 0)
346                         GOTO(out_xattr, rc);
347
348                 /* Add "system.posix_acl_access" to the list */
349                 if (lli->lli_posix_acl && valid & OBD_MD_FLXATTRLS) {
350                         if (size == 0) {
351                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
352                         } else if (size - rc >= sizeof(XATTR_NAME_ACL_ACCESS)) {
353                                 memcpy(buffer + rc, XATTR_NAME_ACL_ACCESS,
354                                        sizeof(XATTR_NAME_ACL_ACCESS));
355                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
356                         } else {
357                                 GOTO(out_xattr, rc = -ERANGE);
358                         }
359                 }
360         } else {
361 getxattr_nocache:
362                 rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
363                                  valid, name, NULL, 0, size, 0, &req);
364                 if (rc < 0)
365                         GOTO(out_xattr, rc);
366
367                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
368                 LASSERT(body);
369
370                 /* only detect the xattr size */
371                 if (size == 0)
372                         GOTO(out, rc = body->mbo_eadatasize);
373
374                 if (size < body->mbo_eadatasize) {
375                         CERROR("server bug: replied size %u > %u\n",
376                                 body->mbo_eadatasize, (int)size);
377                         GOTO(out, rc = -ERANGE);
378                 }
379
380                 if (body->mbo_eadatasize == 0)
381                         GOTO(out, rc = -ENODATA);
382
383                 /* do not need swab xattr data */
384                 xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
385                                                         body->mbo_eadatasize);
386                 if (!xdata)
387                         GOTO(out, rc = -EFAULT);
388
389                 memcpy(buffer, xdata, body->mbo_eadatasize);
390                 rc = body->mbo_eadatasize;
391         }
392
393         EXIT;
394
395 out_xattr:
396         if (rc == -EOPNOTSUPP && type == XATTR_USER_T) {
397                 LCONSOLE_INFO("%s: disabling user_xattr feature because "
398                                 "it is not supported on the server: rc = %d\n",
399                                 ll_get_fsname(inode->i_sb, NULL, 0), rc);
400                 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
401         }
402 out:
403         ptlrpc_req_finished(req);
404         return rc;
405 }
406
407 static int ll_xattr_get_common(const struct xattr_handler *handler,
408                                struct dentry *dentry,
409                                struct inode *inode,
410                                const char *name, void *buffer, size_t size)
411 {
412         struct ll_sb_info *sbi = ll_i2sbi(inode);
413         char *fullname;
414         int rc;
415
416         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
417
418         rc = xattr_type_filter(sbi, handler);
419         if (rc)
420                 RETURN(rc);
421
422         /* LU-549:  Disable security.selinux when selinux is disabled */
423         if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() &&
424             !strcmp(name, "selinux"))
425                 RETURN(-EOPNOTSUPP);
426
427 #ifdef CONFIG_FS_POSIX_ACL
428         /* posix acl is under protection of LOOKUP lock. when calling to this,
429          * we just have path resolution to the target inode, so we have great
430          * chance that cached ACL is uptodate.
431          */
432         if (handler->flags == XATTR_ACL_ACCESS_T) {
433                 struct ll_inode_info *lli = ll_i2info(inode);
434                 struct posix_acl *acl;
435
436                 spin_lock(&lli->lli_lock);
437                 acl = posix_acl_dup(lli->lli_posix_acl);
438                 spin_unlock(&lli->lli_lock);
439
440                 if (!acl)
441                         RETURN(-ENODATA);
442
443                 rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
444                 posix_acl_release(acl);
445                 RETURN(rc);
446         }
447         if (handler->flags == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode))
448                 RETURN(-ENODATA);
449 #endif
450
451         fullname = kasprintf(GFP_KERNEL, "%s%s", handler->prefix, name);
452         if (!fullname)
453                 RETURN(-ENOMEM);
454
455         rc = ll_xattr_list(inode, fullname, handler->flags, buffer, size,
456                            OBD_MD_FLXATTR);
457         kfree(fullname);
458         return rc;
459 }
460
461 static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
462 {
463         ssize_t rc;
464
465         if (S_ISREG(inode->i_mode)) {
466                 struct cl_object *obj = ll_i2info(inode)->lli_clob;
467                 struct cl_layout cl = {
468                         .cl_buf.lb_buf = buf,
469                         .cl_buf.lb_len = buf_size,
470                 };
471                 struct lu_env *env;
472                 u16 refcheck;
473
474                 if (!obj)
475                         RETURN(-ENODATA);
476
477                 env = cl_env_get(&refcheck);
478                 if (IS_ERR(env))
479                         RETURN(PTR_ERR(env));
480
481                 rc = cl_object_layout_get(env, obj, &cl);
482                 if (rc < 0)
483                         GOTO(out_env, rc);
484
485                 if (!cl.cl_size)
486                         GOTO(out_env, rc = -ENODATA);
487
488                 rc = cl.cl_size;
489
490                 if (!buf_size)
491                         GOTO(out_env, rc);
492
493                 LASSERT(buf && rc <= buf_size);
494
495                 /*
496                  * Do not return layout gen for getxattr() since
497                  * otherwise it would confuse tar --xattr by
498                  * recognizing layout gen as stripe offset when the
499                  * file is restored. See LU-2809.
500                  */
501                 if (((struct lov_mds_md *)buf)->lmm_magic == LOV_MAGIC_COMP_V1)
502                         goto out_env;
503
504                 ((struct lov_mds_md *)buf)->lmm_layout_gen = 0;
505 out_env:
506                 cl_env_put(env, &refcheck);
507
508                 RETURN(rc);
509         } else if (S_ISDIR(inode->i_mode)) {
510                 struct ptlrpc_request *req = NULL;
511                 struct lov_mds_md *lmm = NULL;
512                 int lmm_size = 0;
513
514                 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmm_size,
515                                       &req, 0);
516                 if (rc < 0)
517                         GOTO(out_req, rc);
518
519                 if (!buf_size)
520                         GOTO(out_req, rc = lmm_size);
521
522                 if (buf_size < lmm_size)
523                         GOTO(out_req, rc = -ERANGE);
524
525                 memcpy(buf, lmm, lmm_size);
526                 GOTO(out_req, rc = lmm_size);
527 out_req:
528                 if (req)
529                         ptlrpc_req_finished(req);
530
531                 return rc;
532         } else {
533                 RETURN(-ENODATA);
534         }
535 }
536
537 static int ll_xattr_get(const struct xattr_handler *handler,
538                         struct dentry *dentry, struct inode *inode,
539                         const char *name, void *buffer, size_t size)
540 {
541         LASSERT(inode);
542         LASSERT(name);
543
544         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
545                PFID(ll_inode2fid(inode)), inode, name);
546
547         if (!strcmp(name, "lov")) {
548                 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
549
550                 return ll_getxattr_lov(inode, buffer, size);
551         }
552
553         return ll_xattr_get_common(handler, dentry, inode, name, buffer, size);
554 }
555
556 ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)
557 {
558         struct inode *inode = dentry->d_inode;
559         struct ll_sb_info *sbi = ll_i2sbi(inode);
560         char *xattr_name;
561         ssize_t rc, rc2;
562         size_t len, rem;
563
564         LASSERT(inode);
565
566         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
567                PFID(ll_inode2fid(inode)), inode);
568
569         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_LISTXATTR, 1);
570
571         rc = ll_xattr_list(inode, NULL, XATTR_OTHER_T, buffer, size,
572                            OBD_MD_FLXATTRLS);
573         if (rc < 0)
574                 RETURN(rc);
575
576         /*
577          * If we're being called to get the size of the xattr list
578          * (size == 0) then just assume that a lustre.lov xattr
579          * exists.
580          */
581         if (!size)
582                 RETURN(rc + sizeof(XATTR_LUSTRE_LOV));
583
584         xattr_name = buffer;
585         rem = rc;
586
587         while (rem > 0) {
588                 len = strnlen(xattr_name, rem - 1) + 1;
589                 rem -= len;
590                 if (!xattr_type_filter(sbi, get_xattr_type(xattr_name))) {
591                         /* Skip OK xattr type, leave it in buffer. */
592                         xattr_name += len;
593                         continue;
594                 }
595
596                 /*
597                  * Move up remaining xattrs in buffer
598                  * removing the xattr that is not OK.
599                  */
600                 memmove(xattr_name, xattr_name + len, rem);
601                 rc -= len;
602         }
603
604         rc2 = ll_getxattr_lov(inode, NULL, 0);
605         if (rc2 == -ENODATA)
606                 RETURN(rc);
607
608         if (rc2 < 0)
609                 RETURN(rc2);
610
611         if (size < rc + sizeof(XATTR_LUSTRE_LOV))
612                 RETURN(-ERANGE);
613
614         memcpy(buffer + rc, XATTR_LUSTRE_LOV, sizeof(XATTR_LUSTRE_LOV));
615
616         RETURN(rc + sizeof(XATTR_LUSTRE_LOV));
617 }
618
619 #ifdef HAVE_XATTR_HANDLER_SIMPLIFIED
620 static int ll_xattr_get_common_4_3(const struct xattr_handler *handler,
621                                    struct dentry *dentry, const char *name,
622                                    void *buffer, size_t size)
623 {
624         return ll_xattr_get_common(handler, dentry, dentry->d_inode, name,
625                                    buffer, size);
626 }
627
628 static int ll_xattr_get_4_3(const struct xattr_handler *handler,
629                             struct dentry *dentry, const char *name,
630                             void *buffer, size_t size)
631 {
632         return ll_xattr_get(handler, dentry, dentry->d_inode, name, buffer,
633                             size);
634 }
635
636 static int ll_xattr_set_common_4_3(const struct xattr_handler *handler,
637                                    struct dentry *dentry, const char *name,
638                                    const void *value, size_t size, int flags)
639 {
640         return ll_xattr_set_common(handler, dentry, dentry->d_inode, name,
641                                    value, size, flags);
642 }
643
644 static int ll_xattr_set_4_3(const struct xattr_handler *handler,
645                             struct dentry *dentry, const char *name,
646                             const void *value, size_t size, int flags)
647 {
648         return ll_xattr_set(handler, dentry, dentry->d_inode, name, value,
649                             size, flags);
650 }
651
652 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
653 const struct xattr_handler *get_xattr_handler(int handler_flag)
654 {
655         int i = 0;
656
657         while (ll_xattr_handlers[i]) {
658                 if (ll_xattr_handlers[i]->flags == handler_flag)
659                         return ll_xattr_handlers[i];
660                 i++;
661         }
662         return NULL;
663 }
664
665 static int ll_xattr_get_common_3_11(struct dentry *dentry, const char *name,
666                                    void *buffer, size_t size, int handler_flags)
667 {
668         const struct xattr_handler *handler = get_xattr_handler(handler_flags);
669
670         if (!handler)
671                 return -ENXIO;
672
673         return ll_xattr_get_common(handler, dentry, dentry->d_inode, name,
674                                    buffer, size);
675 }
676
677 static int ll_xattr_get_3_11(struct dentry *dentry, const char *name,
678                             void *buffer, size_t size, int handler_flags)
679 {
680         const struct xattr_handler *handler = get_xattr_handler(handler_flags);
681
682         if (!handler)
683                 return -ENXIO;
684
685         return ll_xattr_get(handler, dentry, dentry->d_inode, name, buffer,
686                             size);
687 }
688
689 static int ll_xattr_set_common_3_11(struct dentry *dentry, const char *name,
690                                    const void *value, size_t size, int flags,
691                                    int handler_flags)
692 {
693         const struct xattr_handler *handler = get_xattr_handler(handler_flags);
694
695         if (!handler)
696                 return -ENXIO;
697
698         return ll_xattr_set_common(handler, dentry, dentry->d_inode, name,
699                                    value, size, flags);
700 }
701
702 static int ll_xattr_set_3_11(struct dentry *dentry, const char *name,
703                             const void *value, size_t size, int flags,
704                             int handler_flags)
705 {
706         const struct xattr_handler *handler = get_xattr_handler(handler_flags);
707
708         if (!handler)
709                 return -ENXIO;
710
711         return ll_xattr_set(handler, dentry, dentry->d_inode, name, value,
712                             size, flags);
713 }
714 #endif
715
716 static const struct xattr_handler ll_user_xattr_handler = {
717         .prefix = XATTR_USER_PREFIX,
718         .flags = XATTR_USER_T,
719 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
720         .get = ll_xattr_get_common_4_3,
721         .set = ll_xattr_set_common_4_3,
722 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
723         .get = ll_xattr_get_common_3_11,
724         .set = ll_xattr_set_common_3_11,
725 #else
726         .get = ll_xattr_get_common,
727         .set = ll_xattr_set_common,
728 #endif
729 };
730
731 static const struct xattr_handler ll_trusted_xattr_handler = {
732         .prefix = XATTR_TRUSTED_PREFIX,
733         .flags = XATTR_TRUSTED_T,
734 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
735         .get = ll_xattr_get_4_3,
736         .set = ll_xattr_set_4_3,
737 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
738         .get = ll_xattr_get_3_11,
739         .set = ll_xattr_set_3_11,
740 #else
741         .get = ll_xattr_get,
742         .set = ll_xattr_set,
743 #endif
744 };
745
746 static const struct xattr_handler ll_security_xattr_handler = {
747         .prefix = XATTR_SECURITY_PREFIX,
748         .flags = XATTR_SECURITY_T,
749 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
750         .get = ll_xattr_get_common_4_3,
751         .set = ll_xattr_set_common_4_3,
752 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
753         .get = ll_xattr_get_common_3_11,
754         .set = ll_xattr_set_common_3_11,
755 #else
756         .get = ll_xattr_get_common,
757         .set = ll_xattr_set_common,
758 #endif
759 };
760
761 static const struct xattr_handler ll_acl_access_xattr_handler = {
762         .prefix = XATTR_NAME_POSIX_ACL_ACCESS,
763         .flags = XATTR_ACL_ACCESS_T,
764 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
765         .get = ll_xattr_get_common_4_3,
766         .set = ll_xattr_set_common_4_3,
767 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
768         .get = ll_xattr_get_common_3_11,
769         .set = ll_xattr_set_common_3_11,
770 #else
771         .get = ll_xattr_get_common,
772         .set = ll_xattr_set_common,
773 #endif
774 };
775
776 static const struct xattr_handler ll_acl_default_xattr_handler = {
777         .prefix = XATTR_NAME_POSIX_ACL_DEFAULT,
778         .flags = XATTR_ACL_DEFAULT_T,
779 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
780         .get = ll_xattr_get_common_4_3,
781         .set = ll_xattr_set_common_4_3,
782 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
783         .get = ll_xattr_get_common_3_11,
784         .set = ll_xattr_set_common_3_11,
785 #else
786         .get = ll_xattr_get_common,
787         .set = ll_xattr_set_common,
788 #endif
789 };
790
791 static const struct xattr_handler ll_lustre_xattr_handler = {
792         .prefix = XATTR_LUSTRE_PREFIX,
793         .flags = XATTR_LUSTRE_T,
794 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
795         .get = ll_xattr_get_4_3,
796         .set = ll_xattr_set_4_3,
797 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
798         .get = ll_xattr_get_3_11,
799         .set = ll_xattr_set_3_11,
800 #else
801         .get = ll_xattr_get,
802         .set = ll_xattr_set,
803 #endif
804 };
805
806 const struct xattr_handler *ll_xattr_handlers[] = {
807         &ll_user_xattr_handler,
808         &ll_trusted_xattr_handler,
809         &ll_security_xattr_handler,
810 #ifdef CONFIG_FS_POSIX_ACL
811         &ll_acl_access_xattr_handler,
812         &ll_acl_default_xattr_handler,
813 #endif
814         &ll_lustre_xattr_handler,
815         NULL,
816 };