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 <portals/list.h>
26 /* helper functions for calling the llog obd methods */
28 int obd_llog_setup(struct obd_device *obd, int index,
29 struct obd_device *disk_obd, int count,
30 struct llog_logid *logid, struct llog_operations *op)
33 struct llog_ctxt *ctxt;
36 if (index < 0 || index >= LLOG_MAX_CTXTS)
39 OBD_ALLOC(ctxt, sizeof(*ctxt));
43 obd->obd_llog_ctxt[index] = ctxt;
44 ctxt->loc_logops = op;
46 ctxt->loc_idx = index;
47 ctxt->loc_exp = class_export_get(disk_obd->obd_self_export);
48 sema_init(&ctxt->loc_sem, 1);
50 if (op->lop_close == llog_lvfs_ops.lop_close) {
51 ctxt->loc_fsops = disk_obd->obd_fsops;
52 ctxt->loc_lvfs_ctxt = &disk_obd->obd_lvfs_ctxt;
53 if (!strcmp(disk_obd->obd_type->typ_name, "mds")) {
54 struct mds_obd *mds = &disk_obd->u.mds;
55 ctxt->loc_objects_dir = mds->mds_objects_dir;
56 ctxt->loc_logs_dir = mds->mds_logs_dir;
61 rc = op->lop_setup(obd, index, disk_obd, count, logid);
63 obd->obd_llog_ctxt[index] = NULL;
64 OBD_FREE(ctxt, sizeof(*ctxt));
69 EXPORT_SYMBOL(obd_llog_setup);
71 int obd_llog_cleanup(struct llog_ctxt *ctxt)
78 ctxt->loc_obd->obd_llog_ctxt[ctxt->loc_idx] = NULL;
79 class_export_put(ctxt->loc_exp);
82 if (CTXTP(ctxt, cleanup))
83 rc = CTXTP(ctxt, cleanup)(ctxt);
85 OBD_FREE(ctxt, sizeof(*ctxt));
89 EXPORT_SYMBOL(obd_llog_cleanup);
91 /* callback func for llog_process in llog_obd_origin_setup */
92 static int cat_cancel_cb(struct llog_handle *cathandle,
93 struct llog_rec_hdr *rec, void *data)
95 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
96 struct llog_handle *loghandle;
97 struct llog_log_hdr *llh;
101 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
102 CERROR("invalid record in catalog\n");
105 CWARN("processing log "LPX64":%x at index %u of catalog "LPX64"\n",
106 lir->lid_id.lgl_oid, lir->lid_id.lgl_ogen,
107 rec->lrh_index, cathandle->lgh_id.lgl_oid);
109 rc = llog_cat_id2handle(cathandle, &loghandle, &lir->lid_id);
111 CERROR("Cannot find handle for log "LPX64"\n",
112 lir->lid_id.lgl_oid);
116 llh = loghandle->lgh_hdr;
117 if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
118 (llh->llh_count == 1)) {
119 rc = llog_destroy(loghandle);
121 CERROR("failure destroying log in postsetup: %d\n", rc);
124 index = loghandle->u.phd.phd_cookie.lgc_index;
125 llog_free_handle(loghandle);
128 llog_cat_set_first_idx(cathandle, index);
129 rc = llog_cancel_rec(cathandle, index);
131 CWARN("cancel log "LPX64":%x at index %u of catalog "
132 LPX64"\n", lir->lid_id.lgl_oid,
133 lir->lid_id.lgl_ogen, rec->lrh_index,
134 cathandle->lgh_id.lgl_oid);
140 /* lop_setup method for filter/osc */
141 // XXX how to set exports
142 int llog_obd_origin_setup(struct obd_device *obd, int index,
143 struct obd_device *disk_obd, int count,
144 struct llog_logid *logid)
146 struct llog_ctxt *ctxt;
147 struct llog_handle *handle;
148 struct lvfs_run_ctxt saved;
157 ctxt = llog_get_context(obd, index);
162 rc = llog_create(ctxt, &handle, logid, NULL);
164 rc = llog_create(ctxt, &handle, NULL, NULL);
166 *logid = handle->lgh_id;
171 ctxt->loc_handle = handle;
172 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
173 rc = llog_init_handle(handle, LLOG_F_IS_CAT, NULL);
174 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
178 rc = llog_process(handle, (llog_cb_t)cat_cancel_cb, NULL, NULL);
180 CERROR("llog_process with cat_cancel_cb failed: %d\n", rc);
183 EXPORT_SYMBOL(llog_obd_origin_setup);
185 int obd_llog_cat_initialize(struct obd_device *obd, int count, char *name)
187 struct llog_catid *idarray;
188 int size = sizeof(*idarray) * count;
192 OBD_ALLOC(idarray, size);
196 rc = llog_get_cat_list(&obd->obd_lvfs_ctxt, obd->obd_fsops,
197 name, count, idarray);
199 CERROR("rc: %d\n", rc);
203 rc = obd_llog_init(obd, obd, count, idarray);
205 CERROR("rc: %d\n", rc);
209 rc = llog_put_cat_list(&obd->obd_lvfs_ctxt, obd->obd_fsops,
210 name, count, idarray);
212 CERROR("rc: %d\n", rc);
217 OBD_FREE(idarray, size);
220 EXPORT_SYMBOL(obd_llog_cat_initialize);
222 int obd_llog_init(struct obd_device *obd, struct obd_device *disk_obd,
223 int count, struct llog_catid *logid)
227 OBD_CHECK_OP(obd, llog_init, 0);
228 OBD_COUNTER_INCREMENT(obd, llog_init);
230 rc = OBP(obd, llog_init)(obd, disk_obd, count, logid);
233 EXPORT_SYMBOL(obd_llog_init);
235 int obd_llog_finish(struct obd_device *obd, int count)
239 OBD_CHECK_OP(obd, llog_finish, 0);
240 OBD_COUNTER_INCREMENT(obd, llog_finish);
242 rc = OBP(obd, llog_finish)(obd, count);
245 EXPORT_SYMBOL(obd_llog_finish);