X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_handler.c;h=74b2f115580a1975a178659827439e736c9525eb;hb=b893c0d0269210b125da0481d17b18f5b06fec1d;hp=618638ba935dc2a32f8b96963562ee36fc853324;hpb=fce887d1f9e0170ef33807415bcff4660fe7fa39;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 618638b..74b2f11 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -1,35 +1,49 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * lustre/mdt/mdt_handler.c - * Lustre Metadata Target (mdt) request handler + * GPL HEADER START * - * Copyright (c) 2006 Cluster File Systems, Inc. - * Author: Peter Braam - * Author: Andreas Dilger - * Author: Phil Schwan - * Author: Mike Shaver - * Author: Nikita Danilov - * Author: Huang Hua - * Author: Yury Umanets + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * This file is part of the Lustre file system, http://www.lustre.org - * Lustre is a trademark of Cluster File Systems, Inc. + * 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. * - * You may have signed or agreed to another license before downloading - * this software. If so, you are bound by the terms and conditions - * of that agreement, and the following does not apply to you. See the - * LICENSE file included with this distribution for more information. + * 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). * - * If you did not agree to a different license, then this copy of Lustre - * is open source 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. + * 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 * - * In either case, 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 - * license text for more details. + * 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 2008 Sun Microsystems, Inc. All rights reserved + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/mdt/mdt_handler.c + * + * Lustre Metadata Target (mdt) request handler + * + * Author: Peter Braam + * Author: Andreas Dilger + * Author: Phil Schwan + * Author: Mike Shaver + * Author: Nikita Danilov + * Author: Huang Hua + * Author: Yury Umanets */ #ifndef EXPORT_SYMTAB @@ -53,7 +67,7 @@ #include #include #include "mdt_internal.h" -#include +#include #include mdl_mode_t mdt_mdl_lock_modes[] = { @@ -148,7 +162,7 @@ static struct mdt_device *mdt_dev(struct lu_device *d); static int mdt_regular_handle(struct ptlrpc_request *req); static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags); -static struct lu_object_operations mdt_obj_ops; +static const struct lu_object_operations mdt_obj_ops; int mdt_get_disposition(struct ldlm_reply *rep, int flag) { @@ -319,15 +333,19 @@ static int mdt_getstatus(struct mdt_thread_info *info) static int mdt_statfs(struct mdt_thread_info *info) { - struct md_device *next = info->mti_mdt->mdt_child; - struct obd_statfs *osfs; - int rc; + struct md_device *next = info->mti_mdt->mdt_child; + struct ptlrpc_service *svc; + struct obd_statfs *osfs; + int rc; ENTRY; + svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service; + /* This will trigger a watchdog timeout */ OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP, - (MDT_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1); + (MDT_SERVICE_WATCHDOG_FACTOR * + at_get(&svc->srv_at_estimate) / 1000) + 1); rc = mdt_check_ucred(info); if (rc) @@ -759,7 +777,7 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, struct md_object *next = mdt_object_child(parent); struct lu_fid *child_fid = &info->mti_tmp_fid1; struct lu_name *lname = NULL; - const char *name; + const char *name = NULL; int namelen = 0; struct mdt_lock_handle *lhp; struct ldlm_lock *lock; @@ -780,27 +798,30 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME, RCL_CLIENT) - 1; - LASSERT(namelen >= 0); - - /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID), - * otherwise do not allow empty name, that is the name must contain - * at least one character and the terminating '\0'*/ - if (namelen == 0) { - reqbody =req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY); - LASSERT(fid_is_sane(&reqbody->fid2)); - name = NULL; - - CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", " - "ldlm_rep = %p\n", - PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2), - ldlm_rep); - } else { - lname = mdt_name(info->mti_env, (char *)name, namelen); - CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, " - "ldlm_rep = %p\n", - PFID(mdt_object_fid(parent)), name, ldlm_rep); - } + if (!info->mti_cross_ref) { + /* + * XXX: Check for "namelen == 0" is for getattr by fid + * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name, + * that is the name must contain at least one character and + * the terminating '\0' + */ + if (namelen == 0) { + reqbody = req_capsule_client_get(info->mti_pill, + &RMF_MDT_BODY); + LASSERT(fid_is_sane(&reqbody->fid2)); + name = NULL; + CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", " + "ldlm_rep = %p\n", + PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2), + ldlm_rep); + } else { + lname = mdt_name(info->mti_env, (char *)name, namelen); + CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, " + "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)), + name, ldlm_rep); + } + } mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD); rc = mdt_object_exists(parent); @@ -809,10 +830,10 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, &parent->mot_obj.mo_lu, "Parent doesn't exist!\n"); RETURN(-ESTALE); - } else + } else if (!info->mti_cross_ref) { LASSERTF(rc > 0, "Parent "DFID" is on remote server\n", PFID(mdt_object_fid(parent))); - + } if (lname) { rc = mdt_raw_lookup(info, parent, lname, ldlm_rep); if (rc != 0) { @@ -923,8 +944,10 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, LDLM_LOCK_PUT(lock); rc = 0; } else { - struct md_attr *ma = &info->mti_attr; + struct md_attr *ma; relock: + ma = &info->mti_attr; + mdt_lock_handle_init(lhc); mdt_lock_reg_init(lhc, LCK_PR); @@ -932,6 +955,7 @@ relock: LU_OBJECT_DEBUG(D_WARNING, info->mti_env, &child->mot_obj.mo_lu, "Object doesn't exist!\n"); + GOTO(out_child, rc = -ESTALE); } ma->ma_valid = 0; @@ -966,7 +990,6 @@ relock: lock = ldlm_handle2lock(&lhc->mlh_reg_lh); if (lock) { struct mdt_body *repbody; - struct lu_attr *ma; /* Debugging code. */ res_id = &lock->l_resource->lr_name; @@ -984,7 +1007,6 @@ relock: */ repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); - ma = &info->mti_attr.ma_attr; if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE) mdt_pack_size2body(info, child); @@ -1034,7 +1056,7 @@ out_shrink: return rc; } -static struct lu_device_operations mdt_lu_ops; +static const struct lu_device_operations mdt_lu_ops; static int lu_device_is_mdt(struct lu_device *d) { @@ -1068,8 +1090,7 @@ static int mdt_set_info(struct mdt_thread_info *info) RETURN(-EFAULT); } - if (keylen != (sizeof(KEY_READ_ONLY) - 1) || - memcmp(key, KEY_READ_ONLY, keylen) != 0) + if (!KEY_IS(KEY_READ_ONLY)) RETURN(-EINVAL); req->rq_status = 0; @@ -1123,6 +1144,7 @@ static int mdt_sendpage(struct mdt_thread_info *info, struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info; int tmpcount; int tmpsize; + int timeout; int i; int rc; ENTRY; @@ -1144,9 +1166,13 @@ static int mdt_sendpage(struct mdt_thread_info *info, GOTO(free_desc, rc); if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) - GOTO(abort_bulk, rc); + GOTO(abort_bulk, rc = 0); - *lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL); + timeout = (int) req->rq_deadline - cfs_time_current_sec(); + if (timeout < 0) + CERROR("Req deadline already passed %lu (now: %lu)\n", + req->rq_deadline, cfs_time_current_sec()); + *lwi = LWI_TIMEOUT(max(timeout, 1) * HZ, NULL, NULL); rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi); LASSERT (rc == 0 || rc == -ETIMEDOUT); @@ -1221,7 +1247,7 @@ static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page, continue; fid_le_to_cpu(lf, &ent->lde_fid); - if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT) + if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT) ma->ma_attr.la_mode = S_IFDIR; else ma->ma_attr.la_mode = 0; @@ -1231,7 +1257,7 @@ static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page, memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen)); lname = mdt_name(info->mti_env, name, - le16_to_cpu(ent->lde_namelen) + 1); + le16_to_cpu(ent->lde_namelen)); ma->ma_attr_flags |= MDS_PERM_BYPASS; rc = mdo_name_insert(info->mti_env, md_object_next(&object->mot_obj), @@ -1369,9 +1395,9 @@ static int mdt_readpage(struct mdt_thread_info *info) * reqbody->nlink contains number bytes to read. */ rdpg->rp_hash = reqbody->size; - if ((__u64)rdpg->rp_hash != reqbody->size) { - CERROR("Invalid hash: %#llx != %#llx\n", - (__u64)rdpg->rp_hash, reqbody->size); + if (rdpg->rp_hash != reqbody->size) { + CERROR("Invalid hash: "LPX64" != "LPX64"\n", + rdpg->rp_hash, reqbody->size); RETURN(-EFAULT); } rdpg->rp_count = reqbody->nlink; @@ -1507,12 +1533,6 @@ static int mdt_reint(struct mdt_thread_info *info) ENTRY; - if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MDS_REINT_NET, - OBD_FAIL_MDS_REINT_NET)) { - info->mti_fail_id = OBD_FAIL_MDS_REINT_NET; - RETURN(0); - } - opc = mdt_reint_opcode(info, reint_fmts); if (opc >= 0) { /* @@ -1528,18 +1548,33 @@ static int mdt_reint(struct mdt_thread_info *info) RETURN(rc); } -/* TODO these two methods not available now. */ - /* this should sync the whole device */ -static int mdt_device_sync(struct mdt_thread_info *info) +static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt) { - return 0; + struct dt_device *dt = mdt->mdt_bottom; + int rc; + ENTRY; + + rc = dt->dd_ops->dt_sync(env, dt); + RETURN(rc); } /* this should sync this object */ static int mdt_object_sync(struct mdt_thread_info *info) { - return 0; + struct md_object *next; + int rc; + ENTRY; + + if (!mdt_object_exists(info->mti_object)) { + CWARN("Non existing object "DFID"!\n", + PFID(mdt_object_fid(info->mti_object))); + RETURN(-ESTALE); + } + next = mdt_object_child(info->mti_object); + rc = mo_object_sync(info->mti_env, next); + + RETURN(rc); } static int mdt_sync(struct mdt_thread_info *info) @@ -1563,7 +1598,7 @@ static int mdt_sync(struct mdt_thread_info *info) /* sync the whole device */ rc = req_capsule_server_pack(pill); if (rc == 0) - rc = mdt_device_sync(info); + rc = mdt_device_sync(info->mti_env, info->mti_mdt); else rc = err_serious(rc); } else { @@ -1652,11 +1687,6 @@ static int mdt_enqueue(struct mdt_thread_info *info) */ LASSERT(info->mti_dlm_req != NULL); - if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE)) { - info->mti_fail_id = OBD_FAIL_LDLM_ENQUEUE; - return 0; - } - req = mdt_info_req(info); /* @@ -1718,6 +1748,8 @@ static int mdt_sec_ctx_handle(struct mdt_thread_info *info) sptlrpc_svc_ctx_invalidate(req); } + OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val); + return rc; } @@ -1736,7 +1768,7 @@ struct mdt_object *mdt_object_find(const struct lu_env *env, ENTRY; CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f)); - o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f); + o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL); if (unlikely(IS_ERR(o))) m = (struct mdt_object *)o; else @@ -1771,6 +1803,17 @@ int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o, LASSERT(lh->mlh_type != MDT_PDO_LOCK); } + if (lh->mlh_type == MDT_PDO_LOCK) { + /* check for exists after object is locked */ + if (mdt_object_exists(o) == 0) { + /* Non-existent object shouldn't have PDO lock */ + RETURN(-ESTALE); + } else { + /* Non-dir object shouldn't have PDO lock */ + LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu))); + } + } + memset(policy, 0, sizeof(*policy)); fid_build_reg_res_name(mdt_object_fid(o), res_id); @@ -1795,7 +1838,7 @@ int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o, } /* - * Finish res_id initializing by name hash marking patr of + * Finish res_id initializing by name hash marking part of * directory which is taking modification. */ res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash; @@ -1806,7 +1849,7 @@ int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o, /* * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is * going to be sent to client. If it is - mdt_intent_policy() path will - * fix it up and turns FL_LOCAL flag off. + * fix it up and turn FL_LOCAL flag off. */ rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy, res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB); @@ -1814,16 +1857,6 @@ int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o, if (rc) GOTO(out, rc); - if (lh->mlh_type == MDT_PDO_LOCK) { - /* check for exists after object is locked */ - if (mdt_object_exists(o) == 0) { - /* Non-existent object shouldn't have PDO lock */ - rc = -ESTALE; - } else { - /* Non-dir object shouldn't have PDO lock */ - LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu))); - } - } out: if (rc) mdt_object_unlock(info, o, lh, 1); @@ -1832,6 +1865,23 @@ out: RETURN(rc); } +static inline +void mdt_save_lock(struct ptlrpc_request *req, struct lustre_handle *h, + ldlm_mode_t mode, int decref) +{ + ENTRY; + + if (lustre_handle_is_used(h)) { + if (decref) + mdt_fid_unlock(h, mode); + else + ptlrpc_save_lock(req, h, mode); + h->cookie = 0ull; + } + + EXIT; +} + /* * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock() * to save this lock in req. when transaction committed, req will be released, @@ -1843,23 +1893,8 @@ void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o, struct ptlrpc_request *req = mdt_info_req(info); ENTRY; - if (lustre_handle_is_used(&lh->mlh_pdo_lh)) { - /* Do not save PDO locks to request, just decref. */ - mdt_fid_unlock(&lh->mlh_pdo_lh, - lh->mlh_pdo_mode); - lh->mlh_pdo_lh.cookie = 0ull; - } - - if (lustre_handle_is_used(&lh->mlh_reg_lh)) { - if (decref) { - mdt_fid_unlock(&lh->mlh_reg_lh, - lh->mlh_reg_mode); - } else { - ptlrpc_save_lock(req, &lh->mlh_reg_lh, - lh->mlh_reg_mode); - } - lh->mlh_reg_lh.cookie = 0ull; - } + mdt_save_lock(req, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref); + mdt_save_lock(req, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref); EXIT; } @@ -2050,22 +2085,18 @@ static int mdt_req_handle(struct mdt_thread_info *info, LASSERT(current->journal_info == NULL); /* - * Mask out OBD_FAIL_ONCE, because that will stop - * correct handling of failed req later in ldlm due to doing - * obd_fail_loc |= OBD_FAIL_ONCE without actually - * correct actions like it is done in target_send_reply_msg(). + * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try + * to put same checks into handlers like mdt_close(), mdt_reint(), + * etc., without talking to mdt authors first. Checking same thing + * there again is useless and returning 0 error wihtout packing reply + * is buggy! Handlers either pack reply or return error. + * + * We return 0 here and do not send any reply in order to emulate + * network failure. Do not send any reply in case any of NET related + * fail_id has occured. */ - if (h->mh_fail_id != 0) { - /* - * Set to info->mti_fail_id to handler fail_id, it will be used - * later, and better than use default fail_id. - */ - if (OBD_FAIL_CHECK_RESET(h->mh_fail_id && OBD_FAIL_MASK_LOC, - h->mh_fail_id & ~OBD_FAILED)) { - info->mti_fail_id = h->mh_fail_id; - RETURN(0); - } - } + if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE)) + RETURN(0); rc = 0; flags = h->mh_flags; @@ -2112,6 +2143,13 @@ static int mdt_req_handle(struct mdt_thread_info *info, * only */ rc = h->mh_act(info); + if (rc == 0 && + !req->rq_no_reply && req->rq_reply_state == NULL) { + DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not " + "pack reply and returned 0 error\n", + h->mh_name); + LBUG(); + } serious = is_serious(rc); rc = clear_serious(rc); } else @@ -2147,7 +2185,8 @@ static int mdt_req_handle(struct mdt_thread_info *info, LBUG(); } - RETURN(rc); + target_send_reply(req, rc, info->mti_fail_id); + RETURN(0); } void mdt_lock_handle_init(struct mdt_lock_handle *lh) @@ -2341,21 +2380,6 @@ static int mdt_recovery(struct mdt_thread_info *info) RETURN(+1); } -static int mdt_reply(struct ptlrpc_request *req, int rc, - struct mdt_thread_info *info) -{ - ENTRY; - -#if 0 - if (req->rq_reply_state == NULL && rc == 0) { - req->rq_status = rc; - lustre_pack_reply(req, 1, NULL, NULL); - } -#endif - target_send_reply(req, rc, info->mti_fail_id); - RETURN(0); -} - static int mdt_msg_check_version(struct lustre_msg *msg) { int rc; @@ -2459,7 +2483,6 @@ static int mdt_handle0(struct ptlrpc_request *req, supported); if (likely(h != NULL)) { rc = mdt_req_handle(info, h, req); - rc = mdt_reply(req, rc, info); } else { CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) ); req->rq_status = -ENOTSUPP; @@ -2657,7 +2680,7 @@ int mdt_intent_lock_replace(struct mdt_thread_info *info, * lock. */ if (new_lock == NULL) - new_lock = ldlm_handle2lock(&lh->mlh_reg_lh); + new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0); if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) { lh->mlh_reg_lh.cookie = 0; @@ -2693,29 +2716,35 @@ int mdt_intent_lock_replace(struct mdt_thread_info *info, RETURN(ELDLM_LOCK_REPLACED); } - /* This lock might already be given to the client by an resent req, - * in this case we should return ELDLM_LOCK_ABORTED, - * so we should check led_held_locks here, but it will affect - * performance, FIXME + /* + * Fixup the lock to be given to the client. */ - /* Fixup the lock to be given to the client */ lock_res_and_lock(new_lock); - new_lock->l_readers = 0; - new_lock->l_writers = 0; + /* Zero new_lock->l_readers and new_lock->l_writers without triggering + * possible blocking AST. */ + while (new_lock->l_readers > 0) { + lu_ref_del(&new_lock->l_reference, "reader", new_lock); + lu_ref_del(&new_lock->l_reference, "user", new_lock); + new_lock->l_readers--; + } + while (new_lock->l_writers > 0) { + lu_ref_del(&new_lock->l_reference, "writer", new_lock); + lu_ref_del(&new_lock->l_reference, "user", new_lock); + new_lock->l_writers--; + } new_lock->l_export = class_export_get(req->rq_export); - spin_lock(&req->rq_export->exp_ldlm_data.led_lock); - list_add(&new_lock->l_export_chain, - &new_lock->l_export->exp_ldlm_data.led_held_locks); - spin_unlock(&req->rq_export->exp_ldlm_data.led_lock); - new_lock->l_blocking_ast = lock->l_blocking_ast; new_lock->l_completion_ast = lock->l_completion_ast; new_lock->l_remote_handle = lock->l_remote_handle; new_lock->l_flags &= ~LDLM_FL_LOCAL; + lustre_hash_add(new_lock->l_export->exp_lock_hash, + &new_lock->l_remote_handle, + &new_lock->l_exp_hash); + unlock_res_and_lock(new_lock); - LDLM_LOCK_PUT(new_lock); + LDLM_LOCK_RELEASE(new_lock); lh->mlh_reg_lh.cookie = 0; RETURN(ELDLM_LOCK_REPLACED); @@ -2730,7 +2759,7 @@ static void mdt_intent_fixup_resent(struct mdt_thread_info *info, struct obd_export *exp = req->rq_export; struct lustre_handle remote_hdl; struct ldlm_request *dlmreq; - struct list_head *iter; + struct ldlm_lock *lock; if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)) return; @@ -2738,27 +2767,24 @@ static void mdt_intent_fixup_resent(struct mdt_thread_info *info, dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ); remote_hdl = dlmreq->lock_handle[0]; - spin_lock(&exp->exp_ldlm_data.led_lock); - list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) { - struct ldlm_lock *lock; - lock = list_entry(iter, struct ldlm_lock, l_export_chain); - if (lock == new_lock) - continue; - if (lock->l_remote_handle.cookie == remote_hdl.cookie) { + lock = lustre_hash_lookup(exp->exp_lock_hash, &remote_hdl); + if (lock) { + if (lock != new_lock) { lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie; lh->mlh_reg_mode = lock->l_granted_mode; - LDLM_DEBUG(lock, "restoring lock cookie"); + LDLM_DEBUG(lock, "Restoring lock cookie"); DEBUG_REQ(D_DLMTRACE, req, "restoring lock cookie "LPX64, lh->mlh_reg_lh.cookie); if (old_lock) *old_lock = LDLM_LOCK_GET(lock); - spin_unlock(&exp->exp_ldlm_data.led_lock); + lh_put(exp->exp_lock_hash, &lock->l_exp_hash); return; } + + lh_put(exp->exp_lock_hash, &lock->l_exp_hash); } - spin_unlock(&exp->exp_ldlm_data.led_lock); /* * If the xid matches, then we know this is a resent request, and allow @@ -2899,8 +2925,25 @@ static int mdt_intent_reint(enum mdt_it_code opcode, rep->lock_policy_res2 = clear_serious(rc); lhc->mlh_reg_lh.cookie = 0ull; - rc = ELDLM_LOCK_ABORTED; - RETURN(rc); + if (rc == -ENOTCONN || rc == -ENODEV) { + /* + * If it is the disconnect error (ENODEV & ENOCONN), the error + * will be returned by rq_status, and client at ptlrpc layer + * will detect this, then disconnect, reconnect the import + * immediately, instead of impacting the following the rpc. + */ + RETURN(rc); + } else { + /* + * For other cases, the error will be returned by intent. + * and client will retrieve the result from intent. + */ + /* + * FIXME: when open lock is finished, that should be + * checked here. + */ + RETURN(ELDLM_LOCK_ABORTED); + } } static int mdt_intent_code(long itcode) @@ -3004,12 +3047,6 @@ static int mdt_intent_policy(struct ldlm_namespace *ns, if (it != NULL) { const struct ldlm_request *dlmreq; __u64 req_bits; -#if 0 - struct ldlm_lock *lock = *lockp; - - LDLM_DEBUG(lock, "intent policy opc: %s\n", - ldlm_it2str(it->opc)); -#endif rc = mdt_intent_opc(it->opc, info, lockp, flags); if (rc == 0) @@ -3043,15 +3080,15 @@ static int mdt_intent_policy(struct ldlm_namespace *ns, static void mdt_seq_adjust(const struct lu_env *env, struct mdt_device *m, int lost) { - struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site; + struct md_site *ms = mdt_md_site(m); struct lu_range out; ENTRY; - LASSERT(ls && ls->ls_server_seq); + LASSERT(ms && ms->ms_server_seq); LASSERT(lost >= 0); /* get extra seq from seq_server, moving it's range up */ while (lost-- > 0) { - seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env); + seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env); } EXIT; } @@ -3059,25 +3096,27 @@ static void mdt_seq_adjust(const struct lu_env *env, static int mdt_seq_fini(const struct lu_env *env, struct mdt_device *m) { - struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site; + struct md_site *ms = mdt_md_site(m); ENTRY; - if (ls && ls->ls_server_seq) { - seq_server_fini(ls->ls_server_seq, env); - OBD_FREE_PTR(ls->ls_server_seq); - ls->ls_server_seq = NULL; + if (ms != NULL) { + if (ms->ms_server_seq) { + seq_server_fini(ms->ms_server_seq, env); + OBD_FREE_PTR(ms->ms_server_seq); + ms->ms_server_seq = NULL; } - if (ls && ls->ls_control_seq) { - seq_server_fini(ls->ls_control_seq, env); - OBD_FREE_PTR(ls->ls_control_seq); - ls->ls_control_seq = NULL; + if (ms->ms_control_seq) { + seq_server_fini(ms->ms_control_seq, env); + OBD_FREE_PTR(ms->ms_control_seq); + ms->ms_control_seq = NULL; } - if (ls && ls->ls_client_seq) { - seq_client_fini(ls->ls_client_seq); - OBD_FREE_PTR(ls->ls_client_seq); - ls->ls_client_seq = NULL; + if (ms->ms_client_seq) { + seq_client_fini(ms->ms_client_seq); + OBD_FREE_PTR(ms->ms_client_seq); + ms->ms_client_seq = NULL; + } } RETURN(0); @@ -3087,25 +3126,25 @@ static int mdt_seq_init(const struct lu_env *env, const char *uuid, struct mdt_device *m) { - struct lu_site *ls; + struct md_site *ms; char *prefix; int rc; ENTRY; - ls = m->mdt_md_dev.md_lu_dev.ld_site; + ms = mdt_md_site(m); /* * This is sequence-controller node. Init seq-controller server on local * MDT. */ - if (ls->ls_node_id == 0) { - LASSERT(ls->ls_control_seq == NULL); + if (ms->ms_node_id == 0) { + LASSERT(ms->ms_control_seq == NULL); - OBD_ALLOC_PTR(ls->ls_control_seq); - if (ls->ls_control_seq == NULL) + OBD_ALLOC_PTR(ms->ms_control_seq); + if (ms->ms_control_seq == NULL) RETURN(-ENOMEM); - rc = seq_server_init(ls->ls_control_seq, + rc = seq_server_init(ms->ms_control_seq, m->mdt_bottom, uuid, LUSTRE_SEQ_CONTROLLER, env); @@ -3113,13 +3152,13 @@ static int mdt_seq_init(const struct lu_env *env, if (rc) GOTO(out_seq_fini, rc); - OBD_ALLOC_PTR(ls->ls_client_seq); - if (ls->ls_client_seq == NULL) + OBD_ALLOC_PTR(ms->ms_client_seq); + if (ms->ms_client_seq == NULL) GOTO(out_seq_fini, rc = -ENOMEM); OBD_ALLOC(prefix, MAX_OBD_NAME + 5); if (prefix == NULL) { - OBD_FREE_PTR(ls->ls_client_seq); + OBD_FREE_PTR(ms->ms_client_seq); GOTO(out_seq_fini, rc = -ENOMEM); } @@ -3128,11 +3167,11 @@ static int mdt_seq_init(const struct lu_env *env, /* * Init seq-controller client after seq-controller server is - * ready. Pass ls->ls_control_seq to it for direct talking. + * ready. Pass ms->ms_control_seq to it for direct talking. */ - rc = seq_client_init(ls->ls_client_seq, NULL, + rc = seq_client_init(ms->ms_client_seq, NULL, LUSTRE_SEQ_METADATA, prefix, - ls->ls_control_seq); + ms->ms_control_seq); OBD_FREE(prefix, MAX_OBD_NAME + 5); if (rc) @@ -3140,13 +3179,13 @@ static int mdt_seq_init(const struct lu_env *env, } /* Init seq-server on local MDT */ - LASSERT(ls->ls_server_seq == NULL); + LASSERT(ms->ms_server_seq == NULL); - OBD_ALLOC_PTR(ls->ls_server_seq); - if (ls->ls_server_seq == NULL) + OBD_ALLOC_PTR(ms->ms_server_seq); + if (ms->ms_server_seq == NULL) GOTO(out_seq_fini, rc = -ENOMEM); - rc = seq_server_init(ls->ls_server_seq, + rc = seq_server_init(ms->ms_server_seq, m->mdt_bottom, uuid, LUSTRE_SEQ_SERVER, env); @@ -3154,11 +3193,11 @@ static int mdt_seq_init(const struct lu_env *env, GOTO(out_seq_fini, rc = -ENOMEM); /* Assign seq-controller client to local seq-server. */ - if (ls->ls_node_id == 0) { - LASSERT(ls->ls_client_seq != NULL); + if (ms->ms_node_id == 0) { + LASSERT(ms->ms_client_seq != NULL); - rc = seq_server_set_cli(ls->ls_server_seq, - ls->ls_client_seq, + rc = seq_server_set_cli(ms->ms_server_seq, + ms->ms_client_seq, env); } @@ -3177,7 +3216,7 @@ static int mdt_seq_init_cli(const struct lu_env *env, struct mdt_device *m, struct lustre_cfg *cfg) { - struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site; + struct md_site *ms = mdt_md_site(m); struct obd_device *mdc; struct obd_uuid *uuidp, *mdcuuidp; char *uuid_str, *mdc_uuid_str; @@ -3201,7 +3240,7 @@ static int mdt_seq_init_cli(const struct lu_env *env, /* check if this is adding the first MDC and controller is not yet * initialized. */ - if (index != 0 || ls->ls_client_seq) + if (index != 0 || ms->ms_client_seq) RETURN(0); uuid_str = lustre_cfg_string(cfg, 1); @@ -3218,9 +3257,9 @@ static int mdt_seq_init_cli(const struct lu_env *env, CERROR("target %s not set up\n", mdc->obd_name); rc = -EINVAL; } else { - LASSERT(ls->ls_control_exp); - OBD_ALLOC_PTR(ls->ls_client_seq); - if (ls->ls_client_seq != NULL) { + LASSERT(ms->ms_control_exp); + OBD_ALLOC_PTR(ms->ms_client_seq); + if (ms->ms_client_seq != NULL) { char *prefix; OBD_ALLOC(prefix, MAX_OBD_NAME + 5); @@ -3230,8 +3269,8 @@ static int mdt_seq_init_cli(const struct lu_env *env, snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s", mdc->obd_name); - rc = seq_client_init(ls->ls_client_seq, - ls->ls_control_exp, + rc = seq_client_init(ms->ms_client_seq, + ms->ms_control_exp, LUSTRE_SEQ_METADATA, prefix, NULL); OBD_FREE(prefix, MAX_OBD_NAME + 5); @@ -3241,8 +3280,8 @@ static int mdt_seq_init_cli(const struct lu_env *env, if (rc) RETURN(rc); - LASSERT(ls->ls_server_seq != NULL); - rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq, + LASSERT(ms->ms_server_seq != NULL); + rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq, env); } @@ -3251,19 +3290,21 @@ static int mdt_seq_init_cli(const struct lu_env *env, static void mdt_seq_fini_cli(struct mdt_device *m) { - struct lu_site *ls; + struct md_site *ms; ENTRY; - ls = m->mdt_md_dev.md_lu_dev.ld_site; + ms = mdt_md_site(m); - if (ls && ls->ls_server_seq) - seq_server_set_cli(ls->ls_server_seq, + if (ms != NULL) { + if (ms->ms_server_seq) + seq_server_set_cli(ms->ms_server_seq, NULL, NULL); - if (ls && ls->ls_control_exp) { - class_export_put(ls->ls_control_exp); - ls->ls_control_exp = NULL; + if (ms->ms_control_exp) { + class_export_put(ms->ms_control_exp); + ms->ms_control_exp = NULL; + } } EXIT; } @@ -3274,13 +3315,13 @@ static void mdt_seq_fini_cli(struct mdt_device *m) static int mdt_fld_fini(const struct lu_env *env, struct mdt_device *m) { - struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site; + struct md_site *ms = mdt_md_site(m); ENTRY; - if (ls && ls->ls_server_fld) { - fld_server_fini(ls->ls_server_fld, env); - OBD_FREE_PTR(ls->ls_server_fld); - ls->ls_server_fld = NULL; + if (ms && ms->ms_server_fld) { + fld_server_fini(ms->ms_server_fld, env); + OBD_FREE_PTR(ms->ms_server_fld); + ms->ms_server_fld = NULL; } RETURN(0); @@ -3290,21 +3331,21 @@ static int mdt_fld_init(const struct lu_env *env, const char *uuid, struct mdt_device *m) { - struct lu_site *ls; + struct md_site *ms; int rc; ENTRY; - ls = m->mdt_md_dev.md_lu_dev.ld_site; + ms = mdt_md_site(m); - OBD_ALLOC_PTR(ls->ls_server_fld); - if (ls->ls_server_fld == NULL) + OBD_ALLOC_PTR(ms->ms_server_fld); + if (ms->ms_server_fld == NULL) RETURN(rc = -ENOMEM); - rc = fld_server_init(ls->ls_server_fld, + rc = fld_server_init(ms->ms_server_fld, m->mdt_bottom, uuid, env); if (rc) { - OBD_FREE_PTR(ls->ls_server_fld); - ls->ls_server_fld = NULL; + OBD_FREE_PTR(ms->ms_server_fld); + ms->ms_server_fld = NULL; RETURN(rc); } @@ -3360,21 +3401,21 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry; conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = MDS_MAXREQSIZE, - .psc_max_reply_size = MDS_MAXREPSIZE, - .psc_req_portal = MDS_REQUEST_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = MDS_MAXREQSIZE, + .psc_max_reply_size = MDS_MAXREPSIZE, + .psc_req_portal = MDS_REQUEST_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, /* * We'd like to have a mechanism to set this on a per-device * basis, but alas... */ - .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), - MDT_MAX_THREADS), - .psc_max_threads = MDT_MAX_THREADS, - .psc_ctx_tags = LCT_MD_THREAD + .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), + MDT_MAX_THREADS), + .psc_max_threads = MDT_MAX_THREADS, + .psc_ctx_tags = LCT_MD_THREAD }; m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client; @@ -3383,7 +3424,8 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) m->mdt_regular_service = ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME, - procfs_entry, NULL, LUSTRE_MDT_NAME); + procfs_entry, target_print_req, + LUSTRE_MDT_NAME); if (m->mdt_regular_service == NULL) RETURN(-ENOMEM); @@ -3396,22 +3438,22 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) * ideally. */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = MDS_MAXREQSIZE, - .psc_max_reply_size = MDS_MAXREPSIZE, - .psc_req_portal = MDS_READPAGE_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, - .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), - MDT_MAX_THREADS), - .psc_max_threads = MDT_MAX_THREADS, - .psc_ctx_tags = LCT_MD_THREAD + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = MDS_MAXREQSIZE, + .psc_max_reply_size = MDS_MAXREPSIZE, + .psc_req_portal = MDS_READPAGE_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, + .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), + MDT_MAX_THREADS), + .psc_max_threads = MDT_MAX_THREADS, + .psc_ctx_tags = LCT_MD_THREAD }; m->mdt_readpage_service = ptlrpc_init_svc_conf(&conf, mdt_readpage_handle, LUSTRE_MDT_NAME "_readpage", - procfs_entry, NULL, "mdt_rdpg"); + procfs_entry, target_print_req,"mdt_rdpg"); if (m->mdt_readpage_service == NULL) { CERROR("failed to start readpage service\n"); @@ -3424,23 +3466,23 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) * setattr service configuration. */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = MDS_MAXREQSIZE, - .psc_max_reply_size = MDS_MAXREPSIZE, - .psc_req_portal = MDS_SETATTR_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = MDS_MAXREQSIZE, + .psc_max_reply_size = MDS_MAXREPSIZE, + .psc_req_portal = MDS_SETATTR_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), - MDT_MAX_THREADS), - .psc_max_threads = MDT_MAX_THREADS, - .psc_ctx_tags = LCT_MD_THREAD + MDT_MAX_THREADS), + .psc_max_threads = MDT_MAX_THREADS, + .psc_ctx_tags = LCT_MD_THREAD }; m->mdt_setattr_service = ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME "_setattr", - procfs_entry, NULL, "mdt_attr"); + procfs_entry, target_print_req,"mdt_attr"); if (!m->mdt_setattr_service) { CERROR("failed to start setattr service\n"); @@ -3455,22 +3497,22 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) * sequence controller service configuration */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = SEQ_MAXREQSIZE, - .psc_max_reply_size = SEQ_MAXREPSIZE, - .psc_req_portal = SEQ_CONTROLLER_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, - .psc_min_threads = SEQ_NUM_THREADS, - .psc_max_threads = SEQ_NUM_THREADS, - .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = SEQ_MAXREQSIZE, + .psc_max_reply_size = SEQ_MAXREPSIZE, + .psc_req_portal = SEQ_CONTROLLER_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, + .psc_min_threads = SEQ_NUM_THREADS, + .psc_max_threads = SEQ_NUM_THREADS, + .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD }; m->mdt_mdsc_service = ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle, LUSTRE_MDT_NAME"_mdsc", - procfs_entry, NULL, "mdt_mdsc"); + procfs_entry, target_print_req,"mdt_mdsc"); if (!m->mdt_mdsc_service) { CERROR("failed to start seq controller service\n"); GOTO(err_mdt_svc, rc = -ENOMEM); @@ -3484,22 +3526,22 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) * metadata sequence server service configuration */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = SEQ_MAXREQSIZE, - .psc_max_reply_size = SEQ_MAXREPSIZE, - .psc_req_portal = SEQ_METADATA_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, - .psc_min_threads = SEQ_NUM_THREADS, - .psc_max_threads = SEQ_NUM_THREADS, - .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = SEQ_MAXREQSIZE, + .psc_max_reply_size = SEQ_MAXREPSIZE, + .psc_req_portal = SEQ_METADATA_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, + .psc_min_threads = SEQ_NUM_THREADS, + .psc_max_threads = SEQ_NUM_THREADS, + .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD }; m->mdt_mdss_service = ptlrpc_init_svc_conf(&conf, mdt_mdss_handle, LUSTRE_MDT_NAME"_mdss", - procfs_entry, NULL, "mdt_mdss"); + procfs_entry, target_print_req,"mdt_mdss"); if (!m->mdt_mdss_service) { CERROR("failed to start metadata seq server service\n"); GOTO(err_mdt_svc, rc = -ENOMEM); @@ -3516,22 +3558,22 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) * controller which manages space. */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = SEQ_MAXREQSIZE, - .psc_max_reply_size = SEQ_MAXREPSIZE, - .psc_req_portal = SEQ_DATA_PORTAL, - .psc_rep_portal = OSC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, - .psc_min_threads = SEQ_NUM_THREADS, - .psc_max_threads = SEQ_NUM_THREADS, - .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = SEQ_MAXREQSIZE, + .psc_max_reply_size = SEQ_MAXREPSIZE, + .psc_req_portal = SEQ_DATA_PORTAL, + .psc_rep_portal = OSC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, + .psc_min_threads = SEQ_NUM_THREADS, + .psc_max_threads = SEQ_NUM_THREADS, + .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD }; m->mdt_dtss_service = ptlrpc_init_svc_conf(&conf, mdt_dtss_handle, LUSTRE_MDT_NAME"_dtss", - procfs_entry, NULL, "mdt_dtss"); + procfs_entry, target_print_req,"mdt_dtss"); if (!m->mdt_dtss_service) { CERROR("failed to start data seq server service\n"); GOTO(err_mdt_svc, rc = -ENOMEM); @@ -3543,22 +3585,22 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) /* FLD service start */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = FLD_MAXREQSIZE, - .psc_max_reply_size = FLD_MAXREPSIZE, - .psc_req_portal = FLD_REQUEST_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, - .psc_min_threads = FLD_NUM_THREADS, - .psc_max_threads = FLD_NUM_THREADS, - .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = FLD_MAXREQSIZE, + .psc_max_reply_size = FLD_MAXREPSIZE, + .psc_req_portal = FLD_REQUEST_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, + .psc_min_threads = FLD_NUM_THREADS, + .psc_max_threads = FLD_NUM_THREADS, + .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD }; m->mdt_fld_service = ptlrpc_init_svc_conf(&conf, mdt_fld_handle, LUSTRE_MDT_NAME"_fld", - procfs_entry, NULL, "mdt_fld"); + procfs_entry, target_print_req, "mdt_fld"); if (!m->mdt_fld_service) { CERROR("failed to start fld service\n"); GOTO(err_mdt_svc, rc = -ENOMEM); @@ -3573,21 +3615,22 @@ static int mdt_start_ptlrpc_service(struct mdt_device *m) * mds-mds requests be not blocked during recovery. */ conf = (typeof(conf)) { - .psc_nbufs = MDS_NBUFS, - .psc_bufsize = MDS_BUFSIZE, - .psc_max_req_size = MDS_MAXREQSIZE, - .psc_max_reply_size = MDS_MAXREPSIZE, - .psc_req_portal = MDS_MDS_PORTAL, - .psc_rep_portal = MDC_REPLY_PORTAL, - .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT, - .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), - MDT_MAX_THREADS), - .psc_max_threads = MDT_MAX_THREADS, - .psc_ctx_tags = LCT_MD_THREAD + .psc_nbufs = MDS_NBUFS, + .psc_bufsize = MDS_BUFSIZE, + .psc_max_req_size = MDS_MAXREQSIZE, + .psc_max_reply_size = MDS_MAXREPSIZE, + .psc_req_portal = MDS_MDS_PORTAL, + .psc_rep_portal = MDC_REPLY_PORTAL, + .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR, + .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS), + MDT_MAX_THREADS), + .psc_max_threads = MDT_MAX_THREADS, + .psc_ctx_tags = LCT_MD_THREAD }; - m->mdt_xmds_service = ptlrpc_init_svc_conf(&conf, mdt_xmds_handle, - LUSTRE_MDT_NAME "_mds", - procfs_entry, NULL, "mdt_xmds"); + m->mdt_xmds_service = + ptlrpc_init_svc_conf(&conf, mdt_xmds_handle, + LUSTRE_MDT_NAME "_mds", + procfs_entry, target_print_req,"mdt_xmds"); if (m->mdt_xmds_service == NULL) { CERROR("failed to start readpage service\n"); @@ -3642,7 +3685,7 @@ static void mdt_stack_fini(const struct lu_env *env, m->mdt_bottom = NULL; } -static struct lu_device *mdt_layer_setup(const struct lu_env *env, +static struct lu_device *mdt_layer_setup(struct lu_env *env, const char *typename, struct lu_device *child, struct lustre_cfg *cfg) @@ -3698,6 +3741,7 @@ static struct lu_device *mdt_layer_setup(const struct lu_env *env, GOTO(out_alloc, rc); } lu_device_get(d); + lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init); RETURN(d); @@ -3710,7 +3754,7 @@ out: return ERR_PTR(rc); } -static int mdt_stack_init(const struct lu_env *env, +static int mdt_stack_init(struct lu_env *env, struct mdt_device *m, struct lustre_cfg *cfg) { struct lu_device *d = &m->mdt_md_dev.md_lu_dev; @@ -3799,8 +3843,11 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); if (ls) { + struct md_site *mite; + lu_site_fini(ls); - OBD_FREE_PTR(ls); + mite = lu_site2md(ls); + OBD_FREE_PTR(mite); d->ld_site = NULL; } LASSERT(atomic_read(&d->ld_ref) == 0); @@ -3863,6 +3910,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, struct lustre_mount_info *lmi; struct lustre_sb_info *lsi; struct lu_site *s; + struct md_site *mite; const char *identity_upcall = "NONE"; int rc; ENTRY; @@ -3901,11 +3949,13 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, spin_lock_init(&m->mdt_client_bitmap_lock); - OBD_ALLOC_PTR(s); - if (s == NULL) + OBD_ALLOC_PTR(mite); + if (mite == NULL) RETURN(-ENOMEM); md_device_init(&m->mdt_md_dev, ldt); + s = &mite->ms_lu; + m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops; m->mdt_md_dev.md_lu_dev.ld_obd = obd; /* set this lu_device to obd, because error handling need it */ @@ -3933,7 +3983,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, /* set server index */ LASSERT(num); - s->ls_node_id = simple_strtol(num, NULL, 10); + lu_site2md(s)->ms_node_id = simple_strtol(num, NULL, 10); /* failover is the default * FIXME: we do not failout mds0/mgs, which may cause some problems. @@ -3952,7 +4002,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, } /* init the stack */ - rc = mdt_stack_init(env, m, cfg); + rc = mdt_stack_init((struct lu_env *)env, m, cfg); if (rc) { CERROR("Can't init device stack, rc %d\n", rc); GOTO(err_fini_proc, rc); @@ -4018,8 +4068,11 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, mdt_init_capa_ctxt(env, m); + /* Reduce the initial timeout on an MDS because it doesn't need such + * a long timeout as an OST does. Adaptive timeouts will adjust this + * value appropriately. */ if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT) - ldlm_timeout = 6; + ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT; RETURN(0); @@ -4045,6 +4098,7 @@ err_fini_stack: mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); err_fini_proc: mdt_procfs_fini(m); + ptlrpc_lprocfs_unregister_obd(obd); lprocfs_obd_cleanup(obd); err_fini_site: lu_site_fini(s); @@ -4099,9 +4153,10 @@ static int mdt_process_config(const struct lu_env *env, struct obd_device *obd = d->ld_obd; lprocfs_mdt_init_vars(&lvars); - rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd); - if (rc) - /* others are passed further */ + rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, + cfg, obd); + if (rc == -ENOSYS) + /* we don't understand; pass it on */ rc = next->ld_ops->ldo_process_config(env, next, cfg); break; } @@ -4148,7 +4203,8 @@ static struct lu_object *mdt_object_alloc(const struct lu_env *env, RETURN(NULL); } -static int mdt_object_init(const struct lu_env *env, struct lu_object *o) +static int mdt_object_init(const struct lu_env *env, struct lu_object *o, + const struct lu_object_conf *_) { struct mdt_device *d = mdt_dev(o->lo_dev); struct lu_device *under; @@ -4185,21 +4241,14 @@ static void mdt_object_free(const struct lu_env *env, struct lu_object *o) EXIT; } -static int mdt_object_print(const struct lu_env *env, void *cookie, - lu_printer_t p, const struct lu_object *o) -{ - return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o); -} - -static struct lu_device_operations mdt_lu_ops = { +static const struct lu_device_operations mdt_lu_ops = { .ldo_object_alloc = mdt_object_alloc, .ldo_process_config = mdt_process_config }; -static struct lu_object_operations mdt_obj_ops = { +static const struct lu_object_operations mdt_obj_ops = { .loo_object_init = mdt_object_init, - .loo_object_free = mdt_object_free, - .loo_object_print = mdt_object_print + .loo_object_free = mdt_object_free }; /* mds_connect_internal */ @@ -4287,7 +4336,7 @@ static int mdt_obd_connect(const struct lu_env *env, void *localdata) { struct mdt_thread_info *info; - struct mdt_client_data *mcd; + struct lsd_client_data *lcd; struct obd_export *exp; struct mdt_device *mdt; struct ptlrpc_request *req; @@ -4331,19 +4380,19 @@ static int mdt_obd_connect(const struct lu_env *env, rc = mdt_connect_internal(exp, mdt, data); if (rc == 0) { - OBD_ALLOC_PTR(mcd); - if (mcd != NULL) { + OBD_ALLOC_PTR(lcd); + if (lcd != NULL) { struct mdt_thread_info *mti; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); LASSERT(mti != NULL); mti->mti_exp = exp; - memcpy(mcd->mcd_uuid, cluuid, sizeof mcd->mcd_uuid); - exp->exp_mdt_data.med_mcd = mcd; + memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid); + exp->exp_mdt_data.med_lcd = lcd; rc = mdt_client_new(env, mdt); if (rc != 0) { - OBD_FREE_PTR(mcd); - exp->exp_mdt_data.med_mcd = NULL; + OBD_FREE_PTR(lcd); + exp->exp_mdt_data.med_lcd = NULL; } } else rc = -ENOMEM; @@ -4417,6 +4466,9 @@ static int mdt_obd_disconnect(struct obd_export *exp) if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL) ldlm_cancel_locks_for_export(exp); + /* release nid stat refererence */ + lprocfs_exp_cleanup(exp); + /* complete all outstanding replies */ spin_lock(&exp->exp_lock); while (!list_empty(&exp->exp_outstanding_replies)) { @@ -4440,6 +4492,7 @@ static int mdt_obd_disconnect(struct obd_export *exp) static int mdt_init_export(struct obd_export *exp) { struct mdt_export_data *med = &exp->exp_mdt_data; + int rc; ENTRY; CFS_INIT_LIST_HEAD(&med->med_open_head); @@ -4449,7 +4502,10 @@ static int mdt_init_export(struct obd_export *exp) spin_lock(&exp->exp_lock); exp->exp_connecting = 1; spin_unlock(&exp->exp_lock); - RETURN(0); + rc = ldlm_init_export(exp); + if (rc) + CERROR("Error %d while initializing export\n", rc); + RETURN(rc); } static int mdt_destroy_export(struct obd_export *export) @@ -4470,6 +4526,7 @@ static int mdt_destroy_export(struct obd_export *export) mdt_cleanup_idmap(med); target_destroy_export(export); + ldlm_destroy_export(export); if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid)) RETURN(0); @@ -4594,7 +4651,7 @@ static int mdt_obd_notify(struct obd_device *host, switch (ev) { case OBD_NOTIFY_CONFIG: - mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned int)data); + mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned long)data); break; default: CDEBUG(D_INFO, "Unhandled notification %#x\n", ev); @@ -4619,7 +4676,7 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, switch (cmd) { case OBD_IOC_SYNC: - rc = dt->dd_ops->dt_sync(&env, dt); + rc = mdt_device_sync(&env, mdt); break; case OBD_IOC_SET_READONLY: rc = dt->dd_ops->dt_sync(&env, dt); @@ -4751,6 +4808,9 @@ static struct lu_device_type_operations mdt_device_type_ops = { .ldto_init = mdt_type_init, .ldto_fini = mdt_type_fini, + .ldto_start = mdt_type_start, + .ldto_stop = mdt_type_stop, + .ldto_device_alloc = mdt_device_alloc, .ldto_device_free = mdt_device_free, .ldto_device_fini = mdt_device_fini @@ -4986,7 +5046,7 @@ static struct mdt_opc_slice mdt_fld_handlers[] = { } }; -MODULE_AUTHOR("Cluster File Systems, Inc. "); +MODULE_AUTHOR("Sun Microsystems, Inc. "); MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")"); MODULE_LICENSE("GPL");