Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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 #ifndef __KERNEL__
30 #include <liblustre.h>
31 #else
32 #include <linux/version.h>
33 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
34 #include <asm/statfs.h>
35 #endif
36 #endif
37
38 #include <linux/lustre_export.h>
39 #include <linux/lustre_net.h>
40 #include <linux/obd_support.h>
41 #include <linux/obd_class.h>
42
43 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs)
44 {
45         osfs->os_type = sfs->f_type;
46         osfs->os_blocks = sfs->f_blocks;
47         osfs->os_bfree = sfs->f_bfree;
48         osfs->os_bavail = sfs->f_bavail;
49         osfs->os_files = sfs->f_files;
50         osfs->os_ffree = sfs->f_ffree;
51         osfs->os_bsize = sfs->f_bsize;
52         osfs->os_namelen = sfs->f_namelen;
53 }
54
55 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs)
56 {
57         sfs->f_type = osfs->os_type;
58         sfs->f_blocks = osfs->os_blocks;
59         sfs->f_bfree = osfs->os_bfree;
60         sfs->f_bavail = osfs->os_bavail;
61         sfs->f_files = osfs->os_files;
62         sfs->f_ffree = osfs->os_ffree;
63         sfs->f_bsize = osfs->os_bsize;
64         sfs->f_namelen = osfs->os_namelen;
65 }
66
67 int obd_self_statfs(struct obd_device *obd, struct statfs *sfs)
68 {
69         struct lustre_handle conn;
70         struct obd_export *export, *my_export = NULL;
71         struct obd_statfs osfs = { 0 };
72         int rc;
73         ENTRY;
74
75         LASSERT( obd != NULL );
76
77         spin_lock(&obd->obd_dev_lock);
78         if (list_empty(&obd->obd_exports)) {
79                 spin_unlock(&obd->obd_dev_lock);
80                 export = my_export = class_new_export(obd);
81                 if (export == NULL)
82                         RETURN(-ENOMEM);
83         } else {
84                 export = list_entry(obd->obd_exports.next, typeof(*export),
85                                     exp_obd_chain);
86                 export = class_export_get(export);
87                 spin_unlock(&obd->obd_dev_lock);
88         }
89         conn.cookie = export->exp_handle.h_cookie;
90
91         rc = obd_statfs(&conn, &osfs);
92         if (!rc)
93                 statfs_unpack(sfs, &osfs);
94
95         if (my_export)
96                 class_unlink_export(my_export);
97
98         class_export_put(export);
99         RETURN(rc);
100 }
101
102 EXPORT_SYMBOL(statfs_pack);
103 EXPORT_SYMBOL(statfs_unpack);
104 EXPORT_SYMBOL(obd_self_statfs);