nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=4:tabstop=4: 00003 */ 00004 00015 #ifdef HAVE_CONFIG_H 00016 #include "config.h" 00017 #endif 00018 #include "fsal_convert.h" 00019 #include "fsal_internal.h" 00020 #include <sys/types.h> 00021 #include <sys/stat.h> 00022 #include <errno.h> 00023 #include <string.h> 00024 #include <fcntl.h> 00025 00026 #define MAX_2( x, y ) ( (x) > (y) ? (x) : (y) ) 00027 #define MAX_3( x, y, z ) ( (x) > (y) ? MAX_2((x),(z)) : MAX_2((y),(z)) ) 00028 00040 int posix2fsal_error(int posix_errorcode) 00041 { 00042 switch (-posix_errorcode) 00043 { 00044 case EPERM: 00045 return ERR_FSAL_PERM; 00046 00047 case ENOENT: 00048 return ERR_FSAL_NOENT; 00049 00050 /* connection error */ 00051 #ifdef _AIX_5 00052 case ENOCONNECT: 00053 #elif defined _LINUX 00054 case ECONNREFUSED: 00055 case ECONNABORTED: 00056 case ECONNRESET: 00057 #endif 00058 00059 /* IO error */ 00060 case EIO: 00061 00062 /* too many open files */ 00063 case ENFILE: 00064 case EMFILE: 00065 00066 /* broken pipe */ 00067 case EPIPE: 00068 00069 /* all shown as IO errors */ 00070 return ERR_FSAL_IO; 00071 00072 /* no such device */ 00073 case ENODEV: 00074 case ENXIO: 00075 return ERR_FSAL_NXIO; 00076 00077 /* invalid file descriptor : */ 00078 case EBADF: 00079 /* we suppose it was not opened... */ 00080 00088 return ERR_FSAL_NOT_OPENED; 00089 00090 case ENOMEM: 00091 return ERR_FSAL_NOMEM; 00092 00093 case EACCES: 00094 return ERR_FSAL_ACCESS; 00095 00096 case EFAULT: 00097 return ERR_FSAL_FAULT; 00098 00099 case EEXIST: 00100 return ERR_FSAL_EXIST; 00101 00102 case EXDEV: 00103 return ERR_FSAL_XDEV; 00104 00105 case ENOTDIR: 00106 return ERR_FSAL_NOTDIR; 00107 00108 case EISDIR: 00109 return ERR_FSAL_ISDIR; 00110 00111 case EINVAL: 00112 return ERR_FSAL_INVAL; 00113 00114 case EFBIG: 00115 return ERR_FSAL_FBIG; 00116 00117 case ENOSPC: 00118 return ERR_FSAL_NOSPC; 00119 00120 case EMLINK: 00121 return ERR_FSAL_MLINK; 00122 00123 case EDQUOT: 00124 return ERR_FSAL_DQUOT; 00125 00126 case ENAMETOOLONG: 00127 return ERR_FSAL_NAMETOOLONG; 00128 00135 #ifdef _AIX 00136 case 87: 00137 #else 00138 case ENOTEMPTY: 00139 case -ENOTEMPTY: 00140 #endif 00141 return ERR_FSAL_NOTEMPTY; 00142 00143 case ESTALE: 00144 return ERR_FSAL_STALE; 00145 00146 /* Error code that needs a retry */ 00147 case EAGAIN: 00148 case EBUSY: 00149 00150 return ERR_FSAL_DELAY; 00151 00152 case ENOTSUP: 00153 return ERR_FSAL_NOTSUPP; 00154 00155 default: 00156 00157 /* other unexpected errors */ 00158 return ERR_FSAL_SERVERFAULT; 00159 } 00160 } 00161 00175 int fsal2posix_openflags(fsal_openflags_t fsal_flags, int *posix_flags) 00176 { 00177 int cpt; 00178 00179 if(!posix_flags) 00180 return ERR_FSAL_FAULT; 00181 00182 /* check that all used flags exist */ 00183 00184 if(fsal_flags & 00185 ~(FSAL_O_RDONLY | FSAL_O_RDWR | FSAL_O_WRONLY | FSAL_O_APPEND | 00186 FSAL_O_TRUNC)) 00187 return ERR_FSAL_INVAL; 00188 00189 /* Check for flags compatibility */ 00190 00191 /* O_RDONLY O_WRONLY O_RDWR cannot be used together */ 00192 00193 cpt = 0; 00194 if(fsal_flags & FSAL_O_RDONLY) 00195 cpt++; 00196 if(fsal_flags & FSAL_O_RDWR) 00197 cpt++; 00198 if(fsal_flags & FSAL_O_WRONLY) 00199 cpt++; 00200 00201 if(cpt > 1) 00202 return ERR_FSAL_INVAL; 00203 00204 /* FSAL_O_APPEND et FSAL_O_TRUNC cannot be used together */ 00205 00206 if((fsal_flags & FSAL_O_APPEND) && (fsal_flags & FSAL_O_TRUNC)) 00207 return ERR_FSAL_INVAL; 00208 00209 /* FSAL_O_TRUNC without FSAL_O_WRONLY or FSAL_O_RDWR */ 00210 00211 if((fsal_flags & FSAL_O_TRUNC) && !(fsal_flags & (FSAL_O_WRONLY | 00212 FSAL_O_RDWR))) 00213 return ERR_FSAL_INVAL; 00214 00215 /* conversion */ 00216 *posix_flags = 0; 00217 00218 if(fsal_flags & FSAL_O_RDONLY) 00219 *posix_flags |= O_RDONLY; 00220 if(fsal_flags & FSAL_O_WRONLY) 00221 *posix_flags |= O_WRONLY; 00222 if(fsal_flags & FSAL_O_RDWR) 00223 *posix_flags |= O_RDWR; 00224 00225 return ERR_FSAL_NO_ERROR; 00226 } 00227 00228 00229 fsal_status_t posix2fsal_attributes(struct stat* st, 00230 fsal_attrib_list_t * attrs) 00231 { 00232 fsal_attrib_mask_t supp_attr, unsupp_attr; 00233 00234 /* sanity checks */ 00235 if(!st || !attrs) 00236 ReturnCode(ERR_FSAL_FAULT, 0); 00237 00238 /* check that asked attributes are supported */ 00239 supp_attr = global_fs_info.supported_attrs; 00240 00241 unsupp_attr = (attrs->asked_attributes) & (~supp_attr); 00242 if(unsupp_attr) 00243 { 00244 LogFullDebug(COMPONENT_FSAL, "Unsupported attributes: %#llX", 00245 unsupp_attr); 00246 ReturnCode(ERR_FSAL_ATTRNOTSUPP, 0); 00247 } 00248 00249 /* Initialize ACL regardless of whether ACL was asked or not. 00250 * This is needed to make sure ACL attribute is initialized. */ 00251 attrs->acl = NULL; 00252 00253 /* Fills the output struct */ 00254 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_SUPPATTR)) 00255 { 00256 attrs->supported_attributes = supp_attr; 00257 } 00258 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_TYPE)) 00259 { 00260 attrs->type = posix2fsal_type(st->st_mode); 00261 } 00262 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_SIZE)) 00263 { 00264 attrs->filesize = st->st_size; 00265 } 00266 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_FSID)) 00267 { 00268 attrs->fsid = posix2fsal_fsid(st->st_dev); 00269 } 00270 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_ACL)) 00271 { 00272 attrs->acl = NULL; 00273 } 00274 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_FILEID)) 00275 { 00276 attrs->fileid = (fsal_u64_t) (st->st_ino); 00277 } 00278 00279 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_MODE)) 00280 { 00281 attrs->mode = unix2fsal_mode(st->st_mode); 00282 } 00283 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_NUMLINKS)) 00284 { 00285 attrs->numlinks = st->st_nlink; 00286 } 00287 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_OWNER)) 00288 { 00289 attrs->owner = st->st_uid; 00290 } 00291 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_GROUP)) 00292 { 00293 attrs->group = st->st_gid; 00294 } 00295 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_ATIME)) 00296 { 00297 attrs->atime = posix2fsal_time(st->st_atime); 00298 00299 } 00300 00301 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_CTIME)) 00302 { 00303 attrs->ctime = posix2fsal_time(st->st_ctime); 00304 } 00305 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_MTIME)) 00306 { 00307 attrs->mtime = posix2fsal_time(st->st_mtime); 00308 } 00309 00310 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_CHGTIME)) 00311 { 00312 attrs->chgtime 00313 = posix2fsal_time(MAX_2(st->st_mtime, st->st_ctime)); 00314 attrs->change = (uint64_t) attrs->chgtime.seconds ; 00315 } 00316 00317 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_SPACEUSED)) 00318 { 00319 attrs->spaceused = st->st_blocks * S_BLKSIZE; 00320 } 00321 00322 if(FSAL_TEST_MASK(attrs->asked_attributes, FSAL_ATTR_RAWDEV)) 00323 { 00324 attrs->rawdev = posix2fsal_devt(st->st_rdev); 00325 } 00326 00327 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00328 } 00329 00330 int stat2fsal_fh(struct ceph_mount_info *cmount, 00331 struct stat *st, 00332 cephfsal_handle_t* handle) 00333 { 00334 VINODE(handle).ino.val = st->st_ino; 00335 VINODE(handle).snapid.val = st->st_dev; 00336 00337 return ceph_ll_connectable_x(cmount, VINODE(handle), 00338 &handle->data.parent_ino, 00339 &handle->data.parent_hash); 00340 }