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, int req_offset,
43 __u64 offset, __u32 size, struct lustre_id *mdc_id)
47 b = lustre_msg_buf(req->rq_reqmsg, req_offset, sizeof (*b));
49 b->size = offset; /* !! */
50 b->nlink = size; /* !! */
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)
59 struct mds_rec_create *rec;
62 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
64 /* XXX do something about time, uid, gid */
65 rec->cr_opcode = REINT_OPEN;
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;
75 tmp = lustre_msg_buf(msg, offset + 1,
76 op_data->namelen + 1);
77 LOGL0(op_data->name, op_data->namelen, tmp);
81 rec->cr_flags |= MDS_OPEN_HAS_EA;
82 tmp = lustre_msg_buf(msg, offset + 2, lmmlen);
83 memcpy (tmp, lmm, lmmlen);
86 rec->cr_flags |= MDS_OPEN_HAS_KEY;
87 tmp = lustre_msg_buf(msg, offset + 3, keylen);
88 memcpy(tmp, key, keylen);
92 void mdc_getattr_pack(struct lustre_msg *msg, int offset,
93 __u64 valid, int flags, struct mdc_op_data *data)
96 b = lustre_msg_buf(msg, offset, sizeof (*b));
105 tmp = lustre_msg_buf(msg, offset + 1,
107 LOGL0(data->name, data->namelen, tmp);
111 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
112 __u64 valid, struct obd_client_handle *och)
114 struct mds_body *body;
116 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
117 mdc_pack_id(&body->id1, oa->o_id, oa->o_generation, oa->o_mode, 0, 0);
119 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
120 if (oa->o_valid & OBD_MD_FLATIME) {
121 body->atime = oa->o_atime;
122 body->valid |= OBD_MD_FLATIME;
124 if (oa->o_valid & OBD_MD_FLMTIME) {
125 body->mtime = oa->o_mtime;
126 body->valid |= OBD_MD_FLMTIME;
128 if (oa->o_valid & OBD_MD_FLCTIME) {
129 body->ctime = oa->o_ctime;
130 body->valid |= OBD_MD_FLCTIME;
132 if (oa->o_valid & OBD_MD_FLSIZE) {
133 body->size = oa->o_size;
134 body->valid |= OBD_MD_FLSIZE;
136 if (oa->o_valid & OBD_MD_FLBLOCKS) {
137 body->blocks = oa->o_blocks;
138 body->valid |= OBD_MD_FLBLOCKS;
140 if (oa->o_valid & OBD_MD_FLFLAGS) {
141 body->flags = oa->o_flags;
142 body->valid |= OBD_MD_FLFLAGS;
144 if (oa->o_valid & OBD_MD_FLEPOCH) {
145 body->io_epoch = oa->o_easize;
146 body->valid |= OBD_MD_FLEPOCH;
151 * these methods needed for saying higher levels that MDC does not pack/unpack
152 * any EAs. This is needed to have real abstraction and do not try to recognize
153 * what OBD type is to avoid calling these methods on it, as they may not be
156 * Sometimes pack/unpack calls happen to MDC too. This is for instance default
157 * striping info for directories and our goal here is to skip them with no
158 * errors or any complains.
160 int mdc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
161 struct lov_stripe_md *lsm)
167 int mdc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
168 struct lov_mds_md *lmm, int lmm_size)