Whamcloud - gitweb
land v0.9.1 on HEAD, in preparation for a 1.0.x branch
[fs/lustre-release.git] / lustre / lov / lov_log.c
1  /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  * Author: Phil Schwan <phil@clusterfs.com>
6  *         Peter Braam <braam@clusterfs.com>
7  *         Mike Shaver <shaver@clusterfs.com>
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #ifndef EXPORT_SYMTAB
26 # define EXPORT_SYMTAB
27 #endif
28 #define DEBUG_SUBSYSTEM S_LOV
29 #ifdef __KERNEL__
30 #include <linux/slab.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/pagemap.h>
35 #include <asm/div64.h>
36 #include <linux/seq_file.h>
37 #else
38 #include <liblustre.h>
39 #endif
40
41 #include <linux/obd_support.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_net.h>
44 #include <linux/lustre_idl.h>
45 #include <linux/lustre_dlm.h>
46 #include <linux/lustre_mds.h>
47 #include <linux/obd_class.h>
48 #include <linux/obd_lov.h>
49 #include <linux/obd_ost.h>
50 #include <linux/lprocfs_status.h>
51
52 #include "lov_internal.h"
53
54 #if 0
55 static int lov_logop_cleanup(struct llog_ctxt *ctxt)
56 {
57         struct lov_obd *lov = &ctxt->loc_obd->u.lov;
58         int i, rc = 0;
59
60         ENTRY;
61         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
62                 struct obd_device *child = lov->tgts[i].ltd_exp->exp_obd;
63                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
64                 rc = llog_cleanup(cctxt);
65                 if (rc) {
66                         CERROR("error lov_llog_open %d\n", i);
67                         break;
68                 }
69         }
70         RETURN(rc);
71 }
72 #endif
73
74 /* Add log records for each OSC that this object is striped over, and return
75  * cookies for each one.  We _would_ have nice abstraction here, except that
76  * we need to keep cookies in stripe order, even if some are NULL, so that
77  * the right cookies are passed back to the right OSTs at the client side.
78  * Unset cookies should be all-zero (which will never occur naturally). */
79 static int lov_llog_origin_add(struct llog_ctxt *ctxt,
80                         struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
81                         struct llog_cookie *logcookies, int numcookies)
82 {
83         struct obd_device *obd = ctxt->loc_obd;
84         struct lov_obd *lov = &obd->u.lov;
85         struct lov_oinfo *loi;
86         struct llog_unlink_rec *lur;
87         int i, rc = 0;
88         ENTRY;
89
90         OBD_ALLOC(lur, sizeof(*lur));
91         if (!lur)
92                 RETURN(-ENOMEM);
93         lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
94         lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
95
96         LASSERT(logcookies && numcookies >= lsm->lsm_stripe_count);
97
98         for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
99                 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
100                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
101
102                 lur->lur_oid = loi->loi_id;
103                 lur->lur_ogen = loi->loi_gr;
104                 rc += llog_add(cctxt, &lur->lur_hdr, NULL, logcookies + rc, numcookies - rc);
105
106         }
107         OBD_FREE(lur, sizeof(*lur));
108
109         RETURN(rc);
110 }
111
112 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
113                                    struct llog_logid *logid,
114                                    struct llog_ctxt_gen *gen)
115 {
116         struct obd_device *obd = ctxt->loc_obd;
117         struct lov_obd *lov = &obd->u.lov;
118         int i, rc = 0;
119         ENTRY;
120
121         LASSERT(lov->desc.ld_tgt_count  == count);
122         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
123                 struct obd_device *child = lov->tgts[i].ltd_exp->exp_obd;
124                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
125                 rc = llog_connect(cctxt, 1, logid, gen);
126                 if (rc) {
127                         CERROR("error osc_llog_connect %d\n", i);
128                         break;
129                 }
130         }
131
132         RETURN(rc);
133 }
134
135 /* the replicators commit callback */
136 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
137                           int count, struct llog_cookie *cookies, int flags)
138 {
139         struct lov_obd *lov;
140         struct obd_device *obd = ctxt->loc_obd;
141         struct lov_oinfo *loi;
142         int rc = 0, i;
143         ENTRY;
144
145         LASSERT(lsm != NULL);
146         LASSERT(count == lsm->lsm_stripe_count);
147
148         loi = lsm->lsm_oinfo;
149         lov = &obd->u.lov;
150         for (i = 0; i < count; i++, cookies++, loi++) {
151                 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
152                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
153                 int err;
154
155                 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
156                 if (err && lov->tgts[loi->loi_ost_idx].active) {
157                         CERROR("error: objid "LPX64" subobj "LPX64
158                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
159                                loi->loi_id, loi->loi_ost_idx, err);
160                         if (!rc)
161                                 rc = err;
162                 }
163         }
164         RETURN(rc);
165 }
166
167 static struct llog_operations lov_unlink_orig_logops = {
168         lop_add: lov_llog_origin_add,
169         lop_connect: lov_llog_origin_connect
170 };
171
172 static struct llog_operations lov_size_repl_logops = {
173         lop_cancel: lov_llog_repl_cancel
174 };
175
176
177 int lov_llog_init(struct obd_device *obd, struct obd_device *tgt,
178                   int count, struct llog_logid *logid)
179 {
180         struct lov_obd *lov = &obd->u.lov;
181         int i, rc = 0;
182         ENTRY;
183         
184         rc = llog_setup(obd, LLOG_UNLINK_ORIG_CTXT, tgt, 0, NULL,
185                         &lov_unlink_orig_logops);
186         if (rc)
187                 RETURN(rc);
188
189         rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL, 
190                         &lov_size_repl_logops);
191         if (rc)
192                 RETURN(rc);
193
194         LASSERT(lov->desc.ld_tgt_count  == count);
195         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
196                 struct obd_device *child = lov->tgts[i].ltd_exp->exp_obd;
197                 rc = obd_llog_init(child, tgt, 1, logid + i);
198                 if (rc) {
199                         CERROR("error osc_llog_init %d\n", i);
200                         break;
201                 }
202         }
203         RETURN(rc);
204 }
205
206 int lov_llog_finish(struct obd_device *obd, int count)
207 {
208         struct lov_obd *lov = &obd->u.lov;
209         int i, rc = 0;
210         ENTRY;
211         
212         rc = llog_cleanup(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT));
213         if (rc)
214                 RETURN(rc);
215
216         rc = llog_cleanup(llog_get_context(obd, LLOG_SIZE_REPL_CTXT));
217         if (rc)
218                 RETURN(rc);
219
220         LASSERT(lov->desc.ld_tgt_count  == count);
221         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
222                 struct obd_device *child = lov->tgts[i].ltd_exp->exp_obd;
223                 rc = obd_llog_finish(child, 1);
224                 if (rc) {
225                         CERROR("error osc_llog_finish %d\n", i);
226                         break;
227                 }
228         }
229         RETURN(rc);
230 }