Whamcloud - gitweb
Merge b_md into HEAD
[fs/lustre-release.git] / lustre / obdclass / statfs_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, 2003 Cluster File Systems, Inc.
5  *   Author: Andreas Dilger <adilger@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
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.
12  *
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.
17  *
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.
21  *
22  * (Un)packing of OST/MDS requests
23  *
24  */
25
26 #define DEBUG_SUBSYSTEM S_CLASS
27
28 #define EXPORT_SYMTAB
29 #include <linux/lustre_net.h>
30 #include <linux/obd_support.h>
31 #include <linux/obd_class.h>
32
33 void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src)
34 {
35         tgt->os_type = HTON__u64(src->os_type);
36         tgt->os_blocks = HTON__u64(src->os_blocks);
37         tgt->os_bfree = HTON__u64(src->os_bfree);
38         tgt->os_bavail = HTON__u64(src->os_bavail);
39         tgt->os_files = HTON__u64(src->os_files);
40         tgt->os_ffree = HTON__u64(src->os_ffree);
41         tgt->os_bsize = HTON__u32(src->os_bsize);
42         tgt->os_namelen = HTON__u32(src->os_namelen);
43 }
44
45 void obd_statfs_unpack(struct obd_statfs *tgt, struct obd_statfs *src)
46 {
47         obd_statfs_pack(tgt, src);
48 }
49
50 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs)
51 {
52         osfs->os_type = sfs->f_type;
53         osfs->os_blocks = sfs->f_blocks;
54         osfs->os_bfree = sfs->f_bfree;
55         osfs->os_bavail = sfs->f_bavail;
56         osfs->os_files = sfs->f_files;
57         osfs->os_ffree = sfs->f_ffree;
58         osfs->os_bsize = sfs->f_bsize;
59         osfs->os_namelen = sfs->f_namelen;
60 }
61
62 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs)
63 {
64         sfs->f_type = osfs->os_type;
65         sfs->f_blocks = osfs->os_blocks;
66         sfs->f_bfree = osfs->os_bfree;
67         sfs->f_bavail = osfs->os_bavail;
68         sfs->f_files = osfs->os_files;
69         sfs->f_ffree = osfs->os_ffree;
70         sfs->f_bsize = osfs->os_bsize;
71         sfs->f_namelen = osfs->os_namelen;
72 }
73
74 int obd_self_statfs(struct obd_device *obd, struct statfs *sfs)
75 {
76         struct lustre_handle conn;
77         struct obd_export *export, *my_export = NULL;
78         struct obd_statfs osfs = { 0 };
79         int rc;
80         ENTRY;
81
82         if (list_empty(&obd->obd_exports)) {
83                 export = my_export = class_new_export(obd);
84                 if (export == NULL)
85                         RETURN(-ENOMEM);
86         } else
87                 export = list_entry(obd->obd_exports.next, typeof(*export),
88                                     exp_obd_chain);
89         conn.addr = (unsigned long)export;
90         conn.cookie = export->exp_cookie;
91
92         rc = obd_statfs(&conn, &osfs);
93         if (!rc)
94                 statfs_unpack(sfs, &osfs);
95
96         if (my_export)
97                 class_destroy_export(my_export);
98         RETURN(rc);
99 }
100
101 EXPORT_SYMBOL(obd_statfs_pack);
102 EXPORT_SYMBOL(obd_statfs_unpack);
103 EXPORT_SYMBOL(statfs_pack);
104 EXPORT_SYMBOL(statfs_unpack);
105 EXPORT_SYMBOL(obd_self_statfs);