X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_capa.c;h=71e84340b604a60051328b6bf0ced3aaf8ae73ff;hb=9ca726ac69b07c7fdc8d134df303c3360f7feb02;hp=204adf3a3ec78e025181b8353d2cee0ef12194ac;hpb=8cd6267b5236fe9c16f99ed08687dd7baecfd00c;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_capa.c b/lustre/mdt/mdt_capa.c index 204adf3..71e8434 100644 --- a/lustre/mdt/mdt_capa.c +++ b/lustre/mdt/mdt_capa.c @@ -1,29 +1,43 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * lustre/mdt/mdt_capa.c - * Lustre Metadata Target (mdt) capability key read/write/update. + * GPL HEADER START * - * Copyright (C) 2005 Cluster File Systems, Inc. - * Author: Lai Siyao + * 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 (c) 2007, 2010, Oracle and/or its affiliates. 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_capa.c + * + * Lustre Metadata Target (mdt) capability key read/write/update. + * + * Author: Lai Siyao */ #ifndef EXPORT_SYMTAB @@ -35,25 +49,21 @@ static inline void set_capa_key_expiry(struct mdt_device *mdt) { - mdt->mdt_ck_expiry = jiffies + mdt->mdt_ck_timeout * HZ; + mdt->mdt_ck_expiry = jiffies + mdt->mdt_ck_timeout * CFS_HZ; } static void make_capa_key(struct lustre_capa_key *key, mdsno_t mdsnum, int keyid) { - key->lk_mdsid = mdsnum; + key->lk_seq = mdsnum; key->lk_keyid = keyid + 1; - ll_get_random_bytes(key->lk_key, sizeof(key->lk_key)); + cfs_get_random_bytes(key->lk_key, sizeof(key->lk_key)); } -enum { - MDT_TXN_CAPA_KEYS_WRITE_CREDITS = 1 -}; - static inline void lck_cpu_to_le(struct lustre_capa_key *tgt, struct lustre_capa_key *src) { - tgt->lk_mdsid = cpu_to_le64(src->lk_mdsid); + tgt->lk_seq = cpu_to_le64(src->lk_seq); tgt->lk_keyid = cpu_to_le32(src->lk_keyid); tgt->lk_padding = cpu_to_le32(src->lk_padding); memcpy(tgt->lk_key, src->lk_key, sizeof(src->lk_key)); @@ -62,7 +72,7 @@ static inline void lck_cpu_to_le(struct lustre_capa_key *tgt, static inline void lck_le_to_cpu(struct lustre_capa_key *tgt, struct lustre_capa_key *src) { - tgt->lk_mdsid = le64_to_cpu(src->lk_mdsid); + tgt->lk_seq = le64_to_cpu(src->lk_seq); tgt->lk_keyid = le32_to_cpu(src->lk_keyid); tgt->lk_padding = le32_to_cpu(src->lk_padding); memcpy(tgt->lk_key, src->lk_key, sizeof(src->lk_key)); @@ -79,8 +89,8 @@ static int write_capa_keys(const struct lu_env *env, int i, rc; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - - th = mdt_trans_start(env, mdt, MDT_TXN_CAPA_KEYS_WRITE_CREDITS); + mdt_trans_credit_init(env, mdt, MDT_TXN_CAPA_KEYS_WRITE_OP); + th = mdt_trans_start(env, mdt); if (IS_ERR(th)) RETURN(PTR_ERR(th)); @@ -89,9 +99,9 @@ static int write_capa_keys(const struct lu_env *env, for (i = 0; i < 2; i++) { lck_cpu_to_le(tmp, &keys[i]); - rc = mdt_record_write(env, mdt->mdt_ck_obj, - mdt_buf_const(env, tmp, sizeof(*tmp)), - &off, th); + rc = dt_record_write(env, mdt->mdt_ck_obj, + mdt_buf_const(env, tmp, sizeof(*tmp)), + &off, th); if (rc) break; } @@ -115,8 +125,8 @@ static int read_capa_keys(const struct lu_env *env, tmp = &mti->mti_capa_key; for (i = 0; i < 2; i++) { - rc = mdt_record_read(env, mdt->mdt_ck_obj, - mdt_buf(env, tmp, sizeof(*tmp)), &off); + rc = dt_record_read(env, mdt->mdt_ck_obj, + mdt_buf(env, tmp, sizeof(*tmp)), &off); if (rc) return rc; @@ -138,7 +148,7 @@ int mdt_capa_keys_init(const struct lu_env *env, struct mdt_device *mdt) int rc; ENTRY; - mdsnum = mdt->mdt_md_dev.md_lu_dev.ld_site->ls_node_id; + mdsnum = mdt_md_site(mdt)->ms_node_id; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); LASSERT(mti != NULL); @@ -171,7 +181,7 @@ int mdt_capa_keys_init(const struct lu_env *env, struct mdt_device *mdt) } } set_capa_key_expiry(mdt); - mod_timer(&mdt->mdt_ck_timer, mdt->mdt_ck_expiry); + cfs_timer_arm(&mdt->mdt_ck_timer, mdt->mdt_ck_expiry); CDEBUG(D_SEC, "mds_ck_timer %lu\n", mdt->mdt_ck_expiry); RETURN(0); } @@ -183,7 +193,7 @@ void mdt_ck_timer_callback(unsigned long castmeharder) ENTRY; thread->t_flags |= SVC_EVENT; - wake_up(&thread->t_ctl_waitq); + cfs_waitq_signal(&thread->t_ctl_waitq); EXIT; } @@ -202,24 +212,25 @@ static int mdt_ck_thread_main(void *args) int rc; ENTRY; - ptlrpc_daemonize("mdt_ck"); + cfs_daemonize_ctxt("mdt_ck"); cfs_block_allsigs(); thread->t_flags = SVC_RUNNING; cfs_waitq_signal(&thread->t_ctl_waitq); - rc = lu_env_init(&env, NULL, LCT_MD_THREAD); + rc = lu_env_init(&env, LCT_MD_THREAD|LCT_REMEMBER|LCT_NOREF); if (rc) RETURN(rc); thread->t_env = &env; env.le_ctx.lc_thread = thread; + env.le_ctx.lc_cookie = 0x1; info = lu_context_key_get(&env.le_ctx, &mdt_thread_key); LASSERT(info != NULL); tmp = &info->mti_capa_key; - mdsnum = mdt->mdt_md_dev.md_lu_dev.ld_site->ls_node_id; + mdsnum = mdt_md_site(mdt)->ms_node_id; while (1) { l_wait_event(thread->t_ctl_waitq, thread->t_flags & (SVC_STOPPING | SVC_EVENT), @@ -229,7 +240,7 @@ static int mdt_ck_thread_main(void *args) break; thread->t_flags &= ~SVC_EVENT; - if (time_after(mdt->mdt_ck_expiry, jiffies)) + if (cfs_time_before(cfs_time_current(), mdt->mdt_ck_expiry)) break; *tmp = *rkey; @@ -238,17 +249,17 @@ static int mdt_ck_thread_main(void *args) next = mdt->mdt_child; rc = next->md_ops->mdo_update_capa_key(&env, next, tmp); if (!rc) { - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); *bkey = *rkey; *rkey = *tmp; - spin_unlock(&capa_lock); + cfs_spin_unlock(&capa_lock); rc = write_capa_keys(&env, mdt, mdt->mdt_capa_keys); if (rc) { - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); *rkey = *bkey; memset(bkey, 0, sizeof(*bkey)); - spin_unlock(&capa_lock); + cfs_spin_unlock(&capa_lock); } else { set_capa_key_expiry(mdt); DEBUG_CAPA_KEY(D_SEC, rkey, "new"); @@ -257,10 +268,10 @@ static int mdt_ck_thread_main(void *args) if (rc) { DEBUG_CAPA_KEY(D_ERROR, rkey, "update failed for"); /* next retry is in 300 sec */ - mdt->mdt_ck_expiry = jiffies + 300 * HZ; + mdt->mdt_ck_expiry = jiffies + 300 * CFS_HZ; } - mod_timer(&mdt->mdt_ck_timer, mdt->mdt_ck_expiry); + cfs_timer_arm(&mdt->mdt_ck_timer, mdt->mdt_ck_expiry); CDEBUG(D_SEC, "mdt_ck_timer %lu\n", mdt->mdt_ck_expiry); } lu_env_fini(&env); @@ -277,13 +288,13 @@ int mdt_ck_thread_start(struct mdt_device *mdt) cfs_waitq_init(&thread->t_ctl_waitq); rc = cfs_kernel_thread(mdt_ck_thread_main, mdt, - (CLONE_VM | CLONE_FILES)); + (CLONE_VM | CLONE_FILES)); if (rc < 0) { CERROR("cannot start mdt_ck thread, rc = %d\n", rc); return rc; } - cfs_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING); + l_cfs_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING); return 0; } @@ -296,7 +307,5 @@ void mdt_ck_thread_stop(struct mdt_device *mdt) thread->t_flags = SVC_STOPPING; cfs_waitq_signal(&thread->t_ctl_waitq); - cfs_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED); + l_cfs_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED); } - -