1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_CMOBD
24 #include <linux/version.h>
25 #include <linux/init.h>
26 #include <linux/obd_support.h>
27 #include <linux/lustre_lib.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_idl.h>
30 #include <linux/obd_class.h>
31 #include <linux/lustre_log.h>
32 #include <linux/lustre_cmobd.h>
33 #include <linux/lustre_fsfilt.h>
34 #include <linux/lustre_smfs.h>
36 #include "cm_internal.h"
38 #define OSS_REINT(opcode) \
40 int _opcode = (opcode); \
42 (_opcode == OST_CREATE || \
43 _opcode == OST_SETATTR || \
44 _opcode == OST_WRITE); \
47 #define MDS_REINT(opcode) \
48 ((opcode) == MDS_REINT)
50 static int cmobd_reint_record(struct obd_device *obd,
51 void *record, int opcode)
53 if (OSS_REINT(opcode))
54 return cmobd_reint_oss(obd, record, opcode);
56 if (MDS_REINT(opcode))
57 return cmobd_reint_mds(obd, record, opcode);
59 CERROR("unrecognized reint opcode %d\n", opcode);
63 static int cmobd_reint_cb(struct llog_handle *llh,
64 struct llog_rec_hdr *rec,
67 struct obd_device *obd = (struct obd_device*)data;
73 if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
74 CERROR("log is not plain log\n");
78 if (rec->lrh_type != SMFS_UPDATE_REC)
81 buf = (char *)(rec + 1);
82 rc = smfs_rec_unpack(NULL, buf, &pbuf, &opcode);
86 rc = cmobd_reint_record(obd, pbuf, opcode);
90 /* delete this record. */
96 int cmobd_reintegrate(struct obd_device *obd)
98 struct cm_obd *cmobd = &obd->u.cm;
99 struct llog_ctxt *ctxt = NULL;
100 struct llog_handle *llh;
101 int val_size, rc = 0;
104 /* XXX just fetch the reintegration log context from
105 * cache ost directly, use logid later ?? */
106 val_size = sizeof(ctxt);
107 rc = obd_get_info(cmobd->cache_exp, strlen("reint_log") + 1,
108 "reint_log", &val_size, &ctxt);
112 /* use the already opened log handle instead of
113 * reopen a new log handle */
114 llh = ctxt ? ctxt->loc_handle : NULL;
118 /* FIXME should we insert a LLOG_GEN_REC before process log ? */
119 rc = llog_cat_process(llh, (llog_cb_t)cmobd_reint_cb, obd);