Whamcloud - gitweb
6537be4570c04ddeaf167351aa8aa02b2d60fbf6
[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 /* Add log records for each OSC that this object is striped over, and return
55  * cookies for each one.  We _would_ have nice abstraction here, except that
56  * we need to keep cookies in stripe order, even if some are NULL, so that
57  * the right cookies are passed back to the right OSTs at the client side.
58  * Unset cookies should be all-zero (which will never occur naturally). */
59 static int lov_llog_origin_add(struct llog_ctxt *ctxt,
60                         struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
61                         struct llog_cookie *logcookies, int numcookies,
62                         llog_fill_rec_cb_t fill_cb)
63 {
64         struct obd_device *obd = ctxt->loc_obd;
65         struct lov_obd *lov = &obd->u.lov;
66         struct lov_oinfo *loi;
67         int i, rc = 0;
68         ENTRY;
69
70         LASSERT(logcookies && numcookies >= lsm->lsm_stripe_count);
71
72         for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
73                 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
74                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
75                 struct llog_fill_rec_data data;
76
77                 /* fill mds unlink/setattr log record */
78                 data.lfd_id = loi->loi_id;
79                 data.lfd_ogen = loi->loi_gr;
80                 fill_cb(rec, &data);
81
82                 rc += llog_add(cctxt, rec, NULL, logcookies + rc,
83                                 numcookies - rc, fill_cb);
84
85         }
86
87         RETURN(rc);
88 }
89
90 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
91                                    struct llog_logid *logid, 
92                                    struct llog_gen *gen,
93                                    struct obd_uuid *uuid)
94 {
95         struct obd_device *obd = ctxt->loc_obd;
96         struct lov_obd *lov = &obd->u.lov;
97         struct lov_tgt_desc *tgt;
98         int i, rc = 0;
99         ENTRY;
100
101         LASSERT(lov->desc.ld_tgt_count  == count);
102         for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
103                 struct obd_device *child;
104                 struct llog_ctxt *cctxt;
105                 
106                 if (!tgt->active)
107                         continue;
108                 child = tgt->ltd_exp->exp_obd;
109                 cctxt = llog_get_context(child, ctxt->loc_idx);
110                 if (uuid && !obd_uuid_equals(uuid, &lov->tgts[i].uuid))
111                         continue;
112
113                 rc = llog_connect(cctxt, 1, logid, gen, uuid);
114                 if (rc) {
115                         CERROR("error osc_llog_connect %d\n", i);
116                         break;
117                 }
118         }
119
120         RETURN(rc);
121 }
122
123 /* the replicators commit callback */
124 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
125                           int count, struct llog_cookie *cookies, int flags)
126 {
127         struct lov_obd *lov;
128         struct obd_device *obd = ctxt->loc_obd;
129         struct lov_oinfo *loi;
130         int rc = 0, i;
131         ENTRY;
132
133         LASSERT(lsm != NULL);
134         LASSERT(count == lsm->lsm_stripe_count);
135
136         loi = lsm->lsm_oinfo;
137         lov = &obd->u.lov;
138         for (i = 0; i < count; i++, cookies++, loi++) {
139                 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
140                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
141                 int err;
142
143                 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
144                 if (err && lov->tgts[loi->loi_ost_idx].active) {
145                         CERROR("error: objid "LPX64" subobj "LPX64
146                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
147                                loi->loi_id, loi->loi_ost_idx, err);
148                         if (!rc)
149                                 rc = err;
150                 }
151         }
152         RETURN(rc);
153 }
154
155 static struct llog_operations lov_mds_ost_orig_logops = {
156         lop_add: lov_llog_origin_add,
157         lop_connect: lov_llog_origin_connect
158 };
159
160 static struct llog_operations lov_size_repl_logops = {
161         lop_cancel: lov_llog_repl_cancel
162 };
163
164 int lov_llog_init(struct obd_device *obd, struct obd_device *tgt,
165                   int count, struct llog_catid *logid)
166 {
167         struct lov_obd *lov = &obd->u.lov;
168         struct lov_tgt_desc *ctgt;
169         int i, rc = 0;
170         ENTRY;
171
172         rc = llog_setup(obd, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
173                         &lov_mds_ost_orig_logops);
174         if (rc)
175                 RETURN(rc);
176
177         rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
178                         &lov_size_repl_logops);
179         if (rc)
180                 RETURN(rc);
181
182         LASSERT(lov->desc.ld_tgt_count == count);
183         for (i = 0, ctgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, ctgt++) {
184                 struct obd_device *child;
185                 if (!ctgt->active)
186                         continue;
187                 child = ctgt->ltd_exp->exp_obd;
188                 rc = obd_llog_init(child, tgt, 1, logid + i);
189                 if (rc) {
190                         CERROR("error osc_llog_init %d\n", i);
191                         break;
192                 }
193         }
194         RETURN(rc);
195 }
196
197 int lov_llog_finish(struct obd_device *obd, int count)
198 {
199         struct llog_ctxt *ctxt;
200         int rc = 0, rc2 = 0;
201         ENTRY;
202
203         /* cleanup our llogs only if the ctxts have been setup
204          * (client lov doesn't setup, mds lov does). */
205         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
206         if (ctxt)
207                 rc = llog_cleanup(ctxt);
208
209         ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
210         if (ctxt)
211                 rc2 = llog_cleanup(ctxt);
212         if (!rc)
213                 rc = rc2;
214
215         /* lov->tgt llogs are cleaned during osc_cleanup. */
216         RETURN(rc);
217 }