Whamcloud - gitweb
Fix comments, add declaration for simple_mknod().
[fs/lustre-release.git] / lustre / lib / lov_pack.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc. <adilger@clusterfs.com>
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  * (Un)packing of OST/MDS requests
22  *
23  */
24
25 #define DEBUG_SUBSYSTEM S_LLITE
26
27 #include <linux/lustre_net.h>
28 #include <linux/obd.h>
29 #include <linux/obd_support.h>
30
31 void lov_packdesc(struct lov_desc *ld)
32 {
33         ld->ld_tgt_count = HTON__u32(ld->ld_tgt_count);
34         ld->ld_default_stripe_count = HTON__u32(ld->ld_default_stripe_count);
35         ld->ld_default_stripe_size = HTON__u32(ld->ld_default_stripe_size);
36         ld->ld_pattern = HTON__u32(ld->ld_pattern);
37 }
38
39 void lov_unpackdesc(struct lov_desc *ld)
40 {
41         ld->ld_tgt_count = NTOH__u32(ld->ld_tgt_count);
42         ld->ld_default_stripe_count = HTON__u32(ld->ld_default_stripe_count);
43         ld->ld_default_stripe_size = HTON__u32(ld->ld_default_stripe_size);
44         ld->ld_pattern = HTON__u32(ld->ld_pattern);
45 }
46
47 void lov_packmd(struct lov_mds_md *lmm, struct lov_stripe_md *lsm)
48 {
49         struct lov_oinfo *loi;
50         int i;
51
52         /* XXX endianness */
53         lmm->lmm_magic = (lsm->lsm_magic);
54         lmm->lmm_easize = (lsm->lsm_mds_easize);
55         lmm->lmm_object_id = (lsm->lsm_object_id);
56         lmm->lmm_stripe_size = (lsm->lsm_stripe_size);
57         lmm->lmm_stripe_pattern = (lsm->lsm_stripe_pattern);
58         lmm->lmm_ost_count = (lsm->lsm_ost_count);
59         lmm->lmm_stripe_count = (lsm->lsm_stripe_count);
60         lmm->lmm_stripe_offset = (lsm->lsm_stripe_offset);
61
62         /* Only fill in the object ids which we are actually using.
63          * Assumes lmd_objects is otherwise zero-filled. */
64         for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
65                 lmm->lmm_objects[loi->loi_ost_idx].l_object_id =
66                         (loi->loi_id);
67         }
68 }
69
70 void lov_unpackmd(struct lov_stripe_md *lsm, struct lov_mds_md *lmm)
71 {
72         struct lov_oinfo *loi;
73         int ost_count, ost_offset;
74         int i;
75
76         /* XXX endianness */
77         lsm->lsm_magic = (lmm->lmm_magic);
78         lsm->lsm_mds_easize = (lmm->lmm_easize);
79         lsm->lsm_object_id = (lmm->lmm_object_id);
80         lsm->lsm_stripe_size = (lmm->lmm_stripe_size);
81         lsm->lsm_stripe_pattern = (lmm->lmm_stripe_pattern);
82         lsm->lsm_ost_count = (lmm->lmm_ost_count);
83         lsm->lsm_stripe_count = (lmm->lmm_stripe_count);
84         lsm->lsm_stripe_offset = (lmm->lmm_stripe_offset);
85
86         ost_count = lsm->lsm_ost_count;
87         ost_offset = lsm->lsm_stripe_offset;
88
89         for (i = 0, loi = lsm->lsm_oinfo; i < ost_count; i++, ost_offset++) {
90                 ost_offset %= ost_count;
91
92                 if (!lmm->lmm_objects[ost_offset].l_object_id)
93                         continue;
94
95                 LASSERT(loi - lsm->lsm_oinfo < lsm->lsm_stripe_count);
96                 loi->loi_id = (lmm->lmm_objects[ost_offset].l_object_id);
97                 loi->loi_ost_idx = ost_offset;
98                 loi->loi_size = 0;         /* set by LOV later */
99                 loi++;
100         }
101 }