Whamcloud - gitweb
Branch b1_4_mountconf
[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 the Lustre file system, http://www.lustre.org
10  *   Lustre is a trademark of Cluster File Systems, Inc.
11  *
12  *   You may have signed or agreed to another license before downloading
13  *   this software.  If so, you are bound by the terms and conditions
14  *   of that agreement, and the following does not apply to you.  See the
15  *   LICENSE file included with this distribution for more information.
16  *
17  *   If you did not agree to a different license, then this copy of Lustre
18  *   is open source software; you can redistribute it and/or modify it
19  *   under the terms of version 2 of the GNU General Public License as
20  *   published by the Free Software Foundation.
21  *
22  *   In either case, Lustre is distributed in the hope that it will be
23  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  *   license text for more details.
26  */
27
28 #ifndef EXPORT_SYMTAB
29 # define EXPORT_SYMTAB
30 #endif
31 #define DEBUG_SUBSYSTEM S_LOV
32 #ifdef __KERNEL__
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/slab.h>
37 #include <linux/pagemap.h>
38 #include <asm/div64.h>
39 #include <linux/seq_file.h>
40 #else
41 #include <liblustre.h>
42 #endif
43
44 #include <linux/obd_support.h>
45 #include <linux/lustre_lib.h>
46 #include <linux/lustre_net.h>
47 #include <linux/lustre_idl.h>
48 #include <linux/lustre_dlm.h>
49 #include <linux/lustre_mds.h>
50 #include <linux/obd_class.h>
51 #include <linux/obd_lov.h>
52 #include <linux/obd_ost.h>
53 #include <linux/lprocfs_status.h>
54
55 #include "lov_internal.h"
56
57 /* Add log records for each OSC that this object is striped over, and return
58  * cookies for each one.  We _would_ have nice abstraction here, except that
59  * we need to keep cookies in stripe order, even if some are NULL, so that
60  * the right cookies are passed back to the right OSTs at the client side.
61  * Unset cookies should be all-zero (which will never occur naturally). */
62 static int lov_llog_origin_add(struct llog_ctxt *ctxt,
63                         struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
64                         struct llog_cookie *logcookies, int numcookies)
65 {
66         struct obd_device *obd = ctxt->loc_obd;
67         struct lov_obd *lov = &obd->u.lov;
68         struct lov_oinfo *loi;
69         int i, rc = 0;
70         ENTRY;
71
72         LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count, 
73                  "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
74                  logcookies, numcookies, lsm->lsm_stripe_count);
75
76         for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
77                 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
78                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
79
80                 /* fill mds unlink/setattr log record */
81                 switch (rec->lrh_type) {
82                 case MDS_UNLINK_REC: {
83                         struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
84                         lur->lur_oid = loi->loi_id;
85                         lur->lur_ogen = loi->loi_gr;
86                         break;
87                 }
88                 case MDS_SETATTR_REC: {
89                         struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
90                         lsr->lsr_oid = loi->loi_id;
91                         lsr->lsr_ogen = loi->loi_gr;
92                         break;
93                 }
94                 default:
95                         break;
96                 }
97
98                 rc += llog_add(cctxt, rec, NULL, logcookies + rc,
99                                 numcookies - rc);
100         }
101
102         RETURN(rc);
103 }
104
105 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
106                                    struct llog_logid *logid,
107                                    struct llog_gen *gen,
108                                    struct obd_uuid *uuid)
109 {
110         struct obd_device *obd = ctxt->loc_obd;
111         struct lov_obd *lov = &obd->u.lov;
112         struct lov_tgt_desc *tgt;
113         int i, rc = 0;
114         ENTRY;
115
116         /* We might have added an osc and not told the mds yet */
117         if (count != lov->desc.ld_tgt_count)
118                 CERROR("Origin connect mds cnt %d != lov cnt %d\n", count,
119                        lov->desc.ld_tgt_count);
120
121         for (i = 0, tgt = lov->tgts; i < count; i++, tgt++) {
122                 struct obd_device *child;
123                 struct llog_ctxt *cctxt;
124                 
125                 if (!tgt->active)
126                         continue;
127                 child = tgt->ltd_exp->exp_obd;
128                 cctxt = llog_get_context(child, ctxt->loc_idx);
129                 if (uuid && !obd_uuid_equals(uuid, &lov->tgts[i].uuid))
130                         continue;
131
132                 rc = llog_connect(cctxt, 1, logid, gen, uuid);
133                 if (rc) {
134                         CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
135                         break;
136                 }
137         }
138
139         RETURN(rc);
140 }
141
142 /* the replicators commit callback */
143 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
144                           int count, struct llog_cookie *cookies, int flags)
145 {
146         struct lov_obd *lov;
147         struct obd_device *obd = ctxt->loc_obd;
148         struct lov_oinfo *loi;
149         int rc = 0, i;
150         ENTRY;
151
152         LASSERT(lsm != NULL);
153         LASSERT(count == lsm->lsm_stripe_count);
154
155         loi = lsm->lsm_oinfo;
156         lov = &obd->u.lov;
157         for (i = 0; i < count; i++, cookies++, loi++) {
158                 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd;
159                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
160                 int err;
161
162                 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
163                 if (err && lov->tgts[loi->loi_ost_idx].active) {
164                         CERROR("error: objid "LPX64" subobj "LPX64
165                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
166                                loi->loi_id, loi->loi_ost_idx, err);
167                         if (!rc)
168                                 rc = err;
169                 }
170         }
171         RETURN(rc);
172 }
173
174 static struct llog_operations lov_mds_ost_orig_logops = {
175         lop_add: lov_llog_origin_add,
176         lop_connect: lov_llog_origin_connect
177 };
178
179 static struct llog_operations lov_size_repl_logops = {
180         lop_cancel: lov_llog_repl_cancel
181 };
182
183 int lov_llog_init(struct obd_device *obd, struct obd_device *tgt,
184                   int count, struct llog_catid *logid)
185 {
186         struct lov_obd *lov = &obd->u.lov;
187         struct lov_tgt_desc *ctgt;
188         int i, rc = 0;
189         ENTRY;
190
191         rc = llog_setup(obd, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
192                         &lov_mds_ost_orig_logops);
193         if (rc)
194                 RETURN(rc);
195
196         rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
197                         &lov_size_repl_logops);
198         if (rc)
199                 RETURN(rc);
200
201         CDEBUG(D_CONFIG, "llog init with %d targets\n", count);
202         LASSERT(lov->desc.ld_tgt_count == count);
203         for (i = 0, ctgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, ctgt++) {
204                 struct obd_device *child;
205                 if (!ctgt->active)
206                         continue;
207                 child = ctgt->ltd_exp->exp_obd;
208                 rc = obd_llog_init(child, tgt, 1, logid + i);
209                 if (rc) {
210                         CERROR("error osc_llog_init %d\n", i);
211                         break;
212                 }
213         }
214         RETURN(rc);
215 }
216
217 int lov_llog_finish(struct obd_device *obd, int count)
218 {
219         struct llog_ctxt *ctxt;
220         int rc = 0, rc2 = 0;
221         ENTRY;
222
223         /* cleanup our llogs only if the ctxts have been setup
224          * (client lov doesn't setup, mds lov does). */
225         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
226         if (ctxt)
227                 rc = llog_cleanup(ctxt);
228
229         ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
230         if (ctxt)
231                 rc2 = llog_cleanup(ctxt);
232         if (!rc)
233                 rc = rc2;
234
235         /* lov->tgt llogs are cleaned during osc_cleanup. */
236         RETURN(rc);
237 }