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"
43 /* if object is dying, pack the lov/llog data,
44 * parameter info->mti_attr should be valid at this point! */
45 int mdt_handle_last_unlink(struct mdt_thread_info *info,
46 struct mdt_object *mo, const struct req_format *fmt)
48 struct mdt_body *body;
49 struct lu_attr *la = &info->mti_attr.ma_attr;
53 body = req_capsule_server_get(&info->mti_pill,
55 mdt_pack_attr2body(body, la, mdt_object_fid(mo));
57 /* if last unlinked object reference so client should destroy ost
59 if (S_ISREG(la->la_mode) &&
60 la->la_nlink == 0 && mo->mot_header.loh_ref == 1) {
61 struct lov_mds_md *lmm;
63 /* reply should contains more data,
64 * * so we need to extend it */
65 req_capsule_extend(&info->mti_pill, fmt);
67 lmm = req_capsule_server_get(&info->mti_pill,
71 /*TODO: lmm data & llog cookie
72 * rc = mo_xattr_get(info->mti_ctxt, mdt_object_child(o),
73 * lmm, info->mti_mdt->mdt_max_mdsize,
76 * if (S_ISDIR(info->mti_attr.la_mode))
77 * body->valid |= OBD_MD_FLDIREA;
79 * body->valid |= OBD_MD_FLEASIZE;
80 * body->eadatasize = rc;
90 static int mdt_setattr_unpack(struct mdt_thread_info *info)
92 struct mdt_rec_setattr *rec;
93 struct lu_attr *attr = &info->mti_attr.ma_attr;
94 struct mdt_reint_record *rr = &info->mti_rr;
95 struct req_capsule *pill = &info->mti_pill;
98 rec = req_capsule_client_get(pill, &RMF_REC_SETATTR);
103 rr->rr_fid1 = &rec->sa_fid;
104 attr->la_valid = rec->sa_valid;
105 attr->la_mode = rec->sa_mode;
106 attr->la_uid = rec->sa_uid;
107 attr->la_gid = rec->sa_gid;
108 attr->la_size = rec->sa_size;
109 attr->la_flags = rec->sa_attr_flags;
110 attr->la_ctime = rec->sa_ctime;
111 attr->la_atime = rec->sa_atime;
112 attr->la_mtime = rec->sa_mtime;
114 if (req_capsule_field_present(pill, &RMF_EADATA)) {
115 rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA);
116 rr->rr_eadatalen = req_capsule_get_size(pill,
120 if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) {
121 rr->rr_logcookies = req_capsule_client_get(pill,
123 rr->rr_logcookielen = req_capsule_get_size(pill,
131 static int mdt_create_unpack(struct mdt_thread_info *info)
133 struct mdt_rec_create *rec;
134 struct lu_attr *attr = &info->mti_attr.ma_attr;
135 struct mdt_reint_record *rr = &info->mti_rr;
136 struct req_capsule *pill = &info->mti_pill;
140 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
142 rr->rr_fid1 = &rec->cr_fid1;
143 rr->rr_fid2 = &rec->cr_fid2;
144 attr->la_mode = rec->cr_mode;
145 attr->la_rdev = rec->cr_rdev;
146 attr->la_uid = rec->cr_fsuid;
147 attr->la_gid = rec->cr_fsgid;
148 attr->la_flags = rec->cr_flags;
149 attr->la_ctime = rec->cr_time;
150 attr->la_mtime = rec->cr_time;
151 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
153 if (req_capsule_field_present(pill, &RMF_SYMTGT))
154 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
160 static int mdt_link_unpack(struct mdt_thread_info *info)
162 struct mdt_rec_link *rec;
163 struct lu_attr *attr = &info->mti_attr.ma_attr;
164 struct mdt_reint_record *rr = &info->mti_rr;
165 struct req_capsule *pill = &info->mti_pill;
168 rec = req_capsule_client_get(pill, &RMF_REC_LINK);
172 attr->la_uid = rec->lk_fsuid;
173 attr->la_gid = rec->lk_fsgid;
174 rr->rr_fid1 = &rec->lk_fid1;
175 rr->rr_fid2 = &rec->lk_fid2;
176 attr->la_ctime = rec->lk_time;
177 attr->la_mtime = rec->lk_time;
179 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
180 if (rr->rr_name == NULL)
185 static int mdt_unlink_unpack(struct mdt_thread_info *info)
187 struct mdt_rec_unlink *rec;
188 struct lu_attr *attr = &info->mti_attr.ma_attr;
189 struct mdt_reint_record *rr = &info->mti_rr;
190 struct req_capsule *pill = &info->mti_pill;
193 rec = req_capsule_client_get(pill, &RMF_REC_UNLINK);
197 attr->la_uid = rec->ul_fsuid;
198 attr->la_gid = rec->ul_fsgid;
199 rr->rr_fid1 = &rec->ul_fid1;
200 rr->rr_fid2 = &rec->ul_fid2;
201 attr->la_ctime = rec->ul_time;
202 attr->la_mtime = rec->ul_time;
203 attr->la_mode = rec->ul_mode;
205 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
206 if (rr->rr_name == NULL)
211 static int mdt_rename_unpack(struct mdt_thread_info *info)
213 struct mdt_rec_rename *rec;
214 struct lu_attr *attr = &info->mti_attr.ma_attr;
215 struct mdt_reint_record *rr = &info->mti_rr;
216 struct req_capsule *pill = &info->mti_pill;
219 rec = req_capsule_client_get(pill, &RMF_REC_RENAME);
223 attr->la_uid = rec->rn_fsuid;
224 attr->la_gid = rec->rn_fsgid;
225 rr->rr_fid1 = &rec->rn_fid1;
226 rr->rr_fid2 = &rec->rn_fid2;
227 attr->la_ctime = rec->rn_time;
228 attr->la_mtime = rec->rn_time;
230 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
231 if (rr->rr_name == NULL)
233 rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT);
234 if (rr->rr_tgt == NULL)
239 static int mdt_open_unpack(struct mdt_thread_info *info)
241 struct mdt_rec_create *rec;
242 struct lu_attr *attr = &info->mti_attr.ma_attr;
243 struct req_capsule *pill = &info->mti_pill;
244 struct mdt_reint_record *rr = &info->mti_rr;
248 rec = req_capsule_client_get(pill, &RMF_REC_CREATE);
250 rr->rr_fid1 = &rec->cr_fid1;
251 rr->rr_fid2 = &rec->cr_fid2;
252 attr->la_mode = rec->cr_mode;
253 attr->la_flags = rec->cr_flags;
255 rr->rr_name = req_capsule_client_get(pill, &RMF_NAME);
256 if (rr->rr_name == NULL)
266 typedef int (*reint_unpacker)(struct mdt_thread_info *info);
268 static reint_unpacker mdt_reint_unpackers[REINT_MAX] = {
269 [REINT_SETATTR] = mdt_setattr_unpack,
270 [REINT_CREATE] = mdt_create_unpack,
271 [REINT_LINK] = mdt_link_unpack,
272 [REINT_UNLINK] = mdt_unlink_unpack,
273 [REINT_RENAME] = mdt_rename_unpack,
274 [REINT_OPEN] = mdt_open_unpack
277 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op)
283 if (op < REINT_MAX && mdt_reint_unpackers[op] != NULL) {
284 info->mti_rr.rr_opcode = op;
285 rc = mdt_reint_unpackers[op](info);
287 CERROR("Unexpected opcode %d\n", op);