Whamcloud - gitweb
b=3031
[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 lustre_id *mdc_id)
44 {
45         struct mds_body *b;
46
47         b = lustre_msg_buf(req->rq_reqmsg, req_offset, sizeof (*b));
48         b->id1 = *mdc_id;
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
68 /* packing of MDS records */
69 void mdc_open_pack(struct lustre_msg *msg, int offset,
70                    struct mdc_op_data *op_data, __u32 mode,
71                    __u64 rdev, __u32 flags, const void *lmm,
72                    int lmmlen)
73 {
74         struct mds_rec_create *rec;
75         char *tmp;
76         
77         rec = lustre_msg_buf(msg, offset, sizeof (*rec));
78
79         /* XXX do something about time, uid, gid */
80         rec->cr_opcode = REINT_OPEN;
81         if (op_data != NULL)
82                 rec->cr_id = op_data->id1;
83         memset(&rec->cr_replayid, 0, sizeof(rec->cr_replayid));
84         rec->cr_flags = mds_pack_open_flags(flags);
85         rec->cr_time = op_data->mod_time;
86         rec->cr_mode = mode;
87         rec->cr_rdev = rdev;
88
89         if (op_data->name) {
90                 tmp = lustre_msg_buf(msg, offset + 1,
91                                      op_data->namelen + 1);
92                 LOGL0(op_data->name, op_data->namelen, tmp);
93         }
94
95         if (lmm) {
96                 rec->cr_flags |= MDS_OPEN_HAS_EA;
97                 tmp = lustre_msg_buf(msg, offset + 2, lmmlen);
98                 memcpy (tmp, lmm, lmmlen);
99         }
100 }
101
102 void mdc_getattr_pack(struct lustre_msg *msg, int offset,
103                       __u64 valid, int flags, struct mdc_op_data *data)
104 {
105         struct mds_body *b;
106         b = lustre_msg_buf(msg, offset, sizeof (*b));
107
108         b->valid = valid;
109         b->flags = flags;
110
111         b->id1 = data->id1;
112         b->id2 = data->id2;
113         if (data->name) {
114                 char *tmp;
115                 tmp = lustre_msg_buf(msg, offset + 1,
116                                      data->namelen + 1);
117                 LOGL0(data->name, data->namelen, tmp);
118         }
119 }
120
121 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
122                     __u64 valid, struct obd_client_handle *och)
123 {
124         struct mds_body *body;
125
126         body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
127         mdc_pack_id(&body->id1, oa->o_id, 0, oa->o_mode, 0, 0);
128
129         memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
130         if (oa->o_valid & OBD_MD_FLATIME) {
131                 body->atime = oa->o_atime;
132                 body->valid |= OBD_MD_FLATIME;
133         }
134         if (oa->o_valid & OBD_MD_FLMTIME) {
135                 body->mtime = oa->o_mtime;
136                 body->valid |= OBD_MD_FLMTIME;
137         }
138         if (oa->o_valid & OBD_MD_FLCTIME) {
139                 body->ctime = oa->o_ctime;
140                 body->valid |= OBD_MD_FLCTIME;
141         }
142         if (oa->o_valid & OBD_MD_FLSIZE) {
143                 body->size = oa->o_size;
144                 body->valid |= OBD_MD_FLSIZE;
145         }
146         if (oa->o_valid & OBD_MD_FLBLOCKS) {
147                 body->blocks = oa->o_blocks;
148                 body->valid |= OBD_MD_FLBLOCKS;
149         }
150         if (oa->o_valid & OBD_MD_FLFLAGS) {
151                 body->flags = oa->o_flags;
152                 body->valid |= OBD_MD_FLFLAGS;
153         }
154 }
155
156 /* 
157  * these methods needed for saying higher levels that MDC does not pack/unpack
158  * any EAs. This is needed to have real abstraction and do not try to recognize
159  * what OBD type is to avoid calling these methods on it, as they may not be
160  * implemented.
161  *
162  * Sometimes pack/unpack calls happen to MDC too. This is for instance default
163  * striping info for directories and our goal here is to skip them with no
164  * errors or any complains.
165  */
166 int mdc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
167                struct lov_stripe_md *lsm)
168 {
169         ENTRY;
170         RETURN(0);
171 }
172
173 int mdc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
174                  struct lov_mds_md *lmm, int lmm_size)
175 {
176         ENTRY;
177         RETURN(0);
178 }
179