Whamcloud - gitweb
LU-10092 llite: Add persistent cache on client
[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             !inode_owner_or_capable(inode))
128                 RETURN(-EPERM);
129
130         /* b10667: ignore lustre special xattr for now */
131         if (!strcmp(name, "hsm") ||
132             ((handler->flags == XATTR_TRUSTED_T && !strcmp(name, "lov")) ||
133              (handler->flags == XATTR_LUSTRE_T && !strcmp(name, "lov"))))
134                 RETURN(0);
135
136         /* LU-549:  Disable security.selinux when selinux is disabled */
137         if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() &&
138             strcmp(name, "selinux") == 0)
139                 RETURN(-EOPNOTSUPP);
140
141         /*
142          * In user.* namespace, only regular files and directories can have
143          * extended attributes.
144          */
145         if (handler->flags == XATTR_USER_T) {
146                 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
147                         RETURN(-EPERM);
148         }
149
150         fullname = kasprintf(GFP_KERNEL, "%s%s", xattr_prefix(handler), name);
151         if (!fullname)
152                 RETURN(-ENOMEM);
153
154         rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid, fullname,
155                          pv, size, flags, ll_i2suppgid(inode), &req);
156         kfree(fullname);
157         if (rc) {
158                 if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) {
159                         LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
160                         sbi->ll_flags &= ~LL_SBI_USER_XATTR;
161                 }
162                 RETURN(rc);
163         }
164
165         ptlrpc_req_finished(req);
166         RETURN(0);
167 }
168
169 static int get_hsm_state(struct inode *inode, u32 *hus_states)
170 {
171         struct md_op_data *op_data;
172         struct hsm_user_state *hus;
173         int rc;
174
175         OBD_ALLOC_PTR(hus);
176         if (!hus)
177                 return -ENOMEM;
178
179         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
180                                      LUSTRE_OPC_ANY, hus);
181         if (!IS_ERR(op_data)) {
182                 rc = obd_iocontrol(LL_IOC_HSM_STATE_GET, ll_i2mdexp(inode),
183                                    sizeof(*op_data), op_data, NULL);
184                 if (!rc)
185                         *hus_states = hus->hus_states;
186                 else
187                         CDEBUG(D_VFSTRACE, "obd_iocontrol failed. rc = %d\n",
188                                rc);
189
190                 ll_finish_md_op_data(op_data);
191         } else {
192                 rc = PTR_ERR(op_data);
193                 CDEBUG(D_VFSTRACE, "Could not prepare the opdata. rc = %d\n",
194                        rc);
195         }
196         OBD_FREE_PTR(hus);
197         return rc;
198 }
199
200 static int ll_adjust_lum(struct inode *inode, struct lov_user_md *lump)
201 {
202         struct lov_comp_md_v1 *comp_v1 = (struct lov_comp_md_v1 *)lump;
203         struct lov_user_md *v1 = lump;
204         bool need_clear_release = false;
205         bool release_checked = false;
206         bool is_composite = false;
207         u16 entry_count = 1;
208         int rc = 0;
209         int i;
210
211         if (!lump)
212                 return 0;
213
214         if (lump->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
215                 entry_count = comp_v1->lcm_entry_count;
216                 is_composite = true;
217         }
218
219         for (i = 0; i < entry_count; i++) {
220                 if (lump->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
221                         void *ptr = comp_v1;
222
223                         ptr += comp_v1->lcm_entries[i].lcme_offset;
224                         v1 = (struct lov_user_md *)ptr;
225                 }
226
227                 /*
228                  * Attributes that are saved via getxattr will always
229                  * have the stripe_offset as 0. Instead, the MDS
230                  * should be allowed to pick the starting OST index.
231                  * b=17846
232                  */
233                 if (!is_composite && v1->lmm_stripe_offset == 0)
234                         v1->lmm_stripe_offset = -1;
235
236                 /* Avoid anyone directly setting the RELEASED flag. */
237                 if (v1->lmm_pattern & LOV_PATTERN_F_RELEASED) {
238                         if (!release_checked) {
239                                 u32 state = HS_NONE;
240
241                                 rc = get_hsm_state(inode, &state);
242                                 if (rc)
243                                         return rc;
244
245                                 if (!(state & HS_ARCHIVED))
246                                         need_clear_release = true;
247                                 release_checked = true;
248                         }
249                         if (need_clear_release)
250                                 v1->lmm_pattern ^= LOV_PATTERN_F_RELEASED;
251                 }
252         }
253
254         return rc;
255 }
256
257 static int ll_setstripe_ea(struct dentry *dentry, struct lov_user_md *lump,
258                            size_t size)
259 {
260         struct inode *inode = dentry->d_inode;
261         int rc = 0;
262
263         /*
264          * It is possible to set an xattr to a "" value of zero size.
265          * For this case we are going to treat it as a removal.
266          */
267         if (!size && lump)
268                 lump = NULL;
269
270         rc = ll_adjust_lum(inode, lump);
271         if (rc)
272                 return rc;
273
274         if (lump && S_ISREG(inode->i_mode)) {
275                 u64 it_flags = FMODE_WRITE;
276                 ssize_t lum_size;
277
278                 lum_size = ll_lov_user_md_size(lump);
279                 if (lum_size < 0 || size < lum_size)
280                         return -ERANGE;
281
282                 rc = ll_lov_setstripe_ea_info(inode, dentry, it_flags, lump,
283                                               lum_size);
284                 /**
285                  * b=10667: ignore -EEXIST.
286                  * Silently eat error on setting trusted.lov/lustre.lov
287                  * attribute for platforms that added the default option
288                  * to copy all attributes in 'cp' command. Both rsync and
289                  * tar --xattrs also will try to set LOVEA for existing
290                  * files.
291                  */
292                 if (rc == -EEXIST)
293                         rc = 0;
294         } else if (S_ISDIR(inode->i_mode)) {
295                 if (size != 0 && size < sizeof(struct lov_user_md))
296                         return -EINVAL;
297
298                 rc = ll_dir_setstripe(inode, lump, 0);
299         }
300
301         return rc;
302 }
303
304 static int ll_xattr_set(const struct xattr_handler *handler,
305                         struct dentry *dentry, struct inode *inode,
306                         const char *name, const void *value, size_t size,
307                         int flags)
308 {
309         LASSERT(inode);
310         LASSERT(name);
311
312         CDEBUG(D_VFSTRACE, "VFS Op:inode=" DFID "(%p), xattr %s\n",
313                PFID(ll_inode2fid(inode)), inode, name);
314
315         /* lustre/trusted.lov.xxx would be passed through xattr API */
316         if (!strcmp(name, "lov")) {
317                 int op_type = flags == XATTR_REPLACE ? LPROC_LL_REMOVEXATTR :
318                                                        LPROC_LL_SETXATTR;
319
320                 ll_stats_ops_tally(ll_i2sbi(inode), op_type, 1);
321
322                 return ll_setstripe_ea(dentry, (struct lov_user_md *)value,
323                                        size);
324         } else if (!strcmp(name, "lma") || !strcmp(name, "link")) {
325                 int op_type = flags == XATTR_REPLACE ? LPROC_LL_REMOVEXATTR :
326                                                        LPROC_LL_SETXATTR;
327
328                 ll_stats_ops_tally(ll_i2sbi(inode), op_type, 1);
329                 return 0;
330         }
331
332         return ll_xattr_set_common(handler, dentry, inode, name, value, size,
333                                    flags);
334 }
335
336 int ll_xattr_list(struct inode *inode, const char *name, int type, void *buffer,
337                   size_t size, u64 valid)
338 {
339         struct ll_inode_info *lli = ll_i2info(inode);
340         struct ll_sb_info *sbi = ll_i2sbi(inode);
341         struct ptlrpc_request *req = NULL;
342         void *xdata;
343         int rc;
344         ENTRY;
345
346         if (sbi->ll_xattr_cache_enabled && type != XATTR_ACL_ACCESS_T &&
347             (type != XATTR_SECURITY_T || strcmp(name, "security.selinux"))) {
348                 rc = ll_xattr_cache_get(inode, name, buffer, size, valid);
349                 if (rc == -EAGAIN)
350                         goto getxattr_nocache;
351                 if (rc < 0)
352                         GOTO(out_xattr, rc);
353
354                 /* Add "system.posix_acl_access" to the list */
355                 if (lli->lli_posix_acl && valid & OBD_MD_FLXATTRLS) {
356                         if (size == 0) {
357                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
358                         } else if (size - rc >= sizeof(XATTR_NAME_ACL_ACCESS)) {
359                                 memcpy(buffer + rc, XATTR_NAME_ACL_ACCESS,
360                                        sizeof(XATTR_NAME_ACL_ACCESS));
361                                 rc += sizeof(XATTR_NAME_ACL_ACCESS);
362                         } else {
363                                 GOTO(out_xattr, rc = -ERANGE);
364                         }
365                 }
366         } else {
367 getxattr_nocache:
368                 rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid,
369                                  name, size, &req);
370                 if (rc < 0)
371                         GOTO(out_xattr, rc);
372
373                 /* only detect the xattr size */
374                 if (size == 0)
375                         GOTO(out, rc);
376
377                 if (size < rc)
378                         GOTO(out, rc = -ERANGE);
379
380                 /* do not need swab xattr data */
381                 xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
382                                                      rc);
383                 if (!xdata)
384                         GOTO(out, rc = -EPROTO);
385
386                 memcpy(buffer, xdata, rc);
387         }
388
389         EXIT;
390
391 out_xattr:
392         if (rc == -EOPNOTSUPP && type == XATTR_USER_T) {
393                 LCONSOLE_INFO("%s: disabling user_xattr feature because "
394                               "it is not supported on the server: rc = %d\n",
395                               sbi->ll_fsname, rc);
396                 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
397         }
398 out:
399         ptlrpc_req_finished(req);
400         RETURN(rc);
401 }
402
403 static int ll_xattr_get_common(const struct xattr_handler *handler,
404                                struct dentry *dentry,
405                                struct inode *inode,
406                                const char *name, void *buffer, size_t size)
407 {
408         struct ll_sb_info *sbi = ll_i2sbi(inode);
409         char *fullname;
410         int rc;
411
412         ENTRY;
413
414         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
415
416         rc = xattr_type_filter(sbi, handler);
417         if (rc)
418                 RETURN(rc);
419
420         /* LU-549:  Disable security.selinux when selinux is disabled */
421         if (handler->flags == XATTR_SECURITY_T && !selinux_is_enabled() &&
422             !strcmp(name, "selinux"))
423                 RETURN(-EOPNOTSUPP);
424
425 #ifdef CONFIG_FS_POSIX_ACL
426         /* posix acl is under protection of LOOKUP lock. when calling to this,
427          * we just have path resolution to the target inode, so we have great
428          * chance that cached ACL is uptodate.
429          */
430         if (handler->flags == XATTR_ACL_ACCESS_T) {
431                 struct ll_inode_info *lli = ll_i2info(inode);
432                 struct posix_acl *acl;
433
434                 spin_lock(&lli->lli_lock);
435                 acl = posix_acl_dup(lli->lli_posix_acl);
436                 spin_unlock(&lli->lli_lock);
437
438                 if (!acl)
439                         RETURN(-ENODATA);
440
441                 rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
442                 posix_acl_release(acl);
443                 RETURN(rc);
444         }
445         if (handler->flags == XATTR_ACL_DEFAULT_T && !S_ISDIR(inode->i_mode))
446                 RETURN(-ENODATA);
447 #endif
448
449         fullname = kasprintf(GFP_KERNEL, "%s%s", xattr_prefix(handler), name);
450         if (!fullname)
451                 RETURN(-ENOMEM);
452
453         rc = ll_xattr_list(inode, fullname, handler->flags, buffer, size,
454                            OBD_MD_FLXATTR);
455         kfree(fullname);
456         RETURN(rc);
457 }
458
459 static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
460 {
461         ssize_t rc;
462
463         if (S_ISREG(inode->i_mode)) {
464                 struct cl_object *obj = ll_i2info(inode)->lli_clob;
465                 struct cl_layout cl = {
466                         .cl_buf.lb_buf = buf,
467                         .cl_buf.lb_len = buf_size,
468                 };
469                 struct lu_env *env;
470                 u16 refcheck;
471                 u32 magic;
472
473                 if (!obj)
474                         RETURN(-ENODATA);
475
476                 env = cl_env_get(&refcheck);
477                 if (IS_ERR(env))
478                         RETURN(PTR_ERR(env));
479
480                 rc = cl_object_layout_get(env, obj, &cl);
481                 if (rc < 0)
482                         GOTO(out_env, rc);
483
484                 if (!cl.cl_size)
485                         GOTO(out_env, rc = -ENODATA);
486
487                 rc = cl.cl_size;
488
489                 if (!buf_size)
490                         GOTO(out_env, rc);
491
492                 LASSERT(buf && rc <= buf_size);
493
494                 /*
495                  * Do not return layout gen for getxattr() since
496                  * otherwise it would confuse tar --xattr by
497                  * recognizing layout gen as stripe offset when the
498                  * file is restored. See LU-2809.
499                  */
500                 magic = ((struct lov_mds_md *)buf)->lmm_magic;
501                 if (magic == LOV_MAGIC_COMP_V1 || magic == LOV_MAGIC_FOREIGN)
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 #ifdef HAVE_XATTR_HANDLER_NAME
763         .name = XATTR_NAME_POSIX_ACL_ACCESS,
764 #else
765         .prefix = XATTR_NAME_POSIX_ACL_ACCESS,
766 #endif
767         .flags = XATTR_ACL_ACCESS_T,
768 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
769         .get = ll_xattr_get_common_4_3,
770         .set = ll_xattr_set_common_4_3,
771 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
772         .get = ll_xattr_get_common_3_11,
773         .set = ll_xattr_set_common_3_11,
774 #else
775         .get = ll_xattr_get_common,
776         .set = ll_xattr_set_common,
777 #endif
778 };
779
780 static const struct xattr_handler ll_acl_default_xattr_handler = {
781 #ifdef HAVE_XATTR_HANDLER_NAME
782         .name = XATTR_NAME_POSIX_ACL_DEFAULT,
783 #else
784         .prefix = XATTR_NAME_POSIX_ACL_DEFAULT,
785 #endif
786         .flags = XATTR_ACL_DEFAULT_T,
787 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
788         .get = ll_xattr_get_common_4_3,
789         .set = ll_xattr_set_common_4_3,
790 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
791         .get = ll_xattr_get_common_3_11,
792         .set = ll_xattr_set_common_3_11,
793 #else
794         .get = ll_xattr_get_common,
795         .set = ll_xattr_set_common,
796 #endif
797 };
798
799 static const struct xattr_handler ll_lustre_xattr_handler = {
800         .prefix = XATTR_LUSTRE_PREFIX,
801         .flags = XATTR_LUSTRE_T,
802 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
803         .get = ll_xattr_get_4_3,
804         .set = ll_xattr_set_4_3,
805 #elif !defined(HAVE_XATTR_HANDLER_INODE_PARAM)
806         .get = ll_xattr_get_3_11,
807         .set = ll_xattr_set_3_11,
808 #else
809         .get = ll_xattr_get,
810         .set = ll_xattr_set,
811 #endif
812 };
813
814 const struct xattr_handler *ll_xattr_handlers[] = {
815         &ll_user_xattr_handler,
816         &ll_trusted_xattr_handler,
817         &ll_security_xattr_handler,
818 #ifdef CONFIG_FS_POSIX_ACL
819         &ll_acl_access_xattr_handler,
820         &ll_acl_default_xattr_handler,
821 #endif
822         &ll_lustre_xattr_handler,
823         NULL,
824 };