nfs-ganesha 1.4

fsal_create.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #include "fsal.h"
00019 #include "fsal_internal.h"
00020 #include "fsal_convert.h"
00021 #include "fsal_common.h"
00022 
00059 fsal_status_t ZFSFSAL_create(fsal_handle_t * parent_hdl,      /* IN */
00060                              fsal_name_t * p_filename,     /* IN */
00061                              fsal_op_context_t *context,        /* IN */
00062                              fsal_accessmode_t accessmode, /* IN */
00063                              fsal_handle_t * obj_handle,        /* OUT */
00064                              fsal_attrib_list_t * object_attributes        /* [ IN/OUT ] */
00065     )
00066 {
00067 
00068   int rc;
00069   creden_t cred;
00070   zfsfsal_handle_t * parent_directory_handle = (zfsfsal_handle_t *)parent_hdl;
00071   zfsfsal_op_context_t * p_context = (zfsfsal_op_context_t * )context;
00072   zfsfsal_handle_t * object_handle = (zfsfsal_handle_t *)obj_handle;
00073 
00074   /* sanity checks.
00075    * note : object_attributes is optional.
00076    */
00077   if(!parent_directory_handle || !p_context || !object_handle || !p_filename)
00078     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_create);
00079 
00080   /* Hook to prevent creating objects in a snapashot */
00081   if(parent_directory_handle->data.i_snap != 0)
00082   {
00083     LogDebug(COMPONENT_FSAL, "Trying to create a file inside a snapshot");
00084     Return(ERR_FSAL_ROFS, 0, INDEX_FSAL_create);
00085   }
00086   cred.uid = p_context->credential.user;
00087   cred.gid = p_context->credential.group;
00088 
00089   TakeTokenFSCall();
00090 
00091   inogen_t object;
00092   rc = libzfswrap_create(p_context->export_context->p_vfs, &cred,
00093                          parent_directory_handle->data.zfs_handle, p_filename->name,
00094                          fsal2unix_mode(accessmode), &object);
00095 
00096   ReleaseTokenFSCall();
00097 
00098   /* >> interpret returned error << */
00099   if(rc)
00100     Return(posix2fsal_error(rc), 0, INDEX_FSAL_create);
00101 
00102   /* >> set output handle << */
00103   object_handle->data.zfs_handle = object;
00104   object_handle->data.type = FSAL_TYPE_FILE;
00105   object_handle->data.i_snap = 0;
00106 
00107   if(object_attributes)
00108     {
00109       fsal_status_t status = ZFSFSAL_getattrs(obj_handle, context, object_attributes);
00110 
00111       /* on error, we set a special bit in the mask. */
00112       if(FSAL_IS_ERROR(status))
00113         {
00114           FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00115           FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00116         }
00117     }
00118 
00119   /* OK */
00120   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_create);
00121 
00122 }
00123 
00161 fsal_status_t ZFSFSAL_mkdir(fsal_handle_t * parent_hdl,       /* IN */
00162                             fsal_name_t * p_dirname,       /* IN */
00163                             fsal_op_context_t *context, /* IN */
00164                             fsal_accessmode_t accessmode,  /* IN */
00165                             fsal_handle_t * obj_handle, /* OUT */
00166                             fsal_attrib_list_t * object_attributes /* [ IN/OUT ] */
00167     )
00168 {
00169 
00170   int rc;
00171   mode_t unix_mode;
00172   creden_t cred;
00173   zfsfsal_handle_t * parent_directory_handle = (zfsfsal_handle_t *)parent_hdl;
00174   zfsfsal_op_context_t * p_context = (zfsfsal_op_context_t *)context;
00175   zfsfsal_handle_t * object_handle = (zfsfsal_handle_t *)obj_handle;
00176 
00177   /* sanity checks.
00178    * note : object_attributes is optional.
00179    */
00180   if(!parent_directory_handle || !p_context || !object_handle || !p_dirname)
00181     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_mkdir);
00182 
00183   /* Hook to prevent creating objects in a snapashot */
00184   if(parent_directory_handle->data.i_snap != 0)
00185   {
00186     LogDebug(COMPONENT_FSAL, "Trying to create a directory inside a snapshot");
00187     Return(ERR_FSAL_ROFS, 0, INDEX_FSAL_mkdir);
00188   }
00189 
00190   /* convert fsal args to ZFS args */
00191   unix_mode = fsal2unix_mode(accessmode);
00192 
00193 
00194   /* Applying FSAL umask */
00195   unix_mode = unix_mode & ~global_fs_info.umask;
00196   cred.uid = p_context->credential.user;
00197   cred.gid = p_context->credential.group;
00198 
00199   TakeTokenFSCall();
00200 
00201   /* Create the directory */
00202   inogen_t object;
00203   rc = libzfswrap_mkdir(p_context->export_context->p_vfs, &cred,
00204                         parent_directory_handle->data.zfs_handle, p_dirname->name, unix_mode, &object);
00205 
00206   ReleaseTokenFSCall();
00207 
00208   /* >> interpret returned error << */
00209   if(rc)
00210     Return(posix2fsal_error(rc), 0, INDEX_FSAL_mkdir);
00211 
00212   /* set output handle */
00213   object_handle->data.zfs_handle = object;
00214   object_handle->data.type = FSAL_TYPE_DIR;
00215   object_handle->data.i_snap = 0;
00216 
00217   if(object_attributes)
00218     {
00220       fsal_status_t status = ZFSFSAL_getattrs(obj_handle, context, object_attributes);
00221 
00222       /* on error, we set a special bit in the mask. */
00223       if(FSAL_IS_ERROR(status))
00224         {
00225           FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00226           FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00227         }
00228 
00229     }
00230 
00231   /* OK */
00232   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_mkdir);
00233 
00234 }
00235 
00273 fsal_status_t ZFSFSAL_link(fsal_handle_t * target_hdl,  /* IN */
00274                            fsal_handle_t * dir_hdl,     /* IN */
00275                            fsal_name_t * p_link_name,      /* IN */
00276                            fsal_op_context_t * context,  /* IN */
00277                            fsal_attrib_list_t * attributes /* [ IN/OUT ] */
00278     )
00279 {
00280 
00281   int rc;
00282   creden_t cred;
00283   zfsfsal_handle_t * target_handle = (zfsfsal_handle_t *)target_hdl;
00284   zfsfsal_handle_t * dir_handle = (zfsfsal_handle_t *)dir_hdl;
00285   zfsfsal_op_context_t * p_context = (zfsfsal_op_context_t *)context;
00286 
00287   /* sanity checks.
00288    * note : attributes is optional.
00289    */
00290   if(!target_handle || !dir_handle || !p_context || !p_link_name)
00291     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_link);
00292 
00293   /* Hook to prevent creating objects in a snapashot */
00294   if(target_handle->data.i_snap != 0)
00295   {
00296     LogDebug(COMPONENT_FSAL, "Trying to create hard link inside a snapshot");
00297     Return(ERR_FSAL_ROFS, 0, INDEX_FSAL_link);
00298   }
00299 
00300   /* Tests if hardlinking is allowed by configuration. */
00301   if(!global_fs_info.link_support)
00302     Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_link);
00303   cred.uid = p_context->credential.user;
00304   cred.gid = p_context->credential.group;
00305 
00306   TakeTokenFSCall();
00307 
00308   rc = libzfswrap_link(p_context->export_context->p_vfs, &cred,
00309                        dir_handle->data.zfs_handle, target_handle->data.zfs_handle, p_link_name->name);
00310 
00311   ReleaseTokenFSCall();
00312 
00313   /* >> interpret returned error << */
00314   if(rc)
00315     Return(posix2fsal_error(rc), 0, INDEX_FSAL_link);
00316 
00317   if(attributes)
00318     {
00319       fsal_status_t status = ZFSFSAL_getattrs(target_hdl, context, attributes);
00320 
00321       /* on error, we set a special bit in the mask. */
00322       if(FSAL_IS_ERROR(status))
00323         {
00324           FSAL_CLEAR_MASK(attributes->asked_attributes);
00325           FSAL_SET_MASK(attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00326         }
00327 
00328     }
00329 
00330   /* OK */
00331   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_link);
00332 
00333 }
00334 
00342 fsal_status_t ZFSFSAL_mknode(fsal_handle_t * parentdir_handle,     /* IN */
00343                           fsal_name_t * p_node_name,    /* IN */
00344                           fsal_op_context_t * p_context,        /* IN */
00345                           fsal_accessmode_t accessmode, /* IN */
00346                           fsal_nodetype_t nodetype,     /* IN */
00347                           fsal_dev_t * dev,     /* IN */
00348                           fsal_handle_t * p_object_handle, /* OUT (handle to the created node) */
00349                           fsal_attrib_list_t * node_attributes  /* [ IN/OUT ] */
00350     )
00351 {
00352 
00353   /* sanity checks.
00354    * note : link_attributes is optional.
00355    */
00356   if(!parentdir_handle || !p_context || !nodetype || !dev || !p_node_name)
00357     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_mknode);
00358 
00359   /* Not implemented */
00360   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_mknode);
00361 
00362 }