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"
44 /* copied from lov/lov_ea.c, just for debugging, will be removed later */
45 void mdt_dump_lmm(int level, struct lov_mds_md *lmm)
47 struct lov_ost_data_v1 *lod;
50 le16_to_cpu(((struct lov_user_md*)lmm)->lmm_stripe_count);
52 CDEBUG(level, "objid "LPX64", magic 0x%08X, pattern %#X\n",
53 le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),
54 le32_to_cpu(lmm->lmm_pattern));
55 CDEBUG(level,"stripe_size=0x%x, stripe_count=0x%x\n",
56 le32_to_cpu(lmm->lmm_stripe_size),
57 le32_to_cpu(lmm->lmm_stripe_count));
58 LASSERT(stripe_count < (__s16)LOV_MAX_STRIPE_COUNT);
59 for (i = 0, lod = lmm->lmm_objects; i < stripe_count; i++, lod++) {
60 CDEBUG(level, "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
61 i, le32_to_cpu(lod->l_ost_idx),
62 le64_to_cpu(lod->l_object_gr),
63 le64_to_cpu(lod->l_object_id));
67 void mdt_shrink_reply(struct mdt_thread_info *info, int offset)
69 struct ptlrpc_request *req = mdt_info_req(info);
70 struct mdt_body *body;
74 body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
75 LASSERT(body != NULL);
77 md_size = body->eadatasize;
78 acl_size = body->aclsize;
80 CDEBUG(D_INFO, "Shrink to md_size %d cookie_size %d \n",
83 lustre_shrink_reply(req, offset, md_size, 1);
84 lustre_shrink_reply(req, md_size ? offset + 1: offset, acl_size, 0);
88 /* if object is dying, pack the lov/llog data,
89 * parameter info->mti_attr should be valid at this point! */
90 int mdt_handle_last_unlink(struct mdt_thread_info *info, struct mdt_object *mo,
91 const struct md_attr *ma)
93 struct mdt_body *repbody;
94 const struct lu_attr *la = &ma->ma_attr;
97 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
99 if (ma->ma_valid & MA_INODE)
100 mdt_pack_attr2body(repbody, la, mdt_object_fid(mo));
102 if (ma->ma_valid & MA_LOV) {
105 mode = lu_object_attr(&mo->mot_obj.mo_lu);
106 LASSERT(ma->ma_lmm_size);
107 mdt_dump_lmm(D_INFO, ma->ma_lmm);
108 repbody->eadatasize = ma->ma_lmm_size;
110 repbody->valid |= OBD_MD_FLEASIZE;
111 else if (S_ISDIR(mode))
112 repbody->valid |= OBD_MD_FLDIREA;
117 if (ma->ma_cookie_size && (ma->ma_valid & MA_COOKIE)) {
118 repbody->aclsize = ma->ma_cookie_size;
119 repbody->valid |= OBD_MD_FLCOOKIE;
125 static __u64 mdt_attr_valid_xlate(__u64 in, struct mdt_reint_record *rr,
140 if (in & ATTR_FROM_OPEN)
141 rr->rr_flags |= MRF_SETATTR_LOCKED;
143 if (in & ATTR_ATIME_SET)
146 if (in & ATTR_CTIME_SET)
149 if (in & ATTR_MTIME_SET)
152 if (in & ATTR_ATTR_FLAG)
155 /*XXX need ATTR_RAW?*/
156 in &= ~(ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|
157 ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_FROM_OPEN|
158 ATTR_ATIME_SET|ATTR_CTIME_SET|ATTR_MTIME_SET|
159 ATTR_ATTR_FLAG|ATTR_RAW);
161 CERROR("Unknown attr bits: %#llx\n", in);
165 static int mdt_setattr_unpack(struct mdt_thread_info *info)
167 struct mdt_rec_setattr *rec;
168 struct md_attr *ma = &info->mti_attr;
169 struct lu_attr *la = &ma->ma_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_SETATTR);
179 rr->rr_fid1 = &rec->sa_fid;
180 la->la_valid = mdt_attr_valid_xlate(rec->sa_valid, rr, ma);
181 la->la_mode = rec->sa_mode;
182 la->la_flags = rec->sa_attr_flags;
183 la->la_uid = rec->sa_uid;
184 la->la_gid = rec->sa_gid;
185 la->la_size = rec->sa_size;
186 la->la_ctime = rec->sa_ctime;
187 la->la_atime = rec->sa_atime;
188 la->la_mtime = rec->sa_mtime;
189 ma->ma_valid = MA_INODE;
191 if (req_capsule_field_present(pill, &RMF_EADATA)) {
192 ma->ma_lmm = req_capsule_client_get(pill, &RMF_EADATA);
193 ma->ma_lmm_size = req_capsule_get_size(pill, &RMF_EADATA,
195 ma->ma_valid |= MA_LOV;
197 if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) {
198 ma->ma_cookie = req_capsule_client_get(pill,
200 ma->ma_cookie_size = req_capsule_get_size(pill,
203 ma->ma_valid |= MA_COOKIE;
209 static int mdt_create_unpack(struct mdt_thread_info *info)
211 struct mdt_rec_create *rec;
212 struct lu_attr *attr = &info->mti_attr.ma_attr;
213 struct mdt_reint_record *rr = &info->mti_rr;
214 struct req_capsule *pill = &info->mti_pill;
218 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
220 rr->rr_fid1 = &rec->cr_fid1;
221 rr->rr_fid2 = &rec->cr_fid2;
222 attr->la_mode = rec->cr_mode;
223 attr->la_rdev = rec->cr_rdev;
224 attr->la_uid = rec->cr_fsuid;
225 attr->la_gid = rec->cr_fsgid;
226 attr->la_ctime = rec->cr_time;
227 attr->la_mtime = rec->cr_time;
228 attr->la_atime = rec->cr_time;
229 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID |
230 LA_CTIME | LA_MTIME | LA_ATIME;
231 info->mti_spec.sp_cr_flags = rec->cr_flags;
233 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
235 if (req_capsule_field_present(pill, &RMF_SYMTGT)) {
237 tgt = req_capsule_client_get(pill,
241 info->mti_spec.u.sp_symname = tgt;
250 static int mdt_link_unpack(struct mdt_thread_info *info)
252 struct mdt_rec_link *rec;
253 struct lu_attr *attr = &info->mti_attr.ma_attr;
254 struct mdt_reint_record *rr = &info->mti_rr;
255 struct req_capsule *pill = &info->mti_pill;
259 rec = req_capsule_client_get(pill, &RMF_REC_LINK);
261 attr->la_uid = rec->lk_fsuid;
262 attr->la_gid = rec->lk_fsgid;
263 rr->rr_fid1 = &rec->lk_fid1;
264 rr->rr_fid2 = &rec->lk_fid2;
265 attr->la_ctime = rec->lk_time;
266 attr->la_mtime = rec->lk_time;
267 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
268 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
269 if (rr->rr_name == NULL)
276 static int mdt_unlink_unpack(struct mdt_thread_info *info)
278 struct mdt_rec_unlink *rec;
279 struct lu_attr *attr = &info->mti_attr.ma_attr;
280 struct mdt_reint_record *rr = &info->mti_rr;
281 struct req_capsule *pill = &info->mti_pill;
285 rec = req_capsule_client_get(pill, &RMF_REC_UNLINK);
287 attr->la_uid = rec->ul_fsuid;
288 attr->la_gid = rec->ul_fsgid;
289 rr->rr_fid1 = &rec->ul_fid1;
290 rr->rr_fid2 = &rec->ul_fid2;
291 attr->la_ctime = rec->ul_time;
292 attr->la_mtime = rec->ul_time;
293 attr->la_mode = rec->ul_mode;
295 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE;
296 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
297 if (rr->rr_name == NULL)
304 static int mdt_rename_unpack(struct mdt_thread_info *info)
306 struct mdt_rec_rename *rec;
307 struct lu_attr *attr = &info->mti_attr.ma_attr;
308 struct mdt_reint_record *rr = &info->mti_rr;
309 struct req_capsule *pill = &info->mti_pill;
313 rec = req_capsule_client_get(pill, &RMF_REC_RENAME);
315 attr->la_uid = rec->rn_fsuid;
316 attr->la_gid = rec->rn_fsgid;
317 rr->rr_fid1 = &rec->rn_fid1;
318 rr->rr_fid2 = &rec->rn_fid2;
319 attr->la_ctime = rec->rn_time;
320 attr->la_mtime = rec->rn_time;
321 attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME;
322 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
323 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
324 if (rr->rr_name == NULL || rr->rr_tgt == NULL)
331 static int mdt_open_unpack(struct mdt_thread_info *info)
333 struct mdt_rec_create *rec;
334 struct lu_attr *attr = &info->mti_attr.ma_attr;
335 struct req_capsule *pill = &info->mti_pill;
336 struct mdt_reint_record *rr = &info->mti_rr;
340 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
342 rr->rr_fid1 = &rec->cr_fid1;
343 rr->rr_fid2 = &rec->cr_fid2;
344 attr->la_mode = rec->cr_mode;
345 attr->la_rdev = rec->cr_rdev;
346 attr->la_uid = rec->cr_fsuid;
347 attr->la_gid = rec->cr_fsgid;
348 attr->la_ctime = rec->cr_time;
349 attr->la_mtime = rec->cr_time;
350 attr->la_atime = rec->cr_time;
351 attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_CTIME
352 | LA_MTIME | LA_ATIME;
353 info->mti_spec.sp_cr_flags = rec->cr_flags;
354 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
355 if (rr->rr_name == NULL)
356 /*XXX: what about open by FID? */
363 if (req_capsule_field_present(pill, &RMF_EADATA)) {
364 struct md_create_spec *sp = &info->mti_spec;
365 sp->u.sp_ea.eadata = req_capsule_client_get(pill,
367 sp->u.sp_ea.eadatalen = req_capsule_get_size(pill,
375 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
377 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
378 [REINT_SETATTR] = mdt_setattr_unpack,
379 [REINT_CREATE] = mdt_create_unpack,
380 [REINT_LINK] = mdt_link_unpack,
381 [REINT_UNLINK] = mdt_unlink_unpack,
382 [REINT_RENAME] = mdt_rename_unpack,
383 [REINT_OPEN] = mdt_open_unpack
386 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
392 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
393 info->mti_rr.rr_opcode = op;
394 rc = mdt_reint_unpackers[op](info);
396 CERROR("Unexpected opcode %d\n", op);