s3: Added SMB_VFS_INIT_SEARCH_OP to initialize data at the beginning of SMB search...
authorSteven Danneman <steven.danneman@isilon.com>
Tue, 3 Feb 2009 05:37:51 +0000 (21:37 -0800)
committerSteven Danneman <steven.danneman@isilon.com>
Tue, 10 Feb 2009 07:56:17 +0000 (23:56 -0800)
By default this VFS call is a NOOP, but the onefs vfs module takes advantage
of it to initialize direntry search caches at the beginning of each
TRANS2_FIND_FIRST, TRANS2_FIND_NEXT, SMBffirst, SMBsearch, and SMBunique

source3/include/proto.h
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_default.c
source3/modules/vfs_full_audit.c
source3/smbd/dir.c
source3/smbd/reply.c
source3/smbd/trans2.c

index eef7a0dd247f7016804917b11ab0be24ee56d6f9..849bed3b0b850e1da367c215734f7a5c1595e204 100644 (file)
@@ -6495,6 +6495,7 @@ const char *dptr_ReadDirName(TALLOC_CTX *ctx,
                        SMB_STRUCT_STAT *pst);
 bool dptr_SearchDir(struct dptr_struct *dptr, const char *name, long *poffset, SMB_STRUCT_STAT *pst);
 void dptr_DirCacheAdd(struct dptr_struct *dptr, const char *name, long offset);
+void dptr_init_search_op(struct dptr_struct *dptr);
 bool dptr_fill(char *buf1,unsigned int key);
 struct dptr_struct *dptr_fetch(char *buf,int *num);
 struct dptr_struct *dptr_fetch_lanman2(int dptr_num);
index 6aea0ae6a08725742cb4122a68b1d0c20bfe7c2b..99af30b1c5ed74f134bc2db6012b6e40a0faf7c4 100644 (file)
 /* Leave at 25 - not yet released. Add create time to ntimes. -- tstecher. */
 /* Leave at 25 - not yet released. Add get_alloc_size call. -- tprouty. */
 /* Leave at 25 - not yet released. Add SMB_STRUCT_STAT to readdir. - sdann */
+/* Leave at 25 - not yet released. Add init_search_op call. - sdann */
 
 #define SMB_VFS_INTERFACE_VERSION 25
 
@@ -144,14 +145,14 @@ struct smb_file_time;
 
 /*
     Available VFS operations. These values must be in sync with vfs_ops struct
-    (struct vfs_fn_pointers and struct vfs_handle_pointers inside of struct vfs_ops). 
+    (struct vfs_fn_pointers and struct vfs_handle_pointers inside of struct vfs_ops).
     In particular, if new operations are added to vfs_ops, appropriate constants
     should be added to vfs_op_type so that order of them kept same as in vfs_ops.
 */
 
 typedef enum _vfs_op_type {
        SMB_VFS_OP_NOOP = -1,
-       
+
        /* Disk operations */
 
        SMB_VFS_OP_CONNECT = 0,
@@ -173,6 +174,7 @@ typedef enum _vfs_op_type {
        SMB_VFS_OP_MKDIR,
        SMB_VFS_OP_RMDIR,
        SMB_VFS_OP_CLOSEDIR,
+       SMB_VFS_OP_INIT_SEARCH_OP,
 
        /* File operations */
 
@@ -313,6 +315,7 @@ struct vfs_ops {
                int (*mkdir)(struct vfs_handle_struct *handle, const char *path, mode_t mode);
                int (*rmdir)(struct vfs_handle_struct *handle, const char *path);
                int (*closedir)(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *dir);
+               void (*init_search_op)(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp);
 
                /* File operations */
 
@@ -484,6 +487,7 @@ struct vfs_ops {
                struct vfs_handle_struct *mkdir;
                struct vfs_handle_struct *rmdir;
                struct vfs_handle_struct *closedir;
+               struct vfs_handle_struct *init_search_op;
 
                /* File operations */
 
index 208566f77e0926a3c9f254523d9a7192296eb08e..e57cbd253862bd129b623dbadf9d6a94baf47255 100644 (file)
@@ -45,6 +45,7 @@
 #define SMB_VFS_MKDIR(conn, path, mode) ((conn)->vfs.ops.mkdir((conn)->vfs.handles.mkdir,(path), (mode)))
 #define SMB_VFS_RMDIR(conn, path) ((conn)->vfs.ops.rmdir((conn)->vfs.handles.rmdir, (path)))
 #define SMB_VFS_CLOSEDIR(conn, dir) ((conn)->vfs.ops.closedir((conn)->vfs.handles.closedir, dir))
+#define SMB_VFS_INIT_SEARCH_OP(conn, dirp) ((conn)->vfs.ops.init_search_op((conn)->vfs.handles.init_search_op, (dirp)))
 
 /* File operations */
 #define SMB_VFS_OPEN(conn, fname, fsp, flags, mode) (((conn)->vfs.ops.open)((conn)->vfs.handles.open, (fname), (fsp), (flags), (mode)))
 #define SMB_VFS_OPAQUE_MKDIR(conn, path, mode) ((conn)->vfs_opaque.ops.mkdir((conn)->vfs_opaque.handles.mkdir,(path), (mode)))
 #define SMB_VFS_OPAQUE_RMDIR(conn, path) ((conn)->vfs_opaque.ops.rmdir((conn)->vfs_opaque.handles.rmdir, (path)))
 #define SMB_VFS_OPAQUE_CLOSEDIR(conn, dir) ((conn)->vfs_opaque.ops.closedir((conn)->vfs_opaque.handles.closedir, dir))
+#define SMB_VFS_OPAQUE_INIT_SEARCH_OP(conn, dirp) ((conn)->vfs_opaque.ops.init_search_op((conn)->vfs_opaque.handles.init_search_op, (dirp)))
 
 /* File operations */
 #define SMB_VFS_OPAQUE_OPEN(conn, fname, fsp, flags, mode) (((conn)->vfs_opaque.ops.open)((conn)->vfs_opaque.handles.open, (fname), (fsp), (flags), (mode)))
 #define SMB_VFS_NEXT_MKDIR(handle, path, mode) ((handle)->vfs_next.ops.mkdir((handle)->vfs_next.handles.mkdir,(path), (mode)))
 #define SMB_VFS_NEXT_RMDIR(handle, path) ((handle)->vfs_next.ops.rmdir((handle)->vfs_next.handles.rmdir, (path)))
 #define SMB_VFS_NEXT_CLOSEDIR(handle, dir) ((handle)->vfs_next.ops.closedir((handle)->vfs_next.handles.closedir, dir))
+#define SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp) ((handle)->vfs_next.ops.init_search_op((handle)->vfs_next.handles.init_search_op, (dirp)))
 
 /* File operations */
 #define SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode) (((handle)->vfs_next.ops.open)((handle)->vfs_next.handles.open, (fname), (fsp), (flags), (mode)))
index 7d61191a6973a1e50223979fb19148f7ce5db8ff..cb56690dbb8f2c9108d2d5dace3e91bb3e68d753 100644 (file)
@@ -206,6 +206,13 @@ static int vfswrap_closedir(vfs_handle_struct *handle,  SMB_STRUCT_DIR *dirp)
        return result;
 }
 
+static void vfswrap_init_search_op(vfs_handle_struct *handle,
+                                  SMB_STRUCT_DIR *dirp)
+{
+       /* Default behavior is a NOOP */
+       return;
+}
+
 /* File operations */
 
 static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
@@ -1449,6 +1456,8 @@ static vfs_op_tuple vfs_default_ops[] = {
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_closedir),  SMB_VFS_OP_CLOSEDIR,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_init_search_op),    SMB_VFS_OP_INIT_SEARCH_OP,
+        SMB_VFS_LAYER_OPAQUE},
 
        /* File operations */
 
index e279772494d752dc1e445d21f515fcc89984a3a0..e7ca77f6fa9b5ef681fab449709927fc8d1851f4 100644 (file)
@@ -108,6 +108,8 @@ static int smb_full_audit_rmdir(vfs_handle_struct *handle,
                       const char *path);
 static int smb_full_audit_closedir(vfs_handle_struct *handle,
                          SMB_STRUCT_DIR *dirp);
+static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
+                       SMB_STRUCT_DIR *dirp);
 static int smb_full_audit_open(vfs_handle_struct *handle,
                      const char *fname, files_struct *fsp, int flags, mode_t mode);
 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
@@ -373,6 +375,8 @@ static vfs_op_tuple audit_op_tuples[] = {
         SMB_VFS_LAYER_LOGGER},
        {SMB_VFS_OP(smb_full_audit_closedir),   SMB_VFS_OP_CLOSEDIR,
         SMB_VFS_LAYER_LOGGER},
+       {SMB_VFS_OP(smb_full_audit_init_search_op), SMB_VFS_OP_INIT_SEARCH_OP,
+        SMB_VFS_LAYER_LOGGER},
 
        /* File operations */
 
@@ -587,6 +591,7 @@ static struct {
        { SMB_VFS_OP_MKDIR,     "mkdir" },
        { SMB_VFS_OP_RMDIR,     "rmdir" },
        { SMB_VFS_OP_CLOSEDIR,  "closedir" },
+       { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
        { SMB_VFS_OP_OPEN,      "open" },
        { SMB_VFS_OP_CREATE_FILE, "create_file" },
        { SMB_VFS_OP_CLOSE,     "close" },
@@ -1110,6 +1115,15 @@ static int smb_full_audit_closedir(vfs_handle_struct *handle,
        return result;
 }
 
+static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
+                       SMB_STRUCT_DIR *dirp)
+{
+       SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
+
+       do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
+       return;
+}
+
 static int smb_full_audit_open(vfs_handle_struct *handle,
                      const char *fname, files_struct *fsp, int flags, mode_t mode)
 {
index c4f6b4fe5596d9cd3db001258c310e17ad30bd5e..6618bf07b015717a5f3e9a7269d4fd797014149c 100644 (file)
@@ -680,6 +680,14 @@ void dptr_DirCacheAdd(struct dptr_struct *dptr, const char *name, long offset)
        DirCacheAdd(dptr->dir_hnd, name, offset);
 }
 
+/****************************************************************************
+ Initialize variables & state data at the beginning of all search SMB requests.
+****************************************************************************/
+void dptr_init_search_op(struct dptr_struct *dptr)
+{
+       return SMB_VFS_INIT_SEARCH_OP(dptr->conn, dptr->dir_hnd->dir);
+}
+
 /****************************************************************************
  Fill the 5 byte server reserved dptr field.
 ****************************************************************************/
index 628f481c1ce1e03641ac13b215a52106b2ac78b3..256160c402570728afbfb73d834d872231773b65 100644 (file)
@@ -1380,6 +1380,9 @@ void reply_search(struct smb_request *req)
 
        DEBUG(4,("dptr_num is %d\n",dptr_num));
 
+       /* Initialize per SMBsearch/SMBffirst/SMBfunique operation data */
+       dptr_init_search_op(conn->dirptr);
+
        if ((dirtype&0x1F) == aVOLID) {
                char buf[DIR_STRUCT_SIZE];
                memcpy(buf,status,21);
index 6a6e59a581a9dfbafaef08e983a12ac5b735451b..cea066e97ff453477c73b55a20dac645f4f8f1e6 100644 (file)
@@ -1914,7 +1914,7 @@ close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
                /* W2K3 seems to treat zero as 1. */
                maxentries = 1;
        }
+
        switch (info_level) {
                case SMB_FIND_INFO_STANDARD:
                case SMB_FIND_EA_SIZE:
@@ -2043,7 +2043,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
        params = *pparams;
 
-       /* Save the wildcard match and attribs we are using on this directory - 
+       /* Save the wildcard match and attribs we are using on this directory -
                needed as lanman2 assumes these are being saved between calls */
 
        ntstatus = dptr_create(conn,
@@ -2064,6 +2064,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        dptr_num = dptr_dnum(conn->dirptr);
        DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype));
 
+       /* Initialize per TRANS2_FIND_FIRST operation data */
+       dptr_init_search_op(conn->dirptr);
+
        /* We don't need to check for VOL here as this is returned by
                a different TRANS2 call. */
 
@@ -2078,7 +2081,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        for (i=0;(i<maxentries) && !finished && !out_of_space;i++) {
                bool got_exact_match = False;
 
-               /* this is a heuristic to avoid seeking the dirptr except when 
+               /* this is a heuristic to avoid seeking the dirptr except when
                        absolutely necessary. It allows for a filename of about 40 chars */
                if (space_remaining < DIRLEN_GUESS && numentries > 0) {
                        out_of_space = True;
@@ -2374,6 +2377,9 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                (long)conn->dirptr,
                dptr_TellDir(conn->dirptr)));
 
+       /* Initialize per TRANS2_FIND_NEXT operation data */
+       dptr_init_search_op(conn->dirptr);
+
        /* We don't need to check for VOL here as this is returned by
                a different TRANS2 call. */