Whamcloud - gitweb
b=201
authorpschwan <pschwan>
Wed, 30 Oct 2002 08:20:49 +0000 (08:20 +0000)
committerpschwan <pschwan>
Wed, 30 Oct 2002 08:20:49 +0000 (08:20 +0000)
b=285
- Added generation numbers to MDS locks (still need to for OSC locks, bug 294)
- fixup the inode pointer in the ldlm_lock after intent gives us a lock on a
  different resource (bug 285)
- cancel locks when the inodes are flushed from the cache (bug 201)
- fix serious cache coherancy bugs by really tying locks to dentries:
  - always return 0 from revalidate2 for a negative dentry, forcing lookup2
  - when MDS locks are cancelled, unhash the associated dentries (but do NOT
    remove them from the aliases list)
    - avoid calling the cancellation callback at shutdown and clear_inode time,
      by adding yet another flag, this time to cancel_unused
  - lookup2 searches for old dentries that may satisfy a new request, and may
    reuse a dentry that we previously unhashed

We broke hard links even more than they were before--you've been warned!

15 files changed:
lustre/include/linux/lustre_dlm.h
lustre/include/linux/lustre_lite.h
lustre/include/linux/lustre_mds.h
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_request.c
lustre/ldlm/ldlm_resource.c
lustre/llite/dcache.c
lustre/llite/namei.c
lustre/llite/recover.c
lustre/llite/super.c
lustre/lov/lov_obd.c
lustre/mdc/mdc_request.c
lustre/mds/handler.c
lustre/osc/osc_request.c

index 5798815..5dcd21f 100644 (file)
@@ -41,6 +41,8 @@ typedef enum {
 #define LDLM_FL_CANCEL         (1 << 8)
 #define LDLM_FL_REPLAY         (1 << 9)
 #define LDLM_FL_INTENT_ONLY    (1 << 10) /* don't grant lock, just do intent */
+#define LDLM_FL_LOCAL_ONLY     (1 << 11) /* see ldlm_cli_cancel_unused */
+#define LDLM_FL_NO_CALLBACK    (1 << 12) /* see ldlm_cli_cancel_unused */
 
 #define LDLM_CB_BLOCKING    1
 #define LDLM_CB_CANCELING   2
@@ -234,14 +236,15 @@ do {                                                                          \
         }                                                                     \
         if (lock->l_resource->lr_type == LDLM_EXTENT) {                       \
                 CDEBUG(D_DLMTRACE, "### " format                              \
-                       " (%s: lock %p(rc=%d/%d,%d) mode %s/%s on res "        \
-                       LPU64" (rc=%d) type %s ["LPU64"->"LPU64"] remote "     \
+                       " (%s: lock %p(rc=%d/%d,%d) mode %s/%s on res "LPU64   \
+                       "/"LPU64" (rc=%d) type %s ["LPU64"->"LPU64"] remote "  \
                        LPX64")\n" , ## a,                                     \
                        lock->l_resource->lr_namespace->ns_name, lock,         \
                        lock->l_refc, lock->l_readers, lock->l_writers,        \
                        ldlm_lockname[lock->l_granted_mode],                   \
                        ldlm_lockname[lock->l_req_mode],                       \
                        lock->l_resource->lr_name[0],                          \
+                       lock->l_resource->lr_name[1],                          \
                        atomic_read(&lock->l_resource->lr_refcount),           \
                        ldlm_typename[lock->l_resource->lr_type],              \
                        lock->l_extent.start, lock->l_extent.end,              \
@@ -250,13 +253,14 @@ do {                                                                          \
         }                                                                     \
         {                                                                     \
                 CDEBUG(D_DLMTRACE, "### " format                              \
-                       " (%s: lock %p(rc=%d/%d,%d) mode %s/%s on res "        \
-                       LPU64" (rc=%d) type %s remote "LPX64")\n" , ## a,      \
+                       " (%s: lock %p(rc=%d/%d,%d) mode %s/%s on res "LPU64   \
+                       "/"LPU64" (rc=%d) type %s remote "LPX64")\n" , ## a,   \
                        lock->l_resource->lr_namespace->ns_name, lock,         \
                        lock->l_refc, lock->l_readers, lock->l_writers,        \
                        ldlm_lockname[lock->l_granted_mode],                   \
                        ldlm_lockname[lock->l_req_mode],                       \
                        lock->l_resource->lr_name[0],                          \
+                       lock->l_resource->lr_name[1],                          \
                        atomic_read(&lock->l_resource->lr_refcount),           \
                        ldlm_typename[lock->l_resource->lr_type],              \
                        lock->l_remote_handle.addr);                           \
@@ -284,7 +288,8 @@ void ldlm_unregister_intent(void);
 void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh);
 struct ldlm_lock *__ldlm_handle2lock(struct lustre_handle *, int strict);
 void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh);
-void ldlm_cancel_callback(struct ldlm_lock *lock);
+void ldlm_cancel_callback(struct ldlm_lock *);
+int ldlm_lock_set_data(struct lustre_handle *, void *data, int datalen);
 
 static inline struct ldlm_lock *ldlm_handle2lock(struct lustre_handle *h)
 {
@@ -398,7 +403,7 @@ int ldlm_server_ast(struct lustre_handle *lockh, struct ldlm_lock_desc *new,
                     void *data, __u32 data_len);
 int ldlm_cli_convert(struct lustre_handle *, int new_mode, int *flags);
 int ldlm_cli_cancel(struct lustre_handle *lockh);
-int ldlm_cli_cancel_unused(struct ldlm_namespace *, __u64 *, int local_only);
+int ldlm_cli_cancel_unused(struct ldlm_namespace *, __u64 *, int flags);
 
 /* mds/handler.c */
 /* This has to be here because recurisve inclusion sucks. */
index 13c1e5d..99d93b2 100644 (file)
@@ -153,6 +153,12 @@ int ll_lock(struct inode *dir, struct dentry *dentry,
             struct lookup_intent *it, struct lustre_handle *lockh);
 int ll_unlock(__u32 mode, struct lustre_handle *lockh);
 
+typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
+                                struct dentry **, struct lookup_intent *,
+                                int offset, obd_id ino);
+int ll_intent_lock(struct inode *parent, struct dentry **,
+                   struct lookup_intent *, intent_finish_cb);
+
 /* dcache.c */
 void ll_intent_release(struct dentry *, struct lookup_intent *);
 int ll_set_dd(struct dentry *de);
index 16c9c6f..dfa3bec 100644 (file)
@@ -154,6 +154,7 @@ int mdc_enqueue(struct lustre_handle *conn, int lock_type,
                 struct lookup_intent *it, int lock_mode, struct inode *dir,
                 struct dentry *de, struct lustre_handle *lockh, char *tgt,
                 int tgtlen, void *data, int datalen);
+int mdc_cancel_unused(struct lustre_handle *conn, struct inode *, int flags);
 int mdc_getlovinfo(struct obd_device *obd, struct lustre_handle *mdc_connh,
                    struct ptlrpc_request **request);
 int mdc_getstatus(struct lustre_handle *conn,
index 2bf4fa7..269f394 100644 (file)
@@ -858,6 +858,22 @@ void ldlm_lock_cancel(struct ldlm_lock *lock)
         EXIT;
 }
 
+int ldlm_lock_set_data(struct lustre_handle *lockh, void *data, int datalen)
+{
+        struct ldlm_lock *lock = ldlm_handle2lock(lockh);
+        ENTRY;
+
+        if (lock == NULL)
+                RETURN(-EINVAL);
+
+        lock->l_data = data;
+        lock->l_data_len = datalen;
+
+        LDLM_LOCK_PUT(lock);
+
+        RETURN(0);
+}
+
 void ldlm_cancel_locks_for_export(struct obd_export *exp)
 {
         struct list_head *iter, *n; /* MUST BE CALLED "n"! */
index 27cb758..cc4ebe5 100644 (file)
@@ -701,6 +701,7 @@ EXPORT_SYMBOL(ldlm_lock_match);
 EXPORT_SYMBOL(ldlm_lock_addref);
 EXPORT_SYMBOL(ldlm_lock_decref);
 EXPORT_SYMBOL(ldlm_lock_change_resource);
+EXPORT_SYMBOL(ldlm_lock_set_data);
 EXPORT_SYMBOL(ldlm_cli_convert);
 EXPORT_SYMBOL(ldlm_cli_enqueue);
 EXPORT_SYMBOL(ldlm_cli_cancel);
index 4117b67..a823007 100644 (file)
@@ -256,7 +256,7 @@ int ldlm_cli_enqueue(struct lustre_handle *connh,
                        body->lock_desc.l_extent.start,
                        body->lock_desc.l_extent.end,
                        reply->lock_extent.start, reply->lock_extent.end);
-                cookie = &reply->lock_extent; /* FIXME bug 629281 */
+                cookie = &reply->lock_extent; /* FIXME bug 267 */
                 cookielen = sizeof(reply->lock_extent);
         }
 
@@ -458,7 +458,7 @@ int ldlm_cli_cancel(struct lustre_handle *lockh)
                 if (!req)
                         GOTO(out, rc = -ENOMEM);
 
-                /* XXX FIXME bug 625069 */
+                /* XXX FIXME bug 249 */
                 req->rq_request_portal = LDLM_REQUEST_PORTAL;
                 req->rq_reply_portal = LDLM_REPLY_PORTAL;
 
@@ -493,7 +493,7 @@ int ldlm_cli_cancel(struct lustre_handle *lockh)
 }
 
 static int ldlm_cli_cancel_unused_resource(struct ldlm_namespace *ns,
-                                           __u64 *res_id, int local_only)
+                                           __u64 *res_id, int flags)
 {
         struct ldlm_resource *res;
         struct list_head *tmp, *next, list = LIST_HEAD_INIT(list);
@@ -535,9 +535,14 @@ static int ldlm_cli_cancel_unused_resource(struct ldlm_namespace *ns,
                 int rc;
                 w = list_entry(tmp, struct ldlm_ast_work, w_list);
 
-                if (local_only)
+                /* Prevent the cancel callback from being called by setting
+                 * LDLM_FL_CANCEL in the lock.  Very sneaky. -p */
+                if (flags & LDLM_FL_NO_CALLBACK)
+                        w->w_lock->l_flags |= LDLM_FL_CANCEL;
+
+                if (flags & LDLM_FL_LOCAL_ONLY) {
                         ldlm_lock_cancel(w->w_lock);
-                else {
+                else {
                         ldlm_lock2handle(w->w_lock, &lockh);
                         rc = ldlm_cli_cancel(&lockh);
                         if (rc != ELDLM_OK)
@@ -559,12 +564,12 @@ static int ldlm_cli_cancel_unused_resource(struct ldlm_namespace *ns,
  * If 'local_only' is true, throw the locks away without trying to notify the
  * server. */
 int ldlm_cli_cancel_unused(struct ldlm_namespace *ns, __u64 *res_id,
-                           int local_only)
+                           int flags)
 {
         int i;
 
         if (res_id)
-                RETURN(ldlm_cli_cancel_unused_resource(ns, res_id, local_only));
+                RETURN(ldlm_cli_cancel_unused_resource(ns, res_id, flags));
 
         l_lock(&ns->ns_lock);
         for (i = 0; i < RES_HASH_SIZE; i++) {
@@ -576,7 +581,7 @@ int ldlm_cli_cancel_unused(struct ldlm_namespace *ns, __u64 *res_id,
                         ldlm_resource_getref(res);
 
                         rc = ldlm_cli_cancel_unused_resource(ns, res->lr_name,
-                                                             local_only);
+                                                             flags);
 
                         if (rc)
                                 CERROR("cancel_unused_res ("LPU64"): %d\n",
index 683f1c9..954e46c 100644 (file)
@@ -133,6 +133,9 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
                 LDLM_LOCK_GET(lock);
 
+                /* At shutdown time, don't call the cancellation callback */
+                lock->l_flags |= LDLM_FL_CANCEL;
+
                 if (client) {
                         struct lustre_handle lockh;
                         ldlm_lock2handle(lock, &lockh);
index 0990504..fbbc305 100644 (file)
@@ -73,14 +73,21 @@ void ll_intent_release(struct dentry *de, struct lookup_intent *it)
 
 int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
 {
-        int ll_intent_lock(struct inode *parent, struct dentry *dentry,
-                           struct lookup_intent *it, void *);
         int rc;
         ENTRY;
 
-        rc = ll_intent_lock(de->d_parent->d_inode, de, it, NULL);
+        /* We don't want to cache negative dentries, so return 0 immediately.
+         * We believe that this is safe, that negative dentries cannot be
+         * pinned by someone else */
+        if (de->d_inode == NULL) {
+                CDEBUG(D_INODE, "negative dentry: ret 0 to force lookup2\n");
+                RETURN(0);
+        }
+
+        rc = ll_intent_lock(de->d_parent->d_inode, &de, it, NULL);
         if (rc < 0) {
                 /* Something bad happened; overwrite it_status? */
+                CERROR("ll_intent_lock: %d\n", rc);
         }
 
         if (it != NULL && it->it_status == 0) {
@@ -131,8 +138,8 @@ int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it)
         /* If the dentry is busy, we won't get called in lookup2 if we
          * return 0, so return 1.
          *
-         * This is a temporary fix for bug 618962, but is one of the causes of
-         * 619078. */
+         * This is a temporary fix for bug 224, but is one of the causes of
+         * 225. */
         CDEBUG(D_INFO, "d_count: %d\n", atomic_read(&de->d_count));
         if (it && atomic_read(&de->d_count) > 1) {
                 CDEBUG(D_INFO, "returning 1 for %*s during %s because d_count "
index 06e3fae..c09924d 100644 (file)
@@ -166,14 +166,11 @@ static int ll_intent_to_lock_mode(struct lookup_intent *it)
 #define LL_LOOKUP_POSITIVE 1
 #define LL_LOOKUP_NEGATIVE 2
 
-typedef int (*intent_finish_cb)(int flag, struct ptlrpc_request *,
-                                struct dentry *, struct lookup_intent *,
-                                int offset, obd_id ino);
-
-int ll_intent_lock(struct inode *parent, struct dentry *dentry,
+int ll_intent_lock(struct inode *parent, struct dentry **de,
                    struct lookup_intent *it,
                    intent_finish_cb intent_finish)
 {
+        struct dentry *dentry = *de;
         struct ll_sb_info *sbi = ll_i2sbi(parent);
         struct lustre_handle lockh;
         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
@@ -248,12 +245,14 @@ int ll_intent_lock(struct inode *parent, struct dentry *dentry,
                                 atomic_inc(&request->rq_refcount);
                                 GOTO(out, flag = LL_LOOKUP_NEGATIVE);
                         }
+                        /* Fall through to update attibutes. */
                 } else if (it->it_op & (IT_GETATTR | IT_SETATTR | IT_LOOKUP |
                                         IT_READLINK)) {
                         /* For check ops, we want the lookup to succeed */
                         it->it_data = NULL;
                         if (it->it_status)
                                 GOTO(out, flag = LL_LOOKUP_NEGATIVE);
+                        /* Fall through to update attibutes. */
                 } else if (it->it_op & (IT_RENAME | IT_LINK)) {
                         /* For rename, we want the source lookup to succeed */
                         if (it->it_status) {
@@ -261,22 +260,27 @@ int ll_intent_lock(struct inode *parent, struct dentry *dentry,
                                 GOTO(drop_req, rc = it->it_status);
                         }
                         it->it_data = dentry;
+                        /* Fall through to update attibutes. */
                 } else if (it->it_op & (IT_UNLINK | IT_RMDIR)) {
                         /* For remove ops, we want the lookup to succeed unless
                          * the file truly doesn't exist */
                         it->it_data = NULL;
                         if (it->it_status == -ENOENT)
                                 GOTO(out, flag = LL_LOOKUP_NEGATIVE);
+                        /* No point in updating attributes that we're about to
+                         * unlink.  -phil */
                         GOTO(out, flag = LL_LOOKUP_POSITIVE);
                 } else if (it->it_op == IT_OPEN) {
                         it->it_data = NULL;
                         if (it->it_status && it->it_status != -EEXIST)
                                 GOTO(out, flag = LL_LOOKUP_NEGATIVE);
+                        /* Fall through to update attibutes. */
                 } else if (it->it_op & (IT_RENAME2 | IT_LINK2)) {
                         it->it_data = NULL;
                         /* This means the target lookup is negative */
                         if (mds_body->valid == 0)
                                 GOTO(out, flag = LL_LOOKUP_NEGATIVE);
+                        /* XXX bug 289: should we maybe fall through here? -p */
                         GOTO(out, flag = LL_LOOKUP_POSITIVE);
                 }
 
@@ -323,10 +327,12 @@ int ll_intent_lock(struct inode *parent, struct dentry *dentry,
 
         EXIT;
  out:
-        if (intent_finish != NULL)
-                rc = intent_finish(flag, request, dentry, it, offset, ino);
-        else
+        if (intent_finish != NULL) {
+                rc = intent_finish(flag, request, de, it, offset, ino);
+                dentry = *de; /* intent_finish may change *de */
+        } else {
                 ptlrpc_req_finished(request);
+        }
 
         if (it->it_op == IT_LOOKUP || rc < 0)
                 ll_intent_release(dentry, it);
@@ -340,10 +346,43 @@ int ll_intent_lock(struct inode *parent, struct dentry *dentry,
         return rc;
 }
 
-static int lookup2_finish(int flag, struct ptlrpc_request *request,
-                          struct dentry *dentry, struct lookup_intent *it,
-                          int offset, obd_id ino)
+/* Search "inode"'s alias list for a dentry that has the same name and parent as
+ * de.  If found, return it.  If not found, return de. */
+static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
+{
+       struct list_head *tmp;
+
+       spin_lock(&dcache_lock);
+        list_for_each(tmp, &inode->i_dentry) {
+               struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
+
+                /* We are called here with 'de' already on the aliases list. */
+                if (dentry == de)
+                        continue;
+
+                if (dentry->d_parent != de->d_parent)
+                        continue;
+
+                if (dentry->d_name.len != de->d_name.len)
+                        continue;
+
+                if (memcmp(dentry->d_name.name, de->d_name.name,
+                           de->d_name.len) != 0)
+                        continue;
+
+                spin_unlock(&dcache_lock);
+                d_rehash(dentry);
+                return dget(dentry);
+       }
+       spin_unlock(&dcache_lock);
+        return de;
+}
+
+static int
+lookup2_finish(int flag, struct ptlrpc_request *request, struct dentry **de,
+               struct lookup_intent *it, int offset, obd_id ino)
 {
+        struct dentry *dentry = *de, *saved = *de;
         struct inode *inode = NULL;
         struct ll_read_inode2_cookie lic;
 
@@ -368,6 +407,15 @@ static int lookup2_finish(int flag, struct ptlrpc_request *request,
                          * I think it is, but double-check refcounts. -phil */
                         RETURN(-ENOMEM);
                 }
+
+                dentry = *de = ll_find_alias(inode, dentry);
+
+                /* We asked for a lock on the directory, and may have been
+                 * granted a lock on the inode.  Just in case, fixup the data
+                 * pointer. */
+                ldlm_lock_set_data((struct lustre_handle *)it->it_lock_handle,
+                                   inode, sizeof(*inode));
+
                 EXIT;
         } else {
                 ENTRY;
@@ -381,7 +429,8 @@ static int lookup2_finish(int flag, struct ptlrpc_request *request,
         } else
                 CERROR("NOT allocating fsdata - already set\n");
 
-        d_add(dentry, inode);
+        if (dentry == saved)
+                d_add(dentry, inode);
 
         if (it->it_status == 0) {
                 LL_SAVE_INTENT(dentry, it);
@@ -399,15 +448,19 @@ static int lookup2_finish(int flag, struct ptlrpc_request *request,
 static struct dentry *ll_lookup2(struct inode *parent, struct dentry *dentry,
                                  struct lookup_intent *it)
 {
+        struct dentry *save = dentry;
         int rc;
 
-        rc = ll_intent_lock(parent, dentry, it, lookup2_finish);
+        rc = ll_intent_lock(parent, &dentry, it, lookup2_finish);
         if (rc < 0) {
                 CERROR("ll_intent_lock: %d\n", rc);
                 return ERR_PTR(rc);
         }
 
-        return 0;
+        if (dentry == save)
+                return NULL;
+        else
+                return dentry;
 }
 
 static struct inode *ll_create_node(struct inode *dir, const char *name,
@@ -486,6 +539,14 @@ static struct inode *ll_create_node(struct inode *dir, const char *name,
                 GOTO(out, -EIO);
         }
 
+        if (it && it->it_disposition) {
+                /* We asked for a lock on the directory, but were
+                 * granted a lock on the inode.  Since we finally have
+                 * an inode pointer, stuff it in the lock. */
+                ldlm_lock_set_data((struct lustre_handle *)it->it_lock_handle,
+                                   inode, sizeof(*inode));
+        }
+
         EXIT;
  out:
         if (lsm && lmm)
index 04df215..d512ce2 100644 (file)
@@ -112,7 +112,7 @@ static void prepare_osc(struct obd_import *imp)
 static void prepare_mdc(struct obd_import *imp)
 {
         struct ldlm_namespace *ns = imp->imp_obd->obd_namespace;
-        ldlm_cli_cancel_unused(ns, NULL, 1 /* local only */);
+        ldlm_cli_cancel_unused(ns, NULL, LDLM_FL_LOCAL_ONLY);
 }
 
 static int ll_prepare_recovery(struct ptlrpc_connection *conn)
index 2d28a69..71cfc32 100644 (file)
@@ -264,8 +264,16 @@ static void ll_put_super(struct super_block *sb)
 
 static void ll_clear_inode(struct inode *inode)
 {
+        struct ll_sb_info *sbi = ll_i2sbi(inode);
+        int rc;
         ENTRY;
 
+        rc = mdc_cancel_unused(&sbi->ll_mdc_conn, inode, LDLM_FL_NO_CALLBACK);
+        if (rc < 0) {
+                CERROR("obd_cancel_unused: %d\n", rc);
+                /* XXX FIXME do something dramatic */
+        }
+
         if (atomic_read(&inode->i_count) == 0) {
                 struct ll_inode_info *lli = ll_i2info(inode);
                 struct lov_stripe_md *lsm = lli->lli_smd;
@@ -280,6 +288,7 @@ static void ll_clear_inode(struct inode *inode)
                         lli->lli_symlink_name = NULL;
                 }
         }
+
         EXIT;
 }
 
index 0621574..6e70e3b 100644 (file)
@@ -1301,7 +1301,7 @@ static int lov_cancel(struct lustre_handle *conn, struct lov_stripe_md *lsm,
 }
 
 static int lov_cancel_unused(struct lustre_handle *conn,
-                             struct lov_stripe_md *lsm, int local_only)
+                             struct lov_stripe_md *lsm, int flags)
 {
         struct obd_export *export = class_conn2export(conn);
         struct lov_obd *lov;
@@ -1325,7 +1325,7 @@ static int lov_cancel_unused(struct lustre_handle *conn,
                 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
                 submd.lsm_stripe_count = 0;
                 rc = obd_cancel_unused(&lov->tgts[loi->loi_ost_idx].conn,
-                                       &submd, local_only);
+                                       &submd, flags);
                 if (rc)
                         CERROR("Error cancel unused objid "LPX64" subobj "LPX64
                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
index 4478db2..62d4610 100644 (file)
@@ -155,21 +155,44 @@ int mdc_getattr(struct lustre_handle *conn,
         return rc;
 }
 
+static void d_delete_aliases(struct inode *inode)
+{
+        struct dentry *dentry;
+       struct list_head *tmp;
+        int dentry_count = 0;
+        ENTRY;
+
+       spin_lock(&dcache_lock);
+        list_for_each(tmp, &inode->i_dentry) {
+                dentry = list_entry(tmp, struct dentry, d_alias);
+                dentry_count++;
+        }
+
+        /* XXX FIXME tell phil/peter that you see this -- unless you're playing
+         * with hard links, in which case, stop. */
+        LASSERT(dentry_count <= 1);
+
+        if (dentry_count == 0) {
+                spin_unlock(&dcache_lock);
+                EXIT;
+                return;
+        }
+
+        CDEBUG(D_INODE, "d_deleting dentry %p\n", dentry);
+        dget_locked(dentry);
+        spin_unlock(&dcache_lock);
+        d_delete(dentry);
+        dput(dentry);
+        EXIT;
+}
+
 static int mdc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                             void *data, __u32 data_len, int flag)
 {
         int rc;
-        struct inode *inode = data;
         struct lustre_handle lockh;
         ENTRY;
 
-        if (data_len != sizeof(*inode)) {
-                CERROR("data_len should be %d, but is %d\n", sizeof(*inode),
-                       data_len);
-                LBUG();
-                RETURN(-EINVAL);
-        }
-
         switch (flag) {
         case LDLM_CB_BLOCKING:
                 ldlm_lock2handle(lock, &lockh);
@@ -179,16 +202,24 @@ static int mdc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                         RETURN(rc);
                 }
                 break;
-        case LDLM_CB_CANCELING:
-                /* FIXME: do something better than throwing away everything */
-                if (inode == NULL)
-                        LBUG();
+        case LDLM_CB_CANCELING: {
+                /* Invalidate all dentries associated with this inode */
+                struct inode *inode = data;
+
+                LASSERT(inode != NULL);
+                LASSERT(data_len == sizeof(*inode));
+
                 if (S_ISDIR(inode->i_mode)) {
                         CDEBUG(D_INODE, "invalidating inode %ld\n",
                                inode->i_ino);
                         ll_invalidate_inode_pages(inode);
                 }
+
+                LASSERT(igrab(inode) == inode);
+                d_delete_aliases(inode);
+                iput(inode);
                 break;
+        }
         default:
                 LBUG();
         }
@@ -373,7 +404,7 @@ int mdc_enqueue(struct lustre_handle *conn, int lock_type,
 {
         struct ptlrpc_request *req;
         struct obd_device *obddev = class_conn2obd(conn);
-        __u64 res_id[RES_NAME_SIZE] = {dir->i_ino};
+        __u64 res_id[RES_NAME_SIZE] = {dir->i_ino, (__u64)dir->i_generation};
         int size[6] = {sizeof(struct ldlm_request), sizeof(struct ldlm_intent)};
         int rc, flags = 0;
         int repsize[3] = {sizeof(struct ldlm_reply),
@@ -542,6 +573,15 @@ int mdc_enqueue(struct lustre_handle *conn, int lock_type,
         RETURN(0);
 }
 
+int mdc_cancel_unused(struct lustre_handle *conn, struct inode *inode,
+                      int flags)
+{
+        __u64 res_id[RES_NAME_SIZE] = {inode->i_ino, inode->i_generation};
+        struct obd_device *obddev = class_conn2obd(conn);
+        ENTRY;
+        RETURN(ldlm_cli_cancel_unused(obddev->obd_namespace, res_id, flags));
+}
+
 struct replay_open_data {
         struct lustre_handle *fh;
 };
@@ -760,6 +800,7 @@ MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(mdc_getstatus);
 EXPORT_SYMBOL(mdc_getlovinfo);
 EXPORT_SYMBOL(mdc_enqueue);
+EXPORT_SYMBOL(mdc_cancel_unused);
 EXPORT_SYMBOL(mdc_getattr);
 EXPORT_SYMBOL(mdc_statfs);
 EXPORT_SYMBOL(mdc_create);
index c61591f..87f2cec 100644 (file)
@@ -1389,7 +1389,6 @@ static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
                         }
                 }
 
-
                 if (flags & LDLM_FL_INTENT_ONLY) {
                         LDLM_DEBUG(lock, "INTENT_ONLY, aborting lock");
                         RETURN(ELDLM_LOCK_ABORTED);
@@ -1397,6 +1396,7 @@ static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
                 /* Give the client a lock on the child object, instead of the
                  * parent that it requested. */
                 new_resid[0] = NTOH__u32(mds_rep->ino);
+                new_resid[1] = NTOH__u32(mds_rep->generation);
                 if (new_resid[0] == 0)
                         LBUG();
                 old_res = lock->l_resource->lr_name[0];
index 2bc9093..610287a 100644 (file)
@@ -709,12 +709,12 @@ static int osc_cancel(struct lustre_handle *oconn, struct lov_stripe_md *md,
 }
 
 static int osc_cancel_unused(struct lustre_handle *connh,
-                             struct lov_stripe_md *lsm, int local)
+                             struct lov_stripe_md *lsm, int flags)
 {
         struct obd_device *obddev = class_conn2obd(connh);
         __u64 res_id[RES_NAME_SIZE] = { lsm->lsm_object_id };
 
-        return ldlm_cli_cancel_unused(obddev->obd_namespace, res_id, local);
+        return ldlm_cli_cancel_unused(obddev->obd_namespace, res_id, flags);
 }
 
 static int osc_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)