nfs-ganesha 1.4

fsal_rename.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2010 The Linux Box, Inc.
00005  * Contributor : Adam C. Emerson <aemerson@linuxbox.com>
00006  *
00007  * Portions copyright CEA/DAM/DIF  (2008)
00008  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00009  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00010  *
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 3 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00025  *
00026  * ------------- 
00027  */
00028 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include "fsal.h"
00040 #include "fsal_internal.h"
00041 #include "fsal_convert.h"
00042 
00084 fsal_status_t CEPHFSAL_rename(fsal_handle_t * extold_parent,
00085                               fsal_name_t * old_name,
00086                               fsal_handle_t * extnew_parent,
00087                               fsal_name_t * new_name,
00088                               fsal_op_context_t * extcontext,
00089                               fsal_attrib_list_t * src_dir_attributes,
00090                               fsal_attrib_list_t * tgt_dir_attributes)
00091 {
00092   int rc;
00093   cephfsal_handle_t* old_parent = (cephfsal_handle_t*) extold_parent;
00094   cephfsal_handle_t* new_parent = (cephfsal_handle_t*) extnew_parent;
00095   cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext;
00096   char oldstr[FSAL_MAX_NAME_LEN];
00097   char newstr[FSAL_MAX_NAME_LEN];
00098   int uid = FSAL_OP_CONTEXT_TO_UID(context);
00099   int gid = FSAL_OP_CONTEXT_TO_GID(context);
00100 
00101   /* sanity checks.
00102    * note : src/tgt_dir_attributes are optional.
00103    */
00104   if(!old_parent || !new_parent || !old_name || !new_name || !context)
00105     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_rename);
00106 
00107   if(src_dir_attributes)
00108     {
00109       fsal_status_t status =
00110         CEPHFSAL_getattrs(extold_parent, extcontext, src_dir_attributes);
00111 
00112       if(FSAL_IS_ERROR(status))
00113         {
00114           FSAL_CLEAR_MASK(src_dir_attributes->asked_attributes);
00115           FSAL_SET_MASK(src_dir_attributes->asked_attributes,
00116                         FSAL_ATTR_RDATTR_ERR);
00117         }
00118     }
00119 
00120   if(tgt_dir_attributes)
00121     {
00122       fsal_status_t status;
00123 
00124       /* optimization when src=tgt : */
00125 
00126       if(!CEPHFSAL_handlecmp(extold_parent, extnew_parent, &status)
00127          && src_dir_attributes)
00128         {
00129           /* If source dir = target dir, we just copy the attributes.
00130            * to avoid doing another getattr.
00131            */
00132           (*tgt_dir_attributes) = (*src_dir_attributes);
00133         }
00134       else
00135         {
00136           status = CEPHFSAL_getattrs(extnew_parent, extcontext,
00137                                      tgt_dir_attributes);
00138 
00139           if(FSAL_IS_ERROR(status))
00140             {
00141               FSAL_CLEAR_MASK(tgt_dir_attributes->asked_attributes);
00142               FSAL_SET_MASK(tgt_dir_attributes->asked_attributes,
00143                             FSAL_ATTR_RDATTR_ERR);
00144             }
00145         }
00146     }
00147 
00148   FSAL_name2str(old_name, oldstr, FSAL_MAX_NAME_LEN);
00149   FSAL_name2str(new_name, newstr, FSAL_MAX_NAME_LEN);
00150   rc = ceph_ll_rename(context->export_context->cmount,
00151                       VINODE(old_parent), oldstr,
00152                       VINODE(new_parent), newstr,
00153                       uid, gid);
00154 
00155   if (rc < 0)
00156     Return(posix2fsal_error(rc), 0, INDEX_FSAL_rename);
00157 
00158   /* OK */
00159   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_rename);
00160 }