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