]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/cifs/readdir.c
[CIFS] Readpages and readir performance improvements - eliminate extra
[karo-tx-linux.git] / fs / cifs / readdir.c
index 9780f4ee7f1285bf1dff4fd6627ebefafdc41de9..9bdaaecae36f683ef52196b4d54cee256b006029 100644 (file)
@@ -142,6 +142,11 @@ static void fill_in_inode(struct inode *tmp_inode,
                tmp_inode->i_gid = cifs_sb->mnt_gid;
                /* set default mode. will override for dirs below */
                tmp_inode->i_mode = cifs_sb->mnt_file_mode;
+       } else {
+               /* mask off the type bits since it gets set
+               below and we do not want to get two type
+               bits set */
+               tmp_inode->i_mode &= ~S_IFMT;
        }
 
        if (attr & ATTR_DIRECTORY) {
@@ -152,12 +157,18 @@ static void fill_in_inode(struct inode *tmp_inode,
                }
                tmp_inode->i_mode |= S_IFDIR;
        } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) && 
-                  (attr & ATTR_SYSTEM) && (end_of_file == 0)) {
-               *pobject_type = DT_FIFO;
-               tmp_inode->i_mode |= S_IFIFO;
-/* BB Finish for SFU style symlinks and devies */
-/*     } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
-               (attr & ATTR_SYSTEM) && ) { */
+                  (attr & ATTR_SYSTEM)) {
+               if (end_of_file == 0)  {
+                       *pobject_type = DT_FIFO;
+                       tmp_inode->i_mode |= S_IFIFO;
+               } else {
+                       /* rather than get the type here, we mark the
+                       inode as needing revalidate and get the real type
+                       (blk vs chr vs. symlink) later ie in lookup */
+                       *pobject_type = DT_REG;
+                       tmp_inode->i_mode |= S_IFREG; 
+                       cifsInfo->time = 0;     
+               }
 /* we no longer mark these because we could not follow them */
 /*        } else if (attr & ATTR_REPARSE) {
                 *pobject_type = DT_LNK;
@@ -193,14 +204,23 @@ static void fill_in_inode(struct inode *tmp_inode,
        if (S_ISREG(tmp_inode->i_mode)) {
                cFYI(1, ("File inode"));
                tmp_inode->i_op = &cifs_file_inode_ops;
-               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
-                       tmp_inode->i_fop = &cifs_file_direct_ops;
+               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
+                       if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                               tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
+                       else
+                               tmp_inode->i_fop = &cifs_file_direct_ops;
+               
+               } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                       tmp_inode->i_fop = &cifs_file_nobrl_ops;
                else
                        tmp_inode->i_fop = &cifs_file_ops;
                if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
                        tmp_inode->i_fop->lock = NULL;
                tmp_inode->i_data.a_ops = &cifs_addr_ops;
-
+               if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
+                  (cifs_sb->tcon->ses->server->maxBuf <
+                       4096 + MAX_CIFS_HDR_SIZE))
+                       tmp_inode->i_data.a_ops->readpages = NULL;
                if(isNewInode)
                        return; /* No sense invalidating pages for new inode
                                   since have not started caching readahead file
@@ -255,6 +275,9 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
            cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastStatusChange));
 
        tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
+       /* since we set the inode type below we need to mask off type
+           to avoid strange results if bits above were corrupt */
+        tmp_inode->i_mode &= ~S_IFMT;
        if (type == UNIX_FILE) {
                *pobject_type = DT_REG;
                tmp_inode->i_mode |= S_IFREG;
@@ -280,6 +303,11 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
        } else if (type == UNIX_SOCKET) {
                *pobject_type = DT_SOCK;
                tmp_inode->i_mode |= S_IFSOCK;
+       } else {
+               /* safest to just call it a file */
+               *pobject_type = DT_REG;
+               tmp_inode->i_mode |= S_IFREG;
+               cFYI(1,("unknown inode type %d",type)); 
        }
 
        tmp_inode->i_uid = le64_to_cpu(pfindData->Uid);
@@ -306,6 +334,10 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
                if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
                        tmp_inode->i_fop->lock = NULL;
                tmp_inode->i_data.a_ops = &cifs_addr_ops;
+               if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
+                  (cifs_sb->tcon->ses->server->maxBuf < 
+                       4096 + MAX_CIFS_HDR_SIZE))
+                       tmp_inode->i_data.a_ops->readpages = NULL;
 
                if(isNewInode)
                        return; /* No sense invalidating pages for new inode since we
@@ -389,7 +421,8 @@ ffirst_retry:
 
        rc = CIFSFindFirst(xid, pTcon,full_path,cifs_sb->local_nls,
                &cifsFile->netfid, &cifsFile->srch_inf,
-               cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb));
+               cifs_sb->mnt_cifs_flags & 
+                       CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb));
        if(rc == 0)
                cifsFile->invalidHandle = FALSE;
        if((rc == -EOPNOTSUPP) && 
@@ -506,6 +539,30 @@ static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile)
        return rc;
 }
 
+/* Check if directory that we are searching has changed so we can decide
+   whether we can use the cached search results from the previous search */
+static int is_dir_changed(struct file * file)
+{
+       struct inode * inode;
+       struct cifsInodeInfo *cifsInfo;
+
+       if(file->f_dentry == NULL)
+               return 0;
+
+       inode = file->f_dentry->d_inode;
+
+       if(inode == NULL)
+               return 0;
+
+       cifsInfo = CIFS_I(inode);
+
+       if(cifsInfo->time == 0)
+               return 1; /* directory was changed, perhaps due to unlink */
+       else
+               return 0;
+
+}
+
 /* find the corresponding entry in the search */
 /* Note that the SMB server returns search entries for . and .. which
    complicates logic here if we choose to parse for them and we do not
@@ -522,7 +579,8 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
        struct cifsFileInfo * cifsFile = file->private_data;
        /* check if index in the buffer */
        
-       if((cifsFile == NULL) || (ppCurrentEntry == NULL) || (num_to_ret == NULL))
+       if((cifsFile == NULL) || (ppCurrentEntry == NULL) || 
+          (num_to_ret == NULL))
                return -ENOENT;
        
        *ppCurrentEntry = NULL;
@@ -530,7 +588,9 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
                cifsFile->srch_inf.index_of_last_entry - 
                        cifsFile->srch_inf.entries_in_buffer;
 /*     dump_cifs_file_struct(file, "In fce ");*/
-       if(index_to_find < first_entry_in_buffer) {
+       if(((index_to_find < cifsFile->srch_inf.index_of_last_entry) && 
+            is_dir_changed(file)) || 
+          (index_to_find < first_entry_in_buffer)) {
                /* close and restart search */
                cFYI(1,("search backing up - close and restart search"));
                cifsFile->invalidHandle = TRUE;
@@ -597,7 +657,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
        }
 
        if(pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
-               cFYI(1,("can not return entries when pos_in_buf beyond last entry"));
+               cFYI(1,("can not return entries pos_in_buf beyond last entry"));
                *num_to_ret = 0;
        } else
                *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
@@ -664,7 +724,7 @@ static int cifs_get_name_from_search_buf(struct qstr *pqst,
                                        (__le16 *)filename, len/2, nlt);
                else
                        pqst->len = cifs_strfromUCS_le((char *)pqst->name,
-                                       (wchar_t *)filename,len/2,nlt);
+                                       (__le16 *)filename,len/2,nlt);
        } else {
                pqst->name = filename;
                pqst->len = len;
@@ -826,7 +886,6 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
        if(pTcon == NULL)
                return -EINVAL;
 
-
        switch ((int) file->f_pos) {
        case 0:
                /*if (filldir(direntry, ".", 1, file->f_pos,