nfs-ganesha 1.4

nfs4_op_remove.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2008)
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 
00037 #ifdef HAVE_CONFIG_H
00038 #include "config.h"
00039 #endif
00040 
00041 #ifdef _SOLARIS
00042 #include "solaris_port.h"
00043 #endif
00044 
00045 #include <stdio.h>
00046 #include <string.h>
00047 #include <pthread.h>
00048 #include <fcntl.h>
00049 #include <sys/file.h>           /* for having FNDELAY */
00050 #include "HashData.h"
00051 #include "HashTable.h"
00052 #include "log.h"
00053 #include "ganesha_rpc.h"
00054 #include "nfs4.h"
00055 #include "nfs_core.h"
00056 #include "sal_functions.h"
00057 #include "nfs_proto_functions.h"
00058 #include "nfs_proto_tools.h"
00059 #include "nfs_tools.h"
00060 #include "nfs_file_handle.h"
00061 #include "sal_functions.h"
00062 
00076 #define arg_REMOVE4 op->nfs_argop4_u.opremove
00077 #define res_REMOVE4 resp->nfs_resop4_u.opremove
00078 
00079 int nfs4_op_remove(struct nfs_argop4 *op, compound_data_t * data, struct nfs_resop4 *resp)
00080 {
00081   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_remove";
00082 
00083   cache_entry_t        * parent_entry = NULL;
00084   fsal_attrib_list_t     attr_parent;
00085   fsal_name_t            name;
00086   cache_inode_status_t   cache_status;
00087 
00088   resp->resop = NFS4_OP_REMOVE;
00089   res_REMOVE4.status = NFS4_OK;
00090 
00091   /*
00092    * Do basic checks on a filehandle
00093    * Delete arg_REMOVE4.target in directory pointed by currentFH
00094    * Make sure the currentFH is pointed a directory
00095    */
00096   res_REMOVE4.status = nfs4_sanity_check_FH(data, DIRECTORY);
00097   if(res_REMOVE4.status != NFS4_OK)
00098     return res_REMOVE4.status;
00099 
00100   /* Pseudo Fs is explictely a Read-Only File system */
00101   if(nfs4_Is_Fh_Pseudo(&(data->currentFH)))
00102     {
00103       res_REMOVE4.status = NFS4ERR_ROFS;
00104       return res_REMOVE4.status;
00105     }
00106 
00107   if (nfs_in_grace())
00108     {
00109       res_REMOVE4.status = NFS4ERR_GRACE;
00110       return res_REMOVE4.status;
00111     }
00112 
00113   /* If Filehandle points to a xattr object, manage it via the xattrs specific functions */
00114   if(nfs4_Is_Fh_Xattr(&(data->currentFH)))
00115     return nfs4_op_remove_xattr(op, data, resp);
00116 
00117   /* Get the parent entry (aka the current one in the compound data) */
00118   parent_entry = data->current_entry;
00119 
00120   /* We have to keep track of the 'change' file attribute for reply structure */
00121   memset(&(res_REMOVE4.REMOVE4res_u.resok4.cinfo.before), 0, sizeof(changeid4));
00122   res_REMOVE4.REMOVE4res_u.resok4.cinfo.before =
00123        cache_inode_get_changeid4(parent_entry);
00124 
00125   /* Check for name length */
00126   if(arg_REMOVE4.target.utf8string_len > FSAL_MAX_NAME_LEN)
00127     {
00128       res_REMOVE4.status = NFS4ERR_NAMETOOLONG;
00129       return res_REMOVE4.status;
00130     }
00131 
00132   /* get the filename from the argument, it should not be empty */
00133   if(arg_REMOVE4.target.utf8string_len == 0)
00134     {
00135       res_REMOVE4.status = NFS4ERR_INVAL;
00136       return res_REMOVE4.status;
00137     }
00138 
00139   /* NFS4_OP_REMOVE can delete files as well as directory, it replaces NFS3_RMDIR and NFS3_REMOVE
00140    * because of this, we have to know if object is a directory or not */
00141   if((cache_status =
00142       cache_inode_error_convert(FSAL_buffdesc2name
00143                                 ((fsal_buffdesc_t *) & arg_REMOVE4.target,
00144                                  &name))) != CACHE_INODE_SUCCESS)
00145     {
00146       res_REMOVE4.status = nfs4_Errno(cache_status);
00147       return res_REMOVE4.status;
00148     }
00149 
00150   /* Test RM7: remiving '.' should return NFS4ERR_BADNAME */
00151   if(!FSAL_namecmp(&name, (fsal_name_t *) & FSAL_DOT)
00152      || !FSAL_namecmp(&name, (fsal_name_t *) & FSAL_DOT_DOT))
00153     {
00154       res_REMOVE4.status = NFS4ERR_BADNAME;
00155       return res_REMOVE4.status;
00156     }
00157 
00158   if((cache_status = cache_inode_remove(parent_entry,
00159                                         &name,
00160                                         &attr_parent,
00161                                         data->pcontext,
00162                                         &cache_status)) != CACHE_INODE_SUCCESS)
00163     {
00164       res_REMOVE4.status = nfs4_Errno(cache_status);
00165       return res_REMOVE4.status;
00166     }
00167 
00168   res_REMOVE4.REMOVE4res_u.resok4.cinfo.after
00169        = cache_inode_get_changeid4(parent_entry);
00170 
00171   /* Operation was not atomic .... */
00172   res_REMOVE4.REMOVE4res_u.resok4.cinfo.atomic = FALSE;
00173 
00174   /* If you reach this point, everything was ok */
00175 
00176   res_REMOVE4.status = NFS4_OK;
00177 
00178   return NFS4_OK;
00179 }                               /* nfs4_op_remove */
00180 
00191 void nfs4_op_remove_Free(REMOVE4res * resp)
00192 {
00193   /* Nothing to be done */
00194   return;
00195 }                               /* nfs4_op_remove_Free */