Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / mdc / mdc_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  */
21
22 #define DEBUG_SUBSYSTEM S_MDS
23 #ifndef __KERNEL__
24 # include <liblustre.h>
25 #endif
26 #include <linux/lustre_idl.h>
27 #include <linux/lustre_net.h>
28 #include <linux/lustre_mds.h>
29 #include <linux/lustre_lite.h>
30
31 void mds_readdir_pack(struct ptlrpc_request *req, __u64 offset, __u32 size,
32                       obd_id ino, int type, __u64 xid)
33 {
34         struct mds_body *b;
35
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;
40         b->fid1.id = ino;
41         b->fid1.f_type = type;
42         b->size = offset;                       /* !! */
43         b->suppgid = -1;
44         b->blocks = xid;                        /* !! */
45         b->nlink = size;                        /* !! */
46 }
47
48 static void mds_pack_body(struct mds_body *b)
49 {
50         LASSERT (b != NULL);
51
52         b->fsuid = current->fsuid;
53         b->fsgid = current->fsgid;
54         b->capability = current->cap_effective;
55 }
56
57 void mds_pack_req_body(struct ptlrpc_request *req)
58 {
59         struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
60         mds_pack_body(b);
61 }
62
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)
68 {
69         struct mds_rec_create *rec;
70         char *tmp;
71         rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
72
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));
79         rec->cr_mode = mode;
80         rec->cr_rdev = rdev;
81         rec->cr_uid = uid;
82         rec->cr_gid = gid;
83         rec->cr_time = time;
84         if (in_group_p(op_data->gid1))
85                 rec->cr_suppgid = op_data->gid1;
86         else
87                 rec->cr_suppgid = -1;
88
89         tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
90         LOGL0(op_data->name, op_data->namelen, tmp);
91
92         if (data) {
93                 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
94                 memcpy (tmp, data, datalen);
95         }
96 }
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,
101                    __u32 flags,
102                    const void *data, int datalen)
103 {
104         struct mds_rec_create *rec;
105         char *tmp;
106         rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
107
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));
116         rec->cr_mode = mode;
117         rec->cr_flags = flags;
118         rec->cr_rdev = rdev;
119         rec->cr_uid = uid;
120         rec->cr_gid = gid;
121         rec->cr_time = time;
122         if (in_group_p(op_data->gid1))
123                 rec->cr_suppgid = op_data->gid1;
124         else
125                 rec->cr_suppgid = -1;
126
127         tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
128         LOGL0(op_data->name, op_data->namelen, tmp);
129
130         if (data) {
131                 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
132                 memcpy (tmp, data, datalen);
133         }
134 }
135 void mds_setattr_pack(struct ptlrpc_request *req,
136                       struct mdc_op_data *data,
137                       struct iattr *iattr, void *ea, int ealen)
138 {
139         struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, 0,
140                                                      sizeof (*rec));
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);
146
147         if (iattr) {
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;
157
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;
163                 else
164                         rec->sa_suppgid = -1;
165         }
166
167         if (ealen != 0)
168                 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, ealen), ea, ealen);
169 }
170
171 void mds_unlink_pack(struct ptlrpc_request *req, int offset,
172                      struct mdc_op_data *data)
173 {
174         struct mds_rec_unlink *rec;
175         char *tmp;
176
177         rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
178         LASSERT (rec != NULL);
179
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;
187         else
188                 rec->ul_suppgid = -1;
189         ll_ino2fid(&rec->ul_fid1, data->ino1, data->gen1, data->typ1);
190         if (data->ino2)
191                 ll_ino2fid(&rec->ul_fid2, data->ino2, data->gen2, data->typ2);
192
193         tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
194         LASSERT (tmp != NULL);
195         LOGL0(data->name, data->namelen, tmp);
196 }
197
198 void mds_link_pack(struct ptlrpc_request *req, int offset,
199                    struct mdc_op_data *data)
200 {
201         struct mds_rec_link *rec;
202         char *tmp;
203
204         rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
205
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;
212         else
213                 rec->lk_suppgid1 = -1;
214         if (in_group_p(data->gid2))
215                 rec->lk_suppgid2 = data->gid2;
216         else
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);
220
221         tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
222         LOGL0(data->name, data->namelen, tmp);
223 }
224
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)
228 {
229         struct mds_rec_rename *rec;
230         char *tmp;
231
232         rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
233
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;
241         else
242                 rec->rn_suppgid1 = -1;
243         if (in_group_p(data->gid2))
244                 rec->rn_suppgid2 = data->gid2;
245         else
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);
249
250         tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, oldlen + 1);
251         LOGL0(old, oldlen, tmp);
252
253         if (new) {
254                 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, newlen + 1);
255                 LOGL0(new, newlen, tmp);
256         }
257 }
258
259 void mds_getattr_pack(struct ptlrpc_request *req, int valid, int offset,
260                       int flags, struct mdc_op_data *data)
261 {
262         struct mds_body *b;
263         b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b));
264
265         b->fsuid = current->fsuid;
266         b->fsgid = current->fsgid;
267         b->capability = current->cap_effective;
268         b->valid = valid;
269         b->flags = flags;
270         if (in_group_p(data->gid1))
271                 b->suppgid = data->gid1;
272         else
273                 b->suppgid = -1;
274
275         ll_ino2fid(&b->fid1, data->ino1, data->gen1, data->typ1);
276         if (data->name) {
277                 char *tmp;
278                 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
279                                      data->namelen + 1);
280                 LOGL0(data->name, data->namelen, tmp);
281         }
282 }