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)
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;
54 rec = req_capsule_client_get(pill, &RMF_REC_SETATTR);
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;
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,
76 if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) {
77 rr->rr_logcookies = req_capsule_client_get(pill,
79 rr->rr_logcookielen = req_capsule_get_size(pill,
90 static int mdt_create_unpack(struct mdt_thread_info *info)
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;
99 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
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);
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);
119 static int mdt_link_unpack(struct mdt_thread_info *info)
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;
128 rec = req_capsule_client_get(pill, &RMF_REC_LINK);
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;
138 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
139 if (rr->rr_name == NULL)
147 static int mdt_unlink_unpack(struct mdt_thread_info *info)
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;
156 rec = req_capsule_client_get(pill, &RMF_REC_UNLINK);
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;
167 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
168 if (rr->rr_name == NULL)
176 static int mdt_rename_unpack(struct mdt_thread_info *info)
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;
185 rec = req_capsule_client_get(pill, &RMF_REC_RENAME);
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;
195 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
196 if (rr->rr_name == NULL)
198 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
199 if (rr->rr_tgt == NULL)
208 static int mdt_open_unpack(struct mdt_thread_info *info)
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;
217 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
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;
224 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
225 if (rr->rr_name == NULL)
235 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
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
246 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
252 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
253 info->mti_rr.rr_opcode = op;
254 rc = mdt_reint_unpackers[op](info);
256 CERROR("Unexpected opcode %d\n", op);