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 int _9p_write( _9p_request_data_t * preq9p, 00054 void * pworker_data, 00055 u32 * plenout, 00056 char * preply) 00057 { 00058 char * cursor = preq9p->_9pmsg + _9P_HDR_SIZE + _9P_TYPE_SIZE ; 00059 00060 u16 * msgtag = NULL ; 00061 u32 * fid = NULL ; 00062 u64 * offset = NULL ; 00063 u32 * count = NULL ; 00064 00065 u32 outcount = 0 ; 00066 00067 _9p_fid_t * pfid = NULL ; 00068 00069 fsal_size_t size; 00070 fsal_size_t written_size = 0; 00071 fsal_boolean_t eof_met; 00072 cache_inode_status_t cache_status = CACHE_INODE_SUCCESS; 00073 //uint64_t stable_flag = CACHE_INODE_SAFE_WRITE_TO_FS; 00074 uint64_t stable_flag = CACHE_INODE_UNSAFE_WRITE_TO_FS_BUFFER; 00075 00076 caddr_t databuffer = NULL ; 00077 00078 fsal_status_t fsal_status ; 00079 char xattrval[XATTR_BUFFERSIZE] ; 00080 00081 /* Get data */ 00082 _9p_getptr( cursor, msgtag, u16 ) ; 00083 _9p_getptr( cursor, fid, u32 ) ; 00084 _9p_getptr( cursor, offset, u64 ) ; 00085 _9p_getptr( cursor, count, u32 ) ; 00086 00087 databuffer = cursor ; 00088 00089 LogDebug( COMPONENT_9P, "TWRITE: tag=%u fid=%u offset=%llu count=%u", 00090 (u32)*msgtag, *fid, (unsigned long long)*offset, *count ) ; 00091 00092 if( *fid >= _9P_FID_PER_CONN ) 00093 return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ; 00094 00095 pfid = &preq9p->pconn->fids[*fid] ; 00096 00097 /* Do the job */ 00098 size = *count ; 00099 00100 if( pfid->specdata.xattr.xattr_content != NULL ) 00101 { 00102 snprintf( xattrval, XATTR_BUFFERSIZE, "%.*s", *count, databuffer ) ; 00103 00104 _9p_chomp_attr_value( xattrval, strlen( xattrval ) ) ; 00105 00106 fsal_status = FSAL_SetXAttrValueById( &pfid->pentry->handle, 00107 pfid->specdata.xattr.xattr_id, 00108 &pfid->fsal_op_context, 00109 xattrval, 00110 size+1 ) ; 00111 if(FSAL_IS_ERROR(fsal_status)) 00112 return _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_inode_error_convert(fsal_status) ), plenout, preply ) ; 00113 00114 /* Cache the value */ 00115 memcpy( pfid->specdata.xattr.xattr_content, xattrval, size ) ; 00116 00117 outcount = *count ; 00118 } 00119 else 00120 { 00121 if(cache_inode_rdwr( pfid->pentry, 00122 CACHE_INODE_WRITE, 00123 *offset, 00124 size, 00125 &written_size, 00126 databuffer, 00127 &eof_met, 00128 &pfid->fsal_op_context, 00129 stable_flag, 00130 &cache_status ) != CACHE_INODE_SUCCESS ) 00131 return _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_status), plenout, preply ) ; 00132 00133 outcount = (u32)written_size ; 00134 } 00135 00136 /* Build the reply */ 00137 _9p_setinitptr( cursor, preply, _9P_RWRITE ) ; 00138 _9p_setptr( cursor, msgtag, u16 ) ; 00139 00140 _9p_setvalue( cursor, outcount, u32 ) ; 00141 00142 _9p_setendptr( cursor, preply ) ; 00143 _9p_checkbound( cursor, preply, plenout ) ; 00144 00145 LogDebug( COMPONENT_9P, "RWRITE: tag=%u fid=%u offset=%llu input count=%u output count=%u", 00146 (u32)*msgtag, *fid , (unsigned long long)*offset, *count, outcount ) ; 00147 00148 return 1 ; 00149 } 00150