2 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * You should have received a copy of the GNU General Public License
6 * along with Lustre; if not, write to the Free Software
7 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10 #define DEBUG_SUBSYSTEM S_LOG
19 #include <liblustre.h>
22 #include <linux/obd_class.h>
23 #include <linux/lustre_log.h>
24 #include <linux/lustre_mds.h>
25 #include <libcfs/list.h>
27 /* helper functions for calling the llog obd methods */
28 int obd_llog_setup(struct obd_device *obd, struct obd_llogs *llogs,
29 int index, struct obd_device *disk_obd, int count,
30 struct llog_logid *logid, struct llog_operations *op)
32 struct llog_ctxt *ctxt;
38 if (index < 0 || index >= LLOG_MAX_CTXTS)
41 OBD_ALLOC(ctxt, sizeof(*ctxt));
45 llogs->llog_ctxt[index] = ctxt;
46 obd->obd_llog_ctxt[index] = ctxt;
47 ctxt->loc_logops = op;
49 ctxt->loc_llogs = llogs;
50 ctxt->loc_idx = index;
52 ctxt->loc_exp = class_export_get(disk_obd->obd_self_export);
53 sema_init(&ctxt->loc_sem, 1);
55 if (op->lop_close == llog_lvfs_ops.lop_close) {
56 ctxt->loc_fsops = disk_obd->obd_fsops;
57 ctxt->loc_lvfs_ctxt = &disk_obd->obd_lvfs_ctxt;
58 if (!strcmp(disk_obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
59 struct mds_obd *mds = &disk_obd->u.mds;
60 ctxt->loc_objects_dir = mds->mds_objects_dir;
61 ctxt->loc_logs_dir = mds->mds_logs_dir;
62 } else if (!strcmp(disk_obd->obd_type->typ_name, "confobd")) {
63 struct conf_obd *confobd = &disk_obd->u.conf;
64 ctxt->loc_objects_dir = confobd->cfobd_objects_dir;
65 ctxt->loc_logs_dir = confobd->cfobd_logs_dir;
70 rc = op->lop_setup(obd, llogs, index, disk_obd, count, logid);
72 obd->obd_llog_ctxt[index] = NULL;
73 OBD_FREE(ctxt, sizeof(*ctxt));
78 EXPORT_SYMBOL(obd_llog_setup);
80 int obd_llog_cleanup(struct llog_ctxt *ctxt)
88 if (CTXTP(ctxt, cleanup))
89 rc = CTXTP(ctxt, cleanup)(ctxt);
91 ctxt->loc_obd->obd_llog_ctxt[ctxt->loc_idx] = NULL;
92 ctxt->loc_llogs->llog_ctxt[ctxt->loc_idx] = NULL;
93 class_export_put(ctxt->loc_exp);
95 OBD_FREE(ctxt, sizeof(*ctxt));
98 EXPORT_SYMBOL(obd_llog_cleanup);
100 /* callback func for llog_process in llog_obd_origin_setup */
101 static int cat_cancel_cb(struct llog_handle *cathandle,
102 struct llog_rec_hdr *rec, void *data)
104 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
105 struct llog_handle *loghandle;
109 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
110 CERROR("invalid record in catalog\n");
113 CDEBUG(D_HA, "processing log "LPX64":%x at index %u of catalog "LPX64"\n",
114 lir->lid_id.lgl_oid, lir->lid_id.lgl_ogen,
115 rec->lrh_index, cathandle->lgh_id.lgl_oid);
117 rc = llog_cat_id2handle(cathandle, &loghandle, &lir->lid_id);
119 CERROR("Cannot find handle for log "LPX64"\n",
120 lir->lid_id.lgl_oid);
124 if (cathandle->lgh_last_idx == loghandle->u.phd.phd_cookie.lgc_index)
125 cathandle->u.chd.chd_current_log = loghandle;
130 /* lop_setup method for filter/osc */
131 // XXX how to set exports
132 int llog_obd_origin_setup(struct obd_device *obd, struct obd_llogs *llogs,
133 int index, struct obd_device *disk_obd, int count,
134 struct llog_logid *logid)
136 struct llog_ctxt *ctxt;
137 struct llog_handle *handle;
138 struct lvfs_run_ctxt saved;
147 ctxt = llog_get_context(llogs, index);
151 if (logid->lgl_oid) {
152 rc = llog_open(ctxt, &handle, logid, NULL, 0);
154 rc = llog_open(ctxt, &handle, NULL, NULL, 0);
156 *logid = handle->lgh_id;
161 ctxt->loc_handle = handle;
162 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
163 rc = llog_init_handle(handle, LLOG_F_IS_CAT, NULL);
164 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
168 rc = llog_process(handle, (llog_cb_t)cat_cancel_cb, NULL, NULL);
170 CERROR("llog_process with cat_cancel_cb failed: %d\n", rc);
173 llogs->llog_ctxt[index] = NULL;
174 OBD_FREE(ctxt, sizeof(*ctxt));
178 EXPORT_SYMBOL(llog_obd_origin_setup);
180 int obd_llog_cat_initialize(struct obd_device *obd, struct obd_llogs *llogs,
181 int count, const char *name)
183 struct llog_catid *idarray;
184 int size = sizeof(*idarray) * count;
188 OBD_ALLOC(idarray, size);
192 rc = llog_get_cat_list(&obd->obd_lvfs_ctxt, obd->obd_fsops,
193 name, count, idarray);
195 CERROR("rc: %d\n", rc);
199 rc = obd_llog_init(obd, llogs, obd, count, idarray);
201 CERROR("rc: %d\n", rc);
205 rc = llog_put_cat_list(&obd->obd_lvfs_ctxt, obd->obd_fsops,
206 name, count, idarray);
208 CERROR("rc: %d\n", rc);
213 OBD_FREE(idarray, size);
216 EXPORT_SYMBOL(obd_llog_cat_initialize);
218 int obd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
219 struct obd_device *disk_obd, int count,
220 struct llog_catid *logid)
224 OBD_CHECK_OP(obd, llog_init, 0);
225 OBD_COUNTER_INCREMENT(obd, llog_init);
227 rc = OBP(obd, llog_init)(obd, llogs, disk_obd, count, logid);
230 EXPORT_SYMBOL(obd_llog_init);
232 int obd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs, int count)
236 OBD_CHECK_OP(obd, llog_finish, 0);
237 OBD_COUNTER_INCREMENT(obd, llog_finish);
239 rc = OBP(obd, llog_finish)(obd, llogs, count);
242 EXPORT_SYMBOL(obd_llog_finish);