From 77e44127bb39f5d1dc1f4e61274e5df7bf707603 Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Sun, 14 Oct 2012 15:58:13 +0400 Subject: [PATCH] LU-2145 target: move target code to the separate directory Create target/ directory for unified target code and move there already existed code from ptlrpc/target.c Signed-off-by: Mikhail Pershin Change-Id: Id808ed3eb390dd051cbca0a3ef2bf02e5f5d722f Reviewed-on: http://review.whamcloud.com/4258 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev --- lustre/autoMakefile.am | 2 +- lustre/autoconf/lustre-core.m4 | 1 + lustre/include/lu_target.h | 4 +- lustre/mdt/mdt_handler.c | 6 +- lustre/ofd/ofd_dev.c | 6 +- lustre/ptlrpc/Makefile.in | 15 +- lustre/ptlrpc/ptlrpc_internal.h | 9 +- lustre/ptlrpc/ptlrpc_module.c | 4 +- lustre/target/Makefile.am | 34 ++++ lustre/target/tgt_internal.h | 69 +++++++ lustre/{ptlrpc/target.c => target/tgt_lastrcvd.c} | 233 ++-------------------- lustre/target/tgt_main.c | 122 +++++++++++ 12 files changed, 264 insertions(+), 241 deletions(-) create mode 100644 lustre/target/Makefile.am create mode 100644 lustre/target/tgt_internal.h rename lustre/{ptlrpc/target.c => target/tgt_lastrcvd.c} (74%) create mode 100644 lustre/target/tgt_main.c diff --git a/lustre/autoMakefile.am b/lustre/autoMakefile.am index 57029c8..728b4c2 100644 --- a/lustre/autoMakefile.am +++ b/lustre/autoMakefile.am @@ -43,7 +43,7 @@ ALWAYS_SUBDIRS = include lvfs obdclass ldlm ptlrpc obdecho \ mgc fid fld doc utils tests scripts autoconf contrib conf SERVER_SUBDIRS = ost mds mgs mdt cmm mdd ofd osd-zfs osd-ldiskfs \ - quota osp lod + quota osp lod target CLIENT_SUBDIRS = mdc lmv llite lclient lov osc diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index bee849c..0bfadda 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -2522,6 +2522,7 @@ lustre/mgc/Makefile lustre/mgc/autoMakefile lustre/mgs/Makefile lustre/mgs/autoMakefile +lustre/target/Makefile lustre/ptlrpc/Makefile lustre/ptlrpc/autoMakefile lustre/ptlrpc/gss/Makefile diff --git a/lustre/include/lu_target.h b/lustre/include/lu_target.h index 7773160..1b41913 100644 --- a/lustre/include/lu_target.h +++ b/lustre/include/lu_target.h @@ -70,9 +70,9 @@ void lut_boot_epoch_update(struct lu_target *lut); int lut_last_commit_cb_add(struct thandle *th, struct lu_target *lut, struct obd_export *exp, __u64 transno); int lut_new_client_cb_add(struct thandle *th, struct obd_export *exp); -int lut_init(const struct lu_env *env, struct lu_target *lut, +int tgt_init(const struct lu_env *env, struct lu_target *lut, struct obd_device *obd, struct dt_device *dt); -void lut_fini(const struct lu_env *env, struct lu_target *lut); +void tgt_fini(const struct lu_env *env, struct lu_target *lut); int lut_client_alloc(struct obd_export *exp); void lut_client_free(struct obd_export *exp); int lut_client_del(const struct lu_env *env, struct obd_export *exp); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 6a51282..95bfdf9 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -5035,7 +5035,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) mdt_procfs_fini(m); - lut_fini(env, &m->mdt_lut); + tgt_fini(env, &m->mdt_lut); mdt_fs_cleanup(env, m); upcall_cache_cleanup(m->mdt_identity_cache); m->mdt_identity_cache = NULL; @@ -5215,7 +5215,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, } } - rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom); + rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom); if (rc) GOTO(err_fini_stack, rc); @@ -5328,7 +5328,7 @@ err_free_ns: err_fini_seq: mdt_seq_fini(env, m); mdt_fld_fini(env, m); - lut_fini(env, &m->mdt_lut); + tgt_fini(env, &m->mdt_lut); err_fini_stack: mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); err_lmi: diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index 302f435..bc26331 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -565,7 +565,7 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, m->ofd_grant_ratio = ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved); - rc = lut_init(env, &m->ofd_lut, obd, m->ofd_osd); + rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd); if (rc) GOTO(err_free_ns, rc); @@ -575,7 +575,7 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, RETURN(0); err_fini_lut: - lut_fini(env, &m->ofd_lut); + tgt_fini(env, &m->ofd_lut); err_free_ns: ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force); obd->obd_namespace = m->ofd_namespace = NULL; @@ -595,7 +595,7 @@ static void ofd_fini(const struct lu_env *env, struct ofd_device *m) obd_exports_barrier(obd); obd_zombie_barrier(); - lut_fini(env, &m->ofd_lut); + tgt_fini(env, &m->ofd_lut); ofd_fs_cleanup(env, m); ofd_free_capa_keys(m); diff --git a/lustre/ptlrpc/Makefile.in b/lustre/ptlrpc/Makefile.in index 9a2e0ca..86da7be 100644 --- a/lustre/ptlrpc/Makefile.in +++ b/lustre/ptlrpc/Makefile.in @@ -1,7 +1,8 @@ MODULES := ptlrpc LDLM := @top_srcdir@/lustre/ldlm/ +TARGET := @top_srcdir@/lustre/target/ -ldlm_objs := $(LDLM)l_lock.o $(LDLM)ldlm_lock.o +ldlm_objs := $(LDLM)l_lock.o $(LDLM)ldlm_lock.o ldlm_objs += $(LDLM)ldlm_resource.o $(LDLM)ldlm_lib.o ldlm_objs += $(LDLM)ldlm_plain.o $(LDLM)ldlm_extent.o ldlm_objs += $(LDLM)ldlm_request.o $(LDLM)ldlm_lockd.o @@ -15,9 +16,10 @@ ptlrpc_objs += pers.o lproc_ptlrpc.o wiretest.o layout.o ptlrpc_objs += sec.o sec_bulk.o sec_gc.o sec_config.o sec_lproc.o ptlrpc_objs += sec_null.o sec_plain.o -@SERVER_TRUE@ptlrpc_objs += target.o +target_objs := $(TARGET)tgt_main.o $(TARGET)tgt_lastrcvd.o ptlrpc-objs := $(ldlm_objs) $(ptlrpc_objs) +@SERVER_TRUE@ptlrpc-objs += $(target_objs) @GSS_TRUE@subdir-m += gss @@ -32,7 +34,12 @@ l_lock.c: @LUSTRE@/ldlm/l_lock.c interval_tree.c: @LUSTRE@/ldlm/interval_tree.c ln -sf $< $@ -EXTRA_DIST = $(ptlrpc_objs:.o=.c) ptlrpc_internal.h -EXTRA_PRE_CFLAGS := -I@LUSTRE@/ldlm +tgt_%.c: @LUSTRE@/target/tgt_%.c + ln -sf $< $@ + +EXTRA_DIST := $(ptlrpc_objs:.o=.c) ptlrpc_internal.h +@SERVER_TRUE@EXTRA_DIST += $(TARGET)tgt_internal.h + +EXTRA_PRE_CFLAGS := -I@LUSTRE@/ldlm -I@LUSTRE@/target @INCLUDE_RULES@ diff --git a/lustre/ptlrpc/ptlrpc_internal.h b/lustre/ptlrpc/ptlrpc_internal.h index ff5be4e..63098fe 100644 --- a/lustre/ptlrpc/ptlrpc_internal.h +++ b/lustre/ptlrpc/ptlrpc_internal.h @@ -156,16 +156,15 @@ static inline int ll_rpc_recoverable_error(int rc) } #ifdef HAVE_SERVER_SUPPORT -/* target.c */ -int lut_mod_init(void); -void lut_mod_exit(void); +int tgt_mod_init(void); +void tgt_mod_exit(void); #else -static inline int lut_mod_init(void) +static inline int tgt_mod_init(void) { return 0; } -static inline void lut_mod_exit(void) +static inline void tgt_mod_exit(void) { return; } diff --git a/lustre/ptlrpc/ptlrpc_module.c b/lustre/ptlrpc/ptlrpc_module.c index 9554935..5f05852 100644 --- a/lustre/ptlrpc/ptlrpc_module.c +++ b/lustre/ptlrpc/ptlrpc_module.c @@ -112,7 +112,7 @@ __init int ptlrpc_init(void) #ifdef __KERNEL__ cleanup_phase = 7; - rc = lut_mod_init(); + rc = tgt_mod_init(); if (rc) GOTO(cleanup, rc); #endif @@ -146,7 +146,7 @@ cleanup: #ifdef __KERNEL__ static void __exit ptlrpc_exit(void) { - lut_mod_exit(); + tgt_mod_exit(); llog_recov_fini(); sptlrpc_fini(); ldlm_exit(); diff --git a/lustre/target/Makefile.am b/lustre/target/Makefile.am new file mode 100644 index 0000000..7e9cd51 --- /dev/null +++ b/lustre/target/Makefile.am @@ -0,0 +1,34 @@ +# +# GPL HEADER START +# +# 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). +# +# You should have received a copy of the GNU General Public License +# version 2 along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 021110-1307, USA +# +# GPL HEADER END +# + +# +# Copyright (c) 2011, 2012, Intel Corporation. +# Use is subject to license terms. +# + +# +# target is built into ptlrpc +# + +MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ +EXTRA_DIST = tgt_main.c tgt_lastrcvd.c tgt_internal.h diff --git a/lustre/target/tgt_internal.h b/lustre/target/tgt_internal.h new file mode 100644 index 0000000..f538abd --- /dev/null +++ b/lustre/target/tgt_internal.h @@ -0,0 +1,69 @@ +/* + * GPL HEADER START + * + * 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). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA + * + * GPL HEADER END + */ +/* + * Copyright (c) 2011, 2012, Intel Corporation. + */ +/* + * lustre/target/tgt_internal.h + * + * Lustre Unified Target header file + * + * Author: Mikhail Pershin + */ + +#ifndef _TG_INTERNAL_H +#define _TG_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +extern struct lu_context_key tgt_thread_key; + +/** + * Common data shared by tg-level handlers. This is allocated per-thread to + * reduce stack consumption. + */ +struct tgt_thread_info { + /* server and client data buffers */ + struct lr_server_data tti_lsd; + struct lsd_client_data tti_lcd; + struct lu_buf tti_buf; + loff_t tti_off; +}; + +static inline struct tgt_thread_info *tgt_th_info(const struct lu_env *env) +{ + struct tgt_thread_info *tti; + + tti = lu_context_key_get(&env->le_ctx, &tgt_thread_key); + LASSERT(tti); + return tti; +} + +#endif /* _TG_INTERNAL_H */ diff --git a/lustre/ptlrpc/target.c b/lustre/target/tgt_lastrcvd.c similarity index 74% rename from lustre/ptlrpc/target.c rename to lustre/target/tgt_lastrcvd.c index 2b099a9..03014a1 100644 --- a/lustre/ptlrpc/target.c +++ b/lustre/target/tgt_lastrcvd.c @@ -33,153 +33,31 @@ * This file is part of Lustre, http://www.lustre.org/ * Lustre is a trademark of Sun Microsystems, Inc. * - * Lustre Common Target - * These are common function for MDT and OST recovery-related functionality + * Lustre Unified Target + * These are common function to work with last_received file * - * Author: Mikhail Pershin + * Author: Mikhail Pershin */ - #include -#include #include #include -/** - * Common data shared by tg-level handlers. This is allocated per-thread to - * reduce stack consumption. - */ -struct tg_thread_info { - /* server and client data buffers */ - struct lr_server_data tti_lsd; - struct lsd_client_data tti_lcd; - struct lu_buf tti_buf; - loff_t tti_off; -}; +#include "tgt_internal.h" -static inline struct lu_buf *tti_buf_lsd(struct tg_thread_info *tti) +static inline struct lu_buf *tti_buf_lsd(struct tgt_thread_info *tti) { tti->tti_buf.lb_buf = &tti->tti_lsd; tti->tti_buf.lb_len = sizeof(tti->tti_lsd); return &tti->tti_buf; } -static inline struct lu_buf *tti_buf_lcd(struct tg_thread_info *tti) +static inline struct lu_buf *tti_buf_lcd(struct tgt_thread_info *tti) { tti->tti_buf.lb_buf = &tti->tti_lcd; tti->tti_buf.lb_len = sizeof(tti->tti_lcd); return &tti->tti_buf; } -extern struct lu_context_key tg_thread_key; - -static inline struct tg_thread_info *tg_th_info(const struct lu_env *env) -{ - struct tg_thread_info *tti; - - tti = lu_context_key_get(&env->le_ctx, &tg_thread_key); - LASSERT(tti); - return tti; -} - -/** - * Update client data in last_rcvd file. An obd API - */ -static int obt_client_data_update(struct obd_export *exp) -{ - struct tg_export_data *ted = &exp->exp_target_data; - struct obd_device_target *obt = &exp->exp_obd->u.obt; - struct lu_target *lut = class_exp2tgt(exp); - loff_t off = ted->ted_lr_off; - int rc = 0; - - rc = fsfilt_write_record(exp->exp_obd, obt->obt_rcvd_filp, - ted->ted_lcd, sizeof(*ted->ted_lcd), &off, 0); - - CDEBUG(D_INFO, "update client idx %u last_epoch %#x (%#x)\n", - ted->ted_lr_idx, le32_to_cpu(ted->ted_lcd->lcd_last_epoch), - le32_to_cpu(lut->lut_lsd.lsd_start_epoch)); - - return rc; -} - -/** - * Update server data in last_rcvd file. An obd API - */ -int obt_server_data_update(struct lu_target *lut, int force_sync) -{ - struct obd_device_target *obt = &lut->lut_obd->u.obt; - loff_t off = 0; - int rc; - ENTRY; - - CDEBUG(D_SUPER, - "%s: mount_count is "LPU64", last_transno is "LPU64"\n", - lut->lut_lsd.lsd_uuid, - le64_to_cpu(lut->lut_lsd.lsd_mount_count), - le64_to_cpu(lut->lut_lsd.lsd_last_transno)); - - rc = fsfilt_write_record(lut->lut_obd, obt->obt_rcvd_filp, - &lut->lut_lsd, sizeof(lut->lut_lsd), - &off, force_sync); - if (rc) - CERROR("error writing lr_server_data: rc = %d\n", rc); - - RETURN(rc); -} - -/** - * Update client epoch with server's one - */ -void obt_client_epoch_update(struct obd_export *exp) -{ - struct lsd_client_data *lcd = exp->exp_target_data.ted_lcd; - struct lu_target *lut = class_exp2tgt(exp); - - /** VBR: set client last_epoch to current epoch */ - if (le32_to_cpu(lcd->lcd_last_epoch) >= - le32_to_cpu(lut->lut_lsd.lsd_start_epoch)) - return; - lcd->lcd_last_epoch = lut->lut_lsd.lsd_start_epoch; - obt_client_data_update(exp); -} - -/** - * Increment server epoch. An obd API - */ -static void obt_boot_epoch_update(struct lu_target *lut) -{ - struct obd_device *obd = lut->lut_obd; - __u32 start_epoch; - struct ptlrpc_request *req; - cfs_list_t client_list; - - cfs_spin_lock(&lut->lut_translock); - start_epoch = lr_epoch(le64_to_cpu(lut->lut_last_transno)) + 1; - lut->lut_last_transno = cpu_to_le64((__u64)start_epoch << - LR_EPOCH_BITS); - lut->lut_lsd.lsd_start_epoch = cpu_to_le32(start_epoch); - cfs_spin_unlock(&lut->lut_translock); - - CFS_INIT_LIST_HEAD(&client_list); - cfs_spin_lock(&obd->obd_recovery_task_lock); - cfs_list_splice_init(&obd->obd_final_req_queue, &client_list); - cfs_spin_unlock(&obd->obd_recovery_task_lock); - - /** - * go through list of exports participated in recovery and - * set new epoch for them - */ - cfs_list_for_each_entry(req, &client_list, rq_list) { - LASSERT(!req->rq_export->exp_delayed); - obt_client_epoch_update(req->rq_export); - } - /** return list back at once */ - cfs_spin_lock(&obd->obd_recovery_task_lock); - cfs_list_splice_init(&client_list, &obd->obd_final_req_queue); - cfs_spin_unlock(&obd->obd_recovery_task_lock); - obt_server_data_update(lut, 1); -} - /** * Allocate in-memory data for client slot related to export. */ @@ -225,7 +103,7 @@ EXPORT_SYMBOL(lut_client_free); int lut_client_data_read(const struct lu_env *env, struct lu_target *tg, struct lsd_client_data *lcd, loff_t *off, int index) { - struct tg_thread_info *tti = tg_th_info(env); + struct tgt_thread_info *tti = tgt_th_info(env); int rc; tti_buf_lcd(tti); @@ -251,7 +129,7 @@ int lut_client_data_write(const struct lu_env *env, struct lu_target *tg, struct lsd_client_data *lcd, loff_t *off, struct thandle *th) { - struct tg_thread_info *tti = tg_th_info(env); + struct tgt_thread_info *tti = tgt_th_info(env); lcd_cpu_to_le(lcd, &tti->tti_lcd); tti_buf_lcd(tti); @@ -267,7 +145,7 @@ int lut_client_data_update(const struct lu_env *env, struct obd_export *exp) { struct tg_export_data *ted = &exp->exp_target_data; struct lu_target *tg = class_exp2tgt(exp); - struct tg_thread_info *tti = tg_th_info(env); + struct tgt_thread_info *tti = tgt_th_info(env); struct thandle *th; int rc = 0; @@ -316,7 +194,7 @@ out: int lut_server_data_read(const struct lu_env *env, struct lu_target *tg) { - struct tg_thread_info *tti = tg_th_info(env); + struct tgt_thread_info *tti = tgt_th_info(env); int rc; tti->tti_off = 0; @@ -335,7 +213,7 @@ EXPORT_SYMBOL(lut_server_data_read); int lut_server_data_write(const struct lu_env *env, struct lu_target *tg, struct thandle *th) { - struct tg_thread_info *tti = tg_th_info(env); + struct tgt_thread_info *tti = tgt_th_info(env); int rc; ENTRY; @@ -360,7 +238,7 @@ EXPORT_SYMBOL(lut_server_data_write); int lut_server_data_update(const struct lu_env *env, struct lu_target *tg, int sync) { - struct tg_thread_info *tti = tg_th_info(env); + struct tgt_thread_info *tti = tgt_th_info(env); struct thandle *th; int rc = 0; @@ -466,9 +344,6 @@ void lut_boot_epoch_update(struct lu_target *lut) if (lut->lut_obd->obd_stopping) return; - /** Increase server epoch after recovery */ - if (lut->lut_bottom == NULL) - return obt_boot_epoch_update(lut); rc = lu_env_init(&env, LCT_DT_THREAD); if (rc) { @@ -799,87 +674,3 @@ int lut_client_del(const struct lu_env *env, struct obd_export *exp) RETURN(rc); } EXPORT_SYMBOL(lut_client_del); - -int lut_init(const struct lu_env *env, struct lu_target *lut, - struct obd_device *obd, struct dt_device *dt) -{ - struct dt_object_format dof; - struct lu_attr attr; - struct lu_fid fid; - struct dt_object *o; - int rc = 0; - ENTRY; - - LASSERT(lut); - LASSERT(obd); - lut->lut_obd = obd; - lut->lut_bottom = dt; - lut->lut_last_rcvd = NULL; - obd->u.obt.obt_lut = lut; - - cfs_spin_lock_init(&lut->lut_translock); - - OBD_ALLOC(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); - if (lut->lut_client_bitmap == NULL) - RETURN(-ENOMEM); - - /** obdfilter has no lu_device stack yet */ - if (dt == NULL) - RETURN(rc); - - memset(&attr, 0, sizeof(attr)); - attr.la_valid = LA_MODE; - attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; - dof.dof_type = dt_mode_to_dft(S_IFREG); - - lu_local_obj_fid(&fid, MDT_LAST_RECV_OID); - - o = dt_find_or_create(env, lut->lut_bottom, &fid, &dof, &attr); - if (!IS_ERR(o)) { - lut->lut_last_rcvd = o; - } else { - OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); - lut->lut_client_bitmap = NULL; - rc = PTR_ERR(o); - CERROR("cannot open %s: rc = %d\n", LAST_RCVD, rc); - } - - RETURN(rc); -} -EXPORT_SYMBOL(lut_init); - -void lut_fini(const struct lu_env *env, struct lu_target *lut) -{ - ENTRY; - - if (lut->lut_client_bitmap) { - OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); - lut->lut_client_bitmap = NULL; - } - if (lut->lut_last_rcvd) { - lu_object_put(env, &lut->lut_last_rcvd->do_lu); - lut->lut_last_rcvd = NULL; - } - EXIT; -} -EXPORT_SYMBOL(lut_fini); - -/* context key constructor/destructor: tg_key_init, tg_key_fini */ -LU_KEY_INIT_FINI(tg, struct tg_thread_info); -/* context key: tg_thread_key */ -LU_CONTEXT_KEY_DEFINE(tg, LCT_MD_THREAD|LCT_DT_THREAD); -LU_KEY_INIT_GENERIC(tg); -EXPORT_SYMBOL(tg_thread_key); - -int lut_mod_init(void) -{ - tg_key_init_generic(&tg_thread_key, NULL); - lu_context_key_register_many(&tg_thread_key, NULL); - return 0; -} - -void lut_mod_exit(void) -{ - lu_context_key_degister_many(&tg_thread_key, NULL); -} - diff --git a/lustre/target/tgt_main.c b/lustre/target/tgt_main.c new file mode 100644 index 0000000..d7b6500 --- /dev/null +++ b/lustre/target/tgt_main.c @@ -0,0 +1,122 @@ +/* + * GPL HEADER START + * + * 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). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA + * + * GPL HEADER END + */ +/* + * Copyright (c) 2011, 2012, Intel Corporation. + */ +/* + * lustre/target/tgt_main.c + * + * Lustre Unified Target main initialization code + * + * Author: Mikhail Pershin + */ + +#define DEBUG_SUBSYSTEM S_CLASS + +#include + +#include "tgt_internal.h" + +int tgt_init(const struct lu_env *env, struct lu_target *lut, + struct obd_device *obd, struct dt_device *dt) +{ + struct dt_object_format dof; + struct lu_attr attr; + struct lu_fid fid; + struct dt_object *o; + int rc = 0; + + ENTRY; + + LASSERT(lut); + LASSERT(obd); + lut->lut_obd = obd; + lut->lut_bottom = dt; + lut->lut_last_rcvd = NULL; + obd->u.obt.obt_lut = lut; + obd->u.obt.obt_magic = OBT_MAGIC; + + cfs_spin_lock_init(&lut->lut_translock); + + OBD_ALLOC(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); + if (lut->lut_client_bitmap == NULL) + RETURN(-ENOMEM); + + memset(&attr, 0, sizeof(attr)); + attr.la_valid = LA_MODE; + attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; + dof.dof_type = dt_mode_to_dft(S_IFREG); + + lu_local_obj_fid(&fid, MDT_LAST_RECV_OID); + + o = dt_find_or_create(env, lut->lut_bottom, &fid, &dof, &attr); + if (!IS_ERR(o)) { + lut->lut_last_rcvd = o; + } else { + OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); + lut->lut_client_bitmap = NULL; + rc = PTR_ERR(o); + CERROR("cannot open %s: rc = %d\n", LAST_RCVD, rc); + } + + RETURN(rc); +} +EXPORT_SYMBOL(tgt_init); + +void tgt_fini(const struct lu_env *env, struct lu_target *lut) +{ + ENTRY; + + if (lut->lut_client_bitmap) { + OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); + lut->lut_client_bitmap = NULL; + } + if (lut->lut_last_rcvd) { + lu_object_put(env, &lut->lut_last_rcvd->do_lu); + lut->lut_last_rcvd = NULL; + } + EXIT; +} +EXPORT_SYMBOL(tgt_fini); + +/* context key constructor/destructor: tg_key_init, tg_key_fini */ +LU_KEY_INIT_FINI(tgt, struct tgt_thread_info); + +/* context key: tg_thread_key */ +LU_CONTEXT_KEY_DEFINE(tgt, LCT_MD_THREAD | LCT_DT_THREAD); +EXPORT_SYMBOL(tgt_thread_key); + +LU_KEY_INIT_GENERIC(tg); + +int tgt_mod_init(void) +{ + tg_key_init_generic(&tgt_thread_key, NULL); + lu_context_key_register_many(&tgt_thread_key, NULL); + return 0; +} + +void tgt_mod_exit(void) +{ + lu_context_key_degister(&tgt_thread_key); +} + -- 1.8.3.1