1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_MDS
24 # include <liblustre.h>
26 #include <linux/lustre_idl.h>
27 #include <linux/lustre_net.h>
28 #include <linux/lustre_mds.h>
29 #include <linux/lustre_lite.h>
31 void mds_readdir_pack(struct ptlrpc_request *req, __u64 offset, __u32 size,
32 obd_id ino, int type, __u64 xid)
36 b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
37 b->fsuid = current->fsuid;
38 b->fsgid = current->fsgid;
39 b->capability = current->cap_effective;
41 b->fid1.f_type = type;
42 b->size = offset; /* !! */
44 b->blocks = xid; /* !! */
45 b->nlink = size; /* !! */
48 static void mds_pack_body(struct mds_body *b)
52 b->fsuid = current->fsuid;
53 b->fsgid = current->fsgid;
54 b->capability = current->cap_effective;
57 void mds_pack_req_body(struct ptlrpc_request *req)
59 struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
63 /* packing of MDS records */
64 void mds_create_pack(struct ptlrpc_request *req, int offset,
65 struct mdc_op_data *op_data,
66 __u32 mode, __u64 rdev, __u32 uid, __u32 gid, __u64 time,
67 const void *data, int datalen)
69 struct mds_rec_create *rec;
71 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
73 rec->cr_opcode = REINT_CREATE;
74 rec->cr_fsuid = current->fsuid;
75 rec->cr_fsgid = current->fsgid;
76 rec->cr_cap = current->cap_effective;
77 ll_ino2fid(&rec->cr_fid, op_data->ino1, op_data->gen1, op_data->typ1);
78 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
84 if (in_group_p(op_data->gid1))
85 rec->cr_suppgid = op_data->gid1;
89 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
90 LOGL0(op_data->name, op_data->namelen, tmp);
93 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
94 memcpy (tmp, data, datalen);
97 /* packing of MDS records */
98 void mds_open_pack(struct ptlrpc_request *req, int offset,
99 struct mdc_op_data *op_data,
100 __u32 mode, __u64 rdev, __u32 uid, __u32 gid, __u64 time,
102 const void *data, int datalen)
104 struct mds_rec_create *rec;
106 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
108 /* XXX do something about time, uid, gid */
109 rec->cr_opcode = REINT_OPEN;
110 rec->cr_fsuid = current->fsuid;
111 rec->cr_fsgid = current->fsgid;
112 rec->cr_cap = current->cap_effective;
113 ll_ino2fid(&rec->cr_fid, op_data->ino1,
114 op_data->gen1, op_data->typ1);
115 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
117 rec->cr_flags = flags;
122 if (in_group_p(op_data->gid1))
123 rec->cr_suppgid = op_data->gid1;
125 rec->cr_suppgid = -1;
127 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
128 LOGL0(op_data->name, op_data->namelen, tmp);
131 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
132 memcpy (tmp, data, datalen);
135 void mds_setattr_pack(struct ptlrpc_request *req,
136 struct mdc_op_data *data,
137 struct iattr *iattr, void *ea, int ealen)
139 struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, 0,
141 rec->sa_opcode = REINT_SETATTR;
142 rec->sa_fsuid = current->fsuid;
143 rec->sa_fsgid = current->fsgid;
144 rec->sa_cap = current->cap_effective;
145 ll_ino2fid(&rec->sa_fid, data->ino1, data->gen1, data->typ1);
148 rec->sa_valid = iattr->ia_valid;
149 rec->sa_mode = iattr->ia_mode;
150 rec->sa_uid = iattr->ia_uid;
151 rec->sa_gid = iattr->ia_gid;
152 rec->sa_size = iattr->ia_size;
153 rec->sa_atime = LTIME_S(iattr->ia_atime);
154 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
155 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
156 rec->sa_attr_flags = iattr->ia_attr_flags;
158 if ((iattr->ia_valid & ATTR_GID) && in_group_p(iattr->ia_gid))
159 rec->sa_suppgid = iattr->ia_gid;
160 else if ((iattr->ia_valid & ATTR_MODE) &&
161 in_group_p(data->gid1))
162 rec->sa_suppgid = data->gid1;
164 rec->sa_suppgid = -1;
168 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, ealen), ea, ealen);
171 void mds_unlink_pack(struct ptlrpc_request *req, int offset,
172 struct mdc_op_data *data)
174 struct mds_rec_unlink *rec;
177 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
178 LASSERT (rec != NULL);
180 rec->ul_opcode = REINT_UNLINK;
181 rec->ul_fsuid = current->fsuid;
182 rec->ul_fsgid = current->fsgid;
183 rec->ul_cap = current->cap_effective;
184 rec->ul_mode = data->mode;
185 if (in_group_p(data->gid1))
186 rec->ul_suppgid = data->gid1;
188 rec->ul_suppgid = -1;
189 ll_ino2fid(&rec->ul_fid1, data->ino1, data->gen1, data->typ1);
191 ll_ino2fid(&rec->ul_fid2, data->ino2, data->gen2, data->typ2);
193 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
194 LASSERT (tmp != NULL);
195 LOGL0(data->name, data->namelen, tmp);
198 void mds_link_pack(struct ptlrpc_request *req, int offset,
199 struct mdc_op_data *data)
201 struct mds_rec_link *rec;
204 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
206 rec->lk_opcode = REINT_LINK;
207 rec->lk_fsuid = current->fsuid;
208 rec->lk_fsgid = current->fsgid;
209 rec->lk_cap = current->cap_effective;
210 if (in_group_p(data->gid1))
211 rec->lk_suppgid1 = data->gid1;
213 rec->lk_suppgid1 = -1;
214 if (in_group_p(data->gid2))
215 rec->lk_suppgid2 = data->gid2;
217 rec->lk_suppgid2 = -1;
218 ll_ino2fid(&rec->lk_fid1, data->ino1, data->gen1, data->typ1);
219 ll_ino2fid(&rec->lk_fid2, data->ino2, data->gen2, data->typ2);
221 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
222 LOGL0(data->name, data->namelen, tmp);
225 void mds_rename_pack(struct ptlrpc_request *req, int offset,
226 struct mdc_op_data *data,
227 const char *old, int oldlen, const char *new, int newlen)
229 struct mds_rec_rename *rec;
232 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
234 /* XXX do something about time, uid, gid */
235 rec->rn_opcode = REINT_RENAME;
236 rec->rn_fsuid = current->fsuid;
237 rec->rn_fsgid = current->fsgid;
238 rec->rn_cap = current->cap_effective;
239 if (in_group_p(data->gid1))
240 rec->rn_suppgid1 = data->gid1;
242 rec->rn_suppgid1 = -1;
243 if (in_group_p(data->gid2))
244 rec->rn_suppgid2 = data->gid2;
246 rec->rn_suppgid2 = -1;
247 ll_ino2fid(&rec->rn_fid1, data->ino1, data->gen1, data->typ1);
248 ll_ino2fid(&rec->rn_fid2, data->ino2, data->gen2, data->typ2);
250 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, oldlen + 1);
251 LOGL0(old, oldlen, tmp);
254 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, newlen + 1);
255 LOGL0(new, newlen, tmp);
259 void mds_getattr_pack(struct ptlrpc_request *req, int valid, int offset,
260 int flags, struct mdc_op_data *data)
263 b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b));
265 b->fsuid = current->fsuid;
266 b->fsgid = current->fsgid;
267 b->capability = current->cap_effective;
270 if (in_group_p(data->gid1))
271 b->suppgid = data->gid1;
275 ll_ino2fid(&b->fid1, data->ino1, data->gen1, data->typ1);
278 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
280 LOGL0(data->name, data->namelen, tmp);