Whamcloud - gitweb
land b_ost_amd onto HEAD.
[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, struct llog_rec_hdr *rec,
60                                void *buf, struct llog_cookie *logcookies, 
61                                int numcookies, void *data)
62 {
63         struct obd_device *obd = ctxt->loc_obd;
64         struct lov_obd *lov = &obd->u.lov;
65         struct lov_oinfo *loi;
66         struct llog_unlink_rec *lur;
67         struct lov_stripe_md *lsm = (struct lov_stripe_md *)buf;
68         int i, rc = 0;
69         ENTRY;
70
71         OBD_ALLOC(lur, sizeof(*lur));
72         if (!lur)
73                 RETURN(-ENOMEM);
74         lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
75         lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
76
77         LASSERT(logcookies && numcookies >= lsm->lsm_stripe_count);
78
79         for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
80                 struct obd_device *child =
81                         lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
82                 struct llog_ctxt *cctxt;
83                 cctxt = llog_get_context(&child->obd_llogs, ctxt->loc_idx);
84
85                 lur->lur_oid = loi->loi_id;
86                 lur->lur_ogen = loi->loi_gr;
87                 LASSERT(lsm->lsm_object_gr == loi->loi_gr);
88                 rc += llog_add(cctxt, &lur->lur_hdr, NULL, logcookies + rc,
89                                numcookies - rc, NULL);
90         }
91         OBD_FREE(lur, sizeof(*lur));
92
93         RETURN(rc);
94 }
95
96 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
97                                    struct llog_logid *logid,
98                                    struct llog_gen *gen, struct obd_uuid *uuid)
99 {
100         struct obd_device *obd = ctxt->loc_obd;
101         struct lov_obd *lov = &obd->u.lov;
102         struct lov_tgt_desc *tgt;
103         int i, rc = 0;
104         ENTRY;
105
106         LASSERT(lov->desc.ld_tgt_count  == count);
107         for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
108                 struct obd_device *child;
109                 struct llog_ctxt *cctxt;
110
111                 if (!tgt->active)
112                         continue;
113                 child = tgt->ltd_exp->exp_obd;
114
115                 cctxt = llog_get_context(&child->obd_llogs, ctxt->loc_idx);
116                 if (uuid && !obd_uuid_equals(uuid, &lov->tgts[i].uuid))
117                         continue;
118
119                 rc = llog_connect(cctxt, 1, logid, gen, uuid);
120                 if (rc) {
121                         CERROR("error osc_llog_connect %d\n", i);
122                         break;
123                 }
124         }
125
126         RETURN(rc);
127 }
128
129 /* the replicators commit callback */
130 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, int count, 
131                                 struct llog_cookie *cookies, int flags,
132                                 void *data)
133 {
134         struct lov_stripe_md *lsm = (struct lov_stripe_md *)data;
135         struct lov_obd *lov;
136         struct obd_device *obd = ctxt->loc_obd;
137         struct lov_oinfo *loi;
138         int rc = 0, i;
139         ENTRY;
140
141         LASSERT(lsm != NULL);
142         LASSERT(count == lsm->lsm_stripe_count);
143
144         loi = lsm->lsm_oinfo;
145         lov = &obd->u.lov;
146         for (i = 0; i < count; i++, cookies++, loi++) {
147                 struct obd_device *child =
148                         lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd; 
149                 struct llog_ctxt *cctxt;
150                 int err;
151
152                 cctxt = llog_get_context(&child->obd_llogs, ctxt->loc_idx);
153                 err = llog_cancel(cctxt, 1, cookies, flags, NULL);
154                 if (err && lov->tgts[loi->loi_ost_idx].active) {
155                         CERROR("error: objid "LPX64" subobj "LPX64
156                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
157                                loi->loi_id, loi->loi_ost_idx, err);
158                         if (!rc)
159                                 rc = err;
160                 }
161         }
162         RETURN(rc);
163 }
164
165 static struct llog_operations lov_unlink_orig_logops = {
166         lop_add: lov_llog_origin_add,
167         lop_connect: lov_llog_origin_connect
168 };
169
170 static struct llog_operations lov_size_repl_logops = {
171         lop_cancel: lov_llog_repl_cancel
172 };
173
174 int lov_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
175                   struct obd_device *tgt, int count, struct llog_catid *logid)
176 {
177         struct lov_obd *lov = &obd->u.lov;
178         struct lov_tgt_desc *ctgt;
179         int i, rc = 0;
180         ENTRY;
181         
182         rc = obd_llog_setup(obd, llogs, LLOG_UNLINK_ORIG_CTXT, tgt, 0, NULL,
183                             &lov_unlink_orig_logops);
184         if (rc)
185                 RETURN(rc);
186
187         rc = obd_llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL, 
188                             &lov_size_repl_logops);
189         if (rc)
190                 RETURN(rc);
191
192         LASSERT(lov->desc.ld_tgt_count  == count);
193         for (i = 0, ctgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, ctgt++) {
194                 struct obd_device *child;
195
196                 if (!ctgt->active)
197                         continue;
198                 child = ctgt->ltd_exp->exp_obd;
199                 rc = obd_llog_init(child, &child->obd_llogs, tgt, 1, logid + i);
200                 if (rc) {
201                         CERROR("error osc_llog_init %d\n", i);
202                         break;
203                 }
204         }
205         RETURN(rc);
206 }
207
208 int lov_llog_finish(struct obd_device *obd, struct obd_llogs *llogs, int count)
209 {
210         struct lov_obd *lov = &obd->u.lov;
211         struct lov_tgt_desc *tgt;
212         int i, rc = 0;
213         ENTRY;
214
215         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_UNLINK_ORIG_CTXT));
216         if (rc)
217                 RETURN(rc);
218
219         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_SIZE_REPL_CTXT));
220         if (rc)
221                 RETURN(rc);
222
223         if (lov->desc.ld_tgt_count != count) {
224                 CERROR("LOV tgt count != passed tgt count (%d != %d)\n",
225                        lov->desc.ld_tgt_count, count);
226                 count = MIN(lov->desc.ld_tgt_count, count);
227         }
228         for (i = 0, tgt = lov->tgts; i < count; i++, tgt++) {
229                 struct obd_device *child;
230
231                 if (!tgt->active)
232                         continue;
233                 child = tgt->ltd_exp->exp_obd;
234                 rc = obd_llog_finish(child, &child->obd_llogs, 1);
235                 if (rc) {
236                         CERROR("osc_llog_finish error; index=%d; rc=%d\n",
237                                i, rc);
238                         break;
239                 }
240         }
241         RETURN(rc);
242 }