4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <linux/sched.h>
40 #include <linux/selinux.h>
42 #define DEBUG_SUBSYSTEM S_LLITE
44 #include "../include/obd_support.h"
45 #include "../include/lustre_lite.h"
46 #include "../include/lustre_dlm.h"
47 #include "../include/lustre_ver.h"
48 #include "../include/lustre_eacl.h"
50 #include "llite_internal.h"
52 #define XATTR_USER_T (1)
53 #define XATTR_TRUSTED_T (2)
54 #define XATTR_SECURITY_T (3)
55 #define XATTR_ACL_ACCESS_T (4)
56 #define XATTR_ACL_DEFAULT_T (5)
57 #define XATTR_LUSTRE_T (6)
58 #define XATTR_OTHER_T (7)
61 int get_xattr_type(const char *name
)
63 if (!strcmp(name
, POSIX_ACL_XATTR_ACCESS
))
64 return XATTR_ACL_ACCESS_T
;
66 if (!strcmp(name
, POSIX_ACL_XATTR_DEFAULT
))
67 return XATTR_ACL_DEFAULT_T
;
69 if (!strncmp(name
, XATTR_USER_PREFIX
,
70 sizeof(XATTR_USER_PREFIX
) - 1))
73 if (!strncmp(name
, XATTR_TRUSTED_PREFIX
,
74 sizeof(XATTR_TRUSTED_PREFIX
) - 1))
75 return XATTR_TRUSTED_T
;
77 if (!strncmp(name
, XATTR_SECURITY_PREFIX
,
78 sizeof(XATTR_SECURITY_PREFIX
) - 1))
79 return XATTR_SECURITY_T
;
81 if (!strncmp(name
, XATTR_LUSTRE_PREFIX
,
82 sizeof(XATTR_LUSTRE_PREFIX
) - 1))
83 return XATTR_LUSTRE_T
;
89 int xattr_type_filter(struct ll_sb_info
*sbi
, int xattr_type
)
91 if ((xattr_type
== XATTR_ACL_ACCESS_T
||
92 xattr_type
== XATTR_ACL_DEFAULT_T
) &&
93 !(sbi
->ll_flags
& LL_SBI_ACL
))
96 if (xattr_type
== XATTR_USER_T
&& !(sbi
->ll_flags
& LL_SBI_USER_XATTR
))
98 if (xattr_type
== XATTR_TRUSTED_T
&& !capable(CFS_CAP_SYS_ADMIN
))
100 if (xattr_type
== XATTR_OTHER_T
)
107 int ll_setxattr_common(struct inode
*inode
, const char *name
,
108 const void *value
, size_t size
,
109 int flags
, __u64 valid
)
111 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
112 struct ptlrpc_request
*req
= NULL
;
115 #ifdef CONFIG_FS_POSIX_ACL
116 struct rmtacl_ctl_entry
*rce
= NULL
;
117 posix_acl_xattr_header
*new_value
= NULL
;
118 ext_acl_xattr_header
*acl
= NULL
;
120 const char *pv
= value
;
122 xattr_type
= get_xattr_type(name
);
123 rc
= xattr_type_filter(sbi
, xattr_type
);
127 if ((xattr_type
== XATTR_ACL_ACCESS_T
||
128 xattr_type
== XATTR_ACL_DEFAULT_T
) &&
129 !inode_owner_or_capable(inode
))
132 /* b10667: ignore lustre special xattr for now */
133 if ((xattr_type
== XATTR_TRUSTED_T
&& strcmp(name
, "trusted.lov") == 0) ||
134 (xattr_type
== XATTR_LUSTRE_T
&& strcmp(name
, "lustre.lov") == 0))
137 /* b15587: ignore security.capability xattr for now */
138 if ((xattr_type
== XATTR_SECURITY_T
&&
139 strcmp(name
, "security.capability") == 0))
142 /* LU-549: Disable security.selinux when selinux is disabled */
143 if (xattr_type
== XATTR_SECURITY_T
&& !selinux_is_enabled() &&
144 strcmp(name
, "security.selinux") == 0)
147 #ifdef CONFIG_FS_POSIX_ACL
148 if (sbi
->ll_flags
& LL_SBI_RMT_CLIENT
&&
149 (xattr_type
== XATTR_ACL_ACCESS_T
||
150 xattr_type
== XATTR_ACL_DEFAULT_T
)) {
151 rce
= rct_search(&sbi
->ll_rct
, current_pid());
153 (rce
->rce_ops
!= RMT_LSETFACL
&&
154 rce
->rce_ops
!= RMT_RSETFACL
))
157 if (rce
->rce_ops
== RMT_LSETFACL
) {
158 struct eacl_entry
*ee
;
160 ee
= et_search_del(&sbi
->ll_et
, current_pid(),
161 ll_inode2fid(inode
), xattr_type
);
163 if (valid
& OBD_MD_FLXATTR
) {
164 acl
= lustre_acl_xattr_merge2ext(
165 (posix_acl_xattr_header
*)value
,
171 size
= CFS_ACL_XATTR_SIZE(\
172 le32_to_cpu(acl
->a_count
), \
174 pv
= (const char *)acl
;
177 } else if (rce
->rce_ops
== RMT_RSETFACL
) {
178 size
= lustre_posix_acl_xattr_filter(
179 (posix_acl_xattr_header
*)value
,
181 if (unlikely(size
< 0))
184 pv
= (const char *)new_value
;
188 valid
|= rce_ops2valid(rce
->rce_ops
);
191 oc
= ll_mdscapa_get(inode
);
192 rc
= md_setxattr(sbi
->ll_md_exp
, ll_inode2fid(inode
), oc
,
193 valid
, name
, pv
, size
, 0, flags
,
194 ll_i2suppgid(inode
), &req
);
196 #ifdef CONFIG_FS_POSIX_ACL
197 if (new_value
!= NULL
)
198 lustre_posix_acl_xattr_free(new_value
, size
);
200 lustre_ext_acl_xattr_free(acl
);
203 if (rc
== -EOPNOTSUPP
&& xattr_type
== XATTR_USER_T
) {
204 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
205 sbi
->ll_flags
&= ~LL_SBI_USER_XATTR
;
210 ptlrpc_req_finished(req
);
214 int ll_setxattr(struct dentry
*dentry
, const char *name
,
215 const void *value
, size_t size
, int flags
)
217 struct inode
*inode
= dentry
->d_inode
;
222 CDEBUG(D_VFSTRACE
, "VFS Op:inode=%lu/%u(%p), xattr %s\n",
223 inode
->i_ino
, inode
->i_generation
, inode
, name
);
225 ll_stats_ops_tally(ll_i2sbi(inode
), LPROC_LL_SETXATTR
, 1);
227 if ((strncmp(name
, XATTR_TRUSTED_PREFIX
,
228 sizeof(XATTR_TRUSTED_PREFIX
) - 1) == 0 &&
229 strcmp(name
+ sizeof(XATTR_TRUSTED_PREFIX
) - 1, "lov") == 0) ||
230 (strncmp(name
, XATTR_LUSTRE_PREFIX
,
231 sizeof(XATTR_LUSTRE_PREFIX
) - 1) == 0 &&
232 strcmp(name
+ sizeof(XATTR_LUSTRE_PREFIX
) - 1, "lov") == 0)) {
233 struct lov_user_md
*lump
= (struct lov_user_md
*)value
;
236 if (size
!= 0 && size
< sizeof(struct lov_user_md
))
239 /* Attributes that are saved via getxattr will always have
240 * the stripe_offset as 0. Instead, the MDS should be
241 * allowed to pick the starting OST index. b=17846 */
242 if (lump
!= NULL
&& lump
->lmm_stripe_offset
== 0)
243 lump
->lmm_stripe_offset
= -1;
245 if (lump
!= NULL
&& S_ISREG(inode
->i_mode
)) {
247 int flags
= FMODE_WRITE
;
248 int lum_size
= (lump
->lmm_magic
== LOV_USER_MAGIC_V1
) ?
249 sizeof(*lump
) : sizeof(struct lov_user_md_v3
);
251 memset(&f
, 0, sizeof(f
)); /* f.f_flags is used below */
253 rc
= ll_lov_setstripe_ea_info(inode
, &f
, flags
, lump
,
255 /* b10667: rc always be 0 here for now */
257 } else if (S_ISDIR(inode
->i_mode
)) {
258 rc
= ll_dir_setstripe(inode
, lump
, 0);
263 } else if (strcmp(name
, XATTR_NAME_LMA
) == 0 ||
264 strcmp(name
, XATTR_NAME_LINK
) == 0)
267 return ll_setxattr_common(inode
, name
, value
, size
, flags
,
271 int ll_removexattr(struct dentry
*dentry
, const char *name
)
273 struct inode
*inode
= dentry
->d_inode
;
278 CDEBUG(D_VFSTRACE
, "VFS Op:inode=%lu/%u(%p), xattr %s\n",
279 inode
->i_ino
, inode
->i_generation
, inode
, name
);
281 ll_stats_ops_tally(ll_i2sbi(inode
), LPROC_LL_REMOVEXATTR
, 1);
282 return ll_setxattr_common(inode
, name
, NULL
, 0, 0,
287 int ll_getxattr_common(struct inode
*inode
, const char *name
,
288 void *buffer
, size_t size
, __u64 valid
)
290 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
291 struct ptlrpc_request
*req
= NULL
;
292 struct mdt_body
*body
;
296 struct rmtacl_ctl_entry
*rce
= NULL
;
297 struct ll_inode_info
*lli
= ll_i2info(inode
);
299 CDEBUG(D_VFSTRACE
, "VFS Op:inode=%lu/%u(%p)\n",
300 inode
->i_ino
, inode
->i_generation
, inode
);
302 /* listxattr have slightly different behavior from of ext3:
303 * without 'user_xattr' ext3 will list all xattr names but
304 * filtered out "^user..*"; we list them all for simplicity.
307 xattr_type
= XATTR_OTHER_T
;
311 xattr_type
= get_xattr_type(name
);
312 rc
= xattr_type_filter(sbi
, xattr_type
);
316 /* b15587: ignore security.capability xattr for now */
317 if ((xattr_type
== XATTR_SECURITY_T
&&
318 strcmp(name
, "security.capability") == 0))
321 /* LU-549: Disable security.selinux when selinux is disabled */
322 if (xattr_type
== XATTR_SECURITY_T
&& !selinux_is_enabled() &&
323 strcmp(name
, "security.selinux") == 0)
326 #ifdef CONFIG_FS_POSIX_ACL
327 if (sbi
->ll_flags
& LL_SBI_RMT_CLIENT
&&
328 (xattr_type
== XATTR_ACL_ACCESS_T
||
329 xattr_type
== XATTR_ACL_DEFAULT_T
)) {
330 rce
= rct_search(&sbi
->ll_rct
, current_pid());
332 (rce
->rce_ops
!= RMT_LSETFACL
&&
333 rce
->rce_ops
!= RMT_LGETFACL
&&
334 rce
->rce_ops
!= RMT_RSETFACL
&&
335 rce
->rce_ops
!= RMT_RGETFACL
))
339 /* posix acl is under protection of LOOKUP lock. when calling to this,
340 * we just have path resolution to the target inode, so we have great
341 * chance that cached ACL is uptodate.
343 if (xattr_type
== XATTR_ACL_ACCESS_T
&&
344 !(sbi
->ll_flags
& LL_SBI_RMT_CLIENT
)) {
346 struct posix_acl
*acl
;
348 spin_lock(&lli
->lli_lock
);
349 acl
= posix_acl_dup(lli
->lli_posix_acl
);
350 spin_unlock(&lli
->lli_lock
);
355 rc
= posix_acl_to_xattr(&init_user_ns
, acl
, buffer
, size
);
356 posix_acl_release(acl
);
359 if (xattr_type
== XATTR_ACL_DEFAULT_T
&& !S_ISDIR(inode
->i_mode
))
364 if (sbi
->ll_xattr_cache_enabled
&& xattr_type
!= XATTR_ACL_ACCESS_T
) {
365 rc
= ll_xattr_cache_get(inode
, name
, buffer
, size
, valid
);
367 goto getxattr_nocache
;
371 /* Add "system.posix_acl_access" to the list */
372 if (lli
->lli_posix_acl
!= NULL
&& valid
& OBD_MD_FLXATTRLS
) {
374 rc
+= sizeof(XATTR_NAME_ACL_ACCESS
);
375 } else if (size
- rc
>= sizeof(XATTR_NAME_ACL_ACCESS
)) {
376 memcpy(buffer
+ rc
, XATTR_NAME_ACL_ACCESS
,
377 sizeof(XATTR_NAME_ACL_ACCESS
));
378 rc
+= sizeof(XATTR_NAME_ACL_ACCESS
);
386 oc
= ll_mdscapa_get(inode
);
387 rc
= md_getxattr(sbi
->ll_md_exp
, ll_inode2fid(inode
), oc
,
388 valid
| (rce
? rce_ops2valid(rce
->rce_ops
) : 0),
389 name
, NULL
, 0, size
, 0, &req
);
395 body
= req_capsule_server_get(&req
->rq_pill
, &RMF_MDT_BODY
);
398 /* only detect the xattr size */
400 rc
= body
->eadatasize
;
404 if (size
< body
->eadatasize
) {
405 CERROR("server bug: replied size %u > %u\n",
406 body
->eadatasize
, (int)size
);
411 if (body
->eadatasize
== 0) {
416 /* do not need swab xattr data */
417 xdata
= req_capsule_server_sized_get(&req
->rq_pill
, &RMF_EADATA
,
424 memcpy(buffer
, xdata
, body
->eadatasize
);
425 rc
= body
->eadatasize
;
428 #ifdef CONFIG_FS_POSIX_ACL
429 if (rce
&& rce
->rce_ops
== RMT_LSETFACL
) {
430 ext_acl_xattr_header
*acl
;
432 acl
= lustre_posix_acl_xattr_2ext(
433 (posix_acl_xattr_header
*)buffer
, rc
);
439 rc
= ee_add(&sbi
->ll_et
, current_pid(), ll_inode2fid(inode
),
441 if (unlikely(rc
< 0)) {
442 lustre_ext_acl_xattr_free(acl
);
449 if (rc
== -EOPNOTSUPP
&& xattr_type
== XATTR_USER_T
) {
451 "%s: disabling user_xattr feature because it is not supported on the server: rc = %d\n",
452 ll_get_fsname(inode
->i_sb
, NULL
, 0), rc
);
453 sbi
->ll_flags
&= ~LL_SBI_USER_XATTR
;
456 ptlrpc_req_finished(req
);
460 ssize_t
ll_getxattr(struct dentry
*dentry
, const char *name
,
461 void *buffer
, size_t size
)
463 struct inode
*inode
= dentry
->d_inode
;
468 CDEBUG(D_VFSTRACE
, "VFS Op:inode=%lu/%u(%p), xattr %s\n",
469 inode
->i_ino
, inode
->i_generation
, inode
, name
);
471 ll_stats_ops_tally(ll_i2sbi(inode
), LPROC_LL_GETXATTR
, 1);
473 if ((strncmp(name
, XATTR_TRUSTED_PREFIX
,
474 sizeof(XATTR_TRUSTED_PREFIX
) - 1) == 0 &&
475 strcmp(name
+ sizeof(XATTR_TRUSTED_PREFIX
) - 1, "lov") == 0) ||
476 (strncmp(name
, XATTR_LUSTRE_PREFIX
,
477 sizeof(XATTR_LUSTRE_PREFIX
) - 1) == 0 &&
478 strcmp(name
+ sizeof(XATTR_LUSTRE_PREFIX
) - 1, "lov") == 0)) {
479 struct lov_stripe_md
*lsm
;
480 struct lov_user_md
*lump
;
481 struct lov_mds_md
*lmm
= NULL
;
482 struct ptlrpc_request
*request
= NULL
;
483 int rc
= 0, lmmsize
= 0;
485 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
))
488 if (size
== 0 && S_ISDIR(inode
->i_mode
)) {
489 /* XXX directory EA is fix for now, optimize to save
491 rc
= sizeof(struct lov_user_md
);
495 lsm
= ccc_inode_lsm_get(inode
);
497 if (S_ISDIR(inode
->i_mode
)) {
498 rc
= ll_dir_getstripe(inode
, &lmm
,
504 /* LSM is present already after lookup/getattr call.
505 * we need to grab layout lock once it is implemented */
506 rc
= obd_packmd(ll_i2dtexp(inode
), &lmm
, lsm
);
509 ccc_inode_lsm_put(inode
, lsm
);
515 /* used to call ll_get_max_mdsize() forward to get
516 * the maximum buffer size, while some apps (such as
517 * rsync 3.0.x) care much about the exact xattr value
523 if (size
< lmmsize
) {
524 CERROR("server bug: replied size %d > %d for %s (%s)\n",
525 lmmsize
, (int)size
, dentry
->d_name
.name
, name
);
530 lump
= (struct lov_user_md
*)buffer
;
531 memcpy(lump
, lmm
, lmmsize
);
532 /* do not return layout gen for getxattr otherwise it would
533 * confuse tar --xattr by recognizing layout gen as stripe
534 * offset when the file is restored. See LU-2809. */
535 lump
->lmm_layout_gen
= 0;
540 ptlrpc_req_finished(request
);
542 obd_free_diskmd(ll_i2dtexp(inode
), &lmm
);
546 return ll_getxattr_common(inode
, name
, buffer
, size
, OBD_MD_FLXATTR
);
549 ssize_t
ll_listxattr(struct dentry
*dentry
, char *buffer
, size_t size
)
551 struct inode
*inode
= dentry
->d_inode
;
553 struct lov_mds_md
*lmm
= NULL
;
554 struct ptlrpc_request
*request
= NULL
;
559 CDEBUG(D_VFSTRACE
, "VFS Op:inode=%lu/%u(%p)\n",
560 inode
->i_ino
, inode
->i_generation
, inode
);
562 ll_stats_ops_tally(ll_i2sbi(inode
), LPROC_LL_LISTXATTR
, 1);
564 rc
= ll_getxattr_common(inode
, NULL
, buffer
, size
, OBD_MD_FLXATTRLS
);
568 if (buffer
!= NULL
) {
569 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
570 char *xattr_name
= buffer
;
574 xlen
= strnlen(xattr_name
, rem
- 1) + 1;
576 if (xattr_type_filter(sbi
,
577 get_xattr_type(xattr_name
)) == 0) {
578 /* skip OK xattr type
584 /* move up remaining xattrs in buffer
585 * removing the xattr that is not OK
587 memmove(xattr_name
, xattr_name
+ xlen
, rem
);
591 if (S_ISREG(inode
->i_mode
)) {
592 if (!ll_i2info(inode
)->lli_has_smd
)
594 } else if (S_ISDIR(inode
->i_mode
)) {
595 rc2
= ll_dir_getstripe(inode
, &lmm
, &lmmsize
, &request
);
601 } else if (S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
)) {
602 const int prefix_len
= sizeof(XATTR_LUSTRE_PREFIX
) - 1;
603 const size_t name_len
= sizeof("lov") - 1;
604 const size_t total_len
= prefix_len
+ name_len
+ 1;
606 if (((rc
+ total_len
) > size
) && (buffer
!= NULL
)) {
607 ptlrpc_req_finished(request
);
611 if (buffer
!= NULL
) {
613 memcpy(buffer
, XATTR_LUSTRE_PREFIX
, prefix_len
);
614 memcpy(buffer
+ prefix_len
, "lov", name_len
);
615 buffer
[prefix_len
+ name_len
] = '\0';
620 ptlrpc_req_finished(request
);
This page took 0.04691 seconds and 5 git commands to generate.