#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
-# include <linux/buffer_head.h>
-# include <linux/workqueue.h>
-#else
-# include <linux/locks.h>
-#endif
+#include <linux/buffer_head.h>
+#include <linux/workqueue.h>
#include <obd_class.h>
#include <obd_lov.h>
LASSERT(atomic_read(&mfd->mfd_refcount) > 0 &&
atomic_read(&mfd->mfd_refcount) < 0x5a5a);
if (atomic_dec_and_test(&mfd->mfd_refcount)) {
- LASSERT(list_empty(&mfd->mfd_handle.h_link));
- OBD_FREE(mfd, sizeof *mfd);
+ OBD_FREE_RCU(mfd, sizeof *mfd, &mfd->mfd_handle);
}
}
struct mds_update_record *rec,
struct mds_obd *mds, struct obd_device *obd,
struct dentry *dchild, void **handle,
- obd_id **ids)
+ struct lov_mds_md **objid)
{
struct inode *inode = dchild->d_inode;
struct obd_trans_info oti = { 0 };
if (!S_ISREG(inode->i_mode))
RETURN(0);
- if (rec->ur_flags & MDS_OPEN_DELAY_CREATE ||
- !(rec->ur_flags & FMODE_WRITE))
+ if (!md_should_create(rec->ur_flags))
RETURN(0);
body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
if (body->valid & OBD_MD_FLEASIZE)
RETURN(0);
- OBD_ALLOC(*ids, mds->mds_lov_desc.ld_tgt_count * sizeof(**ids));
- if (*ids == NULL)
- RETURN(-ENOMEM);
oti_init(&oti, req);
- oti.oti_objid = *ids;
/* replay case */
if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
GOTO(out_ids, rc);
}
- mds_objids_from_lmm(*ids, lmm, &mds->mds_lov_desc);
-
rc = fsfilt_set_md(obd, inode, *handle, lmm, lmm_size, "lov");
if (rc)
CERROR("open replay failed to set md:%d\n", rc);
LASSERT(lmm_buf);
memcpy(lmm_buf, lmm, lmm_size);
+ *objid = lmm_buf;
RETURN(rc);
}
- if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_ALLOC_OBDO))
+ if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOC_OBDO))
GOTO(out_ids, rc = -ENOMEM);
- oinfo.oi_oa = obdo_alloc();
+ OBDO_ALLOC(oinfo.oi_oa);
if (oinfo.oi_oa == NULL)
GOTO(out_ids, rc = -ENOMEM);
oinfo.oi_oa->o_uid = 0; /* must have 0 uid / gid on OST */
if (rc)
GOTO(out_oa, rc);
}
- rc = obd_create(mds->mds_osc_exp, oinfo.oi_oa,
+ rc = obd_create(mds->mds_osc_exp, oinfo.oi_oa,
&oinfo.oi_md, &oti);
if (rc) {
int level = D_ERROR;
GOTO(out_oa, rc);
}
oinfo.oi_md->lsm_object_id = oinfo.oi_oa->o_id;
+ oinfo.oi_md->lsm_object_gr = oinfo.oi_oa->o_gr;
}
- if (inode->i_size) {
- oinfo.oi_oa->o_size = inode->i_size;
- obdo_from_inode(oinfo.oi_oa, inode, OBD_MD_FLTYPE |
- OBD_MD_FLATIME | OBD_MD_FLMTIME |
+ if (i_size_read(inode)) {
+ oinfo.oi_oa->o_size = i_size_read(inode);
+ obdo_from_inode(oinfo.oi_oa, inode, OBD_MD_FLTYPE |
+ OBD_MD_FLATIME | OBD_MD_FLMTIME |
OBD_MD_FLCTIME | OBD_MD_FLSIZE);
/* pack lustre id to OST */
if (IS_ERR(*handle)) {
rc = PTR_ERR(*handle);
*handle = NULL;
- GOTO(out_oa, rc);
+ GOTO(free_diskmd, rc);
}
rc = fsfilt_set_md(obd, inode, *handle, lmm, lmm_size, "lov");
lmm_buf = lustre_msg_buf(req->rq_repmsg, offset, lmm_size);
LASSERT(lmm_buf);
memcpy(lmm_buf, lmm, lmm_size);
+
+ *objid = lmm_buf; // save for mds_lov_update_objid
+
+free_diskmd:
obd_free_diskmd(mds->mds_osc_exp, &lmm);
- out_oa:
+out_oa:
oti_free_cookies(&oti);
- obdo_free(oinfo.oi_oa);
- out_ids:
- if (rc) {
- OBD_FREE(*ids, mds->mds_lov_desc.ld_tgt_count * sizeof(**ids));
- *ids = NULL;
- }
+ OBDO_FREE(oinfo.oi_oa);
+out_ids:
if (oinfo.oi_md)
obd_free_memmd(mds->mds_osc_exp, &oinfo.oi_md);
RETURN(rc);
struct mds_obd *mds = mds_req2mds(req);
struct obd_device *obd = req->rq_export->exp_obd;
struct mds_file_data *mfd = NULL;
- obd_id *ids = NULL; /* object IDs created */
+ struct lov_mds_md *lmm; /* object IDs created */
int rc = 0;
ENTRY;
!(body->valid & OBD_MD_FLMODEASIZE)) {
/* no EA: create objects */
rc = mds_create_objects(req, DLM_REPLY_REC_OFF + 1, rec,
- mds, obd, dchild, handle, &ids);
+ mds, obd, dchild, handle, &lmm);
if (rc) {
CERROR("mds_create_objects: rc = %d\n", rc);
UNLOCK_INODE_MUTEX(dchild->d_inode);
CDEBUG(D_INODE, "mfd %p, cookie "LPX64"\n", mfd,
mfd->mfd_handle.h_cookie);
- if (ids != NULL) {
- mds_lov_update_objids(obd, ids);
- OBD_FREE(ids, sizeof(*ids) * mds->mds_lov_desc.ld_tgt_count);
- }
+ if (lmm != NULL)
+ mds_lov_update_objids(obd, lmm);
+
if (rc) /* coverity[deadcode] */
mds_mfd_unlink(mfd, 1);
rc = mds_finish_open(req, dchild, body, flags, &handle, rec, rep, NULL);
rc = mds_finish_transno(mds, dchild->d_inode, handle,
- req, rc, rep ? rep->lock_policy_res1 : 0);
+ req, rc, rep ? rep->lock_policy_res1 : 0, 0);
/* XXX what do we do here if mds_finish_transno itself failed? */
l_dput(dchild);
rc = lustre_pack_reply(req, 2, size, NULL);
if (rc)
RETURN(rc);
+
repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
sizeof(*repbody));
if (child_lockh == NULL)
child_lockh = &lockh;
- rc = ldlm_cli_enqueue_local(obd->obd_namespace, child_res_id,
+ rc = ldlm_cli_enqueue_local(obd->obd_namespace, &child_res_id,
LDLM_PLAIN, NULL, LCK_EX, &lock_flags,
ldlm_blocking_ast, ldlm_completion_ast,
NULL, NULL, 0, NULL, child_lockh);
mds_counter_incr(req->rq_export, LPROC_MDS_OPEN);
- OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PAUSE_OPEN | OBD_FAIL_ONCE,
- (obd_timeout + 1) / 4);
+ OBD_FAIL_TIMEOUT_ORSET(OBD_FAIL_MDS_PAUSE_OPEN, OBD_FAIL_ONCE,
+ (obd_timeout + 1) / 4);
CLASSERT(MAXQUOTAS < 4);
if (offset == DLM_INTENT_REC_OFF) { /* intent */
if (rec->ur_flags & (MDS_OPEN_CREAT | MDS_OPEN_JOIN_FILE))
parent_mode = LCK_EX;
dparent = mds_fid2locked_dentry(obd, rec->ur_fid1, NULL, parent_mode,
- &parent_lockh, rec->ur_name,
- rec->ur_namelen - 1,
- MDS_INODELOCK_UPDATE);
+ &parent_lockh, MDS_INODELOCK_UPDATE);
if (IS_ERR(dparent)) {
rc = PTR_ERR(dparent);
if (rc != -ENOENT) {
}
/* Step 2: Lookup the child */
- dchild = ll_lookup_one_len(rec->ur_name, dparent, rec->ur_namelen - 1);
+
+ if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
+ (rec->ur_flags & MDS_OPEN_LOCK) && (rec->ur_namelen == 1)) {
+ /* hack for nfsd with no_subtree_check, it will use anon
+ * dentry w/o filename to open the file. the anon dentry's
+ * parent was set to itself, so rec->ur_fid1 is the file.
+ * And in MDC it cannot derive the dentry's parent dentry,
+ * hence the file's name, so we hack here in MDS,
+ * refer to bug 13030. */
+ dchild = mds_fid2dentry(mds, rec->ur_fid1, NULL);
+ } else {
+ dchild = ll_lookup_one_len(rec->ur_name, dparent,
+ rec->ur_namelen - 1);
+ }
if (IS_ERR(dchild)) {
rc = PTR_ERR(dchild);
dchild = NULL; /* don't confuse mds_finish_transno() below */
GOTO(cleanup, rc = -ENOTDIR);
}
- if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_CREATE)) {
- obd_fail_loc = OBD_FAIL_LDLM_REPLY | OBD_FAIL_ONCE;
+ if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_OPEN_CREATE,
+ OBD_FAIL_LDLM_REPLY | OBD_FAIL_ONCE)) {
GOTO(cleanup, rc = -EAGAIN);
}
else
child_mode = LCK_CR;
- if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
+ if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
(rec->ur_flags & MDS_OPEN_LOCK)) {
/* In case of replay we do not get a lock assuming that the
caller has it already */
child_res_id.name[0] = dchild->d_inode->i_ino;
child_res_id.name[1] = dchild->d_inode->i_generation;
- rc = ldlm_cli_enqueue_local(obd->obd_namespace, child_res_id,
- LDLM_IBITS, &policy, child_mode,
- &lock_flags, ldlm_blocking_ast,
+ rc = ldlm_cli_enqueue_local(obd->obd_namespace, &child_res_id,
+ LDLM_IBITS, &policy, child_mode,
+ &lock_flags, ldlm_blocking_ast,
ldlm_completion_ast, NULL, NULL,
0, NULL, child_lockh);
if (rc != ELDLM_OK)
cleanup:
rc = mds_finish_transno(mds, dchild ? dchild->d_inode : NULL, handle,
- req, rc, rep ? rep->lock_policy_res1 : 0);
+ req, rc, rep ? rep->lock_policy_res1 : 0, 0);
cleanup_no_trans:
switch (cleanup_phase) {
/* trigger dqacq on the owner of child and parent */
lquota_adjust(mds_quota_interface_ref, obd, qcids, qpids, rc,
FSFILT_OP_CREATE);
+
+ /* If we have not taken the "open" lock, we may not return 0 here,
+ because caller expects 0 to mean "lock is taken", and it needs
+ nonzero return here for caller to return EDLM_LOCK_ABORTED to
+ client. Later caller should rewrite the return value back to zero
+ if it to be used any further
+ */
RETURN(rc);
}
* (it will not even _have_ an entry in last_rcvd anymore).
*
* Returns EAGAIN if the client needs to get more data and re-close. */
-int mds_mfd_close(struct ptlrpc_request *req, int offset,
- struct obd_device *obd, struct mds_file_data *mfd,
- int unlink_orphan, struct lov_mds_md *lmm, int lmm_size,
+int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd,
+ struct mds_file_data *mfd, int unlink_orphan,
+ struct lov_mds_md *lmm, int lmm_size,
struct llog_cookie *logcookies, int cookies_size,
__u64 *valid)
{
inode->i_nlink, mds_orphan_open_count(inode));
last_orphan = mds_orphan_open_dec_test(inode) &&
- mds_inode_is_orphan(inode);
- MDS_UP_WRITE_ORPHAN_SEM(inode);
+ mds_inode_is_orphan(inode);
/* this is half of the actual "close" */
if (mfd->mfd_mode & FMODE_WRITE) {
} else if (mfd->mfd_mode & MDS_FMODE_EXEC) {
mds_allow_write_access(inode);
}
+ /* here writecount change also needs protection from orphan write sem.
+ * so drop orphan write sem after mds_put_write_access, bz 12888. */
+ MDS_UP_WRITE_ORPHAN_SEM(inode);
if (last_orphan && unlink_orphan) {
int stripe_count = 0;
LASSERT(rc == 0); /* mds_put_write_access must have succeeded */
- CDEBUG(D_HA, "destroying orphan object %s\n", fidname);
+ CDEBUG(D_INODE, "destroying orphan object %s\n", fidname);
if ((S_ISREG(inode->i_mode) && inode->i_nlink != 1) ||
(S_ISDIR(inode->i_mode) && inode->i_nlink != 2))
handle = NULL;
GOTO(cleanup, rc);
}
+
if (lmm != NULL && (*valid & OBD_MD_FLEASIZE) &&
mds_log_op_unlink(obd, lmm, lmm_size,
logcookies, cookies_size) > 0) {
cleanup:
if (req != NULL && reply_body != NULL) {
- rc = mds_finish_transno(mds, pending_dir, handle, req, rc, 0);
+ rc = mds_finish_transno(mds, pending_dir, handle, req, rc, 0, 0);
} else if (handle) {
int err = fsfilt_commit(obd, pending_dir, handle, 0);
if (err) {
ENTRY;
rc = lustre_pack_reply(req, 4, repsize, NULL);
- if (rc) {
- CERROR("lustre_pack_reply: rc = %d\n", rc);
+ if (rc)
req->rq_status = rc;
/* continue on to drop local open even if we can't send reply */
- } else {
+ else
MDS_CHECK_RESENT(req, mds_reconstruct_generic(req));
- }
- CDEBUG(D_HA, "close req->rep_len %d mdsize %d cookiesize %d\n",
+ CDEBUG(D_INODE, "close req->rep_len %d mdsize %d cookiesize %d\n",
req->rq_replen,
obd->u.mds.mds_max_mdsize, obd->u.mds.mds_max_cookiesize);
mds_counter_incr(req->rq_export, LPROC_MDS_CLOSE);
RETURN(-EFAULT);
}
- if (body->flags & MDS_BFLAG_UNCOMMITTED_WRITES)
- /* do some stuff */ ;
-
spin_lock(&med->med_open_lock);
mfd = mds_handle2mfd(&body->handle);
if (mfd == NULL) {
}
rc = lustre_pack_reply(req, 2, size, NULL);
- if (rc) {
- CERROR("lustre_pack_reply: rc = %d\n", rc);
+ if (rc)
req->rq_status = rc;
- }
RETURN(0);
}