1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Andreas Dilger <adilger@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * (Un)packing of OST/MDS requests
26 #define DEBUG_SUBSYSTEM S_CLASS
30 #include <liblustre.h>
33 #include <linux/version.h>
34 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
35 #include <asm/statfs.h>
38 #include <linux/lustre_export.h>
39 #include <linux/lustre_net.h>
40 #include <linux/obd_support.h>
41 #include <linux/obd_class.h>
43 void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src)
45 tgt->os_type = HTON__u64(src->os_type);
46 tgt->os_blocks = HTON__u64(src->os_blocks);
47 tgt->os_bfree = HTON__u64(src->os_bfree);
48 tgt->os_bavail = HTON__u64(src->os_bavail);
49 tgt->os_files = HTON__u64(src->os_files);
50 tgt->os_ffree = HTON__u64(src->os_ffree);
51 tgt->os_bsize = HTON__u32(src->os_bsize);
52 tgt->os_namelen = HTON__u32(src->os_namelen);
55 void obd_statfs_unpack(struct obd_statfs *tgt, struct obd_statfs *src)
57 obd_statfs_pack(tgt, src);
60 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs)
62 osfs->os_type = sfs->f_type;
63 osfs->os_blocks = sfs->f_blocks;
64 osfs->os_bfree = sfs->f_bfree;
65 osfs->os_bavail = sfs->f_bavail;
66 osfs->os_files = sfs->f_files;
67 osfs->os_ffree = sfs->f_ffree;
68 osfs->os_bsize = sfs->f_bsize;
69 osfs->os_namelen = sfs->f_namelen;
72 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs)
74 sfs->f_type = osfs->os_type;
75 sfs->f_blocks = osfs->os_blocks;
76 sfs->f_bfree = osfs->os_bfree;
77 sfs->f_bavail = osfs->os_bavail;
78 sfs->f_files = osfs->os_files;
79 sfs->f_ffree = osfs->os_ffree;
80 sfs->f_bsize = osfs->os_bsize;
81 sfs->f_namelen = osfs->os_namelen;
84 int obd_self_statfs(struct obd_device *obd, struct statfs *sfs)
86 struct lustre_handle conn;
87 struct obd_export *export, *my_export = NULL;
88 struct obd_statfs osfs = { 0 };
92 if (list_empty(&obd->obd_exports)) {
93 export = my_export = class_new_export(obd);
97 export = list_entry(obd->obd_exports.next, typeof(*export),
99 conn.addr = (unsigned long)export;
100 conn.cookie = export->exp_cookie;
102 rc = obd_statfs(&conn, &osfs);
104 statfs_unpack(sfs, &osfs);
107 class_destroy_export(my_export);
111 EXPORT_SYMBOL(obd_statfs_pack);
112 EXPORT_SYMBOL(obd_statfs_unpack);
113 EXPORT_SYMBOL(statfs_pack);
114 EXPORT_SYMBOL(statfs_unpack);
115 EXPORT_SYMBOL(obd_self_statfs);