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