Commit a3c849f1 authored by Vitaly Fertman's avatar Vitaly Fertman Committed by Greg Kroah-Hartman
Browse files

staging: lustre: ldlm: xattr locks are lost on mdt



On the server side mdt_intent_getxattr() can return EFAULT if a
buffer cannot be found, it is returned after lock_replace, where a
new lock is installed into lockp. An error forces ldlm_lock_enqueue()
to destroy the original lock, but ldlm_handle_enqueue0() drops the
reference on the new lock. The xattr client code implied intent
error is returned under a lock, which is immediately cancelled.
Check if a lock obtained and cancel it properly for error cases.
Note: we should support both cases for interop needs, an intent
error under a lock and with a lock abort. Keep returning a lock
with an intent error for interop purposes for now, to be dropped
later when client will get old enough. make all intent ops to
work through md_intent_lock: getxattr and layout, which should
extract the intent error.

Signed-off-by: default avatarVitaly Fertman <vitaly.fertman@seagate.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-7433
Seagate-bug-id: MRP-3072 MRP-3137
Reviewed-on: http://review.whamcloud.com/17220


Reviewed-by: default avatarAndrew Perepechko <andrew.perepechko@seagate.com>
Reviewed-by: default avatarAndriy Skulysh <andriy.skulysh@seagate.com>
Tested-by: default avatarElena V. Gryaznova <elena.gryaznova@seagate.com>
Reviewed-by: default avatarJohn L. Hammond <john.hammond@intel.com>
Reviewed-by: default avatarLai Siyao <lai.siyao@intel.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarJames Simmons <jsimmons@infradead.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8c493188
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -909,8 +909,7 @@ struct md_ops {
		      const void *, size_t, umode_t, uid_t, gid_t,
		      cfs_cap_t, __u64, struct ptlrpc_request **);
	int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
		       const union ldlm_policy_data *,
		       struct lookup_intent *, struct md_op_data *,
		       const union ldlm_policy_data *, struct md_op_data *,
		       struct lustre_handle *, __u64);
	int (*getattr)(struct obd_export *, struct md_op_data *,
		       struct ptlrpc_request **);
+1 −2
Original line number Diff line number Diff line
@@ -1241,7 +1241,6 @@ static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
static inline int md_enqueue(struct obd_export *exp,
			     struct ldlm_enqueue_info *einfo,
			     const union ldlm_policy_data *policy,
			     struct lookup_intent *it,
			     struct md_op_data *op_data,
			     struct lustre_handle *lockh,
			     __u64 extra_lock_flags)
@@ -1250,7 +1249,7 @@ static inline int md_enqueue(struct obd_export *exp,

	EXP_CHECK_MD_OP(exp, enqueue);
	EXP_MD_COUNTER_INCREMENT(exp, enqueue);
	rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
	rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
					extra_lock_flags);
	return rc;
}
+6 −10
Original line number Diff line number Diff line
@@ -2514,7 +2514,7 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
	       PFID(ll_inode2fid(inode)), flock.l_flock.pid, flags,
	       einfo.ei_mode, flock.l_flock.start, flock.l_flock.end);

	rc = md_enqueue(sbi->ll_md_exp, &einfo, &flock, NULL, op_data, &lockh,
	rc = md_enqueue(sbi->ll_md_exp, &einfo, &flock, op_data, &lockh,
			flags);

	/* Restore the file lock type if not TEST lock. */
@@ -2527,7 +2527,7 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)

	if (rc2 && file_lock->fl_type != F_UNLCK) {
		einfo.ei_mode = LCK_NL;
		md_enqueue(sbi->ll_md_exp, &einfo, &flock, NULL, op_data,
		md_enqueue(sbi->ll_md_exp, &einfo, &flock, op_data,
			   &lockh, flags);
		rc = rc2;
	}
@@ -3474,12 +3474,7 @@ static int ll_layout_refresh_locked(struct inode *inode)
	struct lookup_intent   it;
	struct lustre_handle   lockh;
	enum ldlm_mode	       mode;
	struct ldlm_enqueue_info einfo = {
		.ei_type = LDLM_IBITS,
		.ei_mode = LCK_CR,
		.ei_cb_bl = &ll_md_blocking_ast,
		.ei_cb_cp = &ldlm_completion_ast,
	};
	struct ptlrpc_request *req;
	int rc;

again:
@@ -3503,13 +3498,13 @@ static int ll_layout_refresh_locked(struct inode *inode)
	/* have to enqueue one */
	memset(&it, 0, sizeof(it));
	it.it_op = IT_LAYOUT;
	lockh.cookie = 0ULL;

	LDLM_DEBUG_NOLOCK("%s: requeue layout lock for file " DFID "(%p)",
			  ll_get_fsname(inode->i_sb, NULL, 0),
			  PFID(&lli->lli_fid), inode);

	rc = md_enqueue(sbi->ll_md_exp, &einfo, NULL, &it, op_data, &lockh, 0);
	rc = md_intent_lock(sbi->ll_md_exp, op_data, &it, &req,
			    &ll_md_blocking_ast, 0);
	ptlrpc_req_finished(it.it_request);
	it.it_request = NULL;

@@ -3522,6 +3517,7 @@ static int ll_layout_refresh_locked(struct inode *inode)
	if (rc == 0) {
		/* set lock data in case this is a new lock */
		ll_set_lock_data(sbi->ll_md_exp, inode, &it, NULL);
		lockh.cookie = it.it_lock_handle;
		rc = ll_layout_lock_set(&lockh, mode, inode);
		if (rc == -EAGAIN)
			goto again;
+27 −48
Original line number Diff line number Diff line
@@ -272,12 +272,6 @@ static int ll_xattr_find_get_lock(struct inode *inode,
	struct lustre_handle lockh = { 0 };
	struct md_op_data *op_data;
	struct ll_inode_info *lli = ll_i2info(inode);
	struct ldlm_enqueue_info einfo = {
		.ei_type = LDLM_IBITS,
		.ei_mode = it_to_lock_mode(oit),
		.ei_cb_bl = &ll_md_blocking_ast,
		.ei_cb_cp = &ldlm_completion_ast,
	};
	struct ll_sb_info *sbi = ll_i2sbi(inode);
	struct obd_export *exp = sbi->ll_md_exp;
	int rc;
@@ -308,8 +302,9 @@ static int ll_xattr_find_get_lock(struct inode *inode,

	op_data->op_valid = OBD_MD_FLXATTR | OBD_MD_FLXATTRLS;

	rc = md_enqueue(exp, &einfo, NULL, oit, op_data, &lockh, 0);
	rc = md_intent_lock(exp, op_data, oit, req, &ll_md_blocking_ast, 0);
	ll_finish_md_op_data(op_data);
	*req = oit->it_request;

	if (rc < 0) {
		CDEBUG(D_CACHE,
@@ -319,7 +314,6 @@ static int ll_xattr_find_get_lock(struct inode *inode,
		return rc;
	}

	*req = oit->it_request;
out:
	down_write(&lli->lli_xattrs_list_rwsem);
	mutex_unlock(&lli->lli_xattrs_enq_lock);
@@ -330,16 +324,15 @@ static int ll_xattr_find_get_lock(struct inode *inode,
/**
 * Refill the xattr cache.
 *
 * Fetch and cache the whole of xattrs for @inode, acquiring
 * a read or a write xattr lock depending on operation in @oit.
 * Intent is dropped on exit unless the operation is setxattr.
 * Fetch and cache the whole of xattrs for @inode, acquiring a read lock.
 *
 * \retval 0       no error occurred
 * \retval -EPROTO network protocol error
 * \retval -ENOMEM not enough memory for the cache
 */
static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
static int ll_xattr_cache_refill(struct inode *inode)
{
	struct lookup_intent oit = { .it_op = IT_GETXATTR };
	struct ll_sb_info *sbi = ll_i2sbi(inode);
	struct ptlrpc_request *req = NULL;
	const char *xdata, *xval, *xtail, *xvtail;
@@ -348,40 +341,31 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
	__u32 *xsizes;
	int rc, i;

	rc = ll_xattr_find_get_lock(inode, oit, &req);
	rc = ll_xattr_find_get_lock(inode, &oit, &req);
	if (rc)
		goto out_no_unlock;
		goto err_req;

	/* Do we have the data at this point? */
	if (ll_xattr_cache_valid(lli)) {
		ll_stats_ops_tally(sbi, LPROC_LL_GETXATTR_HITS, 1);
		ll_intent_drop_lock(&oit);
		rc = 0;
		goto out_maybe_drop;
		goto err_req;
	}

	/* Matched but no cache? Cancelled on error by a parallel refill. */
	if (unlikely(!req)) {
		CDEBUG(D_CACHE, "cancelled by a parallel getxattr\n");
		ll_intent_drop_lock(&oit);
		rc = -EIO;
		goto out_maybe_drop;
	}

	if (oit->it_status < 0) {
		CDEBUG(D_CACHE,
		       "getxattr intent returned %d for fid " DFID "\n",
		       oit->it_status, PFID(ll_inode2fid(inode)));
		rc = oit->it_status;
		/* xattr data is so large that we don't want to cache it */
		if (rc == -ERANGE)
			rc = -EAGAIN;
		goto out_destroy;
		goto err_unlock;
	}

	body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
	if (!body) {
		CERROR("no MDT BODY in the refill xattr reply\n");
		rc = -EPROTO;
		goto out_destroy;
		goto err_cancel;
	}
	/* do not need swab xattr data */
	xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
@@ -393,7 +377,7 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
	if (!xdata || !xval || !xsizes) {
		CERROR("wrong setxattr reply\n");
		rc = -EPROTO;
		goto out_destroy;
		goto err_cancel;
	}

	xtail = xdata + body->mbo_eadatasize;
@@ -429,7 +413,7 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
		}
		if (rc < 0) {
			ll_xattr_cache_destroy_locked(lli);
			goto out_destroy;
			goto err_cancel;
		}
		xdata += strlen(xdata) + 1;
		xval  += *xsizes;
@@ -439,28 +423,24 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
	if (xdata != xtail || xval != xvtail)
		CERROR("a hole in xattr data\n");

	ll_set_lock_data(sbi->ll_md_exp, inode, oit, NULL);

	goto out_maybe_drop;
out_maybe_drop:

		ll_intent_drop_lock(oit);
	ll_set_lock_data(sbi->ll_md_exp, inode, &oit, NULL);
	ll_intent_drop_lock(&oit);

	if (rc != 0)
		up_write(&lli->lli_xattrs_list_rwsem);
out_no_unlock:
	ptlrpc_req_finished(req);

	return rc;

out_destroy:
	up_write(&lli->lli_xattrs_list_rwsem);

err_cancel:
	ldlm_lock_decref_and_cancel((struct lustre_handle *)
					&oit->it_lock_handle,
					oit->it_lock_mode);
				    &oit.it_lock_handle,
				    oit.it_lock_mode);
err_unlock:
	up_write(&lli->lli_xattrs_list_rwsem);
err_req:
	if (rc == -ERANGE)
		rc = -EAGAIN;

	goto out_no_unlock;
	ptlrpc_req_finished(req);
	return rc;
}

/**
@@ -480,7 +460,6 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
int ll_xattr_cache_get(struct inode *inode, const char *name, char *buffer,
		       size_t size, __u64 valid)
{
	struct lookup_intent oit = { .it_op = IT_GETXATTR };
	struct ll_inode_info *lli = ll_i2info(inode);
	int rc = 0;

@@ -489,7 +468,7 @@ int ll_xattr_cache_get(struct inode *inode, const char *name, char *buffer,
	down_read(&lli->lli_xattrs_list_rwsem);
	if (!ll_xattr_cache_valid(lli)) {
		up_read(&lli->lli_xattrs_list_rwsem);
		rc = ll_xattr_cache_refill(inode, &oit);
		rc = ll_xattr_cache_refill(inode);
		if (rc)
			return rc;
		downgrade_write(&lli->lli_xattrs_list_rwsem);
+8 −4
Original line number Diff line number Diff line
@@ -447,6 +447,9 @@ static int lmv_intent_lookup(struct obd_export *exp,
		}
	}

	if (!it_has_reply_body(it))
		return 0;

	/*
	 * MDS has returned success. Probably name has been resolved in
	 * remote inode. Let's check this.
@@ -483,7 +486,7 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
	       (int)op_data->op_namelen, op_data->op_name,
	       PFID(&op_data->op_fid1));

	if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_LAYOUT))
	if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_LAYOUT | IT_GETXATTR))
		rc = lmv_intent_lookup(exp, op_data, it, reqp, cb_blocking,
				       extra_lock_flags);
	else if (it->it_op & IT_OPEN)
@@ -497,7 +500,8 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,

		if (it->it_lock_mode) {
			lock_handle.cookie = it->it_lock_handle;
			ldlm_lock_decref(&lock_handle, it->it_lock_mode);
			ldlm_lock_decref_and_cancel(&lock_handle,
						    it->it_lock_mode);
		}

		it->it_lock_handle = 0;
@@ -505,7 +509,7 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,

		if (it->it_remote_lock_mode) {
			lock_handle.cookie = it->it_remote_lock_handle;
			ldlm_lock_decref(&lock_handle,
			ldlm_lock_decref_and_cancel(&lock_handle,
						    it->it_remote_lock_mode);
		}

Loading