1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Target (mdt) request unpacking helper.
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>
16 * This file is part of the Lustre file system, http://www.lustre.org
17 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
37 # define EXPORT_SYMTAB
39 #define DEBUG_SUBSYSTEM S_MDS
41 #include "mdt_internal.h"
45 static int mdt_setattr_unpack(struct mdt_thread_info *info)
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;
53 rec = req_capsule_client_get(pill, &RMF_REC_SETATTR);
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;
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,
75 if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) {
76 rr->rr_logcookies = req_capsule_client_get(pill,
78 rr->rr_logcookielen = req_capsule_get_size(pill,
86 static int mdt_create_unpack(struct mdt_thread_info *info)
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;
95 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
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);
108 if (req_capsule_field_present(pill, &RMF_SYMTGT))
109 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
115 static int mdt_link_unpack(struct mdt_thread_info *info)
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;
123 rec = req_capsule_client_get(pill, &RMF_REC_LINK);
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;
134 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
135 if (rr->rr_name == NULL)
140 static int mdt_unlink_unpack(struct mdt_thread_info *info)
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;
148 rec = req_capsule_client_get(pill, &RMF_REC_UNLINK);
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;
160 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
161 if (rr->rr_name == NULL)
166 static int mdt_rename_unpack(struct mdt_thread_info *info)
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;
174 rec = req_capsule_client_get(pill, &RMF_REC_RENAME);
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;
185 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
186 if (rr->rr_name == NULL)
188 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
189 if (rr->rr_tgt == NULL)
194 static int mdt_open_unpack(struct mdt_thread_info *info)
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;
203 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
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;
210 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
211 if (rr->rr_name == NULL)
221 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
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
232 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
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);
244 CERROR("Unexpected opcode %d\n", op);