nfs-ganesha 1.4

9p_lcreate.c

Go to the documentation of this file.
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_lcreate( _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   u32  * flags  = NULL ;
00063   u32  * mode   = NULL ;
00064   u32  * gid    = NULL ;
00065   u16  * name_len = NULL ;
00066   char * name_str = NULL ;
00067 
00068   _9p_fid_t * pfid = NULL ;
00069   _9p_qid_t qid_newfile ;
00070   u32 iounit = 0 ;
00071 
00072   cache_entry_t       * pentry_newfile = NULL ;
00073   fsal_name_t           file_name ; 
00074   fsal_attrib_list_t    fsalattr ;
00075   cache_inode_status_t  cache_status ;
00076   fsal_openflags_t      openflags = 0 ;
00077 
00078   if ( !preq9p || !pworker_data || !plenout || !preply )
00079    return -1 ;
00080   /* Get data */
00081   _9p_getptr( cursor, msgtag, u16 ) ; 
00082 
00083   _9p_getptr( cursor, fid,    u32 ) ; 
00084   _9p_getstr( cursor, name_len, name_str ) ;
00085   _9p_getptr( cursor, flags,  u32 ) ;
00086   _9p_getptr( cursor, mode,   u32 ) ;
00087   _9p_getptr( cursor, gid,    u32 ) ;
00088 
00089   LogDebug( COMPONENT_9P, "TLCREATE: tag=%u fid=%u name=%.*s flags=0%o mode=0%o gid=%u",
00090             (u32)*msgtag, *fid, *name_len, name_str, *flags, *mode, *gid ) ;
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    snprintf( file_name.name, FSAL_MAX_NAME_LEN, "%.*s", *name_len, name_str ) ;
00098    file_name.len = *name_len+1 ;
00099 
00100    /* Create the file */
00101 
00102    /* BUGAZOMEU: @todo : the gid parameter is not used yet, flags is not yet used */
00103    if( ( pentry_newfile = cache_inode_create( pfid->pentry,
00104                                               &file_name,
00105                                               REGULAR_FILE,
00106                                               *mode,
00107                                               NULL,
00108                                               &fsalattr,
00109                                               &pfid->fsal_op_context, 
00110                                               &cache_status)) == NULL)
00111      return  _9p_rerror( preq9p, msgtag,  _9p_tools_errno( cache_status ) , plenout, preply ) ;
00112       
00113    _9p_openflags2FSAL( flags, &openflags ) ; 
00114 
00115    if(cache_inode_open( pentry_newfile, 
00116                         openflags, 
00117                         &pfid->fsal_op_context,
00118                         0, 
00119                         &cache_status) != CACHE_INODE_SUCCESS) 
00120      return _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_status ), plenout, preply ) ;
00121 
00122    /* Build the qid */
00123    qid_newfile.type    = _9P_QTFILE ;
00124    qid_newfile.version = 0 ;
00125    qid_newfile.path    = fsalattr.fileid ;
00126 
00127    iounit = 0 ; /* default value */
00128 
00129    /* The fid will represent the new file now */
00130    pfid->pentry = pentry_newfile ;
00131    pfid->qid = qid_newfile ;
00132    pfid->specdata.xattr.xattr_id = 0 ;
00133    pfid->specdata.xattr.xattr_content = NULL ;
00134 
00135 
00136    /* Build the reply */
00137   _9p_setinitptr( cursor, preply, _9P_RLCREATE ) ;
00138   _9p_setptr( cursor, msgtag, u16 ) ;
00139 
00140   _9p_setqid( cursor, qid_newfile ) ;
00141   _9p_setvalue( cursor, iounit, u32 ) ;
00142 
00143   _9p_setendptr( cursor, preply ) ;
00144   _9p_checkbound( cursor, preply, plenout ) ;
00145 
00146   LogDebug( COMPONENT_9P, 
00147             "RLCREATE: tag=%u fid=%u name=%.*s qid=(type=%u,version=%u,path=%llu) iounit=%u",
00148             (u32)*msgtag, *fid, *name_len, name_str, qid_newfile.type, qid_newfile.version, (unsigned long long)qid_newfile.path, iounit ) ;
00149 
00150   return 1 ;
00151 }
00152