s3: OneFS bulk directory enumeration support
[ira/wip.git] / source3 / modules / vfs_onefs.c
index e2f272aa115dff4b9ca4bdeba58f71190a3c09dc..af52c713a835856751ccc08d0d67b8679077e2de 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 
+#define ONEFS_DATA_FASTBUF     10
+
+struct onefs_vfs_config share_config[ONEFS_DATA_FASTBUF];
+struct onefs_vfs_config *pshare_config;
+
+static void onefs_load_faketimestamp_config(struct vfs_handle_struct *handle,
+                                           struct onefs_vfs_config *cfg)
+{
+       const char **parm;
+       int snum = SNUM(handle->conn);
+
+       parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_NOW,
+                                  NULL);
+
+       if (parm) {
+               cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
+               set_namearray(&cfg->atime_now_list,*parm);
+       }
+
+       parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_CTIME_NOW,
+                                  NULL);
+
+       if (parm) {
+               cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
+               set_namearray(&cfg->ctime_now_list,*parm);
+       }
+
+       parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_NOW,
+                                  NULL);
+
+       if (parm) {
+               cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
+               set_namearray(&cfg->mtime_now_list,*parm);
+       }
+
+       parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_STATIC,
+                                  NULL);
+
+       if (parm) {
+               cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
+               set_namearray(&cfg->atime_static_list,*parm);
+       }
+
+       parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_STATIC,
+                                  NULL);
+
+       if (parm) {
+               cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
+               set_namearray(&cfg->mtime_static_list,*parm);
+       }
+
+       cfg->atime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_ATIME_SLOP,0);
+       cfg->ctime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_CTIME_SLOP,0);
+       cfg->mtime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_MTIME_SLOP,0);
+}
+
+
+static int onefs_load_config(struct vfs_handle_struct *handle)
+{
+       int snum = SNUM(handle->conn);
+       int share_count = lp_numservices();
+
+       if (!pshare_config) {
+
+               if (share_count <= ONEFS_DATA_FASTBUF)
+                       pshare_config = share_config;
+               else {
+                       pshare_config =
+                           SMB_MALLOC_ARRAY(struct onefs_vfs_config,
+                                            share_count);
+                       if (!pshare_config) {
+                               errno = ENOMEM;
+                               return -1;
+                       }
+
+                       memset(pshare_config, 0,
+                           (sizeof(struct onefs_vfs_config) * share_count));
+               }
+       }
+
+       if ((pshare_config[snum].init_flags &
+               ONEFS_VFS_CONFIG_INITIALIZED) == 0) {
+                       pshare_config[snum].init_flags =
+                           ONEFS_VFS_CONFIG_INITIALIZED;
+                       onefs_load_faketimestamp_config(handle,
+                                                       &pshare_config[snum]);
+       }
+
+       return 0;
+}
+
+bool onefs_get_config(int snum, int config_type,
+                     struct onefs_vfs_config *cfg)
+{
+       if (share_config[snum].init_flags & config_type)
+               *cfg = share_config[snum];
+       else
+               return false;
+
+       return true;
+}
+
+static int onefs_connect(struct vfs_handle_struct *handle, const char *service,
+                        const char *user)
+{
+       int ret = onefs_load_config(handle);
+
+       if (ret)
+               return ret;
+
+       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+}
+
 static int onefs_mkdir(vfs_handle_struct *handle, const char *path,
                       mode_t mode)
 {
@@ -40,8 +153,9 @@ static int onefs_open(vfs_handle_struct *handle, const char *fname,
        return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
 }
 
-static uint64_t onefs_get_alloc_size(struct vfs_handle_struct *handle,  files_struct *fsp,
-                               const SMB_STRUCT_STAT *sbuf)
+static uint64_t onefs_get_alloc_size(struct vfs_handle_struct *handle,
+                                    files_struct *fsp,
+                                    const SMB_STRUCT_STAT *sbuf)
 {
        uint64_t result;
 
@@ -130,10 +244,26 @@ static uint32_t onefs_fs_capabilities(struct vfs_handle_struct *handle)
 }
 
 static vfs_op_tuple onefs_ops[] = {
+       {SMB_VFS_OP(onefs_connect), SMB_VFS_OP_CONNECT,
+        SMB_VFS_LAYER_TRANSPARENT},
        {SMB_VFS_OP(onefs_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
         SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(onefs_opendir), SMB_VFS_OP_OPENDIR,
+        SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(onefs_readdir), SMB_VFS_OP_READDIR,
+        SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(onefs_seekdir), SMB_VFS_OP_SEEKDIR,
+        SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(onefs_telldir), SMB_VFS_OP_TELLDIR,
+        SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(onefs_rewinddir), SMB_VFS_OP_REWINDDIR,
+        SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(onefs_mkdir), SMB_VFS_OP_MKDIR,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(onefs_closedir), SMB_VFS_OP_CLOSEDIR,
+        SMB_VFS_LAYER_TRANSPARENT},
+       {SMB_VFS_OP(onefs_init_search_op), SMB_VFS_OP_INIT_SEARCH_OP,
+        SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(onefs_open), SMB_VFS_OP_OPEN,
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(onefs_create_file), SMB_VFS_OP_CREATE_FILE,