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 stripe_count = lsm->lsm_stripe_count;
65 /* XXX LOV STACKING call into osc for sizes */
66 lmm_size = lov_mds_md_size(ost_count);
73 ost_count = ((*lmmp)->lmm_ost_count);
74 OBD_FREE(*lmmp, lov_mds_md_size(ost_count));
80 OBD_ALLOC(*lmmp, lmm_size);
87 lmm->lmm_stripe_count = (stripe_count);
91 lmm->lmm_magic = (lsm->lsm_magic);
92 lmm->lmm_object_id = (lsm->lsm_object_id);
93 lmm->lmm_stripe_size = (lsm->lsm_stripe_size);
94 lmm->lmm_stripe_pattern = (lsm->lsm_stripe_pattern);
95 lmm->lmm_stripe_offset = (lsm->lsm_stripe_offset);
96 lmm->lmm_ost_count = (lov->desc.ld_tgt_count);
98 /* Only fill in the object ids which we are actually using.
99 * Assumes lmm_objects is otherwise zero-filled. */
100 for (i = 0, loi = lsm->lsm_oinfo; i < stripe_count; i++, loi++)
101 /* XXX call down to osc_packmd() to do the packing */
102 lmm->lmm_objects[loi->loi_ost_idx].l_object_id = (loi->loi_id);
107 int lov_unpackmd(struct lustre_handle *conn, struct lov_stripe_md **lsmp,
108 struct lov_mds_md *lmm)
110 struct obd_device *obd = class_conn2obd(conn);
111 struct lov_obd *lov = &obd->u.lov;
112 struct lov_stripe_md *lsm;
113 struct lov_oinfo *loi;
114 int ost_count = lov->desc.ld_active_tgt_count;
116 int stripe_count = 0;
123 stripe_count = (lmm->lmm_stripe_count);
126 stripe_count = lov->desc.ld_default_stripe_count;
127 if (!stripe_count || stripe_count > ost_count)
128 stripe_count = ost_count;
130 /* XXX LOV STACKING call into osc for sizes */
131 lsm_size = lov_stripe_md_size(stripe_count);
137 stripe_count = (*lsmp)->lsm_stripe_count;
138 OBD_FREE(*lsmp, lov_stripe_md_size(stripe_count));
144 OBD_ALLOC(*lsmp, lsm_size);
151 lsm->lsm_stripe_count = stripe_count;
156 ost_offset = lsm->lsm_stripe_offset = (lmm->lmm_stripe_offset);
157 lsm->lsm_magic = (lmm->lmm_magic);
158 lsm->lsm_object_id = (lmm->lmm_object_id);
159 lsm->lsm_stripe_size = (lmm->lmm_stripe_size);
160 lsm->lsm_stripe_pattern = (lmm->lmm_stripe_pattern);
162 for (i = 0, loi = lsm->lsm_oinfo; i < ost_count; i++, ost_offset++) {
163 ost_offset %= ost_count;
165 if (!lmm->lmm_objects[ost_offset].l_object_id)
168 LASSERT(loi - lsm->lsm_oinfo < stripe_count);
169 /* XXX LOV STACKING call down to osc_unpackmd() */
170 loi->loi_id = (lmm->lmm_objects[ost_offset].l_object_id);
171 loi->loi_ost_idx = ost_offset;