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 <portals/list.h>
27 /* helper functions for calling the llog obd methods */
29 int obd_llog_setup(struct obd_device *obd, struct obd_llogs *llogs,
30 int index, struct obd_device *disk_obd, int count,
31 struct llog_logid *logid, struct llog_operations *op)
34 struct llog_ctxt *ctxt;
39 if (index < 0 || index >= LLOG_MAX_CTXTS)
42 OBD_ALLOC(ctxt, sizeof(*ctxt));
46 llogs->llog_ctxt[index] = ctxt;
47 obd->obd_llog_ctxt[index] = ctxt;
48 ctxt->loc_logops = op;
50 ctxt->loc_llogs = llogs;
51 ctxt->loc_idx = index;
53 ctxt->loc_exp = class_export_get(disk_obd->obd_self_export);
54 sema_init(&ctxt->loc_sem, 1);
56 if (op->lop_close == llog_lvfs_ops.lop_close) {
57 ctxt->loc_fsops = disk_obd->obd_fsops;
58 ctxt->loc_lvfs_ctxt = &disk_obd->obd_lvfs_ctxt;
59 if (!strcmp(disk_obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
60 struct mds_obd *mds = &disk_obd->u.mds;
61 ctxt->loc_objects_dir = mds->mds_objects_dir;
62 ctxt->loc_logs_dir = mds->mds_logs_dir;
67 rc = op->lop_setup(obd, llogs, index, disk_obd, count, logid);
69 obd->obd_llog_ctxt[index] = NULL;
70 OBD_FREE(ctxt, sizeof(*ctxt));
75 EXPORT_SYMBOL(obd_llog_setup);
77 int obd_llog_cleanup(struct llog_ctxt *ctxt)
85 if (CTXTP(ctxt, cleanup))
86 rc = CTXTP(ctxt, cleanup)(ctxt);
88 ctxt->loc_obd->obd_llog_ctxt[ctxt->loc_idx] = NULL;
89 ctxt->loc_llogs->llog_ctxt[ctxt->loc_idx] = NULL;
90 class_export_put(ctxt->loc_exp);
92 OBD_FREE(ctxt, sizeof(*ctxt));
95 EXPORT_SYMBOL(obd_llog_cleanup);
97 /* callback func for llog_process in llog_obd_origin_setup */
98 static int cat_cancel_cb(struct llog_handle *cathandle,
99 struct llog_rec_hdr *rec, void *data)
101 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
102 struct llog_handle *loghandle;
106 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
107 CERROR("invalid record in catalog\n");
110 CDEBUG(D_HA, "processing log "LPX64":%x at index %u of catalog "LPX64"\n",
111 lir->lid_id.lgl_oid, lir->lid_id.lgl_ogen,
112 rec->lrh_index, cathandle->lgh_id.lgl_oid);
114 rc = llog_cat_id2handle(cathandle, &loghandle, &lir->lid_id);
116 CERROR("Cannot find handle for log "LPX64"\n",
117 lir->lid_id.lgl_oid);
121 if (cathandle->lgh_last_idx == loghandle->u.phd.phd_cookie.lgc_index)
122 cathandle->u.chd.chd_current_log = loghandle;
127 /* lop_setup method for filter/osc */
128 // XXX how to set exports
129 int llog_obd_origin_setup(struct obd_device *obd, struct obd_llogs *llogs,
130 int index, struct obd_device *disk_obd, int count,
131 struct llog_logid *logid)
133 struct llog_ctxt *ctxt;
134 struct llog_handle *handle;
135 struct lvfs_run_ctxt saved;
144 ctxt = llog_get_context(llogs, index);
148 if (logid->lgl_oid) {
149 rc = llog_open(ctxt, &handle, logid, NULL, 0);
151 rc = llog_open(ctxt, &handle, NULL, NULL, 0);
153 *logid = handle->lgh_id;
158 ctxt->loc_handle = handle;
159 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
160 rc = llog_init_handle(handle, LLOG_F_IS_CAT, NULL);
161 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
165 rc = llog_process(handle, (llog_cb_t)cat_cancel_cb, NULL, NULL);
167 CERROR("llog_process with cat_cancel_cb failed: %d\n", rc);
170 llogs->llog_ctxt[index] = NULL;
171 OBD_FREE(ctxt, sizeof(*ctxt));
175 EXPORT_SYMBOL(llog_obd_origin_setup);
177 int obd_llog_cat_initialize(struct obd_device *obd, struct obd_llogs *llogs,
178 int count, char *name)
180 struct llog_catid *idarray;
181 int size = sizeof(*idarray) * count;
185 OBD_ALLOC(idarray, size);
189 rc = llog_get_cat_list(&obd->obd_lvfs_ctxt, obd->obd_fsops,
190 name, count, idarray);
192 CERROR("rc: %d\n", rc);
196 rc = obd_llog_init(obd, llogs, obd, count, idarray);
198 CERROR("rc: %d\n", rc);
202 rc = llog_put_cat_list(&obd->obd_lvfs_ctxt, obd->obd_fsops,
203 name, count, idarray);
205 CERROR("rc: %d\n", rc);
210 OBD_FREE(idarray, size);
213 EXPORT_SYMBOL(obd_llog_cat_initialize);
215 int obd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
216 struct obd_device *disk_obd, int count,
217 struct llog_catid *logid)
221 OBD_CHECK_OP(obd, llog_init, 0);
222 OBD_COUNTER_INCREMENT(obd, llog_init);
224 rc = OBP(obd, llog_init)(obd, llogs, disk_obd, count, logid);
227 EXPORT_SYMBOL(obd_llog_init);
229 int obd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs, int count)
233 OBD_CHECK_OP(obd, llog_finish, 0);
234 OBD_COUNTER_INCREMENT(obd, llog_finish);
236 rc = OBP(obd, llog_finish)(obd, llogs, count);
239 EXPORT_SYMBOL(obd_llog_finish);