1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc. <adilger@clusterfs.com>
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.
21 * (Un)packing of OST/MDS requests
25 #define DEBUG_SUBSYSTEM S_LLITE
27 #include <linux/lustre_net.h>
28 #include <linux/obd.h>
29 #include <linux/obd_lov.h>
30 #include <linux/obd_support.h>
32 /* lov_packdesc() is in mds/mds_lov.c */
34 void lov_unpackdesc(struct lov_desc *ld)
36 ld->ld_tgt_count = NTOH__u32(ld->ld_tgt_count);
37 ld->ld_default_stripe_count = HTON__u32(ld->ld_default_stripe_count);
38 ld->ld_default_stripe_size = HTON__u32(ld->ld_default_stripe_size);
39 ld->ld_pattern = HTON__u32(ld->ld_pattern);
42 /* Pack LOV object metadata for shipment to the MDS.
44 * XXX In the future, this will be enhanced to get the EA size from the
45 * underlying OSC device(s) to get their EA sizes so we can stack
46 * LOVs properly. For now lov_mds_md_size() just assumes one obd_id
49 int lov_packmd(struct lustre_handle *conn, struct lov_mds_md **lmmp,
50 struct lov_stripe_md *lsm)
52 struct obd_device *obd = class_conn2obd(conn);
53 struct lov_obd *lov = &obd->u.lov;
54 struct lov_oinfo *loi;
55 struct lov_mds_md *lmm;
56 int ost_count = lov->desc.ld_tgt_count;
57 int stripe_count = ost_count;
63 if (lsm->lsm_magic != LOV_MAGIC) {
64 CERROR("bad mem LOV MAGIC: %#08x != %#08x\n",
65 lsm->lsm_magic, LOV_MAGIC);
68 stripe_count = lsm->lsm_stripe_count;
71 /* XXX LOV STACKING call into osc for sizes */
72 lmm_size = lov_mds_md_size(ost_count);
79 ost_count = ((*lmmp)->lmm_ost_count);
80 OBD_FREE(*lmmp, lov_mds_md_size(ost_count));
86 OBD_ALLOC(*lmmp, lmm_size);
93 lmm->lmm_stripe_count = (stripe_count);
97 lmm->lmm_magic = (lsm->lsm_magic);
98 lmm->lmm_object_id = (lsm->lsm_object_id);
99 LASSERT(lsm->lsm_object_id);
100 lmm->lmm_stripe_size = (lsm->lsm_stripe_size);
101 lmm->lmm_stripe_pattern = (lsm->lsm_stripe_pattern);
102 lmm->lmm_stripe_offset = (lsm->lsm_stripe_offset);
103 lmm->lmm_ost_count = (lov->desc.ld_tgt_count);
105 /* Only fill in the object ids which we are actually using.
106 * Assumes lmm_objects is otherwise zero-filled. */
107 for (i = 0, loi = lsm->lsm_oinfo; i < stripe_count; i++, loi++) {
108 /* XXX call down to osc_packmd() to do the packing */
109 LASSERT(loi->loi_id);
110 lmm->lmm_objects[loi->loi_ost_idx].l_object_id = (loi->loi_id);
116 int lov_unpackmd(struct lustre_handle *conn, struct lov_stripe_md **lsmp,
117 struct lov_mds_md *lmm)
119 struct obd_device *obd = class_conn2obd(conn);
120 struct lov_obd *lov = &obd->u.lov;
121 struct lov_stripe_md *lsm;
122 struct lov_oinfo *loi;
123 int ost_count = lov->desc.ld_active_tgt_count;
125 int stripe_count = 0;
132 if (lmm->lmm_magic != LOV_MAGIC) {
133 CERROR("bad wire LOV MAGIC: %#08x != %#08x\n",
134 lmm->lmm_magic, LOV_MAGIC);
137 stripe_count = (lmm->lmm_stripe_count);
141 stripe_count = lov->desc.ld_default_stripe_count;
142 if (!stripe_count || stripe_count > ost_count)
143 stripe_count = ost_count;
145 /* XXX LOV STACKING call into osc for sizes */
146 lsm_size = lov_stripe_md_size(stripe_count);
152 stripe_count = (*lsmp)->lsm_stripe_count;
153 OBD_FREE(*lsmp, lov_stripe_md_size(stripe_count));
159 OBD_ALLOC(*lsmp, lsm_size);
166 lsm->lsm_stripe_count = stripe_count;
171 ost_offset = lsm->lsm_stripe_offset = (lmm->lmm_stripe_offset);
172 lsm->lsm_magic = (lmm->lmm_magic);
173 lsm->lsm_object_id = (lmm->lmm_object_id);
174 LASSERT(lsm->lsm_object_id);
175 lsm->lsm_stripe_size = (lmm->lmm_stripe_size);
176 lsm->lsm_stripe_pattern = (lmm->lmm_stripe_pattern);
178 for (i = 0, loi = lsm->lsm_oinfo; i < ost_count; i++, ost_offset++) {
179 ost_offset %= ost_count;
181 if (!lmm->lmm_objects[ost_offset].l_object_id)
184 LASSERT(loi - lsm->lsm_oinfo < stripe_count);
185 /* XXX LOV STACKING call down to osc_unpackmd() */
186 loi->loi_id = (lmm->lmm_objects[ost_offset].l_object_id);
187 loi->loi_ost_idx = ost_offset;
190 LASSERT(loi - lsm->lsm_oinfo == stripe_count);