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.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_MDS
28 # include <liblustre.h>
30 #include <linux/lustre_idl.h>
31 #include <linux/lustre_net.h>
32 #include <linux/lustre_mds.h>
33 #include "mdc_internal.h"
36 /* some liblustre hackings here */
42 void mdc_readdir_pack(struct ptlrpc_request *req, __u64 offset, __u32 size,
43 struct ll_fid *mdc_fid)
47 b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
48 b->fsuid = current->fsuid;
49 b->fsgid = current->fsgid;
50 b->capability = current->cap_effective;
52 b->size = offset; /* !! */
54 b->nlink = size; /* !! */
57 static void mdc_pack_body(struct mds_body *b)
61 b->fsuid = current->fsuid;
62 b->fsgid = current->fsgid;
63 b->capability = current->cap_effective;
66 void mdc_pack_req_body(struct ptlrpc_request *req)
68 struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
71 static __u32 mds_pack_open_flags(__u32 flags)
74 (flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC |
75 MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
77 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
78 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
79 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
80 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
81 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
82 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
85 /* packing of MDS records */
86 void mdc_open_pack(struct lustre_msg *msg, int offset,
87 struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
88 __u32 flags, const void *lmm, int lmmlen)
90 struct mds_rec_create *rec;
92 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
94 /* XXX do something about time, uid, gid */
95 rec->cr_opcode = REINT_OPEN;
96 rec->cr_fsuid = current->fsuid;
97 rec->cr_fsgid = current->fsgid;
98 rec->cr_cap = current->cap_effective;
100 rec->cr_fid = op_data->fid1;
101 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
103 rec->cr_flags = mds_pack_open_flags(flags);
105 rec->cr_time = op_data->mod_time;
106 rec->cr_suppgid = op_data->ctxt.gid1;
109 tmp = lustre_msg_buf(msg, offset + 1,
110 op_data->namelen + 1);
111 LOGL0(op_data->name, op_data->namelen, tmp);
115 rec->cr_flags |= MDS_OPEN_HAS_EA;
116 tmp = lustre_msg_buf(msg, offset + 2, lmmlen);
117 memcpy (tmp, lmm, lmmlen);
120 void mdc_getattr_pack(struct lustre_msg *msg, int valid, int offset,
121 int flags, struct mdc_op_data *data)
124 b = lustre_msg_buf(msg, offset, sizeof (*b));
126 b->fsuid = current->fsuid;
127 b->fsgid = current->fsgid;
128 b->capability = current->cap_effective;
131 b->suppgid = data->ctxt.gid1;
133 b->fid1 = data->fid1;
134 b->fid2 = data->fid2;
137 tmp = lustre_msg_buf(msg, offset + 1,
139 LOGL0(data->name, data->namelen, tmp);
143 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
144 int valid, struct obd_client_handle *och)
146 struct mds_body *body;
148 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
150 mdc_pack_fid(&body->fid1, oa->o_id, 0, oa->o_mode);
151 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
152 if (oa->o_valid & OBD_MD_FLATIME) {
153 body->atime = oa->o_atime;
154 body->valid |= OBD_MD_FLATIME;
156 if (oa->o_valid & OBD_MD_FLMTIME) {
157 body->mtime = oa->o_mtime;
158 body->valid |= OBD_MD_FLMTIME;
160 if (oa->o_valid & OBD_MD_FLCTIME) {
161 body->ctime = oa->o_ctime;
162 body->valid |= OBD_MD_FLCTIME;
164 if (oa->o_valid & OBD_MD_FLSIZE) {
165 body->size = oa->o_size;
166 body->valid |= OBD_MD_FLSIZE;
168 if (oa->o_valid & OBD_MD_FLBLOCKS) {
169 body->blocks = oa->o_blocks;
170 body->valid |= OBD_MD_FLBLOCKS;
172 if (oa->o_valid & OBD_MD_FLFLAGS) {
173 body->flags = oa->o_flags;
174 body->valid |= OBD_MD_FLFLAGS;