* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#define DEBUG_SUBSYSTEM S_MDS
+#include <linux/xattr.h>
+#include <obd_class.h>
+#include <lustre_nodemap.h>
#include <lustre_acl.h>
#include "mdt_internal.h"
if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK))
RETURN(-ENOMEM);
- valid = info->mti_body->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
+ valid = info->mti_body->mbo_valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
/* Determine how many bytes we need */
if (valid == OBD_MD_FLXATTR) {
/* N.B. eadatasize = 0 is not valid for FLXATTRALL */
/* We could calculate accurate sizes, but this would
* introduce a lot of overhead, let's do it later... */
- size = info->mti_body->eadatasize;
+ size = info->mti_body->mbo_eadatasize;
req_capsule_set_size(pill, &RMF_EAVALS, RCL_SERVER, size);
req_capsule_set_size(pill, &RMF_EAVALS_LENS, RCL_SERVER, size);
- } else {
- CDEBUG(D_INFO, "Valid bits: "LPX64"\n", info->mti_body->valid);
+ } else {
+ CDEBUG(D_INFO, "Valid bits: "LPX64"\n",
+ info->mti_body->mbo_valid);
RETURN(-EINVAL);
}
- if (size == -ENODATA) {
- size = 0;
- } else if (size < 0) {
- CERROR("Error geting EA size: %d\n", size);
- RETURN(size);
- }
-
- if (info->mti_body->eadatasize != 0 &&
- info->mti_body->eadatasize < size)
- RETURN(-ERANGE);
+ if (size == -ENODATA) {
+ size = 0;
+ } else if (size < 0) {
+ if (size != -EOPNOTSUPP)
+ CERROR("Error geting EA size: %d\n", size);
+ RETURN(size);
+ }
req_capsule_set_size(pill, &RMF_EADATA, RCL_SERVER,
- info->mti_body->eadatasize == 0 ? 0 : size);
+ info->mti_body->mbo_eadatasize == 0 ? 0 : size);
rc = req_capsule_server_pack(pill);
if (rc) {
LASSERT(rc < 0);
CDEBUG(D_INODE, "getxattr %s\n", xattr_name);
rc = mo_xattr_get(info->mti_env, next, buf, xattr_name);
- if (rc < 0) {
- CERROR("getxattr failed: %d\n", rc);
+ if (rc < 0)
GOTO(out, rc);
- }
- if (info->mti_body->valid &
+ if (info->mti_body->mbo_valid &
(OBD_MD_FLRMTLSETFACL | OBD_MD_FLRMTLGETFACL))
flags = CFS_IC_ALL;
- else if (info->mti_body->valid & OBD_MD_FLRMTRGETFACL)
+ else if (info->mti_body->mbo_valid & OBD_MD_FLRMTRGETFACL)
flags = CFS_IC_MAPPED;
if (rc > 0 && flags != CFS_IC_NOTHING) {
eadatahead = buf->lb_buf;
/* Fill out EADATA first */
- eadatasize = mo_xattr_list(env, next, buf);
- if (eadatasize < 0)
- GOTO(out, rc = eadatasize);
+ rc = mo_xattr_list(env, next, buf);
+ if (rc < 0)
+ GOTO(out_shrink, rc);
+ eadatasize = rc;
eadatatail = eadatahead + eadatasize;
v = req_capsule_server_get(info->mti_pill, &RMF_EAVALS);
/* Fill out EAVALS and EAVALS_LENS */
for (b = eadatahead; b < eadatatail; b += strlen(b) + 1, v += rc) {
buf->lb_buf = v;
- buf->lb_len = reqbody->eadatasize - eavallen;
+ buf->lb_len = reqbody->mbo_eadatasize - eavallen;
rc = mdt_getxattr_one(info, b, next, buf, med, uc);
if (rc < 0)
- GOTO(out, rc);
+ GOTO(out_shrink, rc);
sizes[eavallens] = rc;
eavallens++;
eavallen += rc;
}
- repbody->aclsize = eavallen;
- repbody->max_mdsize = eavallens;
+out_shrink:
+ if (rc < 0) {
+ eadatasize = 0;
+ eavallens = 0;
+ eavallen = 0;
+ }
+ repbody->mbo_aclsize = eavallen;
+ repbody->mbo_max_mdsize = eavallens;
req_capsule_shrink(info->mti_pill, &RMF_EAVALS, eavallen, RCL_SERVER);
req_capsule_shrink(info->mti_pill, &RMF_EAVALS_LENS,
eavallens * sizeof(__u32), RCL_SERVER);
req_capsule_shrink(info->mti_pill, &RMF_EADATA, eadatasize, RCL_SERVER);
- GOTO(out, rc = eadatasize);
-out:
+ if (rc >= 0)
+ RETURN(eadatasize);
return rc;
}
int mdt_getxattr(struct mdt_thread_info *info)
{
- struct ptlrpc_request *req = mdt_info_req(info);
- struct mdt_export_data *med = mdt_req2med(req);
- struct lu_ucred *uc = mdt_ucred(info);
+ struct ptlrpc_request *req = mdt_info_req(info);
+ struct mdt_export_data *med = mdt_req2med(req);
+ struct lu_ucred *uc = lu_ucred(info->mti_env);
struct mdt_body *reqbody;
struct mdt_body *repbody = NULL;
struct md_object *next;
__u32 remote = exp_connect_rmtclient(info->mti_exp);
__u32 perm;
int easize, rc;
- obd_valid valid;
+ u64 valid;
ENTRY;
LASSERT(info->mti_object != NULL);
LASSERT(lu_object_assert_exists(&info->mti_object->mot_obj));
- CDEBUG(D_INODE, "getxattr "DFID"\n", PFID(&info->mti_body->fid1));
+ CDEBUG(D_INODE, "getxattr "DFID"\n", PFID(&info->mti_body->mbo_fid1));
reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
if (reqbody == NULL)
next = mdt_object_child(info->mti_object);
- if (info->mti_body->valid & OBD_MD_FLRMTRGETFACL) {
+ if (info->mti_body->mbo_valid & OBD_MD_FLRMTRGETFACL) {
if (unlikely(!remote))
GOTO(out, rc = err_serious(-EINVAL));
LASSERT(repbody != NULL);
/* No need further getxattr. */
- if (easize == 0 || reqbody->eadatasize == 0)
- GOTO(out, rc = easize);
+ if (easize == 0 || reqbody->mbo_eadatasize == 0)
+ GOTO(out, rc = easize);
- buf = &info->mti_buf;
- buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_EADATA);
- buf->lb_len = easize;
+ buf = &info->mti_buf;
+ buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_EADATA);
+ buf->lb_len = easize;
- valid = info->mti_body->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
+ valid = info->mti_body->mbo_valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
if (valid == OBD_MD_FLXATTR) {
char *xattr_name = req_capsule_client_get(info->mti_pill,
out:
if (rc >= 0) {
mdt_counter_incr(req, LPROC_MDT_GETXATTR);
- repbody->eadatasize = rc;
+ repbody->mbo_eadatasize = rc;
rc = 0;
}
mdt_exit_ucred(info);
int mdt_reint_setxattr(struct mdt_thread_info *info,
struct mdt_lock_handle *unused)
{
- struct ptlrpc_request *req = mdt_info_req(info);
- struct lu_ucred *uc = mdt_ucred(info);
- struct mdt_lock_handle *lh;
- const struct lu_env *env = info->mti_env;
- struct lu_buf *buf = &info->mti_buf;
- struct mdt_reint_record *rr = &info->mti_rr;
- struct md_attr *ma = &info->mti_attr;
- struct lu_attr *attr = &info->mti_attr.ma_attr;
- struct mdt_object *obj;
- struct md_object *child;
- __u64 valid = attr->la_valid;
- const char *xattr_name = rr->rr_name;
- int xattr_len = rr->rr_eadatalen;
- __u64 lockpart;
- int rc;
- posix_acl_xattr_header *new_xattr = NULL;
- __u32 remote = exp_connect_rmtclient(info->mti_exp);
- __u32 perm;
- ENTRY;
+ struct ptlrpc_request *req = mdt_info_req(info);
+ struct lu_ucred *uc = lu_ucred(info->mti_env);
+ struct mdt_lock_handle *lh;
+ const struct lu_env *env = info->mti_env;
+ struct lu_buf *buf = &info->mti_buf;
+ struct mdt_reint_record *rr = &info->mti_rr;
+ struct md_attr *ma = &info->mti_attr;
+ struct lu_attr *attr = &info->mti_attr.ma_attr;
+ struct mdt_object *obj;
+ struct md_object *child;
+ struct obd_export *exp = info->mti_exp;
+ struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap;
+ __u64 valid = attr->la_valid;
+ const char *xattr_name = rr->rr_name.ln_name;
+ int xattr_len = rr->rr_eadatalen;
+ __u64 lockpart;
+ int rc;
+ posix_acl_xattr_header *new_xattr = NULL;
+ __u32 remote = exp_connect_rmtclient(info->mti_exp);
+ __u32 perm;
+ ENTRY;
- CDEBUG(D_INODE, "setxattr for "DFID"\n", PFID(rr->rr_fid1));
+ CDEBUG(D_INODE, "setxattr for "DFID": %s %s\n", PFID(rr->rr_fid1),
+ valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name);
if (info->mti_dlm_req)
- ldlm_request_cancel(req, info->mti_dlm_req, 0);
+ ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SETXATTR))
RETURN(err_serious(-ENOMEM));
- CDEBUG(D_INODE, "%s xattr %s\n",
- valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name);
-
rc = mdt_init_ucred_reint(info);
if (rc != 0)
RETURN(rc);
perm = mdt_identity_get_perm(uc->uc_identity, remote,
req->rq_peer.nid);
- if (!(perm & CFS_RMTACL_PERM))
- GOTO(out, rc = err_serious(-EPERM));
- }
+ if (!(perm & CFS_RMTACL_PERM))
+ GOTO(out, rc = err_serious(-EPERM));
+ }
- if (strncmp(xattr_name, XATTR_USER_PREFIX,
- sizeof(XATTR_USER_PREFIX) - 1) == 0) {
+ if (strncmp(xattr_name, XATTR_USER_PREFIX,
+ sizeof(XATTR_USER_PREFIX) - 1) == 0) {
if (!(exp_connect_flags(req->rq_export) & OBD_CONNECT_XATTR))
GOTO(out, rc = -EOPNOTSUPP);
- if (strcmp(xattr_name, XATTR_NAME_LOV) == 0)
- GOTO(out, rc = -EACCES);
- if (strcmp(xattr_name, XATTR_NAME_LMA) == 0)
- GOTO(out, rc = 0);
- if (strcmp(xattr_name, XATTR_NAME_LINK) == 0)
- GOTO(out, rc = 0);
- } else if ((valid & OBD_MD_FLXATTR) &&
- (strncmp(xattr_name, XATTR_NAME_ACL_ACCESS,
- sizeof(XATTR_NAME_ACL_ACCESS) - 1) == 0 ||
- strncmp(xattr_name, XATTR_NAME_ACL_DEFAULT,
- sizeof(XATTR_NAME_ACL_DEFAULT) - 1) == 0)) {
- /* currently lustre limit acl access size */
- if (xattr_len > LUSTRE_POSIX_ACL_MAX_SIZE)
- GOTO(out, -ERANGE);
- }
+ } else if (strncmp(xattr_name, XATTR_TRUSTED_PREFIX,
+ sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0) {
+
+ if (!md_capable(mdt_ucred(info), CFS_CAP_SYS_ADMIN))
+ GOTO(out, rc = -EPERM);
+
+ if (strcmp(xattr_name, XATTR_NAME_LOV) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_LMA) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_LMV) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_LINK) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_FID) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_VERSION) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_SOM) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_HSM) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE) == 0)
+ GOTO(out, rc = 0);
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+ if (strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE_OLD) == 0)
+ GOTO(out, rc = 0);
+#endif
+ } else if ((valid & OBD_MD_FLXATTR) &&
+ (strcmp(xattr_name, XATTR_NAME_ACL_ACCESS) == 0 ||
+ strcmp(xattr_name, XATTR_NAME_ACL_DEFAULT) == 0)) {
+
+ /* currently lustre limit acl access size */
+ if (xattr_len > LUSTRE_POSIX_ACL_MAX_SIZE)
+ GOTO(out, rc = -ERANGE);
+
+ rc = nodemap_map_acl(nodemap, rr->rr_eadata, xattr_len,
+ NODEMAP_CLIENT_TO_FS);
+ if (rc < 0)
+ GOTO(out, rc);
+
+ /* ACLs were mapped out, return an error so the user knows */
+ if (rc != xattr_len)
+ GOTO(out, rc = -EPERM);
+ }
lockpart = MDS_INODELOCK_UPDATE;
/* Revoke all clients' lookup lock, since the access
* to cancel them. */
mdt_lock_reg_init(lh, LCK_EX);
obj = mdt_object_find_lock(info, rr->rr_fid1, lh, lockpart);
- if (IS_ERR(obj))
- GOTO(out, rc = PTR_ERR(obj));
+ if (IS_ERR(obj))
+ GOTO(out, rc = PTR_ERR(obj));
- info->mti_mos = obj;
- rc = mdt_version_get_check_save(info, obj, 0);
- if (rc)
- GOTO(out_unlock, rc);
+ tgt_vbr_obj_set(env, mdt_obj2dt(obj));
+ rc = mdt_version_get_check_save(info, obj, 0);
+ if (rc)
+ GOTO(out_unlock, rc);
if (unlikely(!(valid & OBD_MD_FLCTIME))) {
/* This isn't strictly an error, but all current clients
PFID(rr->rr_fid1), valid);
attr->la_ctime = cfs_time_current_sec();
}
- attr->la_valid = LA_CTIME;
- child = mdt_object_child(obj);
- if (valid & OBD_MD_FLXATTR) {
- char *xattr = (void *)rr->rr_eadata;
-
- if (xattr_len > 0) {
- int flags = 0;
-
- if (valid & OBD_MD_FLRMTLSETFACL) {
- if (unlikely(!remote))
- GOTO(out_unlock, rc = -EINVAL);
-
- xattr_len = mdt_rmtlsetfacl(info, child,
- xattr_name,
- (ext_acl_xattr_header *)xattr,
- &new_xattr);
- if (xattr_len < 0)
- GOTO(out_unlock, rc = xattr_len);
-
- xattr = (char *)new_xattr;
- }
-
- if (attr->la_flags & XATTR_REPLACE)
- flags |= LU_XATTR_REPLACE;
-
- if (attr->la_flags & XATTR_CREATE)
- flags |= LU_XATTR_CREATE;
-
- mdt_fail_write(env, info->mti_mdt->mdt_bottom,
- OBD_FAIL_MDS_SETXATTR_WRITE);
-
- buf->lb_buf = xattr;
- buf->lb_len = xattr_len;
- rc = mo_xattr_set(env, child, buf, xattr_name, flags);
- /* update ctime after xattr changed */
- if (rc == 0) {
- ma->ma_attr_flags |= MDS_PERM_BYPASS;
- mo_attr_set(env, child, ma);
- }
- }
+ attr->la_valid = LA_CTIME;
+ child = mdt_object_child(obj);
+ if (valid & OBD_MD_FLXATTR) {
+ void *xattr = rr->rr_eadata;
+ int flags = 0;
+
+ if (valid & OBD_MD_FLRMTLSETFACL) {
+ if (unlikely(!remote))
+ GOTO(out_unlock, rc = -EINVAL);
+
+ xattr_len = mdt_rmtlsetfacl(info, child, xattr_name,
+ xattr, &new_xattr);
+ if (xattr_len < 0)
+ GOTO(out_unlock, rc = xattr_len);
+
+ xattr = new_xattr;
+ }
+
+ if (attr->la_flags & XATTR_REPLACE)
+ flags |= LU_XATTR_REPLACE;
+
+ if (attr->la_flags & XATTR_CREATE)
+ flags |= LU_XATTR_CREATE;
+
+ mdt_fail_write(env, info->mti_mdt->mdt_bottom,
+ OBD_FAIL_MDS_SETXATTR_WRITE);
+
+ buf->lb_buf = xattr;
+ buf->lb_len = xattr_len;
+ rc = mo_xattr_set(env, child, buf, xattr_name, flags);
+ /* update ctime after xattr changed */
+ if (rc == 0) {
+ ma->ma_attr_flags |= MDS_PERM_BYPASS;
+ mo_attr_set(env, child, ma);
+ }
} else if (valid & OBD_MD_FLXATTRRM) {
rc = mo_xattr_del(env, child, xattr_name);
/* update ctime after xattr changed */