Whamcloud - gitweb
- unland b_fid to HEAD
[fs/lustre-release.git] / lustre / mds / mds_log.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/mds/mds_log.c
5  *
6  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
7  *   Author: Peter Braam <braam@clusterfs.com>
8  *   Author: Andreas Dilger <adilger@clusterfs.com>
9  *   Author: Phil Schwan <phil@clusterfs.com>
10  *
11  *   This file is part of Lustre, http://www.lustre.org.
12  *
13  *   Lustre is free software; you can redistribute it and/or
14  *   modify it under the terms of version 2 of the GNU General Public
15  *   License as published by the Free Software Foundation.
16  *
17  *   Lustre is distributed in the hope that it will be useful,
18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *   GNU General Public License for more details.
21  *
22  *   You should have received a copy of the GNU General Public License
23  *   along with Lustre; if not, write to the Free Software
24  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #define DEBUG_SUBSYSTEM S_MDS
28
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
32
33 #include <portals/list.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_fsfilt.h>
36 #include <linux/lustre_commit_confd.h>
37
38 #include "mds_internal.h"
39
40 static int mds_llog_origin_add(struct llog_ctxt *ctxt, struct llog_rec_hdr *rec,
41                                void *buf, struct llog_cookie *logcookies,
42                                int numcookies, void *data,
43                                struct rw_semaphore **lock, int *lock_count)
44 {
45         struct obd_device *obd = ctxt->loc_obd;
46         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
47         struct llog_ctxt *lctxt;
48         int rc;
49         ENTRY;
50
51         lctxt = llog_get_context(&lov_obd->obd_llogs, ctxt->loc_idx);
52         rc = llog_add(lctxt, rec, buf, logcookies, numcookies, data,
53                       lock, lock_count);
54         RETURN(rc);
55 }
56
57 static int mds_llog_origin_connect(struct llog_ctxt *ctxt, int count,
58                                    struct llog_logid *logid,
59                                    struct llog_gen *gen, struct obd_uuid *uuid)
60 {
61         struct obd_device *obd = ctxt->loc_obd;
62         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
63         struct llog_ctxt *lctxt;
64         int rc;
65         ENTRY;
66
67         lctxt = llog_get_context(&lov_obd->obd_llogs, ctxt->loc_idx);
68         rc = llog_connect(lctxt, count, logid, gen, uuid);
69         RETURN(rc);
70 }
71
72 static int mds_llog_repl_cancel(struct llog_ctxt *ctxt, int count, 
73                                 struct llog_cookie *cookies, int flags,
74                                 void *data)
75 {
76         struct obd_device *obd = ctxt->loc_obd;
77         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
78         struct llog_ctxt *lctxt;
79         int rc;
80         ENTRY;
81
82         lctxt = llog_get_context(&lov_obd->obd_llogs, ctxt->loc_idx);
83         rc = llog_cancel(lctxt, count, cookies, flags, data);
84         RETURN(rc);
85 }
86
87 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
88                       struct lov_mds_md *lmm, int lmm_size,
89                       struct llog_cookie *logcookies, int cookies_size,
90                       struct llog_create_locks **res)
91 {
92         struct mds_obd *mds = &obd->u.mds;
93         struct lov_stripe_md *lsm = NULL;
94         struct llog_ctxt *ctxt;
95         struct llog_create_locks *lcl = NULL;
96         int rc, size = 0,offset = offsetof(struct llog_create_locks, lcl_locks);
97         int lock_count = 0;
98         ENTRY;
99
100         if (IS_ERR(mds->mds_osc_obd))
101                 RETURN(PTR_ERR(mds->mds_osc_obd));
102
103         RETURN(0);
104
105         rc = obd_unpackmd(mds->mds_osc_exp, &lsm,
106                           lmm, lmm_size);
107         if (rc < 0)
108                 RETURN(rc);
109
110         if (res != NULL) {
111                 size = offset +
112                        sizeof(struct rw_semaphore *) * lsm->lsm_stripe_count;
113                 OBD_ALLOC(lcl, size);
114                 if (lcl == NULL)
115                         RETURN(-ENOMEM);
116
117                 lcl->lcl_count = lsm->lsm_stripe_count;
118                 *res = lcl;
119         }
120
121         ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
122         rc = llog_add(ctxt, NULL, lsm, logcookies,
123                       cookies_size / sizeof(struct llog_cookie), NULL,
124                       res ? &lcl->lcl_locks[0] : NULL, &lock_count);
125
126         obd_free_memmd(mds->mds_osc_exp, &lsm);
127
128         if (res && (rc <= 0 || lock_count == 0)) {
129                 OBD_FREE(lcl, size);
130                 *res = NULL;
131         }
132
133         RETURN(rc);
134 }
135
136 static struct llog_operations mds_unlink_orig_logops = {
137         lop_add:        mds_llog_origin_add,
138         lop_connect:    mds_llog_origin_connect,
139 };
140
141 static struct llog_operations mds_size_repl_logops = {
142         lop_cancel:     mds_llog_repl_cancel,
143 };
144
145 int mds_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
146                   struct obd_device *tgt, int count, struct llog_catid *logid)
147 {
148         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
149         int rc;
150         ENTRY;
151
152         rc = obd_llog_setup(obd, llogs, LLOG_UNLINK_ORIG_CTXT, tgt, 0, NULL,
153                             &mds_unlink_orig_logops);
154         if (rc)
155                 RETURN(rc);
156
157         rc = obd_llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
158                             &mds_size_repl_logops);
159         if (rc)
160                 RETURN(rc);
161
162         rc = obd_llog_init(lov_obd, &lov_obd->obd_llogs, tgt, count, logid);
163         if (rc)
164                 CERROR("error lov_llog_init\n");
165
166         RETURN(rc);
167 }
168
169 int mds_llog_finish(struct obd_device *obd, struct obd_llogs *llogs, int count)
170 {
171         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
172         int rc;
173         ENTRY;
174
175         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_UNLINK_ORIG_CTXT));
176         if (rc)
177                 RETURN(rc);
178
179         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_SIZE_REPL_CTXT));
180         if (rc)
181                 RETURN(rc);
182
183         rc = obd_llog_finish(lov_obd, &lov_obd->obd_llogs, count);
184         if (rc)
185                 CERROR("error lov_llog_finish\n");
186
187         RETURN(rc);
188 }