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