Whamcloud - gitweb
clear memory before unpacking reint request.
[fs/lustre-release.git] / lustre / mdt / mdt_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/mdt/mdt_lib.c
5  *  Lustre Metadata Target (mdt) request unpacking helper.
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Peter Braam <braam@clusterfs.com>
9  *   Author: Andreas Dilger <adilger@clusterfs.com>
10  *   Author: Phil Schwan <phil@clusterfs.com>
11  *   Author: Mike Shaver <shaver@clusterfs.com>
12  *   Author: Nikita Danilov <nikita@clusterfs.com>
13  *   Author: Huang Hua <huanghua@clusterfs.com>
14  *
15  *
16  *   This file is part of the Lustre file system, http://www.lustre.org
17  *   Lustre is a trademark of Cluster File Systems, Inc.
18  *
19  *   You may have signed or agreed to another license before downloading
20  *   this software.  If so, you are bound by the terms and conditions
21  *   of that agreement, and the following does not apply to you.  See the
22  *   LICENSE file included with this distribution for more information.
23  *
24  *   If you did not agree to a different license, then this copy of Lustre
25  *   is open source software; you can redistribute it and/or modify it
26  *   under the terms of version 2 of the GNU General Public License as
27  *   published by the Free Software Foundation.
28  *
29  *   In either case, Lustre is distributed in the hope that it will be
30  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
31  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  *   license text for more details.
33  */
34
35
36 #ifndef EXPORT_SYMTAB
37 # define EXPORT_SYMTAB
38 #endif
39 #define DEBUG_SUBSYSTEM S_MDS
40
41 #include "mdt_internal.h"
42
43
44 /* unpacking */
45 static int mdt_setattr_unpack(struct mdt_thread_info *info)
46 {
47         struct mdt_rec_setattr *rec;
48         struct lu_attr *attr = &info->mti_attr;
49         struct mdt_reint_record *rr = &info->mti_rr;
50         struct req_capsule *pill = &info->mti_pill;
51         ENTRY;
52
53         rec = req_capsule_client_get(pill, &RMF_REC_SETATTR);
54
55         if (rec == NULL)
56                 RETURN(-EFAULT);
57
58         rr->rr_fid1 = &rec->sa_fid;
59         attr->la_valid = rec->sa_valid;
60         attr->la_mode  = rec->sa_mode;
61         attr->la_uid   = rec->sa_uid;
62         attr->la_gid   = rec->sa_gid;
63         attr->la_size  = rec->sa_size;
64         attr->la_flags = rec->sa_attr_flags;
65         attr->la_ctime = rec->sa_ctime;
66         attr->la_atime = rec->sa_atime;
67         attr->la_mtime = rec->sa_mtime;
68
69         if (req_capsule_field_present(pill, &RMF_EADATA)) {
70                 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
71                 rr->rr_eadatalen = req_capsule_get_size(pill, 
72                                                         &RMF_EADATA,
73                                                         RCL_CLIENT);
74         }
75         if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) {
76                 rr->rr_logcookies = req_capsule_client_get(pill, 
77                                                            &RMF_LOGCOOKIES);
78                 rr->rr_logcookielen = req_capsule_get_size(pill, 
79                                                            &RMF_LOGCOOKIES,
80                                                            RCL_CLIENT);
81         }
82
83         RETURN(0);
84 }
85
86 static int mdt_create_unpack(struct mdt_thread_info *info)
87 {
88         struct mdt_rec_create *rec;
89         struct lu_attr *attr = &info->mti_attr;
90         struct mdt_reint_record *rr = &info->mti_rr;
91         struct req_capsule *pill = &info->mti_pill;
92         int result = 0;
93         ENTRY;
94
95         rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
96         if (rec != NULL) {
97                 rr->rr_fid1 = &rec->cr_fid1;
98                 rr->rr_fid2 = &rec->cr_fid2;
99                 attr->la_mode = rec->cr_mode;
100                 attr->la_rdev  = rec->cr_rdev;
101                 attr->la_uid   = rec->cr_fsuid;
102                 attr->la_gid   = rec->cr_fsgid;
103                 attr->la_flags = rec->cr_flags;
104                 attr->la_ctime = rec->cr_time;
105                 attr->la_mtime = rec->cr_time;
106                 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
107
108                 if (req_capsule_field_present(pill, &RMF_SYMTGT))
109                         rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
110         } else
111                 result = -EFAULT;
112         RETURN(result);
113 }
114
115 static int mdt_link_unpack(struct mdt_thread_info *info)
116 {
117         struct mdt_rec_link *rec;
118         struct lu_attr *attr = &info->mti_attr;
119         struct mdt_reint_record *rr = &info->mti_rr;
120         struct req_capsule *pill = &info->mti_pill;
121         ENTRY;
122
123         rec = req_capsule_client_get(pill, &RMF_REC_LINK);
124         if (rec == NULL)
125                 RETURN(-EFAULT);
126
127         attr->la_uid = rec->lk_fsuid;
128         attr->la_gid = rec->lk_fsgid;
129         rr->rr_fid1 = &rec->lk_fid1;
130         rr->rr_fid2 = &rec->lk_fid2;
131         attr->la_ctime = rec->lk_time;
132         attr->la_mtime = rec->lk_time;
133
134         rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
135         if (rr->rr_name == NULL)
136                 RETURN(-EFAULT);
137         RETURN(0);
138 }
139
140 static int mdt_unlink_unpack(struct mdt_thread_info *info)
141 {
142         struct mdt_rec_unlink *rec;
143         struct lu_attr *attr = &info->mti_attr;
144         struct mdt_reint_record *rr = &info->mti_rr;
145         struct req_capsule *pill = &info->mti_pill;
146         ENTRY;
147
148         rec = req_capsule_client_get(pill, &RMF_REC_UNLINK);
149         if (rec == NULL)
150                 RETURN(-EFAULT);
151
152         attr->la_uid = rec->ul_fsuid;
153         attr->la_gid = rec->ul_fsgid;
154         rr->rr_fid1 = &rec->ul_fid1;
155         rr->rr_fid2 = &rec->ul_fid2;
156         attr->la_ctime = rec->ul_time;
157         attr->la_mtime = rec->ul_time;
158         attr->la_mode  = rec->ul_mode;
159
160         rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
161         if (rr->rr_name == NULL)
162                 RETURN(-EFAULT);
163         RETURN(0);
164 }
165
166 static int mdt_rename_unpack(struct mdt_thread_info *info)
167 {
168         struct mdt_rec_rename *rec;
169         struct lu_attr *attr = &info->mti_attr;
170         struct mdt_reint_record *rr = &info->mti_rr;
171         struct req_capsule *pill = &info->mti_pill;
172         ENTRY;
173
174         rec = req_capsule_client_get(pill, &RMF_REC_RENAME);
175         if (rec == NULL)
176                 RETURN(-EFAULT);
177
178         attr->la_uid = rec->rn_fsuid;
179         attr->la_gid = rec->rn_fsgid;
180         rr->rr_fid1 = &rec->rn_fid1;
181         rr->rr_fid2 = &rec->rn_fid2;
182         attr->la_ctime = rec->rn_time;
183         attr->la_mtime = rec->rn_time;
184
185         rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
186         if (rr->rr_name == NULL)
187                 RETURN(-EFAULT);
188         rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
189         if (rr->rr_tgt == NULL)
190                 RETURN(-EFAULT);
191         RETURN(0);
192 }
193
194 static int mdt_open_unpack(struct mdt_thread_info *info)
195 {
196         struct mdt_rec_create   *rec;
197         struct lu_attr          *attr = &info->mti_attr;
198         struct req_capsule      *pill = &info->mti_pill;
199         struct mdt_reint_record *rr   = &info->mti_rr;
200         int result;
201         ENTRY;
202
203         rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
204         if (rec != NULL) {
205                 rr->rr_fid1   = &rec->cr_fid1;
206                 rr->rr_fid2   = &rec->cr_fid2;
207                 attr->la_mode = rec->cr_mode;
208                 attr->la_flags  = rec->cr_flags;
209
210                 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
211                 if (rr->rr_name == NULL)
212                         result = -EFAULT;
213                 else
214                         result = 0;
215         } else
216                 result = -EFAULT;
217
218         RETURN(result);
219 }
220
221 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
222
223 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
224         [REINT_SETATTR]  = mdt_setattr_unpack,
225         [REINT_CREATE]   = mdt_create_unpack,
226         [REINT_LINK]     = mdt_link_unpack,
227         [REINT_UNLINK]   = mdt_unlink_unpack,
228         [REINT_RENAME]   = mdt_rename_unpack,
229         [REINT_OPEN]     = mdt_open_unpack
230 };
231
232 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
233 {
234         int rc;
235
236         ENTRY;
237
238         if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
239                 memset(&info->mti_rr, 0, sizeof info->mti_rr);
240                 memset(&info->mti_attr, 0, sizeof info->mti_attr);
241                 info->mti_rr.rr_opcode = op;
242                 rc = mdt_reint_unpackers[op](info);
243         } else {
244                 CERROR("Unexpected opcode %d\n", op);
245                 rc = -EFAULT;
246         }
247         RETURN(rc);
248 }