4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA
24 * Copyright (c) 2012, Intel Corporation.
27 * lustre/target/tgt_main.c
29 * Lustre Unified Target main initialization code
31 * Author: Mikhail Pershin <mike.pershin@intel.com>
34 #define DEBUG_SUBSYSTEM S_CLASS
38 #include "tgt_internal.h"
40 int tgt_init(const struct lu_env *env, struct lu_target *lut,
41 struct obd_device *obd, struct dt_device *dt)
43 struct dt_object_format dof;
55 lut->lut_last_rcvd = NULL;
56 obd->u.obt.obt_lut = lut;
57 obd->u.obt.obt_magic = OBT_MAGIC;
59 spin_lock_init(&lut->lut_translock);
61 OBD_ALLOC(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3);
62 if (lut->lut_client_bitmap == NULL)
65 memset(&attr, 0, sizeof(attr));
66 attr.la_valid = LA_MODE;
67 attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
68 dof.dof_type = dt_mode_to_dft(S_IFREG);
70 lu_local_obj_fid(&fid, LAST_RECV_OID);
72 o = dt_find_or_create(env, lut->lut_bottom, &fid, &dof, &attr);
74 lut->lut_last_rcvd = o;
76 OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3);
77 lut->lut_client_bitmap = NULL;
79 CERROR("cannot open %s: rc = %d\n", LAST_RCVD, rc);
84 EXPORT_SYMBOL(tgt_init);
86 void tgt_fini(const struct lu_env *env, struct lu_target *lut)
90 if (lut->lut_client_bitmap) {
91 OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3);
92 lut->lut_client_bitmap = NULL;
94 if (lut->lut_last_rcvd) {
95 lu_object_put(env, &lut->lut_last_rcvd->do_lu);
96 lut->lut_last_rcvd = NULL;
100 EXPORT_SYMBOL(tgt_fini);
102 /* context key constructor/destructor: tg_key_init, tg_key_fini */
103 LU_KEY_INIT_FINI(tgt, struct tgt_thread_info);
105 /* context key: tg_thread_key */
106 LU_CONTEXT_KEY_DEFINE(tgt, LCT_MD_THREAD | LCT_DT_THREAD);
107 EXPORT_SYMBOL(tgt_thread_key);
109 LU_KEY_INIT_GENERIC(tg);
111 int tgt_mod_init(void)
113 tg_key_init_generic(&tgt_thread_key, NULL);
114 lu_context_key_register_many(&tgt_thread_key, NULL);
118 void tgt_mod_exit(void)
120 lu_context_key_degister(&tgt_thread_key);