Whamcloud - gitweb
- landing b_fid.
[fs/lustre-release.git] / lustre / cmobd / cm_reint.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  */
21
22 #define DEBUG_SUBSYSTEM S_CMOBD
23
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>
35
36 #include "cm_internal.h"
37
38 #define OSS_REINT(opcode)      \
39 ({                             \
40     int _opcode = (opcode);    \
41                                \
42     (_opcode == OST_CREATE  || \
43      _opcode == OST_SETATTR || \
44      _opcode == OST_WRITE);    \
45 })
46
47 #define MDS_REINT(opcode)      \
48     ((opcode) == MDS_REINT)
49
50 static int cmobd_reint_record(struct obd_device *obd, 
51                               void *record, int opcode)
52 {
53         if (OSS_REINT(opcode))
54                 return cmobd_reint_oss(obd, record, opcode);
55         
56         if (MDS_REINT(opcode))
57                 return cmobd_reint_mds(obd, record, opcode);
58
59         CERROR("unrecognized reint opcode %d\n", opcode);
60         return -EINVAL;
61 }
62
63 static int cmobd_reint_cb(struct llog_handle *llh, 
64                           struct llog_rec_hdr *rec,
65                           void *data)
66 {
67         struct obd_device *obd = (struct obd_device*)data;
68         char *buf, *pbuf;
69         int rc = 0, opcode;
70         
71         ENTRY;
72
73         if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
74                 CERROR("log is not plain log\n");
75                 RETURN(-EINVAL);
76         }
77         
78         if (rec->lrh_type != SMFS_UPDATE_REC)
79                 RETURN(-EINVAL);
80
81         buf = (char *)(rec + 1);
82         rc = smfs_rec_unpack(NULL, buf, &pbuf, &opcode);
83         if (rc)
84                 GOTO(out, rc);
85
86         rc = cmobd_reint_record(obd, pbuf, opcode); 
87         if (rc)
88                 GOTO(out, rc);
89
90         /* delete this record. */
91         rc = LLOG_DEL_RECORD; 
92 out:
93         RETURN(rc);
94 }
95
96 int cmobd_reintegrate(struct obd_device *obd)
97 {
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;
102         ENTRY;
103
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);
109         if (rc)
110                 RETURN(rc);
111
112         /* use the already opened log handle instead of 
113          * reopen a new log handle */
114         llh = ctxt ? ctxt->loc_handle : NULL;
115         if (llh == NULL)
116                 RETURN(-EFAULT);
117
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);
120
121         RETURN(rc);
122 }