Whamcloud - gitweb
(1) more code for MDT in reint.
[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 #ifdef MDT_CODE
48         struct mdt_rec_setattr *rec;
49         struct lu_attr *attr = &info->mti_attr;
50         struct mdt_reint_record *rr = &info->mti_rr;
51         struct req_capsule *pill = &info->mti_pill;
52         ENTRY;
53
54         rec = req_capsule_client_get(pill, &RMF_REC_SETATTR);
55
56         if (rec == NULL)
57                 RETURN (-EFAULT);
58
59         rr->rr_fid1 = &rec->sa_fid;
60         attr->la_valid = rec->sa_valid;
61         attr->la_mode  = rec->sa_mode;
62         attr->la_uid   = rec->sa_uid;
63         attr->la_gid   = rec->sa_gid;
64         attr->la_size  = rec->sa_size;
65         attr->la_flags = rec->sa_attr_flags;
66         attr->la_ctime = rec->sa_ctime;
67         attr->la_atime = rec->sa_atime;
68         attr->la_mtime = rec->sa_mtime;
69
70         if (req_capsule_field_present(pill, &RMF_EADATA)) {
71                 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
72                 rr->rr_eadatalen = req_capsule_get_size(pill, 
73                                                         &RMF_EADATA,
74                                                         RCL_CLIENT);
75         }
76         if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) {
77                 rr->rr_logcookies = req_capsule_client_get(pill, 
78                                                            &RMF_LOGCOOKIES);
79                 rr->rr_logcookielen = req_capsule_get_size(pill, 
80                                                            &RMF_LOGCOOKIES,
81                                                            RCL_CLIENT);
82         }
83
84         RETURN(0);
85 #endif
86         ENTRY;
87         RETURN(-EOPNOTSUPP);
88 }
89
90 static int mdt_create_unpack(struct mdt_thread_info *info)
91 {
92         struct mdt_rec_create *rec;
93         struct lu_attr *attr = &info->mti_attr;
94         struct mdt_reint_record *rr = &info->mti_rr;
95         struct req_capsule *pill = &info->mti_pill;
96         int result = 0;
97         ENTRY;
98
99         rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
100         if (rec != NULL) {
101                 rr->rr_fid1 = &rec->cr_fid1;
102                 rr->rr_fid2 = &rec->cr_fid2;
103                 attr->la_mode = rec->cr_mode;
104                 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
105 #ifdef MDT_CODE
106                 attr->la_rdev  = rec->cr_rdev;
107                 attr->la_uid   = rec->cr_fsuid;
108                 attr->la_gid   = rec->cr_fsgid;
109                 attr->la_flags = rec->cr_flags;
110                 attr->la_ctime = rec->cr_time;
111                 if (req_capsule_field_present(pill, &RMF_SYMTGT))
112                         rr->rr_tgt  = req_capsule_client_get(pill, &RMF_SYMTGT);
113 #endif
114         } else
115                 result = -EFAULT;
116         RETURN(result);
117 }
118
119 static int mdt_link_unpack(struct mdt_thread_info *info)
120 {
121 #ifdef MDT_CODE
122         struct mdt_rec_link *rec;
123         struct lu_attr *attr = &info->mti_attr;
124         struct mdt_reint_record *rr = &info->mti_rr;
125         struct req_capsule *pill = &info->mti_pill;
126         ENTRY;
127
128         rec = req_capsule_client_get(pill, &RMF_REC_LINK);
129         if (rec == NULL)
130                 RETURN (-EFAULT);
131
132         attr->la_uid = rec->lk_fsuid;
133         attr->la_gid = rec->lk_fsgid;
134         rr->rr_fid1 = &rec->lk_fid1;
135         rr->rr_fid2 = &rec->lk_fid2;
136         attr->la_ctime = rec->lk_time;
137
138         rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
139         if (rr->rr_name == NULL)
140                 RETURN (-EFAULT);
141         RETURN(0);
142 #endif
143         ENTRY;
144         RETURN(-EOPNOTSUPP);
145 }
146
147 static int mdt_unlink_unpack(struct mdt_thread_info *info)
148 {
149 #ifdef MDT_CODE
150         struct mdt_rec_unlink *rec;
151         struct lu_attr *attr = &info->mti_attr;
152         struct mdt_reint_record *rr = &info->mti_rr;
153         struct req_capsule *pill = &info->mti_pill;
154         ENTRY;
155
156         rec = req_capsule_client_get(pill, &RMF_REC_UNLINK);
157         if (rec == NULL)
158                 RETURN (-EFAULT);
159
160         attr->la_uid = rec->ul_fsuid;
161         attr->la_gid = rec->ul_fsgid;
162         rr->rr_fid1 = &rec->ul_fid1;
163         rr->rr_fid2 = &rec->ul_fid2;
164         attr->la_ctime = rec->ul_time;
165         attr->la_mode  = rec->ul_mode;
166
167         rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
168         if (rr->rr_name == NULL)
169                 RETURN (-EFAULT);
170         RETURN(0);
171 #endif
172         ENTRY;
173         RETURN(-EOPNOTSUPP);
174 }
175
176 static int mdt_rename_unpack(struct mdt_thread_info *info)
177 {
178 #ifdef MDT_CODE
179         struct mdt_rec_rename *rec;
180         struct lu_attr *attr = &info->mti_attr;
181         struct mdt_reint_record *rr = &info->mti_rr;
182         struct req_capsule *pill = &info->mti_pill;
183         ENTRY;
184
185         rec = req_capsule_client_get(pill, &RMF_REC_RENAME);
186         if (rec == NULL)
187                 RETURN (-EFAULT);
188
189         attr->la_uid = rec->rn_fsuid;
190         attr->la_gid = rec->rn_fsgid;
191         rr->rr_fid1 = &rec->rn_fid1;
192         rr->rr_fid2 = &rec->rn_fid2;
193         attr->la_ctime = rec->rn_time;
194
195         rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
196         if (rr->rr_name == NULL)
197                 RETURN (-EFAULT);
198         rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
199         if (rr->rr_tgt == NULL)
200                 RETURN (-EFAULT);
201         RETURN(0);
202 #endif
203  
204         ENTRY;
205         RETURN(-EOPNOTSUPP);
206 }
207
208 static int mdt_open_unpack(struct mdt_thread_info *info)
209 {
210         struct mdt_rec_create   *rec;
211         struct lu_attr          *attr = &info->mti_attr;
212         struct req_capsule      *pill = &info->mti_pill;
213         struct mdt_reint_record *rr   = &info->mti_rr;
214         int result;
215         ENTRY;
216
217         rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
218         if (rec != NULL) {
219                 rr->rr_fid1   = &rec->cr_fid1;
220                 rr->rr_fid2   = &rec->cr_fid2;
221                 attr->la_mode = rec->cr_mode;
222                 attr->la_flags  = rec->cr_flags;
223
224                 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
225                 if (rr->rr_name == NULL)
226                         result = -EFAULT;
227                 else
228                         result = 0;
229         } else
230                 result = -EFAULT;
231
232         RETURN(result);
233 }
234
235 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
236
237 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
238         [REINT_SETATTR]  = mdt_setattr_unpack,
239         [REINT_CREATE]   = mdt_create_unpack,
240         [REINT_LINK]     = mdt_link_unpack,
241         [REINT_UNLINK]   = mdt_unlink_unpack,
242         [REINT_RENAME]   = mdt_rename_unpack,
243         [REINT_OPEN]     = mdt_open_unpack
244 };
245
246 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
247 {
248         int rc;
249
250         ENTRY;
251
252         if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
253                 info->mti_rr.rr_opcode = op;
254                 rc = mdt_reint_unpackers[op](info);
255         } else {
256                 CERROR("Unexpected opcode %d\n", op);
257                 rc = -EFAULT;
258         }
259         RETURN(rc);
260 }