Whamcloud - gitweb
- landing of b_fid after merge with b_hd_cleanup_merge.
[fs/lustre-release.git] / lustre / obdfilter / filter_log.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/fs/obdfilter/filter_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_FILTER
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 "filter_internal.h"
39
40 int filter_log_sz_change(struct llog_handle *cathandle, 
41                          struct lustre_id *id, __u32 io_epoch,
42                          struct llog_cookie *logcookie, 
43                          struct inode *inode)
44 {
45         struct llog_size_change_rec *lsc;
46         int rc;
47         struct ost_filterdata *ofd;
48         ENTRY;
49
50         down(&inode->i_sem);
51         ofd = inode->i_filterdata;
52         
53         if (ofd && ofd->ofd_epoch >= io_epoch) {
54                 if (ofd->ofd_epoch > io_epoch)
55                         CERROR("client sent old epoch %d for obj ino %ld\n", 
56                                io_epoch, inode->i_ino);
57                 up(&inode->i_sem);
58                 RETURN(0);
59         }
60
61         if (ofd && ofd->ofd_epoch < io_epoch) {
62                 ofd->ofd_epoch = io_epoch;
63         } else if (!ofd) {
64                 OBD_ALLOC(ofd, sizeof(*ofd));
65                 if (!ofd)
66                         GOTO(out, rc = -ENOMEM);
67                 igrab(inode);
68                 inode->i_filterdata = ofd;
69                 ofd->ofd_epoch = io_epoch;
70         }
71         /* the decision to write a record is now made, unlock */
72         up(&inode->i_sem);
73
74         OBD_ALLOC(lsc, sizeof(*lsc));
75         if (lsc == NULL)
76                 RETURN(-ENOMEM);
77         lsc->lsc_hdr.lrh_len = lsc->lsc_tail.lrt_len = sizeof(*lsc);
78         lsc->lsc_hdr.lrh_type =  OST_SZ_REC;
79         lsc->lsc_id = *id;
80         lsc->lsc_io_epoch = io_epoch;
81
82         rc = llog_cat_add_rec(cathandle, &lsc->lsc_hdr, logcookie,
83                               NULL, NULL, NULL);
84         OBD_FREE(lsc, sizeof(*lsc));
85
86         if (rc > 0) {
87                 LASSERT(rc == sizeof(*logcookie));
88                 rc = 0;
89         }
90
91         out:
92         RETURN(rc);
93 }
94 struct obd_llogs * filter_grab_llog_for_group(struct obd_device *,
95                                               int, struct obd_export *);
96
97 /* When this (destroy) operation is committed, return the cancel cookie */
98 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
99                               void *cb_data, int error)
100 {
101         struct llog_cookie *cookie = cb_data;
102         struct obd_llogs *llogs = NULL;
103         struct llog_ctxt *ctxt;
104
105         /* we have to find context for right group */
106         llogs = filter_grab_llog_for_group(obd, cookie->lgc_lgl.lgl_ogr, NULL);
107
108         if (llogs) {
109                 ctxt = llog_get_context(llogs, cookie->lgc_subsys + 1);
110                 if (ctxt) {
111                         llog_cancel(ctxt, 1, cookie, 0, NULL);
112                 } else
113                         CERROR("no valid context for group "LPU64"\n",
114                                cookie->lgc_lgl.lgl_ogr);
115         } else {
116                 CDEBUG(D_HA, "unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_ogr);
117         }
118
119         OBD_FREE(cb_data, sizeof(struct llog_cookie));
120 }
121
122 /* Callback for processing the unlink log record received from MDS by 
123  * llog_client_api.
124  */
125 int filter_recov_log_unlink_cb(struct llog_handle *llh, 
126                                struct llog_rec_hdr *rec, void *data)
127 {
128         struct llog_ctxt *ctxt = llh->lgh_ctxt;
129         struct obd_device *obd = ctxt->loc_obd;
130         struct obd_export *exp = obd->obd_self_export;
131         struct llog_cookie cookie;
132         struct llog_gen_rec *lgr;
133         struct llog_unlink_rec *lur;
134         struct obdo *oa;
135         obd_id oid;
136         int rc = 0;
137         ENTRY;
138     
139         if (!(le32_to_cpu(llh->lgh_hdr->llh_flags) & LLOG_F_IS_PLAIN)) {
140                 CERROR("log is not plain\n");
141                 RETURN(-EINVAL);
142         }
143         if (rec->lrh_type != MDS_UNLINK_REC &&
144             rec->lrh_type != LLOG_GEN_REC) {
145                 CERROR("log record type error\n");
146                 RETURN(-EINVAL);
147         }
148  
149         cookie.lgc_lgl = llh->lgh_id;
150         cookie.lgc_subsys = LLOG_UNLINK_ORIG_CTXT;
151         cookie.lgc_index = le32_to_cpu(rec->lrh_index);
152
153         if (rec->lrh_type == LLOG_GEN_REC) {
154                 lgr = (struct llog_gen_rec *)rec;
155                 if (llog_gen_lt(lgr->lgr_gen, ctxt->loc_gen))
156                         rc = 0;
157                 else
158                         rc = LLOG_PROC_BREAK;
159                 CWARN("fetch generation log, send cookie\n");
160                 llog_cancel(ctxt, 1, &cookie, 0, NULL);
161                 RETURN(rc);
162         }
163
164         lur = (struct llog_unlink_rec *)rec;
165         oa = obdo_alloc();
166         if (oa == NULL) 
167                 RETURN(-ENOMEM);
168         oa->o_valid |= OBD_MD_FLCOOKIE;
169         oa->o_id = lur->lur_oid;
170         oa->o_gr = lur->lur_ogen;
171         oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
172         memcpy(obdo_logcookie(oa), &cookie, sizeof(cookie));
173         oid = oa->o_id;
174
175         rc = obd_destroy(exp, oa, NULL, NULL);
176         obdo_free(oa);
177         if (rc == -ENOENT) {
178                 CDEBUG(D_HA, "object already removed, send cookie\n");
179                 llog_cancel(ctxt, 1, &cookie, 0, NULL);
180                 RETURN(0);
181         }
182
183         if (rc == 0)
184                 CDEBUG(D_HA, "object: "LPU64" in record is destroyed\n", oid);
185
186         RETURN(rc);
187 }