Whamcloud - gitweb
- landing of b_fid after merge with b_hd_cleanup_merge.
[fs/lustre-release.git] / lustre / cmobd / cmobd_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 "cmobd_internal.h"
37
38 static int cmobd_reint_record(int opcode, struct obd_device *obd, char *record)
39 {
40         int rc = 0;
41         
42         switch (opcode) {
43         case OST_CREATE:
44                 rc = cmobd_reint_create(obd, record);
45                 break;                       
46         case OST_SETATTR:
47                 rc = cmobd_reint_setattr(obd, record);
48                 break;                       
49         case OST_WRITE:
50                 rc = cmobd_reint_write(obd, record);
51                 break;                       
52         case MDS_REINT:
53                 rc = cmobd_reint_mds(obd, record);
54                 break;                       
55         default:
56                 CERROR("unrecognized format %d\n", opcode);
57                 rc = -EINVAL;
58                 break; 
59         }
60         return rc;
61 }  
62 static int cmobd_reint_cb(struct llog_handle *llh, struct llog_rec_hdr *rec,
63                           void *data)
64 {
65         struct obd_device *obd = (struct obd_device*)data;
66         char *buf, *pbuf;
67         int rc = 0, opcode;
68         
69         ENTRY;
70
71         if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
72                 CERROR("log is not plain log\n");
73                 RETURN(-EINVAL);
74         }
75         if (rec->lrh_type != SMFS_UPDATE_REC)
76                 RETURN(-EINVAL);
77
78         buf = (char *)(rec + 1);
79         rc = smfs_rec_unpack(NULL, buf, &pbuf, &opcode);
80         if (rc)
81                 GOTO(out, rc);
82         rc = cmobd_reint_record(opcode, obd, pbuf); 
83         if (rc)
84                 GOTO(out, rc);
85         /*delete this record*/
86         rc = LLOG_DEL_RECORD; 
87 out:
88         RETURN(rc);
89 }
90
91 int cmobd_reintegrate(struct obd_device *obd)
92 {
93         struct cache_manager_obd *cmobd = &obd->u.cmobd;
94         struct llog_ctxt *ctxt = NULL;
95         struct llog_handle *llh;
96         int val_size, rc = 0;
97         ENTRY;
98
99         /* XXX just fetch the reintegration log context from
100          * cache ost directly, use logid later ?? */
101         val_size = sizeof(ctxt);
102         rc = obd_get_info(cmobd->cm_cache_exp, strlen("reint_log") + 1,
103                           "reint_log", &val_size, &ctxt);
104         if (rc)
105                 RETURN(rc);
106
107         /* use the already opened log handle instead of 
108          * reopen a new log handle */
109         llh = ctxt ? ctxt->loc_handle : NULL;
110         if (llh == NULL)
111                 RETURN(-EFAULT);
112
113         /* FIXME should we insert a LLOG_GEN_REC before process log ? */
114         rc = llog_cat_process(llh, (llog_cb_t)cmobd_reint_cb, obd);
115
116         RETURN(rc);
117 }
118
119