X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fllite%2Fdcache.c;h=9dba881179a43b4ea5592bff647f8ba7862d745c;hp=577d288a9d117d20b82a3d9229cbf137cc652833;hb=c5050e412572b00cbe93d8517d2d1f767bebfa92;hpb=cc846846900ece1d5b06a4c48176604da5bd90dc diff --git a/lustre/llite/dcache.c b/lustre/llite/dcache.c index 577d288a..9dba881 100644 --- a/lustre/llite/dcache.c +++ b/lustre/llite/dcache.c @@ -1,7 +1,7 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (c) 2001, 2002 Cluster File Systems, Inc. + * Copyright (c) 2001-2003 Cluster File Systems, Inc. * * This file is part of Lustre, http://www.lustre.org. * @@ -20,136 +20,353 @@ */ #include -#include +#include +#include #include #define DEBUG_SUBSYSTEM S_LLITE #include #include +#include #include -extern struct address_space_operations ll_aops; +#include "llite_internal.h" -void ll_release(struct dentry *de) +/* should NOT be called with the dcache lock, see fs/dcache.c */ +static void ll_release(struct dentry *de) { + struct ll_dentry_data *lld; ENTRY; - + LASSERT(de != NULL); + lld = ll_d2d(de); + LASSERT(lld != NULL); + LASSERT(lld->lld_cwd_count == 0); + LASSERT(lld->lld_mnt_count == 0); OBD_FREE(de->d_fsdata, sizeof(struct ll_dentry_data)); + EXIT; } -void ll_intent_release(struct dentry *de) +void ll_set_dd(struct dentry *de) +{ + ENTRY; + LASSERT(de != NULL); + + lock_kernel(); + if (de->d_fsdata == NULL) { + OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data)); + } + unlock_kernel(); + + EXIT; +} + +void ll_intent_release(struct lookup_intent *it) { - struct lookup_intent *it; struct lustre_handle *handle; ENTRY; - it = de->d_it; - if (it == NULL) { - EXIT; - return; + if (it->it_op && it->d.lustre.it_lock_mode) { + handle = (struct lustre_handle *)&it->d.lustre.it_lock_handle; + CDEBUG(D_DLMTRACE, "releasing lock with cookie "LPX64 + " from it %p\n", handle->cookie, it); + ldlm_lock_decref(handle, it->d.lustre.it_lock_mode); + + /* intent_release may be called multiple times, from + this thread and we don't want to double-decref this + lock (see bug 494) */ + it->d.lustre.it_lock_mode = 0; } + it->it_magic = 0; + it->it_op_release = 0; + it->d.lustre.it_disposition = 0; + it->d.lustre.it_data = NULL; + EXIT; +} + +void ll_unhash_aliases(struct inode *inode) +{ + struct list_head *tmp, *head; + struct ll_sb_info *sbi; + ENTRY; - LASSERT(ll_d2d(de) != NULL); - - if (it->it_lock_mode) { - handle = (struct lustre_handle *)it->it_lock_handle; - if (it->it_op == IT_SETATTR) { - int rc; - ldlm_lock_decref(handle, it->it_lock_mode); - rc = ldlm_cli_cancel(handle); - if (rc < 0) - CERROR("ldlm_cli_cancel: %d\n", rc); - } else - ldlm_lock_decref(handle, it->it_lock_mode); + sbi = ll_i2sbi(inode); + + CDEBUG(D_INODE, "marking dentries for ino %lu/%u(%p) invalid\n", + inode->i_ino, inode->i_generation, inode); + + if (inode == NULL) { + CERROR("unexpected NULL inode, tell phil\n"); + return; } - de->d_it = NULL; - //up(&ll_d2d(de)->lld_it_sem); + head = &inode->i_dentry; +restart: + spin_lock(&dcache_lock); + tmp = head; + while ((tmp = tmp->next) != head) { + struct dentry *dentry = list_entry(tmp, struct dentry, d_alias); + if (!atomic_read(&dentry->d_count)) { + dget_locked(dentry); + __d_drop(dentry); + spin_unlock(&dcache_lock); + dput(dentry); + goto restart; + } else { + hlist_del_init(&dentry->d_hash); + dentry->d_flags |= DCACHE_LUSTRE_INVALID; + hlist_add_head(&dentry->d_hash, + &sbi->ll_orphan_dentry_list); + } + } + spin_unlock(&dcache_lock); EXIT; } -int ll_revalidate2(struct dentry *de, int flags, struct lookup_intent *it) +extern struct dentry *ll_find_alias(struct inode *, struct dentry *); + +static int revalidate_it_finish(struct ptlrpc_request *request, int offset, + struct lookup_intent *it, + struct dentry *de) { - struct ll_sb_info *sbi = ll_s2sbi(de->d_sb); - struct lustre_handle lockh; - __u64 res_id[RES_NAME_SIZE] = {0}; - struct obd_device *obddev; + struct ll_sb_info *sbi; int rc = 0; ENTRY; - if (it) { - CDEBUG(D_INFO, "name: %*s, intent: %s\n", de->d_name.len, - de->d_name.name, ldlm_it2str(it->it_op)); - if (it->it_op == IT_RENAME) - it->it_data = de; - } + if (!request) + RETURN(0); - if (!de->d_inode) - GOTO(out, rc = 0); + if (it_disposition(it, DISP_LOOKUP_NEG)) + RETURN(-ENOENT); - obddev = class_conn2obd(&sbi->ll_mdc_conn); - res_id[0] = de->d_inode->i_ino; + sbi = ll_i2sbi(de->d_inode); + rc = ll_prep_inode(sbi->ll_osc_exp, &de->d_inode, request, offset,NULL); - CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id[0]); + RETURN(rc); +} - if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT, - NULL, 0, LCK_PR, &lockh)) { - ldlm_lock_decref(&lockh, LCK_PR); - GOTO(out, rc = 1); +void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry) +{ + LASSERT(it != NULL); + LASSERT(dentry != NULL); + + if (it->d.lustre.it_lock_mode && dentry->d_inode != NULL) { + struct inode *inode = dentry->d_inode; + CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)\n", + inode, inode->i_ino, inode->i_generation); + mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode); } - if (ldlm_lock_match(obddev->obd_namespace, res_id, LDLM_MDSINTENT, - NULL, 0, LCK_PW, &lockh)) { - ldlm_lock_decref(&lockh, LCK_PW); - GOTO(out, rc = 1); + /* drop IT_LOOKUP locks */ + if (it->it_op == IT_LOOKUP) + ll_intent_release(it); +} + +void ll_frob_intent(struct lookup_intent **itp, struct lookup_intent *deft) +{ + struct lookup_intent *it = *itp; +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) + if (it && it->it_magic != INTENT_MAGIC) { + CERROR("WARNING: uninitialized intent\n"); + LBUG(); } + if (it && (it->it_op == IT_GETATTR || it->it_op == 0)) + it->it_op = IT_LOOKUP; + +#endif + if (!it || it->it_op == IT_GETXATTR) + it = *itp = deft; + + it->it_op_release = ll_intent_release; +} + +int ll_revalidate_it(struct dentry *de, int flags, struct lookup_intent *it) +{ + int rc; + struct ll_fid pfid, cfid; + struct it_cb_data icbd; + struct ll_uctxt ctxt; + struct ptlrpc_request *req = NULL; + struct lookup_intent lookup_it = { .it_op = IT_LOOKUP }; + struct obd_export *exp; + + ENTRY; + CDEBUG(D_VFSTRACE, "VFS Op:name=%s,intent=%s\n", de->d_name.name, + LL_IT2STR(it)); + + /* Cached negative dentries are unsafe for now - look them up again */ + if (de->d_inode == NULL) + RETURN(0); + + exp = ll_i2mdcexp(de->d_inode); + ll_inode2fid(&pfid, de->d_parent->d_inode); + ll_inode2fid(&cfid, de->d_inode); + icbd.icbd_parent = de->d_parent->d_inode; + icbd.icbd_childp = &de; + + /* + * never execute intents for mount points + * - attrs will be fixed up in ll_revalidate_inode + */ + if (d_mountpoint(de)) + RETURN(1); - /* 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. */ - CDEBUG(D_INFO, "d_count: %d\n", atomic_read(&de->d_count)); - if (it && atomic_read(&de->d_count) > 0) { - CERROR("returning 1 for %*s during %s because d_count is %d\n", - de->d_name.len, de->d_name.name, ldlm_it2str(it->it_op), - atomic_read(&de->d_count)); - GOTO(out, rc = 1); + ll_frob_intent(&it, &lookup_it); + LASSERT(it); + + ll_i2uctxt(&ctxt, de->d_parent->d_inode, de->d_inode); + + rc = mdc_intent_lock(exp, &ctxt, &pfid, de->d_name.name, de->d_name.len, + NULL, 0, + &cfid, it, flags, &req, ll_mdc_blocking_ast); + /* If req is NULL, then mdc_intent_lock only tried to do a lock match; + * if all was well, it will return 1 if it found locks, 0 otherwise. */ + if (req == NULL && rc >= 0) + GOTO(out, rc); + + if (rc < 0) { + if (rc != -ESTALE) { + CDEBUG(D_INFO, "ll_intent_lock: rc %d : it->it_status " + "%d\n", rc, it->d.lustre.it_status); + } + GOTO(out, rc = 0); } - out: - if (ll_d2d(de) == NULL) { - CERROR("allocating fsdata\n"); - ll_set_dd(de); + rc = revalidate_it_finish(req, 1, it, de); + if (rc != 0) { + ll_intent_release(it); + GOTO(out, rc = 0); } - //down(&ll_d2d(de)->lld_it_sem); - // de->d_it = it; + rc = 1; + /* unfortunately ll_intent_lock may cause a callback and revoke our + dentry */ + spin_lock(&dcache_lock); + hlist_del_init(&de->d_hash); + __d_rehash(de, 0); + spin_unlock(&dcache_lock); + + out: + if (req != NULL && rc == 1) + ptlrpc_req_finished(req); + if (rc == 0) { + ll_unhash_aliases(de->d_inode); + de->d_flags |= DCACHE_LUSTRE_INVALID; + } else { + ll_lookup_finish_locks(it, de); + de->d_flags &= ~DCACHE_LUSTRE_INVALID; + } RETURN(rc); } -int ll_set_dd(struct dentry *de) +/*static*/ void ll_pin(struct dentry *de, struct vfsmount *mnt, int flag) { + struct inode *inode= de->d_inode; + struct ll_sb_info *sbi = ll_i2sbi(inode); + struct ll_dentry_data *ldd = ll_d2d(de); + struct obd_client_handle *handle; + int rc = 0; ENTRY; - LASSERT(de != NULL); + LASSERT(ldd); lock_kernel(); + /* Strictly speaking this introduces an additional race: the + * increments should wait until the rpc has returned. + * However, given that at present the function is void, this + * issue is moot. */ + if (flag == 1 && (++ldd->lld_mnt_count) > 1) { + unlock_kernel(); + EXIT; + return; + } - if (de->d_fsdata != NULL) { - CERROR("dentry %p already has d_fsdata set\n", de); - } else { - OBD_ALLOC(de->d_fsdata, sizeof(struct ll_dentry_data)); - sema_init(&ll_d2d(de)->lld_it_sem, 1); + if (flag == 0 && (++ldd->lld_cwd_count) > 1) { + unlock_kernel(); + EXIT; + return; + } + unlock_kernel(); + + handle = (flag) ? &ldd->lld_mnt_och : &ldd->lld_cwd_och; + rc = obd_pin(sbi->ll_mdc_exp, inode->i_ino, inode->i_generation, + inode->i_mode & S_IFMT, handle, flag); + + if (rc) { + lock_kernel(); + memset(handle, 0, sizeof(*handle)); + if (flag == 0) + ldd->lld_cwd_count--; + else + ldd->lld_mnt_count--; + unlock_kernel(); + } + + EXIT; + return; +} + +/*static*/ void ll_unpin(struct dentry *de, struct vfsmount *mnt, int flag) +{ + struct ll_sb_info *sbi = ll_i2sbi(de->d_inode); + struct ll_dentry_data *ldd = ll_d2d(de); + struct obd_client_handle handle; + int count, rc = 0; + ENTRY; + LASSERT(ldd); + + lock_kernel(); + /* Strictly speaking this introduces an additional race: the + * increments should wait until the rpc has returned. + * However, given that at present the function is void, this + * issue is moot. */ + handle = (flag) ? ldd->lld_mnt_och : ldd->lld_cwd_och; + if (handle.och_magic != OBD_CLIENT_HANDLE_MAGIC) { + /* the "pin" failed */ + unlock_kernel(); + EXIT; + return; } + if (flag) + count = --ldd->lld_mnt_count; + else + count = --ldd->lld_cwd_count; unlock_kernel(); - RETURN(0); + if (count != 0) { + EXIT; + return; + } + + rc = obd_unpin(sbi->ll_mdc_exp, &handle, flag); + EXIT; + return; +} + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +static int ll_revalidate_nd(struct dentry *dentry, struct nameidata *nd) +{ + int rc; + ENTRY; + + if (nd->flags & LOOKUP_LAST && !(nd->flags & LOOKUP_LINK_NOTLAST)) + rc = ll_revalidate_it(dentry, nd->flags, &nd->intent); + else + rc = ll_revalidate_it(dentry, 0, NULL); + + RETURN(rc); } +#endif struct dentry_operations ll_d_ops = { - .d_revalidate2 = ll_revalidate2, - .d_intent_release = ll_intent_release, +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) + .d_revalidate = ll_revalidate_nd, +#else + .d_revalidate_it = ll_revalidate_it, +#endif .d_release = ll_release, +#if 0 + .d_pin = ll_pin, + .d_unpin = ll_unpin, +#endif };