X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fliblustre%2Fnamei.c;h=004461a5fc962cc0918e34ab336aae283d349e9c;hb=e1a430be4a4a08e39b945a35a04c8286353fb6fc;hp=02abb6069e6140ef88b2693ac1af6ce15c87160d;hpb=56a32318ff0509aaddb69466b4f17069c3f207b6;p=fs%2Flustre-release.git diff --git a/lustre/liblustre/namei.c b/lustre/liblustre/namei.c index 02abb60..004461a 100644 --- a/lustre/liblustre/namei.c +++ b/lustre/liblustre/namei.c @@ -1,24 +1,41 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: +/* + * GPL HEADER START * - * Lustre Light name resolution + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * Copyright (c) 2002-2004 Cluster File Systems, Inc. + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * - * This file is part of Lustre, http://www.lustre.org. + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * Copyright (c) 2011, Whamcloud, Inc. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * lustre/liblustre/namei.c * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Lustre Light name resolution */ #define DEBUG_SUBSYSTEM S_LLITE @@ -29,94 +46,60 @@ #include #include #include -#include +#include #include -#ifdef HAVE_XTIO_H -#include -#endif -#include -#include -#include -#include -#ifdef HAVE_FILE_H -#include -#endif - -#undef LIST_HEAD - #include "llite_lib.h" -static void ll_intent_drop_lock(struct lookup_intent *it) +void ll_intent_drop_lock(struct lookup_intent *it) { struct lustre_handle *handle; - if (it->it_op && LUSTRE_IT(it)->it_lock_mode) { - handle = (struct lustre_handle *)&LUSTRE_IT(it)->it_lock_handle; + 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, LUSTRE_IT(it)->it_lock_mode); + ldlm_lock_decref(handle, it->d.lustre.it_lock_mode); /* bug 494: intent_release may be called multiple times, from * this thread and we don't want to double-decref this lock */ - LUSTRE_IT(it)->it_lock_mode = 0; + it->d.lustre.it_lock_mode = 0; } } -static void ll_intent_release(struct lookup_intent *it) +void ll_intent_release(struct lookup_intent *it) { ENTRY; ll_intent_drop_lock(it); it->it_magic = 0; it->it_op_release = 0; - LUSTRE_IT(it)->it_disposition = 0; - LUSTRE_IT(it)->it_data = NULL; + it->d.lustre.it_disposition = 0; + it->d.lustre.it_data = NULL; EXIT; } -#if 0 -/* - * remove the stale inode from pnode - */ -void unhook_stale_inode(struct pnode *pno) -{ - struct inode *inode = pno->p_base->pb_ino; - ENTRY; - - LASSERT(inode); - LASSERT(llu_i2info(inode)->lli_stale_flag); - - pno->p_base->pb_ino = NULL; - I_RELE(inode); - - if (!llu_i2info(inode)->lli_open_count) { - CDEBUG(D_INODE, "unhook inode %p (ino %lu) from pno %p\n", - inode, llu_i2info(inode)->lli_st_ino, pno); - if (!inode->i_ref) - _sysio_i_gone(inode); - } - - EXIT; - return; -} -#endif - void llu_lookup_finish_locks(struct lookup_intent *it, struct pnode *pnode) { + struct inode *inode; LASSERT(it); LASSERT(pnode); - if (it && pnode->p_base->pb_ino != NULL) { - struct inode *inode = pnode->p_base->pb_ino; - CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%lu)\n", - inode, llu_i2info(inode)->lli_st_ino, + inode = pnode->p_base->pb_ino; + if (it->d.lustre.it_lock_mode && inode != NULL) { + struct llu_sb_info *sbi; + + CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%llu/%lu)\n", + inode, (long long)llu_i2stat(inode)->st_ino, llu_i2info(inode)->lli_st_generation); - mdc_set_lock_data(NULL, &LUSTRE_IT(it)->it_lock_handle, inode); + + sbi = llu_i2sbi(inode); + md_set_lock_data(sbi->ll_md_exp, + &it->d.lustre.it_lock_handle, inode, NULL); } /* drop lookup/getattr locks */ - if (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR) + if (it->it_op & (IT_LOOKUP | IT_GETATTR)) ll_intent_release(it); } @@ -126,12 +109,12 @@ static inline void llu_invalidate_inode_pages(struct inode * inode) /* do nothing */ } -int llu_mdc_blocking_ast(struct ldlm_lock *lock, - struct ldlm_lock_desc *desc, - void *data, int flag) +int llu_md_blocking_ast(struct ldlm_lock *lock, + struct ldlm_lock_desc *desc, + void *data, int flag) { - int rc; struct lustre_handle lockh; + int rc; ENTRY; @@ -147,30 +130,42 @@ int llu_mdc_blocking_ast(struct ldlm_lock *lock, case LDLM_CB_CANCELING: { struct inode *inode = llu_inode_from_lock(lock); struct llu_inode_info *lli; + struct intnl_stat *st; __u64 bits = lock->l_policy_data.l_inodebits.bits; + struct lu_fid *fid; /* Invalidate all dentries associated with this inode */ if (inode == NULL) break; - lli = llu_i2info(inode); + lli = llu_i2info(inode); + st = llu_i2stat(inode); if (bits & MDS_INODELOCK_UPDATE) - clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags); - - if (lock->l_resource->lr_name.name[0] != id_fid(&lli->lli_id) || - lock->l_resource->lr_name.name[1] != id_group(&lli->lli_id)) { - LDLM_ERROR(lock, "data mismatch with object "DLID4, - OLID4(&lli->lli_id)); + lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK; + + fid = &lli->lli_fid; + if (lock->l_resource->lr_name.name[0] != fid_seq(fid) || + lock->l_resource->lr_name.name[1] != fid_oid(fid) || + lock->l_resource->lr_name.name[2] != fid_ver(fid)) { + LDLM_ERROR(lock,"data mismatch with ino %llu/%llu/%llu", + (long long)fid_seq(fid), + (long long)fid_oid(fid), + (long long)fid_ver(fid)); } - if (S_ISDIR(lli->lli_st_mode) && + if (S_ISDIR(st->st_mode) && (bits & MDS_INODELOCK_UPDATE)) { - CDEBUG(D_INODE, "invalidating inode %lu\n", - lli->lli_st_ino); + CDEBUG(D_INODE, "invalidating inode %llu\n", + (long long)st->st_ino); llu_invalidate_inode_pages(inode); } +/* + if (inode->i_sb->s_root && + inode != inode->i_sb->s_root->d_inode) + ll_unhash_aliases(inode); +*/ I_RELE(inode); break; } @@ -182,7 +177,6 @@ int llu_mdc_blocking_ast(struct ldlm_lock *lock, } static int pnode_revalidate_finish(struct ptlrpc_request *req, - int offset, struct lookup_intent *it, struct pnode *pnode) { @@ -199,21 +193,22 @@ static int pnode_revalidate_finish(struct ptlrpc_request *req, if (it_disposition(it, DISP_LOOKUP_NEG)) RETURN(-ENOENT); - rc = mdc_req2lustre_md(llu_i2sbi(inode)->ll_md_exp, req, offset, - llu_i2sbi(inode)->ll_dt_exp, &md); + rc = md_get_lustre_md(llu_i2sbi(inode)->ll_md_exp, req, + llu_i2sbi(inode)->ll_dt_exp, + llu_i2sbi(inode)->ll_md_exp, &md); if (rc) RETURN(rc); - llu_update_inode(inode, md.body, md.lsm); + llu_update_inode(inode, &md); RETURN(rc); } -int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it) +static int llu_pb_revalidate(struct pnode *pnode, int flags, + struct lookup_intent *it) { struct pnode_base *pb = pnode->p_base; - struct lustre_id pid, cid; - struct it_cb_data icbd; + struct md_op_data op_data = {{ 0 }}; struct ptlrpc_request *req = NULL; struct lookup_intent lookup_it = { .it_op = IT_LOOKUP }; struct obd_export *exp; @@ -236,10 +231,11 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it) */ { struct llu_inode_info *lli = llu_i2info(pb->pb_ino); + struct intnl_stat *st = llu_i2stat(pb->pb_ino); if (lli->lli_it) { - CDEBUG(D_INODE, "inode %lu still have intent " + CDEBUG(D_INODE, "inode %llu still have intent " "%p(opc 0x%x), release it\n", - lli->lli_st_ino, lli->lli_it, + (long long) st->st_ino, lli->lli_it, lli->lli_it->it_op); ll_intent_release(lli->lli_it); OBD_FREE(lli->lli_it, sizeof(*lli->lli_it)); @@ -248,19 +244,20 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it) } exp = llu_i2mdexp(pb->pb_ino); - ll_inode2id(&pid, pnode->p_parent->p_base->pb_ino); - ll_inode2id(&cid, pb->pb_ino); - icbd.icbd_parent = pnode->p_parent->p_base->pb_ino; - icbd.icbd_child = pnode; if (!it) { it = &lookup_it; it->it_op_release = ll_intent_release; } - rc = mdc_intent_lock(exp, &pid, pb->pb_name.name, pb->pb_name.len, - NULL, 0, &cid, it, flags, &req, llu_mdc_blocking_ast); - /* If req is NULL, then mdc_intent_lock only tried to do a lock match; + llu_prep_md_op_data(&op_data, pnode->p_parent->p_base->pb_ino, + pb->pb_ino, pb->pb_name.name, pb->pb_name.len, + 0, LUSTRE_OPC_ANY); + + rc = md_intent_lock(exp, &op_data, NULL, 0, it, flags, + &req, llu_md_blocking_ast, + LDLM_FL_CANCEL_ON_BLOCK); + /* If req is NULL, then md_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); @@ -268,7 +265,7 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it) if (rc < 0) GOTO(out, rc = 0); - rc = pnode_revalidate_finish(req, 1, it, pnode); + rc = pnode_revalidate_finish(req, it, pnode); if (rc != 0) { ll_intent_release(it); GOTO(out, rc = 0); @@ -315,11 +312,11 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset, if (it_disposition(it, DISP_OPEN_OPEN) && it_open_error(DISP_OPEN_OPEN, it)) { CDEBUG(D_INODE, "detect mds open error\n"); - /* undo which did by mdc_intent_lock */ + /* undo which did by md_intent_lock */ if (it_disposition(it, DISP_OPEN_CREATE) && !it_open_error(DISP_OPEN_CREATE, it)) { LASSERT(request); - LASSERT(atomic_read(&request->rq_refcount) > 1); + LASSERT(cfs_atomic_read(&request->rq_refcount) > 1); CDEBUG(D_INODE, "dec a ref of req %p\n", request); ptlrpc_req_finished(request); } @@ -329,14 +326,17 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset, /* NB 1 request reference will be taken away by ll_intent_lock() * when I return */ - if (!it_disposition(it, DISP_LOOKUP_NEG) || - (it->it_op & IT_CREAT)) { + if (!it_disposition(it, DISP_LOOKUP_NEG) || (it->it_op & IT_CREAT)) { struct lustre_md md; struct llu_inode_info *lli; + struct intnl_stat *st; ENTRY; - rc = mdc_req2lustre_md(sbi->ll_md_exp, request, offset, - sbi->ll_dt_exp, &md); + if (it_disposition(it, DISP_OPEN_CREATE)) + ptlrpc_req_finished(request); + + rc = md_get_lustre_md(sbi->ll_md_exp, request, + sbi->ll_dt_exp, sbi->ll_md_exp, &md); if (rc) RETURN(rc); @@ -346,25 +346,22 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset, if (md.lsm != NULL) obd_free_memmd(sbi->ll_dt_exp, &md.lsm); RETURN(inode ? PTR_ERR(inode) : -ENOMEM); - } else if (md.lsm != NULL && - llu_i2info(inode)->lli_smd != md.lsm) { + } else if (md.lsm != NULL) { obd_free_memmd(sbi->ll_dt_exp, &md.lsm); } lli = llu_i2info(inode); + st = llu_i2stat(inode); /* If this is a stat, get the authoritative file size */ - if (it->it_op == IT_GETATTR && S_ISREG(lli->lli_st_mode) && - lli->lli_smd != NULL) { - struct lov_stripe_md *lsm = lli->lli_smd; + if (it->it_op == IT_GETATTR && S_ISREG(st->st_mode) && + lli->lli_has_smd) { ldlm_error_t rc; - LASSERT(lsm->lsm_object_id != 0); - /* bug 2334: drop MDS lock before acquiring OST lock */ ll_intent_drop_lock(it); - rc = llu_glimpse_size(inode); + rc = cl_glimpse_size(inode); if (rc) { I_RELE(inode); RETURN(rc); @@ -379,14 +376,14 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset, LL_SAVE_INTENT(inode, it); child->p_base->pb_ino = inode; + RETURN(0); } struct inode *llu_inode_from_lock(struct ldlm_lock *lock) { struct inode *inode; -#warning "fix l_lock() using here!" -// l_lock(&lock->l_resource->lr_namespace->ns_lock); + lock_res_and_lock(lock); if (lock->l_ast_data) { inode = (struct inode *)lock->l_ast_data; @@ -394,17 +391,18 @@ struct inode *llu_inode_from_lock(struct ldlm_lock *lock) } else inode = NULL; -// l_unlock(&lock->l_resource->lr_namespace->ns_lock); + unlock_res_and_lock(lock); return inode; } static int llu_lookup_it(struct inode *parent, struct pnode *pnode, struct lookup_intent *it, int flags) { - struct lustre_id pid; + struct md_op_data op_data = {{ 0 }}; struct it_cb_data icbd; struct ptlrpc_request *req = NULL; struct lookup_intent lookup_it = { .it_op = IT_LOOKUP }; + __u32 opc; int rc; ENTRY; @@ -418,18 +416,25 @@ static int llu_lookup_it(struct inode *parent, struct pnode *pnode, icbd.icbd_child = pnode; icbd.icbd_parent = parent; - icbd.icbd_child = pnode; - ll_inode2id(&pid, parent); - rc = mdc_intent_lock(llu_i2mdexp(parent), &pid, - pnode->p_base->pb_name.name, - pnode->p_base->pb_name.len, - NULL, 0, NULL, it, flags, &req, - llu_mdc_blocking_ast); + if (it->it_op & IT_CREAT || + (it->it_op & IT_OPEN && it->it_create_mode & O_CREAT)) { + opc = LUSTRE_OPC_CREATE; + } else { + opc = LUSTRE_OPC_ANY; + } + + llu_prep_md_op_data(&op_data, parent, NULL, + pnode->p_base->pb_name.name, + pnode->p_base->pb_name.len, flags, opc); + + rc = md_intent_lock(llu_i2mdexp(parent), &op_data, NULL, 0, it, + flags, &req, llu_md_blocking_ast, + LDLM_FL_CANCEL_ON_BLOCK); if (rc < 0) GOTO(out, rc); - - rc = lookup_it_finish(req, 1, it, &icbd); + + rc = lookup_it_finish(req, DLM_REPLY_REC_OFF, it, &icbd); if (rc != 0) { ll_intent_release(it); GOTO(out, rc); @@ -496,6 +501,12 @@ translate_lookup_intent(struct intent *intent, const char *path) if (it->it_flags & O_CREAT) { it->it_op |= IT_CREAT; it->it_create_mode = *((int*)intent->int_arg1); + /* bug 7278: libsysio hack. For O_EXCL, libsysio depends on + this lookup to return negative result, but then there is no + way to find out original intent in ll_iop_open(). So we just + clear O_EXCL from libsysio flags here to avoid checking + for negative result. O_EXCL will be enforced by MDS. */ + *((int*)intent->int_arg2) &= ~O_EXCL; } if (intent->int_opmask & INT_GETATTR) @@ -510,7 +521,7 @@ translate_lookup_intent(struct intent *intent, const char *path) /* conform to kernel code, if only IT_LOOKUP was set, don't * pass down it */ - if (!it->it_op || it->it_op == IT_LOOKUP) { + if (!it->it_op || it->it_op & IT_LOOKUP) { OBD_FREE(it, sizeof(*it)); it = NULL; } @@ -540,7 +551,7 @@ int llu_iop_lookup(struct pnode *pnode, if (pnode->p_mount->mnt_root == pnode) { struct inode *i = pnode->p_base->pb_ino; *inop = i; - return 0; + RETURN(0); } if (!pnode->p_base->pb_name.len) @@ -552,7 +563,7 @@ int llu_iop_lookup(struct pnode *pnode, if (llu_pb_revalidate(pnode, 0, it)) { LASSERT(pnode->p_base->pb_ino); *inop = pnode->p_base->pb_ino; - RETURN(0); + GOTO(out, rc = 0); } rc = llu_lookup_it(pnode->p_parent->p_base->pb_ino, pnode, it, 0); @@ -563,5 +574,9 @@ int llu_iop_lookup(struct pnode *pnode, *inop = pnode->p_base->pb_ino; } +out: + if (it) + OBD_FREE(it, sizeof(*it)); + liblustre_wait_event(0); RETURN(rc); }