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_common.h" 00021 #include "namespace.h" 00022 00024 static int FS_Specific_Init(fusefs_specific_initinfo_t * fs_init_info) 00025 { 00026 00027 int rc = 0; 00028 fsal_op_context_t ctx; 00029 struct stat stbuf; 00030 unsigned int root_gen; 00031 00032 struct ganefuse_conn_info conn = { 00033 .proto_major = 0, /* XXX is another value necessary ? */ 00034 .proto_minor = 0, /* XXX is another value necessary ? */ 00035 .async_read = 0, 00036 .max_write = global_fs_info.maxwrite, 00037 .max_readahead = global_fs_info.maxread, 00038 .reserved = {0} 00039 }; 00040 00041 /* set filesystems operations and opaque info */ 00042 p_fs_ops = fs_init_info->fs_ops; 00043 fs_user_data = fs_init_info->user_data; 00044 00045 /* create a "fake" context in case init use it */ 00046 00047 fs_private_data = NULL; 00048 00049 FUSEFSAL_InitClientContext(&ctx); 00050 fsal_set_thread_context(&ctx); 00051 00052 /* call filesystem's init */ 00053 00054 if(p_fs_ops->init) 00055 { 00056 fs_private_data = p_fs_ops->init(&conn); 00057 } 00058 00059 /* reset context now fs_private_data is known */ 00060 00061 FUSEFSAL_InitClientContext(&ctx); 00062 fsal_set_thread_context(&ctx); 00063 00064 /* initialize namespace by getting root inode number 00065 * getattr is mandatory ! 00066 */ 00067 00068 if(!p_fs_ops->getattr) 00069 return -ENOSYS; 00070 00071 rc = p_fs_ops->getattr("/", &stbuf); 00072 00073 if(rc) 00074 { 00075 LogCrit(COMPONENT_FSAL, 00076 "FSAL INIT: Could not call initial 'getattr' on filesystem root"); 00077 00078 return rc; 00079 } 00080 00081 /* generation based on ctime for avoiding stale handles */ 00082 root_gen = stbuf.st_ctime; 00083 00084 if(stbuf.st_ino == 0) 00085 { 00086 /* filesystem does not provide inodes ! */ 00087 LogCrit(COMPONENT_FSAL, "WARNING in lookup: filesystem does not provide inode numbers"); 00088 /* root will have inode nbr 1 */ 00089 stbuf.st_ino = 1; 00090 } 00091 00092 /* initialize namespace */ 00093 rc = NamespaceInit(stbuf.st_ino, stbuf.st_dev, &root_gen); 00094 00095 return rc; 00096 00097 } 00098 00120 fsal_status_t FUSEFSAL_Init(fsal_parameter_t * init_info /* IN */ 00121 ) 00122 { 00123 00124 fsal_status_t status; 00125 int rc; 00126 00127 /* sanity check. */ 00128 00129 if(!init_info) 00130 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_Init); 00131 00132 /* proceeds FSAL internal status initialization */ 00133 00134 status = fsal_internal_init_global(&(init_info->fsal_info), 00135 &(init_info->fs_common_info)); 00136 00137 if(FSAL_IS_ERROR(status)) 00138 Return(status.major, status.minor, INDEX_FSAL_Init); 00139 00140 /* initialize filesystem stuff */ 00141 00142 if((rc = FS_Specific_Init((fusefs_specific_initinfo_t *) &init_info->fs_specific_info))) 00143 Return(ERR_FSAL_BAD_INIT, -rc, INDEX_FSAL_Init); 00144 00145 /* Everything went OK. */ 00146 00147 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_Init); 00148 00149 }