Whamcloud - gitweb
- landing of b_hd_cleanup_merge to HEAD.
[fs/lustre-release.git] / lustre / cmobd / cmobd_mds_reint.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #define DEBUG_SUBSYSTEM S_CMOBD
23
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/obd_class.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_mds.h>
30 #include <linux/lustre_smfs.h>
31 #include "cmobd_internal.h"
32
33 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
34  * should take the normal semaphore and go to the normal portal.
35  *
36  * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
37  * magic open-path setattr that should take the setattr semaphore and
38  * go to the setattr portal. */
39 int cmobd_setattr_reint(struct obd_device *obd, struct ptlrpc_request *req)
40 {
41         struct mds_rec_setattr *rec;
42         int    size[1], rc = 0; 
43         
44         ENTRY;
45
46         rec = (struct mds_rec_setattr *)lustre_msg_buf(req->rq_reqmsg, 0, 0);
47         if (!rec) 
48                 RETURN (-EINVAL);
49         if (rec->sa_valid & ATTR_FROM_OPEN) 
50                 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
51
52         if (rec->sa_valid & (ATTR_MTIME | ATTR_CTIME)) 
53                 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
54                        ((time_t)rec->sa_mtime), 
55                        ((time_t)rec->sa_ctime));
56         size[0] = sizeof(struct mds_body);
57         req->rq_replen = lustre_msg_size(1, size);
58
59         rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
60         
61         if (rc == -ERESTARTSYS)
62                 rc = 0;
63
64         RETURN(rc);
65 }
66
67 int cmobd_create_reint(struct obd_device *obd, struct ptlrpc_request *req)
68 {
69         int rc = 0, level, size[1];
70         ENTRY;
71
72         size[0] = sizeof(struct mds_body);
73         req->rq_replen = lustre_msg_size(1, size);
74
75         level = LUSTRE_IMP_FULL;
76  resend:
77         rc = mdc_reint(req, NULL, level);
78         /* Resend if we were told to. */
79         if (rc == -ERESTARTSYS) {
80                 level = LUSTRE_IMP_RECOVER;
81                 goto resend;
82         }
83
84         if (!rc)
85                 mdc_store_inode_generation(NULL, req, 0, 0);
86
87         RETURN(rc);
88 }
89
90 int cmobd_unlink_reint(struct obd_device *obd, struct ptlrpc_request *req)
91 {
92         int rc = 0, size[3];
93         ENTRY;
94         
95         size[0] = sizeof(struct mds_body);
96         size[1] = obd->u.cli.cl_max_mds_easize;
97         size[2] = obd->u.cli.cl_max_mds_cookiesize;
98         req->rq_replen = lustre_msg_size(3, size);
99
100         rc = mdc_reint(req,  NULL, LUSTRE_IMP_FULL);
101         if (rc == -ERESTARTSYS)
102                 rc = 0;
103         RETURN(rc);
104 }
105
106 int cmobd_link_reint(struct obd_device *obd, struct ptlrpc_request *req)
107 {
108         int rc = 0, size[1];
109         ENTRY;
110
111         size[0] = sizeof(struct mds_body);
112         req->rq_replen = lustre_msg_size(1, size);
113
114         rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
115         if (rc == -ERESTARTSYS)
116                 rc = 0;
117
118         RETURN(rc);
119 }
120
121 int cmobd_rename_reint(struct obd_device *obd, struct ptlrpc_request *req)
122 {
123         int rc = 0, size[2];
124         ENTRY;
125
126         size[0] = sizeof(struct mds_body);
127         size[1] = obd->u.cli.cl_max_mds_easize;
128         req->rq_replen = lustre_msg_size(2, size);
129
130         rc = mdc_reint(req,  NULL, LUSTRE_IMP_FULL);
131         if (rc == -ERESTARTSYS)
132                 rc = 0;
133
134         RETURN(rc);
135 }
136
137 typedef int (*cmobd_reint_mds_rec)(struct obd_device*,
138                                    struct ptlrpc_request *req);
139
140 static cmobd_reint_mds_rec cmobd_mds_reint[REINT_MAX + 1] = {
141         [REINT_SETATTR] cmobd_setattr_reint,
142         [REINT_CREATE] cmobd_create_reint,
143         [REINT_LINK] cmobd_link_reint,
144         [REINT_UNLINK] cmobd_unlink_reint,
145         [REINT_RENAME] cmobd_rename_reint,
146 };
147
148 int cmobd_reint_mds(struct obd_device *obd, void* record)
149 {
150         struct cache_manager_obd *cmobd = &obd->u.cmobd;
151         struct ptlrpc_request *req; 
152         struct lustre_msg *msg; 
153         struct mds_kml_pack_info *mkpi;
154         __u32  opcode; 
155         int    rc = 0;
156         mkpi = (struct mds_kml_pack_info *)record; 
157        
158         req = ptlrpc_prep_req(class_exp2cliimp(cmobd->cm_master_exp), 
159                               LUSTRE_MDS_VERSION, MDS_REINT,
160                               mkpi->mpi_bufcount, mkpi->mpi_size, NULL);
161         if (req == NULL)
162                 RETURN(-ENOMEM);
163         record += sizeof(*mkpi);
164         msg = (struct lustre_msg *)record;
165         opcode = (__u32)*(int*)lustre_msg_buf(msg, 0, 0); 
166         if (opcode > REINT_MAX || opcode <= 0) {
167                 CERROR("Unrecorgnized reint opcode %u in cmobd mds reint\n",
168                         opcode);
169                 GOTO(out, rc=-EINVAL);
170         }
171         
172         memcpy(req->rq_reqmsg, record, mkpi->mpi_total_size);
173         /*flags and opc will be rewrite, so reset here 
174          *FIXME maybe should set some flags in reint process*/  
175
176         req->rq_reqmsg->opc = MDS_REINT;
177         req->rq_reqmsg->flags = 0;
178
179         rc = cmobd_mds_reint[opcode](cmobd->cm_master_obd, req);
180 out:
181         ptlrpc_req_finished(req);
182         return rc;
183
184