nfs-ganesha 1.4

9p_xattrcreate.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 <sys/types.h>
00048 #include <attr/xattr.h>
00049 #include "nfs_core.h"
00050 #include "log.h"
00051 #include "cache_inode.h"
00052 #include "fsal.h"
00053 #include "9p.h"
00054 
00055 
00056 int _9p_xattrcreate( _9p_request_data_t * preq9p, 
00057                      void  * pworker_data,
00058                      u32 * plenout, 
00059                      char * preply)
00060 {
00061   char * cursor = preq9p->_9pmsg + _9P_HDR_SIZE + _9P_TYPE_SIZE ;
00062 
00063   u16 * msgtag = NULL ;
00064   u32 * fid    = NULL ;
00065   u64 * size ;
00066   u32 * flag ;
00067   u16 * name_len ;
00068   char * name_str ;
00069 
00070   _9p_fid_t * pfid = NULL ;
00071 
00072   fsal_status_t fsal_status ; 
00073   fsal_name_t name;
00074 
00075   if ( !preq9p || !pworker_data || !plenout || !preply )
00076    return -1 ;
00077 
00078   /* Get data */
00079   _9p_getptr( cursor, msgtag, u16 ) ; 
00080   _9p_getptr( cursor, fid,    u32 ) ; 
00081   _9p_getstr( cursor, name_len, name_str ) ;
00082   _9p_getptr( cursor, size,   u64 ) ; 
00083   _9p_getptr( cursor, flag,   u32 ) ; 
00084 
00085   LogDebug( COMPONENT_9P, "TXATTRCREATE: tag=%u fid=%u name=%.*s size=%llu flag=%u",
00086             (u32)*msgtag, *fid, *name_len, name_str, (unsigned long long)*size, *flag ) ;
00087 
00088   if( *fid >= _9P_FID_PER_CONN )
00089     return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ;
00090 
00091   pfid = &preq9p->pconn->fids[*fid] ;
00092   
00093   snprintf( name.name, FSAL_MAX_NAME_LEN, "%.*s", *name_len, name_str ) ;
00094   name.len = *name_len + 1 ;
00095 
00096   if( *size == 0LL ) 
00097    {
00098      /* Size == 0 : this is in fact a call to removexattr */
00099       LogDebug( COMPONENT_9P, "TXATTRCREATE: tag=%u fid=%u : will remove xattr %s",
00100                  (u32)*msgtag, *fid,  name.name ) ;
00101     
00102      fsal_status = FSAL_RemoveXAttrByName( &pfid->pentry->handle,
00103                                            &pfid->fsal_op_context,
00104                                            &name ) ;
00105 
00106      if(FSAL_IS_ERROR(fsal_status))
00107        return  _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_inode_error_convert(fsal_status) ),  plenout, preply ) ;
00108    }
00109   else
00110    {
00111      /* Size != 0 , this is a creation/replacement of xattr */
00112 
00113      /* Create the xattr at the FSAL level and cache result */
00114      if( ( pfid->specdata.xattr.xattr_content = gsh_malloc( XATTR_BUFFERSIZE ) ) == NULL ) 
00115        return _9p_rerror( preq9p, msgtag, ENOMEM, plenout, preply ) ;
00116 
00117      fsal_status = FSAL_SetXAttrValue( &pfid->pentry->handle,
00118                                        &name,
00119                                        &pfid->fsal_op_context,
00120                                        pfid->specdata.xattr.xattr_content, 
00121                                        *size, 
00122                                         (*flag == XATTR_REPLACE) ? FALSE : TRUE ) ;
00123 
00124      if(FSAL_IS_ERROR(fsal_status))
00125        return  _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_inode_error_convert(fsal_status) ),  plenout, preply ) ;
00126 
00127      fsal_status = FSAL_GetXAttrIdByName( &pfid->pentry->handle,
00128                                           &name, 
00129                                           &pfid->fsal_op_context,
00130                                           &pfid->specdata.xattr.xattr_id);
00131       if(FSAL_IS_ERROR(fsal_status))
00132        return  _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_inode_error_convert(fsal_status) ),  plenout, preply ) ;
00133    }
00134 
00135   /* Build the reply */
00136   _9p_setinitptr( cursor, preply, _9P_RXATTRCREATE ) ;
00137   _9p_setptr( cursor, msgtag, u16 ) ;
00138 
00139   _9p_setendptr( cursor, preply ) ;
00140   _9p_checkbound( cursor, preply, plenout ) ;
00141 
00142   LogDebug( COMPONENT_9P, "RXATTRCREATE: tag=%u fid=%u name=%.*s size=%llu flag=%u",
00143             (u32)*msgtag, *fid, *name_len, name_str, (unsigned long long)*size, *flag ) ;
00144 
00145   return 1 ;
00146 } /* _9p_xattrcreate */
00147