nfs-ganesha 1.4
|
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 #include "HPSSclapiExt/hpssclapiext.h" 00023 00024 #include <hpss_errno.h> 00025 00062 fsal_status_t HPSSFSAL_create(hpssfsal_handle_t * parent_directory_handle, /* IN */ 00063 fsal_name_t * p_filename, /* IN */ 00064 hpssfsal_op_context_t * p_context, /* IN */ 00065 fsal_accessmode_t accessmode, /* IN */ 00066 hpssfsal_handle_t * object_handle, /* OUT */ 00067 fsal_attrib_list_t * object_attributes /* [ IN/OUT ] */ 00068 ) 00069 { 00070 00071 int rc; 00072 mode_t unix_mode; 00073 00074 hpss_Attrs_t new_attrs; 00075 ns_ObjHandle_t new_hdl; 00076 00077 /* cos management */ 00078 hpss_cos_hints_t hint; 00079 hpss_cos_priorities_t hintpri; 00080 00081 /* If no COS is specified in the config file, 00082 * we give NULL pointers to CreateHandle, 00083 * to use the default Cos for this Fileset. 00084 */ 00085 hpss_cos_hints_t *p_hint = NULL; 00086 hpss_cos_priorities_t *p_hintpri = NULL; 00087 00088 /* sanity checks. 00089 * note : object_attributes is optional. 00090 */ 00091 if(!parent_directory_handle || !p_context || !object_handle || !p_filename) 00092 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_create); 00093 00094 /* convert fsal mode to unix mode. */ 00095 unix_mode = fsal2unix_mode(accessmode); 00096 00097 /* Apply umask */ 00098 unix_mode = unix_mode & ~global_fs_info.umask; 00099 00100 /* Eventually set cos */ 00101 00102 if(p_context->export_context->default_cos != 0) 00103 { 00104 HPSSFSAL_BuildCos(p_context->export_context->default_cos, &hint, &hintpri); 00105 p_hint = &hint; 00106 p_hintpri = &hintpri; 00107 } 00108 00109 if(p_context->export_context->default_cos != 0) 00110 LogDebug(COMPONENT_FSAL, "Creating file with COS = %d", 00111 p_context->export_context->default_cos); 00112 else 00113 LogDebug(COMPONENT_FSAL, "Creating file with default fileset COS."); 00114 00115 LogDebug(COMPONENT_FSAL, "Creation mode: 0%o", accessmode); 00116 00117 /* call to API */ 00118 00119 TakeTokenFSCall(); 00120 00121 rc = HPSSFSAL_CreateHandle(&(parent_directory_handle->data.ns_handle), /* IN - Parent object handle */ 00122 p_filename->name, /* IN - Name of the file to be created */ 00123 unix_mode, /* IN - Desired file perms */ 00124 &(p_context->credential.hpss_usercred), /* IN - User credentials */ 00125 p_hint, /* IN - Desired class of service */ 00126 p_hintpri, /* IN - Priorities of hint struct */ 00127 NULL, /* OUT - Granted class of service */ 00128 (object_attributes ? &new_attrs : NULL), /* OUT - File attributes */ 00129 &new_hdl, /* OUT - File handle */ 00130 NULL); /* OUT - Client authorization */ 00131 00132 ReleaseTokenFSCall(); 00133 00134 /* /!\ WARNING : When the directory handle is stale, HPSS returns ENOTDIR. 00135 * If the returned value is HPSS_ENOTDIR, parent handle MAY be stale. 00136 * Thus, we must double-check by calling getattrs. 00137 */ 00138 if(rc == HPSS_ENOTDIR || rc == HPSS_ENOENT) 00139 { 00140 if(HPSSFSAL_IsStaleHandle(&parent_directory_handle->data.ns_handle, 00141 &p_context->credential.hpss_usercred)) 00142 { 00143 Return(ERR_FSAL_STALE, -rc, INDEX_FSAL_create); 00144 } 00145 } 00146 00147 /* other errors */ 00148 00149 if(rc) 00150 Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_create); 00151 00152 /* set output handle */ 00153 memset( (char *)object_handle, 0, sizeof( hpssfsal_handle_t ) ) ; 00154 object_handle->data.obj_type = FSAL_TYPE_FILE; 00155 object_handle->data.ns_handle = new_hdl; 00156 00157 if(object_attributes) 00158 { 00159 00160 fsal_status_t status; 00161 00162 /* convert hpss attributes to fsal attributes */ 00163 00164 status = hpss2fsal_attributes(&new_hdl, &new_attrs, object_attributes); 00165 00166 /* on error, we set a special bit in the mask. */ 00167 if(FSAL_IS_ERROR(status)) 00168 { 00169 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00170 FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00171 } 00172 00173 } 00174 00175 /* OK */ 00176 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_create); 00177 00178 } 00179 00217 fsal_status_t HPSSFSAL_mkdir(hpssfsal_handle_t * parent_directory_handle, /* IN */ 00218 fsal_name_t * p_dirname, /* IN */ 00219 hpssfsal_op_context_t * p_context, /* IN */ 00220 fsal_accessmode_t accessmode, /* IN */ 00221 hpssfsal_handle_t * object_handle, /* OUT */ 00222 fsal_attrib_list_t * object_attributes /* [ IN/OUT ] */ 00223 ) 00224 { 00225 00226 int rc; 00227 mode_t unix_mode; 00228 ns_ObjHandle_t lnk_hdl; 00229 hpss_Attrs_t lnk_attr; 00230 00231 /* sanity checks. 00232 * note : object_attributes is optional. 00233 */ 00234 if(!parent_directory_handle || !p_context || !object_handle || !p_dirname) 00235 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_mkdir); 00236 00237 /* convert FSAL mode to HPSS mode. */ 00238 unix_mode = fsal2unix_mode(accessmode); 00239 00240 /* Apply umask */ 00241 unix_mode = unix_mode & ~global_fs_info.umask; 00242 00243 TakeTokenFSCall(); 00244 00245 rc = HPSSFSAL_MkdirHandle(&(parent_directory_handle->data.ns_handle), 00246 p_dirname->name, 00247 unix_mode, 00248 &(p_context->credential.hpss_usercred), 00249 &lnk_hdl, (object_attributes ? &lnk_attr : NULL)); 00250 00251 ReleaseTokenFSCall(); 00252 00253 /* /!\ WARNING : When the directory handle is stale, HPSS returns ENOTDIR. 00254 * If the returned value is HPSS_ENOTDIR, parent handle MAY be stale. 00255 * Thus, we must double-check by calling getattrs. 00256 */ 00257 if(rc == HPSS_ENOTDIR || rc == HPSS_ENOENT) 00258 { 00259 if(HPSSFSAL_IsStaleHandle(&parent_directory_handle->data.ns_handle, 00260 &p_context->credential.hpss_usercred)) 00261 { 00262 Return(ERR_FSAL_STALE, -rc, INDEX_FSAL_mkdir); 00263 } 00264 } 00265 00266 /* other errors */ 00267 00268 if(rc) 00269 Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_mkdir); 00270 00271 /* set output handle */ 00272 memset( (char *)object_handle, 0, sizeof( hpssfsal_handle_t ) ) ; 00273 object_handle->data.obj_type = FSAL_TYPE_DIR; 00274 object_handle->data.ns_handle = lnk_hdl; 00275 00276 if(object_attributes) 00277 { 00278 00279 fsal_status_t status; 00280 00281 /* convert hpss attributes to fsal attributes */ 00282 00283 status = hpss2fsal_attributes(&lnk_hdl, &lnk_attr, object_attributes); 00284 00285 /* on error, we set a special bit in the mask. */ 00286 if(FSAL_IS_ERROR(status)) 00287 { 00288 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00289 FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00290 } 00291 } 00292 00293 /* OK */ 00294 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_mkdir); 00295 00296 } 00297 00335 fsal_status_t HPSSFSAL_link(hpssfsal_handle_t * target_handle, /* IN */ 00336 hpssfsal_handle_t * dir_handle, /* IN */ 00337 fsal_name_t * p_link_name, /* IN */ 00338 hpssfsal_op_context_t * p_context, /* IN */ 00339 fsal_attrib_list_t * attributes /* [ IN/OUT ] */ 00340 ) 00341 { 00342 00343 int rc; 00344 00345 /* sanity checks. 00346 * note : attributes is optional. 00347 */ 00348 LogFullDebug(COMPONENT_FSAL,"%p %p %p %p \n", target_handle, dir_handle, p_context, p_link_name); 00349 00350 if(!target_handle || !dir_handle || !p_context || !p_link_name) 00351 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_link); 00352 00353 /* Tests if hardlinking is allowed by configuration. */ 00354 00355 if(!global_fs_info.link_support) 00356 Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_link); 00357 00358 /* Call to HPSS API */ 00359 00360 TakeTokenFSCall(); 00361 00362 rc = hpss_LinkHandle(&(target_handle->data.ns_handle), /* IN - Handle of existing file */ 00363 &(dir_handle->data.ns_handle), /* IN - parent directory handle */ 00364 p_link_name->name, /* IN - New name of the object */ 00365 &(p_context->credential.hpss_usercred)); /* IN - pointer to user credentials */ 00366 00367 ReleaseTokenFSCall(); 00368 00369 /* /!\ WARNING : When one of the handles is stale, HPSS returns ENOTDIR or ENOENT. 00370 * Thus, we must check this by calling HPSSFSAL_IsStaleHandle. 00371 */ 00372 if(rc == HPSS_ENOTDIR || rc == HPSS_ENOENT) 00373 { 00374 if(HPSSFSAL_IsStaleHandle(&dir_handle->data.ns_handle, 00375 &p_context->credential.hpss_usercred) 00376 || 00377 HPSSFSAL_IsStaleHandle(&target_handle->data.ns_handle, 00378 &p_context->credential.hpss_usercred)) 00379 { 00380 Return(ERR_FSAL_STALE, -rc, INDEX_FSAL_link); 00381 } 00382 } 00383 00384 /* other errors */ 00385 if(rc) 00386 Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_link); 00387 00388 /* optionnaly get attributes */ 00389 00390 if(attributes) 00391 { 00392 00393 fsal_status_t st; 00394 00395 st = HPSSFSAL_getattrs(target_handle, p_context, attributes); 00396 00397 /* on error, we set a special bit in the mask. */ 00398 if(FSAL_IS_ERROR(st)) 00399 { 00400 FSAL_CLEAR_MASK(attributes->asked_attributes); 00401 FSAL_SET_MASK(attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00402 } 00403 00404 } 00405 00406 /* OK */ 00407 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_link); 00408 00409 } 00410 00418 fsal_status_t HPSSFSAL_mknode(hpssfsal_handle_t * parentdir_handle, /* IN */ 00419 fsal_name_t * p_node_name, /* IN */ 00420 hpssfsal_op_context_t * p_context, /* IN */ 00421 fsal_accessmode_t accessmode, /* IN */ 00422 fsal_nodetype_t nodetype, /* IN */ 00423 fsal_dev_t * dev, /* IN */ 00424 hpssfsal_handle_t * p_object_handle, /* OUT (handle to the created node) */ 00425 fsal_attrib_list_t * node_attributes /* [ IN/OUT ] */ 00426 ) 00427 { 00428 00429 /* sanity checks. 00430 * note : link_attributes is optional. 00431 */ 00432 if(!parentdir_handle || !p_context || !nodetype || !dev || !p_node_name) 00433 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_mknode); 00434 00435 /* Not implemented */ 00436 Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_mknode); 00437 00438 }