* Copyright (c) 2002, 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/
}
if (bits & MDS_INODELOCK_XATTR) {
+ if (S_ISDIR(inode->i_mode))
+ ll_i2info(inode)->lli_def_stripe_offset = -1;
ll_xattr_cache_destroy(inode);
bits &= ~MDS_INODELOCK_XATTR;
}
alias = ll_splice_alias(inode, *de);
if (IS_ERR(alias))
- RETURN(PTR_ERR(alias));
+ GOTO(out, rc = PTR_ERR(alias));
+
*de = alias;
} else if (!it_disposition(it, DISP_LOOKUP_NEG) &&
!it_disposition(it, DISP_OPEN_CREATE)) {
(*de)->d_name.name,
(*de)->d_name.len, &fid);
if (rc != 0)
- RETURN(rc);
+ GOTO(out, rc);
}
if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
d_lustre_revalidate(*de);
ll_intent_release(&parent_it);
}
- }
+ }
+
+ GOTO(out, rc = 0);
+
+out:
+ if (rc != 0 && it->it_op & IT_OPEN)
+ ll_open_cleanup((*de)->d_sb, request);
- RETURN(0);
+ return rc;
}
static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
struct lookup_intent *it)
{
- struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
- struct dentry *save = dentry, *retval;
- struct ptlrpc_request *req = NULL;
- struct md_op_data *op_data;
+ struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
+ struct dentry *save = dentry, *retval;
+ struct ptlrpc_request *req = NULL;
+ struct md_op_data *op_data = NULL;
__u32 opc;
int rc;
ENTRY;
op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
dentry->d_name.len, 0, opc, NULL);
- if (IS_ERR(op_data))
- RETURN((void *)op_data);
+ if (IS_ERR(op_data))
+ RETURN((void *)op_data);
- /* enforce umask if acl disabled or MDS doesn't support umask */
- if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
+ /* enforce umask if acl disabled or MDS doesn't support umask */
+ if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
it->it_create_mode &= ~current_umask();
rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
&ll_md_blocking_ast, 0);
- ll_finish_md_op_data(op_data);
- if (rc < 0)
- GOTO(out, retval = ERR_PTR(rc));
+ /* If the MDS allows the client to chgrp (CFS_SETGRP_PERM), but the
+ * client does not know which suppgid should be sent to the MDS, or
+ * some other(s) changed the target file's GID after this RPC sent
+ * to the MDS with the suppgid as the original GID, then we should
+ * try again with right suppgid. */
+ if (rc == -EACCES && it->it_op & IT_OPEN &&
+ it_disposition(it, DISP_OPEN_DENY)) {
+ struct mdt_body *body;
+
+ LASSERT(req != NULL);
+
+ body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
+ if (op_data->op_suppgids[0] == body->mbo_gid ||
+ op_data->op_suppgids[1] == body->mbo_gid ||
+ !in_group_p(make_kgid(&init_user_ns, body->mbo_gid)))
+ GOTO(out, retval = ERR_PTR(-EACCES));
+
+ fid_zero(&op_data->op_fid2);
+ op_data->op_suppgids[1] = body->mbo_gid;
+ ptlrpc_req_finished(req);
+ req = NULL;
+ ll_intent_release(it);
+ rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
+ &ll_md_blocking_ast, 0);
+ }
+
+ if (rc < 0)
+ GOTO(out, retval = ERR_PTR(rc));
rc = ll_lookup_it_finish(req, it, parent, &dentry);
if (rc != 0) {
}
ll_lookup_finish_locks(it, dentry);
- retval = (dentry == save) ? NULL : dentry;
- EXIT;
+ GOTO(out, retval = (dentry == save) ? NULL : dentry);
out:
+ if (op_data != NULL && !IS_ERR(op_data))
+ ll_finish_md_op_data(op_data);
+
ptlrpc_req_finished(req);
return retval;
}
if (unlikely(tgt != NULL))
tgt_len = strlen(tgt) + 1;
+again:
op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
name->len, 0, opc, NULL);
if (IS_ERR(op_data))
from_kgid(&init_user_ns, current_fsgid()),
cfs_curproc_cap_pack(), rdev, &request);
ll_finish_md_op_data(op_data);
- if (err)
- GOTO(err_exit, err);
+ if (err) {
+ /* If the client doesn't know where to create a subdirectory (or
+ * in case of a race that sends the RPC to the wrong MDS), the
+ * MDS will return -EREMOTE and the client will fetch the layout
+ * for the directory, either from the local xattr cache or the
+ * MDS, then create the directory on the right MDT. */
+ if (err == -EREMOTE) {
+ struct lmv_user_md *lum;
+ int rc;
+
+ ptlrpc_req_finished(request);
+ request = NULL;
+
+ OBD_ALLOC_PTR(lum);
+ if (lum == NULL)
+ GOTO(err_exit, err = -ENOMEM);
+
+ rc = ll_getxattr_common(dir, XATTR_NAME_DEFAULT_LMV,
+ lum, sizeof(*lum),
+ OBD_MD_FLXATTR);
+ if (rc < 0) {
+ OBD_FREE_PTR(lum);
+ if (rc == -ENODATA)
+ GOTO(err_exit, err);
+ else
+ GOTO(err_exit, rc);
+ }
+
+ ll_i2info(dir)->lli_def_stripe_offset =
+ le32_to_cpu(lum->lum_stripe_offset);
+ OBD_FREE_PTR(lum);
+ goto again;
+ }
+ GOTO(err_exit, err);
+ }
ll_update_times(request, dir);
EXIT;
err_exit:
- ptlrpc_req_finished(request);
+ if (request != NULL)
+ ptlrpc_req_finished(request);
return err;
}
RETURN(rc);
}
-int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
-{
- struct mdt_body *body;
- struct lov_mds_md *eadata;
- struct lov_stripe_md *lsm = NULL;
- struct obd_trans_info oti = { 0 };
- struct obdo *oa;
- struct obd_capa *oc = NULL;
- int rc;
- ENTRY;
-
- /* req is swabbed so this is safe */
- body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
- if (!(body->mbo_valid & OBD_MD_FLEASIZE))
- RETURN(0);
-
- if (body->mbo_eadatasize == 0) {
- CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
- GOTO(out, rc = -EPROTO);
- }
-
- /* The MDS sent back the EA because we unlinked the last reference
- * to this file. Use this EA to unlink the objects on the OST.
- * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
- * check it is complete and sensible. */
- eadata = req_capsule_server_sized_get(&request->rq_pill, &RMF_MDT_MD,
- body->mbo_eadatasize);
- LASSERT(eadata != NULL);
-
- rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->mbo_eadatasize);
- if (rc < 0) {
- CERROR("obd_unpackmd: %d\n", rc);
- GOTO(out, rc);
- }
- LASSERT(rc >= sizeof(*lsm));
-
- OBDO_ALLOC(oa);
- if (oa == NULL)
- GOTO(out_free_memmd, rc = -ENOMEM);
-
- oa->o_oi = lsm->lsm_oi;
- oa->o_mode = body->mbo_mode & S_IFMT;
- oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
-
- if (body->mbo_valid & OBD_MD_FLCOOKIE) {
- oa->o_valid |= OBD_MD_FLCOOKIE;
- oti.oti_logcookies =
- req_capsule_server_sized_get(&request->rq_pill,
- &RMF_LOGCOOKIES,
- sizeof(struct llog_cookie) *
- lsm->lsm_stripe_count);
- if (oti.oti_logcookies == NULL) {
- oa->o_valid &= ~OBD_MD_FLCOOKIE;
- body->mbo_valid &= ~OBD_MD_FLCOOKIE;
- }
- }
-
- if (body->mbo_valid & OBD_MD_FLOSSCAPA) {
- rc = md_unpack_capa(ll_i2mdexp(dir), request, &RMF_CAPA2, &oc);
- if (rc)
- GOTO(out_free_memmd, rc);
- }
-
- rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti,
- ll_i2mdexp(dir), oc);
- capa_put(oc);
- if (rc)
- CERROR("obd destroy objid "DOSTID" error %d\n",
- POSTID(&lsm->lsm_oi), rc);
-out_free_memmd:
- obd_free_memmd(ll_i2dtexp(dir), &lsm);
- OBDO_FREE(oa);
-out:
- return rc;
-}
-
/* ll_unlink() doesn't update the inode with the new link count.
* Instead, ll_ddelete() and ll_d_iput() will update it based upon if
* there is any lock existing. They will recycle dentries and inodes
ll_update_times(request, dir);
ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
- rc = ll_objects_destroy(request, dir);
out:
ptlrpc_req_finished(request);
RETURN(rc);
ll_update_times(request, src);
ll_update_times(request, tgt);
ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
- err = ll_objects_destroy(request, src);
}
ptlrpc_req_finished(request);