/* lock types */
char *ldlm_lockname[] = {
- [0] "--",
+ [0] "--",
[LCK_EX] "EX",
[LCK_PW] "PW",
[LCK_PR] "PR",
[LCK_NL] "NL"
};
char *ldlm_typename[] = {
- [LDLM_PLAIN] "PLN",
- [LDLM_EXTENT] "EXT",
+ [LDLM_PLAIN] "PLN",
+ [LDLM_EXTENT] "EXT",
[LDLM_MDSINTENT] "INT"
};
+char *ldlm_it2str(int it)
+{
+ switch (it) {
+ case IT_OPEN:
+ return "open";
+ case IT_CREAT:
+ return "creat";
+ case (IT_OPEN | IT_CREAT):
+ return "open|creat";
+ case IT_MKDIR:
+ return "mkdir";
+ case IT_LINK:
+ return "link";
+ case IT_SYMLINK:
+ return "symlink";
+ case IT_UNLINK:
+ return "unlink";
+ case IT_RMDIR:
+ return "rmdir";
+ case IT_RENAME:
+ return "rename";
+ case IT_RENAME2:
+ return "rename2";
+ case IT_READDIR:
+ return "readdir";
+ case IT_GETATTR:
+ return "getattr";
+ case IT_SETATTR:
+ return "setattr";
+ case IT_READLINK:
+ return "readlink";
+ case IT_MKNOD:
+ return "mknod";
+ case IT_LOOKUP:
+ return "lookup";
+ default:
+ CERROR("Unknown intent %d\n", it);
+ return "UNKNOWN";
+ }
+}
+
extern kmem_cache_t *ldlm_lock_slab;
-int (*mds_reint_p)(int offset, struct ptlrpc_request *req) = NULL;
-int (*mds_getattr_name_p)(int offset, struct ptlrpc_request *req) = NULL;
static int ldlm_plain_compat(struct ldlm_lock *a, struct ldlm_lock *b);
-static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
- ldlm_mode_t mode, void *data);
-ldlm_res_compat ldlm_res_compat_table [] = {
+ldlm_res_compat ldlm_res_compat_table[] = {
[LDLM_PLAIN] ldlm_plain_compat,
[LDLM_EXTENT] ldlm_extent_compat,
[LDLM_MDSINTENT] ldlm_plain_compat
};
-ldlm_res_policy ldlm_res_policy_table [] = {
+ldlm_res_policy ldlm_res_policy_table[] = {
[LDLM_PLAIN] NULL,
[LDLM_EXTENT] ldlm_extent_policy,
- [LDLM_MDSINTENT] ldlm_intent_policy
+ [LDLM_MDSINTENT] NULL
};
+void ldlm_register_intent(int (*arg) (struct ldlm_lock * lock, void *req_cookie,
+ ldlm_mode_t mode, void *data))
+{
+ ldlm_res_policy_table[LDLM_MDSINTENT] = arg;
+}
+
+void ldlm_unregister_intent()
+{
+ ldlm_res_policy_table[LDLM_MDSINTENT] = NULL;
+}
/*
* REFCOUNTED LOCK OBJECTS
ldlm_resource_put(lock->l_resource);
if (lock->l_parent)
- ldlm_lock_put(lock->l_parent);
+ LDLM_LOCK_PUT(lock->l_parent);
if (lock->l_refc == 0 && (lock->l_flags & LDLM_FL_DESTROYED)) {
+ lock->l_resource = NULL;
+ LDLM_DEBUG(lock, "final lock_put on destroyed lock, freeing");
if (lock->l_connection)
ptlrpc_put_connection(lock->l_connection);
CDEBUG(D_MALLOC, "kfreed 'lock': %d at %p (tot 1).\n",
lock->l_flags = LDLM_FL_DESTROYED;
l_unlock(&lock->l_resource->lr_namespace->ns_lock);
- ldlm_lock_put(lock);
+ LDLM_LOCK_PUT(lock);
EXIT;
}
}
/* this is the extra refcount, to prevent the lock
evaporating */
- ldlm_lock_get(lock);
+ LDLM_LOCK_GET(lock);
RETURN(lock);
}
ENTRY;
l_lock(&ns->ns_lock);
- type = lock->l_resource->lr_type;
+ if (memcmp(new_resid, lock->l_resource->lr_name,
+ sizeof(lock->l_resource->lr_name)) == 0) {
+ /* Nothing to do */
+ l_unlock(&ns->ns_lock);
+ RETURN(0);
+ }
+ type = lock->l_resource->lr_type;
+ if (new_resid[0] == 0)
+ LBUG();
lock->l_resource = ldlm_resource_get(ns, NULL, new_resid, type, 1);
if (lock->l_resource == NULL) {
LBUG();
void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh)
{
- lockh->addr = (__u64)(unsigned long)lock;
+ lockh->addr = (__u64) (unsigned long)lock;
lockh->cookie = lock->l_random;
}
struct ldlm_lock *ldlm_handle2lock(struct lustre_handle *handle)
{
- struct ldlm_lock *lock = NULL;
+ struct ldlm_lock *lock = NULL, *retval = NULL;
ENTRY;
if (!handle || !handle->addr)
l_lock(&lock->l_resource->lr_namespace->ns_lock);
if (lock->l_random != handle->cookie)
- GOTO(out, handle = NULL);
+ GOTO(out, NULL);
if (lock->l_flags & LDLM_FL_DESTROYED)
- GOTO(out, handle = NULL);
+ GOTO(out, NULL);
- ldlm_lock_get(lock);
+ retval = LDLM_LOCK_GET(lock);
EXIT;
- out:
+ out:
l_unlock(&lock->l_resource->lr_namespace->ns_lock);
- return lock;
+ return retval;
}
-static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
- ldlm_mode_t mode, void *data)
-{
- struct ptlrpc_request *req = req_cookie;
- int rc = 0;
- ENTRY;
-
- if (!req_cookie)
- RETURN(0);
-
- if (req->rq_reqmsg->bufcount > 1) {
- /* an intent needs to be considered */
- struct ldlm_intent *it = lustre_msg_buf(req->rq_reqmsg, 1);
- struct mds_body *mds_rep;
- struct ldlm_reply *rep;
- __u64 new_resid[3] = {0, 0, 0}, old_res;
- int bufcount = -1, rc, size[3] = {sizeof(struct ldlm_reply),
- sizeof(struct mds_body),
- sizeof(struct obdo)};
-
- it->opc = NTOH__u64(it->opc);
-
- LDLM_DEBUG(lock, "intent policy, opc: %Ld", it->opc);
-
- /* prepare reply */
- switch(it->opc) {
- case IT_GETATTR:
- /* Note that in the negative case you may be returning
- * a file and its obdo */
- case IT_CREAT:
- case IT_CREAT|IT_OPEN:
- case IT_MKDIR:
- case IT_SYMLINK:
- case IT_MKNOD:
- case IT_LINK:
- case IT_OPEN:
- case IT_RENAME:
- bufcount = 3;
- break;
- case IT_UNLINK:
- bufcount = 2;
- size[1] = sizeof(struct obdo);
- break;
- case IT_RMDIR:
- case IT_RENAME2:
- bufcount = 1;
- break;
- default:
- LBUG();
- }
-
- rc = lustre_pack_msg(bufcount, size, NULL, &req->rq_replen,
- &req->rq_repmsg);
- if (rc) {
- rc = req->rq_status = -ENOMEM;
- RETURN(rc);
- }
-
- rep = lustre_msg_buf(req->rq_repmsg, 0);
- rep->lock_policy_res1 = 1;
-
- /* execute policy */
- switch (it->opc) {
- case IT_CREAT:
- case IT_CREAT|IT_OPEN:
- case IT_MKDIR:
- case IT_SETATTR:
- case IT_SYMLINK:
- case IT_MKNOD:
- case IT_LINK:
- case IT_UNLINK:
- case IT_RMDIR:
- case IT_RENAME2:
- if (mds_reint_p == NULL)
- mds_reint_p =
- inter_module_get_request
- ("mds_reint", "mds");
- if (IS_ERR(mds_reint_p)) {
- CERROR("MDSINTENT locks require the MDS "
- "module.\n");
- LBUG();
- RETURN(-EINVAL);
- }
- rc = mds_reint_p(2, req);
- if (rc || req->rq_status != 0) {
- rep->lock_policy_res2 = req->rq_status;
- RETURN(ELDLM_LOCK_ABORTED);
- }
- break;
- case IT_GETATTR:
- case IT_READDIR:
- case IT_RENAME:
- case IT_OPEN:
- if (mds_getattr_name_p == NULL)
- mds_getattr_name_p =
- inter_module_get_request
- ("mds_getattr_name", "mds");
- if (IS_ERR(mds_getattr_name_p)) {
- CERROR("MDSINTENT locks require the MDS "
- "module.\n");
- LBUG();
- RETURN(-EINVAL);
- }
- rc = mds_getattr_name_p(2, req);
- /* FIXME: we need to sit down and decide on who should
- * set req->rq_status, who should return negative and
- * positive return values, and what they all mean. */
- if (rc || req->rq_status != 0) {
- rep->lock_policy_res2 = req->rq_status;
- RETURN(ELDLM_LOCK_ABORTED);
- }
- break;
- case IT_READDIR|IT_OPEN:
- LBUG();
- break;
- default:
- CERROR("Unhandled intent\n");
- LBUG();
- }
-
- if (it->opc == IT_UNLINK || it->opc == IT_RMDIR ||
- it->opc == IT_RENAME || it->opc == IT_RENAME2)
- RETURN(ELDLM_LOCK_ABORTED);
-
- rep->lock_policy_res2 = req->rq_status;
- mds_rep = lustre_msg_buf(req->rq_repmsg, 1);
- new_resid[0] = NTOH__u32(mds_rep->ino);
- if (new_resid[0] == 0)
- LBUG();
- old_res = lock->l_resource->lr_name[0];
-
- CDEBUG(D_INFO, "remote intent: locking %d instead of"
- "%ld\n", mds_rep->ino, (long)old_res);
-
- ldlm_lock_change_resource(lock, new_resid);
- if (lock->l_resource == NULL) {
- LBUG();
- RETURN(-ENOMEM);
- }
- LDLM_DEBUG(lock, "intent policy, old res %ld",
- (long)old_res);
- RETURN(ELDLM_LOCK_CHANGED);
- } else {
- int size = sizeof(struct ldlm_reply);
- rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen,
- &req->rq_repmsg);
- if (rc) {
- CERROR("out of memory\n");
- LBUG();
- RETURN(-ENOMEM);
- }
- }
- RETURN(rc);
-}
static int ldlm_plain_compat(struct ldlm_lock *a, struct ldlm_lock *b)
{
OBD_ALLOC(w, sizeof(*w));
if (!w) {
LBUG();
- return;
+ GOTO(out, 0);
}
if (new) {
ldlm_lock2desc(new, &w->w_desc);
}
- w->w_lock = ldlm_lock_get(lock);
+ w->w_lock = LDLM_LOCK_GET(lock);
list_add(&w->w_list, lock->l_resource->lr_tmp);
- out:
+ out:
l_unlock(&lock->l_resource->lr_namespace->ns_lock);
return;
}
lock = ldlm_handle2lock(lockh);
ldlm_lock_addref_internal(lock, mode);
- ldlm_lock_put(lock);
+ LDLM_LOCK_PUT(lock);
}
/* only called for local locks */
else
lock->l_writers++;
l_unlock(&lock->l_resource->lr_namespace->ns_lock);
- ldlm_lock_get(lock);
+ LDLM_LOCK_GET(lock);
LDLM_DEBUG(lock, "ldlm_lock_addref(%s)", ldlm_lockname[mode]);
}
* run the callback. */
if (!lock->l_readers && !lock->l_writers &&
(lock->l_flags & LDLM_FL_CBPENDING)) {
- struct lustre_handle lockh;
-
if (!lock->l_resource->lr_namespace->ns_client) {
CERROR("LDLM_FL_CBPENDING set on non-local lock!\n");
LBUG();
LDLM_DEBUG(lock, "final decref done on cbpending lock");
l_unlock(&lock->l_resource->lr_namespace->ns_lock);
- ldlm_lock2handle(lock, &lockh);
- /* FIXME: -1 is a really, really bad 'desc' */
- lock->l_blocking_ast(&lockh, (void *)-1, lock->l_data,
+ /* FIXME: need a real 'desc' here */
+ lock->l_blocking_ast(lock, NULL, lock->l_data,
lock->l_data_len);
} else
l_unlock(&lock->l_resource->lr_namespace->ns_lock);
- ldlm_lock_put(lock); /* matches the ldlm_lock_get in addref */
- ldlm_lock_put(lock); /* matches the handle2lock above */
+ LDLM_LOCK_PUT(lock); /* matches the ldlm_lock_get in addref */
+ LDLM_LOCK_PUT(lock); /* matches the handle2lock above */
EXIT;
}
static int ldlm_lock_compat_list(struct ldlm_lock *lock, int send_cbs,
- struct list_head *queue)
+ struct list_head *queue)
{
struct list_head *tmp, *pos;
int rc = 1;
EXIT;
}
+/* returns a referenced lock or NULL */
static struct ldlm_lock *search_queue(struct list_head *queue, ldlm_mode_t mode,
struct ldlm_extent *extent)
{
/* Must be called with no resource or lock locks held.
*
* Returns 1 if it finds an already-existing lock that is compatible; in this
- * case, lockh is filled in with a addref()ed lock */
-int ldlm_lock_match(struct ldlm_namespace *ns, __u64 *res_id, __u32 type,
+ * case, lockh is filled in with a addref()ed lock
+*/
+int ldlm_lock_match(struct ldlm_namespace *ns, __u64 * res_id, __u32 type,
void *cookie, int cookielen, ldlm_mode_t mode,
struct lustre_handle *lockh)
{
GOTO(out, rc = 1);
EXIT;
- out:
+ out:
ldlm_resource_put(res);
l_unlock(&ns->ns_lock);
if (lock) {
ldlm_lock2handle(lock, lockh);
- wait_event(lock->l_waitq,
- lock->l_req_mode == lock->l_granted_mode);
+ if (lock->l_completion_ast)
+ lock->l_completion_ast(lock, LDLM_FL_WAIT_NOREPROC);
}
if (rc)
LDLM_DEBUG(lock, "matched");
/* Returns a referenced, lock */
struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
struct lustre_handle *parent_lock_handle,
- __u64 *res_id, __u32 type,
- ldlm_mode_t mode,
- void *data,
- __u32 data_len)
+ __u64 * res_id, __u32 type,
+ ldlm_mode_t mode, void *data, __u32 data_len)
{
struct ldlm_resource *res, *parent_res = NULL;
struct ldlm_lock *lock, *parent_lock;
}
/* Must be called with lock->l_lock and lock->l_resource->lr_lock not held */
-ldlm_error_t ldlm_lock_enqueue(struct ldlm_lock *lock,
+ldlm_error_t ldlm_lock_enqueue(struct ldlm_lock * lock,
void *cookie, int cookie_len,
int *flags,
- ldlm_lock_callback completion,
- ldlm_lock_callback blocking)
+ ldlm_completion_callback completion,
+ ldlm_blocking_callback blocking)
{
struct ldlm_resource *res;
int local;
GOTO(out, ELDLM_OK);
}
- /* If this is a local resource, put it on the appropriate list. */
- /* FIXME: don't like this: can we call ldlm_resource_unlink_lock? */
- list_del_init(&lock->l_res_link);
+ /* This distinction between local lock trees is very important; a client
+ * namespace only has information about locks taken by that client, and
+ * thus doesn't have enough information to decide for itself if it can
+ * be granted (below). In this case, we do exactly what the server
+ * tells us to do, as dictated by the 'flags' */
+ ldlm_resource_unlink_lock(lock);
if (local) {
if (*flags & LDLM_FL_BLOCK_CONV)
ldlm_resource_add_lock(res, res->lr_converting.prev,
*flags |= LDLM_FL_BLOCK_WAIT;
GOTO(out, ELDLM_OK);
}
- if (!ldlm_lock_compat(lock,0)) {
+ if (!ldlm_lock_compat(lock, 0)) {
ldlm_resource_add_lock(res, res->lr_waiting.prev, lock);
*flags |= LDLM_FL_BLOCK_GRANTED;
GOTO(out, ELDLM_OK);
ldlm_grant_lock(lock);
EXIT;
- out:
+ out:
/* Don't set 'completion_ast' until here so that if the lock is granted
* immediately we don't do an unnecessary completion call. */
lock->l_completion_ast = completion;
list_for_each_safe(tmp, pos, rpc_list) {
struct ldlm_ast_work *w =
list_entry(tmp, struct ldlm_ast_work, w_list);
- struct lustre_handle lockh;
- ldlm_lock2handle(w->w_lock, &lockh);
if (w->w_blocking)
rc = w->w_lock->l_blocking_ast
- (&lockh, &w->w_desc, w->w_data, w->w_datalen);
+ (w->w_lock, &w->w_desc, w->w_data,
+ w->w_datalen);
else
- rc = w->w_lock->l_completion_ast
- (&lockh, NULL, w->w_data, w->w_datalen);
+ rc = w->w_lock->l_completion_ast(w->w_lock, w->w_flags);
if (rc)
CERROR("Failed AST - should clean & disconnect "
"client\n");
- ldlm_lock_put(w->w_lock);
+ LDLM_LOCK_PUT(w->w_lock);
list_del(&w->w_list);
OBD_FREE(w, sizeof(*w));
}
EXIT;
}
-/* Must be called with lock and lock->l_resource unlocked */
void ldlm_lock_cancel(struct ldlm_lock *lock)
{
struct ldlm_resource *res;
ldlm_resource_unlink_lock(lock);
ldlm_lock_destroy(lock);
l_unlock(&ns->ns_lock);
+ EXIT;
}
-/* Must be called with lock and lock->l_resource unlocked */
struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
int *flags)
{
res->lr_tmp = NULL;
granted = 1;
/* FIXME: completion handling not with ns_lock held ! */
- wake_up(&lock->l_waitq);
+ if (lock->l_completion_ast)
+ lock->l_completion_ast(lock, 0);
}
} else
list_add(&lock->l_res_link, res->lr_converting.prev);
lock->l_version[2], lock->l_version[3]);
CDEBUG(D_OTHER, " -- Lock dump: %p (%s)\n", lock, ver);
+ CDEBUG(D_OTHER, " Node: NID %x (rhandle: %Lx)\n",
+ lock->l_connection->c_peer.peer_nid,
+ lock->l_remote_handle.addr);
CDEBUG(D_OTHER, " Parent: %p\n", lock->l_parent);
CDEBUG(D_OTHER, " Resource: %p (%Ld)\n", lock->l_resource,
lock->l_resource->lr_name[0]);