Whamcloud - gitweb
0398ce36d2599ee6c1b0332c3b02e45582ddd563
[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                        LTIME_S(((time_t)rec->sa_mtime)), 
55                        LTIME_S(((time_t)rec->sa_ctime)));
56         
57         size[0] = sizeof(struct mds_body);
58         req->rq_replen = lustre_msg_size(1, size);
59
60         rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
61         
62         if (rc == -ERESTARTSYS)
63                 rc = 0;
64
65         RETURN(rc);
66 }
67
68 int cmobd_create_reint(struct obd_device *obd, struct ptlrpc_request *req)
69 {
70         int rc = 0, level, size[1];
71         ENTRY;
72
73         size[0] = sizeof(struct mds_body);
74         req->rq_replen = lustre_msg_size(1, size);
75
76         level = LUSTRE_IMP_FULL;
77  resend:
78         rc = mdc_reint(req, NULL, level);
79         /* Resend if we were told to. */
80         if (rc == -ERESTARTSYS) {
81                 level = LUSTRE_IMP_RECOVER;
82                 goto resend;
83         }
84
85         if (!rc)
86                 mdc_store_inode_generation(NULL, req, 0, 0);
87
88         RETURN(rc);
89 }
90
91 int cmobd_unlink_reint(struct obd_device *obd, struct ptlrpc_request *req)
92 {
93         int rc = 0, size[3];
94         ENTRY;
95         
96         size[0] = sizeof(struct mds_body);
97         size[1] = obd->u.cli.cl_max_mds_easize;
98         size[2] = obd->u.cli.cl_max_mds_cookiesize;
99         req->rq_replen = lustre_msg_size(3, size);
100
101         rc = mdc_reint(req,  NULL, LUSTRE_IMP_FULL);
102         if (rc == -ERESTARTSYS)
103                 rc = 0;
104         RETURN(rc);
105 }
106
107 int cmobd_link_reint(struct obd_device *obd, struct ptlrpc_request *req)
108 {
109         int rc = 0, size[1];
110         ENTRY;
111
112         size[0] = sizeof(struct mds_body);
113         req->rq_replen = lustre_msg_size(1, size);
114
115         rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
116         if (rc == -ERESTARTSYS)
117                 rc = 0;
118
119         RETURN(rc);
120 }
121
122 int cmobd_rename_reint(struct obd_device *obd, struct ptlrpc_request *req)
123 {
124         int rc = 0, size[2];
125         ENTRY;
126
127         size[0] = sizeof(struct mds_body);
128         size[1] = obd->u.cli.cl_max_mds_easize;
129         req->rq_replen = lustre_msg_size(2, size);
130
131         rc = mdc_reint(req,  NULL, LUSTRE_IMP_FULL);
132         if (rc == -ERESTARTSYS)
133                 rc = 0;
134
135         RETURN(rc);
136 }
137
138 typedef int (*cmobd_reint_mds_rec)(struct obd_device*,
139                                    struct ptlrpc_request *req);
140
141 static cmobd_reint_mds_rec cmobd_mds_reint[REINT_MAX + 1] = {
142         [REINT_SETATTR] cmobd_setattr_reint,
143         [REINT_CREATE] cmobd_create_reint,
144         [REINT_LINK] cmobd_link_reint,
145         [REINT_UNLINK] cmobd_unlink_reint,
146         [REINT_RENAME] cmobd_rename_reint,
147 };
148
149 int cmobd_reint_mds(struct obd_device *obd, void* record)
150 {
151         struct cache_manager_obd *cmobd = &obd->u.cmobd;
152         struct ptlrpc_request *req; 
153         struct lustre_msg *msg; 
154         struct mds_kml_pack_info *mkpi;
155         __u32  opcode; 
156         int    rc = 0;
157         mkpi = (struct mds_kml_pack_info *)record; 
158        
159         req = ptlrpc_prep_req(class_exp2cliimp(cmobd->cm_master_exp), 
160                               MDS_REINT, mkpi->mpi_bufcount, mkpi->mpi_size, 
161                               NULL);
162         if (req == NULL)
163                 RETURN(-ENOMEM);
164         record += sizeof(*mkpi);
165         msg = (struct lustre_msg *)record;
166         opcode = (__u32)*(int*)lustre_msg_buf(msg, 0, 0); 
167         if (opcode > REINT_MAX || opcode <= 0) {
168                 CERROR("Unrecorgnized reint opcode %u in cmobd mds reint\n",
169                         opcode);
170                 GOTO(out, rc=-EINVAL);
171         }
172         
173         memcpy(req->rq_reqmsg, record, mkpi->mpi_total_size);
174         /*flags and opc will be rewrite, so reset here 
175          *FIXME maybe should set some flags in reint process*/  
176
177         req->rq_reqmsg->opc = MDS_REINT;
178         req->rq_reqmsg->flags = 0;
179
180         rc = cmobd_mds_reint[opcode](cmobd->cm_master_obd, req);
181 out:
182         ptlrpc_req_finished(req);
183         return rc;
184
185