Whamcloud - gitweb
land b_groups onto HEAD:
[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 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_MDS
26 #ifndef __KERNEL__
27 # include <fcntl.h>
28 # include <liblustre.h>
29 #endif
30 #include <linux/lustre_idl.h>
31 #include <linux/lustre_net.h>
32 #include <linux/lustre_mds.h>
33 #include "mdc_internal.h"
34
35 #ifndef __KERNEL__
36 /* some liblustre hackings here */
37 #ifndef O_DIRECTORY
38 #define O_DIRECTORY     0
39 #endif
40 #endif
41
42 void mdc_readdir_pack(struct ptlrpc_request *req, int req_offset,
43                       __u64 offset, __u32 size, struct ll_fid *mdc_fid)
44 {
45         struct mds_body *b;
46
47         b = lustre_msg_buf(req->rq_reqmsg, req_offset, sizeof (*b));
48         b->fid1 = *mdc_fid;
49         b->size = offset;                       /* !! */
50         b->nlink = size;                        /* !! */
51 }
52
53 static __u32 mds_pack_open_flags(__u32 flags)
54 {
55         return
56                 (flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC |
57                           MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
58                           MDS_OPEN_HAS_OBJS)) |
59                 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
60                 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
61                 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
62                 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
63                 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
64                 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
65                 0;
66 }
67 /* packing of MDS records */
68 void mdc_open_pack(struct lustre_msg *msg, int offset,
69                    struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
70                    __u32 flags, const void *lmm, int lmmlen)
71 {
72         struct mds_rec_create *rec;
73         char *tmp;
74         rec = lustre_msg_buf(msg, offset, sizeof (*rec));
75
76         /* XXX do something about time, uid, gid */
77         rec->cr_opcode = REINT_OPEN;
78         if (op_data != NULL)
79                 rec->cr_fid = op_data->fid1;
80         memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
81         rec->cr_mode = mode;
82         rec->cr_flags = mds_pack_open_flags(flags);
83         rec->cr_rdev = rdev;
84         rec->cr_time = op_data->mod_time;
85
86         if (op_data->name) {
87                 tmp = lustre_msg_buf(msg, offset + 1,
88                                      op_data->namelen + 1);
89                 LOGL0(op_data->name, op_data->namelen, tmp);
90         }
91
92         if (lmm) {
93                 rec->cr_flags |= MDS_OPEN_HAS_EA;
94                 tmp = lustre_msg_buf(msg, offset + 2, lmmlen);
95                 memcpy (tmp, lmm, lmmlen);
96         }
97 }
98
99 void mdc_getattr_pack(struct lustre_msg *msg, int offset, int valid,
100                       int flags, struct mdc_op_data *data)
101 {
102         struct mds_body *b;
103         b = lustre_msg_buf(msg, offset, sizeof (*b));
104
105         b->valid = valid;
106         b->flags = flags;
107
108         b->fid1 = data->fid1;
109         b->fid2 = data->fid2;
110         if (data->name) {
111                 char *tmp;
112                 tmp = lustre_msg_buf(msg, offset + 1,
113                                      data->namelen + 1);
114                 LOGL0(data->name, data->namelen, tmp);
115         }
116 }
117
118 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
119                     int valid, struct obd_client_handle *och)
120 {
121         struct mds_body *body;
122
123         body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
124
125         mdc_pack_fid(&body->fid1, oa->o_id, 0, oa->o_mode);
126         memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
127         if (oa->o_valid & OBD_MD_FLATIME) {
128                 body->atime = oa->o_atime;
129                 body->valid |= OBD_MD_FLATIME;
130         }
131         if (oa->o_valid & OBD_MD_FLMTIME) {
132                 body->mtime = oa->o_mtime;
133                 body->valid |= OBD_MD_FLMTIME;
134         }
135         if (oa->o_valid & OBD_MD_FLCTIME) {
136                 body->ctime = oa->o_ctime;
137                 body->valid |= OBD_MD_FLCTIME;
138         }
139         if (oa->o_valid & OBD_MD_FLSIZE) {
140                 body->size = oa->o_size;
141                 body->valid |= OBD_MD_FLSIZE;
142         }
143         if (oa->o_valid & OBD_MD_FLBLOCKS) {
144                 body->blocks = oa->o_blocks;
145                 body->valid |= OBD_MD_FLBLOCKS;
146         }
147         if (oa->o_valid & OBD_MD_FLFLAGS) {
148                 body->flags = oa->o_flags;
149                 body->valid |= OBD_MD_FLFLAGS;
150         }
151 }