nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright CEA/DAM/DIF (2011) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 */ 00025 00035 #ifdef HAVE_CONFIG_H 00036 #include "config.h" 00037 #endif 00038 00039 #ifdef _SOLARIS 00040 #include "solaris_port.h" 00041 #endif 00042 00043 #include <stdio.h> 00044 #include <string.h> 00045 #include <pthread.h> 00046 #include <sys/stat.h> 00047 #include "nfs_core.h" 00048 #include "log.h" 00049 #include "cache_inode.h" 00050 #include "fsal.h" 00051 #include "9p.h" 00052 00053 00054 00055 int _9p_statfs( _9p_request_data_t * preq9p, 00056 void * pworker_data, 00057 u32 * plenout, 00058 char * preply) 00059 { 00060 char * cursor = preq9p->_9pmsg + _9P_HDR_SIZE + _9P_TYPE_SIZE ; 00061 00062 u16 * msgtag = NULL ; 00063 u32 * fid = NULL ; 00064 00065 _9p_fid_t * pfid = NULL ; 00066 00067 u32 type = 0x6969 ; /* NFS_SUPER_MAGIC for wanting of better, FSAL do not return this information */ 00068 u32 bsize = 1 ; // cache_inode_statfs and FSAL already care for blocksize 00069 u64 * blocks = NULL ; 00070 u64 * bfree = NULL ; 00071 u64 * bavail = NULL ; 00072 u64 * files = NULL ; 00073 u64 * ffree = NULL ; 00074 u64 fsid = 0LL ; 00075 00076 u32 namelen = MAXNAMLEN ; 00077 00078 fsal_dynamicfsinfo_t dynamicinfo; 00079 cache_inode_status_t cache_status; 00080 00081 if ( !preq9p || !pworker_data || !plenout || !preply ) 00082 return -1 ; 00083 /* Get data */ 00084 _9p_getptr( cursor, msgtag, u16 ) ; 00085 _9p_getptr( cursor, fid, u32 ) ; 00086 00087 LogDebug( COMPONENT_9P, "TSTATFS: tag=%u fid=%u", 00088 (u32)*msgtag, *fid ) ; 00089 00090 if( *fid >= _9P_FID_PER_CONN ) 00091 return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ; 00092 00093 pfid = &preq9p->pconn->fids[*fid] ; 00094 00095 /* Get the FS's stats */ 00096 if( cache_inode_statfs( pfid->pentry, 00097 &dynamicinfo, 00098 &pfid->fsal_op_context, 00099 &cache_status ) != CACHE_INODE_SUCCESS ) 00100 return _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_status ), plenout, preply ) ; 00101 00102 blocks = (u64 *)&dynamicinfo.total_bytes ; 00103 bfree = (u64 *)&dynamicinfo.free_bytes ; 00104 bavail = (u64 *)&dynamicinfo.avail_bytes ; 00105 files = (u64 *)&dynamicinfo.total_files ; 00106 ffree = (u64 *)&dynamicinfo.free_files ; 00107 fsid = (u64 )pfid->pentry->attributes.rawdev.major ; 00108 00109 /* Build the reply */ 00110 _9p_setinitptr( cursor, preply, _9P_RSTATFS ) ; 00111 _9p_setptr( cursor, msgtag, u16 ) ; 00112 00113 _9p_setvalue( cursor, type, u32 ) ; 00114 _9p_setvalue( cursor, bsize, u32 ) ; 00115 _9p_setptr( cursor, blocks, u64 ) ; 00116 _9p_setptr( cursor, bfree, u64 ) ; 00117 _9p_setptr( cursor, bavail, u64 ) ; 00118 _9p_setptr( cursor, files, u64 ) ; 00119 _9p_setptr( cursor, ffree, u64 ) ; 00120 _9p_setvalue( cursor, fsid, u64 ) ; 00121 _9p_setvalue( cursor, namelen, u32 ) ; 00122 00123 _9p_setendptr( cursor, preply ) ; 00124 _9p_checkbound( cursor, preply, plenout ) ; 00125 00126 LogDebug( COMPONENT_9P, "RSTATFS: tag=%u fid=%u", 00127 (u32)*msgtag, *fid ) ; 00128 00129 return 1 ; 00130 } 00131