Whamcloud - gitweb
Landing b1_4_quotaoff to b1_4
[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 <libcfs/list.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_fsfilt.h>
36 #include <linux/lustre_commit_confd.h>
37 #include <linux/lustre_log.h>
38
39 #include "mds_internal.h"
40
41 /* callback function of lov to fill unlink log record */
42 static int mds_log_fill_unlink_rec(struct llog_rec_hdr *rec, void *data)
43 {
44         struct llog_fill_rec_data *lfd = (struct llog_fill_rec_data *)data;
45         struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
46                                                                                                                              
47         lur->lur_oid = lfd->lfd_id;
48         lur->lur_ogen = lfd->lfd_ogen;
49                                                                                                                              
50         RETURN(0);
51 }
52
53 /* callback function of lov to fill setattr log record */
54 static int mds_log_fill_setattr_rec(struct llog_rec_hdr *rec, void *data)
55 {
56         struct llog_fill_rec_data *lfd = (struct llog_fill_rec_data *)data;
57         struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
58                                                                                                                              
59         lsr->lsr_oid = lfd->lfd_id;
60         lsr->lsr_ogen = lfd->lfd_ogen;
61                                                                                                                              
62         RETURN(0);
63 }
64
65 static int mds_llog_origin_add(struct llog_ctxt *ctxt,
66                         struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
67                         struct llog_cookie *logcookies, int numcookies,
68                         llog_fill_rec_cb_t fill_cb)
69 {
70         struct obd_device *obd = ctxt->loc_obd;
71         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
72         struct llog_ctxt *lctxt;
73         int rc;
74         ENTRY;
75
76         lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
77         rc = llog_add(lctxt, rec, lsm, logcookies, numcookies, fill_cb);
78         RETURN(rc);
79 }
80
81 static int mds_llog_origin_connect(struct llog_ctxt *ctxt, int count,
82                                    struct llog_logid *logid,
83                                    struct llog_gen *gen,
84                                    struct obd_uuid *uuid)
85 {
86         struct obd_device *obd = ctxt->loc_obd;
87         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
88         struct llog_ctxt *lctxt;
89         int rc;
90         ENTRY;
91
92         lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
93         rc = llog_connect(lctxt, count, logid, gen, uuid);
94         RETURN(rc);
95 }
96
97 static int mds_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
98                           int count, struct llog_cookie *cookies, int flags)
99 {
100         struct obd_device *obd = ctxt->loc_obd;
101         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
102         struct llog_ctxt *lctxt;
103         int rc;
104         ENTRY;
105
106         lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
107         rc = llog_cancel(lctxt, lsm, count, cookies,flags);
108         RETURN(rc);
109 }
110
111 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
112                       struct lov_mds_md *lmm, int lmm_size,
113                       struct llog_cookie *logcookies, int cookies_size)
114 {
115         struct mds_obd *mds = &obd->u.mds;
116         struct lov_stripe_md *lsm = NULL;
117         struct llog_ctxt *ctxt;
118         struct llog_unlink_rec *lur;
119         int rc;
120         ENTRY;
121
122         if (IS_ERR(mds->mds_osc_obd))
123                 RETURN(PTR_ERR(mds->mds_osc_obd));
124
125         rc = obd_unpackmd(mds->mds_osc_exp, &lsm,
126                           lmm, lmm_size);
127         if (rc < 0)
128                 RETURN(rc);
129
130         /* first prepare unlink log record */
131         OBD_ALLOC(lur, sizeof(*lur));
132         if (!lur)
133                 RETURN(-ENOMEM);
134         lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
135         lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
136
137         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
138         rc = llog_add(ctxt, &lur->lur_hdr, lsm, logcookies,
139                       cookies_size / sizeof(struct llog_cookie),
140                       mds_log_fill_unlink_rec);
141
142         obd_free_memmd(mds->mds_osc_exp, &lsm);
143         OBD_FREE(lur, sizeof(*lur));
144
145         RETURN(rc);
146 }
147
148 int mds_log_op_setattr(struct obd_device *obd, struct inode *inode,
149                       struct lov_mds_md *lmm, int lmm_size,
150                       struct llog_cookie *logcookies, int cookies_size)
151 {
152         struct mds_obd *mds = &obd->u.mds;
153         struct lov_stripe_md *lsm = NULL;
154         struct llog_ctxt *ctxt;
155         struct llog_setattr_rec *lsr;
156         int rc;
157         ENTRY;
158                                                                                                                              
159         if (IS_ERR(mds->mds_osc_obd))
160                 RETURN(PTR_ERR(mds->mds_osc_obd));
161                                                                                                                              
162         rc = obd_unpackmd(mds->mds_osc_exp, &lsm,
163                           lmm, lmm_size);
164         if (rc < 0)
165                 RETURN(rc);
166
167         OBD_ALLOC(lsr, sizeof(*lsr));
168         if (!lsr)
169                 RETURN(-ENOMEM);
170                                                                                                                              
171         /* prepare setattr log record */
172         lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
173         lsr->lsr_hdr.lrh_type = MDS_SETATTR_REC;
174         lsr->lsr_uid = inode->i_uid;
175         lsr->lsr_gid = inode->i_gid;
176                                                                                                                              
177         /* write setattr log */
178         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
179         rc = llog_add(ctxt, &lsr->lsr_hdr, lsm, logcookies,
180                       cookies_size / sizeof(struct llog_cookie),
181                       mds_log_fill_setattr_rec);
182
183         obd_free_memmd(mds->mds_osc_exp, &lsm);
184         OBD_FREE(lsr, sizeof(*lsr));
185
186         RETURN(rc);
187 }
188
189 static struct llog_operations mds_ost_orig_logops = {
190         lop_add:        mds_llog_origin_add,
191         lop_connect:    mds_llog_origin_connect,
192 };
193
194 static struct llog_operations mds_size_repl_logops = {
195         lop_cancel:     mds_llog_repl_cancel
196 };
197
198 int mds_llog_init(struct obd_device *obd, struct obd_device *tgt,
199                   int count, struct llog_catid *logid)
200 {
201         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
202         int rc;
203         ENTRY;
204
205         rc = llog_setup(obd, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
206                         &mds_ost_orig_logops);
207         if (rc)
208                 RETURN(rc);
209
210         rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
211                         &mds_size_repl_logops);
212         if (rc)
213                 RETURN(rc);
214
215         rc = obd_llog_init(lov_obd, tgt, count, logid);
216         if (rc)
217                 CERROR("error lov_llog_init\n");
218
219         RETURN(rc);
220 }
221
222 int mds_llog_finish(struct obd_device *obd, int count)
223 {
224         struct llog_ctxt *ctxt;
225         int rc = 0, rc2 = 0;
226         ENTRY;
227
228         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
229         if (ctxt) 
230                 rc = llog_cleanup(ctxt);
231
232         ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
233         if (ctxt)
234                 rc2 = llog_cleanup(ctxt);
235         if (!rc)
236                 rc = rc2;
237
238         RETURN(rc);
239 }